Browse code

New global variable route_type with the type of route being executed

This patch adds a new global variable called route_type. This value of
the variable is one of the *_ROUTE values defined in route.h. Those
defines have been moved from sr_module.h, originally they were used
as the flags for functions in module exports but we can use them here
for the global route_type variable as well.

The variable route_type is meant to be used by module functions, in
some cases they need to test for the type of the route being executed
to know what functions are available and whether the sip message being
process is stored in shared memory or private memory.

The tm module contained similar variable (which was exported through
the tm module API), but it makes more sense to keep it in sip-router
core, because the core can execute two route types, the request route
and the onreply route, even if the tm module is not used.

Jan Janak authored on 07/03/2009 00:42:04
Showing 2 changed files
... ...
@@ -42,6 +42,29 @@
42 42
 
43 43
 /*#include "cfg_parser.h" */
44 44
 
45
+/* Various types of route sections, make sure that the values defined in the
46
+ * macros below occupy disjunct bits so that they can also be used as flags
47
+ */
48
+#define REQUEST_ROUTE (1 << 0)
49
+#define FAILURE_ROUTE (1 << 1)
50
+#define ONREPLY_ROUTE (1 << 2)
51
+#define BRANCH_ROUTE  (1 << 3)
52
+#define ONSEND_ROUTE  (1 << 4)
53
+#define ERROR_ROUTE   (1 << 5)
54
+#define LOCAL_ROUTE   (1 << 6)
55
+
56
+/* The value of this variable is one of the route types defined above and it
57
+ * determines the type of the route being executed, module functions can use
58
+ * this value to determine the type of the route they are being executed in
59
+ */
60
+extern int route_type;
61
+
62
+#define set_route_type(type) \
63
+	do {					 \
64
+		route_type = (type); \
65
+	} while(0)
66
+
67
+#define is_route_type(type) (route_type == (type))
45 68
 
46 69
 struct route_list{
47 70
 	struct action** rlist;
... ...
@@ -62,6 +62,7 @@
62 62
 #include "version.h"
63 63
 #include "rpc.h"
64 64
 #include "route_struct.h"
65
+#include "route.h"
65 66
 #include "str.h"
66 67
 
67 68
 /* kamailio compat */
... ...
@@ -146,15 +147,6 @@ typedef int (*param_func_t)( modparam_t type, void* val);
146 146
 #define VAR_PARAM_NO  -128  /* function has variable number of parameters
147 147
 							   (see cmd_function_var for the prototype) */
148 148
 
149
-/* functions flags */
150
-#define REQUEST_ROUTE 1  /* Function can be used in request route blocks */
151
-#define FAILURE_ROUTE 2  /* Function can be used in reply route blocks */
152
-#define ONREPLY_ROUTE 4  /* Function can be used in on_reply */
153
-#define BRANCH_ROUTE  8  /* Function can be used in branch_route blocks */
154
-#define ONSEND_ROUTE 16  /* Function can be used in onsend_route blocks */
155
-#define ERROR_ROUTE  32  /* Function can be used in an error route */ 
156
-#define LOCAL_ROUTE  64  /* Function can be used in a local route */
157
-
158 149
 /* Macros - used as rank in child_init function */
159 150
 #define PROC_MAIN      0  /* Main ser process */
160 151
 #define PROC_TIMER    -1  /* Timer attendant process */