From a3f2781acd1e3072d44854713cf58cd8376f0516 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 22 Oct 2021 12:34:13 -0400 Subject: [PATCH] TT#147451 refactor media_block_match Change-Id: Id4094e59100d05f3e6afa5f923aa55e1c8ddba4d --- daemon/call_interfaces.c | 61 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 83e7de1f9..1e7d14088 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2040,31 +2040,11 @@ const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output return NULL; } -static const char *media_block_match(struct call **call, struct call_monologue **monologue, - struct sdp_ng_flags *flags, bencode_item_t *input, enum call_opmode opmode) +static const char *media_block_match1(struct call *call, struct call_monologue **monologue, + struct sdp_ng_flags *flags) { - struct sdp_ng_flags flags_store; - - if (!flags) - flags = &flags_store; - - *call = NULL; - *monologue = NULL; - - call_ng_process_flags(flags, input, opmode); - - if (!flags->call_id.s) - return "No call-id in message"; - *call = call_get_opmode(&flags->call_id, opmode); - if (!*call) - return "Unknown call-ID"; - - // directional? - if (flags->all) // explicitly non-directional, so skip the rest - return NULL; - if (flags->label.s) { - *monologue = g_hash_table_lookup((*call)->labels, &flags->label); + *monologue = g_hash_table_lookup(call->labels, &flags->label); if (!*monologue) return "No monologue matching the given label"; } @@ -2073,7 +2053,7 @@ static const char *media_block_match(struct call **call, struct call_monologue * if (sockaddr_parse_any_str(&addr, &flags->address)) return "Failed to parse network address"; // walk our structures to find a matching stream - for (GList *l = (*call)->monologues.head; l; l = l->next) { + for (GList *l = call->monologues.head; l; l = l->next) { *monologue = l->data; for (GList *k = (*monologue)->medias.head; k; k = k->next) { struct call_media *media = k->data; @@ -2092,11 +2072,40 @@ found: ; } else if (flags->from_tag.s) { - *monologue = call_get_monologue(*call, &flags->from_tag); + *monologue = call_get_monologue(call, &flags->from_tag); if (!*monologue) return "From-tag given, but no such tag exists"; - __monologue_unkernelize(*monologue); } + if (*monologue) + __monologue_unkernelize(*monologue); + return NULL; +} +static const char *media_block_match(struct call **call, struct call_monologue **monologue, + struct sdp_ng_flags *flags, bencode_item_t *input, enum call_opmode opmode) +{ + struct sdp_ng_flags flags_store; + + if (!flags) + flags = &flags_store; + + *call = NULL; + *monologue = NULL; + + call_ng_process_flags(flags, input, opmode); + + if (!flags->call_id.s) + return "No call-id in message"; + *call = call_get_opmode(&flags->call_id, opmode); + if (!*call) + return "Unknown call-ID"; + + // directional? + if (flags->all) // explicitly non-directional, so skip the rest + return NULL; + + const char *err = media_block_match1(*call, monologue, flags); + if (err) + return err; // for generic ops, handle set-label here if given if (opmode == OP_OTHER && flags->set_label.len && *monologue) {