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