core: distinct core and tm onreply route tests
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Mon, 22 Feb 2010 13:49:37 +0000 (14:49 +0100)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Mon, 22 Feb 2010 15:46:05 +0000 (16:46 +0100)
- added TM_ONREPLY_ROUTE and CORE_ONREPLY_ROUTE to the possible
route types. This allows to distinguish between the main reply
route (executed by the core) and onreply routes executed by tm.
ONREPLY_ROUTE was changed to TM_ONREPLY_ROUTE|CORE_ONREPLY_ROUTE,
so that is_route_type(ONREPLY_ROUTE) will return true both for
 CORE_ONREPLY_ROUTE and TM_ONREPLY_ROUTE.

- onreply_route[0] {} is equivalent with onreply_route{}.

- use different route types when parsing the script for
 onreply_route{} (CORE_ONREPLY_ROUTE) and onreply_route[x]{},
  where x!=0 (TM_ONREPLY_ROUTE).

cfg.y
receive.c
route.h

diff --git a/cfg.y b/cfg.y
index 763879a..453e6a1 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -647,7 +647,7 @@ statement:
        | module_stm
        | {rt=REQUEST_ROUTE;} route_stm
        | {rt=FAILURE_ROUTE;} failure_route_stm
-       | {rt=ONREPLY_ROUTE;} onreply_route_stm
+       | onreply_route_stm
        | {rt=BRANCH_ROUTE;} branch_route_stm
        | {rt=ONSEND_ROUTE;}   send_route_stm
        | {rt=EVENT_ROUTE;}   event_route_stm
@@ -1775,35 +1775,46 @@ failure_route_stm:
        }
        | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
        ;
+
 onreply_route_stm:
-       ROUTE_ONREPLY LBRACE actions RBRACE {
+       ROUTE_ONREPLY LBRACE {rt=CORE_ONREPLY_ROUTE;} actions RBRACE {
        #ifdef SHM_MEM
                if (!shm_initialized() && init_shm()<0) {
                        yyerror("Can't initialize shared memory");
                        YYABORT;
                }
        #endif /* SHM_MEM */
-               push($3, &onreply_rt.rlist[DEFAULT_RT]);
+               push($4, &onreply_rt.rlist[DEFAULT_RT]);
        }
-       | ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
+       | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
+       | ROUTE_ONREPLY LBRACK route_name RBRACK 
+               {rt=(*$3=='0' && $3[1]==0)?CORE_ONREPLY_ROUTE:TM_ONREPLY_ROUTE;}
+               LBRACE actions RBRACE {
        #ifdef SHM_MEM
                if (!shm_initialized() && init_shm()<0) {
                        yyerror("Can't initialize shared memory");
                        YYABORT;
                }
        #endif /* SHM_MEM */
-               i_tmp=route_get(&onreply_rt, $3);
-               if (i_tmp==-1){
-                       yyerror("internal error");
-                       YYABORT;
-               }
-               if (onreply_rt.rlist[i_tmp]){
-                       yyerror("duplicate route");
-                       YYABORT;
+               if (*$3=='0' && $3[1]==0){
+                       /* onreply_route[0] {} is equivalent with onreply_route {}*/
+                       push($7, &onreply_rt.rlist[DEFAULT_RT]);
+               }else{
+                       i_tmp=route_get(&onreply_rt, $3);
+                       if (i_tmp==-1){
+                               yyerror("internal error");
+                               YYABORT;
+                       }
+                       if (onreply_rt.rlist[i_tmp]){
+                               yyerror("duplicate route");
+                               YYABORT;
+                       }
+                       push($7, &onreply_rt.rlist[i_tmp]);
                }
-               push($6, &onreply_rt.rlist[i_tmp]);
        }
-       | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
+       | ROUTE_ONREPLY LBRACK route_name RBRACK error {
+               yyerror("invalid onreply_route statement");
+       }
        ;
 branch_route_stm:
        ROUTE_BRANCH LBRACE actions RBRACE {
index a045e3a..df26196 100644 (file)
--- a/receive.c
+++ b/receive.c
@@ -247,7 +247,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 
                /* exec the onreply routing script */
                if (onreply_rt.rlist[DEFAULT_RT]){
-                       set_route_type(ONREPLY_ROUTE);
+                       set_route_type(CORE_ONREPLY_ROUTE);
                        ret=run_top_route(onreply_rt.rlist[DEFAULT_RT], msg, &ctx);
 #ifndef NO_ONREPLY_ROUTE_ERROR
                        if (unlikely(ret<0)){
diff --git a/route.h b/route.h
index e346ebd..5e3e04d 100644 (file)
--- a/route.h
+++ b/route.h
  */
 #define REQUEST_ROUTE (1 << 0)
 #define FAILURE_ROUTE (1 << 1)
-#define ONREPLY_ROUTE (1 << 2)
+#define TM_ONREPLY_ROUTE (1 << 2)
 #define BRANCH_ROUTE  (1 << 3)
 #define ONSEND_ROUTE  (1 << 4)
 #define ERROR_ROUTE   (1 << 5)
 #define LOCAL_ROUTE   (1 << 6)
+#define CORE_ONREPLY_ROUTE (1 << 7)
+#define ONREPLY_ROUTE (TM_ONREPLY_ROUTE|CORE_ONREPLY_ROUTE)
 #define EVENT_ROUTE   REQUEST_ROUTE
 #define ANY_ROUTE     (0xFFFFFFFF)
 
@@ -68,7 +70,7 @@ extern int route_type;
 
 #define get_route_type()       route_type
 
-#define is_route_type(type) (route_type == (type))
+#define is_route_type(type) (route_type & (type))
 
 struct route_list{
        struct action** rlist;