Module: sip-router
Branch: master
Commit: 15627cd0cb424d76eb266e66e51fe90a4ddefb71
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=15627cd…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Apr 21 12:53:03 2010 +0200
dset: exposed branch structure
- added helper functions to allow branch attributes updates via PVs
- related to FS#8
---
dset.c | 69 ++++++++++++++++++++++++++++++++++++++++++++-------------------
dset.h | 36 +++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 21 deletions(-)
diff --git a/dset.c b/dset.c
index e3dc844..8223615 100644
--- a/dset.c
+++ b/dset.c
@@ -55,27 +55,6 @@
#define Q_PARAM ">;q="
#define Q_PARAM_LEN (sizeof(Q_PARAM) - 1)
-struct branch
-{
- char uri[MAX_URI_SIZE];
- unsigned int len;
-
- /* Real destination of the request */
- char dst_uri[MAX_URI_SIZE];
- unsigned int dst_uri_len;
-
- /* Path set */
- char path[MAX_PATH_SIZE];
- unsigned int path_len;
-
- int q; /* Preference of the contact among
- * contact within the array */
- struct socket_info* force_send_socket;
-
- /* Branch flags */
- flag_t flags;
-};
-
/*
* Where we store URIs of additional transaction branches
@@ -96,6 +75,54 @@ static qvalue_t ruri_q = Q_UNSPECIFIED;
static flag_t ruri_bflags;
+/*! \brief
+ * Return pointer to branch[idx] structure
+ * @param idx - branch index
+ *
+ * @return pointer to branch or NULL if invalid branch
+ */
+branch_t *get_sip_branch(int idx)
+{
+ if(nr_branches==0)
+ return NULL;
+ if(idx<0)
+ {
+ if(nr_branches + idx >= 0)
+ return &branches[nr_branches+idx];
+ return NULL;
+ }
+ if(idx < nr_branches)
+ return &branches[idx];
+ return 0;
+}
+
+/*! \brief
+ * Drop branch[idx]
+ * @param idx - branch index
+ *
+ * @return 0 on success, -1 on error
+ */
+int drop_sip_branch(int idx)
+{
+ if(nr_branches==0 || idx>=nr_branches)
+ return 0;
+ if(idx<0 && nr_branches+idx<0)
+ return 0;
+ /* last branch */
+ if(idx==nr_branches-1)
+ {
+ nr_branches--;
+ return 0;
+ }
+ if(idx<0)
+ idx = nr_branches+idx;
+ /* shift back one position */
+ for(; idx<nr_branches-1; idx++)
+ memcpy(&branches[idx], &branches[idx+1], sizeof(branch_t));
+ nr_branches--;
+ return 0;
+}
+
static inline flag_t* get_bflags_ptr(unsigned int branch)
{
if (branch == 0) return &ruri_bflags;
diff --git a/dset.h b/dset.h
index 0293c03..ca91211 100644
--- a/dset.h
+++ b/dset.h
@@ -39,6 +39,42 @@
extern unsigned int nr_branches;
/*! \brief
+ * Structure for storing branch attributes
+ */
+struct branch
+{
+ char uri[MAX_URI_SIZE];
+ unsigned int len;
+
+ /* Real destination of the request */
+ char dst_uri[MAX_URI_SIZE];
+ unsigned int dst_uri_len;
+
+ /* Path set */
+ char path[MAX_PATH_SIZE];
+ unsigned int path_len;
+
+ int q; /* Preference of the contact among
+ * contact within the array */
+ struct socket_info* force_send_socket;
+
+ /* Branch flags */
+ flag_t flags;
+};
+
+typedef struct branch branch_t;
+
+/*! \brief
+ * Return pointer to branch[idx] structure
+ */
+branch_t *get_sip_branch(int idx);
+
+/*! \brief
+ * Drop branch[idx]
+ */
+int drop_sip_branch(int idx);
+
+/*! \brief
* Add a new branch to current transaction
*/
int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,