Przeglądaj źródła

siputils: new function is_gruu(uri)

- wrapper function to test quickly if a SIP URI indicates a GRUU
  address or not
Daniel-Constantin Mierla 13 lat temu
rodzic
commit
0a8ad0ac8f

+ 61 - 41
modules_k/siputils/README

@@ -40,7 +40,7 @@ Edited by
 
 
 Gabriel Vasile
 Gabriel Vasile
 
 
-   Copyright © 2008, 2005, 2003 1&1 Internet AG, FhG Fokus, Voice Sistem
+   Copyright © 2008, 2005, 2003 1&1 Internet AG, FhG Fokus, Voice Sistem
    SRL
    SRL
      __________________________________________________________________
      __________________________________________________________________
 
 
@@ -91,6 +91,7 @@ Gabriel Vasile
               4.21. set_uri_host(uri, host)
               4.21. set_uri_host(uri, host)
               4.22. is_request()
               4.22. is_request()
               4.23. is_reply()
               4.23. is_reply()
+              4.24. is_gruu([uri])
 
 
    List of Examples
    List of Examples
 
 
@@ -126,6 +127,7 @@ Gabriel Vasile
    1.30. set_uri_host usage
    1.30. set_uri_host usage
    1.31. is_request usage
    1.31. is_request usage
    1.32. is_reply usage
    1.32. is_reply usage
+   1.33. is_gruu() usage
 
 
 Chapter 1. Admin Guide
 Chapter 1. Admin Guide
 
 
@@ -174,6 +176,7 @@ Chapter 1. Admin Guide
         4.21. set_uri_host(uri, host)
         4.21. set_uri_host(uri, host)
         4.22. is_request()
         4.22. is_request()
         4.23. is_reply()
         4.23. is_reply()
+        4.24. is_gruu([uri])
 
 
 1. Overview
 1. Overview
 
 
@@ -194,7 +197,7 @@ Chapter 1. Admin Guide
 
 
    To answer OPTIONS request directed to your server is the easiest way
    To answer OPTIONS request directed to your server is the easiest way
    for is-alive-tests on the SIP (application) layer from remote (similar
    for is-alive-tests on the SIP (application) layer from remote (similar
-   to ICMP echo requests, also known as “ping�, on the network layer).
+   to ICMP echo requests, also known as "ping", on the network layer).
 
 
 2. Dependencies
 2. Dependencies
 
 
@@ -228,9 +231,9 @@ Chapter 1. Admin Guide
 
 
    Timeout value in seconds, define how long the call-id is stored in the
    Timeout value in seconds, define how long the call-id is stored in the
    internal list kept for replacing 183 messages with 180. A reasonable
    internal list kept for replacing 183 messages with 180. A reasonable
-   value is “30�.
+   value is "30".
 
 
-   Default value is “0�. This means functionality is disabled.
+   Default value is "0". This means functionality is disabled.
 
 
    Example 1.1. Set ring_timeout parameter
    Example 1.1. Set ring_timeout parameter
 ...
 ...
@@ -241,10 +244,10 @@ modparam("siputils", "ring_timeout", 30)
 
 
    This parameter is the content of the Accept header field. Note: it is
    This parameter is the content of the Accept header field. Note: it is
    not clearly written in RFC3261 if a proxy should accept any content
    not clearly written in RFC3261 if a proxy should accept any content
