Browse code

core: Update get_branch() to return instance from appended branches

- get_branch() and next_branch() updated
- modified select_core.c to use new function definition

Hugh Waite authored on 27/03/2013 11:44:08
Showing 3 changed files
... ...
@@ -216,7 +216,7 @@ void set_branch_iterator(int n)
216 216
 char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
217 217
 		 str* path, unsigned int *flags,
218 218
 		 struct socket_info** force_socket,
219
-		 str *ruid)
219
+		 str *ruid, str *instance)
220 220
 {
221 221
 	if (i < nr_branches) {
222 222
 		*len = branches[i].len;
... ...
@@ -237,6 +237,10 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
237 237
 			ruid->len = branches[i].ruid_len;
238 238
 			ruid->s = (ruid->len)?branches[i].ruid:0;
239 239
 		}
240
+		if (instance) {
241
+			instance->len = branches[i].instance_len;
242
+			instance->s = (instance->len)?branches[i].instance:0;
243
+		}
240 244
 		return branches[i].uri;
241 245
 	} else {
242 246
 		*len = 0;
... ...
@@ -257,6 +261,10 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
257 257
 			ruid->s = 0;
258 258
 			ruid->len = 0;
259 259
 		}
260
+		if (instance) {
261
+			instance->s = 0;
262
+			instance->len = 0;
263
+		}
260 264
 		return 0;
261 265
 	}
262 266
 }
... ...
@@ -268,12 +276,12 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
268 268
  */
269 269
 char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
270 270
 		  unsigned int* flags, struct socket_info** force_socket,
271
-		  str* ruid)
271
+		  str* ruid, str *instance)
272 272
 {
273 273
 	char* ret;
274 274
 	
275 275
 	ret=get_branch(branch_iterator, len, q, dst_uri, path, flags,
276
-		       force_socket, ruid);
276
+		       force_socket, ruid, instance);
277 277
 	if (likely(ret))
278 278
 		branch_iterator++;
279 279
 	return ret;
... ...
@@ -442,7 +450,7 @@ char* print_dset(struct sip_msg* msg, int* len)
442 442
 	crt_branch = get_branch_iterator();
443 443
 
444 444
 	init_branch_iterator();
445
-	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0))) {
445
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0))) {
446 446
 		cnt++;
447 447
 		*len += uri.len;
448 448
 		if (q != Q_UNSPECIFIED) {
... ...
@@ -483,7 +491,7 @@ char* print_dset(struct sip_msg* msg, int* len)
483 483
 	}
484 484
 
485 485
 	init_branch_iterator();
486
-	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0))) {
486
+	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0))) {
487 487
 		if (i) {
488 488
 			memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN);
489 489
 			p += CONTACT_DELIM_LEN;
... ...
@@ -140,12 +140,12 @@ void set_branch_iterator(int n);
140 140
  */
141 141
 char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
142 142
 		  unsigned int* flags, struct socket_info** force_socket,
143
-		  str *ruid);
143
+		  str *ruid, str *instance);
144 144
 
145 145
 char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri,
146 146
 		  str* path, unsigned int *flags,
147 147
 		  struct socket_info** force_socket,
148
-		  str* ruid);
148
+		  str* ruid, str *instance);
149 149
 
150 150
 /*! \brief
151 151
  * Empty the array of branches
... ...
@@ -1621,7 +1621,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
1621 1621
 		char *c;
1622 1622
 		init_branch_iterator();
1623 1623
 		len = 0;
1624
-		while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0))) {
1624
+		while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0))) {
1625 1625
 
1626 1626
 			if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {
1627 1627
 				l = dst_uri.len;
... ...
@@ -1645,7 +1645,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
1645 1645
 		init_branch_iterator();
1646 1646
 		res->len = 0;
1647 1647
 		n = 0;
1648
-		while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0))) {
1648
+		while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0))) {
1649 1649
 			if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {
1650 1650
 				l = dst_uri.len;
1651 1651
 				c = dst_uri.s;
... ...
@@ -1687,7 +1687,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
1687 1687
 		if (n < 0 || n >= nr_branches) 
1688 1688
 			return -1;
1689 1689
 		init_branch_iterator();
1690
-		for (; (c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0)) && n; n--);
1690
+		for (; (c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0)) && n; n--);
1691 1691
 		if (!c) return 1;
1692 1692
 		
1693 1693
 		if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {