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