[SR-Dev] git:master: New global variable route_type with the type of route being executed

Jan Janak jan at iptel.org
Sat Mar 7 01:51:45 CET 2009


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

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Sat Mar  7 01:42:04 2009 +0100

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.

---

 route.h     |   23 +++++++++++++++++++++++
 sr_module.h |   10 +---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/route.h b/route.h
index 732d4a9..221fb4c 100644
--- a/route.h
+++ b/route.h
@@ -42,6 +42,29 @@
 
 /*#include "cfg_parser.h" */
 
+/* Various types of route sections, make sure that the values defined in the
+ * macros below occupy disjunct bits so that they can also be used as flags
+ */
+#define REQUEST_ROUTE (1 << 0)
+#define FAILURE_ROUTE (1 << 1)
+#define ONREPLY_ROUTE (1 << 2)
+#define BRANCH_ROUTE  (1 << 3)
+#define ONSEND_ROUTE  (1 << 4)
+#define ERROR_ROUTE   (1 << 5)
+#define LOCAL_ROUTE   (1 << 6)
+
+/* The value of this variable is one of the route types defined above and it
+ * determines the type of the route being executed, module functions can use
+ * this value to determine the type of the route they are being executed in
+ */
+extern int route_type;
+
+#define set_route_type(type) \
+	do {					 \
+		route_type = (type); \
+	} while(0)
+
+#define is_route_type(type) (route_type == (type))
 
 struct route_list{
 	struct action** rlist;
diff --git a/sr_module.h b/sr_module.h
index 149ca6e..0078f25 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -62,6 +62,7 @@
 #include "version.h"
 #include "rpc.h"
 #include "route_struct.h"
+#include "route.h"
 #include "str.h"
 
 /* kamailio compat */
@@ -146,15 +147,6 @@ typedef int (*param_func_t)( modparam_t type, void* val);
 #define VAR_PARAM_NO  -128  /* function has variable number of parameters
 							   (see cmd_function_var for the prototype) */
 
-/* functions flags */
-#define REQUEST_ROUTE 1  /* Function can be used in request route blocks */
-#define FAILURE_ROUTE 2  /* Function can be used in reply route blocks */
-#define ONREPLY_ROUTE 4  /* Function can be used in on_reply */
-#define BRANCH_ROUTE  8  /* Function can be used in branch_route blocks */
-#define ONSEND_ROUTE 16  /* Function can be used in onsend_route blocks */
-#define ERROR_ROUTE  32  /* Function can be used in an error route */ 
-#define LOCAL_ROUTE  64  /* Function can be used in a local route */
-
 /* Macros - used as rank in child_init function */
 #define PROC_MAIN      0  /* Main ser process */
 #define PROC_TIMER    -1  /* Timer attendant process */




More information about the sr-dev mailing list