Module: sip-router
Branch: master
Commit: 0202608d607019077e69f432343c767f96db9372
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0202608…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sat Mar 14 19:23:07 2009 +0100
Functions to set/reset/test per-branch flags.
This patch adds support for setbflag,resetbflag, and isbflagset
functions, these functions can be used to manipulate branch flags and
they are inspired by similar functions in kamailio.
There is a small difference compared to their counterparts in kamailio
though. The second parameter of all these functions is of type flag_t
and it is the index (counting from 0) of the flag to be manipulated.
This is better aligned with how normal flags (flags.[ch]) in sip-router
work. Similar functions in kamailio took the mask as the second
parameter with values of flags to be manipulated.
This also prevents users from modifying multiple flags at the same time
accidental (note that it is not obvious from the function name that
the function could do it).
---
dset.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
dset.h | 30 ++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/dset.c b/dset.c
index e4e995a..a3a6fff 100644
--- a/dset.c
+++ b/dset.c
@@ -66,7 +66,7 @@ struct branch
struct socket_info* force_send_socket;
/* Branch flags */
- unsigned int flags;
+ flag_t flags;
};
@@ -83,7 +83,47 @@ unsigned int nr_branches = 0;
static int branch_iterator = 0;
/* The q parameter of the Request-URI */
-static qvalue_t ruri_q = Q_UNSPECIFIED;
+static qvalue_t ruri_q = Q_UNSPECIFIED;
+
+/* Branch flags of the Request-URI */
+static flag_t ruri_bflags;
+
+
+static inline flag_t* get_bflags_ptr(unsigned int branch)
+{
+ if (branch == 0) return &ruri_bflags;
+ if (branch - 1 < nr_branches) return &branches[branch - 1].flags;
+ return NULL;
+}
+
+
+int setbflag(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ (*flags) |= 1 << flag;
+ return 1;
+}
+
+
+int isbflagset(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ return ((*flags) & (1 << flag)) ? 1 : -1;
+}
+
+
+int resetbflag(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ (*flags) &= ~ (1 << flag);
+ return 1;
+}
/*
diff --git a/dset.h b/dset.h
index c23d4ce..a4b4f7c 100644
--- a/dset.h
+++ b/dset.h
@@ -30,6 +30,7 @@
#include "ip_addr.h"
#include "qvalue.h"
+#include "flags.h"
struct sip_msg;
@@ -82,5 +83,34 @@ qvalue_t get_ruri_q(void);
int get_request_uri(struct sip_msg* _m, str* _u);
int rewrite_uri(struct sip_msg* _m, str* _s);
+/**
+ * Set a per-branch flag to 1.
+ *
+ * This function sets the value of one particular branch flag to 1.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be set (starting with 0)
+ * @return 1 on success, -1 on failure.
+ */
+int setbflag(unsigned int branch, flag_t flag);
+
+/**
+ * Reset a per-branch flag value to 0.
+ *
+ * This function resets the value of one particular branch flag to 0.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be reset (starting with 0)
+ * @return 1 on success, -1 on failure.
+ */
+int resetbflag(unsigned int branch, flag_t flag);
+
+/**
+ * Determine if a branch flag is set.
+ *
+ * This function tests the value of one particular per-branch flag.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be tested (starting with 0)
+ * @return 1 if the branch flag is set, -1 if not or on failure.
+ */
+int isbflagset(unsigned int branch, flag_t flag);
#endif /* _DSET_H */