Kamailio SIP Server v4.2.x (stable): Transformations

Transformation is basically a function that is applied to a pseudo-variable (PV) to get a special value from it. The value of PV is not affected at all.

Transformations are implemented by various modules, most of them being in pv module.

The transformations are intended to facilitate access to different attributes of PV (like strlen of value, parts of value, substrings) or complete different value of PV (encoded in hexa, md5 value, escape/unescape PV value for DB operations…).

A transformation is represented in between '{' and '}' and follows the name of a PV. When using transformations, the PV name and transformations must be enclosed in between '(' and ')', following the $ sign.

The transformations can be used anywhere, being considered parts of PV – in xlog, avpops or other modules' functions and parameters, in right side assignment expressions or in comparisons.

String Transformations

The name of these transformation starts with 's.'. They are intended to apply string operations to PV.

Available transformations in this class:

{s.len}

Return strlen of PV value

$var(x) = "abc";
if($(var(x){s.len}) == 3)
{
...
}

{s.int}

Return integer value of a string-represented number

$var(x) = "1234";
if($(var(x){s.int})==1234) {
...
}

{s.md5}

Return md5 over PV value

xlog("md5 over From username: $(fU{s.md5})");

{s.sha256}

Return sha 256 over PV value

xlog("sha 256 over From username: $(fU{s.sha256})");

{s.sha384}

Return sha 384 over PV value

xlog("sha 384 over From username: $(fU{s.sha384})");

{s.sha512}

Return sha 512 over PV value

xlog("sha 512 over From username: $(fU{s.sha512})");

{s.substr,offset,length}

Return substring starting at offset having size of 'length'. If offset is negative, then it is counted from the end of PV value, -1 being the last char. In case of positive value, 0 is first char. Length must be positive, in case of 0, substring to the end of PV value is returned. offset and length can be PV as well.

Example:

$var(x) = "abcd";
$(var(x){s.substr,1,0}); => "bcd"

{s.select,index,separator}

Return a field from PV value. The field is selected based on separator and index. The separator must be a character used to identify the fields. Index must be a integer value or a PV. If index is negative, the count of fields starts from end of PV value, -1 being last field. If index is positive, 0 is the first field.

{s.replace,match,repl}

Replace all occurrences of match with repl. The parameters can be pseudo-variables.

Example:

$var(x)="abababa";
$(var(x){s.replace,a,c}=>"cbcbcbc"

{s.ftime,format}

Format the epoch in the pv according to the parameter. The parameter has to be strftime formatting string.

$(TS{s.ftime,%Y-%m-%d %H:%M:%S})

{s.trim}

Remove left and right whitespaces (' ', '\t', '\r', '\n') around PV value.

$(var(x){s.trim})

{s.rtrim}

Remove right whitespaces (' ', '\t', '\r', '\n') around PV value.

$(var(x){s.rtrim})

{s.ltrim}

Remove left whitespaces (' ', '\t', '\r', '\n') around PV value.

$(var(x){s.ltrim})

{s.rm,match}

Remove occurrences of 'match' from PV. 'match' can be static string or variable.

$(var(x){s.rm,test})

URI Transformations

The name of transformation starts with 'uri.'. The PV value is considered to be a SIP URI. This transformation returns parts of SIP URI (see struct sip_uri). If that part is missing, the returned value is an empty string.

Available transformations in this class:

{uri.user}

Return the user part

{uri.host}

(same as {uri.domain})

Return the domain part

{uri.passwd}

Return the password

{uri.port}

Return the port

{uri.params}

Return the URI parameters in a string

{uri.param,name}

Return the value of parameter with name 'name'

{uri.headers}

Return URI headers

{uri.transport}

Return the value of transport parameter

{uri.ttl}

Return the value of ttl parameter

{uri.uparam}

Return the value of user parameter

{uri.maddr}

Return the value of maddr parameter

{uri.method}

Return the value of method parameter

{uri.lr}

Return the value of lr parameter

{uri.r2}

Return the value of r2 parameter

Parameters List Transformations

The name of the transformation starts with 'param.'. The PV value is considered to be a string like name1=value1;name2=value2;…”. The transformations returns the value for a specific parameter, or the name of a parameter at a specific index.

Available transformations in this class:

{param.value,name[, delimiter]}

Return the value of parameter 'name'

Example:

"a=1;b=2;c=3"{param.value,c} = "3"

'name' can be a pseudo-variable

'delimiter' allows you to specify a single character to use as the parameter delimiter. For example, when parsing HTTP URL query strings use '&'.

{param.valueat,index[, delimiter]}

Return the value of parameter at position give by 'index' (0-based index)

Example:

"a=1;b=2;c=3"{param.valueat,1} = "2"

'index' can be a pseudo-variable

'delimiter' allows you to specify a single character to use as the parameter delimiter. For example, when parsing HTTP URL query strings use '&'.

{param.name,index[, delimiter]}

Return the name of parameter at position 'index'.

Example:

"a=1;b=2;c=3"{param.name,1} = "b"

'delimiter' allows you to specify a single character to use as the parameter delimiter. For example, when parsing HTTP URL query strings use '&'.

{param.count[, delimiter]}

Return the number of parameters in the list.

Example:

"a=1;b=2;c=3"{param.count} = 3

'delimiter' allows you to specify a single character to use as the parameter delimiter. For example, when parsing HTTP URL query strings use '&'.

Name-address Transformations

The name of the transformation starts with 'nameaddr.'. The PV value is considered to be a string like '[display_name] uri'. The transformations returns the value for a specific field.