This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
cookbooks:devel:transformations [2014/07/30 14:44] lucian.balaceanu |
cookbooks:devel:transformations [2020/07/17 08:13] miconda |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Kamailio SIP Server | + | ====== |
+ | |||
+ | Version: | ||
< | < | ||
Line 6: | Line 8: | ||
</ | </ | ||
- | **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 114: | 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 122: | Line 133: | ||
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} ==== | ==== {s.encode.base64} ==== | ||
Return base64 encoding of PV value | Return base64 encoding of PV value | ||
- | |||
==== {s.decode.base64} ==== | ==== {s.decode.base64} ==== | ||
Decode base64 encoded PV and return value | 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 161: | 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 262: | Line 334: | ||
$(var(x){s.rm, | $(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> | ||
+ | abababa" | ||
+ | # will return 4 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== {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 326: | Line 452: | ||
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: | ||
+ | |||
+ | < | ||
+ | " | ||
+ | </ | ||
===== 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. | ||
Line 514: | Line 655: | ||
==== {re.subst, | ==== {re.subst, | ||
- | Perform | + | Perform |
<code c> | <code c> | ||
Line 557: | Line 698: | ||
$avp(strnr) = " | $avp(strnr) = " | ||
| | ||
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
- | xlog(" | + | xlog(" |
Output: | Output: | ||
Line 625: | Line 766: | ||
$(hu{url.querystring}) => " | $(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, | ||
+ | |||
</ | </ | ||