Browse code

core: Initial revision of branch_failure_route

- New branch_failure_route defined
- cfg route is called but xlog() causes segfault

Hugh Waite authored on 19/03/2013 15:43:46
Showing 6 changed files
... ...
@@ -200,6 +200,7 @@ ERROR	error
200 200
 ROUTE	route
201 201
 ROUTE_REQUEST request_route
202 202
 ROUTE_FAILURE failure_route
203
+ROUTE_BRANCH_FAILURE branch_failure_route
203 204
 ROUTE_REPLY reply_route
204 205
 ROUTE_ONREPLY onreply_route
205 206
 ROUTE_BRANCH branch_route
... ...
@@ -623,6 +624,8 @@ IMPORTFILE      "import_file"
623 623
 <INITIAL>{ROUTE_REPLY}	{ count(); yylval.strval=yytext; return ROUTE_REPLY; }
624 624
 <INITIAL>{ROUTE_FAILURE}	{ count(); yylval.strval=yytext;
625 625
 								return ROUTE_FAILURE; }
626
+<INITIAL>{ROUTE_BRANCH_FAILURE}	{ count(); yylval.strval=yytext;
627
+								return ROUTE_BRANCH_FAILURE; }
626 628
 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
627 629
 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
628 630
 <INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
... ...
@@ -314,6 +314,7 @@ extern char *finame;
314 314
 %token ROUTE
315 315
 %token ROUTE_REQUEST
316 316
 %token ROUTE_FAILURE
317
+%token ROUTE_BRANCH_FAILURE
317 318
 %token ROUTE_ONREPLY
318 319
 %token ROUTE_REPLY
319 320
 %token ROUTE_BRANCH
... ...
@@ -705,6 +706,7 @@ statement:
705 705
 	| module_stm
706 706
 	| {rt=REQUEST_ROUTE;} route_stm
707 707
 	| {rt=FAILURE_ROUTE;} failure_route_stm
708
+	| {rt=BRANCH_FAILURE_ROUTE;} branch_failure_route_stm
708 709
 	| onreply_route_stm
709 710
 	| {rt=BRANCH_ROUTE;} branch_route_stm
710 711
 	| {rt=ONSEND_ROUTE;}   send_route_stm
... ...
@@ -1970,6 +1972,28 @@ failure_route_stm:
1970 1970
 	| ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1971 1971
 	;
1972 1972
 
1973
+branch_failure_route_stm:
1974
+	ROUTE_BRANCH_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1975
+	#ifdef SHM_MEM
1976
+		if (!shm_initialized() && init_shm()<0) {
1977
+			yyerror("Can't initialize shared memory");
1978
+			YYABORT;
1979
+		}
1980
+	#endif /* SHM_MEM */
1981
+		i_tmp=route_get(&branch_failure_rt, $3);
1982
+		if (i_tmp==-1){
1983
+			yyerror("internal error");
1984
+			YYABORT;
1985
+		}
1986
+		if (branch_failure_rt.rlist[i_tmp]){
1987
+			yyerror("duplicate route");
1988
+			YYABORT;
1989
+		}
1990
+		push($6, &branch_failure_rt.rlist[i_tmp]);
1991
+	}
1992
+	| ROUTE_BRANCH_FAILURE error { yyerror("invalid branch_failure_route statement"); }
1993
+	;
1994
+
1973 1995
 
1974 1996
 route_reply_main:	ROUTE_ONREPLY { ; }
1975 1997
 		  | ROUTE_REPLY { ; }
... ...
@@ -102,6 +102,7 @@
102 102
 struct route_list main_rt;
103 103
 struct route_list onreply_rt;
104 104
 struct route_list failure_rt;
105
+struct route_list branch_failure_rt;
105 106
 struct route_list branch_rt;
106 107
 struct route_list onsend_rt;
107 108
 struct route_list event_rt;
