cookbooks:devel:transformations
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cookbooks:devel:transformations [2011/12/16 22:41] – [{s.ftime,format}] miconda | cookbooks:devel:transformations [2022/04/08 16:08] (current) – [URI Alias Transformations] miconda | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Kamailio SIP Server | + | ====== |
+ | |||
+ | Version: | ||
< | < | ||
Main author: | Main author: | ||
- | | + | |
</ | </ | ||
- | **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. | + | **Transformation** is basically a function that is applied to a pseudo-variable (PV) to get a property of it. The value of PV is not affected at all. |
Transformations are implemented by various modules, most of them being in **pv** module. | Transformations are implemented by various modules, most of them being in **pv** module. | ||
Line 66: | Line 68: | ||
< | < | ||
xlog(" | xlog(" | ||
+ | </ | ||
+ | |||
+ | ==== {s.sha256} ==== | ||
+ | |||
+ | Return sha 256 over PV value | ||
+ | |||
+ | < | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | ==== {s.sha384} ==== | ||
+ | |||
+ | Return sha 384 over PV value | ||
+ | |||
+ | < | ||
+ | xlog(" | ||
+ | </ | ||
+ | |||
+ | ==== {s.sha512} ==== | ||
+ | |||
+ | Return sha 512 over PV value | ||
+ | |||
+ | < | ||
+ | xlog(" | ||
</ | </ | ||
Line 90: | Line 116: | ||
$(var(x){s.select, | $(var(x){s.select, | ||
</ | </ | ||
+ | |||
+ | |||
+ | ==== {s.encode.7bit} ==== | ||
+ | |||
+ | Return encoding in 7Bit of PV value | ||
+ | |||
+ | ==== {s.decode.7bit} ==== | ||
+ | |||
+ | Return decoding of PV value in 7Bit | ||
==== {s.encode.hexa} ==== | ==== {s.encode.hexa} ==== | ||
Line 99: | Line 134: | ||
Return decoding from hexa of PV value | Return decoding from hexa of PV value | ||
+ | ==== {s.encode.base58} ==== | ||
+ | |||
+ | Return base58 encoding of PV value. | ||
+ | |||
+ | The set of base58 digits is: | ||
+ | |||
+ | < | ||
+ | 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz | ||
+ | </ | ||
+ | |||
+ | ==== {s.decode.base58} ==== | ||
+ | |||
+ | Return base58 decoding of PV value. | ||
+ | |||
+ | ==== {s.encode.base64} ==== | ||
+ | |||
+ | Return base64 encoding of PV value | ||
+ | ==== {s.decode.base64} ==== | ||
+ | |||
+ | Decode base64 encoded PV and return value | ||
+ | |||
+ | ==== {s.encode.base64t} ==== | ||
+ | |||
+ | Return base64 encoding of PV value without trailing padding characters(' | ||
+ | |||
+ | |||
+ | ==== {s.decode.base64t} ==== | ||
+ | |||
+ | Decode base64 encoded PV, handling missing trailing padding characters, and return value. | ||
+ | |||
+ | ==== {s.encode.base64url} ==== | ||
+ | |||
+ | Return base64-url encoding of PV value | ||
+ | |||
+ | ==== {s.decode.base64url} ==== | ||
+ | |||
+ | Decode base64-url encoded PV and return value | ||
+ | |||
+ | ==== {s.encode.base64urlt} ==== | ||
+ | |||
+ | Return base64-url encoding of PV value without trailing padding characters(' | ||
+ | |||
+ | |||
+ | ==== {s.decode.base64urlt} ==== | ||
+ | |||
+ | Decode base64-url encoded PV, handling missing trailing padding characters, and return value. | ||
Line 129: | Line 210: | ||
Return unescaped string of PV value, changing ' | Return unescaped string of PV value, changing ' | ||
+ | |||
+ | |||
+ | ==== {s.escape.csv} ==== | ||
+ | |||
+ | Escapes a string to use as a CSV field, as specified in RFC4180: | ||
+ | * enclose string in double quotes | ||
+ | * escape double quotes with a second double quote | ||
+ | |||
+ | Example: | ||
+ | <code c> | ||
+ | $var(x) = ' | ||
+ | $(var(x){s.escape.csv}); | ||
+ | </ | ||
+ | |||
+ | ==== {s.numeric} ==== | ||
+ | |||
+ | Removes all non-numeric parts of string. | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | $var(x) = " | ||
+ | $(var(x){s.numeric}) => " | ||
+ | </ | ||
==== {s.tolower} ==== | ==== {s.tolower} ==== | ||
Line 222: | Line 326: | ||
$(var(x){s.ltrim}) | $(var(x){s.ltrim}) | ||
</ | </ | ||
+ | |||
+ | ==== {s.rm, | ||
+ | |||
+ | Remove occurrences of ' | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){s.rm, | ||
+ | </ | ||
+ | |||
+ | ==== {s.rmws} ==== | ||
+ | |||
+ | Remove occurrences of whitespace characters (' ', '\t, ' | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){s.rmws}) | ||
+ | </ | ||
+ | ==== {s.corehash, | ||
+ | |||
+ | Return the hash id computed with Kamailio' | ||
+ | |||
+ | Note: the value is returned as string. | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){s.corehash}) | ||
+ | </ | ||
+ | |||
+ | ==== {s.unquote} ==== | ||
+ | |||
+ | Return the value without surrounding single (') or double quotes ("). | ||
+ | |||
+ | <code c> | ||
+ | $var(x) = " | ||
+ | $var(alice) = $(var(x){s.unquote}); | ||
+ | </ | ||
+ | |||
+ | ==== {s.unbracket} ==== | ||
+ | |||
+ | Return the value without surrounding (), [], {} or <>. | ||
+ | |||
+ | <code c> | ||
+ | $var(x) = "< | ||
+ | $var(uri) = $(var(x){s.unbracket}); | ||
+ | </ | ||
+ | |||
+ | ==== {s.count,c} ==== | ||
+ | |||
+ | Count how many times c appears in the pv value. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | # will return 4 | ||
+ | </ | ||
+ | |||
+ | ==== {s.after,x} ==== | ||
+ | |||
+ | Return the part of the string after the character **x** searched from the start of the value. If the character **x** is not found, it returns empty string. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | # will return " | ||
+ | </ | ||
+ | |||
+ | ==== {s.rafter, | ||
+ | |||
+ | Return the part of the string after the character **x** searched from the end of the value. If the character **x** is not found, it returns empty string. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | # will return " | ||
+ | </ | ||
+ | ==== {s.before, | ||
+ | |||
+ | Return the part of the string before the character **x** searched from the start of the value. If the character **x** is not found, it returns the entire input string. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | # will return " | ||
+ | </ | ||
+ | |||
+ | ==== {s.rbefore, | ||
+ | |||
+ | Return the part of the string before the character **x** searched from the end of the value. If the character **x** is not found, it returns the entire input string. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | # will return " | ||
+ | </ | ||
+ | |||
+ | ==== {s.fmtlines, | ||
+ | |||
+ | Format the value in lines of n characters, adding m spaces to the start of each new line (not to first line). Each line is ended with " | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {s.fmtlinet, | ||
+ | |||
+ | Format the value in lines of n characters, adding m tabs to the start of each new line (not to first line). Each line is ended with " | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | </ | ||
+ | ==== {s.urlencode.param} ==== | ||
+ | |||
+ | Encode the value for URL param format. | ||
+ | |||
+ | ==== {s.urldecode.param} ==== | ||
+ | |||
+ | Decode the value from URL param format. | ||
+ | |||
===== URI Transformations ===== | ===== URI Transformations ===== | ||
Line 286: | Line 501: | ||
Return the value of r2 parameter | Return the value of r2 parameter | ||
+ | ==== {uri.scheme} ==== | ||
+ | |||
+ | Return the string value of URI scheme. | ||
+ | |||
+ | ==== {uri.tosocket} ==== | ||
+ | |||
+ | Return the string value corresponding to socket address matching proto, address and port from the URI. In other words, converts from a format like **sip: | ||
+ | |||
+ | Example: | ||
+ | |||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {uri.duri} ==== | ||
+ | |||
+ | Return the destination URI for routing, keeping only schema, host, port and transport parameter. If port and transport are not in the original value, they are also not in the returned value. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $var(ouri) = " | ||
+ | $var(duri) = $(var(ouri){uri.duri}); | ||
+ | </ | ||
+ | |||
+ | ==== {uri.saor} ==== | ||
+ | |||
+ | Return the SIP AoR, keeping only schema, user and host. If user is not in the original value, it is also not in the returned value. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $var(ouri) = " | ||
+ | $var(suri) = $(var(ouri){uri.saor}); | ||
+ | </ | ||
+ | |||
+ | ==== {uri.suri} ==== | ||
+ | |||
+ | Return the simple URI for routing, keeping only schema, user, host, port and transport parameter. If user, port and transport are not in the original value, they are also not in the returned value. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $var(ouri) = " | ||
+ | $var(suri) = $(var(ouri){uri.suri}); | ||
+ | </ | ||
===== Parameters List Transformations ===== | ===== Parameters List Transformations ===== | ||
The name of the transformation starts with ' | The name of the transformation starts with ' | ||
- | Available transformations in this class: | + | Available transformations in this class are presented in the next sections. |
+ | |||
+ | **Important Note:** the delimiter cannot be comma (,), because this transformation is using SIP header/URI parameters parser and the comma is a delimiter between serialized SIP header/URI bodies. The workaround is to use the subst transformation to replace the comma with another character that is used then as separator. | ||
- | ==== {param.value, | + | ==== {param.value, |
Return the value of parameter ' | Return the value of parameter ' | ||
Line 304: | Line 567: | ||
' | ' | ||
- | ==== {param.valueat, | + | ' |
+ | |||
+ | ==== {param.in, | ||
+ | |||
+ | Return 1 if the parameter ' | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ' | ||
+ | |||
+ | ' | ||
+ | |||
+ | ==== {param.valueat, | ||
Return the value of parameter at position give by ' | Return the value of parameter at position give by ' | ||
Line 315: | Line 593: | ||
' | ' | ||
- | ==== {param.name, | + | ' |
+ | |||
+ | ==== {param.name, | ||
Return the name of parameter at position ' | Return the name of parameter at position ' | ||
Line 324: | Line 604: | ||
</ | </ | ||
+ | ' | ||
- | ==== {param.count} ==== | + | ==== {param.count[, delimiter]} ==== |
Return the number of parameters in the list. | Return the number of parameters in the list. | ||
Line 333: | Line 614: | ||
" | " | ||
</ | </ | ||
+ | |||
+ | ' | ||
===== Name-address Transformations ===== | ===== Name-address Transformations ===== | ||
Line 395: | Line 678: | ||
* return parameters part from To body | * return parameters part from To body | ||
+ | ===== Line Transformations ===== | ||
+ | |||
+ | Line-based operations on text values. | ||
+ | |||
+ | ==== {line.count} ==== | ||
+ | |||
+ | Return the number of lines. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){line.count}) | ||
+ | </ | ||
+ | |||
+ | ==== {line.at, | ||
+ | |||
+ | Return the line at position ' | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){line.at, | ||
+ | </ | ||
+ | |||
+ | ==== {line.sw, | ||
+ | |||
+ | Return the line starting with **match**. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | $(var(x){line.sw, | ||
+ | </ | ||
+ | |||
+ | ===== MSRP Transformations ===== | ||
+ | |||
+ | <fc # | ||
+ | |||
+ | ==== {msrpuri.user} ==== | ||
+ | |||
+ | User part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.host} ==== | ||
+ | |||
+ | Host part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.port} ==== | ||
+ | |||
+ | Port part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.session} ==== | ||
+ | |||
+ | Session ID part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.proto} ==== | ||
+ | |||
+ | Transport layer part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.params} ==== | ||
+ | |||
+ | Parameters part of a MSRP URI. | ||
+ | |||
+ | ==== {msrpuri.userinfo} ==== | ||
+ | |||
+ | User-Info part of a MSRP URI. This is the same as user part, when there are no user parameters or password fields. Otherwise, it include the whole part after scheme and before ' | ||
===== Regular Expression Transformations ===== | ===== Regular Expression Transformations ===== | ||
<fc # | <fc # | ||
- | |||
==== {re.subst, | ==== {re.subst, | ||
- | Perform | + | Perform |
<code c> | <code c> | ||
Line 446: | Line 793: | ||
$avp(strnr) = " | $avp(strnr) = " | ||
| | ||
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
Output: | Output: | ||
Line 488: | Line 835: | ||
</ | </ | ||
+ | ===== HTTP URL Transformations ===== | ||
+ | <fc # | ||
+ | |||
+ | ==== {url.path} ==== | ||
+ | |||
+ | Path part of an HTTP URL. | ||
+ | |||
+ | For example, | ||
+ | < | ||
+ | # When the first line of HTTP request is | ||
+ | # "GET / | ||
+ | |||
+ | $(hu{url.path}) => "/ | ||
+ | </ | ||
+ | |||
+ | ==== {url.querystring} ==== | ||
+ | |||
+ | Query string part of an HTTP URL. | ||
+ | For example, | ||
+ | |||
+ | < | ||
+ | # When the first line of HTTP request is | ||
+ | # "GET / | ||
+ | |||
+ | $(hu{url.querystring}) => " | ||
+ | </ | ||
+ | |||
+ | ===== JSON Transformations ===== | ||
+ | |||
+ | <fc # | ||
+ | |||
+ | |||
+ | ==== {json.parse} ==== | ||
+ | |||
+ | You can use the transformation to extract values from the json structured pseudo-variables | ||
+ | |||
+ | < | ||
+ | |||
+ | $var(Custom-Data) = $(rb{json.parse, | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Socket Address Transformations ===== | ||
+ | |||
+ | Transformations related to socket address values (**proto: | ||
+ | |||
+ | ==== {sock.host} ==== | ||
+ | |||
+ | Return the host part. | ||
+ | |||
+ | ==== {sock.port} ==== | ||
+ | |||
+ | Return the port part. | ||
+ | |||
+ | ==== {sock.proto} ==== | ||
+ | |||
+ | Return the proto part. | ||
+ | |||
+ | ==== {sock.touri} ==== | ||
+ | |||
+ | Return the socket address converted to SIP URI: **sip: | ||
+ | |||
+ | ===== URI Alias Transformations ===== | ||
+ | |||
+ | Transformations related to URI alias values (**addr~port~protoid**). | ||
+ | |||
+ | ==== {urialias.encode} ==== | ||
+ | |||
+ | Encode SIP URI to alias value. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {urialias.decode} ==== | ||
+ | |||
+ | Decode from alias value to SIP URI. | ||
+ | |||
+ | <code c> | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ===== Value Transformations | ||
+ | |||
+ | Exported by **pv** module. | ||
+ | |||
+ | ==== {val.json} ==== | ||
+ | |||
+ | If value is $null, return empty string; if value is string, then it is escaped for use as json value (without surrounding quotes. | ||
+ | |||
+ | <code c> | ||
+ | $var(x) = '" | ||
+ | $(var(x){val.json}) => \" | ||
+ | </ | ||
+ | |||
+ | ==== {val.n0} ==== | ||
+ | |||
+ | Return integer 0 for values that are $null. | ||
+ | |||
+ | <code c> | ||
+ | $sht(a=> | ||
+ | $(sht(a=> | ||
+ | </ | ||
+ | |||
+ | ==== {val.ne} ==== | ||
+ | |||
+ | Return empty string for values that are $null. | ||
+ | |||
+ | <code c> | ||
+ | $sht(a=> | ||
+ | # $(sht(a=> | ||
+ | </ | ||
+ | |||
+ | ==== {val.jsonqe} ==== | ||
+ | |||
+ | If value is $null, return quoted empty string; if value is string, then it is escaped for use as json value already with surrounding quotes; if the value is int, then it is preserved as it is. | ||
+ | |||
+ | <code c> | ||
+ | $var(x) = '" | ||
+ | $(var(x){val.jsonqe}) => " | ||
+ | </ |
cookbooks/devel/transformations.1324075296.txt.gz · Last modified: 2011/12/16 22:41 by miconda