Adding Custom SIP Header for REGISTER on PJSIP Trunk

(Nick Piggott) #1


My provider (Vodafone UK) needs me to include two custom headers on every SIP transaction.

I know that User-Agent is a global, which I can change. So I’ve concentrated on adding the X-Serialnumber header.

I’ve used these posts as reference on how to do that

I have a

which contains:

include => func-apply-sipheaders-custom
exten => s,1,Noop(Applying SIP Headers to channel ${CHANNEL})
exten => s,n,Set(TECH=${CUT(CHANNEL,/,1)})
exten => s,n,While($["${SET(sipkey=${SHIFT(SIPHEADERKEYS)})}" != ""])
exten => s,n,Set(sipheader=${HASH(SIPHEADERS,${sipkey})})
exten => s,n,ExecIf($["${sipheader}" = "unset" & "${TECH}" = "PJSIP"]?Set(PJSIP_HEADER(remove,${sipkey})=))
exten => s,n,ExecIf($["${sipheader}" != "unset" & "${sipkey}" = "Alert-Info" & ${REGEX("^<[^>]*>" ${sipheader})} != 1 & ${REGEX("\;info=" ${sipheader})} != 1]?Set(sipheader=<>\;info=${sipheader}))
exten => s,n,ExecIf($["${sipheader}" != "unset" & "${sipkey}" = "Alert-Info" & ${REGEX("^<[^>]*>" ${sipheader})} != 1]?Set(sipheader=<>${sipheader}))
exten => s,n,ExecIf($["${TECH}" = "PJSIP" & "${sipheader}" != "unset"]?Set(PJSIP_HEADER(add,${sipkey})=${sipheader}))
exten => s,n,EndWhile
exten => s,n,Noop(Applying X-Serialnumber Header to channel)
exten => s,n,Set(PJSIP_HEADER(add,X-Serialnumber)=AAAAAA))
exten => s,n,Return()

;--== end of [func-apply-sipheaders] ==--;

You’ll see I’ve added a PJSIP_HEADER(add,X-Serialnumber)=AAAAA statement to the end of the macro.

I have not altered the dial plan for the relevant trunk (it’s still Tt), as I understand that this macro is always called?

I’ve also tried following the recommendation in this post to create [macro-dialout-trunk-predial-hook] in extensions_custom.conf.

But when I turn on pjsip logger in the asterisk cli, I’m not seeing the additional X-Serialnumber being added to the REGISTER transaction.

Are there any suggestions on how I can debug this further, or amend the dialplan / configuration?



(Joshua C. Colp) #2

The dialplan is for calls, not for registrations. There is not currently a way to add arbitrary headers to REGISTER requests.

(Nick Piggott) #3

OK, thanks for clarifying. That would explain why it’s not working, and why I should stop trying!

(system) closed #4

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