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