[SR-Dev] git:master: Kamailio compatibility: dset manipulation functions

Jan Janak jan at iptel.org
Mon Mar 16 02:26:45 CET 2009


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

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Mon Mar 16 00:48:06 2009 +0100

Kamailio compatibility: dset manipulation functions

This patch adds two extra kamailio compatibility functions:
 * get_branch which allows the caller to obtain the parameters of a
   branch using its index
 * km_append_branch which is similar to append_branch in sip-router
   except that the parameters of the function are slightly different.

---

 dset.c |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dset.h |    8 ++++
 2 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/dset.c b/dset.c
index a3a6fff..8c0a555 100644
--- a/dset.c
+++ b/dset.c
@@ -174,6 +174,46 @@ char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len, struct so
 }
 
 
+/** \brief Get a branch from the destination set
+ * \return Return the 'i' branch from the dset
+ * array, 0 is returned if there are no
+ * more branches
+ */
+char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
+				 str* path, unsigned int *flags, struct socket_info** force_socket)
+{
+	if (i < nr_branches) {
+		*len = branches[i].len;
+		*q = branches[i].q;
+		if (dst_uri) {
+			dst_uri->len = branches[i].dst_uri_len;
+			dst_uri->s = (dst_uri->len)?branches[i].dst_uri:0;
+		}
+		if (path) {
+			path->len = branches[i].path_len;
+			path->s = (path->len)?branches[i].path:0;
+		}
+		if (force_socket)
+			*force_socket = branches[i].force_send_socket;
+		if (flags)
+			*flags = branches[i].flags;
+		return branches[i].uri;
+	} else {
+		*len = 0;
+		*q = Q_UNSPECIFIED;
+		if (dst_uri) {
+			dst_uri->s = 0;
+			dst_uri->len = 0;
+		}
+		if (force_socket)
+			*force_socket = 0;
+		if (flags)
+			*flags = 0;
+		return 0;
+	}
+}
+
+
 /*
  * Empty the dset array
  */
@@ -244,6 +284,87 @@ int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, in
 }
 
 
+/* ! \brief
+ * Add a new branch to current transaction using str parameters
+ * Kamailio compatibility version
+ */
+int km_append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
+		qvalue_t q, unsigned int flags, struct socket_info* force_socket)
+{
+	str luri;
+
+#ifdef USE_LOCAL_ROUTE
+	if (dset_state==0)
+		return -1;
+#endif
+
+	/* if we have already set up the maximum number
+	 * of branches, don't try new ones 
+	 */
+	if (nr_branches == MAX_BRANCHES - 1) {
+		LOG(L_ERR, "max nr of branches exceeded\n");
+		ser_error = E_TOO_MANY_BRANCHES;
+		return -1;
+	}
+
+	/* if not parameterized, take current uri */
+	if (uri==0 || uri->len==0 || uri->s==0) {
+		if (msg->new_uri.s)
+			luri = msg->new_uri;
+		else
+			luri = msg->first_line.u.request.uri;
+	} else {
+		luri = *uri;
+	}
+
+	if (luri.len > MAX_URI_SIZE - 1) {
+		LOG(L_ERR, "too long uri: %.*s\n", luri.len, luri.s);
+		return -1;
+	}
+
+	/* copy the dst_uri */
+	if (dst_uri && dst_uri->len && dst_uri->s) {
+		if (dst_uri->len > MAX_URI_SIZE - 1) {
+			LOG(L_ERR, "too long dst_uri: %.*s\n",
+				dst_uri->len, dst_uri->s);
+			return -1;
+		}
+		memcpy(branches[nr_branches].dst_uri, dst_uri->s, dst_uri->len);
+		branches[nr_branches].dst_uri[dst_uri->len] = 0;
+		branches[nr_branches].dst_uri_len = dst_uri->len;
+	} else {
+		branches[nr_branches].dst_uri[0] = '\0';
+		branches[nr_branches].dst_uri_len = 0;
+	}
+
+	/* copy the path string */
+	if (path && path->len && path->s) {
+		if (path->len > MAX_PATH_SIZE - 1) {
+			LOG(L_ERR, "too long path: %.*s\n", path->len, path->s);
+			return -1;
+		}
+		memcpy(branches[nr_branches].path, path->s, path->len);
+		branches[nr_branches].path[path->len] = 0;
+		branches[nr_branches].path_len = path->len;
+	} else {
+		branches[nr_branches].path[0] = '\0';
+		branches[nr_branches].path_len = 0;
+	}
+
+	/* copy the ruri */
+	memcpy(branches[nr_branches].uri, luri.s, luri.len);
+	branches[nr_branches].uri[luri.len] = 0;
+	branches[nr_branches].len = luri.len;
+	branches[nr_branches].q = q;
+
+	branches[nr_branches].force_send_socket = force_socket;
+	branches[nr_branches].flags = flags;
+
+	nr_branches++;
+	return 1;
+}
+
+
 /*
  * Create a Contact header field from the dset
  * array
diff --git a/dset.h b/dset.h
index a4b4f7c..36ffaff 100644
--- a/dset.h
+++ b/dset.h
@@ -44,6 +44,10 @@ int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, in
 		  qvalue_t q, struct socket_info* force_socket);
 
 
+int km_append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
+					 qvalue_t q, unsigned int flags, struct socket_info* force_socket);
+
+
 /* 
  * Iterate through the list of transaction branches 
  */
@@ -56,6 +60,10 @@ void init_branch_iterator(void);
 char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len, struct socket_info** force_socket);
 
 
+char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri,
+				  str* path, unsigned int *flags, struct socket_info** force_socket);
+
+
 /*
  * Empty the array of branches
  */




More information about the sr-dev mailing list