Browse code

core script parsing: various small fixes

- fix: allow "default" in a config var id (e.g. session_timer.default).
It stopped working after default became a keyword (switch()).
- fix: allow negative number in selects (e.g. @eval.pop[-1])
- fix: allow negative number in function parameters
- fix setavpflag, resetavpflag, isavpflag and "simple" avp names

Andrei Pelinescu-Onciul authored on 06/05/2009 14:45:04
Showing 1 changed files
... ...
@@ -561,6 +561,7 @@ static int case_check_default(struct case_stms* stms);
561 561
 %type <strval>	route_name;
562 562
 %type <intval> avpflag_oper
563 563
 %type <intval> rve_un_op
564
+%type <strval> cfg_var_id
564 565
 /* %type <intval> rve_op */
565 566
 
566 567
 /*%type <route_el> rules;
... ...
@@ -1361,29 +1362,37 @@ assign_stm:
1361 1362
 	| cfg_var
1362 1363
 	| error EQUAL { yyerror("unknown config variable"); }
1363 1364
 	;
1365
+	
1366
+cfg_var_id: ID 
1367
+	| DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
1368
+	;
1369
+	
1364 1370
 cfg_var:
1365
-	ID DOT ID EQUAL NUMBER {
1371
+	cfg_var_id DOT cfg_var_id EQUAL NUMBER {
1366 1372
 		if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1367 1373
 			yyerror("variable cannot be declared");
1368 1374
 		}
1369 1375
 	}
1370
-	| ID DOT ID EQUAL STRING {
1376
+	| cfg_var_id DOT cfg_var_id EQUAL STRING {
1371 1377
 		if (cfg_declare_str($1, $3, $5, NULL)) {
1372 1378
 			yyerror("variable cannot be declared");
1373 1379
 		}
1374 1380
 	}
1375
-	| ID DOT ID EQUAL NUMBER CFG_DESCRIPTION STRING {
1381
+	| cfg_var_id DOT cfg_var_id EQUAL NUMBER CFG_DESCRIPTION STRING {
1376 1382
 		if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1377 1383
 			yyerror("variable cannot be declared");
1378 1384
 		}
1379 1385
 	}
1380
-	| ID DOT ID EQUAL STRING CFG_DESCRIPTION STRING {
1386
+	| cfg_var_id DOT cfg_var_id EQUAL STRING CFG_DESCRIPTION STRING {
1381 1387
 		if (cfg_declare_str($1, $3, $5, $7)) {
1382 1388
 			yyerror("variable cannot be declared");
1383 1389
 		}
1384 1390
 	}
1385
-	| ID DOT ID EQUAL error { yyerror("number or string expected"); }
1391
+	| cfg_var_id DOT cfg_var_id EQUAL error { 
1392
+		yyerror("number or string expected"); 
1393
+	}
1386 1394
 	;
1395
+
1387 1396
 module_stm:
1388 1397
 	LOADMODULE STRING {
1389 1398
 		DBG("loading module %s\n", $2);
... ...
@@ -2010,7 +2019,7 @@ select_param:
2010 2019
 		sel.params[sel.n].v.s.len = strlen($1);
2011 2020
 		sel.n++;
2012 2021
 	}
2013
-	| ID LBRACK NUMBER RBRACK {
2022
+	| ID LBRACK intno RBRACK {
2014 2023
 		if (sel.n >= MAX_SELECT_PARAMS-2) {
2015 2024
 			yyerror("Select identifier too long\n");
2016 2025
 		}
... ...
@@ -2071,8 +2080,8 @@ attr_spec:
2071 2080
 attr_mark:
2072 2081
 	ATTR_MARK {
2073 2082
 		s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2074
-		if (!s_attr) { yyerror("No memory left"); }
2075
-		s_attr->type = 0;
2083
+		if (!s_attr) { yyerror("No memory left"); YYABORT; }
2084
+		else s_attr->type = 0;
2076 2085
 	}
2077 2086
 	;
2078 2087
 attr_id:
... ...
@@ -2108,6 +2117,17 @@ attr_id_any:
2108 2117
 ;
2109 2118
 attr_id_any_str:
2110 2119
 	attr_id
2120
+	| avp_pvar {
2121
+		if ($1->type==LV_AVP){
2122
+			s_attr = pkg_malloc(sizeof(struct avp_spec));
2123
+			if (!s_attr) { yyerror("No memory left"); YYABORT; }
2124
+			else{
2125
+				*s_attr=$1->lv.avps;
2126
+			}
2127
+		}else
2128
+			$$=0; /* not an avp, a pvar */
2129
+		pkg_free($1);
2130
+	}
2111 2131
 	| STRING {
2112 2132
 		avp_spec_t *avp_spec;
2113 2133
 		str s;
... ...
@@ -2266,8 +2286,8 @@ rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
2266 2286
 
2267 2287
 rval_expr: rval						{ $$=$1;
2268 2288
 										if ($$==0){
2269
-											yyerror("out of memory\n");
2270
-											YYABORT;
2289
+											/*yyerror("out of memory\n");*/
2290
+											YYERROR;
2271 2291
 										}
2272 2292
 									}
2273 2293
 		| rve_un_op %prec NOT rval_expr	{$$=mk_rve1($1, $2); }
... ...
@@ -2589,6 +2609,13 @@ cmd:
2589 2609
 		if (i_tmp==0) yyerror("avpflag not declared");
2590 2610
 		$$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
2591 2611
 	}
2612
+	| avpflag_oper LPAREN attr_id_any_str COMMA error RPAREN {
2613
+		$$=0; yyerror("error parsing flag name");
2614
+	}
2615
+	| avpflag_oper LPAREN error COMMA flag_name RPAREN {
2616
+		$$=0; yyerror("error parsing first parameter (avp or string)");
2617
+	}
2618
+	| avpflag_oper LPAREN error RPAREN { $$=0; yyerror("bad parameters"); }
2592 2619
 	| avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
2593 2620
 	| ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5); }
2594 2621
 	| ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
... ...
@@ -2765,7 +2792,7 @@ func_params:
2765 2792
 	| func_params error { yyerror("call params error\n"); }
2766 2793
 	;
2767 2794
 func_param:
2768
-        NUMBER {
2795
+        intno {
2769 2796
 		if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2770 2797
 			mod_func_action->val[mod_func_action->val[1].u.number+2].type =
2771 2798
 				NUMBER_ST;