0

I'm trying to forward a specific incoming header to the other leg of the call, but can't figure out how to pass the value of the header in the incoming leg to the pre-dial handler

[addheaders] exten => addheader,1,Verbose("Setting header") exten => addheader,1,Verbose(${somevar}) ; The 'somevar' variable doesn't exist anymore exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader)=test) exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader2)=${somevar}) exten => addheader,n,Return() [incoming] exten => _+4600.,1,Ringing exten => _+4600.,n,Set(somevar=${PJSIP_HEADER(read,TheHeaderIWantToForward)}) exten => _+4600.,n,Verbose(${somevar}) ; Prints the correct value exten => _+4600.,n,Dial(PJSIP/${EXTEN:1},,b(addheaders^addheader^1)) exten => _+4600.,n,Hangup 

I have successfully managed to add the X-MyHeader to the outbound call leg (as the asterisk documentation shows how to), but how do I actually pass the value to the other context? I can't read the variable in "[addheaders]", and I can only read the headers in "[incoming]"

3 Answers 3

2

You can use _VARIABLE: https://wiki.asterisk.org/wiki/display/AST/Variable+Inheritance

[handler] exten => addheader,1,NoOp(Value is ${somevar}) same => n,Set(PJSIP_HEADER(add,X-myheader=${somevar}) same => n,Return() [internal] exten => 6010,1,NoOp(Test) same => n,Set(_somevar=${PJSIP_HEADER(read,X-myheader)}) same => n,NoOp(Value is ${somevar}) same => n,Dial(PJSIP/6010,,b(handler^addheader^1)) same => n,Hangup() 
0

Don't know if this was the 'correct' way of doing this, but i solved it by accepting wildcard extensions in the addheaders context:

[addheaders] exten => _.,1,Set(PJSIP_HEADER(add,X-header-to-be-forwarded)=${EXTEN}) exten => _.,n,Return() [incoming] exten => _+4600.,1,Ringing exten => _+4600.,2,Set(customheader=${PJSIP_HEADER(read,X-header-to-be-forwarded)}) exten => _+4600.,3,GotoIf($["${customheader}"=""]?7:) ; Skip adding the header if it is empty exten => _+4600.,4,Dial(PJSIP/${EXTEN:1},,b(addheaders^${customheader}^1)) exten => _+4600.,5,GoTo(9)) exten => _+4600.,6,Dial(PJSIP/${EXTEN:1}) exten => _+4600.,7,Hangup 

This has some limitations, for example "." or "," cant be used, but it solved our problem.

0

You can also pass arguments to the Dial applications b option:

b([[context^]exten^]priority[(arg1[^...][^argN])]): Before initiating an outgoing call, Gosub to the specified location using the newly created channel. The Gosub will be executed for each destination channel. 

Like this:

exten => _+4600.,n,Dial(PJSIP/${EXTEN:1},,b(addheaders^addheader^1(${somevar}))) 

Then use it:

exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader)=${ARG1}) 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.