Merge commit 'origin/ser_core_cvs'
[sip-router] / cfg.y
1 /*
2  * $Id$
3  *
4  *  cfg grammar
5  *
6  * Copyright (C) 2001-2003 FhG Fokus
7  *
8  * This file is part of ser, a free SIP server.
9  *
10  * ser is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * For a license to use the ser software under conditions
16  * other than those described here, or to purchase support for this
17  * software, please contact iptel.org by e-mail at the following addresses:
18  *    info@iptel.org
19  *
20  * ser is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  */
29  /*
30  * History:
31  * ---------
32  * 2003-01-29  src_port added (jiri)
33  * 2003-01-23  mhomed added (jiri)
34  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
35  * 2003-03-19  Added support for route type in find_export (janakj)
36  * 2003-03-20  Regex support in modparam (janakj)
37  * 2003-04-01  added dst_port, proto , af (andrei)
38  * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
39  * 2003-04-12  added force_rport, chroot and wdir (andrei)
40  * 2003-04-15  added tcp_children, disable_tcp (andrei)
41  * 2003-04-22  strip_tail added (jiri)
42  * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify,
43  *              require_certificate added (andrei)
44  * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
45  * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
46  * 2003-10-10  added <,>,<=,>=, != operators support
47  *             added msg:len (andrei)
48  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49  * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
50  * 2003-10-24  converted to the new socket_info lists (andrei)
51  * 2003-10-28  added tcp_accept_aliases (andrei)
52  * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
53  * 2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
54  * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
55  * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
56  *             added MCAST_TTL (andrei)
57  * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
58  *              (andrei)
59  * 2004-10-19  added FROM_URI, TO_URI (andrei)
60  * 2004-11-30  added force_send_socket (andrei)
61  * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
62  *              (andrei)
63  * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
64  *             DNS_TRY_IPV6 (andrei)
65  * 2005-07-12  default onreply route added (andrei)
66  * 2005-11-16  fixed if (cond) cmd; (andrei)
67  * 2005-12-11  added onsend_route support, fcmd (filtered cmd),
68  *             snd_{ip,port,proto,af}, to_{ip,proto} (andrei)
69  * 2005-12-19  select framework (mma)
70  * 2006-01-06  AVP index support (mma)
71  * 2005-01-07  optional semicolon in statement, PARAM_STR&PARAM_STRING
72  * 2006-02-02  named flags support (andrei)
73  * 2006-02-06  named routes support (andrei)
74  * 2006-05-30  avp flags (tma)
75  * 2006-09-11  added dns cache (use, flags, ttls, mem ,gc) & dst blacklist
76  *              options (andrei)
77  * 2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
78  *              (vlada)
79  * 2007-02-09  separated command needed for tls-in-core and for tls in general
80  *              (andrei)
81  * 2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
82  *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
83  *              RT_TIMER2_POLICY (andrei)
84  * 2007-06-16  added DDNS_SRV_LB, DNS_TRY_NAPTR (andrei)
85  * 2007-09-10  introduced phone2tel option which allows NOT to consider
86  *             user=phone URIs as TEL URIs (jiri)
87  * 2007-10-10  added DNS_SEARCH_FMATCH (mma)
88  * 2007-11-28  added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT,
89  *              LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei)
90  * 2008-01-24  added cfg_var definition (Miklos)
91  * 2008-11-18  support for variable parameter module functions (andrei)
92  * 2007-12-03  support for generalised lvalues and rvalues:
93  *               lval=rval_expr, where lval=avp|pvar  (andrei)
94  * 2007-12-06  expression are now evaluated in terms of rvalues;
95  *             NUMBER is now always positive; cleanup (andrei)
96  * 2009-01-26  case/switch() support (andrei)
97  * 2009-03-10  added SET_USERPHONE action (Miklos)
98 */
99
100 %{
101
102 #include <stdlib.h>
103 #include <stdio.h>
104 #include <stdarg.h>
105 #include <sys/types.h>
106 #include <sys/socket.h>
107 #include <netinet/in.h>
108 #include <arpa/inet.h>
109 #include <string.h>
110 #include <errno.h>
111 #include "route_struct.h"
112 #include "globals.h"
113 #include "route.h"
114 #include "switch.h"
115 #include "dprint.h"
116 #include "sr_module.h"
117 #include "modparam.h"
118 #include "ip_addr.h"
119 #include "resolve.h"
120 #include "socket_info.h"
121 #include "name_alias.h"
122 #include "ut.h"
123 #include "dset.h"
124 #include "select.h"
125 #include "flags.h"
126 #include "tcp_init.h"
127 #include "tcp_options.h"
128 #include "sctp_options.h"
129 #include "pvar.h"
130 #include "lvalue.h"
131 #include "rvalue.h"
132 #include "sr_compat.h"
133 #include "msg_translator.h"
134
135 #include "config.h"
136 #include "cfg_core.h"
137 #include "cfg/cfg.h"
138 #ifdef CORE_TLS
139 #include "tls/tls_config.h"
140 #endif
141 #include "timer_ticks.h"
142
143 #ifdef DEBUG_DMALLOC
144 #include <dmalloc.h>
145 #endif
146
147 /* hack to avoid alloca usage in the generated C file (needed for compiler
148  with no built in alloca, like icc*/
149 #undef _ALLOCA_H
150
151 #define onsend_check(s) \
152         do{\
153                 if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\
154         }while(0)
155
156
157 #ifdef USE_DNS_CACHE
158         #define IF_DNS_CACHE(x) x
159 #else
160         #define IF_DNS_CACHE(x) warn("dns cache support not compiled in")
161 #endif
162
163 #ifdef USE_DNS_FAILOVER
164         #define IF_DNS_FAILOVER(x) x
165 #else
166         #define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in")
167 #endif
168
169 #ifdef USE_NAPTR
170         #define IF_NAPTR(x) x
171 #else
172         #define IF_NAPTR(x) warn("dns naptr support not compiled in")
173 #endif
174
175 #ifdef USE_DST_BLACKLIST
176         #define IF_DST_BLACKLIST(x) x
177 #else
178         #define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
179 #endif
180
181 #ifdef USE_STUN
182         #define IF_STUN(x) x
183 #else 
184         #define IF_STUN(x) warn("stun support not compiled in")
185 #endif
186
187
188 extern int yylex();
189 static void yyerror(char* s, ...);
190 static void yyerror_at(struct cfg_pos* pos, char* s, ...);
191 static char* tmp;
192 static int i_tmp;
193 static unsigned u_tmp;
194 static struct socket_id* lst_tmp;
195 static struct name_lst*  nl_tmp;
196 static int rt;  /* Type of route block for find_export */
197 static str* str_tmp;
198 static str s_tmp;
199 static struct ip_addr* ip_tmp;
200 static struct avp_spec* s_attr;
201 static select_t sel;
202 static select_t* sel_ptr;
203 static pv_spec_t* pv_spec;
204 static struct action *mod_func_action;
205 static struct lvalue* lval_tmp;
206 static struct rvalue* rval_tmp;
207
208 static void warn(char* s, ...);
209 static void warn_at(struct cfg_pos* pos, char* s, ...);
210 static void get_cpos(struct cfg_pos* pos);
211 static struct rval_expr* mk_rve_rval(enum rval_type, void* v);
212 static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1);
213 static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
214                                                                         struct rval_expr* rve2);
215 static struct socket_id* mk_listen_id(char*, int, int);
216 static struct name_lst* mk_name_lst(char* name, int flags);
217 static struct socket_id* mk_listen_id2(struct name_lst*, int, int);
218 static void free_name_lst(struct name_lst* lst);
219 static void free_socket_id_lst(struct socket_id* i);
220
221 static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re, 
222                                                                         struct action* a, int* err);
223 static int case_check_type(struct case_stms* stms);
224 static int case_check_default(struct case_stms* stms);
225
226
227 %}
228
229 %union {
230         long intval;
231         unsigned long uval;
232         char* strval;
233         struct expr* expr;
234         struct action* action;
235         struct case_stms* case_stms;
236         struct net* ipnet;
237         struct ip_addr* ipaddr;
238         struct socket_id* sockid;
239         struct name_lst* name_l;
240         struct avp_spec* attr;
241         struct _pv_spec* pvar;
242         struct lvalue* lval;
243         struct rvalue* rval;
244         struct rval_expr* rv_expr;
245         select_t* select;
246 }
247
248 /* terminals */
249
250
251 /* keywords */
252 %token FORWARD
253 %token FORWARD_TCP
254 %token FORWARD_TLS
255 %token FORWARD_SCTP
256 %token FORWARD_UDP
257 %token SEND
258 %token SEND_TCP
259 %token DROP
260 %token RETURN
261 %token BREAK
262 %token LOG_TOK
263 %token ERROR
264 %token ROUTE
265 %token ROUTE_FAILURE
266 %token ROUTE_ONREPLY
267 %token ROUTE_BRANCH
268 %token ROUTE_SEND
269 %token EXEC
270 %token SET_HOST
271 %token SET_HOSTPORT
272 %token SET_HOSTPORTTRANS
273 %token PREFIX
274 %token STRIP
275 %token STRIP_TAIL
276 %token SET_USERPHONE
277 %token APPEND_BRANCH
278 %token SET_USER
279 %token SET_USERPASS
280 %token SET_PORT
281 %token SET_URI
282 %token REVERT_URI
283 %token FORCE_RPORT
284 %token FORCE_TCP_ALIAS
285 %token UDP_MTU
286 %token UDP_MTU_TRY_PROTO
287 %token IF
288 %token ELSE
289 %token SET_ADV_ADDRESS
290 %token SET_ADV_PORT
291 %token FORCE_SEND_SOCKET
292 %token SWITCH
293 %token CASE
294 %token DEFAULT
295 %token WHILE
296 %token URIHOST
297 %token URIPORT
298 %token MAX_LEN
299 %token SETFLAG
300 %token RESETFLAG
301 %token ISFLAGSET
302 %token SETAVPFLAG
303 %token RESETAVPFLAG
304 %token ISAVPFLAGSET
305 %token METHOD
306 %token URI
307 %token FROM_URI
308 %token TO_URI
309 %token SRCIP
310 %token SRCPORT
311 %token DSTIP
312 %token DSTPORT
313 %token TOIP
314 %token TOPORT
315 %token SNDIP
316 %token SNDPORT
317 %token SNDPROTO
318 %token SNDAF
319 %token PROTO
320 %token AF
321 %token MYSELF
322 %token MSGLEN
323 %token RETCODE
324 %token UDP
325 %token TCP
326 %token TLS
327 %token SCTP
328
329 /* config vars. */
330 %token DEBUG_V
331 %token FORK
332 %token LOGSTDERROR
333 %token LOGFACILITY
334 %token LISTEN
335 %token ALIAS
336 %token DNS
337 %token REV_DNS
338 %token DNS_TRY_IPV6
339 %token DNS_TRY_NAPTR
340 %token DNS_SRV_LB
341 %token DNS_UDP_PREF
342 %token DNS_TCP_PREF
343 %token DNS_TLS_PREF
344 %token DNS_SCTP_PREF
345 %token DNS_RETR_TIME
346 %token DNS_RETR_NO
347 %token DNS_SERVERS_NO
348 %token DNS_USE_SEARCH
349 %token DNS_SEARCH_FMATCH
350 %token DNS_CACHE_INIT
351 %token DNS_USE_CACHE
352 %token DNS_USE_FAILOVER
353 %token DNS_CACHE_FLAGS
354 %token DNS_CACHE_NEG_TTL
355 %token DNS_CACHE_MIN_TTL
356 %token DNS_CACHE_MAX_TTL
357 %token DNS_CACHE_MEM
358 %token DNS_CACHE_GC_INT
359 %token DNS_CACHE_DEL_NONEXP
360 /*blacklist*/
361 %token DST_BLST_INIT
362 %token USE_DST_BLST
363 %token DST_BLST_MEM
364 %token DST_BLST_TTL
365 %token DST_BLST_GC_INT
366
367 %token PORT
368 %token STAT
369 %token CHILDREN
370 %token CHECK_VIA
371 %token PHONE2TEL
372 %token SYN_BRANCH
373 %token MEMLOG
374 %token MEMDBG
375 %token SIP_WARNING
376 %token SERVER_SIGNATURE
377 %token REPLY_TO_VIA
378 %token LOADMODULE
379 %token LOADPATH
380 %token MODPARAM
381 %token MAXBUFFER
382 %token USER
383 %token GROUP
384 %token CHROOT
385 %token WDIR
386 %token MHOMED
387 %token DISABLE_TCP
388 %token TCP_ACCEPT_ALIASES
389 %token TCP_CHILDREN
390 %token TCP_CONNECT_TIMEOUT
391 %token TCP_SEND_TIMEOUT
392 %token TCP_CON_LIFETIME
393 %token TCP_POLL_METHOD
394 %token TCP_MAX_CONNECTIONS
395 %token TCP_NO_CONNECT
396 %token TCP_SOURCE_IPV4
397 %token TCP_SOURCE_IPV6
398 %token TCP_OPT_FD_CACHE
399 %token TCP_OPT_BUF_WRITE
400 %token TCP_OPT_CONN_WQ_MAX
401 %token TCP_OPT_WQ_MAX
402 %token TCP_OPT_RD_BUF
403 %token TCP_OPT_WQ_BLK
404 %token TCP_OPT_DEFER_ACCEPT
405 %token TCP_OPT_DELAYED_ACK
406 %token TCP_OPT_SYNCNT
407 %token TCP_OPT_LINGER2
408 %token TCP_OPT_KEEPALIVE
409 %token TCP_OPT_KEEPIDLE
410 %token TCP_OPT_KEEPINTVL
411 %token TCP_OPT_KEEPCNT
412 %token TCP_OPT_CRLF_PING
413 %token DISABLE_TLS
414 %token ENABLE_TLS
415 %token TLSLOG
416 %token TLS_PORT_NO
417 %token TLS_METHOD
418 %token TLS_HANDSHAKE_TIMEOUT
419 %token TLS_SEND_TIMEOUT
420 %token SSLv23
421 %token SSLv2
422 %token SSLv3
423 %token TLSv1
424 %token TLS_VERIFY
425 %token TLS_REQUIRE_CERTIFICATE
426 %token TLS_CERTIFICATE
427 %token TLS_PRIVATE_KEY
428 %token TLS_CA_LIST
429 %token DISABLE_SCTP
430 %token ENABLE_SCTP
431 %token SCTP_CHILDREN
432 %token SCTP_SOCKET_RCVBUF
433 %token SCTP_SOCKET_SNDBUF
434 %token SCTP_AUTOCLOSE
435 %token SCTP_SEND_TTL
436 %token SCTP_SEND_RETRIES
437 %token ADVERTISED_ADDRESS
438 %token ADVERTISED_PORT
439 %token DISABLE_CORE
440 %token OPEN_FD_LIMIT
441 %token SHM_FORCE_ALLOC
442 %token MLOCK_PAGES
443 %token REAL_TIME
444 %token RT_PRIO
445 %token RT_POLICY
446 %token RT_TIMER1_PRIO
447 %token RT_TIMER1_POLICY
448 %token RT_TIMER2_PRIO
449 %token RT_TIMER2_POLICY
450 %token MCAST_LOOPBACK
451 %token MCAST_TTL
452 %token TOS
453 %token PMTU_DISCOVERY
454 %token KILL_TIMEOUT
455 %token MAX_WLOOPS
456 %token CFG_DESCRIPTION
457 %token SERVER_ID
458
459 %token FLAGS_DECL
460 %token AVPFLAGS_DECL
461
462 %token ATTR_MARK
463 %token SELECT_MARK
464 %token ATTR_FROM
465 %token ATTR_TO
466 %token ATTR_FROMURI
467 %token ATTR_TOURI
468 %token ATTR_FROMUSER
469 %token ATTR_TOUSER
470 %token ATTR_FROMDOMAIN
471 %token ATTR_TODOMAIN
472 %token ATTR_GLOBAL
473 %token ADDEQ
474
475
476 %token STUN_REFRESH_INTERVAL
477 %token STUN_ALLOW_STUN
478 %token STUN_ALLOW_FP
479
480
481 /* operators, C like precedence */
482 %right EQUAL
483 %left LOG_OR
484 %left LOG_AND
485 %left BIN_OR
486 %left BIN_AND
487 %left EQUAL_T DIFF MATCH
488 %left GT LT GTE LTE
489 %left PLUS MINUS
490 %left STAR SLASH
491 %right NOT
492 %left DOT
493
494 /* values */
495 %token <intval> NUMBER
496 %token <strval> ID
497 %token <strval> STRING
498 %token <strval> IPV6ADDR
499 %token <strval> PVAR
500 /* not clear yet if this is an avp or pvar */
501 %token <strval> AVP_OR_PVAR
502
503 /* other */
504 %token COMMA
505 %token SEMICOLON
506 %token RPAREN
507 %token LPAREN
508 %token LBRACE
509 %token RBRACE
510 %token LBRACK
511 %token RBRACK
512 %token CR
513 %token COLON
514
515
516 /*non-terminals */
517 %type <expr> exp exp_elem
518 %type <intval> intno eint_op eint_op_onsend
519 %type <intval> eip_op eip_op_onsend
520 %type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
521 %type <action> switch_cmd while_cmd
522 %type <case_stms> single_case case_stms
523 %type <ipaddr> ipv4 ipv6 ipv6addr ip
524 %type <ipnet> ipnet
525 %type <strval> host
526 %type <strval> listen_id
527 %type <name_l> listen_id_lst
528 %type <name_l> listen_id2
529 %type <sockid>  id_lst
530 %type <sockid>  phostport
531 %type <sockid>  listen_phostport
532 %type <intval> proto port
533 %type <intval> equalop strop cmpop rve_cmpop rve_equalop
534 %type <intval> uri_type
535 %type <attr> attr_id
536 %type <attr> attr_id_num_idx
537 %type <attr> attr_id_no_idx
538 %type <attr> attr_id_ass
539 /*%type <attr> attr_id_val*/
540 %type <attr> attr_id_any
541 %type <attr> attr_id_any_str
542 %type <pvar> pvar
543 %type <lval> lval
544 %type <rv_expr> rval rval_expr ct_rval
545 %type <lval> avp_pvar
546 /* %type <intval> class_id */
547 %type <intval> assign_op
548 %type <select> select_id
549 %type <strval>  flag_name;
550 %type <strval>  route_name;
551 %type <intval> avpflag_oper
552 %type <intval> rve_un_op
553 /* %type <intval> rve_op */
554
555 /*%type <route_el> rules;
556   %type <route_el> rule;
557 */
558
559 %%
560
561
562 cfg:
563         statements
564         ;
565 statements:
566         statements statement {}
567         | statement {}
568         | statements error { yyerror(""); YYABORT;}
569         ;
570 statement:
571         assign_stm
572         | flags_decl
573         | avpflags_decl
574         | module_stm
575         | {rt=REQUEST_ROUTE;} route_stm
576         | {rt=FAILURE_ROUTE;} failure_route_stm
577         | {rt=ONREPLY_ROUTE;} onreply_route_stm
578         | {rt=BRANCH_ROUTE;} branch_route_stm
579         | {rt=ONSEND_ROUTE;}   send_route_stm
580         | SEMICOLON     /* null statement */
581         | CR    /* null statement*/
582         ;
583 listen_id:
584         ip {
585                 tmp=ip_addr2a($1);
586                 if (tmp==0) {
587                         LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
588                                         "address.\n");
589                         $$=0;
590                 } else {
591                         $$=pkg_malloc(strlen(tmp)+1);
592                         if ($$==0) {
593                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
594                                                 "memory.\n");
595                         } else {
596                                 strncpy($$, tmp, strlen(tmp)+1);
597                         }
598                 }
599         }
600         | STRING {
601                 $$=pkg_malloc(strlen($1)+1);
602                 if ($$==0) {
603                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
604                                                 "memory.\n");
605                 } else {
606                                 strncpy($$, $1, strlen($1)+1);
607                 }
608         }
609         | host {
610                 $$=pkg_malloc(strlen($1)+1);
611                 if ($$==0) {
612                                 LOG(L_CRIT, "ERROR: cfg. parser: out of "
613                                                 "memory.\n");
614                 } else {
615                                 strncpy($$, $1, strlen($1)+1);
616                 }
617         }
618         ;
619
620
621 listen_id_lst:
622         listen_id       { $$=mk_name_lst($1, SI_IS_MHOMED); }
623         | listen_id COMMA listen_id_lst { $$=mk_name_lst($1, SI_IS_MHOMED); 
624                                                                                 if ($$) $$->next=$3;
625                                                                         }
626         ;
627
628 listen_id2:
629         LPAREN listen_id_lst RPAREN { $$=$2; }
630         | listen_id     { $$=mk_name_lst($1, 0); }
631         ;
632
633 proto:
634         UDP     { $$=PROTO_UDP; }
635         | TCP   { $$=PROTO_TCP; }
636         | TLS   { $$=PROTO_TLS; }
637         | SCTP  { $$=PROTO_SCTP; }
638         | STAR  { $$=0; }
639         ;
640 port:
641         NUMBER  { $$=$1; }
642         | STAR  { $$=0; }
643 ;
644 phostport:
645         listen_id               { $$=mk_listen_id($1, 0, 0); }
646         | listen_id COLON port  { $$=mk_listen_id($1, 0, $3); }
647         | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
648         | proto COLON listen_id COLON port      { $$=mk_listen_id($3, $1, $5);}
649         | listen_id COLON error { $$=0; yyerror(" port number expected"); }
650         ;
651
652 listen_phostport:
653         listen_id2              { $$=mk_listen_id2($1, 0, 0); }
654         | listen_id2 COLON port { $$=mk_listen_id2($1, 0, $3); }
655         | proto COLON listen_id2        { $$=mk_listen_id2($3, $1, 0); }
656         | proto COLON listen_id2 COLON port     { $$=mk_listen_id2($3, $1, $5);}
657         | listen_id2 COLON error { $$=0; yyerror(" port number expected"); }
658         ;
659
660 id_lst:
661         listen_phostport                {  $$=$1 ; }
662         | listen_phostport id_lst       { $$=$1; $$->next=$2; }
663         ;
664
665 intno: NUMBER
666         |  MINUS %prec NOT NUMBER { $$=-$2; }
667         ;
668
669 flags_decl:             FLAGS_DECL      flag_list
670                         |       FLAGS_DECL error { yyerror("flag list expected\n"); }
671 ;
672 flag_list:              flag_spec
673                         |       flag_spec COMMA flag_list
674 ;
675
676 flag_spec:              flag_name       { if (register_flag($1,-1)<0)
677                                                                 yyerror("register flag failed");
678                                                 }
679                         |       flag_name COLON NUMBER {
680                                                 if (register_flag($1, $3)<0)
681                                                                 yyerror("register flag failed");
682                                                                                 }
683 ;
684
685 flag_name:              STRING  { $$=$1; }
686                         |       ID              { $$=$1; }
687 ;
688
689 avpflags_decl:
690         AVPFLAGS_DECL avpflag_list
691         | AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
692         ;
693 avpflag_list:
694         avpflag_spec
695         | avpflag_spec COMMA avpflag_list
696         ;
697 avpflag_spec:
698         flag_name {
699                 if (register_avpflag($1)==0)
700                         yyerror("cannot declare avpflag");
701         }
702         ;
703 assign_stm:
704         DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
705         | DEBUG_V EQUAL error  { yyerror("number  expected"); }
706         | FORK  EQUAL NUMBER { dont_fork= ! $3; }
707         | FORK  EQUAL error  { yyerror("boolean value expected"); }
708         | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
709         | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
710         | LOGFACILITY EQUAL ID {
711                 if ( (i_tmp=str2facility($3))==-1)
712                         yyerror("bad facility (see syslog(3) man page)");
713                 if (!config_check)
714                         default_core_cfg.log_facility=i_tmp;
715         }
716         | LOGFACILITY EQUAL error { yyerror("ID expected"); }
717         | DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
718         | DNS EQUAL error { yyerror("boolean value expected"); }
719         | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
720         | REV_DNS EQUAL error { yyerror("boolean value expected"); }
721         | DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
722         | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
723         | DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
724         | DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
725         | DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
726         | DNS_SRV_LB error { yyerror("boolean value expected"); }
727         | DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
728         | DNS_UDP_PREF error { yyerror("number expected"); }
729         | DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
730         | DNS_TCP_PREF error { yyerror("number expected"); }
731         | DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
732         | DNS_TLS_PREF error { yyerror("number expected"); }
733         | DNS_SCTP_PREF EQUAL intno { 
734                                                                 IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
735         | DNS_SCTP_PREF error { yyerror("number expected"); }
736         | DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
737         | DNS_RETR_TIME error { yyerror("number expected"); }
738         | DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
739         | DNS_RETR_NO error { yyerror("number expected"); }
740         | DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
741         | DNS_SERVERS_NO error { yyerror("number expected"); }
742         | DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
743         | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
744         | DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
745         | DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
746         | DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
747         | DNS_CACHE_INIT error { yyerror("boolean value expected"); }
748         | DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
749         | DNS_USE_CACHE error { yyerror("boolean value expected"); }
750         | DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
751         | DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
752         | DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
753         | DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
754         | DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
755         | DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
756         | DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
757         | DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
758         | DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
759         | DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
760         | DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
761         | DNS_CACHE_MEM error { yyerror("boolean value expected"); }
762         | DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
763         | DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
764         | DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
765         | DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
766         | DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
767         | DST_BLST_INIT error { yyerror("boolean value expected"); }
768         | USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
769         | USE_DST_BLST error { yyerror("boolean value expected"); }
770         | DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }
771         | DST_BLST_MEM error { yyerror("boolean value expected"); }
772         | DST_BLST_TTL EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3); }
773         | DST_BLST_TTL error { yyerror("boolean value expected"); }
774         | DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
775         | DST_BLST_GC_INT error { yyerror("boolean value expected"); }
776         | PORT EQUAL NUMBER   { port_no=$3; }
777         | STAT EQUAL STRING {
778                 #ifdef STATS
779                                 stat_file=$3;
780                 #endif
781         }
782         | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
783         | MAXBUFFER EQUAL error { yyerror("number expected"); }
784         | PORT EQUAL error    { yyerror("number expected"); }
785         | CHILDREN EQUAL NUMBER { children_no=$3; }
786         | CHILDREN EQUAL error { yyerror("number expected"); }
787         | CHECK_VIA EQUAL NUMBER { check_via=$3; }
788         | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
789         | PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
790         | PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
791         | SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
792         | SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
793         | MEMLOG EQUAL intno { memlog=$3; }
794         | MEMLOG EQUAL error { yyerror("int value expected"); }
795         | MEMDBG EQUAL intno { memdbg=$3; }
796         | MEMDBG EQUAL error { yyerror("int value expected"); }
797         | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
798         | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
799         | USER EQUAL STRING     { user=$3; }
800         | USER EQUAL ID         { user=$3; }
801         | USER EQUAL error      { yyerror("string value expected"); }
802         | GROUP EQUAL STRING     { group=$3; }
803         | GROUP EQUAL ID         { group=$3; }
804         | GROUP EQUAL error      { yyerror("string value expected"); }
805         | CHROOT EQUAL STRING     { chroot_dir=$3; }
806         | CHROOT EQUAL ID         { chroot_dir=$3; }
807         | CHROOT EQUAL error      { yyerror("string value expected"); }
808         | WDIR EQUAL STRING     { working_dir=$3; }
809         | WDIR EQUAL ID         { working_dir=$3; }
810         | WDIR EQUAL error      { yyerror("string value expected"); }
811         | MHOMED EQUAL NUMBER { mhomed=$3; }
812         | MHOMED EQUAL error { yyerror("boolean value expected"); }
813         | DISABLE_TCP EQUAL NUMBER {
814                 #ifdef USE_TCP
815                         tcp_disable=$3;
816                 #else
817                         warn("tcp support not compiled in");
818                 #endif
819         }
820         | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
821         | TCP_ACCEPT_ALIASES EQUAL NUMBER {
822                 #ifdef USE_TCP
823                         tcp_default_cfg.accept_aliases=$3;
824                 #else
825                         warn("tcp support not compiled in");
826                 #endif
827         }
828         | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
829         | TCP_CHILDREN EQUAL NUMBER {
830                 #ifdef USE_TCP
831                         tcp_children_no=$3;
832                 #else
833                         warn("tcp support not compiled in");
834                 #endif
835         }
836         | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
837         | TCP_CONNECT_TIMEOUT EQUAL intno {
838                 #ifdef USE_TCP
839                         tcp_default_cfg.connect_timeout_s=$3;
840                 #else
841                         warn("tcp support not compiled in");
842                 #endif
843         }
844         | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
845         | TCP_SEND_TIMEOUT EQUAL intno {
846                 #ifdef USE_TCP
847                         tcp_default_cfg.send_timeout=S_TO_TICKS($3);
848                 #else
849                         warn("tcp support not compiled in");
850                 #endif
851         }
852         | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
853         | TCP_CON_LIFETIME EQUAL intno {
854                 #ifdef USE_TCP
855                         if ($3<0)
856                                 tcp_default_cfg.con_lifetime=-1;
857                         else
858                                 tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
859                 #else
860                         warn("tcp support not compiled in");
861                 #endif
862         }
863         | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
864         | TCP_POLL_METHOD EQUAL ID {
865                 #ifdef USE_TCP
866                         tcp_poll_method=get_poll_type($3);
867                         if (tcp_poll_method==POLL_NONE) {
868                                 LOG(L_CRIT, "bad poll method name:"
869                                                 " %s\n, try one of %s.\n",
870                                                 $3, poll_support);
871                                 yyerror("bad tcp_poll_method "
872                                                 "value");
873                         }
874                 #else
875                         warn("tcp support not compiled in");
876                 #endif
877         }
878         | TCP_POLL_METHOD EQUAL STRING {
879                 #ifdef USE_TCP
880                         tcp_poll_method=get_poll_type($3);
881                         if (tcp_poll_method==POLL_NONE) {
882                                 LOG(L_CRIT, "bad poll method name:"
883                                                 " %s\n, try one of %s.\n",
884                                                 $3, poll_support);
885                                 yyerror("bad tcp_poll_method "
886                                                 "value");
887                         }
888                 #else
889                         warn("tcp support not compiled in");
890                 #endif
891         }
892         | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
893         | TCP_MAX_CONNECTIONS EQUAL NUMBER {
894                 #ifdef USE_TCP
895                         tcp_max_connections=$3;
896                 #else
897                         warn("tcp support not compiled in");
898                 #endif
899         }
900         | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
901         | TCP_NO_CONNECT EQUAL NUMBER {
902                 #ifdef USE_TCP
903                         tcp_default_cfg.no_connect=$3;
904                 #else
905                         warn("tcp support not compiled in");
906                 #endif
907         }
908         | TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
909         | TCP_SOURCE_IPV4 EQUAL ipv4 {
910                 #ifdef USE_TCP
911                         if (tcp_set_src_addr($3)<0)
912                                 warn("tcp_source_ipv4 failed");
913                 #else
914                         warn("tcp support not compiled in");
915                 #endif
916                 pkg_free($3);
917         }
918         | TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
919         | TCP_SOURCE_IPV6 EQUAL ipv6 {
920                 #ifdef USE_TCP
921                         #ifdef USE_IPV6
922                                 if (tcp_set_src_addr($3)<0)
923                                         warn("tcp_source_ipv6 failed");
924                         #else
925                                 warn("IPv6 support not compiled in");
926                         #endif
927                 #else
928                         warn("tcp support not compiled in");
929                 #endif
930                 pkg_free($3);
931         }
932         | TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
933         | TCP_OPT_FD_CACHE EQUAL NUMBER {
934                 #ifdef USE_TCP
935                         tcp_default_cfg.fd_cache=$3;
936                 #else
937                         warn("tcp support not compiled in");
938                 #endif
939         }
940         | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
941         | TCP_OPT_BUF_WRITE EQUAL NUMBER {
942                 #ifdef USE_TCP
943                         tcp_default_cfg.async=$3;
944                 #else
945                         warn("tcp support not compiled in");
946                 #endif
947         }
948         | TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
949         | TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
950                 #ifdef USE_TCP
951                         tcp_default_cfg.tcpconn_wq_max=$3;
952                 #else
953                         warn("tcp support not compiled in");
954                 #endif
955         }
956         | TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
957         | TCP_OPT_WQ_MAX EQUAL NUMBER {
958                 #ifdef USE_TCP
959                         tcp_default_cfg.tcp_wq_max=$3;
960                 #else
961                         warn("tcp support not compiled in");
962                 #endif
963         }
964         | TCP_OPT_WQ_MAX error { yyerror("number expected"); }
965         | TCP_OPT_RD_BUF EQUAL NUMBER {
966                 #ifdef USE_TCP
967                         tcp_default_cfg.rd_buf_size=$3;
968                 #else
969                         warn("tcp support not compiled in");
970                 #endif
971         }
972         | TCP_OPT_RD_BUF error { yyerror("number expected"); }
973         | TCP_OPT_WQ_BLK EQUAL NUMBER {
974                 #ifdef USE_TCP
975                         tcp_default_cfg.wq_blk_size=$3;
976                 #else
977                         warn("tcp support not compiled in");
978                 #endif
979         }
980         | TCP_OPT_WQ_BLK error { yyerror("number expected"); }
981         | TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
982                 #ifdef USE_TCP
983                         tcp_default_cfg.defer_accept=$3;
984                 #else
985                         warn("tcp support not compiled in");
986                 #endif
987         }
988         | TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
989         | TCP_OPT_DELAYED_ACK EQUAL NUMBER {
990                 #ifdef USE_TCP
991                         tcp_default_cfg.delayed_ack=$3;
992                 #else
993                         warn("tcp support not compiled in");
994                 #endif
995         }
996         | TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
997         | TCP_OPT_SYNCNT EQUAL NUMBER {
998                 #ifdef USE_TCP
999                         tcp_default_cfg.syncnt=$3;
1000                 #else
1001                         warn("tcp support not compiled in");
1002                 #endif
1003         }
1004         | TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
1005         | TCP_OPT_LINGER2 EQUAL NUMBER {
1006                 #ifdef USE_TCP
1007                         tcp_default_cfg.linger2=$3;
1008                 #else
1009                         warn("tcp support not compiled in");
1010                 #endif
1011         }
1012         | TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
1013         | TCP_OPT_KEEPALIVE EQUAL NUMBER {
1014                 #ifdef USE_TCP
1015                         tcp_default_cfg.keepalive=$3;
1016                 #else
1017                         warn("tcp support not compiled in");
1018                 #endif
1019         }
1020         | TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
1021         | TCP_OPT_KEEPIDLE EQUAL NUMBER {
1022                 #ifdef USE_TCP
1023                         tcp_default_cfg.keepidle=$3;
1024                 #else
1025                         warn("tcp support not compiled in");
1026                 #endif
1027         }
1028         | TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
1029         | TCP_OPT_KEEPINTVL EQUAL NUMBER {
1030                 #ifdef USE_TCP
1031                         tcp_default_cfg.keepintvl=$3;
1032                 #else
1033                         warn("tcp support not compiled in");
1034                 #endif
1035         }
1036         | TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
1037         | TCP_OPT_KEEPCNT EQUAL NUMBER {
1038                 #ifdef USE_TCP
1039                         tcp_default_cfg.keepcnt=$3;
1040                 #else
1041                         warn("tcp support not compiled in");
1042                 #endif
1043         }
1044         | TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
1045         | TCP_OPT_CRLF_PING EQUAL NUMBER {
1046                 #ifdef USE_TCP
1047                         tcp_default_cfg.crlf_ping=$3;
1048                 #else
1049                         warn("tcp support not compiled in");
1050                 #endif
1051         }
1052         | TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
1053         | DISABLE_TLS EQUAL NUMBER {
1054                 #ifdef USE_TLS
1055                         tls_disable=$3;
1056                 #else
1057                         warn("tls support not compiled in");
1058                 #endif
1059         }
1060         | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1061         | ENABLE_TLS EQUAL NUMBER {
1062                 #ifdef USE_TLS
1063                         tls_disable=!($3);
1064                 #else
1065                         warn("tls support not compiled in");
1066                 #endif
1067         }
1068         | ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1069         | TLSLOG EQUAL NUMBER {
1070                 #ifdef CORE_TLS
1071                         tls_log=$3;
1072                 #else
1073                         warn("tls-in-core support not compiled in");
1074                 #endif
1075         }
1076         | TLSLOG EQUAL error { yyerror("int value expected"); }
1077         | TLS_PORT_NO EQUAL NUMBER {
1078                 #ifdef USE_TLS
1079                         tls_port_no=$3;
1080                 #else
1081                         warn("tls support not compiled in");
1082                 #endif
1083         }
1084         | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
1085         | TLS_METHOD EQUAL SSLv23 {
1086                 #ifdef CORE_TLS
1087                         tls_method=TLS_USE_SSLv23;
1088                 #else
1089                         warn("tls-in-core support not compiled in");
1090                 #endif
1091         }
1092         | TLS_METHOD EQUAL SSLv2 {
1093                 #ifdef CORE_TLS
1094                         tls_method=TLS_USE_SSLv2;
1095                 #else
1096                         warn("tls-in-core support not compiled in");
1097                 #endif
1098         }
1099         | TLS_METHOD EQUAL SSLv3 {
1100                 #ifdef CORE_TLS
1101                         tls_method=TLS_USE_SSLv3;
1102                 #else
1103                         warn("tls-in-core support not compiled in");
1104                 #endif
1105         }
1106         | TLS_METHOD EQUAL TLSv1 {
1107                 #ifdef CORE_TLS
1108                         tls_method=TLS_USE_TLSv1;
1109                 #else
1110                         warn("tls-in-core support not compiled in");
1111                 #endif
1112         }
1113         | TLS_METHOD EQUAL error {
1114                 #ifdef CORE_TLS
1115                         yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
1116                 #else
1117                         warn("tls-in-core support not compiled in");
1118                 #endif
1119         }
1120         | TLS_VERIFY EQUAL NUMBER {
1121                 #ifdef CORE_TLS
1122                         tls_verify_cert=$3;
1123                 #else
1124                         warn("tls-in-core support not compiled in");
1125                 #endif
1126         }
1127         | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
1128         | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
1129                 #ifdef CORE_TLS
1130                         tls_require_cert=$3;
1131                 #else
1132                         warn( "tls-in-core support not compiled in");
1133                 #endif
1134         }
1135         | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
1136         | TLS_CERTIFICATE EQUAL STRING {
1137                 #ifdef CORE_TLS
1138                         tls_cert_file=$3;
1139                 #else
1140                         warn("tls-in-core support not compiled in");
1141                 #endif
1142         }
1143         | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
1144         | TLS_PRIVATE_KEY EQUAL STRING {
1145                 #ifdef CORE_TLS
1146                         tls_pkey_file=$3;
1147                 #else
1148                         warn("tls-in-core support not compiled in");
1149                 #endif
1150         }
1151         | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1152         | TLS_CA_LIST EQUAL STRING {
1153                 #ifdef CORE_TLS
1154                         tls_ca_file=$3;
1155                 #else
1156                         warn("tls-in-core support not compiled in");
1157                 #endif
1158         }
1159         | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1160         | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
1161                 #ifdef CORE_TLS
1162                         tls_handshake_timeout=$3;
1163                 #else
1164                         warn("tls-in-core support not compiled in");
1165                 #endif
1166         }
1167         | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
1168         | TLS_SEND_TIMEOUT EQUAL NUMBER {
1169                 #ifdef CORE_TLS
1170                         tls_send_timeout=$3;
1171                 #else
1172                         warn("tls-in-core support not compiled in");
1173                 #endif
1174         }
1175         | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
1176         | DISABLE_SCTP EQUAL NUMBER {
1177                 #ifdef USE_SCTP
1178                         sctp_disable=$3;
1179                 #else
1180                         warn("sctp support not compiled in");
1181                 #endif
1182         }
1183         | DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
1184         | ENABLE_SCTP EQUAL NUMBER {
1185                 #ifdef USE_SCTP
1186                         sctp_disable=($3<=1)?!$3:$3;
1187                 #else
1188                         warn("sctp support not compiled in");
1189                 #endif
1190         }
1191         | ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
1192         | SCTP_CHILDREN EQUAL NUMBER {
1193                 #ifdef USE_SCTP
1194                         sctp_children_no=$3;
1195                 #else
1196                         warn("sctp support not compiled in");
1197                 #endif
1198         }
1199         | SCTP_CHILDREN EQUAL error { yyerror("number expected"); }
1200         | SCTP_SOCKET_RCVBUF EQUAL NUMBER {
1201                 #ifdef USE_SCTP
1202                         sctp_options.sctp_so_rcvbuf=$3;
1203                 #else
1204                         warn("sctp support not compiled in");
1205                 #endif
1206         }
1207         | SCTP_SOCKET_RCVBUF EQUAL error { yyerror("number expected"); }
1208         | SCTP_SOCKET_SNDBUF EQUAL NUMBER {
1209                 #ifdef USE_SCTP
1210                         sctp_options.sctp_so_sndbuf=$3;
1211                 #else
1212                         warn("sctp support not compiled in");
1213                 #endif
1214         }
1215         | SCTP_SOCKET_SNDBUF EQUAL error { yyerror("number expected"); }
1216         | SCTP_AUTOCLOSE EQUAL NUMBER {
1217                 #ifdef USE_SCTP
1218                         sctp_options.sctp_autoclose=$3;
1219                 #else
1220                         warn("sctp support not compiled in");
1221                 #endif
1222         }
1223         | SCTP_AUTOCLOSE EQUAL error { yyerror("number expected"); }
1224         | SCTP_SEND_TTL EQUAL NUMBER {
1225                 #ifdef USE_SCTP
1226                         sctp_options.sctp_send_ttl=$3;
1227                 #else
1228                         warn("sctp support not compiled in");
1229                 #endif
1230         }
1231         | SCTP_SEND_TTL EQUAL error { yyerror("number expected"); }
1232         | SCTP_SEND_RETRIES EQUAL NUMBER {
1233                 #ifdef USE_SCTP
1234                         sctp_options.sctp_send_retries=$3;
1235                 #else
1236                         warn("sctp support not compiled in");
1237                 #endif
1238         }
1239         | SCTP_SEND_RETRIES EQUAL error { yyerror("number expected"); }
1240         | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
1241         | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
1242         | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
1243         | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
1244         | LISTEN EQUAL id_lst {
1245                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1246                         if (add_listen_iface(   lst_tmp->addr_lst->name,
1247                                                                         lst_tmp->addr_lst->next,
1248                                                                         lst_tmp->port, lst_tmp->proto,
1249                                                                         lst_tmp->flags)!=0) {
1250                                 LOG(L_CRIT,  "ERROR: cfg. parser: failed to add listen"
1251                                                                 " address\n");
1252                                 break;
1253                         }
1254                 }
1255                 free_socket_id_lst($3);
1256         }
1257         | LISTEN EQUAL  error { yyerror("ip address or hostname expected"); }
1258         | ALIAS EQUAL  id_lst {
1259                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
1260                         add_alias(      lst_tmp->addr_lst->name,
1261                                                 strlen(lst_tmp->addr_lst->name),
1262                                                 lst_tmp->port, lst_tmp->proto);
1263                         for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
1264                                 add_alias(nl_tmp->name, strlen(nl_tmp->name),
1265                                                         lst_tmp->port, lst_tmp->proto);
1266                 }
1267                 free_socket_id_lst($3);
1268         }
1269         | ALIAS  EQUAL error  { yyerror(" hostname expected"); }
1270         | ADVERTISED_ADDRESS EQUAL listen_id {
1271                 default_global_address.s=$3;
1272                 default_global_address.len=strlen($3);
1273         }
1274         | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
1275         | ADVERTISED_PORT EQUAL NUMBER {
1276                 tmp=int2str($3, &i_tmp);
1277                 if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
1278                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1279                         default_global_port.len=0;
1280                 } else {
1281                         default_global_port.len=i_tmp;
1282                         memcpy(default_global_port.s, tmp, default_global_port.len);
1283                 };
1284         }
1285         |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
1286         | DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
1287         | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1288         | OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1289         | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1290         | SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
1291         | SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1292         | MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1293         | MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
1294         | REAL_TIME EQUAL NUMBER { real_time=$3; }
1295         | REAL_TIME EQUAL error { yyerror("boolean value expected"); }
1296         | RT_PRIO EQUAL NUMBER { rt_prio=$3; }
1297         | RT_PRIO EQUAL error { yyerror("boolean value expected"); }
1298         | RT_POLICY EQUAL NUMBER { rt_policy=$3; }
1299         | RT_POLICY EQUAL error { yyerror("boolean value expected"); }
1300         | RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
1301         | RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
1302         | RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
1303         | RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
1304         | RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
1305         | RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
1306         | RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
1307         | RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
1308         | MCAST_LOOPBACK EQUAL NUMBER {
1309                 #ifdef USE_MCAST
1310                         mcast_loopback=$3;
1311                 #else
1312                         warn("no multicast support compiled in");
1313                 #endif
1314         }
1315         | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
1316         | MCAST_TTL EQUAL NUMBER {
1317                 #ifdef USE_MCAST
1318                         mcast_ttl=$3;
1319                 #else
1320                         warn("no multicast support compiled in");
1321                 #endif
1322         }
1323         | MCAST_TTL EQUAL error { yyerror("number expected"); }
1324         | TOS EQUAL NUMBER { tos=$3; }
1325         | TOS EQUAL error { yyerror("number expected"); }
1326         | PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
1327         | PMTU_DISCOVERY error { yyerror("number expected"); }
1328         | KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
1329         | KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
1330         | MAX_WLOOPS EQUAL NUMBER { default_core_cfg.max_while_loops=$3; }
1331         | MAX_WLOOPS EQUAL error { yyerror("number expected"); }
1332         | STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
1333         | STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
1334         | STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
1335         | STUN_ALLOW_STUN EQUAL error{ yyerror("number expected"); }
1336         | STUN_ALLOW_FP EQUAL NUMBER { IF_STUN(stun_allow_fp=$3) ; }
1337         | STUN_ALLOW_FP EQUAL error{ yyerror("number expected"); }
1338     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1339         | UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1340         | UDP_MTU EQUAL error { yyerror("number expected"); }
1341         | FORCE_RPORT EQUAL NUMBER 
1342                 { default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1343         | FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1344         | UDP_MTU_TRY_PROTO EQUAL proto
1345                 { default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
1346         | UDP_MTU_TRY_PROTO EQUAL error
1347                 { yyerror("TCP, TLS, SCTP or UDP expected"); }
1348         | cfg_var
1349         | error EQUAL { yyerror("unknown config variable"); }
1350         ;
1351 cfg_var:
1352         ID DOT ID EQUAL NUMBER {
1353                 if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1354                         yyerror("variable cannot be declared");
1355                 }
1356         }
1357         | ID DOT ID EQUAL STRING {
1358                 if (cfg_declare_str($1, $3, $5, NULL)) {
1359                         yyerror("variable cannot be declared");
1360                 }
1361         }
1362         | ID DOT ID EQUAL NUMBER CFG_DESCRIPTION STRING {
1363                 if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1364                         yyerror("variable cannot be declared");
1365                 }
1366         }
1367         | ID DOT ID EQUAL STRING CFG_DESCRIPTION STRING {
1368                 if (cfg_declare_str($1, $3, $5, $7)) {
1369                         yyerror("variable cannot be declared");
1370                 }
1371         }
1372         | ID DOT ID EQUAL error { yyerror("number or string expected"); }
1373         ;
1374 module_stm:
1375         LOADMODULE STRING {
1376                 DBG("loading module %s\n", $2);
1377                         if (load_module($2)!=0) {
1378                                 yyerror("failed to load module");
1379                         }
1380         }
1381         | LOADMODULE error      { yyerror("string expected"); }
1382         | LOADPATH STRING {
1383                 DBG("loading modules under %s\n", $2);
1384                 printf("loading modules under %s\n", $2);
1385                 mods_dir = $2;
1386         }
1387         | LOADPATH error        { yyerror("string expected"); }
1388         | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1389                 if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1390                          yyerror("Can't set module parameter");
1391                 }
1392         }
1393         | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1394                 if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1395                          yyerror("Can't set module parameter");
1396                 }
1397         }
1398         | MODPARAM error { yyerror("Invalid arguments"); }
1399         ;
1400 ip:
1401         ipv4  { $$=$1; }
1402         | ipv6  { $$=$1; }
1403         ;
1404 ipv4:
1405         NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
1406                 $$=pkg_malloc(sizeof(struct ip_addr));
1407                 if ($$==0) {
1408                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1409                 } else {
1410                         memset($$, 0, sizeof(struct ip_addr));
1411                         $$->af=AF_INET;
1412                         $$->len=4;
1413                         if (($1>255) || ($1<0) ||
1414                                 ($3>255) || ($3<0) ||
1415                                 ($5>255) || ($5<0) ||
1416                                 ($7>255) || ($7<0)) {
1417                                 yyerror("invalid ipv4 address");
1418                                 $$->u.addr32[0]=0;
1419                                 /* $$=0; */
1420                         } else {
1421                                 $$->u.addr[0]=$1;
1422                                 $$->u.addr[1]=$3;
1423                                 $$->u.addr[2]=$5;
1424                                 $$->u.addr[3]=$7;
1425                                 /*
1426                                 $$=htonl( ($1<<24)|
1427                                 ($3<<16)| ($5<<8)|$7 );
1428                                 */
1429                         }
1430                 }
1431         }
1432         ;
1433 ipv6addr:
1434         IPV6ADDR {
1435                 $$=pkg_malloc(sizeof(struct ip_addr));
1436                 if ($$==0) {
1437                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1438                 } else {
1439                 #ifdef USE_IPV6
1440                         memset($$, 0, sizeof(struct ip_addr));
1441                         $$->af=AF_INET6;
1442                         $$->len=16;
1443                         if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
1444                                 yyerror("bad ipv6 address");
1445                         }
1446                 #else
1447                         yyerror("ipv6 address & no ipv6 support compiled in");
1448                         YYABORT;
1449                 #endif
1450                 }
1451         }
1452         ;
1453 ipv6:
1454         ipv6addr { $$=$1; }
1455         | LBRACK ipv6addr RBRACK {$$=$2; }
1456 ;
1457
1458
1459 route_name:             NUMBER  {
1460                                         tmp=int2str($1, &i_tmp);
1461                                         if (($$=pkg_malloc(i_tmp+1))==0) {
1462                                                 yyerror("out of  memory");
1463                                                 YYABORT;
1464                                         } else {
1465                                                 memcpy($$, tmp, i_tmp);
1466                                                 $$[i_tmp]=0;
1467                                         }
1468                                                 }
1469                         |       ID              { $$=$1; }
1470                         |       STRING  { $$=$1; }
1471 ;
1472
1473 route_stm:
1474         ROUTE LBRACE actions RBRACE { push($3, &main_rt.rlist[DEFAULT_RT]); }
1475         | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
1476                 i_tmp=route_get(&main_rt, $3);
1477                 if (i_tmp==-1){
1478                         yyerror("internal error");
1479                         YYABORT;
1480                 }
1481                 if (main_rt.rlist[i_tmp]){
1482                         yyerror("duplicate route");
1483                         YYABORT;
1484                 }
1485                 push($6, &main_rt.rlist[i_tmp]);
1486         }
1487         | ROUTE error { yyerror("invalid  route  statement"); }
1488         ;
1489 failure_route_stm:
1490         ROUTE_FAILURE LBRACE actions RBRACE {
1491                                                                         push($3, &failure_rt.rlist[DEFAULT_RT]);
1492                                                                                 }
1493         | ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1494                 i_tmp=route_get(&failure_rt, $3);
1495                 if (i_tmp==-1){
1496                         yyerror("internal error");
1497                         YYABORT;
1498                 }
1499                 if (failure_rt.rlist[i_tmp]){
1500                         yyerror("duplicate route");
1501                         YYABORT;
1502                 }
1503                 push($6, &failure_rt.rlist[i_tmp]);
1504         }
1505         | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1506         ;
1507 onreply_route_stm:
1508         ROUTE_ONREPLY LBRACE actions RBRACE {
1509                                                                         push($3, &onreply_rt.rlist[DEFAULT_RT]);
1510                                                                                 }
1511         | ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
1512                 i_tmp=route_get(&onreply_rt, $3);
1513                 if (i_tmp==-1){
1514                         yyerror("internal error");
1515                         YYABORT;
1516                 }
1517                 if (onreply_rt.rlist[i_tmp]){
1518                         yyerror("duplicate route");
1519                         YYABORT;
1520                 }
1521                 push($6, &onreply_rt.rlist[i_tmp]);
1522         }
1523         | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
1524         ;
1525 branch_route_stm:
1526         ROUTE_BRANCH LBRACE actions RBRACE {
1527                                                                         push($3, &branch_rt.rlist[DEFAULT_RT]);
1528                                                                                 }
1529         | ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1530                 i_tmp=route_get(&branch_rt, $3);
1531                 if (i_tmp==-1){
1532                         yyerror("internal error");
1533                         YYABORT;
1534                 }
1535                 if (branch_rt.rlist[i_tmp]){
1536                         yyerror("duplicate route");
1537                         YYABORT;
1538                 }
1539                 push($6, &branch_rt.rlist[i_tmp]);
1540         }
1541         | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1542         ;
1543 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1544                                                                         push($3, &onsend_rt.rlist[DEFAULT_RT]);
1545                                                                                                 }
1546         | ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1547                 i_tmp=route_get(&onsend_rt, $3);
1548                 if (i_tmp==-1){
1549                         yyerror("internal error");
1550                         YYABORT;
1551                 }
1552                 if (onsend_rt.rlist[i_tmp]){
1553                         yyerror("duplicate route");
1554                         YYABORT;
1555                 }
1556                 push($6, &onsend_rt.rlist[i_tmp]);
1557         }
1558         | ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1559         ;
1560
1561 exp:    rval_expr
1562                 {
1563                         if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1564                                 yyerror("invalid expression");
1565                                 $$=0;
1566                         }else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
1567                                 yyerror("invalid expression type, int expected\n");
1568                                 $$=0;
1569                         }else
1570                                 $$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
1571                 }
1572         ;
1573
1574 /* exp elem operators */
1575 equalop:
1576         EQUAL_T {$$=EQUAL_OP; }
1577         | DIFF  {$$=DIFF_OP; }
1578         ;
1579 cmpop:
1580           GT    {$$=GT_OP; }
1581         | LT    {$$=LT_OP; }
1582         | GTE   {$$=GTE_OP; }
1583         | LTE   {$$=LTE_OP; }
1584         ;
1585 strop:
1586         equalop {$$=$1; }
1587         | MATCH {$$=MATCH_OP; }
1588         ;
1589
1590
1591 /* rve expr. operators */
1592 rve_equalop:
1593         EQUAL_T {$$=RVE_EQ_OP; }
1594         | DIFF  {$$=RVE_DIFF_OP; }
1595         ;
1596 rve_cmpop:
1597           GT    {$$=RVE_GT_OP; }
1598         | LT    {$$=RVE_LT_OP; }
1599         | GTE   {$$=RVE_GTE_OP; }
1600         | LTE   {$$=RVE_LTE_OP; }
1601         ;
1602
1603
1604
1605 /* boolean expression uri operands */
1606 uri_type:
1607         URI             {$$=URI_O;}
1608         | FROM_URI      {$$=FROM_URI_O;}
1609         | TO_URI        {$$=TO_URI_O;}
1610         ;
1611
1612
1613 /* boolean expression integer operands, available only in the
1614   onsend route */
1615 eint_op_onsend:
1616                         SNDPORT         { $$=SNDPORT_O; }
1617                 |       TOPORT          { $$=TOPORT_O; }
1618                 |       SNDPROTO        { $$=SNDPROTO_O; }
1619                 |       SNDAF           { $$=SNDAF_O; }
1620                 ;
1621
1622 /* boolean expression integer operands */
1623 eint_op:        SRCPORT         { $$=SRCPORT_O; }
1624                 |       DSTPORT         { $$=DSTPORT_O; }
1625                 |       PROTO           { $$=PROTO_O; }
1626                 |       AF                      { $$=AF_O; }
1627                 |       MSGLEN          { $$=MSGLEN_O; }
1628                 |       RETCODE         { $$=RETCODE_O; }
1629                 | eint_op_onsend
1630         ;
1631
1632 /* boolean expression ip/ipnet operands */
1633 eip_op_onsend:
1634                         SNDIP           { onsend_check("snd_ip"); $$=SNDIP_O; }
1635                 |       TOIP            { onsend_check("to_ip");  $$=TOIP_O; }
1636                 ;
1637
1638 eip_op:         SRCIP           { $$=SRCIP_O; }
1639                 |       DSTIP           { $$=DSTIP_O; }
1640                 | eip_op_onsend
1641                 ;
1642
1643
1644
1645 exp_elem:
1646         METHOD strop %prec EQUAL_T rval_expr
1647                 {$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
1648         | METHOD strop %prec EQUAL_T ID
1649                 {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
1650         | METHOD strop error { $$=0; yyerror("string expected"); }
1651         | METHOD error  
1652                 { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
1653         | uri_type strop %prec EQUAL_T rval_expr
1654                 {$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
1655         | uri_type strop %prec EQUAL_T MYSELF
1656                 {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1657         | uri_type strop %prec EQUAL_T error
1658                 { $$=0; yyerror("string or MYSELF expected"); }
1659         | uri_type error
1660                 { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
1661         | eint_op cmpop %prec GT rval_expr { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1662         | eint_op equalop %prec EQUAL_T rval_expr 
1663                 { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1664         | eint_op cmpop error   { $$=0; yyerror("number expected"); }
1665         | eint_op equalop error { $$=0; yyerror("number expected"); }
1666         | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1667         | eip_op strop %prec EQUAL_T ipnet { $$=mk_elem($2, $1, 0, NET_ST, $3); }
1668         | eip_op strop %prec EQUAL_T rval_expr {
1669                         s_tmp.s=0;
1670                         $$=0;
1671                         if (rve_is_constant($3)){
1672                                 i_tmp=rve_guess_type($3);
1673                                 if (i_tmp==RV_INT)
1674                                         yyerror("string expected");
1675                                 else if (i_tmp==RV_STR){
1676                                         if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
1677                                                                 (rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
1678                                                 rval_destroy(rval_tmp);
1679                                                 yyerror("bad rvalue expression");
1680                                         }else{
1681                                                 rval_destroy(rval_tmp);
1682                                         }
1683                                 }else{
1684                                         yyerror("BUG: unexpected dynamic type");
1685                                 }
1686                         }else{
1687                                         warn("non constant rvalue in ip comparison");
1688                         }
1689                         if (s_tmp.s){
1690                                 ip_tmp=str2ip(&s_tmp);
1691                         #ifdef USE_IPV6
1692                                 if (ip_tmp==0)
1693                                         ip_tmp=str2ip6(&s_tmp);
1694                         #endif
1695                                 pkg_free(s_tmp.s);
1696                                 if (ip_tmp) {
1697                                         $$=mk_elem($2, $1, 0, NET_ST, 
1698                                                                 mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1699                                 } else {
1700                                         $$=mk_elem($2, $1, 0, RVE_ST, $3);
1701                                 }
1702                         }else{
1703                                 $$=mk_elem($2, $1, 0, RVE_ST, $3);
1704                         }
1705                 }
1706         | eip_op strop %prec EQUAL_T host
1707                 { $$=mk_elem($2, $1, 0, STRING_ST, $3); }
1708         | eip_op strop %prec EQUAL_T MYSELF
1709                 { $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1710         | eip_op strop %prec EQUAL_T error
1711                 { $$=0; yyerror( "ip address or hostname expected" ); }
1712         | eip_op error
1713                 { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
1714         
1715         | MYSELF equalop %prec EQUAL_T uri_type
1716                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1717         | MYSELF equalop %prec EQUAL_T eip_op
1718                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1719         | MYSELF equalop %prec EQUAL_T error
1720                 { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
1721         | MYSELF error  { $$=0; yyerror ("invalid operator, == or != expected"); }
1722         ;
1723 /*
1724 exp_elem2:
1725         rval_expr cmpop %prec GT rval_expr
1726                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1727         |
1728         rval_expr equalop %prec EQUAL_T rval_expr
1729                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1730         | rval_expr LOG_AND rval_expr
1731                 { $$=mk_exp_rve(LOGAND_OP, $1, $3);}
1732         | rval_expr LOG_OR rval_expr
1733                 { $$=mk_exp_rve(LOGOR_OP, $1, $3);}
1734 ;
1735 */
1736
1737 ipnet:
1738         ip SLASH ip     { $$=mk_net($1, $3); }
1739         | ip SLASH NUMBER {
1740                 if (($3<0) || ($3>$1->len*8)) {
1741                         yyerror("invalid bit number in netmask");
1742                         $$=0;
1743                 } else {
1744                         $$=mk_net_bitlen($1, $3);
1745                 /*
1746                         $$=mk_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
1747                 */
1748                 }
1749         }
1750         | ip    { $$=mk_net_bitlen($1, $1->len*8); }
1751         | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
1752         ;
1753
1754 host:
1755         ID { $$=$1; }
1756         | host DOT ID {
1757                 $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1758                 if ($$==0) {
1759                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1760                 } else {
1761                         memcpy($$, $1, strlen($1));
1762                         $$[strlen($1)]='.';
1763                         memcpy($$+strlen($1)+1, $3, strlen($3));
1764                         $$[strlen($1)+1+strlen($3)]=0;
1765                 }
1766                 pkg_free($1);
1767                 pkg_free($3);
1768         }
1769         | host MINUS ID {
1770                 $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1771                 if ($$==0) {
1772                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1773                 } else {
1774                         memcpy($$, $1, strlen($1));
1775                         $$[strlen($1)]='-';
1776                         memcpy($$+strlen($1)+1, $3, strlen($3));
1777                         $$[strlen($1)+1+strlen($3)]=0;
1778                 }
1779                 pkg_free($1);
1780                 pkg_free($3);
1781         }
1782         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
1783         ;
1784 /* filtered cmd */
1785 fcmd:
1786         cmd {
1787                 /* check if allowed */
1788                 if ($1 && rt==ONSEND_ROUTE) {
1789                         switch($1->type) {
1790                                 case DROP_T:
1791                                 case SEND_T:
1792                                 case SEND_TCP_T:
1793                                 case LOG_T:
1794                                 case SETFLAG_T:
1795                                 case RESETFLAG_T:
1796                                 case ISFLAGSET_T:
1797                                 case IF_T:
1798                                 case MODULE_T:
1799                                         $$=$1;
1800                                         break;
1801                                 default:
1802                                         $$=0;
1803                                         yyerror("command not allowed in onsend_route\n");
1804                         }
1805                 } else {
1806                         $$=$1;
1807                 }
1808         }
1809         ;
1810 /*
1811 exp_stm:
1812         fcmd    { $$=$1; }
1813         | if_cmd        { $$=$1; }
1814         | assign_action { $$ = $1; }
1815         | LBRACE actions RBRACE { $$=$2; }
1816         ;
1817 */
1818 stm:
1819         action  { $$=$1; }
1820         | LBRACE actions RBRACE { $$=$2; }
1821         ;
1822 actions:
1823         actions action  {$$=append_action($1, $2); }
1824         | action        {$$=$1;}
1825         | actions error { $$=0; yyerror("bad command"); }
1826         ;
1827 action:
1828         fcmd SEMICOLON {$$=$1;}
1829         | if_cmd {$$=$1;}
1830         | switch_cmd {$$=$1;}
1831         | while_cmd { $$=$1; }
1832         | assign_action SEMICOLON {$$=$1;}
1833         | SEMICOLON /* null action */ {$$=0;}
1834         | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
1835         ;
1836 if_cmd:
1837         IF exp stm              { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0); }
1838         | IF exp stm ELSE stm   { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5); }
1839         ;
1840
1841 ct_rval: rval_expr {
1842                         $$=0;
1843                         if (!rve_is_constant($1)){
1844                                 yyerror("constant expected");
1845                         /*
1846                         } else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1847                                 yyerror("invalid expression (bad type)");
1848                         }else if (i_tmp!=RV_INT){
1849                                 yyerror("invalid expression type, int expected\n");
1850                         */
1851                         }else
1852                                 $$=$1;
1853                 }
1854 ;
1855 single_case:
1856         CASE ct_rval COLON actions {
1857                 $$=0;
1858                 if ($2==0) yyerror ("bad case label");
1859                 else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
1860                                 YYABORT;
1861                 }
1862         }
1863 | CASE SLASH ct_rval COLON actions {
1864                 $$=0;
1865                 if ($3==0) yyerror ("bad case label");
1866                 else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
1867                                 YYABORT;
1868                 }
1869         }
1870         | CASE ct_rval COLON {
1871                 $$=0;
1872                 if ($2==0) yyerror ("bad case label");
1873                 else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
1874                                 YYABORT;
1875                 }
1876         }
1877         | CASE SLASH ct_rval COLON {
1878                 $$=0;
1879                 if ($3==0) yyerror ("bad case label");
1880                 else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
1881                                 YYABORT;
1882                 }
1883         }
1884         | DEFAULT COLON actions {
1885                 if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp=-10)){
1886                                 YYABORT;
1887                 }
1888         }
1889         | DEFAULT COLON {
1890                 if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
1891                                 YYABORT;
1892                 }
1893         }
1894         | CASE error { $$=0; yyerror("bad case label"); }
1895         | CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
1896 ;
1897 case_stms:
1898         case_stms single_case {
1899                 $$=$1;
1900                 if ($2==0) yyerror ("bad case");
1901                 if ($$){
1902                         *($$->append)=$2;
1903                         if (*($$->append)!=0)
1904                                 $$->append=&((*($$->append))->next);
1905                 }
1906         }
1907         | single_case {
1908                 $$=$1;
1909                 if ($1==0) yyerror ("bad case");
1910                 else $$->append=&($$->next);
1911         }
1912 ;
1913 switch_cmd:
1914           SWITCH rval_expr LBRACE case_stms RBRACE { 
1915                 $$=0;
1916                 if ($2==0) yyerror("bad expression in switch(...)");
1917                 else if ($4==0) yyerror ("bad switch body");
1918                 else if (case_check_default($4)!=0)
1919                         yyerror_at(&$2->fpos, "bad switch(): too many "
1920                                                         "\"default:\" labels\n");
1921                 else if (case_check_type($4)!=0)
1922                         yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
1923                                                         " string/RE cases not allowed\n");
1924                 else{
1925                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
1926                         if ($$==0) {
1927                                 yyerror("internal error");
1928                                 YYABORT;
1929                         }
1930                 }
1931         }
1932         | SWITCH rval_expr LBRACE RBRACE {
1933                 $$=0;
1934                 warn("empty switch()");
1935                 if ($2==0) yyerror("bad expression in switch(...)");
1936                 else{
1937                         /* it might have sideffects, so leave it for the optimizer */
1938                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
1939                         if ($$==0) {
1940                                 yyerror("internal error");
1941                                 YYABORT;
1942                         }
1943                 }
1944         }
1945         | SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
1946         | SWITCH rval_expr LBRACE error RBRACE 
1947                 {$$=0; yyerror ("bad switch body"); }
1948 ;
1949
1950 while_cmd:
1951         WHILE rval_expr stm {
1952                 if ($2){
1953                         if (rve_is_constant($2))
1954                                 warn_at(&$2->fpos, "constant value in while(...)");
1955                 }else
1956                         yyerror_at(&$2->fpos, "bad while(...) expression");
1957                 $$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
1958         }
1959 ;
1960
1961 /* class_id:
1962         LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
1963         | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
1964         | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
1965         ;
1966 */
1967 select_param:
1968         ID {
1969                 if (sel.n >= MAX_SELECT_PARAMS-1) {
1970                         yyerror("Select identifier too long\n");
1971                 }
1972                 sel.params[sel.n].type = SEL_PARAM_STR;
1973                 sel.params[sel.n].v.s.s = $1;
1974                 sel.params[sel.n].v.s.len = strlen($1);
1975                 sel.n++;
1976         }
1977         | ID LBRACK NUMBER RBRACK {
1978                 if (sel.n >= MAX_SELECT_PARAMS-2) {
1979                         yyerror("Select identifier too long\n");
1980                 }
1981                 sel.params[sel.n].type = SEL_PARAM_STR;
1982                 sel.params[sel.n].v.s.s = $1;
1983                 sel.params[sel.n].v.s.len = strlen($1);
1984                 sel.n++;
1985                 sel.params[sel.n].type = SEL_PARAM_INT;
1986                 sel.params[sel.n].v.i = $3;
1987                 sel.n++;
1988         }
1989         | ID LBRACK STRING RBRACK {
1990                 if (sel.n >= MAX_SELECT_PARAMS-2) {
1991                         yyerror("Select identifier too long\n");
1992                 }
1993                 sel.params[sel.n].type = SEL_PARAM_STR;
1994                 sel.params[sel.n].v.s.s = $1;
1995                 sel.params[sel.n].v.s.len = strlen($1);
1996                 sel.n++;
1997                 sel.params[sel.n].type = SEL_PARAM_STR;
1998                 sel.params[sel.n].v.s.s = $3;
1999                 sel.params[sel.n].v.s.len = strlen($3);
2000                 sel.n++;
2001         }
2002         ;
2003 select_params:
2004         select_params DOT select_param
2005         | select_param
2006         ;
2007 select_id:
2008         SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
2009                 sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
2010                 if (!sel_ptr) {
2011                         yyerror("No memory left to allocate select structure\n");
2012                 }
2013                 memcpy(sel_ptr, &sel, sizeof(select_t));
2014                 $$ = sel_ptr;
2015         }
2016         ;
2017 attr_class_spec:
2018         ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
2019         | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
2020         | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
2021         | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
2022         | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
2023         | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
2024         | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
2025         | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
2026         | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
2027         ;
2028 attr_name_spec:
2029         ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
2030         ;
2031 attr_spec:
2032         attr_name_spec
2033         | attr_class_spec DOT attr_name_spec
2034         ;
2035 attr_mark:
2036         ATTR_MARK {
2037                 s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2038                 if (!s_attr) { yyerror("No memory left"); }
2039                 s_attr->type = 0;
2040         }
2041         ;
2042 attr_id:
2043         attr_mark attr_spec { $$ = s_attr; }
2044         ;
2045 attr_id_num_idx:
2046         attr_mark attr_spec LBRACK intno RBRACK {
2047                 s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
2048                 s_attr->index = ($4<0?-$4:$4);
2049                 $$ = s_attr;
2050         }
2051         ;
2052 attr_id_no_idx:
2053         attr_mark attr_spec LBRACK RBRACK {
2054                 s_attr->type|= AVP_INDEX_ALL;
2055                 $$ = s_attr;
2056         }
2057         ;
2058 attr_id_ass:
2059         attr_id
2060         | attr_id_no_idx
2061         ;
2062 /*
2063 attr_id_val:
2064         attr_id
2065         | attr_id_num_idx
2066         ;
2067 */
2068 attr_id_any:
2069         attr_id
2070         | attr_id_no_idx
2071         | attr_id_num_idx
2072 ;
2073 attr_id_any_str:
2074         attr_id
2075         | STRING {
2076                 avp_spec_t *avp_spec;
2077                 str s;
2078                 int type, idx;
2079                 avp_spec = pkg_malloc(sizeof(*avp_spec));
2080                 if (!avp_spec) {
2081                         yyerror("Not enough memory");
2082                         YYABORT;
2083                 }
2084                 s.s = $1;
2085                 if (s.s[0] == '$')
2086                         s.s++;
2087                 s.len = strlen(s.s);
2088                 if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
2089                         yyerror("error when parsing AVP");
2090                         pkg_free(avp_spec);
2091                         YYABORT;
2092                 }
2093                 avp_spec->type = type;
2094                 avp_spec->index = idx;
2095                 $$ = avp_spec;
2096         }
2097         ;
2098
2099 pvar:   PVAR {
2100                         pv_spec=pkg_malloc(sizeof(*pv_spec));
2101                         if (!pv_spec) {
2102                                 yyerror("Not enough memory");
2103                                 YYABORT;
2104                         }
2105                         memset(pv_spec, 0, sizeof(*pv_spec));
2106                         s_tmp.s=$1; s_tmp.len=strlen($1);
2107                         if (pv_parse_spec(&s_tmp, pv_spec)==0){
2108                                 yyerror("unknown script pseudo variable");
2109                                 pkg_free(pv_spec);
2110                                 pv_spec=0;
2111                                 YYABORT;
2112                         }
2113                         $$=pv_spec;
2114                 }
2115         ;
2116
2117 avp_pvar:       AVP_OR_PVAR {
2118                                 lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2119                                 if (!lval_tmp) {
2120                                         yyerror("Not enough memory");
2121                                         YYABORT;
2122                                 }
2123                                 memset(lval_tmp, 0, sizeof(*lval_tmp));
2124                                 s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
2125                                 if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
2126                                         /* not a pvar, try avps */
2127                                         lval_tmp->lv.avps.type|= AVP_NAME_STR;
2128                                         lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
2129                                         lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
2130                                         lval_tmp->type=LV_AVP;
2131                                 }else{
2132                                         lval_tmp->type=LV_PVAR;
2133                                 }
2134                                 $$ = lval_tmp;
2135                                 DBG("parsed ambigous avp/pvar \"%.*s\" to %d\n",
2136                                                         s_tmp.len, s_tmp.s, lval_tmp->type);
2137                         }
2138         ;
2139
2140
2141 /*
2142 assign_op:
2143         ADDEQ { $$ = ADD_T; }
2144         | EQUAL { $$ = ASSIGN_T; }
2145         ;
2146 */
2147 assign_op:
2148         EQUAL { $$ = ASSIGN_T; }
2149         ;
2150
2151
2152 lval: attr_id_ass {
2153                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2154                                         if (!lval_tmp) {
2155                                                 yyerror("Not enough memory");
2156                                                 YYABORT;
2157                                         }
2158                                         lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
2159                                         pkg_free($1); /* free the avp spec we just copied */
2160                                         $$=lval_tmp;
2161                                 }
2162         | pvar        {
2163                                         if (!pv_is_w($1))
2164                                                 yyerror("read only pvar in assignment left side");
2165                                         if ($1->trans!=0)
2166                                                 yyerror("pvar with transformations in assignment"
2167                                                                 " left side");
2168                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2169                                         if (!lval_tmp) {
2170                                                 yyerror("Not enough memory");
2171                                                 YYABORT;
2172                                         }
2173                                         lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=*($1);
2174                                         pkg_free($1); /* free the pvar spec we just copied */
2175                                         $$=lval_tmp;
2176                                 }
2177         | avp_pvar    {
2178                                         if (($1)->type==LV_PVAR){
2179                                                 if (!pv_is_w(&($1)->lv.pvs))
2180                                                         yyerror("read only pvar in assignment left side");
2181                                                 if ($1->lv.pvs.trans!=0)
2182                                                         yyerror("pvar with transformations in assignment"
2183                                                                         " left side");
2184                                         }
2185                                         $$=$1;
2186                                 }
2187         ;
2188
2189 rval: intno                     {$$=mk_rve_rval(RV_INT, (void*)$1); }
2190         | STRING                        {       s_tmp.s=$1; s_tmp.len=strlen($1);
2191                                                         $$=mk_rve_rval(RV_STR, &s_tmp); }
2192         | attr_id_any           {$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
2193         | pvar                          {$$=mk_rve_rval(RV_PVAR, $1); pkg_free($1); }
2194         | avp_pvar                      {
2195                                                         switch($1->type){
2196                                                                 case LV_AVP:
2197                                                                         $$=mk_rve_rval(RV_AVP, &$1->lv.avps);
2198                                                                         break;
2199                                                                 case LV_PVAR:
2200                                                                         $$=mk_rve_rval(RV_PVAR, &$1->lv.pvs);
2201                                                                         break;
2202                                                                 default:
2203                                                                         yyerror("BUG: invalid lvalue type ");
2204                                                                         YYABORT;
2205                                                         }
2206                                                         pkg_free($1); /* not needed anymore */
2207                                                 }
2208         | select_id                     {$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
2209         | fcmd                          {$$=mk_rve_rval(RV_ACTION_ST, $1); }
2210         | exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
2211         | LBRACE actions RBRACE {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2212         | LBRACE error RBRACE   { yyerror("bad command block"); }
2213         | LPAREN assign_action RPAREN   {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2214         | LPAREN error RPAREN   { yyerror("bad expression"); }
2215         ;
2216
2217
2218 rve_un_op: NOT  { $$=RVE_LNOT_OP; }
2219                 |  MINUS %prec NOT      { $$=RVE_UMINUS_OP; } 
2220                 /* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
2221         ;
2222
2223 /*
2224 rve_op:         PLUS            { $$=RVE_PLUS_OP; }
2225                 |       MINUS           { $$=RVE_MINUS_OP; }
2226                 |       STAR            { $$=RVE_MUL_OP; }
2227                 |       SLASH           { $$=RVE_DIV_OP; }
2228         ;
2229 */
2230
2231 rval_expr: rval                                         { $$=$1;
2232                                                                                         if ($$==0){
2233                                                                                                 yyerror("out of memory\n");
2234                                                                                                 YYABORT;
2235                                                                                         }
2236                                                                         }
2237                 | rve_un_op %prec NOT rval_expr {$$=mk_rve1($1, $2); }
2238                 | rval_expr PLUS rval_expr              {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
2239                 | rval_expr MINUS rval_expr             {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
2240                 | rval_expr STAR rval_expr              {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
2241                 | rval_expr SLASH rval_expr             {$$=mk_rve2(RVE_DIV_OP, $1, $3); }
2242                 | rval_expr BIN_OR rval_expr    {$$=mk_rve2(RVE_BOR_OP, $1,  $3); }
2243                 | rval_expr BIN_AND rval_expr   {$$=mk_rve2(RVE_BAND_OP, $1,  $3);}
2244                 | rval_expr rve_cmpop %prec GT rval_expr { $$=mk_rve2( $2, $1, $3);}
2245                 | rval_expr rve_equalop %prec EQUAL_T rval_expr
2246                         { $$=mk_rve2( $2, $1, $3);}
2247                 | rval_expr LOG_AND rval_expr   { $$=mk_rve2(RVE_LAND_OP, $1, $3);}
2248                 | rval_expr LOG_OR rval_expr    { $$=mk_rve2(RVE_LOR_OP, $1, $3);}
2249                 | LPAREN rval_expr RPAREN               { $$=$2;}
2250                 | rve_un_op %prec NOT error             { yyerror("bad expression"); }
2251                 | rval_expr PLUS error                  { yyerror("bad expression"); }
2252                 | rval_expr MINUS error                 { yyerror("bad expression"); }
2253                 | rval_expr STAR error                  { yyerror("bad expression"); }
2254                 | rval_expr SLASH error                 { yyerror("bad expression"); }
2255                 | rval_expr BIN_OR error                { yyerror("bad expression"); }
2256                 | rval_expr BIN_AND error               { yyerror("bad expression"); }
2257                 | rval_expr rve_cmpop %prec GT error
2258                         { yyerror("bad expression"); }
2259                 | rval_expr rve_equalop %prec EQUAL_T error
2260                         { yyerror("bad expression"); }
2261                 | rval_expr LOG_AND error               { yyerror("bad expression"); }
2262                 | rval_expr LOG_OR error                { yyerror("bad expression"); }
2263                 ;
2264
2265 assign_action: lval assign_op  rval_expr        { $$=mk_action($2, 2, LVAL_ST, $1, 
2266                                                                                                                           RVE_ST, $3);
2267                                                                                 }
2268         ;
2269
2270 /*
2271 assign_action:
2272         attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
2273         | attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
2274         | attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
2275         | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
2276         | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
2277         | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
2278         ;
2279 */
2280
2281 avpflag_oper:
2282         SETAVPFLAG { $$ = 1; }
2283         | RESETAVPFLAG { $$ = 0; }
2284         | ISAVPFLAGSET { $$ = -1; }
2285         ;
2286 cmd:
2287         FORWARD LPAREN host RPAREN      { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2288         | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2289         | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2290         | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2291         | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2292         | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2293         | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2294         | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2295         | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2296         | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
2297         | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
2298         | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2299         | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2300         | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2301         | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2302         | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2303         | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2304         | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2305         | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2306         | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2307         | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
2308         | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
2309         | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2310         | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2311         | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2312         | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2313         | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2314         | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2315         | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2316         | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2317         | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2318         | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2319         | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
2320         | FORWARD_TLS LPAREN host RPAREN {
2321                 #ifdef USE_TLS
2322                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2323                 #else
2324                         $$=0;
2325                         yyerror("tls support not compiled in");
2326                 #endif
2327         }
2328         | FORWARD_TLS LPAREN STRING RPAREN {
2329                 #ifdef USE_TLS
2330                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2331                 #else
2332                         $$=0;
2333                         yyerror("tls support not compiled in");
2334                 #endif
2335         }
2336         | FORWARD_TLS LPAREN ip RPAREN  {
2337                 #ifdef USE_TLS
2338                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0);
2339                 #else
2340                         $$=0;
2341                         yyerror("tls support not compiled in");
2342                 #endif
2343         }
2344         | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
2345                 #ifdef USE_TLS
2346                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
2347                 #else
2348                         $$=0;
2349                         yyerror("tls support not compiled in");
2350                 #endif
2351         }
2352         | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
2353                 #ifdef USE_TLS
2354                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
2355                 #else
2356                         $$=0;
2357                         yyerror("tls support not compiled in");
2358                 #endif
2359         }
2360         | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
2361                 #ifdef USE_TLS
2362                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5);
2363                 #else
2364                         $$=0;
2365                         yyerror("tls support not compiled in");
2366                 #endif
2367                                         }
2368         | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
2369                 #ifdef USE_TLS
2370                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0);
2371                 #else
2372                         $$=0;
2373                         yyerror("tls support not compiled in");
2374                 #endif
2375         }
2376         | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
2377                 #ifdef USE_TLS
2378                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5);
2379                 #else
2380                         $$=0;
2381                         yyerror("tls support not compiled in");
2382                 #endif
2383         }
2384         | FORWARD_TLS LPAREN URIHOST RPAREN {
2385                 #ifdef USE_TLS
2386                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0);
2387                 #else
2388                         $$=0;
2389                         yyerror("tls support not compiled in");
2390                 #endif
2391         }
2392         | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
2393         | FORWARD_TLS LPAREN error RPAREN { $$=0; 
2394                                                                         yyerror("bad forward_tls argument"); }
2395         | FORWARD_SCTP LPAREN host RPAREN {
2396                 #ifdef USE_SCTP
2397                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2398                 #else
2399                         $$=0;
2400                         yyerror("sctp support not compiled in");
2401                 #endif
2402         }
2403         | FORWARD_SCTP LPAREN STRING RPAREN {
2404                 #ifdef USE_SCTP
2405                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2406                 #else
2407                         $$=0;
2408                         yyerror("sctp support not compiled in");
2409                 #endif
2410         }
2411         | FORWARD_SCTP LPAREN ip RPAREN {
2412                 #ifdef USE_SCTP
2413                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0);
2414                 #else
2415                         $$=0;
2416                         yyerror("sctp support not compiled in");
2417                 #endif
2418         }
2419         | FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
2420                 #ifdef USE_SCTP
2421                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2422                                                         (void*)$5);
2423                 #else
2424                         $$=0;
2425                         yyerror("sctp support not compiled in");
2426                 #endif
2427         }
2428         | FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
2429                 #ifdef USE_SCTP
2430                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2431                                                         (void*)$5);
2432                 #else
2433                         $$=0;
2434                         yyerror("sctp support not compiled in");
2435                 #endif
2436         }
2437         | FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
2438                 #ifdef USE_SCTP
2439                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 
2440                                                         (void*)$5);
2441                 #else
2442                         $$=0;
2443                         yyerror("sctp support not compiled in");
2444                 #endif
2445                                         }
2446         | FORWARD_SCTP LPAREN URIHOST COMMA URIPORT RPAREN {
2447                 #ifdef USE_SCTP
2448                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0);
2449                 #else
2450                         $$=0;
2451                         yyerror("sctp support not compiled in");
2452                 #endif
2453         }
2454         | FORWARD_SCTP LPAREN URIHOST COMMA NUMBER RPAREN {
2455                 #ifdef USE_SCTP
2456                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST,
2457                                                         (void*)$5);
2458                 #else
2459                         $$=0;
2460                         yyerror("sctp support not compiled in");
2461                 #endif
2462         }
2463         | FORWARD_SCTP LPAREN URIHOST RPAREN {
2464                 #ifdef USE_SCTP
2465                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0);
2466                 #else
2467                         $$=0;
2468                         yyerror("tls support not compiled in");
2469                 #endif
2470         }
2471         | FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
2472         | FORWARD_SCTP LPAREN error RPAREN { $$=0; 
2473                                                                         yyerror("bad forward_tls argument"); }
2474         | SEND LPAREN host RPAREN       { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2475         | SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2476         | SEND LPAREN ip RPAREN         { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2477         | SEND LPAREN host COMMA NUMBER RPAREN  { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2478         | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2479         | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2480         | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
2481         | SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
2482         | SEND_TCP LPAREN host RPAREN   { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2483         | SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2484         | SEND_TCP LPAREN ip RPAREN     { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2485         | SEND_TCP LPAREN host COMMA NUMBER RPAREN      { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);}
2486         | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2487         | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2488         | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2489         | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
2490         | DROP LPAREN RPAREN            {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2491         | DROP LPAREN NUMBER RPAREN     {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$3, NUMBER_ST, (void*)EXIT_R_F); }
2492         | DROP NUMBER                   {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)EXIT_R_F); }
2493         | DROP RETCODE                  {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2494         | DROP                          {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2495         | RETURN                        {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST, (void*)RETURN_R_F); }
2496         | RETURN NUMBER                 {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)RETURN_R_F);}
2497         | RETURN RETCODE                {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)RETURN_R_F);}
2498         | BREAK                         {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F); }
2499         | LOG_TOK LPAREN STRING RPAREN  {$$=mk_action(LOG_T, 2, NUMBER_ST,
2500                                                                                 (void*)(L_DBG+1), STRING_ST, $3); }
2501         | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN     {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); }
2502         | LOG_TOK error                 { $$=0; yyerror("missing '(' or ')' ?"); }
2503         | LOG_TOK LPAREN error RPAREN   { $$=0; yyerror("bad log argument"); }
2504         | SETFLAG LPAREN NUMBER RPAREN  {
2505                                                         if (check_flag($3)==-1)
2506                                                                 yyerror("bad flag value");
2507                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
2508                                                                                                         (void*)$3);
2509                                                                         }
2510         | SETFLAG LPAREN flag_name RPAREN       {
2511                                                         i_tmp=get_flag_no($3, strlen($3));
2512                                                         if (i_tmp<0) yyerror("flag not declared");
2513                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
2514                                                                                 (void*)(long)i_tmp);
2515                                                                         }
2516         | SETFLAG error                 { $$=0; yyerror("missing '(' or ')'?"); }
2517         | RESETFLAG LPAREN NUMBER RPAREN {
2518                                                         if (check_flag($3)==-1)
2519                                                                 yyerror("bad flag value");
2520                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
2521                                                                         }
2522         | RESETFLAG LPAREN flag_name RPAREN     {
2523                                                         i_tmp=get_flag_no($3, strlen($3));
2524                                                         if (i_tmp<0) yyerror("flag not declared");
2525                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
2526                                                                                 (void*)(long)i_tmp);
2527                                                                         }
2528         | RESETFLAG error               { $$=0; yyerror("missing '(' or ')'?"); }
2529         | ISFLAGSET LPAREN NUMBER RPAREN {
2530                                                         if (check_flag($3)==-1)
2531                                                                 yyerror("bad flag value");
2532                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
2533                                                                         }
2534         | ISFLAGSET LPAREN flag_name RPAREN     {
2535                                                         i_tmp=get_flag_no($3, strlen($3));
2536                                                         if (i_tmp<0) yyerror("flag not declared");
2537                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
2538                                                                                 (void*)(long)i_tmp);
2539                                                                         }
2540         | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
2541         | avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
2542                 i_tmp=get_avpflag_no($5);
2543                 if (i_tmp==0) yyerror("avpflag not declared");
2544                 $$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
2545         }
2546         | avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
2547         | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5); }
2548         | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
2549         | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
2550         | ROUTE LPAREN route_name RPAREN        {
2551                                                 i_tmp=route_get(&main_rt, $3);
2552                                                 if (i_tmp==-1){
2553                                                         yyerror("internal error");
2554                                                         YYABORT;
2555                                                 }
2556                                                 $$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp);
2557                                                                                 }
2558         | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
2559         | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
2560         | EXEC LPAREN STRING RPAREN     { $$=mk_action(EXEC_T, 1, STRING_ST, $3); }
2561         | SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, 1, STRING_ST, $3); }
2562         | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
2563         | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2564         | PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, 1, STRING_ST,  $3); }
2565         | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
2566         | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2567         | STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 1, NUMBER_ST, (void*)$3); }
2568         | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
2569         | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2570         | STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, 1, NUMBER_ST, (void*) $3); }
2571         | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
2572         | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2573         | SET_USERPHONE LPAREN RPAREN { $$=mk_action(SET_USERPHONE_T, 0); }
2574         | SET_USERPHONE error { $$=0; yyerror("missing '(' or ')' ?"); }
2575         | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN {
2576                 qvalue_t q;
2577                 if (str2q(&q, $5, strlen($5)) < 0) {
2578                         yyerror("bad argument, q value expected");
2579                 }
2580                 $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)(long)q);
2581         }
2582         | APPEND_BRANCH LPAREN STRING RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2583         | APPEND_BRANCH LPAREN RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, 0, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2584         | APPEND_BRANCH {  $$=mk_action( APPEND_BRANCH_T, 1, STRING_ST, 0); }
2585         | SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); }
2586         | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2587         | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2588         | SET_HOSTPORTTRANS LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORTTRANS_T, 1, STRING_ST, $3); }
2589         | SET_HOSTPORTTRANS error { $$=0; yyerror("missing '(' or ')' ?"); }
2590         | SET_HOSTPORTTRANS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2591         | SET_PORT LPAREN STRING RPAREN { $$=mk_action(SET_PORT_T, 1, STRING_ST, $3); }
2592         | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2593         | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2594         | SET_USER LPAREN STRING RPAREN { $$=mk_action(SET_USER_T, 1, STRING_ST, $3); }
2595         | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
2596         | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2597         | SET_USERPASS LPAREN STRING RPAREN { $$=mk_action(SET_USERPASS_T, 1, STRING_ST, $3); }
2598         | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
2599         | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2600         | SET_URI LPAREN STRING RPAREN { $$=mk_action(SET_URI_T, 1, STRING_ST,$3); }
2601         | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
2602         | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2603         | REVERT_URI LPAREN RPAREN { $$=mk_action(REVERT_URI_T, 0); }
2604         | REVERT_URI { $$=mk_action(REVERT_URI_T, 0); }
2605         | FORCE_RPORT LPAREN RPAREN     { $$=mk_action(FORCE_RPORT_T, 0); }
2606         | FORCE_RPORT   {$$=mk_action(FORCE_RPORT_T, 0); }
2607         | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN  {
2608                 #ifdef USE_TCP
2609                         $$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
2610                 #else
2611                         yyerror("tcp support not compiled in");
2612                 #endif
2613         }
2614         | FORCE_TCP_ALIAS LPAREN RPAREN {
2615                 #ifdef USE_TCP
2616                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2617                 #else
2618                         yyerror("tcp support not compiled in");
2619                 #endif
2620         }
2621         | FORCE_TCP_ALIAS                               {
2622                 #ifdef USE_TCP
2623                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2624                 #else
2625                         yyerror("tcp support not compiled in");
2626                 #endif
2627         }
2628         | FORCE_TCP_ALIAS LPAREN error RPAREN   {$$=0; yyerror("bad argument, number expected"); }
2629         | UDP_MTU_TRY_PROTO LPAREN proto RPAREN
2630                 { $$=mk_action(UDP_MTU_TRY_PROTO_T, 1, NUMBER_ST, $3); }
2631         | UDP_MTU_TRY_PROTO LPAREN error RPAREN
2632                 { $$=0; yyerror("bad argument, UDP, TCP, TLS or SCTP expected"); }
2633         | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
2634                 $$=0;
2635                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2636                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2637                 } else {
2638                         str_tmp->s=$3;
2639                         str_tmp->len=strlen($3);
2640                         $$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
2641                 }
2642         }
2643         | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2644         | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
2645         | SET_ADV_PORT LPAREN NUMBER RPAREN {
2646                 $$=0;
2647                 tmp=int2str($3, &i_tmp);
2648                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2649                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2650                 } else {
2651                         if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
2652                                 LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2653                         } else {
2654                                 memcpy(str_tmp->s, tmp, i_tmp);
2655                                 str_tmp->len=i_tmp;
2656                                 $$=mk_action(SET_ADV_PORT_T, 1, STR_ST, str_tmp);
2657                         }
2658                 }
2659         }
2660         | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2661         | SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
2662         | FORCE_SEND_SOCKET LPAREN phostport RPAREN { 
2663                 $$=mk_action(FORCE_SEND_SOCKET_T, 1, SOCKID_ST, $3);
2664         }
2665         | FORCE_SEND_SOCKET LPAREN error RPAREN {
2666                 $$=0; yyerror("bad argument, [proto:]host[:port] expected");
2667         }
2668         | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
2669         | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST,
2670                         0); } LPAREN func_params RPAREN {
2671                 mod_func_action->val[0].u.data = 
2672                         find_export_record($1, mod_func_action->val[1].u.number, rt,
2673                                                                 &u_tmp);
2674                 if (mod_func_action->val[0].u.data == 0) {
2675                         if (find_export_record($1, mod_func_action->val[1].u.number, 0,
2676                                                                         &u_tmp) ) {
2677                                         yyerror("Command cannot be used in the block\n");
2678                         } else {
2679                                 yyerror("unknown command, missing loadmodule?\n");
2680                         }
2681                         pkg_free(mod_func_action);
2682                         mod_func_action=0;
2683                 }else{
2684                         switch( ((union cmd_export_u*)
2685                                                 mod_func_action->val[0].u.data)->c.param_no){
2686                                 case 0:
2687                                 case 1:
2688                                 case 2:
2689                                         /* MODULE_T used for 0-2 params */
2690                                         break;
2691                                 case 3:
2692                                         mod_func_action->type=MODULE3_T;
2693                                         break;
2694                                 case 4:
2695                                         mod_func_action->type=MODULE4_T;
2696                                         break;
2697                                 case 5:
2698                                         mod_func_action->type=MODULE5_T;
2699                                         break;
2700                                 case 6:
2701                                         mod_func_action->type=MODULE6_T;
2702                                         break;
2703                                 case VAR_PARAM_NO:
2704                                         mod_func_action->type=MODULEX_T;
2705                                         break;
2706                                 default:
2707                                         yyerror("too many parameters for function\n");
2708                                         break;
2709                         }
2710                 }
2711                 $$ = mod_func_action;
2712         }
2713         | ID error                                      { yyerror("'('')' expected (function call)");}
2714         ;
2715 func_params:
2716         /* empty */
2717         | func_params COMMA func_param { }
2718         | func_param {}
2719         | func_params error { yyerror("call params error\n"); }
2720         ;
2721 func_param:
2722         NUMBER {
2723                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2724                         mod_func_action->val[mod_func_action->val[1].u.number+2].type =
2725                                 NUMBER_ST;
2726                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.number =
2727                                 $1;
2728                         mod_func_action->val[1].u.number++;
2729                 } else {
2730                         yyerror("Too many arguments\n");
2731                 }
2732         }
2733         | STRING {
2734                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2735                         mod_func_action->val[mod_func_action->val[1].u.number+2].type = STRING_ST;
2736                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.string = $1;
2737                         mod_func_action->val[1].u.number++;
2738                 } else {
2739                         yyerror("Too many arguments\n");
2740                 }
2741         }
2742         ;
2743 %%
2744
2745 extern int line;
2746 extern int column;
2747 extern int startcolumn;
2748 extern int startline;
2749
2750
2751 static void get_cpos(struct cfg_pos* pos)
2752 {
2753         pos->s_line=startline;
2754         pos->e_line=line;
2755         pos->s_col=startcolumn;
2756         pos->e_col=column-1;
2757 }
2758
2759
2760 static void warn_at(struct cfg_pos* p, char* format, ...)
2761 {
2762         va_list ap;
2763         char s[256];
2764         
2765         va_start(ap, format);
2766         vsnprintf(s, sizeof(s), format, ap);
2767         va_end(ap);
2768         if (p->e_line!=p->s_line)
2769                 LOG(L_WARN, "cfg. warning: (%d,%d-%d,%d): %s\n",
2770                                         p->s_line, p->s_col, p->e_line, p->e_col, s);
2771         else if (p->s_col!=p->e_col)
2772                 LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n",
2773                                         p->s_line, p->s_col, p->e_col, s);
2774         else
2775                 LOG(L_WARN, "cfg. warning: (%d,%d): %s\n",
2776                                 p->s_line, p->s_col, s);
2777         cfg_warnings++;
2778 }
2779
2780
2781
2782 static void yyerror_at(struct cfg_pos* p, char* format, ...)
2783 {
2784         va_list ap;
2785         char s[256];
2786         
2787         va_start(ap, format);
2788         vsnprintf(s, sizeof(s), format, ap);
2789         va_end(ap);
2790         if (p->e_line!=p->s_line)
2791                 LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d-%d,%d): %s\n", 
2792                                         p->s_line, p->s_col, p->e_line, p->e_col, s);
2793         else if (p->s_col!=p->e_col)
2794                 LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d-%d): %s\n", 
2795                                         p->s_line, p->s_col, p->e_col, s);
2796         else
2797                 LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d): %s\n", 
2798                                         p->s_line, p->s_col, s);
2799         cfg_errors++;
2800 }
2801
2802
2803
2804 static void warn(char* format, ...)
2805 {
2806         va_list ap;
2807         char s[256];
2808         struct cfg_pos pos;
2809         
2810         get_cpos(&pos);
2811         va_start(ap, format);
2812         vsnprintf(s, sizeof(s), format, ap);
2813         va_end(ap);
2814         warn_at(&pos, s);
2815 }
2816
2817
2818
2819 static void yyerror(char* format, ...)
2820 {
2821         va_list ap;
2822         char s[256];
2823         struct cfg_pos pos;
2824         
2825         get_cpos(&pos);
2826         va_start(ap, format);
2827         vsnprintf(s, sizeof(s), format, ap);
2828         va_end(ap);
2829         yyerror_at(&pos, s);
2830 }
2831
2832
2833
2834 /** mk_rval_expr_v wrapper.
2835  *  checks mk_rval_expr_v return value and sets the cfg. pos
2836  *  (line and column numbers)
2837  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr_v)
2838  */
2839 static struct rval_expr* mk_rve_rval(enum rval_type type, void* v)
2840 {
2841         struct rval_expr* ret;
2842         struct cfg_pos pos;
2843
2844         get_cpos(&pos);
2845         ret=mk_rval_expr_v(type, v, &pos);
2846         if (ret==0){
2847                 yyerror("internal error: failed to create rval expr");
2848                 /* YYABORT; */
2849         }
2850         return ret;
2851 }
2852
2853
2854 /** mk_rval_expr1 wrapper.
2855  *  checks mk_rval_expr1 return value (!=0 and type checking)
2856  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr1)
2857  */
2858 static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1)
2859 {
2860         struct rval_expr* ret;
2861         struct rval_expr* bad_rve;
2862         enum rval_type type, bad_t, exp_t;
2863         
2864         if (rve1==0)
2865                 return 0;
2866         ret=mk_rval_expr1(op, rve1, &rve1->fpos);
2867         if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
2868                 yyerror_at(&rve1->fpos, "bad expression: type mismatch"
2869                                         " (%s instead of %s)", rval_type_name(bad_t),
2870                                         rval_type_name(exp_t));
2871         }
2872         return ret;
2873 }
2874
2875
2876 /** mk_rval_expr2 wrapper.
2877  *  checks mk_rval_expr2 return value (!=0 and type checking)
2878  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr2)
2879  */
2880 static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
2881                                                                         struct rval_expr* rve2)
2882 {
2883         struct rval_expr* ret;
2884         struct rval_expr* bad_rve;
2885         enum rval_type type, bad_t, exp_t;
2886         struct cfg_pos pos;
2887         
2888         if ((rve1==0) || (rve2==0))
2889                 return 0;
2890         cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
2891         ret=mk_rval_expr2(op, rve1, rve2, &pos);
2892         if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
2893                 yyerror_at(&pos, "bad expression: type mismatch:"
2894                                                 " %s instead of %s at (%d,%d)",
2895                                                 rval_type_name(bad_t), rval_type_name(exp_t),
2896                                                 bad_rve->fpos.s_line, bad_rve->fpos.s_col);
2897         }
2898         return ret;
2899 }
2900
2901
2902 static struct name_lst* mk_name_lst(char* host, int flags)
2903 {
2904         struct name_lst* l;
2905         l=pkg_malloc(sizeof(struct name_lst));
2906         if (l==0) {
2907                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2908         } else {
2909                 l->name=host;
2910                 l->flags=flags;
2911                 l->next=0;
2912         }
2913         return l;
2914 }
2915
2916
2917 static struct socket_id* mk_listen_id(char* host, int proto, int port)
2918 {
2919         struct socket_id* l;
2920         l=pkg_malloc(sizeof(struct socket_id));
2921         if (l==0) {
2922                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2923         } else {
2924                 l->addr_lst=mk_name_lst(host, 0);
2925                 if (l->addr_lst==0){
2926                         pkg_free(l);
2927                         return 0;
2928                 }
2929                 l->flags=0;
2930                 l->port=port;
2931                 l->proto=proto;
2932                 l->next=0;
2933         }
2934         return l;
2935 }
2936
2937
2938 static void free_name_lst(struct name_lst* lst)
2939 {
2940         struct name_lst* tmp;
2941         
2942         while(lst){
2943                 tmp=lst;
2944                 lst=lst->next;
2945                 pkg_free(tmp);
2946         }
2947 }
2948
2949
2950 static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
2951                                                                                 int port)
2952 {
2953         struct socket_id* l;
2954         l=pkg_malloc(sizeof(struct socket_id));
2955         if (l==0) {
2956                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2957         } else {
2958                 l->flags=addr_l->flags;
2959                 l->port=port;
2960                 l->proto=proto;
2961                 l->addr_lst=addr_l;
2962                 l->next=0;
2963         }
2964         return l;
2965 }
2966
2967
2968 static void free_socket_id(struct socket_id* i)
2969 {
2970         free_name_lst(i->addr_lst);
2971         pkg_free(i);
2972 }
2973
2974
2975 static void free_socket_id_lst(struct socket_id* lst)
2976 {
2977         struct socket_id* tmp;
2978         
2979         while(lst){
2980                 tmp=lst;
2981                 lst=lst->next;
2982                 free_socket_id(tmp);
2983         }
2984 }
2985
2986
2987 /** create a temporary case statmenet structure.
2988  *  *err will be filled in case of error (return == 0):
2989  *   -1 - non constant expression
2990  *   -2 - expression error (bad type)
2991  *   -10 - memory allocation error
2992  */
2993 static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re,
2994                                                                                         struct action* a, int* err)
2995 {
2996         struct case_stms* s;
2997         struct rval_expr* bad_rve;
2998         enum rval_type type, bad_t, exp_t;
2999         enum match_str_type t;
3000         
3001         t=MATCH_UNKNOWN;
3002         if (ct){
3003                 /* if ct!=0 => case, else if ct==0 is a default */
3004                 if (!rve_is_constant(ct)){
3005                         yyerror_at(&ct->fpos, "non constant expression in case");
3006                         *err=-1;
3007                         return 0;
3008                 }
3009                 if (rve_check_type(&type, ct, &bad_rve, &bad_t, &exp_t)!=1){
3010                         yyerror_at(&ct->fpos, "bad expression: type mismatch:"
3011                                                         " %s instead of %s at (%d,%d)",
3012                                                         rval_type_name(bad_t), rval_type_name(exp_t),
3013                                                         bad_rve->fpos.s_line, bad_rve->fpos.s_col);
3014                         *err=-2;
3015                         return 0;
3016                 }
3017                 if (is_re)
3018                         t=MATCH_RE;
3019                 else if (type==RV_STR)
3020                         t=MATCH_STR;
3021                 else
3022                         t=MATCH_INT;
3023         }
3024
3025         s=pkg_malloc(sizeof(*s));
3026         if (s==0) {
3027                 yyerror("internal error: memory allocation failure");
3028                 *err=-10;
3029         } else {
3030                 memset(s, 0, sizeof(*s));
3031                 s->ct_rve=ct;
3032                 s->type=t;
3033                 s->actions=a;
3034                 s->next=0;
3035                 s->append=0;
3036         }
3037         return s;
3038 }
3039
3040
3041 /*
3042  * @return 0 on success, -1 on error.
3043  */
3044 static int case_check_type(struct case_stms* stms)
3045 {
3046         struct case_stms* c;
3047         struct case_stms* s;
3048         
3049         for(c=stms; c ; c=c->next){
3050                 if (!c->ct_rve) continue;
3051                 for (s=c->next; s; s=s->next){
3052                         if (!s->ct_rve) continue;
3053                         if ((s->type!=c->type) &&
3054                                 !(      (c->type==MATCH_STR || c->type==MATCH_RE) &&
3055                                         (s->type==MATCH_STR || s->type==MATCH_RE) ) ){
3056                                         yyerror_at(&s->ct_rve->fpos, "type mismatch in case");
3057                                         return -1;
3058                         }
3059                 }
3060         }
3061         return 0;
3062 }
3063
3064
3065 /*
3066  * @return 0 on success, -1 on error.
3067  */
3068 static int case_check_default(struct case_stms* stms)
3069 {
3070         struct case_stms* c;
3071         int default_no;
3072         
3073         default_no=0;
3074         for(c=stms; c ; c=c->next)
3075                 if (c->ct_rve==0) default_no++;
3076         return (default_no<=1)?0:-1;
3077 }
3078
3079
3080
3081 /*
3082 int main(int argc, char ** argv)
3083 {
3084         if (yyparse()!=0)
3085                 fprintf(stderr, "parsing error\n");
3086 }
3087 */