ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-lexer.l
Revision: 8098
Committed: Sun Apr 2 10:09:50 2017 UTC (9 years, 3 months ago) by michael
File size: 11747 byte(s)
Log Message:
- Added IPv6 blacklist support. Initial patch by Andreas Rammhold.

File Contents

# Content
1 /*
2 * Copyright (c) 2002 Erik Fears
3 * Copyright (c) 2014-2017 ircd-hybrid development team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20
21 %option case-insensitive
22 %option noyywrap
23 %option noinput
24 %option nounput
25 %option never-interactive
26
27 %x IN_COMMENT
28
29 %{
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "compat.h"
34 #include "config.h"
35 #include "config-parser.h" /* autogenerated header file */
36 #include "log.h"
37
38 #undef YY_FATAL_ERROR
39 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
40
41 #undef YY_INPUT
42 #define YY_INPUT(buf,result,max_size) \
43 if (!(result = conf_yy_input(buf, max_size))) \
44 YY_FATAL_ERROR("input in flex scanner failed");
45 #define MAX_INCLUDE_DEPTH 10
46
47
48 unsigned int lineno = 1;
49 char linebuf[512];
50 char conffilebuf[512];
51
52 static struct included_file
53 {
54 YY_BUFFER_STATE state;
55 unsigned int lineno;
56 FILE *file;
57 char conffile[512];
58 } include_stack[MAX_INCLUDE_DEPTH];
59
60 static unsigned int include_stack_ptr;
61
62
63 static void conf_include(void);
64 static int conf_eof(void);
65
66 static int
67 conf_yy_input(char *lbuf, unsigned int max_size)
68 {
69 return fgets(lbuf, max_size, conf_file) == NULL ? 0 : strlen(lbuf);
70 }
71
72 static int
73 conf_yy_fatal_error(const char *msg)
74 {
75 return 0;
76 }
77 %}
78
79 WS [[:blank:]]*
80 DIGIT [[:digit:]]+
81 COMMENT ("//"|"#").*
82 qstring \"[^\"\n]*[\"\n]
83 include \.include{WS}(\<.*\>|\".*\")
84
85 %%
86
87 "/*" { BEGIN IN_COMMENT; }
88 <IN_COMMENT>"*/" { BEGIN INITIAL; }
89 <IN_COMMENT>. ; /* Eat everything but a newline */
90 <IN_COMMENT>\n { ++lineno; }
91 <IN_COMMENT><<EOF>> { BEGIN INITIAL; if (conf_eof()) yyterminate(); }
92
93 {include} { conf_include(); }
94 \n.* { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); }
95 {WS} ;
96 {COMMENT} ;
97 {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
98 {qstring} { if (yytext[yyleng - 2] == '\\')
99 {
100 yyless(yyleng - 1); /* Return last quote */
101 yymore(); /* Append next string */
102 }
103 else
104 {
105 yylval.string = yytext + 1;
106
107 if (yylval.string[yyleng - 2] != '"')
108 log_printf("CONFIG ->Unterminated character string");
109 else
110 {
111 unsigned int i = 0, j = 0;
112
113 yylval.string[yyleng - 2] = '\0'; /* Remove close quote */
114
115 for (; yylval.string[i] != '\0'; ++i, ++j)
116 {
117 if (yylval.string[i] != '\\')
118 yylval.string[j] = yylval.string[i];
119 else
120 {
121 ++i;
122
123 if (yylval.string[i] == '\0') /* XXX: should not happen */
124 {
125 log_printf("CONFIG -> Unterminated character string");
126 break;
127 }
128
129 yylval.string[j] = yylval.string[i];
130 }
131 }
132
133 yylval.string[j] = '\0';
134 return STRING;
135 }
136 }
137 }
138
139 ADDRESS_FAMILY { return ADDRESS_FAMILY; }
140 AWAY { return AWAY; }
141 BAN_UNKNOWN { return BAN_UNKNOWN; }
142 BLACKLIST { return BLACKLIST; }
143 CHANNEL { return CHANNEL; }
144 COMMAND_INTERVAL { return COMMAND_INTERVAL; }
145 COMMAND_QUEUE_SIZE { return COMMAND_QUEUE_SIZE; }
146 COMMAND_TIMEOUT { return COMMAND_TIMEOUT; }
147 CONNREGEX { return CONNREGEX; }
148 DNS_FDLIMIT { return DNS_FDLIMIT; }
149 DNS_TIMEOUT { return DNS_TIMEOUT; }
150 DNSBL_FROM { return DNSBL_FROM; }
151 DNSBL_TO { return DNSBL_TO; }
152 EXEMPT { return EXEMPT; }
153 FD { return FD; }
154 INVITE { return INVITE; }
155 IPV4 { return IPV4; }
156 IPV6 { return IPV6; }
157 IRC { return IRC; }
158 KLINE { return KLINE; }
159 KEY { return KEY; }
160 MASK { return MASK; }
161 MAX_READ { return MAX_READ; }
162 MODE { return MODE; }
163 NAME { return NAME; }
164 NEGCACHE { return NEGCACHE; }
165 NEGCACHE_REBUILD { return NEGCACHE_REBUILD; }
166 NICK { return NICK; }
167 NICKSERV { return NICKSERV; }
168 NOTICE { return NOTICE; }
169 OPER { return OPER; }
170 OPM { return OPM; }
171 OPTIONS { return OPTIONS; }
172 PASSWORD { return PASSWORD; }
173 PERFORM { return PERFORM; }
174 PIDFILE { return PIDFILE; }
175 PORT { return PORT; }
176 PROTOCOL { return PROTOCOL; }
177 READTIMEOUT { return READTIMEOUT; }
178 REALNAME { return REALNAME; }
179 RECONNECTINTERVAL { return RECONNECTINTERVAL; }
180 REPLY { return REPLY; }
181 SCANLOG { return SCANLOG; }
182 SCANNER { return SCANNER; }
183 SENDMAIL { return SENDMAIL; }
184 SERVER { return SERVER; }
185 TARGET_IP { return TARGET_IP; }
186 TARGET_PORT { return TARGET_PORT; }
187 TARGET_STRING { return TARGET_STRING;}
188 TIMEOUT { return TIMEOUT; }
189 TYPE { return TYPE; }
190 USER { return USER; }
191 USERNAME { return USERNAME; }
192 VHOST { return VHOST; }
193
194 years { return YEARS; }
195 year { return YEARS; }
196 months { return MONTHS; }
197 month { return MONTHS; }
198 weeks { return WEEKS; }
199 week { return WEEKS; }
200 days { return DAYS; }
201 day { return DAYS; }
202 hours { return HOURS; }
203 hour { return HOURS; }
204 minutes { return MINUTES; }
205 minute { return MINUTES; }
206 seconds { return SECONDS; }
207 second { return SECONDS; }
208
209 bytes { return BYTES; }
210 byte { return BYTES; }
211 kilobytes { return KBYTES; }
212 kilobyte { return KBYTES; }
213 kbytes { return KBYTES; }
214 kbyte { return KBYTES; }
215 kb { return KBYTES; }
216 megabytes { return MBYTES; }
217 megabyte { return MBYTES; }
218 mbytes { return MBYTES; }
219 mbyte { return MBYTES; }
220 mb { return MBYTES; }
221
222 HTTP {
223 yylval.number = OPM_TYPE_HTTP;
224 return PROTOCOLTYPE;
225 }
226
227 HTTPPOST {
228 yylval.number = OPM_TYPE_HTTPPOST;
229 return PROTOCOLTYPE;
230 }
231
232 HTTPS {
233 yylval.number = OPM_TYPE_HTTPS;
234 return PROTOCOLTYPE;
235 }
236
237 HTTPSPOST {
238 yylval.number = OPM_TYPE_HTTPSPOST;
239 return PROTOCOLTYPE;
240 }
241
242 SOCKS4 {
243 yylval.number = OPM_TYPE_SOCKS4;
244 return PROTOCOLTYPE;
245 }
246
247 SOCKS5 {
248 yylval.number = OPM_TYPE_SOCKS5;
249 return PROTOCOLTYPE;
250 }
251
252 WINGATE {
253 yylval.number = OPM_TYPE_WINGATE;
254 return PROTOCOLTYPE;
255 }
256
257 ROUTER {
258 yylval.number = OPM_TYPE_ROUTER;
259 return PROTOCOLTYPE;
260 }
261
262 DREAMBOX {
263 yylval.number = OPM_TYPE_DREAMBOX;
264 return PROTOCOLTYPE;
265 }
266
267
268 TRUE {
269 yylval.number=1;
270 return NUMBER;
271 }
272 YES {
273 yylval.number=1;
274 return NUMBER;
275 }
276 ON {
277 yylval.number=1;
278 return NUMBER;
279 }
280
281
282
283 FALSE {
284 yylval.number=0;
285 return NUMBER;
286 }
287
288 NO {
289 yylval.number=0;
290 return NUMBER;
291 }
292
293 OFF {
294 yylval.number=0;
295 return NUMBER;
296 }
297
298 . { return yytext[0]; }
299 <<EOF>> { if (conf_eof()) yyterminate(); }
300
301 %%
302
303 static void
304 conf_include(void)
305 {
306 char *p = NULL;
307 char filenamebuf[512];
308
309 if ((p = strchr(yytext, '<')) == NULL)
310 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
311 else
312 *strchr(++p, '>') = '\0';
313
314 /* do stacking and co. */
315 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
316 {
317 log_printf("CONFIG -> Includes nested too deep in %s", p);
318 return;
319 }
320
321 if (*p == '/') /* if it is an absolute path */
322 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
323 else
324 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", HOPM_ETCDIR, p);
325
326 FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
327 if (!tmp_fbfile_in)
328 {
329 log_printf("CONFIG -> Unable to read configuration file '%s': %s",
330 filenamebuf, strerror(errno));
331 return;
332 }
333
334 struct included_file *file = &include_stack[include_stack_ptr++];
335 file->lineno = lineno;
336 file->file = conf_file;
337 file->state = YY_CURRENT_BUFFER;
338 strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
339
340 lineno = 1;
341 conf_file = tmp_fbfile_in;
342 strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
343
344 yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
345 }
346
347 static int
348 conf_eof(void)
349 {
350 if (include_stack_ptr == 0)
351 return 1;
352
353 /* switch buffer */
354 struct included_file *file = &include_stack[--include_stack_ptr];
355
356 /* close current file */
357 fclose(conf_file);
358
359 /* switch buffers */
360 yy_delete_buffer(YY_CURRENT_BUFFER);
361 yy_switch_to_buffer(file->state);
362
363 /* switch lineno */
364 lineno = file->lineno;
365
366 /* switch file */
367 conf_file = file->file;
368
369 strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
370 return 0;
371 }

Properties

Name Value
svn:eol-style native
svn:keywords Id