33
33
#include "asterisk/channel.h"
34
34
#include "asterisk/module.h"
35
35
#include "asterisk/callerid.h"
36
+ #include "asterisk/conversions.h"
36
37
37
38
/*!
38
39
* \internal
@@ -119,6 +120,58 @@ static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *hea
119
120
return parsed_hdr ;
120
121
}
121
122
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
+
122
175
/*!
123
176
* \internal
124
177
* \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
371
424
static int caller_id_incoming_request (struct ast_sip_session * session , pjsip_rx_data * rdata )
372
425
{
373
426
if (!session -> channel ) {
427
+ int ani2 ;
374
428
/*
375
429
* Since we have no channel this must be the initial inbound
376
430
* 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_
387
441
if (!session -> endpoint -> id .self .number .valid ) {
388
442
set_id_from_from (rdata , & session -> id );
389
443
}
444
+ if (!set_id_from_oli (rdata , & ani2 )) {
445
+ session -> ani2 = ani2 ;
446
+ } else {
447
+ session -> ani2 = 0 ;
448
+ }
390
449
} else {
391
450
/*
392
451
* ReINVITE or UPDATE. Check for changes to the ID and queue
0 commit comments