[Asterisk-code-review] res_pjsip_session: Add custom parameter support. (asterisk[16])

N A asteriskteam at digium.com
Sat Jul 23 15:16:42 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18857 )


Change subject: res_pjsip_session: Add custom parameter support.
......................................................................

res_pjsip_session: Add custom parameter support.

Adds support for custom URI parameters in the From
header in PJSIP. This is often imperative when doing
SS7 over SIP, and this helps bring us closer to
feature parity with chan_sip.

ASTERISK-30150 #close

Change-Id: Ifb1bc3c512ad5f6faeaebd7817f004a2ecbd6428
---
A doc/CHANGES-staging/res_pjsip_session_params.txt
M res/res_pjsip_session.c
2 files changed, 42 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/18857/1

diff --git a/doc/CHANGES-staging/res_pjsip_session_params.txt b/doc/CHANGES-staging/res_pjsip_session_params.txt
new file mode 100644
index 0000000..06a061c
--- /dev/null
+++ b/doc/CHANGES-staging/res_pjsip_session_params.txt
@@ -0,0 +1,5 @@
+Subject: res_pjsip_session
+
+It is now possible to set custom URI parameters
+in the From header in an outgoing call through
+the SIPURIPARAMETERS variable on a channel.
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 3c55af7..b839bab 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1633,7 +1633,7 @@
 	pjsip_sip_uri *dlg_info_uri;
 	pjsip_sip_uri *dlg_contact_uri;
 	int restricted;
-	const char *pjsip_from_domain;
+	const char *pjsip_from_domain, *pjsip_uri_params;
 
 	if (!session->channel || session->saved_from_hdr) {
 		return;
@@ -1687,6 +1687,42 @@
 			ast_sip_session_get_name(session), pjsip_from_domain);
 		pj_strdup2(dlg_pool, &dlg_info_uri->host, pjsip_from_domain);
 	}
+
+	/* Set URI (inside the <>, as opposed to header (outside the <>)) parameters, if requested.
+	 * This is often necessary for SS7 trunking over SIP. Most carriers require
+	 * that added parameters be URI parameters (as opposed to header parameters).
+	 *
+	 * other_param is how to add custom URI parameters to the header
+	 * XXX: header_param is for header parameters, but doesn't seem to work at the moment.
+	 *
+	 * Especially when dealing with SS7 or TDM elements over SIP,
+	 * injecting parameters into the user and/or method parameters
+	 * is required.
+	 *
+	 * For example, if wanted to set the isup-oli parameter to the channel's ANI2 value:
+	 * e.g. pjsip_param_add(dlg_pool, &dlg_info_uri->other_param, "isup-oli", ani2);
+	 */
+
+#define pjsip_param_add(pool, list, pname, pvalue) { \
+	pjsip_param *param; \
+	param = PJ_POOL_ALLOC_T(pool, pjsip_param); \
+	pj_strdup2(pool, &param->name, pname); \
+	pj_strdup2(pool, &param->value, pvalue); \
+	pj_list_insert_before(list, param); \
+}
+
+	/* Add any URI parameters that we find on the channel */
+	pjsip_uri_params = pbx_builtin_getvar_helper(session->channel, "SIPURIPARAMETERS");
+	if (!ast_strlen_zero(pjsip_uri_params)) {
+		char *params, *param_name, *param_value;
+		params = ast_strdupa(pjsip_uri_params);
+		while ((param_value = strsep(&params, ","))) {
+			param_name = strsep(&param_value, "=");
+			ast_debug(3, "Adding URI parameter to From header: %s=%s\n", param_name, S_OR(param_value, ""));
+			pjsip_param_add(dlg_pool, &dlg_info_uri->other_param, param_name, S_OR(param_value, ""));
+		}
+	}
+#undef pjsip_param_add
 	ast_channel_unlock(session->channel);
 
 	/* We need to save off the non-anonymized From for RPID/PAI generation (for domain) */

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18857
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ifb1bc3c512ad5f6faeaebd7817f004a2ecbd6428
Gerrit-Change-Number: 18857
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220723/dc20b9bd/attachment-0001.html>


More information about the asterisk-code-review mailing list