<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16119">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Verified
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_caller_id: Add ANI2/OLI parsing<br><br>Adds parsing of ANI II digits (Originating<br>Line Information) to PJSIP, on par with<br>what currently exists in chan_sip.<br><br>ASTERISK-29472<br><br>Change-Id: Ifc938a7a7d45ce33999ebf3656a542226f6d3847<br>---<br>M channels/chan_pjsip.c<br>M include/asterisk/res_pjsip_session.h<br>M res/res_pjsip_caller_id.c<br>3 files changed, 62 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index aa78e18..4206974 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -625,6 +625,7 @@</span><br><span> </span><br><span> ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);</span><br><span> ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_caller(chan)->ani2 = session->ani2;</span><br><span> </span><br><span> if (!ast_strlen_zero(exten)) {</span><br><span> /* Set provided DNID on the new channel. */</span><br><span>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h</span><br><span>index 9c90a59..9669b45 100644</span><br><span>--- a/include/asterisk/res_pjsip_session.h</span><br><span>+++ b/include/asterisk/res_pjsip_session.h</span><br><span>@@ -227,6 +227,8 @@</span><br><span> AST_VECTOR(, struct ast_rtp_instance_stats *) media_stats;</span><br><span> /*! Number of challenges received during outgoing requests to determine if we are in a loop */</span><br><span> unsigned int authentication_challenge_count:4;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Originating Line Info (ANI II digits) */</span><br><span style="color: hsl(120, 100%, 40%);">+ int ani2;</span><br><span> };</span><br><span> </span><br><span> typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);</span><br><span>diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c</span><br><span>index bea635f..40435c1 100644</span><br><span>--- a/res/res_pjsip_caller_id.c</span><br><span>+++ b/res/res_pjsip_caller_id.c</span><br><span>@@ -33,6 +33,7 @@</span><br><span> #include "asterisk/channel.h"</span><br><span> #include "asterisk/module.h"</span><br><span> #include "asterisk/callerid.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/conversions.h"</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span>@@ -121,6 +122,58 @@</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set an ANI2 integer based on OLI data in a From header</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This uses the contents of a From header in order to set Originating Line information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata The incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param ani2 The ANI2 field to set</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Successfully parsed OLI</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-zero Could not parse OLI</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int set_id_from_oli(pjsip_rx_data *rdata, int *ani2)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char fromhdr[AST_CHANNEL_NAME];</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *s = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_name_addr *id_name_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,</span><br><span style="color: hsl(120, 100%, 40%);">+ PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);</span><br><span style="color: hsl(120, 100%, 40%);">+ id_name_addr = (pjsip_name_addr *) from->uri;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!from) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* This had better not happen */</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri(id_name_addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_pj_str(fromhdr, &uri->user, sizeof(fromhdr));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Look for the possible OLI tags. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((s = strcasestr(fromhdr, ";isup-oli="))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ s += 10;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if ((s = strcasestr(fromhdr, ";ss7-oli="))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ s += 9;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if ((s = strcasestr(fromhdr, ";oli="))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ s += 5;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(s)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* OLI tag is missing, or present with nothing following the '=' sign */</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* just in case OLI is quoted */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (*s == '\"') {</span><br><span style="color: hsl(120, 100%, 40%);">+ s++;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_str_to_int(s, ani2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span> * \brief Set an ast_party_id structure based on data in a P-Asserted-Identity header</span><br><span> *</span><br><span> * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span>@@ -371,6 +424,7 @@</span><br><span> static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)</span><br><span> {</span><br><span> if (!session->channel) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int ani2;</span><br><span> /*</span><br><span> * Since we have no channel this must be the initial inbound</span><br><span> * INVITE. Set the session ID directly because the channel</span><br><span>@@ -387,6 +441,11 @@</span><br><span> if (!session->endpoint->id.self.number.valid) {</span><br><span> set_id_from_from(rdata, &session->id);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!set_id_from_oli(rdata, &ani2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ session->ani2 = ani2;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ session->ani2 = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> /*</span><br><span> * ReINVITE or UPDATE. Check for changes to the ID and queue</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16119">change 16119</a>. To unsubscribe, or for help writing mail filters, 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/c/asterisk/+/16119"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ifc938a7a7d45ce33999ebf3656a542226f6d3847 </div>
<div style="display:none"> Gerrit-Change-Number: 16119 </div>
<div style="display:none"> Gerrit-PatchSet: 6 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-CC: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>