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