[Asterisk-code-review] res_pjsip_caller_id: Add ANI2/OLI parsing (asterisk[16])

Friendly Automation asteriskteam at digium.com
Wed Sep 15 10:08:23 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16119 )

Change subject: res_pjsip_caller_id: Add ANI2/OLI parsing
......................................................................

res_pjsip_caller_id: Add ANI2/OLI parsing

Adds parsing of ANI II digits (Originating
Line Information) to PJSIP, on par with
what currently exists in chan_sip.

ASTERISK-29472

Change-Id: Ifc938a7a7d45ce33999ebf3656a542226f6d3847
---
M channels/chan_pjsip.c
M include/asterisk/res_pjsip_session.h
M res/res_pjsip_caller_id.c
3 files changed, 62 insertions(+), 0 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved; Verified
  Friendly Automation: Approved for Submit



diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index aa78e18..4206974 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -625,6 +625,7 @@
 
 	ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);
 	ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);
+	ast_channel_caller(chan)->ani2 = session->ani2;
 
 	if (!ast_strlen_zero(exten)) {
 		/* Set provided DNID on the new channel. */
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 9c90a59..9669b45 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -227,6 +227,8 @@
 	AST_VECTOR(, struct ast_rtp_instance_stats *) media_stats;
 	/*! Number of challenges received during outgoing requests to determine if we are in a loop */
 	unsigned int authentication_challenge_count:4;
+	/*! Originating Line Info (ANI II digits) */
+	int ani2;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c
index bea635f..40435c1 100644
--- a/res/res_pjsip_caller_id.c
+++ b/res/res_pjsip_caller_id.c
@@ -33,6 +33,7 @@
 #include "asterisk/channel.h"
 #include "asterisk/module.h"
 #include "asterisk/callerid.h"
+#include "asterisk/conversions.h"
 
 /*!
  * \internal
@@ -121,6 +122,58 @@
 
 /*!
  * \internal
+ * \brief Set an ANI2 integer based on OLI data in a From header
+ *
+ * This uses the contents of a From header in order to set Originating Line information.
+ *
+ * \param rdata The incoming message
+ * \param ani2 The ANI2 field to set
+ * \retval 0 Successfully parsed OLI
+ * \retval non-zero Could not parse OLI
+ */
+static int set_id_from_oli(pjsip_rx_data *rdata, int *ani2)
+{
+	char fromhdr[AST_CHANNEL_NAME];
+	const char *s = NULL;
+	pjsip_sip_uri *uri;
+	pjsip_name_addr *id_name_addr;
+
+	pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,
+			PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);
+	id_name_addr = (pjsip_name_addr *) from->uri;
+
+	if (!from) {
+		/* This had better not happen */
+		return -1;
+	}
+
+	uri = pjsip_uri_get_uri(id_name_addr);
+	ast_copy_pj_str(fromhdr, &uri->user, sizeof(fromhdr));
+
+	/* Look for the possible OLI tags. */
+	if ((s = strcasestr(fromhdr, ";isup-oli="))) {
+		s += 10;
+	} else if ((s = strcasestr(fromhdr, ";ss7-oli="))) {
+		s += 9;
+	} else if ((s = strcasestr(fromhdr, ";oli="))) {
+		s += 5;
+	}
+
+	if (ast_strlen_zero(s)) {
+		/* OLI tag is missing, or present with nothing following the '=' sign */
+		return -1;
+	}
+
+	/* just in case OLI is quoted */
+	if (*s == '\"') {
+		s++;
+	}
+
+	return ast_str_to_int(s, ani2);
+}
+
+/*!
+ * \internal
  * \brief Set an ast_party_id structure based on data in a P-Asserted-Identity header
  *
  * This makes use of \ref set_id_from_hdr for setting name and number. It uses
@@ -371,6 +424,7 @@
 static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
 	if (!session->channel) {
+		int ani2;
 		/*
 		 * Since we have no channel this must be the initial inbound
 		 * INVITE.  Set the session ID directly because the channel
@@ -387,6 +441,11 @@
 		if (!session->endpoint->id.self.number.valid) {
 			set_id_from_from(rdata, &session->id);
 		}
+		if (!set_id_from_oli(rdata, &ani2)) {
+			session->ani2 = ani2;
+		} else {
+			session->ani2 = 0;
+		}
 	} else {
 		/*
 		 * ReINVITE or UPDATE.  Check for changes to the ID and queue

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ifc938a7a7d45ce33999ebf3656a542226f6d3847
Gerrit-Change-Number: 16119
Gerrit-PatchSet: 6
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-CC: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210915/e14a0b84/attachment-0001.html>


More information about the asterisk-code-review mailing list