1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
|
textops Module
Andrei Pelinescu-Onciul
FhG FOKUS
<pelinescu-onciul@fokus.fraunhofer.de>
Edited by
Andrei Pelinescu-Onciul
<pelinescu-onciul@fokus.fraunhofer.de>
Edited by
Daniel-Constantin Mierla
<miconda@gmail.com>
Edited by
Juha Heinanen
<jh@tutpro.com>
Copyright © 2003 FhG FOKUS
__________________________________________________________________
Table of Contents
1. Admin Guide
1. Overview
1.1. Known Limitations
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Functions
3.1. search(re)
3.2. search_body(re)
3.3. search_hf(hf, re, flags)
3.4. search_append(re, txt)
3.5. search_append_body(re, txt)
3.6. replace(re, txt)
3.7. replace_body(re, txt)
3.8. replace_all(re, txt)
3.9. replace_body_all(re, txt)
3.10. replace_body_atonce(re, txt)
3.11. subst('/re/repl/flags')
3.12. subst_uri('/re/repl/flags')
3.13. subst_user('/re/repl/flags')
3.14. subst_body('/re/repl/flags')
3.15. subst_hf(hf, subexp, flags)
3.16. set_body(txt,content_type)
3.17. set_reply_body(txt,content_type)
3.18. filter_body(content_type)
3.19. append_to_reply(txt)
3.20. append_hf(txt[, hdr])
3.21. insert_hf(txt[, hdr])
3.22. append_urihf(prefix, suffix)
3.23. is_present_hf(hf_name)
3.24. is_present_hf_re(hf_name_re)
3.25. append_time()
3.26. append_time_to_request()
3.27. is_method(name)
3.28. remove_hf(hname)
3.29. remove_hf_re(re)
3.30. has_body(), has_body(mime)
3.31. is_audio_on_hold()
3.32. is_privacy(privacy_type)
3.33. in_list(subject, list, separator)
3.34. cmp_str(str1, str2)
3.35. cmp_istr(str1, str2)
3.36. starts_with(str1, str2)
3.37. set_body_multipart([txt,content_type][,boundary])
3.38. append_body_part(txt,content_type[,
content_disposition])
3.39. remove_body_part(content_type)
4. Known Limitations
2. Developer Guide
1. Functions
1.1. load_textops(*import_structure)
List of Examples
1.1. search usage
1.2. search_body usage
1.3. search_body usage
1.4. search_append usage
1.5. search_append_body usage
1.6. replace usage
1.7. replace_body usage
1.8. replace_all usage
1.9. replace_body_all usage
1.10. replace_body_atonce usage
1.11. subst usage
1.12. subst_uri usage
1.13. subst usage
1.14. subst_body usage
1.15. search_body usage
1.16. set_body usage
1.17. set_reply_body usage
1.18. filter_body usage
1.19. append_to_reply usage
1.20. append_hf usage
1.21. insert_hf usage
1.22. append_urihf usage
1.23. is_present_hf usage
1.24. is_present_hf_re usage
1.25. append_time usage
1.26. append_time_to_request usage
1.27. is_method usage
1.28. remove_hf usage
1.29. remove_hf_re usage
1.30. has_body usage
1.31. is_audio_on_hold usage
1.32. is_privacy usage
1.33. in_list() usage
1.34. cmp_str usage
1.35. cmp_str usage
1.36. starts_with usage
1.37. set_body_multipart usage
1.38. append_body_part usage
1.39. remove_body_part usage
Chapter 1. Admin Guide
Table of Contents
1. Overview
1.1. Known Limitations
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Functions
3.1. search(re)
3.2. search_body(re)
3.3. search_hf(hf, re, flags)
3.4. search_append(re, txt)
3.5. search_append_body(re, txt)
3.6. replace(re, txt)
3.7. replace_body(re, txt)
3.8. replace_all(re, txt)
3.9. replace_body_all(re, txt)
3.10. replace_body_atonce(re, txt)
3.11. subst('/re/repl/flags')
3.12. subst_uri('/re/repl/flags')
3.13. subst_user('/re/repl/flags')
3.14. subst_body('/re/repl/flags')
3.15. subst_hf(hf, subexp, flags)
3.16. set_body(txt,content_type)
3.17. set_reply_body(txt,content_type)
3.18. filter_body(content_type)
3.19. append_to_reply(txt)
3.20. append_hf(txt[, hdr])
3.21. insert_hf(txt[, hdr])
3.22. append_urihf(prefix, suffix)
3.23. is_present_hf(hf_name)
3.24. is_present_hf_re(hf_name_re)
3.25. append_time()
3.26. append_time_to_request()
3.27. is_method(name)
3.28. remove_hf(hname)
3.29. remove_hf_re(re)
3.30. has_body(), has_body(mime)
3.31. is_audio_on_hold()
3.32. is_privacy(privacy_type)
3.33. in_list(subject, list, separator)
3.34. cmp_str(str1, str2)
3.35. cmp_istr(str1, str2)
3.36. starts_with(str1, str2)
3.37. set_body_multipart([txt,content_type][,boundary])
3.38. append_body_part(txt,content_type[, content_disposition])
3.39. remove_body_part(content_type)
4. Known Limitations
1. Overview
1.1. Known Limitations
The module implements text based operations over the SIP message
processed by Kamailio. SIP is a text based protocol and the module
provides a large set of very useful functions to manipulate the message
at text level, e.g., regular expression search and replace, Perl-like
substitutions, checks for method type, header presence, insert of new
header and date, etc.
1.1. Known Limitations
search ignores folded lines. For example, search(“(From|f):.*@foo.bar”)
doesn't match the following From header field:
From: medabeda
<sip:medameda@foo.bar>;tag=1234
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
2.1. Kamailio Modules
The following modules must be loaded before this module:
* No dependencies on other Kamailio modules.
2.2. External Libraries or Applications
The following libraries or applications must be installed before
running Kamailio with this module loaded:
* None.
3. Functions
3.1. search(re)
3.2. search_body(re)
3.3. search_hf(hf, re, flags)
3.4. search_append(re, txt)
3.5. search_append_body(re, txt)
3.6. replace(re, txt)
3.7. replace_body(re, txt)
3.8. replace_all(re, txt)
3.9. replace_body_all(re, txt)
3.10. replace_body_atonce(re, txt)
3.11. subst('/re/repl/flags')
3.12. subst_uri('/re/repl/flags')
3.13. subst_user('/re/repl/flags')
3.14. subst_body('/re/repl/flags')
3.15. subst_hf(hf, subexp, flags)
3.16. set_body(txt,content_type)
3.17. set_reply_body(txt,content_type)
3.18. filter_body(content_type)
3.19. append_to_reply(txt)
3.20. append_hf(txt[, hdr])
3.21. insert_hf(txt[, hdr])
3.22. append_urihf(prefix, suffix)
3.23. is_present_hf(hf_name)
3.24. is_present_hf_re(hf_name_re)
3.25. append_time()
3.26. append_time_to_request()
3.27. is_method(name)
3.28. remove_hf(hname)
3.29. remove_hf_re(re)
3.30. has_body(), has_body(mime)
3.31. is_audio_on_hold()
3.32. is_privacy(privacy_type)
3.33. in_list(subject, list, separator)
3.34. cmp_str(str1, str2)
3.35. cmp_istr(str1, str2)
3.36. starts_with(str1, str2)
3.37. set_body_multipart([txt,content_type][,boundary])
3.38. append_body_part(txt,content_type[, content_disposition])
3.39. remove_body_part(content_type)
3.1. search(re)
Searches for the re in the message.
Meaning of the parameters is as follows:
* re - Regular expression.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.1. search usage
...
if ( search("[Ss][Ii][Pp]") ) { /*....*/ };
...
3.2. search_body(re)
Searches for the re in the body of the message.
Meaning of the parameters is as follows:
* re - Regular expression.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.2. search_body usage
...
if ( search_body("[Ss][Ii][Pp]") ) { /*....*/ };
...
3.3. search_hf(hf, re, flags)
Searches for the re in the body of a header field.
Meaning of the parameters is as follows:
* hf - header field name.
* re - regular expression.
* flags - control flags - it has to be one of: a - all headers
matching the name; f - only first header matching the name; l -
only the last header matching the name.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.3. search_body usage
...
if ( search_hf("From", ":test@", "a") ) { /*....*/ };
...
3.4. search_append(re, txt)
Searches for the first match of re and appends txt after it.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String to be appended.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.4. search_append usage
...
search_append("[Oo]pen[Ss]er", " SIP Proxy");
...
3.5. search_append_body(re, txt)
Searches for the first match of re in the body of the message and
appends txt after it.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String to be appended.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.5. search_append_body usage
...
search_append_body("[Oo]pen[Ss]er", " SIP Proxy");
...
3.6. replace(re, txt)
Replaces the first occurrence of re with txt.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.6. replace usage
...
replace("openser", "Kamailio SIP Proxy");
...
3.7. replace_body(re, txt)
Replaces the first occurrence of re in the body of the message with
txt.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.7. replace_body usage
...
replace_body("openser", "Kamailio SIP Proxy");
...
3.8. replace_all(re, txt)
Replaces all occurrence of re with txt.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.8. replace_all usage
...
replace_all("openser", "Kamailio SIP Proxy");
...
3.9. replace_body_all(re, txt)
Replaces all occurrence of re in the body of the message with txt.
Matching is done on a per-line basis.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.9. replace_body_all usage
...
replace_body_all("openser", "Kamailio SIP Proxy");
...
3.10. replace_body_atonce(re, txt)
Replaces all occurrence of re in the body of the message with txt.
Matching is done over the whole body.
Meaning of the parameters is as follows:
* re - Regular expression.
* txt - String.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.10. replace_body_atonce usage
...
# strip the whole body from the message:
if(has_body() && replace_body_atonce("^.+$", ""))
remove_hf("Content-Type");
...
3.11. subst('/re/repl/flags')
Replaces re with repl (sed or perl like).
Meaning of the parameters is as follows:
* '/re/repl/flags' - sed like regular expression. flags can be a
combination of i (case insensitive), g (global) or s (match newline
don't treat it as end of line).
're' - is regular expresion
'repl' - is replacement string - may contain pseudo-varibales
'flags' - substitution flags (i - ignore case, g - global)
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.11. subst usage
...
# replace the uri in to: with the message uri (just an example)
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1\u\2/ig') ) {};
# replace the uri in to: with the value of avp sip_address (just an example)
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1$avp(sip_address)\2/ig') )
{};
...
3.12. subst_uri('/re/repl/flags')
Runs the re substitution on the message uri (like subst but works only
on the uri)
Meaning of the parameters is as follows:
* '/re/repl/flags' - sed like regular expression. flags can be a
combination of i (case insensitive), g (global) or s (match newline
don't treat it as end of line).
're' - is regular expresion
'repl' - is replacement string - may contain pseudo-varibales
'flags' - substitution flags (i - ignore case, g - global)
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.12. subst_uri usage
...
# adds 3463 prefix to numeric uris, and save the original uri (\0 match)
# as a parameter: orig_uri (just an example)
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:3463\1@\2;orig_uri=\0/i')){$
# adds the avp 'uri_prefix' as prefix to numeric uris, and save the original
# uri (\0 match) as a parameter: orig_uri (just an example)
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:$avp(uri_prefix)\1@\2;orig_uri=\0/i')){$
...
3.13. subst_user('/re/repl/flags')
Runs the re substitution on the message uri (like subst_uri but works
only on the user portion of the uri)
Meaning of the parameters is as follows:
* '/re/repl/flags' - sed like regular expression. flags can be a
combination of i (case insensitive), g (global) or s (match newline
don't treat it as end of line).
're' - is regular expresion
'repl' - is replacement string - may contain pseudo-varibales
'flags' - substitution flags (i - ignore case, g - global)
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.13. subst usage
...
# adds 3463 prefix to uris ending with 3642 (just an example)
if (subst_user('/3642$/36423463/')){$
...
# adds avp 'user_prefix' as prefix to username in r-uri ending with 3642
if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
...
3.14. subst_body('/re/repl/flags')
Replaces re with repl (sed or perl like) in the body of the message.
Meaning of the parameters is as follows:
* '/re/repl/flags' - sed like regular expression. flags can be a
combination of i (case insensitive), g (global) or s (match newline
don't treat it as end of line).
're' - is regular expresion
'repl' - is replacement string - may contain pseudo-varibales
'flags' - substitution flags (i - ignore case, g - global)
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.14. subst_body usage
...
if ( subst_body('/^o=(.*) /o=$fU /') ) {};
...
3.15. subst_hf(hf, subexp, flags)
Perl-like substitutions in the body of a header field.
Meaning of the parameters is as follows:
* hf - header field name.
* subexp - substitution expression in the same format as of the
'subst' function parameter.
* flags - control flags - it has to be one of: a - all headers
matching the name; f - only first header matching the name; l -
only the last header matching the name.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.15. search_body usage
...
if ( subst_hf("From", "/:test@/:best@/", "a") ) { /*....*/ };
...
3.16. set_body(txt,content_type)
Set body to a SIP message.
Meaning of the parameters is as follows:
* txt - text for the body, can include pseudo-variables.
* content_type - value of Content-Type header, can include
pseudo-variables.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.16. set_body usage
...
set_body("test", "text/plain");
...
3.17. set_reply_body(txt,content_type)
Set body to a SIP reply to be generated by Kamailio.
Meaning of the parameters is as follows:
* txt - text for the body, can include pseudo-variables.
* content_type - value of Content-Type header, can include
pseudo-variables.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
Example 1.17. set_reply_body usage
...
set_reply_body("test", "text/plain");
...
3.18. filter_body(content_type)
Filters multipart/mixed body by leaving out all other body parts except
the first body part of given type.
Meaning of the parameters is as follows:
* content_type - Content type to be left in the body.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.18. filter_body usage
...
if (has_body("multipart/mixed")) {
if (filter_body("application/sdp") {
remove_hf("Content-Type");
append_hf("Content-Type: application/sdp\r\n");
} else {
xlog("Body part application/sdp not found\n");
}
}
...
3.19. append_to_reply(txt)
Append txt as header to the reply.
Meaning of the parameters is as follows:
* txt - String which may contains pseudo-variables.
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
FAILURE_ROUTE, ERROR_ROUTE.
Example 1.19. append_to_reply usage
...
append_to_reply("Foo: bar\r\n");
append_to_reply("Foo: $rm at $Ts\r\n");
...
3.20. append_hf(txt[, hdr])
Appends 'txt' as header after first header field or after last 'hdr'
header field.
Meaning of the parameters is as follows:
* txt - Header field to be appended. The value can contain
pseudo-variables which will be replaced at run time.
* hdr - Header name after which the 'txt' is appended.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.20. append_hf usage
...
append_hf("P-hint: VOICEMAIL\r\n");
append_hf("From-username: $fU\r\n", "Call-ID");
...
3.21. insert_hf(txt[, hdr])
Inserts 'txt' as header before the first header field or before first
'hdr' header field if 'hdr' is given.
Meaning of the parameters is as follows:
* txt - Header field to be inserted. The value can contain
pseudo-variables which will be replaced at run time.
* hdr - Header name before which the 'txt' is inserted.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.21. insert_hf usage
...
insert_hf("P-hint: VOICEMAIL\r\n");
insert_hf("To-username: $tU\r\n");
insert_hf("P-hint: VOICEMAIL\r\n", "Call-ID");
insert_hf("To-username: $tU\r\n", "Call-ID");
...
3.22. append_urihf(prefix, suffix)
Append header field name with original Request-URI in middle.
Meaning of the parameters is as follows:
* prefix - string (usually at least header field name).
* suffix - string (usually at least line terminator).
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
Example 1.22. append_urihf usage
...
append_urihf("CC-Diversion: ", "\r\n");
...
3.23. is_present_hf(hf_name)
Return true if a header field is present in message.
Note
The function is also able to distinguish the compact names. For exmaple
“From” will match with “f”
Meaning of the parameters is as follows:
* hf_name - Header field name.(long or compact form)
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.23. is_present_hf usage
...
if (is_present_hf("From")) log(1, "From HF Present");
...
3.24. is_present_hf_re(hf_name_re)
Return true if a header field whose name matches regular expression
'hf_name_re' is present in message.
Meaning of the parameters is as follows:
* hf_name_re - Regular expression to match header field name.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.24. is_present_hf_re usage
...
if (is_present_hf_re("^P-")) log(1, "There are headers starting with P-\n");
...
3.25. append_time()
Adds a time header to the reply of the request. You must use it before
functions that are likely to send a reply, e.g., save() from
'registrar' module. Header format is: “Date: %a, %d %b %Y %H:%M:%S
GMT”, with the legend:
* %a abbreviated week of day name (locale)
* %d day of month as decimal number
* %b abbreviated month name (locale)
* %Y year with century
* %H hour
* %M minutes
* %S seconds
Return true if a header was succesfully appended.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
Example 1.25. append_time usage
...
append_time();
...
3.26. append_time_to_request()
Adds a time header to the request. Header format is: “Date: %a, %d %b
%Y %H:%M:%S GMT”, with the legend:
* %a abbreviated week of day name (locale)
* %d day of month as decimal number
* %b abbreviated month name (locale)
* %Y year with century
* %H hour
* %M minutes
* %S seconds
Return true if a header was succesfully appended.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, BRANCH_ROUTE.
Example 1.26. append_time_to_request usage
...
if(!is_present_hf("Date"))
append_time_to_request();
...
3.27. is_method(name)
Check if the method of the message matches the name. If name is a known
method (invite, cancel, ack, bye, options, info, update, register,
message, subscribe, notify, refer, prack), the function performs method
ID testing (integer comparison) instead of ignore case string
comparison.
The 'name' can be a list of methods in the form of
'method1|method2|...'. In this case, the function returns true if the
SIP message's method is one from the list. IMPORTANT NOTE: in the list
must be only methods defined in Kamailio with ID (invite, cancel, ack,
bye, options, info, update, register, message, subscribe, notify,
refer, prack, publish; for more see:
http://www.iana.org/assignments/sip-parameters).
If used for replies, the function tests the value of method field from
CSeq header.
Meaning of the parameters is as follows:
* name - SIP method name
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE, and BRANCH_ROUTE.
Example 1.27. is_method usage
...
if(is_method("INVITE"))
{
# process INVITEs here
}
if(is_method("OPTION|UPDATE"))
{
# process OPTIONs and UPDATEs here
}
...
3.28. remove_hf(hname)
Remove from message all headers with name “hname”. Header matching is
case-insensitive. Matches and removes also the compact header forms.
Returns true if at least one header is found and removed.
Meaning of the parameters is as follows:
* hname - header name to be removed.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.28. remove_hf usage
...
if(remove_hf("User-Agent"))
{
# User Agent header removed
}
# compact form: remove "Contact" or "m" header
remove_hf("Contact")
# compact form: remove "Contact" or "m" header
remove_hf("m")
...
3.29. remove_hf_re(re)
Remove from message all headers with name matching regular expression
“re”
Returns true if at least one header is found and removed.
Meaning of the parameters is as follows:
* re - regular expression to match the header name to be removed.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.29. remove_hf_re usage
...
if(remove_hf_re("^P-"))
{
# All headers starting with "P-" removed
}
...
3.30. has_body(), has_body(mime)
The function returns true if the SIP message has a body attached. The
checked includes also the “Content-Length” header presence and value.
If a parameter is given, the mime described will be also checked
against the “Content-Type” header.
Meaning of the parameters is as follows:
* mime - mime to be checked against the “Content-Type” header. If not
present or 0, this check will be disabled.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.30. has_body usage
...
if(has_body("application/sdp"))
{
# do interesting stuff here
}
...
3.31. is_audio_on_hold()
The function returns true if the SIP message has a body attached and at
least one audio stream in on hold.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.31. is_audio_on_hold usage
...
if(is_audio_on_hold())
{
# do interesting stuff here
}
...
3.32. is_privacy(privacy_type)
The function returns true if the SIP message has a Privacy header field
that includes the given privacy_type among its privacy values. See
http://www.iana.org/assignments/sip-priv-values for possible privacy
type values.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.32. is_privacy usage
...
if(is_privacy("id"))
{
# do interesting stuff here
}
...
3.33. in_list(subject, list, separator)
Function checks if subject string is found in list string where list
items are separated by separator string. Subject and list strings may
contain pseudo variables. Separator string needs to be one character
long. Returns 1 if subject is found and -1 otherwise.
Function can be used from all kinds of routes.
Example 1.33. in_list() usage
...
$var(subject) = "fi";
$var(list) = "dk,fi,no,se";
if (in_list("$var(subject)", "$var(list)", ",") {
xlog("L_INFO", "subject is found in list\n");
}
...
3.34. cmp_str(str1, str2)
The function returns true if the two parameters matches as string case
sensitive comparison.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.34. cmp_str usage
...
if(cmp_str("$rU", "kamailio"))
{
# do interesting stuff here
}
...
3.35. cmp_istr(str1, str2)
The function returns true if the two parameters matches as string case
insensitive comparison.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.35. cmp_str usage
...
if(cmp_istr("$rU@you", "kamailio@YOU"))
{
# do interesting stuff here
}
...
3.36. starts_with(str1, str2)
The function returns true if the first string starts with the second
string.
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
FAILURE_ROUTE and BRANCH_ROUTE.
Example 1.36. starts_with usage
...
if (starts_with("$rU", "+358"))
{
# do interesting stuff here
}
...
3.37. set_body_multipart([txt,content_type][,boundary])
Set multipart body to a SIP message. If called with no parameters, will
convert present body to multipart.
Meaning of the parameters is as follows:
* txt - text for the body, can include pseudo-variables.
* content_type - value of Content-Type header, can include
pseudo-variables.
* boundary - string to use as boundary, can include pseudo-variables.
Default: unique-boundary-1
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
The core will take care of the last boundary ending "--". Detecting
wich one is the last and fixing the others if needed.
Example 1.37. set_body_multipart usage
...
set_body_multipart("test", "text/plain", "delimiter");
...
Will produce:
...
Content-Type: multipart/mixed;boundary="delimiter"
Mime-Version: 1.0
--delimiter
Content-Type: text/plain
text
--delimiter
...
3.38. append_body_part(txt,content_type[, content_disposition])
Append a part on multipart body SIP message. Will use
"unique-boundary-1" as boundary.
Meaning of the parameters is as follows:
* txt - text for the multipart body, can include pseudo-variables.
* content_type - value of Content-Type header, can include
pseudo-variables.
* content_disposition - value of Content-Disposition header, can
include pseudo-variables.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
The core will take care of the last boundary ending "--". Detecting
wich one is the last and fixing the others if needed.
Example 1.38. append_body_part usage
...
$var(b) = "7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c"
append_body_part("$var(b)", "application/vnd.cirpack.isdn-ext", "signal;handling
=required");
...
Will append this the body:
...
Content-Type: application/vnd.cirpack.isdn-ext
Content-Disposition: signal;handling=required
7e Od 04 55 75 69 20 4d 61 6b 65 43 61 6c 6c
--unique-boundary-1
...
3.39. remove_body_part(content_type)
Remove a part on a multipart body SIP message.
Meaning of the parameters is as follows:
* content_type - value of Content-Type header of the part to be
removed. If more than one exists the first occurrence will be
removed.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE.
The core will take care of the last boundary ending "--". Detecting
wich one is the last and fixing the others if needed.
Example 1.39. remove_body_part usage
...
remove_body_part("application/vnd.cirpack.isdn-ext");
...
4. Known Limitations
Search functions are applied to the original request, i.e., they ignore
all changes resulting from message processing in Kamailio script.
Chapter 2. Developer Guide
Table of Contents
1. Functions
1.1. load_textops(*import_structure)
1. Functions
1.1. load_textops(*import_structure)
1.1. load_textops(*import_structure)
For programmatic use only--import the Textops API.
Meaning of the parameters is as follows:
* import_structure - Pointer to the import structure - see “struct
textops_binds” in modules/textops/api.h
|