QUESTION Help extracting the Diversion Header (RDNIS) from an INVITE packet

jehowe

Guru
Joined
Nov 14, 2007
Messages
288
Reaction score
4
I have only inbound forwarded calls coming into a 1.8.x PIAF box and need to figure out a way to pull the originally dialed number (called RDNIS, the number doing the forwarding) from the INVITE packet.

The diversion header itself looks like this:

Code:
Diversion: <sip:[email protected]:5060>;privacy=full;screen=no; reason=unknown; counter=1

As inbound calls come in, I'd like to be able to read the RDNIS number (3125551212) into a context as it comes in for upstream processing.
 

jehowe

Guru
Joined
Nov 14, 2007
Messages
288
Reaction score
4
Thank you lgaetz! I'll have time to work with this tonight or over the weekend, and will post the results.

Jeff
 

jehowe

Guru
Joined
Nov 14, 2007
Messages
288
Reaction score
4
Thanks again lgaetz for getting me started, I had a real adventure getting it all sorted. I needed to extract the phone numbers from the 'Diversion', 'From', and 'To' headers, two of which had variable lengths, meaning the offset:length fields weren't going to work.

I couldn't get regx to work at all and ended up using a perl script and the 'shell' function to get things cleaned up.

For the record, here's the perl script contents I made (testcall.pl in this case) that filters the headers- finding a minimum of 10 (maximum of 15) consecutive digits within a string variable (foo) passed from asterisk.


#!/usr/bin/perl
$str = $ARGV[0];
($callnum) = ($str =~ /.+:\+?(\d{10,15}).+/);
print "$callnum";

Below are the lines in asterisk, the first reading the header into 'foo', the second passing the string to perl, creating'foo2' with the clean results:

exten => _X.,n,Set(foo=${SIP_HEADER(From)})
exten => _X.,n,Set(foo2=${SHELL(/usr/bin/perl /var/lib/asterisk/agi-bin/testcall.pl '${foo}')})

One nagging question that cost me a couple hours was why in the line above, double quoting around the variable: "${foo}" was leading to inconsistent results depending on the header contents- the perl script was not the issue. I ended up using single quotes, '${foo}' which resolved it. I don't remember ever having issues with " variables in the past.
 

jehowe

Guru
Joined
Nov 14, 2007
Messages
288
Reaction score
4
Thanks for the regex example! I found a lot of contradictory posts about what to try, what works/doesn't work using regex and Asterisk, and just could not get it working yesterday.
 

Members online

Forum statistics

Threads
25,783
Messages
167,515
Members
19,203
Latest member
frapu
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top