- Spelling checked
[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  */
60
61
62 %{
63
64 #include <stdlib.h>
65 #include <stdio.h>
66 #include <sys/types.h>
67 #include <sys/socket.h>
68 #include <netinet/in.h>
69 #include <arpa/inet.h>
70 #include <string.h>
71 #include <errno.h>
72 #include "route_struct.h"
73 #include "globals.h"
74 #include "route.h"
75 #include "dprint.h"
76 #include "sr_module.h"
77 #include "modparam.h"
78 #include "ip_addr.h"
79 #include "resolve.h"
80 #include "socket_info.h"
81 #include "name_alias.h"
82 #include "ut.h"
83 #include "dset.h"
84
85
86 #include "config.h"
87 #ifdef USE_TLS
88 #include "tls/tls_config.h"
89 #endif
90
91 #ifdef DEBUG_DMALLOC
92 #include <dmalloc.h>
93 #endif
94
95 /* hack to avoid alloca usage in the generated C file (needed for compiler
96  with no built in alloca, like icc*/
97 #undef _ALLOCA_H
98
99 struct id_list{
100         char* name;
101         int proto;
102         int port;
103         struct id_list* next;
104 };
105
106 extern int yylex();
107 static void yyerror(char* s);
108 static char* tmp;
109 static int i_tmp;
110 static void* f_tmp;
111 static struct id_list* lst_tmp;
112 static int rt;  /* Type of route block for find_export */
113 static str* str_tmp;
114 static str s_tmp;
115 static struct ip_addr* ip_tmp;
116
117 static void warn(char* s);
118 static struct id_list* mk_listen_id(char*, int, int);
119  
120
121 %}
122
123 %union {
124         long intval;
125         unsigned long uval;
126         char* strval;
127         struct expr* expr;
128         struct action* action;
129         struct net* ipnet;
130         struct ip_addr* ipaddr;
131         struct id_list* idlst;
132 }
133
134 /* terminals */
135
136
137 /* keywords */
138 %token FORWARD
139 %token FORWARD_TCP
140 %token FORWARD_TLS
141 %token FORWARD_UDP
142 %token SEND
143 %token SEND_TCP
144 %token DROP
145 %token LOG_TOK
146 %token ERROR
147 %token ROUTE
148 %token ROUTE_FAILURE
149 %token ROUTE_ONREPLY
150 %token EXEC
151 %token SET_HOST
152 %token SET_HOSTPORT
153 %token PREFIX
154 %token STRIP
155 %token STRIP_TAIL
156 %token APPEND_BRANCH
157 %token SET_USER
158 %token SET_USERPASS
159 %token SET_PORT
160 %token SET_URI
161 %token REVERT_URI
162 %token FORCE_RPORT
163 %token FORCE_TCP_ALIAS
164 %token IF
165 %token ELSE
166 %token SET_ADV_ADDRESS
167 %token SET_ADV_PORT
168 %token URIHOST
169 %token URIPORT
170 %token MAX_LEN
171 %token SETFLAG
172 %token RESETFLAG
173 %token ISFLAGSET
174 %token METHOD
175 %token URI
176 %token SRCIP
177 %token SRCPORT
178 %token DSTIP
179 %token DSTPORT
180 %token PROTO
181 %token AF
182 %token MYSELF
183 %token MSGLEN 
184 %token UDP
185 %token TCP
186 %token TLS
187
188 /* config vars. */
189 %token DEBUG
190 %token FORK
191 %token LOGSTDERROR
192 %token LOGFACILITY
193 %token LISTEN
194 %token ALIAS
195 %token DNS
196 %token REV_DNS
197 %token PORT
198 %token STAT
199 %token CHILDREN
200 %token CHECK_VIA
201 %token SYN_BRANCH
202 %token MEMLOG
203 %token SIP_WARNING
204 %token FIFO
205 %token FIFO_DIR
206 %token SOCK_MODE
207 %token SOCK_USER
208 %token SOCK_GROUP
209 %token FIFO_DB_URL
210 %token UNIX_SOCK
211 %token UNIX_SOCK_CHILDREN
212 %token UNIX_TX_TIMEOUT
213 %token SERVER_SIGNATURE
214 %token REPLY_TO_VIA
215 %token LOADMODULE
216 %token MODPARAM
217 %token MAXBUFFER
218 %token USER
219 %token GROUP
220 %token CHROOT
221 %token WDIR
222 %token MHOMED
223 %token DISABLE_TCP
224 %token TCP_ACCEPT_ALIASES
225 %token TCP_CHILDREN
226 %token TCP_CONNECT_TIMEOUT
227 %token TCP_SEND_TIMEOUT
228 %token DISABLE_TLS
229 %token TLSLOG
230 %token TLS_PORT_NO
231 %token TLS_METHOD
232 %token TLS_HANDSHAKE_TIMEOUT
233 %token TLS_SEND_TIMEOUT
234 %token SSLv23
235 %token SSLv2
236 %token SSLv3
237 %token TLSv1
238 %token TLS_VERIFY
239 %token TLS_REQUIRE_CERTIFICATE
240 %token TLS_CERTIFICATE
241 %token TLS_PRIVATE_KEY
242 %token TLS_CA_LIST
243 %token ADVERTISED_ADDRESS
244 %token ADVERTISED_PORT
245 %token DISABLE_CORE
246 %token OPEN_FD_LIMIT
247 %token MCAST_LOOPBACK
248 %token MCAST_TTL
249
250
251
252
253 /* operators */
254 %nonassoc EQUAL
255 %nonassoc EQUAL_T
256 %nonassoc GT
257 %nonassoc LT
258 %nonassoc GTE
259 %nonassoc LTE
260 %nonassoc DIFF
261 %nonassoc MATCH
262 %left OR
263 %left AND
264 %left NOT
265
266 /* values */
267 %token <intval> NUMBER
268 %token <strval> ID
269 %token <strval> STRING
270 %token <strval> IPV6ADDR
271
272 /* other */
273 %token COMMA
274 %token SEMICOLON
275 %token RPAREN
276 %token LPAREN
277 %token LBRACE
278 %token RBRACE
279 %token LBRACK
280 %token RBRACK
281 %token SLASH
282 %token DOT
283 %token CR
284 %token COLON
285 %token STAR
286
287
288 /*non-terminals */
289 %type <expr> exp exp_elem /*, condition*/
290 %type <action> action actions cmd if_cmd stm
291 %type <ipaddr> ipv4 ipv6 ipv6addr ip
292 %type <ipnet> ipnet
293 %type <strval> host
294 %type <strval> listen_id
295 %type <idlst>  id_lst
296 %type <idlst>  phostport
297 %type <intval> proto port
298 %type <intval> equalop strop intop
299 /*%type <route_el> rules;
300   %type <route_el> rule;
301 */
302
303
304
305 %%
306
307
308 cfg:    statements
309         ;
310
311 statements:     statements statement {}
312                 | statement {}
313                 | statements error { yyerror(""); YYABORT;}
314         ;
315
316 statement:      assign_stm 
317                 | module_stm
318                 | {rt=REQUEST_ROUTE;} route_stm 
319                 | {rt=FAILURE_ROUTE;} failure_route_stm
320                 | {rt=ONREPLY_ROUTE;} onreply_route_stm
321
322                 | CR    /* null statement*/
323         ;
324
325 listen_id:      ip                      {       tmp=ip_addr2a($1);
326                                                         if(tmp==0){
327                                                                 LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
328                                                                                 "address.\n");
329                                                                 $$=0;
330                                                         }else{
331                                                                 $$=pkg_malloc(strlen(tmp)+1);
332                                                                 if ($$==0){
333                                                                         LOG(L_CRIT, "ERROR: cfg. parser: out of "
334                                                                                         "memory.\n");
335                                                                 }else{
336                                                                         strncpy($$, tmp, strlen(tmp)+1);
337                                                                 }
338                                                         }
339                                                 }
340                  |      STRING                  {       $$=pkg_malloc(strlen($1)+1);
341                                                         if ($$==0){
342                                                                         LOG(L_CRIT, "ERROR: cfg. parser: out of "
343                                                                                         "memory.\n");
344                                                         }else{
345                                                                         strncpy($$, $1, strlen($1)+1);
346                                                         }
347                                                 }
348                  |      host            {       $$=pkg_malloc(strlen($1)+1);
349                                                         if ($$==0){
350                                                                         LOG(L_CRIT, "ERROR: cfg. parser: out of "
351                                                                                         "memory.\n");
352                                                         }else{
353                                                                         strncpy($$, $1, strlen($1)+1);
354                                                         }
355                                                 }
356         ;
357
358 proto:    UDP   { $$=PROTO_UDP; }
359                 | TCP   { $$=PROTO_TCP; }
360                 | TLS   { $$=PROTO_TLS; }
361                 | STAR  { $$=0; }
362                 ;
363
364 port:     NUMBER        { $$=$1; }
365                 | STAR          { $$=0; }
366 ;
367
368 phostport:      listen_id                               { $$=mk_listen_id($1, 0, 0); }
369                         | listen_id COLON port  { $$=mk_listen_id($1, 0, $3); }
370                         | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
371                         | proto COLON listen_id COLON port      { $$=mk_listen_id($3, $1, $5);}
372                         | listen_id COLON error { $$=0; yyerror(" port number expected"); }
373                         ;
374
375 id_lst:         phostport               {  $$=$1 ; }
376                 | phostport id_lst      { $$=$1; $$->next=$2; }
377                 ;
378
379
380 assign_stm:     DEBUG EQUAL NUMBER { debug=$3; }
381                 | DEBUG EQUAL error  { yyerror("number  expected"); }
382                 | FORK  EQUAL NUMBER { dont_fork= ! $3; }
383                 | FORK  EQUAL error  { yyerror("boolean value expected"); }
384                 | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
385                 | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
386                 | LOGFACILITY EQUAL ID {
387                                         if ( (i_tmp=str2facility($3))==-1)
388                                                 yyerror("bad facility (see syslog(3) man page)");
389                                         if (!config_check)
390                                                 log_facility=i_tmp;
391                                                                         }
392                 | LOGFACILITY EQUAL error { yyerror("ID expected"); }
393                 | DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
394                 | DNS EQUAL error { yyerror("boolean value expected"); }
395                 | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
396                 | REV_DNS EQUAL error { yyerror("boolean value expected"); }
397                 | PORT EQUAL NUMBER   { port_no=$3; }
398                 | STAT EQUAL STRING {
399                                         #ifdef STATS
400                                                         stat_file=$3;
401                                         #endif
402                                                         }
403                 | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
404                 | MAXBUFFER EQUAL error { yyerror("number expected"); }
405                 | PORT EQUAL error    { yyerror("number expected"); } 
406                 | CHILDREN EQUAL NUMBER { children_no=$3; }
407                 | CHILDREN EQUAL error { yyerror("number expected"); } 
408                 | CHECK_VIA EQUAL NUMBER { check_via=$3; }
409                 | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
410                 | SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
411                 | SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
412                 | MEMLOG EQUAL NUMBER { memlog=$3; }
413                 | MEMLOG EQUAL error { yyerror("int value expected"); }
414                 | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
415                 | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
416                 | FIFO EQUAL STRING { fifo=$3; }
417                 | FIFO EQUAL error { yyerror("string value expected"); }
418                 | FIFO_DIR EQUAL STRING { fifo_dir=$3; }
419                 | FIFO_DIR EQUAL error { yyerror("string value expected"); }
420                 | SOCK_MODE EQUAL NUMBER { sock_mode=$3; }
421                 | SOCK_MODE EQUAL error { yyerror("int value expected"); }
422                 | SOCK_USER EQUAL STRING { sock_user=$3; }
423                 | SOCK_USER EQUAL ID     { sock_user=$3; }
424                 | SOCK_USER EQUAL error { yyerror("string value expected"); }
425                 | SOCK_GROUP EQUAL STRING { sock_group=$3; }
426                 | SOCK_GROUP EQUAL ID     { sock_group=$3; }
427                 | SOCK_GROUP EQUAL error { yyerror("string value expected"); }
428                 | FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
429                 | FIFO_DB_URL EQUAL error  { yyerror("string value expected"); }
430                 | UNIX_SOCK EQUAL STRING { unixsock_name=$3; }
431                 | UNIX_SOCK EQUAL error { yyerror("string value expected"); }
432                 | UNIX_SOCK_CHILDREN EQUAL NUMBER { unixsock_children=$3; }
433                 | UNIX_SOCK_CHILDREN EQUAL error { yyerror("int value expected\n"); }
434                 | UNIX_TX_TIMEOUT EQUAL NUMBER { unixsock_tx_timeout=$3; }
435                 | UNIX_TX_TIMEOUT EQUAL error { yyerror("int value expected\n"); }
436                 | USER EQUAL STRING     { user=$3; }
437                 | USER EQUAL ID         { user=$3; }
438                 | USER EQUAL error      { yyerror("string value expected"); }
439                 | GROUP EQUAL STRING     { group=$3; }
440                 | GROUP EQUAL ID         { group=$3; }
441                 | GROUP EQUAL error      { yyerror("string value expected"); }
442                 | CHROOT EQUAL STRING     { chroot_dir=$3; }
443                 | CHROOT EQUAL ID         { chroot_dir=$3; }
444                 | CHROOT EQUAL error      { yyerror("string value expected"); }
445                 | WDIR EQUAL STRING     { working_dir=$3; }
446                 | WDIR EQUAL ID         { working_dir=$3; }
447                 | WDIR EQUAL error      { yyerror("string value expected"); }
448                 | MHOMED EQUAL NUMBER { mhomed=$3; }
449                 | MHOMED EQUAL error { yyerror("boolean value expected"); }
450                 | DISABLE_TCP EQUAL NUMBER {
451                                                                         #ifdef USE_TCP
452                                                                                 tcp_disable=$3;
453                                                                         #else
454                                                                                 warn("tcp support not compiled in");
455                                                                         #endif
456                                                                         }
457                 | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
458                 | TCP_ACCEPT_ALIASES EQUAL NUMBER {
459                                                                         #ifdef USE_TCP
460                                                                                 tcp_accept_aliases=$3;
461                                                                         #else
462                                                                                 warn("tcp support not compiled in");
463                                                                         #endif
464                                                                         }
465                 | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
466                 | TCP_CHILDREN EQUAL NUMBER {
467                                                                         #ifdef USE_TCP
468                                                                                 tcp_children_no=$3;
469                                                                         #else
470                                                                                 warn("tcp support not compiled in");
471                                                                         #endif
472                                                                         }
473                 | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
474                 | TCP_CONNECT_TIMEOUT EQUAL NUMBER {
475                                                                         #ifdef USE_TCP
476                                                                                 tcp_connect_timeout=$3;
477                                                                         #else
478                                                                                 warn("tcp support not compiled in");
479                                                                         #endif
480                                                                         }
481                 | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
482                 | TCP_SEND_TIMEOUT EQUAL NUMBER {
483                                                                         #ifdef USE_TCP
484                                                                                 tcp_send_timeout=$3;
485                                                                         #else
486                                                                                 warn("tcp support not compiled in");
487                                                                         #endif
488                                                                         }
489                 | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
490                 | DISABLE_TLS EQUAL NUMBER {
491                                                                         #ifdef USE_TLS
492                                                                                 tls_disable=$3;
493                                                                         #else
494                                                                                 warn("tls support not compiled in");
495                                                                         #endif
496                                                                         }
497                 | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
498                 | TLSLOG EQUAL NUMBER           { 
499                                                                         #ifdef USE_TLS
500                                                                                 tls_log=$3;
501                                                                         #else
502                                                                                 warn("tls support not compiled in");
503                                                                         #endif
504                                                                         }
505                 | TLSLOG EQUAL error { yyerror("int value expected"); }
506                 | TLS_PORT_NO EQUAL NUMBER {
507                                                                         #ifdef USE_TLS
508                                                                                 tls_port_no=$3;
509                                                                         #else
510                                                                                 warn("tls support not compiled in");
511                                                                         #endif
512                                                                         }
513                 | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
514                 | TLS_METHOD EQUAL SSLv23 {
515                                                                         #ifdef USE_TLS
516                                                                                 tls_method=TLS_USE_SSLv23;
517                                                                         #else
518                                                                                 warn("tls support not compiled in");
519                                                                         #endif
520                                                                         }
521                 | TLS_METHOD EQUAL SSLv2 {
522                                                                         #ifdef USE_TLS
523                                                                                 tls_method=TLS_USE_SSLv2;
524                                                                         #else
525                                                                                 warn("tls support not compiled in");
526                                                                         #endif
527                                                                         }
528                 | TLS_METHOD EQUAL SSLv3 {
529                                                                         #ifdef USE_TLS
530                                                                                 tls_method=TLS_USE_SSLv3;
531                                                                         #else
532                                                                                 warn("tls support not compiled in");
533                                                                         #endif
534                                                                         }
535                 | TLS_METHOD EQUAL TLSv1 {
536                                                                         #ifdef USE_TLS
537                                                                                 tls_method=TLS_USE_TLSv1;
538                                                                         #else
539                                                                                 warn("tls support not compiled in");
540                                                                         #endif
541                                                                         }
542                 | TLS_METHOD EQUAL error {
543                                                                         #ifdef USE_TLS
544                                                                                 yyerror("SSLv23, SSLv2, SSLv3 or TLSv1"
545                                                                                                         " expected");
546                                                                         #else
547                                                                                 warn("tls support not compiled in");
548                                                                         #endif
549                                                                         }
550                                                                                 
551                 | TLS_VERIFY EQUAL NUMBER {
552                                                                         #ifdef USE_TLS
553                                                                                 tls_verify_cert=$3;
554                                                                         #else
555                                                                                 warn("tls support not compiled in");
556                                                                         #endif
557                                                                         }
558                 | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
559                 | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
560                                                                         #ifdef USE_TLS
561                                                                                 tls_require_cert=$3;
562                                                                         #else
563                                                                                 warn( "tls support not compiled in");
564                                                                         #endif
565                                                                         }
566                 | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value"
567                                                                                                                                 " expected"); }
568                 | TLS_CERTIFICATE EQUAL STRING { 
569                                                                         #ifdef USE_TLS
570                                                                                         tls_cert_file=$3;
571                                                                         #else
572                                                                                 warn("tls support not compiled in");
573                                                                         #endif
574                                                                         }
575                 | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
576                 | TLS_PRIVATE_KEY EQUAL STRING { 
577                                                                         #ifdef USE_TLS
578                                                                                         tls_pkey_file=$3;
579                                                                         #else
580                                                                                 warn("tls support not compiled in");
581                                                                         #endif
582                                                                         }
583                 | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
584                 | TLS_CA_LIST EQUAL STRING { 
585                                                                         #ifdef USE_TLS
586                                                                                         tls_ca_file=$3;
587                                                                         #else
588                                                                                 warn("tls support not compiled in");
589                                                                         #endif
590                                                                         }
591                 | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
592                 | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
593                                                                         #ifdef USE_TLS
594                                                                                 tls_handshake_timeout=$3;
595                                                                         #else
596                                                                                 warn("tls support not compiled in");
597                                                                         #endif
598                                                                         }
599                 | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
600                 | TLS_SEND_TIMEOUT EQUAL NUMBER {
601                                                                         #ifdef USE_TLS
602                                                                                 tls_send_timeout=$3;
603                                                                         #else
604                                                                                 warn("tls support not compiled in");
605                                                                         #endif
606                                                                         }
607                 | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
608                 | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
609                 | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
610                 | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
611                 | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
612                 | LISTEN EQUAL id_lst {
613                                                         for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
614                                                                 if (add_listen_iface(   lst_tmp->name,
615                                                                                                                 lst_tmp->port,
616                                                                                                                 lst_tmp->proto,
617                                                                                                                 0
618                                                                                                         )!=0){
619                                                                         LOG(L_CRIT,  "ERROR: cfg. parser: failed"
620                                                                                         " to add listen address\n");
621                                                                         break;
622                                                                 }
623                                                         }
624                                                          }
625                 | LISTEN EQUAL  error { yyerror("ip address or hostname"
626                                                 "expected"); }
627                 | ALIAS EQUAL  id_lst { 
628                                                         for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
629                                                                 add_alias(lst_tmp->name, strlen(lst_tmp->name),
630                                                                                         lst_tmp->port, lst_tmp->proto);
631                                                           }
632                 | ALIAS  EQUAL error  { yyerror(" hostname expected"); }
633                 | ADVERTISED_ADDRESS EQUAL listen_id {
634                                                                 default_global_address.s=$3;
635                                                                 default_global_address.len=strlen($3);
636                                                                 }
637                 |ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
638                                                                                                 "expected"); }
639                 | ADVERTISED_PORT EQUAL NUMBER {
640                                                                 tmp=int2str($3, &i_tmp);
641                                                                 if ((default_global_port.s=pkg_malloc(i_tmp))
642                                                                                 ==0){
643                                                                                 LOG(L_CRIT, "ERROR: cfg. parser:"
644                                                                                                         " out of memory.\n");
645                                                                                 default_global_port.len=0;
646                                                                 }else{
647                                                                         default_global_port.len=i_tmp;
648                                                                         memcpy(default_global_port.s, tmp,
649                                                                                         default_global_port.len);
650                                                                 };
651                                                                 }
652                 |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
653                                                                                                 "expected"); }
654                 | DISABLE_CORE EQUAL NUMBER {
655                                                                                 disable_core_dump=$3;
656                                                                         }
657                 | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
658                 | OPEN_FD_LIMIT EQUAL NUMBER {
659                                                                                 open_files_limit=$3;
660                                                                         }
661                 | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
662                 | MCAST_LOOPBACK EQUAL NUMBER {
663                                                                 #ifdef USE_MCAST
664                                                                                 mcast_loopback=$3;
665                                                                 #else
666                                                                         warn("no multicast support compiled in");
667                                                                 #endif
668                   }
669                 | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
670                 | MCAST_TTL EQUAL NUMBER {
671                                                                 #ifdef USE_MCAST
672                                                                                 mcast_ttl=$3;
673                                                                 #else
674                                                                         warn("no multicast support compiled in");
675                                                                 #endif
676                   }
677                 | MCAST_TTL EQUAL error { yyerror("number expected"); }
678                 | error EQUAL { yyerror("unknown config variable"); }
679         ;
680
681 module_stm:     LOADMODULE STRING       { DBG("loading module %s\n", $2);
682                                                                   if (load_module($2)!=0){
683                                                                                 yyerror("failed to load module");
684                                                                   }
685                                                                 }
686                  | LOADMODULE error     { yyerror("string expected");  }
687                  | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
688                          if (set_mod_param_regex($3, $5, STR_PARAM, $7) != 0) {
689                                  yyerror("Can't set module parameter");
690                          }
691                    }
692                  | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
693                          if (set_mod_param_regex($3, $5, INT_PARAM, (void*)$7) != 0) {
694                                  yyerror("Can't set module parameter");
695                          }
696                    }
697                  | MODPARAM error { yyerror("Invalid arguments"); }
698                  ;
699
700
701 ip:              ipv4  { $$=$1; }
702                 |ipv6  { $$=$1; }
703                 ;
704
705 ipv4:   NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { 
706                                                                                         $$=pkg_malloc(
707                                                                                                         sizeof(struct ip_addr));
708                                                                                         if ($$==0){
709                                                                                                 LOG(L_CRIT, "ERROR: cfg. "
710                                                                                                         "parser: out of memory.\n"
711                                                                                                         );
712                                                                                         }else{
713                                                                                                 memset($$, 0, 
714                                                                                                         sizeof(struct ip_addr));
715                                                                                                 $$->af=AF_INET;
716                                                                                                 $$->len=4;
717                                                                                                 if (($1>255) || ($1<0) ||
718                                                                                                         ($3>255) || ($3<0) ||
719                                                                                                         ($5>255) || ($5<0) ||
720                                                                                                         ($7>255) || ($7<0)){
721                                                                                                         yyerror("invalid ipv4"
722                                                                                                                         "address");
723                                                                                                         $$->u.addr32[0]=0;
724                                                                                                         /* $$=0; */
725                                                                                                 }else{
726                                                                                                         $$->u.addr[0]=$1;
727                                                                                                         $$->u.addr[1]=$3;
728                                                                                                         $$->u.addr[2]=$5;
729                                                                                                         $$->u.addr[3]=$7;
730                                                                                                         /*
731                                                                                                         $$=htonl( ($1<<24)|
732                                                                                                         ($3<<16)| ($5<<8)|$7 );
733                                                                                                         */
734                                                                                                 }
735                                                                                         }
736                                                                                                 }
737         ;
738
739 ipv6addr:       IPV6ADDR {
740                                         $$=pkg_malloc(sizeof(struct ip_addr));
741                                         if ($$==0){
742                                                 LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
743                                         }else{
744                                                 memset($$, 0, sizeof(struct ip_addr));
745                                                 $$->af=AF_INET6;
746                                                 $$->len=16;
747                                         #ifdef USE_IPV6
748                                                 if (inet_pton(AF_INET6, $1, $$->u.addr)<=0){
749                                                         yyerror("bad ipv6 address");
750                                                 }
751                                         #else
752                                                 yyerror("ipv6 address & no ipv6 support compiled in");
753                                                 YYABORT;
754                                         #endif
755                                         }
756                                 }
757         ;
758
759 ipv6:   ipv6addr { $$=$1; }
760         | LBRACK ipv6addr RBRACK {$$=$2; }
761 ;
762
763
764 route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
765
766             | ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { 
767                                                                                 if (($3<RT_NO) && ($3>=0)){
768                                                                                         push($6, &rlist[$3]);
769                                                                                 }else{
770                                                                                         yyerror("invalid routing"
771                                                                                                         "table number");
772                                                                                         YYABORT; }
773                                                                                 }
774                 | ROUTE error { yyerror("invalid  route  statement"); }
775         ;
776
777 failure_route_stm: ROUTE_FAILURE LBRACK NUMBER RBRACK LBRACE actions RBRACE {
778                                                                                 if (($3<FAILURE_RT_NO)&&($3>=1)){
779                                                                                         push($6, &failure_rlist[$3]);
780                                                                                 } else {
781                                                                                         yyerror("invalid reply routing"
782                                                                                                 "table number");
783                                                                                         YYABORT; }
784                                                                                 }
785                 | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
786         ;
787
788 onreply_route_stm: ROUTE_ONREPLY LBRACK NUMBER RBRACK LBRACE actions RBRACE {
789                                                                                 if (($3<ONREPLY_RT_NO)&&($3>=1)){
790                                                                                         push($6, &onreply_rlist[$3]);
791                                                                                 } else {
792                                                                                         yyerror("invalid reply routing"
793                                                                                                 "table number");
794                                                                                         YYABORT; }
795                                                                                 }
796                 | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
797         ;
798 /*
799 rules:  rules rule { push($2, &$1); $$=$1; }
800         | rule {$$=$1; }
801         | rules error { $$=0; yyerror("invalid rule"); }
802          ;
803
804 rule:   condition       actions CR {
805                                                                 $$=0;
806                                                                 if (add_rule($1, $2, &$$)<0) {
807                                                                         yyerror("error calling add_rule");
808                                                                         YYABORT;
809                                                                 }
810                                                           }
811         | CR            { $$=0;}
812         | condition error { $$=0; yyerror("bad actions in rule"); }
813         ;
814
815 condition:      exp {$$=$1;}
816 */
817
818 exp:    exp AND exp     { $$=mk_exp(AND_OP, $1, $3); }
819         | exp OR  exp           { $$=mk_exp(OR_OP, $1, $3);  }
820         | NOT exp                       { $$=mk_exp(NOT_OP, $2, 0);  }
821         | LPAREN exp RPAREN     { $$=$2; }
822         | exp_elem                      { $$=$1; }
823         ;
824
825 equalop:          EQUAL_T {$$=EQUAL_OP; }
826                         | DIFF  {$$=DIFF_OP; }
827                 ;
828                 
829 intop:  equalop {$$=$1; }
830                 |  GT   {$$=GT_OP; }
831                 | LT    {$$=LT_OP; }
832                 | GTE   {$$=GTE_OP; }
833                 | LTE   {$$=LTE_OP; }
834                 ;
835                 
836 strop:  equalop {$$=$1; }
837                 | MATCH {$$=MATCH_OP; }
838                 ;
839
840 exp_elem:       METHOD strop STRING     {$$= mk_elem(   $2, STRING_ST, 
841                                                                                                         METHOD_O, $3);
842                                                                         }
843                 | METHOD strop  ID      {$$ = mk_elem(  $2, STRING_ST,
844                                                                                         METHOD_O, $3); 
845                                                         }
846                 | METHOD strop error { $$=0; yyerror("string expected"); }
847                 | METHOD error  { $$=0; yyerror("invalid operator,"
848                                                                                 "== , !=, or =~ expected");
849                                                 }
850                 | URI strop STRING      {$$ = mk_elem(  $2, STRING_ST,
851                                                                                                 URI_O, $3); 
852                                                                 }
853                 | URI strop host        {$$ = mk_elem(  $2, STRING_ST,
854                                                                                         URI_O, $3); 
855                                                         }
856                 | URI equalop MYSELF    { $$=mk_elem(   $2, MYSELF_ST,
857                                                                                                 URI_O, 0);
858                                                                 }
859                 | URI strop error { $$=0; yyerror("string or MYSELF expected"); }
860                 | URI error     { $$=0; yyerror("invalid operator,"
861                                                                         " == , != or =~ expected");
862                                         }
863                 | SRCPORT intop NUMBER  { $$=mk_elem(   $2, NUMBER_ST,
864                                                                                                 SRCPORT_O, (void *) $3 ); }
865                 | SRCPORT intop error { $$=0; yyerror("number expected"); }
866                 | SRCPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
867                 | DSTPORT intop NUMBER  { $$=mk_elem(   $2, NUMBER_ST,
868                                                                                                 DSTPORT_O, (void *) $3 ); }
869                 | DSTPORT intop error { $$=0; yyerror("number expected"); }
870                 | DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
871                 | PROTO intop proto     { $$=mk_elem(   $2, NUMBER_ST,
872                                                                                                 PROTO_O, (void *) $3 ); }
873                 | PROTO intop error { $$=0;
874                                                                 yyerror("protocol expected (udp, tcp or tls)");
875                                                         }
876                 | PROTO error { $$=0; yyerror("equal/!= operator expected"); }
877                 | AF intop NUMBER       { $$=mk_elem(   $2, NUMBER_ST,
878                                                                                                 AF_O, (void *) $3 ); }
879                 | AF intop error { $$=0; yyerror("number expected"); }
880                 | AF error { $$=0; yyerror("equal/!= operator expected"); }
881                 | MSGLEN intop NUMBER   { $$=mk_elem(   $2, NUMBER_ST,
882                                                                                                 MSGLEN_O, (void *) $3 ); }
883                 | MSGLEN intop MAX_LEN  { $$=mk_elem(   $2, NUMBER_ST,
884                                                                                                 MSGLEN_O, (void *) BUF_SIZE); }
885                 | MSGLEN intop error { $$=0; yyerror("number expected"); }
886                 | MSGLEN error { $$=0; yyerror("equal/!= operator expected"); }
887                 | SRCIP equalop ipnet   { $$=mk_elem(   $2, NET_ST,
888                                                                                                 SRCIP_O, $3);
889                                                                 }
890                 | SRCIP strop STRING    {       s_tmp.s=$3;
891                                                                         s_tmp.len=strlen($3);
892                                                                         ip_tmp=str2ip(&s_tmp);
893                                                                         if (ip_tmp==0)
894                                                                                 ip_tmp=str2ip6(&s_tmp);
895                                                                         if (ip_tmp){
896                                                                                 $$=mk_elem(     $2, NET_ST, SRCIP_O,
897                                                                                                 mk_net_bitlen(ip_tmp, 
898                                                                                                                 ip_tmp->len*8) );
899                                                                         }else{
900                                                                                 $$=mk_elem(     $2, STRING_ST,
901                                                                                                 SRCIP_O, $3);
902                                                                         }
903                                                                 }
904                 | SRCIP strop host      { $$=mk_elem(   $2, STRING_ST,
905                                                                                                 SRCIP_O, $3);
906                                                                 }
907                 | SRCIP equalop MYSELF  { $$=mk_elem(   $2, MYSELF_ST,
908                                                                                                 SRCIP_O, 0);
909                                                                 }
910                 | SRCIP strop error { $$=0; yyerror( "ip address or hostname"
911                                                  "expected" ); }
912                 | SRCIP error  { $$=0; 
913                                                  yyerror("invalid operator, ==, != or =~ expected");}
914                 | DSTIP equalop ipnet   { $$=mk_elem(   $2, NET_ST,
915                                                                                                 DSTIP_O, $3);
916                                                                 }
917                 | DSTIP strop STRING    {       s_tmp.s=$3;
918                                                                         s_tmp.len=strlen($3);
919                                                                         ip_tmp=str2ip(&s_tmp);
920                                                                         if (ip_tmp==0)
921                                                                                 ip_tmp=str2ip6(&s_tmp);
922                                                                         if (ip_tmp){
923                                                                                 $$=mk_elem(     $2, NET_ST, DSTIP_O,
924                                                                                                 mk_net_bitlen(ip_tmp, 
925                                                                                                                 ip_tmp->len*8) );
926                                                                         }else{
927                                                                                 $$=mk_elem(     $2, STRING_ST,
928                                                                                                 DSTIP_O, $3);
929                                                                         }
930                                                                 }
931                 | DSTIP strop host      { $$=mk_elem(   $2, STRING_ST,
932                                                                                                 DSTIP_O, $3);
933                                                                 }
934                 | DSTIP equalop MYSELF  { $$=mk_elem(   $2, MYSELF_ST,
935                                                                                                 DSTIP_O, 0);
936                                                                 }
937                 | DSTIP strop error { $$=0; yyerror( "ip address or hostname"
938                                                                         "expected" ); }
939                 | DSTIP error { $$=0; 
940                                                 yyerror("invalid operator, ==, != or =~ expected");}
941                 | MYSELF equalop URI    { $$=mk_elem(   $2, MYSELF_ST,
942                                                                                                 URI_O, 0);
943                                                                 }
944                 | MYSELF equalop SRCIP  { $$=mk_elem(   $2, MYSELF_ST,
945                                                                                                 SRCIP_O, 0);
946                                                                 }
947                 | MYSELF equalop DSTIP  { $$=mk_elem(   $2, MYSELF_ST,
948                                                                                                 DSTIP_O, 0);
949                                                                 }
950                 | MYSELF equalop error {        $$=0; 
951                                                                         yyerror(" URI, SRCIP or DSTIP expected"); }
952                 | MYSELF error  { $$=0; 
953                                                         yyerror ("invalid operator, == or != expected");
954                                                 }
955                 | stm                           { $$=mk_elem( NO_OP, ACTIONS_ST, ACTION_O, $1 ); }
956                 | NUMBER                {$$=mk_elem( NO_OP, NUMBER_ST, NUMBER_O, (void*)$1 ); }
957         ;
958
959 ipnet:  ip SLASH ip     { $$=mk_net($1, $3); } 
960         | ip SLASH NUMBER       {       if (($3<0) || ($3>$1->len*8)){
961                                                                 yyerror("invalid bit number in netmask");
962                                                                 $$=0;
963                                                         }else{
964                                                                 $$=mk_net_bitlen($1, $3);
965                                                         /*
966                                                                 $$=mk_net($1, 
967                                                                                 htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
968                                                         */
969                                                         }
970                                                 }
971         | ip                            { $$=mk_net_bitlen($1, $1->len*8); }
972         | ip SLASH error        { $$=0;
973                                                  yyerror("netmask (eg:255.0.0.0 or 8) expected");
974                                                 }
975         ;
976
977 host:   ID                              { $$=$1; }
978         | host DOT ID           { $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
979                                                   if ($$==0){
980                                                         LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
981                                                                                 " failure while parsing host\n");
982                                                   }else{
983                                                         memcpy($$, $1, strlen($1));
984                                                         $$[strlen($1)]='.';
985                                                         memcpy($$+strlen($1)+1, $3, strlen($3));
986                                                         $$[strlen($1)+1+strlen($3)]=0;
987                                                   }
988                                                   pkg_free($1); pkg_free($3);
989                                                 }
990         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
991         ;
992
993
994 stm:            cmd                                             { $$=$1; }
995                 |       if_cmd                                  { $$=$1; }
996                 |       LBRACE actions RBRACE   { $$=$2; }
997         ;
998
999 actions:        actions action  {$$=append_action($1, $2); }
1000                 | action                        {$$=$1;}
1001                 | actions error { $$=0; yyerror("bad command"); }
1002         ;
1003
1004 action:         cmd SEMICOLON {$$=$1;}
1005                 | if_cmd {$$=$1;}
1006                 | SEMICOLON /* null action */ {$$=0;}
1007                 | cmd error { $$=0; yyerror("bad command: missing ';'?"); }
1008         ;
1009
1010 if_cmd:         IF exp stm                              { $$=mk_action3( IF_T,
1011                                                                                                          EXPR_ST,
1012                                                                                                          ACTIONS_ST,
1013                                                                                                          NOSUBTYPE,
1014                                                                                                          $2,
1015                                                                                                          $3,
1016                                                                                                          0);
1017                                                                         }
1018                 |       IF exp stm ELSE stm             { $$=mk_action3( IF_T,
1019                                                                                                          EXPR_ST,
1020                                                                                                          ACTIONS_ST,
1021                                                                                                          ACTIONS_ST,
1022                                                                                                          $2,
1023                                                                                                          $3,
1024                                                                                                          $5);
1025                                                                         }
1026         ;
1027
1028 cmd:            FORWARD LPAREN host RPAREN      { $$=mk_action( FORWARD_T,
1029                                                                                                                 STRING_ST,
1030                                                                                                                 NUMBER_ST,
1031                                                                                                                 $3,
1032                                                                                                                 0);
1033                                                                                 }
1034                 | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T,
1035                                                                                                                 STRING_ST,
1036                                                                                                                 NUMBER_ST,
1037                                                                                                                 $3,
1038                                                                                                                 0);
1039                                                                                 }
1040                 | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T,
1041                                                                                                                 IP_ST,
1042                                                                                                                 NUMBER_ST,
1043                                                                                                                 (void*)$3,
1044                                                                                                                 0);
1045                                                                                 }
1046                 | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T,
1047                                                                                                                                  STRING_ST,
1048                                                                                                                                  NUMBER_ST,
1049                                                                                                                                 $3,
1050                                                                                                                                 (void*)$5);
1051                                                                                                  }
1052                 | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T,
1053                                                                                                                                  STRING_ST,
1054                                                                                                                                  NUMBER_ST,
1055                                                                                                                                 $3,
1056                                                                                                                                 (void*)$5);
1057                                                                                                         }
1058                 | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T,
1059                                                                                                                                  IP_ST,
1060                                                                                                                                  NUMBER_ST,
1061                                                                                                                                  (void*)$3,
1062                                                                                                                                 (void*)$5);
1063                                                                                                   }
1064                 | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN {
1065                                                                                                         $$=mk_action(FORWARD_T,
1066                                                                                                                                  URIHOST_ST,
1067                                                                                                                                  URIPORT_ST,
1068                                                                                                                                 0,
1069                                                                                                                                 0);
1070                                                                                                         }
1071                                                                                                         
1072                                                                         
1073                 | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {
1074                                                                                                         $$=mk_action(FORWARD_T,
1075                                                                                                                                  URIHOST_ST,
1076                                                                                                                                  NUMBER_ST,
1077                                                                                                                                 0,
1078                                                                                                                                 (void*)$5);
1079                                                                                                         }
1080                 | FORWARD LPAREN URIHOST RPAREN {
1081                                                                                                         $$=mk_action(FORWARD_T,
1082                                                                                                                                  URIHOST_ST,
1083                                                                                                                                  NUMBER_ST,
1084                                                                                                                                 0,
1085                                                                                                                                 0);
1086                                                                                 }
1087                 | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
1088                 | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward"
1089                                                                                 "argument"); }
1090                 | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action( FORWARD_UDP_T,
1091                                                                                                                 STRING_ST,
1092                                                                                                                 NUMBER_ST,
1093                                                                                                                 $3,
1094                                                                                                                 0);
1095                                                                                 }
1096                 | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action( FORWARD_UDP_T,
1097                                                                                                                 STRING_ST,
1098                                                                                                                 NUMBER_ST,
1099                                                                                                                 $3,
1100                                                                                                                 0);
1101                                                                                 }
1102                 | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action( FORWARD_UDP_T,
1103                                                                                                                 IP_ST,
1104                                                                                                                 NUMBER_ST,
1105                                                                                                                 (void*)$3,
1106                                                                                                                 0);
1107                                                                                 }
1108                 | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(
1109                                                                                                                                 FORWARD_UDP_T,
1110                                                                                                                                  STRING_ST,
1111                                                                                                                                  NUMBER_ST,
1112                                                                                                                                 $3,
1113                                                                                                                                 (void*)$5);
1114                                                                                                  }
1115                 | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(
1116                                                                                                                                 FORWARD_UDP_T,
1117                                                                                                                                  STRING_ST,
1118                                                                                                                                  NUMBER_ST,
1119                                                                                                                                 $3,
1120                                                                                                                                 (void*)$5);
1121                                                                                                         }
1122                 | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(
1123                                                                                                                                 FORWARD_UDP_T,
1124                                                                                                                                  IP_ST,
1125                                                                                                                                  NUMBER_ST,
1126                                                                                                                                  (void*)$3,
1127                                                                                                                                 (void*)$5);
1128                                                                                                   }
1129                 | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {
1130                                                                                                         $$=mk_action(FORWARD_UDP_T,
1131                                                                                                                                  URIHOST_ST,
1132                                                                                                                                  URIPORT_ST,
1133                                                                                                                                 0,
1134                                                                                                                                 0);
1135                                                                                                         }
1136                                                                                                         
1137                                                                         
1138                 | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN {
1139                                                                                                         $$=mk_action(FORWARD_UDP_T,
1140                                                                                                                                  URIHOST_ST,
1141                                                                                                                                  NUMBER_ST,
1142                                                                                                                                 0,
1143                                                                                                                                 (void*)$5);
1144                                                                                                         }
1145                 | FORWARD_UDP LPAREN URIHOST RPAREN {
1146                                                                                                         $$=mk_action(FORWARD_UDP_T,
1147                                                                                                                                  URIHOST_ST,
1148                                                                                                                                  NUMBER_ST,
1149                                                                                                                                 0,
1150                                                                                                                                 0);
1151                                                                                 }
1152                 | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
1153                 | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp"
1154                                                                                 "argument"); }
1155                 | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action( FORWARD_TCP_T,
1156                                                                                                                 STRING_ST,
1157                                                                                                                 NUMBER_ST,
1158                                                                                                                 $3,
1159                                                                                                                 0);
1160                                                                                 }
1161                 | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action( FORWARD_TCP_T,
1162                                                                                                                 STRING_ST,
1163                                                                                                                 NUMBER_ST,
1164                                                                                                                 $3,
1165                                                                                                                 0);
1166                                                                                 }
1167                 | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action( FORWARD_TCP_T,
1168                                                                                                                 IP_ST,
1169                                                                                                                 NUMBER_ST,
1170                                                                                                                 (void*)$3,
1171                                                                                                                 0);
1172                                                                                 }
1173                 | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(
1174                                                                                                                                 FORWARD_TCP_T,
1175                                                                                                                                  STRING_ST,
1176                                                                                                                                  NUMBER_ST,
1177                                                                                                                                 $3,
1178                                                                                                                                 (void*)$5);
1179                                                                                                  }
1180                 | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(
1181                                                                                                                                 FORWARD_TCP_T,
1182                                                                                                                                  STRING_ST,
1183                                                                                                                                  NUMBER_ST,
1184                                                                                                                                 $3,
1185                                                                                                                                 (void*)$5);
1186                                                                                                         }
1187                 | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T,
1188                                                                                                                                  IP_ST,
1189                                                                                                                                  NUMBER_ST,
1190                                                                                                                                  (void*)$3,
1191                                                                                                                                 (void*)$5);
1192                                                                                                   }
1193                 | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {
1194                                                                                                         $$=mk_action(FORWARD_TCP_T,
1195                                                                                                                                  URIHOST_ST,
1196                                                                                                                                  URIPORT_ST,
1197                                                                                                                                 0,
1198                                                                                                                                 0);
1199                                                                                                         }
1200                                                                                                         
1201                                                                         
1202                 | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN {
1203                                                                                                         $$=mk_action(FORWARD_TCP_T,
1204                                                                                                                                  URIHOST_ST,
1205                                                                                                                                  NUMBER_ST,
1206                                                                                                                                 0,
1207                                                                                                                                 (void*)$5);
1208                                                                                                         }
1209                 | FORWARD_TCP LPAREN URIHOST RPAREN {
1210                                                                                                         $$=mk_action(FORWARD_TCP_T,
1211                                                                                                                                  URIHOST_ST,
1212                                                                                                                                  NUMBER_ST,
1213                                                                                                                                 0,
1214                                                                                                                                 0);
1215                                                                                 }
1216                 | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
1217                 | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp"
1218                                                                                 "argument"); }
1219                 | FORWARD_TLS LPAREN host RPAREN        {
1220                                                                                 #ifdef USE_TLS
1221                                                                                         $$=mk_action(   FORWARD_TLS_T,
1222                                                                                                                 STRING_ST,
1223                                                                                                                 NUMBER_ST,
1224                                                                                                                 $3,
1225                                                                                                                 0);
1226                                                                                 #else
1227                                                                                         $$=0;
1228                                                                                         yyerror("tls support not "
1229                                                                                                         "compiled in");
1230                                                                                 #endif
1231                                                                                 }
1232                 | FORWARD_TLS LPAREN STRING RPAREN      {
1233                                                                                 #ifdef USE_TLS
1234                                                                                         $$=mk_action(   FORWARD_TLS_T,
1235                                                                                                                         STRING_ST,
1236                                                                                                                         NUMBER_ST,
1237                                                                                                                         $3,
1238                                                                                                                         0);
1239                                                                                 #else
1240                                                                                         $$=0;
1241                                                                                         yyerror("tls support not "
1242                                                                                                         "compiled in");
1243                                                                                 #endif
1244                                                                                 }
1245                 | FORWARD_TLS LPAREN ip RPAREN  { 
1246                                                                                 #ifdef USE_TLS
1247                                                                                         $$=mk_action(   FORWARD_TLS_T,
1248                                                                                                                         IP_ST,
1249                                                                                                                         NUMBER_ST,
1250                                                                                                                         (void*)$3,
1251                                                                                                                         0);
1252                                                                                 #else
1253                                                                                         $$=0;
1254                                                                                         yyerror("tls support not "
1255                                                                                                         "compiled in");
1256                                                                                 #endif
1257                                                                                 }
1258                 | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN { 
1259                                                                                 #ifdef USE_TLS
1260                                                                                         $$=mk_action(   FORWARD_TLS_T,
1261                                                                                                                          STRING_ST,
1262                                                                                                                          NUMBER_ST,
1263                                                                                                                         $3,
1264                                                                                                                         (void*)$5);
1265                                                                                 #else
1266                                                                                         $$=0;
1267                                                                                         yyerror("tls support not "
1268                                                                                                         "compiled in");
1269                                                                                 #endif
1270                                                                                                  }
1271                 | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
1272                                                                                 #ifdef USE_TLS
1273                                                                                         $$=mk_action(   FORWARD_TLS_T,
1274                                                                                                                          STRING_ST,
1275                                                                                                                          NUMBER_ST,
1276                                                                                                                         $3,
1277                                                                                                                         (void*)$5);
1278                                                                                 #else
1279                                                                                         $$=0;
1280                                                                                         yyerror("tls support not "
1281                                                                                                         "compiled in");
1282                                                                                 #endif
1283                                                                                                         }
1284                 | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
1285                                                                                 #ifdef USE_TLS
1286                                                                                         $$=mk_action(   FORWARD_TLS_T,
1287                                                                                                                          IP_ST,
1288                                                                                                                          NUMBER_ST,
1289                                                                                                                          (void*)$3,
1290                                                                                                                         (void*)$5);
1291                                                                                 #else
1292                                                                                         $$=0;
1293                                                                                         yyerror("tls support not "
1294                                                                                                         "compiled in");
1295                                                                                 #endif
1296                                                                                                   }
1297                 | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
1298                                                                                 #ifdef USE_TLS
1299                                                                                         $$=mk_action(   FORWARD_TLS_T,
1300                                                                                                                          URIHOST_ST,
1301                                                                                                                          URIPORT_ST,
1302                                                                                                                         0,
1303                                                                                                                         0);
1304                                                                                 #else
1305                                                                                         $$=0;
1306                                                                                         yyerror("tls support not "
1307                                                                                                         "compiled in");
1308                                                                                 #endif
1309                                                                                                         }
1310                                                                                                         
1311                                                                         
1312                 | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
1313                                                                                 #ifdef USE_TLS
1314                                                                                         $$=mk_action(   FORWARD_TLS_T,
1315                                                                                                                          URIHOST_ST,
1316                                                                                                                          NUMBER_ST,
1317                                                                                                                         0,
1318                                                                                                                         (void*)$5);
1319                                                                                 #else
1320                                                                                         $$=0;
1321                                                                                         yyerror("tls support not "
1322                                                                                                         "compiled in");
1323                                                                                 #endif
1324                                                                                                         }
1325                 | FORWARD_TLS LPAREN URIHOST RPAREN {
1326                                                                                 #ifdef USE_TLS
1327                                                                                         $$=mk_action(   FORWARD_TLS_T,
1328                                                                                                                          URIHOST_ST,
1329                                                                                                                          NUMBER_ST,
1330                                                                                                                         0,
1331                                                                                                                         0);
1332                                                                                 #else
1333                                                                                         $$=0;
1334                                                                                         yyerror("tls support not "
1335                                                                                                         "compiled in");
1336                                                                                 #endif
1337                                                                                 }
1338                 | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
1339                 | FORWARD_TLS LPAREN error RPAREN { $$=0; yyerror("bad forward_tls"
1340                                                                                 "argument"); }
1341                 
1342                 | SEND LPAREN host RPAREN       { $$=mk_action( SEND_T,
1343                                                                                                         STRING_ST,
1344                                                                                                         NUMBER_ST,
1345                                                                                                         $3,
1346                                                                                                         0);
1347                                                                         }
1348                 | SEND LPAREN STRING RPAREN { $$=mk_action(     SEND_T,
1349                                                                                                         STRING_ST,
1350                                                                                                         NUMBER_ST,
1351                                                                                                         $3,
1352                                                                                                         0);
1353                                                                         }
1354                 | SEND LPAREN ip RPAREN         { $$=mk_action( SEND_T,
1355                                                                                                         IP_ST,
1356                                                                                                         NUMBER_ST,
1357                                                                                                         (void*)$3,
1358                                                                                                         0);
1359                                                                         }
1360                 | SEND LPAREN host COMMA NUMBER RPAREN  { $$=mk_action( SEND_T,
1361                                                                                                                                 STRING_ST,
1362                                                                                                                                 NUMBER_ST,
1363                                                                                                                                 $3,
1364                                                                                                                                 (void*)$5);
1365                                                                                                 }
1366                 | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action( SEND_T,
1367                                                                                                                                 STRING_ST,
1368                                                                                                                                 NUMBER_ST,
1369                                                                                                                                 $3,
1370                                                                                                                                 (void*)$5);
1371                                                                                                 }
1372                 | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(    SEND_T,
1373                                                                                                                                 IP_ST,
1374                                                                                                                                 NUMBER_ST,
1375                                                                                                                                 (void*)$3,
1376                                                                                                                                 (void*)$5);
1377                                                                                            }
1378                 | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
1379                 | SEND LPAREN error RPAREN { $$=0; yyerror("bad send"
1380                                                                                                         "argument"); }
1381                 | SEND_TCP LPAREN host RPAREN   { $$=mk_action( SEND_TCP_T,
1382                                                                                                         STRING_ST,
1383                                                                                                         NUMBER_ST,
1384                                                                                                         $3,
1385                                                                                                         0);
1386                                                                         }
1387                 | SEND_TCP LPAREN STRING RPAREN { $$=mk_action( SEND_TCP_T,
1388                                                                                                         STRING_ST,
1389                                                                                                         NUMBER_ST,
1390                                                                                                         $3,
1391                                                                                                         0);
1392                                                                         }
1393                 | SEND_TCP LPAREN ip RPAREN             { $$=mk_action( SEND_TCP_T,
1394                                                                                                         IP_ST,
1395                                                                                                         NUMBER_ST,
1396                                                                                                         (void*)$3,
1397                                                                                                         0);
1398                                                                         }
1399                 | SEND_TCP LPAREN host COMMA NUMBER RPAREN      { $$=mk_action( SEND_TCP_T,
1400                                                                                                                                 STRING_ST,
1401                                                                                                                                 NUMBER_ST,
1402                                                                                                                                 $3,
1403                                                                                                                                 (void*)$5);
1404                                                                                                 }
1405                 | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(     SEND_TCP_T,
1406                                                                                                                                 STRING_ST,
1407                                                                                                                                 NUMBER_ST,
1408                                                                                                                                 $3,
1409                                                                                                                                 (void*)$5);
1410                                                                                                 }
1411                 | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(        SEND_TCP_T,
1412                                                                                                                                 IP_ST,
1413                                                                                                                                 NUMBER_ST,
1414                                                                                                                                 (void*)$3,
1415                                                                                                                                 (void*)$5);
1416                                                                                            }
1417                 | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
1418                 | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp"
1419                                                                                                         "argument"); }
1420                 | DROP LPAREN RPAREN    {$$=mk_action(DROP_T,0, 0, 0, 0); }
1421                 | DROP                                  {$$=mk_action(DROP_T,0, 0, 0, 0); }
1422                 | LOG_TOK LPAREN STRING RPAREN  {$$=mk_action(  LOG_T, NUMBER_ST, 
1423                                                                                                         STRING_ST,(void*)4,$3);
1424                                                                         }
1425                 | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN     {$$=mk_action(  LOG_T,
1426                                                                                                                                 NUMBER_ST, 
1427                                                                                                                                 STRING_ST,
1428                                                                                                                                 (void*)$3,
1429                                                                                                                                 $5);
1430                                                                                                 }
1431                 | LOG_TOK error { $$=0; yyerror("missing '(' or ')' ?"); }
1432                 | LOG_TOK LPAREN error RPAREN { $$=0; yyerror("bad log"
1433                                                                         "argument"); }
1434                 | SETFLAG LPAREN NUMBER RPAREN {$$=mk_action( SETFLAG_T, NUMBER_ST, 0,
1435                                                                                                         (void *)$3, 0 ); }
1436                 | SETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
1437                 | RESETFLAG LPAREN NUMBER RPAREN {$$=mk_action( RESETFLAG_T, NUMBER_ST, 0,
1438                                                                                                         (void *)$3, 0 ); }
1439                 | RESETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
1440                 | ISFLAGSET LPAREN NUMBER RPAREN {$$=mk_action( ISFLAGSET_T, NUMBER_ST, 0,
1441                                                                                                         (void *)$3, 0 ); }
1442                 | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
1443                 | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T,
1444                                                                                                                                 STRING_ST, 
1445                                                                                                                                 STRING_ST,
1446                                                                                                                                 $3,
1447                                                                                                                                 $5);
1448                                                                                                   }
1449                 | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
1450                 | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error"
1451                                                                                                                 "argument"); }
1452                 | ROUTE LPAREN NUMBER RPAREN    { $$=mk_action(ROUTE_T, NUMBER_ST,
1453                                                                                                                 0, (void*)$3, 0);
1454                                                                                 }
1455                 | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
1456                 | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route"
1457                                                 "argument"); }
1458                 | EXEC LPAREN STRING RPAREN     { $$=mk_action( EXEC_T, STRING_ST, 0,
1459                                                                                                         $3, 0);
1460                                                                         }
1461                 | SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, STRING_ST,
1462                                                                                                                 0, $3, 0); }
1463                 | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
1464                 | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1465                                                                                                                 "string expected"); }
1466
1467                 | PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, STRING_ST,
1468                                                                                                                 0, $3, 0); }
1469                 | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
1470                 | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1471                                                                                                                 "string expected"); }
1472                 | STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 
1473                                                                         NUMBER_ST, 0, (void *) $3, 0); }
1474                 | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
1475                 | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1476                                                                                                                 "number expected"); }
1477
1478                 | STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, NUMBER_ST,
1479                                                                                                                 0, (void *) $3, 0); }
1480                 | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
1481                 | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1482                                                                                                                 "number expected"); }
1483                 | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN { 
1484                     {   qvalue_t q;
1485                         if (str2q(&q, $5, strlen($5)) < 0) {
1486                                 yyerror("bad argument, q value expected");
1487                         }
1488                         $$=mk_action(APPEND_BRANCH_T, STRING_ST, NUMBER_ST, $3, (void *)q); } 
1489                 }
1490         
1491                 | APPEND_BRANCH LPAREN STRING RPAREN { $$=mk_action( APPEND_BRANCH_T,
1492                                                                                                         STRING_ST, NUMBER_ST, $3, (void *)Q_UNSPECIFIED) ; }
1493                 | APPEND_BRANCH LPAREN RPAREN { $$=mk_action( APPEND_BRANCH_T,
1494                                                                                                         STRING_ST, NUMBER_ST, 0, (void *)Q_UNSPECIFIED ) ; }
1495                 | APPEND_BRANCH {  $$=mk_action( APPEND_BRANCH_T, STRING_ST, 0, 0, 0 ) ; }
1496
1497                 | SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action( SET_HOSTPORT_T, 
1498                                                                                                                 STRING_ST, 0, $3, 0); }
1499                 | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
1500                 | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument,"
1501                                                                                                 " string expected"); }
1502                 | SET_PORT LPAREN STRING RPAREN { $$=mk_action( SET_PORT_T, STRING_ST,
1503                                                                                                                 0, $3, 0); }
1504                 | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
1505                 | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1506                                                                                                                 "string expected"); }
1507                 | SET_USER LPAREN STRING RPAREN { $$=mk_action( SET_USER_T, STRING_ST,
1508                                                                                                                 0, $3, 0); }
1509                 | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
1510                 | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1511                                                                                                                 "string expected"); }
1512                 | SET_USERPASS LPAREN STRING RPAREN { $$=mk_action( SET_USERPASS_T, 
1513                                                                                                                 STRING_ST, 0, $3, 0); }
1514                 | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
1515                 | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1516                                                                                                                 "string expected"); }
1517                 | SET_URI LPAREN STRING RPAREN { $$=mk_action( SET_URI_T, STRING_ST, 
1518                                                                                                                 0, $3, 0); }
1519                 | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
1520                 | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1521                                                                                 "string expected"); }
1522                 | REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1523                 | REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1524                 | FORCE_RPORT LPAREN RPAREN     {
1525                                                         #ifdef USE_TCP
1526                                                                 $$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); 
1527                                                         #else
1528                                                                 yyerror("tcp support not compiled in");
1529                                                         #endif
1530                                                         }
1531                 | FORCE_RPORT                           {$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1532                 | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN  {
1533                                         #ifdef USE_TCP
1534                                                 $$=mk_action(FORCE_TCP_ALIAS_T,NUMBER_ST, 0,
1535                                                                                 (void*)$3, 0);
1536                                         #else
1537                                                 yyerror("tcp support not compiled in");
1538                                         #endif
1539                                                                                                 }
1540                 | FORCE_TCP_ALIAS LPAREN RPAREN {
1541                                         #ifdef USE_TCP
1542                                                 $$=mk_action(FORCE_TCP_ALIAS_T,0, 0, 0, 0); 
1543                                         #else
1544                                                 yyerror("tcp support not compiled in");
1545                                         #endif
1546                                                                                 }
1547                 | FORCE_TCP_ALIAS                               {
1548                                         #ifdef USE_TCP
1549                                                 $$=mk_action(FORCE_TCP_ALIAS_T,0, 0, 0, 0);
1550                                         #else
1551                                                 yyerror("tcp support not compiled in");
1552                                         #endif
1553                                                                                 }
1554                 | FORCE_TCP_ALIAS LPAREN error RPAREN   {$$=0; 
1555                                         yyerror("bad argument, number expected");
1556                                         }
1557                 | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1558                                                                 $$=0;
1559                                                                 if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1560                                                                                 LOG(L_CRIT, "ERROR: cfg. parser:"
1561                                                                                                         " out of memory.\n");
1562                                                                 }else{
1563                                                                                 str_tmp->s=$3;
1564                                                                                 str_tmp->len=strlen($3);
1565                                                                                 $$=mk_action(SET_ADV_ADDR_T, STR_ST,
1566                                                                                              0, str_tmp, 0);
1567                                                                 }
1568                                                                                                   }
1569                 | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1570                                                                                                                 "string expected"); }
1571                 | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
1572                 | SET_ADV_PORT LPAREN NUMBER RPAREN {
1573                                                                 $$=0;
1574                                                                 tmp=int2str($3, &i_tmp);
1575                                                                 if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1576                                                                                 LOG(L_CRIT, "ERROR: cfg. parser:"
1577                                                                                                         " out of memory.\n");
1578                                                                 }else{
1579                                                                         if ((str_tmp->s=pkg_malloc(i_tmp))==0){
1580                                                                                 LOG(L_CRIT, "ERROR: cfg. parser:"
1581                                                                                                         " out of memory.\n");
1582                                                                         }else{
1583                                                                                 memcpy(str_tmp->s, tmp, i_tmp);
1584                                                                                 str_tmp->len=i_tmp;
1585                                                                                 $$=mk_action(SET_ADV_PORT_T, STR_ST,
1586                                                                                                         0, str_tmp, 0);
1587                                                                         }
1588                                                                 }
1589                                                                             }
1590                 | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1591                                                                                                                 "string expected"); }
1592                 | SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
1593                 | ID LPAREN RPAREN                      { f_tmp=(void*)find_export($1, 0, rt);
1594                                                                            if (f_tmp==0){
1595                                                                                    if (find_export($1, 0, 0)) {
1596                                                                                            yyerror("Command cannot be used in the block\n");
1597                                                                                    } else {
1598                                                                                            yyerror("unknown command, missing"
1599                                                                                                    " loadmodule?\n");
1600                                                                                    }
1601                                                                                 $$=0;
1602                                                                            }else{
1603                                                                                 $$=mk_action(   MODULE_T,
1604                                                                                                                 CMDF_ST,
1605                                                                                                                 0,
1606                                                                                                                 f_tmp,
1607                                                                                                                 0
1608                                                                                                         );
1609                                                                            }
1610                                                                         }
1611                 | ID LPAREN STRING RPAREN { f_tmp=(void*)find_export($1, 1, rt);
1612                                                                         if (f_tmp==0){
1613                                                                                 if (find_export($1, 1, 0)) {
1614                                                                                         yyerror("Command cannot be used in the block\n");
1615                                                                                 } else {
1616                                                                                         yyerror("unknown command, missing"
1617                                                                                                 " loadmodule?\n");
1618                                                                                 }
1619                                                                                 $$=0;
1620                                                                         }else{
1621                                                                                 $$=mk_action(   MODULE_T,
1622                                                                                                                 CMDF_ST,
1623                                                                                                                 STRING_ST,
1624                                                                                                                 f_tmp,
1625                                                                                                                 $3
1626                                                                                                         );
1627                                                                         }
1628                                                                   }
1629                 | ID LPAREN STRING  COMMA STRING RPAREN 
1630                                                                   { f_tmp=(void*)find_export($1, 2, rt);
1631                                                                         if (f_tmp==0){
1632                                                                                 if (find_export($1, 2, 0)) {
1633                                                                                         yyerror("Command cannot be used in the block\n");
1634                                                                                 } else {
1635                                                                                         yyerror("unknown command, missing"
1636                                                                                                 " loadmodule?\n");
1637                                                                                 }
1638                                                                                 $$=0;
1639                                                                         }else{
1640                                                                                 $$=mk_action3(  MODULE_T,
1641                                                                                                                 CMDF_ST,
1642                                                                                                                 STRING_ST,
1643                                                                                                                 STRING_ST,
1644                                                                                                                 f_tmp,
1645                                                                                                                 $3,
1646                                                                                                                 $5
1647                                                                                                         );
1648                                                                         }
1649                                                                   }
1650                 | ID LPAREN error RPAREN { $$=0; yyerror("bad arguments"); }
1651         ;
1652
1653
1654 %%
1655
1656 extern int line;
1657 extern int column;
1658 extern int startcolumn;
1659 static void warn(char* s)
1660 {
1661         LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n", line, startcolumn, 
1662                         column, s);
1663         cfg_errors++;
1664 }
1665
1666 static void yyerror(char* s)
1667 {
1668         LOG(L_CRIT, "parse error (%d,%d-%d): %s\n", line, startcolumn, 
1669                         column, s);
1670         cfg_errors++;
1671 }
1672
1673
1674 static struct id_list* mk_listen_id(char* host, int proto, int port)
1675 {
1676         struct id_list* l;
1677         l=pkg_malloc(sizeof(struct id_list));
1678         if (l==0){
1679                 LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1680         }else{
1681                 l->name=host;
1682                 l->port=port;
1683                 l->proto=proto;
1684                 l->next=0;
1685         }
1686         return l;
1687 }
1688
1689
1690 /*
1691 int main(int argc, char ** argv)
1692 {
1693         if (yyparse()!=0)
1694                 fprintf(stderr, "parsing error\n");
1695 }
1696 */