What is the preferred way to set SIP headers with pjsip on non-pjsip channels?


I’m currently switching from chan_sip to pjsip and I’m running into an issue with setting headers:
I need to set some specific SIP headers, which my SIP trunk requires me to set on outbound calls.

With chan_sip, I simple set SIPAddHeader(Header: value) somewhere in dialplan and this got inherited to the next SIP channel.
This is important, as some calls originate from Local channels (i.e. from scripts).

With pjsip using Set(PJSIP_HEADER(add,Header)=value) I get
res_pjsip_header_funcs.c:513 func_write_header: This function requires a PJSIP channel. and of course no header when I try to set this header on the originating channel (which is, in this case, a “Local” or “IAX” channel).
At the moment, I’m trying to do this with a GoSub in the outbound dial to quickly add the header, but this is not a very nice solution in my case, since those headers vary in very specific ways and it’s simply just somewhat fiddly.

Is there a way to pre-define SIP headers to be set if a PJSIP channel is forked from the current channel - like the old (better?) behaviour of chan_sip?


The chan_sip behaviour is actually a kludge. The function simply sets certain channel variables, which can also be set directly, with the same effect…

You could always set your own channel variables, or even the ones that chan_sip uses, and have code in the dialplan that dials the real channel, which checks those variables.

Yeah, except…
To set the PJSIP headers, I call a Sub on Dial with Dial(+4912435,B(mysub...)).
With uppercase B, the Sub is executed on the new PJSIP channel - without any channel variables I have in the originating channel.
When calling the Sub with lowercase b option, I’m executing the Sub on the originating channel and can’t set any SIP headers.

With this, I would need to deliver tens of parameters with the Dial(), which is not very handy.
Or am I missing a point?

Did you set inherited channel variables? If not, then such variables would not appear in the dialed channel.

an actual working example

exten => s,1,NoOP(— setting sip header x-src to {ARG1} ---) same => n,NoOP(--- INSIDE HERE VAR1 becomes ARG1 , VAR2 become ARG2 .. ---) same => n,Set(PJSIP_HEADER(add,X-SRC1)={ARG1})
same => n,Set(CALLERID(all)={ARG1} <{ARG1}>)
same => n,Return()

exten => 33500000000,1,NoOP(- - - EXAMPLE CALL - - -)
same => n,Dial(PJSIP/335000000@myTrunk,b(add-sip-header^s^1(VAR1,VAR2,VAR3})))
same => n,Hangup()

Making the variable inherit is done when you set it, not when you use it, so this code doesn’t answer the question you were asked.

Also, you haven’t marked it up properly, as pre-formatted text, for the forum, so it is difficult to read.

That’s it - totally forgot variable inheritance exists :smiley:
It still is a bit unhandy (IMHO), maybe there is a method in the future, to pre-set those variables without the need of a GoSub.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.