| 1 |
Pseudo-Variables Module |
| 2 |
|
| 3 |
Daniel-Constantin Mierla |
| 4 |
|
| 5 |
asipto.com |
| 6 |
<[email protected]> |
| 7 |
|
| 8 |
Edited by |
| 9 |
|
| 10 |
Daniel-Constantin Mierla |
| 11 |
|
| 12 |
<[email protected]> |
| 13 |
|
| 14 |
Copyright © 2008-2011 Daniel-Constantin Mierla (asipto.com) |
| 15 |
|
| 16 |
Copyright © 2011 Juha Heinanen |
| 17 |
|
| 18 |
Copyright © 2013 Olle E. Johansson, Edvina AB |
| 19 |
__________________________________________________________________ |
| 20 |
|
| 21 |
Table of Contents |
| 22 |
|
| 23 |
1. Admin Guide |
| 24 |
|
| 25 |
1. Overview |
| 26 |
2. Dependencies |
| 27 |
|
| 28 |
2.1. Kamailio Modules |
| 29 |
2.2. External Libraries or Applications |
| 30 |
|
| 31 |
3. Parameters |
| 32 |
|
| 33 |
3.1. shvset (string) |
| 34 |
3.2. varset (string) |
| 35 |
3.3. avp_aliases (string) |
| 36 |
|
| 37 |
4. Functions |
| 38 |
|
| 39 |
4.1. pv_isset(pvar) |
| 40 |
4.2. pv_unset(pvar) |
| 41 |
4.3. is_int(pvar) |
| 42 |
4.4. typeof(pvar, vtype) |
| 43 |
4.5. not_empty(pvar) |
| 44 |
4.6. xavp_copy(source_name, source_index, destination_name) |
| 45 |
4.7. xavp_copy(source_name, source_index, destination_name, |
| 46 |
destination_index) |
| 47 |
|
| 48 |
4.8. xavp_params_explode(sparams, xname) |
| 49 |
4.9. xavp_xparams_explode(sparams, sep, xname) |
| 50 |
4.10. xavp_params_implode(xname, pvname) |
| 51 |
4.11. xavp_params_implode_qval(xname, pvname) |
| 52 |
4.12. xavu_params_explode(sparams, xname) |
| 53 |
4.13. xavu_params_implode(xname, pvname) |
| 54 |
4.14. xavp_slist_explode(slist, sep, mode, xname) |
| 55 |
4.15. xavp_child_seti(rname, cname, ival) |
| 56 |
4.16. xavi_child_seti(rname, cname, ival) |
| 57 |
4.17. xavp_child_sets(rname, cname, sval) |
| 58 |
4.18. xavi_child_sets(rname, cname, sval) |
| 59 |
4.19. xavp_rm(rname) |
| 60 |
4.20. xavp_rm_all(rname) |
| 61 |
4.21. xavi_rm(rname) |
| 62 |
4.22. xavi_rm_all(rname) |
| 63 |
4.23. xavp_child_rm(rname, cname) |
| 64 |
4.24. xavi_child_rm(rname, cname) |
| 65 |
4.25. xavp_lshift(xname, idx) |
| 66 |
4.26. xavp_push_dst(xname) |
| 67 |
4.27. sbranch_set_ruri() |
| 68 |
4.28. sbranch_append() |
| 69 |
4.29. sbranch_reset() |
| 70 |
4.30. pv_xavp_print() |
| 71 |
4.31. pv_xavu_print() |
| 72 |
4.32. pv_xavi_print() |
| 73 |
4.33. pv_var_to_xavp(varname, xname) |
| 74 |
4.34. pv_xavp_to_var(xname) |
| 75 |
4.35. pv_evalx(dst, fmt) |
| 76 |
|
| 77 |
5. RPC Commands |
| 78 |
|
| 79 |
5.1. pv.shvSet |
| 80 |
5.2. pv.shvGet |
| 81 |
|
| 82 |
List of Examples |
| 83 |
|
| 84 |
1.1. shvset parameter usage |
| 85 |
1.2. varset parameter usage |
| 86 |
1.3. avp_aliases parameter usage |
| 87 |
1.4. pv_isset usage |
| 88 |
1.5. pv_unset usage |
| 89 |
1.6. is_int() usage |
| 90 |
1.7. typeof() usage |
| 91 |
1.8. not_empty() usage |
| 92 |
1.9. xavp_copy usage |
| 93 |
1.10. xavp_copy usage |
| 94 |
1.11. xavp_params_explode usage |
| 95 |
1.12. xavp_xparams_explode usage |
| 96 |
1.13. xavp_params_implode usage |
| 97 |
1.14. xavp_params_implode_qval usage |
| 98 |
1.15. xavu_params_explode usage |
| 99 |
1.16. xavu_params_implode usage |
| 100 |
1.17. xavp_slist_explode usage |
| 101 |
1.18. xavp_child_seti usage |
| 102 |
1.19. xavi_child_seti usage |
| 103 |
1.20. xavp_child_sets usage |
| 104 |
1.21. xavi_child_sets usage |
| 105 |
1.22. xavp_rm usage |
| 106 |
1.23. xavp_rm_all usage |
| 107 |
1.24. xavi_rm usage |
| 108 |
1.25. xavi_rm_all usage |
| 109 |
1.26. xavp_child_rm usage |
| 110 |
1.27. xavi_child_rm usage |
| 111 |
1.28. xavp_lshift usage |
| 112 |
1.29. xavp_push_dst usage |
| 113 |
1.30. sbranch_set_ruri() usage |
| 114 |
1.31. sbranch_append() usage |
| 115 |
1.32. sbranch_append() usage |
| 116 |
1.33. pv_xavp_print() usage |
| 117 |
1.34. pv_xavu_print() usage |
| 118 |
1.35. pv_xavi_print() usage |
| 119 |
1.36. pv_var_to_xavp() usage |
| 120 |
1.37. pv_xavp_to_var() usage |
| 121 |
1.38. pv_xavp_to_var() usage |
| 122 |
1.39. pv.shvSet usage |
| 123 |
1.40. pv.shvGet usage |
| 124 |
|
| 125 |
Chapter 1. Admin Guide |
| 126 |
|
| 127 |
Table of Contents |
| 128 |
|
| 129 |
1. Overview |
| 130 |
2. Dependencies |
| 131 |
|
| 132 |
2.1. Kamailio Modules |
| 133 |
2.2. External Libraries or Applications |
| 134 |
|
| 135 |
3. Parameters |
| 136 |
|
| 137 |
3.1. shvset (string) |
| 138 |
3.2. varset (string) |
| 139 |
3.3. avp_aliases (string) |
| 140 |
|
| 141 |
4. Functions |
| 142 |
|
| 143 |
4.1. pv_isset(pvar) |
| 144 |
4.2. pv_unset(pvar) |
| 145 |
4.3. is_int(pvar) |
| 146 |
4.4. typeof(pvar, vtype) |
| 147 |
4.5. not_empty(pvar) |
| 148 |
4.6. xavp_copy(source_name, source_index, destination_name) |
| 149 |
4.7. xavp_copy(source_name, source_index, destination_name, |
| 150 |
destination_index) |
| 151 |
|
| 152 |
4.8. xavp_params_explode(sparams, xname) |
| 153 |
4.9. xavp_xparams_explode(sparams, sep, xname) |
| 154 |
4.10. xavp_params_implode(xname, pvname) |
| 155 |
4.11. xavp_params_implode_qval(xname, pvname) |
| 156 |
4.12. xavu_params_explode(sparams, xname) |
| 157 |
4.13. xavu_params_implode(xname, pvname) |
| 158 |
4.14. xavp_slist_explode(slist, sep, mode, xname) |
| 159 |
4.15. xavp_child_seti(rname, cname, ival) |
| 160 |
4.16. xavi_child_seti(rname, cname, ival) |
| 161 |
4.17. xavp_child_sets(rname, cname, sval) |
| 162 |
4.18. xavi_child_sets(rname, cname, sval) |
| 163 |
4.19. xavp_rm(rname) |
| 164 |
4.20. xavp_rm_all(rname) |
| 165 |
4.21. xavi_rm(rname) |
| 166 |
4.22. xavi_rm_all(rname) |
| 167 |
4.23. xavp_child_rm(rname, cname) |
| 168 |
4.24. xavi_child_rm(rname, cname) |
| 169 |
4.25. xavp_lshift(xname, idx) |
| 170 |
4.26. xavp_push_dst(xname) |
| 171 |
4.27. sbranch_set_ruri() |
| 172 |
4.28. sbranch_append() |
| 173 |
4.29. sbranch_reset() |
| 174 |
4.30. pv_xavp_print() |
| 175 |
4.31. pv_xavu_print() |
| 176 |
4.32. pv_xavi_print() |
| 177 |
4.33. pv_var_to_xavp(varname, xname) |
| 178 |
4.34. pv_xavp_to_var(xname) |
| 179 |
4.35. pv_evalx(dst, fmt) |
| 180 |
|
| 181 |
5. RPC Commands |
| 182 |
|
| 183 |
5.1. pv.shvSet |
| 184 |
5.2. pv.shvGet |
| 185 |
|
| 186 |
1. Overview |
| 187 |
|
| 188 |
This module collects the core pseudo-variables that can be used in |
| 189 |
configuration file. They are listed in wiki: |
| 190 |
https://www.kamailio.org/wikidocs/ in Pseudo-Variables section |
| 191 |
|
| 192 |
2. Dependencies |
| 193 |
|
| 194 |
2.1. Kamailio Modules |
| 195 |
2.2. External Libraries or Applications |
| 196 |
|
| 197 |
2.1. Kamailio Modules |
| 198 |
|
| 199 |
The following modules must be loaded before this module: |
| 200 |
* No dependencies on other Kamailio modules. |
| 201 |
|
| 202 |
2.2. External Libraries or Applications |
| 203 |
|
| 204 |
The following libraries or applications must be installed before |
| 205 |
running Kamailio with this module loaded: |
| 206 |
* None. |
| 207 |
|
| 208 |
3. Parameters |
| 209 |
|
| 210 |
3.1. shvset (string) |
| 211 |
3.2. varset (string) |
| 212 |
3.3. avp_aliases (string) |
| 213 |
|
| 214 |
3.1. shvset (string) |
| 215 |
|
| 216 |
Set the initial value of a shared variable ($shv(name)). The parameter |
| 217 |
can be set many times. |
| 218 |
|
| 219 |
The value of the parameter has the format: _name_ '=' _type_ ':' |
| 220 |
_value_ |
| 221 |
* _name_: shared variable name |
| 222 |
* _type_: type of the value |
| 223 |
+ “i”: integer value |
| 224 |
+ “s”: string value |
| 225 |
* _value_: value to be set |
| 226 |
|
| 227 |
Note: this is special useful for usage with KEMI scripts, the $shv(...) |
| 228 |
variables must be defined during Kamailio initialization in order to |
| 229 |
become available in all worker processes. |
| 230 |
|
| 231 |
Default value is “NULL”. |
| 232 |
|
| 233 |
Example 1.1. shvset parameter usage |
| 234 |
... |
| 235 |
modparam("pv", "shvset", "debug=i:1") |
| 236 |
modparam("pv", "shvset", "pstngw=s:sip:10.10.10.10") |
| 237 |
... |
| 238 |
|
| 239 |
3.2. varset (string) |
| 240 |
|
| 241 |
Set the value of a script variable ($var(name)). The parameter can be |
| 242 |
set many times. |
| 243 |
|
| 244 |
The value of the parameter has the format: _name_ '=' _type_ ':' |
| 245 |
_value_ |
| 246 |
* _name_: shared variable name |
| 247 |
* _type_: type of the value |
| 248 |
+ “i”: integer value |
| 249 |
+ “s”: string value |
| 250 |
* _value_: value to be set |
| 251 |
|
| 252 |
Default value is “NULL”. |
| 253 |
|
| 254 |
Example 1.2. varset parameter usage |
| 255 |
... |
| 256 |
modparam("pv", "varset", "init=i:1") |
| 257 |
modparam("pv", "varset", "gw=s:sip:11.11.11.11;transport=tcp") |
| 258 |
... |
| 259 |
|
| 260 |
3.3. avp_aliases (string) |
| 261 |
|
| 262 |
Define aliases for PV AVP names. |
| 263 |
|
| 264 |
Default value is NULL. |
| 265 |
|
| 266 |
Example 1.3. avp_aliases parameter usage |
| 267 |
... |
| 268 |
modparam("pv","avp_aliases","email=s:email_addr;tmp=i:100") |
| 269 |
... |
| 270 |
|
| 271 |
4. Functions |
| 272 |
|
| 273 |
4.1. pv_isset(pvar) |
| 274 |
4.2. pv_unset(pvar) |
| 275 |
4.3. is_int(pvar) |
| 276 |
4.4. typeof(pvar, vtype) |
| 277 |
4.5. not_empty(pvar) |
| 278 |
4.6. xavp_copy(source_name, source_index, destination_name) |
| 279 |
4.7. xavp_copy(source_name, source_index, destination_name, |
| 280 |
destination_index) |
| 281 |
|
| 282 |
4.8. xavp_params_explode(sparams, xname) |
| 283 |
4.9. xavp_xparams_explode(sparams, sep, xname) |
| 284 |
4.10. xavp_params_implode(xname, pvname) |
| 285 |
4.11. xavp_params_implode_qval(xname, pvname) |
| 286 |
4.12. xavu_params_explode(sparams, xname) |
| 287 |
4.13. xavu_params_implode(xname, pvname) |
| 288 |
4.14. xavp_slist_explode(slist, sep, mode, xname) |
| 289 |
4.15. xavp_child_seti(rname, cname, ival) |
| 290 |
4.16. xavi_child_seti(rname, cname, ival) |
| 291 |
4.17. xavp_child_sets(rname, cname, sval) |
| 292 |
4.18. xavi_child_sets(rname, cname, sval) |
| 293 |
4.19. xavp_rm(rname) |
| 294 |
4.20. xavp_rm_all(rname) |
| 295 |
4.21. xavi_rm(rname) |
| 296 |
4.22. xavi_rm_all(rname) |
| 297 |
4.23. xavp_child_rm(rname, cname) |
| 298 |
4.24. xavi_child_rm(rname, cname) |
| 299 |
4.25. xavp_lshift(xname, idx) |
| 300 |
4.26. xavp_push_dst(xname) |
| 301 |
4.27. sbranch_set_ruri() |
| 302 |
4.28. sbranch_append() |
| 303 |
4.29. sbranch_reset() |
| 304 |
4.30. pv_xavp_print() |
| 305 |
4.31. pv_xavu_print() |
| 306 |
4.32. pv_xavi_print() |
| 307 |
4.33. pv_var_to_xavp(varname, xname) |
| 308 |
4.34. pv_xavp_to_var(xname) |
| 309 |
4.35. pv_evalx(dst, fmt) |
| 310 |
|
| 311 |
4.1. pv_isset(pvar) |
| 312 |
|
| 313 |
Return true if a PV value is different than 'null'. |
| 314 |
|
| 315 |
Meaning of the parameters is as follows: |
| 316 |
* pvar - pvar identifier. |
| 317 |
|
| 318 |
This function can be used from ANY_ROUTE. |
| 319 |
|
| 320 |
Example 1.4. pv_isset usage |
| 321 |
... |
| 322 |
if(pv_isset("$avp(s:x)")) |
| 323 |
{ |
| 324 |
... |
| 325 |
} |
| 326 |
... |
| 327 |
|
| 328 |
4.2. pv_unset(pvar) |
| 329 |
|
| 330 |
Unset the value of the PV (e.g., delete AVP, set to null). |
| 331 |
|
| 332 |
Meaning of the parameters is as follows: |
| 333 |
* pvar - pvar identifier. |
| 334 |
|
| 335 |
This function can be used from ANY_ROUTE. |
| 336 |
|
| 337 |
Example 1.5. pv_unset usage |
| 338 |
... |
| 339 |
pv_unset("$avp(s:x)"); |
| 340 |
... |
| 341 |
|
| 342 |
4.3. is_int(pvar) |
| 343 |
|
| 344 |
Function checks if pvar argument contains integer value and returns 1 |
| 345 |
if it does and -1 otherwise. |
| 346 |
|
| 347 |
Function can be used from all kinds of routes. |
| 348 |
|
| 349 |
Example 1.6. is_int() usage |
| 350 |
... |
| 351 |
if (is_int("$var(foo)")) { |
| 352 |
xlog("L_INFO", "variable foo contains integer value\n"); |
| 353 |
} |
| 354 |
... |
| 355 |
|
| 356 |
4.4. typeof(pvar, vtype) |
| 357 |
|
| 358 |
Returns true if the type of pseudo-variable matches the second |
| 359 |
parameter. The second parameter can be: 'int' - type is integer; 'str' |
| 360 |
- type is string; 'null' - type is null. |
| 361 |
|
| 362 |
Function can be used from ANYROUTE. |
| 363 |
|
| 364 |
Example 1.7. typeof() usage |
| 365 |
... |
| 366 |
if (typeof("$var(foo)", "str")) { |
| 367 |
xdbg("variable foo is a string\n"); |
| 368 |
} |
| 369 |
... |
| 370 |
|
| 371 |
4.5. not_empty(pvar) |
| 372 |
|
| 373 |
Returns true if the pseudo-variables has the type string and is not |
| 374 |
empty value. |
| 375 |
|
| 376 |
Function can be used from all kinds of routes. |
| 377 |
|
| 378 |
Example 1.8. not_empty() usage |
| 379 |
... |
| 380 |
if (not_empty("$var(foo)")) { |
| 381 |
append_hf("X-Foo: $var(foo)\r\n"); |
| 382 |
} |
| 383 |
... |
| 384 |
|
| 385 |
4.6. xavp_copy(source_name, source_index, destination_name) |
| 386 |
|
| 387 |
Copy and append one XAVP. |
| 388 |
|
| 389 |
The parameters can be variables or strings. First parameter is the |
| 390 |
source XAVP name. Second parameter is the source XAVP stack index, use |
| 391 |
0 to copy the last assigned XAVP. Third parameter is the destination |
| 392 |
XAVP name, if found the XAVP will be appended else it will be created. |
| 393 |
|
| 394 |
Function can be used from ANY ROUTE. |
| 395 |
|
| 396 |
Example 1.9. xavp_copy usage |
| 397 |
... |
| 398 |
# Using xavp_copy to reorder an existing xavp stack in a new one |
| 399 |
$xavp(a=>x) = "a-0-x"; |
| 400 |
$xavp(a[0]=>y) = "a-0-y"; |
| 401 |
$xavp(a=>x) = "a-1-x"; |
| 402 |
$xavp(a[0]=>y) = "a-1-y"; |
| 403 |
$xavp(a=>x) = "a-2-x"; |
| 404 |
$xavp(a[0]=>y) = "a-2-y"; |
| 405 |
|
| 406 |
xinfo("BEFORE $xavp(a[0]=>x) == [a-2-x] == $xavp(a[0]=>y) == [a-2-y]\n"); |
| 407 |
xinfo("BEFORE $xavp(a[1]=>x) == [a-1-x] == $xavp(a[1]=>y) == [a-1-y]\n"); |
| 408 |
xinfo("BEFORE $xavp(a[2]=>x) == [a-0-x] == $xavp(a[2]=>y) == [a-0-y]\n"); |
| 409 |
|
| 410 |
# reorder |
| 411 |
$var(source_index) = 1; |
| 412 |
$var(destination_name) = "b"; |
| 413 |
xavp_copy("a", "2", "b"); |
| 414 |
xavp_copy("a", "$var(source_index)", "$var(destination_name)"); |
| 415 |
xavp_copy("a", "0", "$var(destination_name)"); |
| 416 |
|
| 417 |
xinfo("AFTER $xavp(b[0]=>x) == [a-0-x] == $xavp(b[0]=>y) == [a-0-y]\n"); |
| 418 |
xinfo("AFTER $xavp(b[1]=>x) == [a-1-x] == $xavp(b[1]=>y) == [a-1-y]\n"); |
| 419 |
xinfo("AFTER $xavp(b[2]=>x) == [a-2-x] == $xavp(b[2]=>y) == [a-2-y]\n"); |
| 420 |
... |
| 421 |
|
| 422 |
4.7. xavp_copy(source_name, source_index, destination_name, |
| 423 |
destination_index) |
| 424 |
|
| 425 |
Copy and replace one XAVP. |
| 426 |
|
| 427 |
The parameters can be variables or strings. First parameter is the |
| 428 |
source XAVP name. Second parameter is the source XAVP stack index, use |
| 429 |
0 to copy the last assigned XAVP. Third parameter is the destination |
| 430 |
XAVP name, if not found xavp_copy will return -1. Fourth parameter is |
| 431 |
the destination XAVP index, if not found xavp_copy will return -1. |
| 432 |
|
| 433 |
Function can be used from ANY ROUTE. |
| 434 |
|
| 435 |
Example 1.10. xavp_copy usage |
| 436 |
... |
| 437 |
# Using xavp_copy to reorder an existing xavp stack inplace |
| 438 |
$xavp(d=>x) = "d-0-x"; |
| 439 |
$xavp(d[0]=>y) = "d-0-y"; |
| 440 |
$xavp(d=>x) = "d-1-x"; |
| 441 |
$xavp(d[0]=>y) = "d-1-y"; |
| 442 |
$xavp(d=>x) = "d-2-x"; |
| 443 |
$xavp(d[0]=>y) = "d-2-y"; |
| 444 |
|
| 445 |
xinfo("NEW $xavp(d[0]=>x) == [d-2-x] and $xavp(d[0]=>y) == [d-2-y]\n"); |
| 446 |
xinfo("NEW $xavp(d[1]=>x) == [d-1-x] and $xavp(d[1]=>y) == [d-1-y]\n"); |
| 447 |
xinfo("NEW $xavp(d[2]=>x) == [d-0-x] and $xavp(d[2]=>y) == [d-0-y]\n"); |
| 448 |
|
| 449 |
xavp_copy("d", "0", "e"); |
| 450 |
xavp_copy("d", "2", "d", "0"); |
| 451 |
xavp_copy("e", "0", "d", "2"); |
| 452 |
|
| 453 |
xinfo("AFTER $xavp(d[0]=>x) == [d-0-x] $xavp(d[0]=>y) == [d-0-y]\n"); |
| 454 |
xinfo("AFTER $xavp(d[1]=>x) == [d-1-x] $xavp(d[1]=>y) == [d-1-y]\n"); |
| 455 |
xinfo("AFTER $xavp(d[2]=>x) == [d-2-x] $xavp(d[2]=>y) == [d-2-y]\n"); |
| 456 |
... |
| 457 |
|
| 458 |
4.8. xavp_params_explode(sparams, xname) |
| 459 |
|
| 460 |
Convert a parameters string in xavp attributes. |
| 461 |
|
| 462 |
The first parameter has to be a string in the format of SIP header |
| 463 |
parameters (name1=value1;...;nameN=valueN). The second parameter is the |
| 464 |
name of the root xavp to hold the pairs (nameX,valueX). |
| 465 |
|
| 466 |
The values are stored as string type. |
| 467 |
|
| 468 |
Function can be used from ANY ROUTE. |
| 469 |
|
| 470 |
Example 1.11. xavp_params_explode usage |
| 471 |
... |
| 472 |
xavp_params_explode("a=b;c=d;e=d", "x"); |
| 473 |
# results in: |
| 474 |
# $xavp(x=>a) = "b"; |
| 475 |
# $xavp(x=>c) = "d"; |
| 476 |
# $xavp(x=>e) = "f"; |
| 477 |
... |
| 478 |
|
| 479 |
4.9. xavp_xparams_explode(sparams, sep, xname) |
| 480 |
|
| 481 |
Convert a parameters string in xavp attributes. |
| 482 |
|
| 483 |
The first parameter has to be a string in similar format of SIP header |
| 484 |
parameters (name1=value1;...;nameN=valueN), but the separator can be |
| 485 |
other character than ';'. The second parameter is the separator for the |
| 486 |
parameters list. The third parameter is the name of the root xavp to |
| 487 |
hold the pairs (nameX,valueX). |
| 488 |
|
| 489 |
The values are stored as string type. |
| 490 |
|
| 491 |
Function can be used from ANY ROUTE. |
| 492 |
|
| 493 |
Example 1.12. xavp_xparams_explode usage |
| 494 |
... |
| 495 |
xavp_xparams_explode("a=b,c=d,e=d", ",", "x"); |
| 496 |
# results in: |
| 497 |
# $xavp(x=>a) = "b"; |
| 498 |
# $xavp(x=>c) = "d"; |
| 499 |
# $xavp(x=>e) = "f"; |
| 500 |
... |
| 501 |
|
| 502 |
4.10. xavp_params_implode(xname, pvname) |
| 503 |
|
| 504 |
Serialize the subfields in an XAVP to a parameters string format. |
| 505 |
|
| 506 |
Number values are serialized as unsigned integer string format. |
| 507 |
|
| 508 |
The first parameter has to be the name of XAVP (only the string name, |
| 509 |
not the in $xavp(name)). The second parameter is the name of output |
| 510 |
variable (in full name, like $var(output)). |
| 511 |
|
| 512 |
The value is stored as string type. |
| 513 |
|
| 514 |
Function can be used from ANY ROUTE. |
| 515 |
|
| 516 |
Example 1.13. xavp_params_implode usage |
| 517 |
... |
| 518 |
$xavp(x=>e) = "f"; |
| 519 |
$xavp(x[0]=>c) = "d"; |
| 520 |
$xavp(x[0]=>a) = "b"; |
| 521 |
xavp_params_implode("x", "$var(out)"); |
| 522 |
# results in: $var(out) is "a=b;c=d;e=f;" |
| 523 |
... |
| 524 |
|
| 525 |
4.11. xavp_params_implode_qval(xname, pvname) |
| 526 |
|
| 527 |
Serialize the subfields in an XAVP to a parameters string format, |
| 528 |
enclosing string values in double quotes. |
| 529 |
|
| 530 |
Number values are serialized as unsigned integer string format. |
| 531 |
|
| 532 |
The first parameter has to be the name of XAVP (only the string name, |
| 533 |
not the in $xavp(name)). The second parameter is the name of output |
| 534 |
variable (in full name, like $var(output)). |
| 535 |
|
| 536 |
The value is stored as string type. |
| 537 |
|
| 538 |
Function can be used from ANY ROUTE. |
| 539 |
|
| 540 |
Example 1.14. xavp_params_implode_qval usage |
| 541 |
... |
| 542 |
$xavp(x=>e) = "f"; |
| 543 |
$xavp(x[0]=>c) = 5; |
| 544 |
$xavp(x[0]=>a) = "b"; |
| 545 |
xavp_params_implode("x", "$var(out)"); |
| 546 |
# results in: $var(out) is: a="b";c=5;e="f"; |
| 547 |
... |
| 548 |
|
| 549 |
4.12. xavu_params_explode(sparams, xname) |
| 550 |
|
| 551 |
Convert a parameters string in xavu attributes. |
| 552 |
|
| 553 |
The first parameter has to be a string in the format of SIP header |
| 554 |
parameters (name1=value1;...;nameN=valueN). The second parameter is the |
| 555 |
name of the root xavu to hold the pairs (nameX,valueX). |
| 556 |
|
| 557 |
The values are stored as string type. |
| 558 |
|
| 559 |
Function can be used from ANY ROUTE. |
| 560 |
|
| 561 |
Example 1.15. xavu_params_explode usage |
| 562 |
... |
| 563 |
xavu_params_explode("a=b;c=d;e=d", "x"); |
| 564 |
# results in: |
| 565 |
# $xavu(x=>a) = "b"; |
| 566 |
# $xavu(x=>c) = "d"; |
| 567 |
# $xavu(x=>e) = "f"; |
| 568 |
... |
| 569 |
|
| 570 |
4.13. xavu_params_implode(xname, pvname) |
| 571 |
|
| 572 |
Serialize the subfields in an XAUP to a parameters string format. |
| 573 |
|
| 574 |
Number values are serialized as unsigned integer string format. |
| 575 |
|
| 576 |
The first parameter has to be the name of XAVU (only the string name, |
| 577 |
not the in $xavu(name)). The second parameter is the name of output |
| 578 |
variable (in full name, like $var(output)). |
| 579 |
|
| 580 |
The value is stored as string type. |
| 581 |
|
| 582 |
Function can be used from ANY ROUTE. |
| 583 |
|
| 584 |
Example 1.16. xavu_params_implode usage |
| 585 |
... |
| 586 |
$xavu(x=>e) = "f"; |
| 587 |
$xavu(x=>c) = "d"; |
| 588 |
$xavu(x=>a) = "b"; |
| 589 |
xavu_params_implode("x", "$var(out)"); |
| 590 |
# results in: $var(out) is "a=b;c=d;e=f;" |
| 591 |
... |
| 592 |
|
| 593 |
4.14. xavp_slist_explode(slist, sep, mode, xname) |
| 594 |
|
| 595 |
Breaks a string list in tokens by separators and stores them in XAVPs. |
| 596 |
Note that is not storing empty values. |
| 597 |
|
| 598 |
The first parameter has to be a string (static or with variables). |
| 599 |
|
| 600 |
The second parameter has to contain separator characters (they can be |
| 601 |
many). |
| 602 |
|
| 603 |
The third parameter is mode, controlling the behaviour of extracting |
| 604 |
the tokens, the supported mode right now is 't', which trims the white |
| 605 |
spaces around the value. |
| 606 |
|
| 607 |
The fourth parameter is the name of the root xavp to hold the tokens in |
| 608 |
fields named 'v' and indexed from 0. |
| 609 |
|
| 610 |
The values are stored as string type. |
| 611 |
|
| 612 |
Function can be used from ANY ROUTE. |
| 613 |
|
| 614 |
Example 1.17. xavp_slist_explode usage |
| 615 |
... |
| 616 |
xavp_slist_explode("a=b; c=d;", "=;", "t", "x"); |
| 617 |
# results in: |
| 618 |
# $xavp(x[0]=>v[0]) = "a"; |
| 619 |
# $xavp(x[0]=>v[1]) = "b"; |
| 620 |
# $xavp(x[0]=>v[2]) = "c"; |
| 621 |
# $xavp(x[0]=>v[3]) = "d"; |
| 622 |
... |
| 623 |
|
| 624 |
4.15. xavp_child_seti(rname, cname, ival) |
| 625 |
|
| 626 |
Set the value of $xavp(rname=>cname) to integer value ival. |
| 627 |
|
| 628 |
The first parameter has to be the name of XAVP in the root list. The |
| 629 |
second parameter name of child XAVP. The third parameter can be an |
| 630 |
integer number or a variable holding an integer. |
| 631 |
|
| 632 |
Function can be used from ANY ROUTE. |
| 633 |
|
| 634 |
Example 1.18. xavp_child_seti usage |
| 635 |
... |
| 636 |
$var(n) = 10; |
| 637 |
xavp_child_seti("x", "y", "$var(n)"); |
| 638 |
# results in: $xavp(x=>y) is 10 |
| 639 |
... |
| 640 |
|
| 641 |
4.16. xavi_child_seti(rname, cname, ival) |
| 642 |
|
| 643 |
Set the value of $xavi(rname=>cname) to integer value ival. |
| 644 |
|
| 645 |
The first parameter has to be the name of XAVI in the root list. The |
| 646 |
second parameter name of child XAVI. The third parameter can be an |
| 647 |
integer number or a variable holding an integer. |
| 648 |
|
| 649 |
Function can be used from ANY ROUTE. |
| 650 |
|
| 651 |
Example 1.19. xavi_child_seti usage |
| 652 |
... |
| 653 |
$var(n) = 10; |
| 654 |
xavi_child_seti("WhatEver", "FoO", "$var(n)"); |
| 655 |
# results in: $xavi(whatever=>foo) is 10 |
| 656 |
... |
| 657 |
|
| 658 |
4.17. xavp_child_sets(rname, cname, sval) |
| 659 |
|
| 660 |
Set the value of $xavp(rname=>cname) to string value sval. |
| 661 |
|
| 662 |
The first parameter has to be the name of XAVP in the root list. The |
| 663 |
second parameter name of child XAVP. The third parameter can be a |
| 664 |
static or dynamic (with variables) string. |
| 665 |
|
| 666 |
Function can be used from ANY ROUTE. |
| 667 |
|
| 668 |
Example 1.20. xavp_child_sets usage |
| 669 |
... |
| 670 |
$var(n) = 10; |
| 671 |
xavp_child_sets("x", "y", "Count: $var(n)"); |
| 672 |
# results in: $xavp(x=>y) is "Count: 10" |
| 673 |
... |
| 674 |
|
| 675 |
4.18. xavi_child_sets(rname, cname, sval) |
| 676 |
|
| 677 |
Set the value of $xavi(rname=>cname) to string value sval. |
| 678 |
|
| 679 |
The first parameter has to be the name of XAVI in the root list. The |
| 680 |
second parameter name of child XAVI. The third parameter can be a |
| 681 |
static or dynamic (with variables) string. |
| 682 |
|
| 683 |
Function can be used from ANY ROUTE. |
| 684 |
|
| 685 |
Example 1.21. xavi_child_sets usage |
| 686 |
... |
| 687 |
$var(n) = 10; |
| 688 |
xavi_child_sets("WhatEver", "FoO", "Count: $var(n)"); |
| 689 |
# results in: $xavi(whatever=>foo) is "Count: 10" |
| 690 |
... |
| 691 |
|
| 692 |
4.19. xavp_rm(rname) |
| 693 |
|
| 694 |
Remove the value of $xavp(rname). |
| 695 |
|
| 696 |
The parameter has to be the name of XAVP in the root list. It can be |
| 697 |
static or dynamic string (to include variables). |
| 698 |
|
| 699 |
Function can be used from ANY ROUTE. |
| 700 |
|
| 701 |
Example 1.22. xavp_rm usage |
| 702 |
... |
| 703 |
xavp_rm("x"); |
| 704 |
# same result as: $xavp(x) = $null; |
| 705 |
... |
| 706 |
|
| 707 |
4.20. xavp_rm_all(rname) |
| 708 |
|
| 709 |
Remove all the values of $xavp(rname). |
| 710 |
|
| 711 |
The parameter has to be the name of XAVP in the root list. It can be |
| 712 |
static or dynamic string (to include variables). |
| 713 |
|
| 714 |
Function can be used from ANY ROUTE. |
| 715 |
|
| 716 |
Example 1.23. xavp_rm_all usage |
| 717 |
... |
| 718 |
xavp_rm_all("x"); |
| 719 |
... |
| 720 |
|
| 721 |
4.21. xavi_rm(rname) |
| 722 |
|
| 723 |
Remove the value of $xavi(rname). |
| 724 |
|
| 725 |
The parameter has to be the name of XAVI in the root list. It can be |
| 726 |
static or dynamic string (to include variables). |
| 727 |
|
| 728 |
Function can be used from ANY ROUTE. |
| 729 |
|
| 730 |
Example 1.24. xavi_rm usage |
| 731 |
... |
| 732 |
xavi_rm("WhatEver"); |
| 733 |
# same result as: $xavi(whatever) = $null; |
| 734 |
... |
| 735 |
|
| 736 |
4.22. xavi_rm_all(rname) |
| 737 |
|
| 738 |
Remove all the values of $xavi(rname). |
| 739 |
|
| 740 |
The parameter has to be the name of XAVI in the root list. It can be |
| 741 |
static or dynamic string (to include variables). |
| 742 |
|
| 743 |
Function can be used from ANY ROUTE. |
| 744 |
|
| 745 |
Example 1.25. xavi_rm_all usage |
| 746 |
... |
| 747 |
xavi_rm_all("WhatEver"); |
| 748 |
... |
| 749 |
|
| 750 |
4.23. xavp_child_rm(rname, cname) |
| 751 |
|
| 752 |
Remove the value of $xavp(rname=>cname). |
| 753 |
|
| 754 |
The first parameter has to be the name of XAVP in the root list. The |
| 755 |
second parameter name of child XAVP. Both parameters can be static or |
| 756 |
dynamic strings (to include variables). |
| 757 |
|
| 758 |
Function can be used from ANY ROUTE. |
| 759 |
|
| 760 |
Example 1.26. xavp_child_rm usage |
| 761 |
... |
| 762 |
xavp_child_rm("x", "y"); |
| 763 |
# same result as: $xavp(x=>y) = $null; |
| 764 |
... |
| 765 |
|
| 766 |
4.24. xavi_child_rm(rname, cname) |
| 767 |
|
| 768 |
Remove the value of $xavi(rname=>cname). |
| 769 |
|
| 770 |
The first parameter has to be the name of XAVI in the root list. The |
| 771 |
second parameter name of child XAVI. Both parameters can be static or |
| 772 |
dynamic strings (to include variables). |
| 773 |
|
| 774 |
Function can be used from ANY ROUTE. |
| 775 |
|
| 776 |
Example 1.27. xavi_child_rm usage |
| 777 |
... |
| 778 |
xavi_child_rm("WhatEver", "FoO"); |
| 779 |
# same result as: $xavi(whatever=>foo) = $null; |
| 780 |
... |
| 781 |
|
| 782 |
4.25. xavp_lshift(xname, idx) |
| 783 |
|
| 784 |
Left shift with rotation of the xavps with name xname so that the one |
| 785 |
at the index idx becomes the first and the ones before it are at the |
| 786 |
end of the list. |
| 787 |
|
| 788 |
The first parameter has to be the name of XAVP in the root list. |
| 789 |
|
| 790 |
The second parameter is the index of the XAVP that becomes the first |
| 791 |
one (if it is greater than the number of XAVPs, modulo operation is |
| 792 |
done first; if it is negative, it counts from the end of the list). |
| 793 |
|
| 794 |
The parameters can be with variables. |
| 795 |
|
| 796 |
Function can be used from ANY ROUTE. |
| 797 |
|
| 798 |
Example 1.28. xavp_lshift usage |
| 799 |
... |
| 800 |
$xavp(n) = 10; |
| 801 |
$xavp(n) = 20; |
| 802 |
$xavp(n) = 30; |
| 803 |
xavp_lshift("n", "1"); |
| 804 |
# results in: $xavp(n) having the list of values 20 30 10 |
| 805 |
... |
| 806 |
|
| 807 |
4.26. xavp_push_dst(xname) |
| 808 |
|
| 809 |
Set destination fields from XAVP attributes. |
| 810 |
|
| 811 |
The first parameter has to be the name of XAVP in the root list. |
| 812 |
|
| 813 |
The parameters can be with variables. |
| 814 |
|
| 815 |
The attributes that can be stored in the XAVP fields: |
| 816 |
* uri: SIP URI address to set R-URI |
| 817 |
* dsturi: SIP URI address to set DST-URI |
| 818 |
* socket: listen address to set outgoing socket |
| 819 |
|
| 820 |
Function can be used from REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE. |
| 821 |
|
| 822 |
Example 1.29. xavp_push_dst usage |
| 823 |
... |
| 824 |
$xavp(dst=>uri) = "sip:[email protected]"; |
| 825 |
$xavp(dst[0]=>dsturi) = "sip:proxy.com"; |
| 826 |
$xavp(dst[0]=>socket) = "udp:1.2.3.4:5060"; |
| 827 |
xavp_push_dst("dst"); |
| 828 |
... |
| 829 |
|
| 830 |
4.27. sbranch_set_ruri() |
| 831 |
|
| 832 |
Use the attributes from static branch ($sbranch(key) variable) to set |
| 833 |
request URI and the other fields of the branch associated with request |
| 834 |
URI (destination URI, path, ...). |
| 835 |
|
| 836 |
Content of the static branch is not reset after this function is |
| 837 |
executed. It has to be done explicitly with sbranch_reset(). |
| 838 |
|
| 839 |
Function can be used from REQUEST_ROUTE, BRANCH_ROUTE or FAILURE_ROUTE. |
| 840 |
|
| 841 |
Example 1.30. sbranch_set_ruri() usage |
| 842 |
... |
| 843 |
sbranch_reset(); |
| 844 |
$sbranch(uri) = "sip:127.0.0.1:5080"; |
| 845 |
$sbranch(dst_uri) = "sip:127.0.0.1:5090"; |
| 846 |
$sbranch(path) = "sip:127.0.0.1:5090, sip:127.0.0.1:5094"; |
| 847 |
$sbranch(send_socket) = "udp:127.0.0.1:5060"; |
| 848 |
sbranch_set_ruri(); |
| 849 |
... |
| 850 |
|
| 851 |
4.28. sbranch_append() |
| 852 |
|
| 853 |
Use the attributes from static branch ($sbranch(key) variable) to |
| 854 |
append a new branch to destination set. It is an alternative to |
| 855 |
append_branch() that allows setting each attribute specific to the |
| 856 |
branch. |
| 857 |
|
| 858 |
Content of the static branch is not reset after this function is |
| 859 |
executed. It has to be done explicitly with sbranch_reset(). |
| 860 |
|
| 861 |
Function can be used from REQUEST_ROUTE, BRANCH_ROUTE or FAILURE_ROUTE. |
| 862 |
|
| 863 |
Example 1.31. sbranch_append() usage |
| 864 |
... |
| 865 |
sbranch_reset(); |
| 866 |
$sbranch(uri) = "sip:127.0.0.1:5080"; |
| 867 |
$sbranch(dst_uri) = "sip:127.0.0.1:5090"; |
| 868 |
$sbranch(send_socket) = "udp:127.0.0.1:5060"; |
| 869 |
sbranch_append(); |
| 870 |
... |
| 871 |
|
| 872 |
4.29. sbranch_reset() |
| 873 |
|
| 874 |
Reset the content of static branch ($sbranch(key) variable. |
| 875 |
|
| 876 |
Function can be used from REQUEST_ROUTE, BRANCH_ROUTE or FAILURE_ROUTE. |
| 877 |
|
| 878 |
Example 1.32. sbranch_append() usage |
| 879 |
... |
| 880 |
sbranch_reset(); |
| 881 |
... |
| 882 |
|
| 883 |
4.30. pv_xavp_print() |
| 884 |
|
| 885 |
Print all XAVPs to the syslog using INFO log level. |
| 886 |
|
| 887 |
Function can be used from ANY_ROUTE. |
| 888 |
|
| 889 |
Example 1.33. pv_xavp_print() usage |
| 890 |
... |
| 891 |
pv_xavp_print(); |
| 892 |
... |
| 893 |
|
| 894 |
4.31. pv_xavu_print() |
| 895 |
|
| 896 |
Print all XAVUs to the syslog using INFO log level. |
| 897 |
|
| 898 |
Function can be used from ANY_ROUTE. |
| 899 |
|
| 900 |
Example 1.34. pv_xavu_print() usage |
| 901 |
... |
| 902 |
pv_xavu_print(); |
| 903 |
... |
| 904 |
|
| 905 |
4.32. pv_xavi_print() |
| 906 |
|
| 907 |
Print all XAVIs to the syslog using INFO log level. |
| 908 |
|
| 909 |
Function can be used from ANY_ROUTE. |
| 910 |
|
| 911 |
Example 1.35. pv_xavi_print() usage |
| 912 |
... |
| 913 |
pv_xavi_print(); |
| 914 |
... |
| 915 |
|
| 916 |
4.33. pv_var_to_xavp(varname, xname) |
| 917 |
|
| 918 |
Copy the script variable value into an xavp. |
| 919 |
|
| 920 |
First parameter can be '*' in order to copy all script variables. |
| 921 |
Second parameter is the name of the destination xavp. If xavp already |
| 922 |
exists it will be reset first. |
| 923 |
|
| 924 |
Both parameters can contain variables that are evaluated at runtime. |
| 925 |
|
| 926 |
Function can be used from ANY_ROUTE. |
| 927 |
|
| 928 |
Example 1.36. pv_var_to_xavp() usage |
| 929 |
... |
| 930 |
$var("temp") = 3; |
| 931 |
$var("foo") = "foo indeed"; |
| 932 |
pv_var_to_xavp("temp", "ok"); |
| 933 |
... |
| 934 |
$xavp("ok[0]=>temp") now is 3 |
| 935 |
... |
| 936 |
pv_var_to_xavp("*", "ok"); |
| 937 |
... |
| 938 |
$xavp("ok[0]=>temp") now is 3 |
| 939 |
$xavp("ok[0]=>foo") now is "foo indeed" |
| 940 |
... |
| 941 |
|
| 942 |
4.34. pv_xavp_to_var(xname) |
| 943 |
|
| 944 |
Copy xavp values into vars. Reverse of pv_var_to_xavp(). |
| 945 |
|
| 946 |
Both parameters can contain variables that are evaluated at runtime. |
| 947 |
|
| 948 |
Function can be used from ANY_ROUTE. |
| 949 |
|
| 950 |
Example 1.37. pv_xavp_to_var() usage |
| 951 |
... |
| 952 |
$xavp("bar=>temp") = 3; |
| 953 |
$xavp("bar[0]=>foo") = "foo indeed"; |
| 954 |
pv_xavp_to_var("bar"); |
| 955 |
... |
| 956 |
$var("temp") now is 3 |
| 957 |
$var("foo") now is "foo indeed" |
| 958 |
... |
| 959 |
|
| 960 |
4.35. pv_evalx(dst, fmt) |
| 961 |
|
| 962 |
The fmt string is evaluated twice for exiting variables, the result is |
| 963 |
stored in dst variable. The dst must be the name of a writable |
| 964 |
variable. The fmt can contain variables that have a value containing |
| 965 |
other variables. |
| 966 |
|
| 967 |
Function can be used from ANY_ROUTE. |
| 968 |
|
| 969 |
Example 1.38. pv_xavp_to_var() usage |
| 970 |
... |
| 971 |
$var(x) = "test"; |
| 972 |
$var(y) = "$var(x)" |
| 973 |
pv_evalx("$var(z)", "$var(y) one"); |
| 974 |
|
| 975 |
# - the value of $var(z) is "test one" |
| 976 |
... |
| 977 |
|
| 978 |
5. RPC Commands |
| 979 |
|
| 980 |
5.1. pv.shvSet |
| 981 |
5.2. pv.shvGet |
| 982 |
|
| 983 |
5.1. pv.shvSet |
| 984 |
|
| 985 |
Set the value of a shared variable ($shv(name)). |
| 986 |
|
| 987 |
Parameters: |
| 988 |
* _name_: shared variable name |
| 989 |
* _type_: type of the value |
| 990 |
+ “int”: integer value |
| 991 |
+ “str”: string value |
| 992 |
* _value_: value to be set |
| 993 |
|
| 994 |
Example 1.39. pv.shvSet usage |
| 995 |
... |
| 996 |
$ kamctl rpc pv.shvSet debug int 3 |
| 997 |
... |
| 998 |
|
| 999 |
5.2. pv.shvGet |
| 1000 |
|
| 1001 |
Get the value of a shared variable ($shv(name)). |
| 1002 |
|
| 1003 |
Parameters: |
| 1004 |
* _name_: shared variable name |
| 1005 |
|
| 1006 |
If no name is given, all shared variables are listed. |
| 1007 |
|
| 1008 |
Example 1.40. pv.shvGet usage |
| 1009 |
... |
| 1010 |
$ kamctl rpc pv.shvGet debug |
| 1011 |
... |