Browse code

core: save and restore branch_iterator in print_dset

- safe usage in branch_route where branch_interator is used to add the
new brnaches, but some variables can change it if used in config
branch_route
- closes FS#182, reported by Pawel Sternal

Daniel-Constantin Mierla authored on 24/11/2011 11:56:28
Showing 2 changed files
... ...
@@ -191,11 +191,21 @@ void init_branch_iterator(void)
191 191
 	branch_iterator = 0;
192 192
 }
193 193
 
194
+/**
195
+ * return the value of current branch iterator
196
+ */
194 197
 int get_branch_iterator(void)
195 198
 {
196 199
 	return branch_iterator;
197 200
 }
198 201
 
202
+/**
203
+ * set the value of current branch interator
204
+ */
205
+void set_branch_iterator(int n)
206
+{
207
+	branch_iterator = n;
208
+}
199 209
 
200 210
 
201 211
 /** \brief Get a branch from the destination set
... ...
@@ -366,6 +376,7 @@ char* print_dset(struct sip_msg* msg, int* len)
366 376
 	qvalue_t q;
367 377
 	str uri;
368 378
 	char* p, *qbuf;
379
+	int crt_branch;
369 380
 	static char dset[MAX_REDIRECTION_LEN];
370 381
 
371 382
 	if (msg->new_uri.s) {
... ...
@@ -379,6 +390,9 @@ char* print_dset(struct sip_msg* msg, int* len)
379 390
 		*len = 0;
380 391
 	}
381 392
 
393
+	/* backup current branch index to restore it later */
394
+	crt_branch = get_branch_iterator();
395
+
382 396
 	init_branch_iterator();
383 397
 	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0))) {
384 398
 		cnt++;
... ...
@@ -394,7 +408,7 @@ char* print_dset(struct sip_msg* msg, int* len)
394 408
 
395 409
 	if (*len + 1 > MAX_REDIRECTION_LEN) {
396 410
 		LOG(L_ERR, "ERROR: redirection buffer length exceed\n");
397
-		return 0;
411
+		goto error;
398 412
 	}
399 413
 
400 414
 	memcpy(dset, CONTACT, CONTACT_LEN);
... ...
@@ -445,7 +459,12 @@ char* print_dset(struct sip_msg* msg, int* len)
445 459
 	}
446 460
 
447 461
 	memcpy(p, CRLF " ", CRLF_LEN + 1);
462
+	set_branch_iterator(crt_branch);
448 463
 	return dset;
464
+
465
+error:
466
+	set_branch_iterator(crt_branch);
467
+	return 0;
449 468
 }
450 469
 
451 470
 
... ...
@@ -107,15 +107,19 @@ static inline int ser_append_branch(struct sip_msg* msg,
107 107
 
108 108
 
109 109
 /*! \brief
110
- * Iterate through the list of transaction branches 
110
+ * Init the index to iterate through the list of transaction branches
111 111
  */
112 112
 void init_branch_iterator(void);
113 113
 
114 114
 /*! \brief
115
- * Return branch iterator position 
115
+ * Return branch iterator position
116 116
  */
117 117
 int get_branch_iterator(void);
118 118
 
119
+/*! \brief
120
+ * Set branch iterator position
121
+ */
122
+void set_branch_iterator(int n);
119 123
 
120 124
 /*! \brief Get the next branch in the current transaction.
121 125
  * @return pointer to the uri of the next branch (which the length written in