Kamailio-开源SIP软交换平台

中国第一个专注Kamailio SIP 软交换技术分享平台

用户工具

站点工具


pv_module_holding_pseudo-variables_released

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

pv_module_holding_pseudo-variables_released [2017/09/11 16:18] (当前版本)
james_zhu 创建
行 1: 行 1:
 +====== Pseudo-Variables Module ======
  
 +==== Daniel-Constantin Mierla ====
 +
 +asipto.com\\ ​
 +
 +''<​[[daniel@asipto.com|daniel@asipto.com]]>''​
 +
 +=== Edited by ===
 +
 +==== Daniel-Constantin Mierla ====
 +
 +''<​[[daniel@asipto.com|daniel@asipto.com]]>''​
 +
 +Copyright © 2008-2011 Daniel-Constantin Mierla (asipto.com)
 +
 +Copyright © 2011 Juha Heinanen
 +
 +Copyright © 2013 Olle E. Johansson, Edvina AB
 +
 +----
 +
 +**Table of Contents**
 +
 +  * **1. Admin Guide** ​
 +    * **1. Overview** ​
 +    * **2. Dependencies** ​
 +      * **2.1. Kamailio Modules** ​
 +      * **2.2. External Libraries or Applications** ​
 +    * **3. Parameters** ​
 +      * **3.1. shvset (string)** ​
 +      * **3.2. varset (string)** ​
 +      * **3.3. avp_aliases (string)** ​
 +    * **4. Functions** ​
 +      * **4.1. pv_isset(pvar)** ​
 +      * **4.2. pv_unset(pvar)** ​
 +      * **4.3. is_int(pvar)** ​
 +      * **4.4. typeof(pvar,​ vtype)** ​
 +      * **4.5. not_empty(pvar)** ​
 +      * **4.6. xavp_params_explode(sparams,​ xname)** ​
 +      * **4.7. sbranch_set_ruri()** ​
 +      * **4.8. sbranch_append()** ​
 +      * **4.9. sbranch_reset()** ​
 +      * **4.10. pv_xavp_print()** ​
 +      * **4.11. pv_var_to_xavp(varname,​ xname)** ​
 +      * **4.12. pv_xavp_to_var(xname)** ​
 +      * **4.13. pv_evalx(dst,​ fmt)** ​
 +    * **5. RPC Commands** ​
 +      * **5.1. pv.shvSet** ​
 +      * **5.2. pv.shvGet** ​
 +
 +**List of Examples**
 +
 +  * **1.1. shvset parameter usage** ​
 +  * **1.2. varset parameter usage** ​
 +  * **1.3. avp_aliases parameter usage** ​
 +  * **1.4. pv_isset usage** ​
 +  * **1.5. pv_unset usage** ​
 +  * **1.6. is_int() usage** ​
 +  * **1.7. typeof() usage** ​
 +  * **1.8. not_empty() usage** ​
 +  * **1.9. xavp_params_explode usage** ​
 +  * **1.10. sbranch_set_ruri() usage** ​
 +  * **1.11. sbranch_append() usage** ​
 +  * **1.12. sbranch_append() usage** ​
 +  * **1.13. pv_xavp_print() usage** ​
 +  * **1.14. pv_var_to_xavp() usage** ​
 +  * **1.15. pv_xavp_to_var() usage** ​
 +  * **1.16. pv_xavp_to_var() usage** ​
 +  * **1.17. pv.shvSet usage** ​
 +  * **1.18. pv.shvGet usage** ​
 +
 +====== Chapter 1. Admin Guide ======
 +
 +**Table of Contents**
 +
 +  * **1. Overview** ​
 +  * **2. Dependencies** ​
 +    * **2.1. Kamailio Modules** ​
 +    * **2.2. External Libraries or Applications** ​
 +  * **3. Parameters** ​
 +    * **3.1. shvset (string)** ​
 +    * **3.2. varset (string)** ​
 +    * **3.3. avp_aliases (string)** ​
 +  * **4. Functions** ​
 +    * **4.1. pv_isset(pvar)** ​
 +    * **4.2. pv_unset(pvar)** ​
 +    * **4.3. is_int(pvar)** ​
 +    * **4.4. typeof(pvar,​ vtype)** ​
 +    * **4.5. not_empty(pvar)** ​
 +    * **4.6. xavp_params_explode(sparams,​ xname)** ​
 +    * **4.7. sbranch_set_ruri()** ​
 +    * **4.8. sbranch_append()** ​
 +    * **4.9. sbranch_reset()** ​
 +    * **4.10. pv_xavp_print()** ​
 +    * **4.11. pv_var_to_xavp(varname,​ xname)** ​
 +    * **4.12. pv_xavp_to_var(xname)** ​
 +    * **4.13. pv_evalx(dst,​ fmt)** ​
 +  * **5. RPC Commands** ​
 +    * **5.1. pv.shvSet** ​
 +    * **5.2. pv.shvGet** ​
 +
 +===== 1. Overview =====
 +
 +This module collects the core pseudo-variables that can be used in configuration file. They are listed in wiki: [[https://​www.kamailio.org/​wiki/​|https://​www.kamailio.org/​wiki/​]] in Pseudo-Variables section
 +
 +===== 2. Dependencies =====
 +
 +==== 2.1. Kamailio Modules ====
 +
 +The following modules must be loaded before this module:
 +
 +  * No dependencies on other Kamailio modules. ​
 +
 +==== 2.2. External Libraries or Applications ====
 +
 +The following libraries or applications must be installed before running Kamailio with this module loaded:
 +
 +  * None. 
 +
 +===== 3. Parameters =====
 +
 +==== 3.1. shvset (string) ====
 +
 +Set the value of a shared variable ($shv(name)). The parameter can be set many times.
 +
 +The value of the parameter has the format: _name_ '​='​ _type_ ':'​ _value_
 +
 +  * _name_: shared variable name 
 +  * _type_: type of the value “i”: integer value “s”: string value 
 +  * _value_: value to be set 
 +
 +Default value is “NULL”.
 +
 +**Example 1.1. ''​shvset''​ parameter usage**
 +
 +<​code>​
 +...
 +modparam("​pv",​ "​shvset",​ "​debug=i:​1"​)
 +modparam("​pv",​ "​shvset",​ "​pstngw=s:​sip:​10.10.10.10"​)
 +...
 +</​code>​
 +
 +\\ ==== 3.2. varset (string) ====
 +
 +Set the value of a script variable ($var(name)). The parameter can be set many times.
 +
 +The value of the parameter has the format: _name_ '​='​ _type_ ':'​ _value_
 +
 +  * _name_: shared variable name 
 +  * _type_: type of the value “i”: integer value “s”: string value 
 +  * _value_: value to be set 
 +
 +Default value is “NULL”.
 +
 +**Example 1.2. ''​varset''​ parameter usage**
 +
 +<​code>​
 +...
 +modparam("​pv",​ "​varset",​ "​init=i:​1"​)
 +modparam("​pv",​ "​varset",​ "​gw=s:​sip:​11.11.11.11;​transport=tcp"​)
 +...
 +</​code>​
 +
 +\\ ==== 3.3. avp_aliases (string) ====
 +
 +Define aliases for PV AVP names.
 +
 +Default value is NULL.
 +
 +**Example 1.3. ''​avp_aliases''​ parameter usage**
 +
 +<​code>​
 +...
 +modparam("​pv","​avp_aliases","​email=s:​email_addr;​tmp=i:​100"​)
 +...
 +</​code>​
 +
 +\\ ===== 4. Functions =====
 +
 +==== 4.1. pv_isset(pvar) ====
 +
 +Return true if a PV value is different than '​null'​.
 +
 +Meaning of the parameters is as follows:
 +
 +  * pvar - pvar identifier. ​
 +
 +This function can be used from ANY_ROUTE.
 +
 +**Example 1.4. ''​pv_isset''​ usage**
 +
 +<​code>​
 +...
 +if(pv_isset("​$avp(s:​x)"​))
 +{
 +    ...
 +}
 +...
 +</​code>​
 +
 +\\ ==== 4.2. pv_unset(pvar) ====
 +
 +Unset the value of the PV (e.g., delete AVP, set to null).
 +
 +Meaning of the parameters is as follows:
 +
 +  * pvar - pvar identifier. ​
 +
 +This function can be used from ANY_ROUTE.
 +
 +**Example 1.5. ''​pv_unset''​ usage**
 +
 +<​code>​
 +...
 +pv_unset("​$avp(s:​x)"​);​
 +...
 +</​code>​
 +
 +\\ ==== 4.3. is_int(pvar) ====
 +
 +Function checks if pvar argument contains integer value and returns 1 if it does and -1 otherwise.
 +
 +Function can be used from all kinds of routes.
 +
 +**Example 1.6. ''​is_int()''​ usage**
 +
 +<​code>​
 +...
 +if (is_int("​$var(foo)"​)) {
 +    xlog("​L_INFO",​ "​variable foo contains integer value\n"​);​
 +}
 +...
 +</​code>​
 +
 +\\ ==== 4.4. typeof(pvar,​ vtype) ====
 +
 +Returns true if the type of pseudo-variable matches the second parameter. The second parameter can be: '​int'​ - type is integer; '​str'​ - type is string; '​null'​ - type is null.
 +
 +Function can be used from ANYROUTE.
 +
 +**Example 1.7. ''​typeof()''​ usage**
 +
 +<​code>​
 +...
 +if (typeof("​$var(foo)",​ "​str"​)) {
 +    xdbg("​variable foo is a string\n"​);​
 +}
 +...
 +</​code>​
 +
 +\\ ==== 4.5. not_empty(pvar) ====
 +
 +Returns true if the pseudo-variables has the type string and is not empty value.
 +
 +Function can be used from all kinds of routes.
 +
 +**Example 1.8. ''​not_empty()''​ usage**
 +
 +<​code>​
 +...
 +if (not_empty("​$var(foo)"​)) {
 +    append_hf("​X-Foo:​ $var(foo)\r\n"​);​
 +}
 +...
 +</​code>​
 +
 +\\ ==== 4.6. xavp_params_explode(sparams,​ xname) ====
 +
 +Convert a parameters string in xavp atributes.
 +
 +The first parameter has to be a string in the format of SIP header parameters (name1=value1;​...;​nameN=valueN). The second parameter is the name of the root xavp to hold the pairs (nameX,​valueX).
 +
 +The values are stored as string type.
 +
 +Function can be used from ANY ROUTE.
 +
 +**Example 1.9. ''​xavp_params_explode''​ usage**
 +
 +<​code>​
 +...
 +xavp_params_explode("​a=b;​c=d;​e=d",​ "​x"​);​
 +# results in:
 +#    $xavp(x=>​a) = "​b";​
 +#    $xavp(x=>​c) = "​d";​
 +#    $xavp(x=>​e) = "​f";​
 +...
 +</​code>​
 +
 +\\ ==== 4.7. sbranch_set_ruri() ====
 +
 +Use the attributes from static branch ($sbranch(key) variable) to set request URI and the other fields of the branch associated with request URI (destination URI, path, ...).
 +
 +Content of the static branch is not reset after this function is executed. It has to be done explicitely with sbranch_reset().
 +
 +Function can be used from REQUEST_ROUTE,​ BRANCH_ROUTE or FAILURE_ROUTE.
 +
 +**Example 1.10. ''​sbranch_set_ruri()''​ usage**
 +
 +<​code>​
 +...
 +sbranch_reset();​
 +$sbranch(uri) = "​sip:​127.0.0.1:​5080";​
 +$sbranch(dst_uri) =  "​sip:​127.0.0.1:​5090";​
 +$sbranch(path) =  "​sip:​127.0.0.1:​5090,​ sip:​127.0.0.1:​5094";​
 +$sbranch(send_socket) =  "​udp:​127.0.0.1:​5060";​
 +sbranch_set_ruri();​
 +...
 +</​code>​
 +
 +\\ ==== 4.8. sbranch_append() ====
 +
 +Use the attributes from static branch ($sbranch(key) variable) to append a new branch to destination set. It is an alternative to append_branch() that allows setting each attribute specific to the branch.
 +
 +Content of the static branch is not reset after this function is executed. It has to be done explicitely with sbranch_reset().
 +
 +Function can be used from REQUEST_ROUTE,​ BRANCH_ROUTE or FAILURE_ROUTE.
 +
 +**Example 1.11. ''​sbranch_append()''​ usage**
 +
 +<​code>​
 +...
 +sbranch_reset();​
 +$sbranch(uri) = "​sip:​127.0.0.1:​5080";​
 +$sbranch(dst_uri) =  "​sip:​127.0.0.1:​5090";​
 +$sbranch(send_socket) =  "​udp:​127.0.0.1:​5060";​
 +sbranch_append();​
 +...
 +</​code>​
 +
 +\\ ==== 4.9. sbranch_reset() ====
 +
 +Reset the content of static branch ($sbranch(key) variable.
 +
 +Function can be used from REQUEST_ROUTE,​ BRANCH_ROUTE or FAILURE_ROUTE.
 +
 +**Example 1.12. ''​sbranch_append()''​ usage**
 +
 +<​code>​
 +...
 +sbranch_reset();​
 +...
 +</​code>​
 +
 +\\ ==== 4.10. pv_xavp_print() ====
 +
 +Print all XAVPs to the syslog using INFO log level.
 +
 +Function can be used from ANY_ROUTE.
 +
 +**Example 1.13. ''​pv_xavp_print()''​ usage**
 +
 +<​code>​
 +...
 +pv_xavp_print();​
 +...
 +</​code>​
 +
 +\\ ==== 4.11. pv_var_to_xavp(varname,​ xname) ====
 +
 +Copy the script variable value into an xavp.
 +
 +First parameter can be %%'​*'​%% in order to copy all script variables. Second parameter is the name of the destination xavp. If xavp already exists it will be reset first.
 +
 +Both parameters can contain variables that are evaluated at runtime.
 +
 +Function can be used from ANY_ROUTE.
 +
 +**Example 1.14. ''​pv_var_to_xavp()''​ usage**
 +
 +<​code>​
 +...
 +$var("​temp"​) = 3;
 +$var("​foo"​) = "foo indeed";​
 +pv_var_to_xavp("​temp",​ "​ok"​);​
 +...
 +$xavp("​ok[0]=>​temp"​) now is 3
 +...
 +pv_var_to_xavp("​*",​ "​ok"​);​
 +...
 +$xavp("​ok[0]=>​temp"​) now is 3
 +$xavp("​ok[0]=>​foo"​) now is "foo indeed"​
 +...
 +</​code>​
 +
 +\\ ==== 4.12. pv_xavp_to_var(xname) ====
 +
 +Copy xavp values into vars. Reverse of pv_var_to_xavp().
 +
 +Both parameters can contain variables that are evaluated at runtime.
 +
 +Function can be used from ANY_ROUTE.
 +
 +**Example 1.15. ''​pv_xavp_to_var()''​ usage**
 +
 +<​code>​
 +...
 +$xavp("​bar=>​temp"​) = 3;
 +$xavp("​bar[0]=>​foo"​) = "foo indeed";​
 +pv_xavp_to_var("​bar"​);​
 +...
 +$var("​temp"​) now is 3
 +$var("​foo"​) now is "foo indeed"​
 +...
 +</​code>​
 +
 +\\ ==== 4.13. pv_evalx(dst,​ fmt) ====
 +
 +The fmt string is evaluated twice for exiting variables, the result is stored in dst variable. The dst must be the name of a writable variable. The fmt can contain variables that have a value containing other variables.
 +
 +Function can be used from ANY_ROUTE.
 +
 +**Example 1.16. ''​pv_xavp_to_var()''​ usage**
 +
 +<​code>​
 +...
 +$var(x) = "​test";​
 +$var(y) = "​$var(x)"​
 +pv_evalx("​$var(z)",​ "​$var(y) one");
 +
 +# - the value of $var(z) is "test one"
 +...
 +</​code>​
 +
 +\\ ===== 5. RPC Commands =====
 +
 +==== 5.1. pv.shvSet ====
 +
 +Set the value of a shared variable ($shv(name)).
 +
 +Parameters:
 +
 +  * _name_: shared variable name 
 +  * _type_: type of the value “int”: integer value “str”: string value 
 +  * _value_: value to be set 
 +
 +**Example 1.17. ''​pv.shvSet''​ usage**
 +
 +<​code>​
 +...
 +$ kamcmd pv.shvSet debug int 3
 +...
 +</​code>​
 +
 +\\ ==== 5.2. pv.shvGet ====
 +
 +Get the value of a shared variable ($shv(name)).
 +
 +Parameters:
 +
 +  * _name_: shared variable name 
 +
 +If no name is given, all shared variables are listed.
 +
 +**Example 1.18. ''​pv.shvGet''​ usage**
 +
 +<​code>​
 +...
 +$ kamcmd pv.shvGet debug
 +...
 +</​code>​
 +
 +\\
pv_module_holding_pseudo-variables_released.txt · 最后更改: 2017/09/11 16:18 由 james_zhu