f7032383107f7faf293e643bfa9c144260e7d13b
[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 ($1==0){
1569                                 yyerror("invalid expression");
1570                                 $$=0;
1571                         }else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1572                                 yyerror("invalid expression");
1573                                 $$=0;
1574                         }else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
1575                                 yyerror("invalid expression type, int expected\n");
1576                                 $$=0;
1577                         }else
1578                                 $$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
1579                 }
1580         ;
1581
1582 /* exp elem operators */
1583 equalop:
1584         EQUAL_T {$$=EQUAL_OP; }
1585         | DIFF  {$$=DIFF_OP; }
1586         | STREQ {$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
1587         | STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
1588         ;
1589 cmpop:
1590           GT    {$$=GT_OP; }
1591         | LT    {$$=LT_OP; }
1592         | GTE   {$$=GTE_OP; }
1593         | LTE   {$$=LTE_OP; }
1594         ;
1595 strop:
1596         equalop {$$=$1; }
1597         | MATCH {$$=MATCH_OP; }
1598         ;
1599
1600
1601 /* rve expr. operators */
1602 rve_equalop:
1603         EQUAL_T {$$=RVE_EQ_OP; }
1604         | DIFF  {$$=RVE_DIFF_OP; }
1605         | INTEQ {$$=RVE_IEQ_OP; }
1606         | INTDIFF {$$=RVE_IDIFF_OP; }
1607         | STREQ {$$=RVE_STREQ_OP; }
1608         | STRDIFF {$$=RVE_STRDIFF_OP; }
1609         ;
1610 rve_cmpop:
1611           GT    {$$=RVE_GT_OP; }
1612         | LT    {$$=RVE_LT_OP; }
1613         | GTE   {$$=RVE_GTE_OP; }
1614         | LTE   {$$=RVE_LTE_OP; }
1615         ;
1616
1617
1618
1619 /* boolean expression uri operands */
1620 uri_type:
1621         URI             {$$=URI_O;}
1622         | FROM_URI      {$$=FROM_URI_O;}
1623         | TO_URI        {$$=TO_URI_O;}
1624         ;
1625
1626
1627 /* boolean expression integer operands, available only in the
1628   onsend route */
1629 eint_op_onsend:
1630                         SNDPORT         { $$=SNDPORT_O; }
1631                 |       TOPORT          { $$=TOPORT_O; }
1632                 |       SNDPROTO        { $$=SNDPROTO_O; }
1633                 |       SNDAF           { $$=SNDAF_O; }
1634                 ;
1635
1636 /* boolean expression integer operands */
1637 eint_op:        SRCPORT         { $$=SRCPORT_O; }
1638                 |       DSTPORT         { $$=DSTPORT_O; }
1639                 |       PROTO           { $$=PROTO_O; }
1640                 |       AF                      { $$=AF_O; }
1641                 |       MSGLEN          { $$=MSGLEN_O; }
1642                 |       RETCODE         { $$=RETCODE_O; }
1643                 | eint_op_onsend
1644         ;
1645
1646 /* boolean expression ip/ipnet operands */
1647 eip_op_onsend:
1648                         SNDIP           { onsend_check("snd_ip"); $$=SNDIP_O; }
1649                 |       TOIP            { onsend_check("to_ip");  $$=TOIP_O; }
1650                 ;
1651
1652 eip_op:         SRCIP           { $$=SRCIP_O; }
1653                 |       DSTIP           { $$=DSTIP_O; }
1654                 | eip_op_onsend
1655                 ;
1656
1657
1658
1659 exp_elem:
1660         METHOD strop %prec EQUAL_T rval_expr
1661                 {$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
1662         | METHOD strop %prec EQUAL_T ID
1663                 {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
1664         | METHOD strop error { $$=0; yyerror("string expected"); }
1665         | METHOD error  
1666                 { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
1667         | uri_type strop %prec EQUAL_T rval_expr
1668                 {$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
1669         | uri_type strop %prec EQUAL_T MYSELF
1670                 {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1671         | uri_type strop %prec EQUAL_T error
1672                 { $$=0; yyerror("string or MYSELF expected"); }
1673         | uri_type error
1674                 { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
1675         | eint_op cmpop %prec GT rval_expr { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1676         | eint_op equalop %prec EQUAL_T rval_expr 
1677                 { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
1678         | eint_op cmpop error   { $$=0; yyerror("number expected"); }
1679         | eint_op equalop error { $$=0; yyerror("number expected"); }
1680         | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1681         | eip_op strop %prec EQUAL_T ipnet { $$=mk_elem($2, $1, 0, NET_ST, $3); }
1682         | eip_op strop %prec EQUAL_T rval_expr {
1683                         s_tmp.s=0;
1684                         $$=0;
1685                         if (rve_is_constant($3)){
1686                                 i_tmp=rve_guess_type($3);
1687                                 if (i_tmp==RV_INT)
1688                                         yyerror("string expected");
1689                                 else if (i_tmp==RV_STR){
1690                                         if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
1691                                                                 (rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
1692                                                 rval_destroy(rval_tmp);
1693                                                 yyerror("bad rvalue expression");
1694                                         }else{
1695                                                 rval_destroy(rval_tmp);
1696                                         }
1697                                 }else{
1698                                         yyerror("BUG: unexpected dynamic type");
1699                                 }
1700                         }else{
1701                                         warn("non constant rvalue in ip comparison");
1702                         }
1703                         if (s_tmp.s){
1704                                 ip_tmp=str2ip(&s_tmp);
1705                         #ifdef USE_IPV6
1706                                 if (ip_tmp==0)
1707                                         ip_tmp=str2ip6(&s_tmp);
1708                         #endif
1709                                 pkg_free(s_tmp.s);
1710                                 if (ip_tmp) {
1711                                         $$=mk_elem($2, $1, 0, NET_ST, 
1712                                                                 mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1713                                 } else {
1714                                         $$=mk_elem($2, $1, 0, RVE_ST, $3);
1715                                 }
1716                         }else{
1717                                 $$=mk_elem($2, $1, 0, RVE_ST, $3);
1718                         }
1719                 }
1720         | eip_op strop %prec EQUAL_T host
1721                 { $$=mk_elem($2, $1, 0, STRING_ST, $3); }
1722         | eip_op strop %prec EQUAL_T MYSELF
1723                 { $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
1724         | eip_op strop %prec EQUAL_T error
1725                 { $$=0; yyerror( "ip address or hostname expected" ); }
1726         | eip_op error
1727                 { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
1728         
1729         | MYSELF equalop %prec EQUAL_T uri_type
1730                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1731         | MYSELF equalop %prec EQUAL_T eip_op
1732                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
1733         | MYSELF equalop %prec EQUAL_T error
1734                 { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
1735         | MYSELF error  { $$=0; yyerror ("invalid operator, == or != expected"); }
1736         ;
1737 /*
1738 exp_elem2:
1739         rval_expr cmpop %prec GT rval_expr
1740                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1741         |
1742         rval_expr equalop %prec EQUAL_T rval_expr
1743                 { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
1744         | rval_expr LOG_AND rval_expr
1745                 { $$=mk_exp_rve(LOGAND_OP, $1, $3);}
1746         | rval_expr LOG_OR rval_expr
1747                 { $$=mk_exp_rve(LOGOR_OP, $1, $3);}
1748 ;
1749 */
1750
1751 ipnet:
1752         ip SLASH ip     { $$=mk_net($1, $3); }
1753         | ip SLASH NUMBER {
1754                 if (($3<0) || ($3>$1->len*8)) {
1755                         yyerror("invalid bit number in netmask");
1756                         $$=0;
1757                 } else {
1758                         $$=mk_net_bitlen($1, $3);
1759                 /*
1760                         $$=mk_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
1761                 */
1762                 }
1763         }
1764         | ip    { $$=mk_net_bitlen($1, $1->len*8); }
1765         | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
1766         ;
1767
1768 host:
1769         ID { $$=$1; }
1770         | host DOT ID {
1771                 $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1772                 if ($$==0) {
1773                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1774                 } else {
1775                         memcpy($$, $1, strlen($1));
1776                         $$[strlen($1)]='.';
1777                         memcpy($$+strlen($1)+1, $3, strlen($3));
1778                         $$[strlen($1)+1+strlen($3)]=0;
1779                 }
1780                 pkg_free($1);
1781                 pkg_free($3);
1782         }
1783         | host MINUS ID {
1784                 $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1785                 if ($$==0) {
1786                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation failure while parsing host\n");
1787                 } else {
1788                         memcpy($$, $1, strlen($1));
1789                         $$[strlen($1)]='-';
1790                         memcpy($$+strlen($1)+1, $3, strlen($3));
1791                         $$[strlen($1)+1+strlen($3)]=0;
1792                 }
1793                 pkg_free($1);
1794                 pkg_free($3);
1795         }
1796         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
1797         ;
1798 /* filtered cmd */
1799 fcmd:
1800         cmd {
1801                 /* check if allowed */
1802                 if ($1 && rt==ONSEND_ROUTE) {
1803                         switch($1->type) {
1804                                 case DROP_T:
1805                                 case SEND_T:
1806                                 case SEND_TCP_T:
1807                                 case LOG_T:
1808                                 case SETFLAG_T:
1809                                 case RESETFLAG_T:
1810                                 case ISFLAGSET_T:
1811                                 case IF_T:
1812                                 case MODULE_T:
1813                                         $$=$1;
1814                                         break;
1815                                 default:
1816                                         $$=0;
1817                                         yyerror("command not allowed in onsend_route\n");
1818                         }
1819                 } else {
1820                         $$=$1;
1821                 }
1822         }
1823         ;
1824 /*
1825 exp_stm:
1826         fcmd    { $$=$1; }
1827         | if_cmd        { $$=$1; }
1828         | assign_action { $$ = $1; }
1829         | LBRACE actions RBRACE { $$=$2; }
1830         ;
1831 */
1832 stm:
1833         action  { $$=$1; }
1834         | LBRACE actions RBRACE { $$=$2; }
1835         ;
1836 actions:
1837         actions action  {$$=append_action($1, $2); }
1838         | action        {$$=$1;}
1839         | actions error { $$=0; yyerror("bad command"); }
1840         ;
1841 action:
1842         fcmd SEMICOLON {$$=$1;}
1843         | if_cmd {$$=$1;}
1844         | switch_cmd {$$=$1;}
1845         | while_cmd { $$=$1; }
1846         | assign_action SEMICOLON {$$=$1;}
1847         | SEMICOLON /* null action */ {$$=0;}
1848         | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
1849         ;
1850 if_cmd:
1851         IF exp stm              { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0); }
1852         | IF exp stm ELSE stm   { $$=mk_action( IF_T, 3, EXPR_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5); }
1853         ;
1854
1855 ct_rval: rval_expr {
1856                         $$=0;
1857                         if (!rve_is_constant($1)){
1858                                 yyerror("constant expected");
1859                         /*
1860                         } else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1861                                 yyerror("invalid expression (bad type)");
1862                         }else if (i_tmp!=RV_INT){
1863                                 yyerror("invalid expression type, int expected\n");
1864                         */
1865                         }else
1866                                 $$=$1;
1867                 }
1868 ;
1869 single_case:
1870         CASE ct_rval COLON actions {
1871                 $$=0;
1872                 if ($2==0) yyerror ("bad case label");
1873                 else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
1874                                 YYABORT;
1875                 }
1876         }
1877 | CASE SLASH ct_rval COLON actions {
1878                 $$=0;
1879                 if ($3==0) yyerror ("bad case label");
1880                 else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
1881                                 YYABORT;
1882                 }
1883         }
1884         | CASE ct_rval COLON {
1885                 $$=0;
1886                 if ($2==0) yyerror ("bad case label");
1887                 else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
1888                                 YYABORT;
1889                 }
1890         }
1891         | CASE SLASH ct_rval COLON {
1892                 $$=0;
1893                 if ($3==0) yyerror ("bad case label");
1894                 else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
1895                                 YYABORT;
1896                 }
1897         }
1898         | DEFAULT COLON actions {
1899                 if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp=-10)){
1900                                 YYABORT;
1901                 }
1902         }
1903         | DEFAULT COLON {
1904                 if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
1905                                 YYABORT;
1906                 }
1907         }
1908         | CASE error { $$=0; yyerror("bad case label"); }
1909         | CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
1910 ;
1911 case_stms:
1912         case_stms single_case {
1913                 $$=$1;
1914                 if ($2==0) yyerror ("bad case");
1915                 if ($$){
1916                         *($$->append)=$2;
1917                         if (*($$->append)!=0)
1918                                 $$->append=&((*($$->append))->next);
1919                 }
1920         }
1921         | single_case {
1922                 $$=$1;
1923                 if ($1==0) yyerror ("bad case");
1924                 else $$->append=&($$->next);
1925         }
1926 ;
1927 switch_cmd:
1928           SWITCH rval_expr LBRACE case_stms RBRACE { 
1929                 $$=0;
1930                 if ($2==0) yyerror("bad expression in switch(...)");
1931                 else if ($4==0) yyerror ("bad switch body");
1932                 else if (case_check_default($4)!=0)
1933                         yyerror_at(&$2->fpos, "bad switch(): too many "
1934                                                         "\"default:\" labels\n");
1935                 else if (case_check_type($4)!=0)
1936                         yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
1937                                                         " string/RE cases not allowed\n");
1938                 else{
1939                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
1940                         if ($$==0) {
1941                                 yyerror("internal error");
1942                                 YYABORT;
1943                         }
1944                 }
1945         }
1946         | SWITCH rval_expr LBRACE RBRACE {
1947                 $$=0;
1948                 warn("empty switch()");
1949                 if ($2==0) yyerror("bad expression in switch(...)");
1950                 else{
1951                         /* it might have sideffects, so leave it for the optimizer */
1952                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
1953                         if ($$==0) {
1954                                 yyerror("internal error");
1955                                 YYABORT;
1956                         }
1957                 }
1958         }
1959         | SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
1960         | SWITCH rval_expr LBRACE error RBRACE 
1961                 {$$=0; yyerror ("bad switch body"); }
1962 ;
1963
1964 while_cmd:
1965         WHILE rval_expr stm {
1966                 if ($2){
1967                         if (rve_is_constant($2))
1968                                 warn_at(&$2->fpos, "constant value in while(...)");
1969                 }else
1970                         yyerror_at(&$2->fpos, "bad while(...) expression");
1971                 $$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
1972         }
1973 ;
1974
1975 /* class_id:
1976         LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
1977         | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
1978         | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
1979         ;
1980 */
1981 select_param:
1982         ID {
1983                 if (sel.n >= MAX_SELECT_PARAMS-1) {
1984                         yyerror("Select identifier too long\n");
1985                 }
1986                 sel.params[sel.n].type = SEL_PARAM_STR;
1987                 sel.params[sel.n].v.s.s = $1;
1988                 sel.params[sel.n].v.s.len = strlen($1);
1989                 sel.n++;
1990         }
1991         | ID LBRACK NUMBER RBRACK {
1992                 if (sel.n >= MAX_SELECT_PARAMS-2) {
1993                         yyerror("Select identifier too long\n");
1994                 }
1995                 sel.params[sel.n].type = SEL_PARAM_STR;
1996                 sel.params[sel.n].v.s.s = $1;
1997                 sel.params[sel.n].v.s.len = strlen($1);
1998                 sel.n++;
1999                 sel.params[sel.n].type = SEL_PARAM_INT;
2000                 sel.params[sel.n].v.i = $3;
2001                 sel.n++;
2002         }
2003         | ID LBRACK STRING RBRACK {
2004                 if (sel.n >= MAX_SELECT_PARAMS-2) {
2005                         yyerror("Select identifier too long\n");
2006                 }
2007                 sel.params[sel.n].type = SEL_PARAM_STR;
2008                 sel.params[sel.n].v.s.s = $1;
2009                 sel.params[sel.n].v.s.len = strlen($1);
2010                 sel.n++;
2011                 sel.params[sel.n].type = SEL_PARAM_STR;
2012                 sel.params[sel.n].v.s.s = $3;
2013                 sel.params[sel.n].v.s.len = strlen($3);
2014                 sel.n++;
2015         }
2016         ;
2017 select_params:
2018         select_params DOT select_param
2019         | select_param
2020         ;
2021 select_id:
2022         SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
2023                 sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
2024                 if (!sel_ptr) {
2025                         yyerror("No memory left to allocate select structure\n");
2026                 }
2027                 memcpy(sel_ptr, &sel, sizeof(select_t));
2028                 $$ = sel_ptr;
2029         }
2030         ;
2031 attr_class_spec:
2032         ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
2033         | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
2034         | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
2035         | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
2036         | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
2037         | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
2038         | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
2039         | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
2040         | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
2041         ;
2042 attr_name_spec:
2043         ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
2044         ;
2045 attr_spec:
2046         attr_name_spec
2047         | attr_class_spec DOT attr_name_spec
2048         ;
2049 attr_mark:
2050         ATTR_MARK {
2051                 s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2052                 if (!s_attr) { yyerror("No memory left"); }
2053                 s_attr->type = 0;
2054         }
2055         ;
2056 attr_id:
2057         attr_mark attr_spec { $$ = s_attr; }
2058         ;
2059 attr_id_num_idx:
2060         attr_mark attr_spec LBRACK intno RBRACK {
2061                 s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
2062                 s_attr->index = ($4<0?-$4:$4);
2063                 $$ = s_attr;
2064         }
2065         ;
2066 attr_id_no_idx:
2067         attr_mark attr_spec LBRACK RBRACK {
2068                 s_attr->type|= AVP_INDEX_ALL;
2069                 $$ = s_attr;
2070         }
2071         ;
2072 attr_id_ass:
2073         attr_id
2074         | attr_id_no_idx
2075         ;
2076 /*
2077 attr_id_val:
2078         attr_id
2079         | attr_id_num_idx
2080         ;
2081 */
2082 attr_id_any:
2083         attr_id
2084         | attr_id_no_idx
2085         | attr_id_num_idx
2086 ;
2087 attr_id_any_str:
2088         attr_id
2089         | STRING {
2090                 avp_spec_t *avp_spec;
2091                 str s;
2092                 int type, idx;
2093                 avp_spec = pkg_malloc(sizeof(*avp_spec));
2094                 if (!avp_spec) {
2095                         yyerror("Not enough memory");
2096                         YYABORT;
2097                 }
2098                 s.s = $1;
2099                 if (s.s[0] == '$')
2100                         s.s++;
2101                 s.len = strlen(s.s);
2102                 if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
2103                         yyerror("error when parsing AVP");
2104                         pkg_free(avp_spec);
2105                         YYABORT;
2106                 }
2107                 avp_spec->type = type;
2108                 avp_spec->index = idx;
2109                 $$ = avp_spec;
2110         }
2111         ;
2112
2113 pvar:   PVAR {
2114                         pv_spec=pkg_malloc(sizeof(*pv_spec));
2115                         if (!pv_spec) {
2116                                 yyerror("Not enough memory");
2117                                 YYABORT;
2118                         }
2119                         memset(pv_spec, 0, sizeof(*pv_spec));
2120                         s_tmp.s=$1; s_tmp.len=strlen($1);
2121                         if (pv_parse_spec(&s_tmp, pv_spec)==0){
2122                                 yyerror("unknown script pseudo variable");
2123                                 pkg_free(pv_spec);
2124                                 pv_spec=0;
2125                                 YYABORT;
2126                         }
2127                         $$=pv_spec;
2128                 }
2129         ;
2130
2131 avp_pvar:       AVP_OR_PVAR {
2132                                 lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2133                                 if (!lval_tmp) {
2134                                         yyerror("Not enough memory");
2135                                         YYABORT;
2136                                 }
2137                                 memset(lval_tmp, 0, sizeof(*lval_tmp));
2138                                 s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
2139                                 if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
2140                                         /* not a pvar, try avps */
2141                                         lval_tmp->lv.avps.type|= AVP_NAME_STR;
2142                                         lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
2143                                         lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
2144                                         lval_tmp->type=LV_AVP;
2145                                 }else{
2146                                         lval_tmp->type=LV_PVAR;
2147                                 }
2148                                 $$ = lval_tmp;
2149                                 DBG("parsed ambigous avp/pvar \"%.*s\" to %d\n",
2150                                                         s_tmp.len, s_tmp.s, lval_tmp->type);
2151                         }
2152         ;
2153
2154
2155 /*
2156 assign_op:
2157         ADDEQ { $$ = ADD_T; }
2158         | EQUAL { $$ = ASSIGN_T; }
2159         ;
2160 */
2161 assign_op:
2162         EQUAL { $$ = ASSIGN_T; }
2163         ;
2164
2165
2166 lval: attr_id_ass {
2167                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2168                                         if (!lval_tmp) {
2169                                                 yyerror("Not enough memory");
2170                                                 YYABORT;
2171                                         }
2172                                         lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
2173                                         pkg_free($1); /* free the avp spec we just copied */
2174                                         $$=lval_tmp;
2175                                 }
2176         | pvar        {
2177                                         if (!pv_is_w($1))
2178                                                 yyerror("read only pvar in assignment left side");
2179                                         if ($1->trans!=0)
2180                                                 yyerror("pvar with transformations in assignment"
2181                                                                 " left side");
2182                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2183                                         if (!lval_tmp) {
2184                                                 yyerror("Not enough memory");
2185                                                 YYABORT;
2186                                         }
2187                                         lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=*($1);
2188                                         pkg_free($1); /* free the pvar spec we just copied */
2189                                         $$=lval_tmp;
2190                                 }
2191         | avp_pvar    {
2192                                         if (($1)->type==LV_PVAR){
2193                                                 if (!pv_is_w(&($1)->lv.pvs))
2194                                                         yyerror("read only pvar in assignment left side");
2195                                                 if ($1->lv.pvs.trans!=0)
2196                                                         yyerror("pvar with transformations in assignment"
2197                                                                         " left side");
2198                                         }
2199                                         $$=$1;
2200                                 }
2201         ;
2202
2203 rval: intno                     {$$=mk_rve_rval(RV_INT, (void*)$1); }
2204         | STRING                        {       s_tmp.s=$1; s_tmp.len=strlen($1);
2205                                                         $$=mk_rve_rval(RV_STR, &s_tmp); }
2206         | attr_id_any           {$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
2207         | pvar                          {$$=mk_rve_rval(RV_PVAR, $1); pkg_free($1); }
2208         | avp_pvar                      {
2209                                                         switch($1->type){
2210                                                                 case LV_AVP:
2211                                                                         $$=mk_rve_rval(RV_AVP, &$1->lv.avps);
2212                                                                         break;
2213                                                                 case LV_PVAR:
2214                                                                         $$=mk_rve_rval(RV_PVAR, &$1->lv.pvs);
2215                                                                         break;
2216                                                                 default:
2217                                                                         yyerror("BUG: invalid lvalue type ");
2218                                                                         YYABORT;
2219                                                         }
2220                                                         pkg_free($1); /* not needed anymore */
2221                                                 }
2222         | select_id                     {$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
2223         | fcmd                          {$$=mk_rve_rval(RV_ACTION_ST, $1); }
2224         | exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
2225         | LBRACE actions RBRACE {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2226         | LBRACE error RBRACE   { $$=0; yyerror("bad command block"); }
2227         | LPAREN assign_action RPAREN   {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2228         | LPAREN error RPAREN   { $$=0; yyerror("bad expression"); }
2229         ;
2230
2231
2232 rve_un_op: NOT  { $$=RVE_LNOT_OP; }
2233                 |  MINUS %prec NOT      { $$=RVE_UMINUS_OP; } 
2234                 /* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
2235         ;
2236
2237 /*
2238 rve_op:         PLUS            { $$=RVE_PLUS_OP; }
2239                 |       MINUS           { $$=RVE_MINUS_OP; }
2240                 |       STAR            { $$=RVE_MUL_OP; }
2241                 |       SLASH           { $$=RVE_DIV_OP; }
2242         ;
2243 */
2244
2245 rval_expr: rval                                         { $$=$1;
2246                                                                                 /*      if ($$==0){
2247                                                                                                 yyerror("out of memory\n");
2248                                                                                                 YYABORT;
2249                                                                                         }
2250                                                                                         */
2251                                                                         }
2252                 | rve_un_op %prec NOT rval_expr {$$=mk_rve1($1, $2); }
2253                 | rval_expr PLUS rval_expr              {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
2254                 | rval_expr MINUS rval_expr             {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
2255                 | rval_expr STAR rval_expr              {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
2256                 | rval_expr SLASH rval_expr             {$$=mk_rve2(RVE_DIV_OP, $1, $3); }
2257                 | rval_expr BIN_OR rval_expr    {$$=mk_rve2(RVE_BOR_OP, $1,  $3); }
2258                 | rval_expr BIN_AND rval_expr   {$$=mk_rve2(RVE_BAND_OP, $1,  $3);}
2259                 | rval_expr rve_cmpop %prec GT rval_expr { $$=mk_rve2( $2, $1, $3);}
2260                 | rval_expr rve_equalop %prec EQUAL_T rval_expr
2261                         { $$=mk_rve2( $2, $1, $3);}
2262                 | rval_expr LOG_AND rval_expr   { $$=mk_rve2(RVE_LAND_OP, $1, $3);}
2263                 | rval_expr LOG_OR rval_expr    { $$=mk_rve2(RVE_LOR_OP, $1, $3);}
2264                 | LPAREN rval_expr RPAREN               { $$=$2;}
2265                 | STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
2266                 | STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
2267                 | DEFINED rval_expr                             { $$=mk_rve1(RVE_DEFINED_OP, $2);}
2268                 | rve_un_op %prec NOT error             { $$=0; yyerror("bad expression"); }
2269                 | rval_expr PLUS error                  { yyerror("bad expression"); }
2270                 | rval_expr MINUS error                 { yyerror("bad expression"); }
2271                 | rval_expr STAR error                  { yyerror("bad expression"); }
2272                 | rval_expr SLASH error                 { yyerror("bad expression"); }
2273                 | rval_expr BIN_OR error                { yyerror("bad expression"); }
2274                 | rval_expr BIN_AND error               { yyerror("bad expression"); }
2275                 | rval_expr rve_cmpop %prec GT error
2276                         { yyerror("bad expression"); }
2277                 | rval_expr rve_equalop %prec EQUAL_T error
2278                         { yyerror("bad expression"); }
2279                 | rval_expr LOG_AND error               { yyerror("bad expression"); }
2280                 | rval_expr LOG_OR error                { yyerror("bad expression"); }
2281                 | STRLEN LPAREN error RPAREN    { $$=0; yyerror("bad expression"); }
2282                 | STREMPTY LPAREN error RPAREN  { $$=0; yyerror("bad expression"); }
2283                 | DEFINED error                                 { $$=0; yyerror("bad expression"); }
2284                 ;
2285
2286 assign_action: lval assign_op  rval_expr        { $$=mk_action($2, 2, LVAL_ST, $1, 
2287                                                                                                                           RVE_ST, $3);
2288                                                                                 }
2289         ;
2290
2291 /*
2292 assign_action:
2293         attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
2294         | attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
2295         | attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
2296         | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
2297         | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
2298         | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
2299         ;
2300 */
2301
2302 avpflag_oper:
2303         SETAVPFLAG { $$ = 1; }
2304         | RESETAVPFLAG { $$ = 0; }
2305         | ISAVPFLAGSET { $$ = -1; }
2306         ;
2307 cmd:
2308         FORWARD LPAREN host RPAREN      { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2309         | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2310         | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2311         | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2312         | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2313         | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2314         | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2315         | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2316         | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2317         | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
2318         | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
2319         | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2320         | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2321         | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2322         | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2323         | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2324         | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2325         | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2326         | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2327         | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2328         | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
2329         | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
2330         | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2331         | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2332         | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2333         | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2334         | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2335         | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2336         | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); }
2337         | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); }
2338         | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); }
2339         | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2340         | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
2341         | FORWARD_TLS LPAREN host RPAREN {
2342                 #ifdef USE_TLS
2343                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2344                 #else
2345                         $$=0;
2346                         yyerror("tls support not compiled in");
2347                 #endif
2348         }
2349         | FORWARD_TLS LPAREN STRING RPAREN {
2350                 #ifdef USE_TLS
2351                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2352                 #else
2353                         $$=0;
2354                         yyerror("tls support not compiled in");
2355                 #endif
2356         }
2357         | FORWARD_TLS LPAREN ip RPAREN  {
2358                 #ifdef USE_TLS
2359                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0);
2360                 #else
2361                         $$=0;
2362                         yyerror("tls support not compiled in");
2363                 #endif
2364         }
2365         | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
2366                 #ifdef USE_TLS
2367                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
2368                 #else
2369                         $$=0;
2370                         yyerror("tls support not compiled in");
2371                 #endif
2372         }
2373         | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
2374                 #ifdef USE_TLS
2375                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);
2376                 #else
2377                         $$=0;
2378                         yyerror("tls support not compiled in");
2379                 #endif
2380         }
2381         | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
2382                 #ifdef USE_TLS
2383                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5);
2384                 #else
2385                         $$=0;
2386                         yyerror("tls support not compiled in");
2387                 #endif
2388                                         }
2389         | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
2390                 #ifdef USE_TLS
2391                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0);
2392                 #else
2393                         $$=0;
2394                         yyerror("tls support not compiled in");
2395                 #endif
2396         }
2397         | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
2398                 #ifdef USE_TLS
2399                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5);
2400                 #else
2401                         $$=0;
2402                         yyerror("tls support not compiled in");
2403                 #endif
2404         }
2405         | FORWARD_TLS LPAREN URIHOST RPAREN {
2406                 #ifdef USE_TLS
2407                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0);
2408                 #else
2409                         $$=0;
2410                         yyerror("tls support not compiled in");
2411                 #endif
2412         }
2413         | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
2414         | FORWARD_TLS LPAREN error RPAREN { $$=0; 
2415                                                                         yyerror("bad forward_tls argument"); }
2416         | FORWARD_SCTP LPAREN host RPAREN {
2417                 #ifdef USE_SCTP
2418                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2419                 #else
2420                         $$=0;
2421                         yyerror("sctp support not compiled in");
2422                 #endif
2423         }
2424         | FORWARD_SCTP LPAREN STRING RPAREN {
2425                 #ifdef USE_SCTP
2426                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0);
2427                 #else
2428                         $$=0;
2429                         yyerror("sctp support not compiled in");
2430                 #endif
2431         }
2432         | FORWARD_SCTP LPAREN ip RPAREN {
2433                 #ifdef USE_SCTP
2434                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0);
2435                 #else
2436                         $$=0;
2437                         yyerror("sctp support not compiled in");
2438                 #endif
2439         }
2440         | FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
2441                 #ifdef USE_SCTP
2442                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2443                                                         (void*)$5);
2444                 #else
2445                         $$=0;
2446                         yyerror("sctp support not compiled in");
2447                 #endif
2448         }
2449         | FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
2450                 #ifdef USE_SCTP
2451                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
2452                                                         (void*)$5);
2453                 #else
2454                         $$=0;
2455                         yyerror("sctp support not compiled in");
2456                 #endif
2457         }
2458         | FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
2459                 #ifdef USE_SCTP
2460                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 
2461                                                         (void*)$5);
2462                 #else
2463                         $$=0;
2464                         yyerror("sctp support not compiled in");
2465                 #endif
2466                                         }
2467         | FORWARD_SCTP LPAREN URIHOST COMMA URIPORT RPAREN {
2468                 #ifdef USE_SCTP
2469                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0);
2470                 #else
2471                         $$=0;
2472                         yyerror("sctp support not compiled in");
2473                 #endif
2474         }
2475         | FORWARD_SCTP LPAREN URIHOST COMMA NUMBER RPAREN {
2476                 #ifdef USE_SCTP
2477                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST,
2478                                                         (void*)$5);
2479                 #else
2480                         $$=0;
2481                         yyerror("sctp support not compiled in");
2482                 #endif
2483         }
2484         | FORWARD_SCTP LPAREN URIHOST RPAREN {
2485                 #ifdef USE_SCTP
2486                         $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0);
2487                 #else
2488                         $$=0;
2489                         yyerror("tls support not compiled in");
2490                 #endif
2491         }
2492         | FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
2493         | FORWARD_SCTP LPAREN error RPAREN { $$=0; 
2494                                                                         yyerror("bad forward_tls argument"); }
2495         | SEND LPAREN host RPAREN       { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2496         | SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2497         | SEND LPAREN ip RPAREN         { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2498         | SEND LPAREN host COMMA NUMBER RPAREN  { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2499         | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2500         | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2501         | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
2502         | SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
2503         | SEND_TCP LPAREN host RPAREN   { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2504         | SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); }
2505         | SEND_TCP LPAREN ip RPAREN     { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); }
2506         | SEND_TCP LPAREN host COMMA NUMBER RPAREN      { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5);}
2507         | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); }
2508         | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2509         | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2510         | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
2511         | DROP LPAREN RPAREN            {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2512         | DROP LPAREN NUMBER RPAREN     {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$3, NUMBER_ST, (void*)EXIT_R_F); }
2513         | DROP NUMBER                   {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)EXIT_R_F); }
2514         | DROP RETCODE                  {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2515         | DROP                          {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2516         | RETURN                        {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST, (void*)RETURN_R_F); }
2517         | RETURN NUMBER                 {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)RETURN_R_F);}
2518         | RETURN RETCODE                {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)RETURN_R_F);}
2519         | BREAK                         {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F); }
2520         | LOG_TOK LPAREN STRING RPAREN  {$$=mk_action(LOG_T, 2, NUMBER_ST,
2521                                                                                 (void*)(L_DBG+1), STRING_ST, $3); }
2522         | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN     {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); }
2523         | LOG_TOK error                 { $$=0; yyerror("missing '(' or ')' ?"); }
2524         | LOG_TOK LPAREN error RPAREN   { $$=0; yyerror("bad log argument"); }
2525         | SETFLAG LPAREN NUMBER RPAREN  {
2526                                                         if (check_flag($3)==-1)
2527                                                                 yyerror("bad flag value");
2528                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
2529                                                                                                         (void*)$3);
2530                                                                         }
2531         | SETFLAG LPAREN flag_name RPAREN       {
2532                                                         i_tmp=get_flag_no($3, strlen($3));
2533                                                         if (i_tmp<0) yyerror("flag not declared");
2534                                                         $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
2535                                                                                 (void*)(long)i_tmp);
2536                                                                         }
2537         | SETFLAG error                 { $$=0; yyerror("missing '(' or ')'?"); }
2538         | RESETFLAG LPAREN NUMBER RPAREN {
2539                                                         if (check_flag($3)==-1)
2540                                                                 yyerror("bad flag value");
2541                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
2542                                                                         }
2543         | RESETFLAG LPAREN flag_name RPAREN     {
2544                                                         i_tmp=get_flag_no($3, strlen($3));
2545                                                         if (i_tmp<0) yyerror("flag not declared");
2546                                                         $$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
2547                                                                                 (void*)(long)i_tmp);
2548                                                                         }
2549         | RESETFLAG error               { $$=0; yyerror("missing '(' or ')'?"); }
2550         | ISFLAGSET LPAREN NUMBER RPAREN {
2551                                                         if (check_flag($3)==-1)
2552                                                                 yyerror("bad flag value");
2553                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
2554                                                                         }
2555         | ISFLAGSET LPAREN flag_name RPAREN     {
2556                                                         i_tmp=get_flag_no($3, strlen($3));
2557                                                         if (i_tmp<0) yyerror("flag not declared");
2558                                                         $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
2559                                                                                 (void*)(long)i_tmp);
2560                                                                         }
2561         | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
2562         | avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
2563                 i_tmp=get_avpflag_no($5);
2564                 if (i_tmp==0) yyerror("avpflag not declared");
2565                 $$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
2566         }
2567         | avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
2568         | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5); }
2569         | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
2570         | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
2571         | ROUTE LPAREN route_name RPAREN        {
2572                                                 i_tmp=route_get(&main_rt, $3);
2573                                                 if (i_tmp==-1){
2574                                                         yyerror("internal error");
2575                                                         YYABORT;
2576                                                 }
2577                                                 $$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp);
2578                                                                                 }
2579         | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
2580         | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
2581         | EXEC LPAREN STRING RPAREN     { $$=mk_action(EXEC_T, 1, STRING_ST, $3); }
2582         | SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, 1, STRING_ST, $3); }
2583         | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
2584         | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2585         | PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, 1, STRING_ST,  $3); }
2586         | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
2587         | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2588         | STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 1, NUMBER_ST, (void*)$3); }
2589         | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
2590         | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2591         | STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, 1, NUMBER_ST, (void*) $3); }
2592         | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
2593         | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
2594         | SET_USERPHONE LPAREN RPAREN { $$=mk_action(SET_USERPHONE_T, 0); }
2595         | SET_USERPHONE error { $$=0; yyerror("missing '(' or ')' ?"); }
2596         | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN {
2597                 qvalue_t q;
2598                 if (str2q(&q, $5, strlen($5)) < 0) {
2599                         yyerror("bad argument, q value expected");
2600                 }
2601                 $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)(long)q);
2602         }
2603         | APPEND_BRANCH LPAREN STRING RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2604         | APPEND_BRANCH LPAREN RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, 0, NUMBER_ST, (void *)Q_UNSPECIFIED); }
2605         | APPEND_BRANCH {  $$=mk_action( APPEND_BRANCH_T, 1, STRING_ST, 0); }
2606         | SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); }
2607         | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2608         | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2609         | SET_HOSTPORTTRANS LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORTTRANS_T, 1, STRING_ST, $3); }
2610         | SET_HOSTPORTTRANS error { $$=0; yyerror("missing '(' or ')' ?"); }
2611         | SET_HOSTPORTTRANS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2612         | SET_PORT LPAREN STRING RPAREN { $$=mk_action(SET_PORT_T, 1, STRING_ST, $3); }
2613         | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
2614         | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2615         | SET_USER LPAREN STRING RPAREN { $$=mk_action(SET_USER_T, 1, STRING_ST, $3); }
2616         | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
2617         | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2618         | SET_USERPASS LPAREN STRING RPAREN { $$=mk_action(SET_USERPASS_T, 1, STRING_ST, $3); }
2619         | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
2620         | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2621         | SET_URI LPAREN STRING RPAREN { $$=mk_action(SET_URI_T, 1, STRING_ST,$3); }
2622         | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
2623         | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2624         | REVERT_URI LPAREN RPAREN { $$=mk_action(REVERT_URI_T, 0); }
2625         | REVERT_URI { $$=mk_action(REVERT_URI_T, 0); }
2626         | FORCE_RPORT LPAREN RPAREN     { $$=mk_action(FORCE_RPORT_T, 0); }
2627         | FORCE_RPORT   {$$=mk_action(FORCE_RPORT_T, 0); }
2628         | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN  {
2629                 #ifdef USE_TCP
2630                         $$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
2631                 #else
2632                         yyerror("tcp support not compiled in");
2633                 #endif
2634         }
2635         | FORCE_TCP_ALIAS LPAREN RPAREN {
2636                 #ifdef USE_TCP
2637                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2638                 #else
2639                         yyerror("tcp support not compiled in");
2640                 #endif
2641         }
2642         | FORCE_TCP_ALIAS                               {
2643                 #ifdef USE_TCP
2644                         $$=mk_action(FORCE_TCP_ALIAS_T, 0);
2645                 #else
2646                         yyerror("tcp support not compiled in");
2647                 #endif
2648         }
2649         | FORCE_TCP_ALIAS LPAREN error RPAREN   {$$=0; yyerror("bad argument, number expected"); }
2650         | UDP_MTU_TRY_PROTO LPAREN proto RPAREN
2651                 { $$=mk_action(UDP_MTU_TRY_PROTO_T, 1, NUMBER_ST, $3); }
2652         | UDP_MTU_TRY_PROTO LPAREN error RPAREN
2653                 { $$=0; yyerror("bad argument, UDP, TCP, TLS or SCTP expected"); }
2654         | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
2655                 $$=0;
2656                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2657                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2658                 } else {
2659                         str_tmp->s=$3;
2660                         str_tmp->len=strlen($3);
2661                         $$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
2662                 }
2663         }
2664         | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2665         | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
2666         | SET_ADV_PORT LPAREN NUMBER RPAREN {
2667                 $$=0;
2668                 tmp=int2str($3, &i_tmp);
2669                 if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
2670                         LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2671                 } else {
2672                         if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
2673                                 LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
2674                         } else {
2675                                 memcpy(str_tmp->s, tmp, i_tmp);
2676                                 str_tmp->len=i_tmp;
2677                                 $$=mk_action(SET_ADV_PORT_T, 1, STR_ST, str_tmp);
2678                         }
2679                 }
2680         }
2681         | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
2682         | SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
2683         | FORCE_SEND_SOCKET LPAREN phostport RPAREN { 
2684                 $$=mk_action(FORCE_SEND_SOCKET_T, 1, SOCKID_ST, $3);
2685         }
2686         | FORCE_SEND_SOCKET LPAREN error RPAREN {
2687                 $$=0; yyerror("bad argument, [proto:]host[:port] expected");
2688         }
2689         | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
2690         | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST,
2691                         0); } LPAREN func_params RPAREN {
2692                 mod_func_action->val[0].u.data = 
2693                         find_export_record($1, mod_func_action->val[1].u.number, rt,
2694                                                                 &u_tmp);
2695                 if (mod_func_action->val[0].u.data == 0) {
2696                         if (find_export_record($1, mod_func_action->val[1].u.number, 0,
2697                                                                         &u_tmp) ) {
2698                                         yyerror("Command cannot be used in the block\n");
2699                         } else {
2700                                 yyerror("unknown command, missing loadmodule?\n");
2701                         }
2702                         pkg_free(mod_func_action);
2703                         mod_func_action=0;
2704                 }else{
2705                         switch( ((union cmd_export_u*)
2706                                                 mod_func_action->val[0].u.data)->c.param_no){
2707                                 case 0:
2708                                 case 1:
2709                                 case 2:
2710                                         /* MODULE_T used for 0-2 params */
2711                                         break;
2712                                 case 3:
2713                                         mod_func_action->type=MODULE3_T;
2714                                         break;
2715                                 case 4:
2716                                         mod_func_action->type=MODULE4_T;
2717                                         break;
2718                                 case 5:
2719                                         mod_func_action->type=MODULE5_T;
2720                                         break;
2721                                 case 6:
2722                                         mod_func_action->type=MODULE6_T;
2723                                         break;
2724                                 case VAR_PARAM_NO:
2725                                         mod_func_action->type=MODULEX_T;
2726                                         break;
2727                                 default:
2728                                         yyerror("too many parameters for function\n");
2729                                         break;
2730                         }
2731                 }
2732                 $$ = mod_func_action;
2733         }
2734         | ID error                                      { yyerror("'('')' expected (function call)");}
2735         ;
2736 func_params:
2737         /* empty */
2738         | func_params COMMA func_param { }
2739         | func_param {}
2740         | func_params error { yyerror("call params error\n"); }
2741         ;
2742 func_param:
2743         NUMBER {
2744                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2745                         mod_func_action->val[mod_func_action->val[1].u.number+2].type =
2746                                 NUMBER_ST;
2747                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.number =
2748                                 $1;
2749                         mod_func_action->val[1].u.number++;
2750                 } else {
2751                         yyerror("Too many arguments\n");
2752                 }
2753         }
2754         | STRING {
2755                 if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
2756                         mod_func_action->val[mod_func_action->val[1].u.number+2].type = STRING_ST;
2757                         mod_func_action->val[mod_func_action->val[1].u.number+2].u.string = $1;
2758                         mod_func_action->val[1].u.number++;
2759                 } else {
2760                         yyerror("Too many arguments\n");
2761                 }
2762         }
2763         ;
2764 %%
2765
2766 extern int line;
2767 extern int column;
2768 extern int startcolumn;
2769 extern int startline;
2770
2771
2772 static void get_cpos(struct cfg_pos* pos)
2773 {
2774         pos->s_line=startline;
2775         pos->e_line=line;
2776         pos->s_col=startcolumn;
2777         pos->e_col=column-1;
2778 }
2779
2780
2781 static void warn_at(struct cfg_pos* p, char* format, ...)
2782 {
2783         va_list ap;
2784         char s[256];
2785         
2786         va_start(ap, format);
2787         vsnprintf(s, sizeof(s), format, ap);
2788         va_end(ap);
2789         if (p->e_line!=p->s_line)
2790                 LOG(L_WARN, "warning in config file, from line %d, column %d to line %d, column %d: %s\n",
2791                                         p->s_line, p->s_col, p->e_line, p->e_col, s);
2792         else if (p->s_col!=p->e_col)
2793                 LOG(L_WARN, "warning in config file, line %d, column %d-%d: %s\n",
2794                                         p->s_line, p->s_col, p->e_col, s);
2795         else
2796                 LOG(L_WARN, "warning in config file, line %d, column %d: %s\n",
2797                                 p->s_line, p->s_col, s);
2798         cfg_warnings++;
2799 }
2800
2801
2802
2803 static void yyerror_at(struct cfg_pos* p, char* format, ...)
2804 {
2805         va_list ap;
2806         char s[256];
2807         
2808         va_start(ap, format);
2809         vsnprintf(s, sizeof(s), format, ap);
2810         va_end(ap);
2811         if (p->e_line!=p->s_line)
2812                 LOG(L_CRIT, "parse error in config file, from line %d, column %d to line %d, column %d: %s\n",
2813                                         p->s_line, p->s_col, p->e_line, p->e_col, s);
2814         else if (p->s_col!=p->e_col)
2815                 LOG(L_CRIT, "parse error in config file, line %d, column %d-%d: %s\n",
2816                                         p->s_line, p->s_col, p->e_col, s);
2817         else
2818                 LOG(L_CRIT, "parse error in config file, line %d, column %d: %s\n",
2819                                         p->s_line, p->s_col, s);
2820         cfg_errors++;
2821 }
2822
2823
2824
2825 static void warn(char* format, ...)
2826 {
2827         va_list ap;
2828         char s[256];
2829         struct cfg_pos pos;
2830         
2831         get_cpos(&pos);
2832         va_start(ap, format);
2833         vsnprintf(s, sizeof(s), format, ap);
2834         va_end(ap);
2835         warn_at(&pos, s);
2836 }
2837
2838
2839
2840 static void yyerror(char* format, ...)
2841 {
2842         va_list ap;
2843         char s[256];
2844         struct cfg_pos pos;
2845         
2846         get_cpos(&pos);
2847         va_start(ap, format);
2848         vsnprintf(s, sizeof(s), format, ap);
2849         va_end(ap);
2850         yyerror_at(&pos, s);
2851 }
2852
2853
2854
2855 /** mk_rval_expr_v wrapper.
2856  *  checks mk_rval_expr_v return value and sets the cfg. pos
2857  *  (line and column numbers)
2858  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr_v)
2859  */
2860 static struct rval_expr* mk_rve_rval(enum rval_type type, void* v)
2861 {
2862         struct rval_expr* ret;
2863         struct cfg_pos pos;
2864
2865         get_cpos(&pos);
2866         ret=mk_rval_expr_v(type, v, &pos);
2867         if (ret==0){
2868                 yyerror("internal error: failed to create rval expr");
2869                 /* YYABORT; */
2870         }
2871         return ret;
2872 }
2873
2874
2875 /** mk_rval_expr1 wrapper.
2876  *  checks mk_rval_expr1 return value (!=0 and type checking)
2877  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr1)
2878  */
2879 static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1)
2880 {
2881         struct rval_expr* ret;
2882         struct rval_expr* bad_rve;
2883         enum rval_type type, bad_t, exp_t;
2884         
2885         if (rve1==0)
2886                 return 0;
2887         ret=mk_rval_expr1(op, rve1, &rve1->fpos);
2888         if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
2889                 yyerror_at(&rve1->fpos, "bad expression: type mismatch"
2890                                         " (%s instead of %s)", rval_type_name(bad_t),
2891                                         rval_type_name(exp_t));
2892         }
2893         return ret;
2894 }
2895
2896
2897 /** mk_rval_expr2 wrapper.
2898  *  checks mk_rval_expr2 return value (!=0 and type checking)
2899  *  @return rval_expr* on success, 0 on error (@see mk_rval_expr2)
2900  */
2901 static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
2902                                                                         struct rval_expr* rve2)
2903 {
2904         struct rval_expr* ret;
2905         struct rval_expr* bad_rve;
2906         enum rval_type type, bad_t, exp_t;
2907         struct cfg_pos pos;
2908         
2909         if ((rve1==0) || (rve2==0))
2910                 return 0;
2911         bad_rve=0;
2912         bad_t=0;
2913         exp_t=0;
2914         cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
2915         ret=mk_rval_expr2(op, rve1, rve2, &pos);
2916         if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
2917                 if (bad_rve)
2918                         yyerror_at(&pos, "bad expression: type mismatch:"
2919                                                 " %s instead of %s at (%d,%d)",
2920                                                 rval_type_name(bad_t), rval_type_name(exp_t),
2921                                                 bad_rve->fpos.s_line, bad_rve->fpos.s_col);
2922                 else
2923                         yyerror("BUG: unexpected null \"bad\" expression\n");
2924         }
2925         return ret;
2926 }
2927
2928
2929 static struct name_lst* mk_name_lst(char* host, int flags)
2930 {
2931         struct name_lst* l;
2932         l=pkg_malloc(sizeof(struct name_lst));
2933         if (l==0) {
2934                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2935         } else {
2936                 l->name=host;
2937                 l->flags=flags;
2938                 l->next=0;
2939         }
2940         return l;
2941 }
2942
2943
2944 static struct socket_id* mk_listen_id(char* host, int proto, int port)
2945 {
2946         struct socket_id* l;
2947         l=pkg_malloc(sizeof(struct socket_id));
2948         if (l==0) {
2949                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2950         } else {
2951                 l->addr_lst=mk_name_lst(host, 0);
2952                 if (l->addr_lst==0){
2953                         pkg_free(l);
2954                         return 0;
2955                 }
2956                 l->flags=0;
2957                 l->port=port;
2958                 l->proto=proto;
2959                 l->next=0;
2960         }
2961         return l;
2962 }
2963
2964
2965 static void free_name_lst(struct name_lst* lst)
2966 {
2967         struct name_lst* tmp;
2968         
2969         while(lst){
2970                 tmp=lst;
2971                 lst=lst->next;
2972                 pkg_free(tmp);
2973         }
2974 }
2975
2976
2977 static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
2978                                                                                 int port)
2979 {
2980         struct socket_id* l;
2981         l=pkg_malloc(sizeof(struct socket_id));
2982         if (l==0) {
2983                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
2984         } else {
2985                 l->flags=addr_l->flags;
2986                 l->port=port;
2987                 l->proto=proto;
2988                 l->addr_lst=addr_l;
2989                 l->next=0;
2990         }
2991         return l;
2992 }
2993
2994
2995 static void free_socket_id(struct socket_id* i)
2996 {
2997         free_name_lst(i->addr_lst);
2998         pkg_free(i);
2999 }
3000
3001
3002 static void free_socket_id_lst(struct socket_id* lst)
3003 {
3004         struct socket_id* tmp;
3005         
3006         while(lst){
3007                 tmp=lst;
3008                 lst=lst->next;
3009                 free_socket_id(tmp);
3010         }
3011 }
3012
3013
3014 /** create a temporary case statmenet structure.
3015  *  *err will be filled in case of error (return == 0):
3016  *   -1 - non constant expression
3017  *   -2 - expression error (bad type)
3018  *   -10 - memory allocation error
3019  */
3020 static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re,
3021                                                                                         struct action* a, int* err)
3022 {
3023         struct case_stms* s;
3024         struct rval_expr* bad_rve;
3025         enum rval_type type, bad_t, exp_t;
3026         enum match_str_type t;
3027         
3028         t=MATCH_UNKNOWN;
3029         if (ct){
3030                 /* if ct!=0 => case, else if ct==0 is a default */
3031                 if (!rve_is_constant(ct)){
3032                         yyerror_at(&ct->fpos, "non constant expression in case");
3033                         *err=-1;
3034                         return 0;
3035                 }
3036                 if (rve_check_type(&type, ct, &bad_rve, &bad_t, &exp_t)!=1){
3037                         yyerror_at(&ct->fpos, "bad expression: type mismatch:"
3038                                                         " %s instead of %s at (%d,%d)",
3039                                                         rval_type_name(bad_t), rval_type_name(exp_t),
3040                                                         bad_rve->fpos.s_line, bad_rve->fpos.s_col);
3041                         *err=-2;
3042                         return 0;
3043                 }
3044                 if (is_re)
3045                         t=MATCH_RE;
3046                 else if (type==RV_STR)
3047                         t=MATCH_STR;
3048                 else
3049                         t=MATCH_INT;
3050         }
3051
3052         s=pkg_malloc(sizeof(*s));
3053         if (s==0) {
3054                 yyerror("internal error: memory allocation failure");
3055                 *err=-10;
3056         } else {
3057                 memset(s, 0, sizeof(*s));
3058                 s->ct_rve=ct;
3059                 s->type=t;
3060                 s->actions=a;
3061                 s->next=0;
3062                 s->append=0;
3063         }
3064         return s;
3065 }
3066
3067
3068 /*
3069  * @return 0 on success, -1 on error.
3070  */
3071 static int case_check_type(struct case_stms* stms)
3072 {
3073         struct case_stms* c;
3074         struct case_stms* s;
3075         
3076         for(c=stms; c ; c=c->next){
3077                 if (!c->ct_rve) continue;
3078                 for (s=c->next; s; s=s->next){
3079                         if (!s->ct_rve) continue;
3080                         if ((s->type!=c->type) &&
3081                                 !(      (c->type==MATCH_STR || c->type==MATCH_RE) &&
3082                                         (s->type==MATCH_STR || s->type==MATCH_RE) ) ){
3083                                         yyerror_at(&s->ct_rve->fpos, "type mismatch in case");
3084                                         return -1;
3085                         }
3086                 }
3087         }
3088         return 0;
3089 }
3090
3091
3092 /*
3093  * @return 0 on success, -1 on error.
3094  */
3095 static int case_check_default(struct case_stms* stms)
3096 {
3097         struct case_stms* c;
3098         int default_no;
3099         
3100         default_no=0;
3101         for(c=stms; c ; c=c->next)
3102                 if (c->ct_rve==0) default_no++;
3103         return (default_no<=1)?0:-1;
3104 }
3105
3106
3107
3108 /*
3109 int main(int argc, char ** argv)
3110 {
3111         if (yyparse()!=0)
3112                 fprintf(stderr, "parsing error\n");
3113 }
3114 */