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