Skip to content

Commit 5b5c358

Browse files
InterLinked1kharwell
authored andcommitted
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
1 parent b760bad commit 5b5c358

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

channels/chan_pjsip.c

+1
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
634634

635635
ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);
636636
ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);
637+
ast_channel_caller(chan)->ani2 = session->ani2;
637638

638639
if (!ast_strlen_zero(exten)) {
639640
/* Set provided DNID on the new channel. */

include/asterisk/res_pjsip_session.h

+2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ struct ast_sip_session {
239239
unsigned int authentication_challenge_count:4;
240240
/*! The direction of the call respective to Asterisk */
241241
enum ast_sip_session_call_direction call_direction;
242+
/*! Originating Line Info (ANI II digits) */
243+
int ani2;
242244
};
243245

244246
typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);

res/res_pjsip_caller_id.c

+59
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "asterisk/channel.h"
3434
#include "asterisk/module.h"
3535
#include "asterisk/callerid.h"
36+
#include "asterisk/conversions.h"
3637

3738
/*!
3839
* \internal
@@ -119,6 +120,58 @@ static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *hea
119120
return parsed_hdr;
120121
}
121122

123+
/*!
124+
* \internal
125+
* \brief Set an ANI2 integer based on OLI data in a From header
126+
*
127+
* This uses the contents of a From header in order to set Originating Line information.
128+
*
129+
* \param rdata The incoming message
130+
* \param ani2 The ANI2 field to set
131+
* \retval 0 Successfully parsed OLI
132+
* \retval non-zero Could not parse OLI
133+
*/
134+
static int set_id_from_oli(pjsip_rx_data *rdata, int *ani2)
135+
{
136+
char fromhdr[AST_CHANNEL_NAME];
137+
const char *s = NULL;
138+
pjsip_sip_uri *uri;
139+
pjsip_name_addr *id_name_addr;
140+
141+
pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,
142+
PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);
143+
id_name_addr = (pjsip_name_addr *) from->uri;
144+
145+
if (!from) {
146+
/* This had better not happen */
147+
return -1;
148+
}
149+
150+
uri = pjsip_uri_get_uri(id_name_addr);
151+
ast_copy_pj_str(fromhdr, &uri->user, sizeof(fromhdr));
152+
153+
/* Look for the possible OLI tags. */
154+
if ((s = strcasestr(fromhdr, ";isup-oli="))) {
155+
s += 10;
156+
} else if ((s = strcasestr(fromhdr, ";ss7-oli="))) {
157+
s += 9;
158+
} else if ((s = strcasestr(fromhdr, ";oli="))) {
159+
s += 5;
160+
}
161+
162+
if (ast_strlen_zero(s)) {
163+
/* OLI tag is missing, or present with nothing following the '=' sign */
164+
return -1;
165+
}
166+
167+
/* just in case OLI is quoted */
168+
if (*s == '\"') {
169+
s++;
170+
}
171+
172+
return ast_str_to_int(s, ani2);
173+
}
174+
122175
/*!
123176
* \internal
124177
* \brief Set an ast_party_id structure based on data in a P-Asserted-Identity header
@@ -371,6 +424,7 @@ static void update_incoming_connected_line(struct ast_sip_session *session, pjsi
371424
static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
372425
{
373426
if (!session->channel) {
427+
int ani2;
374428
/*
375429
* Since we have no channel this must be the initial inbound
376430
* INVITE. Set the session ID directly because the channel
@@ -387,6 +441,11 @@ static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_
387441
if (!session->endpoint->id.self.number.valid) {
388442
set_id_from_from(rdata, &session->id);
389443
}
444+
if (!set_id_from_oli(rdata, &ani2)) {
445+
session->ani2 = ani2;
446+
} else {
447+
session->ani2 = 0;
448+
}
390449
} else {
391450
/*
392451
* ReINVITE or UPDATE. Check for changes to the ID and queue

0 commit comments

Comments
 (0)