浏览代码

registrar(k): optional uri parameter

- removed aor_avp as it conflicted with unregister uri param
- savel, lookup and register can take an extra optional parameter to
  specify the URI for which to do the operation. It provides the same
  functionality as it was with aor_avp
Daniel-Constantin Mierla 13 年之前
父节点
当前提交
3417a42c64

+ 88 - 109
modules_k/registrar/README

@@ -57,14 +57,13 @@ Bogdan-Andre Iancu
 
         4. Functions
 
-              4.1. save(domain)
-              4.2. save(domain,flags)
-              4.3. lookup(domain)
-              4.4. registered(domain)
-              4.5. add_sock_hdr(hdr_name)
-              4.6. unregister(domain, uri)
-              4.7. reg_fetch_contacts(domain, uri, profile)
-              4.8. reg_free_contacts(profile)
+              4.1. save(domain, [, flags [, uri]])
+              4.2. lookup(domain [, uri])
+              4.3. registered(domain [, uri])
+              4.4. add_sock_hdr(hdr_name)
+              4.5. unregister(domain, uri)
+              4.6. reg_fetch_contacts(domain, uri, profile)
+              4.7. reg_free_contacts(profile)
 
         5. Statistics
 
@@ -89,28 +88,26 @@ Bogdan-Andre Iancu
    1.5. Set default_q parameter
    1.6. Set realm_prefix parameter
    1.7. Set append_branches parameter
-   1.8. Set aor_avp parameter
-   1.9. Set case_sensitive parameter
-   1.10. Set received_avp parameter
-   1.11. Set received_param parameter
-   1.12. Set max_contacts parameter
-   1.13. Set retry_after parameter
-   1.14. Set sock_flag parameter
-   1.15. Set sock_hdr_namer parameter
-   1.16. Set method_filtering parameter
-   1.17. Set use_path parameter
-   1.18. Set path_mode parameter
-   1.19. Set path_use_received parameter
-   1.20. Set reg_callid_avp parameter
-   1.21. save usage
-   1.22. save usage
-   1.23. lookup usage
+   1.8. Set case_sensitive parameter
+   1.9. Set received_avp parameter
+   1.10. Set received_param parameter
+   1.11. Set max_contacts parameter
+   1.12. Set retry_after parameter
+   1.13. Set sock_flag parameter
+   1.14. Set sock_hdr_namer parameter
+   1.15. Set method_filtering parameter
+   1.16. Set use_path parameter
+   1.17. Set path_mode parameter
+   1.18. Set path_use_received parameter
+   1.19. Set reg_callid_avp parameter
+   1.20. save usage
+   1.21. lookup usage
+   1.22. registered usage
+   1.23. add_sock_hdr usage
    1.24. registered usage
-   1.25. add_sock_hdr usage
+   1.25. registered usage
    1.26. registered usage
-   1.27. registered usage
-   1.28. registered usage
-   1.29. $ulc(name) usage
+   1.27. $ulc(name) usage
 
 Chapter 1. Admin Guide
 
@@ -150,14 +147,13 @@ Chapter 1. Admin Guide
 
    4. Functions
 
-        4.1. save(domain)
-        4.2. save(domain,flags)
-        4.3. lookup(domain)
-        4.4. registered(domain)
-        4.5. add_sock_hdr(hdr_name)
-        4.6. unregister(domain, uri)
-        4.7. reg_fetch_contacts(domain, uri, profile)
-        4.8. reg_free_contacts(profile)
+        4.1. save(domain, [, flags [, uri]])
+        4.2. lookup(domain [, uri])
+        4.3. registered(domain [, uri])
+        4.4. add_sock_hdr(hdr_name)
+        4.5. unregister(domain, uri)
+        4.6. reg_fetch_contacts(domain, uri, profile)
+        4.7. reg_free_contacts(profile)
 
    5. Statistics
 
@@ -358,18 +354,8 @@ modparam("registrar", "append_branches", 0)
 
 3.8. aor_avp (str)
 
-   If set, the module will try first to get the AOR from this AVP instead
-   of fetching it form the processed request.
-
-   The AVP must contain a valid SIP URI. If no AVP is found, it will be
-   tried to get the AOR from the message (standard behaviour).
-
-   Default value is "NULL" (disabled).
-
-   Example 1.8. Set aor_avp parameter
-...
-modparam("registrar", "aor_avp", "$avp(i:3223)")
-...
+   This module parameter has been removed. Use the 'uri' parameter from
+   functions (e.g., save, lookup, registered).
 
 3.9. case_sensitive (integer)
 
@@ -380,7 +366,7 @@ modparam("registrar", "aor_avp", "$avp(i:3223)")
 
    Default value is 0.
 
