Browse code

- additional parameter to find_export - find_export updated to honor flags parameter - REPLY_ROUTE defined

Jan Janak authored on 19/03/2003 23:46:09
Showing 6 changed files
... ...
@@ -76,7 +76,7 @@ SEND_TCP	send_tcp
76 76
 LOG		log
77 77
 ERROR	error
78 78
 ROUTE	route
79
-REPLY_ROUTE reply_route
79
+REPL_ROUTE reply_route
80 80
 EXEC	exec
81 81
 SETFLAG		setflag
82 82
 RESETFLAG	resetflag
... ...
@@ -196,7 +196,7 @@ EAT_ABLE	[\ \t\b\r]
196 196
 <INITIAL>{ISFLAGSET}	{ count(); yylval.strval=yytext; return ISFLAGSET; }
197 197
 <INITIAL>{LEN_GT}	{ count(); yylval.strval=yytext; return LEN_GT; }
198 198
 <INITIAL>{ROUTE}	{ count(); yylval.strval=yytext; return ROUTE; }
199
-<INITIAL>{REPLY_ROUTE}	{ count(); yylval.strval=yytext; return REPLY_ROUTE; }
199
+<INITIAL>{REPL_ROUTE}	{ count(); yylval.strval=yytext; return REPL_ROUTE; }
200 200
 <INITIAL>{EXEC}	{ count(); yylval.strval=yytext; return EXEC; }
201 201
 <INITIAL>{SET_HOST}	{ count(); yylval.strval=yytext; return SET_HOST; }
202 202
 <INITIAL>{SET_HOSTPORT}	{ count(); yylval.strval=yytext; return SET_HOSTPORT; }
... ...
@@ -31,6 +31,7 @@
31 31
  * 2003-01-29  src_port added (jiri)
32 32
  * 2003-01-23  mhomed added (jiri)
33 33
  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
34
+ * 2003-03-19  Added support for route type in find_export (janakj)
34 35
  */
35 36
 
36 37
 
... ...
@@ -73,7 +74,8 @@ void yyerror(char* s);
73 74
 char* tmp;
74 75
 void* f_tmp;
75 76
 struct id_list* lst_tmp;
76
-
77
+int rt;  /* Type of route block for find_export */
78
+ 
77 79
 
78 80
 %}
79 81
 
... ...
@@ -101,7 +103,7 @@ struct id_list* lst_tmp;
101 103
 %token LOG_TOK
102 104
 %token ERROR
103 105
 %token ROUTE
104
-%token REPLY_ROUTE
106
+%token REPL_ROUTE
105 107
 %token EXEC
106 108
 %token SET_HOST
107 109
 %token SET_HOSTPORT
... ...
@@ -212,8 +214,9 @@ statements:	statements statement {}
212 214
 
213 215
 statement:	assign_stm 
214 216
 		| module_stm
215
-		| route_stm 
216
-		| reply_route_stm
217
+		| {rt=REQUEST_ROUTE;} route_stm 
218
+		| {rt=REPLY_ROUTE;} reply_route_stm
219
+
217 220
 		| CR	/* null statement*/
218 221
 	;
219 222
 
