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. is_alphanumex(tval, eset)
86 4.16. encode_contact(encoding_prefix,hostpart)
87 4.17. decode_contact()
88 4.18. decode_contact_header()
89 4.19. cmp_uri(str1, str2)
90 4.20. cmp_aor(str1, str2)
91 4.21. append_rpid_hf()
92 4.22. append_rpid_hf(prefix, suffix)
93 4.23. is_rpid_user_e164()
94 4.24. set_uri_user(uri, user)
95 4.25. set_uri_host(uri, host)
99 4.29. is_supported(option)
101 4.31. sip_p_charging_vector(flags)
103 5. Exported pseudo-variables
113 1.1. Set ring_timeout parameter
114 1.2. Set options_accept parameter
115 1.3. Set options_accept_encoding parameter
116 1.4. Set contact_flds_separator parameter
117 1.5. Set options_accept_language parameter
118 1.6. Set options_support parameter
119 1.7. rpid_prefix parameter example
120 1.8. rpid_suffix parameter example
121 1.9. rpid_avp parameter example
122 1.10. ring_insert_callid() usage
123 1.11. options_reply usage
125 1.13. has_totag usage
126 1.14. uri_param usage
127 1.15. uri_param usage
128 1.16. add_uri_param usage
129 1.17. add_uri_param usage
132 1.20. is_uri_user_e164 usage
133 1.21. is_tel_number usage
134 1.22. is_numeric usage
135 1.23. is_alphanum usage
136 1.24. is_alphanumex usage
137 1.25. encode_contact usage
138 1.26. decode_contact usage
139 1.27. decode_contact_header usage
142 1.30. append_rpid_hf usage
143 1.31. append_rpid_hf(prefix, suffix) usage
144 1.32. is_rpid_user_e164 usage
145 1.33. set_uri_user usage
146 1.34. set_uri_host usage
147 1.35. is_request usage
149 1.37. is_gruu() usage
150 1.38. is_supported() usage
151 1.39. is_first_hop() usage
152 1.40. sip_p_charging_vector() usage
154 Chapter 1. Admin Guide
161 2.1. Kamailio Modules
162 2.2. External Libraries or Applications
166 3.1. ring_timeout (int)
167 3.2. options_accept (string)
168 3.3. options_accept_encoding (string)
169 3.4. contact_flds_separator (string)
170 3.5. options_accept_language (string)
171 3.6. options_support (string)
172 3.7. rpid_prefix (string)
173 3.8. rpid_suffix (string)
174 3.9. rpid_avp (string)
178 4.1. ring_insert_callid()
180 4.3. is_user(username)
182 4.5. uri_param(param)
183 4.6. uri_param(param,value)
184 4.7. add_uri_param(param)
185 4.8. get_uri_param(name, var)
186 4.9. tel2sip(uri, hostpart, result)
187 4.10. is_e164(pseudo-variable)
188 4.11. is_uri_user_e164(pseudo-variable)
189 4.12. is_tel_number(tval)
190 4.13. is_numeric(tval)
191 4.14. is_alphanum(tval)
192 4.15. is_alphanumex(tval, eset)
193 4.16. encode_contact(encoding_prefix,hostpart)
194 4.17. decode_contact()
195 4.18. decode_contact_header()
196 4.19. cmp_uri(str1, str2)
197 4.20. cmp_aor(str1, str2)
198 4.21. append_rpid_hf()
199 4.22. append_rpid_hf(prefix, suffix)
200 4.23. is_rpid_user_e164()
201 4.24. set_uri_user(uri, user)
202 4.25. set_uri_host(uri, host)
206 4.29. is_supported(option)
208 4.31. sip_p_charging_vector(flags)
210 5. Exported pseudo-variables
220 This module implement various functions and checks related to SIP
221 message handling and URI handling.
223 It offers some functions related to handle ringing. In a parallel
224 forking scenario you get several 183s with SDP. You don't want that
225 your customers hear more than one ringtone or answer machine in
226 parallel on the phone. So its necessary to drop the 183 in this cases
227 and send a 180 instead.
229 This module also provides a function to answer OPTIONS requests which
230 are directed to the server itself. This means an OPTIONS request which
231 has the address of the server in the request URI, and no username in
232 the URI. The request will be answered with a 200 OK with the
233 capabilities of the server.
235 To answer OPTIONS request directed to your server is the easiest way
236 for is-alive-tests on the SIP (application) layer from remote (similar
237 to ICMP echo requests, also known as “ping”, on the network layer).
241 2.1. Kamailio Modules
242 2.2. External Libraries or Applications
244 2.1. Kamailio Modules
246 The following modules must be loaded before this module:
247 * sl -- Stateless replies.
249 2.2. External Libraries or Applications
251 The following libraries or applications must be installed before
252 running Kamailio with this module loaded:
257 3.1. ring_timeout (int)
258 3.2. options_accept (string)
259 3.3. options_accept_encoding (string)
260 3.4. contact_flds_separator (string)
261 3.5. options_accept_language (string)
262 3.6. options_support (string)
263 3.7. rpid_prefix (string)
264 3.8. rpid_suffix (string)
265 3.9. rpid_avp (string)
267 3.1. ring_timeout (int)
269 Timeout value in seconds, define how long the call-id is stored in the
270 internal list kept for replacing 183 messages with 180. A reasonable
273 Default value is “0”. This means functionality is disabled.
275 Example 1.1. Set ring_timeout parameter
277 modparam("siputils", "ring_timeout", 30)
280 3.2. options_accept (string)
282 This parameter is the content of the Accept header field. Note: it is
283 not clearly written in RFC3261 if a proxy should accept any content
284 (the default “*/*”) because it does not care about content. Or if it
285 does not accept any content, which is “”.
287 Default value is “*/*”.
289 Example 1.2. Set options_accept parameter
291 modparam("siputils", "options_accept", "application/*")
294 3.3. options_accept_encoding (string)
296 This parameter is the content of the Accept-Encoding header field.
297 Please do not change the default value because Kamailio does not
298 support any encodings yet.
302 Example 1.3. Set options_accept_encoding parameter
304 modparam("siputils", "options_accept_encoding", "gzip")
307 3.4. contact_flds_separator (string)
309 First char of this parameter is used as separator for encoding/decoding
314 First char of this field must be set to a value which is not used
315 inside username,password or other fields of contact. Otherwise it is
316 possible for the decoding step to fail/produce wrong results.
318 Default value is “*”.
320 Example 1.4. Set contact_flds_separator parameter
322 modparam("siputils", "contact_flds_separator", "-")
325 then an encoded uri might look
326 sip:user-password-ip-port-protocol@PublicIP
328 3.5. options_accept_language (string)
330 This parameter is the content of the Accept-Language header field. You
331 can set any language code which you prefer for error descriptions from
332 other devices, but presumably there are not many devices around which
333 support other languages than the default English.
335 Default value is “en”.
337 Example 1.5. Set options_accept_language parameter
339 modparam("siputils", "options_accept_language", "de")
342 3.6. options_support (string)
344 This parameter is the content of the Support header field, indicating
345 SIP extensions. Please do not change the default value, because
346 Kamailio currently does not support any of the SIP extensions
347 registered at the IANA.
351 Example 1.6. Set options_support parameter
353 modparam("siputils", "options_support", "100rel")
356 3.7. rpid_prefix (string)
358 Prefix to be added to Remote-Party-ID header field just before the URI
359 returned from either radius or database.
363 Example 1.7. rpid_prefix parameter example
364 modparam("auth", "rpid_prefix", "Whatever <")
366 3.8. rpid_suffix (string)
368 Suffix to be added to Remote-Party-ID header field after the URI
369 returned from either radius or database.
371 Default value is “;party=calling;id-type=subscriber;screen=yes”.
373 Example 1.8. rpid_suffix parameter example
374 modparam("auth", "rpid_suffix", "@1.2.3.4>")
376 3.9. rpid_avp (string)
378 Full AVP specification for the AVP which stores the RPID value. It used
379 to transport the RPID value from authentication backend modules
380 (auth_db or auth_radius) or from script to the auth function
381 append_rpid_hf and is_rpid_user_e164.
383 If defined to NULL string, all RPID functions will fail at runtime.
385 Default value is “$avp(s:rpid)”.
387 Example 1.9. rpid_avp parameter example
388 modparam("auth", "rpid_avp", "$avp(myrpid)")
392 4.1. ring_insert_callid()
394 4.3. is_user(username)
396 4.5. uri_param(param)
397 4.6. uri_param(param,value)
398 4.7. add_uri_param(param)
399 4.8. get_uri_param(name, var)
400 4.9. tel2sip(uri, hostpart, result)
401 4.10. is_e164(pseudo-variable)
402 4.11. is_uri_user_e164(pseudo-variable)
403 4.12. is_tel_number(tval)
404 4.13. is_numeric(tval)
405 4.14. is_alphanum(tval)
406 4.15. is_alphanumex(tval, eset)
407 4.16. encode_contact(encoding_prefix,hostpart)
408 4.17. decode_contact()
409 4.18. decode_contact_header()
410 4.19. cmp_uri(str1, str2)
411 4.20. cmp_aor(str1, str2)
412 4.21. append_rpid_hf()
413 4.22. append_rpid_hf(prefix, suffix)
414 4.23. is_rpid_user_e164()
415 4.24. set_uri_user(uri, user)
416 4.25. set_uri_host(uri, host)
420 4.29. is_supported(option)
422 4.31. sip_p_charging_vector(flags)
424 4.1. ring_insert_callid()
426 Inserting the call-id in the internal list, which is checked when
427 further replies arrive. Any 183 reply that is received during the
428 timeout value will be converted to a 180 message. Please note that you
429 need to set a positive timeout value in order to use this function.
431 The function returns TRUE on success, and FALSE during processing
434 This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
436 Example 1.10. ring_insert_callid() usage
438 ring_insert_callid();
443 This function checks if the request method is OPTIONS and if the
444 request URI does not contain an username. If both is true the request
445 will be answered stateless with “200 OK” and the capabilities from the
448 It sends “500 Server Internal Error” for some errors and returns false
449 if it is called for a wrong request.
451 The check for the request method and the missing username is optional
452 because it is also done by the function itself. But you should not call
453 this function outside the myself check because in this case the
454 function could answer OPTIONS requests which are sent to you as
455 outbound proxy but with an other destination then your proxy (this
456 check is currently missing in the function).
458 This function can be used from REQUEST_ROUTE.
460 Example 1.11. options_reply usage
463 if ((method==OPTIONS) && (! uri=~"sip:.*[@]+.*")) {
469 4.3. is_user(username)
471 Check if the username in credentials matches the given username.
473 Meaning of the parameters is as follows:
474 * username - Username string.
476 This function can be used from REQUEST_ROUTE.
478 Example 1.12. is_user usage
480 if (is_user("john")) {
487 Check if To header field uri contains tag parameter.
489 This function can be used from ANY_ROUTE.
491 Example 1.13. has_totag usage
498 4.5. uri_param(param)
500 Find if Request URI has a given parameter with no value
502 Meaning of the parameters is as follows:
503 * param - parameter name to look for.
505 This function can be used from REQUEST_ROUTE.
507 Example 1.14. uri_param usage
509 if (uri_param("param1")) {
514 4.6. uri_param(param,value)
516 Find if Request URI has a given parameter with matching value
518 Meaning of the parameters is as follows:
519 * param - parameter name to look for.
520 * value - parameter value to match.
522 This function can be used from REQUEST_ROUTE.
524 Example 1.15. uri_param usage
526 if (uri_param("param1","value1")) {
531 4.7. add_uri_param(param)
533 Add to RURI a parameter (name=value);
535 Meaning of the parameters is as follows:
536 * param - parameter to be appended in “name=value” format.
538 This function can be used from REQUEST_ROUTE.
540 Example 1.16. add_uri_param usage
542 add_uri_param("nat=yes");
545 4.8. get_uri_param(name, var)
547 Get the value of RURI parameter.
549 Meaning of the parameters is as follows:
550 * name - the name of R-URI parameter
551 * var - the variable where to store the value of the parameter
553 This function can be used from REQUEST_ROUTE.
555 Example 1.17. add_uri_param usage
557 get_uri_param("nat", "$var(nat)");
560 4.9. tel2sip(uri, hostpart, result)
562 Converts URI in first param (pseudo variable or string) to SIP URI, if
563 it is a tel URI. If conversion was done, writes resulting SIP URI to
564 third param (pseudo variable). Returns 1 if conversion succeeded or if
565 no conversion was needed.
567 The conversion follows the rules in RFC 3261 section 19.1.6:
568 * Visual separators ( "-", ".", "(", ")" ) are removed from tel URI
569 number before converting it to SIP URI userinfo.
570 * tel URI parameters are downcased before appending them to SIP URI
573 The SIP URI hostpart is taken from second param (pseudo variable or
576 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
577 BRANCH_ROUTE, or ONREPLY_ROUTE.
579 Example 1.18. tel2sip usage
581 # $ru: tel:+(34)-999-888-777
582 # $fu: sip:test@foo.com
583 tel2sip("$ru", $fd", "$ru");
584 # $ru: sip:+34999888777@foo.com;user=phone
586 # $ru: tel:+12-(34)-56-78;Ext=200;ISUB=+123-456
587 # $fu: sip:test@foo.com
588 tel2sip("$ru", $fd", "$ru");
589 # $ru: sip:+12345678;ext=200;isub=+123-456@foo.com;user=phone
592 4.10. is_e164(pseudo-variable)
594 Checks if string value of pseudo variable argument is an E164 number.
596 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, and
599 Example 1.19. is_e164 usage
601 if (is_164("$fU")) { # Check From header URI user part
604 if (is_e164("$avp(i:705)") {
605 # Check stgring value stored in avp i:705
610 4.11. is_uri_user_e164(pseudo-variable)
612 Checks if userpart of URI stored in pseudo variable is E164 number.
614 This function can be used from ANY_ROUTE.
616 Example 1.20. is_uri_user_e164 usage
618 if (is_uri_user_e164("$fu")) { # Check From header URI user part
621 if (is_uri_user_e164("$avp(i:705)") {
622 # Check user part of URI stored in avp i:705
627 4.12. is_tel_number(tval)
629 Checks if the parameter value is a telephone number: starting with one
630 optional +, followed by digits. The parameter can include variables.
632 This function can be used from ANY_ROUTE.
634 Example 1.21. is_tel_number usage
636 if (is_tel_number("$rU")) { # Test if R-URI user is telephone number
639 if (is_tel_number("+24242424") {
644 4.13. is_numeric(tval)
646 Checks if the parameter value consists solely of decimal digits. The
647 parameter can include variables.
649 This function can be used from ANY_ROUTE.
651 Example 1.22. is_numeric usage
653 if (is_numeric("$rU")) { # Test if R-URI user consists of decimal digits
658 4.14. is_alphanum(tval)
660 Checks if the parameter value consists solely of decimal digits or
661 alphabetic ASCII characters. The parameter can include variables.
663 This function can be used from ANY_ROUTE.
665 Example 1.23. is_alphanum usage
667 if (is_alphanum("$rU")) {
672 4.15. is_alphanumex(tval, eset)
674 Checks if the value of parameter 'tval' consists solely of decimal
675 digits, alphabetic ASCII characters and the characters in the second
676 parameter 'eset'. The parameters can include variables.
678 This function can be used from ANY_ROUTE.
680 Example 1.24. is_alphanumex usage
682 if (is_alphanumex("$rU", "+.-_")) {
687 4.16. encode_contact(encoding_prefix,hostpart)
689 This function will encode uri-s inside Contact header in the following
690 manner sip:username:password@ip:port;transport=protocol goes
691 sip:encoding_prefix*username*ip*port*protocol@hostpart.
693 * is the default separator and can be changed by setting the
694 contact_flds_separator module parameter.
696 Note: This function discards all of the URI parameters. Thus, none of
697 the parameters (except the transport parameter which is encoded into
698 the userpart) can be restored.
700 The function returns negative on error, 1 on success.
702 Meaning of the parameters is as follows:
703 * encoding_prefix - Something to allow us to determine that a contact
705 * hostpart - An IP address or a hostname.
707 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
709 Example 1.25. encode_contact usage
711 if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
714 4.17. decode_contact()
716 This function will decode the request URI. If the RURI is in the format
717 sip:encoding_prefix*username*ip*port*protocol@hostpart it will be
718 decoded to sip:username:password@ip:port;transport=protocol It uses the
719 default set parameter for contact encoding separator.
721 The function returns negative on error, 1 on success.
723 Meaning of the parameters is as follows:
725 This function can be used from REQUEST_ROUTE.
727 Example 1.26. decode_contact usage
729 if (uri =~ "^sip:natted_client") { decode_contact(); }
732 4.18. decode_contact_header()
734 This function will decode URIs inside Contact header. If the URI in the
735 format sip:encoding_prefix*username*ip*port*protocol@hostpart it will
736 be decoded to sip:username:password@ip:port;transport=protocol. It uses
737 the default set parameter for contact encoding separator.
739 The function returns negative on error, 1 on success.
741 Meaning of the parameters is as follows:
743 This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
745 Example 1.27. decode_contact_header usage
749 decode_contact_header();
754 4.19. cmp_uri(str1, str2)
756 The function returns true if the two parameters matches as SIP URI.
758 This function can be used from ANY_ROUTE.
760 Example 1.28. cmp_uri usage
762 if(cmp_uri("$ru", "sip:kamailio@kamailio.org"))
764 # do interesting stuff here
768 4.20. cmp_aor(str1, str2)
770 The function returns true if the two parameters matches as AoR. The
771 parameters have to be SIP URIs.
773 This function can be used from ANY_ROUTE.
775 Example 1.29. cmp_aor usage
777 if(cmp_aor("$rU@KaMaIlIo.org", "sip:kamailio@$fd"))
779 # do interesting stuff here
783 4.21. append_rpid_hf()
785 Appends to the message a Remote-Party-ID header that contains header
786 'Remote-Party-ID: ' followed by the saved value of the SIP URI received
787 from the database or radius server followed by the value of module
788 parameter radius_rpid_suffix. The function does nothing if no saved SIP
791 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
794 Example 1.30. append_rpid_hf usage
796 append_rpid_hf(); # Append Remote-Party-ID header field
799 4.22. append_rpid_hf(prefix, suffix)
801 This function is the same as Section 4.21, “ append_rpid_hf()”. The
802 only difference is that it accepts two parameters--prefix and suffix to
803 be added to Remote-Party-ID header field. This function ignores
804 rpid_prefix and rpid_suffix parameters, instead of that allows to set
807 Meaning of the parameters is as follows:
808 * prefix - Prefix of the Remote-Party-ID URI. The string will be
809 added at the begining of body of the header field, just before the
811 * suffix - Suffix of the Remote-Party-ID header field. The string
812 will be appended at the end of the header field. It can be used to
813 set various URI parameters, for example.
815 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
818 Example 1.31. append_rpid_hf(prefix, suffix) usage
820 # Append Remote-Party-ID header field
821 append_rpid_hf("", ";party=calling;id-type=subscriber;screen=yes");
824 4.23. is_rpid_user_e164()
826 The function checks if the SIP URI received from the database or radius
827 server and will potentially be used in Remote-Party-ID header field
828 contains an E164 number (+followed by up to 15 decimal digits) in its
829 user part. Check fails, if no such SIP URI exists (i.e. radius server
830 or database didn't provide this information).
832 This function can be used from REQUEST_ROUTE.
834 Example 1.32. is_rpid_user_e164 usage
836 if (is_rpid_user_e164()) {
841 4.24. set_uri_user(uri, user)
843 Sets userpart of SIP URI stored in writable pseudo variable 'uri' to
844 value of pseudo variable 'user'.
846 This function can be used from ANY_ROUTE.
848 Example 1.33. set_uri_user usage
850 $var(uri) = "sip:user@host";
851 $var(user) = "new_user";
852 set_uri_user("$var(uri)", "$var(user)");
855 4.25. set_uri_host(uri, host)
857 Sets hostpart of SIP URI stored in writable pseudo variable 'uri' to
858 value of pseudo variable 'host'.
860 This function can be used from ANY_ROUTE.
862 Example 1.34. set_uri_host usage
864 $var(uri) = "sip:user@host";
865 $var(host) = "new_host";
866 set_uri_host("$var(uri)", "$var(host)");
871 Return true if the SIP message is a request.
873 This function can be used from ANY_ROUTE.
875 Example 1.35. is_request usage
884 Return true if the SIP message is a reply.
886 This function can be used from ANY_ROUTE.
888 Example 1.36. is_reply usage
897 The function returns true if the uri is GRUU ('gr' parameter is
898 present): 1 - pub-gruu; 2 - temp-gruu.
900 Meaning of the parameters is as follows:
901 * uri - the SIP URI to check for GRUU parameter. It is optional, when
902 missing, the value of R-URI is used.
904 This function can be used from ANY_ROUTE.
906 Example 1.37. is_gruu() usage
908 if(is_gruu()) { ... }
911 4.29. is_supported(option)
913 Function returns true if given option is listed in Supported header(s)
914 (if any) of the request. Currently the following options are known:
915 path, 100rel, timer, eventlist, gruu, and outbound.
917 This function can be used from ANY_ROUTE.
919 Example 1.38. is_supported() usage
921 if (is_supported("outbound")) { ... }
926 The function returns true if the proxy is first hop after the original
927 sender. For incoming SIP requests, it means there is only one Via
928 header. For incoming SIP replies, it means that top Record-Route URI is
929 'myself' and source address is not matching it (to avoid detecting in
930 case of local loops). Note that it does not detect spirals, which can
931 have the condition for replies true also in the case of additional SIP
934 This function can be used from ANY_ROUTE.
936 Example 1.39. is_first_hop() usage
938 if(is_first_hop()) { ... }
941 4.31. sip_p_charging_vector(flags)
943 Manage the P-Charging-Vector header (RFC7315). The flags can be: 'r' -
944 remove; 'g' - generate; 'f' - force (remove + generate).
946 This function can be used from ANY_ROUTE.
948 Example 1.40. sip_p_charging_vector() usage
950 sip_p_charging_vector("g");
953 5. Exported pseudo-variables
963 full P-Charging-Vector header
967 icid-value field (see RFC7315 section 5.6)
971 icid-generated-at field (see RFC7315 section 5.6)
975 orig-ioi field (see RFC7315 section 5.6)
979 term-ioi field (see RFC7315 section 5.6)