cfg.lex
3c1a8ef8
 /*
  * $Id$
  *
  * scanner for cfg files
2d4b798e
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
2d4b798e
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * History:
  * -------
e3dccdc9
  *  2003-01-29  src_port added (jiri)
  *  2003-01-23  mhomed added (jiri)
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
aeb805d5
  *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
87405423
  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
3e8c3475
  *  2003-04-12  added force_rport, chdir and wdir (andrei)
1d9f91d6
  *  2003-04-22  strip_tail added (jiri)
46506980
  *  2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
  *               require_certificate added (andrei)
057f0454
  *  2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
6bfaa042
  *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
58481278
  *  2003-10-07  added hex and octal numbers support (andrei)
dda578ba
  *  2003-10-10  replaced len_gt w/ msg:len (andrei)
e5f4cdaf
  *  2003-10-13  added fifo_dir (andrei)
59653eb8
  *  2003-10-28  added tcp_accept_aliases (andrei)
bc977837
  *  2003-11-29  added {tcp_send, tcp_connect, tls_*}_timeout (andrei)
71fd3ebd
  *  2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
  *  2004-04-28  added sock_mode (replaces fifo_mode), sock_user &
  *               sock_group  (andrei)
956d111a
  *  2004-05-03  applied multicast support patch from janakj
  *              added MCAST_TTL (andrei)
7e1a294e
  *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
6b7de230
  *  2004-10-19  added FROM_URI and TO_URI (andrei)
6cd48835
  *  2004-11-30  added force_send_socket
3c1a8ef8
  */
 
 
 %{
 	#include "cfg.tab.h"
7268726e
 	#include "dprint.h"
4e2fdd79
 	#include "globals.h"
e3dccdc9
 	#include "mem/mem.h"
3c1a8ef8
 	#include <string.h>
03150098
 	#include <stdlib.h>
aeb805d5
 	#include "ip_addr.h"
03150098
 
3c1a8ef8
 
 	/* states */
 	#define INITIAL_S		0
 	#define COMMENT_S		1
 	#define COMMENT_LN_S	2
 	#define STRING_S		3
 
7e1a294e
 	#define STR_BUF_ALLOC_UNIT	128
 	struct str_buf{
 		char* s;
 		char* crt;
 		int left;
 	};
 
3c1a8ef8
 	
 	static int comment_nest=0;
 	static int state=0;
7e1a294e
 	static struct str_buf s_buf;
09e52ebb
 	int line=1;
 	int column=1;
 	int startcolumn=1;
3c1a8ef8
 
7e1a294e
 	static char* addchar(struct str_buf *, char);
 	static char* addstr(struct str_buf *, char*, int);
3c1a8ef8
 	static void count();
 
 
 %}
 
 /* start conditions */
 %x STRING1 STRING2 COMMENT COMMENT_LN
 
 /* action keywords */
 FORWARD	forward
0c5da34b
 FORWARD_TCP	forward_tcp
f2f969dd
 FORWARD_UDP	forward_udp
e9b02e8e
 FORWARD_TLS	forward_tls
f20a56a2
 DROP	"drop"|"break"
3c1a8ef8
 SEND	send
0c5da34b
 SEND_TCP	send_tcp
3c1a8ef8
 LOG		log
 ERROR	error
 ROUTE	route
15dde484
 ROUTE_FAILURE failure_route
 ROUTE_ONREPLY onreply_route
09e52ebb
 EXEC	exec
3e8c3475
 FORCE_RPORT		"force_rport"|"add_rport"
59653eb8
 FORCE_TCP_ALIAS		"force_tcp_alias"|"add_tcp_alias"
3881f12c
 SETFLAG		setflag
 RESETFLAG	resetflag
 ISFLAGSET	isflagset
7268726e
 SET_HOST		"rewritehost"|"sethost"|"seth"
 SET_HOSTPORT	"rewritehostport"|"sethostport"|"sethp"
 SET_USER		"rewriteuser"|"setuser"|"setu"
 SET_USERPASS	"rewriteuserpass"|"setuserpass"|"setup"
 SET_PORT		"rewriteport"|"setport"|"setp"
 SET_URI			"rewriteuri"|"seturi"
caf80ae6
 REVERT_URI		"revert_uri"
1f377e97
 PREFIX			"prefix"
 STRIP			"strip"
