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 73
 char* tmp;
74 74
 void* f_tmp;
75 75
 struct id_list* lst_tmp;
76
-
76
+int rt;  /* Type of route block for find_export */
77
+ 
77 78
 
78 79
 %}
79 80
 
... ...
@@ -101,7 +103,7 @@ struct id_list* lst_tmp;
101 101
 %token LOG_TOK
102 102
 %token ERROR
103 103
 %token ROUTE
104
-%token REPLY_ROUTE
104
+%token REPL_ROUTE
105 105
 %token EXEC
106 106
 %token SET_HOST
107 107
 %token SET_HOSTPORT
... ...
@@ -212,8 +214,9 @@ statements:	statements statement {}
212 212
 
213 213
 statement:	assign_stm 
214 214
 		| module_stm
215
-		| route_stm 
216
-		| reply_route_stm
215
+		| {rt=REQUEST_ROUTE;} route_stm 
216
+		| {rt=REPLY_ROUTE;} reply_route_stm
217
+
217 218
 		| CR	/* null statement*/
218 219
 	;
219 220
 
... ...
@@ -441,9 +444,9 @@ ipv6:	IPV6ADDR {
441 441
 	;
442 442
 
443 443
 
444
-route_stm:	ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
444
+route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
445 445
 
446
-		| ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { 
446
+	    | ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { 
447 447
 										if (($3<RT_NO) && ($3>=0)){
448 448
 											push($6, &rlist[$3]);
449 449
 										}else{
... ...
@@ -454,7 +457,7 @@ route_stm:	ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
454 454
 		| ROUTE error { yyerror("invalid  route  statement"); }
455 455
 	;
456 456
 
457
-reply_route_stm: REPLY_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
457
+reply_route_stm: REPL_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
458 458
 										if (($3<REPLY_RT_NO)&&($3>=1)){
459 459
 											push($6, &reply_rlist[$3]);
460 460
 										} else {
... ...
@@ -462,7 +465,7 @@ reply_route_stm: REPLY_ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
462 462
 												"table number");
463 463
 											YYABORT; }
464 464
 										}
465
-		| REPLY_ROUTE error { yyerror("invalid reply_route statement"); }
465
+		| REPL_ROUTE error { yyerror("invalid reply_route statement"); }
466 466
 	;
467 467
 /*
468 468
 rules:	rules rule { push($2, &$1); $$=$1; }
... ...
@@ -1028,10 +1031,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1028 1028
 										"string expected"); }
1029 1029
 		| REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1030 1030
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1031
-		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0);
1031
+		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1032 1032
 									   if (f_tmp==0){
1033
-										yyerror("unknown command, missing"
1034
-										" loadmodule?\n");
1033
+										   if (find_export($1, 0, 0)) {
1034
+											   yyerror("Command cannot be used in the block\n");
1035
+										   } else {
1036
+											   yyerror("unknown command, missing"
1037
+												   " loadmodule?\n");
1038
+										   }
1035 1039
 										$$=0;
1036 1040
 									   }else{
1037 1041
 										$$=mk_action(	MODULE_T,
... ...
@@ -1042,10 +1049,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1042 1042
 													);
1043 1043
 									   }
1044 1044
 									}
1045
-		| ID LPAREN STRING RPAREN { f_tmp=(void*)find_export($1, 1);
1045
+		| ID LPAREN STRING RPAREN { f_tmp=(void*)find_export($1, 1, rt);
1046 1046
 									if (f_tmp==0){
1047
-										yyerror("unknown command, missing"
1048
-										" loadmodule?\n");
1047
+										if (find_export($1, 1, 0)) {
1048
+											yyerror("Command cannot be used in the block\n");
1049
+										} else {
1050
+											yyerror("unknown command, missing"
1051
+												" loadmodule?\n");
1052
+										}
1049 1053
 										$$=0;
1050 1054
 									}else{
1051 1055
 										$$=mk_action(	MODULE_T,
... ...
@@ -1057,10 +1068,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1057 1057
 									}
1058 1058
 								  }
1059 1059
 		| ID LPAREN STRING  COMMA STRING RPAREN 
1060
-								  { f_tmp=(void*)find_export($1, 2);
1060
+								  { f_tmp=(void*)find_export($1, 2, rt);
1061 1061
 									if (f_tmp==0){
1062
-										yyerror("unknown command, missing"
1063
-										" loadmodule?\n");
1062
+										if (find_export($1, 2, 0)) {
1063
+											yyerror("Command cannot be used in the block\n");
1064
+										} else {
1065
+											yyerror("unknown command, missing"
1066
+												" loadmodule?\n");
1067
+										}
1064 1068
 										$$=0;
1065 1069
 									}else{
1066 1070
 										$$=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 195
 
196 196
 
197 197
 /* 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)
198
+ * 0 if not found 
199
+ * flags parameter os OR value of all flags that must match
200
+ */
201
+cmd_function find_export(char* name, int param_no, int flags)
200 202
 {
201 203
 	struct sr_module* t;
202 204
 	cmd_export_t* cmd;
... ...
@@ -204,9 +207,11 @@ cmd_function find_export(char* name, int param_no)
204 204
 	for(t=modules;t;t=t->next){
205 205
 		for(cmd=t->exports->cmds; cmd && cmd->name; cmd++){
206 206
 			if((strcmp(name, cmd->name)==0)&&
207
-				(cmd->param_no==param_no) ){
207
+			   (cmd->param_no==param_no) &&
208
+			   ((cmd->flags & flags) == flags)
209
+			  ){
208 210
 				DBG("find_export: found <%s> in module %s [%s]\n",
209
-						name, t->exports->name, t->path);
211
+				    name, t->exports->name, t->path);
210 212
 				return cmd->function;
211 213
 			}
212 214
 		}
... ...
@@ -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 114
 int register_builtin_modules();
115 115
 int register_module(struct module_exports*, char*,  void*);
116 116
 int load_module(char* path);
117
-cmd_function find_export(char* name, int param_no);
117
+cmd_function find_export(char* name, int param_no, int flags);
118 118
 struct sr_module* find_module(void *f, cmd_export_t** cmd);
119 119
 void destroy_modules();
120 120
 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 325
 	const char *func = __FUNCTION__;
326 326
 	struct stats_funcs f;
327 327
 
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);
328
+	f.reg_func = (void*) find_export("snmp_register_handler", 2, 0);
329
+	f.new_func = (void*) find_export("snmp_new_handler", 1, 0);
330
+	f.free_func = (void*) find_export("snmp_free_handler", 1, 0);
331 331
 	if(!f.reg_func || !f.new_func || !f.free_func) {
332 332
 		LOG(L_INFO, "%s: Couldn't find SNMP module\n", func);
333 333
 		LOG(L_INFO, "%s: Not reporting stats through SNMP\n", func);