Michael Ulitskiy
2015-Oct-06 20:25 UTC
[asterisk-users] PJSIP: how to retrieve underlying SIP Call-ID
Hello, I've started to play with PJSIP and got stuck at the following problem. I need to retrieve SIP Call-ID associated with PJSIP channel. For inbound channel I can use ${PJSIP_HEADER(read,Call-ID)}, but that doesn't work for outbound channel even in pre-dial or hangup handler. Whatever I do PJSIP_HEADER seem to be unable to read headers for outbound channel. Here's what I do: [xyz] exten => 999,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) same => n,Dial(PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)) exten => h,1,NoOp() [_pre_dial] exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) same => n,Set(CHANNEL(hangup_handler_push)=_hangup,s,1()) same => n,Return [_hangup] exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) same => n,Return Here's the result: -- Executing [999 at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "Call-ID: e3e249e5-7e8941dd-da386565 at 192.168.100.238") in new stack -- Executing [999 at xyz:2] Dial("PJSIP/poly_650_2_01-0000006f", "PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)") in new stack -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) start -- Executing [s at _pre_dial:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") in new stack -- Executing [s at _pre_dial:2] Set("PJSIP/xyz011101-00000070", "CHANNEL(hangup_handler_push)=_hangup,s,1()") in new stack -- Executing [s at _pre_dial:3] Return("PJSIP/xyz011101-00000070", "") in new stack == Spawn extension (xyz, 999, 1) exited non-zero on 'PJSIP/xyz011101-00000070' -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) complete GOSUB_RETVAL -- Called PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060 == Using SIP RTP Audio TOS bits 184 -- PJSIP/xyz011101-00000070 is ringing -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) start -- Executing [s at _hangup:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") in new stack -- Executing [s at _hangup:2] Return("PJSIP/xyz011101-00000070", "") in new stack == Spawn extension (xyz, 999, 1) exited non-zero on 'PJSIP/xyz011101-00000070' -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) complete GOSUB_RETVAL == Spawn extension (xyz, 999, 2) exited non-zero on 'PJSIP/poly_650_2_01-0000006f' -- Executing [h at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "") in new stack As you can see I can get Call-ID of inbound channel, but I receive null for the outbound channel in both pre-dial and hangup handlers. So my question is if there's a way to retrieve SIP Call-ID for outbound channels? Also the 2nd question is if PJSIP_HEADER is supposed to be able to read headers of the outbound channel? Thanks, Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20151006/d90c5112/attachment.html>
Matthew Jordan
2015-Oct-06 22:06 UTC
[asterisk-users] PJSIP: how to retrieve underlying SIP Call-ID
On Tue, Oct 6, 2015 at 3:25 PM, Michael Ulitskiy <mulitskiy at acedsl.com> wrote:> Hello, > > > > I've started to play with PJSIP and got stuck at the following problem. > > I need to retrieve SIP Call-ID associated with PJSIP channel. > > For inbound channel I can use ${PJSIP_HEADER(read,Call-ID)}, but that > doesn't work for > > outbound channel even in pre-dial or hangup handler. Whatever I do > PJSIP_HEADER > > seem to be unable to read headers for outbound channel. > > > > Here's what I do: > > > > [xyz] > > exten => 999,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > same => > n,Dial(PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)) > > exten => h,1,NoOp() > > > > [_pre_dial] > > exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > same => n,Set(CHANNEL(hangup_handler_push)=_hangup,s,1()) > > same => n,Return > > > > [_hangup] > > exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > same => n,Return > > > > > > Here's the result: > > -- Executing [999 at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "Call-ID: > e3e249e5-7e8941dd-da386565 at 192.168.100.238") in new stack > > -- Executing [999 at xyz:2] Dial("PJSIP/poly_650_2_01-0000006f", > "PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)") > in new stack > > -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) start > > -- Executing [s at _pre_dial:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") > in new stack > > -- Executing [s at _pre_dial:2] Set("PJSIP/xyz011101-00000070", > "CHANNEL(hangup_handler_push)=_hangup,s,1()") in new stack > > -- Executing [s at _pre_dial:3] Return("PJSIP/xyz011101-00000070", "") in new > stack > > == Spawn extension (xyz, 999, 1) exited non-zero on > 'PJSIP/xyz011101-00000070' > > -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) complete > GOSUB_RETVAL> > -- Called PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060 > > == Using SIP RTP Audio TOS bits 184 > > -- PJSIP/xyz011101-00000070 is ringing > > -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) start > > -- Executing [s at _hangup:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") in > new stack > > -- Executing [s at _hangup:2] Return("PJSIP/xyz011101-00000070", "") in new > stack > > == Spawn extension (xyz, 999, 1) exited non-zero on > 'PJSIP/xyz011101-00000070' > > -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) complete > GOSUB_RETVAL> > == Spawn extension (xyz, 999, 2) exited non-zero on > 'PJSIP/poly_650_2_01-0000006f' > > -- Executing [h at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "") in new stack > > > > As you can see I can get Call-ID of inbound channel, but I receive null for > the outbound channel in both pre-dial and hangup handlers. > > > > So my question is if there's a way to retrieve SIP Call-ID for outbound > channels? > > Also the 2nd question is if PJSIP_HEADER is supposed to be able to read > headers of the outbound channel? >Hi Michael - While you can use PJSIP_HEADER, the ability to retrieve the SIP Call-ID through the CHANNEL function on a PJSIP channel was actually just added in 13.6.0, and should be in the latest RC (13.6.0-rc2 [2]). In either case, you're using a function as opposed to some application, which means you do need to call the functions on the specific channel. To get access to the outbound channel, you can use a pre-dial handler's 'b' option [3]. The Call-ID *should* be set up on the underlying invite session in the PJSIP dialog, even though it hasn't been transmitted yet. Matt [1] https://gerrit.asterisk.org/#/c/1204/ [2] http://downloads.asterisk.org/pub/telephony/asterisk/ChangeLog-13.6.0-rc2 [3] https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers -- Matthew Jordan Digium, Inc. | Director of Technology 445 Jan Davis Drive NW - Huntsville, AL 35806 - USA Check us out at: http://digium.com & http://asterisk.org
Michael Ulitskiy
2015-Oct-07 16:28 UTC
[asterisk-users] PJSIP: how to retrieve underlying SIP Call-ID
Hello Matt, That works (CHANNEL(pjsip,call-id)). Thanks. I'm still interested to know if PJSIP_HEADER is supposed to be able to read headers of the outbound channel. I'm also very interested to know if there's any way in asterisk to access headers received in "200 OK" reply, as my proxy returns some important information there. Thanks a lot, Michael On Tuesday, October 06, 2015 05:06:34 PM Matthew Jordan wrote:> On Tue, Oct 6, 2015 at 3:25 PM, Michael Ulitskiy <mulitskiy at acedsl.com> wrote: > > Hello, > > > > > > > > I've started to play with PJSIP and got stuck at the following problem. > > > > I need to retrieve SIP Call-ID associated with PJSIP channel. > > > > For inbound channel I can use ${PJSIP_HEADER(read,Call-ID)}, but that > > doesn't work for > > > > outbound channel even in pre-dial or hangup handler. Whatever I do > > PJSIP_HEADER > > > > seem to be unable to read headers for outbound channel. > > > > > > > > Here's what I do: > > > > > > > > [xyz] > > > > exten => 999,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > > > same => > > n,Dial(PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)) > > > > exten => h,1,NoOp() > > > > > > > > [_pre_dial] > > > > exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > > > same => n,Set(CHANNEL(hangup_handler_push)=_hangup,s,1()) > > > > same => n,Return > > > > > > > > [_hangup] > > > > exten => s,1,NoOp(Call-ID: ${PJSIP_HEADER(read,Call-ID)}) > > > > same => n,Return > > > > > > > > > > > > Here's the result: > > > > -- Executing [999 at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "Call-ID: > > e3e249e5-7e8941dd-da386565 at 192.168.100.238") in new stack > > > > -- Executing [999 at xyz:2] Dial("PJSIP/poly_650_2_01-0000006f", > > "PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060,30,b(_pre_dial,s,1)") > > in new stack > > > > -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) start > > > > -- Executing [s at _pre_dial:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") > > in new stack > > > > -- Executing [s at _pre_dial:2] Set("PJSIP/xyz011101-00000070", > > "CHANNEL(hangup_handler_push)=_hangup,s,1()") in new stack > > > > -- Executing [s at _pre_dial:3] Return("PJSIP/xyz011101-00000070", "") in new > > stack > > > > == Spawn extension (xyz, 999, 1) exited non-zero on > > 'PJSIP/xyz011101-00000070' > > > > -- PJSIP/xyz011101-00000070 Internal Gosub(_pre_dial,s,1) complete > > GOSUB_RETVAL> > > > -- Called PJSIP/xyz011101/sip:xyz011101@<outbound_proxy>:5060 > > > > == Using SIP RTP Audio TOS bits 184 > > > > -- PJSIP/xyz011101-00000070 is ringing > > > > -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) start > > > > -- Executing [s at _hangup:1] NoOp("PJSIP/xyz011101-00000070", "Call-ID: ") in > > new stack > > > > -- Executing [s at _hangup:2] Return("PJSIP/xyz011101-00000070", "") in new > > stack > > > > == Spawn extension (xyz, 999, 1) exited non-zero on > > 'PJSIP/xyz011101-00000070' > > > > -- PJSIP/xyz011101-00000070 Internal Gosub(_hangup,s,1) complete > > GOSUB_RETVAL> > > > == Spawn extension (xyz, 999, 2) exited non-zero on > > 'PJSIP/poly_650_2_01-0000006f' > > > > -- Executing [h at xyz:1] NoOp("PJSIP/poly_650_2_01-0000006f", "") in new stack > > > > > > > > As you can see I can get Call-ID of inbound channel, but I receive null for > > the outbound channel in both pre-dial and hangup handlers. > > > > > > > > So my question is if there's a way to retrieve SIP Call-ID for outbound > > channels? > > > > Also the 2nd question is if PJSIP_HEADER is supposed to be able to read > > headers of the outbound channel? > > > > Hi Michael - > > While you can use PJSIP_HEADER, the ability to retrieve the SIP > Call-ID through the CHANNEL function on a PJSIP channel was actually > just added in 13.6.0, and should be in the latest RC (13.6.0-rc2 [2]). > > In either case, you're using a function as opposed to some > application, which means you do need to call the functions on the > specific channel. To get access to the outbound channel, you can use a > pre-dial handler's 'b' option [3]. The Call-ID *should* be set up on > the underlying invite session in the PJSIP dialog, even though it > hasn't been transmitted yet. > > Matt > > [1] https://gerrit.asterisk.org/#/c/1204/ > [2] http://downloads.asterisk.org/pub/telephony/asterisk/ChangeLog-13.6.0-rc2 > [3] https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20151007/d0c11871/attachment.html>