From 15d086773781f916b68590d4986a7c6b2106d3f1 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 18 Mar 2024 16:54:05 +0100 Subject: [PATCH] MT#58535 rtpp_flags: add directional flag parsing Is added by: - explicit generic flag "directionl"; or - if the "from-tag" flag is used Introduce the `directional` flag for `sdp_ng_flags` struct. In use by: - `media_block_match1()` Additionally: add `IS_OP_DIRECTIONAL()` marco check. Change-Id: Ifd56ea2ad8277d7dec136def1c028c5e2b680ff1 --- daemon/call_interfaces.c | 14 ++++++++++---- daemon/control_ng_flags_parser.c | 6 ++++-- include/call.h | 5 +++++ include/call_interfaces.h | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index ab92968cb..a36bc36a1 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1036,6 +1036,9 @@ static void call_ng_flags_flags(sdp_ng_flags *out, str *s, helper_arg dummy) { case CSH_LOOKUP("detect-dtmf"): out->detect_dtmf = 1; break; + case CSH_LOOKUP("directional"): + out->directional = 1; + break; case CSH_LOOKUP("discard-recording"): out->discard_recording = 1; break; @@ -2841,7 +2844,7 @@ const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output static const char *media_block_match1(call_t *call, struct call_monologue **monologue, - sdp_ng_flags *flags) + sdp_ng_flags *flags, enum call_opmode opmode) { if (flags->label.s) { *monologue = t_hash_table_lookup(call->labels, &flags->label); @@ -2873,7 +2876,10 @@ static const char *media_block_match1(call_t *call, struct call_monologue **mono found: ; } - else if (flags->from_tag.s) { + /* ignore from-tag, if directional is not set */ + else if (flags->from_tag.s && + (!IS_OP_DIRECTIONAL(opmode) || + (IS_OP_DIRECTIONAL(opmode) && flags->directional))) { *monologue = call_get_monologue(call, &flags->from_tag); if (!*monologue) return "From-tag given, but no such tag exists"; @@ -2900,7 +2906,7 @@ 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); + const char *err = media_block_match1(*call, monologue, flags, opmode); if (err) return err; @@ -2945,7 +2951,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); + const char *err = media_block_match1(*call, &ml, flags, opmode); if (err) return err; if (ml) { diff --git a/daemon/control_ng_flags_parser.c b/daemon/control_ng_flags_parser.c index 58b143194..3e2a1b108 100644 --- a/daemon/control_ng_flags_parser.c +++ b/daemon/control_ng_flags_parser.c @@ -373,10 +373,12 @@ void parse_rtpp_flags(const str * rtpp_flags, bencode_item_t * root_dict, transport = 0x101; /* from-tag can be overriden, but originally has to be provided */ else if (str_eq(&key, "from-tag")) { - if (!val.s) + if (!val.s) { ilogs(control, LOG_DEBUG, "Error processing flag '"STR_FORMAT"' (will be ignored)", STR_FMT(&key)); - else + } else { bencode_dictionary_add_str(root_dict, "from-tag", &val); + out->directional = 1; /* explicitly add directional for this case */ + } } /* direction */ else if (str_eq(&key, "internal") || str_eq(&key, "external")) diff --git a/include/call.h b/include/call.h index ea5e459cc..9918a85b3 100644 --- a/include/call.h +++ b/include/call.h @@ -107,6 +107,11 @@ enum call_opmode { || (opmode == OP_STOP_RECORDING || opmode == OP_PAUSE_RECORDING) \ || (opmode == OP_OTHER)) +#define IS_OP_DIRECTIONAL(opmode) \ + ((opmode == OP_BLOCK_DTMF || opmode == OP_BLOCK_MEDIA) \ + || (opmode == OP_UNBLOCK_DTMF || opmode == OP_UNBLOCK_MEDIA) \ + || (opmode == OP_START_FORWARDING || opmode == OP_STOP_FORWARDING)) + enum call_media_counted { CMC_INCREMENT = 0, CMC_DECREMENT, diff --git a/include/call_interfaces.h b/include/call_interfaces.h index a343bab67..87ede437b 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -218,7 +218,8 @@ struct sdp_ng_flags { block_short:1, disable_jb:1, nat_wait:1, - pierce_nat:1; + pierce_nat:1, + directional:1; };