<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7512">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
Kevin Harwell: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip/res_pjsip: Add CHANNEL(pjsip,request_uri)<br><br>This patch does three things associated with the initial incoming INVITE<br>request URI.<br><br>1) Add access to the full initial incoming INVITE request URI.<br><br>2) We were not setting DNID on incoming PJSIP channels. The DNID is the<br>user portion of the initial incoming INVITE Request-URI. The value is<br>accessed by reading CALLERID(dnid).<br><br>3) Fix CHANNEL(pjsip,target_uri) documentation.<br><br>* The initial incoming INVITE request URI is now available using<br>CHANNEL(pjsip,request_uri).<br><br>* Set the DNID on PJSIP channel creation so CALLERID(dnid) can return the<br>initial incoming INVITE request URI user portion.<br><br>* CHANNEL(pjsip,target_uri) now correctly documents that the target URI is<br>the contact URI.<br><br>* Refactored print_escaped_uri() out of channel_read_pjsip() to handle<br>pjsip_uri_print() error condition when the buffer is too small.<br><br>ASTERISK-27478<br><br>Change-Id: I512e60d1f162395c946451becb37af3333337b33<br>---<br>M channels/chan_pjsip.c<br>M channels/pjsip/dialplan_functions.c<br>M include/asterisk/res_pjsip_session.h<br>M res/res_pjsip_session.c<br>4 files changed, 52 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c<br>index e4e8fa5..69bcc18 100644<br>--- a/channels/chan_pjsip.c<br>+++ b/channels/chan_pjsip.c<br>@@ -605,6 +605,11 @@<br> ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);<br> ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);<br> <br>+ if (!ast_strlen_zero(exten)) {<br>+ /* Set provided DNID on the new channel. */<br>+ ast_channel_dialed(chan)->number.str = ast_strdup(exten);<br>+ }<br>+<br> ast_channel_priority_set(chan, 1);<br> <br> ast_channel_callgroup_set(chan, session->endpoint->pickup.callgroup);<br>diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c<br>index 861edf7..aa376f8 100644<br>--- a/channels/pjsip/dialplan_functions.c<br>+++ b/channels/pjsip/dialplan_functions.c<br>@@ -388,7 +388,7 @@<br> </enumlist><br> </enum><br> <enum name="target_uri"><br>- <para>The request URI of the <literal>INVITE</literal> request associated with the creation of this channel.</para><br>+ <para>The contact URI where requests are sent.</para><br> </enum><br> <enum name="local_uri"><br> <para>The local URI.</para><br>@@ -401,6 +401,10 @@<br> </enum><br> <enum name="remote_tag"><br> <para>Tag in To header</para><br>+ </enum><br>+ <enum name="request_uri"><br>+ <para>The request URI of the incoming <literal>INVITE</literal><br>+ associated with the creation of this channel.</para><br> </enum><br> <enum name="t38state"><br> <para>The current state of any T.38 fax on this channel.</para><br>@@ -656,6 +660,27 @@<br> return 0;<br> }<br> <br>+static int print_escaped_uri(struct ast_channel *chan, const char *type,<br>+ pjsip_uri_context_e context, const void *uri, char *buf, size_t size)<br>+{<br>+ int res;<br>+ char *buf_copy;<br>+<br>+ res = pjsip_uri_print(context, uri, buf, size);<br>+ if (res < 0) {<br>+ ast_log(LOG_ERROR, "Channel %s: Unescaped %s too long for %d byte buffer\n",<br>+ ast_channel_name(chan), type, (int) size);<br>+<br>+ /* Empty buffer that likely is not terminated. */<br>+ buf[0] = '\0';<br>+ return -1;<br>+ }<br>+<br>+ buf_copy = ast_strdupa(buf);<br>+ ast_escape_quoted(buf_copy, buf, size);<br>+ return 0;<br>+}<br>+<br> /*!<br> * \internal \brief Handle reading signalling information<br> */<br>@@ -664,6 +689,7 @@<br> struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);<br> char *buf_copy;<br> pjsip_dialog *dlg;<br>+ int res = 0;<br> <br> if (!channel) {<br> ast_log(AST_LOG_WARNING, "Channel %s has no pvt!\n", ast_channel_name(chan));<br>@@ -689,25 +715,27 @@<br> return -1;<br> #endif<br> } else if (!strcmp(type, "target_uri")) {<br>- pjsip_uri_print(PJSIP_URI_IN_REQ_URI, dlg->target, buf, buflen);<br>- buf_copy = ast_strdupa(buf);<br>- ast_escape_quoted(buf_copy, buf, buflen);<br>+ res = print_escaped_uri(chan, type, PJSIP_URI_IN_REQ_URI, dlg->target, buf,<br>+ buflen);<br> } else if (!strcmp(type, "local_uri")) {<br>- pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dlg->local.info->uri, buf, buflen);<br>- buf_copy = ast_strdupa(buf);<br>- ast_escape_quoted(buf_copy, buf, buflen);<br>+ res = print_escaped_uri(chan, type, PJSIP_URI_IN_FROMTO_HDR, dlg->local.info->uri,<br>+ buf, buflen);<br> } else if (!strcmp(type, "local_tag")) {<br> ast_copy_pj_str(buf, &dlg->local.info->tag, buflen);<br> buf_copy = ast_strdupa(buf);<br> ast_escape_quoted(buf_copy, buf, buflen);<br> } else if (!strcmp(type, "remote_uri")) {<br>- pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dlg->remote.info->uri, buf, buflen);<br>- buf_copy = ast_strdupa(buf);<br>- ast_escape_quoted(buf_copy, buf, buflen);<br>+ res = print_escaped_uri(chan, type, PJSIP_URI_IN_FROMTO_HDR,<br>+ dlg->remote.info->uri, buf, buflen);<br> } else if (!strcmp(type, "remote_tag")) {<br> ast_copy_pj_str(buf, &dlg->remote.info->tag, buflen);<br> buf_copy = ast_strdupa(buf);<br> ast_escape_quoted(buf_copy, buf, buflen);<br>+ } else if (!strcmp(type, "request_uri")) {<br>+ if (channel->session->request_uri) {<br>+ res = print_escaped_uri(chan, type, PJSIP_URI_IN_REQ_URI,<br>+ channel->session->request_uri, buf, buflen);<br>+ }<br> } else if (!strcmp(type, "t38state")) {<br> ast_copy_string(buf, t38state_to_string[channel->session->t38state], buflen);<br> } else if (!strcmp(type, "local_addr")) {<br>@@ -743,7 +771,7 @@<br> return -1;<br> }<br> <br>- return 0;<br>+ return res;<br> }<br> <br> /*! \brief Struct used to push function arguments to task processor */<br>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h<br>index a0fc965..732243f 100644<br>--- a/include/asterisk/res_pjsip_session.h<br>+++ b/include/asterisk/res_pjsip_session.h<br>@@ -211,6 +211,8 @@<br> unsigned int ended_while_deferred:1;<br> /*! DTMF mode to use with this session, from endpoint but can change */<br> enum ast_sip_dtmf_mode dtmf;<br>+ /*! Initial incoming INVITE Request-URI. NULL otherwise. */<br>+ pjsip_uri *request_uri;<br> };<br> <br> typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);<br>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index 781d3e4..55b9120 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -2818,6 +2818,12 @@<br> ast_copy_pj_str(domain, &sip_ruri->host, size);<br> pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);<br> <br>+ /*<br>+ * Save off the INVITE Request-URI in case it is<br>+ * needed: CHANNEL(pjsip,request_uri)<br>+ */<br>+ session->request_uri = pjsip_uri_clone(session->inv_session->pool, ruri);<br>+<br> return SIP_GET_DEST_EXTEN_FOUND;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7512">change 7512</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7512"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I512e60d1f162395c946451becb37af3333337b33 </div>
<div style="display:none"> Gerrit-Change-Number: 7512 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>