Mosly transformations for which I forget the syntax:
In this example, assume the following X-Custom: header
X-Custom: "BetaUser01" <sip:+15555551234@host.domain.com:5075;user=phone>;tag=aa70809-41171;sgid=5;tenant=customer123
"X-Custom" is used for this example, because frequently common headers will not have existing psuedo variables to get specific sections. For exxample, to get the user portion of the URI in a from header it is easier to just use $fU
.
In kamailio.cfg
$var(CustomHeader) = $hdr(X-Custom)
$var(CustomHeader)
is now equal to:
"BetaUser01" <sip:+15555551234@host.domain.com:5075;user=phone>;tag=aa70809-41171;sgid=5;tenant=customer123
The nameaddr
transformations can be used to extract display name and URI from a header like so:
In kamailio.cfg:
$var(CustomHeaderUri) = $(hdr(X-Custom){nameaddr.uri}); ## sip:+15555551234@host.domain.com:5075;user=phone
$var(CustomHeaderName) = $(hdr(X-Custom){nameaddr.name}); ## "BetaUser01" (includes the quotation marks)
Note that our example has two different types of parameters. user=phone
is a URI Parameter because it is part of the URI (meaning it is enclosed in the <
and >
symbols. The section tag=aa70809-41171;sgid=5;tenant=customer123
is a Header Paramter. We'll get to that in a second.
To get the URI parameter:
$var(CustomHeaderUri) = $(hdr(X-Custom){nameaddr.uri}); ## sip:+15555551234@host.domain.com:5075;user=phone
$var(CustomHeaderUriParams) = $(var(CustomHeaderUri){uri.params}); ## user=phone
This could also be written in a single line:
$var(CustomHeaderUriParams) = $(hdr(X-Custom){nameaddr.uri}{uri.params}); ## user=phone
In our example header, the string tag=aa70809-41171;sgid=5;tenant=customer123
is the header paramters. Here's how to extract the header parameters:
$var(CustomHeaderHdrParams) = $(hdr(X-Custom){tobody.params}); ## tag=aa70809-41171;sgid=5;tenant=customer123
Once a parameter list is retrieved, it doesn't matter if it was from the URI params or header params.
- Access the name of the key of the first item in the list (it is a zero indexed array)
$var(FirstKey1) = $(hdr(X-Custom){tobody.params}{param.name,0}); ## tag
- Access the value of the last parameter:
$var(LastVal) = $(hdr(X-Custom){tobody.params}{param.valueat,-1}); ## customer123
- Get the value of the sgid parameter:
$var(sgid) = $(hdr(X-Custom){tobody.params}{param.value,sgid}); ## 5