Asterisk cmd SipAddHeader

Add a SIP header to the outbound call

Description

SIPAddHeader(Header: Content)

Adds a header to a SIP call placed with DIAL. Remember to user the X-header if you are adding non-standard SIP headers, like "X-Asterisk-Accountcode:". Use this with care. Adding the wrong headers may jeopardize the SIP dialog.

With this app, you may add any header to an outgoing call with the Dial() app. It is a generic way of adding custom SIP Headers in your dialplan.

Details

SIPaddheader() adds a SIP header to the first INVITE message in that channel. Of course, you need to know what you do with this function. You can add any header of your own, that you need to communicate with another node. One thing you could do in an Asterisk network is add the account code to the INVITE... You can not replace SIP headers with this function, only add new ones. Remember: If you add non-standard headers, prefix them with "X-", like in e-mail.


Another Way to do it (trough AMI)

If you like to add a SIP header the same way asterisk application "SipAddHeader" does but using the AMI originate instead you can add a "Variable" field to your originate command with this syntax:

Action: Originate
Channel:......
....
Variable: __SIPADDHEADER51=X-Your-Header: header-val
...
...

51 is because the asterisk limits do 50 calls to the func "SipAddHeader" and this way it wont interfere

Example: Improve codec negotiation between Asterisk servers

Note: This example has little practical use because the codec (audionativeformat) cannot be reliably determined before the call has been answered, and after that setting the SIP_CODEC variable has no effect. The procedure is, however, useful if only and exactly one codec is offered during negotiation.

 ; -- Server 1 tells Server 2 which codec we would like best (to avoid transcoding)
 ~np~exten => s,1,GotoIf($["${SIPPEER(${Server2}|ip)}" != "1.2.3.4"]?dial)  ; add the header only for a specific target server~/np~
 exten => s,n,NoOp(Remote SIPPEER IP: ${SIPPEER(${Server2}|ip)} - Current local codec: ${CHANNEL(audionativeformat)})
 exten => s,n,SIPAddHeader(X-Best-Codec: ${CHANNEL(audionativeformat)})
 exten => s,n(dial),Dial(SIP/Server2/1234)

 ; -- Server 2 receives the call and gives Server the preferred codec
 exten => s,1,GotoIf($["${SIP_HEADER(X-Best-Codec)}" = ""]?continue)
 exten => s,n,ExecIf($["${SIP_HEADER(X-Best-Codec)}" != "${CHANNEL(audionativeformat)}"]|Set|SIP_CODEC=${SIP_HEADER(X-Best-Codec)})
 exten => s,n,NoOp(SIP Header X-Best-Codec: ${SIP_HEADER(X-Best-Codec)} - Current codec: ${CHANNEL(audionativeformat)})
 exten => s,n(continue),Goto(1234,1)

 ; -- Server 2 now tries to use the very same codec for the local extension 
 exten => 1234,1,NoOp(Available codecs: ${SIPPEER(phone1234:codecs)} --)
 exten => 1234,n,Set(CODECOK=0)
 exten => 1234,n,Set(CODECOK=${REGEX("${SIP_HEADER(X-Best-Codec)}" ${SIPPEER(phone1234:codecs)})})
 ~np~exten => 1234,n,ExecIf($[${CODECOK} = 1]|Set|SIP_CODEC_OUTBOUND=${SIP_HEADER(X-Best-Codec)})  ; requires Asterisk 1.6.x~/np~
 exten => 1234,n,Dial(SIP/phone1234)


See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Add a SIP header to the outbound call

Description

SIPAddHeader(Header: Content)

Adds a header to a SIP call placed with DIAL. Remember to user the X-header if you are adding non-standard SIP headers, like "X-Asterisk-Accountcode:". Use this with care. Adding the wrong headers may jeopardize the SIP dialog.

With this app, you may add any header to an outgoing call with the Dial() app. It is a generic way of adding custom SIP Headers in your dialplan.

Details

SIPaddheader() adds a SIP header to the first INVITE message in that channel. Of course, you need to know what you do with this function. You can add any header of your own, that you need to communicate with another node. One thing you could do in an Asterisk network is add the account code to the INVITE... You can not replace SIP headers with this function, only add new ones. Remember: If you add non-standard headers, prefix them with "X-", like in e-mail.


Another Way to do it (trough AMI)

If you like to add a SIP header the same way asterisk application "SipAddHeader" does but using the AMI originate instead you can add a "Variable" field to your originate command with this syntax:

Action: Originate
Channel:......
....
Variable: __SIPADDHEADER51=X-Your-Header: header-val
...
...

51 is because the asterisk limits do 50 calls to the func "SipAddHeader" and this way it wont interfere

Example: Improve codec negotiation between Asterisk servers

Note: This example has little practical use because the codec (audionativeformat) cannot be reliably determined before the call has been answered, and after that setting the SIP_CODEC variable has no effect. The procedure is, however, useful if only and exactly one codec is offered during negotiation.

 ; -- Server 1 tells Server 2 which codec we would like best (to avoid transcoding)
 ~np~exten => s,1,GotoIf($["${SIPPEER(${Server2}|ip)}" != "1.2.3.4"]?dial)  ; add the header only for a specific target server~/np~
 exten => s,n,NoOp(Remote SIPPEER IP: ${SIPPEER(${Server2}|ip)} - Current local codec: ${CHANNEL(audionativeformat)})
 exten => s,n,SIPAddHeader(X-Best-Codec: ${CHANNEL(audionativeformat)})
 exten => s,n(dial),Dial(SIP/Server2/1234)

 ; -- Server 2 receives the call and gives Server the preferred codec
 exten => s,1,GotoIf($["${SIP_HEADER(X-Best-Codec)}" = ""]?continue)
 exten => s,n,ExecIf($["${SIP_HEADER(X-Best-Codec)}" != "${CHANNEL(audionativeformat)}"]|Set|SIP_CODEC=${SIP_HEADER(X-Best-Codec)})
 exten => s,n,NoOp(SIP Header X-Best-Codec: ${SIP_HEADER(X-Best-Codec)} - Current codec: ${CHANNEL(audionativeformat)})
 exten => s,n(continue),Goto(1234,1)

 ; -- Server 2 now tries to use the very same codec for the local extension 
 exten => 1234,1,NoOp(Available codecs: ${SIPPEER(phone1234:codecs)} --)
 exten => 1234,n,Set(CODECOK=0)
 exten => 1234,n,Set(CODECOK=${REGEX("${SIP_HEADER(X-Best-Codec)}" ${SIPPEER(phone1234:codecs)})})
 ~np~exten => 1234,n,ExecIf($[${CODECOK} = 1]|Set|SIP_CODEC_OUTBOUND=${SIP_HEADER(X-Best-Codec)})  ; requires Asterisk 1.6.x~/np~
 exten => 1234,n,Dial(SIP/phone1234)


See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: muppetmaster, Last modification: Fri 15 of Jun, 2012 (19:03 UTC) by elbriga
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+