-   Example 1.9. Set case_sensitive parameter
+   Example 1.8. Set case_sensitive parameter
 ...
 modparam("registrar", "case_sensitive", 1)
 ...
@@ -400,7 +386,7 @@ Note
 
    Default value is "NULL" (disabled).
 
-   Example 1.10. Set received_avp parameter
+   Example 1.9. Set received_avp parameter
 ...
 modparam("registrar", "received_avp", "$avp(s:rcv)")
 ...
@@ -412,7 +398,7 @@ modparam("registrar", "received_avp", "$avp(s:rcv)")
 
    Default value is "received".
 
-   Example 1.11. Set received_param parameter
+   Example 1.10. Set received_param parameter
 ...
 modparam("registrar", "received_param", "rcv")
 ...
@@ -425,7 +411,7 @@ modparam("registrar", "received_param", "rcv")
 
    Default value is 0.
 
-   Example 1.12. Set max_contacts parameter
+   Example 1.11. Set max_contacts parameter
 ...
 # Allow no more than 10 contacts per AOR
 modparam("registrar", "max_contacts", 10)
@@ -445,7 +431,7 @@ modparam("registrar", "max_contacts", 10)
 
    Default value is 0 (disabled).
 
-   Example 1.13. Set retry_after parameter
+   Example 1.12. Set retry_after parameter
 ...
 modparam("registrar", "retry_after", 30)
 ...
@@ -460,7 +446,7 @@ modparam("registrar", "retry_after", 30)
 
    Default value is -1 (no flag).
 
-   Example 1.14. Set sock_flag parameter
+   Example 1.13. Set sock_flag parameter
 ...
 modparam("registrar", "sock_flag", 18)
 ...
@@ -475,7 +461,7 @@ modparam("registrar", "sock_flag", 18)
 
    Default value is NULL.
 
-   Example 1.15. Set sock_hdr_namer parameter
+   Example 1.14. Set sock_hdr_namer parameter
 ...
 modparam("registrar", "sock_hdr_name", "Sock-Info")
 ...
@@ -487,7 +473,7 @@ modparam("registrar", "sock_hdr_name", "Sock-Info")
 
    Default value is 0 (disabled).
 
-   Example 1.16. Set method_filtering parameter
+   Example 1.15. Set method_filtering parameter
 ...
 modparam("registrar", "method_filtering", 1)
 ...
@@ -499,7 +485,7 @@ modparam("registrar", "method_filtering", 1)
 
    Default value is 0 (disabled).
 
-   Example 1.17. Set use_path parameter
+   Example 1.16. Set use_path parameter
 ...
 modparam("registrar", "use_path", 1)
 ...
@@ -522,7 +508,7 @@ modparam("registrar", "use_path", 1)
 
    Default value is 2.
 
-   Example 1.18. Set path_mode parameter
+   Example 1.17. Set path_mode parameter
 ...
 modparam("registrar", "path_mode", 0)
 ...
@@ -537,7 +523,7 @@ modparam("registrar", "path_mode", 0)
 
    Default value is 0 (disabled).
 
-   Example 1.19. Set path_use_received parameter
+   Example 1.18. Set path_use_received parameter
 ...
 modparam("registrar", "path_use_received", 1)
 ...
@@ -550,23 +536,22 @@ modparam("registrar", "path_use_received", 1)
 
    Default value is NULL (disabled).
 
-   Example 1.20. Set reg_callid_avp parameter
+   Example 1.19. Set reg_callid_avp parameter
 ...
 modparam("registrar", "reg_callid_avp", "$avp(s:avp)")
 ...
 
 4. Functions
 
-   4.1. save(domain)
-   4.2. save(domain,flags)
-   4.3. lookup(domain)
-   4.4. registered(domain)
-   4.5. add_sock_hdr(hdr_name)
-   4.6. unregister(domain, uri)
-   4.7. reg_fetch_contacts(domain, uri, profile)
-   4.8. reg_free_contacts(profile)
+   4.1. save(domain, [, flags [, uri]])
+   4.2. lookup(domain [, uri])
+   4.3. registered(domain [, uri])
+   4.4. add_sock_hdr(hdr_name)
+   4.5. unregister(domain, uri)
+   4.6. reg_fetch_contacts(domain, uri, profile)
+   4.7. reg_free_contacts(profile)
 
-4.1. save(domain)
+4.1. save(domain, [, flags [, uri]])
 
    The function processes a REGISTER message. It can add, remove or modify
    usrloc records depending on Contact and Expires HFs in the REGISTER
@@ -578,30 +563,8 @@ modparam("registrar", "reg_callid_avp", "$avp(s:avp)")
    Meaning of the parameters is as follows:
      * domain - Logical domain within registrar. If database is used then
        this must be name of the table which stores the contacts.
