Bladeren bron

registrar: add contact and recieved values to xavp_rcd

set xavp_rcd at registered() too
Victor Seva 10 jaren geleden
bovenliggende
commit
be4f1a65d1
2 gewijzigde bestanden met toevoegingen van 72 en 23 verwijderingen
  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>
 		<para>
 			Defines the name of XAVP class to store details from the
 			Defines the name of XAVP class to store details from the
 			location records. The values are stored as inner XAVPs, like
 			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>
 		</para>
 		<itemizedlist>
 		<itemizedlist>
 		<listitem>
 		<listitem>
@@ -748,11 +748,31 @@ modparam("registrar", "xavp_cfg", "reg")
 				id.
 				id.
 			</para>
 			</para>
 		</listitem>
 		</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>
 		</itemizedlist>
 		<para>
 		<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>
 		</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>
 		<para>
 		<emphasis>
 		<emphasis>
 			Default value is NULL (disabled).
 			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);
      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
 /*! \brief
  * Lookup contact in the database and rewrite Request-URI
  * Lookup contact in the database and rewrite Request-URI
  * or not according to _mode value:
  * 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};
 	str inst = {0};
 	unsigned int ahash = 0;
 	unsigned int ahash = 0;
 	sr_xavp_t *xavp=NULL;
 	sr_xavp_t *xavp=NULL;
-	sr_xavp_t *list=NULL;
-	str xname = {"ruid", 4};
-	sr_xval_t xval;
 	sip_uri_t path_uri;
 	sip_uri_t path_uri;
 	str path_str;
 	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 next hop address */
 		reset_dst_uri(_m);
 		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
 		/* If a Path is present, use first path-uri in favour of
 		 * received-uri because in that case the last hop towards the uac
 		 * 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)))
 				memcmp(match_contact.s, ptr->c.s, match_contact.len)))
 				continue;
 				continue;
 
 
+			xavp_rcd_helper(ptr);
+
 			if(ptr->xavp!=NULL && match_action_flag == 1) {
 			if(ptr->xavp!=NULL && match_action_flag == 1) {
 				sr_xavp_t *xavp = xavp_clone_level_nodata(ptr->xavp);
 				sr_xavp_t *xavp = xavp_clone_level_nodata(ptr->xavp);
 				if(xavp_add(xavp, NULL)<0) {
 				if(xavp_add(xavp, NULL)<0) {