File: conffile.l

package info (click to toggle)
carbon-c-relay 3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,604 kB
  • sloc: ansic: 8,354; sh: 1,401; yacc: 924; lex: 354; python: 112; makefile: 110
file content (354 lines) | stat: -rw-r--r-- 7,555 bytes parent folder | download
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
%{
#include "allocator.h"
#include "conffile.h"
#include "conffile.tab.h"
#define YYSTYPE ROUTER_YYSTYPE

#define YY_DECL int router_yylex \
	(YYSTYPE *yylval_param, ROUTER_YYLTYPE *llocp, yyscan_t yyscanner, router *rtr, allocator *ralloc, allocator *palloc)
#define YY_USER_ACTION llocp->first_line = llocp->last_line = yylineno; \
	llocp->first_column = yycolumn; llocp->last_column = yycolumn+yyleng-1; \
	yycolumn += yyleng;
#define YY_USER_INIT yycolumn = 0; yylineno = 0;

int identstate = 0;
%}

%option nostdinit
%option yylineno
%option noyywrap
%option prefix="router_yy"
%option reentrant bison-bridge

%option noinput
%option nounput

%x cl ma re ag se st li qu
%x idcl idma idag idin idli

IDCHR	[a-zA-Z0-9[\](){}|\\^?*$&%<>:/,._+-]

%%

	char string_buf[1024];
	char *strbuf = NULL;

cluster				{
						identstate = cl;
						BEGIN(idcl);
						return crCLUSTER;
					}
<cl>forward			{
						identstate = idcl;
						BEGIN(idcl);
						return crFORWARD;
					}
<cl>any_of			{
						identstate = idcl;
						BEGIN(idcl);
						return crANY_OF;
					}
<cl>failover		{
						identstate = idcl;
						BEGIN(idcl);
						return crFAILOVER;
					}
<idcl>useall			return crUSEALL;
<cl>carbon_ch		{
						identstate = idcl;
						BEGIN(idcl);
						return crCARBON_CH;
					}
<cl>fnv1a_ch		{
						identstate = idcl;
						BEGIN(idcl);
						return crFNV1A_CH;
					}
<cl>jump_fnv1a_ch	{
						identstate = idcl;
						BEGIN(idcl);
						return crJUMP_FNV1A_CH;
					}
<idcl>replication		return crREPLICATION;
<cl>file			{
						identstate = idcl;
						BEGIN(idcl);
						return crFILE;
					}
<idcl>ip				return crIP;
<idcl>proto				return crPROTO;
<idcl>udp				return crUDP;
<idcl>tcp				return crTCP;
<idcl>type				return crTYPE;
<idcl>linemode			return crLINEMODE;
<idcl>syslog			return crSYSLOGMODE;
<idcl>transport			return crTRANSPORT;
<idcl>gzip				return crGZIP;
<idcl>lz4				return crLZ4;
<idcl>snappy			return crSNAPPY;
<idcl>ssl				return crSSL;
<idcl>=					return '=';

match				{
						identstate = idma;
						BEGIN(idma);
						return crMATCH;
					}
<idma>\*				return '*';
<idma>validate		{
						identstate = ma;
						BEGIN(idma);
						return crVALIDATE;
					}
<ma>else				return crELSE;
<ma>log					return crLOG;
<ma>drop				return crDROP;
<ma,idma>route		{
						BEGIN(ma);
						return crROUTE;
					}
<ma>using			{	
						identstate = ma;
						BEGIN(idma);
						return crUSING;
					}
<ma,idma>send		{
						BEGIN(ma);
						return crSEND;
					}
<ma>to				{
						identstate = idcl;
						BEGIN(idcl);
						return crTO;
					}
<idcl>blackhole			return crBLACKHOLE;
<ma,idcl>stop			return crSTOP;

rewrite				{
						identstate = re;
						BEGIN(idma);
						return crREWRITE;
					}
<re>into			{
						identstate = re;
						BEGIN(idma);
						return crINTO;
					}

aggregate			{
						identstate = idag;
						BEGIN(idag);
						return crAGGREGATE;
					}
<idag>every			{
						BEGIN(ag);
						return crEVERY;
					}
<ag>seconds				return crSECONDS;
<ag>expire				return crEXPIRE;
<ag>after				return crAFTER;
<ag>timestamp			return crTIMESTAMP;
<ag>at					return crAT;
<ag>start				return crSTART;
<ag>middle				return crMIDDLE;
<ag>end					return crEND;
<ag>of					return crOF;
<ag>bucket				return crBUCKET;
<ag>compute				return crCOMPUTE;
<ag>summary				return crSUM;
<ag>sum					return crSUM;
<ag>count				return crCOUNT;
<ag>cnt					return crCOUNT;
<ag>maximum				return crMAX;
<ag>max					return crMAX;
<ag>minimum				return crMIN;
<ag>min					return crMIN;
<ag>average				return crAVERAGE;
<ag>avg					return crAVERAGE;
<ag>median				return crMEDIAN;
<ag>percentile[0-9]* {
						yylval_param->crINTVAL =
							atoi(yytext + strlen("percentile"));
						return crPERCENTILE;
					}
