[Home]

Summary:ASTERISK-26178: Setting custom SIP headers in PJSIP when using ARI
Reporter:Sebastian (sroberts)Labels:
Date Opened:2016-07-07 07:13:51Date Closed:2016-07-07 08:12:23
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Resources/res_pjsip
Versions:13.5.0 13.9.1 Frequency of
Occurrence
Related
Issues:
Environment:Asterisk 13, PJSIP channel driverAttachments:( 0) pjsipaddheader.patch
Description:We currently have an application that is using the ARI exclusively for managing calls. What we need is a mechanism to set custom SIP headers when originating a new channel via the ARI. This is possible with the old chan_sip driver but creating a variable called "SIPADDHEADERXX", the contents of which are added to the INVITE as a custom header when the INVITE is created.

We need the same functionality for the PJSIP channel driver so I have created a patch for chan_pjsip.c that implements this functionality in the same manner - you can set a varaiable called "PJSIPADDHEADERXX" and in the call() method in chan_pjsip.c it will add the header to the INVITE before sending it.

This is working for me right now, I would just like to know though whether this is something that has been otherwise planned already? I can't find any reference to it here or on Google. If not, is this a valid/recommended means of doing this?

I'm happy to do the work in order to implement this properly, if someone could give me some guidance as to how best to implement it? I'm sure someone else out there also needs this functionality.

I've attached the patch here, it works great in versions 13.5.0 and 13.9.1 where I have tested it thus far.

Comments:By: Asterisk Team (asteriskteam) 2016-07-07 07:13:53.075-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Joshua C. Colp (jcolp) 2016-07-07 07:17:57.886-0500

A dialplan function exists, PJSIP_HEADER[1], for adding/getting headers on PJSIP channels. Dialplan functions can also be used when originating a call through ARI. Does this not work for you?

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_PJSIP_HEADER

By: Sebastian (sroberts) 2016-07-07 07:37:18.855-0500

I need the headers to be set on the initial INVITE that is sent in order to pick the values up on the receiving Asterisk. We also have some services which capture SIP traffic off the network and we want to be able to match the header values for captured SIP conversations.

The problem  when originating with ari is that it only hands the channel over to the dialplan or stasis application after the endpoint has been answered so there is no way to set  custom headers on the initial INVITE. I realize that one can use the Local channel to loop back into the dialplan and then call, however this causes extra complexity when trying to manage the channels. We are trying to keep as much of the call routing and management logic in our application and not in the dialplan.

By: Sebastian (sroberts) 2016-07-07 08:11:54.192-0500

Apologies, I see the syntax needed for setting the headers using PJSIP_HEADER.

This issue can be closed

By: Sebastian (sroberts) 2016-07-07 08:12:23.807-0500

There is a mechanism for achieving this using the ARI already

By: Sotiris Ganouris (sotoz) 2017-10-03 05:27:42.605-0500

So from the discussion, I understand that there is a way to add headers using ARI and PJSIP? But I can't find how to do without specifically calling the PJSIP_HEADER() dialplan application. I need to do it with ChannelOriginateWithId. Sebastian, what is the needed syntax?

By: Joshua C. Colp (jcolp) 2017-10-03 05:31:43.166-0500

[~sotoz] PJSIP_HEADER is a dialplan function, not an application, which means it can be used anywhere you can set/get variables - including in originate. You can pass variables to it to set on the channel, and dialplan functions work there.

By: Sotiris Ganouris (sotoz) 2017-10-03 05:41:32.867-0500

Hey, Joshua, thanks for the reply.
That means that when doing a request to originateWithId: POST /channels/channelId

I can pass at the body of request a json like so:
{quote}
{"variables":{ "PJSIP_HEADER(add,P-Asserted-Id)": "1234567890 <sip:1234567890@x.x.x.x>" }}
{quote}

Is that the correct syntax for using this dialplan function when originating a channel?

By: Joshua C. Colp (jcolp) 2017-10-03 05:47:45.744-0500

[~sotoz] At first glance yes, but I haven't done so in quite a long time.

By: Sotiris Ganouris (sotoz) 2017-10-03 19:15:05.304-0500

[~jcolp] it doesn't seem to work unfortunately. While ARI responds with 200 it doesn't add the header in the INVITE when originating. Is there another way to add a sip header with ARI while using pjsip in originate? [~sroberts] maybe you remember what you did here to solve this issue?

By: Joshua C. Colp (jcolp) 2017-10-03 21:11:20.580-0500

[~sotoz] No, that is the only way - using the dialplan function. You might try the app-dev mailing list[1] as people who use ARI hang out there, and someone may be able to provide a complete working example.

[1] http://lists.digium.com/pipermail/asterisk-app-dev/