| 1 |
textops Module |
| 2 |
|
| 3 |
Andrei Pelinescu-Onciul |
| 4 |
|
| 5 |
FhG FOKUS |
| 6 |
<[email protected]> |
| 7 |
|
| 8 |
Edited by |
| 9 |
|
| 10 |
Andrei Pelinescu-Onciul |
| 11 |
|
| 12 |
<[email protected]> |
| 13 |
|
| 14 |
Daniel-Constantin Mierla |
| 15 |
|
| 16 |
<[email protected]> |
| 17 |
|
| 18 |
Juha Heinanen |
| 19 |
|
| 20 |
<[email protected]> |
| 21 |
|
| 22 |
Ovidiu Sas |
| 23 |
|
| 24 |
<[email protected]> |
| 25 |
|
| 26 |
Copyright © 2003 FhG FOKUS |
| 27 |
__________________________________________________________________ |
| 28 |
|
| 29 |
Table of Contents |
| 30 |
|
| 31 |
1. Admin Guide |
| 32 |
|
| 33 |
1. Overview |
| 34 |
2. Known Limitations |
| 35 |
3. Dependencies |
| 36 |
|
| 37 |
3.1. Kamailio Modules |
| 38 |
3.2. External Libraries or Applications |
| 39 |
|
| 40 |
4. Functions |
| 41 |
|
| 42 |
4.1. search(re) |
| 43 |
4.2. search_body(re) |
| 44 |
4.3. search_str(text, re) |
| 45 |
4.4. search_hf(hf, re, flags) |
| 46 |
4.5. search_append(re, txt) |
| 47 |
4.6. search_append_body(re, txt) |
| 48 |
4.7. replace(re, txt) |
| 49 |
4.8. replace_body(re, txt) |
| 50 |
4.9. replace_hdrs(re, txt) |
| 51 |
4.10. replace_all(re, txt) |
| 52 |
4.11. replace_body_all(re, txt) |
| 53 |
4.12. replace_body_atonce(re, txt) |
| 54 |
4.13. replace_str(match, repl, mode) |
| 55 |
4.14. replace_body_str(match, repl, mode) |
| 56 |
4.15. replace_hdrs_str(match, repl, mode) |
| 57 |
4.16. subst('/re/repl/flags') |
| 58 |
4.17. subst_uri('/re/repl/flags') |
| 59 |
4.18. subst_user('/re/repl/flags') |
| 60 |
4.19. subst_body('/re/repl/flags') |
| 61 |
4.20. subst_hf(hf, subexp, flags) |
| 62 |
4.21. subst_v(itext, subexp, ovp) |
| 63 |
4.22. set_body(txt, content_type) |
| 64 |
4.23. set_body_hex(htxt, content_type) |
| 65 |
4.24. set_reply_body(txt, content_type) |
| 66 |
4.25. set_reply_body_hex(txt, content_type) |
| 67 |
4.26. filter_body(content_type) |
| 68 |
4.27. append_to_reply(txt) |
| 69 |
4.28. append_hf(txt[, hdr]) |
| 70 |
4.29. insert_hf(txt[, hdr]) |
| 71 |
4.30. append_urihf(prefix, suffix) |
| 72 |
4.31. is_present_hf(hf_name) |
| 73 |
4.32. is_present_hf_pv(hf_name) |
| 74 |
4.33. is_present_hf_re(hf_name_re) |
| 75 |
4.34. is_present_hf_re_pv(hf_name_re) |
| 76 |
4.35. append_time() |
| 77 |
4.36. append_time_to_request() |
| 78 |
4.37. is_method(name) |
| 79 |
4.38. remove_hf(hname) |
| 80 |
4.39. remove_hf_pv(hname) |
| 81 |
4.40. remove_hf_re(re) |
| 82 |
4.41. remove_hf_re_pv(re) |
| 83 |
4.42. remove_hf_exp(expmatch, expskip) |
| 84 |
4.43. remove_hf_exp_pv(expmatch, expskip) |
| 85 |
4.44. remove_hf_idx(hname, idx) |
| 86 |
4.45. remove_hf_match(hname, op, expr) |
| 87 |
4.46. has_body(), has_body(mime) |
| 88 |
4.47. is_audio_on_hold() |
| 89 |
4.48. is_privacy(privacy_type) |
| 90 |
4.49. in_list(subject, list, separator) |
| 91 |
4.50. in_list_prefix(subject, list, separator) |
| 92 |
4.51. cmp_str(str1, str2) |
| 93 |
4.52. cmp_istr(str1, str2) |
| 94 |
4.53. starts_with(str1, str2) |
| 95 |
4.54. ends_with(str1, str2) |
| 96 |
4.55. str_find(str1, str2) |
| 97 |
4.56. str_ifind(str1, str2) |
| 98 |
4.57. str_any_in(txt, clist) |
| 99 |
4.58. str_all_in(txt, clist) |
| 100 |
4.59. set_body_multipart([txt, content_type][, boundary]) |
| 101 |
4.60. append_body_part(txt, content_type[, |
| 102 |
content_disposition]) |
| 103 |
|
| 104 |
4.61. append_body_part_hex(txt, content_type[, |
| 105 |
content_disposition]) |
| 106 |
|
| 107 |
4.62. get_body_part(content_type, opv) |
| 108 |
4.63. get_body_part_raw(content_type, opv) |
| 109 |
4.64. remove_body_part(content_type) |
| 110 |
4.65. regex_substring(itext, regexp, mindex, mcount, dpv) |
| 111 |
4.66. via_param_rm(name, idx) |
| 112 |
|
| 113 |
2. Developer Guide |
| 114 |
|
| 115 |
1. Functions |
| 116 |
|
| 117 |
1.1. load_textops(*import_structure) |
| 118 |
|
| 119 |
List of Examples |
| 120 |
|
| 121 |
1.1. search usage |
| 122 |
1.2. search_body usage |
| 123 |
1.3. search_str usage |
| 124 |
1.4. search_hf usage |
| 125 |
1.5. search_append usage |
| 126 |
1.6. search_append_body usage |
| 127 |
1.7. replace usage |
| 128 |
1.8. replace_body usage |
| 129 |
1.9. replace_hdrs usage |
| 130 |
1.10. replace_all usage |
| 131 |
1.11. replace_body_all usage |
| 132 |
1.12. replace_body_atonce usage |
| 133 |
1.13. replace_str usage |
| 134 |
1.14. replace_body_str usage |
| 135 |
1.15. replace_hdrs_str usage |
| 136 |
1.16. subst usage |
| 137 |
1.17. subst_uri usage |
| 138 |
1.18. subst usage |
| 139 |
1.19. subst_body usage |
| 140 |
1.20. subst_hf usage |
| 141 |
1.21. subst_v usage |
| 142 |
1.22. set_body usage |
| 143 |
1.23. set_body_hex usage |
| 144 |
1.24. set_reply_body usage |
| 145 |
1.25. set_reply_body_hex usage |
| 146 |
1.26. filter_body usage |
| 147 |
1.27. append_to_reply usage |
| 148 |
1.28. append_hf usage |
| 149 |
1.29. insert_hf usage |
| 150 |
1.30. append_urihf usage |
| 151 |
1.31. is_present_hf usage |
| 152 |
1.32. is_present_hf_pv usage |
| 153 |
1.33. is_present_hf_re usage |
| 154 |
1.34. is_present_hf_re_pv usage |
| 155 |
1.35. append_time usage |
| 156 |
1.36. append_time_to_request usage |
| 157 |
1.37. is_method usage |
| 158 |
1.38. remove_hf usage |
| 159 |
1.39. remove_hf_pv usage |
| 160 |
1.40. remove_hf_re usage |
| 161 |
1.41. remove_hf_re_pv usage |
| 162 |
1.42. remove_hf_exp usage |
| 163 |
1.43. remove_hf_exp_pv usage |
| 164 |
1.44. remove_hf_idx usage |
| 165 |
1.45. remove_hf_match usage |
| 166 |
1.46. has_body usage |
| 167 |
1.47. is_audio_on_hold usage |
| 168 |
1.48. is_privacy usage |
| 169 |
1.49. in_list usage |
| 170 |
1.50. in_list_prefix usage |
| 171 |
1.51. cmp_str usage |
| 172 |
1.52. cmp_str usage |
| 173 |
1.53. starts_with usage |
| 174 |
1.54. ends_with usage |
| 175 |
1.55. str_find usage |
| 176 |
1.56. str_ifind usage |
| 177 |
1.57. str_any_in usage |
| 178 |
1.58. str_all_in usage |
| 179 |
1.59. set_body_multipart usage |
| 180 |
1.60. append_body_part usage |
| 181 |
1.61. append_body_part with headers |
| 182 |
1.62. append_body_part_hex usage |
| 183 |
1.63. get_body_part usage |
| 184 |
1.64. get_body_part_raw usage |
| 185 |
1.65. remove_body_part usage |
| 186 |
1.66. _regex_substring usage |
| 187 |
1.67. via_param_rm usage |
| 188 |
|
| 189 |
Chapter 1. Admin Guide |
| 190 |
|
| 191 |
Table of Contents |
| 192 |
|
| 193 |
1. Overview |
| 194 |
2. Known Limitations |
| 195 |
3. Dependencies |
| 196 |
|
| 197 |
3.1. Kamailio Modules |
| 198 |
3.2. External Libraries or Applications |
| 199 |
|
| 200 |
4. Functions |
| 201 |
|
| 202 |
4.1. search(re) |
| 203 |
4.2. search_body(re) |
| 204 |
4.3. search_str(text, re) |
| 205 |
4.4. search_hf(hf, re, flags) |
| 206 |
4.5. search_append(re, txt) |
| 207 |
4.6. search_append_body(re, txt) |
| 208 |
4.7. replace(re, txt) |
| 209 |
4.8. replace_body(re, txt) |
| 210 |
4.9. replace_hdrs(re, txt) |
| 211 |
4.10. replace_all(re, txt) |
| 212 |
4.11. replace_body_all(re, txt) |
| 213 |
4.12. replace_body_atonce(re, txt) |
| 214 |
4.13. replace_str(match, repl, mode) |
| 215 |
4.14. replace_body_str(match, repl, mode) |
| 216 |
4.15. replace_hdrs_str(match, repl, mode) |
| 217 |
4.16. subst('/re/repl/flags') |
| 218 |
4.17. subst_uri('/re/repl/flags') |
| 219 |
4.18. subst_user('/re/repl/flags') |
| 220 |
4.19. subst_body('/re/repl/flags') |
| 221 |
4.20. subst_hf(hf, subexp, flags) |
| 222 |
4.21. subst_v(itext, subexp, ovp) |
| 223 |
4.22. set_body(txt, content_type) |
| 224 |
4.23. set_body_hex(htxt, content_type) |
| 225 |
4.24. set_reply_body(txt, content_type) |
| 226 |
4.25. set_reply_body_hex(txt, content_type) |
| 227 |
4.26. filter_body(content_type) |
| 228 |
4.27. append_to_reply(txt) |
| 229 |
4.28. append_hf(txt[, hdr]) |
| 230 |
4.29. insert_hf(txt[, hdr]) |
| 231 |
4.30. append_urihf(prefix, suffix) |
| 232 |
4.31. is_present_hf(hf_name) |
| 233 |
4.32. is_present_hf_pv(hf_name) |
| 234 |
4.33. is_present_hf_re(hf_name_re) |
| 235 |
4.34. is_present_hf_re_pv(hf_name_re) |
| 236 |
4.35. append_time() |
| 237 |
4.36. append_time_to_request() |
| 238 |
4.37. is_method(name) |
| 239 |
4.38. remove_hf(hname) |
| 240 |
4.39. remove_hf_pv(hname) |
| 241 |
4.40. remove_hf_re(re) |
| 242 |
4.41. remove_hf_re_pv(re) |
| 243 |
4.42. remove_hf_exp(expmatch, expskip) |
| 244 |
4.43. remove_hf_exp_pv(expmatch, expskip) |
| 245 |
4.44. remove_hf_idx(hname, idx) |
| 246 |
4.45. remove_hf_match(hname, op, expr) |
| 247 |
4.46. has_body(), has_body(mime) |
| 248 |
4.47. is_audio_on_hold() |
| 249 |
4.48. is_privacy(privacy_type) |
| 250 |
4.49. in_list(subject, list, separator) |
| 251 |
4.50. in_list_prefix(subject, list, separator) |
| 252 |
4.51. cmp_str(str1, str2) |
| 253 |
4.52. cmp_istr(str1, str2) |
| 254 |
4.53. starts_with(str1, str2) |
| 255 |
4.54. ends_with(str1, str2) |
| 256 |
4.55. str_find(str1, str2) |
| 257 |
4.56. str_ifind(str1, str2) |
| 258 |
4.57. str_any_in(txt, clist) |
| 259 |
4.58. str_all_in(txt, clist) |
| 260 |
4.59. set_body_multipart([txt, content_type][, boundary]) |
| 261 |
4.60. append_body_part(txt, content_type[, content_disposition]) |
| 262 |
4.61. append_body_part_hex(txt, content_type[, |
| 263 |
content_disposition]) |
| 264 |
|
| 265 |
4.62. get_body_part(content_type, opv) |
| 266 |
4.63. get_body_part_raw(content_type, opv) |
| 267 |
4.64. remove_body_part(content_type) |
| 268 |
4.65. regex_substring(itext, regexp, mindex, mcount, dpv) |
| 269 |
4.66. via_param_rm(name, idx) |
| 270 |
|
| 271 |
1. Overview |
| 272 |
|
| 273 |
The module implements text based operations over the SIP message |
| 274 |
processed by Kamailio. SIP is a text based protocol and the module |
| 275 |
provides a large set of very useful functions to manipulate the message |
| 276 |
at text level, e.g., regular expression search, replace or |
| 277 |
substitutions, checks for method type, header presence, insert of new |
| 278 |
header and date, string comparisons, multi-part body operations, etc. |
| 279 |
|
| 280 |
If not stated otherwise, the regular expressions parameters for search, |
| 281 |
replace or substitute have to be in POSIX format. For PCRE regular |
| 282 |
expression matching, see the pcre or dialplan modules. |
| 283 |
|
| 284 |
2. Known Limitations |
| 285 |
|
| 286 |
Search functions are applied to the original request, i.e., they ignore |
| 287 |
all changes resulting from message processing in Kamailio script. |
| 288 |
|
| 289 |
Search ignores folded lines. For example, search(“(From|f):.*@foo.bar”) |
| 290 |
doesn't match the following From header field: |
| 291 |
From: medabeda |
| 292 |
<sip:[email protected]>;tag=1234 |
| 293 |
|
| 294 |
3. Dependencies |
| 295 |
|
| 296 |
3.1. Kamailio Modules |
| 297 |
3.2. External Libraries or Applications |
| 298 |
|
| 299 |
3.1. Kamailio Modules |
| 300 |
|
| 301 |
The following modules must be loaded before this module: |
| 302 |
* No dependencies on other Kamailio modules. |
| 303 |
|
| 304 |
3.2. External Libraries or Applications |
| 305 |
|
| 306 |
The following libraries or applications must be installed before |
| 307 |
running Kamailio with this module loaded: |
| 308 |
* None. |
| 309 |
|
| 310 |
4. Functions |
| 311 |
|
| 312 |
4.1. search(re) |
| 313 |
4.2. search_body(re) |
| 314 |
4.3. search_str(text, re) |
| 315 |
4.4. search_hf(hf, re, flags) |
| 316 |
4.5. search_append(re, txt) |
| 317 |
4.6. search_append_body(re, txt) |
| 318 |
4.7. replace(re, txt) |
| 319 |
4.8. replace_body(re, txt) |
| 320 |
4.9. replace_hdrs(re, txt) |
| 321 |
4.10. replace_all(re, txt) |
| 322 |
4.11. replace_body_all(re, txt) |
| 323 |
4.12. replace_body_atonce(re, txt) |
| 324 |
4.13. replace_str(match, repl, mode) |
| 325 |
4.14. replace_body_str(match, repl, mode) |
| 326 |
4.15. replace_hdrs_str(match, repl, mode) |
| 327 |
4.16. subst('/re/repl/flags') |
| 328 |
4.17. subst_uri('/re/repl/flags') |
| 329 |
4.18. subst_user('/re/repl/flags') |
| 330 |
4.19. subst_body('/re/repl/flags') |
| 331 |
4.20. subst_hf(hf, subexp, flags) |
| 332 |
4.21. subst_v(itext, subexp, ovp) |
| 333 |
4.22. set_body(txt, content_type) |
| 334 |
4.23. set_body_hex(htxt, content_type) |
| 335 |
4.24. set_reply_body(txt, content_type) |
| 336 |
4.25. set_reply_body_hex(txt, content_type) |
| 337 |
4.26. filter_body(content_type) |
| 338 |
4.27. append_to_reply(txt) |
| 339 |
4.28. append_hf(txt[, hdr]) |
| 340 |
4.29. insert_hf(txt[, hdr]) |
| 341 |
4.30. append_urihf(prefix, suffix) |
| 342 |
4.31. is_present_hf(hf_name) |
| 343 |
4.32. is_present_hf_pv(hf_name) |
| 344 |
4.33. is_present_hf_re(hf_name_re) |
| 345 |
4.34. is_present_hf_re_pv(hf_name_re) |
| 346 |
4.35. append_time() |
| 347 |
4.36. append_time_to_request() |
| 348 |
4.37. is_method(name) |
| 349 |
4.38. remove_hf(hname) |
| 350 |
4.39. remove_hf_pv(hname) |
| 351 |
4.40. remove_hf_re(re) |
| 352 |
4.41. remove_hf_re_pv(re) |
| 353 |
4.42. remove_hf_exp(expmatch, expskip) |
| 354 |
4.43. remove_hf_exp_pv(expmatch, expskip) |
| 355 |
4.44. remove_hf_idx(hname, idx) |
| 356 |
4.45. remove_hf_match(hname, op, expr) |
| 357 |
4.46. has_body(), has_body(mime) |
| 358 |
4.47. is_audio_on_hold() |
| 359 |
4.48. is_privacy(privacy_type) |
| 360 |
4.49. in_list(subject, list, separator) |
| 361 |
4.50. in_list_prefix(subject, list, separator) |
| 362 |
4.51. cmp_str(str1, str2) |
| 363 |
4.52. cmp_istr(str1, str2) |
| 364 |
4.53. starts_with(str1, str2) |
| 365 |
4.54. ends_with(str1, str2) |
| 366 |
4.55. str_find(str1, str2) |
| 367 |
4.56. str_ifind(str1, str2) |
| 368 |
4.57. str_any_in(txt, clist) |
| 369 |
4.58. str_all_in(txt, clist) |
| 370 |
4.59. set_body_multipart([txt, content_type][, boundary]) |
| 371 |
4.60. append_body_part(txt, content_type[, content_disposition]) |
| 372 |
4.61. append_body_part_hex(txt, content_type[, content_disposition]) |
| 373 |
4.62. get_body_part(content_type, opv) |
| 374 |
4.63. get_body_part_raw(content_type, opv) |
| 375 |
4.64. remove_body_part(content_type) |
| 376 |
4.65. regex_substring(itext, regexp, mindex, mcount, dpv) |
| 377 |
4.66. via_param_rm(name, idx) |
| 378 |
|
| 379 |
4.1. search(re) |
| 380 |
|
| 381 |
Searches for the re in the message. |
| 382 |
|
| 383 |
Meaning of the parameters is as follows: |
| 384 |
* re - Regular expression. |
| 385 |
|
| 386 |
Note: it performs Posix regex matching and the 're' parameter is |
| 387 |
compiled with the flags REG_EXTENDED|REG_ICASE|REG_NEWLINE. |
| 388 |
|
| 389 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 390 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 391 |
|
| 392 |
Example 1.1. search usage |
| 393 |
... |
| 394 |
if ( search("[Ss][Ii][Pp]") ) { /*....*/ }; |
| 395 |
... |
| 396 |
|
| 397 |
4.2. search_body(re) |
| 398 |
|
| 399 |
Searches for the re in the body of the message. |
| 400 |
|
| 401 |
Meaning of the parameters is as follows: |
| 402 |
* re - Regular expression. |
| 403 |
|
| 404 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 405 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 406 |
|
| 407 |
Example 1.2. search_body usage |
| 408 |
... |
| 409 |
if ( search_body("[Ss][Ii][Pp]") ) { /*....*/ }; |
| 410 |
... |
| 411 |
|
| 412 |
4.3. search_str(text, re) |
| 413 |
|
| 414 |
Searches for the re in the body of the message. |
| 415 |
|
| 416 |
Meaning of the parameters is as follows: |
| 417 |
* text - text to perform regex searching over it. |
| 418 |
* re - regular expression to match over the 'text' parameter. |
| 419 |
|
| 420 |
Both parameters can contain variables. |
| 421 |
|
| 422 |
This function can be used from ANY_ROUTE. |
| 423 |
|
| 424 |
Example 1.3. search_str usage |
| 425 |
... |
| 426 |
if ( search_str("$ru", ";transport=tcp") ) { /*....*/ }; |
| 427 |
... |
| 428 |
|
| 429 |
4.4. search_hf(hf, re, flags) |
| 430 |
|
| 431 |
Searches for the re in the body of a header field. |
| 432 |
|
| 433 |
Meaning of the parameters is as follows: |
| 434 |
* hf - header field name. |
| 435 |
* re - regular expression. |
| 436 |
* flags - control flags - it has to be one of: a - all headers |
| 437 |
matching the name; f - only first header matching the name; l - |
| 438 |
only the last header matching the name. |
| 439 |
|
| 440 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 441 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 442 |
|
| 443 |
Example 1.4. search_hf usage |
| 444 |
... |
| 445 |
if ( search_hf("From", ":test@", "a") ) { /*....*/ }; |
| 446 |
... |
| 447 |
|
| 448 |
4.5. search_append(re, txt) |
| 449 |
|
| 450 |
Searches for the first match of re and appends txt after it. |
| 451 |
|
| 452 |
Meaning of the parameters is as follows: |
| 453 |
* re - Regular expression. |
| 454 |
* txt - String to be appended. |
| 455 |
|
| 456 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 457 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 458 |
|
| 459 |
Example 1.5. search_append usage |
| 460 |
... |
| 461 |
search_append("[Oo]pen[Ss]er", " SIP Proxy"); |
| 462 |
... |
| 463 |
|
| 464 |
4.6. search_append_body(re, txt) |
| 465 |
|
| 466 |
Searches for the first match of re in the body of the message and |
| 467 |
appends txt after it. |
| 468 |
|
| 469 |
Meaning of the parameters is as follows: |
| 470 |
* re - Regular expression. |
| 471 |
* txt - String to be appended. |
| 472 |
|
| 473 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 474 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 475 |
|
| 476 |
Example 1.6. search_append_body usage |
| 477 |
... |
| 478 |
search_append_body("[Oo]pen[Ss]er", " SIP Proxy"); |
| 479 |
... |
| 480 |
|
| 481 |
4.7. replace(re, txt) |
| 482 |
|
| 483 |
Replaces the first occurrence of re with txt. |
| 484 |
|
| 485 |
Meaning of the parameters is as follows: |
| 486 |
* re - Regular expression. |
| 487 |
* txt - String. |
| 488 |
|
| 489 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 490 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 491 |
|
| 492 |
Example 1.7. replace usage |
| 493 |
... |
| 494 |
replace("server", "Kamailio SIP Proxy"); |
| 495 |
... |
| 496 |
|
| 497 |
4.8. replace_body(re, txt) |
| 498 |
|
| 499 |
Replaces the first occurrence of re in the body of the message with |
| 500 |
txt. |
| 501 |
|
| 502 |
Meaning of the parameters is as follows: |
| 503 |
* re - Regular expression. |
| 504 |
* txt - String. |
| 505 |
|
| 506 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 507 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 508 |
|
| 509 |
Example 1.8. replace_body usage |
| 510 |
... |
| 511 |
replace_body("server", "Kamailio SIP Proxy"); |
| 512 |
... |
| 513 |
|
| 514 |
4.9. replace_hdrs(re, txt) |
| 515 |
|
| 516 |
Replaces the first occurrence of re in the SIP headers of the message |
| 517 |
with txt. |
| 518 |
|
| 519 |
Meaning of the parameters is as follows: |
| 520 |
* re - Regular expression. |
| 521 |
* txt - String. |
| 522 |
|
| 523 |
This function can be used from ANY_ROUTE. |
| 524 |
|
| 525 |
Example 1.9. replace_hdrs usage |
| 526 |
... |
| 527 |
replace_hdrs("Kamailio", "Kamailio SIP Proxy"); |
| 528 |
... |
| 529 |
|
| 530 |
4.10. replace_all(re, txt) |
| 531 |
|
| 532 |
Replaces all occurrence of re with txt. |
| 533 |
|
| 534 |
Meaning of the parameters is as follows: |
| 535 |
* re - Regular expression. |
| 536 |
* txt - String. |
| 537 |
|
| 538 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 539 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 540 |
|
| 541 |
Example 1.10. replace_all usage |
| 542 |
... |
| 543 |
replace_all("server", "Kamailio SIP Proxy"); |
| 544 |
... |
| 545 |
|
| 546 |
4.11. replace_body_all(re, txt) |
| 547 |
|
| 548 |
Replaces all occurrence of re in the body of the message with txt. |
| 549 |
Matching is done on a per-line basis. |
| 550 |
|
| 551 |
Meaning of the parameters is as follows: |
| 552 |
* re - Regular expression. |
| 553 |
* txt - String. |
| 554 |
|
| 555 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 556 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 557 |
|
| 558 |
Example 1.11. replace_body_all usage |
| 559 |
... |
| 560 |
replace_body_all("server", "Kamailio SIP Proxy"); |
| 561 |
... |
| 562 |
|
| 563 |
4.12. replace_body_atonce(re, txt) |
| 564 |
|
| 565 |
Replaces all occurrence of re in the body of the message with txt. |
| 566 |
Matching is done over the whole body. |
| 567 |
|
| 568 |
Meaning of the parameters is as follows: |
| 569 |
* re - Regular expression. |
| 570 |
* txt - String. |
| 571 |
|
| 572 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 573 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 574 |
|
| 575 |
Example 1.12. replace_body_atonce usage |
| 576 |
... |
| 577 |
# strip the whole body from the message: |
| 578 |
if(has_body() && replace_body_atonce("^.+$", "")) |
| 579 |
remove_hf("Content-Type"); |
| 580 |
... |
| 581 |
|
| 582 |
4.13. replace_str(match, repl, mode) |
| 583 |
|
| 584 |
Replaces the first or all occurrence of 'match' with 'repl' by doing |
| 585 |
string comparison for matching. It is applied over headers and message |
| 586 |
body (not over the first line). |
| 587 |
|
| 588 |
Meaning of the parameters is as follows: |
| 589 |
* match - string to be matched. |
| 590 |
* repl - string to be used as replacement. |
| 591 |
* mode - 'f' - replace only first match; 'a' - replace all matches. |
| 592 |
|
| 593 |
This function can be used from ANY_ROUTE. |
| 594 |
|
| 595 |
Example 1.13. replace_str usage |
| 596 |
... |
| 597 |
replace_str("Kamailio", "Kamailio SIP Proxy", "a"); |
| 598 |
... |
| 599 |
|
| 600 |
4.14. replace_body_str(match, repl, mode) |
| 601 |
|
| 602 |
Replaces the first or all occurrence of 'match' with 'repl' by doing |
| 603 |
string comparison for matching. It is applied over the message body. |
| 604 |
|
| 605 |
Meaning of the parameters is as follows: |
| 606 |
* match - string to be matched. |
| 607 |
* repl - string to be used as replacement. |
| 608 |
* mode - 'f' - replace only first match; 'a' - replace all matches. |
| 609 |
|
| 610 |
This function can be used from ANY_ROUTE. |
| 611 |
|
| 612 |
Example 1.14. replace_body_str usage |
| 613 |
... |
| 614 |
replace_body_str("Kamailio", "Kamailio SIP Proxy", "a"); |
| 615 |
... |
| 616 |
|
| 617 |
4.15. replace_hdrs_str(match, repl, mode) |
| 618 |
|
| 619 |
Replaces the first or all occurrence of 'match' with 'repl' by doing |
| 620 |
string comparison for matching. It is applied over the part with |
| 621 |
headers of the SIP message. |
| 622 |
|
| 623 |
Meaning of the parameters is as follows: |
| 624 |
* match - string to be matched. |
| 625 |
* repl - string to be used as replacement. |
| 626 |
* mode - 'f' - replace only first match; 'a' - replace all matches. |
| 627 |
|
| 628 |
This function can be used from ANY_ROUTE. |
| 629 |
|
| 630 |
Example 1.15. replace_hdrs_str usage |
| 631 |
... |
| 632 |
replace_hdrs_str("Kamailio", "Kamailio SIP Proxy", "a"); |
| 633 |
... |
| 634 |
|
| 635 |
4.16. subst('/re/repl/flags') |
| 636 |
|
| 637 |
Replaces re with repl. |
| 638 |
|
| 639 |
Meaning of the parameters is as follows: |
| 640 |
* '/re/repl/flags' - sed like regular expression. flags can be a |
| 641 |
combination of i (case insensitive), g (global) or s (match newline |
| 642 |
don't treat it as end of line). |
| 643 |
're' - is regular expression |
| 644 |
'repl' - is replacement string - may contain pseudo-variables |
| 645 |
'flags' - substitution flags (i - ignore case, g - global) |
| 646 |
|
| 647 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 648 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 649 |
|
| 650 |
Example 1.16. subst usage |
| 651 |
... |
| 652 |
# replace the uri in to: with the message uri (just an example) |
| 653 |
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1\u\2/ig') ) {}; |
| 654 |
|
| 655 |
# replace the uri in to: with the value of avp sip_address (just an example) |
| 656 |
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1$avp(sip_address)\2/ig') ) |
| 657 |
{}; |
| 658 |
|
| 659 |
... |
| 660 |
|
| 661 |
4.17. subst_uri('/re/repl/flags') |
| 662 |
|
| 663 |
Runs the re substitution on the message uri (like subst but works only |
| 664 |
on the uri) |
| 665 |
|
| 666 |
Meaning of the parameters is as follows: |
| 667 |
* '/re/repl/flags' - sed like regular expression. flags can be a |
| 668 |
combination of i (case insensitive), g (global) or s (match newline |
| 669 |
don't treat it as end of line). |
| 670 |
're' - is regular expression |
| 671 |
'repl' - is replacement string - may contain pseudo-variables |
| 672 |
'flags' - substitution flags (i - ignore case, g - global) |
| 673 |
|
| 674 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 675 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 676 |
|
| 677 |
Example 1.17. subst_uri usage |
| 678 |
... |
| 679 |
# adds 3463 prefix to numeric uris, and save the original uri (\0 match) |
| 680 |
# as a parameter: orig_uri (just an example) |
| 681 |
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:3463\1@\2;orig_uri=\0/i')){$ |
| 682 |
|
| 683 |
# adds the avp 'uri_prefix' as prefix to numeric uris, and save the original |
| 684 |
# uri (\0 match) as a parameter: orig_uri (just an example) |
| 685 |
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:$avp(uri_prefix)\1@\2;orig_uri=\0/i')){$ |
| 686 |
|
| 687 |
... |
| 688 |
|
| 689 |
4.18. subst_user('/re/repl/flags') |
| 690 |
|
| 691 |
Runs the re substitution on the message uri (like subst_uri but works |
| 692 |
only on the user portion of the uri) |
| 693 |
|
| 694 |
Meaning of the parameters is as follows: |
| 695 |
* '/re/repl/flags' - sed like regular expression. flags can be a |
| 696 |
combination of i (case insensitive), g (global) or s (match newline |
| 697 |
don't treat it as end of line). |
| 698 |
're' - is regular expression |
| 699 |
'repl' - is replacement string - may contain pseudo-variables |
| 700 |
'flags' - substitution flags (i - ignore case, g - global) |
| 701 |
|
| 702 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 703 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 704 |
|
| 705 |
Example 1.18. subst usage |
| 706 |
... |
| 707 |
# adds 3463 prefix to uris ending with 3642 (just an example) |
| 708 |
if (subst_user('/3642$/36423463/')){$ |
| 709 |
|
| 710 |
... |
| 711 |
# adds avp 'user_prefix' as prefix to username in r-uri ending with 3642 |
| 712 |
if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$ |
| 713 |
|
| 714 |
... |
| 715 |
|
| 716 |
4.19. subst_body('/re/repl/flags') |
| 717 |
|
| 718 |
Replaces re with repl in the body of the message. |
| 719 |
|
| 720 |
Meaning of the parameters is as follows: |
| 721 |
* '/re/repl/flags' - sed like regular expression. flags can be a |
| 722 |
combination of i (case insensitive), g (global) or s (match newline |
| 723 |
don't treat it as end of line). |
| 724 |
're' - is regular expression |
| 725 |
'repl' - is replacement string - may contain pseudo-variables |
| 726 |
'flags' - substitution flags (i - ignore case, g - global) |
| 727 |
|
| 728 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 729 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 730 |
|
| 731 |
Example 1.19. subst_body usage |
| 732 |
... |
| 733 |
if ( subst_body('/^o=(.*) /o=$fU /') ) {}; |
| 734 |
|
| 735 |
... |
| 736 |
|
| 737 |
4.20. subst_hf(hf, subexp, flags) |
| 738 |
|
| 739 |
Substitutions in the body of a header field. |
| 740 |
|
| 741 |
Meaning of the parameters is as follows: |
| 742 |
* hf - header field name. |
| 743 |
* subexp - substitution expression in the same format as of the |
| 744 |
'subst' function parameter. |
| 745 |
* flags - control flags - it has to be one of: a - all headers |
| 746 |
matching the name; f - only first header matching the name; l - |
| 747 |
only the last header matching the name. |
| 748 |
|
| 749 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 750 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 751 |
|
| 752 |
Example 1.20. subst_hf usage |
| 753 |
... |
| 754 |
if ( subst_hf("From", "/:test@/:best@/", "a") ) { /*....*/ }; |
| 755 |
... |
| 756 |
|
| 757 |
4.21. subst_v(itext, subexp, ovp) |
| 758 |
|
| 759 |
Sed-like substitution subexp applied to itext, with result stored in |
| 760 |
opv. |
| 761 |
|
| 762 |
Meaning of the parameters is as follows: |
| 763 |
* itext - input text, it can contain variables. |
| 764 |
* subexp - substitution expression in the same format as of the |
| 765 |
'subst' function parameter, it can contain variables. |
| 766 |
* opv - variable name where to store the result. |
| 767 |
|
| 768 |
This function can be used from ANY_ROUTE. |
| 769 |
|
| 770 |
Example 1.21. subst_v usage |
| 771 |
... |
| 772 |
subst_v("$var(x)", "/:test@/:best@/", "$var(r)"); |
| 773 |
... |
| 774 |
|
| 775 |
4.22. set_body(txt, content_type) |
| 776 |
|
| 777 |
Set body to a SIP message. |
| 778 |
|
| 779 |
Meaning of the parameters is as follows: |
| 780 |
* txt - text for the body, can include pseudo-variables. |
| 781 |
* content_type - value of Content-Type header, can include |
| 782 |
pseudo-variables. |
| 783 |
|
| 784 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 785 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 786 |
|
| 787 |
Example 1.22. set_body usage |
| 788 |
... |
| 789 |
set_body("test", "text/plain"); |
| 790 |
... |
| 791 |
|
| 792 |
4.23. set_body_hex(htxt, content_type) |
| 793 |
|
| 794 |
Set body to a SIP message with the hexa-decoded value of htxt. |
| 795 |
|
| 796 |
Meaning of the parameters is as follows: |
| 797 |
* htxt - hexa-encoded value for the body, can include |
| 798 |
pseudo-variables. White spaces and tabs are ignored. |
| 799 |
* content_type - value of Content-Type header, can include |
| 800 |
pseudo-variables. |
| 801 |
|
| 802 |
This function can be used from ANY_ROUTE. |
| 803 |
|
| 804 |
Example 1.23. set_body_hex usage |
| 805 |
... |
| 806 |
set_body_hex("b0 8e 4a f2", "binary/data"); |
| 807 |
... |
| 808 |
|
| 809 |
4.24. set_reply_body(txt, content_type) |
| 810 |
|
| 811 |
Set body to a SIP reply to be generated by Kamailio. |
| 812 |
|
| 813 |
Meaning of the parameters is as follows: |
| 814 |
* txt - text for the body, can include pseudo-variables. |
| 815 |
* content_type - value of Content-Type header, can include |
| 816 |
pseudo-variables. |
| 817 |
|
| 818 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 819 |
BRANCH_ROUTE. |
| 820 |
|
| 821 |
Example 1.24. set_reply_body usage |
| 822 |
... |
| 823 |
set_reply_body("test", "text/plain"); |
| 824 |
... |
| 825 |
|
| 826 |
4.25. set_reply_body_hex(txt, content_type) |
| 827 |
|
| 828 |
Same as set_reply_body(), but with the body provided as hexa-encoded |
| 829 |
value. The whitespaces are ignored when decoding the body parameter. |
| 830 |
|
| 831 |
Example 1.25. set_reply_body_hex usage |
| 832 |
... |
| 833 |
set_reply_body_hex("4b 82 00 a2", "binary/data"); |
| 834 |
... |
| 835 |
|
| 836 |
4.26. filter_body(content_type) |
| 837 |
|
| 838 |
Filters multipart/mixed body by leaving out all other body parts except |
| 839 |
the first body part of given type. |
| 840 |
|
| 841 |
Meaning of the parameters is as follows: |
| 842 |
* content_type - Content type to be left in the body. |
| 843 |
|
| 844 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 845 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 846 |
|
| 847 |
Example 1.26. filter_body usage |
| 848 |
... |
| 849 |
if (has_body("multipart/mixed")) { |
| 850 |
if (filter_body("application/sdp")) { |
| 851 |
remove_hf("Content-Type"); |
| 852 |
append_hf("Content-Type: application/sdp\r\n"); |
| 853 |
} else { |
| 854 |
xlog("Body part application/sdp not found\n"); |
| 855 |
} |
| 856 |
} |
| 857 |
... |
| 858 |
|
| 859 |
4.27. append_to_reply(txt) |
| 860 |
|
| 861 |
Append txt as header to the reply that is going to be generated by |
| 862 |
Kamailio (e.g., via sl_send_reply(...)). |
| 863 |
|
| 864 |
Meaning of the parameters is as follows: |
| 865 |
* txt - String which may contains pseudo-variables. Note that the |
| 866 |
value has to be ended with "\r\n" (end of header characters |
| 867 |
sequence). |
| 868 |
|
| 869 |
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, |
| 870 |
FAILURE_ROUTE, ERROR_ROUTE. |
| 871 |
|
| 872 |
Example 1.27. append_to_reply usage |
| 873 |
... |
| 874 |
append_to_reply("Foo: bar\r\n"); |
| 875 |
append_to_reply("Foo: $rm at $Ts\r\n"); |
| 876 |
... |
| 877 |
|
| 878 |
4.28. append_hf(txt[, hdr]) |
| 879 |
|
| 880 |
Appends 'txt' as header at the end of all the headers, or after last |
| 881 |
header named 'hdr' if the second parameter is provided. |
| 882 |
|
| 883 |
Meaning of the parameters is as follows: |
| 884 |
* txt - Header field to be appended. The value can contain |
| 885 |
pseudo-variables which will be replaced at run time. Note that the |
| 886 |
value has to be ended with "\r\n" (end of header characters |
| 887 |
sequence). |
| 888 |
* hdr - Header name after which the 'txt' is appended. |
| 889 |
|
| 890 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 891 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 892 |
|
| 893 |
Example 1.28. append_hf usage |
| 894 |
... |
| 895 |
append_hf("P-hint: VOICEMAIL\r\n"); |
| 896 |
append_hf("From-username: $fU\r\n", "Call-ID"); |
| 897 |
... |
| 898 |
|
| 899 |
4.29. insert_hf(txt[, hdr]) |
| 900 |
|
| 901 |
Inserts 'txt' as header before the first header field, or before first |
| 902 |
header named 'hdr' if the second parameter is provided. |
| 903 |
|
| 904 |
Meaning of the parameters is as follows: |
| 905 |
* txt - Header field to be inserted. The value can contain |
| 906 |
pseudo-variables which will be replaced at run time. Note that the |
| 907 |
value has to be ended with "\r\n" (end of header characters |
| 908 |
sequence). |
| 909 |
* hdr - Header name before which the 'txt' is inserted. |
| 910 |
|
| 911 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 912 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 913 |
|
| 914 |
Example 1.29. insert_hf usage |
| 915 |
... |
| 916 |
insert_hf("P-hint: VOICEMAIL\r\n"); |
| 917 |
insert_hf("To-username: $tU\r\n"); |
| 918 |
insert_hf("P-hint: VOICEMAIL\r\n", "Call-ID"); |
| 919 |
insert_hf("To-username: $tU\r\n", "Call-ID"); |
| 920 |
... |
| 921 |
|
| 922 |
4.30. append_urihf(prefix, suffix) |
| 923 |
|
| 924 |
Append header field name with original Request-URI in middle. |
| 925 |
|
| 926 |
Meaning of the parameters is as follows: |
| 927 |
* prefix - string (usually at least header field name). |
| 928 |
* suffix - string (usually at least line terminator). |
| 929 |
|
| 930 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 931 |
BRANCH_ROUTE. |
| 932 |
|
| 933 |
Example 1.30. append_urihf usage |
| 934 |
... |
| 935 |
append_urihf("CC-Diversion: ", "\r\n"); |
| 936 |
... |
| 937 |
|
| 938 |
4.31. is_present_hf(hf_name) |
| 939 |
|
| 940 |
Return true if a header field is present in message. |
| 941 |
|
| 942 |
Note |
| 943 |
|
| 944 |
The function is also able to distinguish the compact names. For example |
| 945 |
“From” will match with “f”. |
| 946 |
|
| 947 |
Meaning of the parameters is as follows: |
| 948 |
* hf_name - Header field name (long or compact form). It can be only |
| 949 |
a static string value. |
| 950 |
|
| 951 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 952 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 953 |
|
| 954 |
Example 1.31. is_present_hf usage |
| 955 |
... |
| 956 |
if (is_present_hf("From")) xlog("From HF Present"); |
| 957 |
... |
| 958 |
|
| 959 |
4.32. is_present_hf_pv(hf_name) |
| 960 |
|
| 961 |
Same as is_present_hf() function, but the parameter can contain |
| 962 |
variables. |
| 963 |
|
| 964 |
Example 1.32. is_present_hf_pv usage |
| 965 |
... |
| 966 |
if (is_present_hf_pv("$var(hname)")) xinfo("Header $var(hname) is present\n"); |
| 967 |
... |
| 968 |
|
| 969 |
4.33. is_present_hf_re(hf_name_re) |
| 970 |
|
| 971 |
Return true if a header field whose name matches regular expression |
| 972 |
'hf_name_re' is present in message. |
| 973 |
|
| 974 |
Meaning of the parameters is as follows: |
| 975 |
* hf_name_re - Regular expression to match header field name. It can |
| 976 |
be only a static string value. |
| 977 |
|
| 978 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 979 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 980 |
|
| 981 |
Example 1.33. is_present_hf_re usage |
| 982 |
... |
| 983 |
if (is_present_hf_re("^P-")) |
| 984 |
xlog("There are headers starting with P-\n"); |
| 985 |
... |
| 986 |
|
| 987 |
4.34. is_present_hf_re_pv(hf_name_re) |
| 988 |
|
| 989 |
Same as is_present_hf_re() function, but the parameter can contain |
| 990 |
variables. |
| 991 |
|
| 992 |
Example 1.34. is_present_hf_re_pv usage |
| 993 |
... |
| 994 |
if (is_present_hf_re_pv_("^$var(prefix)")) |
| 995 |
xlog("There are headers starting with $var(prefix)\n"); |
| 996 |
... |
| 997 |
|
| 998 |
4.35. append_time() |
| 999 |
|
| 1000 |
Adds a time header to the reply of the request. You must use it before |
| 1001 |
functions that are likely to send a reply, e.g., save() from |
| 1002 |
'registrar' module. Header format is: “Date: %a, %d %b %Y %H:%M:%S |
| 1003 |
GMT”, with the legend: |
| 1004 |
* %a abbreviated week of day name (locale) |
| 1005 |
* %d day of month as decimal number |
| 1006 |
* %b abbreviated month name (locale) |
| 1007 |
* %Y year with century |
| 1008 |
* %H hour |
| 1009 |
* %M minutes |
| 1010 |
* %S seconds |
| 1011 |
|
| 1012 |
Return true if a header was successfully appended. |
| 1013 |
|
| 1014 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1015 |
BRANCH_ROUTE. |
| 1016 |
|
| 1017 |
Example 1.35. append_time usage |
| 1018 |
... |
| 1019 |
append_time(); |
| 1020 |
... |
| 1021 |
|
| 1022 |
4.36. append_time_to_request() |
| 1023 |
|
| 1024 |
Adds a time header to the request. Header format is: “Date: %a, %d %b |
| 1025 |
%Y %H:%M:%S GMT”, with the legend: |
| 1026 |
* %a abbreviated week of day name (locale) |
| 1027 |
* %d day of month as decimal number |
| 1028 |
* %b abbreviated month name (locale) |
| 1029 |
* %Y year with century |
| 1030 |
* %H hour |
| 1031 |
* %M minutes |
| 1032 |
* %S seconds |
| 1033 |
|
| 1034 |
Return true if a header was successfully appended. |
| 1035 |
|
| 1036 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1037 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 1038 |
|
| 1039 |
Example 1.36. append_time_to_request usage |
| 1040 |
... |
| 1041 |
if(!is_present_hf("Date")) |
| 1042 |
append_time_to_request(); |
| 1043 |
... |
| 1044 |
|
| 1045 |
4.37. is_method(name) |
| 1046 |
|
| 1047 |
Check if the method of the message matches the name. If name is a known |
| 1048 |
method (invite, cancel, ack, bye, options, info, update, register, |
| 1049 |
message, subscribe, notify, refer, prack), the function performs method |
| 1050 |
ID testing (integer comparison) instead of ignore case string |
| 1051 |
comparison. |
| 1052 |
|
| 1053 |
The 'name' can be a list of methods in the form of |
| 1054 |
'method1|method2|...'. In this case, the function returns true if the |
| 1055 |
SIP message's method is one from the list. IMPORTANT NOTE: in the list |
| 1056 |
must be only methods defined in Kamailio with ID (invite, cancel, ack, |
| 1057 |
bye, options, info, update, register, message, subscribe, notify, |
| 1058 |
refer, prack, publish; for more see: |
| 1059 |
http://www.iana.org/assignments/sip-parameters). |
| 1060 |
|
| 1061 |
If used for replies, the function tests the value of method field from |
| 1062 |
CSeq header. |
| 1063 |
|
| 1064 |
Meaning of the parameters is as follows: |
| 1065 |
* name - SIP method name |
| 1066 |
|
| 1067 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1068 |
FAILURE_ROUTE, and BRANCH_ROUTE. |
| 1069 |
|
| 1070 |
Example 1.37. is_method usage |
| 1071 |
... |
| 1072 |
if(is_method("INVITE")) |
| 1073 |
{ |
| 1074 |
# process INVITEs here |
| 1075 |
} |
| 1076 |
if(is_method("OPTION|UPDATE")) |
| 1077 |
{ |
| 1078 |
# process OPTIONs and UPDATEs here |
| 1079 |
} |
| 1080 |
... |
| 1081 |
|
| 1082 |
4.38. remove_hf(hname) |
| 1083 |
|
| 1084 |
Remove from message all headers with name “hname”. Header matching is |
| 1085 |
case-insensitive. Matches and removes also the compact header forms. |
| 1086 |
|
| 1087 |
Returns true if at least one header is found and removed. |
| 1088 |
|
| 1089 |
Meaning of the parameters is as follows: |
| 1090 |
* hname - header name to be removed. It can be only a static string |
| 1091 |
(because of the optimizations done at startup to speed up execution |
| 1092 |
at runtime). |
| 1093 |
|
| 1094 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1095 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1096 |
|
| 1097 |
Example 1.38. remove_hf usage |
| 1098 |
... |
| 1099 |
if(remove_hf("User-Agent")) |
| 1100 |
{ |
| 1101 |
# User Agent header removed |
| 1102 |
} |
| 1103 |
# compact form: remove "Contact" or "m" header |
| 1104 |
remove_hf("Contact"); |
| 1105 |
# compact form: remove "Contact" or "m" header |
| 1106 |
remove_hf("m"); |
| 1107 |
... |
| 1108 |
|
| 1109 |
4.39. remove_hf_pv(hname) |
| 1110 |
|
| 1111 |
Same as remove_hf() function, but the parameter can contain variables. |
| 1112 |
|
| 1113 |
Example 1.39. remove_hf_pv usage |
| 1114 |
... |
| 1115 |
remove_hf_pv("$var(hname)"); |
| 1116 |
... |
| 1117 |
|
| 1118 |
4.40. remove_hf_re(re) |
| 1119 |
|
| 1120 |
Remove from message all headers with name matching regular expression |
| 1121 |
“re” |
| 1122 |
|
| 1123 |
Returns true if at least one header is found and removed. |
| 1124 |
|
| 1125 |
Meaning of the parameters is as follows: |
| 1126 |
* re - regular expression to match the header name to be removed. |
| 1127 |
|
| 1128 |
This function can be used from ANY_ROUTE. |
| 1129 |
|
| 1130 |
Example 1.40. remove_hf_re usage |
| 1131 |
... |
| 1132 |
if(remove_hf_re("^P-")) |
| 1133 |
{ |
| 1134 |
# All headers starting with "P-" removed |
| 1135 |
} |
| 1136 |
... |
| 1137 |
|
| 1138 |
4.41. remove_hf_re_pv(re) |
| 1139 |
|
| 1140 |
Same as remove_hf_re() function, but the parameter can contain |
| 1141 |
variables. |
| 1142 |
|
| 1143 |
Example 1.41. remove_hf_re_pv usage |
| 1144 |
... |
| 1145 |
if(remove_hf_re_pv("^$var(prefix)")) |
| 1146 |
{ |
| 1147 |
# All headers starting with $var(prefix) value removed |
| 1148 |
} |
| 1149 |
... |
| 1150 |
|
| 1151 |
4.42. remove_hf_exp(expmatch, expskip) |
| 1152 |
|
| 1153 |
Remove from message all headers with name matching regular expression |
| 1154 |
“expmatch”, but not matching regular expression “expskip”. |
| 1155 |
|
| 1156 |
Returns true if at least one header is found and removed. |
| 1157 |
|
| 1158 |
Meaning of the parameters is as follows: |
| 1159 |
* expmatch - regular expression to match the header name to be |
| 1160 |
removed. |
| 1161 |
* expskip - regular expression to match the header name to be skipped |
| 1162 |
from removal. |
| 1163 |
|
| 1164 |
This function can be used from ANY_ROUTE. |
| 1165 |
|
| 1166 |
Example 1.42. remove_hf_exp usage |
| 1167 |
... |
| 1168 |
if(remove_hf_exp("^P-", "^P-Keep-")) |
| 1169 |
{ |
| 1170 |
# All headers starting with "P-" removed, |
| 1171 |
# except the ones starting with "P-Keep-" |
| 1172 |
} |
| 1173 |
... |
| 1174 |
|
| 1175 |
4.43. remove_hf_exp_pv(expmatch, expskip) |
| 1176 |
|
| 1177 |
Same as remove_hf_exp() function, but the parameters can contain |
| 1178 |
variables. |
| 1179 |
|
| 1180 |
Example 1.43. remove_hf_exp_pv usage |
| 1181 |
... |
| 1182 |
if(remove_hf_exp_pv("^$var(match)", "^$var(keep)")) |
| 1183 |
{ |
| 1184 |
# All headers starting with $var(match) value removed, |
| 1185 |
# except the ones starting with $var(keep) value |
| 1186 |
} |
| 1187 |
... |
| 1188 |
|
| 1189 |
4.44. remove_hf_idx(hname, idx) |
| 1190 |
|
| 1191 |
Remove from message the headers matching by name 'hname' with the index |
| 1192 |
'idx'. |
| 1193 |
|
| 1194 |
Returns true if the header is removed. |
| 1195 |
|
| 1196 |
Meaning of the parameters is as follows: |
| 1197 |
* hname - header name. |
| 1198 |
* idx - index of the header, starting from 0 with first header; |
| 1199 |
negative values count from the end of the headers, -1 being the |
| 1200 |
last header matching the name. |
| 1201 |
|
| 1202 |
The parameters can be config variables. |
| 1203 |
|
| 1204 |
This function can be used from ANY_ROUTE. |
| 1205 |
|
| 1206 |
Example 1.44. remove_hf_idx usage |
| 1207 |
... |
| 1208 |
remove_hf_idx("X-My-Header", "-1"); |
| 1209 |
... |
| 1210 |
|
| 1211 |
4.45. remove_hf_match(hname, op, expr) |
| 1212 |
|
| 1213 |
Remove from message all headers with name 'hname' matching the body |
| 1214 |
with expression “expr”, based on operator “op”. |
| 1215 |
|
| 1216 |
Returns true if at least one header is found and removed. |
| 1217 |
|
| 1218 |
Meaning of the parameters is as follows: |
| 1219 |
* hanem - name of the header. |
| 1220 |
* op - operator - it can be: 'eq' - equal; 'ne' - not equal; 'in' - |
| 1221 |
include; 're' - regular expression match. |
| 1222 |
* expr - expression to match. |
| 1223 |
|
| 1224 |
This function can be used from ANY_ROUTE. |
| 1225 |
|
| 1226 |
Example 1.45. remove_hf_match usage |
| 1227 |
... |
| 1228 |
if(remove_hf_match("X-Info", "in", "^data")) { |
| 1229 |
# all headers with name "X-Info" that have the body matching regular |
| 1230 |
# expression "^data" are removed |
| 1231 |
} |
| 1232 |
... |
| 1233 |
|
| 1234 |
4.46. has_body(), has_body(mime) |
| 1235 |
|
| 1236 |
The function returns true if the SIP message has a body attached. The |
| 1237 |
check includes also the “Content-Length” header presence and value. |
| 1238 |
|
| 1239 |
If a parameter is given, the mime described will be also checked |
| 1240 |
against the “Content-Type” header. |
| 1241 |
|
| 1242 |
Meaning of the parameters is as follows: |
| 1243 |
* mime - mime to be checked against the “Content-Type” header. If not |
| 1244 |
present or 0, this check will be disabled. |
| 1245 |
|
| 1246 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1247 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1248 |
|
| 1249 |
Example 1.46. has_body usage |
| 1250 |
... |
| 1251 |
if(has_body("application/sdp")) |
| 1252 |
{ |
| 1253 |
# do interesting stuff here |
| 1254 |
} |
| 1255 |
... |
| 1256 |
|
| 1257 |
4.47. is_audio_on_hold() |
| 1258 |
|
| 1259 |
The function returns true if the SIP message has a body attached and at |
| 1260 |
least one audio stream in on hold. The return code of the function |
| 1261 |
indicates the detected hold type: |
| 1262 |
* 1 - RFC2543 hold type: null connection IP detected |
| 1263 |
* 2 - RFC3264 hold type: inactive or sendonly attributes detected |
| 1264 |
|
| 1265 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1266 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1267 |
|
| 1268 |
Example 1.47. is_audio_on_hold usage |
| 1269 |
... |
| 1270 |
if(is_audio_on_hold()) |
| 1271 |
{ |
| 1272 |
switch ($rc) { |
| 1273 |
case 1: |
| 1274 |
# RFC2543 hold type |
| 1275 |
# do interesting stuff here |
| 1276 |
break; |
| 1277 |
case 2: |
| 1278 |
# RFC3264 hold type |
| 1279 |
# do interesting stuff here |
| 1280 |
break; |
| 1281 |
} |
| 1282 |
... |
| 1283 |
|
| 1284 |
4.48. is_privacy(privacy_type) |
| 1285 |
|
| 1286 |
The function returns true if the SIP message has a Privacy header field |
| 1287 |
that includes the given privacy_type among its privacy values. See |
| 1288 |
http://www.iana.org/assignments/sip-priv-values for possible privacy |
| 1289 |
type values. |
| 1290 |
|
| 1291 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1292 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1293 |
|
| 1294 |
Example 1.48. is_privacy usage |
| 1295 |
... |
| 1296 |
if(is_privacy("id")) |
| 1297 |
{ |
| 1298 |
# do interesting stuff here |
| 1299 |
} |
| 1300 |
... |
| 1301 |
|
| 1302 |
4.49. in_list(subject, list, separator) |
| 1303 |
|
| 1304 |
Function checks if subject string is found in list string where list |
| 1305 |
items are separated by separator string. Subject and list strings may |
| 1306 |
contain pseudo variables. Separator string needs to be one character |
| 1307 |
long. Returns 1 if subject is found and -1 otherwise. |
| 1308 |
|
| 1309 |
Function can be used from all kinds of routes. |
| 1310 |
|
| 1311 |
Example 1.49. in_list usage |
| 1312 |
... |
| 1313 |
$var(subject) = "fi"; |
| 1314 |
$var(list) = "dk,fi,no,se"; |
| 1315 |
if (in_list("$var(subject)", "$var(list)", ",")) { |
| 1316 |
xlog("L_INFO", "subject is found in list\n"); |
| 1317 |
} |
| 1318 |
... |
| 1319 |
|
| 1320 |
4.50. in_list_prefix(subject, list, separator) |
| 1321 |
|
| 1322 |
Function checks if any element in list string is a prefix for subject |
| 1323 |
string where list items are separated by separator string. Subject and |
| 1324 |
list strings may contain pseudo variables. Separator string needs to be |
| 1325 |
one character long. Returns 1 if subject is found and -1 otherwise. |
| 1326 |
|
| 1327 |
Function can be used from all kinds of routes. |
| 1328 |
|
| 1329 |
Example 1.50. in_list_prefix usage |
| 1330 |
... |
| 1331 |
$var(subject) = "final"; |
| 1332 |
$var(list) = "dk,fi,no,se"; |
| 1333 |
if (in_list_prefix("$var(subject)", "$var(list)", ",")) { |
| 1334 |
xlog("L_INFO", "prefix for subject is found in list\n"); |
| 1335 |
} |
| 1336 |
... |
| 1337 |
|
| 1338 |
4.51. cmp_str(str1, str2) |
| 1339 |
|
| 1340 |
The function returns true if the two parameters matches as string case |
| 1341 |
sensitive comparison. |
| 1342 |
|
| 1343 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1344 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1345 |
|
| 1346 |
Example 1.51. cmp_str usage |
| 1347 |
... |
| 1348 |
if(cmp_str("$rU", "kamailio")) |
| 1349 |
{ |
| 1350 |
# do interesting stuff here |
| 1351 |
} |
| 1352 |
... |
| 1353 |
|
| 1354 |
4.52. cmp_istr(str1, str2) |
| 1355 |
|
| 1356 |
The function returns true if the two parameters matches as string case |
| 1357 |
insensitive comparison. |
| 1358 |
|
| 1359 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1360 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1361 |
|
| 1362 |
Example 1.52. cmp_str usage |
| 1363 |
... |
| 1364 |
if(cmp_istr("$rU@you", "kamailio@YOU")) |
| 1365 |
{ |
| 1366 |
# do interesting stuff here |
| 1367 |
} |
| 1368 |
... |
| 1369 |
|
| 1370 |
4.53. starts_with(str1, str2) |
| 1371 |
|
| 1372 |
The function returns true if the first string starts with the second |
| 1373 |
string. |
| 1374 |
|
| 1375 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1376 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1377 |
|
| 1378 |
Example 1.53. starts_with usage |
| 1379 |
... |
| 1380 |
if (starts_with("$rU", "+358")) |
| 1381 |
{ |
| 1382 |
# do interesting stuff here |
| 1383 |
} |
| 1384 |
... |
| 1385 |
|
| 1386 |
4.54. ends_with(str1, str2) |
| 1387 |
|
| 1388 |
The function returns true if the first string ends with the second |
| 1389 |
string. The parameters can contain variables. |
| 1390 |
|
| 1391 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 1392 |
FAILURE_ROUTE and BRANCH_ROUTE. |
| 1393 |
|
| 1394 |
Example 1.54. ends_with usage |
| 1395 |
... |
| 1396 |
if (ends_with("$rU", "8800")) |
| 1397 |
{ |
| 1398 |
# do interesting stuff here |
| 1399 |
} |
| 1400 |
... |
| 1401 |
|
| 1402 |
4.55. str_find(str1, str2) |
| 1403 |
|
| 1404 |
The function returns true (greater than 0) if the str2 string is found |
| 1405 |
in str1, case sensitive comparison. |
| 1406 |
|
| 1407 |
This function can be used from ANY_ROUTE. |
| 1408 |
|
| 1409 |
Example 1.55. str_find usage |
| 1410 |
... |
| 1411 |
if (str_find("$rU", "8800")) { |
| 1412 |
# do interesting stuff here |
| 1413 |
} |
| 1414 |
... |
| 1415 |
|
| 1416 |
4.56. str_ifind(str1, str2) |
| 1417 |
|
| 1418 |
The function returns true (greater than 0) if the str2 string is found |
| 1419 |
in str1, case insensitive comparison. |
| 1420 |
|
| 1421 |
This function can be used from ANY_ROUTE. |
| 1422 |
|
| 1423 |
Example 1.56. str_ifind usage |
| 1424 |
... |
| 1425 |
if (str_ifind("$rU", "Alice")) { |
| 1426 |
# do interesting stuff here |
| 1427 |
} |
| 1428 |
... |
| 1429 |
|
| 1430 |
4.57. str_any_in(txt, clist) |
| 1431 |
|
| 1432 |
Return 1 (true) if any character in "clist" is found inside "txt". Both |
| 1433 |
parameters can contain variables. |
| 1434 |
|
| 1435 |
This function can be used from ANY_ROUTE. |
| 1436 |
|
| 1437 |
Example 1.57. str_any_in usage |
| 1438 |
... |
| 1439 |
if (str_any_in("$hdr(X-Hdr)", ";',:")) { |
| 1440 |
# do interesting stuff here |
| 1441 |
} |
| 1442 |
... |
| 1443 |
|
| 1444 |
4.58. str_all_in(txt, clist) |
| 1445 |
|
| 1446 |
Return 1 (true) if all character in "clist" are found inside "txt". |
| 1447 |
Both paramters can contain variables. |
| 1448 |
|
| 1449 |
This function can be used from ANY_ROUTE. |
| 1450 |
|
| 1451 |
Example 1.58. str_all_in usage |
| 1452 |
... |
| 1453 |
if (str_all_in("$hdr(X-Hdr)", ".;-")) { |
| 1454 |
# do interesting stuff here |
| 1455 |
} |
| 1456 |
... |
| 1457 |
|
| 1458 |
4.59. set_body_multipart([txt, content_type][, boundary]) |
| 1459 |
|
| 1460 |
Set multipart body to a SIP message. If called with no parameters, will |
| 1461 |
convert present body to multipart. |
| 1462 |
|
| 1463 |
Meaning of the parameters is as follows: |
| 1464 |
* txt - text for the body, can include pseudo-variables. |
| 1465 |
* content_type - value of Content-Type header, can include |
| 1466 |
pseudo-variables. |
| 1467 |
* boundary - string to use as boundary, can include pseudo-variables. |
| 1468 |
Default: unique-boundary-1 |
| 1469 |
|
| 1470 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1471 |
BRANCH_ROUTE. |
| 1472 |
|
| 1473 |
The core will take care of the last boundary ending with "--", |
| 1474 |
detecting which one is the last and fixing the others if needed. |
| 1475 |
|
| 1476 |
Note: it may be required that msg_apply_changes() from textopsx module |
| 1477 |
has to be executed if there are other operations over the new body. |
| 1478 |
|
| 1479 |
Example 1.59. set_body_multipart usage |
| 1480 |
... |
| 1481 |
set_body_multipart("test", "text/plain", "delimiter"); |
| 1482 |
msg_apply_changes(); |
| 1483 |
append_body_part(...); |
| 1484 |
msg_apply_changes(); |
| 1485 |
|
| 1486 |
... |
| 1487 |
|
| 1488 |
# Will produce: |
| 1489 |
|
| 1490 |
... |
| 1491 |
Content-Type: multipart/mixed;boundary="delimiter" |
| 1492 |
Mime-Version: 1.0 |
| 1493 |
|
| 1494 |
--delimiter |
| 1495 |
Content-Type: text/plain |
| 1496 |
|
| 1497 |
text |
| 1498 |
|
| 1499 |
--delimiter |
| 1500 |
... |
| 1501 |
|
| 1502 |
4.60. append_body_part(txt, content_type[, content_disposition]) |
| 1503 |
|
| 1504 |
Append a part on multipart body SIP message. Will use |
| 1505 |
"unique-boundary-1" as boundary. |
| 1506 |
|
| 1507 |
Meaning of the parameters is as follows: |
| 1508 |
* txt - text for the multipart body, can include pseudo-variables. |
| 1509 |
* content_type - value of Content-Type header, can include |
| 1510 |
pseudo-variables. |
| 1511 |
* content_disposition - value of Content-Disposition header, can |
| 1512 |
include pseudo-variables. |
| 1513 |
|
| 1514 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1515 |
BRANCH_ROUTE. |
| 1516 |
|
| 1517 |
The core will take care of the last boundary ending with "--", |
| 1518 |
detecting which one is the last and fixing the others if needed. |
| 1519 |
|
| 1520 |
Note: it may be required that msg_apply_changes() from textopsx module |
| 1521 |
has to be executed if there are other operations over the new body. |
| 1522 |
|
| 1523 |
Example 1.60. append_body_part usage |
| 1524 |
... |
| 1525 |
$var(b) = "7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c"; |
| 1526 |
append_body_part("$var(b)", "application/vnd.cirpack.isdn-ext", "signal;handling |
| 1527 |
=required"); |
| 1528 |
msg_apply_changes(); |
| 1529 |
... |
| 1530 |
|
| 1531 |
# Will append this to the body: |
| 1532 |
|
| 1533 |
... |
| 1534 |
Content-Type: application/vnd.cirpack.isdn-ext |
| 1535 |
Content-Disposition: signal;handling=required |
| 1536 |
|
| 1537 |
7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c |
| 1538 |
|
| 1539 |
--unique-boundary-1 |
| 1540 |
... |
| 1541 |
|
| 1542 |
If other headers should be added to a MIME body part, they can be |
| 1543 |
appended after the value of the content-type parameter, separated by |
| 1544 |
`\r\n` (at the very end do not add the '\r\n'). |
| 1545 |
|
| 1546 |
Example 1.61. append_body_part with headers |
| 1547 |
... |
| 1548 |
$var(b) = "7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c"; |
| 1549 |
append_body_part("$var(b)", "application/vnd.cirpack.isdn-ext\r\nX-Header: xyz", |
| 1550 |
"signal;handling=required"); |
| 1551 |
msg_apply_changes(); |
| 1552 |
... |
| 1553 |
|
| 1554 |
# Will append this to the body: |
| 1555 |
|
| 1556 |
... |
| 1557 |
Content-Type: application/vnd.cirpack.isdn-ext |
| 1558 |
X-Header: xyz |
| 1559 |
Content-Disposition: signal;handling=required |
| 1560 |
|
| 1561 |
7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c |
| 1562 |
|
| 1563 |
--unique-boundary-1 |
| 1564 |
... |
| 1565 |
|
| 1566 |
4.61. append_body_part_hex(txt, content_type[, content_disposition]) |
| 1567 |
|
| 1568 |
Append a part on multipart body SIP message, with the content provided |
| 1569 |
in hexa format. Will use "unique-boundary-1" as boundary. |
| 1570 |
|
| 1571 |
Meaning of the parameters is as follows: |
| 1572 |
* txt - content for the multipart body in hexa format. Spaces can be |
| 1573 |
used between the pairs of hexa digits to make it easier to read in |
| 1574 |
the config, they are ignored and not added in the body part. The |
| 1575 |
parameter can include pseudo-variables. |
| 1576 |
* content_type - value of Content-Type header, can include |
| 1577 |
pseudo-variables. |
| 1578 |
* content_disposition - value of Content-Disposition header, can |
| 1579 |
include pseudo-variables. |
| 1580 |
|
| 1581 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1582 |
BRANCH_ROUTE. |
| 1583 |
|
| 1584 |
The core will take care of the last boundary ending with "--", |
| 1585 |
detecting which one is the last and fixing the others if needed. |
| 1586 |
|
| 1587 |
Note: it may be required that msg_apply_changes() from textopsx module |
| 1588 |
has to be executed if there are other operations over the new body. |
| 1589 |
|
| 1590 |
Example 1.62. append_body_part_hex usage |
| 1591 |
... |
| 1592 |
$var(b) = "6b 61 6d 61 69 6c 69 6f"; |
| 1593 |
append_body_part_hex("$var(b)", "application/my-custom-ext"); |
| 1594 |
msg_apply_changes(); |
| 1595 |
... |
| 1596 |
|
| 1597 |
# Will append this to the body: |
| 1598 |
|
| 1599 |
... |
| 1600 |
Content-Type: application/my-custom-ext |
| 1601 |
|
| 1602 |
kamailio |
| 1603 |
|
| 1604 |
--unique-boundary-1 |
| 1605 |
... |
| 1606 |
|
| 1607 |
If other headers should be added to a MIME body part, see the docs for |
| 1608 |
append_body_part(...) function. |
| 1609 |
|
| 1610 |
4.62. get_body_part(content_type, opv) |
| 1611 |
|
| 1612 |
Return the content of a multipart body SIP message, storing it in opv. |
| 1613 |
|
| 1614 |
Meaning of the parameters is as follows: |
| 1615 |
* content_type - value of Content-Type header of the part to be |
| 1616 |
returned. If more than one exists the first occurrence will be |
| 1617 |
returned. |
| 1618 |
* opv - variable name where to store the result. |
| 1619 |
|
| 1620 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1621 |
BRANCH_ROUTE, ONREPLY_ROUTE. |
| 1622 |
|
| 1623 |
Example 1.63. get_body_part usage |
| 1624 |
... |
| 1625 |
get_body_part("application/vnd.cirpack.isdn-ext", "$var(pbody)"); |
| 1626 |
... |
| 1627 |
|
| 1628 |
4.63. get_body_part_raw(content_type, opv) |
| 1629 |
|
| 1630 |
Return the content of a multipart body SIP message, including headers |
| 1631 |
and boundary string, storing it in opv. |
| 1632 |
|
| 1633 |
Meaning of the parameters is as follows: |
| 1634 |
* content_type - value of Content-Type header of the part to be |
| 1635 |
returned. If more than one exists the first occurrence will be |
| 1636 |
returned. |
| 1637 |
* opv - variable name where to store the result. |
| 1638 |
|
| 1639 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1640 |
BRANCH_ROUTE, ONREPLY_ROUTE. |
| 1641 |
|
| 1642 |
Example 1.64. get_body_part_raw usage |
| 1643 |
... |
| 1644 |
get_body_part("application/vnd.cirpack.isdn-ext", "$var(hbody)"); |
| 1645 |
... |
| 1646 |
|
| 1647 |
4.64. remove_body_part(content_type) |
| 1648 |
|
| 1649 |
Remove a part on a multipart body SIP message. |
| 1650 |
|
| 1651 |
Meaning of the parameters is as follows: |
| 1652 |
* content_type - value of Content-Type header of the part to be |
| 1653 |
removed. If more than one exists the first occurrence will be |
| 1654 |
removed. |
| 1655 |
|
| 1656 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1657 |
BRANCH_ROUTE. |
| 1658 |
|
| 1659 |
The core will take care of the last boundary ending with "--", |
| 1660 |
detecting which one is the last and fixing the others if needed. |
| 1661 |
|
| 1662 |
Note: it may be required that msg_apply_changes() from textopsx module |
| 1663 |
has to be executed if there are other operations over the new body. |
| 1664 |
|
| 1665 |
Example 1.65. remove_body_part usage |
| 1666 |
... |
| 1667 |
remove_body_part("application/vnd.cirpack.isdn-ext"); |
| 1668 |
msg_apply_changes(); |
| 1669 |
... |
| 1670 |
|
| 1671 |
4.65. regex_substring(itext, regexp, mindex, mcount, dpv) |
| 1672 |
|
| 1673 |
Search in text with given regular expression then set dpv |
| 1674 |
pseudo-variable with the matched token at provided index. |
| 1675 |
|
| 1676 |
Meaning of the parameters is as follows: |
| 1677 |
* itext - text to be searched (dynamic string) |
| 1678 |
* regexp - regular expression (dynamic string) |
| 1679 |
* mindex - index of the matched token (int or variable holding int) |
| 1680 |
* mcount - the number of maximum expected matches (int or variable |
| 1681 |
holding int) |
| 1682 |
* dpv - variable to be set with matched token (static string with a |
| 1683 |
name of a variable) |
| 1684 |
|
| 1685 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 1686 |
BRANCH_ROUTE. |
| 1687 |
|
| 1688 |
Note that the regular expression extended is used. More info at: |
| 1689 |
https://www.regular-expressions.info/posix.html. |
| 1690 |
|
| 1691 |
Example 1.66. _regex_substring usage |
| 1692 |
... |
| 1693 |
regex_substring("___ abc123def ___ ghi456 ___", "([a-z]*)([0-9]+)([a-z]* |
| 1694 |
)", |
| 1695 |
1, 3, "$var(asd)"); |
| 1696 |
xlog("L_WARN","RESULT: $var(asd)\r\n"); |
| 1697 |
------ |
| 1698 |
result: |
| 1699 |
abc |
| 1700 |
---- |
| 1701 |
... |
| 1702 |
|
| 1703 |
4.66. via_param_rm(name, idx) |
| 1704 |
|
| 1705 |
Remove parameter matching by name from Via body at the specified index. |
| 1706 |
The index starts from 0 (first Via body). Negative index counts from |
| 1707 |
the end of the list for Via header bodies (-1 is the last Via body). |
| 1708 |
|
| 1709 |
Meaning of the parameters is as follows: |
| 1710 |
* name - name of the parameter |
| 1711 |
* idx - index of the Via body. |
| 1712 |
|
| 1713 |
The parameters can also be variables. |
| 1714 |
|
| 1715 |
This function can be used from ANY_ROUTE. |
| 1716 |
|
| 1717 |
Example 1.67. via_param_rm usage |
| 1718 |
... |
| 1719 |
via_param_rm("p1", "0"); |
| 1720 |
... |
| 1721 |
|
| 1722 |
Chapter 2. Developer Guide |
| 1723 |
|
| 1724 |
Table of Contents |
| 1725 |
|
| 1726 |
1. Functions |
| 1727 |
|
| 1728 |
1.1. load_textops(*import_structure) |
| 1729 |
|
| 1730 |
1. Functions |
| 1731 |
|
| 1732 |
1.1. load_textops(*import_structure) |
| 1733 |
|
| 1734 |
1.1. load_textops(*import_structure) |
| 1735 |
|
| 1736 |
For programmatic use only--import the Textops API. |
| 1737 |
|
| 1738 |
Meaning of the parameters is as follows: |
| 1739 |
* import_structure - Pointer to the import structure - see “struct |
| 1740 |
textops_binds” in modules/textops/api.h |