1d9f91d6
 STRIP_TAIL		"strip_tail"
caf80ae6
 APPEND_BRANCH	"append_branch"
f20a56a2
 IF				"if"
 ELSE			"else"
6bfaa042
 SET_ADV_ADDRESS	"set_advertised_address"
 SET_ADV_PORT	"set_advertised_port"
6cd48835
 FORCE_SEND_SOCKET	"force_send_socket"
7268726e
 
5ada8f8a
 /*ACTION LVALUES*/
 URIHOST			"uri:host"
 URIPORT			"uri:port"
 
1f377e97
 MAX_LEN			"max_len"
 
7268726e
 
3c1a8ef8
 /* condition keywords */
 METHOD	method
53c7e0f1
 /* hack -- the second element in first line is referable
87405423
    as either uri or status; it only would makes sense to
    call it "uri" from route{} and status from onreply_route{}
 */
 URI		"uri"|"status"
6b7de230
 FROM_URI	"from_uri"
 TO_URI		"to_uri"
3c1a8ef8
 SRCIP	src_ip
049f64c2
 SRCPORT	src_port
3c1a8ef8
 DSTIP	dst_ip
aeb805d5
 DSTPORT	dst_port
 PROTO	proto
 AF		af
855c2e68
 MYSELF	myself
dda578ba
 MSGLEN			"msg:len"
3c1a8ef8
 /* operators */
 EQUAL	=
 EQUAL_T	==
dda578ba
 GT	>
 LT	<
 GTE	>=
 LTE	<=
 DIFF	!=
7268726e
 MATCH	=~
09e52ebb
 NOT		!|"not"
3c1a8ef8
 AND		"and"|"&&"|"&"
 OR		"or"|"||"|"|"
91ab6402
 PLUS	"+"
 MINUS	"-"
3c1a8ef8
 
 /* config vars. */
 DEBUG	debug
 FORK	fork
 LOGSTDERROR	log_stderror
26456ace
 LOGFACILITY	log_facility
3c1a8ef8
 LISTEN		listen
e278821b
 ALIAS		alias
3c1a8ef8
 DNS		 dns
 REV_DNS	 rev_dns
7268726e
 PORT	port
f571aa35
 STAT	statistics
c3ce2841
 MAXBUFFER maxbuffer
7268726e
 CHILDREN children
 CHECK_VIA	check_via
caf80ae6
 SYN_BRANCH syn_branch
057f0454
 MEMLOG		"memlog"|"mem_log"
caf80ae6
 SIP_WARNING sip_warning
 FIFO fifo
e5f4cdaf
 FIFO_DIR  fifo_dir
71fd3ebd
 SOCK_MODE "fifo_mode"|"sock_mode"|"file_mode"
 SOCK_USER "fifo_user"|"sock_user"
 SOCK_GROUP "fifo_group"|"sock_group"
1580c821
 FIFO_DB_URL fifo_db_url
58ec33d5
 UNIX_SOCK unix_sock
 UNIX_SOCK_CHILDREN unix_sock_children
9a4cec7f
 UNIX_TX_TIMEOUT unix_tx_timeout
caf80ae6
 SERVER_SIGNATURE server_signature
 REPLY_TO_VIA reply_to_via
054cb6cf
 USER		"user"|"uid"
 GROUP		"group"|"gid"
3e8c3475
 CHROOT		"chroot"
 WDIR		"workdir"|"wdir"
2d4b798e
 MHOMED		mhomed
5dcfb23d
 DISABLE_TCP		"disable_tcp"
 TCP_CHILDREN	"tcp_children"
59653eb8
 TCP_ACCEPT_ALIASES	"tcp_accept_aliases"
bc977837
 TCP_SEND_TIMEOUT	"tcp_send_timeout"
 TCP_CONNECT_TIMEOUT	"tcp_connect_timeout"
46506980
 DISABLE_TLS		"disable_tls"
057f0454
 TLSLOG			"tlslog"|"tls_log"
 TLS_PORT_NO		"tls_port_no"
 TLS_METHOD		"tls_method"
46506980
 TLS_VERIFY		"tls_verify"
 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
 TLS_CERTIFICATE	"tls_certificate"
 TLS_PRIVATE_KEY "tls_private_key"
 TLS_CA_LIST		"tls_ca_list"
