PageRenderTime 21ms CodeModel.GetById 3ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/cfg.y

https://bitbucket.org/viraptor/opensips-mirror
Happy | 2510 lines | 2374 code | 136 blank | 0 comment | 0 complexity | d444a1806e877ef5f6df0e2cd1413a9e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * $Id$
   3 *
   4 *  cfg grammar
   5 *
   6 * Copyright (C) 2001-2003 FhG Fokus
   7 * Copyright (C) 2005-2009 Voice Sistem S.R.L.
   8 * Copyright (C) 2006 enum.at
   9 *
  10 * This file is part of opensips, a free SIP server.
  11 *
  12 * opensips is free software; you can redistribute it and/or modify
  13 * it under the terms of the GNU General Public License as published by
  14 * the Free Software Foundation; either version 2 of the License, or
  15 * (at your option) any later version
  16 *
  17 * opensips is distributed in the hope that it will be useful,
  18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20 * GNU General Public License for more details.
  21 *
  22 * You should have received a copy of the GNU General Public License 
  23 * along with this program; if not, write to the Free Software 
  24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25 */
  26 /*
  27 * History:
  28 * ---------
  29 * 2003-01-29  src_port added (jiri)
  30 * 2003-01-23  mhomed added (jiri)
  31 * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  32 * 2003-03-19  Added support for route type in find_export (janakj)
  33 * 2003-03-20  Regex support in modparam (janakj)
  34 * 2003-04-01  added dst_port, proto , af (andrei)
  35 * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
  36 * 2003-04-12  added force_rport, chroot and wdir (andrei)
  37 * 2003-04-15  added tcp_children, disable_tcp (andrei)
  38 * 2003-04-22  strip_tail added (jiri)
  39 * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
  40 *              require_certificate added (andrei)
  41 * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
  42 * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
  43 * 2003-10-10  added <,>,<=,>=, != operators support
  44 *             added msg:len (andrei)
  45 * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
  46 * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
  47 * 2003-10-24  converted to the new socket_info lists (andrei)
  48 * 2003-10-28  added tcp_accept_aliases (andrei)
  49 * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
  50 * 2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
  51 * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
  52 * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
  53               added MCAST_TTL (andrei)
  54 * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
  55 *              (andrei)
  56 * 2004-10-19  added FROM_URI, TO_URI (andrei)
  57 * 2004-11-30  added force_send_socket (andrei)
  58 * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
  59 *              (andrei)
  60 * 2005-07-26  default onreply route added (andrei)
  61 * 2005-11-22  added tos configurability (thanks to Andreas Granig)
  62 * 2005-11-29  added serialize_branches and next_branches (bogdan)
  63 * 2006-03-02  MODULE_T action points to a cmd_export_t struct instead to 
  64 *              a function address - more info is accessible (bogdan)
  65 * 2006-03-02  store the cfg line into the action struct to be able to
  66 *              give more hints if fixups fail (bogdan)
  67 * 2006-05-22  forward(_udp,_tcp,_tls) and send(_tcp) merged in forward() and
  68 *              send() (bogdan)
  69 *  2006-12-22  functions for script and branch flags added (bogdan)
  70 *  2007-01-11  auto_aliases option added (bogdan)
  71 *  2007-01-25  disable_dns_failover option added (bogdan)
  72 */
  73
  74
  75%{
  76
  77#include <stdlib.h>
  78#include <stdio.h>
  79#include <sys/types.h>
  80#include <sys/socket.h>
  81#include <sys/stat.h>
  82#include <unistd.h>
  83#include <netinet/in.h>
  84#include <netinet/in_systm.h>
  85#include <netinet/ip.h>
  86#include <arpa/inet.h>
  87#include <string.h>
  88#include <errno.h>
  89#include "route_struct.h"
  90#include "globals.h"
  91#include "route.h"
  92#include "dprint.h"
  93#include "sr_module.h"
  94#include "modparam.h"
  95#include "ip_addr.h"
  96#include "resolve.h"
  97#include "socket_info.h"
  98#include "name_alias.h"
  99#include "ut.h"
 100#include "dset.h"
 101#include "pvar.h"
 102#include "blacklists.h"
 103#include "xlog.h"
 104
 105
 106#include "config.h"
 107#ifdef USE_TLS
 108#include "tls/tls_config.h"
 109#include "tls/tls_domain.h"
 110#endif
 111
 112#ifdef DEBUG_DMALLOC
 113#include <dmalloc.h>
 114#endif
 115
 116/* hack to avoid alloca usage in the generated C file (needed for compiler
 117 with no built in alloca, like icc*/
 118#undef _ALLOCA_H
 119
 120
 121extern int yylex();
 122static void yyerror(char* s);
 123static void yyerrorf(char* fmt, ...);
 124static char* tmp;
 125static int i_tmp;
 126static void* cmd_tmp;
 127static struct socket_id* lst_tmp;
 128static int rt;  /* Type of route block for find_export */
 129static str* str_tmp;
 130static str s_tmp;
 131static str tstr;
 132static struct ip_addr* ip_tmp;
 133static pv_spec_t *spec;
 134static pv_elem_t *pvmodel;
 135static struct bl_rule *bl_head = 0;
 136static struct bl_rule *bl_tail = 0;
 137static struct stat statf;
 138
 139action_elem_t elems[MAX_ACTION_ELEMS];
 140
 141#if !defined(USE_TLS) || !defined(USE_TCP) ||  !defined(USE_MCAST)
 142static void warn(char* s);
 143#endif
 144static struct socket_id* mk_listen_id(char*, int, int);
 145static struct socket_id* set_listen_id_adv(struct socket_id *, char *, int);
 146
 147static char *mpath=NULL;
 148static char mpath_buf[256];
 149static int  mpath_len = 0;
 150
 151extern int line;
 152
 153#define mk_action0(_res, _type, _p1_type, _p2_type, _p1, _p2) \
 154	do { \
 155		_res = mk_action(_type, 0, 0, line); \
 156	} while(0)
 157#define mk_action1(_res, _type, _p1_type, _p1) \
 158	do { \
 159		elems[0].type = _p1_type; \
 160		elems[0].u.data = _p1; \
 161		_res = mk_action(_type, 1, elems, line); \
 162	} while(0)
 163#define	mk_action2(_res, _type, _p1_type, _p2_type, _p1, _p2) \
 164	do { \
 165		elems[0].type = _p1_type; \
 166		elems[0].u.data = _p1; \
 167		elems[1].type = _p2_type; \
 168		elems[1].u.data = _p2; \
 169		_res = mk_action(_type, 2, elems, line); \
 170	} while(0)
 171#define mk_action3(_res, _type, _p1_type, _p2_type, _p3_type, _p1, _p2, _p3) \
 172	do { \
 173		elems[0].type = _p1_type; \
 174		elems[0].u.data = _p1; \
 175		elems[1].type = _p2_type; \
 176		elems[1].u.data = _p2; \
 177		elems[2].type = _p3_type; \
 178		elems[2].u.data = _p3; \
 179		_res = mk_action(_type, 3, elems, line); \
 180	} while(0)
 181
 182%}
 183
 184%union {
 185	long intval;
 186	unsigned long uval;
 187	char* strval;
 188	struct expr* expr;
 189	struct action* action;
 190	struct net* ipnet;
 191	struct ip_addr* ipaddr;
 192	struct socket_id* sockid;
 193	struct _pv_spec *specval;
 194}
 195
 196/* terminals */
 197
 198
 199/* keywords */
 200%token FORWARD
 201%token SEND
 202%token DROP
 203%token EXIT
 204%token RETURN
 205%token LOG_TOK
 206%token ERROR
 207%token ROUTE
 208%token ROUTE_FAILURE
 209%token ROUTE_ONREPLY
 210%token ROUTE_BRANCH
 211%token ROUTE_ERROR
 212%token ROUTE_LOCAL
 213%token ROUTE_STARTUP
 214%token ROUTE_TIMER
 215%token SET_HOST
 216%token SET_HOSTPORT
 217%token PREFIX
 218%token STRIP
 219%token STRIP_TAIL
 220%token APPEND_BRANCH
 221%token PV_PRINTF
 222%token SET_USER
 223%token SET_USERPASS
 224%token SET_PORT
 225%token SET_URI
 226%token REVERT_URI
 227%token SET_DSTURI
 228%token RESET_DSTURI
 229%token ISDSTURISET
 230%token FORCE_RPORT
 231%token FORCE_LOCAL_RPORT
 232%token FORCE_TCP_ALIAS
 233%token IF
 234%token ELSE
 235%token SWITCH
 236%token CASE
 237%token DEFAULT
 238%token SBREAK
 239%token WHILE
 240%token SET_ADV_ADDRESS
 241%token SET_ADV_PORT
 242%token FORCE_SEND_SOCKET
 243%token SERIALIZE_BRANCHES
 244%token NEXT_BRANCHES
 245%token USE_BLACKLIST
 246%token UNUSE_BLACKLIST
 247%token MAX_LEN
 248%token SETDEBUG
 249%token SETFLAG
 250%token RESETFLAG
 251%token ISFLAGSET
 252%token SETBFLAG
 253%token RESETBFLAG
 254%token ISBFLAGSET
 255%token SETSFLAG
 256%token RESETSFLAG
 257%token ISSFLAGSET
 258%token METHOD
 259%token URI
 260%token FROM_URI
 261%token TO_URI
 262%token SRCIP
 263%token SRCPORT
 264%token DSTIP
 265%token DSTPORT
 266%token PROTO
 267%token AF
 268%token MYSELF
 269%token MSGLEN 
 270%token UDP
 271%token TCP
 272%token TLS
 273%token SCTP
 274%token NULLV
 275%token CACHE_STORE
 276%token CACHE_FETCH
 277%token CACHE_REMOVE
 278%token XDBG
 279%token XLOG
 280%token XLOG_BUF_SIZE
 281%token XLOG_FORCE_COLOR
 282
 283/* config vars. */
 284%token DEBUG
 285%token FORK
 286%token LOGSTDERROR
 287%token LOGFACILITY
 288%token LOGNAME
 289%token AVP_ALIASES
 290%token LISTEN
 291%token ALIAS
 292%token AUTO_ALIASES
 293%token DNS
 294%token REV_DNS
 295%token DNS_TRY_IPV6
 296%token DNS_RETR_TIME
 297%token DNS_RETR_NO
 298%token DNS_SERVERS_NO
 299%token DNS_USE_SEARCH
 300%token MAX_WHILE_LOOPS
 301%token PORT
 302%token CHILDREN
 303%token CHECK_VIA
 304%token MEMLOG
 305%token MEMDUMP
 306%token SIP_WARNING
 307%token SOCK_MODE
 308%token SOCK_USER
 309%token SOCK_GROUP
 310%token UNIX_SOCK
 311%token UNIX_SOCK_CHILDREN
 312%token UNIX_TX_TIMEOUT
 313%token SERVER_SIGNATURE
 314%token SERVER_HEADER
 315%token USER_AGENT_HEADER
 316%token LOADMODULE
 317%token MPATH
 318%token MODPARAM
 319%token MAXBUFFER
 320%token USER
 321%token GROUP
 322%token CHROOT
 323%token WDIR
 324%token MHOMED
 325%token DISABLE_TCP
 326%token TCP_ACCEPT_ALIASES
 327%token TCP_CHILDREN
 328%token TCP_CONNECT_TIMEOUT
 329%token TCP_SEND_TIMEOUT
 330%token TCP_CON_LIFETIME
 331%token TCP_POLL_METHOD
 332%token TCP_MAX_CONNECTIONS
 333%token TCP_OPT_CRLF_PINGPONG
 334%token DISABLE_TLS
 335%token TLSLOG
 336%token TLS_PORT_NO
 337%token TLS_METHOD
 338%token TLS_HANDSHAKE_TIMEOUT
 339%token TLS_SEND_TIMEOUT
 340%token TLS_SERVER_DOMAIN
 341%token TLS_CLIENT_DOMAIN
 342%token TLS_CLIENT_DOMAIN_AVP
 343%token SSLv23
 344%token SSLv2
 345%token SSLv3
 346%token TLSv1
 347%token TLS_VERIFY_CLIENT
 348%token TLS_VERIFY_SERVER
 349%token TLS_REQUIRE_CLIENT_CERTIFICATE
 350%token TLS_CERTIFICATE
 351%token TLS_PRIVATE_KEY
 352%token TLS_CA_LIST
 353%token TLS_CIPHERS_LIST
 354%token ADVERTISED_ADDRESS
 355%token ADVERTISED_PORT
 356%token DISABLE_CORE
 357%token OPEN_FD_LIMIT
 358%token MCAST_LOOPBACK
 359%token MCAST_TTL
 360%token TOS
 361%token DISABLE_DNS_FAILOVER
 362%token DISABLE_DNS_BLACKLIST
 363%token DST_BLACKLIST
 364%token DISABLE_STATELESS_FWD
 365%token DB_VERSION_TABLE
 366
 367
 368
 369
 370/* operators */
 371%nonassoc EQUAL
 372%nonassoc EQUAL_T
 373%nonassoc GT
 374%nonassoc LT
 375%nonassoc GTE
 376%nonassoc LTE
 377%nonassoc DIFF
 378%nonassoc MATCH
 379%nonassoc NOTMATCH
 380%nonassoc COLONEQ
 381%nonassoc PLUSEQ
 382%nonassoc MINUSEQ
 383%nonassoc SLASHEQ
 384%nonassoc MULTEQ
 385%nonassoc MODULOEQ
 386%nonassoc BANDEQ
 387%nonassoc BOREQ
 388%nonassoc BXOREQ
 389
 390%left OR AND
 391%left BOR BAND BXOR BLSHIFT BRSHIFT
 392%left PLUS MINUS SLASH MULT MODULO
 393%right NOT BNOT
 394
 395/* values */
 396%token <intval> NUMBER
 397%token <intval> ZERO
 398%token <strval> ID
 399%token <strval> STRING
 400%token <strval> SCRIPTVAR
 401%token <strval> IPV6ADDR
 402
 403/* other */
 404%token COMMA
 405%token SEMICOLON
 406%token RPAREN
 407%token LPAREN
 408%token LBRACE
 409%token RBRACE
 410%token LBRACK
 411%token RBRACK
 412%token SLASH
 413%token AS
 414%token DOT
 415%token CR
 416%token COLON
 417%token ANY
 418%token SCRIPTVARERR
 419
 420
 421/*non-terminals */
 422%type <expr> exp exp_elem exp_cond assignexp /*, condition*/
 423%type <action> action actions cmd if_cmd stm exp_stm assign_cmd while_cmd
 424%type <action> switch_cmd switch_stm case_stms case_stm default_stm
 425%type <intval> module_func_param
 426%type <ipaddr> ipv4 ipv6 ipv6addr ip
 427%type <ipnet> ipnet
 428%type <specval> script_var
 429%type <strval> host
 430%type <strval> listen_id
 431%type <sockid> id_lst
 432%type <sockid> phostport
 433%type <intval> proto port
 434%type <strval> host_sep
 435%type <intval> uri_type
 436%type <intval> equalop compop matchop strop intop
 437%type <intval> assignop
 438%type <intval> snumber
 439%type <strval> route_name
 440
 441
 442
 443%%
 444
 445
 446cfg:	statements
 447	;
 448
 449statements:	statements statement {}
 450		| statement {}
 451		| statements error { yyerror(""); YYABORT;}
 452	;
 453
 454statement:	assign_stm 
 455		| module_stm
 456		| {rt=REQUEST_ROUTE;} route_stm 
 457		| {rt=FAILURE_ROUTE;} failure_route_stm
 458		| {rt=ONREPLY_ROUTE;} onreply_route_stm
 459		| {rt=BRANCH_ROUTE;} branch_route_stm
 460		| {rt=ERROR_ROUTE;} error_route_stm
 461		| {rt=LOCAL_ROUTE;} local_route_stm
 462		| {rt=STARTUP_ROUTE;} startup_route_stm
 463		| {rt=TIMER_ROUTE;} timer_route_stm
 464
 465		| CR	/* null statement*/
 466	;
 467
 468listen_id:	ip			{	tmp=ip_addr2a($1);
 469							if(tmp==0){
 470								LM_CRIT("cfg. parser: bad ip address.\n");
 471								$$=0;
 472							}else{
 473								$$=pkg_malloc(strlen(tmp)+1);
 474								if ($$==0){
 475									LM_CRIT("cfg. parser: out of memory.\n");
 476								}else{
 477									strncpy($$, tmp, strlen(tmp)+1);
 478								}
 479							}
 480						}
 481		|	STRING			{	$$=pkg_malloc(strlen($1)+1);
 482							if ($$==0){
 483									LM_CRIT("cfg. parser: out of memory.\n");
 484							}else{
 485									strncpy($$, $1, strlen($1)+1);
 486							}
 487						}
 488		|	host		{	if ($1==0) {
 489								$$ = 0;
 490							} else {
 491								$$=pkg_malloc(strlen($1)+1);
 492								if ($$==0){
 493									LM_CRIT("cfg. parser: out of memory.\n");
 494								}else{
 495									strncpy($$, $1, strlen($1)+1);
 496								}
 497							}
 498						}
 499	;
 500
 501proto:	  UDP	{ $$=PROTO_UDP; }
 502		| TCP	{ $$=PROTO_TCP; }
 503		| TLS	{
 504			#ifdef USE_TLS
 505				$$=PROTO_TLS;
 506			#else
 507				$$=PROTO_TCP;
 508				warn("tls support not compiled in");
 509			#endif
 510			}
 511		| SCTP  { 
 512			#ifdef USE_SCTP
 513				$$=PROTO_SCTP;
 514			#else
 515				yyerror("sctp support not compiled in\n");YYABORT;
 516			#endif
 517			}
 518		| ANY	{ $$=0; }
 519		;
 520
 521port:	  NUMBER	{ $$=$1; }
 522		| ANY		{ $$=0; }
 523;
 524
 525snumber:	NUMBER	{ $$=$1; }
 526		| PLUS NUMBER	{ $$=$2; }
 527		| MINUS NUMBER	{ $$=-$2; }
 528;
 529
 530
 531phostport:	listen_id				{ $$=mk_listen_id($1, 0, 0); }
 532			| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
 533			| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
 534			| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
 535			| phostport AS listen_id { set_listen_id_adv((struct socket_id *)$1, $3, 5060); }
 536			| phostport AS listen_id COLON port{ set_listen_id_adv((struct socket_id *)$1, $3, $5); }
 537			| listen_id COLON error { $$=0; yyerror(" port number expected"); }
 538			;
 539
 540id_lst:		phostport		{  $$=$1 ; }
 541		| phostport id_lst	{ $$=$1; $$->next=$2; }
 542		;
 543
 544
 545blst_elem: LPAREN  proto COMMA ipnet COMMA port COMMA STRING RPAREN {
 546				s_tmp.s=$8;
 547				s_tmp.len=strlen($8);
 548				if (add_rule_to_list(&bl_head,&bl_tail,$4,&s_tmp,$6,$2,0)) {
 549					yyerror("failed to add backlist element\n");YYABORT;
 550				}
 551			}
 552		| NOT  LPAREN  proto COMMA ipnet COMMA port COMMA STRING RPAREN {
 553				s_tmp.s=$9;
 554				s_tmp.len=strlen($9);
 555				if (add_rule_to_list(&bl_head,&bl_tail,$5,&s_tmp,
 556				$7,$3,BLR_APPLY_CONTRARY)) {
 557					yyerror("failed to add backlist element\n");YYABORT;
 558				}
 559			}
 560		;
 561
 562blst_elem_list: blst_elem_list COMMA blst_elem {}
 563		| blst_elem {}
 564		| blst_elem_list error { yyerror("bad black list element");}
 565		;
 566
 567
 568assign_stm: DEBUG EQUAL snumber { 
 569#ifdef CHANGEABLE_DEBUG_LEVEL
 570					*debug=$3;
 571#else
 572					debug=$3;
 573#endif
 574			}
 575		| DEBUG EQUAL error  { yyerror("number  expected"); }
 576		| FORK  EQUAL NUMBER { dont_fork= ! $3; }
 577		| FORK  EQUAL error  { yyerror("boolean value expected"); }
 578		| LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
 579		| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
 580		| LOGFACILITY EQUAL ID {
 581					if ( (i_tmp=str2facility($3))==-1)
 582						yyerror("bad facility (see syslog(3) man page)");
 583					if (!config_check)
 584						log_facility=i_tmp;
 585									}
 586		| LOGFACILITY EQUAL error { yyerror("ID expected"); }
 587		| LOGNAME EQUAL STRING { log_name=$3; }
 588		| LOGNAME EQUAL error { yyerror("string value expected"); }
 589		| AVP_ALIASES EQUAL STRING { 
 590				if ($3!=0 && $3[0]!=0)
 591					if ( add_avp_galias_str($3)!=0 )
 592						yyerror("invalid AVP aliases");;
 593			}
 594		| AVP_ALIASES EQUAL error { yyerror("string value expected"); }
 595		| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
 596		| DNS EQUAL error { yyerror("boolean value expected"); }
 597		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
 598		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
 599		| DNS_TRY_IPV6 EQUAL NUMBER   { dns_try_ipv6=$3; }
 600		| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
 601		| DNS_RETR_TIME EQUAL NUMBER   { dns_retr_time=$3; }
 602		| DNS_RETR_TIME error { yyerror("number expected"); }
 603		| DNS_RETR_NO EQUAL NUMBER   { dns_retr_no=$3; }
 604		| DNS_RETR_NO error { yyerror("number expected"); }
 605		| DNS_SERVERS_NO EQUAL NUMBER   { dns_servers_no=$3; }
 606		| DNS_SERVERS_NO error { yyerror("number expected"); }
 607		| DNS_USE_SEARCH EQUAL NUMBER   { dns_search_list=$3; }
 608		| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
 609		| PORT EQUAL NUMBER   { port_no=$3; }
 610		| PORT EQUAL error    { yyerror("number expected"); } 
 611		| MAX_WHILE_LOOPS EQUAL NUMBER { max_while_loops=$3; }
 612		| MAX_WHILE_LOOPS EQUAL error { yyerror("number expected"); } 
 613		| MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
 614		| MAXBUFFER EQUAL error { yyerror("number expected"); }
 615		| CHILDREN EQUAL NUMBER { children_no=$3; }
 616		| CHILDREN EQUAL error { yyerror("number expected"); } 
 617		| CHECK_VIA EQUAL NUMBER { check_via=$3; }
 618		| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
 619		| MEMLOG EQUAL NUMBER { memlog=$3; memdump=$3; }
 620		| MEMLOG EQUAL error { yyerror("int value expected"); }
 621		| MEMDUMP EQUAL NUMBER { memdump=$3; }
 622		| MEMDUMP EQUAL error { yyerror("int value expected"); }
 623		| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
 624		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
 625		| USER EQUAL STRING     { user=$3; }
 626		| USER EQUAL ID         { user=$3; }
 627		| USER EQUAL error      { yyerror("string value expected"); }
 628		| GROUP EQUAL STRING     { group=$3; }
 629		| GROUP EQUAL ID         { group=$3; }
 630		| GROUP EQUAL error      { yyerror("string value expected"); }
 631		| CHROOT EQUAL STRING     { chroot_dir=$3; }
 632		| CHROOT EQUAL ID         { chroot_dir=$3; }
 633		| CHROOT EQUAL error      { yyerror("string value expected"); }
 634		| WDIR EQUAL STRING     { working_dir=$3; }
 635		| WDIR EQUAL ID         { working_dir=$3; }
 636		| WDIR EQUAL error      { yyerror("string value expected"); }
 637		| MHOMED EQUAL NUMBER { mhomed=$3; }
 638		| MHOMED EQUAL error { yyerror("boolean value expected"); }
 639		| DISABLE_TCP EQUAL NUMBER {
 640									#ifdef USE_TCP
 641										tcp_disable=$3;
 642									#else
 643										warn("tcp support not compiled in");
 644									#endif
 645									}
 646		| DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
 647		| TCP_ACCEPT_ALIASES EQUAL NUMBER {
 648									#ifdef USE_TCP
 649										tcp_accept_aliases=$3;
 650									#else
 651										warn("tcp support not compiled in");
 652									#endif
 653									}
 654		| TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
 655		| TCP_CHILDREN EQUAL NUMBER {
 656									#ifdef USE_TCP
 657										tcp_children_no=$3;
 658									#else
 659										warn("tcp support not compiled in");
 660									#endif
 661									}
 662		| TCP_CHILDREN EQUAL error { yyerror("number expected"); }
 663		| TCP_CONNECT_TIMEOUT EQUAL NUMBER {
 664									#ifdef USE_TCP
 665										tcp_connect_timeout=$3;
 666									#else
 667										warn("tcp support not compiled in");
 668									#endif
 669									}
 670		| TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
 671		| TCP_SEND_TIMEOUT EQUAL NUMBER {
 672									#ifdef USE_TCP
 673										tcp_send_timeout=$3;
 674									#else
 675										warn("tcp support not compiled in");
 676									#endif
 677									}
 678		| TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
 679		| TCP_CON_LIFETIME EQUAL NUMBER {
 680									#ifdef USE_TCP
 681										tcp_con_lifetime=$3;
 682									#else
 683										warn("tcp support not compiled in");
 684									#endif
 685									}
 686		| TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
 687		| TCP_POLL_METHOD EQUAL ID {
 688									#ifdef USE_TCP
 689										tcp_poll_method=get_poll_type($3);
 690										if (tcp_poll_method==POLL_NONE){
 691											LM_CRIT("bad poll method name:"
 692												" %s\n, try one of %s.\n",
 693												$3, poll_support);
 694											yyerror("bad tcp_poll_method "
 695												"value");
 696										}
 697									#else
 698										warn("tcp support not compiled in");
 699									#endif
 700									}
 701		| TCP_POLL_METHOD EQUAL STRING {
 702									#ifdef USE_TCP
 703										tcp_poll_method=get_poll_type($3);
 704										if (tcp_poll_method==POLL_NONE){
 705											LM_CRIT("bad poll method name:"
 706												" %s\n, try one of %s.\n",
 707												$3, poll_support);
 708											yyerror("bad tcp_poll_method "
 709												"value");
 710										}
 711									#else
 712										warn("tcp support not compiled in");
 713									#endif
 714									}
 715		| TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
 716		| TCP_MAX_CONNECTIONS EQUAL NUMBER {
 717									#ifdef USE_TCP
 718										tcp_max_connections=$3;
 719									#else
 720										warn("tcp support not compiled in");
 721									#endif
 722									}
 723		| TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
 724		| TCP_OPT_CRLF_PINGPONG EQUAL NUMBER {
 725			#ifdef USE_TCP
 726				tcp_crlf_pingpong=$3;
 727			#else
 728				warn("tcp support not compiled in");
 729			#endif
 730		}
 731		| TCP_OPT_CRLF_PINGPONG EQUAL error { yyerror("boolean value expected"); }
 732		| DISABLE_TLS EQUAL NUMBER {
 733									#ifdef USE_TLS
 734										tls_disable=$3;
 735									#else
 736										warn("tls support not compiled in");
 737									#endif
 738									}
 739		| DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
 740		| TLSLOG EQUAL NUMBER 		{ 
 741									#ifdef USE_TLS
 742										tls_log=$3;
 743									#else
 744										warn("tls support not compiled in");
 745									#endif
 746									}
 747		| TLSLOG EQUAL error { yyerror("int value expected"); }
 748		| TLS_PORT_NO EQUAL NUMBER {
 749									#ifdef USE_TLS
 750										tls_port_no=$3;
 751									#else
 752										warn("tls support not compiled in");
 753									#endif
 754									}
 755		| TLS_PORT_NO EQUAL error { yyerror("number expected"); }
 756		| TLS_METHOD EQUAL SSLv23 {
 757									#ifdef USE_TLS
 758										tls_default_server_domain->method =
 759											TLS_USE_SSLv23;
 760										tls_default_client_domain->method =
 761											TLS_USE_SSLv23;
 762									#else
 763										warn("tls support not compiled in");
 764									#endif
 765									}
 766		| TLS_METHOD EQUAL SSLv2 {
 767									#ifdef USE_TLS
 768										tls_default_server_domain->method =
 769											TLS_USE_SSLv2;
 770										tls_default_client_domain->method =
 771											TLS_USE_SSLv2;
 772									#else
 773										warn("tls support not compiled in");
 774									#endif
 775									}
 776		| TLS_METHOD EQUAL SSLv3 {
 777									#ifdef USE_TLS
 778										tls_default_server_domain->method =
 779											TLS_USE_SSLv3;
 780										tls_default_client_domain->method =
 781											TLS_USE_SSLv3;
 782									#else
 783										warn("tls support not compiled in");
 784									#endif
 785									}
 786		| TLS_METHOD EQUAL TLSv1 {
 787									#ifdef USE_TLS
 788										tls_default_server_domain->method =
 789											TLS_USE_TLSv1;
 790										tls_default_client_domain->method =
 791											TLS_USE_TLSv1;
 792									#else
 793										warn("tls support not compiled in");
 794									#endif
 795									}
 796		| TLS_METHOD EQUAL error {
 797									#ifdef USE_TLS
 798										yyerror("SSLv23, SSLv2, SSLv3 or TLSv1"
 799													" expected");
 800									#else
 801										warn("tls support not compiled in");
 802									#endif
 803									}
 804										
 805		| TLS_VERIFY_CLIENT EQUAL NUMBER {
 806									#ifdef USE_TLS
 807										tls_default_server_domain->verify_cert
 808											= $3;
 809									#else
 810										warn("tls support not compiled in");
 811									#endif
 812									}
 813		| TLS_VERIFY_CLIENT EQUAL error { yyerror("boolean value expected"); }
 814		| TLS_VERIFY_SERVER EQUAL NUMBER {
 815									#ifdef USE_TLS
 816										tls_default_client_domain->verify_cert
 817											=$3;
 818									#else
 819										warn("tls support not compiled in");
 820									#endif
 821									}
 822		| TLS_VERIFY_SERVER EQUAL error { yyerror("boolean value expected"); }
 823		| TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL NUMBER {
 824									#ifdef USE_TLS
 825										tls_default_server_domain->require_client_cert=$3;
 826									#else
 827										warn( "tls support not compiled in");
 828									#endif
 829									}
 830		| TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
 831		| TLS_CERTIFICATE EQUAL STRING { 
 832									#ifdef USE_TLS
 833										tls_default_server_domain->cert_file=
 834											$3;
 835										tls_default_client_domain->cert_file=
 836											$3;
 837									#else
 838										warn("tls support not compiled in");
 839									#endif
 840									}
 841		| TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
 842		| TLS_PRIVATE_KEY EQUAL STRING { 
 843									#ifdef USE_TLS
 844										tls_default_server_domain->pkey_file=
 845											$3;
 846										tls_default_client_domain->pkey_file=
 847											$3;
 848									#else
 849										warn("tls support not compiled in");
 850									#endif
 851									}
 852		| TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
 853		| TLS_CA_LIST EQUAL STRING { 
 854									#ifdef USE_TLS
 855										tls_default_server_domain->ca_file =
 856											$3;
 857										tls_default_client_domain->ca_file =
 858											$3;
 859									#else
 860										warn("tls support not compiled in");
 861									#endif
 862									}
 863		| TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
 864		| TLS_CIPHERS_LIST EQUAL STRING { 
 865									#ifdef USE_TLS
 866										tls_default_server_domain->ciphers_list
 867											= $3;
 868										tls_default_client_domain->ciphers_list
 869											= $3;
 870									#else
 871										warn("tls support not compiled in");
 872									#endif
 873									}
 874		| TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
 875		| TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
 876									#ifdef USE_TLS
 877										tls_handshake_timeout=$3;
 878									#else
 879										warn("tls support not compiled in");
 880									#endif
 881									}
 882		| TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
 883		| TLS_SEND_TIMEOUT EQUAL NUMBER {
 884									#ifdef USE_TLS
 885										tls_send_timeout=$3;
 886									#else
 887										warn("tls support not compiled in");
 888									#endif
 889									}
 890		| TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
 891		| TLS_CLIENT_DOMAIN_AVP EQUAL NUMBER {
 892									#ifdef USE_TLS
 893										tls_client_domain_avp=$3;
 894									#else
 895										warn("tls support not compiled in");
 896									#endif
 897									}
 898		| TLS_CLIENT_DOMAIN_AVP EQUAL error { yyerror("number expected"); }
 899		| tls_server_domain_stm
 900		| tls_client_domain_stm
 901		| SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
 902		| SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
 903		| SERVER_HEADER EQUAL STRING { server_header.s=$3;
 904									server_header.len=strlen($3);
 905									}
 906		| SERVER_HEADER EQUAL error { yyerror("string value expected"); }
 907		| USER_AGENT_HEADER EQUAL STRING { user_agent_header.s=$3;
 908									user_agent_header.len=strlen($3);
 909									}
 910		| USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
 911		| XLOG_BUF_SIZE EQUAL NUMBER { xlog_buf_size = $3; }
 912		| XLOG_FORCE_COLOR EQUAL NUMBER { xlog_force_color = $3; } 
 913		| XLOG_BUF_SIZE EQUAL error { yyerror("number expected"); }
 914		| XLOG_FORCE_COLOR EQUAL error { yyerror("boolean value expected"); }
 915			
 916		| LISTEN EQUAL id_lst {
 917							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
 918								if (add_listen_iface(	lst_tmp->name,
 919														lst_tmp->port,
 920														lst_tmp->proto,
 921														lst_tmp->adv_name,
 922														lst_tmp->adv_port,
 923														0
 924													)!=0){
 925									LM_CRIT("cfg. parser: failed"
 926											" to add listen address\n");
 927									break;
 928								}
 929							}
 930							 }
 931		| LISTEN EQUAL  error { yyerror("ip address or hostname "
 932						"expected (use quotes if the hostname includes"
 933						" config keywords)"); }
 934		| ALIAS EQUAL  id_lst { 
 935							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
 936								add_alias(lst_tmp->name, strlen(lst_tmp->name),
 937											lst_tmp->port, lst_tmp->proto);
 938							  }
 939		| ALIAS  EQUAL error  { yyerror("hostname expected (use quotes"
 940							" if the hostname includes config keywords)"); }
 941		| AUTO_ALIASES EQUAL NUMBER { auto_aliases=$3; }
 942		| AUTO_ALIASES EQUAL error  { yyerror("number  expected"); }
 943		| ADVERTISED_ADDRESS EQUAL listen_id {
 944								if ($3) {
 945									default_global_address.s=$3;
 946									default_global_address.len=strlen($3);
 947								}
 948								}
 949		|ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
 950												"expected"); }
 951		| ADVERTISED_PORT EQUAL NUMBER {
 952								tmp=int2str($3, &i_tmp);
 953								if ((default_global_port.s=pkg_malloc(i_tmp))
 954										==0){
 955										LM_CRIT("cfg. parser: out of memory.\n");
 956										default_global_port.len=0;
 957								}else{
 958									default_global_port.len=i_tmp;
 959									memcpy(default_global_port.s, tmp,
 960											default_global_port.len);
 961								};
 962								}
 963		|ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
 964												"expected"); }
 965		| DISABLE_CORE EQUAL NUMBER {
 966										disable_core_dump=$3;
 967									}
 968		| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
 969		| OPEN_FD_LIMIT EQUAL NUMBER {
 970										open_files_limit=$3;
 971									}
 972		| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
 973		| MCAST_LOOPBACK EQUAL NUMBER {
 974								#ifdef USE_MCAST
 975										mcast_loopback=$3;
 976								#else
 977									warn("no multicast support compiled in");
 978								#endif
 979		  }
 980		| MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
 981		| MCAST_TTL EQUAL NUMBER {
 982								#ifdef USE_MCAST
 983										mcast_ttl=$3;
 984								#else
 985									warn("no multicast support compiled in");
 986								#endif
 987		  }
 988		| MCAST_TTL EQUAL error { yyerror("number expected as tos"); }
 989		| TOS EQUAL NUMBER { tos = $3;
 990							if (tos<=0)
 991								yyerror("invalid tos value");
 992		 }
 993		| TOS EQUAL ID { if (strcasecmp($3,"IPTOS_LOWDELAY")) {
 994								tos=IPTOS_LOWDELAY;
 995							} else if (strcasecmp($3,"IPTOS_THROUGHPUT")) {
 996								tos=IPTOS_THROUGHPUT;
 997							} else if (strcasecmp($3,"IPTOS_RELIABILITY")) {
 998								tos=IPTOS_RELIABILITY;
 999#if defined(IPTOS_MINCOST)
1000							} else if (strcasecmp($3,"IPTOS_MINCOST")) {
1001								tos=IPTOS_MINCOST;
1002#endif
1003#if defined(IPTOS_LOWCOST)
1004							} else if (strcasecmp($3,"IPTOS_LOWCOST")) {
1005								tos=IPTOS_LOWCOST;
1006#endif
1007							} else {
1008								yyerror("invalid tos value - allowed: "
1009									"IPTOS_LOWDELAY,IPTOS_THROUGHPUT,"
1010									"IPTOS_RELIABILITY"
1011#if defined(IPTOS_LOWCOST)
1012									",IPTOS_LOWCOST"
1013#endif
1014#if defined(IPTOS_MINCOST)
1015									",IPTOS_MINCOST"
1016#endif
1017									"\n");
1018							}
1019		 }
1020		| TOS EQUAL error { yyerror("number expected"); }
1021		| MPATH EQUAL STRING { mpath=$3; strcpy(mpath_buf, $3);
1022								mpath_len=strlen($3); 
1023								if(mpath_buf[mpath_len-1]!='/') {
1024									mpath_buf[mpath_len]='/';
1025									mpath_len++;
1026									mpath_buf[mpath_len]='\0';
1027								}
1028							}
1029		| MPATH EQUAL error  { yyerror("string value expected"); }
1030		| DISABLE_DNS_FAILOVER EQUAL NUMBER {
1031										disable_dns_failover=$3;
1032									}
1033		| DISABLE_DNS_FAILOVER error { yyerror("boolean value expected"); }
1034		| DISABLE_DNS_BLACKLIST EQUAL NUMBER {
1035										disable_dns_blacklist=$3;
1036									}
1037		| DISABLE_DNS_BLACKLIST error { yyerror("boolean value expected"); }
1038		| DST_BLACKLIST EQUAL ID COLON LBRACE blst_elem_list RBRACE {
1039				s_tmp.s = $3;
1040				s_tmp.len = strlen($3);
1041				if ( create_bl_head( BL_CORE_ID, BL_READONLY_LIST,
1042				bl_head, bl_tail, &s_tmp)==0) {
1043					yyerror("failed to create blacklist\n");
1044					YYABORT;
1045				}
1046				bl_head = bl_tail = 0;
1047				}
1048		| DISABLE_STATELESS_FWD EQUAL NUMBER {
1049				sl_fwd_disabled=$3;
1050				}
1051		| DB_VERSION_TABLE EQUAL STRING { db_version_table=$3; }
1052		| DB_VERSION_TABLE EQUAL error { yyerror("string value expected"); }
1053		| error EQUAL { yyerror("unknown config variable"); }
1054	;
1055
1056module_stm:	LOADMODULE STRING	{
1057			if(*$2!='/' && mpath!=NULL
1058					&& strlen($2)+mpath_len<255)
1059			{
1060				strcpy(mpath_buf+mpath_len, $2);
1061				if (stat(mpath_buf, &statf) == -1) {
1062					i_tmp = strlen(mpath_buf);
1063					if(strchr($2, '/')==NULL &&
1064							strncmp(mpath_buf+i_tmp-3, ".so", 3)==0)
1065					{
1066						if(i_tmp+strlen($2)<255)
1067						{
1068							strcpy(mpath_buf+i_tmp-3, "/");
1069							strcpy(mpath_buf+i_tmp-2, $2);
1070							if (stat(mpath_buf, &statf) == -1) {
1071								mpath_buf[mpath_len]='\0';
1072								LM_ERR("module '%s' not found in '%s'\n",
1073									$2, mpath_buf);
1074								yyerror("failed to load module");
1075							}
1076						} else {
1077							yyerror("failed to load module - path too long");
1078						}
1079					} else {
1080						yyerror("failed to load module - not found");
1081					}
1082				}
1083				LM_DBG("loading module %s\n", mpath_buf);
1084				if (sr_load_module(mpath_buf)!=0){
1085					yyerror("failed to load module");
1086				}
1087				mpath_buf[mpath_len]='\0';
1088			} else {
1089				LM_DBG("loading module %s\n", $2);
1090				if (sr_load_module($2)!=0){
1091					yyerror("failed to load module");
1092				}
1093			}
1094		}
1095		| LOADMODULE error	{ yyerror("string expected");  }
1096		| MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1097				if (set_mod_param_regex($3, $5, STR_PARAM, $7) != 0) {
1098					yyerrorf("Parameter <%s> not found in module <%s> - can't set",
1099						$5, $3);
1100				}
1101			}
1102		| MODPARAM LPAREN STRING COMMA STRING COMMA snumber RPAREN {
1103				if (set_mod_param_regex($3, $5, INT_PARAM, (void*)$7) != 0) {
1104					yyerrorf("Parameter <%s> not found in module <%s> - can't set",
1105						$5, $3);
1106				}
1107			}
1108		| MODPARAM error { yyerror("Invalid arguments"); }
1109		;
1110
1111
1112ip:		 ipv4  { $$=$1; }
1113		|ipv6  { $$=$1; }
1114		;
1115
1116ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { 
1117											$$=pkg_malloc(
1118													sizeof(struct ip_addr));
1119											if ($$==0){
1120												LM_CRIT("cfg. "
1121													"parser: out of memory.\n"
1122													);
1123											}else{
1124												memset($$, 0, 
1125													sizeof(struct ip_addr));
1126												$$->af=AF_INET;
1127												$$->len=4;
1128												if (($1>255) || ($1<0) ||
1129													($3>255) || ($3<0) ||
1130													($5>255) || ($5<0) ||
1131													($7>255) || ($7<0)){
1132													yyerror("invalid ipv4"
1133															"address");
1134													$$->u.addr32[0]=0;
1135													/* $$=0; */
1136												}else{
1137													$$->u.addr[0]=$1;
1138													$$->u.addr[1]=$3;
1139													$$->u.addr[2]=$5;
1140													$$->u.addr[3]=$7;
1141													/*
1142													$$=htonl( ($1<<24)|
1143													($3<<16)| ($5<<8)|$7 );
1144													*/
1145												}
1146											}
1147												}
1148	;
1149
1150ipv6addr:	IPV6ADDR {
1151					$$=pkg_malloc(sizeof(struct ip_addr));
1152					if ($$==0){
1153						LM_CRIT("ERROR: cfg. parser: out of memory.\n");
1154					}else{
1155						memset($$, 0, sizeof(struct ip_addr));
1156						$$->af=AF_INET6;
1157						$$->len=16;
1158					#ifdef USE_IPV6
1159						if (inet_pton(AF_INET6, $1, $$->u.addr)<=0){
1160							yyerror("bad ipv6 address");
1161						}
1162					#else
1163						yyerror("ipv6 address & no ipv6 support compiled in");
1164						YYABORT;
1165					#endif
1166					}
1167				}
1168	;
1169
1170ipv6:	ipv6addr { $$=$1; }
1171	| LBRACK ipv6addr RBRACK {$$=$2; }
1172;
1173
1174tls_server_domain_stm : TLS_SERVER_DOMAIN LBRACK ip COLON port RBRACK { 
1175						#ifdef USE_TLS
1176							if (tls_new_server_domain($3, $5)) 
1177								yyerror("tls_new_server_domain failed");
1178						#else	
1179							warn("tls support not compiled in");
1180						#endif
1181							}
1182	         LBRACE tls_server_decls RBRACE
1183;
1184
1185tls_client_domain_stm : TLS_CLIENT_DOMAIN LBRACK ip COLON port RBRACK { 
1186						#ifdef USE_TLS
1187							if (tls_new_client_domain($3, $5))
1188								yyerror("tls_new_client_domain failed");
1189						#else	
1190							warn("tls support not compiled in");
1191						#endif
1192							}
1193	         LBRACE tls_client_decls RBRACE
1194;
1195
1196tls_client_domain_stm : TLS_CLIENT_DOMAIN LBRACK STRING RBRACK { 
1197						#ifdef USE_TLS
1198							if (tls_new_client_domain_name($3, strlen($3)))
1199								yyerror("tls_new_client_domain_name failed");
1200						#else	
1201							warn("tls support not compiled in");
1202						#endif
1203							}
1204	         LBRACE tls_client_decls RBRACE
1205;
1206
1207tls_server_decls : tls_server_var
1208          | tls_server_decls tls_server_var
1209;
1210
1211tls_client_decls : tls_client_var
1212          | tls_client_decls tls_client_var
1213;
1214	
1215tls_server_var : TLS_METHOD EQUAL SSLv23 { 
1216						#ifdef USE_TLS
1217									tls_server_domains->method=TLS_USE_SSLv23;
1218						#else
1219									warn("tls support not compiled in");
1220						#endif
1221								}
1222	| TLS_METHOD EQUAL SSLv2 { 
1223						#ifdef USE_TLS
1224									tls_server_domains->method=TLS_USE_SSLv2;
1225						#else
1226									warn("tls support not compiled in");
1227						#endif
1228								}
1229	| TLS_METHOD EQUAL SSLv3 { 
1230						#ifdef USE_TLS
1231									tls_server_domains->method=TLS_USE_SSLv3;
1232						#else
1233									warn("tls support not compiled in");
1234						#endif
1235								}
1236	| TLS_METHOD EQUAL TLSv1 { 
1237						#ifdef USE_TLS
1238									tls_server_domains->method=TLS_USE_TLSv1;
1239						#else
1240									warn("tls support not compiled in");
1241						#endif
1242								}
1243	| TLS_METHOD EQUAL error { yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected"); }
1244	| TLS_CERTIFICATE EQUAL STRING { 
1245						#ifdef USE_TLS
1246									tls_server_domains->cert_file=$3;
1247						#else
1248									warn("tls support not compiled in");
1249						#endif
1250								}
1251	| TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
1252
1253	| TLS_PRIVATE_KEY EQUAL STRING { 
1254						#ifdef USE_TLS
1255									tls_server_domains->pkey_file=$3;
1256						#else
1257									warn("tls support not compiled in");
1258						#endif
1259								}
1260	| TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1261
1262	| TLS_CA_LIST EQUAL STRING { 
1263						#ifdef USE_TLS
1264									tls_server_domains->ca_file=$3; 
1265						#else
1266									warn("tls support not compiled in");
1267						#endif
1268								}	
1269	| TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1270	| TLS_CIPHERS_LIST EQUAL STRING { 
1271						#ifdef USE_TLS
1272									tls_server_domains->ciphers_list=$3;
1273						#else
1274									warn("tls support not compiled in");
1275						#endif
1276								}
1277	| TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
1278	| TLS_VERIFY_CLIENT EQUAL NUMBER {
1279						#ifdef USE_TLS
1280									tls_server_domains->verify_cert=$3;
1281						#else
1282									warn("tls support not compiled in");
1283						#endif
1284								}
1285	| TLS_VERIFY_CLIENT EQUAL error { yyerror("boolean value expected"); }
1286	| TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL NUMBER {
1287						#ifdef USE_TLS
1288									tls_server_domains->require_client_cert=$3;
1289						#else
1290									warn( "tls support not compiled in");
1291						#endif
1292								}
1293	| TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL error { 
1294						yyerror("boolean value expected"); }
1295;
1296
1297tls_client_var : TLS_METHOD EQUAL SSLv23 { 
1298						#ifdef USE_TLS
1299									tls_client_domains->method=TLS_USE_SSLv23;
1300						#else
1301									warn("tls support not compiled in");
1302						#endif
1303								}
1304	| TLS_METHOD EQUAL SSLv2 { 
1305						#ifdef USE_TLS
1306									tls_client_domains->method=TLS_USE_SSLv2;
1307						#else
1308									warn("tls support not compiled in");
1309						#endif
1310								}
1311	| TLS_METHOD EQUAL SSLv3 { 
1312						#ifdef USE_TLS
1313									tls_client_domains->method=TLS_USE_SSLv3;
1314						#else
1315									warn("tls support not compiled in");
1316						#endif
1317								}
1318	| TLS_METHOD EQUAL TLSv1 { 
1319						#ifdef USE_TLS
1320									tls_client_domains->method=TLS_USE_TLSv1;
1321						#else
1322									warn("tls support not compiled in");
1323						#endif
1324								}
1325	| TLS_METHOD EQUAL error {
1326						yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected"); }
1327	| TLS_CERTIFICATE EQUAL STRING { 
1328						#ifdef USE_TLS
1329									tls_client_domains->cert_file=$3;
1330						#else
1331									warn("tls support not compiled in");
1332						#endif
1333								}
1334	| TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
1335
1336	| TLS_PRIVATE_KEY EQUAL STRING { 
1337						#ifdef USE_TLS
1338									tls_client_domains->pkey_file=$3;
1339						#else
1340									warn("tls support not compiled in");
1341						#endif
1342								}
1343	| TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1344
1345	| TLS_CA_LIST EQUAL STRING { 
1346						#ifdef USE_TLS
1347									tls_client_domains->ca_file=$3; 
1348						#else
1349									warn("tls support not compiled in");
1350						#endif
1351								}	
1352	| TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1353	| TLS_CIPHERS_LIST EQUAL STRING { 
1354						#ifdef USE_TLS
1355									tls_client_domains->ciphers_list=$3;
1356						#else
1357									warn("tls support not compiled in");
1358						#endif
1359								}
1360	| TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
1361	| TLS_VERIFY_SERVER EQUAL NUMBER {
1362						#ifdef USE_TLS
1363									tls_client_domains->verify_cert=$3;
1364						#else
1365									warn("tls support not compiled in");
1366						#endif
1367								}
1368	| TLS_VERIFY_SERVER EQUAL error { yyerror("boolean value expected"); }
1369;
1370
1371route_name:  ID {
1372				$$ = $1;
1373				}
1374		| NUMBER {
1375				tmp=int2str($1, &i_tmp);
1376				if (($$=pkg_malloc(i_tmp+1))==0)
1377					yyerror("cfg. parser: out of memory.\n");
1378				memcpy( $$, tmp, i_tmp);
1379				$$[i_tmp] = 0;
1380				}
1381		|STRING {
1382				$$ = $1;
1383		}
1384;
1385
1386route_stm:  ROUTE LBRACE actions RBRACE {
1387						if (rlist[DEFAULT_RT].a!=0) {
1388							yyerror("overwritting default "
1389								"request routing table");
1390							YYABORT;
1391						}
1392						push($3, &rlist[DEFAULT_RT].a);
1393					}
1394		| ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE { 
1395						if ( strtol($3,&tmp,10)==0 && *tmp==0) {
1396							/* route[0] detected */
1397							if (rlist[DEFAULT_RT].a!=0) {
1398								yyerror("overwritting(2) default "
1399									"request routing table");
1400								YYABORT;
1401							}
1402							push($6, &rlist[DEFAULT_RT].a);
1403						} else {
1404							i_tmp = get_script_route_idx($3,rlist,RT_NO,1);
1405							if (i_tmp==-1) YYABORT;
1406							push($6, &rlist[i_tmp].a);
1407						}
1408					}
1409		| ROUTE error { yyerror("invalid  route  statement"); }
1410	;
1411
1412failure_route_stm: ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1413						i_tmp = get_script_route_idx($3,failure_rlist,
1414								FAILURE_RT_NO,1);
1415						if (i_tmp==-1) YYABORT;
1416						push($6, &failure_rlist[i_tmp].a);
1417					}
1418		| ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1419	;
1420
1421onreply_route_stm: ROUTE_ONREPLY LBRACE actions RBRACE {
1422						if (onreply_rlist[DEFAULT_RT].a!=0) {
1423							yyerror("overwritting default "
1424								"onreply routing table");
1425							YYABORT;
1426						}
1427						push($3, &onreply_rlist[DEFAULT_RT].a);
1428					}
1429		| ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
1430						i_tmp = get_script_route_idx($3,onreply_rlist,
1431								ONREPLY_RT_NO,1);
1432						if (i_tmp==-1) YYABORT;
1433						push($6, &onreply_rlist[i_tmp].a);
1434					}
1435		| ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
1436	;
1437
1438branch_route_stm: ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1439						i_tmp = get_script_route_idx($3,branch_rlist,
1440								BRANCH_RT_NO,1);
1441						if (i_tmp==-1) YYABORT;
1442						push($6, &branch_rlist[i_tmp].a);
1443					}
1444		| ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1445	;
1446
1447error_route_stm:  ROUTE_ERROR LBRACE actions RBRACE {
1448						if (error_rlist.a!=0) {
1449							yyerror("overwritting default "
1450								"error routing table");
1451							YYABORT;
1452						}
1453						push($3, &error_rlist.a);
1454					}
1455		| ROUTE_ERROR error { yyerror("invalid error_route statement"); }
1456	;
1457
1458local_route_stm:  ROUTE_LOCAL LBRACE actions RBRACE {
1459						if (local_rlist.a!=0) {
1460							yyerror("re-definition of local "
1461								"route detected");
1462							YYABORT;
1463						}
1464						push($3, &local_rlist.a);
1465					}
1466		| ROUTE_LOCAL error { yyerror("invalid local_route statement"); }
1467	;
1468
1469startup_route_stm:  ROUTE_STARTUP LBRACE actions RBRACE {
1470						if (startup_rlist.a!=0) {
1471							yyerror("re-definition of startup "
1472								"route detected");
1473							YYABORT;
1474						}
1475						push($3, &startup_rlist.a);
1476					}
1477		| ROUTE_STARTUP error { yyerror("invalid startup_route statement"); }
1478	;
1479
1480timer_route_stm:  ROUTE_TIMER LBRACK route_name COMMA NUMBER RBRACK LBRACE actions RBRACE {
1481						i_tmp = 0;
1482						while (timer_rlist[i_tmp].a!=0 && i_tmp < TIMER_RT_NO) {
1483							i_tmp++;
1484						}
1485						if(i_tmp == TIMER_RT_NO) {
1486							yyerror("Too many timer routes defined\n");
1487							YYABORT;
1488						}
1489						timer_rlist[i_tmp].interval = $5;
1490						push($8, &timer_rlist[i_tmp].a);
1491					}
1492		| ROUTE_TIMER error { yyerror("invalid timer_route statement"); }
1493	;
1494
1495exp:	exp AND exp 	{ $$=mk_exp(AND_OP, $1, $3); }
1496	| exp OR  exp		{ $$=mk_exp(OR_OP, $1, $3);  }
1497	| NOT exp 			{ $$=mk_exp(NOT_OP, $2, 0);  }
1498	| LPAREN exp RPAREN	{ $$=mk_exp(EVAL_OP, $2, 0); }
1499	| LBRACK assignexp RBRACK { $$=$2; }
1500	| exp_elem			{ $$=$1; }
1501	;
1502
1503equalop:	  EQUAL_T {$$=EQUAL_OP; }
1504			| DIFF	{$$=DIFF_OP; }
1505		;
1506
1507compop:	GT	{$$=GT_OP; }
1508		| LT	{$$=LT_OP; }
1509		| GTE	{$$=GTE_OP; }
1510		| LTE	{$$=LTE_OP; }
1511	;		
1512matchop: MATCH	{$$=MATCH_OP; }
1513		| NOTMATCH	{$$=NOTMATCH_OP; }
1514	;
1515
1516intop:	equalop	{$$=$1; }
1517	 | compop	{$$=$1; }
1518	;
1519		
1520strop:	equalop	{$$=$1; }
1521	    | compop {$$=$1; }
1522		| matchop	{$$=$1; }
1523	;
1524
1525uri_type:	URI			{$$=URI_O;}
1526		|	FROM_URI	{$$=FROM_URI_O;}
1527		|	TO_URI		{$$=TO_URI_O;}
1528		;
1529
1530script_var:	SCRIPTVAR	{ 
1531				spec = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t));
1532				if (spec==NULL){
1533					yyerror("no more pkg memory\n");
1534				}
1535				memset(spec, 0, sizeof(pv_spec_t));
1536				tstr.s = $1;
1537				tstr.len = strlen(tstr.s);
1538				if(pv_parse_spec(&tstr, spec)==NULL)
1539				{
1540					yyerror("unknown script variable");
1541				}
1542				$$ = spec;
1543			}
1544		| SCRIPTVARERR {
1545			$$=0; yyerror("invalid script variable name");
1546		}
1547		;
1548
1549exp_elem: exp_cond		{$$=$1; }
1550		| exp_stm		{$$=mk_elem( NO_OP, ACTION_O, 0, ACTIONS_ST, $1 ); }
1551		| snumber		{$$=mk_elem( NO_OP, NUMBER_O, 0, NUMBER_ST, 
1552											(void*)$1 ); }
1553		| script_var    {
1554				$$=mk_elem(NO_OP, SCRIPTVAR_O,0,SCRIPTVAR_ST,(void*)$1);
1555			}
1556		| uri_type strop host 	{$$ = mk_elem($2, $1, 0, STR_ST, $3); 
1557				 			}
1558		| DSTIP equalop ipnet	{ $$=mk_elem($2, DSTIP_O, 0, NET_ST, $3);
1559								}
1560		| DSTIP strop host	{ $$=mk_elem($2, DSTIP_O, 0, STR_ST, $3);
1561								}
1562		| SRCIP equalop ipnet	{ $$=mk_elem($2, SRCIP_O, 0, NET_ST, $3);
1563								}
1564		| SRCIP strop host	{ $$=mk_elem($2, SRCIP_O, 0, STR_ST, $3);
1565								}
1566	;
1567
1568exp_cond:	METHOD strop STRING	{$$= mk_elem($2, METHOD_O, 0, STR_ST, $3);
1569									}
1570		| METHOD strop  ID	{$$ = mk_elem($2, METHOD_O, 0, STR_ST, $3); 
1571				 			}
1572		| METHOD strop error { $$=0; yyerror("string expected"); }
1573		| METHOD error	{ $$=0; yyerror("invalid operator,"
1574										"== , !=, or =~ expected");
1575						}
1576		| script_var strop script_var {
1577				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,SCRIPTVAR_ST,(void*)$3);
1578			}
1579		| script_var strop STRING {
1580				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,STR_ST,$3);
1581			}
1582		| script_var strop ID {
1583				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,STR_ST,$3);
1584			}
1585		| script_var intop snumber {
1586				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,NUMBER_ST,(void *)$3);
1587			}
1588		| script_var equalop MYSELF	{ 
1589				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1, MYSELF_ST, 0);
1590			}
1591		| script_var equalop NULLV	{ 
1592				$$=mk_elem( $2, SCRIPTVAR_O,(void*)$1, NULLV_ST, 0);
1593			}
1594		| uri_type strop STRING	{$$ = mk_elem($2, $1, 0, STR_ST, $3); 
1595				 				}
1596		| uri_type equalop MYSELF	{ $$=mk_elem($2, $1, 0, MYSELF_ST, 0);
1597								}
1598		| uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
1599		| uri_type error	{ $$=0; yyerror("invalid operator,"
1600									" == , != or =~ expected");
1601					}
1602		| SRCPORT intop NUMBER	{ $$=mk_elem($2, SRCPORT_O, 0, NUMBER_ST,
1603												(void *) $3 ); }
1604		| SRCPORT intop error { $$=0; yyerror("number expected"); }
1605		| SRCPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1606		| DSTPORT intop NUMBER	{ $$=mk_elem($2, DSTPORT_O, 0, NUMBER_ST,
1607												(void *) $3 ); }
1608		| DSTPORT intop error { $$=0; yyerror("number expected"); }
1609		| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
1610		| PROTO intop proto	{ $$=mk_elem($2, PROTO_O, 0, NUMBER_ST,
1611												(void *) $3 ); }
1612		| PROTO intop error { $$=0;
1613								yyerror("protocol expected (udp, tcp or tls)");
1614							}
1615		| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
1616		| AF intop NUMBER	{ $$=mk_elem($2, AF_O, 0, NUMBER_ST,
1617												(void *) $3 ); }
1618		| AF intop error { $$=0; yyerror("number expected"); }
1619		| AF error { $$=0; yyerror("equal/!= operator expected"); }
1620		| MSGLEN intop NUMBER	{ $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST,
1621												(void *) $3 ); }
1622		| MSGLEN intop MAX_LEN	{ $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST,
1623												(void *) BUF_SIZE); }
1624		| MSGLEN intop error { $$=0; yyerror("number expected"); }
1625		| MSGLEN error { $$=0; yyerror("equal/!= operator expected"); }
1626		| SRCIP strop STRING	{	s_tmp.s=$3;
1627									s_tmp.len=strlen($3);
1628									ip_tmp=str2ip(&s_tmp);
1629									if (ip_tmp==0)
1630										ip_tmp=str2ip6(&s_tmp);
1631									if (ip_tmp){
1632										$$=mk_elem($2, SRCIP_O, 0, NET_ST,
1633												mk_net_bitlen(ip_tmp, 
1634														ip_tmp->len*8) );
1635									}else{
1636										$$=mk_elem($2, SRCIP_O, 0, STR_ST,
1637												$3);
1638									}
1639								}
1640		| SRCIP equalop MYSELF  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
1641								}
1642		| SRCIP strop error { $$=0; yyerror( "ip address or hostname"
1643						 "expected" ); }
1644		| SRCIP error  { $$=0; 
1645						 yyerror("invalid operator, ==, != or =~ expected");}
1646		| DSTIP strop STRING	{	s_tmp.s=$3;
1647									s_tmp.len=strlen($3);
1648									ip_tmp=str2ip(&s_tmp);
1649									if (ip_tmp==0)
1650										ip_tmp=str2ip6(&s_tmp);
1651									if (ip_tmp){
1652										$$=mk_elem($2, DSTIP_O, 0, NET_ST,
1653												mk_net_bitlen(ip_tmp, 
1654														ip_tmp->len*8) );
1655									}else{
1656										$$=mk_elem($2, DSTIP_O, 0, STR_ST,
1657												$3);
1658									}
1659								}
1660		| DSTIP equalop MYSELF  { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0);
1661								}
1662		| DSTIP strop error { $$=0; yyerror( "ip address or hostname"
1663						 			"expected" ); }
1664		| DSTIP error { $$=0; 
1665						yyerror("invalid operator, ==, != or =~ expected");}
1666		| MYSELF equalop uri_type	{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0);
1667								}
1668		| MYSELF equalop SRCIP  { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
1669								}
1670		| MYSELF equalop DSTIP  { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0);
1671								}
1672		| MYSELF equalop error {	$$=0; 
1673									yyerror(" URI, SRCIP or DSTIP expected"); }
1674		| MYSELF error	{ $$=0; 
1675							yyerror ("invalid operator, == or != expected");
1676						}
1677	;
1678
1679ipnet:	ip SLASH ip	{ $$=mk_net($1, $3); } 
1680	| ip SLASH NUMBER 	{	if (($3<0) || ($3>(long)$1->len*8)){
1681								yyerror("invalid bit number in netmask");
1682								$$=0;
1683							}else{
1684								$$=mk_net_bitlen($1, $3);
1685							/*
1686								$$=mk_net($1, 
1687										htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
1688							*/
1689							}
1690						}
1691	| ip				{ $$=mk_net_bitlen($1, $1->len*8); }
1692	| ip SLASH error	{ $$=0;
1693						 yyerror("netmask (eg:255.0.0.0 or 8) expected");
1694						}
1695	;
1696
1697
1698
1699host_sep:	DOT {$$=".";}
1700		|	MINUS {$$="-"; }
1701		;
1702
1703host:	ID				{ $$=$1; }
1704	| host host_sep ID	{ $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
1705						  if ($$==0){
1706							LM_CRIT("cfg. parser: memory allocation"
1707										" failure while parsing host\n");
1708						  }else{
1709							memcpy($$, $1, strlen($1));
1710							$$[strlen($1)]=*$2;
1711							memcpy($$+strlen($1)+1, $3, strlen($3));
1712							$$[strlen($1)+1+strlen($3)]=0;
1713						  }
1714						  pkg_free($1); pkg_free($3);
1715						}
1716	| host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname (use quotes if hostname has config keywords)"); }
1717	;
1718
1719assignop:
1720	EQUAL { $$ = EQ_T; }
1721	| COLONEQ { $$ = COLONEQ_T; }
1722	| PLUSEQ { $$ = PLUSEQ_T; }
1723	| MINUSEQ { $$ = MINUSEQ_T;}
1724	| SLASHEQ { $$ = DIVEQ_T; }
1725	| MULTEQ { $$ = MULTEQ_T; }
1726	| MODULOEQ { $$ = MODULOEQ_T; }
1727	| BANDEQ { $$ = BANDEQ_T; }
1728	| BOREQ { $$ = BOREQ_T; }
1729	| BXOREQ { $$ = BXOREQ_T; } 
1730	;
1731
1732assignexp :
1733	snumber { $$ = mk_elem(VALUE_OP, NUMBERV_O, (void*)$1, 0, 0); }
1734	| STRING { $$ = mk_elem(VALUE_OP, STRINGV_O, $1, 0, 0); }
1735	| ID { $$ = mk_elem(VAL…

Large files files are truncated, but you can click here to view the full file