cfg.lex
3c1a8ef8
 /*
  * scanner for cfg files
2d4b798e
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
2d4b798e
  *
493ef6c1
  * This file is part of Kamailio, a free SIP server.
2d4b798e
  *
493ef6c1
  * Kamailio is free software; you can redistribute it and/or modify
2d4b798e
  * 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
  *
493ef6c1
  * Kamailio is distributed in the hope that it will be useful,
2d4b798e
  * 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.
  *
0973fee7
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
2d4b798e
  *
face488e
 */
3c1a8ef8
 
0dabc34a
 %option noinput
3c1a8ef8
 
 %{
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"
1644a0f1
 	#include "usr_avp.h"
3fb428ed
 	#include "select.h"
1644a0f1
 	#include "cfg.tab.h"
f69ff7d9
 	#include "sr_compat.h"
20cddb28
 	#include "ppcfg.h"
3c1a8ef8
 
 	/* states */
 	#define INITIAL_S		0
 	#define COMMENT_S		1
1644a0f1
 	#define COMMENT_LN_S	        2
3c1a8ef8
 	#define STRING_S		3
26a886bc
 	#define ATTR_S                  4  /* avp/attr */
 	#define SELECT_S                5
 	#define AVP_PVAR_S              6  /* avp or pvar */
 	#define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
f69ff7d9
 	#define PVARID_S                8  /* $foo.bar...*/
070afdb2
 	#define STR_BETWEEN_S		9
20cddb28
 	#define LINECOMMENT_S           10
360c6412
 	#define DEFINE_S                11
 	#define DEFINE_EOL_S            12
20cddb28
 	#define IFDEF_S                 13
 	#define IFDEF_EOL_S             14
360c6412
 	#define IFDEF_SKIP_S            15
20cddb28
 	#define DEFINE_DATA_S           16
5e701d6a
 	#define EVRT_NAME_S             17
3c1a8ef8
 
7e1a294e
 	#define STR_BUF_ALLOC_UNIT	128
 	struct str_buf{
 		char* s;
 		char* crt;
 		int left;
 	};
 
0973fee7
 
3c1a8ef8
 	static int comment_nest=0;
26a886bc
 	static int p_nest=0;
5d0fe6b0
 	static int state=0, old_state=0, old_initial=0;
7e1a294e
 	static struct str_buf s_buf;
09e52ebb
 	int line=1;
 	int column=1;
 	int startcolumn=1;
9c674bfa
 	int startline=1;
d2056519
 	char *finame = 0;
c44685cb
 	char *routename = 0;
 	char *default_routename = 0;
 
9c674bfa
 	static int ign_lines=0;
 	static int ign_columns=0;
f9276a5b
 	char* yy_number_str=0; /* str correspondent for the current NUMBER token */
20cddb28
 	int r = 0;
 	str *sdef = 0;
3c1a8ef8
 
7e1a294e
 	static char* addchar(struct str_buf *, char);
 	static char* addstr(struct str_buf *, char*, int);
3c1a8ef8
 	static void count();
9c674bfa
 	static void count_more();
 	static void count_ignore();
3c1a8ef8
 
d2056519
 	#define MAX_INCLUDE_DEPTH 10
 	static struct sr_yy_state {
 		YY_BUFFER_STATE state;
 		int line;
 		int column;
 		int startcolumn;
 		int startline;
 		char *finame;
c44685cb
 		char *routename;
d2056519
 	} include_stack[MAX_INCLUDE_DEPTH];
 	static int include_stack_ptr = 0;
 
1cdad56c
 	static int sr_push_yy_state(char *fin, int mode);
d2056519
 	static int sr_pop_yy_state();
 
 	static struct sr_yy_fname {
 		char *fname;
 		struct sr_yy_fname *next;
 	} *sr_yy_fname_list = 0;
3c1a8ef8
 
20cddb28
 	static str  *pp_define_get(int len, const char * text);
360c6412
 	static int  pp_ifdef_type(int pos);
 	static void pp_ifdef_var(int len, const char * text);
 	static void pp_ifdef();
 	static void pp_else();
 	static void pp_endif();
 
3c1a8ef8
 %}
 
 /* start conditions */
070afdb2
 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P 
5e701d6a
 %x PVARID INCLF IMPTF EVRTNAME
20cddb28
 %x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
f69ff7d9
 
 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
 SER_CFG			SER
 KAMAILIO_CFG	KAMAILIO|OPENSER
 MAXCOMPAT_CFG	MAXCOMPAT|ALL
3c1a8ef8
 
 /* action keywords */
 FORWARD	forward
0c5da34b
 FORWARD_TCP	forward_tcp
f2f969dd
 FORWARD_UDP	forward_udp
e9b02e8e
 FORWARD_TLS	forward_tls
ed990c31
 FORWARD_SCTP	forward_sctp
8ebb586d
 DROP	"drop"
 EXIT	"exit"
01dea124
 RETURN	"return"
 BREAK	"break"
3c1a8ef8
 LOG		log
 ERROR	error
 ROUTE	route
3bf9b2c6
 ROUTE_REQUEST request_route
15dde484
 ROUTE_FAILURE failure_route
1d2246f4
 ROUTE_REPLY reply_route
15dde484
 ROUTE_ONREPLY onreply_route
7662b2e7
 ROUTE_BRANCH branch_route
0d88ce78
 ROUTE_SEND onsend_route
31b5e3d0
 ROUTE_EVENT event_route
09e52ebb
 EXEC	exec
3e8c3475
 FORCE_RPORT		"force_rport"|"add_rport"
c37c22b4
 ADD_LOCAL_RPORT		"add_local_rport"
59653eb8
 FORCE_TCP_ALIAS		"force_tcp_alias"|"add_tcp_alias"
f62c96d8
 UDP_MTU		"udp_mtu"
 UDP_MTU_TRY_PROTO	"udp_mtu_try_proto"
e92fe8b4
 UDP4_RAW		"udp4_raw"
 UDP4_RAW_MTU	"udp4_raw_mtu"
2556cd84
 UDP4_RAW_TTL	"udp4_raw_ttl"
3881f12c
 SETFLAG		setflag
 RESETFLAG	resetflag
 ISFLAGSET	isflagset
65938e0e
 FLAGS_DECL	"flags"|"bool"
85d4627f
 SETAVPFLAG	setavpflag
 RESETAVPFLAG	resetavpflag
 ISAVPFLAGSET	isavpflagset
 AVPFLAGS_DECL	avpflags
7268726e
 SET_HOST		"rewritehost"|"sethost"|"seth"
 SET_HOSTPORT	"rewritehostport"|"sethostport"|"sethp"
6973e34c
 SET_HOSTPORTTRANS	"rewritehostporttrans"|"sethostporttrans"|"sethpt"
7268726e
 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"
536065b8
 SET_USERPHONE		"userphone"
9fa304f1
 REMOVE_BRANCH	"remove_branch"
 CLEAR_BRANCHES	"clear_branches"
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"
58cbf7f7
 SET_FWD_NO_CONNECT		"set_forward_no_connect"
 SET_RPL_NO_CONNECT	"set_reply_no_connect"
 SET_FWD_CLOSE	"set_forward_close"
 SET_RPL_CLOSE	"set_reply_close"
a29a8b6d
 SWITCH			"switch"
 CASE			"case"
 DEFAULT			"default"
d14a718f
 WHILE			"while"
7268726e
 
415f24a4
 CFG_SELECT	"cfg_select"
 CFG_RESET	"cfg_reset"
 
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
0d88ce78
 SNDIP	snd_ip
 SNDPORT	snd_port
 SNDPROTO	snd_proto|to_proto
 SNDAF		snd_af|to_af
 TOIP	to_ip
 TOPORT	to_port
aeb805d5
 PROTO	proto
 AF		af
855c2e68
 MYSELF	myself
dda578ba
 MSGLEN			"msg:len"
0c73dfed
 RETCODE	\$\?|\$retcode|\$rc
3c1a8ef8
 /* operators */
 EQUAL	=
 EQUAL_T	==
dda578ba
 GT	>
 LT	<
 GTE	>=
 LTE	<=
 DIFF	!=
7268726e
 MATCH	=~
8126b425
 ADDEQ     "+="
09e52ebb
 NOT		!|"not"
1644a0f1
 LOG_AND		"and"|"&&"
 BIN_AND         "&"
 LOG_OR		"or"|"||"
 BIN_OR          "|"
508ad1c0
 BIN_NOT     "~"
 BIN_XOR     "^"
 BIN_LSHIFT     "<<"
 BIN_RSHIFT     ">>"
91ab6402
 PLUS	"+"
 MINUS	"-"
333a3335
 MODULO	"mod"
d4799027
 STRLEN	"strlen"
 STREMPTY	"strempty"
 DEFINED		"defined"
298512a2
 STREQ	eq
 INTEQ	ieq
 STRDIFF	ne
 INTDIFF	ine
e41bc057
 INTCAST	\(int\)
 STRCAST \(str\)
3c1a8ef8
 
1644a0f1
 /* Attribute specification */
26a886bc
 ATTR_MARK   "%"
 VAR_MARK    "$"
3fb428ed
 SELECT_MARK  "@"
fd6d4dc9
 ATTR_FROM         "f"
 ATTR_TO           "t"
e61ba5d2
 ATTR_FROMURI      "fr"
 ATTR_TOURI       "tr"
fd6d4dc9
 ATTR_FROMUSER     "fu"
 ATTR_TOUSER       "tu"
18cf23c0
 ATTR_FROMDOMAIN   "fd"
 ATTR_TODOMAIN     "td"
 ATTR_GLOBAL       "g"
1644a0f1
 
26a886bc
 /* avp prefix */
 AVP_PREF	(([ft][rud]?)|g)\.
 
3c1a8ef8
 /* config vars. */
 DEBUG	debug
 FORK	fork
c2429a58
 FORK_DELAY	fork_delay
