Browse code

core: support for event_route

- a new type of route available in config
- prototye: event_route[groupid:eventid]
- groupid should be the name of the module that triggers the event
- eventid some meaningful short text describing the event
- the route is not executed from other routes, but internally when some
events happen
- to be used to get error_route and local_route K functionalities
- ex: event_route[core:request-parse-error]
- ex: event_route[tm:local-request]
- note: those are not implemented yet
- the approach has the benefit of not needing to alter the grammer if
new routes need to be defined
- still to-do:
- module that executes the event should export contraints of what
route type the functions must obey if used inside (for now
REQUEST_ROUTE functions can be used)
- first implementation is in htable module
- event route after all modules are initialized

Daniel-Constantin Mierla authored on 19/05/2009 16:55:12
Showing 5 changed files
... ...
@@ -161,6 +161,7 @@ ROUTE_FAILURE failure_route
161 161
 ROUTE_ONREPLY onreply_route
162 162
 ROUTE_BRANCH branch_route
163 163
 ROUTE_SEND onsend_route
164
+ROUTE_EVENT event_route
164 165
 EXEC	exec
165 166
 FORCE_RPORT		"force_rport"|"add_rport"
166 167
 FORCE_TCP_ALIAS		"force_tcp_alias"|"add_tcp_alias"
... ...
@@ -449,7 +450,7 @@ COLON		":"
449 450
 STAR		\*
450 451
 DOT			\.
451 452
 CR			\n
452
-
453
+EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*":"[a-zA-Z][0-9a-zA-Z-]*
453 454
 
454 455
 
455 456
 COM_LINE	#
... ...
@@ -492,6 +493,7 @@ EAT_ABLE	[\ \t\b\r]
492 493
 								return ROUTE_FAILURE; }
493 494
 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
494 495
 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
496
+<INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
495 497
 <INITIAL>{EXEC}	{ count(); yylval.strval=yytext; return EXEC; }
496 498
 <INITIAL>{SET_HOST}	{ count(); yylval.strval=yytext; return SET_HOST; }
497 499
 <INITIAL>{SET_HOSTPORT}	{ count(); yylval.strval=yytext; return SET_HOSTPORT; }
... ...
@@ -940,6 +942,11 @@ EAT_ABLE	[\ \t\b\r]
940 942
 <INITIAL>{DOT}		{ count(); return DOT; }
941 943
 <INITIAL>\\{CR}		{count(); } /* eat the escaped CR */
942 944
 <INITIAL>{CR}		{ count();/* return CR;*/ }
945
+<INITIAL>{EVENT_RT_NAME}	{ count();
946
+								addstr(&s_buf, yytext, yyleng);
947
+								yylval.strval=s_buf.s;
948
+								memset(&s_buf, 0, sizeof(s_buf));
949
+								return EVENT_RT_NAME; }
943 950
 
944 951
 
945 952
 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; 
... ...
@@ -269,6 +269,7 @@ static int case_check_default(struct case_stms* stms);
269 269
 %token ROUTE_ONREPLY
270 270
 %token ROUTE_BRANCH
271 271
 %token ROUTE_SEND
272
+%token ROUTE_EVENT
272 273
 %token EXEC
273 274
 %token SET_HOST
274 275
 %token SET_HOSTPORT
... ...
@@ -509,6 +510,7 @@ static int case_check_default(struct case_stms* stms);
509 510
 %token <strval> PVAR
510 511
 /* not clear yet if this is an avp or pvar */
511 512
 %token <strval> AVP_OR_PVAR
513
+%token <strval> EVENT_RT_NAME
512 514
 
513 515
 /* other */
514 516
 %token COMMA
... ...
@@ -589,6 +591,7 @@ statement:
589 591
 	| {rt=ONREPLY_ROUTE;} onreply_route_stm
590 592
 	| {rt=BRANCH_ROUTE;} branch_route_stm
591 593
 	| {rt=ONSEND_ROUTE;}   send_route_stm
594
+	| {rt=EVENT_ROUTE;}   event_route_stm
592 595
 	| SEMICOLON	/* null statement */