bc977837
 TLS_HANDSHAKE_TIMEOUT	"tls_handshake_timeout"
 TLS_SEND_TIMEOUT	"tls_send_timeout"
6bfaa042
 ADVERTISED_ADDRESS	"advertised_address"
 ADVERTISED_PORT		"advertised_port"
385c63eb
 DISABLE_CORE		"disable_core_dump"
 OPEN_FD_LIMIT		"open_files_limit"
2ba73117
 MCAST_LOOPBACK		"mcast_loopback"
 MCAST_TTL			"mcast_ttl"
3c1a8ef8
 
3bf76e49
 LOADMODULE	loadmodule
31309a3a
 MODPARAM        modparam
3bf76e49
 
3c1a8ef8
 /* values */
 YES			"yes"|"true"|"on"|"enable"
 NO			"no"|"false"|"off"|"disable"
057f0454
 UDP			"udp"|"UDP"
 TCP			"tcp"|"TCP"
 TLS			"tls"|"TLS"
 INET		"inet"|"INET"
 INET6		"inet6"|"INET6"
 SSLv23			"sslv23"|"SSLv23"|"SSLV23"
 SSLv2			"sslv2"|"SSLv2"|"SSLV2"
 SSLv3			"sslv3"|"SSLv3"|"SSLV3"
 TLSv1			"tlsv1"|"TLSv1"|"TLSV1"
3c1a8ef8
 
 LETTER		[a-zA-Z]
 DIGIT		[0-9]
3bf76e49
 ALPHANUM	{LETTER}|{DIGIT}|[_]
58481278
 NUMBER		0|([1-9]{DIGIT}*)
3c1a8ef8
 ID			{LETTER}{ALPHANUM}*
4e2fdd79
 HEX			[0-9a-fA-F]
58481278
 HEXNUMBER	0x{HEX}+
 OCTNUMBER	0[0-7]+
4e2fdd79
 HEX4		{HEX}{1,4}
 IPV6ADDR	({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
3c1a8ef8
 QUOTES		\"
 TICK		\'
 SLASH		"/"
 SEMICOLON	;
 RPAREN		\)
 LPAREN		\(
 LBRACE		\{
 RBRACE		\}
 LBRACK		\[
 RBRACK		\]
f539ba9c
 COMMA		","
e5f4cdaf
 COLON		":"
 STAR		\*
3c1a8ef8
 DOT			\.
 CR			\n
 
 
 
 COM_LINE	#
 COM_START	"/\*"
 COM_END		"\*/"
 
 EAT_ABLE	[\ \t\b\r]
 
 %%
 
 
 <INITIAL>{EAT_ABLE}	{ count(); }
 
 <INITIAL>{FORWARD}	{count(); yylval.strval=yytext; return FORWARD; }
0c5da34b
 <INITIAL>{FORWARD_TCP}	{count(); yylval.strval=yytext; return FORWARD_TCP; }
e9b02e8e
 <INITIAL>{FORWARD_TLS}	{count(); yylval.strval=yytext; return FORWARD_TLS; }
f2f969dd
 <INITIAL>{FORWARD_UDP}	{count(); yylval.strval=yytext; return FORWARD_UDP; }
3c1a8ef8
 <INITIAL>{DROP}	{ count(); yylval.strval=yytext; return DROP; }
 <INITIAL>{SEND}	{ count(); yylval.strval=yytext; return SEND; }
0c5da34b
 <INITIAL>{SEND_TCP}	{ count(); yylval.strval=yytext; return SEND_TCP; }
7268726e
 <INITIAL>{LOG}	{ count(); yylval.strval=yytext; return LOG_TOK; }
3c1a8ef8
 <INITIAL>{ERROR}	{ count(); yylval.strval=yytext; return ERROR; }
3881f12c
 <INITIAL>{SETFLAG}	{ count(); yylval.strval=yytext; return SETFLAG; }
 <INITIAL>{RESETFLAG}	{ count(); yylval.strval=yytext; return RESETFLAG; }
 <INITIAL>{ISFLAGSET}	{ count(); yylval.strval=yytext; return ISFLAGSET; }
dda578ba
 <INITIAL>{MSGLEN}	{ count(); yylval.strval=yytext; return MSGLEN; }
3c1a8ef8
 <INITIAL>{ROUTE}	{ count(); yylval.strval=yytext; return ROUTE; }
15dde484
 <INITIAL>{ROUTE_ONREPLY}	{ count(); yylval.strval=yytext;
 								return ROUTE_ONREPLY; }
 <INITIAL>{ROUTE_FAILURE}	{ count(); yylval.strval=yytext;
 								return ROUTE_FAILURE; }
09e52ebb
 <INITIAL>{EXEC}	{ count(); yylval.strval=yytext; return EXEC; }
7268726e
 <INITIAL>{SET_HOST}	{ count(); yylval.strval=yytext; return SET_HOST; }
 <INITIAL>{SET_HOSTPORT}	{ count(); yylval.strval=yytext; return SET_HOSTPORT; }
 <INITIAL>{SET_USER}	{ count(); yylval.strval=yytext; return SET_USER; }
 <INITIAL>{SET_USERPASS}	{ count(); yylval.strval=yytext; return SET_USERPASS; }
 <INITIAL>{SET_PORT}	{ count(); yylval.strval=yytext; return SET_PORT; }
 <INITIAL>{SET_URI}	{ count(); yylval.strval=yytext; return SET_URI; }
caf80ae6
 <INITIAL>{REVERT_URI}	{ count(); yylval.strval=yytext; return REVERT_URI; }
1f377e97
 <INITIAL>{PREFIX}	{ count(); yylval.strval=yytext; return PREFIX; }
 <INITIAL>{STRIP}	{ count(); yylval.strval=yytext; return STRIP; }
1d9f91d6
 <INITIAL>{STRIP_TAIL}	{ count(); yylval.strval=yytext; return STRIP_TAIL; }
3e8c3475
 <INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; 
 								return APPEND_BRANCH; }
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
59653eb8
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
 								return FORCE_TCP_ALIAS; }
