Browse Source

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.
Jan Janak 16 years ago
parent
commit
7c7704130a
2 changed files with 57 additions and 0 deletions
  1. 37 0
      flags.c
  2. 20 0
      flags.h

+ 37 - 0
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
 

+ 20 - 0
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);