52d33940
 MODINIT_DELAY	modinit_delay
3c1a8ef8
 LOGSTDERROR	log_stderror
26456ace
 LOGFACILITY	log_facility
95bf8645
 LOGNAME		log_name
fe00a334
 LOGCOLOR	log_color
35e94c97
 LOGPREFIX	log_prefix
88b06d1f
 LOGENGINETYPE	log_engine_type
 LOGENGINEDATA	log_engine_data
3c1a8ef8
 LISTEN		listen
574daa6d
 ADVERTISE	advertise|ADVERTISE
e278821b
 ALIAS		alias
bb4cd6b0
 SR_AUTO_ALIASES	auto_aliases
3c1a8ef8
 DNS		 dns
 REV_DNS	 rev_dns
878fc194
 DNS_TRY_IPV6	dns_try_ipv6
dd4ffbb7
 DNS_TRY_NAPTR	dns_try_naptr
 DNS_SRV_LB		dns_srv_lb|dns_srv_loadbalancing
 DNS_UDP_PREF	dns_udp_pref|dns_udp_preference
 DNS_TCP_PREF	dns_tcp_pref|dns_tcp_preference
 DNS_TLS_PREF	dns_tls_pref|dns_tls_preference
7d11cc0c
 DNS_SCTP_PREF	dns_sctp_pref|dns_sctp_preference
878fc194
 DNS_RETR_TIME	dns_retr_time
 DNS_RETR_NO		dns_retr_no
 DNS_SERVERS_NO	dns_servers_no
 DNS_USE_SEARCH	dns_use_search_list
740a5978
 DNS_SEARCH_FMATCH	dns_search_full_match
a9fc979c
 DNS_NAPTR_IGNORE_RFC	dns_naptr_ignore_rfc
dcb59e67
 /* dns cache */
7905e2d6
 DNS_CACHE_INIT	dns_cache_init
dcb59e67
 DNS_USE_CACHE	use_dns_cache
 DNS_USE_FAILOVER	use_dns_failover
 DNS_CACHE_FLAGS		dns_cache_flags
 DNS_CACHE_NEG_TTL	dns_cache_negative_ttl
 DNS_CACHE_MIN_TTL	dns_cache_min_ttl
 DNS_CACHE_MAX_TTL	dns_cache_max_ttl
 DNS_CACHE_MEM		dns_cache_mem
 DNS_CACHE_GC_INT	dns_cache_gc_interval
4136d191
 DNS_CACHE_DEL_NONEXP	dns_cache_del_nonexp|dns_cache_delete_nonexpired
0d4d530e
 DNS_CACHE_REC_PREF	dns_cache_rec_pref
bd3d3546
 /* ipv6 auto bind */
 AUTO_BIND_IPV6		auto_bind_ipv6
dcb59e67
 /* blacklist */
7905e2d6
 DST_BLST_INIT	dst_blacklist_init
dcb59e67
 USE_DST_BLST		use_dst_blacklist
 DST_BLST_MEM		dst_blacklist_mem
 DST_BLST_TTL		dst_blacklist_expire|dst_blacklist_ttl
 DST_BLST_GC_INT		dst_blacklist_gc_interval
0e055147
 DST_BLST_UDP_IMASK	dst_blacklist_udp_imask
 DST_BLST_TCP_IMASK	dst_blacklist_tcp_imask
 DST_BLST_TLS_IMASK	dst_blacklist_tls_imask
 DST_BLST_SCTP_IMASK	dst_blacklist_sctp_imask
dcb59e67
 
 
7268726e
 PORT	port
f571aa35
 STAT	statistics
c3ce2841
 MAXBUFFER maxbuffer
5cd87175
 SQL_BUFFER_SIZE sql_buffer_size
7268726e
 CHILDREN children
edf5e385
 SOCKET_WORKERS socket_workers
d5a22ca8
 ASYNC_WORKERS async_workers
55be13df
 ASYNC_USLEEP async_usleep
7268726e
 CHECK_VIA	check_via
face488e
 PHONE2TEL	phone2tel
057f0454
 MEMLOG		"memlog"|"mem_log"
58d0d1b5
 MEMDBG		"memdbg"|"mem_dbg"
d740c34e
 MEMSUM		"mem_summary"
d89420df
 MEMSAFETY	"mem_safety"
 MEMJOIN		"mem_join"
7e2e4ff4
 CORELOG		"corelog"|"core_log"
caf80ae6
 SIP_WARNING sip_warning
 SERVER_SIGNATURE server_signature
c745469f
 SERVER_HEADER server_header
 USER_AGENT_HEADER user_agent_header
caf80ae6
 REPLY_TO_VIA reply_to_via
054cb6cf
 USER		"user"|"uid"
 GROUP		"group"|"gid"
3e8c3475
 CHROOT		"chroot"
 WDIR		"workdir"|"wdir"
ca1358f2
 RUNDIR		"rundir"|"run_dir"
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"
55d8155e
 TCP_CON_LIFETIME	"tcp_connection_lifetime"
 TCP_POLL_METHOD		"tcp_poll_method"
 TCP_MAX_CONNECTIONS	"tcp_max_connections"
61f8b970
 TLS_MAX_CONNECTIONS	"tls_max_connections"
de223f01
 TCP_NO_CONNECT		"tcp_no_connect"
761bd309
 TCP_SOURCE_IPV4		"tcp_source_ipv4"
 TCP_SOURCE_IPV6		"tcp_source_ipv6"
20c64cc6
 TCP_OPT_FD_CACHE	"tcp_fd_cache"
69515cab
 TCP_OPT_BUF_WRITE	"tcp_buf_write"|"tcp_async"
885b9f62
 TCP_OPT_CONN_WQ_MAX	"tcp_conn_wq_max"
 TCP_OPT_WQ_MAX		"tcp_wq_max"
e655392a
 TCP_OPT_RD_BUF		"tcp_rd_buf_size"
 TCP_OPT_WQ_BLK		"tcp_wq_blk_size"
20c64cc6
 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
 TCP_OPT_DELAYED_ACK	"tcp_delayed_ack"
 TCP_OPT_SYNCNT		"tcp_syncnt"
 TCP_OPT_LINGER2		"tcp_linger2"
 TCP_OPT_KEEPALIVE	"tcp_keepalive"
 TCP_OPT_KEEPIDLE	"tcp_keepidle"
 TCP_OPT_KEEPINTVL	"tcp_keepintvl"
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
c7337a27
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
d4cc4103
 TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
691a3439
 TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
6c53d41a
 DISABLE_TLS		"disable_tls"|"tls_disable"
 ENABLE_TLS		"enable_tls"|"tls_enable"
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"
ed990c31
 DISABLE_SCTP	"disable_sctp"
c8e95587
 ENABLE_SCTP	"enable_sctp"
ed990c31
 SCTP_CHILDREN	"sctp_children"
c8586f86
 
6bfaa042
 ADVERTISED_ADDRESS	"advertised_address"
 ADVERTISED_PORT		"advertised_port"
385c63eb
 DISABLE_CORE		"disable_core_dump"
 OPEN_FD_LIMIT		"open_files_limit"
647cc983
 SHM_MEM_SZ		"shm"|"shm_mem"|"shm_mem_size"
71a0a583
 SHM_FORCE_ALLOC		"shm_force_alloc"
 MLOCK_PAGES			"mlock_pages"
 REAL_TIME			"real_time"
 RT_PRIO				"rt_prio"
 RT_POLICY			"rt_policy"
 RT_TIMER1_PRIO		"rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
 RT_TIMER1_POLICY	"rt_timer1_policy"|"rt_ftimer_policy"
 RT_TIMER2_PRIO		"rt_timer2_prio"|"rt_stimer_prio"
 RT_TIMER2_POLICY	"rt_timer2_policy"|"rt_stimer_policy"
2ba73117
 MCAST_LOOPBACK		"mcast_loopback"
fe09f315
 MCAST_TTL		"mcast_ttl"
 TOS			"tos"
f3a26797
 PMTU_DISCOVERY	"pmtu_discovery"
96d09107
 KILL_TIMEOUT	"exit_timeout"|"ser_kill_timeout"
d14a718f
 MAX_WLOOPS		"max_while_loops"
7614a1d0
 PVBUFSIZE		"pv_buffer_size"
 PVBUFSLOTS		"pv_buffer_slots"
adf32ec8
 HTTP_REPLY_PARSE		"http_reply_hack"|"http_reply_parse"
8fb8b261
 VERSION_TABLE_CFG		"version_table"
3c1a8ef8
 
89fde575
 SERVER_ID     "server_id"
 
d1c60718
 MAX_RECURSIVE_LEVEL		"max_recursive_level"
e008edb9
 MAX_BRANCHES_PARAM		"max_branches"|"max_branches"
d1c60718
 
930aba29
 LATENCY_LOG				latency_log
 LATENCY_LIMIT_DB		latency_limit_db
 LATENCY_LIMIT_ACTION	latency_limit_action
 
d4ed4771
 MSG_TIME	msg_time
214b161e
 ONSEND_RT_REPLY		"onsend_route_reply"
140137c9
 CFG_DESCRIPTION		"description"|"descr"|"desc"
 
3bf76e49
 LOADMODULE	loadmodule
8d503e9e
 LOADPATH	"loadpath"|"mpath"
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"
c9831d2a
 SCTP		"sctp"|"SCTP"
8c6f700b
 WS		"ws"|"WS"
8393efff
 WSS		"wss"|"WSS"
057f0454
 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]
360c6412
 LETTER_     {LETTER}|[_]
 ALPHANUM    {LETTER_}|{DIGIT}
 ID          {LETTER_}{ALPHANUM}*
f9276a5b
 NUM_ID		{ALPHANUM}+
4e2fdd79
 HEX			[0-9a-fA-F]
58481278
 HEXNUMBER	0x{HEX}+
 OCTNUMBER	0[0-7]+
