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