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