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