80ae84b9
 DECNUMBER       0|([1-9]{DIGIT}*)
1644a0f1
 BINNUMBER       [0-1]+b
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
fb4d9dae
 EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*(":"[a-zA-Z][0-9a-zA-Z-]*)+
3c1a8ef8
 
 
584508d5
 COM_LINE	"#"|"//"
3c1a8ef8
 COM_START	"/\*"
 COM_END		"\*/"
 
47b81cd0
 /* start of pre-processing directives */
 PREP_START	"#!"|"!!"
 
4a9f0a3d
 DEFINE       "define"|"def"
360c6412
 IFDEF        ifdef
 IFNDEF       ifndef
 ENDIF        endif
13de789c
 TRYDEF       "trydefine"|"trydef"
 REDEF        "redefine"|"redef"
 
360c6412
 /* else is already defined */
 
3c1a8ef8
 EAT_ABLE	[\ \t\b\r]
 
20cddb28
 /* pre-processing blocks */
 SUBST       subst
78d26523
 SUBSTDEF    substdef
8198fd2b
 SUBSTDEFS   substdefs
20cddb28
 
1cdad56c
 /* include files */
 INCLUDEFILE     "include_file"
 IMPORTFILE      "import_file"
 
3c1a8ef8
 %%
 
 
 <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; }
ed990c31
 <INITIAL>{FORWARD_SCTP}	{count(); yylval.strval=yytext; return FORWARD_SCTP;}
f2f969dd
 <INITIAL>{FORWARD_UDP}	{count(); yylval.strval=yytext; return FORWARD_UDP; }
3c1a8ef8
 <INITIAL>{DROP}	{ count(); yylval.strval=yytext; return DROP; }
8ebb586d
 <INITIAL>{EXIT}	{ count(); yylval.strval=yytext; return EXIT; }
01dea124
 <INITIAL>{RETURN}	{ count(); yylval.strval=yytext; return RETURN; }
 <INITIAL>{BREAK}	{ count(); yylval.strval=yytext; return BREAK; }
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; }
65938e0e
 <INITIAL>{FLAGS_DECL}	{ count(); yylval.strval=yytext; return FLAGS_DECL; }
85d4627f
 <INITIAL>{SETAVPFLAG}	{ count(); yylval.strval=yytext; return SETAVPFLAG; }
 <INITIAL>{RESETAVPFLAG}	{ count(); yylval.strval=yytext; return RESETAVPFLAG; }
 <INITIAL>{ISAVPFLAGSET}	{ count(); yylval.strval=yytext; return ISAVPFLAGSET; }
 <INITIAL>{AVPFLAGS_DECL}	{ count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
dda578ba
 <INITIAL>{MSGLEN}	{ count(); yylval.strval=yytext; return MSGLEN; }
821d1d9f
 <INITIAL>{ROUTE}	{ count(); default_routename="DEFAULT_ROUTE";
c44685cb
 						yylval.strval=yytext; return ROUTE; }
821d1d9f
 <INITIAL>{ROUTE_REQUEST}	{ count(); default_routename="DEFAULT_ROUTE";
c44685cb
 								yylval.strval=yytext; return ROUTE_REQUEST; }
821d1d9f
 <INITIAL>{ROUTE_ONREPLY}	{ count(); default_routename="DEFAULT_ONREPLY";
c44685cb
 								yylval.strval=yytext;
15dde484
 								return ROUTE_ONREPLY; }
821d1d9f
 <INITIAL>{ROUTE_REPLY}	{ count(); default_routename="DEFAULT_ONREPLY";
c44685cb
 							yylval.strval=yytext; return ROUTE_REPLY; }
821d1d9f
 <INITIAL>{ROUTE_FAILURE}	{ count(); default_routename="DEFAULT_FAILURE";
c44685cb
 								yylval.strval=yytext;
15dde484
 								return ROUTE_FAILURE; }
821d1d9f
 <INITIAL>{ROUTE_BRANCH} { count(); default_routename="DEFAULT_BRANCH";
c44685cb
 							yylval.strval=yytext; return ROUTE_BRANCH; }
821d1d9f
 <INITIAL>{ROUTE_SEND} { count(); default_routename="DEFAULT_SEND";
c44685cb
 							yylval.strval=yytext; return ROUTE_SEND; }
821d1d9f
 <INITIAL>{ROUTE_EVENT} { count(); default_routename="DEFAULT_EVENT";
5e701d6a
 							yylval.strval=yytext;
 							state=EVRT_NAME_S; BEGIN(EVRTNAME);
 							return ROUTE_EVENT; }
 <EVRTNAME>{LBRACK}          { count(); return LBRACK; }
 <EVRTNAME>{EAT_ABLE}|{CR}				{ count(); };
 <EVRTNAME>{EVENT_RT_NAME}	{ count();
 								addstr(&s_buf, yytext, yyleng);
 								yylval.strval=s_buf.s;
546e624a
 								routename=s_buf.s;
5e701d6a
 								memset(&s_buf, 0, sizeof(s_buf));
 								return EVENT_RT_NAME; }
 <EVRTNAME>{RBRACK}          { count();
 								state=INITIAL_S; BEGIN(INITIAL);
 								return RBRACK; }
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; }
6973e34c
 <INITIAL>{SET_HOSTPORTTRANS}	{ count(); yylval.strval=yytext; return SET_HOSTPORTTRANS; }
7268726e
 <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; }
9fa304f1
 <INITIAL>{REMOVE_BRANCH}	{ count(); yylval.strval=yytext;
 								return REMOVE_BRANCH; }
 <INITIAL>{CLEAR_BRANCHES}	{ count(); yylval.strval=yytext;
 								return CLEAR_BRANCHES; }
536065b8
 <INITIAL>{SET_USERPHONE}	{ count(); yylval.strval=yytext;
 								return SET_USERPHONE; }
3e8c3475
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
c37c22b4
 <INITIAL>{ADD_LOCAL_RPORT}	{ count(); yylval.strval=yytext;
 								return ADD_LOCAL_RPORT; }
59653eb8
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
 								return FORCE_TCP_ALIAS; }
f62c96d8
 <INITIAL>{UDP_MTU}	{ count(); yylval.strval=yytext; return UDP_MTU; }
 <INITIAL>{UDP_MTU_TRY_PROTO}	{ count(); yylval.strval=yytext;
 									return UDP_MTU_TRY_PROTO; }
e92fe8b4
 <INITIAL>{UDP4_RAW}	{ count(); yylval.strval=yytext; return UDP4_RAW; }
 <INITIAL>{UDP4_RAW_MTU}	{ count(); yylval.strval=yytext; return UDP4_RAW_MTU; }
2556cd84
 <INITIAL>{UDP4_RAW_TTL}	{ count(); yylval.strval=yytext; return UDP4_RAW_TTL; }
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; }
58cbf7f7
 <INITIAL>{SET_FWD_NO_CONNECT}	{ count(); yylval.strval=yytext;
 									return SET_FWD_NO_CONNECT; }
 <INITIAL>{SET_RPL_NO_CONNECT}	{ count(); yylval.strval=yytext;
 									return SET_RPL_NO_CONNECT; }
 <INITIAL>{SET_FWD_CLOSE}		{ count(); yylval.strval=yytext;
 									return SET_FWD_CLOSE; }
 <INITIAL>{SET_RPL_CLOSE}		{ count(); yylval.strval=yytext;
 									return SET_RPL_CLOSE; }
a29a8b6d
 <INITIAL>{SWITCH}	{ count(); yylval.strval=yytext; return SWITCH; }
 <INITIAL>{CASE}	{ count(); yylval.strval=yytext; return CASE; }
 <INITIAL>{DEFAULT}	{ count(); yylval.strval=yytext; return DEFAULT; }
d14a718f
 <INITIAL>{WHILE}	{ count(); yylval.strval=yytext; return WHILE; }
6bfaa042
 
1c9c433f
 <INITIAL>{INCLUDEFILE}  { count(); BEGIN(INCLF); }
7a2e73a6
 <INITIAL>{PREP_START}{INCLUDEFILE}  { count(); BEGIN(INCLF); }
 
1cdad56c
 <INITIAL>{IMPORTFILE}  { count(); BEGIN(IMPTF); }
7a2e73a6
 <INITIAL>{PREP_START}{IMPORTFILE}  { count(); BEGIN(IMPTF); }
d2056519
 
415f24a4
 <INITIAL>{CFG_SELECT}	{ count(); yylval.strval=yytext; return CFG_SELECT; }
 <INITIAL>{CFG_RESET}	{ count(); yylval.strval=yytext; return CFG_RESET; }
 
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; }
0d88ce78
 <INITIAL>{SNDIP}	{ count(); yylval.strval=yytext; return SNDIP; }
 <INITIAL>{SNDPORT}	{ count(); yylval.strval=yytext; return SNDPORT; }
 <INITIAL>{SNDPROTO}	{ count(); yylval.strval=yytext; return SNDPROTO; }
 <INITIAL>{SNDAF}	{ count(); yylval.strval=yytext; return SNDAF; }
 <INITIAL>{TOIP}		{ count(); yylval.strval=yytext; return TOIP; }
 <INITIAL>{TOPORT}	{ count(); yylval.strval=yytext; return TOPORT; }
aeb805d5
 <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
 
a86d53b0
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG_V; }
3c1a8ef8
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
c2429a58
 <INITIAL>{FORK_DELAY}	{ count(); yylval.strval=yytext; return FORK_DELAY; }
52d33940
 <INITIAL>{MODINIT_DELAY}	{ count(); yylval.strval=yytext; return MODINIT_DELAY; }
3c1a8ef8
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
26456ace
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
95bf8645
 <INITIAL>{LOGNAME}	{ yylval.strval=yytext; return LOGNAME; }
fe00a334
 <INITIAL>{LOGCOLOR}	{ yylval.strval=yytext; return LOGCOLOR; }
