[asterisk-users] PJSIP_HEADER - Diversion header manipulation
Davor Jovanovic
davor.jovanovic at srce.hr
Tue Dec 11 07:35:04 CST 2018
Hi John,
yes I tried to do "remove" and "update" of the Diversion header but I
get "No headers had been previously added to this session" error. As you
can see from the configuration and logs below I can successfully add
another From: header and make update to that additional From header.
I previously missed to notice change in the domain part of SIP URI in
Diversion header. Phone sets Diversion header to "836 at 10.201.1.19" and
Asterisk makes change in domain part of Diversion hdr in INVITE message
to "192.168.1.101". This server has two network interfaces and
192.168.1.101 is set on eth0. So, Asterisk makes a change to Diversion
header but not the one set by PJSIP_HEADER function.
Davor
#1 Phone -> Asterisk
U 10.201.8.192:5060 -> 10.201.1.19:5060
SIP/2.0 302 Moved Temporarily.
Diversion: <sip:836 at 10.201.1.19>;reason=unconditional.
Server: Linksys/SPA922-6.1.5(a).
Content-Length: 0.
#2 Asterisk -> TSP provider
U 10.201.1.19:5060 -> 10.201.1.15:5060
INVITE sip:0123456789 at 10.201.1.15:5060 SIP/2.0.
From: <sip:527 at 192.168.1.101>;tag=629ca252-0930-404b-9f58-f921ed264ebf.
From: Update to From Header.
CustomOne:
<sip:custom_one at example.com>;reason=unconditional;screen=yes;privacy=off).
CustomTwo:
<sip:custom_two at example.com>;reason=unconditional;screen=yes;privacy=off).
Diversion: <sip:836 at 192.168.1.101>;reason=unconditional.
[add_diversion]
exten => FWDdiver,1,Set(PJSIP_HEADER(remove,Diversion)=)
exten => FWDdiver,2,Set(PJSIP_HEADER(update,Diversion)=new_diversion_update)
exten => FWDdiver,3,Set(PJSIP_HEADER(add,From)=Another From Header)
exten =>
FWDdiver,4,Set(PJSIP_HEADER(add,Diversion)=<sip:new_diversion at example.com>\;reason=unconditional\;screen=yes\;privacy=off))
exten =>
FWDdiver,5,Set(PJSIP_HEADER(add,CustomOne)=<sip:custom_one at example.com>\;reason=unconditional\;screen=yes\;privacy=off))
exten =>
FWDdiver,6,Set(PJSIP_HEADER(add,CustomTwo)=<sip:custom_two at example.com>\;reason=unconditional\;screen=yes\;privacy=off))
exten => FWDdiver,7,Set(PJSIP_HEADER(update,From)=Update to From Header)
exten => FWDdiver,8,Return()
Asterisk*CLI>
-- Executing [FWDdiver at add_diversion:4] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(remove,Diversion)=") in new stack
[Dec 11 14:10:05] ERROR[4426]: res_pjsip_header_funcs.c:410
remove_header: No headers had been previously added to this session.
-- Executing [FWDdiver at add_diversion:5] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(update,Diversion)=new_diversion_update") in new stack
[Dec 11 14:10:05] ERROR[4426]: res_pjsip_header_funcs.c:373
update_header: No headers had been previously added to this session.
-- Executing [FWDdiver at add_diversion:6] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(add,From)=Another From Header") in new stack
-- Executing [FWDdiver at add_diversion:7] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(add,Diversion)=<sip:new_diversion at example.com>;reason=unconditional;screen=yes;privacy=off)")
in new stack
-- Executing [FWDdiver at add_diversion:8] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(add,CustomOne)=<sip:custom_one at example.com>;reason=unconditional;screen=yes;privacy=off)")
in new stack
-- Executing [FWDdiver at add_diversion:9] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(add,CustomTwo)=<sip:custom_two at example.com>;reason=unconditional;screen=yes;privacy=off)")
in new stack
-- Executing [FWDdiver at add_diversion:10] Set("PJSIP/SBC1-0000003a",
"PJSIP_HEADER(update,From)=Update to From Header") in new stack
-- Executing [FWDdiver at add_diversion:11]
Return("PJSIP/SBC1-0000003a", "") in new stack
On 10.12.2018. 18:23, John Kiniston wrote:
> Davor,
>
> Have you attempted to do a Set(PJSIP_HEADER(remove,Diversion)=)) in your
> add_diversion context to remove the header Asterisk is passing through?
>
> On Mon, Dec 10, 2018 at 3:04 AM Davor Jovanovic <davor.jovanovic at srce.hr
> <mailto:davor.jovanovic at srce.hr>> wrote:
>
> Hi all,
>
> I’m trying to rewrite Diversion header when call forwarding is done on
> the phone. The phone sends "302 Moved Temporarily" response and sets
> Diversion header to a local number, but before Asterisk sends this call
> towards TSP provider I need to change Diversion header to a full PSTN
> number. I am using PJSIP_HEADER in a pre-dial handler (configuration is
> below). On the same call I can add some other custom headers (logs are
> below).
>
> Is there any chance I can rewrite Diversion header in this scenario
> with
> PJSIP_HEADER function? Asterisk version is 16.0.1 built from source on
> Debian 9.
>
>
> Thank you
>
> Davor
>
>
> # Outgoing context - TSP provider
> [outgoing]
> exten =>
> 0123456789,1,Dial(PJSIP/${EXTEN}@${SBC_1},,b(add_diversion^FWDdiver^1))
> same => n,Hangup()
>
> # Diversion manipulation context
> [add_diversion]
> exten =>
> FWDdiver,1,Set(PJSIP_HEADER(add,Diversion)=<sip:full_pstn_no at example.com
> <mailto:sip%3Afull_pstn_no at example.com>>\;reason=unconditional\;screen=yes\;privacy=off))
> exten =>
> FWDdiver,2,Set(PJSIP_HEADER(add,CustomOne)=<sip:custom_one at example.com
> <mailto:sip%3Acustom_one at example.com>>\;reason=unconditional\;screen=yes\;privacy=off))
> exten =>
> FWDdiver,3,Set(PJSIP_HEADER(add,CustomTwo)=<sip:custom_two at example.com
> <mailto:sip%3Acustom_two at example.com>>\;reason=unconditional\;screen=yes\;privacy=off))
> exten => FWDdiver,4,Return()
>
>
> Asterisk*CLI>
> -- Now forwarding PJSIP/527-00000168 to
> 'Local/0123456789 at outgoing'
> (thanks to PJSIP/836-00000169)
> [Dec 10 10:25:08] NOTICE[26309][C-000000c0]: app_dial.c:1005
> do_forward:
> Not accepting call completion offers from call-forward recipient
> Local/0123456789 at outgoing-0000002c;1
> -- Executing [0123456789 at outgoing:1]
> Dial("Local/0123456789 at outgoing-0000002c;2",
> "PJSIP/0123456789 at SBC1,,b(add_diversion^FWDdiver^1)") in new stack
> -- PJSIP/SBC1-0000016a Internal
> Gosub(add_diversion,FWDdiver,1) start
> -- Executing [FWDdiver at add_diversion:1]
> Set("PJSIP/SBC1-0000016a",
> "PJSIP_HEADER(add,Diversion)=<sip:full_pstn_no at example.com
> <mailto:sip%3Afull_pstn_no at example.com>>;reason=unconditional;screen=yes;privacy=off)")
>
> in new stack
> -- Executing [FWDdiver at add_diversion:2]
> Set("PJSIP/SBC1-0000016a",
> "PJSIP_HEADER(add,CustomOne)=<sip:custom_one at example.com
> <mailto:sip%3Acustom_one at example.com>>;reason=unconditional;screen=yes;privacy=off)")
>
> in new stack
> -- Executing [FWDdiver at add_diversion:3]
> Set("PJSIP/SBC1-0000016a",
> "PJSIP_HEADER(add,CustomTwo)=<sip:custom_two at example.com
> <mailto:sip%3Acustom_two at example.com>>;reason=unconditional;screen=yes;privacy=off)")
>
> in new stack
> -- Executing [FWDdiver at add_diversion:4]
> Return("PJSIP/SBC1-0000016a", "") in new stack
>
>
> Phone => Asterisk
> U 10.201.8.192:5060 <http://10.201.8.192:5060> -> 10.201.1.19:5060
> <http://10.201.1.19:5060>
> SIP/2.0 302 Moved Temporarily.
> Diversion: <sip:836 at 10.201.1.19
> <mailto:sip%3A836 at 10.201.1.19>>;reason=unconditional.
>
>
> Asterisk => TSP provider
> U 10.201.1.19:5060 <http://10.201.1.19:5060> -> 10.201.1.15:5060
> <http://10.201.1.15:5060>
> CustomOne:
> <sip:custom_one at example.com
> <mailto:sip%3Acustom_one at example.com>>;reason=unconditional;screen=yes;privacy=off.
> CustomTwo:
> <sip:custom_two at example.com
> <mailto:sip%3Acustom_two at example.com>>;reason=unconditional;screen=yes;privacy=off.
> Diversion: <sip:836 at 192.168.1.101
> <mailto:sip%3A836 at 192.168.1.101>>;reason=unconditional.
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at:
> https://community.asterisk.org/
>
> New to Asterisk? Start here:
> https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
>
>
> --
> A human being should be able to change a diaper, plan an invasion,
> butcher a hog, conn a ship, design a building, write a sonnet, balance
> accounts, build a wall, set a bone, comfort the dying, take orders, give
> orders, cooperate, act alone, solve equations, analyze a new problem,
> pitch manure, program a computer, cook a tasty meal, fight efficiently,
> die gallantly. Specialization is for insects.
> ---Heinlein
>
More information about the asterisk-users
mailing list