Browse code

The possibility to set independent destination URIs for branches.

Jan Janak authored on 01/09/2004 10:12:41
Showing 4 changed files
... ...
@@ -283,7 +283,7 @@ int do_action(struct action* a, struct sip_msg* msg)
283 283
 			}
284 284
 			ret=append_branch( msg, a->p1.string, 
285 285
 					   a->p1.string ? strlen(a->p1.string):0,
286
-					   a->p2.number);
286
+					   0, 0, a->p2.number);
287 287
 			break;
288 288
 
289 289
 		/* jku begin: is_length_greater_than */
... ...
@@ -50,6 +50,11 @@ struct branch
50 50
 {
51 51
 	char uri[MAX_URI_SIZE];
52 52
 	unsigned int len;
53
+
54
+	     /* Real destination of the request */
55
+	char dst_uri[MAX_URI_SIZE];
56
+	unsigned int dst_uri_len;
57
+
53 58
 	int q; /* Preference of the contact among
54 59
 		* contact within the array */
55 60
 };
... ...
@@ -87,7 +92,7 @@ void init_branch_iterator(void)
87 87
  * array, 0 is returned if there are no
88 88
  * more branches
89 89
  */
90
-char* next_branch(int* len, qvalue_t* q)
90
+char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len)
91 91
 {
92 92
 	unsigned int i;
93 93
 
... ...
@@ -96,10 +101,18 @@ char* next_branch(int* len, qvalue_t* q)
96 96
 		branch_iterator++;
97 97
 		*len = branches[i].len;
98 98
 		*q = branches[i].q;
99
+		if (dst_uri && dst_len) {
100
+			*dst_uri = branches[i].dst_uri;
101
+			*dst_len = branches[i].dst_uri_len;
102
+		}
99 103
 		return branches[i].uri;
100 104
 	} else {
101 105
 		*len = 0;
102 106
 		*q = Q_UNSPECIFIED;
107
+		if (dst_uri && dst_len) {
108
+			*dst_uri = 0;
109
+			*dst_len = 0;
110
+		}
103 111
 		return 0;
104 112
 	}
105 113
 }
... ...
@@ -118,7 +131,7 @@ void clear_branches(void)
118 118
 /* 
119 119
  * Add a new branch to current transaction 
120 120
  */
121
-int append_branch(struct sip_msg* msg, char* uri, int uri_len, qvalue_t q)
121
+int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, int dst_uri_len, qvalue_t q)
122 122
 {
123 123
 	     /* if we have already set up the maximum number
124 124
 	      * of branches, don't try new ones 
... ...
@@ -152,6 +165,12 @@ int append_branch(struct sip_msg* msg, char* uri, int uri_len, qvalue_t q)
152 152
 	branches[nr_branches].len = uri_len;
153 153
 	branches[nr_branches].q = q;
154 154
 	
155
+	if (dst_uri) {
156
+		memcpy(branches[nr_branches].dst_uri, dst_uri, dst_uri_len);
157
+		branches[nr_branches].dst_uri[dst_uri_len] = 0;
158
+		branches[nr_branches].dst_uri_len = dst_uri_len;
159
+	}
160
+
155 161
 	nr_branches++;
156 162
 	return 1;
157 163
 }
... ...
@@ -181,7 +200,7 @@ char* print_dset(struct sip_msg* msg, int* len)
181 181
 	}
182 182
 
183 183
 	init_branch_iterator();
184
-	while ((uri.s = next_branch(&uri.len, &q))) {
184
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0))) {
185 185
 		cnt++;
186 186
 		*len += uri.len;
187 187
 		if (q != Q_UNSPECIFIED) {
... ...
@@ -222,7 +241,7 @@ char* print_dset(struct sip_msg* msg, int* len)
222 222
 	}
223 223
 
224 224
 	init_branch_iterator();
225
-	while ((uri.s = next_branch(&uri.len, &q))) {
225
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0))) {
226 226
 		if (i) {
227 227
 			memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN);
228 228
 			p += CONTACT_DELIM_LEN;
... ...
@@ -35,7 +35,7 @@ struct sip_msg;
35 35
 /* 
36 36
  * Add a new branch to current transaction 
37 37
  */
38
-int append_branch(struct sip_msg* msg, char* uri, int uri_len, qvalue_t q);
38
+int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, int dst_uri_len, qvalue_t q);
39 39
 
40 40
 
41 41
 /* 
... ...
@@ -47,7 +47,7 @@ void init_branch_iterator(void);
47 47
 /*
48 48
  * Get the next branch in the current transaction
49 49
  */
50
-char* next_branch(int* len, qvalue_t* q);
50
+char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len);
51 51
 
52 52
 
53 53
 /*
... ...
@@ -407,6 +407,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
407 407
 	struct cell *t_invite;
408 408
 	int success_branch;
409 409
 	int try_new;
410
+	str dst_uri;
410 411
 
411 412
 	/* make -Wall happy */
412 413
 	current_uri.s=0;
... ...
@@ -444,10 +445,10 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
444 444
 	} else try_new=0;
445 445
 
446 446
 	init_branch_iterator();
447
-	while((current_uri.s=next_branch( &current_uri.len, &q))) {
447
+	while((current_uri.s=next_branch( &current_uri.len, &q, &dst_uri.s, &dst_uri.len))) {
448 448
 		try_new++;
449 449
 		branch_ret=add_uac( t, p_msg, &current_uri, 
450
-				    (p_msg->dst_uri.len) ? (&p_msg->dst_uri) : &current_uri, 
450
+				    (dst_uri.len) ? (&dst_uri) : &current_uri, 
451 451
 				    proxy, proto);
452 452
 		/* pick some of the errors in case things go wrong;
453 453
 		   note that picking lowest error is just as good as