-
-   Return codes:
-     * -1 - error.
-       1 - contacts inserted.
-       2 - contacts updated.
-       3 - contacts deleted.
-       4 - contacts returned.
-
-   This function can be used from REQUEST_ROUTE and REPLY_ROUTE.
-
-   Example 1.21. save usage
-...
-save("location");
-...
-
-4.2. save(domain,flags)
-
-   Same as save() but it accepts a set of flags for controlling its
-   behaviour.
-
-   Meaning of the parameters is as follows:
-     * domain - Logical domain within registrar. If database is used then
-       this must be name of the table which stores the contacts.
-     * flags - the value may be a bitwise OR of the following flags:
+     * flags (optional) - the value may be a bitwise OR of the following
+       flags:
           + 0x01 - save the contacts only in memory cache without no DB
             operation;
           + 0x02 - do not generate a SIP reply to the current REGISTER
@@ -612,15 +575,27 @@ save("location");
             registration, remove them. This mode ensures one contact per
             AoR (user).
        The flags may be given in decimal or hexa format.
+     * uri (optional - flags param has to be set and can be 0 for default
+       behavior) - SIP URI to do be used instead of To header URI. It can
+       be a dynamic string with pseudo-variables.
 
-   This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
+   Return codes:
+     * -1 - error.
+       1 - contacts inserted.
+       2 - contacts updated.
+       3 - contacts deleted.
+       4 - contacts returned.
 
-   Example 1.22. save usage
+   This function can be used from REQUEST_ROUTE and REPLY_ROUTE.
+
+   Example 1.20. save usage
 ...
-save("location","0x01");
+save("location");
+save("location", "0x01");
+save("location", "0x00", "sip:[email protected]");
 ...
 
-4.3. lookup(domain)
+4.2. lookup(domain [, uri])
 
    The functions extracts username from Request-URI and tries to find all
    contacts for the username in usrloc. If there are no such contacts, -1
@@ -635,6 +610,8 @@ save("location","0x01");
 
    Meaning of the parameters is as follows:
      * domain - Name of table that should be used for the lookup.
+     * uri (optional) - SIP URI to do be used instead of R-URI. It can be
+       a dynamic string with pseudo-variables.
 
    Return codes:
      * 1 - contacts found and returned.