f20a56a2
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
3c1a8ef8
 
6bfaa042
 <INITIAL>{SET_ADV_ADDRESS}	{ count(); yylval.strval=yytext;
 										return SET_ADV_ADDRESS; }
 <INITIAL>{SET_ADV_PORT}	{ count(); yylval.strval=yytext;
 										return SET_ADV_PORT; }
6cd48835
 <INITIAL>{FORCE_SEND_SOCKET}	{	count(); yylval.strval=yytext;
 									return FORCE_SEND_SOCKET; }
6bfaa042
 
5ada8f8a
 <INITIAL>{URIHOST}	{ count(); yylval.strval=yytext; return URIHOST; }
 <INITIAL>{URIPORT}	{ count(); yylval.strval=yytext; return URIPORT; }
 
1f377e97
 <INITIAL>{MAX_LEN}	{ count(); yylval.strval=yytext; return MAX_LEN; }
 
3c1a8ef8
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
6b7de230
 <INITIAL>{FROM_URI}	{ count(); yylval.strval=yytext; return FROM_URI; }
 <INITIAL>{TO_URI}	{ count(); yylval.strval=yytext; return TO_URI; }
3c1a8ef8
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
049f64c2
 <INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
3c1a8ef8
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
aeb805d5
 <INITIAL>{DSTPORT}	{ count(); yylval.strval=yytext; return DSTPORT; }
 <INITIAL>{PROTO}	{ count(); yylval.strval=yytext; return PROTO; }
 <INITIAL>{AF}	{ count(); yylval.strval=yytext; return AF; }
855c2e68
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
3c1a8ef8
 
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
26456ace
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
3c1a8ef8
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
e278821b
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
3c1a8ef8
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
7268726e
 <INITIAL>{PORT}	{ count(); yylval.strval=yytext; return PORT; }
f571aa35
 <INITIAL>{STAT}	{ count(); yylval.strval=yytext; return STAT; }
c3ce2841
 <INITIAL>{MAXBUFFER}	{ count(); yylval.strval=yytext; return MAXBUFFER; }
7268726e
 <INITIAL>{CHILDREN}	{ count(); yylval.strval=yytext; return CHILDREN; }
 <INITIAL>{CHECK_VIA}	{ count(); yylval.strval=yytext; return CHECK_VIA; }
caf80ae6
 <INITIAL>{SYN_BRANCH}	{ count(); yylval.strval=yytext; return SYN_BRANCH; }
843b2927
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
caf80ae6
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
054cb6cf
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }
3e8c3475
 <INITIAL>{CHROOT}	{ count(); yylval.strval=yytext; return CHROOT; }
 <INITIAL>{WDIR}	{ count(); yylval.strval=yytext; return WDIR; }
