Module: sip-router
Branch: master
Commit: 31b5e3d0e7812bc008a05311c213848b55fd9387
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=31b5e3d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue May 19 19:55:12 2009 +0300
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
---
cfg.lex | 9 ++++++++-
cfg.y | 18 ++++++++++++++++++
config.h | 1 +
route.c | 7 +++++++
route.h | 2 ++
5 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index 957e27f..afae712 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -161,6 +161,7 @@ ROUTE_FAILURE failure_route
ROUTE_ONREPLY onreply_route
ROUTE_BRANCH branch_route
ROUTE_SEND onsend_route
+ROUTE_EVENT event_route
EXEC exec
FORCE_RPORT "force_rport"|"add_rport"
FORCE_TCP_ALIAS "force_tcp_alias"|"add_tcp_alias"
@@ -449,7 +450,7 @@ COLON ":"
STAR \*
DOT \.
CR \n
-
+EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*":"[a-zA-Z][0-9a-zA-Z-]*
COM_LINE #
@@ -492,6 +493,7 @@ EAT_ABLE [\ \t\b\r]
return ROUTE_FAILURE; }
<INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
<INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
+<INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
<INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
<INITIAL>{SET_HOST} { count(); yylval.strval=yytext; return SET_HOST; }
<INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
@@ -940,6 +942,11 @@ EAT_ABLE [\ \t\b\r]
<INITIAL>{DOT} { count(); return DOT; }
<INITIAL>\\{CR} {count(); } /* eat the escaped CR */
<INITIAL>{CR} { count();/* return CR;*/ }
+<INITIAL>{EVENT_RT_NAME} { count();
+ addstr(&s_buf, yytext, yyleng);
+ yylval.strval=s_buf.s;
+ memset(&s_buf, 0, sizeof(s_buf));
+ return EVENT_RT_NAME; }
<INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START;
diff --git a/cfg.y b/cfg.y
index 6eec3b1..d8d0e35 100644
--- a/cfg.y
+++ b/cfg.y
@@ -269,6 +269,7 @@ static int case_check_default(struct case_stms* stms);
%token ROUTE_ONREPLY
%token ROUTE_BRANCH
%token ROUTE_SEND
+%token ROUTE_EVENT
%token EXEC
%token SET_HOST
%token SET_HOSTPORT
@@ -509,6 +510,7 @@ static int case_check_default(struct case_stms* stms);
%token <strval> PVAR
/* not clear yet if this is an avp or pvar */
%token <strval> AVP_OR_PVAR
+%token <strval> EVENT_RT_NAME
/* other */
%token COMMA
@@ -589,6 +591,7 @@ statement:
| {rt=ONREPLY_ROUTE;} onreply_route_stm
| {rt=BRANCH_ROUTE;} branch_route_stm
| {rt=ONSEND_ROUTE;} send_route_stm
+ | {rt=EVENT_ROUTE;} event_route_stm
| SEMICOLON /* null statement */
| CR /* null statement*/
;
@@ -1579,6 +1582,21 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
}
| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
;
+event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
+ i_tmp=route_get(&event_rt, $3);
+ if (i_tmp==-1){
+ yyerror("internal error");
+ YYABORT;
+ }
+ if (event_rt.rlist[i_tmp]){
+ yyerror("duplicate route");
+ YYABORT;
+ }
+ push($6, &event_rt.rlist[i_tmp]);
+ }
+
+ | ROUTE_EVENT error { yyerror("invalid event_route statement"); }
+ ;
/*exp: rval_expr
{
diff --git a/config.h b/config.h
index 317ff1c..e78d727 100644
--- a/config.h
+++ b/config.h
@@ -62,6 +62,7 @@
#define ONREPLY_RT_NO RT_NO /* on_reply routing tables number */
#define BRANCH_RT_NO RT_NO /* branch_route routing tables number */
#define ONSEND_RT_NO 1 /* onsend_route routing tables number */
+#define EVENT_RT_NO RT_NO /* event_route routing tables number */
#define DEFAULT_RT 0 /* default routing table */
#define MAX_REC_LEV 100 /* maximum number of recursive calls */
diff --git a/route.c b/route.c
index 77adbfb..e22820d 100644
--- a/route.c
+++ b/route.c
@@ -93,6 +93,7 @@ struct route_list onreply_rt;
struct route_list failure_rt;
struct route_list branch_rt;
struct route_list onsend_rt;
+struct route_list event_rt;
int route_type = REQUEST_ROUTE;
@@ -131,6 +132,7 @@ void destroy_routes()
destroy_rlist(&onreply_rt);
destroy_rlist(&failure_rt);
destroy_rlist(&branch_rt);
+ destroy_rlist(&event_rt);
}
@@ -201,6 +203,8 @@ int init_routes()
goto error;
if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
goto error;
+ if (init_rlist("event", &event_rt, EVENT_RT_NO, RT_HASH_SIZE)<0)
+ goto error;
return 0;
error:
destroy_routes();
@@ -1807,6 +1811,8 @@ int fix_rls()
return ret;
if ((ret=fix_rl(&onsend_rt))!=0)
return ret;
+ if ((ret=fix_rl(&event_rt))!=0)
+ return ret;
return 0;
}
@@ -1838,4 +1844,5 @@ void print_rls()
print_rl(&failure_rt, "failure");
print_rl(&branch_rt, "branch");
print_rl(&onsend_rt, "onsend");
+ print_rl(&event_rt, "event");
}
diff --git a/route.h b/route.h
index cb86ba4..6232f4b 100644
--- a/route.h
+++ b/route.h
@@ -52,6 +52,7 @@
#define ONSEND_ROUTE (1 << 4)
#define ERROR_ROUTE (1 << 5)
#define LOCAL_ROUTE (1 << 6)
+#define EVENT_ROUTE REQUEST_ROUTE
#define ANY_ROUTE (0xFFFFFFFF)
/* 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;
extern struct route_list failure_rt;
extern struct route_list branch_rt;
extern struct route_list onsend_rt;
+extern struct route_list event_rt;
/* script optimization level */
extern int scr_opt_lev;