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 449
 STAR		\*
450 450
 DOT			\.
451 451
 CR			\n
452
-
452
+EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*":"[a-zA-Z][0-9a-zA-Z-]*
453 453
 
454 454
 
455 455
 COM_LINE	#
... ...
@@ -492,6 +493,7 @@ EAT_ABLE	[\ \t\b\r]
492 492
 								return ROUTE_FAILURE; }
493 493
 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
494 494
 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
495
+<INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
495 496
 <INITIAL>{EXEC}	{ count(); yylval.strval=yytext; return EXEC; }
496 497
 <INITIAL>{SET_HOST}	{ count(); yylval.strval=yytext; return SET_HOST; }
497 498
 <INITIAL>{SET_HOSTPORT}	{ count(); yylval.strval=yytext; return SET_HOSTPORT; }
... ...
@@ -940,6 +942,11 @@ EAT_ABLE	[\ \t\b\r]
940 940
 <INITIAL>{DOT}		{ count(); return DOT; }
941 941
 <INITIAL>\\{CR}		{count(); } /* eat the escaped CR */
942 942
 <INITIAL>{CR}		{ count();/* return CR;*/ }
943
+<INITIAL>{EVENT_RT_NAME}	{ count();
944
+								addstr(&s_buf, yytext, yyleng);
945
+								yylval.strval=s_buf.s;
946
+								memset(&s_buf, 0, sizeof(s_buf));
947
+								return EVENT_RT_NAME; }
943 948
 
944 949
 
945 950
 <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 509
 %token <strval> PVAR
510 510
 /* not clear yet if this is an avp or pvar */
511 511
 %token <strval> AVP_OR_PVAR
512
+%token <strval> EVENT_RT_NAME
512 513
 
513 514
 /* other */
514 515
 %token COMMA
... ...
@@ -589,6 +591,7 @@ statement:
589 589
 	| {rt=ONREPLY_ROUTE;} onreply_route_stm
590 590
 	| {rt=BRANCH_ROUTE;} branch_route_stm
591 591
 	| {rt=ONSEND_ROUTE;}   send_route_stm
592
+	| {rt=EVENT_ROUTE;}   event_route_stm
592 593
 	| SEMICOLON	/* null statement */
593 594
 	| CR	/* null statement*/
594 595
 	;
... ...
@@ -1579,6 +1582,21 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1579 1579
 	}
1580 1580
 	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1581 1581
 	;
1582
+event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1583
+		i_tmp=route_get(&event_rt, $3);
1584
+		if (i_tmp==-1){
1585
+			yyerror("internal error");
1586
+			YYABORT;
1587
+		}
1588
+		if (event_rt.rlist[i_tmp]){
1589
+			yyerror("duplicate route");
1590
+			YYABORT;
1591
+		}
1592
+		push($6, &event_rt.rlist[i_tmp]);
1593
+	}
1594
+
1595
+	| ROUTE_EVENT error { yyerror("invalid event_route statement"); }
1596
+	;
1582 1597
 
1583 1598
 /*exp:	rval_expr
1584 1599
 		{
... ...
@@ -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 131
 	destroy_rlist(&onreply_rt);
132 132
 	destroy_rlist(&failure_rt);
133 133
 	destroy_rlist(&branch_rt);
134
+	destroy_rlist(&event_rt);
134 135
 }
135 136
 
136 137
 
... ...
@@ -201,6 +203,8 @@ int init_routes()
201 201
 		goto error;
202 202
 	if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
203 203
 		goto error;
204
+	if (init_rlist("event", &event_rt, EVENT_RT_NO, RT_HASH_SIZE)<0)
205
+		goto error;
204 206
 	return 0;
205 207
 error:
206 208
 	destroy_routes();
... ...
@@ -1807,6 +1811,8 @@ int fix_rls()
1807 1807
 		return ret;
1808 1808
 	if ((ret=fix_rl(&onsend_rt))!=0)
1809 1809
 		return ret;
1810
+	if ((ret=fix_rl(&event_rt))!=0)
1811
+		return ret;
1810 1812
 
1811 1813
 	return 0;
1812 1814
 }
... ...
@@ -1838,4 +1844,5 @@ void print_rls()
1838 1838
 	print_rl(&failure_rt, "failure");
1839 1839
 	print_rl(&branch_rt, "branch");
1840 1840
 	print_rl(&onsend_rt, "onsend");
1841
+	print_rl(&event_rt, "event");
1841 1842
 }
... ...
@@ -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 82
 extern struct route_list failure_rt;
83 83
 extern struct route_list branch_rt;
84 84
 extern struct route_list onsend_rt;
85
+extern struct route_list event_rt;
85 86
 
86 87
 /* script optimization level */
87 88
 extern int scr_opt_lev;