Browse Source

registrar: add contact and recieved values to xavp_rcd

set xavp_rcd at registered() too
Victor Seva 10 years ago
parent
commit
be4f1a65d1
2 changed files with 72 additions and 23 deletions
  1. 23 3
      modules/registrar/doc/registrar_admin.xml
  2. 49 20
      modules/registrar/lookup.c

+ 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) {