ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-lexer.l
Revision: 8750
Committed: Tue Jan 1 11:06:38 2019 UTC (7 years, 6 months ago) by michael
File size: 11960 byte(s)
Log Message:
- Update copyright years

File Contents

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

Properties

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