From 92d172b524f4d14ecd97dd5badaf2e62f48c4066 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 19 Jul 2024 10:09:02 +0200 Subject: [PATCH] MT#60476 sdp_replace: add support of replace `origin-full` flag Make the `sdp_replace()` compliant with `sdp_create()` in terms of the replace `origin-full` flag support. Also introduce according unit tests. Change-Id: Ib950a957d5ee3820dbc8a831fe0a7ea570b4c59b --- daemon/sdp.c | 75 ++++++++++++++++++++++++++++++------------ t/auto-daemon-tests.pl | 44 +++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 21 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index 9d3f2c415f..cff9cb5c53 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -3287,35 +3287,68 @@ int sdp_replace(struct sdp_chopper *chop, sdp_sessions_q *sessions, goto error; err = "error while processing o= line"; - /* don't set `->session_sdp_orig` for non-tagged monologues (answerer side) - * answerer has to fill this structure with his own origin. - */ - if (!monologue->session_sdp_orig && monologue->tag.len) { - monologue->session_sdp_orig = sdp_orig_dup(&session->origin); - } - else if (monologue->session_sdp_orig && flags->replace_username) { - /* make sure the username field in the o= line always remains the same - * in all SDPs going to a particular endpoint */ + + if (flags->replace_origin_full && session->origin.parsed) { + char id_str[64]; + sprintf(id_str, "%llu", ((unsigned long long) rtpe_now.tv_sec << 32 | rtpe_now.tv_usec)); + + if (!monologue->session_sdp_orig && monologue->tag.len) { + monologue->session_sdp_orig = sdp_orig_dup(&session->origin); + } + /* username */ if (copy_up_to(chop, &session->origin.username)) goto error; - chopper_append_str(chop, &monologue->session_sdp_orig->username); + chopper_append_c(chop, "-"); if (skip_over(chop, &session->origin.username)) goto error; - } - /* record position of o= line and init SDP version */ - if (copy_up_to(chop, &session->origin.version_str)) - goto error; - session->origin.version_output_pos = chop->output->len; - /* TODO: should we just go to 128bit length? */ - if (monologue->session_sdp_orig && monologue->session_sdp_orig->version_num == ULLONG_MAX) - monologue->session_sdp_orig->version_num = (unsigned int)ssl_random(); - /* replace origin's network addr */ - if (session->origin.parsed && flags->replace_origin && - flags->ice_option != ICE_FORCE_RELAY) { + /* session id */ + if (copy_up_to(chop, &session->origin.session_id)) + goto error; + chopper_append_c(chop, id_str); + if (skip_over(chop, &session->origin.session_id)) + goto error; + /* session version */ + if (copy_up_to(chop, &session->origin.version_str)) + goto error; + chopper_append_c(chop, id_str); + if (skip_over(chop, &session->origin.version_str)) + goto error; + /* address type and address */ err = "failed to replace network address"; if (replace_network_address(chop, &session->origin.address, ps, flags, false)) goto error; } + else { + /* don't set `->session_sdp_orig` for non-tagged monologues (answerer side) + * answerer has to fill this structure with his own origin. + */ + if (!monologue->session_sdp_orig && monologue->tag.len) { + monologue->session_sdp_orig = sdp_orig_dup(&session->origin); + } + else if (monologue->session_sdp_orig && flags->replace_username) { + /* make sure the username field in the o= line always remains the same + * in all SDPs going to a particular endpoint */ + if (copy_up_to(chop, &session->origin.username)) + goto error; + chopper_append_str(chop, &monologue->session_sdp_orig->username); + if (skip_over(chop, &session->origin.username)) + goto error; + } + /* record position of o= line and init SDP version */ + if (copy_up_to(chop, &session->origin.version_str)) + goto error; + session->origin.version_output_pos = chop->output->len; + /* TODO: should we just go to 128bit length? */ + if (monologue->session_sdp_orig && monologue->session_sdp_orig->version_num == ULLONG_MAX) + monologue->session_sdp_orig->version_num = (unsigned int)ssl_random(); + /* replace origin's network addr */ + if (session->origin.parsed && flags->replace_origin && + flags->ice_option != ICE_FORCE_RELAY) { + err = "failed to replace network address"; + if (replace_network_address(chop, &session->origin.address, ps, flags, false)) + goto error; + } + } err = "error while processing s= line"; if (!monologue->sdp_session_name) diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl index 3442bc6cb1..c6d502b4a9 100755 --- a/t/auto-daemon-tests.pl +++ b/t/auto-daemon-tests.pl @@ -22266,6 +22266,50 @@ sub stun_succ { new_call; +offer('SDP replace everything with origin-full', { replace => ['origin-full'] }, < ['origin-full'] }, <last_out_sdp', but the version still gets increased offer('SDP version force increase', { replace => ['force-increment-sdp-ver'] }, <