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