35e94c97
 <INITIAL>{LOGPREFIX}	{ yylval.strval=yytext; return LOGPREFIX; }
88b06d1f
 <INITIAL>{LOGENGINETYPE}	{ yylval.strval=yytext; return LOGENGINETYPE; }
 <INITIAL>{LOGENGINEDATA}	{ yylval.strval=yytext; return LOGENGINEDATA; }
3c1a8ef8
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
574daa6d
 <INITIAL>{ADVERTISE}	{ count(); yylval.strval=yytext; return ADVERTISE; }
e278821b
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
bb4cd6b0
 <INITIAL>{SR_AUTO_ALIASES}	{ count(); yylval.strval=yytext;
 									return SR_AUTO_ALIASES; }
3c1a8ef8
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
878fc194
 <INITIAL>{DNS_TRY_IPV6}	{ count(); yylval.strval=yytext;
 								return DNS_TRY_IPV6; }
dd4ffbb7
 <INITIAL>{DNS_TRY_NAPTR}	{ count(); yylval.strval=yytext;
 								return DNS_TRY_NAPTR; }
 <INITIAL>{DNS_SRV_LB}	{ count(); yylval.strval=yytext;
 								return DNS_SRV_LB; }
 <INITIAL>{DNS_UDP_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_UDP_PREF; }
 <INITIAL>{DNS_TCP_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_TCP_PREF; }
 <INITIAL>{DNS_TLS_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_TLS_PREF; }
7d11cc0c
 <INITIAL>{DNS_SCTP_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_SCTP_PREF; }
878fc194
 <INITIAL>{DNS_RETR_TIME}	{ count(); yylval.strval=yytext;
 								return DNS_RETR_TIME; }
 <INITIAL>{DNS_RETR_NO}	{ count(); yylval.strval=yytext;
 								return DNS_RETR_NO; }
 <INITIAL>{DNS_SERVERS_NO}	{ count(); yylval.strval=yytext;
 								return DNS_SERVERS_NO; }
 <INITIAL>{DNS_USE_SEARCH}	{ count(); yylval.strval=yytext;
 								return DNS_USE_SEARCH; }
740a5978
 <INITIAL>{DNS_SEARCH_FMATCH}	{ count(); yylval.strval=yytext;
 								return DNS_SEARCH_FMATCH; }
a9fc979c
 <INITIAL>{DNS_NAPTR_IGNORE_RFC}	{ count(); yylval.strval=yytext;
 								return DNS_NAPTR_IGNORE_RFC; }
7905e2d6
 <INITIAL>{DNS_CACHE_INIT}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_INIT; }
dcb59e67
 <INITIAL>{DNS_USE_CACHE}	{ count(); yylval.strval=yytext;
 								return DNS_USE_CACHE; }
 <INITIAL>{DNS_USE_FAILOVER}	{ count(); yylval.strval=yytext;
 								return DNS_USE_FAILOVER; }
 <INITIAL>{DNS_CACHE_FLAGS}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_FLAGS; }
 <INITIAL>{DNS_CACHE_NEG_TTL}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_NEG_TTL; }
 <INITIAL>{DNS_CACHE_MIN_TTL}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_MIN_TTL; }
 <INITIAL>{DNS_CACHE_MAX_TTL}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_MAX_TTL; }
 <INITIAL>{DNS_CACHE_MEM}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_MEM; }
 <INITIAL>{DNS_CACHE_GC_INT}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_GC_INT; }
4136d191
 <INITIAL>{DNS_CACHE_DEL_NONEXP}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_DEL_NONEXP; }
0d4d530e
 <INITIAL>{DNS_CACHE_REC_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_REC_PREF; }
bd3d3546
 <INITIAL>{AUTO_BIND_IPV6}	{ count(); yylval.strval=yytext;
 								return AUTO_BIND_IPV6; }
7905e2d6
 <INITIAL>{DST_BLST_INIT}	{ count(); yylval.strval=yytext;
 								return DST_BLST_INIT; }
dcb59e67
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
 								return USE_DST_BLST; }
 <INITIAL>{DST_BLST_MEM}	{ count(); yylval.strval=yytext;
 								return DST_BLST_MEM; }
 <INITIAL>{DST_BLST_TTL}	{ count(); yylval.strval=yytext;
 								return DST_BLST_TTL; }
 <INITIAL>{DST_BLST_GC_INT}	{ count(); yylval.strval=yytext;
 								return DST_BLST_GC_INT; }
0e055147
 <INITIAL>{DST_BLST_UDP_IMASK}	{ count(); yylval.strval=yytext;
 								return DST_BLST_UDP_IMASK; }
 <INITIAL>{DST_BLST_TCP_IMASK}	{ count(); yylval.strval=yytext;
 								return DST_BLST_TCP_IMASK; }
 <INITIAL>{DST_BLST_TLS_IMASK}	{ count(); yylval.strval=yytext;
 								return DST_BLST_TLS_IMASK; }
 <INITIAL>{DST_BLST_SCTP_IMASK}	{ count(); yylval.strval=yytext;
 								return DST_BLST_SCTP_IMASK; }
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; }
5cd87175
 <INITIAL>{SQL_BUFFER_SIZE}	{ count(); yylval.strval=yytext; return SQL_BUFFER_SIZE; }
7268726e
 <INITIAL>{CHILDREN}	{ count(); yylval.strval=yytext; return CHILDREN; }
edf5e385
 <INITIAL>{SOCKET_WORKERS}	{ count(); yylval.strval=yytext; return SOCKET_WORKERS; }
d5a22ca8
 <INITIAL>{ASYNC_WORKERS}	{ count(); yylval.strval=yytext; return ASYNC_WORKERS; }
55be13df
 <INITIAL>{ASYNC_USLEEP}	{ count(); yylval.strval=yytext; return ASYNC_USLEEP; }
7268726e
 <INITIAL>{CHECK_VIA}	{ count(); yylval.strval=yytext; return CHECK_VIA; }
face488e
 <INITIAL>{PHONE2TEL}	{ count(); yylval.strval=yytext; return PHONE2TEL; }
843b2927
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
58d0d1b5
 <INITIAL>{MEMDBG}	{ count(); yylval.strval=yytext; return MEMDBG; }
d740c34e
 <INITIAL>{MEMSUM}	{ count(); yylval.strval=yytext; return MEMSUM; }
ffb8754f
 <INITIAL>{MEMSAFETY}	{ count(); yylval.strval=yytext; return MEMSAFETY; }
d89420df
 <INITIAL>{MEMJOIN}	{ count(); yylval.strval=yytext; return MEMJOIN; }
7e2e4ff4
 <INITIAL>{CORELOG}	{ count(); yylval.strval=yytext; return CORELOG; }
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; }
ca1358f2
 <INITIAL>{RUNDIR}	{ count(); yylval.strval=yytext; return RUNDIR; }
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; }
55d8155e
 <INITIAL>{TCP_CON_LIFETIME}		{ count(); yylval.strval=yytext;
 									return TCP_CON_LIFETIME; }
 <INITIAL>{TCP_POLL_METHOD}		{ count(); yylval.strval=yytext;
 									return TCP_POLL_METHOD; }
 <INITIAL>{TCP_MAX_CONNECTIONS}	{ count(); yylval.strval=yytext;
 									return TCP_MAX_CONNECTIONS; }
61f8b970
 <INITIAL>{TLS_MAX_CONNECTIONS}	{ count(); yylval.strval=yytext;
 									return TLS_MAX_CONNECTIONS; }
de223f01
 <INITIAL>{TCP_NO_CONNECT}		{ count(); yylval.strval=yytext;
 									return TCP_NO_CONNECT; }
761bd309
 <INITIAL>{TCP_SOURCE_IPV4}		{ count(); yylval.strval=yytext;
 									return TCP_SOURCE_IPV4; }
 <INITIAL>{TCP_SOURCE_IPV6}		{ count(); yylval.strval=yytext;
 									return TCP_SOURCE_IPV6; }
20c64cc6
 <INITIAL>{TCP_OPT_FD_CACHE}		{ count(); yylval.strval=yytext;
 									return TCP_OPT_FD_CACHE; }
885b9f62
 <INITIAL>{TCP_OPT_CONN_WQ_MAX}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_CONN_WQ_MAX; }
 <INITIAL>{TCP_OPT_WQ_MAX}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_WQ_MAX; }
e655392a
 <INITIAL>{TCP_OPT_RD_BUF}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_RD_BUF; }
 <INITIAL>{TCP_OPT_WQ_BLK}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_WQ_BLK; }
885b9f62
 <INITIAL>{TCP_OPT_BUF_WRITE}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_BUF_WRITE; }
20c64cc6
 <INITIAL>{TCP_OPT_DEFER_ACCEPT}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_DEFER_ACCEPT; }
 <INITIAL>{TCP_OPT_DELAYED_ACK}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_DELAYED_ACK; }
 <INITIAL>{TCP_OPT_SYNCNT}		{ count(); yylval.strval=yytext;
 									return TCP_OPT_SYNCNT; }
 <INITIAL>{TCP_OPT_LINGER2}		{ count(); yylval.strval=yytext;
 									return TCP_OPT_LINGER2; }
 <INITIAL>{TCP_OPT_KEEPALIVE}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_KEEPALIVE; }
 <INITIAL>{TCP_OPT_KEEPIDLE}		{ count(); yylval.strval=yytext;
 									return TCP_OPT_KEEPIDLE; }
 <INITIAL>{TCP_OPT_KEEPINTVL}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_KEEPINTVL; }
 <INITIAL>{TCP_OPT_KEEPCNT}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_KEEPCNT; }
c7337a27
 <INITIAL>{TCP_OPT_CRLF_PING}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_CRLF_PING; }
d4cc4103
 <INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_ACCEPT_NO_CL; }
691a3439
 <INITIAL>{TCP_CLONE_RCVBUF}		{ count(); yylval.strval=yytext;
 									return TCP_CLONE_RCVBUF; }
