Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
transformations:1.2.x [2007/09/21 21:36] – external edit 127.0.0.1 | transformations:1.2.x [2008/03/17 22:35] (current) – 86.121.131.233 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== OpenSER Transformations for Version 1.2.x ====== | ||
+ | < | ||
+ | Main author: | ||
+ | | ||
+ | </ | ||
+ | |||
+ | [b]Transformation[/ | ||
+ | |||
+ | Starting with 1.2.0, all PV can be used directly in the script. For example: | ||
+ | |||
+ | < | ||
+ | # check if username in From header | ||
+ | # is equal with username in To header | ||
+ | if($fU==$tU) { | ||
+ | ... | ||
+ | } | ||
+ | |||
+ | # r-uri username based processing | ||
+ | switch($ruri.user) { | ||
+ | case " | ||
+ | ... | ||
+ | | ||
+ | case " | ||
+ | ... | ||
+ | | ||
+ | | ||
+ | ... | ||
+ | } | ||
+ | |||
+ | # assign integer value to an AVP | ||
+ | $avp(i:11) = 1; | ||
+ | |||
+ | #assing string value to an AVP | ||
+ | $avp(i:22) = " | ||
+ | |||
+ | # write ruri in an AVP | ||
+ | $avp(i:33) = $ruri; | ||
+ | |||
+ | # concat " | ||
+ | # in a script variable x | ||
+ | $var(x) = " | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | 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/ | ||
+ | |||
+ | A transformation is represented in between ' | ||
+ | |||
+ | < | ||
+ | # the length of From URI ($fu is PV for From URI) | ||
+ | |||
+ | $(fu{s.len}) | ||
+ | </ | ||
+ | |||
+ | Many transformations can be applied in the same time to a PV. | ||
+ | |||
+ | < | ||
+ | # the length of escaped ' | ||
+ | |||
+ | $(hdr(Test){s.escape.common}{s.len}) | ||
+ | </ | ||
+ | |||
+ | The transformations can be used anywhere, being considered parts of PV -- in xlog, avpops or other modules' | ||
+ | |||
+ | [color=brown]IMPORTANT[/ | ||
+ | |||
+ | ===== String Transformations ===== | ||
+ | The name of these transformation starts with ' | ||
+ | |||
+ | Available transformations in this class: | ||
+ | |||
+ | |||
+ | ==== {s.len} ==== | ||
+ | |||
+ | Return strlen of PV value | ||
+ | |||
+ | ==== {s.int} ==== | ||
+ | |||
+ | Return integer value of a string-represented number | ||
+ | |||
+ | ==== {s.md5} ==== | ||
+ | |||
+ | Return md5 over PV value | ||
+ | |||
+ | ==== {s.substr, | ||
+ | |||
+ | Return substring starting at offset having size of ' | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {s.select, | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {s.encode.hexa} ==== | ||
+ | |||
+ | Return encoding in hexa of PV value | ||
+ | |||
+ | ==== {s.decode.hexa} ==== | ||
+ | |||
+ | Return decoding from hexa of PV value | ||
+ | |||
+ | ==== {s.escape.common} ==== | ||
+ | |||
+ | Return escaped string of PV value. Characters escaped are ''', | ||
+ | |||
+ | |||
+ | |||
+ | ==== {s.unescape.common} ==== | ||
+ | |||
+ | Return unescaped string of PV value. Reverse of above transformation. | ||
+ | |||
+ | ==== {s.escape.user} ==== | ||
+ | |||
+ | Return escaped string of PV value, changing to ' | ||
+ | |||
+ | ==== {s.unescape.user} ==== | ||
+ | |||
+ | Return unescaped string of PV value, changing ' | ||
+ | |||
+ | |||
+ | ===== URI Transformations ===== | ||
+ | |||
+ | The name of transformation starts with ' | ||
+ | |||
+ | Available transformations in this class: | ||
+ | |||
+ | ==== {uri.user} ==== | ||
+ | |||
+ | Return the user part | ||
+ | |||
+ | ==== {uri.host} ==== | ||
+ | |||
+ | (same as [b]{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, | ||
+ | |||
+ | Return the value of parameter with 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 ' | ||
+ | |||
+ | Available transformations in this class: | ||
+ | |||
+ | ==== {param.value, | ||
+ | |||
+ | Return the value of parameter ' | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== {param.name, | ||
+ | |||
+ | Return the name of parameter at position ' | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | Within a PV, many transformation can be applied, being executed from left to right. | ||
+ | |||
+ | * The length of the value of parameter at postion 1 (remember 0 is first position, 1 is second position) | ||
+ | |||
+ | < | ||
+ | $var(x) = " | ||
+ | $(var(x){param.value, | ||
+ | </ | ||
+ | |||
+ | * Test if whether is un-registration or not | ||
+ | |||
+ | < | ||
+ | if(is_method(" | ||
+ | xlog(" | ||
+ | </ |