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 92
  * array, 0 is returned if there are no
88 93
  * more branches
89 94
  */
90
-char* next_branch(int* len, qvalue_t* q)
95
+char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len)
91 96
 {
92 97
 	unsigned int i;
93 98
 
... ...
@@ -96,10 +101,18 @@ char* next_branch(int* len, qvalue_t* q)
96 101
 		branch_iterator++;
97 102
 		*len = branches[i].len;
98 103
 		*q = branches[i].q;
104
+		if (dst_uri && dst_len) {
105
+			*dst_uri = branches[i].dst_uri;
106
+			*dst_len = branches[i].dst_uri_len;
107
+		}
99 108
 		return branches[i].uri;
100 109
 	} else {
101 110
 		*len = 0;
102 111
 		*q = Q_UNSPECIFIED;
112
+		if (dst_uri && dst_len) {
113
+			*dst_uri = 0;
114
+			*dst_len = 0;
115
+		}
103 116
 		return 0;
104 117
 	}
105 118
 }
... ...
@@ -118,7 +131,7 @@ void clear_branches(void)
118 131
 /* 
119 132
  * Add a new branch to current transaction 
120 133
  */
121
-int append_branch(struct sip_msg* msg, char* uri, int uri_len, qvalue_t q)
134
+int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, int dst_uri_len, qvalue_t q)
122 135
 {
123 136
 	     /* if we have already set up the maximum number
124 137
 	      * 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 165
 	branches[nr_branches].len = uri_len;
153 166
 	branches[nr_branches].q = q;
154 167
 	
168
+	if (dst_uri) {
169
+		memcpy(branches[nr_branches].dst_uri, dst_uri, dst_uri_len);
170
+		branches[nr_branches].dst_uri[dst_uri_len] = 0;
171
+		branches[nr_branches].dst_uri_len = dst_uri_len;
172
+	}
173
+
155 174
 	nr_branches++;
156 175
 	return 1;
157 176
 }
... ...
@@ -181,7 +200,7 @@ char* print_dset(struct sip_msg* msg, int* len)
181 200
 	}
182 201
 
183 202
 	init_branch_iterator();
184
-	while ((uri.s = next_branch(&uri.len, &q))) {
203
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0))) {
185 204
 		cnt++;
186 205
 		*len += uri.len;
187 206
 		if (q != Q_UNSPECIFIED) {
... ...
@@ -222,7 +241,7 @@ char* print_dset(struct sip_msg* msg, int* len)
222 241
 	}
223 242
 
224 243
 	init_branch_iterator();
225
-	while ((uri.s = next_branch(&uri.len, &q))) {
244
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0))) {
226 245
 		if (i) {
227 246
 			memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN);
228 247
 			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 445
 	} else try_new=0;
445 446
 
446 447
 	init_branch_iterator();
447
-	while((current_uri.s=next_branch( &current_uri.len, &q))) {
448
+	while((current_uri.s=next_branch( &current_uri.len, &q, &dst_uri.s, &dst_uri.len))) {
448 449
 		try_new++;
449 450
 		branch_ret=add_uac( t, p_msg, &current_uri, 
450
-				    (p_msg->dst_uri.len) ? (&p_msg->dst_uri) : &current_uri, 
451
+				    (dst_uri.len) ? (&dst_uri) : &current_uri, 
451 452
 				    proxy, proto);
452 453
 		/* pick some of the errors in case things go wrong;
453 454
 		   note that picking lowest error is just as good as