46506980
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
6c53d41a
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_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; }
0973fee7
 <INITIAL>{TLS_CERTIFICATE}	{ count(); yylval.strval=yytext;
46506980
 										return TLS_CERTIFICATE; }
0973fee7
 <INITIAL>{TLS_PRIVATE_KEY}	{ count(); yylval.strval=yytext;
46506980
 										return TLS_PRIVATE_KEY; }
0973fee7
 <INITIAL>{TLS_CA_LIST}	{ count(); yylval.strval=yytext;
46506980
 										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; }
ed990c31
 <INITIAL>{DISABLE_SCTP}	{ count(); yylval.strval=yytext; return DISABLE_SCTP;}
c8e95587
 <INITIAL>{ENABLE_SCTP}	{ count(); yylval.strval=yytext; return ENABLE_SCTP;}
ed990c31
 <INITIAL>{SCTP_CHILDREN}	{ count(); yylval.strval=yytext;
 										return SCTP_CHILDREN; }
caf80ae6
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
c745469f
 <INITIAL>{SERVER_HEADER}	{ count(); yylval.strval=yytext; return SERVER_HEADER; }
 <INITIAL>{USER_AGENT_HEADER}	{ count(); yylval.strval=yytext; return USER_AGENT_HEADER; }
caf80ae6
 <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; }
647cc983
 <INITIAL>{SHM_MEM_SZ}		{	count(); yylval.strval=yytext;
 									return SHM_MEM_SZ; }
71a0a583
 <INITIAL>{SHM_FORCE_ALLOC}		{	count(); yylval.strval=yytext;
 									return SHM_FORCE_ALLOC; }
 <INITIAL>{MLOCK_PAGES}		{	count(); yylval.strval=yytext;
 									return MLOCK_PAGES; }
 <INITIAL>{REAL_TIME}		{	count(); yylval.strval=yytext;
 									return REAL_TIME; }
 <INITIAL>{RT_PRIO}		{	count(); yylval.strval=yytext;
 									return RT_PRIO; }
 <INITIAL>{RT_POLICY}		{	count(); yylval.strval=yytext;
 									return RT_POLICY; }
 <INITIAL>{RT_TIMER1_PRIO}		{	count(); yylval.strval=yytext;
 									return RT_TIMER1_PRIO; }
 <INITIAL>{RT_TIMER1_POLICY}		{	count(); yylval.strval=yytext;
 									return RT_TIMER1_POLICY; }
 <INITIAL>{RT_TIMER2_PRIO}		{	count(); yylval.strval=yytext;
 									return RT_TIMER2_PRIO; }
 <INITIAL>{RT_TIMER2_POLICY}		{	count(); yylval.strval=yytext;
 									return RT_TIMER2_POLICY; }
2ba73117
 <INITIAL>{MCAST_LOOPBACK}		{	count(); yylval.strval=yytext;
 									return MCAST_LOOPBACK; }
 <INITIAL>{MCAST_TTL}		{	count(); yylval.strval=yytext;
 									return MCAST_TTL; }
fe09f315
 <INITIAL>{TOS}			{	count(); yylval.strval=yytext;
 									return TOS; }
f3a26797
 <INITIAL>{PMTU_DISCOVERY}		{	count(); yylval.strval=yytext;
 									return PMTU_DISCOVERY; }
96d09107
 <INITIAL>{KILL_TIMEOUT}			{	count(); yylval.strval=yytext;
 									return KILL_TIMEOUT; }
d14a718f
 <INITIAL>{MAX_WLOOPS}			{	count(); yylval.strval=yytext;
 									return MAX_WLOOPS; }
7614a1d0
 <INITIAL>{PVBUFSIZE}			{	count(); yylval.strval=yytext;
 									return PVBUFSIZE; }
 <INITIAL>{PVBUFSLOTS}			{	count(); yylval.strval=yytext;
 									return PVBUFSLOTS; }
adf32ec8
 <INITIAL>{HTTP_REPLY_PARSE}		{	count(); yylval.strval=yytext;
 									return HTTP_REPLY_PARSE; }
8fb8b261
 <INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
89fde575
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
d1c60718
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
e008edb9
 <INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
930aba29
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
d4ed4771
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
214b161e
 <INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
930aba29
 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
 <INITIAL>{LATENCY_LIMIT_ACTION}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;}
140137c9
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
3bf76e49
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
6c8f8d5b
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
31309a3a
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
3c1a8ef8
 
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
8126b425
 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
3c1a8ef8
 <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; }
1644a0f1
 <INITIAL>{LOG_AND}	{ count(); return LOG_AND; }
 <INITIAL>{BIN_AND}	{ count(); return BIN_AND; }
 <INITIAL>{LOG_OR}	{ count(); return LOG_OR;  }
 <INITIAL>{BIN_OR}	{ count(); return BIN_OR;  }
508ad1c0
 <INITIAL>{BIN_NOT}	{ count(); return BIN_NOT;  }
 <INITIAL>{BIN_XOR}	{ count(); return BIN_XOR;  }
 <INITIAL>{BIN_LSHIFT}	{ count(); return BIN_LSHIFT;  }
 <INITIAL>{BIN_RSHIFT}	{ count(); return BIN_RSHIFT;  }
91ab6402
 <INITIAL>{PLUS}		{ count(); return PLUS; }
 <INITIAL>{MINUS}	{ count(); return MINUS; }
333a3335
 <INITIAL>{MODULO}	{ count(); return MODULO; }
d4799027
 <INITIAL>{STRLEN}	{ count(); return STRLEN; }
 <INITIAL>{STREMPTY}	{ count(); return STREMPTY; }
 <INITIAL>{DEFINED}	{ count(); return DEFINED; }
298512a2
 <INITIAL>{STREQ}	{ count(); return STREQ; }
 <INITIAL>{INTEQ}	{ count(); return INTEQ; }
 <INITIAL>{STRDIFF}	{ count(); return STRDIFF; }
 <INITIAL>{INTDIFF}	{ count(); return INTDIFF; }
e41bc057
 <INITIAL>{INTCAST}	{ count(); return INTCAST; }
 <INITIAL>{STRCAST}	{ count(); return STRCAST; }
3c1a8ef8
 
3fb428ed
 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
0973fee7
 <SELECT>{ID}		{ count(); addstr(&s_buf, yytext, yyleng);
3fb428ed
                           yylval.strval=s_buf.s;
                           memset(&s_buf, 0, sizeof(s_buf));
0973fee7
                           return ID;
3fb428ed
                         }
 <SELECT>{DOT}           { count(); return DOT; }
 <SELECT>{LBRACK}        { count(); return LBRACK; }
 <SELECT>{RBRACK}        { count(); return RBRACK; }
f9276a5b
 <SELECT>{DECNUMBER}	{ count(); yylval.intval=atoi(yytext);
 						yy_number_str=yytext; return NUMBER; }
 <SELECT>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16);
 						yy_number_str=yytext; return NUMBER; }
 <SELECT>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8);
 						yy_number_str=yytext; return NUMBER; }
 <SELECT>{BINNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 2);
 						yy_number_str=yytext; return NUMBER; }
3fb428ed
 
 
26a886bc
 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
 							return ATTR_MARK; }
fd6d4dc9
 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
e61ba5d2
 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
18cf23c0
 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
1644a0f1
 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
 <ATTR>{DOT}             { count(); return DOT; }
145e3fb3
 <ATTR>{LBRACK}          { count(); return LBRACK; }
 <ATTR>{RBRACK}          { count(); return RBRACK; }
26a886bc
 <ATTR>{STAR}			{ count(); return STAR; }
4d601c6d
 <ATTR>{DECNUMBER}		{ count(); yylval.intval=atoi(yytext);
 							yy_number_str=yytext; return NUMBER; }
26a886bc
 <ATTR>{ID}				{ count(); addstr(&s_buf, yytext, yyleng);
 							yylval.strval=s_buf.s;
 							memset(&s_buf, 0, sizeof(s_buf));
 							state = INITIAL_S;
 							BEGIN(INITIAL);
 							return ID;
 						}
 
f69ff7d9
 <INITIAL>{VAR_MARK}{LPAREN}	{
 								switch(sr_cfg_compat){
 									case SR_COMPAT_SER:
 										state=ATTR_S; BEGIN(ATTR);
 										yyless(1);
 										count();
 										return ATTR_MARK;
 										break;
 									case SR_COMPAT_KAMAILIO:
 									case SR_COMPAT_MAX:
 									default:
 										state = PVAR_P_S; BEGIN(PVAR_P);
 										p_nest=1; yymore();
 										break;
 								}
 							}
26a886bc
 	/* eat everything between 2 () and return PVAR token and a string
 	   containing everything (including $ and ()) */
 <PVAR_P>{RPAREN}			{	p_nest--;
 								if (p_nest==0){
 									count();
 									addstr(&s_buf, yytext, yyleng);
39ffe589
 									r = pp_subst_run(&s_buf.s);
26a886bc
 									yylval.strval=s_buf.s;
 									memset(&s_buf, 0, sizeof(s_buf));
 									state=INITIAL_S;
 									BEGIN(INITIAL);
 									return PVAR;
 								}
 								yymore();
 							}
1c67272d
 <PVAR_P>{LPAREN}			{ p_nest++; yymore(); }
26a886bc
 <PVAR_P>.					{ yymore(); }
 
796ee85e
 <PVARID>{ID}|'\.'			{yymore(); }
f69ff7d9
 <PVARID>{LPAREN}			{	state = PVAR_P_S; BEGIN(PVAR_P);
 								p_nest=1; yymore(); }
d2d6b4b9
 <PVARID>{CR}|{EAT_ABLE}|.	{	yyless(yyleng-1);
796ee85e
 								count();
 								addstr(&s_buf, yytext, yyleng);
39ffe589
 								r = pp_subst_run(&s_buf.s);
796ee85e
 								yylval.strval=s_buf.s;
 								memset(&s_buf, 0, sizeof(s_buf));
 								state=INITIAL_S;
 								BEGIN(INITIAL);
f69ff7d9
 								return PVAR;
 							}
