[Asterisk-code-review] chan pjsip/res pjsip: Add CHANNEL(pjsip,request uri) (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Mon Dec 11 15:20:13 CST 2017


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/7512


Change subject: chan_pjsip/res_pjsip: Add CHANNEL(pjsip,request_uri)
......................................................................

chan_pjsip/res_pjsip: Add CHANNEL(pjsip,request_uri)

This patch does three things associated with the initial incoming INVITE
request URI.

1) Add access to the full initial incoming INVITE request URI.

2) We were not setting DNID on incoming PJSIP channels.  The DNID is the
user portion of the initial incoming INVITE Request-URI.  The value is
accessed by reading CALLERID(dnid).

3) Fix CHANNEL(pjsip,target_uri) documentation.

* The initial incoming INVITE request URI is now available using
CHANNEL(pjsip,request_uri).

* Set the DNID on PJSIP channel creation so CALLERID(dnid) can return the
initial incoming INVITE request URI user portion.

* CHANNEL(pjsip,target_uri) now correctly documents that the target URI is
the contact URI.

ASTERISK-27478

Change-Id: I512e60d1f162395c946451becb37af3333337b33
---
M channels/chan_pjsip.c
M channels/pjsip/dialplan_functions.c
M include/asterisk/res_pjsip_session.h
M res/res_pjsip_session.c
4 files changed, 24 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/12/7512/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index e4e8fa5..69bcc18 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -605,6 +605,11 @@
 	ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);
 	ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);
 
+	if (!ast_strlen_zero(exten)) {
+		/* Set provided DNID on the new channel. */
+		ast_channel_dialed(chan)->number.str = ast_strdup(exten);
+	}
+
 	ast_channel_priority_set(chan, 1);
 
 	ast_channel_callgroup_set(chan, session->endpoint->pickup.callgroup);
diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index 861edf7..329c49f 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -388,7 +388,7 @@
 						</enumlist>
 					</enum>
 					<enum name="target_uri">
-						<para>The request URI of the <literal>INVITE</literal> request associated with the creation of this channel.</para>
+						<para>The contact URI where requests are sent.</para>
 					</enum>
 					<enum name="local_uri">
 						<para>The local URI.</para>
@@ -401,6 +401,10 @@
 					</enum>
 					<enum name="remote_tag">
 						<para>Tag in To header</para>
+					</enum>
+					<enum name="request_uri">
+						<para>The request URI of the incoming <literal>INVITE</literal>
+						associated with the creation of this channel.</para>
 					</enum>
 					<enum name="t38state">
 						<para>The current state of any T.38 fax on this channel.</para>
@@ -708,6 +712,12 @@
 		ast_copy_pj_str(buf, &dlg->remote.info->tag, buflen);
 		buf_copy = ast_strdupa(buf);
 		ast_escape_quoted(buf_copy, buf, buflen);
+	} else if (!strcmp(type, "request_uri")) {
+		if (channel->session->request_uri) {
+			pjsip_uri_print(PJSIP_URI_IN_REQ_URI, channel->session->request_uri, buf, buflen);
+			buf_copy = ast_strdupa(buf);
+			ast_escape_quoted(buf_copy, buf, buflen);
+		}
 	} else if (!strcmp(type, "t38state")) {
 		ast_copy_string(buf, t38state_to_string[channel->session->t38state], buflen);
 	} else if (!strcmp(type, "local_addr")) {
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index a0fc965..732243f 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -211,6 +211,8 @@
 	unsigned int ended_while_deferred:1;
 	/*! DTMF mode to use with this session, from endpoint but can change */
 	enum ast_sip_dtmf_mode dtmf;
+	/*! Initial incoming INVITE Request-URI.  NULL otherwise. */
+	pjsip_uri *request_uri;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 781d3e4..55b9120 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2818,6 +2818,12 @@
 		ast_copy_pj_str(domain, &sip_ruri->host, size);
 		pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
 
+		/*
+		 * Save off the INVITE Request-URI in case it is
+		 * needed: CHANNEL(pjsip,request_uri)
+		 */
+		session->request_uri = pjsip_uri_clone(session->inv_session->pool, ruri);
+
 		return SIP_GET_DEST_EXTEN_FOUND;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/7512
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I512e60d1f162395c946451becb37af3333337b33
Gerrit-Change-Number: 7512
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171211/7a20e060/attachment.html>


More information about the asterisk-code-review mailing list