Browse code

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 authored on 15/03/2009 19:45:53
Showing 2 changed files
... ...
@@ -43,6 +43,10 @@
43 43
 #include "clist.h"
44 44
 #include "mem/mem.h"
45 45
 
46
+/* Script flags */
47
+static flag_t sflags = 0;
48
+
49
+
46 50
 int setflag( struct sip_msg* msg, flag_t flag ) {
47 51
 	msg->flags |= 1 << flag;
48 52
 	return 1;
... ...
@@ -72,6 +76,39 @@ int flag_in_range( flag_t flag ) {
72 72
 }
73 73
 
74 74
 
75
+int setsflagsval(flag_t val)
76
+{
77
+	sflags = val;
78
+	return 1;
79
+}
80
+
81
+
82
+int setsflag(flag_t flag)
83
+{
84
+	sflags |= 1 << flag;
85
+	return 1;
86
+}
87
+
88
+
89
+int resetsflag(flag_t flag)
90
+{
91
+	sflags &= ~ (1 << flag);
92
+	return 1;
93
+}
94
+
95
+
96
+int issflagset(flag_t flag)
97
+{
98
+	return (sflags & (1<<flag)) ? 1 : -1;
99
+}
100
+
101
+
102
+flag_t getsflags(void)
103
+{
104
+	return sflags;
105
+}
106
+
107
+
75 108
 /* use 2^k */
76 109
 #define FLAGS_NAME_HASH_ENTRIES		32
77 110
 
... ...
@@ -43,6 +43,26 @@ int setflag( struct sip_msg* msg, flag_t flag );
43 43
 int resetflag( struct sip_msg* msg, flag_t flag );
44 44
 int isflagset( struct sip_msg* msg, flag_t flag );
45 45
 
46
+
47
+/* Script flag functions. Script flags are global flags that keep their
48
+ * value regardless of the SIP message being processed.
49
+ */
50
+
51
+/* Set the value of all the global flags */
52
+int setsflagsval(flag_t val);
53
+
54
+/* Set the given flag to 1. Parameter flag contains the index of the flag */
55
+int setsflag(flag_t flag);
56
+
57
+/* Reset the given flag to 0. Parameter flag contains the index of the flag */
58
+int resetsflag(flag_t flag);
59
+
60
+/* Returns 1 if the given flag is set and -1 otherwise */
61
+int issflagset(flag_t flag);
62
+
63
+/* Get the value of all the script flags combined */
64
+flag_t getsflags(void);
65
+
46 66
 int flag_in_range( flag_t flag );
47 67
 
48 68
 int register_flag(char* name, int pos);