26a886bc
 
0c73dfed
 	/* if found retcode => it's a built-in pvar */
 <INITIAL>{RETCODE}			{ count(); yylval.strval=yytext; return PVAR; }
f69ff7d9
 
 <INITIAL>{VAR_MARK}			{
 								switch(sr_cfg_compat){
 									case SR_COMPAT_SER:
 										count();
 										state=ATTR_S; BEGIN(ATTR);
 										return ATTR_MARK;
 										break;
 									case SR_COMPAT_KAMAILIO:
 										state=PVARID_S; BEGIN(PVARID);
 										yymore();
 										break;
 									case SR_COMPAT_MAX:
 									default: 
 										state=AVP_PVAR_S; BEGIN(AVP_PVAR);
 										yymore();
 										break;
 								}
 							}
26a886bc
 	/* avp prefix detected -> go to avp mode */
 <AVP_PVAR>{AVP_PREF}		|
070afdb2
 <AVP_PVAR>{ID}{LBRACK}		{ state = ATTR_S; BEGIN(ATTR); yyless(1); count();
26a886bc
 							  return ATTR_MARK; }
2ac5604b
 <AVP_PVAR>{ID}{LPAREN}		{ state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
 								yymore(); }
f69ff7d9
 <AVP_PVAR>{ID}				{	count(); addstr(&s_buf, yytext, yyleng);
26a886bc
 								yylval.strval=s_buf.s;
 								memset(&s_buf, 0, sizeof(s_buf));
 								state = INITIAL_S;
 								BEGIN(INITIAL);
 								return AVP_OR_PVAR;
 							}
4e2fdd79
 
 <INITIAL>{IPV6ADDR}		{ count(); yylval.strval=yytext; return IPV6ADDR; }
f9276a5b
 <INITIAL>{DECNUMBER}	{ count(); yylval.intval=atoi(yytext);
 								yy_number_str=yytext; return NUMBER; }
58481278
 <INITIAL>{HEXNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 16);
f9276a5b
 							yy_number_str=yytext; return NUMBER; }
58481278
 <INITIAL>{OCTNUMBER}	{ count(); yylval.intval=(int)strtol(yytext, 0, 8);
4d601c6d
 							yy_number_str=yytext; return NUMBER; }
f9276a5b
 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
 							yy_number_str=yytext; return NUMBER; }
 <INITIAL>{YES}			{ count(); yylval.intval=1;
 							yy_number_str=yytext; return NUMBER; }
 <INITIAL>{NO}			{ count(); yylval.intval=0;
 							yy_number_str=yytext; return NUMBER; }
e5f4cdaf
 <INITIAL>{TCP}			{ count(); return TCP; }
 <INITIAL>{UDP}			{ count(); return UDP; }
 <INITIAL>{TLS}			{ count(); return TLS; }
c9831d2a
 <INITIAL>{SCTP}			{ count(); return SCTP; }
8c6f700b
 <INITIAL>{WS}			{ count(); return WS; }
8393efff
 <INITIAL>{WSS}			{ count(); return WSS; }
f9276a5b
 <INITIAL>{INET}			{ count(); yylval.intval=AF_INET;
 							yy_number_str=yytext; return NUMBER; }
aeb805d5
 <INITIAL>{INET6}		{ count();
abdf40da
 						yylval.intval=AF_INET6;
f9276a5b
 						yy_number_str=yytext;
 						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; }
9c674bfa
 <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
 
 
9c674bfa
 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; 
 							old_state = state; state=STRING_S;
 							BEGIN(STRING1); }
 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state;
 					state=STRING_S; BEGIN(STRING2); }
3c1a8ef8
 
 
9c674bfa
 <STRING1>{QUOTES} { count_more(); 
3c1a8ef8
 						yytext[yyleng-1]=0; yyleng--;
7e1a294e
 						addstr(&s_buf, yytext, yyleng);
f84c93b3
 						state=STR_BETWEEN_S;
070afdb2
 						BEGIN(STR_BETWEEN);
3c1a8ef8
 					}
9c674bfa
 <STRING2>{TICK}  { count_more(); state=old_state; BEGIN(old_initial);
3c1a8ef8
 						yytext[yyleng-1]=0; yyleng--;
7e1a294e
 						addstr(&s_buf, yytext, yyleng);
20cddb28
 						r = pp_subst_run(&s_buf.s);
7e1a294e
 						yylval.strval=s_buf.s;
 						memset(&s_buf, 0, sizeof(s_buf));
c07508e2
 						return STRING;
3c1a8ef8
 					}
 <STRING2>.|{EAT_ABLE}|{CR}	{ yymore(); }
 
9c674bfa
 <STRING1>\\n		{ count_more(); addchar(&s_buf, '\n'); }
 <STRING1>\\r		{ count_more(); addchar(&s_buf, '\r'); }
 <STRING1>\\a		{ count_more(); addchar(&s_buf, '\a'); }
 <STRING1>\\t		{ count_more(); addchar(&s_buf, '\t'); }
 <STRING1>\\{QUOTES}	{ count_more(); addchar(&s_buf, '"');  }
 <STRING1>\\\\		{ count_more(); addchar(&s_buf, '\\'); }
 <STRING1>\\x{HEX}{1,2}	{ count_more(); addchar(&s_buf,
7e1a294e
 											(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) */
9c674bfa
 <STRING1>\\[0-7]{2,3}	{ count_more(); addchar(&s_buf,
7e1a294e
 											(char)strtol(yytext+1, 0, 8));  }
9c674bfa
 <STRING1>\\{CR}		{ count_more(); } /* eat escaped CRs */
 <STRING1>.|{EAT_ABLE}|{CR}	{ count_more(); addchar(&s_buf, *yytext); }
 
 <STR_BETWEEN>{EAT_ABLE}|{CR}	{ count_ignore(); }
 <STR_BETWEEN>{QUOTES}			{ count_more(); state=STRING_S;
 								  BEGIN(STRING1);}
 <STR_BETWEEN>.					{	
 									yyless(0); /* reparse it */
 									/* ignore the whitespace now that is
 									  counted, return saved string value */
070afdb2
 									state=old_state; BEGIN(old_initial);
20cddb28
 									r = pp_subst_run(&s_buf.s);
070afdb2
 									yylval.strval=s_buf.s;
 									memset(&s_buf, 0, sizeof(s_buf));
 									return STRING;
 								}
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(); };
 
f69ff7d9
 <INITIAL>{COM_LINE}!{SER_CFG}{CR}		{ count();
 											sr_cfg_compat=SR_COMPAT_SER;}
 <INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}	{ count(); 
 											sr_cfg_compat=SR_COMPAT_KAMAILIO;}
 <INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR}	{ count(); 
 												sr_cfg_compat=SR_COMPAT_MAX;}
360c6412
 