@@ -644,7 +621,7 @@ save("location","0x01");
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.23. lookup usage
+   Example 1.21. lookup usage
 ...
 lookup("location");
 switch ($retcode) {
@@ -658,7 +635,7 @@ switch ($retcode) {
 };
 ...
 
-4.4. registered(domain)
+4.3. registered(domain [, uri])
 
    The function returns true if the AOR in the Request-URI is registered,
    false otherwise. The function does not modify the message being
@@ -667,10 +644,12 @@ switch ($retcode) {
 
    Meaning of the parameters is as follows:
      * domain - Name of table that should be used for the lookup.
+     * uri (optional) - SIP URI to do be used instead of R-URI. It can be
+       a dynamic string with pseudo-variables.
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.24. registered usage
+   Example 1.22. registered usage
 ...
 if (registered("location")) {
         sl_send_reply("100", "Trying");
@@ -678,7 +657,7 @@ if (registered("location")) {
 };
 ...
 
-4.5. add_sock_hdr(hdr_name)
+4.4. add_sock_hdr(hdr_name)
 
    Adds to the current REGISTER request a new header with "hdr_name" which
    contains the description of the received socket (proto:ip:port)
@@ -690,12 +669,12 @@ if (registered("location")) {
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.25. add_sock_hdr usage
+   Example 1.23. add_sock_hdr usage
 ...
 add_sock_hdr("Sock-Info");
 ...
 
-4.6. unregister(domain, uri)
+4.5. unregister(domain, uri)
 
    The function remove all the contact associated to 'uri'.
 
@@ -708,13 +687,13 @@ add_sock_hdr("Sock-Info");
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.26. registered usage
+   Example 1.24. registered usage
 ...
 unregister("location", "$ru");
 unregister("location", "sip:[email protected]");
 ...
 
-4.7. reg_fetch_contacts(domain, uri, profile)
+4.6. reg_fetch_contacts(domain, uri, profile)
 
    The function fetches the contacts for 'uri' from table 'domain' to
    pseudo-variable $ulc(profile).
@@ -730,13 +709,13 @@ unregister("location", "sip:[email protected]");
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.27. registered usage
+   Example 1.25. registered usage
 ...
 reg_fetch_contacts("location", "$ru", "callee");
 reg_fetch_contacts("location", "sip:[email protected]", "caller");
 ...
 
-4.8. reg_free_contacts(profile)
+4.7. reg_free_contacts(profile)
 
    The function frees the contacts from pseudo-variable $ulc(profile).
    Should be called to release the content of a profile. Anyhow, fetching
@@ -749,7 +728,7 @@ reg_fetch_contacts("location", "sip:[email protected]", "caller");
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
-   Example 1.28. registered usage
+   Example 1.26. registered usage
 ...
 reg_free_contacts("callee");
 ...
@@ -815,7 +794,7 @@ reg_free_contacts("callee");
    The pseudo-variable accepts positive index value to access a specific
    contact record.
 
-   Example 1.29. $ulc(name) usage
+   Example 1.27. $ulc(name) usage
 ...
 if(reg_fetch_contacts("location", "$fu", "caller"))
 {

+ 3 - 3
modules_k/registrar/api.c

@@ -45,7 +45,7 @@ int regapi_save(struct sip_msg *msg, char *table, int flags)
 		LM_ERR("usrloc domain [%s] not found\n", table);
 		return -1;
 	}
-	return save(msg, d, flags);
+	return save(msg, d, flags, NULL);
 }
 
 /**
@@ -60,7 +60,7 @@ int regapi_lookup(struct sip_msg *msg, char *table)
 		LM_ERR("usrloc domain [%s] not found\n", table);
 		return -1;
 	}
-	return lookup(msg, d);
+	return lookup(msg, d, NULL);
 }
 
 /**
@@ -75,7 +75,7 @@ int regapi_registered(struct sip_msg *msg, char *table)
 		LM_ERR("usrloc domain [%s] not found\n", table);
 		return -1;
 	}
-	return registered(msg, (char*)d, NULL);
+	return registered(msg, d, NULL);
 }
 
 /**

+ 1 - 12
modules_k/registrar/common.c

@@ -53,22 +53,11 @@ int extract_aor(str* _uri, str* _a)
 	str tmp;
 	struct sip_uri puri;
 	int user_len;
-	int_str avp_val;
-	struct usr_avp *avp;
 	str *uri;
 	str realm_prefix;
 	
 	memset(aor_buf, 0, MAX_AOR_LEN);
-	if (aor_avp_name.n!=0) {
-		avp = search_first_avp( aor_avp_type, aor_avp_name, &avp_val, 0);
-		if (avp && is_avp_str_val(avp)) {
-			uri = &avp_val.s;
-		} else {
-			uri = _uri;
-		}
-	} else {
-		uri=_uri;
-	}
+	uri=_uri;
 
 	if (parse_uri(uri->s, uri->len, &puri) < 0) {
 		rerrno = R_AOR_PARSE;

+ 50 - 77
modules_k/registrar/doc/registrar_admin.xml

@@ -284,26 +284,9 @@ modparam("registrar", "append_branches", 0)
 	<section>
 		<title><varname>aor_avp</varname> (str)</title>
 		<para>
-		If set, the module will try first to get the AOR from this AVP 
-		instead of fetching it form the processed request.
+		This module parameter has been removed. Use the 'uri' parameter from
+		functions (e.g., save, lookup, registered).
 		</para>
-		<para>
-		The AVP must contain a valid SIP URI. If no AVP is found, it will be
-		tried to get the AOR from the message (standard behaviour).
-		</para>
-		<para>
-		<emphasis>
-			Default value is "NULL" (disabled).
-		</emphasis>
-		</para>
-		<example>
-		<title>Set <varname>aor_avp</varname> parameter</title>
-		<programlisting format="linespecific">
-...
-modparam("registrar", "aor_avp", "$avp(i:3223)")
-...
-</programlisting>
-		</example>
 	</section>
 
 	<section>
@@ -630,7 +613,7 @@ modparam("registrar", "reg_callid_avp", "$avp(s:avp)")
 	<title>Functions</title>
 	<section>
 		<title>
-		<function moreinfo="none">save(domain)</function>
+		<function moreinfo="none">save(domain, [, flags [, uri]])</function>
 		</title>
 		<para>
 		The function processes a REGISTER message. It can add, remove or 
@@ -649,61 +632,10 @@ modparam("registrar", "reg_callid_avp", "$avp(s:avp)")
 			stores the contacts.
 			</para>
 		</listitem>
-		</itemizedlist>
-		<para>Return codes:</para>
-		<itemizedlist>
 		<listitem>
 			<para>
-			<emphasis>-1</emphasis> - error.
-			</para>
-			<para>
-			<emphasis>1</emphasis> - contacts inserted.
-			</para>
-			<para>
-			<emphasis>2</emphasis> - contacts updated.
-			</para>
-			<para>
-			<emphasis>3</emphasis> - contacts deleted.
-			</para>
-			<para>
-			<emphasis>4</emphasis> - contacts returned.
-			</para>
-		</listitem>
-		</itemizedlist>
-		<para>
-		This function can be used from REQUEST_ROUTE and REPLY_ROUTE.
-		</para>
-		<example>
-		<title><function>save</function> usage</title>
-		<programlisting format="linespecific">
-...
-save("location");
-...
-</programlisting>
-		</example>
-	</section>
-
-	<section>
-		<title>
-		<function moreinfo="none">save(domain,flags)</function>
-		</title>
-		<para>
-		Same as <function>save()</function> but it accepts a set of flags for
-		controlling its behaviour.
-		</para>
-		<para>Meaning of the parameters is as follows:</para>
-		<itemizedlist>
-		<listitem>
-			<para>
-			<emphasis>domain</emphasis> - Logical domain within registrar. 
-			If database is used then this must be name of the table which 
-			stores the contacts.
-			</para>
-		</listitem>
-		<listitem>
-			<para>
-			<emphasis>flags</emphasis> - the value may be a bitwise OR of 
-			the following flags:
+			<emphasis>flags</emphasis> (optional) - the value may be a bitwise
+			OR of the following flags:
 			</para>
 			<itemizedlist>
 				<listitem>
@@ -725,15 +657,44 @@ save("location");
 			</itemizedlist>
 			<para>The flags may be given in decimal or hexa format.</para>
 		</listitem>
+		<listitem>
+			<para>
+			<emphasis>uri</emphasis> (optional - flags param has to be set and
+			can be 0 for default behavior) - SIP URI to do be used instead of To
+			header URI. It can be a dynamic string with pseudo-variables.
+			</para>
+		</listitem>
+		</itemizedlist>
+		<para>Return codes:</para>
+		<itemizedlist>
+		<listitem>
+			<para>
+			<emphasis>-1</emphasis> - error.
+			</para>
+			<para>
+			<emphasis>1</emphasis> - contacts inserted.
+			</para>
+			<para>
+			<emphasis>2</emphasis> - contacts updated.
+			</para>
+			<para>
+			<emphasis>3</emphasis> - contacts deleted.
+			</para>
+			<para>
+			<emphasis>4</emphasis> - contacts returned.
+			</para>
+		</listitem>
 		</itemizedlist>
 		<para>
-		This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
+		This function can be used from REQUEST_ROUTE and REPLY_ROUTE.
 		</para>
 		<example>
 		<title><function>save</function> usage</title>
 		<programlisting format="linespecific">
 ...
-save("location","0x01");
+save("location");
+save("location", "0x01");
+save("location", "0x00", "sip:[email protected]");
 ...
 </programlisting>
 		</example>
@@ -741,7 +702,7 @@ save("location","0x01");
 
 	<section>
 		<title>
-		<function moreinfo="none">lookup(domain)</function>
+		<function moreinfo="none">lookup(domain [, uri])</function>
 		</title>
 		<para>
 		The functions extracts username from Request-URI and tries to find 
@@ -764,6 +725,12 @@ save("location","0x01");
 			for the lookup.
 			</para>
 		</listitem>
+		<listitem>
+			<para>
+			<emphasis>uri</emphasis> (optional) - SIP URI to do be used instead
+			of R-URI. It can be a dynamic string with pseudo-variables.
+			</para>
+		</listitem>
 		</itemizedlist>
 		<para>Return codes:</para>
 		<itemizedlist>
@@ -807,7 +774,7 @@ switch ($retcode) {
 
 	<section>
 		<title>
-		<function moreinfo="none">registered(domain)</function>
+		<function moreinfo="none">registered(domain [, uri])</function>
 		</title>
 		<para>
 		The function returns true if the AOR in the Request-URI is 
@@ -823,6 +790,12 @@ switch ($retcode) {
 			used for the lookup.
 			</para>
 		</listitem>
+		<listitem>
+			<para>
+			<emphasis>uri</emphasis> (optional) - SIP URI to do be used instead
+			of R-URI. It can be a dynamic string with pseudo-variables.
+			</para>
+		</listitem>
 		</itemizedlist>
 		<para>
 		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.

+ 16 - 10
modules_k/registrar/lookup.c

@@ -38,6 +38,7 @@
 #include "../../str.h"
 #include "../../config.h"
 #include "../../action.h"
+#include "../../mod_fix.h"
 #include "../../parser/parse_rr.h"
 #include "../usrloc/usrloc.h"
 #include "common.h"
@@ -56,7 +57,7 @@
  *          -2 : found but method not allowed
  *          -3 : error
  */
-int lookup(struct sip_msg* _m, udomain_t* _d)
+int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri)
 {
 	urecord_t* r;
 	str aor, uri;
@@ -70,7 +71,7 @@ int lookup(struct sip_msg* _m, udomain_t* _d)
 	if (_m->new_uri.s) uri = _m->new_uri;
 	else uri = _m->first_line.u.request.uri;
 	
-	if (extract_aor(&uri, &aor) < 0) {
+	if (extract_aor((_uri)?_uri:&uri, &aor) < 0) {
 		LM_ERR("failed to extract address of record\n");
 		return -3;
 	}
@@ -180,7 +181,7 @@ done:
  * it is similar to lookup but registered neither rewrites
  * the Request-URI nor appends branches
  */
-int registered(struct sip_msg* _m, char* _t, char* _s)
+int registered(struct sip_msg* _m, udomain_t* _d, str* _uri)
 {
 	str uri, aor;
 	urecord_t* r;
@@ -188,19 +189,24 @@ int registered(struct sip_msg* _m, char* _t, char* _s)
 	int res;
 	int_str match_callid=(int_str)0;
 
-	if (_m->new_uri.s) uri = _m->new_uri;
-	else uri = _m->first_line.u.request.uri;
+	if(_uri!=NULL)
+	{
+		uri = *_uri;
+	} else {
+		if (_m->new_uri.s) uri = _m->new_uri;
+		else uri = _m->first_line.u.request.uri;
+	}
 	
 	if (extract_aor(&uri, &aor) < 0) {
 		LM_ERR("failed to extract address of record\n");
 		return -1;
 	}
 	
-	ul.lock_udomain((udomain_t*)_t, &aor);
-	res = ul.get_urecord((udomain_t*)_t, &aor, &r);
+	ul.lock_udomain(_d, &aor);
+	res = ul.get_urecord(_d, &aor, &r);
 
 	if (res < 0) {
-		ul.unlock_udomain((udomain_t*)_t, &aor);
+		ul.unlock_udomain(_d, &aor);
 		LM_ERR("failed to query usrloc\n");
 		return -1;
 	}
@@ -224,13 +230,13 @@ int registered(struct sip_msg* _m, char* _t, char* _s)
 				memcmp(match_callid.s.s,ptr->callid.s,match_callid.s.len))
 				continue;
 			ul.release_urecord(r);
-			ul.unlock_udomain((udomain_t*)_t, &aor);
+			ul.unlock_udomain(_d, &aor);
 			LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
 			return 1;
 		}
 	}
 
-	ul.unlock_udomain((udomain_t*)_t, &aor);
+	ul.unlock_udomain(_d, &aor);
 	LM_DBG("'%.*s' not found in usrloc\n", aor.len, ZSW(aor.s));
 	return -1;
 }

+ 2 - 2
modules_k/registrar/lookup.h

@@ -39,7 +39,7 @@
 /*! \brief
  * Lookup a contact in usrloc and rewrite R-URI if found
  */
-int lookup(struct sip_msg* _m, udomain_t* _d);
+int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri);
 
 
 /*! \brief
@@ -47,7 +47,7 @@ int lookup(struct sip_msg* _m, udomain_t* _d);
  * it is similar to lookup but registered neither rewrites
  * the Request-URI nor appends branches
  */
