Explorar el Código

Merge pull request #329 from kamailio/vseva/registrar_xavp_rcd

registrar: add contact and received info to xavp_rcd
Victor Seva hace 10 años
padre
commit
7a4899bbdf
Se han modificado 3 ficheros con 119 adiciones y 65 borrados
  1. 47 42
      modules/registrar/README
  2. 23 3
      modules/registrar/doc/registrar_admin.xml
  3. 49 20
      modules/registrar/lookup.c

+ 47 - 42
modules/registrar/README

@@ -20,7 +20,7 @@ Edited by
 
 Bogdan-Andre Iancu
 
-   Copyright © 2003 FhG FOKUS
+   Copyright (c) 2003 FhG FOKUS
      __________________________________________________________________
 
    Table of Contents
@@ -676,11 +676,16 @@ modparam("registrar", "xavp_cfg", "reg")
 
    Defines the name of XAVP class to store details from the location
    records. The values are stored as inner XAVPs, like
-   $xavp(class=>attribute). Valid inner XAVP names:
+   $xavp(class[0]=>attribute). Valid inner XAVP names:
      * ruid - the record's internal unique id.
+     * contact - the record's contact value.
+     * received - the record's received value.
 
-   For example. if this parameter is set to 'ulrcd', then the ruid for
-   contact records are set in $xavp(ulrcd=>ruid).
+   For example. if this parameter is set to 'ulrcd', then values are set
+   in:
+     * $xavp(ulrcd[0]=>ruid)
+     * $xavp(ulrcd[0]=>contact)
+     * $xavp(ulrcd[0]=>received)
 
    Default value is NULL (disabled).
 
@@ -787,7 +792,7 @@ modparam("registrar", "flow_timer", 25)
    4.7. reg_fetch_contacts(domain, uri, profile)
    4.8. reg_free_contacts(profile)
 
-4.1. save(domain, [, flags [, uri]])
+4.1.  save(domain, [, flags [, uri]])
 
    The function processes a REGISTER message. It can add, remove or modify
    location records (in usrloc) depending on Contact and Expires HFs in
@@ -832,7 +837,7 @@ save("location", "0x01");
 save("location", "0x00", "sip:[email protected]");
 ...
 
-4.2. lookup(domain [, uri])
+4.2.  lookup(domain [, uri])
 
    The lookup function extracts username and/or domain from Request-URI
    and tries to find all contacts for the username in usrloc. If there are
@@ -872,7 +877,7 @@ switch ($retcode) {
 };
 ...
 
-4.3. lookup_branches(domain)
+4.3.  lookup_branches(domain)
 
    The function performs lookup(domain) on r-uri and additional branches
    (only branches that have no other attributes set than uri).