2d4b798e
 <INITIAL>{MHOMED}	{ count(); yylval.strval=yytext; return MHOMED; }
5dcfb23d
 <INITIAL>{DISABLE_TCP}	{ count(); yylval.strval=yytext; return DISABLE_TCP; }
 <INITIAL>{TCP_CHILDREN}	{ count(); yylval.strval=yytext; return TCP_CHILDREN; }
59653eb8
 <INITIAL>{TCP_ACCEPT_ALIASES}	{ count(); yylval.strval=yytext;
 									return TCP_ACCEPT_ALIASES; }
bc977837
 <INITIAL>{TCP_SEND_TIMEOUT}		{ count(); yylval.strval=yytext;
 									return TCP_SEND_TIMEOUT; }
 <INITIAL>{TCP_CONNECT_TIMEOUT}		{ count(); yylval.strval=yytext;
 									return TCP_CONNECT_TIMEOUT; }
46506980
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
057f0454
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
 <INITIAL>{TLS_PORT_NO}	{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
 <INITIAL>{TLS_METHOD}	{ count(); yylval.strval=yytext; return TLS_METHOD; }
46506980
 <INITIAL>{TLS_VERIFY}	{ count(); yylval.strval=yytext; return TLS_VERIFY; }
 <INITIAL>{TLS_REQUIRE_CERTIFICATE}	{ count(); yylval.strval=yytext;
 										return TLS_REQUIRE_CERTIFICATE; }
 <INITIAL>{TLS_CERTIFICATE}	{ count(); yylval.strval=yytext; 
 										return TLS_CERTIFICATE; }
 <INITIAL>{TLS_PRIVATE_KEY}	{ count(); yylval.strval=yytext; 
 										return TLS_PRIVATE_KEY; }
 <INITIAL>{TLS_CA_LIST}	{ count(); yylval.strval=yytext; 
 										return TLS_CA_LIST; }
bc977837
 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}	{ count(); yylval.strval=yytext;
 										return TLS_HANDSHAKE_TIMEOUT; }
 <INITIAL>{TLS_SEND_TIMEOUT}	{ count(); yylval.strval=yytext;
 										return TLS_SEND_TIMEOUT; }
caf80ae6
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
e5f4cdaf
 <INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
ed7856ed
 <INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
71fd3ebd
 <INITIAL>{SOCK_MODE}	{ count(); yylval.strval=yytext; return SOCK_MODE; }
 <INITIAL>{SOCK_USER}	{ count(); yylval.strval=yytext; return SOCK_USER; }
 <INITIAL>{SOCK_GROUP}	{ count(); yylval.strval=yytext; return SOCK_GROUP; }
58ec33d5
 <INITIAL>{UNIX_SOCK} { count(); yylval.strval=yytext; return UNIX_SOCK; }
 <INITIAL>{UNIX_SOCK_CHILDREN} { count(); yylval.strval=yytext; return UNIX_SOCK_CHILDREN; }
9a4cec7f
 <INITIAL>{UNIX_TX_TIMEOUT} { count(); yylval.strval=yytext; return UNIX_TX_TIMEOUT; }
caf80ae6
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
6bfaa042
 <INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
 									return ADVERTISED_ADDRESS; }
 <INITIAL>{ADVERTISED_PORT}		{	count(); yylval.strval=yytext;
 									return ADVERTISED_PORT; }
385c63eb
 <INITIAL>{DISABLE_CORE}		{	count(); yylval.strval=yytext;
 									return DISABLE_CORE; }
 <INITIAL>{OPEN_FD_LIMIT}		{	count(); yylval.strval=yytext;
 									return OPEN_FD_LIMIT; }
2ba73117
 <INITIAL>{MCAST_LOOPBACK}		{	count(); yylval.strval=yytext;
 									return MCAST_LOOPBACK; }
 <INITIAL>{MCAST_TTL}		{	count(); yylval.strval=yytext;
 									return MCAST_TTL; }
3bf76e49
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
31309a3a
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
3c1a8ef8
 
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
 <INITIAL>{EQUAL_T}	{ count(); return EQUAL_T; }
