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]"

Pownyan
  • 101
  • 2

2 Answers2

1

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()
jnkrpx
  • 11
  • 1
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.

Pownyan
  • 101
  • 2