13de789c
 <INITIAL>{PREP_START}{DEFINE}{EAT_ABLE}+	{	count(); pp_define_set_type(0);
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
 <INITIAL>{PREP_START}{TRYDEF}{EAT_ABLE}+	{	count(); pp_define_set_type(1);
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
 <INITIAL>{PREP_START}{REDEF}{EAT_ABLE}+	{	count(); pp_define_set_type(2);
20cddb28
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
 <DEFINE_ID>{ID}                 {	count();
 									if (pp_define(yyleng, yytext)) return 1;
 									state = DEFINE_EOL_S; BEGIN(DEFINE_EOL); }
 <DEFINE_EOL>{EAT_ABLE}			{	count(); }
 <DEFINE_EOL>{CR}				{	count();
360c6412
 									state = INITIAL; BEGIN(INITIAL); }
20cddb28
 <DEFINE_EOL>.                   {	count();
 									addstr(&s_buf, yytext, yyleng);
 									state = DEFINE_DATA_S; BEGIN(DEFINE_DATA); }
 <DEFINE_DATA>\\{CR}		{	count(); } /* eat the escaped CR */
 <DEFINE_DATA>{CR}		{	count();
 							if (pp_define_set(strlen(s_buf.s), s_buf.s)) return 1;
 							memset(&s_buf, 0, sizeof(s_buf));
 							state = INITIAL; BEGIN(INITIAL); }
 <DEFINE_DATA>.          {	count();
 							addstr(&s_buf, yytext, yyleng); }
 
47b81cd0
 <INITIAL>{PREP_START}{SUBST}	{ count();  return SUBST;}
78d26523
 <INITIAL>{PREP_START}{SUBSTDEF}	{ count();  return SUBSTDEF;}
8198fd2b
 <INITIAL>{PREP_START}{SUBSTDEFS}	{ count();  return SUBSTDEFS;}
360c6412
 
47b81cd0
 <INITIAL,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+    { count();
360c6412
 								if (pp_ifdef_type(1)) return 1;
 								state = IFDEF_S; BEGIN(IFDEF_ID); }
47b81cd0
 <INITIAL,IFDEF_SKIP>{PREP_START}{IFNDEF}{EAT_ABLE}+    { count();
360c6412
 								if (pp_ifdef_type(0)) return 1;
 								state = IFDEF_S; BEGIN(IFDEF_ID); }
 <IFDEF_ID>{ID}                { count();
                                 pp_ifdef_var(yyleng, yytext);
                                 state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); }
 <IFDEF_EOL>{EAT_ABLE}*{CR}    { count(); pp_ifdef(); }
 
47b81cd0
 <INITIAL,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR}    { count(); pp_else(); }
360c6412
 
47b81cd0
 <INITIAL,IFDEF_SKIP>{PREP_START}{ENDIF}{EAT_ABLE}*{CR}    { count();
360c6412
 															pp_endif(); }
 
  /* we're in an ifdef that evaluated to false -- throw it away */
 <IFDEF_SKIP>.|{CR}    { count(); }
 
  /* this is split so the shebangs match more, giving them priority */
 <INITIAL>{COM_LINE}        { count(); state = LINECOMMENT_S;
 								BEGIN(LINECOMMENT); }
 <LINECOMMENT>.*{CR}        { count(); state = INITIAL_S; BEGIN(INITIAL); }
3c1a8ef8
 
20cddb28
 <INITIAL>{ID}		{	if ((sdef = pp_define_get(yyleng, yytext))!=NULL) {
 							for (r=sdef->len-1; r>=0; r--)
 								unput(sdef->s[r]); /* reverse order */
 						} else {
 							count();
 							addstr(&s_buf, yytext, yyleng);
 							yylval.strval=s_buf.s;
 							memset(&s_buf, 0, sizeof(s_buf));
 							return ID;
 						}
 					}
f9276a5b
 <INITIAL>{NUM_ID}			{ count(); addstr(&s_buf, yytext, yyleng);
 									yylval.strval=s_buf.s;
 									memset(&s_buf, 0, sizeof(s_buf));
 									return NUM_ID; }
3c1a8ef8
 
5d0fe6b0
 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
 
1c9c433f
 <INCLF>[ \t]*      /* eat the whitespace */
dc0bc9de
 <INCLF>[^ \t\r\n]+   { /* get the include file name */
4c5120b7
 				memset(&s_buf, 0, sizeof(s_buf));
 				addstr(&s_buf, yytext, yyleng);
 				r = pp_subst_run(&s_buf.s);
 				if(sr_push_yy_state(s_buf.s, 0)<0)
1cdad56c
 				{
 					LOG(L_CRIT, "error at %s line %d\n", (finame)?finame:"cfg", line);
 					exit(-1);
 				}
4c5120b7
 				memset(&s_buf, 0, sizeof(s_buf));
1cdad56c
 				BEGIN(INITIAL);
 }
 
 <IMPTF>[ \t]*      /* eat the whitespace */
dc0bc9de
 <IMPTF>[^ \t\r\n]+   { /* get the import file name */
4c5120b7
 				memset(&s_buf, 0, sizeof(s_buf));
 				addstr(&s_buf, yytext, yyleng);
 				r = pp_subst_run(&s_buf.s);
 				if(sr_push_yy_state(s_buf.s, 1)<0)
2b680bde
 				{
 					LOG(L_CRIT, "error at %s line %d\n", (finame)?finame:"cfg", line);
d2056519
 					exit(-1);
2b680bde
 				}
4c5120b7
 				memset(&s_buf, 0, sizeof(s_buf));
d2056519
 				BEGIN(INITIAL);
 }
 
3c1a8ef8
 
 <<EOF>>							{
 									switch(state){
070afdb2
 										case STR_BETWEEN_S:
 											state=old_state;
 											BEGIN(old_initial);
20cddb28
 											r = pp_subst_run(&s_buf.s);
070afdb2
 											yylval.strval=s_buf.s;
 											memset(&s_buf, 0, sizeof(s_buf));
 											return STRING;
0973fee7
 										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;
ea6f7be1
 										case  ATTR_S:
 											LOG(L_CRIT, "ERROR: unexpected EOF"
 													" while parsing"
 													" avp name\n");
 											break;
f69ff7d9
 										case PVARID_S:
 											p_nest=0;
ea6f7be1
 										case PVAR_P_S: 
 											LOG(L_CRIT, "ERROR: unexpected EOF"
 													" while parsing pvar name"
 													" (%d paranthesis open)\n",
 													p_nest);
 											break;
 										case AVP_PVAR_S:
 											LOG(L_CRIT, "ERROR: unexpected EOF"
 													" while parsing"
 													" avp or pvar name\n");
3c1a8ef8
 									}
d2056519
 									if(sr_pop_yy_state()<0)
 										return 0;
3c1a8ef8
 								}
0973fee7
 
3c1a8ef8
 %%
 
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;
0973fee7
 
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){
0973fee7
 			memcpy(tmp, dst_b->s, used);
7e1a294e
 			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;
0973fee7
 
7e1a294e
 	return dst_b->s;
3c1a8ef8
 error:
7268726e
 	LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
831a9a48
 	LOG(L_CRIT, "ERROR:lex:addstr: try to increase pkg size with"
 					" -M parameter\n");
 	exit(-1);
3c1a8ef8
 }
 
 
 
9c674bfa
 /** helper function for count_*(). */
 static void count_lc(int* l, int* c)
3c1a8ef8
 {
 	int i;
 	for (i=0; i<yyleng;i++){
 		if (yytext[i]=='\n'){
9c674bfa
 			(*l)++;
 			(*c)=1;
3c1a8ef8
 		}else if (yytext[i]=='\t'){
9c674bfa
 			(*c)++;
 			/*(*c)+=8 -((*c)%8);*/
3c1a8ef8
 		}else{
9c674bfa
 			(*c)++;
3c1a8ef8
 		}
 	}
 }
 
34285950
 
 
9c674bfa
 /* helper function */
 static void count_restore_ignored()
 {
 	if (ign_lines) /* ignored line(s) => column has changed */
 		column=ign_columns;
 	else
 		column+=ign_columns;
 	line+=ign_lines;
 	ign_lines=ign_columns=0;
 }
 
 
 
 /** count/record position for stuff added to the current token. */
 static void count_more()
 {
 	count_restore_ignored();
 	count_lc(&line, &column);
 }
 
 
 
 /** count/record position for a new token. */
 static void count()
 {
 	count_restore_ignored();
 	startline=line;
 	startcolumn=column;
 	count_more();
 }
 
 
 
 /** record discarded stuff (not contained in the token) so that
     the next token position can be adjusted properly*/
 static void count_ignore()
 {
 	count_lc(&ign_lines, &ign_columns);
 }
 
 
34285950
 /* replacement yywrap, removes libfl dependency */
 int yywrap()
 {
 	return 1;
 }
d2056519
 
1cdad56c
 static int sr_push_yy_state(char *fin, int mode)
d2056519
 {
 	struct sr_yy_fname *fn = NULL;
1cdad56c
 	FILE *fp = NULL;
d2056519
 	char *x = NULL;
 	char *newf = NULL;
eb312498
 #define MAX_INCLUDE_FNAME	128
 	char fbuf[MAX_INCLUDE_FNAME];
 	int i, j, l;
1cdad56c
 	char *tmpfiname = 0;
d2056519
 
 	if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
 	{
 		LOG(L_CRIT, "too many includes\n");
 		return -1;
 	}
eb312498
 	l = strlen(fin);
 	if(l>=MAX_INCLUDE_FNAME)
 	{
4c5120b7
 		LOG(L_CRIT, "included file name too long: %s\n", fin);
eb312498
 		return -1;
 	}
 	if(fin[0]!='"' || fin[l-1]!='"')
 	{
4c5120b7
 		LOG(L_CRIT, "included file name must be between quotes: %s\n", fin);
eb312498
 		return -1;
 	}
 	j = 0;
 	for(i=1; i<l-1; i++)
 	{
 		switch(fin[i]) {
 			case '\\':
 				if(i+1==l-1)
 				{
4c5120b7
 					LOG(L_CRIT, "invalid escape at %d in included file name: %s\n", i, fin);
eb312498
 					return -1;
 				}
 				i++;
 				switch(fin[i]) {
 					case 't':
 						fbuf[j++] = '\t';
 					break;
 					case 'n':
 						fbuf[j++] = '\n';
 					break;
 					case 'r':
 						fbuf[j++] = '\r';
 					break;
 					default:
 						fbuf[j++] = fin[i];
 				}
 			break;
 			default:
 				fbuf[j++] = fin[i];
 		}
 	}
 	if(j==0)
 	{
4c5120b7
 		LOG(L_CRIT, "invalid included file name: %s\n", fin);
eb312498
 		return -1;
 	}
 	fbuf[j] = '\0';
d2056519
 
1cdad56c
 	fp = fopen(fbuf, "r" );
d2056519
 
1cdad56c
 	if ( ! fp )
d2056519
 	{
1cdad56c
 		tmpfiname = (finame==0)?cfg_file:finame;
 		if(tmpfiname==0 || fbuf[0]=='/')
d2056519
 		{
1cdad56c
 			if(mode==0)
 			{
 				LOG(L_CRIT, "cannot open included file: %s\n", fin);
 				return -1;
 			} else {
 				LOG(L_DBG, "importing file ignored: %s\n", fin);
 				return 0;
 			}
d2056519
 		}
1cdad56c
 		x = strrchr(tmpfiname, '/');
 		if(x==NULL)
d2056519
 		{
1cdad56c
 			/* nothing else to try */
 			if(mode==0)
d2056519
 			{
1cdad56c
 				LOG(L_CRIT, "cannot open included file: %s\n", fin);
d2056519
 				return -1;
1cdad56c
 			} else {
 				LOG(L_DBG, "importing file ignored: %s\n", fin);
 				return 0;
d2056519
 			}
 		}
1cdad56c
 
 		newf = (char*)pkg_malloc(x-tmpfiname+strlen(fbuf)+2);
 		if(newf==0)
d2056519
 		{
1cdad56c
 			LOG(L_CRIT, "no more pkg\n");
d2056519
 			return -1;
 		}
1cdad56c
 		newf[0] = '\0';
 		strncat(newf, tmpfiname, x-tmpfiname);
 		strcat(newf, "/");
 		strcat(newf, fbuf);
 
 		fp = fopen(newf, "r" );
 		if ( fp==NULL )
 		{
 			pkg_free(newf);
 			if(mode==0)
 			{
 				LOG(L_CRIT, "cannot open included file: %s (%s)\n", fbuf, newf);
 				return -1;
 			} else {
 				LOG(L_DBG, "importing file ignored: %s (%s)\n", fbuf, newf);
 				return 0;
 			}
 		}
eb312498
 		LOG(L_DBG, "including file: %s (%s)\n", fbuf, newf);
d2056519
 	} else {
eb312498
 		newf = fbuf;
d2056519
 	}
 
1cdad56c
 	include_stack[include_stack_ptr].state = YY_CURRENT_BUFFER;
 	include_stack[include_stack_ptr].line = line;
 	include_stack[include_stack_ptr].column = column;
 	include_stack[include_stack_ptr].startline = startline;
 	include_stack[include_stack_ptr].startcolumn = startcolumn;
 	include_stack[include_stack_ptr].finame = finame;
c44685cb
 	include_stack[include_stack_ptr].routename = routename;
1cdad56c
 	include_stack_ptr++;
 
 	line=1;
 	column=1;
 	startline=1;
 	startcolumn=1;
 
 	yyin = fp;
 
eb312498
 	/* make a copy in PKG if does not exist */
d2056519
 	fn = sr_yy_fname_list;
 	while(fn!=0)
 	{
 		if(strcmp(fn->fname, newf)==0)
 		{
eb312498
 			if(newf!=fbuf)
d2056519
 				pkg_free(newf);
eb312498
 			newf = fbuf;
d2056519
 			break;
 		}
 		fn = fn->next;
 	}
 	if(fn==0)
 	{
 		fn = (struct sr_yy_fname*)pkg_malloc(sizeof(struct sr_yy_fname));
 		if(fn==0)
 		{
eb312498
 			if(newf!=fbuf)
d2056519
 				pkg_free(newf);
 			LOG(L_CRIT, "no more pkg\n");
 			return -1;
 		}
eb312498
 		if(newf==fbuf)
d2056519
 		{
eb312498
 			fn->fname = (char*)pkg_malloc(strlen(fbuf)+1);
d2056519
 			if(fn->fname==0)
 			{
 				pkg_free(fn);
 				LOG(L_CRIT, "no more pkg!\n");
 				return -1;
 			}
eb312498
 			strcpy(fn->fname, fbuf);
d2056519
 		} else {
 			fn->fname = newf;
 		}
 		fn->next = sr_yy_fname_list;
 		sr_yy_fname_list = fn;
 	}
 
 	finame = fn->fname;
 
 	yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE ) );
 
 	return 0;
 
 }
 
 static int sr_pop_yy_state()
 {
 	include_stack_ptr--;
 	if (include_stack_ptr<0 )
 		return -1;
 
 	yy_delete_buffer( YY_CURRENT_BUFFER );
 	yy_switch_to_buffer(include_stack[include_stack_ptr].state);
 	line=include_stack[include_stack_ptr].line;
 	column=include_stack[include_stack_ptr].column;
 	startline=include_stack[include_stack_ptr].startline;
 	startcolumn=include_stack[include_stack_ptr].startcolumn;
 	finame = include_stack[include_stack_ptr].finame;
 	return 0;
 }
 