-   (the default “*/*�) because it does not care about content. Or if it
-   does not accept any content, which is “�.
+   (the default "*/*") because it does not care about content. Or if it
+   does not accept any content, which is "".
 
 
-   Default value is “*/*�.
+   Default value is "*/*".
 
 
    Example 1.2. Set options_accept parameter
    Example 1.2. Set options_accept parameter
 ...
 ...
@@ -257,7 +260,7 @@ modparam("siputils", "options_accept", "application/*")
    Please do not change the default value because Kamailio does not
    Please do not change the default value because Kamailio does not
    support any encodings yet.
    support any encodings yet.
 
 
-   Default value is “�.
+   Default value is "".
 
 
    Example 1.3. Set options_accept_encoding parameter
    Example 1.3. Set options_accept_encoding parameter
 ...
 ...
@@ -275,7 +278,7 @@ Warning
    inside username,password or other fields of contact. Otherwise it is
    inside username,password or other fields of contact. Otherwise it is
    possible for the decoding step to fail/produce wrong results.
    possible for the decoding step to fail/produce wrong results.
 
 
-   Default value is “*�.
+   Default value is "*".
 
 
    Example 1.4. Set contact_flds_separator parameter
    Example 1.4. Set contact_flds_separator parameter
 ...
 ...
@@ -292,7 +295,7 @@ modparam("siputils", "contact_flds_separator", "-")
    other devices, but presumably there are not much devices around which
    other devices, but presumably there are not much devices around which
    support other languages then the default English.
    support other languages then the default English.
 
 
-   Default value is “en�.
+   Default value is "en".
 
 
    Example 1.5. Set options_accept_language parameter
    Example 1.5. Set options_accept_language parameter
 ...
 ...
@@ -305,7 +308,7 @@ modparam("siputils", "options_accept_language", "de")
    not change the default value, because Kamailio currently does not
    not change the default value, because Kamailio currently does not
    support any of the SIP extensions registered at the IANA.
    support any of the SIP extensions registered at the IANA.
 
 
-   Default value is “�.
+   Default value is "".
 
 
    Example 1.6. Set options_support parameter
    Example 1.6. Set options_support parameter
 ...
 ...
@@ -317,7 +320,7 @@ modparam("siputils", "options_support", "100rel")
    Prefix to be added to Remote-Party-ID header field just before the URI
    Prefix to be added to Remote-Party-ID header field just before the URI
    returned from either radius or database.
    returned from either radius or database.
 
 
-   Default value is “�.
+   Default value is "".
 
 
    Example 1.7. rpid_prefix parameter example
    Example 1.7. rpid_prefix parameter example
 modparam("auth", "rpid_prefix", "Whatever <")
 modparam("auth", "rpid_prefix", "Whatever <")
@@ -327,7 +330,7 @@ modparam("auth", "rpid_prefix", "Whatever <")
    Suffix to be added to Remote-Party-ID header field after the URI
    Suffix to be added to Remote-Party-ID header field after the URI
    returned from either radius or database.
    returned from either radius or database.
 
 
-   Default value is “;party=calling;id-type=subscriber;screen=yes�.
+   Default value is ";party=calling;id-type=subscriber;screen=yes".
 
 
    Example 1.8. rpid_suffix parameter example
    Example 1.8. rpid_suffix parameter example
 modparam("auth", "rpid_suffix", "@1.2.3.4>")
 modparam("auth", "rpid_suffix", "@1.2.3.4>")
@@ -341,7 +344,7 @@ modparam("auth", "rpid_suffix", "@1.2.3.4>")
 
 
    If defined to NULL string, all RPID functions will fail at runtime.
    If defined to NULL string, all RPID functions will fail at runtime.
 
 
-   Default value is “$avp(s:rpid)�.
+   Default value is "$avp(s:rpid)".
 
 
    Example 1.9. rpid_avp parameter example
    Example 1.9. rpid_avp parameter example
 modparam("auth", "rpid_avp", "$avp(myrpid)")
 modparam("auth", "rpid_avp", "$avp(myrpid)")
@@ -371,8 +374,9 @@ modparam("auth", "rpid_avp", "$avp(myrpid)")
    4.21. set_uri_host(uri, host)
    4.21. set_uri_host(uri, host)
    4.22. is_request()
    4.22. is_request()
    4.23. is_reply()
    4.23. is_reply()
+   4.24. is_gruu([uri])
 
 
-4.1.  ring_insert_callid()
+4.1. ring_insert_callid()
 
 
    Inserting the call-id in the internal list, which is checked when
    Inserting the call-id in the internal list, which is checked when
    further replies arrive. Any 183 reply that is received during the
    further replies arrive. Any 183 reply that is received during the
@@ -389,14 +393,14 @@ modparam("auth", "rpid_avp", "$avp(myrpid)")
 ring_insert_callid();
 ring_insert_callid();
 ...
 ...
 
 
-4.2.  options_reply()
+4.2. options_reply()
 
 
    This function checks if the request method is OPTIONS and if the
    This function checks if the request method is OPTIONS and if the
    request URI does not contain an username. If both is true the request
    request URI does not contain an username. If both is true the request
-   will be answered stateless with “200 OK� and the capabilities from the
+   will be answered stateless with "200 OK" and the capabilities from the
    modules parameters.
    modules parameters.
 
 
-   It sends “500 Server Internal Error� for some errors and returns false
+   It sends "500 Server Internal Error" for some errors and returns false
    if it is called for a wrong request.
    if it is called for a wrong request.
 
 
    The check for the request method and the missing username is optional
    The check for the request method and the missing username is optional
@@ -417,7 +421,7 @@ if (uri==myself) {
 }
 }
 ...
 ...
 
 
