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 1361
 	| cfg_var
1362 1362
 	| error EQUAL { yyerror("unknown config variable"); }
1363 1363
 	;
1364
+	
1365
+cfg_var_id: ID 
1366
+	| DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
1367
+	;
1368
+	
1364 1369
 cfg_var:
1365
-	ID DOT ID EQUAL NUMBER {
1370
+	cfg_var_id DOT cfg_var_id EQUAL NUMBER {
1366 1371
 		if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1367 1372
 			yyerror("variable cannot be declared");
1368 1373
 		}
1369 1374
 	}
1370
-	| ID DOT ID EQUAL STRING {
1375
+	| cfg_var_id DOT cfg_var_id EQUAL STRING {
1371 1376
 		if (cfg_declare_str($1, $3, $5, NULL)) {
1372 1377
 			yyerror("variable cannot be declared");
1373 1378
 		}
1374 1379
 	}
1375
-	| ID DOT ID EQUAL NUMBER CFG_DESCRIPTION STRING {
1380
+	| cfg_var_id DOT cfg_var_id EQUAL NUMBER CFG_DESCRIPTION STRING {
1376 1381
 		if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1377 1382
 			yyerror("variable cannot be declared");
1378 1383
 		}
1379 1384
 	}
1380
-	| ID DOT ID EQUAL STRING CFG_DESCRIPTION STRING {
1385
+	| cfg_var_id DOT cfg_var_id EQUAL STRING CFG_DESCRIPTION STRING {
1381 1386
 		if (cfg_declare_str($1, $3, $5, $7)) {
1382 1387
 			yyerror("variable cannot be declared");
1383 1388
 		}
1384 1389
 	}
1385
-	| ID DOT ID EQUAL error { yyerror("number or string expected"); }
1390
+	| cfg_var_id DOT cfg_var_id EQUAL error { 
1391
+		yyerror("number or string expected"); 
1392
+	}
1386 1393
 	;
1394
+
1387 1395
 module_stm:
1388 1396
 	LOADMODULE STRING {
1389 1397
 		DBG("loading module %s\n", $2);
... ...
@@ -2010,7 +2019,7 @@ select_param:
2010 2010
 		sel.params[sel.n].v.s.len = strlen($1);
2011 2011
 		sel.n++;
2012 2012
 	}
2013
-	| ID LBRACK NUMBER RBRACK {
2013
+	| ID LBRACK intno RBRACK {
2014 2014
 		if (sel.n >= MAX_SELECT_PARAMS-2) {
2015 2015
 			yyerror("Select identifier too long\n");
2016 2016
 		}
... ...
@@ -2071,8 +2080,8 @@ attr_spec:
2071 2071
 attr_mark:
2072 2072
 	ATTR_MARK {
2073 2073
 		s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2074
-		if (!s_attr) { yyerror("No memory left"); }
2075
-		s_attr->type = 0;
2074
+		if (!s_attr) { yyerror("No memory left"); YYABORT; }
2075
+		else s_attr->type = 0;
2076 2076
 	}
2077 2077
 	;
2078 2078
 attr_id:
... ...
@@ -2108,6 +2117,17 @@ attr_id_any:
2108 2108
 ;
2109 2109
 attr_id_any_str:
2110 2110
 	attr_id
2111
+	| avp_pvar {
2112
+		if ($1->type==LV_AVP){
2113
+			s_attr = pkg_malloc(sizeof(struct avp_spec));
2114
+			if (!s_attr) { yyerror("No memory left"); YYABORT; }
2115
+			else{
2116
+				*s_attr=$1->lv.avps;
2117
+			}
2118
+		}else
2119
+			$$=0; /* not an avp, a pvar */
2120
+		pkg_free($1);
2121
+	}
2111 2122
 	| STRING {
2112 2123
 		avp_spec_t *avp_spec;
2113 2124
 		str s;
... ...
@@ -2266,8 +2286,8 @@ rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
2266 2266
 
2267 2267
 rval_expr: rval						{ $$=$1;
2268 2268
 										if ($$==0){
2269
-											yyerror("out of memory\n");
2270
-											YYABORT;
2269
+											/*yyerror("out of memory\n");*/
2270
+											YYERROR;
2271 2271
 										}
2272 2272
 									}
2273 2273
 		| rve_un_op %prec NOT rval_expr	{$$=mk_rve1($1, $2); }
... ...
@@ -2589,6 +2609,13 @@ cmd:
2589 2589
 		if (i_tmp==0) yyerror("avpflag not declared");
2590 2590
 		$$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
2591 2591
 	}
2592
+	| avpflag_oper LPAREN attr_id_any_str COMMA error RPAREN {
2593
+		$$=0; yyerror("error parsing flag name");
2594
+	}
2595
+	| avpflag_oper LPAREN error COMMA flag_name RPAREN {
2596
+		$$=0; yyerror("error parsing first parameter (avp or string)");
2597
+	}
2598
+	| avpflag_oper LPAREN error RPAREN { $$=0; yyerror("bad parameters"); }
2592 2599
 	| avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
2593 2600
 	| ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5); }
2594 2601
 	| ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
... ...
@@ -2765,7 +2792,7 @@ func_params:
2765 2765
 	| func_params error { yyerror("call params error\n"); }
2766 2766
 	;
2767 2767
 func_param:
2768
-        NUMBER {
2768
+        intno {
2769 2769
 		if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2770 2770
 			mod_func_action->val[mod_func_action->val[1].u.number+2].type =
2771 2771
 				NUMBER_ST;