[Devel] Patch: cpl-c feature, support for NAT/received

John Riordan john at junctionnetworks.com
Fri Feb 24 22:41:18 CET 2006


Hi,

Issue:

In CPL, when a lookup of a registered contact is done, the "received"
location attribute is ignored. As such, registrations processed with
fix_nated_register are not handled as expected in CPL.

Patch:

Added support to cpl-c for dealing with the "received" location attribute.


John

-------------- next part --------------
Index: sip-server/modules/cpl-c/cpl.c
===================================================================
RCS file: /cvsroot/openser/sip-server/modules/cpl-c/cpl.c,v
retrieving revision 1.9
diff -u -r1.9 cpl.c
--- sip-server/modules/cpl-c/cpl.c	14 Feb 2006 16:27:15 -0000	1.9
+++ sip-server/modules/cpl-c/cpl.c	24 Feb 2006 21:21:25 -0000
@@ -625,7 +625,7 @@
 		/* build user initial location */
 		if (build_user_AOR( &username, &domain, &loc, 1)!=0 )
 			goto error2;
-		if (add_location( &(cpl_intr->loc_set), &loc,10, 0/*no dup*/)==-1)
+		if (add_location( &(cpl_intr->loc_set), &loc, 0, 10, 0/*no dup*/)==-1)
 			goto error2;
 	}
 
Index: sip-server/modules/cpl-c/cpl_proxy.h
===================================================================
RCS file: /cvsroot/openser/sip-server/modules/cpl-c/cpl_proxy.h,v
retrieving revision 1.4
diff -u -r1.4 cpl_proxy.h
--- sip-server/modules/cpl-c/cpl_proxy.h	10 Feb 2006 18:55:46 -0000	1.4
+++ sip-server/modules/cpl-c/cpl_proxy.h	24 Feb 2006 21:21:25 -0000
@@ -128,7 +128,7 @@
 				prio = 10; /* set default to minimum */
 			}
 			/* add the uri to location set */
