Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated to GIT-18-ff80a61

...

PJSIP_HEADER allows you to read specific SIP headers from the inbound PJSIP channel as well as write(add, update, remove) headers on the outbound channel. One exception is that you can read headers that you have already added on the outbound channel.

Examples:

;

...

Code Block
titleExample: Set somevar to the value of the

...

From

...

header

...

linenumberstrue


exten => 1,1,Set(somevar=${PJSIP_HEADER(read,From)})

;

...

Code Block
titleExample: Set via2 to the value of the 2nd

...

Via

...

header

...

linenumberstrue


exten => 1,1,Set(via2=${PJSIP_HEADER(read,Via,2)})

;

...

Code Block
titleExample: Set xhdr to the value of the

...

1st X-header

...

linenumberstrue


exten => 1,1,Set(xhdr=${PJSIP_HEADER(read,X-*,1)})

;

...

Code Block
titleExample: Add an

...

X-Myheader

...

header with the value of

...

myvalue

...

linenumberstrue


exten => 1,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)

;

...

Code Block
titleExample: Add an

...

X-Myheader

...

header with an empty value

...

linenumberstrue


exten => 1,1,Set(PJSIP_HEADER(add,X-MyHeader)=)

;

...

Code Block
titleExample: Update the value of the header named

...

X-Myheader

...

to

...

newvalue

...

linenumberstrue


; 'X-Myheader' must already exist or the call will fail.

...


exten => 1,1,Set(PJSIP_HEADER(update,X-MyHeader)=newvalue)

;

...

Code Block
titleExample: Remove all headers whose names exactly match

...

X-MyHeader

...

linenumberstrue


exten => 1,1,Set(PJSIP_HEADER(remove,X-MyHeader)=)

;

...

Code Block
titleExample: Remove all headers that begin with

...

X-My

...

linenumberstrue


exten => 1,1,Set(PJSIP_HEADER(remove,X-My*)=)

;

...

Code Block
titleExample: Remove all previously added headers

...

linenumberstrue


exten => 1,1,Set(PJSIP_HEADER(remove,*)=)

;

Info
titleNote

The remove action can be called by reading or writing PJSIP_HEADER.

;

;
Code Block
titleExample: Display the number of headers removed
linenumberstrue


exten => 1,1,Verbose( Removed ${PJSIP_HEADER(remove,X-MyHeader)} headers)

;

;
Code Block
titleExample: Set a variable to the number of headers removed
linenumberstrue


exten => 1,1,Set(count=${PJSIP_HEADER(remove,X-MyHeader)})

;

;
Code Block
titleExample: Just remove them ignoring any count
linenumberstrue


exten => 1,1,Set(=${PJSIP_HEADER(remove,X-MyHeader)})

exten => 1,1,Set(PJSIP_HEADER(remove,X-MyHeader)=)

;

Info
titleNote

If you call PJSIP_HEADER in a normal dialplan context you'll be operating on the caller's (incoming) channel which may not be what you want. To operate on the callee's (outgoing) channel call PJSIP_HEADER in a pre-dial handler.

;
Code Block
titleExample: Set headers on callee channel
linenumberstrue


[handler]

exten => addheader,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)

exten => addheader,2,Set(PJSIP_HEADER(add,X-MyHeader2)=myvalue2)

;



[somecontext]

exten => 1,1,Dial(PJSIP/${EXTEN},,b(handler^addheader^1))

;

Syntax

No Format
PJSIP_HEADER(action,name[,number])

...

This documentation was imported from Asterisk Version GIT-18-1e4ed61ff80a61