diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index a52eff5fe..5f7422ce5 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2086,18 +2086,17 @@ void call_ng_main_flags(const ng_parser_t *parser, str *key, parser_arg value, h } } -static void call_ng_process_flags(sdp_ng_flags *out, ng_command_ctx_t *ctx, enum ng_opmode opmode) { +static void call_ng_process_flags(sdp_ng_flags *out, ng_command_ctx_t *ctx) { const ng_parser_t *parser = ctx->parser_ctx.parser; - call_ng_flags_init(out, opmode); - ctx->opmode = opmode; + call_ng_flags_init(out, ctx->opmode); ctx->flags = out; // check for default templates, "default" first if (rtpe_default_signalling_templates[OP_OTHER].len) parse_rtpp_flags(&rtpe_default_signalling_templates[OP_OTHER], out); // and then one matching the current command - if (opmode != OP_OTHER && rtpe_default_signalling_templates[opmode].len) - parse_rtpp_flags(&rtpe_default_signalling_templates[opmode], out); + if (ctx->opmode != OP_OTHER && rtpe_default_signalling_templates[ctx->opmode].len) + parse_rtpp_flags(&rtpe_default_signalling_templates[ctx->opmode], out); parser->dict_iter(parser, ctx->req, call_ng_main_flags, out); } @@ -2195,7 +2194,7 @@ void save_last_sdp(struct call_monologue *ml, str *sdp, sdp_sessions_q *parsed, } -static enum basic_errors call_ng_basic_checks(sdp_ng_flags *flags, enum ng_opmode opmode) +static enum basic_errors call_ng_basic_checks(sdp_ng_flags *flags) { if (!flags->sdp.s) return NG_ERROR_NO_SDP_BODY; @@ -2203,7 +2202,7 @@ static enum basic_errors call_ng_basic_checks(sdp_ng_flags *flags, enum ng_opmod return NG_ERROR_NO_CALL_ID; if (!flags->from_tag.s) return NG_ERROR_NO_FROM_TAG; - if (opmode == OP_ANSWER && !flags->to_tag.s) + if (flags->opmode == OP_ANSWER && !flags->to_tag.s) return NG_ERROR_NO_TO_TAG; return 0; } @@ -2231,7 +2230,7 @@ static const char *call_offer_get_call(call_t **callp, sdp_ng_flags *flags) { return NULL; } -static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode opmode, const char* addr, +static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, const char* addr, const endpoint_t *sin) { const char *errstr; @@ -2246,17 +2245,17 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode op const ng_parser_t *parser = ctx->parser_ctx.parser; g_auto(str) sdp_out = STR_NULL; - call_ng_process_flags(&flags, ctx, opmode); + call_ng_process_flags(&flags, ctx); - if ((ret = call_ng_basic_checks(&flags, opmode)) > 0) + if ((ret = call_ng_basic_checks(&flags)) > 0) return _ng_basic_errors[ret]; - if (opmode == OP_OFFER) { + if (flags.opmode == OP_OFFER) { errstr = call_offer_get_call(&call, &flags); if (errstr) goto out; } - else if (opmode == OP_ANSWER) { + else if (flags.opmode == OP_ANSWER) { call = call_get(&flags.call_id); errstr = "Unknown call-id"; @@ -2285,7 +2284,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode op goto out; // SDP fragments for trickle ICE must always operate on an existing call - if (opmode == OP_OFFER && trickle_ice_update(ctx->ngbuf, call, &flags, &streams)) { + if (flags.opmode == OP_OFFER && trickle_ice_update(ctx->ngbuf, call, &flags, &streams)) { errstr = NULL; // SDP fragments for trickle ICE are consumed with no replacement returned goto out; @@ -2317,7 +2316,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode op struct call_monologue *from_ml = monologues[0]; struct call_monologue *to_ml = monologues[1]; - if (opmode == OP_OFFER) { + if (flags.opmode == OP_OFFER) { from_ml->tagtype = FROM_TAG; } else { from_ml->tagtype = TO_TAG; @@ -2342,7 +2341,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode op recording = call->recording; - meta_write_sdp_before(recording, &sdp, from_ml, opmode); + meta_write_sdp_before(recording, &sdp, from_ml, flags.opmode); /* if all fine, prepare an outer sdp and save it */ if ((ret = sdp_create(&sdp_out, to_ml, &flags)) == 0) { @@ -2355,7 +2354,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum ng_opmode op ctx->ngbuf->sdp_out = sdp_out.s; ctx->parser_ctx.parser->dict_add_str(output, "sdp", &sdp_out); - meta_write_sdp_after(recording, &sdp_out, from_ml, opmode); + meta_write_sdp_after(recording, &sdp_out, from_ml, flags.opmode); sdp_out = STR_NULL; /* ownership passed to output */ } @@ -2396,11 +2395,11 @@ const char *call_offer_ng(ng_command_ctx_t *ctx, const char* addr, const endpoint_t *sin) { - return call_offer_answer_ng(ctx, OP_OFFER, addr, sin); + return call_offer_answer_ng(ctx, addr, sin); } const char *call_answer_ng(ng_command_ctx_t *ctx) { - return call_offer_answer_ng(ctx, OP_ANSWER, NULL, NULL); + return call_offer_answer_ng(ctx, NULL, NULL); } const char *call_delete_ng(ng_command_ctx_t *ctx) { @@ -2408,7 +2407,7 @@ const char *call_delete_ng(ng_command_ctx_t *ctx) { parser_arg output = ctx->resp; const ng_parser_t *parser = ctx->parser_ctx.parser; - call_ng_process_flags(&rtpp_flags, ctx, OP_DELETE); + call_ng_process_flags(&rtpp_flags, ctx); if (!rtpp_flags.call_id.len) return "No call-id in message"; @@ -2897,7 +2896,7 @@ const char *call_query_ng(ng_command_ctx_t *ctx) { if (!parser->dict_get_str(input, "call-id", &callid)) return "No call-id in message"; - call = call_get_opmode(&callid, OP_QUERY); + call = call_get_opmode(&callid, ctx->opmode); if (!call) return "Unknown call-id"; parser->dict_get_str(input, "from-tag", &fromtag); @@ -2932,7 +2931,6 @@ const char *call_list_ng(ng_command_ctx_t *ctx) { static const char *call_recording_common_ng(ng_command_ctx_t *ctx, - enum ng_opmode opmode, void (*fn)(ng_command_ctx_t *, call_t *call)) { g_auto(sdp_ng_flags) flags; @@ -2940,11 +2938,11 @@ static const char *call_recording_common_ng(ng_command_ctx_t *ctx, parser_arg input = ctx->req; const ng_parser_t *parser = ctx->parser_ctx.parser; - call_ng_process_flags(&flags, ctx, opmode); + call_ng_process_flags(&flags, ctx); if (!parser->dict_get_str(input, "call-id", &flags.call_id)) return "No call-id in message"; - call = call_get_opmode(&flags.call_id, opmode); + call = call_get_opmode(&flags.call_id, flags.opmode); if (!call) return "Unknown call-id"; @@ -2974,7 +2972,7 @@ static void start_recording_fn(ng_command_ctx_t *ctx, call_t *call) { recording_start(call); } const char *call_start_recording_ng(ng_command_ctx_t *ctx) { - return call_recording_common_ng(ctx, OP_START_RECORDING, start_recording_fn); + return call_recording_common_ng(ctx, start_recording_fn); } @@ -2982,7 +2980,7 @@ static void pause_recording_fn(ng_command_ctx_t *ctx, call_t *call) { recording_pause(call); } const char *call_pause_recording_ng(ng_command_ctx_t *ctx) { - return call_recording_common_ng(ctx, OP_PAUSE_RECORDING, pause_recording_fn); + return call_recording_common_ng(ctx, pause_recording_fn); } @@ -3012,12 +3010,12 @@ static void stop_recording_fn(ng_command_ctx_t *ctx, call_t *call) { fn(call); } const char *call_stop_recording_ng(ng_command_ctx_t *ctx) { - return call_recording_common_ng(ctx, OP_STOP_RECORDING, stop_recording_fn); + return call_recording_common_ng(ctx, stop_recording_fn); } static const char *media_block_match1(call_t *call, struct call_monologue **monologue, - sdp_ng_flags *flags, enum ng_opmode opmode) + sdp_ng_flags *flags) { if (flags->label.s) { *monologue = t_hash_table_lookup(call->labels, &flags->label); @@ -3051,8 +3049,8 @@ found: } /* ignore from-tag, if directional is not set */ else if (flags->from_tag.s && - (!IS_OP_DIRECTIONAL(opmode) || - (IS_OP_DIRECTIONAL(opmode) && flags->directional))) { + (!IS_OP_DIRECTIONAL(flags->opmode) || + (IS_OP_DIRECTIONAL(flags->opmode) && flags->directional))) { *monologue = call_get_monologue(call, &flags->from_tag); if (!*monologue) return "From-tag given, but no such tag exists"; @@ -3062,16 +3060,16 @@ found: return NULL; } static const char *media_block_match(call_t **call, struct call_monologue **monologue, - sdp_ng_flags *flags, ng_command_ctx_t *ctx, enum ng_opmode opmode) + sdp_ng_flags *flags, ng_command_ctx_t *ctx) { *call = NULL; *monologue = NULL; - call_ng_process_flags(flags, ctx, opmode); + call_ng_process_flags(flags, ctx); if (!flags->call_id.s) return "No call-id in message"; - *call = call_get_opmode(&flags->call_id, opmode); + *call = call_get_opmode(&flags->call_id, flags->opmode); if (!*call) return "Unknown call-ID"; @@ -3079,12 +3077,12 @@ static const char *media_block_match(call_t **call, struct call_monologue **mono if (flags->all == ALL_ALL) // explicitly non-directional, so skip the rest return NULL; - const char *err = media_block_match1(*call, monologue, flags, opmode); + const char *err = media_block_match1(*call, monologue, flags); if (err) return err; // for generic ops, handle set-label here if given - if (IS_OP_OTHER(opmode) && flags->set_label.len && *monologue) { + if (IS_OP_OTHER(flags->opmode) && flags->set_label.len && *monologue) { (*monologue)->label = call_str_cpy(&flags->set_label); t_hash_table_replace((*call)->labels, &(*monologue)->label, *monologue); } @@ -3098,13 +3096,13 @@ void add_media_to_sub_list(subscription_q *q, struct call_media *media, struct c t_queue_push_tail(q, ms); } static const char *media_block_match_mult(call_t **call, subscription_q *medias, - sdp_ng_flags *flags, ng_command_ctx_t *ctx, enum ng_opmode opmode) + sdp_ng_flags *flags, ng_command_ctx_t *ctx) { - call_ng_process_flags(flags, ctx, opmode); + call_ng_process_flags(flags, ctx); if (!flags->call_id.s) return "No call-id in message"; - *call = call_get_opmode(&flags->call_id, opmode); + *call = call_get_opmode(&flags->call_id, flags->opmode); if (!*call) return "Unknown call-ID"; @@ -3124,7 +3122,7 @@ static const char *media_block_match_mult(call_t **call, subscription_q *medias, /* is a single ml given? */ struct call_monologue *ml = NULL; - const char *err = media_block_match1(*call, &ml, flags, opmode); + const char *err = media_block_match1(*call, &ml, flags); if (err) return err; if (ml) { @@ -3168,7 +3166,7 @@ const char *call_start_forwarding_ng(ng_command_ctx_t *ctx) { const char *errstr = NULL; g_auto(sdp_ng_flags) flags; - errstr = media_block_match(&call, &monologue, &flags, ctx, OP_START_FORWARDING); + errstr = media_block_match(&call, &monologue, &flags, ctx); if (errstr) return errstr; @@ -3197,7 +3195,7 @@ const char *call_stop_forwarding_ng(ng_command_ctx_t *ctx) { const char *errstr = NULL; g_auto(sdp_ng_flags) flags; - errstr = media_block_match(&call, &monologue, &flags, ctx, OP_STOP_FORWARDING); + errstr = media_block_match(&call, &monologue, &flags, ctx); if (errstr) return errstr; @@ -3305,7 +3303,7 @@ const char *call_block_dtmf_ng(ng_command_ctx_t *ctx) { const char *errstr = NULL; g_auto(sdp_ng_flags) flags; - errstr = media_block_match(&call, &monologue, &flags, ctx, OP_BLOCK_DTMF); + errstr = media_block_match(&call, &monologue, &flags, ctx); if (errstr) return errstr; @@ -3320,7 +3318,7 @@ const char *call_unblock_dtmf_ng(ng_command_ctx_t *ctx) { const char *errstr = NULL; g_auto(sdp_ng_flags) flags; - errstr = media_block_match(&call, &monologue, &flags, ctx, OP_UNBLOCK_DTMF); + errstr = media_block_match(&call, &monologue, &flags, ctx); if (errstr) return errstr; @@ -3383,7 +3381,7 @@ static const char *call_block_silence_media(ng_command_ctx_t *ctx, bool on_off, g_auto(sdp_ng_flags) flags; bool found_subscriptions = false; - errstr = media_block_match(&call, &monologue, &flags, ctx, OP_BLOCK_SILENCE_MEDIA); + errstr = media_block_match(&call, &monologue, &flags, ctx); if (errstr) return errstr; @@ -3560,7 +3558,7 @@ static const char *play_media_select_party(call_t **call, monologues_q *monologu t_queue_init(monologues); - const char *err = media_block_match(call, &monologue, flags, ctx, OP_PLAY_MEDIA); + const char *err = media_block_match(call, &monologue, flags, ctx); if (err) return err; if (flags->all == ALL_ALL) @@ -3586,8 +3584,6 @@ const char *call_play_media_ng(ng_command_ctx_t *ctx) { if (err) return err; - flags.opmode = OP_PLAY_MEDIA; - for (__auto_type l = monologues.head; l; l = l->next) { struct call_monologue *monologue = l->data; @@ -3783,9 +3779,9 @@ const char *call_publish_ng(ng_command_ctx_t *ctx, int ret; const ng_parser_t *parser = ctx->parser_ctx.parser; - call_ng_process_flags(&flags, ctx, OP_PUBLISH); + call_ng_process_flags(&flags, ctx); - if ((ret = call_ng_basic_checks(&flags, OP_PUBLISH)) > 0) + if ((ret = call_ng_basic_checks(&flags)) > 0) return _ng_basic_errors[ret]; call = call_get_or_create(&flags.call_id, false); @@ -3838,7 +3834,7 @@ const char *call_subscribe_request_ng(ng_command_ctx_t *ctx) { const ng_parser_t *parser = ctx->parser_ctx.parser; /* get source monologue */ - err = media_block_match_mult(&call, &srms, &flags, ctx, OP_SUBSCRIBE_REQ); + err = media_block_match_mult(&call, &srms, &flags, ctx); if (err) return err; @@ -3944,11 +3940,11 @@ const char *call_subscribe_answer_ng(ng_command_ctx_t *ctx) { g_auto(sdp_streams_q) streams = TYPED_GQUEUE_INIT; g_autoptr(call_t) call = NULL; - call_ng_process_flags(&flags, ctx, OP_SUBSCRIBE_ANS); + call_ng_process_flags(&flags, ctx); if (!flags.call_id.s) return "No call-id in message"; - call = call_get_opmode(&flags.call_id, OP_SUBSCRIBE_ANS); + call = call_get_opmode(&flags.call_id, flags.opmode); if (!call) return "Unknown call-ID"; @@ -3985,11 +3981,11 @@ const char *call_unsubscribe_ng(ng_command_ctx_t *ctx) { g_auto(sdp_ng_flags) flags; g_autoptr(call_t) call = NULL; - call_ng_process_flags(&flags, ctx, OP_SUBSCRIBE_ANS); + call_ng_process_flags(&flags, ctx); if (!flags.call_id.s) return "No call-id in message"; - call = call_get_opmode(&flags.call_id, OP_SUBSCRIBE_ANS); + call = call_get_opmode(&flags.call_id, flags.opmode); if (!call) return "Unknown call-ID"; diff --git a/daemon/control_ng.c b/daemon/control_ng.c index bc2f13ef7..aced8a43d 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -671,9 +671,8 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons GString *log_str; struct timeval cmd_start, cmd_stop, cmd_process_time = {0}; struct control_ng_stats* cur = get_control_ng_stats(&sin->address); - enum ng_opmode command = -1; - ng_command_ctx_t command_ctx = {0}; + ng_command_ctx_t command_ctx = {.opmode = -1}; const ng_parser_t *parser = &ng_parser_native; command_ctx.ngbuf = *ngbufp = ng_buffer_new(ref); @@ -744,109 +743,109 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons switch (__csh_lookup(&cmd)) { case CSH_LOOKUP("ping"): resultstr = "pong"; - command = OP_PING; + command_ctx.opmode = OP_PING; break; case CSH_LOOKUP("offer"): + command_ctx.opmode = OP_OFFER; errstr = call_offer_ng(&command_ctx, addr, sin); - command = OP_OFFER; break; case CSH_LOOKUP("answer"): + command_ctx.opmode = OP_ANSWER; errstr = call_answer_ng(&command_ctx); - command = OP_ANSWER; break; case CSH_LOOKUP("delete"): + command_ctx.opmode = OP_DELETE; errstr = call_delete_ng(&command_ctx); - command = OP_DELETE; break; case CSH_LOOKUP("query"): + command_ctx.opmode = OP_QUERY; errstr = call_query_ng(&command_ctx); - command = OP_QUERY; break; case CSH_LOOKUP("list"): + command_ctx.opmode = OP_LIST; errstr = call_list_ng(&command_ctx); - command = OP_LIST; break; case CSH_LOOKUP("start recording"): + command_ctx.opmode = OP_START_RECORDING; errstr = call_start_recording_ng(&command_ctx); - command = OP_START_RECORDING; break; case CSH_LOOKUP("stop recording"): + command_ctx.opmode = OP_STOP_RECORDING; errstr = call_stop_recording_ng(&command_ctx); - command = OP_STOP_RECORDING; break; case CSH_LOOKUP("pause recording"): + command_ctx.opmode = OP_PAUSE_RECORDING; errstr = call_pause_recording_ng(&command_ctx); - command = OP_PAUSE_RECORDING; break; case CSH_LOOKUP("start forwarding"): + command_ctx.opmode = OP_START_FORWARDING; errstr = call_start_forwarding_ng(&command_ctx); - command = OP_START_FORWARDING; break; case CSH_LOOKUP("stop forwarding"): + command_ctx.opmode = OP_STOP_FORWARDING; errstr = call_stop_forwarding_ng(&command_ctx); - command = OP_STOP_FORWARDING; break; case CSH_LOOKUP("block DTMF"): + command_ctx.opmode = OP_BLOCK_DTMF; errstr = call_block_dtmf_ng(&command_ctx); - command = OP_BLOCK_DTMF; break; case CSH_LOOKUP("unblock DTMF"): + command_ctx.opmode = OP_UNBLOCK_DTMF; errstr = call_unblock_dtmf_ng(&command_ctx); - command = OP_UNBLOCK_DTMF; break; case CSH_LOOKUP("block media"): + command_ctx.opmode = OP_BLOCK_MEDIA; errstr = call_block_media_ng(&command_ctx); - command = OP_BLOCK_MEDIA; break; case CSH_LOOKUP("unblock media"): + command_ctx.opmode = OP_UNBLOCK_MEDIA; errstr = call_unblock_media_ng(&command_ctx); - command = OP_UNBLOCK_MEDIA; break; case CSH_LOOKUP("silence media"): + command_ctx.opmode = OP_SILENCE_MEDIA; errstr = call_silence_media_ng(&command_ctx); - command = OP_SILENCE_MEDIA; break; case CSH_LOOKUP("unsilence media"): + command_ctx.opmode = OP_UNSILENCE_MEDIA; errstr = call_unsilence_media_ng(&command_ctx); - command = OP_UNSILENCE_MEDIA; break; case CSH_LOOKUP("play media"): + command_ctx.opmode = OP_PLAY_MEDIA; errstr = call_play_media_ng(&command_ctx); - command = OP_PLAY_MEDIA; break; case CSH_LOOKUP("stop media"): + command_ctx.opmode = OP_STOP_MEDIA; errstr = call_stop_media_ng(&command_ctx); - command = OP_STOP_MEDIA; break; case CSH_LOOKUP("play DTMF"): + command_ctx.opmode = OP_PLAY_DTMF; errstr = call_play_dtmf_ng(&command_ctx); - command = OP_PLAY_DTMF; break; case CSH_LOOKUP("statistics"): + command_ctx.opmode = OP_STATISTICS; errstr = statistics_ng(&command_ctx); - command = OP_STATISTICS; break; case CSH_LOOKUP("publish"): + command_ctx.opmode = OP_PUBLISH; errstr = call_publish_ng(&command_ctx, addr, sin); - command = OP_PUBLISH; break; case CSH_LOOKUP("subscribe request"): + command_ctx.opmode = OP_SUBSCRIBE_REQ; errstr = call_subscribe_request_ng(&command_ctx); - command = OP_SUBSCRIBE_REQ; break; case CSH_LOOKUP("subscribe answer"): + command_ctx.opmode = OP_SUBSCRIBE_ANS; errstr = call_subscribe_answer_ng(&command_ctx); - command = OP_SUBSCRIBE_ANS; break; case CSH_LOOKUP("unsubscribe"): + command_ctx.opmode = OP_UNSUBSCRIBE; errstr = call_unsubscribe_ng(&command_ctx); - command = OP_UNSUBSCRIBE; break; default: errstr = "Unrecognized command"; } - CH(homer_fill_values, hctx, &callid, command); + CH(homer_fill_values, hctx, &callid, command_ctx.opmode); CH(homer_trace_msg_in, hctx, data); // stop command timer @@ -854,11 +853,11 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons //print command duration timeval_from_us(&cmd_process_time, timeval_diff(&cmd_stop, &cmd_start)); - if (command >= 0 && command < OP_COUNT) { - mutex_lock(&cur->cmd[command].lock); - cur->cmd[command].count++; - timeval_add(&cur->cmd[command].time, &cur->cmd[command].time, &cmd_process_time); - mutex_unlock(&cur->cmd[command].lock); + if (command_ctx.opmode >= 0 && command_ctx.opmode < OP_COUNT) { + mutex_lock(&cur->cmd[command_ctx.opmode].lock); + cur->cmd[command_ctx.opmode].count++; + timeval_add(&cur->cmd[command_ctx.opmode].time, &cur->cmd[command_ctx.opmode].time, &cmd_process_time); + mutex_unlock(&cur->cmd[command_ctx.opmode].lock); } if (errstr) @@ -867,8 +866,8 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons parser->dict_add_string(command_ctx.resp, "result", resultstr); // update interval statistics - RTPE_STATS_INC(ng_commands[command]); - RTPE_STATS_SAMPLE(ng_command_times[command], timeval_us(&cmd_process_time)); + RTPE_STATS_INC(ng_commands[command_ctx.opmode]); + RTPE_STATS_SAMPLE(ng_command_times[command_ctx.opmode], timeval_us(&cmd_process_time)); goto send_resp;