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 366
 	qvalue_t q;
367 367
 	str uri;
368 368
 	char* p, *qbuf;
369
+	int crt_branch;
369 370
 	static char dset[MAX_REDIRECTION_LEN];
370 371
 
371 372
 	if (msg->new_uri.s) {
... ...
@@ -379,6 +390,9 @@ char* print_dset(struct sip_msg* msg, int* len)
379 379
 		*len = 0;
380 380
 	}
381 381
 
382
+	/* backup current branch index to restore it later */
383
+	crt_branch = get_branch_iterator();
384
+
382 385
 	init_branch_iterator();
383 386
 	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0))) {
384 387
 		cnt++;
... ...
@@ -394,7 +408,7 @@ char* print_dset(struct sip_msg* msg, int* len)
394 394
 
395 395
 	if (*len + 1 > MAX_REDIRECTION_LEN) {
396 396
 		LOG(L_ERR, "ERROR: redirection buffer length exceed\n");
397
-		return 0;
397
+		goto error;
398 398
 	}
399 399
 
400 400
 	memcpy(dset, CONTACT, CONTACT_LEN);
... ...
@@ -445,7 +459,12 @@ char* print_dset(struct sip_msg* msg, int* len)
445 445
 	}
446 446
 
447 447
 	memcpy(p, CRLF " ", CRLF_LEN + 1);
448
+	set_branch_iterator(crt_branch);
448 449
 	return dset;
450
+
451
+error:
452
+	set_branch_iterator(crt_branch);
453
+	return 0;
449 454
 }
450 455
 
451 456
 
... ...
@@ -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