From 9cc7c2d58146a4797fe391a7380a2aeef3f53130 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 28 Jul 2023 18:08:30 +0300 Subject: [PATCH] [mod_sofia] Multiple identity headers are partially implemented and duplicating the Identity header should not be allowed. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 3 ++- src/mod/endpoints/mod_sofia/sofia.c | 3 --- src/mod/endpoints/mod_sofia/sofia_glue.c | 3 ++- tests/unit/conf_sip/freeswitch.xml | 4 ++-- tests/unit/conf_test/freeswitch.xml | 4 ++-- tests/unit/switch_ivr_originate.c | 14 ++++++++++++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index f58bb40ac0..245ee13367 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -6350,7 +6350,8 @@ SWITCH_STANDARD_APP(sofia_stir_shaken_vs_function) stir_shaken_cert_t *cert = NULL; stir_shaken_error_t stir_error = { 0 }; switch_status_t claim_status = SWITCH_STATUS_FALSE; - const char *identity_header = switch_channel_get_variable(channel, "sip_h_identity"); + /* sip_identity channel variable is an ARRAY, we support only first identity for now */ + const char *identity_header = switch_channel_get_variable_dup(channel, "sip_identity", SWITCH_TRUE, 0); const char *attestation = NULL; int orig_is_tn = 0; switch_bool_t hangup_on_fail = switch_true(switch_channel_get_variable(channel, "sip_stir_shaken_vs_hangup_on_fail")); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c5b5bcc190..ddde795ef5 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -11500,9 +11500,6 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia } } - if (sip->sip_identity && sip->sip_identity->id_value) { - switch_channel_set_variable(channel, "sip_h_identity", sip->sip_identity->id_value); - } if (sip->sip_date && sip->sip_date->d_time > 0) { // This INVITE has a SIP Date header. // sofia-sip stores the Date header value in sip_date->d_time as seconds since January 1, 1900 0:00:00. diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index eceae218f8..86027da1c0 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1144,7 +1144,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) identity = identity_to_free = sofia_stir_shaken_as_create_identity_header(tech_pvt->session, stir_shaken_attest, cid_num, dest); } if (!identity) { - identity = switch_channel_get_variable(channel, "sip_h_identity"); + /* sip_identity channel variable is an ARRAY, we support only first identity for now */ + identity = switch_channel_get_variable_dup(channel, "sip_identity", SWITCH_TRUE, 0); } if (!date) { date = switch_channel_get_variable(channel, "sip_h_date"); diff --git a/tests/unit/conf_sip/freeswitch.xml b/tests/unit/conf_sip/freeswitch.xml index 9a992a817b..6cb5a8f9e6 100644 --- a/tests/unit/conf_sip/freeswitch.xml +++ b/tests/unit/conf_sip/freeswitch.xml @@ -145,8 +145,8 @@ - - + + diff --git a/tests/unit/conf_test/freeswitch.xml b/tests/unit/conf_test/freeswitch.xml index 9097246041..f94df9bb3e 100644 --- a/tests/unit/conf_test/freeswitch.xml +++ b/tests/unit/conf_test/freeswitch.xml @@ -145,8 +145,8 @@ - - + + diff --git a/tests/unit/switch_ivr_originate.c b/tests/unit/switch_ivr_originate.c index 5603e18f0e..8c257450b6 100644 --- a/tests/unit/switch_ivr_originate.c +++ b/tests/unit/switch_ivr_originate.c @@ -113,6 +113,20 @@ FST_CORE_BEGIN("./conf") } FST_TEARDOWN_END() + FST_SESSION_BEGIN(test_var_array) + { + const char *identity; + + switch_channel_add_variable_var_check(fst_channel, "sip_identity", "test", SWITCH_FALSE, SWITCH_STACK_PUSH); + identity = switch_channel_get_variable_dup(fst_channel, "sip_identity", SWITCH_TRUE, 0); + fst_check_string_equals(identity, "test"); + + switch_channel_add_variable_var_check(fst_channel, "sip_identity", "test2", SWITCH_FALSE, SWITCH_STACK_PUSH); + identity = switch_channel_get_variable_dup(fst_channel, "sip_identity", SWITCH_TRUE, 0); + fst_check_string_equals(identity, "test"); + } + FST_SESSION_END() + FST_TEST_BEGIN(originate_test_external_id) { switch_core_session_t *session = NULL;