-int registered(struct sip_msg* _m, char* _t, char* _s);
+int registered(struct sip_msg* _m, udomain_t* _d, str* _uri);
 
 
 #endif /* LOOKUP_H */

+ 84 - 36
modules_k/registrar/reg_mod.c

@@ -87,11 +87,15 @@ usrloc_api_t ul;/*!< Structure containing pointers to usrloc functions*/
 static int  mod_init(void);
 static int  child_init(int);
 static void mod_destroy(void);
-static int w_save(struct sip_msg* _m, char* _d, char* _cflags);
+static int w_save2(struct sip_msg* _m, char* _d, char* _cflags);
+static int w_save3(struct sip_msg* _m, char* _d, char* _cflags, char* _uri);
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
+static int w_registered(struct sip_msg* _m, char* _d, char* _uri);
+static int w_unregister(struct sip_msg* _m, char* _d, char* _uri);
 
 /*! \brief Fixup functions */
 static int domain_fixup(void** param, int param_no);
+static int domain_uri_fixup(void** param, int param_no);
 static int save_fixup(void** param, int param_no);
 static int unreg_fixup(void** param, int param_no);
 static int fetchc_fixup(void** param, int param_no);
@@ -109,11 +113,6 @@ int path_mode = PATH_MODE_STRICT;		/*!< if the Path HF should be inserted in the
 int path_use_params = 0;			/*!< if the received- and nat-parameters of last Path uri should be used
  						 * to determine if UAC is nat'ed */
 
