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