... ...
@@ -441,9 +444,9 @@ ipv6:	IPV6ADDR {
441 444
 	;
442 445
 
443 446
 
444
-route_stm:	ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
447
+route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
445 448
 
446
-		| ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { 
449
+	    | ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { 
447 450
 										if (($3<RT_NO) && ($3>=0)){
448 451
 											push($6, &rlist[$3]);
449 452
 										}else{
... ...
@@ -454,7 +457,7 @@ route_stm:	ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
454 457
 		| ROUTE error { yyerror("invalid  route  statement"); }
455 458
 	;
456 459
 
457
-reply_route_stm: REPLY_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
460
+reply_route_stm: REPL_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
458 461
 										if (($3<REPLY_RT_NO)&&($3>=1)){
459 462
 											push($6, &reply_rlist[$3]);
460 463
 										} else {
... ...
@@ -462,7 +465,7 @@ reply_route_stm: REPLY_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
462 465
 												"table number");
463 466
 											YYABORT; }
464 467
 										}
465
-		| REPLY_ROUTE error { yyerror("invalid reply_route statement"); }
468
+		| REPL_ROUTE error { yyerror("invalid reply_route statement"); }
466 469
 	;
467 470
 /*
468 471
 rules:	rules rule { push($2, &$1); $$=$1; }
... ...
@@ -1028,10 +1031,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1028 1031
 										"string expected"); }
1029 1032
 		| REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1030 1033
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1031
-		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0);
1034
+		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1032 1035
 									   if (f_tmp==0){
1033
-										yyerror("unknown command, missing"
1034
-										" loadmodule?\n");
1036
+										   if (find_export($1, 0, 0)) {
1037
+											   yyerror("Command cannot be used in the block\n");
1038
+										   } else {
1039
+											   yyerror("unknown command, missing"
1040
+												   " loadmodule?\n");
1041
+										   }
1035 1042
 										$$=0;
1036 1043
 									   }else{
1037 1044
 										$$=mk_action(	MODULE_T,
... ...
@@ -1042,10 +1049,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1042 1049
 													);
1043 1050
 									   }
1044 1051
 									}
1045
-		| ID LPAREN STRING RPAREN { f_tmp=(void*)find_export($1, 1);
1052
+		| ID LPAREN STRING RPAREN { f_tmp=(void*)find_export($1, 1, rt);
1046 1053
 									if (f_tmp==0){
1047
-										yyerror("unknown command, missing"
1048
-										" loadmodule?\n");
1054
+										if (find_export($1, 1, 0)) {
1055
+											yyerror("Command cannot be used in the block\n");
1056
+										} else {
1057
+											yyerror("unknown command, missing"
1058
+												" loadmodule?\n");
1059
+										}
1049 1060
 										$$=0;
1050 1061
 									}else{
1051 1062
 										$$=mk_action(	MODULE_T,
... ...
@@ -1057,10 +1068,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1057 1068
 									}
1058 1069
 								  }
1059 1070
 		| ID LPAREN STRING  COMMA STRING RPAREN 
1060
-								  { f_tmp=(void*)find_export($1, 2);
1071
+								  { f_tmp=(void*)find_export($1, 2, rt);
1061 1072
 									if (f_tmp==0){
1062
-										yyerror("unknown command, missing"
1063
-										" loadmodule?\n");
1073
+										if (find_export($1, 2, 0)) {
1074
+											yyerror("Command cannot be used in the block\n");
1075
+										} else {
1076
+											yyerror("unknown command, missing"
1077
+												" loadmodule?\n");
1078
+										}
1064 1079
 										$$=0;
1065 1080
 									}else{
1066 1081
 										$$=mk_action3(	MODULE_T,
... ...
@@ -34,31 +34,31 @@ db_func_t dbf;
34 34
 
35 35
 int bind_dbmod(void)
36 36
 {
37
-	db_use_table = (db_use_table_f)find_export("~db_use_table", 2);
37
+	db_use_table = (db_use_table_f)find_export("~db_use_table", 2, 0);
38 38
 	if (db_use_table == 0) return -1;
39 39
 
40
-	db_init = (db_init_f)find_export("~db_init", 1);
40
+	db_init = (db_init_f)find_export("~db_init", 1, 0);
41 41
 	if (db_init == 0) return -1;
42 42
 
43
-	db_close = (db_close_f)find_export("~db_close", 2);
43
+	db_close = (db_close_f)find_export("~db_close", 2, 0);
44 44
 	if (db_close == 0) return -1;
45 45
 
46
-	db_query = (db_query_f)find_export("~db_query", 2);
46
+	db_query = (db_query_f)find_export("~db_query", 2, 0);
47 47
 	if (db_query == 0) return -1;
48 48
 
49
-	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2);
49
+	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2, 0);
50 50
 	if (db_raw_query == 0) return -1;
51 51
 
52
-	db_free_query = (db_free_query_f)find_export("~db_free_query", 2);
52
+	db_free_query = (db_free_query_f)find_export("~db_free_query", 2, 0);
53 53
 	if (db_free_query == 0) return -1;
54 54
 
55
-	db_insert = (db_insert_f)find_export("~db_insert", 2);
55
+	db_insert = (db_insert_f)find_export("~db_insert", 2, 0);
56 56
 	if (db_insert == 0) return -1;
57 57
 
58
-	db_delete = (db_delete_f)find_export("~db_delete", 2);
58
+	db_delete = (db_delete_f)find_export("~db_delete", 2, 0);
59 59
 	if (db_delete == 0) return -1;
60 60
 
61
-	db_update = (db_update_f)find_export("~db_update", 2);
61
+	db_update = (db_update_f)find_export("~db_update", 2, 0);
62 62
 	if (db_update == 0) return -1;
63 63
 
64 64
 	return 0;
... ...
@@ -29,6 +29,7 @@
29 29
  *  2003-03-10  switched to new module_exports format: updated find_export,
30 30
  *               find_export_param, find_module (andrei)
31 31
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
32
+ *  2003-03-19  Support for flags in find_export (janakj)
32 33
  */
33 34
 
34 35
 
... ...
@@ -195,8 +196,10 @@ skip:
195 196
 
196 197
 
197 198
 /* searches the module list and returns a pointer to the "name" function or
198
- * 0 if not found */
199
-cmd_function find_export(char* name, int param_no)
199
+ * 0 if not found 
200
+ * flags parameter os OR value of all flags that must match
201
+ */
202
+cmd_function find_export(char* name, int param_no, int flags)
200 203
 {
201 204
 	struct sr_module* t;
202 205
 	cmd_export_t* cmd;
... ...
@@ -204,9 +207,11 @@ cmd_function find_export(char* name, int param_no)
204 207
 	for(t=modules;t;t=t->next){
205 208
 		for(cmd=t->exports->cmds; cmd && cmd->name; cmd++){
206 209
 			if((strcmp(name, cmd->name)==0)&&
207
-				(cmd->param_no==param_no) ){
210
+			   (cmd->param_no==param_no) &&
211
+			   ((cmd->flags & flags) == flags)
212
+			  ){
208 213
 				DBG("find_export: found <%s> in module %s [%s]\n",
209
-						name, t->exports->name, t->path);
214
+				    name, t->exports->name, t->path);
210 215
 				return cmd->function;
211 216
 			}
212 217
 		}
... ...
@@ -57,6 +57,7 @@ typedef enum {
57 57
 
58 58
 
59 59
 #define REQUEST_ROUTE 1         /* Function can be used in request route blocks */
60
+#define REPLY_ROUTE 2           /* Function can be used in reply route blocks */
60 61
 
61 62
 struct cmd_export_ {
62 63
 	char* name;             /* null terminated command name */
... ...
@@ -114,7 +115,7 @@ struct sr_module* modules; /* global module list*/
114 115
 int register_builtin_modules();
115 116
 int register_module(struct module_exports*, char*,  void*);
116 117
 int load_module(char* path);
117
-cmd_function find_export(char* name, int param_no);
118
+cmd_function find_export(char* name, int param_no, int flags);
118 119
 struct sr_module* find_module(void *f, cmd_export_t** cmd);
119 120
 void destroy_modules();
120 121
 int init_child(int rank);
... ...
@@ -26,6 +26,10 @@
26 26
  * You should have received a copy of the GNU General Public License 
27 27
  * along with this program; if not, write to the Free Software 
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
+ *
30
+ * History:
31
+ * -------
32
+ * 2003-03-19: added support for route type in find_export (janakj)
29 33
  */
30 34
 
31 35
 
... ...
@@ -325,9 +329,9 @@ int stats_register()
325 329
 	const char *func = __FUNCTION__;
326 330
 	struct stats_funcs f;
327 331
 
328
-	f.reg_func = (void*) find_export("snmp_register_handler", 2);
329
-	f.new_func = (void*) find_export("snmp_new_handler", 1);
330
-	f.free_func = (void*) find_export("snmp_free_handler", 1);
332
+	f.reg_func = (void*) find_export("snmp_register_handler", 2, 0);
333
+	f.new_func = (void*) find_export("snmp_new_handler", 1, 0);
334
+	f.free_func = (void*) find_export("snmp_free_handler", 1, 0);
331 335
 	if(!f.reg_func || !f.new_func || !f.free_func) {
332 336
 		LOG(L_INFO, "%s: Couldn't find SNMP module\n", func);
333 337
 		LOG(L_INFO, "%s: Not reporting stats through SNMP\n", func);