dda578ba
 <INITIAL>{GT}	{ count(); return GT; }
 <INITIAL>{LT}	{ count(); return LT; }
 <INITIAL>{GTE}	{ count(); return GTE; }
 <INITIAL>{LTE}	{ count(); return LTE; }
 <INITIAL>{DIFF}	{ count(); return DIFF; }
3c1a8ef8
 <INITIAL>{MATCH}	{ count(); return MATCH; }
 <INITIAL>{NOT}		{ count(); return NOT; }
 <INITIAL>{AND}		{ count(); return AND; }
 <INITIAL>{OR}		{ count(); return OR;  }
91ab6402
 <INITIAL>{PLUS}		{ count(); return PLUS; }
 <INITIAL>{MINUS}	{ count(); return MINUS; }
3c1a8ef8
 
4e2fdd79
 
 
 <INITIAL>{IPV6ADDR}		{ count(); yylval.strval=yytext; return IPV6ADDR; }
 <INITIAL>{NUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
58481278
 <INITIAL>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16);
 							return NUMBER; }
 <INITIAL>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8);
 							return NUMBER; }
3c1a8ef8
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
e5f4cdaf
 <INITIAL>{TCP}			{ count(); return TCP; }
 <INITIAL>{UDP}			{ count(); return UDP; }
 <INITIAL>{TLS}			{ count(); return TLS; }
aeb805d5
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
 <INITIAL>{INET6}		{ count();
 						#ifdef USE_IPV6
 						  yylval.intval=AF_INET6;
 						#else
 						  yylval.intval=-1; /* no match*/
 						#endif
 						  return NUMBER; }
057f0454
 <INITIAL>{SSLv23}		{ count(); yylval.strval=yytext; return SSLv23; }
 <INITIAL>{SSLv2}		{ count(); yylval.strval=yytext; return SSLv2; }
 <INITIAL>{SSLv3}		{ count(); yylval.strval=yytext; return SSLv3; }
 <INITIAL>{TLSv1}		{ count(); yylval.strval=yytext; return TLSv1; }
3c1a8ef8
 
 <INITIAL>{COMMA}		{ count(); return COMMA; }
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }
e5f4cdaf
 <INITIAL>{COLON}	{ count(); return COLON; }
 <INITIAL>{STAR}	{ count(); return STAR; }
3c1a8ef8
 <INITIAL>{RPAREN}	{ count(); return RPAREN; }
 <INITIAL>{LPAREN}	{ count(); return LPAREN; }
 <INITIAL>{LBRACE}	{ count(); return LBRACE; }
 <INITIAL>{RBRACE}	{ count(); return RBRACE; }
 <INITIAL>{LBRACK}	{ count(); return LBRACK; }
 <INITIAL>{RBRACK}	{ count(); return RBRACK; }
 <INITIAL>{SLASH}	{ count(); return SLASH; }
 <INITIAL>{DOT}		{ count(); return DOT; }
 <INITIAL>\\{CR}		{count(); } /* eat the escaped CR */
f20a56a2
 <INITIAL>{CR}		{ count();/* return CR;*/ }
3c1a8ef8
 
 
 <INITIAL>{QUOTES} { count(); state=STRING_S; BEGIN(STRING1); }
 <INITIAL>{TICK} { count(); state=STRING_S; BEGIN(STRING2); }
 
 
 <STRING1>{QUOTES} { count(); state=INITIAL_S; BEGIN(INITIAL); 
 						yytext[yyleng-1]=0; yyleng--;
7e1a294e
 						addstr(&s_buf, yytext, yyleng);
 						yylval.strval=s_buf.s;
 						memset(&s_buf, 0, sizeof(s_buf));
c07508e2
 						return STRING;
3c1a8ef8
 					}
 <STRING2>{TICK}  { count(); state=INITIAL_S; BEGIN(INITIAL); 
 						yytext[yyleng-1]=0; yyleng--;
7e1a294e
 						addstr(&s_buf, yytext, yyleng);
 						yylval.strval=s_buf.s;
 						memset(&s_buf, 0, sizeof(s_buf));
c07508e2
 						return STRING;
3c1a8ef8
 					}
 <STRING2>.|{EAT_ABLE}|{CR}	{ yymore(); }
 
