From 3d41b85239869d691467915ace084239cf388ade Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 3 Sep 2020 12:23:09 +0200 Subject: [PATCH] TT#71906 sca: pai_avp parameter Use the avp value when creating P-Asserted-Identity instead of values from Headers in order to allow to insert E164 format value. If no value, skip creation of header. Change-Id: I81282da27325d02987b3dc1079605de0d6b340a8 --- debian/patches/series | 1 + .../sipwise/sca-add-pai_avp-parameter.patch | 161 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 debian/patches/sipwise/sca-add-pai_avp-parameter.patch diff --git a/debian/patches/series b/debian/patches/series index 907e19e10..9ab672b72 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -30,6 +30,7 @@ sipwise/sca-fix-pickup-when-upstream-flow.patch sipwise/sca-fix-on-hold-detection-when-upstream-flow.patch sipwise/sca-debug.patch sipwise/sca-fix-notify-after-bye.patch +sipwise/sca-add-pai_avp-parameter.patch ## backports from upstream (5.4) upstream/0001-Revert-tls-proper-ifdef-on-libssl-version-for-tls_in.patch upstream/0002-Revert-tls-added-define-condition-on-version-functio.patch diff --git a/debian/patches/sipwise/sca-add-pai_avp-parameter.patch b/debian/patches/sipwise/sca-add-pai_avp-parameter.patch new file mode 100644 index 000000000..d93ec797d --- /dev/null +++ b/debian/patches/sipwise/sca-add-pai_avp-parameter.patch @@ -0,0 +1,161 @@ +From: Victor Seva +Date: Thu, 3 Sep 2020 12:19:21 +0200 +Subject: sca: add pai_avp parameter + +Use the avp value when creating P-Asserted-Identity instead of +values from Headers. If no value, skip header creation. +--- + src/modules/sca/sca.c | 27 +++++++++++++++++++++------ + src/modules/sca/sca.h | 2 ++ + src/modules/sca/sca_call_info.c | 26 +++++++++++++++++++------- + src/modules/sca/sca_util.h | 2 ++ + 4 files changed, 44 insertions(+), 13 deletions(-) + +diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c +index c0042b9..bdcc2ab 100644 +--- a/src/modules/sca/sca.c ++++ b/src/modules/sca/sca.c +@@ -70,6 +70,8 @@ unsigned short from_uri_avp_type; + int_str from_uri_avp; + unsigned short to_uri_avp_type; + int_str to_uri_avp; ++unsigned short pai_avp_type; ++int_str pai_avp; + + /* + * PROTOTYPES +@@ -159,6 +161,7 @@ int onhold_bflag = -1; + str server_address = STR_NULL; + str from_uri_avp_param = STR_NULL; + str to_uri_avp_param = STR_NULL; ++str pai_avp_param = STR_NULL; + + static param_export_t params[] = { + {"outbound_proxy", PARAM_STR, &outbound_proxy}, +@@ -174,6 +177,7 @@ static param_export_t params[] = { + {"server_address", PARAM_STR, &server_address}, + {"from_uri_avp", PARAM_STR, &from_uri_avp_param}, + {"to_uri_avp", PARAM_STR, &to_uri_avp_param}, ++ {"pai_avp", PARAM_STR, &pai_avp_param}, + {NULL, 0, NULL}, + }; + +@@ -349,7 +353,7 @@ static int sca_child_init(int rank) + return (0); + } + +-static int sca_process_avps( ++static int sca_process_avp( + str *avp_param, int_str *avp, unsigned short *avp_type) + { + pv_spec_t *avp_spec; +@@ -375,6 +379,21 @@ static int sca_process_avps( + return 0; + } + ++static int sca_process_avps() ++{ ++ if(sca_process_avp(&from_uri_avp_param, &from_uri_avp, &from_uri_avp_type) ++ < 0) { ++ return -1; ++ } ++ if(sca_process_avp(&to_uri_avp_param, &to_uri_avp, &to_uri_avp_type) < 0) { ++ return -1; ++ } ++ if(sca_process_avp(&pai_avp_param, &pai_avp, &pai_avp_type) < 0) { ++ return -1; ++ } ++ return 0; ++} ++ + static int sca_mod_init(void) + { + sca = (sca_mod *)shm_malloc(sizeof(sca_mod)); +@@ -441,11 +460,7 @@ static int sca_mod_init(void) + // timer process forks in sca_child_init, above. + register_dummy_timers(1); + +- if(sca_process_avps(&from_uri_avp_param, &from_uri_avp, &from_uri_avp_type) +- < 0 +- || sca_process_avps( +- &to_uri_avp_param, &to_uri_avp, &to_uri_avp_type) +- < 0) { ++ if(sca_process_avps() < 0) { + goto error; + } + +diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h +index 3d08921..44b354e 100644 +--- a/src/modules/sca/sca.h ++++ b/src/modules/sca/sca.h +@@ -63,5 +63,7 @@ extern unsigned short from_uri_avp_type; + extern int_str from_uri_avp; + extern unsigned short to_uri_avp_type; + extern int_str to_uri_avp; ++extern unsigned short pai_avp_type; ++extern int_str pai_avp; + + #endif // SCA_H +diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c +index d01ab86..1517a35 100644 +--- a/src/modules/sca/sca_call_info.c ++++ b/src/modules/sca/sca_call_info.c +@@ -1138,20 +1138,32 @@ static int sca_call_info_insert_asserted_identity( + str aor = STR_NULL; + str hdr = STR_NULL; + int len; ++ int aor_avp = 0; + int rc = -1; + ++ if(sca_get_avp_value(pai_avp_type, pai_avp, &aor) < 0) { ++ if(pai_avp.s.len > 0) { ++ LM_DBG("$avp(%.*s) has no value, skip PAI\n", STR_FMT(&pai_avp.s)); ++ rc = 1; ++ goto done; ++ } ++ if(sca_create_canonical_aor_for_ua(msg, &aor, ua_type) < 0) { ++ LM_ERR("sca_call_info_insert_asserted_identity: failed to create " ++ "canonical AoR\n"); ++ goto done; ++ } ++ } else { ++ aor_avp = 1; ++ LM_DBG("using $avp(%.*s)[%.*s] as PAI\n", STR_FMT(&pai_avp.s), ++ STR_FMT(&aor)); ++ } ++ + anchor = anchor_lump(msg, msg->eoh - msg->buf, 0, HDR_OTHER_T); + if(anchor == NULL) { + LM_ERR("Failed to anchor lump\n"); + goto done; + } + +- if(sca_create_canonical_aor_for_ua(msg, &aor, ua_type) < 0) { +- LM_ERR("sca_call_info_insert_asserted_identity: failed to create " +- "canonical AoR\n"); +- goto done; +- } +- + #define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX "P-Asserted-Identity: " + #define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN strlen("P-Asserted-Identity: ") + +@@ -1197,7 +1209,7 @@ static int sca_call_info_insert_asserted_identity( + rc = 1; + + done: +- if(aor.s != NULL) { ++ if(aor_avp == 0 && aor.s != NULL) { + pkg_free(aor.s); + } + if(rc < 0 && hdr.s != NULL) { +diff --git a/src/modules/sca/sca_util.h b/src/modules/sca/sca_util.h +index 563dedc..823e51d 100644 +--- a/src/modules/sca/sca_util.h ++++ b/src/modules/sca/sca_util.h +@@ -76,4 +76,6 @@ int sca_create_canonical_aor(sip_msg_t *, str *); + // convenient call hold detection + int sca_call_is_held(sip_msg_t *); + ++int sca_get_avp_value(unsigned short, int_str, str *); ++ + #endif // SCA_UTIL_H