From d31d49370f09479c810107d42327eb419da34239 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 26 Sep 2024 10:07:43 +0200 Subject: [PATCH] MT#61140 call_delete_ng: add normal parsing Add `call_ng_process_flags()` based parsing as for other opmodes, like offer and answer. This keeps the backwards compatibility with the older "flags" parsing approach on the module side, as well as adds the possibility to parse rtpp-flags on the daemon side. As an advantage, there is no need to use specific local parsing for things like to/from tags, call-id, delete-delay etc. Additionally: - this commit introduces flags-flags parsing for the "fatal" flag. However, as before is only taken into account by the `call_delete_ng()` processing, so no functional change. - this commit introduces main-flags parsing for the "delete-delay" flag, which is also only taken into account by the `call_delete_ng()` processing, so no functional change. - this commit adds To-tag options flag prasing into the `call_ng_flags_flags()` function, and is used by `call_delete_ng()` specificially, for cases when more specific identification of monologues to be deleted is used. Change-Id: Ia992e5375a2f86318d9ad193a7857dd589038eed --- daemon/call_interfaces.c | 47 ++++++++++++++++++++++----------------- include/call_interfaces.h | 6 ++++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 64c28bf7f..f596b8368 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1028,6 +1028,9 @@ void call_ng_flags_flags(str *s, unsigned int idx, helper_arg arg) { case CSH_LOOKUP("exclude-recording"): out->exclude_recording = 1; break; + case CSH_LOOKUP("fatal"): + out->fatal = 1; + break; case CSH_LOOKUP("fragment"): out->fragment = 1; break; @@ -1155,6 +1158,11 @@ void call_ng_flags_flags(str *s, unsigned int idx, helper_arg arg) { case CSH_LOOKUP("symmetric-codecs"): ilog(LOG_INFO, "Ignoring obsolete flag `symmetric-codecs`"); break; + case CSH_LOOKUP("to-tag"): + case CSH_LOOKUP("to_tag"): + /* including the “To” tag in the “delete” message allows to be more selective + * about monologues within a dialog to be torn down. */ + out->to_tag_flag = 1; case CSH_LOOKUP("trickle-ICE"): case CSH_LOOKUP("trickle-ice"): out->trickle_ice = 1; @@ -1271,6 +1279,7 @@ void call_ng_flags_init(sdp_ng_flags *out, enum call_opmode opmode) { out->el_option = rtpe_config.endpoint_learning; out->tos = 256; out->delay_buffer = -1; + out->delete_delay = -1; out->volume = 9999; out->digit = -1; out->frequencies = g_array_new(false, false, sizeof(int)); @@ -1500,6 +1509,11 @@ void call_ng_main_flags(const ng_parser_t *parser, str *key, parser_arg value, h case CSH_LOOKUP("db-id"): out->db_id = parser->get_int_str(value, out->db_id); break; + case CSH_LOOKUP("delete delay"): + case CSH_LOOKUP("delete-delay"): + case CSH_LOOKUP("delete_delay"): + out->delete_delay = parser->get_int_str(value, out->delete_delay); + break; case CSH_LOOKUP("direction"): call_ng_direction_flag(parser, out, value); break; @@ -2298,41 +2312,34 @@ static void call_delete_flags(str *key, unsigned int idx, helper_arg arg) { fatal_discard[1] = true; } const char *call_delete_ng(ng_command_ctx_t *ctx) { - str fromtag, totag, viabranch, callid; - parser_arg flags; - bool fatal_discard[2] = {0}; - int delete_delay; - parser_arg input = ctx->req; + g_auto(sdp_ng_flags) rtpp_flags; parser_arg output = ctx->resp; const ng_parser_t *parser = ctx->parser_ctx.parser; - if (!parser->dict_get_str(input, "call-id", &callid)) - return "No call-id in message"; - parser->dict_get_str(input, "from-tag", &fromtag); - parser->dict_get_str(input, "to-tag", &totag); - parser->dict_get_str(input, "via-branch", &viabranch); + call_ng_process_flags(&rtpp_flags, ctx, OP_DELETE); - flags = parser->dict_get_expect(input, "flags", BENCODE_LIST); - if (flags.gen) - parser->list_iter(parser, flags, call_delete_flags, NULL, fatal_discard); - delete_delay = parser->dict_get_int_str(input, "delete-delay", -1); - if (delete_delay == -1) - delete_delay = parser->dict_get_int_str(input, "delete delay", -1); + if (!rtpp_flags.call_id.len) + return "No call-id in message"; - call_t *c = call_get(&callid); + call_t *c = call_get(&rtpp_flags.call_id); if (!c) goto err; - if (fatal_discard[1]) + if (rtpp_flags.discard_recording) recording_discard(c); - if (call_delete_branch(c, &viabranch, &fromtag, &totag, ctx, delete_delay)) + if (call_delete_branch(c, &rtpp_flags.via_branch, + &rtpp_flags.from_tag, + (rtpp_flags.to_tag_flag ? &rtpp_flags.to_tag : NULL), + ctx, rtpp_flags.delete_delay)) + { goto err; + } return NULL; err: - if (fatal_discard[0]) + if (rtpp_flags.fatal) return "Call-ID not found or tags didn't match"; parser->dict_add_string(output, "warning", "Call-ID not found or tags didn't match"); return NULL; diff --git a/include/call_interfaces.h b/include/call_interfaces.h index ac17916d5..e04c36781 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -123,6 +123,7 @@ struct sdp_ng_flags { int media_rec_slot_answer; int media_rec_slots; int repeat_times; + int delete_delay; str file; str blob; long long db_id; @@ -229,7 +230,10 @@ struct sdp_ng_flags { disable_jb:1, nat_wait:1, pierce_nat:1, - directional:1; + directional:1, + fatal:1, + /* to_tag is used especially by delete handling */ + to_tag_flag:1; };