- use_dns_cache can be enabled/disabled runtime
[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 */
92
93 %{
94
95 #include <stdlib.h>
96 #include <stdio.h>
97 #include <sys/types.h>
98 #include <sys/socket.h>
99 #include <netinet/in.h>
100 #include <arpa/inet.h>
101 #include <string.h>
102 #include <errno.h>
103 #include "route_struct.h"
104 #include "globals.h"
105 #include "route.h"
106 #include "dprint.h"
107 #include "sr_module.h"
108 #include "modparam.h"
109 #include "ip_addr.h"
110 #include "resolve.h"
111 #include "socket_info.h"
112 #include "name_alias.h"
113 #include "ut.h"
114 #include "dset.h"
115 #include "select.h"
116 #include "flags.h"
117 #include "tcp_init.h"
118 #include "tcp_options.h"
119
120 #include "config.h"
121 #include "cfg_core.h"
122 #include "cfg/cfg.h"
123 #ifdef CORE_TLS
124 #include "tls/tls_config.h"
125 #endif
126
127 #ifdef DEBUG_DMALLOC
128 #include <dmalloc.h>
129 #endif
130
131 /* hack to avoid alloca usage in the generated C file (needed for compiler
132  with no built in alloca, like icc*/
133 #undef _ALLOCA_H
134
135 #define onsend_check(s) \
136         do{\
137                 if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\
138         }while(0)
139
140
141 #ifdef USE_DNS_CACHE
142         #define IF_DNS_CACHE(x) x
143 #else
144         #define IF_DNS_CACHE(x) warn("dns cache support not compiled in")
145 #endif
146
147 #ifdef USE_DNS_FAILOVER
148         #define IF_DNS_FAILOVER(x) x
149 #else
150         #define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in")
151 #endif
152
153 #ifdef USE_NAPTR
154         #define IF_NAPTR(x) x
155 #else
156         #define IF_NAPTR(x) warn("dns naptr support not compiled in")
157 #endif
158
159 #ifdef USE_DST_BLACKLIST
160         #define IF_DST_BLACKLIST(x) x
161 #else
162         #define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
163 #endif
164
165 #ifdef USE_STUN
166         #define IF_STUN(x) x
167 #else 
168         #define IF_STUN(x) warn("stun support not compiled in")
169 #endif
170
171
172 extern int yylex();
173 static void yyerror(char* s);
174 static char* tmp;
175 static int i_tmp;
176 static struct socket_id* lst_tmp;
177 static int rt;  /* Type of route block for find_export */
178 static str* str_tmp;
179 static str s_tmp;
180 static struct ip_addr* ip_tmp;
181 static struct avp_spec* s_attr;
182 static select_t sel;
183 static select_t* sel_ptr;
184 static struct action *mod_func_action;
185
186 static void warn(char* s);
187 static struct socket_id* mk_listen_id(char*, int, int);
188
189 %}
190
191 %union {
192         long intval;
193         unsigned long uval;
194         char* strval;
195         struct expr* expr;
196         struct action* action;
197         struct net* ipnet;
198         struct ip_addr* ipaddr;
199         struct socket_id* sockid;
200         struct avp_spec* attr;
201         select_t* select;
202 }
203
204 /* terminals */
205
206
207 /* keywords */
208 %token FORWARD
209 %token FORWARD_TCP
210 %token FORWARD_TLS
211 %token FORWARD_UDP
212 %token SEND
213 %token SEND_TCP
214 %token DROP
215 %token RETURN
216 %token BREAK
217 %token LOG_TOK
218 %token ERROR
219 %token ROUTE
220 %token ROUTE_FAILURE
221 %token ROUTE_ONREPLY
222 %token ROUTE_BRANCH
223 %token ROUTE_SEND
224 %token EXEC
225 %token SET_HOST
226 %token SET_HOSTPORT
227 %token PREFIX
228 %token STRIP
229 %token STRIP_TAIL
230 %token APPEND_BRANCH
231 %token SET_USER
232 %token SET_USERPASS
233 %token SET_PORT
234 %token SET_URI
235 %token REVERT_URI
236 %token FORCE_RPORT
237 %token FORCE_TCP_ALIAS
238 %token IF
239 %token ELSE
240 %token SET_ADV_ADDRESS
241 %token SET_ADV_PORT
242 %token FORCE_SEND_SOCKET
243 %token URIHOST
244 %token URIPORT
245 %token MAX_LEN
246 %token SETFLAG
247 %token RESETFLAG
248 %token ISFLAGSET
249 %token SETAVPFLAG
250 %token RESETAVPFLAG
251 %token ISAVPFLAGSET
252 %token METHOD
253 %token URI
254 %token FROM_URI
255 %token TO_URI
256 %token SRCIP
257 %token SRCPORT
258 %token DSTIP
259 %token DSTPORT
260 %token TOIP
261 %token TOPORT
262 %token SNDIP
263 %token SNDPORT
264 %token SNDPROTO
265 %token SNDAF
266 %token PROTO
267 %token AF
268 %token MYSELF
269 %token MSGLEN
270 %token RETCODE
271 %token UDP
272 %token TCP
273 %token TLS
274
275 /* config vars. */
276 %token DEBUG_V
277 %token FORK
278 %token LOGSTDERROR
279 %token LOGFACILITY
280 %token LISTEN
281 %token ALIAS
282 %token DNS
283 %token REV_DNS
284 %token DNS_TRY_IPV6
285 %token DNS_TRY_NAPTR
286 %token DNS_SRV_LB
287 %token DNS_UDP_PREF
288 %token DNS_TCP_PREF
289 %token DNS_TLS_PREF
290 %token DNS_RETR_TIME
291 %token DNS_RETR_NO
292 %token DNS_SERVERS_NO
293 %token DNS_USE_SEARCH
294 %token DNS_SEARCH_FMATCH
295 %token DNS_CACHE_INIT
296 %token DNS_USE_CACHE
297 %token DNS_USE_FAILOVER
298 %token DNS_CACHE_FLAGS
299 %token DNS_CACHE_NEG_TTL
300 %token DNS_CACHE_MIN_TTL
301 %token DNS_CACHE_MAX_TTL
302 %token DNS_CACHE_MEM
303 %token DNS_CACHE_GC_INT
304 %token DNS_CACHE_DEL_NONEXP
305 /*blacklist*/
306 %token DST_BLST_INIT
307 %token USE_DST_BLST
308 %token DST_BLST_MEM
309 %token DST_BLST_TTL
310 %token DST_BLST_GC_INT
311
312 %token PORT
313 %token STAT
314 %token CHILDREN
315 %token CHECK_VIA
316 %token PHONE2TEL
317 %token SYN_BRANCH
318 %token MEMLOG
319 %token MEMDBG
320 %token SIP_WARNING
321 %token SERVER_SIGNATURE
322 %token REPLY_TO_VIA
323 %token LOADMODULE
324 %token MODPARAM
325 %token MAXBUFFER
326 %token USER
327 %token GROUP
328 %token CHROOT
329 %token WDIR
330 %token MHOMED
331 %token DISABLE_TCP
332 %token TCP_ACCEPT_ALIASES
333 %token TCP_CHILDREN
334 %token TCP_CONNECT_TIMEOUT
335 %token TCP_SEND_TIMEOUT
336 %token TCP_CON_LIFETIME
337 %token TCP_POLL_METHOD
338 %token TCP_MAX_CONNECTIONS
339 %token TCP_SOURCE_IPV4
340 %token TCP_SOURCE_IPV6
341 %token TCP_OPT_FD_CACHE
342 %token TCP_OPT_BUF_WRITE
343 %token TCP_OPT_CONN_WQ_MAX
344 %token TCP_OPT_WQ_MAX
345 %token TCP_OPT_DEFER_ACCEPT
346 %token TCP_OPT_DELAYED_ACK
347 %token TCP_OPT_SYNCNT
348 %token TCP_OPT_LINGER2
349 %token TCP_OPT_KEEPALIVE
350 %token TCP_OPT_KEEPIDLE
351 %token TCP_OPT_KEEPINTVL
352 %token TCP_OPT_KEEPCNT
353 %token DISABLE_TLS
354 %token ENABLE_TLS
355 %token TLSLOG
356 %token TLS_PORT_NO
357 %token TLS_METHOD
358 %token TLS_HANDSHAKE_TIMEOUT
359 %token TLS_SEND_TIMEOUT
360 %token SSLv23
361 %token SSLv2
362 %token SSLv3
363 %token TLSv1
364 %token TLS_VERIFY
365 %token TLS_REQUIRE_CERTIFICATE
366 %token TLS_CERTIFICATE
367 %token TLS_PRIVATE_KEY
368 %token TLS_CA_LIST
369 %token ADVERTISED_ADDRESS
370 %token ADVERTISED_PORT
371 %token DISABLE_CORE
372 %token OPEN_FD_LIMIT
373 %token SHM_FORCE_ALLOC
374 %token MLOCK_PAGES
375 %token REAL_TIME
376 %token RT_PRIO
377 %token RT_POLICY
378 %token RT_TIMER1_PRIO
379 %token RT_TIMER1_POLICY
380 %token RT_TIMER2_PRIO
381 %token RT_TIMER2_POLICY
382 %token MCAST_LOOPBACK
383 %token MCAST_TTL
384 %token TOS
385 %token PMTU_DISCOVERY
386 %token KILL_TIMEOUT
387 %token CFG_DESCRIPTION
388
389 %token FLAGS_DECL
390 %token AVPFLAGS_DECL
391
392 %token ATTR_MARK
393 %token SELECT_MARK
394 %token ATTR_FROM
395 %token ATTR_TO
396 %token ATTR_FROMURI
397 %token ATTR_TOURI
398 %token ATTR_FROMUSER
399 %token ATTR_TOUSER
400 %token ATTR_FROMDOMAIN
401 %token ATTR_TODOMAIN
402 %token ATTR_GLOBAL
403 %token ADDEQ
404
405 %token STUN_REFRESH_INTERVAL
406 %token STUN_ALLOW_STUN
407 %token STUN_ALLOW_FP
408
409
410 /* operators */
411 %nonassoc EQUAL
412 %nonassoc EQUAL_T
413 %nonassoc GT
414 %nonassoc LT
415 %nonassoc GTE
416 %nonassoc LTE
417 %nonassoc DIFF
418 %nonassoc MATCH
419 %left LOG_OR
420 %left LOG_AND
421 %left BIN_OR
422 %left BIN_AND
423 %left PLUS MINUS
424 %right NOT
425
426 /* values */
427 %token <intval> NUMBER
428 %token <strval> ID
429 %token <strval> STRING
430 %token <strval> IPV6ADDR
431
432 /* other */
433 %token COMMA
434 %token SEMICOLON
435 %token RPAREN
436 %token LPAREN
437 %token LBRACE
438 %token RBRACE
439 %token LBRACK
440 %token RBRACK
441 %token SLASH
442 %token DOT
443 %token CR
444 %token COLON
445 %token STAR
446
447
448 /*non-terminals */
449 %type <expr> exp exp_elem /*, condition*/
450 %type <action> action actions cmd fcmd if_cmd stm exp_stm assign_action
451 %type <ipaddr> ipv4 ipv6 ipv6addr ip
452 %type <ipnet> ipnet
453 %type <strval> host
454 %type <strval> listen_id
455 %type <sockid>  id_lst
456 %type <sockid>  phostport
457 %type <intval> proto port
458 %type <intval> equalop strop intop binop
459 %type <strval> host_sep
460 %type <intval> uri_type
461 %type <attr> attr_id
462 %type <attr> attr_id_num_idx
463 %type <attr> attr_id_no_idx
464 %type <attr> attr_id_ass
465 %type <attr> attr_id_val
466 %type <attr> attr_id_any
467 %type <attr> attr_id_any_str
468 /* %type <intval> class_id */
469 %type <intval> assign_op
470 %type <select> select_id
471 %type <strval>  flag_name;
472 %type <strval>  route_name;
473 %type <intval> avpflag_oper
474
475 /*%type <route_el> rules;
476   %type <route_el> rule;
477 */
478
479 %%
480
481
482 cfg:
483         statements
484         ;
485 statements:
486         statements statement {}
487         | statement {}
488         | statements error { yyerror(""); YYABORT;}
489         ;
490 statement:
491         assign_stm
492         | flags_decl
493         | avpflags_decl
494         | module_stm
495         | {rt=REQUEST_ROUTE;} route_stm
496         | {rt=FAILURE_ROUTE;} failure_route_stm
497         | {rt=ONREPLY_ROUTE;} onreply_route_stm
498         | {rt=BRANCH_ROUTE;} branch_route_stm
499         | {rt=ONSEND_ROUTE;}   send_route_stm
500         | SEMICOLON     /* null statement */
501         | CR    /* null statement*/
502         ;
503 listen_id:
504         ip {
505                 tmp=ip_addr2a($1);
506                 if (tmp==0) {
507                         LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
508                                         "address.\n");
509                         $$=0;
510                 } else {
511                         $$=pkg_malloc(strlen(tmp)+1);
512                         if ($$==0) {
513                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
514                                                 "memory.\n");
515                         } else {
516                                 strncpy($$, tmp, strlen(tmp)+1);
517                         }
518                 }
519         }
520         | STRING {
521                 $$=pkg_malloc(strlen($1)+1);
522                 if ($$==0) {
523                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
524                                                 "memory.\n");
525                 } else {
526                                 strncpy($$, $1, strlen($1)+1);
527                 }
528         }
529         | host {
530                 $$=pkg_malloc(strlen($1)+1);
531                 if ($$==0) {
532                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
533                                                 "memory.\n");
534                 } else {
535                                 strncpy($$, $1, strlen($1)+1);
536                 }
537         }
538         ;
539 proto:
540         UDP     { $$=PROTO_UDP; }
541         | TCP   { $$=PROTO_TCP; }
542         | TLS   { $$=PROTO_TLS; }
543         | STAR  { $$=0; }
544         ;
545 port:
546         NUMBER  { $$=$1; }
547         | STAR  { $$=0; }
548 ;
549 phostport:
550         listen_id               { $$=mk_listen_id($1, 0, 0); }
551         | listen_id COLON port  { $$=mk_listen_id($1, 0, $3); }
552         | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
553         | proto COLON listen_id COLON port      { $$=mk_listen_id($3, $1, $5);}
554         | listen_id COLON error { $$=0; yyerror(" port number expected"); }
555         ;
556 id_lst:
557         phostport               {  $$=$1 ; }
558         | phostport id_lst      { $$=$1; $$->next=$2; }
559         ;
560
561 flags_decl:             FLAGS_DECL      flag_list
562                         |       FLAGS_DECL error { yyerror("flag list expected\n"); }
563 ;
564 flag_list:              flag_spec
565                         |       flag_spec COMMA flag_list
566 ;
567
568 flag_spec:              flag_name       { if (register_flag($1,-1)<0)
569                                                                 yyerror("register flag failed");
570                                                 }
571                         |       flag_name COLON NUMBER {
572                                                 if (register_flag($1, $3)<0)
573                                                                 yyerror("register flag failed");
574                                                                                 }
575 ;
576
577 flag_name:              STRING  { $$=$1; }
578                         |       ID              { $$=$1; }
579 ;
580
581 avpflags_decl:
582         AVPFLAGS_DECL avpflag_list
583         | AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
584         ;
585 avpflag_list:
586         avpflag_spec
587         | avpflag_spec COMMA avpflag_list
588         ;
589 avpflag_spec:
590         flag_name {
591                 if (register_avpflag($1)==0)
592                         yyerror("cannot declare avpflag");
593         }
594         ;
595 assign_stm:
596         DEBUG_V EQUAL NUMBER { default_core_cfg.debug=$3; }
597         | DEBUG_V EQUAL error  { yyerror("number  expected"); }
598         | FORK  EQUAL NUMBER { dont_fork= ! $3; }
599         | FORK  EQUAL error  { yyerror("boolean value expected"); }
600         | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
601         | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
602         | LOGFACILITY EQUAL ID {
603                 if ( (i_tmp=str2facility($3))==-1)
604                         yyerror("bad facility (see syslog(3) man page)");
605                 if (!config_check)
606                         log_facility=i_tmp;
607         }
608         | LOGFACILITY EQUAL error { yyerror("ID expected"); }
609         | DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
610         | DNS EQUAL error { yyerror("boolean value expected"); }
611         | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
612         | REV_DNS EQUAL error { yyerror("boolean value expected"); }
613         | DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
614         | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
615         | DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
616         | DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
617         | DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
618         | DNS_SRV_LB error { yyerror("boolean value expected"); }
619         | DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_udp_pref=$3); }
620         | DNS_UDP_PREF error { yyerror("number expected"); }
621         | DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3); }
622         | DNS_TCP_PREF error { yyerror("number expected"); }
623         | DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tls_pref=$3); }
624         | DNS_TLS_PREF error { yyerror("number expected"); }
625         | DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
626         | DNS_RETR_TIME error { yyerror("number expected"); }
627         | DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
628         | DNS_RETR_NO error { yyerror("number expected"); }
629         | DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
630         | DNS_SERVERS_NO error { yyerror("number expected"); }
631         | DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
632         | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
633         | DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
634         | DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
635         | DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
636         | DNS_CACHE_INIT error { yyerror("boolean value expected"); }
637         | DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
638         | DNS_USE_CACHE error { yyerror("boolean value expected"); }
639         | DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
640         | DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
641         | DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
642         | DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
643         | DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
644         | DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
645         | DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
646         | DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
647         | DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
648         | DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
649         | DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
650         | DNS_CACHE_MEM error { yyerror("boolean value expected"); }
651         | DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
652         | DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
653         | DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
654         | DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
655         | DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
656         | DST_BLST_INIT error { yyerror("boolean value expected"); }
657         | USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
658         | USE_DST_BLST error { yyerror("boolean value expected"); }
659         | DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }
660         | DST_BLST_MEM error { yyerror("boolean value expected"); }
661         | DST_BLST_TTL EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3); }
662         | DST_BLST_TTL error { yyerror("boolean value expected"); }
663         | DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
664         | DST_BLST_GC_INT error { yyerror("boolean value expected"); }
665         | PORT EQUAL NUMBER   { port_no=$3; }
666         | STAT EQUAL STRING {
667                 #ifdef STATS
668                                 stat_file=$3;
669                 #endif
670         }
671         | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
672         | MAXBUFFER EQUAL error { yyerror("number expected"); }
673         | PORT EQUAL error    { yyerror("number expected"); }
674         | CHILDREN EQUAL NUMBER { children_no=$3; }
675         | CHILDREN EQUAL error { yyerror("number expected"); }
676         | CHECK_VIA EQUAL NUMBER { check_via=$3; }
677         | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
678         | PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
679         | PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
680         | SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
681         | SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
682         | MEMLOG EQUAL NUMBER { memlog=$3; }
683         | MEMLOG EQUAL error { yyerror("int value expected"); }
684         | MEMDBG EQUAL NUMBER { memdbg=$3; }
685         | MEMDBG EQUAL error { yyerror("int value expected"); }
686         | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
687         | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
688         | USER EQUAL STRING     { user=$3; }
689         | USER EQUAL ID         { user=$3; }
690         | USER EQUAL error      { yyerror("string value expected"); }
691         | GROUP EQUAL STRING     { group=$3; }
692         | GROUP EQUAL ID         { group=$3; }
693         | GROUP EQUAL error      { yyerror("string value expected"); }
694         | CHROOT EQUAL STRING     { chroot_dir=$3; }
695         | CHROOT EQUAL ID         { chroot_dir=$3; }
696         | CHROOT EQUAL error      { yyerror("string value expected"); }
697         | WDIR EQUAL STRING     { working_dir=$3; }
698         | WDIR EQUAL ID         { working_dir=$3; }
699         | WDIR EQUAL error      { yyerror("string value expected"); }
700         | MHOMED EQUAL NUMBER { mhomed=$3; }
701         | MHOMED EQUAL error { yyerror("boolean value expected"); }
702         | DISABLE_TCP EQUAL NUMBER {
703                 #ifdef USE_TCP
704                         tcp_disable=$3;
705                 #else
706                         warn("tcp support not compiled in");
707                 #endif
708         }
709         | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
710         | TCP_ACCEPT_ALIASES EQUAL NUMBER {
711                 #ifdef USE_TCP
712                         tcp_accept_aliases=$3;
713                 #else
714                         warn("tcp support not compiled in");
715                 #endif
716         }
717         | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
718         | TCP_CHILDREN EQUAL NUMBER {
719                 #ifdef USE_TCP
720                         tcp_children_no=$3;
721                 #else
722                         warn("tcp support not compiled in");
723                 #endif
724         }
725         | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
726         | TCP_CONNECT_TIMEOUT EQUAL NUMBER {
727                 #ifdef USE_TCP
728                         tcp_connect_timeout=$3;
729                 #else
730                         warn("tcp support not compiled in");
731                 #endif
732         }
733         | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
734         | TCP_SEND_TIMEOUT EQUAL NUMBER {
735                 #ifdef USE_TCP
736                         tcp_send_timeout=$3;
737                 #else
738                         warn("tcp support not compiled in");
739                 #endif
740         }
741         | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
742         | TCP_CON_LIFETIME EQUAL NUMBER {
743                 #ifdef USE_TCP
744                         tcp_con_lifetime=$3;
745                 #else
746                         warn("tcp support not compiled in");
747                 #endif
748         }
749         | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
750         | TCP_POLL_METHOD EQUAL ID {
751                 #ifdef USE_TCP
752                         tcp_poll_method=get_poll_type($3);
753                         if (tcp_poll_method==POLL_NONE) {
754                                 LOG(L_CRIT, "bad poll method name:"
755                                                 " %s\n, try one of %s.\n",
756                                                 $3, poll_support);
757                                 yyerror("bad tcp_poll_method "
758                                                 "value");
759                         }
760                 #else
761                         warn("tcp support not compiled in");
762                 #endif
763         }
764         | TCP_POLL_METHOD EQUAL STRING {
765                 #ifdef USE_TCP
766                         tcp_poll_method=get_poll_type($3);
767                         if (tcp_poll_method==POLL_NONE) {
768                                 LOG(L_CRIT, "bad poll method name:"
769                                                 " %s\n, try one of %s.\n",
770                                                 $3, poll_support);
771                                 yyerror("bad tcp_poll_method "
772                                                 "value");
773                         }
774                 #else
775                         warn("tcp support not compiled in");
776                 #endif
777         }
778         | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
779         | TCP_MAX_CONNECTIONS EQUAL NUMBER {
780                 #ifdef USE_TCP
781                         tcp_max_connections=$3;
782                 #else
783                         warn("tcp support not compiled in");
784                 #endif
785         }
786         | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
787         | TCP_SOURCE_IPV4 EQUAL ipv4 {
788                 #ifdef USE_TCP
789                         if (tcp_set_src_addr($3)<0)
790                                 warn("tcp_source_ipv4 failed");
791                 #else
792                         warn("tcp support not compiled in");
793                 #endif
794                 pkg_free($3);
795         }
796         | TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
797         | TCP_SOURCE_IPV6 EQUAL ipv6 {
798                 #ifdef USE_TCP
799                         #ifdef USE_IPV6
800                                 if (tcp_set_src_addr($3)<0)
801                                         warn("tcp_source_ipv6 failed");
802                         #else
803                                 warn("IPv6 support not compiled in");
804                         #endif
805                 #else
806                         warn("tcp support not compiled in");
807                 #endif
808                 pkg_free($3);
809         }
810         | TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
811         | TCP_OPT_FD_CACHE EQUAL NUMBER {
812                 #ifdef USE_TCP
813                         tcp_options.fd_cache=$3;
814                 #else
815                         warn("tcp support not compiled in");
816                 #endif
817         }
818         | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
819         | TCP_OPT_BUF_WRITE EQUAL NUMBER {
820                 #ifdef USE_TCP
821                         tcp_options.tcp_buf_write=$3;
822                 #else
823                         warn("tcp support not compiled in");
824                 #endif
825         }
826         | TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
827         | TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
828                 #ifdef USE_TCP
829                         tcp_options.tcpconn_wq_max=$3;
830                 #else
831                         warn("tcp support not compiled in");
832                 #endif
833         }
834         | TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
835         | TCP_OPT_WQ_MAX EQUAL NUMBER {
836                 #ifdef USE_TCP
837                         tcp_options.tcp_wq_max=$3;
838                 #else
839                         warn("tcp support not compiled in");
840                 #endif
841         }
842         | TCP_OPT_WQ_MAX error { yyerror("boolean value expected"); }
843         | TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
844                 #ifdef USE_TCP
845                         tcp_options.defer_accept=$3;
846                 #else
847                         warn("tcp support not compiled in");
848                 #endif
849         }
850         | TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
851         | TCP_OPT_DELAYED_ACK EQUAL NUMBER {
852                 #ifdef USE_TCP
853                         tcp_options.delayed_ack=$3;
854                 #else
855                         warn("tcp support not compiled in");
856                 #endif
857         }
858         | TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
859         | TCP_OPT_SYNCNT EQUAL NUMBER {
860                 #ifdef USE_TCP
861                         tcp_options.syncnt=$3;
862                 #else
863                         warn("tcp support not compiled in");
864                 #endif
865         }
866         | TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
867         | TCP_OPT_LINGER2 EQUAL NUMBER {
868                 #ifdef USE_TCP
869                         tcp_options.linger2=$3;
870                 #else
871                         warn("tcp support not compiled in");
872                 #endif
873         }
874         | TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
875         | TCP_OPT_KEEPALIVE EQUAL NUMBER {
876                 #ifdef USE_TCP
877                         tcp_options.keepalive=$3;
878                 #else
879                         warn("tcp support not compiled in");
880                 #endif
881         }
882         | TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
883         | TCP_OPT_KEEPIDLE EQUAL NUMBER {
884                 #ifdef USE_TCP
885                         tcp_options.keepidle=$3;
886                 #else
887                         warn("tcp support not compiled in");
888                 #endif
889         }
890         | TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
891         | TCP_OPT_KEEPINTVL EQUAL NUMBER {
892                 #ifdef USE_TCP
893                         tcp_options.keepintvl=$3;
894                 #else
895                         warn("tcp support not compiled in");
896                 #endif
897         }
898         | TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
899         | TCP_OPT_KEEPCNT EQUAL NUMBER {
900                 #ifdef USE_TCP
901                         tcp_options.keepcnt=$3;
902                 #else
903                         warn("tcp support not compiled in");
904                 #endif
905         }
906         | TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
907         | DISABLE_TLS EQUAL NUMBER {
908                 #ifdef USE_TLS
909                         tls_disable=$3;
910                 #else
911                         warn("tls support not compiled in");
912                 #endif
913         }
914         | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
915         | ENABLE_TLS EQUAL NUMBER {
916                 #ifdef USE_TLS
917                         tls_disable=!($3);
918                 #else
919                         warn("tls support not compiled in");
920                 #endif
921         }
922         | ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
923         | TLSLOG EQUAL NUMBER {
924                 #ifdef CORE_TLS
925                         tls_log=$3;
926                 #else
927                         warn("tls-in-core support not compiled in");
928                 #endif
929         }
930         | TLSLOG EQUAL error { yyerror("int value expected"); }
931         | TLS_PORT_NO EQUAL NUMBER {
932                 #ifdef USE_TLS
933                         tls_port_no=$3;
934                 #else
935                         warn("tls support not compiled in");
936                 #endif
937         }
938         | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
939         | TLS_METHOD EQUAL SSLv23 {
940                 #ifdef CORE_TLS
941                         tls_method=TLS_USE_SSLv23;
942                 #else
943                         warn("tls-in-core support not compiled in");
944                 #endif
945         }
946         | TLS_METHOD EQUAL SSLv2 {
947                 #ifdef CORE_TLS
948                         tls_method=TLS_USE_SSLv2;
949                 #else
950                         warn("tls-in-core support not compiled in");
951                 #endif
952         }
953         | TLS_METHOD EQUAL SSLv3 {
954                 #ifdef CORE_TLS
955                         tls_method=TLS_USE_SSLv3;
956                 #else
957                         warn("tls-in-core support not compiled in");
958                 #endif
959         }
960         | TLS_METHOD EQUAL TLSv1 {
961                 #ifdef CORE_TLS
962                         tls_method=TLS_USE_TLSv1;
963                 #else
964                         warn("tls-in-core support not compiled in");
965                 #endif
966         }
967         | TLS_METHOD EQUAL error {
968                 #ifdef CORE_TLS
969                         yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
970                 #else
971                         warn("tls-in-core support not compiled in");
972                 #endif
973         }
974         | TLS_VERIFY EQUAL NUMBER {
975                 #ifdef CORE_TLS
976                         tls_verify_cert=$3;
977                 #else
978                         warn("tls-in-core support not compiled in");
979                 #endif
980         }
981         | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
982         | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
983                 #ifdef CORE_TLS
984                         tls_require_cert=$3;
985                 #else
986                         warn( "tls-in-core support not compiled in");
987                 #endif
988         }
989         | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
990         | TLS_CERTIFICATE EQUAL STRING {
991                 #ifdef CORE_TLS
992                         tls_cert_file=$3;
993                 #else
994                         warn("tls-in-core support not compiled in");
995                 #endif
996         }
997         | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
998         | TLS_PRIVATE_KEY EQUAL STRING {
999                 #ifdef CORE_TLS
1000                         tls_pkey_file=$3;
1001                 #else
1002                         warn("tls-in-core support not compiled in");
1003                 #endif
1004         }
1005         | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1006         | TLS_CA_LIST EQUAL STRING {
1007                 #ifdef CORE_TLS
1008                         tls_ca_file=$3;
1009                 #else
1010                         warn("tls-in-core support not compiled in");
1011                 #endif
1012         }
1013         | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1014         | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
1015                 #ifdef CORE_TLS
1016                         tls_handshake_timeout=$3;
1017                 #else
1018                         warn("tls-in-core support not compiled in");
1019                 #endif
1020         }
1021         | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
1022         | TLS_SEND_TIMEOUT EQUAL NUMBER {
1023                 #ifdef CORE_TLS
1024                         tls_send_timeout=$3;
1025                 #else
1026                         warn("tls-in-core support not compiled in");
1027                 #endif
1028         }
1029         | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
1030         | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
1031         | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
1032         | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
1033         | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
1034         | LISTEN EQUAL id_lst {
1035                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1036                         if (add_listen_iface(lst_tmp->name, lst_tmp->port, lst_tmp->proto, 0)!=0) {
1037                                 LOG(L_CRIT,  "ERROR: cfg. parser: failed to add listen address\n");
1038                                 break;
1039                         }
1040                 }
1041         }
1042         | LISTEN EQUAL  error { yyerror("ip address or hostname expected"); }
1043         | ALIAS EQUAL  id_lst {
1044                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
1045                         add_alias(lst_tmp->name, strlen(lst_tmp->name), lst_tmp->port, lst_tmp->proto);
1046         }
1047         | ALIAS  EQUAL error  { yyerror(" hostname expected"); }
1048         | ADVERTISED_ADDRESS EQUAL listen_id {
1049                 default_global_address.s=$3;
1050                 default_global_address.len=strlen($3);
1051         }
1052         | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
1053         | ADVERTISED_PORT EQUAL NUMBER {
1054                 tmp=int2str($3, &i_tmp);
1055                 if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
1056                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1057                         default_global_port.len=0;
1058                 } else {
1059                         default_global_port.len=i_tmp;
1060                         memcpy(default_global_port.s, tmp, default_global_port.len);
1061                 };
1062         }
1063         |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
1064         | DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
1065         | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1066         | OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1067         | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1068         | SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
1069         | SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1070         | MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1071         | MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
1072         | REAL_TIME EQUAL NUMBER { real_time=$3; }
1073         | REAL_TIME EQUAL error { yyerror("boolean value expected"); }
1074         | RT_PRIO EQUAL NUMBER { rt_prio=$3; }
1075         | RT_PRIO EQUAL error { yyerror("boolean value expected"); }
1076         | RT_POLICY EQUAL NUMBER { rt_policy=$3; }
1077         | RT_POLICY EQUAL error { yyerror("boolean value expected"); }
1078         | RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
1079         | RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
1080         | RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
1081         | RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
1082         | RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
1083         | RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
1084         | RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
1085         | RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
1086         | MCAST_LOOPBACK EQUAL NUMBER {
1087                 #ifdef USE_MCAST
1088                         mcast_loopback=$3;
1089                 #else
1090                         warn("no multicast support compiled in");
1091                 #endif
1092         }
1093         | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
1094         | MCAST_TTL EQUAL NUMBER {
1095                 #ifdef USE_MCAST
1096                         mcast_ttl=$3;
1097                 #else
1098                         warn("no multicast support compiled in");
1099                 #endif
1100         }
1101         | MCAST_TTL EQUAL error { yyerror("number expected"); }
1102         | TOS EQUAL NUMBER { tos=$3; }
1103         | TOS EQUAL error { yyerror("number expected"); }
1104         | PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
1105         | PMTU_DISCOVERY error { yyerror("number expected"); }
1106         | KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
1107         | KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
1108         | STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
1109         | STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
1110         | STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
1111         | STUN_ALLOW_STUN EQUAL error{ yyerror("number expected"); }
1112         | STUN_ALLOW_FP EQUAL NUMBER { IF_STUN(stun_allow_fp=$3) ; }
1113         | STUN_ALLOW_FP EQUAL error{ yyerror("number expected"); }
1114         | cfg_var
1115         | error EQUAL { yyerror("unknown config variable"); }
1116         ;
1117 cfg_var:
1118         ID DOT ID EQUAL NUMBER {
1119                 if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1120                         yyerror("variable cannot be declared");
1121                 }
1122         }
1123         | ID DOT ID EQUAL STRING {
1124                 if (cfg_declare_str($1, $3, $5, NULL)) {
1125                         yyerror("variable cannot be declared");
1126                 }
1127         }
1128         | ID DOT ID EQUAL NUMBER CFG_DESCRIPTION STRING {
1129                 if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1130                         yyerror("variable cannot be declared");
1131                 }
1132         }
1133         | ID DOT ID EQUAL STRING CFG_DESCRIPTION STRING {
1134                 if (cfg_declare_str($1, $3, $5, $7)) {
1135                         yyerror("variable cannot be declared");
1136                 }
1137         }
1138         | ID DOT ID EQUAL error { yyerror("number or string expected"); }
1139         ;
1140 module_stm:
1141         LOADMODULE STRING {
1142                 DBG("loading module %s\n", $2);
1143                         if (load_module($2)!=0) {
1144                                 yyerror("failed to load module");
1145                         }
1146         }
1147         | LOADMODULE error      { yyerror("string expected"); }
1148         | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1149                 if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1150                          yyerror("Can't set module parameter");
1151                 }
1152         }
1153         | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1154                 if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1155                          yyerror("Can't set module parameter");
1156                 }
1157         }
1158         | MODPARAM error { yyerror("Invalid arguments"); }
1159         ;
1160 ip:
1161         ipv4  { $$=$1; }
1162         | ipv6  { $$=$1; }
1163         ;
1164 ipv4:
1165         NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
1166                 $$=pkg_malloc(sizeof(struct ip_addr));
1167                 if ($$==0) {
1168                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1169                 } else {
1170                         memset($$, 0, sizeof(struct ip_addr));
1171                         $$->af=AF_INET;
1172                         $$->len=4;
1173                         if (($1>255) || ($1<0) ||
1174                                 ($3>255) || ($3<0) ||
1175                                 ($5>255) || ($5<0) ||
1176                                 ($7>255) || ($7<0)) {
1177                                 yyerror("invalid ipv4 address");
1178                                 $$->u.addr32[0]=0;
1179                                 /* $$=0; */
1180                         } else {
1181                                 $$->u.addr[0]=$1;
1182                                 $$->u.addr[1]=$3;
1183                                 $$->u.addr[2]=$5;
1184                                 $$->u.addr[3]=$7;
1185                                 /*
1186                                 $$=htonl( ($1<<24)|
1187                                 ($3<<16)| ($5<<8)|$7 );
1188                                 */
1189                         }
1190                 }
1191         }
1192         ;
1193 ipv6addr:
1194         IPV6ADDR {
1195                 $$=pkg_malloc(sizeof(struct ip_addr));
1196                 if ($$==0) {
1197                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1198                 } else {
1199                         memset($$, 0, sizeof(struct ip_addr));
1200                         $$->af=AF_INET6;
1201                         $$->len=16;
1202                 #ifdef USE_IPV6
1203                         if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
1204                                 yyerror("bad ipv6 address");
1205                         }
1206                 #else
1207                         yyerror("ipv6 address & no ipv6 support compiled in");
1208                         YYABORT;
1209                 #endif
1210                 }
1211         }
1212         ;
1213 ipv6:
1214         ipv6addr { $$=$1; }
1215         | LBRACK ipv6addr RBRACK {$$=$2; }
1216 ;
1217
1218
1219 route_name:             NUMBER  {
1220                                         tmp=int2str($1, &i_tmp);
1221                                         if (($$=pkg_malloc(i_tmp+1))==0) {
1222                                                 yyerror("out of  memory");
1223                                                 YYABORT;
1224                                         } else {
1225                                                 memcpy($$, tmp, i_tmp);
1226                                                 $$[i_tmp]=0;
1227                                         }
1228                                                 }
1229                         |       ID              { $$=$1; }
1230                         |       STRING  { $$=$1; }
1231 ;
1232
1233 route_stm:
1234         ROUTE LBRACE actions RBRACE { push($3, &main_rt.rlist[DEFAULT_RT]); }
1235         | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
1236                 i_tmp=route_get(&main_rt, $3);
1237                 if (i_tmp==-1){
1238                         yyerror("internal error");
1239                         YYABORT;
1240                 }
1241                 if (main_rt.rlist[i_tmp]){
1242                         yyerror("duplicate route");
1243                         YYABORT;
1244                 }
1245                 push($6, &main_rt.rlist[i_tmp]);
1246         }
1247         | ROUTE error { yyerror("invalid  route  statement"); }
1248         ;
1249 failure_route_stm:
1250         ROUTE_FAILURE LBRACE actions RBRACE {
1251                                                                         push($3, &failure_rt.rlist[DEFAULT_RT]);
1252                                                                                 }
1253         | ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1254                 i_tmp=route_get(&failure_rt, $3);
1255                 if (i_tmp==-1){
1256                         yyerror("internal error");
1257                         YYABORT;
1258                 }
1259                 if (failure_rt.rlist[i_tmp]){
1260                         yyerror("duplicate route");
1261                         YYABORT;
1262                 }
1263                 push($6, &failure_rt.rlist[i_tmp]);
1264         }
1265         | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1266         ;
1267 onreply_route_stm:
1268         ROUTE_ONREPLY LBRACE actions RBRACE {
1269                                                                         push($3, &onreply_rt.rlist[DEFAULT_RT]);
1270                                                                                 }
1271         | ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
1272                 i_tmp=route_get(&onreply_rt, $3);
1273                 if (i_tmp==-1){
1274                         yyerror("internal error");
1275                         YYABORT;
1276                 }
1277                 if (onreply_rt.rlist[i_tmp]){
1278                         yyerror("duplicate route");
1279                         YYABORT;
1280                 }
1281                 push($6, &onreply_rt.rlist[i_tmp]);
1282         }
1283         | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
1284         ;
1285 branch_route_stm:
1286         ROUTE_BRANCH LBRACE actions RBRACE {
1287                                                                         push($3, &branch_rt.rlist[DEFAULT_RT]);
1288                                                                                 }
1289         | ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1290                 i_tmp=route_get(&branch_rt, $3);
1291                 if (i_tmp==-1){
1292                         yyerror("internal error");
1293                         YYABORT;
1294                 }
1295                 if (branch_rt.rlist[i_tmp]){
1296                         yyerror("duplicate route");
1297                         YYABORT;
1298                 }
1299                 push($6, &branch_rt.rlist[i_tmp]);
1300         }
1301         | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1302         ;
1303 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1304                                                                         push($3, &onsend_rt.rlist[DEFAULT_RT]);
1305                                                                                                 }
1306         | ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1307                 i_tmp=route_get(&onsend_rt, $3);
1308                 if (i_tmp==-1){
1309                         yyerror("internal error");
1310                         YYABORT;
1311                 }
1312                 if (onsend_rt.rlist[i_tmp]){
1313                         yyerror("duplicate route");
1314                         YYABORT;
1315                 }
1316                 push($6, &onsend_rt.rlist[i_tmp]);
1317         }
1318         | ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1319         ;
1320 /*
1321 rules:
1322         rules rule { push($2, &$1); $$=$1; }
1323         | rule {$$=$1; }
1324         | rules error { $$=0; yyerror("invalid rule"); }
1325         ;
1326 rule:
1327         condition actions CR {
1328                 $$=0;
1329                 if (add_rule($1, $2, &$$)<0) {
1330                         yyerror("error calling add_rule");
1331                         YYABORT;
1332                 }
1333         }
1334         | CR    { $$=0;}
1335         | condition error { $$=0; yyerror("bad actions in rule"); }
1336         ;
1337 condition:
1338         exp {$$=$1;}
1339 */
1340 exp:    exp LOG_AND exp         { $$=mk_exp(LOGAND_OP, $1, $3); }
1341         | exp LOG_OR exp        { $$=mk_exp(LOGOR_OP, $1, $3);  }
1342         | NOT exp               { $$=mk_exp(NOT_OP, $2, 0);  }
1343         | LPAREN exp RPAREN     { $$=$2; }
1344         | exp_elem              { $$=$1; }
1345         ;
1346 equalop:
1347         EQUAL_T {$$=EQUAL_OP; }
1348         | DIFF  {$$=DIFF_OP; }
1349         ;
1350 intop:  equalop {$$=$1; }
1351         | GT    {$$=GT_OP; }
1352         | LT    {$$=LT_OP; }
1353         | GTE   {$$=GTE_OP; }
1354         | LTE   {$$=LTE_OP; }
1355         ;
1356 binop :
1357         BIN_OR { $$= BINOR_OP; }
1358         | BIN_AND { $$ = BINAND_OP; }
1359         ;
1360 strop:
1361         equalop {$$=$1; }
1362         | MATCH {$$=MATCH_OP; }
1363         ;
1364 uri_type:
1365         URI             {$$=URI_O;}
1366         | FROM_URI      {$$=FROM_URI_O;}
1367         | TO_URI        {$$=TO_URI_O;}
1368         ;
1369
1370 exp_elem:
1371         METHOD strop STRING     {$$= mk_elem($2, METHOD_O, 0, STRING_ST, $3);}
1372         | METHOD strop attr_id_val  {$$ = mk_elem($2, METHOD_O, 0, AVP_ST, $3); }
1373         | METHOD strop select_id {$$ = mk_elem($2, METHOD_O, 0, SELECT_ST, $3); }
1374         | METHOD strop  ID      {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
1375         | METHOD strop error { $$=0; yyerror("string expected"); }
1376         | METHOD error  { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
1377         | uri_type strop STRING {$$ = mk_elem($2, $1, 0, STRING_ST, $3); }
1378         | uri_type strop host   {$$ = mk_elem($2, $1, 0, STRING_ST, $3); }
1379         | uri_type strop attr_id_val {$$ = mk_elem($2, $1, 0, AVP_ST, $3); }
1380         | uri_type strop select_id {$$ = mk_elem($2, $1, 0, SELECT_ST, $3); }
1381         | uri_type equalop MYSELF {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1382         | uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
1383         | uri_type error        { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
1384
1385         | SRCPORT intop NUMBER { $$=mk_elem($2, SRCPORT_O, 0, NUMBER_ST, (void*)$3 ); }
1386         | SRCPORT intop attr_id_val { $$=mk_elem($2, SRCPORT_O, 0, AVP_ST, (void*)$3 ); }
1387         | SRCPORT intop error { $$=0; yyerror("number expected"); }
1388         | SRCPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1389
1390         | DSTPORT intop NUMBER  { $$=mk_elem($2, DSTPORT_O, 0, NUMBER_ST, (void*)$3 ); }
1391         | DSTPORT intop attr_id_val     { $$=mk_elem($2, DSTPORT_O, 0, AVP_ST, (void*)$3 ); }
1392         | DSTPORT intop error { $$=0; yyerror("number expected"); }
1393         | DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1394
1395         | SNDPORT intop NUMBER {
1396                 onsend_check("snd_port");
1397                 $$=mk_elem($2, SNDPORT_O, 0, NUMBER_ST, (void*)$3 );
1398         }
1399         | SNDPORT intop attr_id_val {
1400                 onsend_check("snd_port");
1401                 $$=mk_elem($2, SNDPORT_O, 0, AVP_ST, (void*)$3 );
1402         }
1403         | SNDPORT intop error { $$=0; yyerror("number expected"); }
1404         | SNDPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1405
1406         | TOPORT intop NUMBER {
1407                 onsend_check("to_port");
1408                 $$=mk_elem($2, TOPORT_O, 0, NUMBER_ST, (void*)$3 );
1409         }
1410         | TOPORT intop attr_id_val {
1411                 onsend_check("to_port");
1412                 $$=mk_elem($2, TOPORT_O, 0, AVP_ST, (void*)$3 );
1413         }
1414         | TOPORT intop error { $$=0; yyerror("number expected"); }
1415         | TOPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1416
1417         | PROTO intop proto     { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
1418         | PROTO intop attr_id_val       { $$=mk_elem($2, PROTO_O, 0, AVP_ST, (void*)$3 ); }
1419         | PROTO intop error { $$=0; yyerror("protocol expected (udp, tcp or tls)"); }
1420
1421         | PROTO error { $$=0; yyerror("equal/!= operator expected"); }
1422
1423         | SNDPROTO intop proto  {
1424                 onsend_check("snd_proto");
1425                 $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 );
1426         }
1427         | SNDPROTO intop attr_id_val {
1428                 onsend_check("snd_proto");
1429                 $$=mk_elem($2, SNDPROTO_O, 0, AVP_ST, (void*)$3 );
1430         }
1431         | SNDPROTO intop error { $$=0; yyerror("protocol expected (udp, tcp or tls)"); }
1432         | SNDPROTO error { $$=0; yyerror("equal/!= operator expected"); }
1433
1434         | AF intop NUMBER       { $$=mk_elem($2, AF_O, 0, NUMBER_ST,(void *) $3 ); }
1435         | AF intop attr_id_val  { $$=mk_elem($2, AF_O, 0, AVP_ST,(void *) $3 ); }
1436         | AF intop error { $$=0; yyerror("number expected"); }
1437         | AF error { $$=0; yyerror("equal/!= operator expected"); }
1438
1439         | SNDAF intop NUMBER {
1440                 onsend_check("snd_af");
1441                 $$=mk_elem($2, SNDAF_O, 0, NUMBER_ST, (void *) $3 ); }
1442         | SNDAF intop attr_id_val {
1443                 onsend_check("snd_af");
1444                 $$=mk_elem($2, SNDAF_O, 0, AVP_ST, (void *) $3 );
1445         }
1446         | SNDAF intop error { $$=0; yyerror("number expected"); }
1447         | SNDAF error { $$=0; yyerror("equal/!= operator expected"); }
1448
1449         | MSGLEN intop NUMBER           { $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST, (void *) $3 ); }
1450         | MSGLEN intop attr_id_val      { $$=mk_elem($2, MSGLEN_O, 0, AVP_ST, (void *) $3 ); }
1451         | MSGLEN intop MAX_LEN          { $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST, (void *) BUF_SIZE); }
1452         | MSGLEN intop error { $$=0; yyerror("number expected"); }
1453         | MSGLEN error { $$=0; yyerror("equal/!= operator expected"); }
1454
1455         | RETCODE intop NUMBER  { $$=mk_elem($2, RETCODE_O, 0, NUMBER_ST, (void *) $3 ); }
1456         | RETCODE intop attr_id_val     { $$=mk_elem($2, RETCODE_O, 0, AVP_ST, (void *) $3 ); }
1457         | RETCODE intop error { $$=0; yyerror("number expected"); }
1458         | RETCODE error { $$=0; yyerror("equal/!= operator expected"); }
1459
1460         | SRCIP equalop ipnet   { $$=mk_elem($2, SRCIP_O, 0, NET_ST, $3); }
1461         | SRCIP strop STRING {
1462                 s_tmp.s=$3;
1463                 s_tmp.len=strlen($3);
1464                 ip_tmp=str2ip(&s_tmp);
1465                 if (ip_tmp==0)
1466                         ip_tmp=str2ip6(&s_tmp);
1467                 if (ip_tmp) {
1468                         $$=mk_elem($2, SRCIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1469                 } else {
1470                         $$=mk_elem($2, SRCIP_O, 0, STRING_ST, $3);
1471                 }
1472         }
1473         | SRCIP strop host      { $$=mk_elem($2, SRCIP_O, 0, STRING_ST, $3); }
1474         | SRCIP equalop MYSELF  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
1475                                                         }
1476         | SRCIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1477         | SRCIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
1478         | DSTIP equalop ipnet   { $$=mk_elem(   $2, DSTIP_O, 0, NET_ST, (void*)$3); }
1479         | DSTIP strop STRING    {
1480                 s_tmp.s=$3;
1481                 s_tmp.len=strlen($3);
1482                 ip_tmp=str2ip(&s_tmp);
1483                 if (ip_tmp==0)
1484                         ip_tmp=str2ip6(&s_tmp);
1485                 if (ip_tmp) {
1486                         $$=mk_elem($2, DSTIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1487                 } else {
1488                         $$=mk_elem($2, DSTIP_O, 0, STRING_ST, $3);
1489                 }
1490         }
1491         | DSTIP strop host      { $$=mk_elem(   $2, DSTIP_O, 0, STRING_ST, $3); }
1492         | DSTIP equalop MYSELF  { $$=mk_elem(   $2, DSTIP_O, 0, MYSELF_ST, 0); }
1493         | DSTIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1494         | DSTIP error { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1495         | SNDIP equalop ipnet {
1496                 onsend_check("snd_ip");
1497                 $$=mk_elem($2, SNDIP_O, 0, NET_ST, $3);
1498         }
1499         | SNDIP strop STRING    {
1500                 onsend_check("snd_ip");
1501                 s_tmp.s=$3;
1502                 s_tmp.len=strlen($3);
1503                 ip_tmp=str2ip(&s_tmp);
1504                 if (ip_tmp==0)
1505                         ip_tmp=str2ip6(&s_tmp);
1506                 if (ip_tmp) {
1507                         $$=mk_elem($2, SNDIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1508                 } else {
1509                         $$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3);
1510                 }
1511         }
1512         | SNDIP strop host      {
1513                 onsend_check("snd_ip");
1514                 $$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3);
1515         }
1516         | SNDIP equalop attr_id_val     {
1517                 onsend_check("snd_ip");
1518             $$=mk_elem($2, SNDIP_O, 0, AVP_ST, (void*)$3 ); 
1519         }
1520         | SNDIP equalop MYSELF  {
1521                 onsend_check("snd_ip");
1522                 $$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0);
1523         }
1524         | SNDIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1525         | SNDIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1526         | TOIP equalop ipnet    {
1527                 onsend_check("to_ip");
1528                 $$=mk_elem($2, TOIP_O, 0, NET_ST, $3);
1529         }
1530         | TOIP strop STRING     {
1531                 onsend_check("to_ip");
1532                 s_tmp.s=$3;
1533                 s_tmp.len=strlen($3);
1534                 ip_tmp=str2ip(&s_tmp);
1535                 if (ip_tmp==0)
1536                         ip_tmp=str2ip6(&s_tmp);
1537                 if (ip_tmp) {
1538                         $$=mk_elem($2, TOIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1539                 } else {
1540                         $$=mk_elem($2, TOIP_O, 0, STRING_ST, $3);
1541                 }
1542         }
1543         | TOIP strop host       {
1544                 onsend_check("to_ip");
1545                 $$=mk_elem($2, TOIP_O, 0, STRING_ST, $3);
1546         }
1547         | TOIP equalop attr_id_val      {
1548                 onsend_check("to_ip");
1549             $$=mk_elem($2, TOIP_O, 0, AVP_ST, (void*)$3 ); 
1550         }
1551         | TOIP equalop MYSELF  {
1552                 onsend_check("to_ip");
1553                 $$=mk_elem($2, TOIP_O, 0, MYSELF_ST, 0);
1554         }
1555         | TOIP strop error { $$=0; yyerror( "ip address or hostname expected" ); }
1556         | TOIP error  { $$=0; yyerror("invalid operator, ==, != or =~ expected"); }
1557
1558         | MYSELF equalop uri_type       { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1559         | MYSELF equalop SRCIP  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0); }
1560         | MYSELF equalop DSTIP  { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0); }
1561         | MYSELF equalop SNDIP  {
1562                 onsend_check("snd_ip");
1563                 $$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0);
1564         }
1565         | MYSELF equalop TOIP  {
1566                 onsend_check("to_ip");
1567                 $$=mk_elem($2, TOIP_O, 0, MYSELF_ST, 0);
1568         }
1569         | MYSELF equalop error { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
1570         | MYSELF error  { $$=0; yyerror ("invalid operator, == or != expected"); }
1571         | exp_stm       { $$=mk_elem( NO_OP, ACTION_O, 0, ACTIONS_ST, $1);  }
1572         | NUMBER        { $$=mk_elem( NO_OP, NUMBER_O, 0, NUMBER_ST, (void*)$1 ); }
1573
1574         | attr_id_any                           {$$=mk_elem( NO_OP, AVP_O, (void*)$1, 0, 0); }
1575         | attr_id_val strop STRING      {$$=mk_elem( $2, AVP_O, (void*)$1, STRING_ST, $3); }
1576         | attr_id_val strop select_id   {$$=mk_elem( $2, AVP_O, (void*)$1, SELECT_ST, $3); }
1577         | attr_id_val intop NUMBER      {$$=mk_elem( $2, AVP_O, (void*)$1, NUMBER_ST, (void*)$3); }
1578         | attr_id_val binop NUMBER      {$$=mk_elem( $2, AVP_O, (void*)$1, NUMBER_ST, (void*)$3); }
1579         | attr_id_val strop attr_id_val {$$=mk_elem( $2, AVP_O, (void*)$1, AVP_ST, (void*)$3); }
1580
1581         | select_id                 { $$=mk_elem( NO_OP, SELECT_O, $1, 0, 0); }
1582         | select_id strop STRING    { $$=mk_elem( $2, SELECT_O, $1, STRING_ST, $3); }
1583         | select_id strop attr_id_val   { $$=mk_elem( $2, SELECT_O, $1, AVP_ST, (void*)$3); }
1584         | select_id strop select_id { $$=mk_elem( $2, SELECT_O, $1, SELECT_ST, $3); }
1585 ;
1586 ipnet:
1587         ip SLASH ip     { $$=mk_net($1, $3); }
1588         | ip SLASH NUMBER {
1589                 if (($3<0) || ($3>$1->len*8)) {
1590                         yyerror("invalid bit number in netmask");
1591                         $$=0;
1592                 } else {
1593                         $$=mk_net_bitlen($1, $3);
1594                 /*
1595                         $$=mk_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
1596                 */
1597                 }
1598         }
1599         | ip    { $$=mk_net_bitlen($1, $1->len*8); }
1600         | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
1601         ;
1602 host_sep:
1603         DOT {$$=".";}
1604         | MINUS {$$="-"; }
1605         ;
1606
1607 host:
1608         ID { $$=$1; }
1609         | host host_sep ID {
1610                 $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1611                 if ($$==0) {
1612                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1613                 } else {
1614                         memcpy($$, $1, strlen($1));
1615                         $$[strlen($1)]=*$2;
1616                         memcpy($$+strlen($1)+1, $3, strlen($3));
1617                         $$[strlen($1)+1+strlen($3)]=0;
1618                 }
1619                 pkg_free($1);
1620                 pkg_free($3);
1621         }
1622         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
1623         ;
1624 /* filtered cmd */
1625 fcmd:
1626         cmd {
1627                 /* check if allowed */
1628                 if ($1 && rt==ONSEND_ROUTE) {
1629                         switch($1->type) {
1630                                 case DROP_T:
1631                                 case SEND_T:
1632                                 case SEND_TCP_T:
1633                                 case LOG_T:
1634                                 case SETFLAG_T:
1635                                 case RESETFLAG_T:
1636                                 case ISFLAGSET_T:
1637                                 case IF_T:
1638                                 case MODULE_T:
1639                                         $$=$1;
1640                                         break;
1641                                 default:
1642                                         $$=0;
1643                                         yyerror("command not allowed in onsend_route\n");
1644                         }
1645                 } else {
1646                         $$=$1;
1647                 }
1648         }
1649         ;
1650 exp_stm:
1651         fcmd    { $$=$1; }
1652         | if_cmd        { $$=$1; }
1653         | assign_action { $$ = $1; }
1654         | LBRACE actions RBRACE { $$=$2; }
1655         ;
1656 stm:
1657         action  { $$=$1; }
1658         | LBRACE actions RBRACE { $$=$2; }
1659         ;
1660 actions:
1661         actions action  {$$=append_action($1, $2); }
1662         | action        {$$=$1;}
1663         | actions error { $$=0; yyerror("bad command"); }
1664         ;
1665 action:
1666         fcmd SEMICOLON {$$=$1;}
1667         | if_cmd {$$=$1;}
1668         | assign_action SEMICOLON {$$=$1;}
1669         | SEMICOLON /* null action */ {$$=0;}
1670         | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
1671         ;
1672 if_cmd:
1673         IF exp stm              { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0); }
1674         | IF exp stm ELSE stm   { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5); }
1675         ;
1676 /* class_id:
1677         LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
1678         | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
1679         | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
1680         ;
1681 */
1682 select_param:
1683         ID {
1684                 if (sel.n >= MAX_SELECT_PARAMS-1) {
1685                         yyerror("Select identifier too long\n");
1686                 }
1687                 sel.params[sel.n].type = SEL_PARAM_STR;
1688                 sel.params[sel.n].v.s.s = $1;
1689                 sel.params[sel.n].v.s.len = strlen($1);
1690                 sel.n++;
1691         }
1692         | ID LBRACK NUMBER RBRACK {
1693                 if (sel.n >= MAX_SELECT_PARAMS-2) {
1694                         yyerror("Select identifier too long\n");
1695                 }
1696                 sel.params[sel.n].type = SEL_PARAM_STR;
1697                 sel.params[sel.n].v.s.s = $1;
1698                 sel.params[sel.n].v.s.len = strlen($1);
1699                 sel.n++;
1700                 sel.params[sel.n].type = SEL_PARAM_INT;
1701                 sel.params[sel.n].v.i = $3;
1702                 sel.n++;
1703         }
1704         | ID LBRACK STRING RBRACK {
1705                 if (sel.n >= MAX_SELECT_PARAMS-2) {
1706                         yyerror("Select identifier too long\n");
1707                 }
1708                 sel.params[sel.n].type = SEL_PARAM_STR;
1709                 sel.params[sel.n].v.s.s = $1;
1710                 sel.params[sel.n].v.s.len = strlen($1);
1711                 sel.n++;
1712                 sel.params[sel.n].type = SEL_PARAM_STR;
1713                 sel.params[sel.n].v.s.s = $3;
1714                 sel.params[sel.n].v.s.len = strlen($3);
1715                 sel.n++;
1716         }
1717         ;
1718 select_params:
1719         select_params DOT select_param
1720         | select_param
1721         ;
1722 select_id:
1723         SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
1724                 sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
1725                 if (!sel_ptr) {
1726                         yyerror("No memory left to allocate select structure\n");
1727                 }
1728                 memcpy(sel_ptr, &sel, sizeof(select_t));
1729                 $$ = sel_ptr;
1730         }
1731         ;
1732 attr_class_spec:
1733         ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
1734         | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
1735         | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
1736         | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
1737         | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
1738         | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
1739         | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
1740         | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
1741         | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
1742         ;
1743 attr_name_spec:
1744         ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
1745         ;
1746 attr_spec:
1747         attr_name_spec
1748         | attr_class_spec DOT attr_name_spec
1749         ;
1750 attr_mark:
1751         ATTR_MARK {
1752                 s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
1753                 if (!s_attr) { yyerror("No memory left"); }
1754                 s_attr->type = 0;
1755         }
1756         ;
1757 attr_id:
1758         attr_mark attr_spec { $$ = s_attr; }
1759         ;
1760 attr_id_num_idx:
1761         attr_mark attr_spec LBRACK NUMBER RBRACK {
1762                 s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
1763                 s_attr->index = ($4<0?-$4:$4);
1764                 $$ = s_attr;
1765         }
1766         ;
1767 attr_id_no_idx:
1768         attr_mark attr_spec LBRACK RBRACK {
1769                 s_attr->type|= AVP_INDEX_ALL;
1770                 $$ = s_attr;
1771         }
1772         ;
1773 attr_id_ass:
1774         attr_id
1775         | attr_id_no_idx
1776         ;
1777 attr_id_val:
1778         attr_id
1779         | attr_id_num_idx
1780         ;
1781 attr_id_any:
1782         attr_id
1783         | attr_id_no_idx
1784         | attr_id_num_idx
1785 ;
1786 attr_id_any_str:
1787         attr_id
1788         | STRING {
1789                 avp_spec_t *avp_spec;
1790                 str s;
1791                 int type, idx;
1792                 avp_spec = pkg_malloc(sizeof(*avp_spec));
1793                 if (!avp_spec) {
1794                         yyerror("Not enough memory");
1795                         YYABORT;
1796                 }
1797                 s.s = $1;
1798                 if (s.s[0] == '$')
1799                         s.s++;
1800                 s.len = strlen(s.s);
1801                 if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
1802                         yyerror("error when parsing AVP");
1803                         pkg_free(avp_spec);
1804                         YYABORT;
1805                 }
1806                 avp_spec->type = type;
1807                 avp_spec->index = idx;
1808                 $$ = avp_spec;
1809         }
1810         ;
1811 /*
1812 assign_op:
1813         ADDEQ { $$ = ADD_T; }
1814         | EQUAL { $$ = ASSIGN_T; }
1815         ;
1816 */
1817 assign_op:
1818         EQUAL { $$ = ASSIGN_T; }
1819         ;
1820 assign_action:
1821         attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
1822         | attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
1823         | attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
1824         | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
1825         | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
1826         | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
1827         ;
1828 avpflag_oper:
1829         SETAVPFLAG { $$ = 1; }
1830         | RESETAVPFLAG { $$ = 0; }
1831         | ISAVPFLAGSET { $$ = -1; }
1832         ;
1833 cmd:
1834         FORWARD LPAREN host RPAREN      { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1835         | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1836         | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
1837         | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1838         | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1839         | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
1840         | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
1841         | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
1842         | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
1843         | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
1844         | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
1845         | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1846         | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1847         | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
1848         | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1849         | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1850         | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
1851         | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
1852         | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
1853         | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
1854         | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
1855         | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
1856         | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1857         | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1858         | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
1859         | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1860         | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1861         | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
1862         | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
1863         | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
1864         | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
1865         | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
1866         | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
1867         | FORWARD_TLS LPAREN host RPAREN {
1868                 #ifdef USE_TLS
1869                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
1870                 #else
1871                         $$=0;
1872                         yyerror("tls support not compiled in");
1873                 #endif
1874         }
1875         | FORWARD_TLS LPAREN STRING RPAREN {
1876                 #ifdef USE_TLS
1877                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
1878                 #else
1879                         $$=0;
1880                         yyerror("tls support not compiled in");
1881                 #endif
1882         }
1883         | FORWARD_TLS LPAREN ip RPAREN  {
1884                 #ifdef USE_TLS
1885                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0);
1886                 #else
1887                         $$=0;
1888                         yyerror("tls support not compiled in");
1889                 #endif
1890         }
1891         | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
1892                 #ifdef USE_TLS
1893                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
1894                 #else
1895                         $$=0;
1896                         yyerror("tls support not compiled in");
1897                 #endif
1898         }
1899         | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
1900                 #ifdef USE_TLS
1901                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
1902                 #else
1903                         $$=0;
1904                         yyerror("tls support not compiled in");
1905                 #endif
1906         }
1907         | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
1908                 #ifdef USE_TLS
1909                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5);
1910                 #else
1911                         $$=0;
1912                         yyerror("tls support not compiled in");
1913                 #endif
1914                                         }
1915         | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
1916                 #ifdef USE_TLS
1917                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0);
1918                 #else
1919                         $$=0;
1920                         yyerror("tls support not compiled in");
1921                 #endif
1922         }
1923         | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
1924                 #ifdef USE_TLS
1925                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5);
1926                 #else
1927                         $$=0;
1928                         yyerror("tls support not compiled in");
1929                 #endif
1930         }
1931         | FORWARD_TLS LPAREN URIHOST RPAREN {
1932                 #ifdef USE_TLS
1933                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0);
1934                 #else
1935                         $$=0;
1936                         yyerror("tls support not compiled in");
1937                 #endif
1938         }
1939         | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
1940         | FORWARD_TLS LPAREN error RPAREN { $$=0; yyerror("bad forward_tls argument"); }
1941         | SEND LPAREN host RPAREN       { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1942         | SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1943         | SEND LPAREN ip RPAREN         { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
1944         | SEND LPAREN host COMMA NUMBER RPAREN  { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1945         | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1946         | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
1947         | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
1948         | SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
1949         | SEND_TCP LPAREN host RPAREN   { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1950         | SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
1951         | SEND_TCP LPAREN ip RPAREN     { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
1952         | SEND_TCP LPAREN host COMMA NUMBER RPAREN      { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);}
1953         | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
1954         | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
1955         | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
1956         | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
1957         | DROP LPAREN RPAREN            {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
1958         | DROP LPAREN NUMBER RPAREN     {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$3, NUMBER_ST, (void*)EXIT_R_F); }
1959         | DROP NUMBER                   {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)EXIT_R_F); }
1960         | DROP RETCODE                  {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
1961         | DROP                          {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
1962         | RETURN                        {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST, (void*)RETURN_R_F); }
1963         | RETURN NUMBER                 {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)RETURN_R_F);}
1964         | RETURN RETCODE                {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)RETURN_R_F);}
1965         | BREAK                         {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)RETURN_R_F); }
1966         | LOG_TOK LPAREN STRING RPAREN  {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)4, STRING_ST, $3); }
1967         | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN     {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); }
1968         | LOG_TOK error                 { $$=0; yyerror("missing '(' or ')' ?"); }
1969         | LOG_TOK LPAREN error RPAREN   { $$=0; yyerror("bad log argument"); }
1970         | SETFLAG LPAREN NUMBER RPAREN  {
1971                                                         if (check_flag($3)==-1)
1972                                                                 yyerror("bad flag value");
1973                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
1974                                                                                                         (void*)$3);
1975                                                                         }
1976         | SETFLAG LPAREN flag_name RPAREN       {
1977                                                         i_tmp=get_flag_no($3, strlen($3));
1978                                                         if (i_tmp<0) yyerror("flag not declared");
1979                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
1980                                                                                 (void*)(long)i_tmp);
1981                                                                         }
1982         | SETFLAG error                 { $$=0; yyerror("missing '(' or ')'?"); }
1983         | RESETFLAG LPAREN NUMBER RPAREN {
1984                                                         if (check_flag($3)==-1)
1985                                                                 yyerror("bad flag value");
1986                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
1987                                                                         }
1988         | RESETFLAG LPAREN flag_name RPAREN     {
1989                                                         i_tmp=get_flag_no($3, strlen($3));
1990                                                         if (i_tmp<0) yyerror("flag not declared");
1991                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
1992                                                                                 (void*)(long)i_tmp);
1993                                                                         }
1994         | RESETFLAG error               { $$=0; yyerror("missing '(' or ')'?"); }
1995         | ISFLAGSET LPAREN NUMBER RPAREN {
1996                                                         if (check_flag($3)==-1)
1997                                                                 yyerror("bad flag value");
1998                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
1999                                                                         }
2000         | ISFLAGSET LPAREN flag_name RPAREN     {
2001                                                         i_tmp=get_flag_no($3, strlen($3));
2002                                                         if (i_tmp<0) yyerror("flag not declared");
2003                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
2004                                                                                 (void*)(long)i_tmp);
2005                                                                         }
2006         | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
2007         | avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
2008                 i_tmp=get_avpflag_no($5);
2009                 if (i_tmp==0) yyerror("avpflag not declared");
2010                 $$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
2011         }
2012         | avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
2013         | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5); }
2014         | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
2015         | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
2016         | ROUTE LPAREN route_name RPAREN        {
2017                                                 i_tmp=route_get(&main_rt, $3);
2018                                                 if (i_tmp==-1){
2019                                                         yyerror("internal error");
2020                                                         YYABORT;
2021                                                 }
2022                                                 $$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp);
2023                                                                                 }
2024         | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
2025         | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
2026         | EXEC LPAREN STRING RPAREN     { $$=mk_action(EXEC_T, 1, STRING_ST, $3); }
2027         | SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, 1, STRING_ST, $3); }
2028         | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
2029         | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2030         | PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, 1, STRING_ST,  $3); }
2031         | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
2032         | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2033         | STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 1, NUMBER_ST, (void*)$3); }
2034         | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
2035         | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2036         | STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, 1, NUMBER_ST, (void*) $3); }
2037         | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
2038         | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2039         | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN {
2040                 qvalue_t q;
2041                 if (str2q(&q, $5, strlen($5)) < 0) {
2042                         yyerror("bad argument, q value expected");
2043                 }
2044                 $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)(long)q);
2045         }
2046         | APPEND_BRANCH LPAREN STRING RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2047         | APPEND_BRANCH LPAREN RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, 0, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2048         | APPEND_BRANCH {  $$=mk_action( APPEND_BRANCH_T, 1, STRING_ST, 0); }
2049         | SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); }
2050         | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2051         | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2052         | SET_PORT LPAREN STRING RPAREN { $$=mk_action(SET_PORT_T, 1, STRING_ST, $3); }
2053         | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2054         | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2055         | SET_USER LPAREN STRING RPAREN { $$=mk_action(SET_USER_T, 1, STRING_ST, $3); }
2056         | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
2057         | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2058         | SET_USERPASS LPAREN STRING RPAREN { $$=mk_action(SET_USERPASS_T, 1, STRING_ST, $3); }
2059         | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
2060         | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2061         | SET_URI LPAREN STRING RPAREN { $$=mk_action(SET_URI_T, 1, STRING_ST,$3); }
2062         | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
2063         | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2064         | REVERT_URI LPAREN RPAREN { $$=mk_action(REVERT_URI_T, 0); }
2065         | REVERT_URI { $$=mk_action(REVERT_URI_T, 0); }
2066         | FORCE_RPORT LPAREN RPAREN     { $$=mk_action(FORCE_RPORT_T, 0); }
2067         | FORCE_RPORT   {$$=mk_action(FORCE_RPORT_T, 0); }
2068         | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN  {
2069                 #ifdef USE_TCP
2070                         $$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
2071                 #else
2072                         yyerror("tcp support not compiled in");
2073                 #endif
2074         }
2075         | FORCE_TCP_ALIAS LPAREN RPAREN {
2076                 #ifdef USE_TCP
2077                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2078                 #else
2079                         yyerror("tcp support not compiled in");
2080                 #endif
2081         }
2082         | FORCE_TCP_ALIAS                               {
2083                 #ifdef USE_TCP
2084                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2085                 #else
2086                         yyerror("tcp support not compiled in");
2087                 #endif
2088         }
2089         | FORCE_TCP_ALIAS LPAREN error RPAREN   {$$=0; yyerror("bad argument, number expected"); }
2090         | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
2091                 $$=0;
2092                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2093                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2094                 } else {
2095                         str_tmp->s=$3;
2096                         str_tmp->len=strlen($3);
2097                         $$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
2098                 }
2099         }
2100         | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2101         | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
2102         | SET_ADV_PORT LPAREN NUMBER RPAREN {
2103                 $$=0;
2104                 tmp=int2str($3, &i_tmp);
2105                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2106                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2107                 } else {
2108                         if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
2109                                 LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2110                         } else {
2111                                 memcpy(str_tmp->s, tmp, i_tmp);
2112                                 str_tmp->len=i_tmp;
2113                                 $$=mk_action(SET_ADV_PORT_T, 1, STR_ST, str_tmp);
2114                         }
2115                 }
2116         }
2117         | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2118         | SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
2119         | FORCE_SEND_SOCKET LPAREN phostport RPAREN { $$=mk_action(FORCE_SEND_SOCKET_T, 1, SOCKID_ST, $3); }
2120         | FORCE_SEND_SOCKET LPAREN error RPAREN { $$=0; yyerror("bad argument, [proto:]host[:port] expected"); }
2121         | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
2122         | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST, 0); } LPAREN func_params RPAREN      {
2123                 mod_func_action->val[0].u.data = find_export_record($1, mod_func_action->val[1].u.number, rt);
2124                 if (mod_func_action->val[0].u.data == 0) {
2125                         if (find_export_record($1, mod_func_action->val[1].u.number, 0) ) {
2126                                         yyerror("Command cannot be used in the block\n");
2127                         } else {
2128                                 yyerror("unknown command, missing loadmodule?\n");
2129                         }
2130                         pkg_free(mod_func_action);
2131                         mod_func_action=0;
2132                 }
2133                 $$ = mod_func_action;
2134         }
2135         ;
2136 func_params:
2137         /* empty */
2138         | func_params COMMA func_param { }
2139         | func_param {}
2140         | func_params error { yyerror("call params error\n"); YYABORT; }
2141         ;
2142 func_param:
2143         NUMBER {
2144                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2145                         mod_func_action->val[mod_func_action->val[1].u.number+2].type = NUMBER_ST;
2146                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.number = $1;
2147                         mod_func_action->val[1].u.number++;
2148                 } else {
2149                         yyerror("Too many arguments\n");
2150                 }
2151         }
2152         | STRING {
2153                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2154                         mod_func_action->val[mod_func_action->val[1].u.number+2].type = STRING_ST;
2155                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.string = $1;
2156                         mod_func_action->val[1].u.number++;
2157                 } else {
2158                         yyerror("Too many arguments\n");
2159                 }
2160         }
2161         ;
2162 %%
2163
2164 extern int line;
2165 extern int column;
2166 extern int startcolumn;
2167 static void warn(char* s)
2168 {
2169         LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n", line, startcolumn,
2170                         column, s);
2171         cfg_warnings++;
2172 }
2173
2174 static void yyerror(char* s)
2175 {
2176         LOG(L_CRIT, "parse error (%d,%d-%d): %s\n", line, startcolumn,
2177                         column, s);
2178         cfg_errors++;
2179 }
2180
2181
2182 static struct socket_id* mk_listen_id(char* host, int proto, int port)
2183 {
2184         struct socket_id* l;
2185         l=pkg_malloc(sizeof(struct socket_id));
2186         if (l==0) {
2187                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2188         } else {
2189                 l->name=host;
2190                 l->port=port;
2191                 l->proto=proto;
2192                 l->next=0;
2193         }
2194         return l;
2195 }
2196
2197
2198 /*
2199 int main(int argc, char ** argv)
2200 {
2201         if (yyparse()!=0)
2202                 fprintf(stderr, "parsing error\n");
2203 }
2204 */