From b9d24897a7f3e74a43f2de07a8a88391c54849fc Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 5 Oct 2023 10:02:43 +0200 Subject: [PATCH] MT#58441 Add attr subst support to append functions Add media attributes substitution support to the following functions: - `append_attr_to_gstring()` - `append_attr_int_to_gstring()` First functions check, if the attribute has to be removed (by the manipulations profile), if not then it checks out whether we have to substitute it. If neither of manipulations have to be applied, then the given attribute gets attached to the chopper. This gives support of substitution for such media level attributes like: - `mid` - `label` - `ptime` - `ice-ufrag` - `ice-pwd` - `ice-options` etc. Change-Id: I35a1ad71f1031d986a79446522da2a557c09ddcc --- daemon/sdp.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index f0042d395..21c2064d2 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -2848,25 +2848,29 @@ static void append_attr_to_gstring(GString *s, char * name, const str * value, if (name[0] == 'a' && name[1] == '=') name += 2; - str attr = STR_INIT(name); struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media_type); - /* take into account SDP arbitrary manipulations */ - if (sdp_manipulate_remove(sdp_manipulations, &attr) || - sdp_manipulations_subst(sdp_manipulations, &attr)) + str attr = STR_INIT(name); + str * attr_subst = sdp_manipulations_subst(sdp_manipulations, &attr); + + /* first check if the originally present attribute is to be removed */ + if (sdp_manipulate_remove(sdp_manipulations, &attr)) { - ilog(LOG_DEBUG, "Cannot insert: '%s' because prevented by SDP manipulations (remove or subst)", name); + ilog(LOG_DEBUG, "Cannot insert: '%s' because prevented by SDP manipulations (remove)", name); return; } + /* then, if there remains something to be substituted, do that */ + if (attr_subst) + attr = *attr_subst; + /* attr name */ - g_string_append(s, "a="); - g_string_append(s, attr.s); + g_string_append_printf(s, "a=" STR_FORMAT, STR_FMT(&attr)); - /* attr value */ - if (value) { + /* attr value, don't add if substituion presented */ + if (value && !attr_subst) g_string_append_printf(s, STR_FORMAT, STR_FMT(value)); - } + g_string_append(s, "\r\n"); } @@ -2878,24 +2882,29 @@ static void append_attr_int_to_gstring(GString *s, char * name, const int * valu if (name[0] == 'a' && name[1] == '=') name += 2; - str attr = STR_INIT(name); struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media_type); - /* take into account SDP arbitrary manipulations */ - if (sdp_manipulate_remove(sdp_manipulations, &attr) || - sdp_manipulations_subst(sdp_manipulations, &attr)) + str attr = STR_INIT(name); + str * attr_subst = sdp_manipulations_subst(sdp_manipulations, &attr); + + /* first check if the originally present attribute is to be removed */ + if (sdp_manipulate_remove(sdp_manipulations, &attr)) { - ilog(LOG_DEBUG, "Cannot insert: '%s' because prevented by SDP manipulations (remove or subst)", name); + ilog(LOG_DEBUG, "Cannot insert: '%s' because prevented by SDP manipulations (remove)", name); return; } + + /* then, if there remains something to be substituted, do that */ + if (attr_subst) + attr = *attr_subst; + /* attr name */ - g_string_append(s, "a="); - g_string_append(s, attr.s); + g_string_append_printf(s, "a=" STR_FORMAT, STR_FMT(&attr)); - /* attr value */ - if (value) { + /* attr value, don't add if substituion presented */ + if (value && !attr_subst) g_string_append_printf(s, "%i", *value); - } + g_string_append(s, "\r\n"); }