Browse code

-lookup node recognize nated addresses and sets the coresponding script flag

Bogdan-Andrei Iancu authored on 30/11/2003 11:21:47
Showing 5 changed files
... ...
@@ -549,7 +549,7 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
549 549
 	if ( ((unsigned int)str1)&CPL_RUN_OUTGOING ) {
550 550
 		if (get_dest_user( msg, &loc,0)==-1)
551 551
 			goto error3;
552
-		if (add_location( &(cpl_intr->loc_set), &loc,10/*prio*/,1/*dup*/)==-1)
552
+		if (add_location( &(cpl_intr->loc_set), &loc,10,CPL_LOC_DUPL)==-1)
553 553
 			goto error3;
554 554
 	}
555 555
 
... ...
@@ -133,7 +133,7 @@ static inline int add_contacts_to_loc_set(struct sip_msg* msg,
133 133
 				prio = 10; /* set default to minimum */
134 134
 			}
135 135
 			/* add the uri to location set */
136
-			if (add_location( loc_set, &contacts->uri,prio, 1/*dup*/)!=0) {
136
+			if (add_location( loc_set, &contacts->uri,prio, CPL_LOC_DUPL)!=0) {
137 137
 				LOG(L_ERR,"ERROR:cpl-c:add_contacts_to_loc_set: unable to add "
138 138
 				"<%.*s>\n",contacts->uri.len,contacts->uri.s);
139 139
 			}
... ...
@@ -111,7 +111,6 @@ extern char            *log_dir;
111 111
 extern struct tm_binds cpl_tmb;
112 112
 extern udomain_t*      cpl_domain;
113 113
 extern usrloc_api_t    cpl_ulb;
114
-extern int             cpl_nat_flag;
115 114
 
116 115
 
117 116
 struct cpl_interpreter* new_cpl_interpreter( struct sip_msg *msg, str *script)
... ...
@@ -300,15 +299,13 @@ static inline char *run_lookup( struct cpl_interpreter *intr )
300 299
 				DBG("DBG:cpl-c:run_lookup: adding <%.*s>q=%d\n",
301 300
 					contact->c.len,contact->c.s,(int)(10*contact->q));
302 301
 				if (add_location( &(intr->loc_set), &contact->c,
303
-				(int)(10*contact->q), 1/*dup*/ )==-1) {
302
+				(int)(10*contact->q),
303
+				CPL_LOC_DUPL|((contact->flags & FL_NAT)*CPL_LOC_NATED) )==-1) {
304 304
 					LOG(L_ERR,"ERROR:cpl-c:run_lookup: unable to add "
305 305
 						"location to set :-(\n");
306 306
 					cpl_ulb.unlock_udomain( cpl_domain );
307 307
 					goto runtime_error;
308 308
 				}
309
-				/* mark as nated */
310
-				if (contact->flags & FL_NAT)
311
-					setflag( intr->msg, cpl_nat_flag);
312 309
 				/* set the flag for modifing the location set */
313 310
 				intr->flags |= CPL_LOC_SET_MODIFIED;
314 311
 				/* we found a valid contact */
... ...
@@ -34,6 +34,7 @@
34 34
 
35 35
 extern struct tm_binds cpl_tmb;
36 36
 extern int    proxy_route;
37
+extern int    cpl_nat_flag;
37 38
 
38 39
 
39 40
 /* forwards the msg to the given location set; if flags has set the
... ...
@@ -69,6 +70,8 @@ int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
69 70
 			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: do_action failed\n");
70 71
 			goto error;
71 72
 		}
73
+		/* is the location NATED? */
74
+		if ((*locs)->flags&CPL_LOC_NATED) setflag(msg,cpl_nat_flag);
72 75
 		/* free the location and point to the next one */
73 76
 		foo = (*locs)->next;
74 77
 		free_location( *locs );
... ...
@@ -84,6 +87,8 @@ int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
84 87
 				"appending branch <%s>\n",(*locs)->addr.uri.s);
85 88
 			goto error;
86 89
 		}
90
+		/* is the location NATED? */
91
+		if ((*locs)->flags&CPL_LOC_NATED) setflag(msg,cpl_nat_flag);
87 92
 		/* free the location and point to the next one */
88 93
 		foo = (*locs)->next;
89 94
 		free_location( *locs );
... ...
@@ -39,12 +39,16 @@
39 39
 #include "../../dprint.h"
40 40
 
41 41
 
42
+#define CPL_LOC_DUPL    (1<<0)
43
+#define CPL_LOC_NATED   (1<<0)
44
+
42 45
 
43 46
 struct location {
44 47
 	struct address {
45 48
 		str uri;
46 49
 		unsigned int priority;
47 50
 	}addr;
51
+	int flags;
48 52
 	struct location *next;
49 53
 };
50 54
 
... ...
@@ -61,19 +65,19 @@ static inline void free_location( struct location *loc)
61 65
  * list starts with the smallest prio!
62 66
  * For locations having the same prio val, the adding orser will be keept */
63 67
 static inline int add_location(struct location **loc_set, str *uri,
64
-											unsigned int prio, int dup)
68
+											unsigned int prio, int flags)
65 69
 {
66 70
 	struct location *loc;
67 71
 	struct location *foo, *bar;
68 72
 
69 73
 	loc = (struct location*)shm_malloc(
70
-		sizeof(struct location)+(dup?uri->len+1:0) );
74
+		sizeof(struct location)+((flags&CPL_LOC_DUPL)?uri->len+1:0) );
71 75
 	if (!loc) {
72 76
 		LOG(L_ERR,"ERROR:add_location: no more free shm memory!\n");
73 77
 		return -1;
74 78
 	}
75 79
 
76
-	if (dup) {
80
+	if (flags&CPL_LOC_DUPL) {
77 81
 		loc->addr.uri.s = ((char*)loc)+sizeof(struct location);
78 82
 		memcpy(loc->addr.uri.s,uri->s,uri->len);
79 83
 		loc->addr.uri.s[uri->len] = 0;
... ...
@@ -82,6 +86,7 @@ static inline int add_location(struct location **loc_set, str *uri,
82 86
 	}
83 87
 	loc->addr.uri.len = uri->len;
84 88
 	loc->addr.priority = prio;
89
+	loc->flags = flags;
85 90
 
86 91
 	/* find the proper place for the new location */
87 92
 	foo = *loc_set;