aboutsummaryrefslogtreecommitdiffstats
path: root/src/cfg_file.l
blob: 7f2931ccc54a7dc1ba3e573ab0b1d817f74acc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
%x incl
%x module
%x lua
%x worker

%{

#define NO_GMIME
#include "config.h"
#include "cfg_file.h"
#include "cfg_yacc.h"
#ifdef WITH_LUA
#include "lua.h"
#else 
#define add_luabuf(x) yyerror ("lua support diabled")
#endif

#define ECHO do {} while(0)

#define MAX_INCLUDE_DEPTH 10
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
int line_stack[MAX_INCLUDE_DEPTH];
int include_stack_ptr = 0;
extern struct config_file *cfg;

%}

%option noyywrap
%option yylineno

%%
[ \t]*#.*						/* ignore comments */;
.include						BEGIN(incl);
.module							BEGIN(module);
.lua							BEGIN(lua);
worker							BEGIN(worker); return WORKER;
composites						return COMPOSITES;
tempdir							return TEMPDIR;
pidfile							return PIDFILE;

view							return VIEW;
ip								return IP;
from							return FROM;
symbols							return SYMBOLS;

error_time                      return ERROR_TIME;
dead_time                       return DEAD_TIME;
maxerrors                       return MAXERRORS;
reconnect_timeout				return RECONNECT_TIMEOUT;
connect_timeout					return CONNECT_TIMEOUT;
protocol						return PROTOCOL;
memcached						return MEMCACHED;
servers							return SERVERS;
require							return REQUIRE;
filters							return FILTERS;
factors							return FACTORS;
metric							return METRIC;
name							return NAME;
required_score					return REQUIRED_SCORE;
function						return FUNCTION;
cache_file						return CACHE_FILE;
control							return CONTROL;
password						return PASSWORD;
lmtp							return LMTP;
raw_mode						return RAW_MODE;
enabled							return ENABLED;
delivery						return DELIVERY;
agent							return AGENT;

statfile						return STATFILE;
alias							return ALIAS;
pattern							return PATTERN;
weight							return WEIGHT;
size							return SIZE;
tokenizer						return TOKENIZER;
classifier						return CLASSIFIER;
section							return SECTION;
autolearn						return AUTOLEARN;
min_mark						return MIN_MARK;
max_mark						return MAX_MARK;

logging							return LOGGING;

log_type						return LOG_TYPE;
console							return LOG_TYPE_CONSOLE;
syslog							return LOG_TYPE_SYSLOG;
file							return LOG_TYPE_FILE;

log_level						return LOG_LEVEL;
DEBUG							return LOG_LEVEL_DEBUG;
INFO							return LOG_LEVEL_INFO;
WARNING							return LOG_LEVEL_WARNING;
ERROR							return LOG_LEVEL_ERROR;
log_facility					return LOG_FACILITY;
log_file						return LOG_FILENAME;
profile_file					return PROFILE_FILE;

statfile_pool_size				return STATFILE_POOL_SIZE;

\{								return OBRACE;
\}								return EBRACE;
;								return SEMICOLON;
,								return COMMA;
=								return EQSIGN;
yes|YES|no|NO|[yY]|[nN]			yylval.flag=parse_flag(yytext); return FLAG;
\n								/* ignore EOL */;
[ \t]+							/* ignore whitespace */;
\".+[^\\]\"						yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
\"								return QUOTE;
\$[a-zA-Z_][a-zA-Z0-9_]+		yylval.string=strdup(yytext + 1); return VARIABLE;
[0-9]+							yylval.number=strtol(yytext, NULL, 10); return NUMBER;
-?[0-9]+\.?[0-9]*				yylval.fract=strtod(yytext, NULL); return FRACT;
[0-9]+[kKmMgG]?					yylval.limit=parse_limit(yytext); return SIZELIMIT;
[0-9]+[sS]|[0-9]+[mM][sS]		yylval.seconds=parse_seconds(yytext); return SECONDS;
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}	yylval.string=strdup(yytext); return IPADDR;
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}	yylval.string=strdup(yytext); return IPNETWORK;
[*a-zA-Z0-9.-]+:[0-9]{1,5}		yylval.string=strdup(yytext); return HOSTPORT;
[a-zA-Z<][a-zA-Z@+>_-]*         yylval.string=strdup(yytext); return STRING;
\/[^/\n]+\/						yylval.string=strdup(yytext); return REGEXP;
[a-zA-Z0-9].[a-zA-Z0-9\/.-]+	yylval.string=strdup(yytext); return DOMAINNAME;
<incl>[ \t]*      /* eat the whitespace */
<incl>[^ \t\n]+   { /* got the include file name */
		/* got the include file name */
		if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
			yyerror ("yylex: includes nested too deeply" );
			return -1;
		}

		line_stack[include_stack_ptr] = yylineno;
		include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;

		yylineno = 1;
		yyin = fopen (yytext, "r");

		if (!yyin) {
			yyerror ("yylex: cannot open include file");
			return -1;
		}

		yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));

		BEGIN(INITIAL);
}

<<EOF>> {
		if ( --include_stack_ptr < 0 ) {
			include_stack_ptr = 0;
			yylineno = 1;
			post_load_config (cfg);
			yyterminate ();
		}
		else {
			yy_delete_buffer (YY_CURRENT_BUFFER);
			yy_switch_to_buffer (include_stack[include_stack_ptr] );
			yylineno = line_stack[include_stack_ptr];
		}
}

<module>\n								/* ignore EOL */;
<module>[ \t]+							/* ignore whitespace */;
<module>[ \t]*#.*						/* ignore comments */;
<module>\'[a-zA-Z0-9_-]+\'	yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return MODULE_OPT; 
<module>\{	return OBRACE;
<module>\}  BEGIN(INITIAL); return EBRACE;
<module>\;	return SEMICOLON;
<module>=	return EQSIGN;
<module>\$[a-zA-Z_][a-zA-Z0-9_]+		yylval.string=strdup(yytext + 1); return VARIABLE;
<module>[a-zA-Z0-9_%-]+	yylval.string=strdup(yytext); return PARAM;
<module>\".+[^\\]\"	yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;

<worker>\n								/* ignore EOL */;
<worker>[ \t]+							/* ignore whitespace */;
<worker>[ \t]*#.*						/* ignore comments */;
<worker>\{	return OBRACE;
<worker>\}  BEGIN(INITIAL); return EBRACE;
<worker>\;	return SEMICOLON;
<worker>=	return EQSIGN;
<worker>type							return TYPE;
<worker>bind_socket						return BINDSOCK;
<worker>count							return COUNT;
<worker>[0-9]+							yylval.number=strtol(yytext, NULL, 10); return NUMBER;
<worker>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}	yylval.string=strdup(yytext); return IPADDR;
<worker>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}	yylval.string=strdup(yytext); return IPNETWORK;
<worker>[*a-zA-Z0-9.-]+:[0-9]{1,5}		yylval.string=strdup(yytext); return HOSTPORT;
<worker>[a-zA-Z<][a-zA-Z@+>_-]*         yylval.string=strdup(yytext); return STRING;
<worker>\$[a-zA-Z_][a-zA-Z0-9_]+		yylval.string=strdup(yytext + 1); return VARIABLE;
<worker>\".+[^\\]\"	yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;

<lua>\n									/* ignore EOL */;
<lua>[ \t]+								/* ignore whitespace */;
<lua>[ \t]*#.*							/* ignore comments */;
<lua>^.endlua$							BEGIN(INITIAL);
<lua>.*									add_luabuf(yytext); return LUACODE;

%%
/* 
 * vi:ts=4 
 */