7e1a294e
 <STRING1>\\n		{ count(); addchar(&s_buf, '\n'); }
 <STRING1>\\r		{ count(); addchar(&s_buf, '\r'); }
 <STRING1>\\a		{ count(); addchar(&s_buf, '\a'); }
 <STRING1>\\t		{ count(); addchar(&s_buf, '\t'); }
 <STRING1>\\{QUOTES}	{ count(); addchar(&s_buf, '"');  }
 <STRING1>\\\\		{ count(); addchar(&s_buf, '\\'); } 
 <STRING1>\\x{HEX}{1,2}	{ count(); addchar(&s_buf, 
 											(char)strtol(yytext+2, 0, 16)); }
486c97af
  /* don't allow \[0-7]{1}, it will eat the backreferences from
     subst_uri if allowed (although everybody should use '' in subt_uri) */
 <STRING1>\\[0-7]{2,3}	{ count(); addchar(&s_buf, 
7e1a294e
 											(char)strtol(yytext+1, 0, 8));  }
 <STRING1>\\{CR}		{ count(); } /* eat escaped CRs */
 <STRING1>.|{EAT_ABLE}|{CR}	{ addchar(&s_buf, *yytext); }
3c1a8ef8
 
 
 <INITIAL,COMMENT>{COM_START}	{ count(); comment_nest++; state=COMMENT_S;
 										BEGIN(COMMENT); }
 <COMMENT>{COM_END}				{ count(); comment_nest--;
 										if (comment_nest==0){
 											state=INITIAL_S;
 											BEGIN(INITIAL);
 										}
 								}
 <COMMENT>.|{EAT_ABLE}|{CR}				{ count(); };
 
 <INITIAL>{COM_LINE}.*{CR}	{ count(); } 
 
923c0b3b
 <INITIAL>{ID}			{ count(); addstr(&s_buf, yytext, yyleng); 
 									yylval.strval=s_buf.s;
 									memset(&s_buf, 0, sizeof(s_buf));
 									return ID; }
3c1a8ef8
 
 
 <<EOF>>							{
 									switch(state){
 										case STRING_S: 
7268726e
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
 														" unclosed string\n");
7e1a294e
 											if (s_buf.s){
 												pkg_free(s_buf.s);
 												memset(&s_buf, 0,
 															sizeof(s_buf));
 											}
3c1a8ef8
 											break;
 										case COMMENT_S:
7268726e
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
 														" %d comments open\n", comment_nest);
3c1a8ef8
 											break;
 										case COMMENT_LN_S:
7268726e
 											LOG(L_CRIT, "ERROR: unexpected EOF:"
 														"comment line open\n");
3c1a8ef8
 											break;
 									}
 									return 0;
 								}
 			
 %%
 
7e1a294e
 
 static char* addchar(struct str_buf* dst, char c)
 {
 	return addstr(dst, &c, 1);
 }
 
 
 
 static char* addstr(struct str_buf* dst_b, char* src, int len)
3c1a8ef8
 {
 	char *tmp;
7e1a294e
 	unsigned size;
 	unsigned used;
3c1a8ef8
 	
7e1a294e
 	if (dst_b->left<(len+1)){
 		used=(unsigned)(dst_b->crt-dst_b->s);
 		size=used+len+1;
 		/* round up to next multiple */
 		size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
 		tmp=pkg_malloc(size);
3c1a8ef8
 		if (tmp==0) goto error;
7e1a294e
 		if (dst_b->s){
 			memcpy(tmp, dst_b->s, used); 
 			pkg_free(dst_b->s);
 		}
 		dst_b->s=tmp;
 		dst_b->crt=dst_b->s+used;
 		dst_b->left=size-used;
3c1a8ef8
 	}
7e1a294e
 	memcpy(dst_b->crt, src, len);
 	dst_b->crt+=len;
 	*(dst_b->crt)=0;
 	dst_b->left-=len;
 	
 	return dst_b->s;
3c1a8ef8
 error:
7268726e
 	LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
3c1a8ef8
 	return 0;
 }
 
 
 
 static void count()
 {
 	int i;
 	
09e52ebb
 	startcolumn=column;
3c1a8ef8
 	for (i=0; i<yyleng;i++){
 		if (yytext[i]=='\n'){
 			line++;
09e52ebb
 			column=startcolumn=1;
3c1a8ef8
 		}else if (yytext[i]=='\t'){
09e52ebb
 			column++;
 			/*column+=8 -(column%8);*/
3c1a8ef8
 		}else{
 			column++;
 		}
 	}
 }