[sr-dev] git:master: core: save and restore branch_iterator in print_dset

Daniel-Constantin Mierla miconda at gmail.com
Thu Nov 24 12:59:17 CET 2011


Module: sip-router
Branch: master
Commit: c5f101dfac9a50f428e3452893c402d8b1e0400b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c5f101dfac9a50f428e3452893c402d8b1e0400b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Nov 24 12:56:28 2011 +0100

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

---

 dset.c |   21 ++++++++++++++++++++-
 dset.h |    8 ++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/dset.c b/dset.c
index f8bb337..4ba5ccf 100644
--- a/dset.c
+++ b/dset.c
@@ -191,11 +191,21 @@ void init_branch_iterator(void)
 	branch_iterator = 0;
 }
 
+/**
+ * return the value of current branch iterator
+ */
 int get_branch_iterator(void)
 {
 	return branch_iterator;
 }
 
+/**
+ * set the value of current branch interator
+ */
+void set_branch_iterator(int n)
+{
+	branch_iterator = n;
+}
 
 
 /** \brief Get a branch from the destination set
@@ -366,6 +376,7 @@ char* print_dset(struct sip_msg* msg, int* len)
 	qvalue_t q;
 	str uri;
 	char* p, *qbuf;
+	int crt_branch;
 	static char dset[MAX_REDIRECTION_LEN];
 
 	if (msg->new_uri.s) {
@@ -379,6 +390,9 @@ char* print_dset(struct sip_msg* msg, int* len)
 		*len = 0;
 	}
 
+	/* backup current branch index to restore it later */
+	crt_branch = get_branch_iterator();
+
 	init_branch_iterator();
 	while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0))) {
 		cnt++;
@@ -394,7 +408,7 @@ char* print_dset(struct sip_msg* msg, int* len)
 
 	if (*len + 1 > MAX_REDIRECTION_LEN) {
 		LOG(L_ERR, "ERROR: redirection buffer length exceed\n");
-		return 0;
+		goto error;
 	}
 
 	memcpy(dset, CONTACT, CONTACT_LEN);
@@ -445,7 +459,12 @@ char* print_dset(struct sip_msg* msg, int* len)
 	}
 
 	memcpy(p, CRLF " ", CRLF_LEN + 1);
+	set_branch_iterator(crt_branch);
 	return dset;
+
+error:
+	set_branch_iterator(crt_branch);
+	return 0;
 }
 
 
diff --git a/dset.h b/dset.h
index 6f9f067..dfc3083 100644
--- a/dset.h
+++ b/dset.h
@@ -107,15 +107,19 @@ static inline int ser_append_branch(struct sip_msg* msg,
 
 
 /*! \brief
- * Iterate through the list of transaction branches 
+ * Init the index to iterate through the list of transaction branches
  */
 void init_branch_iterator(void);
 
 /*! \brief
- * Return branch iterator position 
+ * Return branch iterator position
  */
 int get_branch_iterator(void);
 
+/*! \brief
+ * Set branch iterator position
+ */
+void set_branch_iterator(int n);
 
 /*! \brief Get the next branch in the current transaction.
  * @return pointer to the uri of the next branch (which the length written in




More information about the sr-dev mailing list