core: added some binary operators
[sip-router] / cfg.y
1 /*
2  * $Id$
3  *
4  *  cfg grammar
5  *
6  * Copyright (C) 2001-2003 FhG Fokus
7  *
8  * This file is part of ser, a free SIP server.
9  *
10  * ser is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * For a license to use the ser software under conditions
16  * other than those described here, or to purchase support for this
17  * software, please contact iptel.org by e-mail at the following addresses:
18  *    info@iptel.org
19  *
20  * ser is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  */
29  /*
30  * History:
31  * ---------
32  * 2003-01-29  src_port added (jiri)
33  * 2003-01-23  mhomed added (jiri)
34  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
35  * 2003-03-19  Added support for route type in find_export (janakj)
36  * 2003-03-20  Regex support in modparam (janakj)
37  * 2003-04-01  added dst_port, proto , af (andrei)
38  * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
39  * 2003-04-12  added force_rport, chroot and wdir (andrei)
40  * 2003-04-15  added tcp_children, disable_tcp (andrei)
41  * 2003-04-22  strip_tail added (jiri)
42  * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify,
43  *              require_certificate added (andrei)
44  * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
45  * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
46  * 2003-10-10  added <,>,<=,>=, != operators support
47  *             added msg:len (andrei)
48  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49  * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
50  * 2003-10-24  converted to the new socket_info lists (andrei)
51  * 2003-10-28  added tcp_accept_aliases (andrei)
52  * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
53  * 2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
54  * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
55  * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
56  *             added MCAST_TTL (andrei)
57  * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
58  *              (andrei)
59  * 2004-10-19  added FROM_URI, TO_URI (andrei)
60  * 2004-11-30  added force_send_socket (andrei)
61  * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
62  *              (andrei)
63  * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
64  *             DNS_TRY_IPV6 (andrei)
65  * 2005-07-12  default onreply route added (andrei)
66  * 2005-11-16  fixed if (cond) cmd; (andrei)
67  * 2005-12-11  added onsend_route support, fcmd (filtered cmd),
68  *             snd_{ip,port,proto,af}, to_{ip,proto} (andrei)
69  * 2005-12-19  select framework (mma)
70  * 2006-01-06  AVP index support (mma)
71  * 2005-01-07  optional semicolon in statement, PARAM_STR&PARAM_STRING
72  * 2006-02-02  named flags support (andrei)
73  * 2006-02-06  named routes support (andrei)
74  * 2006-05-30  avp flags (tma)
75  * 2006-09-11  added dns cache (use, flags, ttls, mem ,gc) & dst blacklist
76  *              options (andrei)
77  * 2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
78  *              (vlada)
79  * 2007-02-09  separated command needed for tls-in-core and for tls in general
80  *              (andrei)
81  * 2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
82  *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
83  *              RT_TIMER2_POLICY (andrei)
84  * 2007-06-16  added DDNS_SRV_LB, DNS_TRY_NAPTR (andrei)
85  * 2007-09-10  introduced phone2tel option which allows NOT to consider
86  *             user=phone URIs as TEL URIs (jiri)
87  * 2007-10-10  added DNS_SEARCH_FMATCH (mma)
88  * 2007-11-28  added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT,
89  *              LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei)
90  * 2008-01-24  added cfg_var definition (Miklos)
91  * 2008-11-18  support for variable parameter module functions (andrei)
92  * 2007-12-03  support for generalised lvalues and rvalues:
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)
96  * 2009-01-26  case/switch() support (andrei)
97  * 2009-03-10  added SET_USERPHONE action (Miklos)
98  * 2009-05-04  switched if to rval_expr (andrei)
99  * 2010-01-10  init shm on first mod_param or route block;
100  *             added SHM_MEM_SZ (andrei)
101  * 2010-02-17  added blacklist imask (DST_BLST_*_IMASK) support (andrei)
102 */
103
104 %expect 6
105
106 %{
107
108 #include <stdlib.h>
109 #include <stdio.h>
110 #include <stdarg.h>
111 #include <sys/types.h>
112 #include <sys/socket.h>
113 #include <netinet/in.h>
114 #include <arpa/inet.h>
115 #include <string.h>
116 #include <errno.h>
117 #include "route_struct.h"
118 #include "globals.h"
119 #ifdef SHM_MEM
120 #include "shm_init.h"
121 #endif /* SHM_MEM */
122 #include "route.h"
123 #include "switch.h"
124 #include "dprint.h"
125 #include "sr_module.h"
126 #include "modparam.h"
127 #include "ip_addr.h"
128 #include "resolve.h"
129 #include "socket_info.h"
130 #include "name_alias.h"
131 #include "ut.h"
132 #include "dset.h"
133 #include "select.h"
134 #include "flags.h"
135 #include "tcp_init.h"
136 #include "tcp_options.h"
137 #include "sctp_options.h"
138 #include "pvar.h"
139 #include "lvalue.h"
140 #include "rvalue.h"
141 #include "sr_compat.h"
142 #include "msg_translator.h"
143
144 #include "ppcfg.h"
145 #include "config.h"
146 #include "cfg_core.h"
147 #include "cfg/cfg.h"
148 #ifdef CORE_TLS
149 #include "tls/tls_config.h"
150 #endif
151 #include "timer_ticks.h"
152
153 #ifdef DEBUG_DMALLOC
154 #include <dmalloc.h>
155 #endif
156
157 /* hack to avoid alloca usage in the generated C file (needed for compiler
158  with no built in alloca, like icc*/
159 #undef _ALLOCA_H
160
161 #define onsend_check(s) \
162         do{\
163                 if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\
164         }while(0)
165
166
167 #ifdef USE_DNS_CACHE
168         #define IF_DNS_CACHE(x) x
169 #else
170         #define IF_DNS_CACHE(x) warn("dns cache support not compiled in")
171 #endif
172
173 #ifdef USE_DNS_FAILOVER
174         #define IF_DNS_FAILOVER(x) x
175 #else
176         #define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in")
177 #endif
178
179 #ifdef USE_NAPTR
180         #define IF_NAPTR(x) x
181 #else
182         #define IF_NAPTR(x) warn("dns naptr support not compiled in")
183 #endif
184
185 #ifdef USE_DST_BLACKLIST
186         #define IF_DST_BLACKLIST(x) x
187 #else
188         #define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
189 #endif
190
191 #ifdef USE_STUN
192         #define IF_STUN(x) x
193 #else 
194         #define IF_STUN(x) warn("stun support not compiled in")
195 #endif
196
197 #ifdef USE_SCTP
198         #define IF_SCTP(x) x
199 #else
200         #define IF_SCTP(x) warn("sctp support not compiled in")
201 #endif
202
203 #ifdef USE_RAW_SOCKS
204         #define IF_RAW_SOCKS(x) x
205 #else
206         #define IF_RAW_SOCKS(x) warn("raw socket support not compiled in")
207 #endif
208
209
210 extern int yylex();
211 /* safer then using yytext which can be array or pointer */
212 extern char* yy_number_str;
213
214 static void yyerror(char* s, ...);
215 static void yyerror_at(struct cfg_pos* pos, char* s, ...);
216 static char* tmp;
217 static int i_tmp;
218 static unsigned u_tmp;
219 static struct socket_id* lst_tmp;
220 static struct name_lst*  nl_tmp;
221 static int rt;  /* Type of route block for find_export */
222 static str* str_tmp;
223 static str s_tmp;
224 static struct ip_addr* ip_tmp;
225 static struct avp_spec* s_attr;
226 static select_t sel;
227 static select_t* sel_ptr;
228 static pv_spec_t* pv_spec;
229 static struct action *mod_func_action;
230 static struct lvalue* lval_tmp;
231 static struct rvalue* rval_tmp;
232
233 static void warn(char* s, ...);
234 static void warn_at(struct cfg_pos* pos, char* s, ...);
235 static void get_cpos(struct cfg_pos* pos);
236 static struct rval_expr* mk_rve_rval(enum rval_type, void* v);
237 static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1);
238 static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
239                                                                         struct rval_expr* rve2);
240 static int rval_expr_int_check(struct rval_expr *rve);
241 static int warn_ct_rve(struct rval_expr *rve, char* name);
242 static struct socket_id* mk_listen_id(char*, int, int);
243 static struct name_lst* mk_name_lst(char* name, int flags);
244 static struct socket_id* mk_listen_id2(struct name_lst*, int, int);
245 static void free_name_lst(struct name_lst* lst);
246 static void free_socket_id_lst(struct socket_id* i);
247
248 static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re, 
249                                                                         struct action* a, int* err);
250 static int case_check_type(struct case_stms* stms);
251 static int case_check_default(struct case_stms* stms);
252 static int mod_f_params_pre_fixup(struct action* a);
253 static void free_mod_func_action(struct action* a);
254
255
256 extern int line;
257 extern int column;
258 extern int startcolumn;
259 extern int startline;
260 extern char *finame;
261
262 #define set_cfg_pos(x) \
263         do{\
264                 if(x) {\
265                 (x)->cline = line;\
266                 (x)->cfile = (finame!=0)?finame:((cfg_file!=0)?cfg_file:"default");\
267                 }\
268         }while(0)
269
270
271 %}
272
273 %union {
274         long intval;
275         unsigned long uval;
276         char* strval;
277         struct expr* expr;
278         struct action* action;
279         struct case_stms* case_stms;
280         struct net* ipnet;
281         struct ip_addr* ipaddr;
282         struct socket_id* sockid;
283         struct name_lst* name_l;
284         struct avp_spec* attr;
285         struct _pv_spec* pvar;
286         struct lvalue* lval;
287         struct rvalue* rval;
288         struct rval_expr* rv_expr;
289         select_t* select;
290 }
291
292 /* terminals */
293
294
295 /* keywords */
296 %token FORWARD
297 %token FORWARD_TCP
298 %token FORWARD_TLS
299 %token FORWARD_SCTP
300 %token FORWARD_UDP
301 %token SEND
302 %token SEND_TCP
303 %token EXIT
304 %token DROP
305 %token RETURN
306 %token BREAK
307 %token LOG_TOK
308 %token ERROR
309 %token ROUTE
310 %token ROUTE_FAILURE
311 %token ROUTE_ONREPLY
312 %token ROUTE_BRANCH
313 %token ROUTE_SEND
314 %token ROUTE_EVENT
315 %token EXEC
316 %token SET_HOST
317 %token SET_HOSTPORT
318 %token SET_HOSTPORTTRANS
319 %token PREFIX
320 %token STRIP
321 %token STRIP_TAIL
322 %token SET_USERPHONE
323 %token APPEND_BRANCH
324 %token SET_USER
325 %token SET_USERPASS
326 %token SET_PORT
327 %token SET_URI
328 %token REVERT_URI
329 %token FORCE_RPORT
330 %token ADD_LOCAL_RPORT
331 %token FORCE_TCP_ALIAS
332 %token UDP_MTU
333 %token UDP_MTU_TRY_PROTO
334 %token UDP4_RAW
335 %token UDP4_RAW_MTU
336 %token UDP4_RAW_TTL
337 %token IF
338 %token ELSE
339 %token SET_ADV_ADDRESS
340 %token SET_ADV_PORT
341 %token FORCE_SEND_SOCKET
342 %token SET_FWD_NO_CONNECT
343 %token SET_RPL_NO_CONNECT
344 %token SET_FWD_CLOSE
345 %token SET_RPL_CLOSE
346 %token SWITCH
347 %token CASE
348 %token DEFAULT
349 %token WHILE
350 %token CFG_SELECT
351 %token CFG_RESET
352 %token URIHOST
353 %token URIPORT
354 %token MAX_LEN
355 %token SETFLAG
356 %token RESETFLAG
357 %token ISFLAGSET
358 %token SETAVPFLAG
359 %token RESETAVPFLAG
360 %token ISAVPFLAGSET
361 %token METHOD
362 %token URI
363 %token FROM_URI
364 %token TO_URI
365 %token SRCIP
366 %token SRCPORT
367 %token DSTIP
368 %token DSTPORT
369 %token TOIP
370 %token TOPORT
371 %token SNDIP
372 %token SNDPORT
373 %token SNDPROTO
374 %token SNDAF
375 %token PROTO
376 %token AF
377 %token MYSELF
378 %token MSGLEN
379 %token UDP
380 %token TCP
381 %token TLS
382 %token SCTP
383
384 /* config vars. */
385 %token DEBUG_V
386 %token FORK
387 %token LOGSTDERROR
388 %token LOGFACILITY
389 %token LOGNAME
390 %token LISTEN
391 %token ALIAS
392 %token SR_AUTO_ALIASES
393 %token DNS
394 %token REV_DNS
395 %token DNS_TRY_IPV6
396 %token DNS_TRY_NAPTR
397 %token DNS_SRV_LB
398 %token DNS_UDP_PREF
399 %token DNS_TCP_PREF
400 %token DNS_TLS_PREF
401 %token DNS_SCTP_PREF
402 %token DNS_RETR_TIME
403 %token DNS_RETR_NO
404 %token DNS_SERVERS_NO
405 %token DNS_USE_SEARCH
406 %token DNS_SEARCH_FMATCH
407 %token DNS_CACHE_INIT
408 %token DNS_USE_CACHE
409 %token DNS_USE_FAILOVER
410 %token DNS_CACHE_FLAGS
411 %token DNS_CACHE_NEG_TTL
412 %token DNS_CACHE_MIN_TTL
413 %token DNS_CACHE_MAX_TTL
414 %token DNS_CACHE_MEM
415 %token DNS_CACHE_GC_INT
416 %token DNS_CACHE_DEL_NONEXP
417 /*blacklist*/
418 %token DST_BLST_INIT
419 %token USE_DST_BLST
420 %token DST_BLST_MEM
421 %token DST_BLST_TTL
422 %token DST_BLST_GC_INT
423 %token DST_BLST_UDP_IMASK
424 %token DST_BLST_TCP_IMASK
425 %token DST_BLST_TLS_IMASK
426 %token DST_BLST_SCTP_IMASK
427
428 %token PORT
429 %token STAT
430 %token CHILDREN
431 %token CHECK_VIA
432 %token PHONE2TEL
433 %token SYN_BRANCH
434 %token MEMLOG
435 %token MEMDBG
436 %token MEMSUM
437 %token CORELOG
438 %token SIP_WARNING
439 %token SERVER_SIGNATURE
440 %token SERVER_HEADER
441 %token USER_AGENT_HEADER
442 %token REPLY_TO_VIA
443 %token LOADMODULE
444 %token LOADPATH
445 %token MODPARAM
446 %token MAXBUFFER
447 %token USER
448 %token GROUP
449 %token CHROOT
450 %token WDIR
451 %token MHOMED
452 %token DISABLE_TCP
453 %token TCP_ACCEPT_ALIASES
454 %token TCP_CHILDREN
455 %token TCP_CONNECT_TIMEOUT
456 %token TCP_SEND_TIMEOUT
457 %token TCP_CON_LIFETIME
458 %token TCP_POLL_METHOD
459 %token TCP_MAX_CONNECTIONS
460 %token TCP_NO_CONNECT
461 %token TCP_SOURCE_IPV4
462 %token TCP_SOURCE_IPV6
463 %token TCP_OPT_FD_CACHE
464 %token TCP_OPT_BUF_WRITE
465 %token TCP_OPT_CONN_WQ_MAX
466 %token TCP_OPT_WQ_MAX
467 %token TCP_OPT_RD_BUF
468 %token TCP_OPT_WQ_BLK
469 %token TCP_OPT_DEFER_ACCEPT
470 %token TCP_OPT_DELAYED_ACK
471 %token TCP_OPT_SYNCNT
472 %token TCP_OPT_LINGER2
473 %token TCP_OPT_KEEPALIVE
474 %token TCP_OPT_KEEPIDLE
475 %token TCP_OPT_KEEPINTVL
476 %token TCP_OPT_KEEPCNT
477 %token TCP_OPT_CRLF_PING
478 %token TCP_OPT_ACCEPT_NO_CL
479 %token DISABLE_TLS
480 %token ENABLE_TLS
481 %token TLSLOG
482 %token TLS_PORT_NO
483 %token TLS_METHOD
484 %token TLS_HANDSHAKE_TIMEOUT
485 %token TLS_SEND_TIMEOUT
486 %token SSLv23
487 %token SSLv2
488 %token SSLv3
489 %token TLSv1
490 %token TLS_VERIFY
491 %token TLS_REQUIRE_CERTIFICATE
492 %token TLS_CERTIFICATE
493 %token TLS_PRIVATE_KEY
494 %token TLS_CA_LIST
495 %token DISABLE_SCTP
496 %token ENABLE_SCTP
497 %token SCTP_CHILDREN
498 %token SCTP_SOCKET_RCVBUF
499 %token SCTP_SOCKET_SNDBUF
500 %token SCTP_AUTOCLOSE
501 %token SCTP_SEND_TTL
502 %token SCTP_SEND_RETRIES
503 %token SCTP_ASSOC_TRACKING
504 %token SCTP_ASSOC_REUSE
505 %token SCTP_MAX_ASSOCS
506 %token SCTP_SRTO_INITIAL
507 %token SCTP_SRTO_MAX
508 %token SCTP_SRTO_MIN
509 %token SCTP_ASOCMAXRXT
510 %token SCTP_INIT_MAX_ATTEMPTS
511 %token SCTP_INIT_MAX_TIMEO
512 %token SCTP_HBINTERVAL
513 %token SCTP_PATHMAXRXT
514 %token SCTP_SACK_DELAY
515 %token SCTP_SACK_FREQ
516 %token SCTP_MAX_BURST
517 %token ADVERTISED_ADDRESS
518 %token ADVERTISED_PORT
519 %token DISABLE_CORE
520 %token OPEN_FD_LIMIT
521 %token SHM_MEM_SZ
522 %token SHM_FORCE_ALLOC
523 %token MLOCK_PAGES
524 %token REAL_TIME
525 %token RT_PRIO
526 %token RT_POLICY
527 %token RT_TIMER1_PRIO
528 %token RT_TIMER1_POLICY
529 %token RT_TIMER2_PRIO
530 %token RT_TIMER2_POLICY
531 %token MCAST_LOOPBACK
532 %token MCAST_TTL
533 %token TOS
534 %token PMTU_DISCOVERY
535 %token KILL_TIMEOUT
536 %token MAX_WLOOPS
537 %token CFG_DESCRIPTION
538 %token SERVER_ID
539
540 %token FLAGS_DECL
541 %token AVPFLAGS_DECL
542
543 %token ATTR_MARK
544 %token SELECT_MARK
545 %token ATTR_FROM
546 %token ATTR_TO
547 %token ATTR_FROMURI
548 %token ATTR_TOURI
549 %token ATTR_FROMUSER
550 %token ATTR_TOUSER
551 %token ATTR_FROMDOMAIN
552 %token ATTR_TODOMAIN
553 %token ATTR_GLOBAL
554 %token ADDEQ
555
556
557 %token STUN_REFRESH_INTERVAL
558 %token STUN_ALLOW_STUN
559 %token STUN_ALLOW_FP
560
561 /*pre-processor*/
562 %token SUBST
563
564 /* operators, C like precedence */
565 %right EQUAL
566 %left LOG_OR
567 %left LOG_AND
568 %left BIN_OR
569 %left BIN_AND
570 %left BIN_XOR
571 %left BIN_LSHIFT
572 %left BIN_RSHIFT
573 %left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
574 %left GT LT GTE LTE
575 %left PLUS MINUS
576 %left STAR SLASH MODULO
577 %right NOT UNARY BIN_NOT
578 %right DEFINED
579 %right INTCAST STRCAST
580 %left DOT
581
582 /* no precedence, they use () */
583 %token STRLEN
584 %token STREMPTY
585
586 /* values */
587 %token <intval> NUMBER
588 %token <strval> ID
589 %token <strval> NUM_ID
590 %token <strval> STRING
591 %token <strval> IPV6ADDR
592 %token <strval> PVAR
593 /* not clear yet if this is an avp or pvar */
594 %token <strval> AVP_OR_PVAR
595 %token <strval> EVENT_RT_NAME
596
597 /* other */
598 %token COMMA
599 %token SEMICOLON
600 %token RPAREN
601 %token LPAREN
602 %token LBRACE
603 %token RBRACE
604 %token LBRACK
605 %token RBRACK
606 %token CR
607 %token COLON
608
609
610 /*non-terminals */
611 /*%type <expr> exp */
612 %type <expr> exp_elem
613 %type <intval> intno eint_op eint_op_onsend
614 %type <intval> eip_op eip_op_onsend
615 %type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
616 %type <action> switch_cmd while_cmd ret_cmd
617 %type <case_stms> single_case case_stms
618 %type <ipaddr> ipv4 ipv6 ipv6addr ip
619 %type <ipnet> ipnet
620 %type <strval> host host_or_if host_if_id
621 %type <strval> listen_id
622 %type <name_l> listen_id_lst
623 %type <name_l> listen_id2
624 %type <sockid>  id_lst
625 %type <sockid>  phostport
626 %type <sockid>  listen_phostport
627 %type <intval> proto port
628 %type <intval> equalop strop cmpop rve_cmpop rve_equalop
629 %type <intval> uri_type
630 %type <attr> attr_id
631 %type <attr> attr_id_num_idx
632 %type <attr> attr_id_no_idx
633 %type <attr> attr_id_ass
634 /*%type <attr> attr_id_val*/
635 %type <attr> attr_id_any
636 %type <attr> attr_id_any_str
637 %type <pvar> pvar
638 %type <lval> lval
639 %type <rv_expr> rval rval_expr ct_rval
640 %type <lval> avp_pvar
641 /* %type <intval> class_id */
642 %type <intval> assign_op
643 %type <select> select_id
644 %type <strval>  flag_name;
645 %type <strval>  route_name;
646 %type <intval> avpflag_oper
647 %type <intval> rve_un_op
648 %type <strval> cfg_var_id
649 /* %type <intval> rve_op */
650
651 /*%type <route_el> rules;
652   %type <route_el> rule;
653 */
654
655 %%
656
657
658 cfg:
659         statements
660         ;
661 statements:
662         statements statement {}
663         | statement {}
664         | statements error { yyerror(""); YYABORT;}
665         ;
666 statement:
667         assign_stm
668         | preprocess_stm
669         | flags_decl
670         | avpflags_decl
671         | module_stm
672         | {rt=REQUEST_ROUTE;} route_stm
673         | {rt=FAILURE_ROUTE;} failure_route_stm
674         | onreply_route_stm
675         | {rt=BRANCH_ROUTE;} branch_route_stm
676         | {rt=ONSEND_ROUTE;}   send_route_stm
677         | {rt=EVENT_ROUTE;}   event_route_stm
678         | SEMICOLON     /* null statement */
679         | CR    /* null statement*/
680         ;
681 listen_id:
682         ip {
683                 if ($1){
684                         tmp=ip_addr2a($1);
685                         if (tmp==0) {
686                                 LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
687                                                 "address.\n");
688                                 $$=0;
689                         } else {
690                                 $$=pkg_malloc(strlen(tmp)+1);
691                                 if ($$==0) {
692                                         LOG(L_CRIT, "ERROR: cfg. parser: out of "
693                                                         "memory.\n");
694                                 } else {
695                                         strncpy($$, tmp, strlen(tmp)+1);
696                                 }
697                         }
698                 }
699         }
700         | STRING {
701                 $$=pkg_malloc(strlen($1)+1);
702                 if ($$==0) {
703                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
704                                                 "memory.\n");
705                 } else {
706                                 strncpy($$, $1, strlen($1)+1);
707                 }
708         }
709         | host_or_if {
710                 if ($1){
711                         $$=pkg_malloc(strlen($1)+1);
712                         if ($$==0) {
713                                         LOG(L_CRIT, "ERROR: cfg. parser: out of "
714                                                         "memory.\n");
715                         } else {
716                                         strncpy($$, $1, strlen($1)+1);
717                         }
718                 }
719         }
720         ;
721
722
723 listen_id_lst:
724         listen_id       { $$=mk_name_lst($1, SI_IS_MHOMED); }
725         | listen_id COMMA listen_id_lst { $$=mk_name_lst($1, SI_IS_MHOMED); 
726                                                                                 if ($$) $$->next=$3;
727                                                                         }
728         ;
729
730 listen_id2:
731         LPAREN listen_id_lst RPAREN { $$=$2; }
732         | listen_id     { $$=mk_name_lst($1, 0); }
733         ;
734
735 proto:
736         UDP     { $$=PROTO_UDP; }
737         | TCP   { $$=PROTO_TCP; }
738         | TLS   { $$=PROTO_TLS; }
739         | SCTP  { $$=PROTO_SCTP; }
740         | STAR  { $$=0; }
741         ;
742 port:
743         NUMBER  { $$=$1; }
744         | STAR  { $$=0; }
745 ;
746 phostport:
747         listen_id               { $$=mk_listen_id($1, 0, 0); }
748         | listen_id COLON port  { $$=mk_listen_id($1, 0, $3); }
749         | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
750         | proto COLON listen_id COLON port      { $$=mk_listen_id($3, $1, $5);}
751         | listen_id COLON error { $$=0; yyerror(" port number expected"); }
752         ;
753
754 listen_phostport:
755         listen_id2              { $$=mk_listen_id2($1, 0, 0); }
756         | listen_id2 COLON port { $$=mk_listen_id2($1, 0, $3); }
757         | proto COLON listen_id2        { $$=mk_listen_id2($3, $1, 0); }
758         | proto COLON listen_id2 COLON port     { $$=mk_listen_id2($3, $1, $5);}
759         | listen_id2 COLON error { $$=0; yyerror(" port number expected"); }
760         ;
761
762 id_lst:
763         listen_phostport                {  $$=$1 ; }
764         | listen_phostport id_lst       { $$=$1;  if ($$) $$->next=$2; }
765         ;
766
767 intno: NUMBER
768         |  MINUS NUMBER %prec UNARY { $$=-$2; }
769         ;
770
771 flags_decl:             FLAGS_DECL      flag_list
772                         |       FLAGS_DECL error { yyerror("flag list expected\n"); }
773 ;
774 flag_list:              flag_spec
775                         |       flag_spec COMMA flag_list
776 ;
777
778 flag_spec:              flag_name       { if (register_flag($1,-1)<0)
779                                                                 yyerror("register flag failed");
780                                                 }
781                         |       flag_name COLON NUMBER {
782                                                 if (register_flag($1, $3)<0)
783                                                                 yyerror("register flag failed");
784                                                                                 }
785 ;
786
787 flag_name:              STRING  { $$=$1; }
788                         |       ID              { $$=$1; }
789 ;
790
791 avpflags_decl:
792         AVPFLAGS_DECL avpflag_list
793         | AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
794         ;
795 avpflag_list:
796         avpflag_spec
797         | avpflag_spec COMMA avpflag_list
798         ;
799 avpflag_spec:
800         flag_name {
801                 if (register_avpflag($1)==0)
802                         yyerror("cannot declare avpflag");
803         }
804         ;
805 assign_stm:
806         DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
807         | DEBUG_V EQUAL error  { yyerror("number  expected"); }
808         | FORK  EQUAL NUMBER { dont_fork= ! $3; }
809         | FORK  EQUAL error  { yyerror("boolean value expected"); }
810         | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
811         | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
812         | LOGFACILITY EQUAL ID {
813                 if ( (i_tmp=str2facility($3))==-1)
814                         yyerror("bad facility (see syslog(3) man page)");
815                 if (!config_check)
816                         default_core_cfg.log_facility=i_tmp;
817         }
818         | LOGFACILITY EQUAL error { yyerror("ID expected"); }
819         | LOGNAME EQUAL STRING { log_name=$3; }
820         | LOGNAME EQUAL error { yyerror("string value expected"); }
821         | DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
822         | DNS EQUAL error { yyerror("boolean value expected"); }
823         | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
824         | REV_DNS EQUAL error { yyerror("boolean value expected"); }
825         | DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
826         | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
827         | DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
828         | DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
829         | DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
830         | DNS_SRV_LB error { yyerror("boolean value expected"); }
831         | DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
832         | DNS_UDP_PREF error { yyerror("number expected"); }
833         | DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
834         | DNS_TCP_PREF error { yyerror("number expected"); }
835         | DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
836         | DNS_TLS_PREF error { yyerror("number expected"); }
837         | DNS_SCTP_PREF EQUAL intno { 
838                                                                 IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
839         | DNS_SCTP_PREF error { yyerror("number expected"); }
840         | DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
841         | DNS_RETR_TIME error { yyerror("number expected"); }
842         | DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
843         | DNS_RETR_NO error { yyerror("number expected"); }
844         | DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
845         | DNS_SERVERS_NO error { yyerror("number expected"); }
846         | DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
847         | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
848         | DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
849         | DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
850         | DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
851         | DNS_CACHE_INIT error { yyerror("boolean value expected"); }
852         | DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
853         | DNS_USE_CACHE error { yyerror("boolean value expected"); }
854         | DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
855         | DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
856         | DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
857         | DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
858         | DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
859         | DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
860         | DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
861         | DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
862         | DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
863         | DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
864         | DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
865         | DNS_CACHE_MEM error { yyerror("boolean value expected"); }
866         | DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
867         | DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
868         | DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
869         | DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
870         | DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
871         | DST_BLST_INIT error { yyerror("boolean value expected"); }
872         | USE_DST_BLST EQUAL NUMBER {
873                 IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3);
874         }
875         | USE_DST_BLST error { yyerror("boolean value expected"); }
876         | DST_BLST_MEM EQUAL NUMBER {
877                 IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); 
878         }
879         | DST_BLST_MEM error { yyerror("boolean value expected"); }
880         | DST_BLST_TTL EQUAL NUMBER {
881                 IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3);
882         }
883         | DST_BLST_TTL error { yyerror("boolean value expected"); }
884         | DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
885         | DST_BLST_GC_INT error { yyerror("boolean value expected"); }
886         | DST_BLST_UDP_IMASK EQUAL NUMBER {
887                 IF_DST_BLACKLIST(default_core_cfg.blst_udp_imask=$3);
888         }
889         | DST_BLST_UDP_IMASK error { yyerror("number(flags) expected"); }
890         | DST_BLST_TCP_IMASK EQUAL NUMBER {
891                 IF_DST_BLACKLIST(default_core_cfg.blst_tcp_imask=$3);
892         }
893         | DST_BLST_TCP_IMASK error { yyerror("number(flags) expected"); }
894         | DST_BLST_TLS_IMASK EQUAL NUMBER {
895                 IF_DST_BLACKLIST(default_core_cfg.blst_tls_imask=$3);
896         }
897         | DST_BLST_TLS_IMASK error { yyerror("number(flags) expected"); }
898         | DST_BLST_SCTP_IMASK EQUAL NUMBER {
899                 IF_DST_BLACKLIST(default_core_cfg.blst_sctp_imask=$3);
900         }
901         | DST_BLST_SCTP_IMASK error { yyerror("number(flags) expected"); }
902         | PORT EQUAL NUMBER   { port_no=$3; }
903         | STAT EQUAL STRING {
904                 #ifdef STATS
905                                 stat_file=$3;
906                 #endif
907         }
908         | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
909         | MAXBUFFER EQUAL error { yyerror("number expected"); }
910         | PORT EQUAL error    { yyerror("number expected"); }
911         | CHILDREN EQUAL NUMBER { children_no=$3; }
912         | CHILDREN EQUAL error { yyerror("number expected"); }
913         | CHECK_VIA EQUAL NUMBER { check_via=$3; }
914         | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
915         | PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
916         | PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
917         | SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
918         | SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
919         | MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
920         | MEMLOG EQUAL error { yyerror("int value expected"); }
921         | MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
922         | MEMDBG EQUAL error { yyerror("int value expected"); }
923         | MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
924         | MEMSUM EQUAL error { yyerror("int value expected"); }
925         | CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
926         | CORELOG EQUAL error { yyerror("int value expected"); }
927         | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
928         | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
929         | USER EQUAL STRING     {
930                 if (shm_initialized())
931                         yyerror("user must be before any modparam or the"
932                                         " route blocks");
933                 else if (user==0)
934                         user=$3; 
935         }
936         | USER EQUAL ID         {
937                 if (shm_initialized())
938                         yyerror("user must be before any modparam or the"
939                                         " route blocks");
940                 else if (user==0)
941                         user=$3;
942         }
943         | USER EQUAL error      { yyerror("string value expected"); }
944         | GROUP EQUAL STRING     { group=$3; }
945         | GROUP EQUAL ID         { group=$3; }
946         | GROUP EQUAL error      { yyerror("string value expected"); }
947         | CHROOT EQUAL STRING     { chroot_dir=$3; }
948         | CHROOT EQUAL ID         { chroot_dir=$3; }
949         | CHROOT EQUAL error      { yyerror("string value expected"); }
950         | WDIR EQUAL STRING     { working_dir=$3; }
951         | WDIR EQUAL ID         { working_dir=$3; }
952         | WDIR EQUAL error      { yyerror("string value expected"); }
953         | MHOMED EQUAL NUMBER { mhomed=$3; }
954         | MHOMED EQUAL error { yyerror("boolean value expected"); }
955         | DISABLE_TCP EQUAL NUMBER {
956                 #ifdef USE_TCP
957                         tcp_disable=$3;
958                 #else
959                         warn("tcp support not compiled in");
960                 #endif
961         }
962         | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
963         | TCP_ACCEPT_ALIASES EQUAL NUMBER {
964                 #ifdef USE_TCP
965                         tcp_default_cfg.accept_aliases=$3;
966                 #else
967                         warn("tcp support not compiled in");
968                 #endif
969         }
970         | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
971         | TCP_CHILDREN EQUAL NUMBER {
972                 #ifdef USE_TCP
973                         tcp_children_no=$3;
974                 #else
975                         warn("tcp support not compiled in");
976                 #endif
977         }
978         | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
979         | TCP_CONNECT_TIMEOUT EQUAL intno {
980                 #ifdef USE_TCP
981                         tcp_default_cfg.connect_timeout_s=$3;
982                 #else
983                         warn("tcp support not compiled in");
984                 #endif
985         }
986         | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
987         | TCP_SEND_TIMEOUT EQUAL intno {
988                 #ifdef USE_TCP
989                         tcp_default_cfg.send_timeout=S_TO_TICKS($3);
990                 #else
991                         warn("tcp support not compiled in");
992                 #endif
993         }
994         | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
995         | TCP_CON_LIFETIME EQUAL intno {
996                 #ifdef USE_TCP
997                         if ($3<0)
998                                 tcp_default_cfg.con_lifetime=-1;
999                         else
1000                                 tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
1001                 #else
1002                         warn("tcp support not compiled in");
1003                 #endif
1004         }
1005         | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
1006         | TCP_POLL_METHOD EQUAL ID {
1007                 #ifdef USE_TCP
1008                         tcp_poll_method=get_poll_type($3);
1009                         if (tcp_poll_method==POLL_NONE) {
1010                                 LOG(L_CRIT, "bad poll method name:"
1011                                                 " %s\n, try one of %s.\n",
1012                                                 $3, poll_support);
1013                                 yyerror("bad tcp_poll_method "
1014                                                 "value");
1015                         }
1016                 #else
1017                         warn("tcp support not compiled in");
1018                 #endif
1019         }
1020         | TCP_POLL_METHOD EQUAL STRING {
1021                 #ifdef USE_TCP
1022                         tcp_poll_method=get_poll_type($3);
1023                         if (tcp_poll_method==POLL_NONE) {
1024                                 LOG(L_CRIT, "bad poll method name:"
1025                                                 " %s\n, try one of %s.\n",
1026                                                 $3, poll_support);
1027                                 yyerror("bad tcp_poll_method "
1028                                                 "value");
1029                         }
1030                 #else
1031                         warn("tcp support not compiled in");
1032                 #endif
1033         }
1034         | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
1035         | TCP_MAX_CONNECTIONS EQUAL NUMBER {
1036                 #ifdef USE_TCP
1037                         tcp_max_connections=$3;
1038                 #else
1039                         warn("tcp support not compiled in");
1040                 #endif
1041         }
1042         | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
1043         | TCP_NO_CONNECT EQUAL NUMBER {
1044                 #ifdef USE_TCP
1045                         tcp_default_cfg.no_connect=$3;
1046                 #else
1047                         warn("tcp support not compiled in");
1048                 #endif
1049         }
1050         | TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
1051         | TCP_SOURCE_IPV4 EQUAL ipv4 {
1052                 #ifdef USE_TCP
1053                         if (tcp_set_src_addr($3)<0)
1054                                 warn("tcp_source_ipv4 failed");
1055                 #else
1056                         warn("tcp support not compiled in");
1057                 #endif
1058                 pkg_free($3);
1059         }
1060         | TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
1061         | TCP_SOURCE_IPV6 EQUAL ipv6 {
1062                 #ifdef USE_TCP
1063                         #ifdef USE_IPV6
1064                                 if (tcp_set_src_addr($3)<0)
1065                                         warn("tcp_source_ipv6 failed");
1066                         #else
1067                                 warn("IPv6 support not compiled in");
1068                         #endif
1069                 #else
1070                         warn("tcp support not compiled in");
1071                 #endif
1072                 pkg_free($3);
1073         }
1074         | TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
1075         | TCP_OPT_FD_CACHE EQUAL NUMBER {
1076                 #ifdef USE_TCP
1077                         tcp_default_cfg.fd_cache=$3;
1078                 #else
1079                         warn("tcp support not compiled in");
1080                 #endif
1081         }
1082         | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
1083         | TCP_OPT_BUF_WRITE EQUAL NUMBER {
1084                 #ifdef USE_TCP
1085                         tcp_default_cfg.async=$3;
1086                 #else
1087                         warn("tcp support not compiled in");
1088                 #endif
1089         }
1090         | TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
1091         | TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
1092                 #ifdef USE_TCP
1093                         tcp_default_cfg.tcpconn_wq_max=$3;
1094                 #else
1095                         warn("tcp support not compiled in");
1096                 #endif
1097         }
1098         | TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
1099         | TCP_OPT_WQ_MAX EQUAL NUMBER {
1100                 #ifdef USE_TCP
1101                         tcp_default_cfg.tcp_wq_max=$3;
1102                 #else
1103                         warn("tcp support not compiled in");
1104                 #endif
1105         }
1106         | TCP_OPT_WQ_MAX error { yyerror("number expected"); }
1107         | TCP_OPT_RD_BUF EQUAL NUMBER {
1108                 #ifdef USE_TCP
1109                         tcp_default_cfg.rd_buf_size=$3;
1110                 #else
1111                         warn("tcp support not compiled in");
1112                 #endif
1113         }
1114         | TCP_OPT_RD_BUF error { yyerror("number expected"); }
1115         | TCP_OPT_WQ_BLK EQUAL NUMBER {
1116                 #ifdef USE_TCP
1117                         tcp_default_cfg.wq_blk_size=$3;
1118                 #else
1119                         warn("tcp support not compiled in");
1120                 #endif
1121         }
1122         | TCP_OPT_WQ_BLK error { yyerror("number expected"); }
1123         | TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
1124                 #ifdef USE_TCP
1125                         tcp_default_cfg.defer_accept=$3;
1126                 #else
1127                         warn("tcp support not compiled in");
1128                 #endif
1129         }
1130         | TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
1131         | TCP_OPT_DELAYED_ACK EQUAL NUMBER {
1132                 #ifdef USE_TCP
1133                         tcp_default_cfg.delayed_ack=$3;
1134                 #else
1135                         warn("tcp support not compiled in");
1136                 #endif
1137         }
1138         | TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
1139         | TCP_OPT_SYNCNT EQUAL NUMBER {
1140                 #ifdef USE_TCP
1141                         tcp_default_cfg.syncnt=$3;
1142                 #else
1143                         warn("tcp support not compiled in");
1144                 #endif
1145         }
1146         | TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
1147         | TCP_OPT_LINGER2 EQUAL NUMBER {
1148                 #ifdef USE_TCP
1149                         tcp_default_cfg.linger2=$3;
1150                 #else
1151                         warn("tcp support not compiled in");
1152                 #endif
1153         }
1154         | TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
1155         | TCP_OPT_KEEPALIVE EQUAL NUMBER {
1156                 #ifdef USE_TCP
1157                         tcp_default_cfg.keepalive=$3;
1158                 #else
1159                         warn("tcp support not compiled in");
1160                 #endif
1161         }
1162         | TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
1163         | TCP_OPT_KEEPIDLE EQUAL NUMBER {
1164                 #ifdef USE_TCP
1165                         tcp_default_cfg.keepidle=$3;
1166                 #else
1167                         warn("tcp support not compiled in");
1168                 #endif
1169         }
1170         | TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
1171         | TCP_OPT_KEEPINTVL EQUAL NUMBER {
1172                 #ifdef USE_TCP
1173                         tcp_default_cfg.keepintvl=$3;
1174                 #else
1175                         warn("tcp support not compiled in");
1176                 #endif
1177         }
1178         | TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
1179         | TCP_OPT_KEEPCNT EQUAL NUMBER {
1180                 #ifdef USE_TCP
1181                         tcp_default_cfg.keepcnt=$3;
1182                 #else
1183                         warn("tcp support not compiled in");
1184                 #endif
1185         }
1186         | TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
1187         | TCP_OPT_CRLF_PING EQUAL NUMBER {
1188                 #ifdef USE_TCP
1189                         tcp_default_cfg.crlf_ping=$3;
1190                 #else
1191                         warn("tcp support not compiled in");
1192                 #endif
1193         }
1194         | TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
1195         | TCP_OPT_ACCEPT_NO_CL EQUAL NUMBER {
1196                 #ifdef USE_TCP
1197                         tcp_default_cfg.accept_no_cl=$3;
1198                 #else
1199                         warn("tcp support not compiled in");
1200                 #endif
1201         }
1202         | TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
1203         | DISABLE_TLS EQUAL NUMBER {
1204                 #ifdef USE_TLS
1205                         tls_disable=$3;
1206                 #else
1207                         warn("tls support not compiled in");
1208                 #endif
1209         }
1210         | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1211         | ENABLE_TLS EQUAL NUMBER {
1212                 #ifdef USE_TLS
1213                         tls_disable=!($3);
1214                 #else
1215                         warn("tls support not compiled in");
1216                 #endif
1217         }
1218         | ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1219         | TLSLOG EQUAL NUMBER {
1220                 #ifdef CORE_TLS
1221                         tls_log=$3;
1222                 #else
1223                         warn("tls-in-core support not compiled in");
1224                 #endif
1225         }
1226         | TLSLOG EQUAL error { yyerror("int value expected"); }
1227         | TLS_PORT_NO EQUAL NUMBER {
1228                 #ifdef USE_TLS
1229                         tls_port_no=$3;
1230                 #else
1231                         warn("tls support not compiled in");
1232                 #endif
1233         }
1234         | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
1235         | TLS_METHOD EQUAL SSLv23 {
1236                 #ifdef CORE_TLS
1237                         tls_method=TLS_USE_SSLv23;
1238                 #else
1239                         warn("tls-in-core support not compiled in");
1240                 #endif
1241         }
1242         | TLS_METHOD EQUAL SSLv2 {
1243                 #ifdef CORE_TLS
1244                         tls_method=TLS_USE_SSLv2;
1245                 #else
1246                         warn("tls-in-core support not compiled in");
1247                 #endif
1248         }
1249         | TLS_METHOD EQUAL SSLv3 {
1250                 #ifdef CORE_TLS
1251                         tls_method=TLS_USE_SSLv3;
1252                 #else
1253                         warn("tls-in-core support not compiled in");
1254                 #endif
1255         }
1256         | TLS_METHOD EQUAL TLSv1 {
1257                 #ifdef CORE_TLS
1258                         tls_method=TLS_USE_TLSv1;
1259                 #else
1260                         warn("tls-in-core support not compiled in");
1261                 #endif
1262         }
1263         | TLS_METHOD EQUAL error {
1264                 #ifdef CORE_TLS
1265                         yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
1266                 #else
1267                         warn("tls-in-core support not compiled in");
1268                 #endif
1269         }
1270         | TLS_VERIFY EQUAL NUMBER {
1271                 #ifdef CORE_TLS
1272                         tls_verify_cert=$3;
1273                 #else
1274                         warn("tls-in-core support not compiled in");
1275                 #endif
1276         }
1277         | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
1278         | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
1279                 #ifdef CORE_TLS
1280                         tls_require_cert=$3;
1281                 #else
1282                         warn( "tls-in-core support not compiled in");
1283                 #endif
1284         }
1285         | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
1286         | TLS_CERTIFICATE EQUAL STRING {
1287                 #ifdef CORE_TLS
1288                         tls_cert_file=$3;
1289                 #else
1290                         warn("tls-in-core support not compiled in");
1291                 #endif
1292         }
1293         | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
1294         | TLS_PRIVATE_KEY EQUAL STRING {
1295                 #ifdef CORE_TLS
1296                         tls_pkey_file=$3;
1297                 #else
1298                         warn("tls-in-core support not compiled in");
1299                 #endif
1300         }
1301         | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1302         | TLS_CA_LIST EQUAL STRING {
1303                 #ifdef CORE_TLS
1304                         tls_ca_file=$3;
1305                 #else
1306                         warn("tls-in-core support not compiled in");
1307                 #endif
1308         }
1309         | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1310         | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
1311                 #ifdef CORE_TLS
1312                         tls_handshake_timeout=$3;
1313                 #else
1314                         warn("tls-in-core support not compiled in");
1315                 #endif
1316         }
1317         | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
1318         | TLS_SEND_TIMEOUT EQUAL NUMBER {
1319                 #ifdef CORE_TLS
1320                         tls_send_timeout=$3;
1321                 #else
1322                         warn("tls-in-core support not compiled in");
1323                 #endif
1324         }
1325         | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
1326         | DISABLE_SCTP EQUAL NUMBER {
1327                 #ifdef USE_SCTP
1328                         sctp_disable=$3;
1329                 #else
1330                         warn("sctp support not compiled in");
1331                 #endif
1332         }
1333         | DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
1334         | ENABLE_SCTP EQUAL NUMBER {
1335                 #ifdef USE_SCTP
1336                         sctp_disable=($3<=1)?!$3:$3;
1337                 #else
1338                         warn("sctp support not compiled in");
1339                 #endif
1340         }
1341         | ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
1342         | SCTP_CHILDREN EQUAL NUMBER {
1343                 #ifdef USE_SCTP
1344                         sctp_children_no=$3;
1345                 #else
1346                         warn("sctp support not compiled in");
1347                 #endif
1348         }
1349         | SCTP_CHILDREN EQUAL error { yyerror("number expected"); }
1350         | SCTP_SOCKET_RCVBUF EQUAL NUMBER {
1351                 #ifdef USE_SCTP
1352                         sctp_default_cfg.so_rcvbuf=$3;
1353                 #else
1354                         warn("sctp support not compiled in");
1355                 #endif
1356         }
1357         | SCTP_SOCKET_RCVBUF EQUAL error { yyerror("number expected"); }
1358         | SCTP_SOCKET_SNDBUF EQUAL NUMBER {
1359                 #ifdef USE_SCTP
1360                         sctp_default_cfg.so_sndbuf=$3;
1361                 #else
1362                         warn("sctp support not compiled in");
1363                 #endif
1364         }
1365         | SCTP_SOCKET_SNDBUF EQUAL error { yyerror("number expected"); }
1366         | SCTP_AUTOCLOSE EQUAL NUMBER {
1367                 #ifdef USE_SCTP
1368                         sctp_default_cfg.autoclose=$3;
1369                 #else
1370                         warn("sctp support not compiled in");
1371                 #endif
1372         }
1373         | SCTP_AUTOCLOSE EQUAL error { yyerror("number expected"); }
1374         | SCTP_SEND_TTL EQUAL NUMBER {
1375                 #ifdef USE_SCTP
1376                         sctp_default_cfg.send_ttl=$3;
1377                 #else
1378                         warn("sctp support not compiled in");
1379                 #endif
1380         }
1381         | SCTP_SEND_TTL EQUAL error { yyerror("number expected"); }
1382         | SCTP_SEND_RETRIES EQUAL NUMBER {
1383                 #ifdef USE_SCTP
1384                         sctp_default_cfg.send_retries=$3;
1385                 #else
1386                         warn("sctp support not compiled in");
1387                 #endif
1388         }
1389         | SCTP_SEND_RETRIES EQUAL error { yyerror("number expected"); }
1390         | SCTP_ASSOC_TRACKING EQUAL NUMBER {
1391                 #ifdef USE_SCTP
1392                         #ifdef SCTP_CONN_REUSE
1393                                 sctp_default_cfg.assoc_tracking=$3;
1394                         #else
1395                                 if ($3)
1396                                         warn("sctp association tracking/reuse (SCTP_CONN_REUSE) "
1397                                                         "support not compiled in");
1398                         #endif /* SCTP_CONN_REUSE */
1399                 #else
1400                         warn("sctp support not compiled in");
1401                 #endif /* USE_SCTP */
1402         }
1403         | SCTP_ASSOC_TRACKING EQUAL error { yyerror("number expected"); }
1404         | SCTP_ASSOC_REUSE EQUAL NUMBER {
1405                 #ifdef USE_SCTP
1406                         #ifdef SCTP_CONN_REUSE
1407                                 sctp_default_cfg.assoc_reuse=$3;
1408                         #else
1409                                 if ($3)
1410                                         warn("sctp association reuse (SCTP_CONN_REUSE) support"
1411                                                         " not compiled in");
1412                         #endif /* SCTP_CONN_REUSE */
1413                 #else
1414                         warn("sctp support not compiled in");
1415                 #endif /* USE_SCTP */
1416         }
1417         | SCTP_ASSOC_REUSE EQUAL error { yyerror("number expected"); }
1418         | SCTP_MAX_ASSOCS EQUAL intno {
1419                         IF_SCTP(sctp_default_cfg.max_assocs=$3);
1420         }
1421         | SCTP_MAX_ASSOCS EQUAL error { yyerror("number expected"); }
1422         | SCTP_SRTO_INITIAL EQUAL NUMBER {
1423                         IF_SCTP(sctp_default_cfg.srto_initial=$3);
1424         }
1425         | SCTP_SRTO_INITIAL EQUAL error { yyerror("number expected"); }
1426         | SCTP_SRTO_MAX EQUAL NUMBER {
1427                         IF_SCTP(sctp_default_cfg.srto_max=$3);
1428         }
1429         | SCTP_SRTO_MAX EQUAL error { yyerror("number expected"); }
1430         | SCTP_SRTO_MIN EQUAL NUMBER {
1431                         IF_SCTP(sctp_default_cfg.srto_min=$3);
1432         }
1433         | SCTP_SRTO_MIN EQUAL error { yyerror("number expected"); }
1434         | SCTP_ASOCMAXRXT EQUAL NUMBER {
1435                         IF_SCTP(sctp_default_cfg.asocmaxrxt=$3);
1436         }
1437         | SCTP_ASOCMAXRXT EQUAL error { yyerror("number expected"); }
1438         | SCTP_INIT_MAX_ATTEMPTS EQUAL NUMBER {
1439                         IF_SCTP(sctp_default_cfg.init_max_attempts=$3);
1440         }
1441         | SCTP_INIT_MAX_ATTEMPTS EQUAL error { yyerror("number expected"); }
1442         | SCTP_INIT_MAX_TIMEO EQUAL NUMBER {
1443                         IF_SCTP(sctp_default_cfg.init_max_timeo=$3);
1444         }
1445         | SCTP_INIT_MAX_TIMEO EQUAL error { yyerror("number expected"); }
1446         | SCTP_HBINTERVAL EQUAL intno {
1447                         IF_SCTP(sctp_default_cfg.hbinterval=$3);
1448         }
1449         | SCTP_HBINTERVAL EQUAL error { yyerror("number expected"); }
1450         | SCTP_PATHMAXRXT EQUAL NUMBER {
1451                         IF_SCTP(sctp_default_cfg.pathmaxrxt=$3);
1452         }
1453         | SCTP_PATHMAXRXT EQUAL error { yyerror("number expected"); }
1454         | SCTP_SACK_DELAY EQUAL NUMBER {
1455                         IF_SCTP(sctp_default_cfg.sack_delay=$3);
1456         }
1457         | SCTP_SACK_DELAY EQUAL error { yyerror("number expected"); }
1458         | SCTP_SACK_FREQ EQUAL NUMBER {
1459                         IF_SCTP(sctp_default_cfg.sack_freq=$3);
1460         }
1461         | SCTP_SACK_FREQ EQUAL error { yyerror("number expected"); }
1462         | SCTP_MAX_BURST EQUAL NUMBER {
1463                         IF_SCTP(sctp_default_cfg.max_burst=$3);
1464         }
1465         | SCTP_MAX_BURST EQUAL error { yyerror("number expected"); }
1466         | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
1467         | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
1468         | SERVER_HEADER EQUAL STRING { server_hdr.s=$3;
1469                         server_hdr.len=strlen(server_hdr.s);
1470         }
1471         | SERVER_HEADER EQUAL error { yyerror("string value expected"); }
1472         | USER_AGENT_HEADER EQUAL STRING { user_agent_hdr.s=$3;
1473                         user_agent_hdr.len=strlen(user_agent_hdr.s);
1474         }
1475         | USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
1476         | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
1477         | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
1478         | LISTEN EQUAL id_lst {
1479                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1480                         if (add_listen_iface(   lst_tmp->addr_lst->name,
1481                                                                         lst_tmp->addr_lst->next,
1482                                                                         lst_tmp->port, lst_tmp->proto,
1483                                                                         lst_tmp->flags)!=0) {
1484                                 LOG(L_CRIT,  "ERROR: cfg. parser: failed to add listen"
1485                                                                 " address\n");
1486                                 break;
1487                         }
1488                 }
1489                 free_socket_id_lst($3);
1490         }
1491         | LISTEN EQUAL  error { yyerror("ip address, interface name or"
1492                                                                         " hostname expected"); }
1493         | ALIAS EQUAL  id_lst {
1494                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
1495                         add_alias(      lst_tmp->addr_lst->name,
1496                                                 strlen(lst_tmp->addr_lst->name),
1497                                                 lst_tmp->port, lst_tmp->proto);
1498                         for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
1499                                 add_alias(nl_tmp->name, strlen(nl_tmp->name),
1500                                                         lst_tmp->port, lst_tmp->proto);
1501                 }
1502                 free_socket_id_lst($3);
1503         }
1504         | ALIAS  EQUAL error  { yyerror(" hostname expected"); }
1505         | SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
1506         | SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
1507         | ADVERTISED_ADDRESS EQUAL listen_id {
1508                 if ($3){
1509                         default_global_address.s=$3;
1510                         default_global_address.len=strlen($3);
1511                 }
1512         }
1513         | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
1514         | ADVERTISED_PORT EQUAL NUMBER {
1515                 tmp=int2str($3, &i_tmp);
1516                 if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
1517                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1518                         default_global_port.len=0;
1519                 } else {
1520                         default_global_port.len=i_tmp;
1521                         memcpy(default_global_port.s, tmp, default_global_port.len);
1522                 };
1523         }
1524         |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
1525         | DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
1526         | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1527         | OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1528         | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1529         | SHM_MEM_SZ EQUAL NUMBER {
1530                 if (shm_initialized())
1531                         yyerror("shm/shm_mem_size must be before any modparam or the"
1532                                         " route blocks");
1533                 else if (shm_mem_size == 0)
1534                         shm_mem_size=$3 * 1024 * 1024;
1535         }
1536         | SHM_MEM_SZ EQUAL error { yyerror("number expected"); }
1537         | SHM_FORCE_ALLOC EQUAL NUMBER {
1538                 if (shm_initialized())
1539                         yyerror("shm_force_alloc must be before any modparam or the"
1540                                         " route blocks");
1541                 else
1542                         shm_force_alloc=$3;
1543         }
1544         | SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1545         | MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1546         | MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
1547         | REAL_TIME EQUAL NUMBER { real_time=$3; }
1548         | REAL_TIME EQUAL error { yyerror("boolean value expected"); }
1549         | RT_PRIO EQUAL NUMBER { rt_prio=$3; }
1550         | RT_PRIO EQUAL error { yyerror("boolean value expected"); }
1551         | RT_POLICY EQUAL NUMBER { rt_policy=$3; }
1552         | RT_POLICY EQUAL error { yyerror("boolean value expected"); }
1553         | RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
1554         | RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
1555         | RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
1556         | RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
1557         | RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
1558         | RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
1559         | RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
1560         | RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
1561         | MCAST_LOOPBACK EQUAL NUMBER {
1562                 #ifdef USE_MCAST
1563                         mcast_loopback=$3;
1564                 #else
1565                         warn("no multicast support compiled in");
1566                 #endif
1567         }
1568         | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
1569         | MCAST_TTL EQUAL NUMBER {
1570                 #ifdef USE_MCAST
1571                         mcast_ttl=$3;
1572                 #else
1573                         warn("no multicast support compiled in");
1574                 #endif
1575         }
1576         | MCAST_TTL EQUAL error { yyerror("number expected"); }
1577         | TOS EQUAL NUMBER { tos=$3; }
1578         | TOS EQUAL error { yyerror("number expected"); }
1579         | PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
1580         | PMTU_DISCOVERY error { yyerror("number expected"); }
1581         | KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
1582         | KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
1583         | MAX_WLOOPS EQUAL NUMBER { default_core_cfg.max_while_loops=$3; }
1584         | MAX_WLOOPS EQUAL error { yyerror("number expected"); }
1585         | STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
1586         | STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
1587         | STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
1588         | STUN_ALLOW_STUN EQUAL error{ yyerror("number expected"); }
1589         | STUN_ALLOW_FP EQUAL NUMBER { IF_STUN(stun_allow_fp=$3) ; }
1590         | STUN_ALLOW_FP EQUAL error{ yyerror("number expected"); }
1591     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1592         | UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1593         | UDP_MTU EQUAL error { yyerror("number expected"); }
1594         | FORCE_RPORT EQUAL NUMBER 
1595                 { default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1596         | FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1597         | UDP_MTU_TRY_PROTO EQUAL proto
1598                 { default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
1599         | UDP_MTU_TRY_PROTO EQUAL error
1600                 { yyerror("TCP, TLS, SCTP or UDP expected"); }
1601         | UDP4_RAW EQUAL intno { IF_RAW_SOCKS(default_core_cfg.udp4_raw=$3); }
1602         | UDP4_RAW EQUAL error { yyerror("number expected"); }
1603         | UDP4_RAW_MTU EQUAL NUMBER {
1604                 IF_RAW_SOCKS(default_core_cfg.udp4_raw_mtu=$3);
1605         }
1606         | UDP4_RAW_MTU EQUAL error { yyerror("number expected"); }
1607         | UDP4_RAW_TTL EQUAL NUMBER {
1608                 IF_RAW_SOCKS(default_core_cfg.udp4_raw_ttl=$3);
1609         }
1610         | UDP4_RAW_TTL EQUAL error { yyerror("number expected"); }
1611         | cfg_var
1612         | error EQUAL { yyerror("unknown config variable"); }
1613         ;
1614         
1615 cfg_var_id: ID 
1616         | DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
1617         ;
1618         
1619 cfg_var:
1620         cfg_var_id DOT cfg_var_id EQUAL NUMBER {
1621                 if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1622                         yyerror("variable cannot be declared");
1623                 }
1624         }
1625         | cfg_var_id DOT cfg_var_id EQUAL STRING {
1626                 if (cfg_declare_str($1, $3, $5, NULL)) {
1627                         yyerror("variable cannot be declared");
1628                 }
1629         }
1630         | cfg_var_id DOT cfg_var_id EQUAL NUMBER CFG_DESCRIPTION STRING {
1631                 if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1632                         yyerror("variable cannot be declared");
1633                 }
1634         }
1635         | cfg_var_id DOT cfg_var_id EQUAL STRING CFG_DESCRIPTION STRING {
1636                 if (cfg_declare_str($1, $3, $5, $7)) {
1637                         yyerror("variable cannot be declared");
1638                 }
1639         }
1640         | cfg_var_id DOT cfg_var_id EQUAL error { 
1641                 yyerror("number or string expected"); 
1642         }
1643         | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL NUMBER {
1644                 if (cfg_ginst_var_int($1, $3, $6, $8)) {
1645                         yyerror("variable cannot be added to the group instance");
1646                 }
1647         }
1648         | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL STRING {
1649                 if (cfg_ginst_var_string($1, $3, $6, $8)) {
1650                         yyerror("variable cannot be added to the group instance");
1651                 }
1652         }
1653         ;
1654
1655 module_stm:
1656         LOADMODULE STRING {
1657                 DBG("loading module %s\n", $2);
1658                         if (load_module($2)!=0) {
1659                                 yyerror("failed to load module");
1660                         }
1661         }
1662         | LOADMODULE error      { yyerror("string expected"); }
1663         | LOADPATH STRING {
1664                 DBG("loading modules under %s\n", $2);
1665                 printf("loading modules under %s\n", $2);
1666                 mods_dir = $2;
1667         }
1668         | LOADPATH error        { yyerror("string expected"); }
1669         | LOADPATH EQUAL STRING {
1670                 DBG("loading modules under %s\n", $3);
1671                 printf("loading modules under %s\n", $3);
1672                 mods_dir = $3;
1673         }
1674         | LOADPATH EQUAL error  { yyerror("string expected"); }
1675         | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1676         #ifdef SHM_MEM
1677                 if (!shm_initialized() && init_shm()<0) {
1678                         yyerror("Can't initialize shared memory");
1679                         YYABORT;
1680                 }
1681         #endif /* SHM_MEM */
1682                 if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1683                          yyerror("Can't set module parameter");
1684                 }
1685         }
1686         | MODPARAM LPAREN STRING COMMA STRING COMMA intno RPAREN {
1687         #ifdef SHM_MEM
1688                 if (!shm_initialized() && init_shm()<0) {
1689                         yyerror("Can't initialize shared memory");
1690                         YYABORT;
1691                 }
1692         #endif /* SHM_MEM */
1693                 if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1694                          yyerror("Can't set module parameter");
1695                 }
1696         }
1697         | MODPARAM error { yyerror("Invalid arguments"); }
1698         ;
1699 ip:
1700         ipv4  { $$=$1; }
1701         | ipv6  { $$=$1; }
1702         ;
1703 ipv4:
1704         NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
1705                 $$=pkg_malloc(sizeof(struct ip_addr));
1706                 if ($$==0) {
1707                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1708                 } else {
1709                         memset($$, 0, sizeof(struct ip_addr));
1710                         $$->af=AF_INET;
1711                         $$->len=4;
1712                         if (($1>255) || ($1<0) ||
1713                                 ($3>255) || ($3<0) ||
1714                                 ($5>255) || ($5<0) ||
1715                                 ($7>255) || ($7<0)) {
1716                                 yyerror("invalid ipv4 address");
1717                                 $$->u.addr32[0]=0;
1718                                 /* $$=0; */
1719                         } else {
1720                                 $$->u.addr[0]=$1;
1721                                 $$->u.addr[1]=$3;
1722                                 $$->u.addr[2]=$5;
1723                                 $$->u.addr[3]=$7;
1724                                 /*
1725                                 $$=htonl( ($1<<24)|
1726                                 ($3<<16)| ($5<<8)|$7 );
1727                                 */
1728                         }
1729                 }
1730         }
1731         ;
1732 ipv6addr:
1733         IPV6ADDR {
1734                 $$=pkg_malloc(sizeof(struct ip_addr));
1735                 if ($$==0) {
1736                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1737                 } else {
1738                 #ifdef USE_IPV6
1739                         memset($$, 0, sizeof(struct ip_addr));
1740                         $$->af=AF_INET6;
1741                         $$->len=16;
1742                         if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
1743                                 yyerror("bad ipv6 address");
1744                         }
1745                 #else
1746                         yyerror("ipv6 address & no ipv6 support compiled in");
1747                         YYABORT;
1748                 #endif
1749                 }
1750         }
1751         ;
1752 ipv6:
1753         ipv6addr { $$=$1; }
1754         | LBRACK ipv6addr RBRACK {$$=$2; }
1755 ;
1756
1757
1758 route_name:             NUMBER  {
1759                                         tmp=int2str($1, &i_tmp);
1760                                         if (($$=pkg_malloc(i_tmp+1))==0) {
1761                                                 yyerror("out of  memory");
1762                                                 YYABORT;
1763                                         } else {
1764                                                 memcpy($$, tmp, i_tmp);
1765                                                 $$[i_tmp]=0;
1766                                         }
1767                                                 }
1768                         |       ID              { $$=$1; }
1769                         |       STRING  { $$=$1; }
1770 ;
1771
1772 route_stm:
1773         ROUTE LBRACE actions RBRACE {
1774         #ifdef SHM_MEM
1775                 if (!shm_initialized() && init_shm()<0) {
1776                         yyerror("Can't initialize shared memory");
1777                         YYABORT;
1778                 }
1779         #endif /* SHM_MEM */
1780                 push($3, &main_rt.rlist[DEFAULT_RT]);
1781         }
1782         | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
1783         #ifdef SHM_MEM
1784                 if (!shm_initialized() && init_shm()<0) {
1785                         yyerror("Can't initialize shared memory");
1786                         YYABORT;
1787                 }
1788         #endif /* SHM_MEM */
1789                 i_tmp=route_get(&main_rt, $3);
1790                 if (i_tmp==-1){
1791                         yyerror("internal error");
1792                         YYABORT;
1793                 }
1794                 if (main_rt.rlist[i_tmp]){
1795                         yyerror("duplicate route");
1796                         YYABORT;
1797                 }
1798                 push($6, &main_rt.rlist[i_tmp]);
1799         }
1800         | ROUTE error { yyerror("invalid  route  statement"); }
1801         ;
1802 failure_route_stm:
1803         ROUTE_FAILURE LBRACE actions RBRACE {
1804         #ifdef SHM_MEM
1805                 if (!shm_initialized() && init_shm()<0) {
1806                         yyerror("Can't initialize shared memory");
1807                         YYABORT;
1808                 }
1809         #endif /* SHM_MEM */
1810                 push($3, &failure_rt.rlist[DEFAULT_RT]);
1811         }
1812         | ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1813         #ifdef SHM_MEM
1814                 if (!shm_initialized() && init_shm()<0) {
1815                         yyerror("Can't initialize shared memory");
1816                         YYABORT;
1817                 }
1818         #endif /* SHM_MEM */
1819                 i_tmp=route_get(&failure_rt, $3);
1820                 if (i_tmp==-1){
1821                         yyerror("internal error");
1822                         YYABORT;
1823                 }
1824                 if (failure_rt.rlist[i_tmp]){
1825                         yyerror("duplicate route");
1826                         YYABORT;
1827                 }
1828                 push($6, &failure_rt.rlist[i_tmp]);
1829         }
1830         | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1831         ;
1832
1833 onreply_route_stm:
1834         ROUTE_ONREPLY LBRACE {rt=CORE_ONREPLY_ROUTE;} actions RBRACE {
1835         #ifdef SHM_MEM
1836                 if (!shm_initialized() && init_shm()<0) {
1837                         yyerror("Can't initialize shared memory");
1838                         YYABORT;
1839                 }
1840         #endif /* SHM_MEM */
1841                 push($4, &onreply_rt.rlist[DEFAULT_RT]);
1842         }
1843         | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
1844         | ROUTE_ONREPLY LBRACK route_name RBRACK 
1845                 {rt=(*$3=='0' && $3[1]==0)?CORE_ONREPLY_ROUTE:TM_ONREPLY_ROUTE;}
1846                 LBRACE actions RBRACE {
1847         #ifdef SHM_MEM
1848                 if (!shm_initialized() && init_shm()<0) {
1849                         yyerror("Can't initialize shared memory");
1850                         YYABORT;
1851                 }
1852         #endif /* SHM_MEM */
1853                 if (*$3=='0' && $3[1]==0){
1854                         /* onreply_route[0] {} is equivalent with onreply_route {}*/
1855                         push($7, &onreply_rt.rlist[DEFAULT_RT]);
1856                 }else{
1857                         i_tmp=route_get(&onreply_rt, $3);
1858                         if (i_tmp==-1){
1859                                 yyerror("internal error");
1860                                 YYABORT;
1861                         }
1862                         if (onreply_rt.rlist[i_tmp]){
1863                                 yyerror("duplicate route");
1864                                 YYABORT;
1865                         }
1866                         push($7, &onreply_rt.rlist[i_tmp]);
1867                 }
1868         }
1869         | ROUTE_ONREPLY LBRACK route_name RBRACK error {
1870                 yyerror("invalid onreply_route statement");
1871         }
1872         ;
1873 branch_route_stm:
1874         ROUTE_BRANCH LBRACE actions RBRACE {
1875         #ifdef SHM_MEM
1876                 if (!shm_initialized() && init_shm()<0) {
1877                         yyerror("Can't initialize shared memory");
1878                         YYABORT;
1879                 }
1880         #endif /* SHM_MEM */
1881                 push($3, &branch_rt.rlist[DEFAULT_RT]);
1882         }
1883         | ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1884         #ifdef SHM_MEM
1885                 if (!shm_initialized() && init_shm()<0) {
1886                         yyerror("Can't initialize shared memory");
1887                         YYABORT;
1888                 }
1889         #endif /* SHM_MEM */
1890                 i_tmp=route_get(&branch_rt, $3);
1891                 if (i_tmp==-1){
1892                         yyerror("internal error");
1893                         YYABORT;
1894                 }
1895                 if (branch_rt.rlist[i_tmp]){
1896                         yyerror("duplicate route");
1897                         YYABORT;
1898                 }
1899                 push($6, &branch_rt.rlist[i_tmp]);
1900         }
1901         | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1902         ;
1903 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1904         #ifdef SHM_MEM
1905                 if (!shm_initialized() && init_shm()<0) {
1906                         yyerror("Can't initialize shared memory");
1907                         YYABORT;
1908                 }
1909         #endif /* SHM_MEM */
1910                 push($3, &onsend_rt.rlist[DEFAULT_RT]);
1911         }
1912         | ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1913         #ifdef SHM_MEM
1914                 if (!shm_initialized() && init_shm()<0) {
1915                         yyerror("Can't initialize shared memory");
1916                         YYABORT;
1917                 }
1918         #endif /* SHM_MEM */
1919                 i_tmp=route_get(&onsend_rt, $3);
1920                 if (i_tmp==-1){
1921                         yyerror("internal error");
1922                         YYABORT;
1923                 }
1924                 if (onsend_rt.rlist[i_tmp]){
1925                         yyerror("duplicate route");
1926                         YYABORT;
1927                 }
1928                 push($6, &onsend_rt.rlist[i_tmp]);
1929         }
1930         | ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1931         ;
1932 event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1933         #ifdef SHM_MEM
1934                 if (!shm_initialized() && init_shm()<0) {
1935                         yyerror("Can't initialize shared memory");
1936                         YYABORT;
1937                 }
1938         #endif /* SHM_MEM */
1939                 i_tmp=route_get(&event_rt, $3);
1940                 if (i_tmp==-1){
1941                         yyerror("internal error");
1942                         YYABORT;
1943                 }
1944                 if (event_rt.rlist[i_tmp]){
1945                         yyerror("duplicate route");
1946                         YYABORT;
1947                 }
1948                 push($6, &event_rt.rlist[i_tmp]);
1949         }
1950
1951         | ROUTE_EVENT error { yyerror("invalid event_route statement"); }
1952         ;
1953 preprocess_stm:
1954         SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
1955         | SUBST error { yyerror("invalid subst preprocess statement"); }
1956         ;
1957
1958 /*exp:  rval_expr
1959                 {
1960                         if ($1==0){
1961                                 yyerror("invalid expression");
1962                                 $$=0;
1963                         }else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1964                                 yyerror("invalid expression");
1965                                 $$=0;
1966                         }else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
1967                                 yyerror("invalid expression type, int expected\n");
1968                                 $$=0;
1969                         }else
1970                                 $$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
1971                 }
1972         ;
1973 */
1974
1975 /* exp elem operators */
1976 equalop:
1977         EQUAL_T {$$=EQUAL_OP; }
1978         | DIFF  {$$=DIFF_OP; }
1979         | STREQ {$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
1980         | STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
1981         ;
1982 cmpop:
1983           GT    {$$=GT_OP; }
1984         | LT    {$$=LT_OP; }
1985         | GTE   {$$=GTE_OP; }
1986         | LTE   {$$=LTE_OP; }
1987         ;
1988 strop:
1989         equalop {$$=$1; }
1990         | MATCH {$$=MATCH_OP; }
1991         ;
1992
1993
1994 /* rve expr. operators */
1995 rve_equalop:
1996         EQUAL_T {$$=RVE_EQ_OP; }
1997         | DIFF  {$$=RVE_DIFF_OP; }
1998         | INTEQ {$$=RVE_IEQ_OP; }
1999         | INTDIFF {$$=RVE_IDIFF_OP; }
2000         | STREQ {$$=RVE_STREQ_OP; }
2001         | STRDIFF {$$=RVE_STRDIFF_OP; }
2002         | MATCH {$$=RVE_MATCH_OP; }
2003         ;
2004 rve_cmpop:
2005           GT    {$$=RVE_GT_OP; }
2006         | LT    {$$=RVE_LT_OP; }
2007         | GTE   {$$=RVE_GTE_OP; }
2008         | LTE   {$$=RVE_LTE_OP; }
2009         ;
2010
2011
2012
2013 /* boolean expression uri operands */
2014 uri_type:
2015         URI             {$$=URI_O;}
2016         | FROM_URI      {$$=FROM_URI_O;}
2017         | TO_URI        {$$=TO_URI_O;}
2018         ;
2019
2020
2021 /* boolean expression integer operands, available only in the
2022   onsend route */
2023 eint_op_onsend:
2024                         SNDPORT         { $$=SNDPORT_O; }
2025                 |       TOPORT          { $$=TOPORT_O; }
2026                 |       SNDAF           { $$=SNDAF_O; }
2027                 ;
2028
2029 /* boolean expression integer operands */
2030 eint_op:        SRCPORT         { $$=SRCPORT_O; }
2031                 |       DSTPORT         { $$=DSTPORT_O; }
2032                 |       AF                      { $$=AF_O; }
2033                 |       MSGLEN          { $$=MSGLEN_O; }
2034                 | eint_op_onsend
2035         ;
2036
2037 /* boolean expression ip/ipnet operands */
2038 eip_op_onsend:
2039                         SNDIP           { onsend_check("snd_ip"); $$=SNDIP_O; }
2040                 |       TOIP            { onsend_check("to_ip");  $$=TOIP_O; }
2041                 ;
2042
2043 eip_op:         SRCIP           { $$=SRCIP_O; }
2044                 |       DSTIP           { $$=DSTIP_O; }
2045                 | eip_op_onsend
2046                 ;
2047
2048
2049
2050 exp_elem:
2051         METHOD strop rval_expr %prec EQUAL_T
2052                 {$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
2053         | METHOD strop ID %prec EQUAL_T
2054                 {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
2055         | METHOD strop error { $$=0; yyerror("string expected"); }
2056         | METHOD error  
2057                 { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
2058         | uri_type strop rval_expr %prec EQUAL_T
2059                 {$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
2060         | uri_type strop MYSELF %prec EQUAL_T
2061                 {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
2062         | uri_type strop error %prec EQUAL_T
2063                 { $$=0; yyerror("string or MYSELF expected"); }
2064         | uri_type error
2065                 { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
2066         | eint_op cmpop rval_expr %prec GT { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
2067         | eint_op equalop rval_expr %prec EQUAL_T
2068                 { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
2069         | eint_op cmpop error   { $$=0; yyerror("number expected"); }
2070         | eint_op equalop error { $$=0; yyerror("number expected"); }
2071         | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
2072         | PROTO equalop proto %prec EQUAL_T
2073                 { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2074         | PROTO equalop rval_expr %prec EQUAL_T
2075                 { $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
2076         | PROTO equalop error
2077                 { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
2078         | SNDPROTO equalop proto %prec EQUAL_T
2079                 { $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2080         | SNDPROTO equalop rval_expr %prec EQUAL_T
2081                 { $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
2082         | SNDPROTO equalop error
2083                 { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
2084         | eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
2085         | eip_op strop rval_expr %prec EQUAL_T {
2086                         s_tmp.s=0;
2087                         $$=0;
2088                         if (rve_is_constant($3)){
2089                                 i_tmp=rve_guess_type($3);
2090                                 if (i_tmp==RV_INT)
2091                                         yyerror("string expected");
2092                                 else if (i_tmp==RV_STR){
2093                                         if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
2094                                                                 (rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
2095                                                 rval_destroy(rval_tmp);
2096                                                 yyerror("bad rvalue expression");
2097                                         }else{
2098                                                 rval_destroy(rval_tmp);
2099                                         }
2100                                 }else{
2101                                         yyerror("BUG: unexpected dynamic type");
2102                                 }
2103                         }else{
2104                                         /* warn("non constant rvalue in ip comparison") */;
2105                         }
2106                         if (s_tmp.s){
2107                                 ip_tmp=str2ip(&s_tmp);
2108                         #ifdef USE_IPV6
2109                                 if (ip_tmp==0)
2110                                         ip_tmp=str2ip6(&s_tmp);
2111                         #endif
2112                                 pkg_free(s_tmp.s);
2113                                 if (ip_tmp) {
2114                                         $$=mk_elem($2, $1, 0, NET_ST, 
2115                                                                 mk_new_net_bitlen(ip_tmp, ip_tmp->len*8) );
2116                                 } else {
2117                                         $$=mk_elem($2, $1, 0, RVE_ST, $3);
2118                                 }
2119                         }else{
2120                                 $$=mk_elem($2, $1, 0, RVE_ST, $3);
2121                         }
2122                 }
2123         | eip_op strop host %prec EQUAL_T
2124                 { $$=mk_elem($2, $1, 0, STRING_ST, $3); }
2125         | eip_op strop MYSELF %prec EQUAL_T
2126                 { $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
2127         | eip_op strop error %prec EQUAL_T
2128                 { $$=0; yyerror( "ip address or hostname expected" ); }
2129         | eip_op error
2130                 { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
2131         
2132         | MYSELF equalop uri_type %prec EQUAL_T
2133                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
2134         | MYSELF equalop eip_op %prec EQUAL_T
2135                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
2136         | MYSELF equalop error %prec EQUAL_T
2137                 { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
2138         | MYSELF error  { $$=0; yyerror ("invalid operator, == or != expected"); }
2139         ;
2140 /*
2141 exp_elem2:
2142         rval_expr cmpop rval_expr %prec GT
2143                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
2144         |
2145         rval_expr equalop rval_expr %prec EQUAL_T
2146                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
2147         | rval_expr LOG_AND rval_expr
2148                 { $$=mk_exp_rve(LOGAND_OP, $1, $3);}
2149         | rval_expr LOG_OR rval_expr
2150                 { $$=mk_exp_rve(LOGOR_OP, $1, $3);}
2151 ;
2152 */
2153
2154 ipnet:
2155         ip SLASH ip     { $$=mk_new_net($1, $3); }
2156         | ip SLASH NUMBER {
2157                 if (($3<0) || ($3>$1->len*8)) {
2158                         yyerror("invalid bit number in netmask");
2159                         $$=0;
2160                 } else {
2161                         $$=mk_new_net_bitlen($1, $3);
2162                 /*
2163                         $$=mk_new_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
2164                 */
2165                 }
2166         }
2167         | ip    { $$=mk_new_net_bitlen($1, $1->len*8); }
2168         | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
2169         ;
2170
2171 host:
2172         ID { $$=$1; }
2173         | host DOT ID {
2174                 if ($1){
2175                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2176                         if ($$==0) {
2177                                 LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
2178                                                         " failure while parsing host\n");
2179                         } else {
2180                                 memcpy($$, $1, strlen($1));
2181                                 $$[strlen($1)]='.';
2182                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2183                                 $$[strlen($1)+1+strlen($3)]=0;
2184                         }
2185                         pkg_free($1);
2186                 }
2187                 if ($3) pkg_free($3);
2188         }
2189         | host MINUS ID {
2190                 if ($1){
2191                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2192                         if ($$==0) {
2193                                 LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
2194                                                         " failure while parsing host\n");
2195                         } else {
2196                                 memcpy($$, $1, strlen($1));
2197                                 $$[strlen($1)]='-';
2198                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2199                                 $$[strlen($1)+1+strlen($3)]=0;
2200                         }
2201                         pkg_free($1);
2202                 }
2203                 if ($3) pkg_free($3);
2204         }
2205         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
2206         | host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
2207         ;
2208
2209 host_if_id: ID
2210                 | NUM_ID
2211                 | NUMBER {
2212                         /* get string version */
2213                         $$=pkg_malloc(strlen(yy_number_str)+1);
2214                         if ($$)
2215                                 strcpy($$, yy_number_str);
2216                 }
2217                 ;
2218
2219 host_or_if:
2220         host_if_id { $$=$1; }
2221         | host_or_if DOT host_if_id {
2222                 if ($1){
2223                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2224                         if ($$==0) {
2225                                 LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
2226                                                         " failure while parsing host/interface name\n");
2227                         } else {
2228                                 memcpy($$, $1, strlen($1));
2229                                 $$[strlen($1)]='.';
2230                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2231                                 $$[strlen($1)+1+strlen($3)]=0;
2232                         }
2233                         pkg_free($1);
2234                 }
2235                 if ($3) pkg_free($3);
2236         }
2237         | host_or_if MINUS host_if_id {
2238                 if ($1){
2239                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2240                         if ($$==0) {
2241                                 LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
2242                                                         " failure while parsing host/interface name\n");
2243                         } else {
2244                                 memcpy($$, $1, strlen($1));
2245                                 $$[strlen($1)]='-';
2246                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2247                                 $$[strlen($1)+1+strlen($3)]=0;
2248                         }
2249                         pkg_free($1);
2250                 }
2251                 if ($3) pkg_free($3);
2252         }
2253         | host_or_if DOT error { $$=0; pkg_free($1);
2254                                                                 yyerror("invalid host or interface name"); }
2255         | host_or_if MINUS error { $$=0; pkg_free($1);
2256                                                                 yyerror("invalid host or interface name"); }
2257         ;
2258
2259
2260 /* filtered cmd */
2261 fcmd:
2262         cmd {
2263                 /* check if allowed */
2264                 if ($1 && rt==ONSEND_ROUTE) {
2265                         switch($1->type) {
2266                                 case DROP_T:
2267                                 case SEND_T:
2268                                 case SEND_TCP_T:
2269                                 case LOG_T:
2270                                 case SETFLAG_T:
2271                                 case RESETFLAG_T:
2272                                 case ISFLAGSET_T:
2273                                 case IF_T:
2274                                 case MODULE0_T:
2275                                 case MODULE1_T:
2276                                 case MODULE2_T:
2277                                 case MODULE3_T:
2278                                 case MODULE4_T:
2279                                 case MODULE5_T:
2280                                 case MODULE6_T:
2281                                 case MODULEX_T:
2282                                 case SET_FWD_NO_CONNECT_T:
2283                                 case SET_RPL_NO_CONNECT_T:
2284                                 case SET_FWD_CLOSE_T:
2285                                 case SET_RPL_CLOSE_T:
2286                                         $$=$1;
2287                                         break;
2288                                 default:
2289                                         $$=0;
2290                                         yyerror("command not allowed in onsend_route\n");
2291                         }
2292                 } else {
2293                         $$=$1;
2294                 }
2295         }
2296         ;
2297 /*
2298 exp_stm:
2299         fcmd    { $$=$1; }
2300         | if_cmd        { $$=$1; }
2301         | assign_action { $$ = $1; }
2302         | LBRACE actions RBRACE { $$=$2; }
2303         ;
2304 */
2305 stm:
2306         action  { $$=$1; }
2307         | LBRACE actions RBRACE { $$=$2; }
2308         ;
2309 actions:
2310         actions action  {$$=append_action($1, $2); }
2311         | action        {$$=$1;}
2312         | actions error { $$=0; yyerror("bad command"); }
2313         ;
2314 action:
2315         fcmd SEMICOLON {$$=$1;}
2316         | if_cmd {$$=$1;}
2317         | switch_cmd {$$=$1;}
2318         | while_cmd { $$=$1; }
2319         | ret_cmd SEMICOLON { $$=$1; }
2320         | assign_action SEMICOLON {$$=$1;}
2321         | SEMICOLON /* null action */ {$$=0;}
2322         | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
2323         ;
2324 if_cmd:
2325         IF rval_expr stm        {
2326                 if ($2 && rval_expr_int_check($2)>=0){
2327                         warn_ct_rve($2, "if");
2328                         $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
2329                         set_cfg_pos($$);
2330                 }else
2331                         YYERROR;
2332         }
2333         | IF rval_expr stm ELSE stm     { 
2334                 if ($2 && rval_expr_int_check($2)>=0){
2335                         warn_ct_rve($2, "if");
2336                         $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5);
2337                         set_cfg_pos($$);
2338                 }else
2339                         YYERROR;
2340         }
2341         ;
2342
2343 ct_rval: rval_expr {
2344                         $$=0;
2345                         if ($1 && !rve_is_constant($1)){
2346                                 yyerror("constant expected");
2347                                 YYERROR;
2348                         /*
2349                         } else if ($1 &&
2350                                                 !rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2351                                 yyerror("invalid expression (bad type)");
2352                         }else if ($1 && i_tmp!=RV_INT){
2353                                 yyerror("invalid expression type, int expected\n");
2354                         */
2355                         }else
2356                                 $$=$1;
2357                 }
2358 ;
2359 single_case:
2360         CASE ct_rval COLON actions {
2361                 $$=0;
2362                 if ($2==0) { yyerror ("bad case label"); YYERROR; }
2363                 else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
2364                                 YYABORT;
2365                 }
2366         }
2367 | CASE SLASH ct_rval COLON actions {
2368                 $$=0;
2369                 if ($3==0) { yyerror ("bad case label"); YYERROR; }
2370                 else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
2371                                 YYABORT;
2372                 }
2373         }
2374         | CASE ct_rval COLON {
2375                 $$=0;
2376                 if ($2==0) { yyerror ("bad case label"); YYERROR; }
2377                 else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2378                                 YYABORT;
2379                 }
2380         }
2381         | CASE SLASH ct_rval COLON {
2382                 $$=0;
2383                 if ($3==0) { yyerror ("bad regex case label"); YYERROR; }
2384                 else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
2385                                 YYABORT;
2386                 }
2387         }
2388         | DEFAULT COLON actions {
2389                 if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp=-10)){
2390                                 YYABORT;
2391                 }
2392         }
2393         | DEFAULT COLON {
2394                 if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2395                                 YYABORT;
2396                 }
2397         }
2398         | CASE error COLON actions { $$=0; yyerror("bad case label"); }
2399         | CASE SLASH error COLON actions { $$=0; yyerror("bad case regex label"); }
2400         | CASE error COLON { $$=0; yyerror("bad case label"); }
2401         | CASE SLASH error COLON { $$=0; yyerror("bad case regex label"); }
2402         | CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
2403 ;
2404 case_stms:
2405         case_stms single_case {
2406                 $$=$1;
2407                 if ($2==0) yyerror ("bad case");
2408                 if ($$){
2409                         *($$->append)=$2;
2410                         if (*($$->append)!=0)
2411                                 $$->append=&((*($$->append))->next);
2412                 }
2413         }
2414         | single_case {
2415                 $$=$1;
2416                 if ($1==0) yyerror ("bad case");
2417                 else $$->append=&($$->next);
2418         }
2419 ;
2420 switch_cmd:
2421           SWITCH rval_expr LBRACE case_stms RBRACE { 
2422                 $$=0;
2423                 if ($2==0){
2424                         yyerror("bad expression in switch(...)");
2425                         YYERROR;
2426                 }else if ($4==0){
2427                         yyerror ("bad switch body");
2428                         YYERROR;
2429                 }else if (case_check_default($4)!=0){
2430                         yyerror_at(&$2->fpos, "bad switch(): too many "
2431                                                         "\"default:\" labels\n");
2432                         YYERROR;
2433                 }else if (case_check_type($4)!=0){
2434                         yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
2435                                                         " string/RE cases not allowed\n");
2436                         YYERROR;
2437                 }else{
2438                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
2439                         if ($$==0) {
2440                                 yyerror("internal error");
2441                                 YYABORT;
2442                         }
2443                         set_cfg_pos($$);
2444                 }
2445         }
2446         | SWITCH rval_expr LBRACE RBRACE {
2447                 $$=0;
2448                 warn("empty switch()");
2449                 if ($2==0){
2450                         yyerror("bad expression in switch(...)");
2451                         YYERROR;
2452                 }else{
2453                         /* it might have sideffects, so leave it for the optimizer */
2454                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
2455                         if ($$==0) {
2456                                 yyerror("internal error");
2457                                 YYABORT;
2458                         }
2459                         set_cfg_pos($$);
2460                 }
2461         }
2462         | SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
2463         | SWITCH rval_expr LBRACE error RBRACE 
2464                 {$$=0; yyerror ("bad switch body"); }
2465 ;
2466
2467 while_cmd:
2468         WHILE rval_expr stm {
2469                 if ($2 && rval_expr_int_check($2)>=0){
2470                         warn_ct_rve($2, "while");
2471                         $$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2472                         set_cfg_pos($$);
2473                 }else{
2474                         yyerror_at(&$2->fpos, "bad while(...) expression");
2475                         YYERROR;
2476                 }
2477         }
2478 ;
2479
2480 /* class_id:
2481         LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
2482         | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
2483         | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
2484         ;
2485 */
2486 select_param:
2487         ID {
2488                 if (sel.n >= MAX_SELECT_PARAMS-1) {
2489                         yyerror("Select identifier too long\n");
2490                 }
2491                 sel.params[sel.n].type = SEL_PARAM_STR;
2492                 sel.params[sel.n].v.s.s = $1;
2493                 sel.params[sel.n].v.s.len = strlen($1);
2494                 sel.n++;
2495         }
2496         | ID LBRACK intno RBRACK {
2497                 if (sel.n >= MAX_SELECT_PARAMS-2) {
2498                         yyerror("Select identifier too long\n");
2499                 }
2500                 sel.params[sel.n].type = SEL_PARAM_STR;
2501                 sel.params[sel.n].v.s.s = $1;
2502                 sel.params[sel.n].v.s.len = strlen($1);
2503                 sel.n++;
2504                 sel.params[sel.n].type = SEL_PARAM_INT;
2505                 sel.params[sel.n].v.i = $3;
2506                 sel.n++;
2507         }
2508         | ID LBRACK STRING RBRACK {
2509                 if (sel.n >= MAX_SELECT_PARAMS-2) {
2510                         yyerror("Select identifier too long\n");
2511                 }
2512                 sel.params[sel.n].type = SEL_PARAM_STR;
2513                 sel.params[sel.n].v.s.s = $1;
2514                 sel.params[sel.n].v.s.len = strlen($1);
2515                 sel.n++;
2516                 sel.params[sel.n].type = SEL_PARAM_STR;
2517                 sel.params[sel.n].v.s.s = $3;
2518                 sel.params[sel.n].v.s.len = strlen($3);
2519                 sel.n++;
2520         }
2521         ;
2522 select_params:
2523         select_params DOT select_param
2524         | select_param
2525         ;
2526 select_id:
2527         SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
2528                 sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
2529                 if (!sel_ptr) {
2530                         yyerror("No memory left to allocate select structure\n");
2531                 }
2532                 memcpy(sel_ptr, &sel, sizeof(select_t));
2533                 $$ = sel_ptr;
2534         }
2535         ;
2536 attr_class_spec:
2537         ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
2538         | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
2539         | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
2540         | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
2541         | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
2542         | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
2543         | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
2544         | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
2545         | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
2546         ;
2547 attr_name_spec:
2548         ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
2549         ;
2550 attr_spec:
2551         attr_name_spec
2552         | attr_class_spec DOT attr_name_spec
2553         ;
2554 attr_mark:
2555         ATTR_MARK {
2556                 s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2557                 if (!s_attr) { yyerror("No memory left"); YYABORT; }
2558                 else s_attr->type = 0;
2559         }
2560         ;
2561 attr_id:
2562         attr_mark attr_spec { $$ = s_attr; }
2563         ;
2564 attr_id_num_idx:
2565         attr_mark attr_spec LBRACK intno RBRACK {
2566                 s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
2567                 s_attr->index = ($4<0?-$4:$4);
2568                 $$ = s_attr;
2569         }
2570         ;
2571 attr_id_no_idx:
2572         attr_mark attr_spec LBRACK RBRACK {
2573                 s_attr->type|= AVP_INDEX_ALL;
2574                 $$ = s_attr;
2575         }
2576         ;
2577 attr_id_ass:
2578         attr_id
2579         | attr_id_no_idx
2580         ;
2581 /*
2582 attr_id_val:
2583         attr_id
2584         | attr_id_num_idx
2585         ;
2586 */
2587 attr_id_any:
2588         attr_id
2589         | attr_id_no_idx
2590         | attr_id_num_idx
2591 ;
2592 attr_id_any_str:
2593         attr_id
2594         | avp_pvar {
2595                 if ($1->type==LV_AVP){
2596                         s_attr = pkg_malloc(sizeof(struct avp_spec));
2597                         if (!s_attr) { yyerror("No memory left"); YYABORT; }
2598                         else{
2599                                 *s_attr=$1->lv.avps;
2600                         }
2601                         $$=s_attr;
2602                 }else
2603                         $$=0; /* not an avp, a pvar */
2604                 pkg_free($1);
2605         }
2606         | STRING {
2607                 avp_spec_t *avp_spec;
2608                 str s;
2609                 int type, idx;
2610                 avp_spec = pkg_malloc(sizeof(*avp_spec));
2611                 if (!avp_spec) {
2612                         yyerror("Not enough memory");
2613                         YYABORT;
2614                 }
2615                 s.s = $1;
2616                 if (s.s[0] == '$')
2617                         s.s++;
2618                 s.len = strlen(s.s);
2619                 if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
2620                         yyerror("error when parsing AVP");
2621                         pkg_free(avp_spec);
2622                         YYABORT;
2623                 }
2624                 avp_spec->type = type;
2625                 avp_spec->index = idx;
2626                 $$ = avp_spec;
2627         }
2628         ;
2629
2630 pvar:   PVAR {
2631                         pv_spec=pkg_malloc(sizeof(*pv_spec));
2632                         if (!pv_spec) {
2633                                 yyerror("Not enough memory");
2634                                 YYABORT;
2635                         }
2636                         memset(pv_spec, 0, sizeof(*pv_spec));
2637                         s_tmp.s=$1; s_tmp.len=strlen($1);
2638                         if (pv_parse_spec(&s_tmp, pv_spec)==0){
2639                                 yyerror("unknown script pseudo variable %s", $1 );
2640                                 pkg_free(pv_spec);
2641                                 pv_spec=0;
2642                                 YYABORT;
2643                         }
2644                         $$=pv_spec;
2645                 }
2646         ;
2647
2648 avp_pvar:       AVP_OR_PVAR {
2649                                 lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2650                                 if (!lval_tmp) {
2651                                         yyerror("Not enough memory");
2652                                         YYABORT;
2653                                 }
2654                                 memset(lval_tmp, 0, sizeof(*lval_tmp));
2655                                 s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
2656                                 if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
2657                                         /* not a pvar, try avps */
2658                                         /* lval_tmp might be partially filled by the failed
2659                                            pv_parse_spec2() (especially if the avp name is the
2660                                            same as a pv class) => clean it again */
2661                                         memset(lval_tmp, 0, sizeof(*lval_tmp));
2662                                         lval_tmp->lv.avps.type|= AVP_NAME_STR;
2663                                         lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
2664                                         lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
2665                                         lval_tmp->type=LV_AVP;
2666                                 }else{
2667                                         lval_tmp->type=LV_PVAR;
2668                                 }
2669                                 $$ = lval_tmp;
2670                                 DBG("parsed ambigous avp/pvar \"%.*s\" to %d\n",
2671                                                         s_tmp.len, s_tmp.s, lval_tmp->type);
2672                         }
2673         ;
2674
2675
2676 /*
2677 assign_op:
2678         ADDEQ { $$ = ADD_T; }
2679         | EQUAL { $$ = ASSIGN_T; }
2680         ;
2681 */
2682 assign_op:
2683         EQUAL { $$ = ASSIGN_T; }
2684         ;
2685
2686
2687 lval: attr_id_ass {
2688                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2689                                         if (!lval_tmp) {
2690                                                 yyerror("Not enough memory");
2691                                                 YYABORT;
2692                                         }
2693                                         lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
2694                                         pkg_free($1); /* free the avp spec we just copied */
2695                                         $$=lval_tmp;
2696                                 }
2697         | pvar        {
2698                                         if (!pv_is_w($1))
2699                                                 yyerror("read only pvar in assignment left side");
2700                                         if ($1->trans!=0)
2701                                                 yyerror("pvar with transformations in assignment"
2702                                                                 " left side");
2703                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2704                                         if (!lval_tmp) {
2705                                                 yyerror("Not enough memory");
2706                                                 YYABORT;
2707                                         }
2708                                         lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=*($1);
2709                                         pkg_free($1); /* free the pvar spec we just copied */
2710                                         $$=lval_tmp;
2711                                 }
2712         | avp_pvar    {
2713                                         if (($1)->type==LV_PVAR){
2714                                                 if (!pv_is_w(&($1)->lv.pvs))
2715                                                         yyerror("read only pvar in assignment left side");
2716                                                 if ($1->lv.pvs.trans!=0)
2717                                                         yyerror("pvar with transformations in assignment"
2718                                                                         " left side");
2719                                         }
2720                                         $$=$1;
2721                                 }
2722         ;
2723
2724 rval: intno                     {$$=mk_rve_rval(RV_INT, (void*)$1); }
2725         | STRING                        {       s_tmp.s=$1; s_tmp.len=strlen($1);
2726                                                         $$=mk_rve_rval(RV_STR, &s_tmp); }
2727         | attr_id_any           {$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
2728         | pvar                          {$$=mk_rve_rval(RV_PVAR, $1); pkg_free($1); }
2729         | avp_pvar                      {
2730                                                         switch($1->type){
2731                                                                 case LV_AVP:
2732                                                                         $$=mk_rve_rval(RV_AVP, &$1->lv.avps);
2733                                                                         break;
2734                                                                 case LV_PVAR:
2735                                                                         $$=mk_rve_rval(RV_PVAR, &$1->lv.pvs);
2736                                                                         break;
2737                                                                 default:
2738                                                                         yyerror("BUG: invalid lvalue type ");
2739                                                                         YYABORT;
2740                                                         }
2741                                                         pkg_free($1); /* not needed anymore */
2742                                                 }
2743         | select_id                     {$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
2744         | fcmd                          {$$=mk_rve_rval(RV_ACTION_ST, $1); }
2745         | exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
2746         | LBRACE actions RBRACE {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2747         | LBRACE error RBRACE   { $$=0; yyerror("bad command block"); }
2748         | LPAREN assign_action RPAREN   {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2749         | LPAREN error RPAREN   { $$=0; yyerror("bad expression"); }
2750         ;
2751
2752
2753 rve_un_op: NOT  { $$=RVE_LNOT_OP; }
2754                 |  BIN_NOT      { $$=RVE_BNOT_OP; }
2755                 |  MINUS %prec UNARY    { $$=RVE_UMINUS_OP; }
2756                 /* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
2757         ;
2758
2759 /*
2760 rve_op:         PLUS            { $$=RVE_PLUS_OP; }
2761                 |       MINUS           { $$=RVE_MINUS_OP; }
2762                 |       STAR            { $$=RVE_MUL_OP; }
2763                 |       SLASH           { $$=RVE_DIV_OP; }
2764                 |       MODULO          { $$=RVE_MOD_OP; }
2765         ;
2766 */
2767
2768 rval_expr: rval                                         { $$=$1;
2769                                                                                 if ($$==0){
2770                                                                                         /*yyerror("out of memory\n");*/
2771                                                                                         YYERROR;
2772                                                                                 }
2773                                                                         }
2774                 | rve_un_op rval_expr %prec UNARY       {$$=mk_rve1($1, $2); }
2775                 | INTCAST rval_expr                             {$$=mk_rve1(RVE_INT_OP, $2); }
2776                 | STRCAST rval_expr                             {$$=mk_rve1(RVE_STR_OP, $2); }
2777                 | rval_expr PLUS rval_expr              {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
2778                 | rval_expr MINUS rval_expr             {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
2779                 | rval_expr STAR rval_expr              {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
2780                 | rval_expr SLASH rval_expr             {$$=mk_rve2(RVE_DIV_OP, $1, $3); }
2781                 | rval_expr MODULO rval_expr    {$$=mk_rve2(RVE_MOD_OP, $1, $3); }
2782                 | rval_expr BIN_OR rval_expr    {$$=mk_rve2(RVE_BOR_OP, $1,  $3); }
2783                 | rval_expr BIN_AND rval_expr   {$$=mk_rve2(RVE_BAND_OP, $1,  $3);}
2784                 | rval_expr BIN_XOR rval_expr   {$$=mk_rve2(RVE_BXOR_OP, $1,  $3);}
2785                 | rval_expr BIN_LSHIFT rval_expr {$$=mk_rve2(RVE_BLSHIFT_OP, $1,  $3);}
2786                 | rval_expr BIN_RSHIFT rval_expr {$$=mk_rve2(RVE_BRSHIFT_OP, $1,  $3);}
2787                 | rval_expr rve_cmpop rval_expr %prec GT { $$=mk_rve2( $2, $1, $3);}
2788                 | rval_expr rve_equalop rval_expr %prec EQUAL_T
2789                         { $$=mk_rve2( $2, $1, $3);}
2790                 | rval_expr LOG_AND rval_expr   { $$=mk_rve2(RVE_LAND_OP, $1, $3);}
2791                 | rval_expr LOG_OR rval_expr    { $$=mk_rve2(RVE_LOR_OP, $1, $3);}
2792                 | LPAREN rval_expr RPAREN               { $$=$2;}
2793                 | STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
2794                 | STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
2795                 | DEFINED rval_expr                             { $$=mk_rve1(RVE_DEFINED_OP, $2);}
2796                 | rve_un_op error %prec UNARY           { $$=0; yyerror("bad expression"); }
2797                 | INTCAST error                                 { $$=0; yyerror("bad expression"); }
2798                 | STRCAST error                                 { $$=0; yyerror("bad expression"); }
2799                 | rval_expr PLUS error                  { $$=0; yyerror("bad expression"); }
2800                 | rval_expr MINUS error                 { $$=0; yyerror("bad expression"); }
2801                 | rval_expr STAR error                  { $$=0; yyerror("bad expression"); }
2802                 | rval_expr SLASH error                 { $$=0; yyerror("bad expression"); }
2803                 | rval_expr MODULO error                        { $$=0; yyerror("bad expression"); }
2804                 | rval_expr BIN_OR error                { $$=0; yyerror("bad expression"); }
2805                 | rval_expr BIN_AND error               { $$=0; yyerror("bad expression"); }
2806                 | rval_expr rve_cmpop error %prec GT
2807                         { $$=0; yyerror("bad expression"); }
2808                 | rval_expr rve_equalop error %prec EQUAL_T
2809                         { $$=0; yyerror("bad expression"); }
2810                 | rval_expr LOG_AND error               { $$=0; yyerror("bad expression"); }
2811                 | rval_expr LOG_OR error                { $$=0; yyerror("bad expression"); }
2812                 | STRLEN LPAREN error RPAREN    { $$=0; yyerror("bad expression"); }
2813                 | STREMPTY LPAREN error RPAREN  { $$=0; yyerror("bad expression"); }
2814                 | DEFINED error                                 { $$=0; yyerror("bad expression"); }
2815                 ;
2816
2817 assign_action: lval assign_op  rval_expr        { $$=mk_action($2, 2, LVAL_ST, $1, 
2818                                                                                                                           RVE_ST, $3);
2819                                                                                         set_cfg_pos($$);
2820                                                                                 }
2821         ;
2822
2823 /*
2824 assign_action:
2825         attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
2826         | attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
2827         | attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
2828         | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
2829         | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
2830         | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
2831         ;
2832 */
2833
2834 avpflag_oper:
2835         SETAVPFLAG { $$ = 1; }
2836         | RESETAVPFLAG { $$ = 0; }
2837         | ISAVPFLAGSET { $$ = -1; }
2838         ;
2839 cmd:
2840         FORWARD LPAREN RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2841         | FORWARD LPAREN host RPAREN    { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2842         | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2843         | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2844         | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2845         | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2846         | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2847         | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2848         | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2849         | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2850         | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
2851         | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
2852         | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2853         | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2854         | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2855         | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2856         | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2857         | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2858         | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2859         | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2860         | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2861         | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
2862         | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
2863         | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2864         | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2865         | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2866         | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2867         | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2868         | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2869         | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2870         | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2871         | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2872         | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2873         | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
2874         | FORWARD_TLS LPAREN host RPAREN {
2875                 #ifdef USE_TLS
2876                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2877                 #else
2878                         $$=0;
2879                         yyerror("tls support not compiled in");
2880                 #endif
2881         }
2882         | FORWARD_TLS LPAREN STRING RPAREN {
2883                 #ifdef USE_TLS
2884                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2885                 #else
2886                         $$=0;
2887                         yyerror("tls support not compiled in");
2888                 #endif
2889         }
2890         | FORWARD_TLS LPAREN ip RPAREN  {
2891                 #ifdef USE_TLS
2892                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
2893                 #else
2894                         $$=0;
2895                         yyerror("tls support not compiled in");
2896                 #endif
2897         }
2898         | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
2899                 #ifdef USE_TLS
2900                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2901                 #else
2902                         $$=0;
2903                         yyerror("tls support not compiled in");
2904                 #endif
2905         }
2906         | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
2907                 #ifdef USE_TLS
2908                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2909                 #else
2910                         $$=0;
2911                         yyerror("tls support not compiled in");
2912                 #endif
2913         }
2914         | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
2915                 #ifdef USE_TLS
2916                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2917                 #else
2918                         $$=0;
2919                         yyerror("tls support not compiled in");
2920                 #endif
2921                                         }
2922         | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
2923                 #ifdef USE_TLS
2924                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
2925                 #else
2926                         $$=0;
2927                         yyerror("tls support not compiled in");
2928                 #endif
2929         }
2930         | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
2931                 #ifdef USE_TLS
2932                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2933                 #else
2934                         $$=0;
2935                         yyerror("tls support not compiled in");
2936                 #endif
2937         }
2938         | FORWARD_TLS LPAREN URIHOST RPAREN {
2939                 #ifdef USE_TLS
2940                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
2941                 #else
2942                         $$=0;
2943                         yyerror("tls support not compiled in");
2944                 #endif
2945         }
2946         | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
2947         | FORWARD_TLS LPAREN error RPAREN { $$=0; 
2948                                                                         yyerror("bad forward_tls argument"); }
2949         | FORWARD_SCTP LPAREN host RPAREN {
2950                 #ifdef USE_SCTP
2951                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2952                 #else
2953                         $$=0;
2954                         yyerror("sctp support not compiled in");
2955                 #endif
2956         }
2957         | FORWARD_SCTP LPAREN STRING RPAREN {
2958                 #ifdef USE_SCTP
2959                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2960                 #else
2961                         $$=0;
2962                         yyerror("sctp support not compiled in");
2963                 #endif
2964         }
2965         | FORWARD_SCTP LPAREN ip RPAREN {
2966                 #ifdef USE_SCTP
2967                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
2968                 #else
2969                         $$=0;
2970                         yyerror("sctp support not compiled in");
2971                 #endif
2972         }
2973         | FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
2974                 #ifdef USE_SCTP
2975                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2976                                                         (void*)$5); set_cfg_pos($$);
2977                 #else
2978                         $$=0;
2979                         yyerror("sctp support not compiled in");
2980                 #endif
2981         }
2982         | FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
2983                 #ifdef USE_SCTP
2984                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2985                                                         (void*)$5); set_cfg_pos($$);
2986                 #else
2987                         $$=0;
2988                         yyerror("sctp support not compiled in");
2989                 #endif
2990         }
2991         | FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
2992                 #ifdef USE_SCTP
2993                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 
2994                                                         (void*)$5); set_cfg_pos($$);
2995                 #else
2996                         $$=0;
2997                         yyerror("sctp support not compiled in");
2998                 #endif
2999                                         }
3000         | FORWARD_SCTP LPAREN URIHOST COMMA URIPORT RPAREN {
3001                 #ifdef USE_SCTP
3002                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
3003                 #else
3004                         $$=0;
3005                         yyerror("sctp support not compiled in");
3006                 #endif
3007         }
3008         | FORWARD_SCTP LPAREN URIHOST COMMA NUMBER RPAREN {
3009                 #ifdef USE_SCTP
3010                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST,
3011                                                         (void*)$5); set_cfg_pos($$);
3012                 #else
3013                         $$=0;
3014                         yyerror("sctp support not compiled in");
3015                 #endif
3016         }
3017         | FORWARD_SCTP LPAREN URIHOST RPAREN {
3018                 #ifdef USE_SCTP
3019                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
3020                 #else
3021                         $$=0;
3022                         yyerror("tls support not compiled in");
3023                 #endif
3024         }
3025         | FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
3026         | FORWARD_SCTP LPAREN error RPAREN { $$=0; 
3027                                                                         yyerror("bad forward_tls argument"); }
3028         | SEND LPAREN host RPAREN       { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3029         | SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3030         | SEND LPAREN ip RPAREN         { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
3031         | SEND LPAREN host COMMA NUMBER RPAREN  { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3032         | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3033         | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3034         | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
3035         | SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
3036         | SEND_TCP LPAREN host RPAREN   { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3037         | SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3038         | SEND_TCP LPAREN ip RPAREN     { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
3039         | SEND_TCP LPAREN host COMMA NUMBER RPAREN      { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);}
3040         | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3041         | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3042         | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
3043         | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
3044         | LOG_TOK LPAREN STRING RPAREN  {$$=mk_action(LOG_T, 2, NUMBER_ST,
3045                                                                                 (void*)(L_DBG+1), STRING_ST, $3);
3046                                                                         set_cfg_pos($$); }
3047         | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN     {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); set_cfg_pos($$); }
3048         | LOG_TOK error                 { $$=0; yyerror("missing '(' or ')' ?"); }
3049         | LOG_TOK LPAREN error RPAREN   { $$=0; yyerror("bad log argument"); }
3050         | SETFLAG LPAREN NUMBER RPAREN  {
3051                                                         if (check_flag($3)==-1)
3052                                                                 yyerror("bad flag value");
3053                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
3054                                                                                                         (void*)$3);
3055                                                         set_cfg_pos($$);
3056                                                                         }
3057         | SETFLAG LPAREN flag_name RPAREN       {
3058                                                         i_tmp=get_flag_no($3, strlen($3));
3059                                                         if (i_tmp<0) yyerror("flag not declared");
3060                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
3061                                                                                 (void*)(long)i_tmp);
3062                                                         set_cfg_pos($$);
3063                                                                         }
3064         | SETFLAG error                 { $$=0; yyerror("missing '(' or ')'?"); }
3065         | RESETFLAG LPAREN NUMBER RPAREN {
3066                                                         if (check_flag($3)==-1)
3067                                                                 yyerror("bad flag value");
3068                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
3069                                                         set_cfg_pos($$);
3070                                                                         }
3071         | RESETFLAG LPAREN flag_name RPAREN     {
3072                                                         i_tmp=get_flag_no($3, strlen($3));
3073                                                         if (i_tmp<0) yyerror("flag not declared");
3074                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
3075                                                                                 (void*)(long)i_tmp);
3076                                                         set_cfg_pos($$);
3077                                                                         }
3078         | RESETFLAG error               { $$=0; yyerror("missing '(' or ')'?"); }
3079         | ISFLAGSET LPAREN NUMBER RPAREN {
3080                                                         if (check_flag($3)==-1)
3081                                                                 yyerror("bad flag value");
3082                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
3083                                                         set_cfg_pos($$);
3084                                                                         }
3085         | ISFLAGSET LPAREN flag_name RPAREN     {
3086                                                         i_tmp=get_flag_no($3, strlen($3));
3087                                                         if (i_tmp<0) yyerror("flag not declared");
3088                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
3089                                                                                 (void*)(long)i_tmp);
3090                                                         set_cfg_pos($$);
3091                                                                         }
3092         | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
3093         | avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
3094                 i_tmp=get_avpflag_no($5);
3095                 if (i_tmp==0) yyerror("avpflag not declared");
3096                 $$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
3097                 set_cfg_pos($$);
3098         }
3099         | avpflag_oper LPAREN attr_id_any_str COMMA error RPAREN {
3100                 $$=0; yyerror("error parsing flag name");
3101         }
3102         | avpflag_oper LPAREN error COMMA flag_name RPAREN {
3103                 $$=0; yyerror("error parsing first parameter (avp or string)");
3104         }
3105         | avpflag_oper LPAREN error RPAREN { $$=0; yyerror("bad parameters"); }
3106         | avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
3107         | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5);
3108                         set_cfg_pos($$);