@@ -889,7 +894,7 @@ switch ($retcode) {
 lookup_branches("location");
 ...
 
-4.4. registered(domain [, uri [, match_option [, match_action]]])
+4.4.  registered(domain [, uri [, match_option [, match_action]]])
 
    The function returns true if the AOR in the URI is registered, false
    otherwise. The function does not modify the message being process, it
@@ -928,7 +933,7 @@ if (registered("location","$rz:$Au", 2)) {
 };
 ...
 
-4.5. add_sock_hdr(hdr_name)
+4.5.  add_sock_hdr(hdr_name)
 
    Adds a new header to the current REGISTER request with "hdr_name" which
    contains the description of the received socket (proto:ip:port)
@@ -945,7 +950,7 @@ if (registered("location","$rz:$Au", 2)) {
 add_sock_hdr("Sock-Info");
 ...
 
-4.6. unregister(domain, uri[, ruid])
+4.6.  unregister(domain, uri[, ruid])
 
    The function removes contacts associated with 'uri' from the location
    database. If 'ruid' is provided a specific contact is removed, if
@@ -972,7 +977,7 @@ unregister("location", "$ru", "$ulc(caller=>ruid)");
 unregister("location", "", "$ruid");
 ...
 
-4.7. reg_fetch_contacts(domain, uri, profile)
+4.7.  reg_fetch_contacts(domain, uri, profile)
 
    The function fetches the contacts for 'uri' from table 'domain' to
    pseudo-variable $ulc(profile).
@@ -994,7 +999,7 @@ reg_fetch_contacts("location", "$ru", "callee");
 reg_fetch_contacts("location", "sip:[email protected]", "caller");
 ...
 
-4.8. reg_free_contacts(profile)
+4.8.  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
@@ -1138,60 +1143,60 @@ Chapter 2. Frequently Asked Questions
 
    2.1.
 
-   What happend with the old "nat_flag" module parameter?
+       What happend with the old "nat_flag" module parameter?
 
-   In was removed, as the module internally loads this value from the
-   "USRLOC" module (see the "nat_bflag" USRLOC parameter).
+       In was removed, as the module internally loads this value from the
+       "USRLOC" module (see the "nat_bflag" USRLOC parameter).
 
    2.2.
 
-   What happend with the old "use_domain" module parameter?
+       What happend with the old "use_domain" module parameter?
 
-   In was removed, as the module internally loads this option from the
-   "USRLOC" module. This was done in order to simplify the configuration.
+       In was removed, as the module internally loads this option from the
+       "USRLOC" module. This was done in order to simplify the configuration.
 
    2.3.
 
-   What happened with the old "save_noreply" and "save_memory" functions?
+       What happened with the old "save_noreply" and "save_memory" functions?
 
-   There functions were merged into the new "save(domain,flags)"
-   functions. If a reply should be sent or if the DB should be updated
-   also is controlled via the flags.
+       There functions were merged into the new "save(domain,flags)"
+       functions. If a reply should be sent or if the DB should be updated
+       also is controlled via the flags.
 
    2.4.
 
-   Where can I find more about Kamailio?
+       Where can I find more about Kamailio?
 
-   Take a look at http://www.kamailio.org/.
+       Take a look at http://www.kamailio.org/.
 
    2.5.
 
-   Where can I post a question about this module?
+       Where can I post a question about this module?
 
-   First at all check if your question was already answered on one of our
-   mailing lists:
-     * User Mailing List -
-       http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
-     * Developer Mailing List -
-       http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
+       First at all check if your question was already answered on one of our
+       mailing lists:
+         * User Mailing List -
+           http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
+         * Developer Mailing List -
+           http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
 
-   E-mails regarding any stable Kamailio release should be sent to
-   <[email protected]> and e-mails regarding development
-   versions should be sent to <[email protected]>.
+       E-mails regarding any stable Kamailio release should be sent to
+       <[email protected]> and e-mails regarding development
+       versions should be sent to <[email protected]>.
 
-   If you want to keep the mail private, send it to
-   <[email protected]>.
+       If you want to keep the mail private, send it to
+       <[email protected]>.
 
    2.6.
 
-   How can I report a bug?
+       How can I report a bug?
 
-   Please follow the guidelines provided at:
-   http://sip-router.org/tracker.
+       Please follow the guidelines provided at:
+       http://sip-router.org/tracker.
 
    2.7.
 
-   What happened to the desc_time_order parameter?
+       What happened to the desc_time_order parameter?
 
-   It was removed, as its functionality was migrated into usrloc module,
-   were there is a parameter with the same name.
+       It was removed, as its functionality was migrated into usrloc module,
+       were there is a parameter with the same name.

+ 23 - 3
modules/registrar/doc/registrar_admin.xml

@@ -739,7 +739,7 @@ modparam("registrar", "xavp_cfg", "reg")
 		<para>
 			Defines the name of XAVP class to store details from the
 			location records. The values are stored as inner XAVPs, like
-			$xavp(class=&gt;attribute). Valid inner XAVP names:
+			$xavp(class[0]=&gt;attribute). Valid inner XAVP names:
 		</para>
 		<itemizedlist>
 		<listitem>
@@ -748,11 +748,31 @@ modparam("registrar", "xavp_cfg", "reg")
 				id.
 			</para>
 		</listitem>
+		<listitem>
+			<para>
+				<emphasis>contact</emphasis> - the record's contact value.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+				<emphasis>received</emphasis> - the record's received value.
+			</para>
+		</listitem>
 		</itemizedlist>
 		<para>
-			For example. if this parameter is set to 'ulrcd', then the ruid
-			for contact records are set in $xavp(ulrcd=&gt;ruid).
+			For example. if this parameter is set to 'ulrcd', then values are set in:
 		</para>
+		<itemizedlist>
+		<listitem>
+			<para><emphasis>$xavp(ulrcd[0]=&gt;ruid)</emphasis></para>
+		</listitem>
+		<listitem>
+			<para><emphasis>$xavp(ulrcd[0]=&gt;contact)</emphasis></para>
+		</listitem>
+		<listitem>
+			<para><emphasis>$xavp(ulrcd[0]=&gt;received)</emphasis></para>
+		</listitem>
+		</itemizedlist>
 		<para>
 		<emphasis>
 			Default value is NULL (disabled).

+ 49 - 20
modules/registrar/lookup.c

@@ -92,6 +92,52 @@ int lookup_to_dset(struct sip_msg* _m, udomain_t* _d, str* _uri) {
      return lookup_helper(_m, _d, _uri, 1);
 }
 
+/*! \brief
+ * add xavp with details of the record (ruid, ...)
+ */
+int xavp_rcd_helper(ucontact_t* ptr) {
+	sr_xavp_t *xavp=NULL;
+	sr_xavp_t *list=NULL;
+	str xname_ruid = {"ruid", 4};
+	str xname_received = { "received", 8};
+	str xname_contact = { "contact", 7};
+	sr_xval_t xval;
+
+	if(ptr==NULL) return -1;
+
+	if(reg_xavp_rcd.s!=NULL)
+	{
+		list = xavp_get(&reg_xavp_rcd, NULL);
+		xavp = list;
+		memset(&xval, 0, sizeof(sr_xval_t));
+		xval.type = SR_XTYPE_STR;
+		xval.v.s = ptr->ruid;
+		xavp_add_value(&xname_ruid, &xval, &xavp);
+
+		if(ptr->received.len > 0)
+		{
+			memset(&xval, 0, sizeof(sr_xval_t));
+			xval.type = SR_XTYPE_STR;
+			xval.v.s = ptr->received;
+			xavp_add_value(&xname_received, &xval, &xavp);
+		}
+
+		memset(&xval, 0, sizeof(sr_xval_t));
+		xval.type = SR_XTYPE_STR;
+		xval.v.s = ptr->c;
+		xavp_add_value(&xname_contact, &xval, &xavp);
+
+		if(list==NULL)
+		{
+			/* no reg_xavp_rcd xavp in root list - add it */
+			xval.type = SR_XTYPE_XAVP;
+			xval.v.xavp = xavp;
+			xavp_add_value(&reg_xavp_rcd, &xval, NULL);
+		}
+	}
+	return 0;
+}
+
 /*! \brief
  * Lookup contact in the database and rewrite Request-URI
  * or not according to _mode value:
@@ -115,9 +161,6 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
 	str inst = {0};
 	unsigned int ahash = 0;
 	sr_xavp_t *xavp=NULL;
-	sr_xavp_t *list=NULL;
-	str xname = {"ruid", 4};
-	sr_xval_t xval;
 	sip_uri_t path_uri;
 	str path_str;
 
@@ -238,23 +281,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
 		/* reset next hop address */
 		reset_dst_uri(_m);
 
-		/* add xavp with details of the record (ruid, ...) */
-		if(reg_xavp_rcd.s!=NULL)
-		{
-			list = xavp_get(&reg_xavp_rcd, NULL);
-			xavp = list;
-			memset(&xval, 0, sizeof(sr_xval_t));
-			xval.type = SR_XTYPE_STR;
-			xval.v.s = ptr->ruid;
-			xavp_add_value(&xname, &xval, &xavp);
-			if(list==NULL)
-			{
-				/* no reg_xavp_rcd xavp in root list - add it */
-				xval.type = SR_XTYPE_XAVP;
-				xval.v.xavp = xavp;
-				xavp_add_value(&reg_xavp_rcd, &xval, NULL);
-			}
-		}
+		xavp_rcd_helper(ptr);
 
 		/* If a Path is present, use first path-uri in favour of
 		 * received-uri because in that case the last hop towards the uac
@@ -713,6 +740,8 @@ int registered4(struct sip_msg* _m, udomain_t* _d, str* _uri, int match_flag, in
 				memcmp(match_contact.s, ptr->c.s, match_contact.len)))
 				continue;
 
+			xavp_rcd_helper(ptr);
+
 			if(ptr->xavp!=NULL && match_action_flag == 1) {
 				sr_xavp_t *xavp = xavp_clone_level_nodata(ptr->xavp);
 				if(xavp_add(xavp, NULL)<0) {