19 Daniel-Constantin Mierla
43 Copyright © 2008, 2005, 2003 1&1 Internet AG, FhG Fokus, Voice Sistem
45 __________________________________________________________________
55 2.2. External Libraries or Applications
59 3.1. ring_timeout (int)
60 3.2. options_accept (string)
61 3.3. options_accept_encoding (string)
62 3.4. contact_flds_separator (string)
63 3.5. options_accept_language (string)
64 3.6. options_support (string)
65 3.7. rpid_prefix (string)
66 3.8. rpid_suffix (string)
67 3.9. rpid_avp (string)
71 4.1. ring_insert_callid()
73 4.3. is_user(username)
76 4.6. uri_param(param,value)
77 4.7. add_uri_param(param)
78 4.8. get_uri_param(name, var)
79 4.9. tel2sip(uri, hostpart, result)
80 4.10. is_e164(pseudo-variable)
81 4.11. is_uri_user_e164(pseudo-variable)
82 4.12. is_tel_number(tval)
83 4.13. is_numeric(tval)
84 4.14. is_alphanum(tval)
85 4.15. encode_contact(encoding_prefix,hostpart)
86 4.16. decode_contact()
87 4.17. decode_contact_header()
88 4.18. cmp_uri(str1, str2)
89 4.19. cmp_aor(str1, str2)
90 4.20. append_rpid_hf()
91 4.21. append_rpid_hf(prefix, suffix)
92 4.22. is_rpid_user_e164()
93 4.23. set_uri_user(uri, user)
94 4.24. set_uri_host(uri, host)
98 4.28. is_supported(option)
100 4.30. sip_p_charging_vector(flags)
102 5. Exported pseudo-variables
112 1.1. Set ring_timeout parameter
113 1.2. Set options_accept parameter
114 1.3. Set options_accept_encoding parameter
115 1.4. Set contact_flds_separator parameter
116 1.5. Set options_accept_language parameter
117 1.6. Set options_support parameter
118 1.7. rpid_prefix parameter example
119 1.8. rpid_suffix parameter example
120 1.9. rpid_avp parameter example
121 1.10. ring_insert_callid() usage
122 1.11. options_reply usage
124 1.13. has_totag usage
125 1.14. uri_param usage
126 1.15. uri_param usage
127 1.16. add_uri_param usage
128 1.17. add_uri_param usage
131 1.20. is_uri_user_e164 usage
132 1.21. is_tel_number usage
133 1.22. is_numeric usage
134 1.23. is_alphanum usage
135 1.24. encode_contact usage
136 1.25. decode_contact usage
137 1.26. decode_contact_header usage
140 1.29. append_rpid_hf usage
141 1.30. append_rpid_hf(prefix, suffix) usage
142 1.31. is_rpid_user_e164 usage
143 1.32. set_uri_user usage
144 1.33. set_uri_host usage
145 1.34. is_request usage
147 1.36. is_gruu() usage
148 1.37. is_supported() usage
149 1.38. is_first_hop() usage
150 1.39. sip_p_charging_vector() usage
152 Chapter 1. Admin Guide
159 2.1. Kamailio Modules
160 2.2. External Libraries or Applications
164 3.1. ring_timeout (int)
165 3.2. options_accept (string)
166 3.3. options_accept_encoding (string)
167 3.4. contact_flds_separator (string)
168 3.5. options_accept_language (string)
169 3.6. options_support (string)
170 3.7. rpid_prefix (string)
171 3.8. rpid_suffix (string)
172 3.9. rpid_avp (string)
176 4.1. ring_insert_callid()
178 4.3. is_user(username)
180 4.5. uri_param(param)
181 4.6. uri_param(param,value)
182 4.7. add_uri_param(param)
183 4.8. get_uri_param(name, var)
184 4.9. tel2sip(uri, hostpart, result)
185 4.10. is_e164(pseudo-variable)
186 4.11. is_uri_user_e164(pseudo-variable)
187 4.12. is_tel_number(tval)
188 4.13. is_numeric(tval)
189 4.14. is_alphanum(tval)
190 4.15. encode_contact(encoding_prefix,hostpart)
191 4.16. decode_contact()
192 4.17. decode_contact_header()
193 4.18. cmp_uri(str1, str2)
194 4.19. cmp_aor(str1, str2)
195 4.20. append_rpid_hf()
196 4.21. append_rpid_hf(prefix, suffix)
197 4.22. is_rpid_user_e164()
198 4.23. set_uri_user(uri, user)
199 4.24. set_uri_host(uri, host)
203 4.28. is_supported(option)
205 4.30. sip_p_charging_vector(flags)
207 5. Exported pseudo-variables
217 This module implement various functions and checks related to SIP
218 message handling and URI handling.
220 It offers some functions related to handle ringing. In a parallel
221 forking scenario you get several 183s with SDP. You don't want that
222 your customers hear more than one ringtone or answer machine in
223 parallel on the phone. So its necessary to drop the 183 in this cases
224 and send a 180 instead.
226 This module also provides a function to answer OPTIONS requests which
227 are directed to the server itself. This means an OPTIONS request which
228 has the address of the server in the request URI, and no username in
229 the URI. The request will be answered with a 200 OK with the
230 capabilities of the server.
232 To answer OPTIONS request directed to your server is the easiest way
233 for is-alive-tests on the SIP (application) layer from remote (similar
234 to ICMP echo requests, also known as “ping”, on the network layer).
238 2.1. Kamailio Modules
239 2.2. External Libraries or Applications
241 2.1. Kamailio Modules
243 The following modules must be loaded before this module:
244 * sl -- Stateless replies.
246 2.2. External Libraries or Applications
248 The following libraries or applications must be installed before
249 running Kamailio with this module loaded:
254 3.1. ring_timeout (int)
255 3.2. options_accept (string)
256 3.3. options_accept_encoding (string)
257 3.4. contact_flds_separator (string)
258 3.5. options_accept_language (string)
259 3.6. options_support (string)
260 3.7. rpid_prefix (string)
261 3.8. rpid_suffix (string)
262 3.9. rpid_avp (string)
264 3.1. ring_timeout (int)
266 Timeout value in seconds, define how long the call-id is stored in the
267 internal list kept for replacing 183 messages with 180. A reasonable
270 Default value is “0”. This means functionality is disabled.
272 Example 1.1. Set ring_timeout parameter
274 modparam("siputils", "ring_timeout", 30)
277 3.2. options_accept (string)
279 This parameter is the content of the Accept header field. Note: it is
280 not clearly written in RFC3261 if a proxy should accept any content
281 (the default “*/*”) because it does not care about content. Or if it
282 does not accept any content, which is “”.
284 Default value is “*/*”.
286 Example 1.2. Set options_accept parameter
288 modparam("siputils", "options_accept", "application/*")
291 3.3. options_accept_encoding (string)
293 This parameter is the content of the Accept-Encoding header field.
294 Please do not change the default value because Kamailio does not
295 support any encodings yet.
299 Example 1.3. Set options_accept_encoding parameter
301 modparam("siputils", "options_accept_encoding", "gzip")
304 3.4. contact_flds_separator (string)
306 First char of this parameter is used as separator for encoding/decoding
311 First char of this field must be set to a value which is not used
312 inside username,password or other fields of contact. Otherwise it is
313 possible for the decoding step to fail/produce wrong results.
315 Default value is “*”.
317 Example 1.4. Set contact_flds_separator parameter
319 modparam("siputils", "contact_flds_separator", "-")
322 then an encoded uri might look
323 sip:user-password-ip-port-protocol@PublicIP
325 3.5. options_accept_language (string)
327 This parameter is the content of the Accept-Language header field. You
328 can set any language code which you prefer for error descriptions from
329 other devices, but presumably there are not many devices around which
330 support other languages than the default English.
332 Default value is “en”.
334 Example 1.5. Set options_accept_language parameter
336 modparam("siputils", "options_accept_language", "de")
339 3.6. options_support (string)
341 This parameter is the content of the Support header field, indicating
342 SIP extensions. Please do not change the default value, because
343 Kamailio currently does not support any of the SIP extensions
344 registered at the IANA.
348 Example 1.6. Set options_support parameter
350 modparam("siputils", "options_support", "100rel")
353 3.7. rpid_prefix (string)
355 Prefix to be added to Remote-Party-ID header field just before the URI
356 returned from either radius or database.
360 Example 1.7. rpid_prefix parameter example
361 modparam("auth", "rpid_prefix", "Whatever <")
363 3.8. rpid_suffix (string)
365 Suffix to be added to Remote-Party-ID header field after the URI
366 returned from either radius or database.
368 Default value is “;party=calling;id-type=subscriber;screen=yes”.
370 Example 1.8. rpid_suffix parameter example
371 modparam("auth", "rpid_suffix", "@1.2.3.4>")
373 3.9. rpid_avp (string)
375 Full AVP specification for the AVP which stores the RPID value. It used
376 to transport the RPID value from authentication backend modules
377 (auth_db or auth_radius) or from script to the auth function
378 append_rpid_hf and is_rpid_user_e164.
380 If defined to NULL string, all RPID functions will fail at runtime.
382 Default value is “$avp(s:rpid)”.
384 Example 1.9. rpid_avp parameter example
385 modparam("auth", "rpid_avp", "$avp(myrpid)")
389 4.1. ring_insert_callid()
391 4.3. is_user(username)
393 4.5. uri_param(param)
394 4.6. uri_param(param,value)
395 4.7. add_uri_param(param)
396 4.8. get_uri_param(name, var)
397 4.9. tel2sip(uri, hostpart, result)
398 4.10. is_e164(pseudo-variable)
399 4.11. is_uri_user_e164(pseudo-variable)
400 4.12. is_tel_number(tval)
401 4.13. is_numeric(tval)
402 4.14. is_alphanum(tval)
403 4.15. encode_contact(encoding_prefix,hostpart)
404 4.16. decode_contact()
405 4.17. decode_contact_header()
406 4.18. cmp_uri(str1, str2)
407 4.19. cmp_aor(str1, str2)
408 4.20. append_rpid_hf()
409 4.21. append_rpid_hf(prefix, suffix)
410 4.22. is_rpid_user_e164()
411 4.23. set_uri_user(uri, user)
412 4.24. set_uri_host(uri, host)
416 4.28. is_supported(option)
418 4.30. sip_p_charging_vector(flags)
420 4.1. ring_insert_callid()
422 Inserting the call-id in the internal list, which is checked when
423 further replies arrive. Any 183 reply that is received during the
424 timeout value will be converted to a 180 message. Please note that you
425 need to set a positive timeout value in order to use this function.
427 The function returns TRUE on success, and FALSE during processing
430 This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
432 Example 1.10. ring_insert_callid() usage
434 ring_insert_callid();
439 This function checks if the request method is OPTIONS and if the
440 request URI does not contain an username. If both is true the request
441 will be answered stateless with “200 OK” and the capabilities from the
444 It sends “500 Server Internal Error” for some errors and returns false
445 if it is called for a wrong request.
447 The check for the request method and the missing username is optional
448 because it is also done by the function itself. But you should not call
449 this function outside the myself check because in this case the
450 function could answer OPTIONS requests which are sent to you as
451 outbound proxy but with an other destination then your proxy (this
452 check is currently missing in the function).
454 This function can be used from REQUEST_ROUTE.
456 Example 1.11. options_reply usage
459 if ((method==OPTIONS) && (! uri=~"sip:.*[@]+.*")) {
465 4.3. is_user(username)
467 Check if the username in credentials matches the given username.
469 Meaning of the parameters is as follows:
470 * username - Username string.
472 This function can be used from REQUEST_ROUTE.
474 Example 1.12. is_user usage
476 if (is_user("john")) {
483 Check if To header field uri contains tag parameter.
485 This function can be used from ANY_ROUTE.
487 Example 1.13. has_totag usage
494 4.5. uri_param(param)
496 Find if Request URI has a given parameter with no value
498 Meaning of the parameters is as follows:
499 * param - parameter name to look for.
501 This function can be used from REQUEST_ROUTE.
503 Example 1.14. uri_param usage
505 if (uri_param("param1")) {
510 4.6. uri_param(param,value)
512 Find if Request URI has a given parameter with matching value
514 Meaning of the parameters is as follows:
515 * param - parameter name to look for.
516 * value - parameter value to match.
518 This function can be used from REQUEST_ROUTE.
520 Example 1.15. uri_param usage
522 if (uri_param("param1","value1")) {
527 4.7. add_uri_param(param)
529 Add to RURI a parameter (name=value);
531 Meaning of the parameters is as follows:
532 * param - parameter to be appended in “name=value” format.
534 This function can be used from REQUEST_ROUTE.
536 Example 1.16. add_uri_param usage
538 add_uri_param("nat=yes");
541 4.8. get_uri_param(name, var)
543 Get the value of RURI parameter.
545 Meaning of the parameters is as follows:
546 * name - the name of R-URI parameter
547 * var - the variable where to store the value of the parameter
549 This function can be used from REQUEST_ROUTE.
551 Example 1.17. add_uri_param usage
553 get_uri_param("nat", "$var(nat)");
556 4.9. tel2sip(uri, hostpart, result)
558 Converts URI in first param (pseudo variable or string) to SIP URI, if
559 it is a tel URI. If conversion was done, writes resulting SIP URI to
560 third param (pseudo variable). Returns 1 if conversion succeeded or if
561 no conversion was needed.
563 The conversion follows the rules in RFC 3261 section 19.1.6:
564 * Visual separators ( "-", ".", "(", ")" ) are removed from tel URI
565 number before converting it to SIP URI userinfo.
566 * tel URI parameters are downcased before appending them to SIP URI
569 The SIP URI hostpart is taken from second param (pseudo variable or
572 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
573 BRANCH_ROUTE, or ONREPLY_ROUTE.
575 Example 1.18. tel2sip usage
577 # $ru: tel:+(34)-999-888-777
578 # $fu: sip:test@foo.com
579 tel2sip("$ru", $fd", "$ru");
580 # $ru: sip:+34999888777@foo.com;user=phone
582 # $ru: tel:+12-(34)-56-78;Ext=200;ISUB=+123-456
583 # $fu: sip:test@foo.com
584 tel2sip("$ru", $fd", "$ru");
585 # $ru: sip:+12345678;ext=200;isub=+123-456@foo.com;user=phone
588 4.10. is_e164(pseudo-variable)
590 Checks if string value of pseudo variable argument is an E164 number.
592 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, and
595 Example 1.19. is_e164 usage
597 if (is_164("$fU")) { # Check From header URI user part
600 if (is_e164("$avp(i:705)") {
601 # Check stgring value stored in avp i:705
606 4.11. is_uri_user_e164(pseudo-variable)
608 Checks if userpart of URI stored in pseudo variable is E164 number.
610 This function can be used from ANY_ROUTE.
612 Example 1.20. is_uri_user_e164 usage
614 if (is_uri_user_e164("$fu")) { # Check From header URI user part
617 if (is_uri_user_e164("$avp(i:705)") {
618 # Check user part of URI stored in avp i:705
623 4.12. is_tel_number(tval)
625 Checks if the parameter value is a telephone number: starting with one
626 optional +, followed by digits. The parameter can include variables.
628 This function can be used from ANY_ROUTE.
630 Example 1.21. is_tel_number usage
632 if (is_tel_number("$rU")) { # Test if R-URI user is telephone number
635 if (is_tel_number("+24242424") {
640 4.13. is_numeric(tval)
642 Checks if the parameter value consists solely of decimal digits. The
643 parameter can include variables.
645 This function can be used from ANY_ROUTE.
647 Example 1.22. is_numeric usage
649 if (is_numeric("$rU")) { # Test if R-URI user consists of decimal digits
654 4.14. is_alphanum(tval)
656 Checks if the parameter value consists solely of decimal digits or
657 alphabetic ASCII characters. The parameter can include variables.
659 This function can be used from ANY_ROUTE.
661 Example 1.23. is_alphanum usage
663 if (is_alphanum("$rU")) {
668 4.15. encode_contact(encoding_prefix,hostpart)
670 This function will encode uri-s inside Contact header in the following
671 manner sip:username:password@ip:port;transport=protocol goes
672 sip:encoding_prefix*username*ip*port*protocol@hostpart.
674 * is the default separator and can be changed by setting the
675 contact_flds_separator module parameter.
677 Note: This function discards all of the URI parameters. Thus, none of
678 the parameters (except the transport parameter which is encoded into
679 the userpart) can be restored.
681 The function returns negative on error, 1 on success.
683 Meaning of the parameters is as follows:
684 * encoding_prefix - Something to allow us to determine that a contact
686 * hostpart - An IP address or a hostname.
688 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
690 Example 1.24. encode_contact usage
692 if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
695 4.16. decode_contact()
697 This function will decode the request URI. If the RURI is in the format
698 sip:encoding_prefix*username*ip*port*protocol@hostpart it will be
699 decoded to sip:username:password@ip:port;transport=protocol It uses the
700 default set parameter for contact encoding separator.
702 The function returns negative on error, 1 on success.
704 Meaning of the parameters is as follows:
706 This function can be used from REQUEST_ROUTE.
708 Example 1.25. decode_contact usage
710 if (uri =~ "^sip:natted_client") { decode_contact(); }
713 4.17. decode_contact_header()
715 This function will decode URIs inside Contact header. If the URI in the
716 format sip:encoding_prefix*username*ip*port*protocol@hostpart it will
717 be decoded to sip:username:password@ip:port;transport=protocol. It uses
718 the default set parameter for contact encoding separator.
720 The function returns negative on error, 1 on success.
722 Meaning of the parameters is as follows:
724 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
726 Example 1.26. decode_contact_header usage
730 decode_contact_header();
735 4.18. cmp_uri(str1, str2)
737 The function returns true if the two parameters matches as SIP URI.
739 This function can be used from ANY_ROUTE.
741 Example 1.27. cmp_uri usage
743 if(cmp_uri("$ru", "sip:kamailio@kamailio.org"))
745 # do interesting stuff here
749 4.19. cmp_aor(str1, str2)
751 The function returns true if the two parameters matches as AoR. The
752 parameters have to be SIP URIs.
754 This function can be used from ANY_ROUTE.
756 Example 1.28. cmp_aor usage
758 if(cmp_aor("$rU@KaMaIlIo.org", "sip:kamailio@$fd"))
760 # do interesting stuff here
764 4.20. append_rpid_hf()
766 Appends to the message a Remote-Party-ID header that contains header
767 'Remote-Party-ID: ' followed by the saved value of the SIP URI received
768 from the database or radius server followed by the value of module
769 parameter radius_rpid_suffix. The function does nothing if no saved SIP
772 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
775 Example 1.29. append_rpid_hf usage
777 append_rpid_hf(); # Append Remote-Party-ID header field
780 4.21. append_rpid_hf(prefix, suffix)
782 This function is the same as Section 4.20, “ append_rpid_hf()”. The
783 only difference is that it accepts two parameters--prefix and suffix to
784 be added to Remote-Party-ID header field. This function ignores
785 rpid_prefix and rpid_suffix parameters, instead of that allows to set
788 Meaning of the parameters is as follows:
789 * prefix - Prefix of the Remote-Party-ID URI. The string will be
790 added at the begining of body of the header field, just before the
792 * suffix - Suffix of the Remote-Party-ID header field. The string
793 will be appended at the end of the header field. It can be used to
794 set various URI parameters, for example.
796 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
799 Example 1.30. append_rpid_hf(prefix, suffix) usage
801 # Append Remote-Party-ID header field
802 append_rpid_hf("", ";party=calling;id-type=subscriber;screen=yes");
805 4.22. is_rpid_user_e164()
807 The function checks if the SIP URI received from the database or radius
808 server and will potentially be used in Remote-Party-ID header field
809 contains an E164 number (+followed by up to 15 decimal digits) in its
810 user part. Check fails, if no such SIP URI exists (i.e. radius server
811 or database didn't provide this information).
813 This function can be used from REQUEST_ROUTE.
815 Example 1.31. is_rpid_user_e164 usage
817 if (is_rpid_user_e164()) {
822 4.23. set_uri_user(uri, user)
824 Sets userpart of SIP URI stored in writable pseudo variable 'uri' to
825 value of pseudo variable 'user'.
827 This function can be used from ANY_ROUTE.
829 Example 1.32. set_uri_user usage
831 $var(uri) = "sip:user@host";
832 $var(user) = "new_user";
833 set_uri_user("$var(uri)", "$var(user)");
836 4.24. set_uri_host(uri, host)
838 Sets hostpart of SIP URI stored in writable pseudo variable 'uri' to
839 value of pseudo variable 'host'.
841 This function can be used from ANY_ROUTE.
843 Example 1.33. set_uri_host usage
845 $var(uri) = "sip:user@host";
846 $var(host) = "new_host";
847 set_uri_host("$var(uri)", "$var(host)");
852 Return true if the SIP message is a request.
854 This function can be used from ANY_ROUTE.
856 Example 1.34. is_request usage
865 Return true if the SIP message is a reply.
867 This function can be used from ANY_ROUTE.
869 Example 1.35. is_reply usage
878 The function returns true if the uri is GRUU ('gr' parameter is
879 present): 1 - pub-gruu; 2 - temp-gruu.
881 Meaning of the parameters is as follows:
882 * uri - the SIP URI to check for GRUU parameter. It is optional, when
883 missing, the value of R-URI is used.
885 This function can be used from ANY_ROUTE.
887 Example 1.36. is_gruu() usage
889 if(is_gruu()) { ... }
892 4.28. is_supported(option)
894 Function returns true if given option is listed in Supported header(s)
895 (if any) of the request. Currently the following options are known:
896 path, 100rel, timer, eventlist, gruu, and outbound.
898 This function can be used from ANY_ROUTE.
900 Example 1.37. is_supported() usage
902 if (is_supported("outbound")) { ... }
907 The function returns true if the proxy is first hop after the original
908 sender. For incoming SIP requests, it means there is only one Via
909 header. For incoming SIP replies, it means that top Record-Route URI is
910 'myself' and source address is not matching it (to avoid detecting in
911 case of local loops). Note that it does not detect spirals, which can
912 have the condition for replies true also in the case of additional SIP
915 This function can be used from ANY_ROUTE.
917 Example 1.38. is_first_hop() usage
919 if(is_first_hop()) { ... }
922 4.30. sip_p_charging_vector(flags)
924 Manage the P-Charging-Vector header (RFC7315). The flags can be: 'r' -
925 remove; 'g' - generate; 'f' - force (remove + generate).
927 This function can be used from ANY_ROUTE.
929 Example 1.39. sip_p_charging_vector() usage
931 sip_p_charging_vector("g");
934 5. Exported pseudo-variables
944 full P-Charging-Vector header
948 icid-value field (see RFC7315 section 5.6)
952 icid-generated-at field (see RFC7315 section 5.6)
956 orig-ioi field (see RFC7315 section 5.6)
960 term-ioi field (see RFC7315 section 5.6)