<ag>variance			return crVARIANCE;
<ag>stddev				return crSTDDEV;
<ag>write				return crWRITE;
<ag>to				{
						identstate = ag;
						BEGIN(idag);
						return crTO;
					}
<ag>send			{
						/* reuse the match logic for send to ... stop */
						BEGIN(ma);
						return crSEND;
					}

send				{
						BEGIN(se);
						return crSEND;
					}
<se>statistics		{
						/* reuse the match logic for send to ... stop */
						BEGIN(ma);
						return crSTATISTICS;
					}

statistics			{
						BEGIN(st);
						return crSTATISTICS;
					}
<st>submit				return crSUBMIT;
<st>every				return crEVERY;
<st>seconds				return crSECONDS;
<st>reset				return crRESET;
<st>counters			return crCOUNTERS;
<st>after				return crAFTER;
<st>interval			return crINTERVAL;
<st>prefix				return crPREFIX;
<st>with			{
						identstate = st;
						BEGIN(idag);
						return crWITH;
					}
<st>send			{
						/* reuse the match logic for send to ... stop */
						BEGIN(ma);
						return crSEND;
					}

listen				{
						BEGIN(li);
						return crLISTEN;
					}
<li>type				return crTYPE;
<li>linemode		{
						identstate = li;
						BEGIN(idli);
						return crLINEMODE;
					}
<idli>transport			return crTRANSPORT;
<idli>gzip			{
						identstate = li;
						BEGIN(idli);
						return crGZIP;
					}
<idli>lz4			{
						identstate = li;
						BEGIN(idli);
						return crLZ4;
					}
<idli>snappy		{
						identstate = li;
						BEGIN(idli);
						return crSNAPPY;
					}
<idli>ssl			{
						identstate = idli;
						BEGIN(idli);
						return crSSL;
					}
<li,idli>proto		{
						BEGIN(li);
						return crPROTO;
					}
<li>udp				{
						identstate = li;
						BEGIN(idli);
						return crUDP;
					}
<li>tcp				{
						identstate = li;
						BEGIN(idli);
						return crTCP;
					}
<li>unix			{
						identstate = li;
						BEGIN(idli);
						return crUNIX;
					}

include				{
						identstate = INITIAL;
						BEGIN(idin);
						return crINCLUDE;
					}

	/* handle quoted strings */
<idcl,idma,idag,idin,idli>\"	{
						strbuf = string_buf;
						BEGIN(qu);
					}
<qu>{
	\"				{
						if (strbuf == string_buf) {
							router_yyerror(llocp, NULL, rtr, ralloc, palloc,
									"empty string");
							yyterminate();
						}
						BEGIN(identstate);
						*strbuf = '\0';
						yylval_param->crSTRING = ra_strdup(palloc, string_buf);
						return crSTRING;
					}
	\n				{
						router_yyerror(llocp, NULL, rtr, ralloc, palloc,
								"unterminated string");
						yyterminate();
					}
	<<EOF>>			{
						router_yyerror(llocp, NULL, rtr, ralloc, palloc,
								"unterminated string");
						yyterminate();
					}
	\\.  			{
						*strbuf++ = yytext[1];
						if (strbuf == string_buf + sizeof(string_buf)) {
							router_yyerror(llocp, NULL, rtr, ralloc, palloc,
									"string too large");
							yyterminate();
						}
					}
	[^\\\n\"]+		{
						char *yptr = yytext;
						while (*yptr) {
							*strbuf++ = *yptr++;
							if (strbuf == string_buf + sizeof(string_buf)) {
								router_yyerror(llocp, NULL, rtr,
										ralloc, palloc, "string too large");
								yyterminate();
							}
						}
					}
}

<*>#.*\n			{
						/* ignore for now
						yylval_param->crCOMMENT = ra_strdup(palloc, yytext);
						return crCOMMENT;
						*/
						yycolumn = 0;
						;
					}

<*>[ \t\r]+			; /* whitespace */
<*>\n+				yycolumn = 0;
<idcl,ag,st>[0-9]+	{
						yylval_param->crINTVAL = atoi(yytext);
						return crINTVAL;
					}
<idcl,idma,idag,idin,idli>{IDCHR}+(\\[ ]{IDCHR}+)*	{
						yylval_param->crSTRING = ra_strdup(palloc, yytext);
						BEGIN(identstate);
						return crSTRING;
					}
<*>;				{ BEGIN(INITIAL); return ';'; }
<*>.				{
						/* feed this back to the parser, it will give a
						 * nice error message */
						yylval_param->crSTRING = ra_strdup(palloc, yytext);
						return crUNEXPECTED;
					}

%%