-4.3.  is_user(username)
+4.3. is_user(username)
 
 
    Check if the username in credentials matches the given username.
    Check if the username in credentials matches the given username.
 
 
@@ -433,7 +437,7 @@ if (is_user("john")) {
 };
 };
 ...
 ...
 
 
-4.4.  has_totag()
+4.4. has_totag()
 
 
    Check if To header field uri contains tag parameter.
    Check if To header field uri contains tag parameter.
 
 
@@ -446,7 +450,7 @@ if (has_totag()) {
 };
 };
 ...
 ...
 
 
-4.5.  uri_param(param)
+4.5. uri_param(param)
 
 
    Find if Request URI has a given parameter with no value
    Find if Request URI has a given parameter with no value
 
 
@@ -462,7 +466,7 @@ if (uri_param("param1")) {
 };
 };
 ...
 ...
 
 
-4.6.  uri_param(param,value)
+4.6. uri_param(param,value)
 
 
    Find if Request URI has a given parameter with matching value
    Find if Request URI has a given parameter with matching value
 
 
@@ -479,12 +483,12 @@ if (uri_param("param1","value1")) {
 };
 };
 ...
 ...
 
 
-4.7.  add_uri_param(param)
+4.7. add_uri_param(param)
 
 
    Add to RURI a parameter (name=value);
    Add to RURI a parameter (name=value);
 
 
    Meaning of the parameters is as follows:
    Meaning of the parameters is as follows:
-     * param - parameter to be appended in “name=value� format.
+     * param - parameter to be appended in "name=value" format.
 
 
    This function can be used from REQUEST_ROUTE.
    This function can be used from REQUEST_ROUTE.
 
 
@@ -493,7 +497,7 @@ if (uri_param("param1","value1")) {
 add_uri_param("nat=yes");
 add_uri_param("nat=yes");
 ...
 ...
 
 
-4.8.  tel2sip(uri, hostpart, result)
+4.8. tel2sip(uri, hostpart, result)
 
 
    Converts URI in first param (pseudo variable or string) to SIP URI, if
    Converts URI in first param (pseudo variable or string) to SIP URI, if
    it is a tel URI. If conversion was done, writes resulting SIP URI to
    it is a tel URI. If conversion was done, writes resulting SIP URI to
@@ -525,7 +529,7 @@ tel2sip("$ru", $fd", "$ru");
 # $ru:  sip:+12345678;ext=200;[email protected];user=phone
 # $ru:  sip:+12345678;ext=200;[email protected];user=phone
 ...
 ...
 
 
-4.9.  is_e164(pseudo-variable)
+4.9. is_e164(pseudo-variable)
 
 
    Checks if string value of pseudo variable argument is an E164 number.
    Checks if string value of pseudo variable argument is an E164 number.
 
 
@@ -543,7 +547,7 @@ if (is_e164("$avp(i:705)") {
 };
 };
 ...
 ...
 
 
-4.10.  is_uri_user_e164(pseudo-variable)
+4.10. is_uri_user_e164(pseudo-variable)
 
 
    Checks if userpart of URI stored in pseudo variable is E164 number.
    Checks if userpart of URI stored in pseudo variable is E164 number.
 
 
@@ -560,7 +564,7 @@ if (is_uri_user_e164("$avp(i:705)") {
 };
 };
 ...
 ...
 
 
-4.11.  encode_contact(encoding_prefix,hostpart)
+4.11. encode_contact(encoding_prefix,hostpart)
 
 
    This function will encode uri-s inside Contact header in the following
    This function will encode uri-s inside Contact header in the following
    manner sip:username:password@ip:port;transport=protocol goes
    manner sip:username:password@ip:port;transport=protocol goes
@@ -587,7 +591,7 @@ if (is_uri_user_e164("$avp(i:705)") {
 if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
 if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
 ...
 ...
 
 
-4.12.  decode_contact()
+4.12. decode_contact()
 
 
    This function will decode the request URI. If the RURI is in the format
    This function will decode the request URI. If the RURI is in the format
    sip:encoding_prefix*username*ip*port*protocol@hostpart it will be
    sip:encoding_prefix*username*ip*port*protocol@hostpart it will be
@@ -605,7 +609,7 @@ if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
 if (uri =~ "^sip:natted_client") { decode_contact(); }
 if (uri =~ "^sip:natted_client") { decode_contact(); }
 ...
 ...
 
 
-4.13.  decode_contact_header()
+4.13. decode_contact_header()
 
 
    This function will decode URIs inside Contact header. If the URI in the
    This function will decode URIs inside Contact header. If the URI in the
    format sip:encoding_prefix*username*ip*port*protocol@hostpart it will
    format sip:encoding_prefix*username*ip*port*protocol@hostpart it will
@@ -627,7 +631,7 @@ reply_route[2] {
 }
 }
 ...
 ...
 
 
-4.14.  cmp_uri(str1, str2)
+4.14. cmp_uri(str1, str2)
 
 
    The function returns true if the two parameters matches as SIP URI.
    The function returns true if the two parameters matches as SIP URI.
 
 
@@ -641,7 +645,7 @@ if(cmp_uri("$ru", "sip:[email protected]"))
 }
 }
 ...
 ...
 
 
-4.15.  cmp_aor(str1, str2)
+4.15. cmp_aor(str1, str2)
 
 
    The function returns true if the two parameters matches as AoR. The
    The function returns true if the two parameters matches as AoR. The
    parameters have to be SIP URIs.
    parameters have to be SIP URIs.
@@ -656,7 +660,7 @@ if(cmp_aor("[email protected]", "sip:kamailio@$fd"))
 }
 }
 ...
 ...
 
 