-			if (add_location( loc_set, &contacts->uri,prio, CPL_LOC_DUPL)!=0) {
+			if (add_location( loc_set, &contacts->uri, 0, prio, CPL_LOC_DUPL)!=0) {
 				LOG(L_ERR,"ERROR:cpl-c:add_contacts_to_loc_set: unable to add "
 				"<%.*s>\n",contacts->uri.len,contacts->uri.s);
 			}
Index: sip-server/modules/cpl-c/cpl_run.c
===================================================================
RCS file: /cvsroot/openser/sip-server/modules/cpl-c/cpl_run.c,v
retrieving revision 1.2
diff -u -r1.2 cpl_run.c
--- sip-server/modules/cpl-c/cpl_run.c	1 Jul 2005 14:52:32 -0000	1.2
+++ sip-server/modules/cpl-c/cpl_run.c	24 Feb 2006 21:21:25 -0000
@@ -293,7 +293,7 @@
 				do {
 					DBG("DBG:cpl-c:run_lookup: adding <%.*s>q=%d\n",
 						contact->c.len,contact->c.s,(int)(10*contact->q));
-					if (add_location( &(intr->loc_set), &contact->c,
+					if (add_location( &(intr->loc_set), &contact->c, &contact->received,
 					(int)(10*contact->q),
 					CPL_LOC_DUPL|((contact->flags & FL_NAT)*CPL_LOC_NATED)
 					)==-1) {
@@ -389,7 +389,7 @@
 
 	if (clear)
 		empty_location_set( &(intr->loc_set) );
-	if (add_location( &(intr->loc_set), &url, prio, 0/*no dup*/ )==-1) {
+	if (add_location( &(intr->loc_set), &url, 0, prio, 0/*no dup*/ )==-1) {
 		LOG(L_ERR,"ERROR:run_location: unable to add location to set :-(\n");
 		goto runtime_error;
 	}
Index: sip-server/modules/cpl-c/cpl_sig.c
===================================================================
RCS file: /cvsroot/openser/sip-server/modules/cpl-c/cpl_sig.c,v
retrieving revision 1.5
diff -u -r1.5 cpl_sig.c
--- sip-server/modules/cpl-c/cpl_sig.c	26 Jan 2006 18:00:25 -0000	1.5
+++ sip-server/modules/cpl-c/cpl_sig.c	24 Feb 2006 21:21:25 -0000
@@ -62,6 +62,20 @@
 			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: do_action failed\n");
 			goto error;
 		}
+		/* build a new action for setting the DSTURI */
+		if((*locs)->addr.received.s && (*locs)->addr.received.len) {
+			DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: rewriting Destination URI with "
+				"<%s>\n",(*locs)->addr.received.s);
+			act.type = SET_DSTURI_T;
+			act.p1_type = STRING_ST;
+			act.p1.string = (*locs)->addr.received.s;
+			act.next = 0;
+			/* push the action */
+			if (do_action(&act, msg) < 0) {
+			  	LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: do_action failed\n");
+				goto error;
+			}
+		}
 		/* is the location NATED? */
 		if ((*locs)->flags&CPL_LOC_NATED) setflag(msg,cpl_env.nat_flag);
 		/* free the location and point to the next one */
@@ -74,7 +88,7 @@
 	while(*locs) {
 		DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: appending branch "
 			"<%.*s>\n",(*locs)->addr.uri.len,(*locs)->addr.uri.s);
-		if(append_branch(msg, &(*locs)->addr.uri, 0, 0, Q_UNSPECIFIED, 0, 0)==-1){
+		if(append_branch(msg, &(*locs)->addr.uri, &(*locs)->addr.received, 0, Q_UNSPECIFIED, 0, 0)==-1){
 			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: failed when "
 				"appending branch <%s>\n",(*locs)->addr.uri.s);
 			goto error;
Index: sip-server/modules/cpl-c/loc_set.h
===================================================================
RCS file: /cvsroot/openser/sip-server/modules/cpl-c/loc_set.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 loc_set.h
--- sip-server/modules/cpl-c/loc_set.h	13 Jun 2005 16:47:36 -0000	1.1.1.1
+++ sip-server/modules/cpl-c/loc_set.h	24 Feb 2006 21:21:26 -0000
@@ -41,6 +41,7 @@
 struct location {
 	struct address {
 		str uri;
+		str received;
 		unsigned int priority;
 	}addr;
 	int flags;
@@ -59,14 +60,18 @@
 /* insert a new location into the set maintaining order by the prio val - the
  * list starts with the smallest prio!
  * For locations having the same prio val, the adding order will be kept */
-static inline int add_location(struct location **loc_set, str *uri,
+static inline int add_location(struct location **loc_set, str *uri, str *received,
 											unsigned int prio, int flags)
 {
 	struct location *loc;
 	struct location *foo, *bar;
 
-	loc = (struct location*)shm_malloc(
-		sizeof(struct location)+((flags&CPL_LOC_DUPL)?uri->len+1:0) );
+	if(received && received->s && received->len)
+		loc = (struct location*)shm_malloc(
+			sizeof(struct location)+((flags&CPL_LOC_DUPL)?uri->len+1+received->len+1:0) );
+	else 
+		loc = (struct location*)shm_malloc(
+			sizeof(struct location)+((flags&CPL_LOC_DUPL)?uri->len+1:0) );
 	if (!loc) {
 		LOG(L_ERR,"ERROR:add_location: no more free shm memory!\n");
 		return -1;
@@ -83,6 +88,22 @@
 	loc->addr.priority = prio;
 	loc->flags = flags;
 
+	if(received && received->s && received->len) {
+		if (flags&CPL_LOC_DUPL) {
+			loc->addr.received.s = ((char*)loc)+sizeof(struct location)+uri->len+1;
+			memcpy(loc->addr.received.s,received->s,received->len);
+			loc->addr.received.s[received->len] = 0;
+		}
+		else {
+			loc->addr.received.s = received->s;
+		}
+		loc->addr.received.len = received->len;
+	}
+	else {
+		loc->addr.received.s = 0;
+		loc->addr.received.len = 0;
+	}
+
 	/* find the proper place for the new location */
 	foo = *loc_set;
 	bar = 0;
@@ -167,7 +188,7 @@
 static inline void print_location_set(struct location *loc_set)
 {
 	while (loc_set) {
-		DBG("DEBUG:cpl_c:print_loc_set: uri=<%s> q=%d\n",loc_set->addr.uri.s,
+		DBG("DEBUG:cpl_c:print_loc_set: uri=<%s> received=<%s> q=%d\n",loc_set->addr.uri.s,loc_set->addr.received.s,
 			loc_set->addr.priority);
 		loc_set=loc_set->next;
 	}


More information about the Devel mailing list