... ...
@@ -142,6 +143,7 @@ void destroy_routes()
142 142
 	destroy_rlist(&main_rt);
143 143
 	destroy_rlist(&onreply_rt);
144 144
 	destroy_rlist(&failure_rt);
145
+	destroy_rlist(&branch_failure_rt);
145 146
 	destroy_rlist(&branch_rt);
146 147
 	destroy_rlist(&event_rt);
147 148
 }
... ...
@@ -210,6 +212,8 @@ int init_routes()
210 210
 		goto error;
211 211
 	if (init_rlist("failure", &failure_rt, FAILURE_RT_NO, RT_HASH_SIZE)<0)
212 212
 		goto error;
213
+	if (init_rlist("branch_failure", &branch_failure_rt, FAILURE_RT_NO, RT_HASH_SIZE)<0)
214
+		goto error;
213 215
 	if (init_rlist("branch", &branch_rt, BRANCH_RT_NO, RT_HASH_SIZE)<0)
214 216
 		goto error;
215 217
 	if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
... ...
@@ -53,6 +53,7 @@
53 53
 #define ERROR_ROUTE   (1 << 5)
54 54
 #define LOCAL_ROUTE   (1 << 6)
55 55
 #define CORE_ONREPLY_ROUTE (1 << 7)
56
+#define BRANCH_FAILURE_ROUTE (1 << 8)
56 57
 #define ONREPLY_ROUTE (TM_ONREPLY_ROUTE|CORE_ONREPLY_ROUTE)
57 58
 #define EVENT_ROUTE   REQUEST_ROUTE
58 59
 #define ANY_ROUTE     (0xFFFFFFFF)
... ...
@@ -85,6 +86,7 @@ extern struct route_list main_rt;
85 85
 /* main reply route table */
86 86
 extern struct route_list onreply_rt;
87 87
 extern struct route_list failure_rt;
88
+extern struct route_list branch_failure_rt;
88 89
 extern struct route_list branch_rt;
89 90
 extern struct route_list onsend_rt;
90 91
 extern struct route_list event_rt;
... ...
@@ -53,7 +53,7 @@
53 53
 #include "mem/mem.h"
54 54
 
55 55
 /* Number of cb types = last cb type */
56
-#define SCRIPT_CB_NUM	EVENT_CB_TYPE
56
+#define SCRIPT_CB_NUM	(CB_TYPE_MAX-1)
57 57
 
58 58
 static struct script_cb *pre_script_cb[SCRIPT_CB_NUM];
59 59
 static struct script_cb *post_script_cb[SCRIPT_CB_NUM];
... ...
@@ -49,14 +49,15 @@ typedef int (cb_function)(struct sip_msg *msg, unsigned int flags, void *param);
49 49
  */
50 50
 enum script_cb_flag { REQUEST_CB=1, FAILURE_CB=2, ONREPLY_CB=4,
51 51
 			BRANCH_CB=8, ONSEND_CB=16, ERROR_CB=32,
52
-			LOCAL_CB=64, EVENT_CB=128 };
52
+			LOCAL_CB=64, EVENT_CB=128, BRANCH_FAILURE_CB=256 };
53 53
 
54 54
 /* Callback types used for executing the callbacks.
55 55
  * Keep in sync with script_cb_flag!!!
56 56
  */
57 57
 enum script_cb_type { REQUEST_CB_TYPE=1, FAILURE_CB_TYPE, ONREPLY_CB_TYPE,
58 58
 			BRANCH_CB_TYPE, ONSEND_CB_TYPE, ERROR_CB_TYPE,
59
-			LOCAL_CB_TYPE, EVENT_CB_TYPE };
59
+			LOCAL_CB_TYPE, EVENT_CB_TYPE, BRANCH_FAILURE_CB_TYPE,
60
+			CB_TYPE_MAX};
60 61
 
61 62
 struct script_cb{
62 63
 	cb_function *cbf;