360c6412
 /* define/ifdef support */
 
20cddb28
 #define MAX_DEFINES    256
 static str pp_defines[MAX_DEFINES][2];
360c6412
 static int pp_num_defines = 0;
13de789c
 static int pp_define_type = 0;
 static int pp_define_index = -1;
360c6412
 
 /* pp_ifdef_stack[i] is 1 if the ifdef test at depth i is either
  * ifdef(defined), ifndef(undefined), or the opposite of these
  * two, but in an else branch
  */
20cddb28
 #define MAX_IFDEFS    256
360c6412
 static int pp_ifdef_stack[MAX_IFDEFS];
 static int pp_sptr = 0; /* stack pointer */
 
 static int pp_lookup(int len, const char * text)
 {
 	str var = {(char *)text, len};
 	int i;
 
 	for (i=0; i<pp_num_defines; i++)
20cddb28
 		if (STR_EQ(pp_defines[i][0], var))
360c6412
 			return i;
 
 	return -1;
 }
 
13de789c
 int pp_define_set_type(int type)
 {
 	pp_define_type = type;
 	return 0;
 }
 
95dec431
 int pp_define(int len, const char * text)
360c6412
 {
13de789c
 	int ppos;
 
04ff37ee
 	LM_DBG("defining id: %.*s\n", len, text);
13de789c
 
360c6412
 	if (pp_num_defines == MAX_DEFINES) {
 		LOG(L_CRIT, "ERROR: too many defines -- adjust MAX_DEFINES\n");
 		return -1;
 	}
 
13de789c
 	pp_define_index = -1;
 	ppos = pp_lookup(len, text);
 	if(ppos >= 0) {
 		if(pp_define_type==1) {
 			LOG(L_DBG, "ignoring - already defined: %.*s\n", len, text);
 			pp_define_index = -2;
 			return 0;
 		} else if(pp_define_type==2) {
 			LOG(L_DBG, "redefining: %.*s\n", len, text);
 			pp_define_index = ppos;
 			if(pp_defines[ppos][1].s != NULL) {
 				pkg_free(pp_defines[ppos][1].s);
 				pp_defines[ppos][1].len = 0;
 				pp_defines[ppos][1].s = NULL;
 			}
 			return 0;
 		} else {
 			LOG(L_CRIT, "ERROR: already defined: %.*s\n", len, text);
 			return -1;
 		}
360c6412
 	}
 
20cddb28
 	pp_defines[pp_num_defines][0].len = len;
 	pp_defines[pp_num_defines][0].s = (char*)pkg_malloc(len+1);
13de789c
 	if(pp_defines[pp_num_defines][0].s==NULL) {
 		LOG(L_CRIT, "no more memory to define: %.*s\n", len, text);
 		return -1;
 	}
20cddb28
 	memcpy(pp_defines[pp_num_defines][0].s, text, len);
 	pp_defines[pp_num_defines][1].len = 0;
 	pp_defines[pp_num_defines][1].s = NULL;
13de789c
 	pp_define_index = pp_num_defines;
360c6412
 	pp_num_defines++;
 
 	return 0;
 }
 
78d26523
 int pp_define_set(int len, char *text)
20cddb28
 {
13de789c
 	int ppos;
 
 	if(pp_define_index == -2) {
 		/* #!trydef that should be ignored */
 		return 0;
 	}
 
 	if(pp_define_index < 0) {
 		/* invalid position in define table */
 		LOG(L_BUG, "BUG: the index in define table not set yet\n");
 		return -1;
 	}
20cddb28
 	if(len<=0) {
 		LOG(L_DBG, "no define value - ignoring\n");
 		return 0;
 	}
 	if (pp_num_defines == MAX_DEFINES) {
13de789c
 		LOG(L_CRIT, "ERROR: too many defines -- adjust MAX_DEFINES\n");
20cddb28
 		return -1;
 	}
 	if (pp_num_defines == 0) {
13de789c
 		LOG(L_BUG, "BUG: setting define value, but no define id yet\n");
20cddb28
 		return -1;
 	}
 
13de789c
 	ppos = pp_define_index;
 	if (pp_defines[ppos][0].s == NULL) {
20cddb28
 		LOG(L_BUG, "BUG: last define ID is null\n");
 		return -1;
 	}
 
13de789c
 	if (pp_defines[ppos][1].s != NULL) {
 		LOG(L_BUG, "BUG: ID %.*s [%d] overwritten\n",
 			pp_defines[ppos][0].len,
 			pp_defines[ppos][0].s, ppos);
20cddb28
 		return -1;
 	}
 
13de789c
 	pp_defines[ppos][1].len = len;
 	pp_defines[ppos][1].s = text;
20cddb28
 	LM_DBG("### setting define ID [%.*s] value [%.*s]\n",
13de789c
 			pp_defines[ppos][0].len,
 			pp_defines[ppos][0].s,
 			pp_defines[ppos][1].len,
 			pp_defines[ppos][1].s);
20cddb28
 	return 0;
 }
 
78d26523
 static str *pp_define_get(int len, const char * text)
20cddb28
 {
 	str var = {(char *)text, len};
 	int i;
 
 	for (i=0; i<pp_num_defines; i++)
 	{
 		if (STR_EQ(pp_defines[i][0], var))
 		{
 			if(pp_defines[i][0].s!=NULL)
 			{
 				LM_DBG("### returning define ID [%.*s] value [%.*s]\n",
 					pp_defines[i][0].len,
 					pp_defines[i][0].s,
 					pp_defines[i][1].len,
 					pp_defines[i][1].s);
 				return &pp_defines[i][1];
 			}
 			return NULL;
 		}
 	}
 	return NULL;
 }
 
360c6412
 static int pp_ifdef_type(int type)
 {
 	if (pp_sptr == MAX_IFDEFS) {
 		LOG(L_CRIT, "ERROR: too many nested ifdefs -- adjust MAX_IFDEFS\n");
 		return -1;
 	}
 
 	pp_ifdef_stack[pp_sptr] = type;
713a0a1f
 	pp_ifdef_level_update(1);
360c6412
 	return 0;
 }
 
 /* this sets the result of the if[n]def expr:
  * ifdef  defined   -> 1
  * ifdef  undefined -> 0
  * ifndef defined   -> 0
  * ifndef undefined -> 1
  */
 static void pp_ifdef_var(int len, const char * text)
 {
 	pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0);
 }
 
 static void pp_update_state()
 {
 	int i;
 
 	for (i=0; i<pp_sptr; i++)
 		if (! pp_ifdef_stack[i]) {
 			state = IFDEF_SKIP_S; BEGIN(IFDEF_SKIP);
 			return;
 		}
 
 	state = INITIAL; BEGIN(INITIAL);
 }
 
 static void pp_ifdef()
 {
 	pp_sptr++;
 	pp_update_state();
 }
 
 static void pp_else()
 {
 	pp_ifdef_stack[pp_sptr-1] ^= 1;
 	pp_update_state();
 }
 
 static void pp_endif()
 {
 	pp_sptr--;
713a0a1f
 	pp_ifdef_level_update(-1);
360c6412
 	pp_update_state();
 }