/[svn]/hopm/branches/1.1.x/src/config-lexer.l
ViewVC logotype

Contents of /hopm/branches/1.1.x/src/config-lexer.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7926 - (show annotations)
Sat Dec 31 13:59:33 2016 UTC (5 years, 7 months ago) by michael
File size: 11598 byte(s)
- Update copyright years

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 AWAY { return AWAY; }
140 BAN_UNKNOWN { return BAN_UNKNOWN; }
141 BLACKLIST { return BLACKLIST; }
142 CHANNEL { return CHANNEL; }
143 COMMAND_INTERVAL { return COMMAND_INTERVAL; }
144 COMMAND_QUEUE_SIZE { return COMMAND_QUEUE_SIZE; }
145 COMMAND_TIMEOUT { return COMMAND_TIMEOUT; }
146 CONNREGEX { return CONNREGEX; }
147 DNS_FDLIMIT { return DNS_FDLIMIT; }
148 DNS_TIMEOUT { return DNS_TIMEOUT; }
149 DNSBL_FROM { return DNSBL_FROM; }
150 DNSBL_TO { return DNSBL_TO; }
151 EXEMPT { return EXEMPT; }
152 FD { return FD; }
153 INVITE { return INVITE; }
154 IRC { return IRC; }
155 KLINE { return KLINE; }
156 KEY { return KEY; }
157 MASK { return MASK; }
158 MAX_READ { return MAX_READ; }
159 MODE { return MODE; }
160 NAME { return NAME; }
161 NEGCACHE { return NEGCACHE; }
162 NEGCACHE_REBUILD { return NEGCACHE_REBUILD; }
163 NICK { return NICK; }
164 NICKSERV { return NICKSERV; }
165 NOTICE { return NOTICE; }
166 OPER { return OPER; }
167 OPM { return OPM; }
168 OPTIONS { return OPTIONS; }
169 PASSWORD { return PASSWORD; }
170 PERFORM { return PERFORM; }
171 PIDFILE { return PIDFILE; }
172 PORT { return PORT; }
173 PROTOCOL { return PROTOCOL; }
174 READTIMEOUT { return READTIMEOUT; }
175 REALNAME { return REALNAME; }
176 RECONNECTINTERVAL { return RECONNECTINTERVAL; }
177 REPLY { return REPLY; }
178 SCANLOG { return SCANLOG; }
179 SCANNER { return SCANNER; }
180 SENDMAIL { return SENDMAIL; }
181 SERVER { return SERVER; }
182 TARGET_IP { return TARGET_IP; }
183 TARGET_PORT { return TARGET_PORT; }
184 TARGET_STRING { return TARGET_STRING;}
185 TIMEOUT { return TIMEOUT; }
186 TYPE { return TYPE; }
187 USER { return USER; }
188 USERNAME { return USERNAME; }
189 VHOST { return VHOST; }
190
191 years { return YEARS; }
192 year { return YEARS; }
193 months { return MONTHS; }
194 month { return MONTHS; }
195 weeks { return WEEKS; }
196 week { return WEEKS; }
197 days { return DAYS; }
198 day { return DAYS; }
199 hours { return HOURS; }
200 hour { return HOURS; }
201 minutes { return MINUTES; }
202 minute { return MINUTES; }
203 seconds { return SECONDS; }
204 second { return SECONDS; }
205
206 bytes { return BYTES; }
207 byte { return BYTES; }
208 kilobytes { return KBYTES; }
209 kilobyte { return KBYTES; }
210 kbytes { return KBYTES; }
211 kbyte { return KBYTES; }
212 kb { return KBYTES; }
213 megabytes { return MBYTES; }
214 megabyte { return MBYTES; }
215 mbytes { return MBYTES; }
216 mbyte { return MBYTES; }
217 mb { return MBYTES; }
218
219 HTTP {
220 yylval.number = OPM_TYPE_HTTP;
221 return PROTOCOLTYPE;
222 }
223
224 HTTPPOST {
225 yylval.number = OPM_TYPE_HTTPPOST;
226 return PROTOCOLTYPE;
227 }
228
229 HTTPS {
230 yylval.number = OPM_TYPE_HTTPS;
231 return PROTOCOLTYPE;
232 }
233
234 HTTPSPOST {
235 yylval.number = OPM_TYPE_HTTPSPOST;
236 return PROTOCOLTYPE;
237 }
238
239 SOCKS4 {
240 yylval.number = OPM_TYPE_SOCKS4;
241 return PROTOCOLTYPE;
242 }
243
244 SOCKS5 {
245 yylval.number = OPM_TYPE_SOCKS5;
246 return PROTOCOLTYPE;
247 }
248
249 WINGATE {
250 yylval.number = OPM_TYPE_WINGATE;
251 return PROTOCOLTYPE;
252 }
253
254 ROUTER {
255 yylval.number = OPM_TYPE_ROUTER;
256 return PROTOCOLTYPE;
257 }
258
259 DREAMBOX {
260 yylval.number = OPM_TYPE_DREAMBOX;
261 return PROTOCOLTYPE;
262 }
263
264
265 TRUE {
266 yylval.number=1;
267 return NUMBER;
268 }
269 YES {
270 yylval.number=1;
271 return NUMBER;
272 }
273 ON {
274 yylval.number=1;
275 return NUMBER;
276 }
277
278
279
280 FALSE {
281 yylval.number=0;
282 return NUMBER;
283 }
284
285 NO {
286 yylval.number=0;
287 return NUMBER;
288 }
289
290 OFF {
291 yylval.number=0;
292 return NUMBER;
293 }
294
295 . { return yytext[0]; }
296 <<EOF>> { if (conf_eof()) yyterminate(); }
297
298 %%
299
300 static void
301 conf_include(void)
302 {
303 char *p = NULL;
304 char filenamebuf[512];
305
306 if ((p = strchr(yytext, '<')) == NULL)
307 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
308 else
309 *strchr(++p, '>') = '\0';
310
311 /* do stacking and co. */
312 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
313 {
314 log_printf("CONFIG -> Includes nested too deep in %s", p);
315 return;
316 }
317
318 if (*p == '/') /* if it is an absolute path */
319 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
320 else
321 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", HOPM_ETCDIR, p);
322
323 FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
324 if (!tmp_fbfile_in)
325 {
326 log_printf("CONFIG -> Unable to read configuration file '%s': %s",
327 filenamebuf, strerror(errno));
328 return;
329 }
330
331 struct included_file *file = &include_stack[include_stack_ptr++];
332 file->lineno = lineno;
333 file->file = conf_file;
334 file->state = YY_CURRENT_BUFFER;
335 strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
336
337 lineno = 1;
338 conf_file = tmp_fbfile_in;
339 strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
340
341 yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
342 }
343
344 static int
345 conf_eof(void)
346 {
347 if (include_stack_ptr == 0)
348 return 1;
349
350 /* switch buffer */
351 struct included_file *file = &include_stack[--include_stack_ptr];
352
353 /* close current file */
354 fclose(conf_file);
355
356 /* switch buffers */
357 yy_delete_buffer(YY_CURRENT_BUFFER);
358 yy_switch_to_buffer(file->state);
359
360 /* switch lineno */
361 lineno = file->lineno;
362
363 /* switch file */
364 conf_file = file->file;
365
366 strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
367 return 0;
368 }

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28