-4.16.  is_rpid_user_e164()
+4.16. is_rpid_user_e164()
 
 
    The function checks if the SIP URI received from the database or radius
    The function checks if the SIP URI received from the database or radius
    server and will potentially be used in Remote-Party-ID header field
    server and will potentially be used in Remote-Party-ID header field
@@ -673,7 +677,7 @@ if (is_rpid_user_e164()) {
 };
 };
 ...
 ...
 
 
-4.17.  append_rpid_hf()
+4.17. append_rpid_hf()
 
 
    Appends to the message a Remote-Party-ID header that contains header
    Appends to the message a Remote-Party-ID header that contains header
    'Remote-Party-ID: ' followed by the saved value of the SIP URI received
    'Remote-Party-ID: ' followed by the saved value of the SIP URI received
@@ -689,9 +693,9 @@ if (is_rpid_user_e164()) {
 append_rpid_hf();  # Append Remote-Party-ID header field
 append_rpid_hf();  # Append Remote-Party-ID header field
 ...
 ...
 
 
-4.18.  append_rpid_hf(prefix, suffix)
+4.18. append_rpid_hf(prefix, suffix)
 
 
-   This function is the same as Section 4.17, “ append_rpid_hf()�. The
+   This function is the same as Section 4.17, " append_rpid_hf()". The
    only difference is that it accepts two parameters--prefix and suffix to
    only difference is that it accepts two parameters--prefix and suffix to
    be added to Remote-Party-ID header field. This function ignores
    be added to Remote-Party-ID header field. This function ignores
    rpid_prefix and rpid_suffix parameters, instead of that allows to set
    rpid_prefix and rpid_suffix parameters, instead of that allows to set
@@ -714,7 +718,7 @@ append_rpid_hf();  # Append Remote-Party-ID header field
 append_rpid_hf("", ";party=calling;id-type=subscriber;screen=yes");
 append_rpid_hf("", ";party=calling;id-type=subscriber;screen=yes");
 ...
 ...
 
 
-4.19.  is_rpid_user_e164()
+4.19. is_rpid_user_e164()
 
 
    The function checks if the SIP URI received from the database or radius
    The function checks if the SIP URI received from the database or radius
    server and will potentially be used in Remote-Party-ID header field
    server and will potentially be used in Remote-Party-ID header field
@@ -731,7 +735,7 @@ if (is_rpid_user_e164()) {
 };
 };
 ...
 ...
 
 
-4.20.  set_uri_user(uri, user)
+4.20. set_uri_user(uri, user)
 
 
    Sets userpart of SIP URI stored in writable pseudo variable 'uri' to
    Sets userpart of SIP URI stored in writable pseudo variable 'uri' to
    value of pseudo variable 'user'.
    value of pseudo variable 'user'.
@@ -745,7 +749,7 @@ $var(user) = "new_user";
 set_uri_user("$var(uri)", "$var(user)");
 set_uri_user("$var(uri)", "$var(user)");
 ...
 ...
 
 
-4.21.  set_uri_host(uri, host)
+4.21. set_uri_host(uri, host)
 
 
    Sets hostpart of SIP URI stored in writable pseudo variable 'uri' to
    Sets hostpart of SIP URI stored in writable pseudo variable 'uri' to
    value of pseudo variable 'host'.
    value of pseudo variable 'host'.
@@ -759,7 +763,7 @@ $var(host) = "new_host";
 set_uri_host("$var(uri)", "$var(host)");
 set_uri_host("$var(uri)", "$var(host)");
 ...
 ...
 
 
