[SR-Dev] git:master: Kamailio compatibility: script flags

Jan Janak jan at iptel.org
Sun Mar 15 23:43:54 CET 2009


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

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Sun Mar 15 20:45:53 2009 +0100

Kamailio compatibility: script flags

This patch adds support for script flags identical to those present in
the kamailio core. Script flags is a global set of flags which preserve
their value for the duration of script processing. Script flags are kept
in a global variable in the sip-router core.

There are several functions that can be used to manipulate the value
of script flags:
 * setflagsval - This function sets the value of _all_ script flags
   at once. The new value of all the flags must be combined in the
   single function parameter.

 * setsflag - This function sets one particular script flag to 1. The
   function gets the index of the flag (counting from 0) as a
   parameter.

 * resetsflag - This function sets one particular script flag to 0. The
   function gets the index of the flag (counting from 0) as a parameter.

 * issflagset - Test the value of a script flag. Returns 1 if the flag
   is set and -1 otherwise.

 * getsflags - Returns the value of all script flags combined into a
   single variable of type flag_t. This function can be used to make a
   backup copy of script flags.

---

 flags.c |   37 +++++++++++++++++++++++++++++++++++++
 flags.h |   20 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/flags.c b/flags.c
index e9f559e..70c3333 100644
--- a/flags.c
+++ b/flags.c
@@ -43,6 +43,10 @@
 #include "clist.h"
 #include "mem/mem.h"
 
+/* Script flags */
+static flag_t sflags = 0;
+
+
 int setflag( struct sip_msg* msg, flag_t flag ) {
 	msg->flags |= 1 << flag;
 	return 1;
@@ -72,6 +76,39 @@ int flag_in_range( flag_t flag ) {
 }
 
 
+int setsflagsval(flag_t val)
+{
+	sflags = val;
+	return 1;
+}
+
+
+int setsflag(flag_t flag)
+{
+	sflags |= 1 << flag;
+	return 1;
+}
+
+
+int resetsflag(flag_t flag)
+{
+	sflags &= ~ (1 << flag);
+	return 1;
+}
+
+
+int issflagset(flag_t flag)
+{
+	return (sflags & (1<<flag)) ? 1 : -1;
+}
+
+
+flag_t getsflags(void)
+{
+	return sflags;
+}
+
+
 /* use 2^k */
 #define FLAGS_NAME_HASH_ENTRIES		32
 
diff --git a/flags.h b/flags.h
index 62b3235..30809fe 100644
--- a/flags.h
+++ b/flags.h
@@ -43,6 +43,26 @@ int setflag( struct sip_msg* msg, flag_t flag );
 int resetflag( struct sip_msg* msg, flag_t flag );
 int isflagset( struct sip_msg* msg, flag_t flag );
 
+
+/* Script flag functions. Script flags are global flags that keep their
+ * value regardless of the SIP message being processed.
+ */
+
+/* Set the value of all the global flags */
+int setsflagsval(flag_t val);
+
+/* Set the given flag to 1. Parameter flag contains the index of the flag */
+int setsflag(flag_t flag);
+
+/* Reset the given flag to 0. Parameter flag contains the index of the flag */
+int resetsflag(flag_t flag);
+
+/* Returns 1 if the given flag is set and -1 otherwise */
+int issflagset(flag_t flag);
+
+/* Get the value of all the script flags combined */
+flag_t getsflags(void);
+
 int flag_in_range( flag_t flag );
 
 int register_flag(char* name, int pos);




More information about the sr-dev mailing list