Browse code

script parsing: rvalues instead of expr.

- expressions are now evaluated in terms of rvalues
- more operators
- operator precedence
- cleanup
- NUMBER is now always positive (added intno which can be
negative)

Andrei Pelinescu-Onciul authored on 09/12/2008 15:18:49
Showing 2 changed files
... ...
@@ -399,7 +399,7 @@ ID			{LETTER}{ALPHANUM}*
399 399
 HEX			[0-9a-fA-F]
400 400
 HEXNUMBER	0x{HEX}+
401 401
 OCTNUMBER	0[0-7]+
402
-DECNUMBER       0|-?([1-9]{DIGIT}*)
402
+DECNUMBER       0|([1-9]{DIGIT}*)
403 403
 BINNUMBER       [0-1]+b
404 404
 HEX4		{HEX}{1,4}
405 405
 IPV6ADDR	({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
... ...
@@ -91,6 +91,8 @@
91 91
  * 2008-11-18  support for variable parameter module functions (andrei)
92 92
  * 2007-12-03  support for generalised lvalues and rvalues:
93 93
  *               lval=rval_expr, where lval=avp|pvar  (andrei)
94
+ * 2007-12-06  expression are now evaluated in terms of rvalues;
95
+ *             NUMBER is now always positive; cleanup (andrei)
94 96
 */
95 97
 
96 98
 %{
... ...
@@ -194,6 +196,7 @@ static select_t* sel_ptr;
194 194
 static pv_spec_t* pv_spec;
195 195
 static struct action *mod_func_action;
196 196
 static struct lvalue* lval_tmp;
197
+static struct rvalue* rval_tmp;
197 198
 
198 199
 static void warn(char* s);
199 200
 static struct socket_id* mk_listen_id(char*, int, int);
... ...
@@ -444,21 +447,18 @@ static void free_socket_id_lst(struct socket_id* i);
444 444
 %token STUN_ALLOW_FP
445 445
 
446 446
 
447
-/* operators */
448
-%nonassoc EQUAL
449
-%nonassoc EQUAL_T
450
-%nonassoc GT
451
-%nonassoc LT
452
-%nonassoc GTE
453
-%nonassoc LTE
454
-%nonassoc DIFF
455
-%nonassoc MATCH
447
+/* operators, C like precedence */
448
+%right EQUAL
456 449
 %left LOG_OR
457 450
 %left LOG_AND
458 451
 %left BIN_OR
459 452
 %left BIN_AND
453
+%left EQUAL_T DIFF MATCH
454
+%left GT LT GTE LTE
460 455
 %left PLUS MINUS
456
+%left STAR SLASH
461 457
 %right NOT
458
+%left DOT
462 459
 
463 460
 /* values */
464 461
 %token <intval> NUMBER
... ...
@@ -478,16 +478,15 @@ static void free_socket_id_lst(struct socket_id* i);
478 478
 %token RBRACE
479 479
 %token LBRACK
480 480
 %token RBRACK
481
-%token SLASH
482
-%token DOT
483 481
 %token CR
484 482
 %token COLON
485
-%token STAR
486 483
 
487 484
 
488 485
 /*non-terminals */
489
-%type <expr> exp exp_elem /*, condition*/
490
-%type <action> action actions cmd fcmd if_cmd stm exp_stm assign_action
486
+%type <expr> exp exp_elem
487
+%type <intval> intno eint_op eint_op_onsend
488
+%type <intval> eip_op eip_op_onsend
489
+%type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
491 490
 %type <ipaddr> ipv4 ipv6 ipv6addr ip
492 491
 %type <ipnet> ipnet
493 492
 %type <strval> host
... ...
@@ -498,19 +497,18 @@ static void free_socket_id_lst(struct socket_id* i);
498 498
 %type <sockid>  phostport
499 499
 %type <sockid>  listen_phostport
500 500
 %type <intval> proto port
501
-%type <intval> equalop strop intop binop
502
-%type <strval> host_sep
501
+%type <intval> equalop strop cmpop
503 502
 %type <intval> uri_type
504 503
 %type <attr> attr_id
505 504
 %type <attr> attr_id_num_idx
506 505
 %type <attr> attr_id_no_idx
507 506
 %type <attr> attr_id_ass
508
-%type <attr> attr_id_val
507
+/*%type <attr> attr_id_val*/
509 508
 %type <attr> attr_id_any
510 509
 %type <attr> attr_id_any_str
511 510
 %type <pvar> pvar
512 511
 %type <lval> lval
513
-%type <rv_expr> rval rval_expr
512
+%type <rv_expr> rval rval_expr 
514 513
 %type <lval> avp_pvar
515 514
 /* %type <intval> class_id */
516 515
 %type <intval> assign_op
... ...
@@ -519,7 +517,7 @@ static void free_socket_id_lst(struct socket_id* i);
519 519
 %type <strval>	route_name;
520 520
 %type <intval> avpflag_oper
521 521
 %type <intval> rve_un_op
522
-%type <intval> rve_op
522
+/* %type <intval> rve_op */
523 523
 
524 524
 /*%type <route_el> rules;
525 525
   %type <route_el> rule;
... ...
@@ -631,6 +629,10 @@ id_lst:
631 631
 	| listen_phostport id_lst	{ $$=$1; $$->next=$2; }
632 632
 	;
633 633
 
634
+intno: NUMBER
635
+	|  MINUS %prec NOT NUMBER { $$=-$2; }
636
+	;
637
+
634 638
 flags_decl:		FLAGS_DECL	flag_list
635 639
 			|	FLAGS_DECL error { yyerror("flag list expected\n"); }
636 640
 ;
... ...
@@ -666,7 +668,7 @@ avpflag_spec:
666 666
 	}
667 667
 	;
668 668
 assign_stm:
669
-	DEBUG_V EQUAL NUMBER { default_core_cfg.debug=$3; }
669
+	DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
670 670
 	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
671 671
 	| FORK  EQUAL NUMBER { dont_fork= ! $3; }
672 672
 	| FORK  EQUAL error  { yyerror("boolean value expected"); }
... ...
@@ -689,13 +691,13 @@ assign_stm:
689 689
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
690 690
 	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
691 691
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
692
-	| DNS_UDP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
692
+	| DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
693 693
 	| DNS_UDP_PREF error { yyerror("number expected"); }
694
-	| DNS_TCP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
694
+	| DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
695 695
 	| DNS_TCP_PREF error { yyerror("number expected"); }
696
-	| DNS_TLS_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
696
+	| DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
697 697
 	| DNS_TLS_PREF error { yyerror("number expected"); }
698
-	| DNS_SCTP_PREF EQUAL NUMBER { 
698
+	| DNS_SCTP_PREF EQUAL intno { 
699 699
 								IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
700 700
 	| DNS_SCTP_PREF error { yyerror("number expected"); }
701 701
 	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
... ...
@@ -755,9 +757,9 @@ assign_stm:
755 755
 	| PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
756 756
 	| SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
757 757
 	| SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
758
-	| MEMLOG EQUAL NUMBER { memlog=$3; }
758
+	| MEMLOG EQUAL intno { memlog=$3; }
759 759
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
760
-	| MEMDBG EQUAL NUMBER { memdbg=$3; }
760
+	| MEMDBG EQUAL intno { memdbg=$3; }
761 761
 	| MEMDBG EQUAL error { yyerror("int value expected"); }
762 762
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
763 763
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
... ...
@@ -799,7 +801,7 @@ assign_stm:
799 799
 		#endif
800 800
 	}
801 801
 	| TCP_CHILDREN EQUAL error { yyerror("number expected"); }
802
-	| TCP_CONNECT_TIMEOUT EQUAL NUMBER {
802
+	| TCP_CONNECT_TIMEOUT EQUAL intno {
803 803
 		#ifdef USE_TCP
804 804
 			tcp_connect_timeout=$3;
805 805
 		#else
... ...
@@ -807,7 +809,7 @@ assign_stm:
807 807
 		#endif
808 808
 	}
809 809
 	| TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
810
-	| TCP_SEND_TIMEOUT EQUAL NUMBER {
810
+	| TCP_SEND_TIMEOUT EQUAL intno {
811 811
 		#ifdef USE_TCP
812 812
 			tcp_send_timeout=$3;
813 813
 		#else
... ...
@@ -815,7 +817,7 @@ assign_stm:
815 815
 		#endif
816 816
 	}
817 817
 	| TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
818
-	| TCP_CON_LIFETIME EQUAL NUMBER {
818
+	| TCP_CON_LIFETIME EQUAL intno {
819 819
 		#ifdef USE_TCP
820 820
 			tcp_con_lifetime=$3;
821 821
 		#else
... ...
@@ -1484,281 +1486,168 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1484 1484
 	}
1485 1485
 	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1486 1486
 	;
1487
-/*
1488
-rules:
1489
-	rules rule { push($2, &$1); $$=$1; }
1490
-	| rule {$$=$1; }
1491
-	| rules error { $$=0; yyerror("invalid rule"); }
1492
-	;
1493
-rule:
1494
-	condition actions CR {
1495
-		$$=0;
1496
-		if (add_rule($1, $2, &$$)<0) {
1497
-			yyerror("error calling add_rule");
1498
-			YYABORT;
1487
+
1488
+exp:	rval_expr
1489
+		{
1490
+			if (!rve_check_type((enum rval_type*)&i_tmp, $1)){
1491
+				yyerror("invalid expression");
1492
+				$$=0;
1493
+			}else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
1494
+				yyerror("invalid expression type, int expected\n");
1495
+				$$=0;
1496
+			}else
1497
+				$$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
1499 1498
 		}
1500
-	}
1501
-	| CR	{ $$=0;}
1502
-	| condition error { $$=0; yyerror("bad actions in rule"); }
1503
-	;
1504
-condition:
1505
-	exp {$$=$1;}
1506
-*/
1507
-exp:	exp LOG_AND exp		{ $$=mk_exp(LOGAND_OP, $1, $3); }
1508
-	| exp LOG_OR exp	{ $$=mk_exp(LOGOR_OP, $1, $3);  }
1509
-	| NOT exp 		{ $$=mk_exp(NOT_OP, $2, 0);  }
1510
-	| LPAREN exp RPAREN	{ $$=$2; }
1511
-	| exp_elem		{ $$=$1; }
1512 1499
 	;
1500
+
1513 1501
 equalop:
1514
-	EQUAL_T {$$=EQUAL_OP; }
1515
-	| DIFF	{$$=DIFF_OP; }
1516
-	;
1517
-intop:	equalop	{$$=$1; }
1518
-	| GT	{$$=GT_OP; }
1519
-	| LT	{$$=LT_OP; }
1520
-	| GTE	{$$=GTE_OP; }
1521
-	| LTE	{$$=LTE_OP; }
1502
+	EQUAL_T {$$=RVE_EQ_OP; }
1503
+	| DIFF	{$$=RVE_DIFF_OP; }
1522 1504
 	;
1523
-binop :
1524
-	BIN_OR { $$= BINOR_OP; }
1525
-	| BIN_AND { $$ = BINAND_OP; }
1505
+cmpop:
1506
+	  GT	{$$=RVE_GT_OP; }
1507
+	| LT	{$$=RVE_LT_OP; }
1508
+	| GTE	{$$=RVE_GTE_OP; }
1509
+	| LTE	{$$=RVE_LTE_OP; }
1526 1510
 	;
1527 1511
 strop:
1528 1512
 	equalop	{$$=$1; }
1529 1513
 	| MATCH	{$$=MATCH_OP; }
1530 1514
 	;
1515
+
1516
+
1517
+/* boolean expression uri operands */
1531 1518
 uri_type:
1532 1519
 	URI		{$$=URI_O;}
1533 1520
 	| FROM_URI	{$$=FROM_URI_O;}
1534 1521
 	| TO_URI	{$$=TO_URI_O;}
1535 1522
 	;
1536 1523
 
1524
+
1525
+/* boolean expression integer operands, available only in the
1526
+  onsend route */
1527
+eint_op_onsend:
1528
+			SNDPORT		{ $$=SNDPORT_O; }
1529
+		|	TOPORT		{ $$=TOPORT_O; }
1530
+		|	SNDPROTO	{ $$=SNDPROTO_O; }
1531
+		|	SNDAF		{ $$=SNDAF_O; }
1532
+		;
1533
+
1534
+/* boolean expression integer operands */
1535
+eint_op:	SRCPORT		{ $$=SRCPORT_O; }
1536
+		|	DSTPORT		{ $$=DSTPORT_O; }
1537
+		|	PROTO		{ $$=PROTO_O; }
1538
+		|	AF			{ $$=AF_O; }
1539
+		|	MSGLEN		{ $$=MSGLEN_O; }
1540
+		|	RETCODE		{ $$=RETCODE_O; }
1541
+		| eint_op_onsend
1542
+	;
1543
+
1544
+/* boolean expression ip/ipnet operands */
1545
+eip_op_onsend:
1546
+			SNDIP		{ onsend_check("snd_ip"); $$=SNDIP_O; }
1547
+		|	TOIP		{ onsend_check("to_ip");  $$=TOIP_O; }
1548
+		;
1549
+
1550
+eip_op:		SRCIP		{ $$=SRCIP_O; }
1551
+		|	DSTIP		{ $$=DSTIP_O; }
1552
+		| eip_op_onsend
1553
+		;
1554
+
1555
+
1556
+
1537 1557
 exp_elem:
1538
-	METHOD strop STRING	{$$= mk_elem($2, METHOD_O, 0, STRING_ST, $3);}
1539
-	| METHOD strop attr_id_val  {$$ = mk_elem($2, METHOD_O, 0, AVP_ST, $3); }
1540
-	| METHOD strop select_id {$$ = mk_elem($2, METHOD_O, 0, SELECT_ST, $3); }
1541
-	| METHOD strop  ID	{$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
1558
+	METHOD strop %prec EQUAL_T rval_expr
1559
+		{$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
1560
+	| METHOD strop %prec EQUAL_T ID
1561
+		{$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
1542 1562
 	| METHOD strop error { $$=0; yyerror("string expected"); }
1543
-	| METHOD error	{ $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
1544
-	| uri_type strop STRING	{$$ = mk_elem($2, $1, 0, STRING_ST, $3); }
1545
-	| uri_type strop host 	{$$ = mk_elem($2, $1, 0, STRING_ST, $3); }
1546
-	| uri_type strop attr_id_val {$$ = mk_elem($2, $1, 0, AVP_ST, $3); }
1547
-	| uri_type strop select_id {$$ = mk_elem($2, $1, 0, SELECT_ST, $3); }
1548
-	| uri_type equalop MYSELF {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1549
-	| uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
1550
-	| uri_type error	{ $$=0; yyerror("invalid operator, == , != or =~ expected"); }
1551
-
1552
-	| SRCPORT intop NUMBER { $$=mk_elem($2, SRCPORT_O, 0, NUMBER_ST, (void*)$3 ); }
1553
-	| SRCPORT intop attr_id_val { $$=mk_elem($2, SRCPORT_O, 0, AVP_ST, (void*)$3 ); }
1554
-	| SRCPORT intop error { $$=0; yyerror("number expected"); }
1555
-	| SRCPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1556
-
1557
-	| DSTPORT intop NUMBER	{ $$=mk_elem($2, DSTPORT_O, 0, NUMBER_ST, (void*)$3 ); }
1558
-	| DSTPORT intop attr_id_val	{ $$=mk_elem($2, DSTPORT_O, 0, AVP_ST, (void*)$3 ); }
1559
-	| DSTPORT intop error { $$=0; yyerror("number expected"); }
1560
-	| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1561
-
1562
-	| SNDPORT intop NUMBER {
1563
-		onsend_check("snd_port");
1564
-		$$=mk_elem($2, SNDPORT_O, 0, NUMBER_ST, (void*)$3 );
1565
-	}
1566
-	| SNDPORT intop attr_id_val {
1567
-		onsend_check("snd_port");
1568
-		$$=mk_elem($2, SNDPORT_O, 0, AVP_ST, (void*)$3 );
1569
-	}
1570
-	| SNDPORT intop error { $$=0; yyerror("number expected"); }
1571
-	| SNDPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1572
-
1573
-	| TOPORT intop NUMBER {
1574
-		onsend_check("to_port");
1575
-		$$=mk_elem($2, TOPORT_O, 0, NUMBER_ST, (void*)$3 );
1576
-	}
1577
-	| TOPORT intop attr_id_val {
1578
-		onsend_check("to_port");
1579
-		$$=mk_elem($2, TOPORT_O, 0, AVP_ST, (void*)$3 );
1580
-	}
1581
-	| TOPORT intop error { $$=0; yyerror("number expected"); }
1582
-	| TOPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1583
-
1584
-	| PROTO intop proto	{ $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
1585
-	| PROTO intop attr_id_val	{ $$=mk_elem($2, PROTO_O, 0, AVP_ST, (void*)$3 ); }
1586
-	| PROTO intop error { $$=0; yyerror("protocol expected (udp, tcp or tls)"); }
1587
-
1588
-	| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
1589
-
1590
-	| SNDPROTO intop proto	{
1591
-		onsend_check("snd_proto");
1592
-		$$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 );
1593
-	}
1594
-	| SNDPROTO intop attr_id_val {
1595
-		onsend_check("snd_proto");
1596
-		$$=mk_elem($2, SNDPROTO_O, 0, AVP_ST, (void*)$3 );
1597
-	}
1598
-	| SNDPROTO intop error { $$=0; yyerror("protocol expected (udp, tcp or tls)"); }
1599
-	| SNDPROTO error { $$=0; yyerror("equal/!= operator expected"); }
1600
-
1601
-	| AF intop NUMBER	{ $$=mk_elem($2, AF_O, 0, NUMBER_ST,(void *) $3 ); }
1602
-	| AF intop attr_id_val	{ $$=mk_elem($2, AF_O, 0, AVP_ST,(void *) $3 ); }
1603
-	| AF intop error { $$=0; yyerror("number expected"); }
1604
-	| AF error { $$=0; yyerror("equal/!= operator expected"); }
1605
-
1606
-	| SNDAF intop NUMBER {
1607
-		onsend_check("snd_af");
1608
-		$$=mk_elem($2, SNDAF_O, 0, NUMBER_ST, (void *) $3 ); }
1609
-	| SNDAF intop attr_id_val {
1610
-		onsend_check("snd_af");
1611
-		$$=mk_elem($2, SNDAF_O, 0, AVP_ST, (void *) $3 );
1612
-	}
1613
-	| SNDAF intop error { $$=0; yyerror("number expected"); }
1614
-	| SNDAF error { $$=0; yyerror("equal/!= operator expected"); }
1615
-
1616
-	| MSGLEN intop NUMBER		{ $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST, (void *) $3 ); }
1617
-	| MSGLEN intop attr_id_val	{ $$=mk_elem($2, MSGLEN_O, 0, AVP_ST, (void *) $3 ); }
1618
-	| MSGLEN intop MAX_LEN		{ $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST, (void *) BUF_SIZE); }
1619
-	| MSGLEN intop error { $$=0; yyerror("number expected"); }
1620
-	| MSGLEN error { $$=0; yyerror("equal/!= operator expected"); }
1621
-
1622
-	| RETCODE intop NUMBER	{ $$=mk_elem($2, RETCODE_O, 0, NUMBER_ST, (void *) $3 ); }
1623
-	| RETCODE intop attr_id_val	{ $$=mk_elem($2, RETCODE_O, 0, AVP_ST, (void *) $3 ); }
1624
-	| RETCODE intop error { $$=0; yyerror("number expected"); }
1625
-	| RETCODE error { $$=0; yyerror("equal/!= operator expected"); }
1626
-
1627
-	| SRCIP equalop ipnet	{ $$=mk_elem($2, SRCIP_O, 0, NET_ST, $3); }
1628
-	| SRCIP strop STRING {
1629
-		s_tmp.s=$3;
1630
-		s_tmp.len=strlen($3);
1631
-		ip_tmp=str2ip(&s_tmp);
1632
-	#ifdef USE_IPV6
1633
-		if (ip_tmp==0)
1634
-			ip_tmp=str2ip6(&s_tmp);
1635
-	#endif
1636
-		if (ip_tmp) {
1637
-			$$=mk_elem($2, SRCIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1638
-		} else {
1639
-			$$=mk_elem($2, SRCIP_O, 0, STRING_ST, $3);
1640
-		}
1641
-	}
1642
-	| SRCIP strop host	{ $$=mk_elem($2, SRCIP_O, 0, STRING_ST, $3); }
1643
-	| SRCIP equalop MYSELF  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
1644
-							}
1645
-	| SRCIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1646
-	| SRCIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
1647
-	| DSTIP equalop ipnet	{ $$=mk_elem(	$2, DSTIP_O, 0, NET_ST, (void*)$3); }
1648
-	| DSTIP strop STRING	{
1649
-		s_tmp.s=$3;
1650
-		s_tmp.len=strlen($3);
1651
-		ip_tmp=str2ip(&s_tmp);
1652
-	#ifdef USE_IPV6
1653
-		if (ip_tmp==0)
1654
-			ip_tmp=str2ip6(&s_tmp);
1655
-	#endif /* USE_IPV6 */
1656
-		if (ip_tmp) {
1657
-			$$=mk_elem($2, DSTIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1658
-		} else {
1659
-			$$=mk_elem($2, DSTIP_O, 0, STRING_ST, $3);
1660
-		}
1661
-	}
1662
-	| DSTIP strop host	{ $$=mk_elem(	$2, DSTIP_O, 0, STRING_ST, $3); }
1663
-	| DSTIP equalop MYSELF  { $$=mk_elem(	$2, DSTIP_O, 0, MYSELF_ST, 0); }
1664
-	| DSTIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1665
-	| DSTIP error { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1666
-	| SNDIP equalop ipnet {
1667
-		onsend_check("snd_ip");
1668
-		$$=mk_elem($2, SNDIP_O, 0, NET_ST, $3);
1669
-	}
1670
-	| SNDIP strop STRING	{
1671
-		onsend_check("snd_ip");
1672
-		s_tmp.s=$3;
1673
-		s_tmp.len=strlen($3);
1674
-		ip_tmp=str2ip(&s_tmp);
1675
-	#ifdef USE_IPV6
1676
-		if (ip_tmp==0)
1677
-			ip_tmp=str2ip6(&s_tmp);
1678
-	#endif /* USE_IPV6 */
1679
-		if (ip_tmp) {
1680
-			$$=mk_elem($2, SNDIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1681
-		} else {
1682
-			$$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3);
1683
-		}
1684
-	}
1685
-	| SNDIP strop host	{
1686
-		onsend_check("snd_ip");
1687
-		$$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3);
1688
-	}
1689
-	| SNDIP equalop attr_id_val	{
1690
-		onsend_check("snd_ip");
1691
-	    $$=mk_elem($2, SNDIP_O, 0, AVP_ST, (void*)$3 ); 
1692
-	}
1693
-	| SNDIP equalop MYSELF  {
1694
-		onsend_check("snd_ip");
1695
-		$$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0);
1696
-	}
1697
-	| SNDIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1698
-	| SNDIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1699
-	| TOIP equalop ipnet	{
1700
-		onsend_check("to_ip");
1701
-		$$=mk_elem($2, TOIP_O, 0, NET_ST, $3);
1702
-	}
1703
-	| TOIP strop STRING	{
1704
-		onsend_check("to_ip");
1705
-		s_tmp.s=$3;
1706
-		s_tmp.len=strlen($3);
1707
-		ip_tmp=str2ip(&s_tmp);
1708
-	#ifdef USE_IPV6
1709
-		if (ip_tmp==0)
1710
-			ip_tmp=str2ip6(&s_tmp);
1711
-	#endif /* USE_IPV6 */
1712
-		if (ip_tmp) {
1713
-			$$=mk_elem($2, TOIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1714
-		} else {
1715
-			$$=mk_elem($2, TOIP_O, 0, STRING_ST, $3);
1563
+	| METHOD error	
1564
+		{ $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
1565
+	| uri_type strop %prec EQUAL_T rval_expr
1566
+		{$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
1567
+	| uri_type strop %prec EQUAL_T MYSELF
1568
+		{$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1569
+	| uri_type strop %prec EQUAL_T error
1570
+		{ $$=0; yyerror("string or MYSELF expected"); }
1571
+	| uri_type error
1572
+		{ $$=0; yyerror("invalid operator, == , != or =~ expected"); }
1573
+	| eint_op cmpop %prec GT rval_expr { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1574
+	| eint_op equalop %prec EQUAL_T rval_expr 
1575
+		{ $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1576
+	| eint_op cmpop error   { $$=0; yyerror("number expected"); }
1577
+	| eint_op equalop error { $$=0; yyerror("number expected"); }
1578
+	| eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1579
+	| eip_op strop %prec EQUAL_T ipnet { $$=mk_elem($2, $1, 0, NET_ST, $3); }
1580
+	| eip_op strop %prec EQUAL_T rval_expr {
1581
+			s_tmp.s=0;
1582
+			$$=0;
1583
+			if (rve_is_constant($3)){
1584
+				i_tmp=rve_guess_type($3);
1585
+				if (i_tmp==RV_INT)
1586
+					yyerror("string expected");
1587
+				else if (i_tmp==RV_STR){
1588
+					if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
1589
+								(rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
1590
+						rval_destroy(rval_tmp);
1591
+						yyerror("bad rvalue expression");
1592
+					}else{
1593
+						rval_destroy(rval_tmp);
1594
+					}
1595
+				}else{
1596
+					yyerror("BUG: unexpected dynamic type");
1597
+				}
1598
+			}else{
1599
+					warn("non constant rvalue in ip comparison");
1600
+			}
1601
+			if (s_tmp.s){
1602
+				ip_tmp=str2ip(&s_tmp);
1603
+			#ifdef USE_IPV6
1604
+				if (ip_tmp==0)
1605
+					ip_tmp=str2ip6(&s_tmp);
1606
+			#endif
1607
+				pkg_free(s_tmp.s);
1608
+				if (ip_tmp) {
1609
+					$$=mk_elem($2, $1, 0, NET_ST, 
1610
+								mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1611
+				} else {
1612
+					$$=mk_elem($2, $1, 0, RVE_ST, $3);
1613
+				}
1614
+			}else{
1615
+				$$=mk_elem($2, $1, 0, RVE_ST, $3);
1616
+			}
1716 1617
 		}
1717
-	}
1718
-	| TOIP strop host	{
1719
-		onsend_check("to_ip");
1720
-		$$=mk_elem($2, TOIP_O, 0, STRING_ST, $3);
1721
-	}
1722
-	| TOIP equalop attr_id_val	{
1723
-		onsend_check("to_ip");
1724
-	    $$=mk_elem($2, TOIP_O, 0, AVP_ST, (void*)$3 ); 
1725
-	}
1726
-	| TOIP equalop MYSELF  {
1727
-		onsend_check("to_ip");
1728
-		$$=mk_elem($2, TOIP_O, 0, MYSELF_ST, 0);
1729
-	}
1730
-	| TOIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1731
-	| TOIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1732
-
1733
-	| MYSELF equalop uri_type	{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1734
-	| MYSELF equalop SRCIP  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0); }
1735
-	| MYSELF equalop DSTIP  { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0); }
1736
-	| MYSELF equalop SNDIP  {
1737
-		onsend_check("snd_ip");
1738
-		$$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0);
1739
-	}
1740
-	| MYSELF equalop TOIP  {
1741
-		onsend_check("to_ip");
1742
-		$$=mk_elem($2, TOIP_O, 0, MYSELF_ST, 0);
1743
-	}
1744
-	| MYSELF equalop error { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
1618
+	| eip_op strop %prec EQUAL_T host
1619
+		{ $$=mk_elem($2, $1, 0, STRING_ST, $3); }
1620
+	| eip_op strop %prec EQUAL_T MYSELF
1621
+		{ $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1622
+	| eip_op strop %prec EQUAL_T error
1623
+		{ $$=0; yyerror( "ip address or hostname expected" ); }
1624
+	| eip_op error
1625
+		{ $$=0; yyerror("invalid operator, ==, != or =~ expected");}
1626
+	
1627
+	| MYSELF equalop %prec EQUAL_T uri_type
1628
+		{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1629
+	| MYSELF equalop %prec EQUAL_T eip_op
1630
+		{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1631
+	| MYSELF equalop %prec EQUAL_T error
1632
+		{ $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
1745 1633
 	| MYSELF error	{ $$=0; yyerror ("invalid operator, == or != expected"); }
1746
-	| exp_stm	{ $$=mk_elem( NO_OP, ACTION_O, 0, ACTIONS_ST, $1);  }
1747
-	| NUMBER	{ $$=mk_elem( NO_OP, NUMBER_O, 0, NUMBER_ST, (void*)$1 ); }
1748
-
1749
-	| attr_id_any				{$$=mk_elem( NO_OP, AVP_O, (void*)$1, 0, 0); }
1750
-	| attr_id_val strop STRING	{$$=mk_elem( $2, AVP_O, (void*)$1, STRING_ST, $3); }
1751
-	| attr_id_val strop select_id	{$$=mk_elem( $2, AVP_O, (void*)$1, SELECT_ST, $3); }
1752
-	| attr_id_val intop NUMBER	{$$=mk_elem( $2, AVP_O, (void*)$1, NUMBER_ST, (void*)$3); }
1753
-	| attr_id_val binop NUMBER	{$$=mk_elem( $2, AVP_O, (void*)$1, NUMBER_ST, (void*)$3); }
1754
-	| attr_id_val strop attr_id_val {$$=mk_elem( $2, AVP_O, (void*)$1, AVP_ST, (void*)$3); }
1755
-	| attr_id_val intop attr_id_val {$$=mk_elem( $2, AVP_O, (void*)$1, AVP_ST, (void*)$3); }
1756
-
1757
-	| select_id                 { $$=mk_elem( NO_OP, SELECT_O, $1, 0, 0); }
1758
-	| select_id strop STRING    { $$=mk_elem( $2, SELECT_O, $1, STRING_ST, $3); }
1759
-	| select_id strop attr_id_val   { $$=mk_elem( $2, SELECT_O, $1, AVP_ST, (void*)$3); }
1760
-	| select_id strop select_id { $$=mk_elem( $2, SELECT_O, $1, SELECT_ST, $3); }
1634
+	;
1635
+/*
1636
+exp_elem2:
1637
+	rval_expr cmpop %prec GT rval_expr
1638
+		{ $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1639
+	|
1640
+	rval_expr equalop %prec EQUAL_T rval_expr
1641
+		{ $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1642
+	| rval_expr LOG_AND rval_expr
1643
+		{ $$=mk_exp_rve(LOGAND_OP, $1, $3);}
1644
+	| rval_expr LOG_OR rval_expr
1645
+		{ $$=mk_exp_rve(LOGOR_OP, $1, $3);}
1761 1646
 ;
1647
+*/
1648
+
1762 1649
 ipnet:
1763 1650
 	ip SLASH ip	{ $$=mk_net($1, $3); }
1764 1651
 	| ip SLASH NUMBER {
... ...
@@ -1775,20 +1664,29 @@ ipnet:
1775 1775
 	| ip	{ $$=mk_net_bitlen($1, $1->len*8); }
1776 1776
 	| ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
1777 1777
 	;
1778
-host_sep:
1779
-	DOT {$$=".";}
1780
-	| MINUS {$$="-"; }
1781
-	;
1782 1778
 
1783 1779
 host:
1784 1780
 	ID { $$=$1; }
1785
-	| host host_sep ID {
1781
+	| host DOT ID {
1786 1782
 		$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1787 1783
 		if ($$==0) {
1788 1784
 			LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1789 1785
 		} else {
1790 1786
 			memcpy($$, $1, strlen($1));
1791
-			$$[strlen($1)]=*$2;
1787
+			$$[strlen($1)]='.';
1788
+			memcpy($$+strlen($1)+1, $3, strlen($3));
1789
+			$$[strlen($1)+1+strlen($3)]=0;
1790
+		}
1791
+		pkg_free($1);
1792
+		pkg_free($3);
1793
+	}
1794
+	| host MINUS ID {
1795
+		$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1796
+		if ($$==0) {
1797
+			LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1798
+		} else {
1799
+			memcpy($$, $1, strlen($1));
1800
+			$$[strlen($1)]='-';
1792 1801
 			memcpy($$+strlen($1)+1, $3, strlen($3));
1793 1802
 			$$[strlen($1)+1+strlen($3)]=0;
1794 1803
 		}
... ...
@@ -1823,12 +1721,14 @@ fcmd:
1823 1823
 		}
1824 1824
 	}
1825 1825
 	;
1826
+/*
1826 1827
 exp_stm:
1827 1828
 	fcmd	{ $$=$1; }
1828 1829
 	| if_cmd	{ $$=$1; }
1829 1830
 	| assign_action { $$ = $1; }
1830 1831
 	| LBRACE actions RBRACE	{ $$=$2; }
1831 1832
 	;
1833
+*/
1832 1834
 stm:
1833 1835
 	action	{ $$=$1; }
1834 1836
 	| LBRACE actions RBRACE	{ $$=$2; }
... ...
@@ -1934,7 +1834,7 @@ attr_id:
1934 1934
 	attr_mark attr_spec { $$ = s_attr; }
1935 1935
 	;
1936 1936
 attr_id_num_idx:
1937
-	attr_mark attr_spec LBRACK NUMBER RBRACK {
1937
+	attr_mark attr_spec LBRACK intno RBRACK {
1938 1938
 		s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
1939 1939
 		s_attr->index = ($4<0?-$4:$4);
1940 1940
 		$$ = s_attr;
... ...
@@ -1950,10 +1850,12 @@ attr_id_ass:
1950 1950
 	attr_id
1951 1951
 	| attr_id_no_idx
1952 1952
 	;
1953
+/*
1953 1954
 attr_id_val:
1954 1955
 	attr_id
1955 1956
 	| attr_id_num_idx
1956 1957
 	;
1958
+*/
1957 1959
 attr_id_any:
1958 1960
 	attr_id
1959 1961
 	| attr_id_no_idx
... ...
@@ -2074,7 +1976,7 @@ lval: attr_id_ass {
2074 2074
 				}
2075 2075
 	;
2076 2076
 
2077
-rval: NUMBER			{$$=mk_rval_expr_v(RV_INT, (void*)$1); }
2077
+rval: intno			{$$=mk_rval_expr_v(RV_INT, (void*)$1); }
2078 2078
 	| STRING			{	s_tmp.s=$1; s_tmp.len=strlen($1);
2079 2079
 							$$=mk_rval_expr_v(RV_STR, &s_tmp); }
2080 2080
 	| attr_id_any		{$$=mk_rval_expr_v(RV_AVP, $1); pkg_free($1); }
... ...
@@ -2095,33 +1997,51 @@ rval: NUMBER			{$$=mk_rval_expr_v(RV_INT, (void*)$1); }
2095 2095
 						}
2096 2096
 	| select_id			{$$=mk_rval_expr_v(RV_SEL, $1); pkg_free($1); }
2097 2097
 	| fcmd				{$$=mk_rval_expr_v(RV_ACTION_ST, $1); }
2098
+	| LBRACE actions RBRACE	{$$=mk_rval_expr_v(RV_ACTION_ST, $2); }
2099
+	| LPAREN assign_action RPAREN	{$$=mk_rval_expr_v(RV_ACTION_ST, $2); }
2098 2100
 	//| exp 				{$$=mk_rval_expr_v(RV_BEXPR, $1);}
2099 2101
 	/* missing/TODO: RV_ACTION_ST */
2100 2102
 	;
2101 2103
 
2102 2104
 
2103
-rve_un_op: MINUS	{ $$=RVE_UMINUS_OP; }
2105
+rve_un_op: NOT	{ $$=RVE_LNOT_OP; }
2106
+		|  MINUS %prec NOT	{ $$=RVE_UMINUS_OP; } 
2104 2107
 		/* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
2105 2108
 	;
2106 2109
 
2110
+/*
2107 2111
 rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
2108 2112
 		|	MINUS		{ $$=RVE_MINUS_OP; }
2109 2113
 		|	STAR		{ $$=RVE_MUL_OP; }
2110
-		/* TODO: RVE_DIV_OP */
2114
+		|	SLASH		{ $$=RVE_DIV_OP; }
2111 2115
 	;
2112
-	
2113
-rval_expr: rval							{ $$=$1;
2116
+*/
2117
+
2118
+rval_expr: rval						{ $$=$1;
2114 2119
 											if ($$==0){
2115 2120
 												yyerror("out of memory\n");
2116 2121
 												YYABORT;
2117 2122
 											}
2118
-										}
2119
-		| LPAREN rval_expr RPAREN		{ $$=$2; }
2120
-		| rve_un_op rval_expr			{$$=mk_rval_expr1($1, $2); }
2121
-		| rval_expr rve_op rval_expr	{$$=mk_rval_expr2($2, $1, $3); }
2122
-	;
2123
-
2124
-assign_action: lval assign_op rval_expr	{ $$=mk_action($2, 2, LVAL_ST, $1, 
2123
+									}
2124
+		| rve_un_op %prec NOT rval_expr 	{$$=mk_rval_expr1($1, $2); }
2125
+		| rval_expr PLUS rval_expr	{$$=mk_rval_expr2(RVE_PLUS_OP, $1, $3); }
2126
+		| rval_expr MINUS rval_expr	{$$=mk_rval_expr2(RVE_MINUS_OP, $1, $3); }
2127
+		| rval_expr STAR rval_expr	{$$=mk_rval_expr2(RVE_MUL_OP, $1, $3); }
2128
+		| rval_expr SLASH rval_expr	{$$=mk_rval_expr2(RVE_DIV_OP, $1, $3); }
2129
+		| rval_expr BIN_OR rval_expr {$$=mk_rval_expr2(RVE_BOR_OP, $1,  $3); }
2130
+		| rval_expr BIN_AND rval_expr {$$=mk_rval_expr2(RVE_BAND_OP, $1,  $3);}
2131
+		| rval_expr cmpop %prec GT rval_expr { $$=mk_rval_expr2( $2, $1, $3);}
2132
+		| rval_expr equalop %prec EQUAL_T rval_expr
2133
+			{ $$=mk_rval_expr2( $2, $1, $3);}
2134
+		| rval_expr LOG_AND rval_expr
2135
+			{ $$=mk_rval_expr2(RVE_LAND_OP, $1, $3);}
2136
+		| rval_expr LOG_OR rval_expr
2137
+			{ $$=mk_rval_expr2(RVE_LOR_OP, $1, $3);}
2138
+		| LPAREN rval_expr RPAREN	{ $$=$2; }
2139
+		| exp_elem { $$=mk_rval_expr_v(RV_BEXPR, $1); }
2140
+		;
2141
+
2142
+assign_action: lval assign_op  rval_expr	{ $$=mk_action($2, 2, LVAL_ST, $1, 
2125 2143
 														 	  RVE_ST, $3);
2126 2144
 										}
2127 2145
 	;