-4.22.  is_request()
+4.22. is_request()
 
 
    Return true if the SIP message is a request.
    Return true if the SIP message is a request.
 
 
@@ -772,7 +776,7 @@ if (is_request()) {
 }
 }
 ...
 ...
 
 
-4.23.  is_reply()
+4.23. is_reply()
 
 
    Return true if the SIP message is a reply.
    Return true if the SIP message is a reply.
 
 
@@ -784,3 +788,19 @@ if (is_reply()) {
         ...
         ...
 }
 }
 ...
 ...
+
+4.24. is_gruu([uri])
+
+   The function returns true if the uri is GRUU ('gr' parameter is
+   present): 1 - pub-gruu; 2 - temp-gruu.
+
+   Meaning of the parameters is as follows:
+     * uri - the SIP URI to check for GRUU parameter. It is optional, when
+       missing, the value of R-URI is used.
+
+   This function can be used from ANY_ROUTE.
+
+   Example 1.33. is_gruu() usage
+...
+if(is_gruu()) { ... }
+...

+ 29 - 0
modules_k/siputils/doc/siputils_admin.xml

@@ -927,6 +927,35 @@ if (is_reply()) {
 	...
 	...
 }
 }
 ...
 ...
+</programlisting>
+		</example>
+	</section>
+	<section id="is-gruu">
+		<title>
+			<function moreinfo="none">is_gruu([uri])</function>
+		</title>
+		<para>
+			The function returns true if the uri is GRUU ('gr' parameter
+			is present): 1 - pub-gruu; 2 - temp-gruu.
+		</para>
+		<para>Meaning of the parameters is as follows:</para>
+		<itemizedlist>
+		<listitem>
+			<para><emphasis>uri</emphasis> - the SIP URI to check for
+				GRUU parameter. It is optional, when missing, the value
+				of R-URI is used.
+			</para>
+		</listitem>
+		</itemizedlist>
+		<para>
+		This function can be used from ANY_ROUTE.
+		</para>
+		<example>
+		<title>is_gruu() usage</title>
+		<programlisting format="linespecific">
+...
+if(is_gruu()) { ... }
+...
 </programlisting>
 </programlisting>
 		</example>
 		</example>
 	</section>
 	</section>

+ 30 - 0
modules_k/siputils/sipops.c

@@ -32,6 +32,7 @@
 
 
 
 
 #include "../../mod_fix.h"
 #include "../../mod_fix.h"
+#include "../../parser/parse_uri.h"
 #include "../../lib/kcore/cmpapi.h"
 #include "../../lib/kcore/cmpapi.h"
 
 
 #include "sipops.h"
 #include "sipops.h"
@@ -84,3 +85,32 @@ int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2)
 	return -2;
 	return -2;
 }
 }
 
 
+int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2)
+{
+	str s1;
+	sip_uri_t turi;
+	sip_uri_t *puri;
+
+	if(uri1!=NULL)
+	{
+		if(fixup_get_svalue(msg, (gparam_p)uri1, &s1)!=0)
+		{
+			LM_ERR("cannot get first parameter\n");
+			return -8;
+		}
+		if(parse_uri(s1.s, s1.len, &turi)!=0)
+			return -1;
+		puri = &turi;
+	} else {
+		if(parse_sip_msg_uri(msg))
+			return -1;
+		puri = &msg->parsed_uri;
+	}
+	if(puri->gr.s!=NULL)
+	{
+		if(puri->gr_val.len>0)
+			return 1;
+		return 2;
+	}
+	return -1;
+}

+ 1 - 0
modules_k/siputils/sipops.h

@@ -38,5 +38,6 @@
 
 
 int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2);
 int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2);
 int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2);
 int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2);
+int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2);
 
 
 #endif
 #endif

+ 4 - 0
modules_k/siputils/siputils.c

@@ -160,6 +160,10 @@ static cmd_export_t cmds[]={
 			0, ANY_ROUTE},
 			0, ANY_ROUTE},
 	{"is_reply",            (cmd_function)w_is_reply,              0, 0,
 	{"is_reply",            (cmd_function)w_is_reply,              0, 0,
 			0, ANY_ROUTE},
 			0, ANY_ROUTE},
+	{"is_gruu",  (cmd_function)w_is_gruu,                    0, 0,
+		0, ANY_ROUTE},
+	{"is_gruu",  (cmd_function)w_is_gruu,                    1, fixup_spve_null,
+		0, ANY_ROUTE},
 	{0,0,0,0,0,0}
 	{0,0,0,0,0,0}
 };
 };