593 596
 	| CR	/* null statement*/
594 597
 	;
... ...
@@ -1579,6 +1582,21 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1579 1582
 	}
1580 1583
 	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1581 1584
 	;
1585
+event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1586
+		i_tmp=route_get(&event_rt, $3);
1587
+		if (i_tmp==-1){
1588
+			yyerror("internal error");
1589
+			YYABORT;
1590
+		}
1591
+		if (event_rt.rlist[i_tmp]){
1592
+			yyerror("duplicate route");
1593
+			YYABORT;
1594
+		}
1595
+		push($6, &event_rt.rlist[i_tmp]);
1596
+	}
1597
+
1598
+	| ROUTE_EVENT error { yyerror("invalid event_route statement"); }
1599
+	;
1582 1600
 
1583 1601
 /*exp:	rval_expr
1584 1602
 		{
... ...
@@ -62,6 +62,7 @@
62 62
 #define ONREPLY_RT_NO RT_NO /* on_reply routing tables number */
63 63
 #define BRANCH_RT_NO RT_NO /* branch_route routing tables number */
64 64
 #define ONSEND_RT_NO 1  /* onsend_route routing tables number */
65
+#define EVENT_RT_NO RT_NO /* event_route routing tables number */
65 66
 #define DEFAULT_RT 0 /* default routing table */
66 67
 
67 68
 #define MAX_REC_LEV 100 /* maximum number of recursive calls */
... ...
@@ -93,6 +93,7 @@ struct route_list onreply_rt;
93 93
 struct route_list failure_rt;
94 94
 struct route_list branch_rt;
95 95
 struct route_list onsend_rt;
96
+struct route_list event_rt;
96 97
 
97 98
 int route_type = REQUEST_ROUTE;
98 99
 
... ...
@@ -131,6 +132,7 @@ void destroy_routes()
131 132
 	destroy_rlist(&onreply_rt);
132 133
 	destroy_rlist(&failure_rt);
133 134
 	destroy_rlist(&branch_rt);
135
+	destroy_rlist(&event_rt);
134 136
 }
135 137
 
136 138
 
... ...
@@ -201,6 +203,8 @@ int init_routes()
201 203
 		goto error;
202 204
 	if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
203 205
 		goto error;
206
+	if (init_rlist("event", &event_rt, EVENT_RT_NO, RT_HASH_SIZE)<0)
207
+		goto error;
204 208
 	return 0;
205 209
 error:
206 210
 	destroy_routes();
... ...
@@ -1807,6 +1811,8 @@ int fix_rls()
1807 1811
 		return ret;
1808 1812
 	if ((ret=fix_rl(&onsend_rt))!=0)
1809 1813
 		return ret;
1814
+	if ((ret=fix_rl(&event_rt))!=0)
1815
+		return ret;
1810 1816
 
1811 1817
 	return 0;
1812 1818
 }
... ...
@@ -1838,4 +1844,5 @@ void print_rls()
1838 1844
 	print_rl(&failure_rt, "failure");
1839 1845
 	print_rl(&branch_rt, "branch");
1840 1846
 	print_rl(&onsend_rt, "onsend");
1847
+	print_rl(&event_rt, "event");
1841 1848
 }
... ...
@@ -52,6 +52,7 @@
52 52
 #define ONSEND_ROUTE  (1 << 4)
53 53
 #define ERROR_ROUTE   (1 << 5)
54 54
 #define LOCAL_ROUTE   (1 << 6)
55
+#define EVENT_ROUTE   REQUEST_ROUTE
55 56
 #define ANY_ROUTE     (0xFFFFFFFF)
56 57
 
57 58
 /* The value of this variable is one of the route types defined above and it
... ...
@@ -82,6 +83,7 @@ extern struct route_list onreply_rt;
82 83
 extern struct route_list failure_rt;
83 84
 extern struct route_list branch_rt;
84 85
 extern struct route_list onsend_rt;
86
+extern struct route_list event_rt;
85 87
 
86 88
 /* script optimization level */
87 89
 extern int scr_opt_lev;