-char *aor_avp_param =0;				/*!< if instead of extacting the AOR from the request, it should be 
- 						 * fetched via this AVP ID */
-unsigned short aor_avp_type=0;
-int_str aor_avp_name;
-
 /* Populate this AVP if testing for specific registration instance. */
 char *reg_callid_avp_param = 0;
 unsigned short reg_callid_avp_type = 0;
@@ -154,17 +153,23 @@ static pv_export_t mod_pvs[] = {
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"save",         (cmd_function)w_save,       1,    save_fixup, 0,
+	{"save",         (cmd_function)w_save2,       1,  save_fixup, 0,
+			REQUEST_ROUTE | ONREPLY_ROUTE },
+	{"save",         (cmd_function)w_save2,       2,  save_fixup, 0,
 			REQUEST_ROUTE | ONREPLY_ROUTE },
-	{"save",         (cmd_function)w_save,       2,    save_fixup, 0,
+	{"save",         (cmd_function)w_save3,       3,  save_fixup, 0,
 			REQUEST_ROUTE | ONREPLY_ROUTE },
-	{"lookup",       (cmd_function)w_lookup,     1,  domain_fixup, 0,
+	{"lookup",       (cmd_function)w_lookup,      1,  domain_uri_fixup, 0,
+			REQUEST_ROUTE | FAILURE_ROUTE },
+	{"lookup",       (cmd_function)w_lookup,      2,  domain_uri_fixup, 0,
+			REQUEST_ROUTE | FAILURE_ROUTE },
+	{"registered",   (cmd_function)w_registered,  1,  domain_uri_fixup, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
-	{"registered",   (cmd_function)registered,   1,  domain_fixup, 0,
+	{"registered",   (cmd_function)w_registered,  2,  domain_uri_fixup, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
-	{"add_sock_hdr", (cmd_function)add_sock_hdr, 1,fixup_str_null, 0,
+	{"add_sock_hdr", (cmd_function)add_sock_hdr,  1,  fixup_str_null, 0,
 			REQUEST_ROUTE },
-	{"unregister",   (cmd_function)unregister,   2,   unreg_fixup, 0,
+	{"unregister",   (cmd_function)w_unregister,  2,  unreg_fixup, 0,
 			REQUEST_ROUTE| FAILURE_ROUTE },
 	{"reg_fetch_contacts", (cmd_function)pv_fetch_contacts, 3, 
 			fetchc_fixup, 0,
@@ -193,7 +198,6 @@ static param_export_t params[] = {
 	{"max_expires",        INT_PARAM, &default_registrar_cfg.max_expires			},
 	{"received_param",     STR_PARAM, &rcv_param           					},
 	{"received_avp",       STR_PARAM, &rcv_avp_param       					},
-	{"aor_avp",            STR_PARAM, &aor_avp_param       					},
 	{"reg_callid_avp",     STR_PARAM, &reg_callid_avp_param					},
 	{"max_contacts",       INT_PARAM, &default_registrar_cfg.max_contacts			},
 	{"retry_after",        INT_PARAM, &default_registrar_cfg.retry_after			},
@@ -290,23 +294,6 @@ static int mod_init(void)
 		rcv_avp_name.n = 0;
 		rcv_avp_type = 0;
 	}
-	if (aor_avp_param && *aor_avp_param) {
-		s.s = aor_avp_param; s.len = strlen(s.s);
-		if (pv_parse_spec(&s, &avp_spec)==0
-				|| avp_spec.type!=PVT_AVP) {
-			LM_ERR("malformed or non AVP %s AVP definition\n", aor_avp_param);
-			return -1;
-		}
-
-		if(pv_get_avp_name(0, &avp_spec.pvp, &aor_avp_name, &aor_avp_type)!=0)
-		{
-			LM_ERR("[%s]- invalid AVP definition\n", aor_avp_param);
-			return -1;
-		}
-	} else {
-		aor_avp_name.n = 0;
-		aor_avp_type = 0;
-	}
 
 	if (reg_callid_avp_param && *reg_callid_avp_param) {
 		s.s = reg_callid_avp_param; s.len = strlen(s.s);
@@ -392,17 +379,62 @@ static int child_init(int rank)
 /*! \brief
  * Wrapper to save(location)
  */
-static int w_save(struct sip_msg* _m, char* _d, char* _cflags)
+static int w_save2(struct sip_msg* _m, char* _d, char* _cflags)
 {
-	return save(_m, (udomain_t*)_d, ((int)(unsigned long)_cflags));
+	return save(_m, (udomain_t*)_d, ((int)(unsigned long)_cflags), NULL);
+}
+
+/*! \brief
+ * Wrapper to save(location)
+ */
+static int w_save3(struct sip_msg* _m, char* _d, char* _cflags, char* _uri)
+{
+	str uri;
+	if(fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0)
+	{
+		LM_ERR("invalid uri parameter\n");
+		return -1;
+	}
+
+	return save(_m, (udomain_t*)_d, ((int)(unsigned long)_cflags), &uri);
 }
 
 /*! \brief
  * Wrapper to lookup(location)
  */
-static int w_lookup(struct sip_msg* _m, char* _d, char* _p2)
+static int w_lookup(struct sip_msg* _m, char* _d, char* _uri)
 {
-	return lookup(_m, (udomain_t*)_d);
+	str uri = {0};
+	if(_uri!=NULL && (fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0))
+	{
+		LM_ERR("invalid uri parameter\n");
+		return -1;
+	}
+
+	return lookup(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL);
+}
+
+static int w_registered(struct sip_msg* _m, char* _d, char* _uri)
+{
+	str uri = {0};
+	if(_uri!=NULL && (fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0))
+	{
+		LM_ERR("invalid uri parameter\n");
+		return -1;
+	}
+	return registered(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL);
+}
+
+static int w_unregister(struct sip_msg* _m, char* _d, char* _uri)
+{
+	str uri = {0};
+	if(fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0)
+	{
+		LM_ERR("invalid uri parameter\n");
+		return -1;
+	}
+
+	return unregister(_m, (udomain_t*)_d, &uri);
 }
 
 /*! \brief
@@ -423,6 +455,20 @@ static int domain_fixup(void** param, int param_no)
 	return 0;
 }
 
+/*! \brief
+ * Convert char* parameter to udomain_t* pointer
+ */
+static int domain_uri_fixup(void** param, int param_no)
+{
+	if (param_no == 1) {
+		return domain_fixup(param, 1);
+	} else if (param_no == 2) {
+		return fixup_spve_null(param, 1);
+	}
+	return 0;
+}
+
+
 /*! \brief
  * Convert char* parameter to udomain_t* pointer
  * Convert char* parameter to pv_elem_t* pointer
@@ -449,7 +495,7 @@ static int save_fixup(void** param, int param_no)
 
 	if (param_no == 1) {
 		return domain_fixup(param,param_no);
-	} else {
+	} else if (param_no == 2) {
 		s.s = (char*)*param;
 		s.len = strlen(s.s);
 		flags = 0;
@@ -463,8 +509,10 @@ static int save_fixup(void** param, int param_no)
 		}
 		pkg_free(*param);
 		*param = (void*)(unsigned long int)flags;
-		return 0;
+	} else if (param_no == 3) {
+		return fixup_spve_null(param, 1);
 	}
+	return 0;
 }
 
 /*! \brief

+ 0 - 2
modules_k/registrar/reg_mod.h

@@ -73,8 +73,6 @@ extern int received_avp;
 extern int reg_use_domain;
 extern float def_q;
 
-extern unsigned short aor_avp_type;
-extern int_str aor_avp_name;
 extern unsigned short rcv_avp_type;
 extern int_str rcv_avp_name;
 extern unsigned short reg_callid_avp_type;

+ 5 - 12
modules_k/registrar/save.c

@@ -749,7 +749,7 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
  * Process REGISTER request and save it's contacts
  */
 #define is_cflag_set(_name) (((unsigned int)_cflags)&(_name))
-int save(struct sip_msg* _m, udomain_t* _d, int _cflags)
+int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
 {
 	contact_t* c;
 	int st, mode;
@@ -770,7 +770,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags)
 	get_act_time();
 	c = get_first_contact(_m);
 
-	if (extract_aor(&get_to(_m)->uri, &aor) < 0) {
+	if (extract_aor((_uri)?_uri:&get_to(_m)->uri, &aor) < 0) {
 		LM_ERR("failed to extract Address Of Record\n");
 		goto error;
 	}
@@ -807,23 +807,16 @@ error:
 	return 0;
 }
 
-int unregister(struct sip_msg* _m, char* _d, char* _uri)
+int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri)
 {
 	str aor = {0, 0};
-	str uri = {0, 0};
 
-	if(fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0)
-	{
-		LM_ERR("invalid uri parameter\n");
-		return -1;
-	}
-
-	if (extract_aor(&uri, &aor) < 0) {
+	if (extract_aor(_uri, &aor) < 0) {
 		LM_ERR("failed to extract Address Of Record\n");
 		return -1;
 	}
 
-	if (star((udomain_t*)_d, &aor) < 0)
+	if (star(_d, &aor) < 0)
 	{
 		LM_ERR("error unregistering user [%.*s]\n", aor.len, aor.s);
 		return -1;

+ 2 - 2
modules_k/registrar/save.h

@@ -46,8 +46,8 @@
 /*! \brief
  * Process REGISTER request and save it's contacts
  */
-int save(struct sip_msg* _m, udomain_t* _d, int _cflags);
-int unregister(struct sip_msg* _m, char* _d, char* _uri);
+int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str* _uri);
+int unregister(struct sip_msg* _m, udomain_t* _d, str* _uri);
 
 
 #endif /* SAVE_H */