ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.1.x/src/config-lexer.l
Revision: 9477
Committed: Sat Jul 4 19:02:07 2020 UTC (6 years, 2 months ago) by michael
File size: 12009 byte(s)
Log Message:
- Incorporate basic TLS support for the irc bot part. Changes submitted by Adam <adam@anope.org>

File Contents

# Content
1 /*
2 * Copyright (c) 2002 Erik Fears
3 * Copyright (c) 2014-2020 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 TLS { return TLS; }
193 TYPE { return TYPE; }
194 USER { return USER; }
195 USERNAME { return USERNAME; }
196 VHOST { return VHOST; }
197
198 years { return YEARS; }
199 year { return YEARS; }
200 months { return MONTHS; }
201 month { return MONTHS; }
202 weeks { return WEEKS; }
203 week { return WEEKS; }
204 days { return DAYS; }
205 day { return DAYS; }
206 hours { return HOURS; }
207 hour { return HOURS; }
208 minutes { return MINUTES; }
209 minute { return MINUTES; }
210 seconds { return SECONDS; }
211 second { return SECONDS; }
212
213 bytes { return BYTES; }
214 byte { return BYTES; }
215 kilobytes { return KBYTES; }
216 kilobyte { return KBYTES; }
217 kbytes { return KBYTES; }
218 kbyte { return KBYTES; }
219 kb { return KBYTES; }
220 megabytes { return MBYTES; }
221 megabyte { return MBYTES; }
222 mbytes { return MBYTES; }
223 mbyte { return MBYTES; }
224 mb { return MBYTES; }
225
226 HTTP {
227 yylval.number = OPM_TYPE_HTTP;
228 return PROTOCOLTYPE;
229 }
230
231 HTTPPOST {
232 yylval.number = OPM_TYPE_HTTPPOST;
233 return PROTOCOLTYPE;
234 }
235
236 HTTPS {
237 yylval.number = OPM_TYPE_HTTPS;
238 return PROTOCOLTYPE;
239 }
240
241 HTTPSPOST {
242 yylval.number = OPM_TYPE_HTTPSPOST;
243 return PROTOCOLTYPE;
244 }
245
246 SOCKS4 {
247 yylval.number = OPM_TYPE_SOCKS4;
248 return PROTOCOLTYPE;
249 }
250
251 SOCKS5 {
252 yylval.number = OPM_TYPE_SOCKS5;
253 return PROTOCOLTYPE;
254 }
255
256 WINGATE {
257 yylval.number = OPM_TYPE_WINGATE;
258 return PROTOCOLTYPE;
259 }
260
261 ROUTER {
262 yylval.number = OPM_TYPE_ROUTER;
263 return PROTOCOLTYPE;
264 }
265
266 DREAMBOX {
267 yylval.number = OPM_TYPE_DREAMBOX;
268 return PROTOCOLTYPE;
269 }
270
271
272 SSH {
273 yylval.number = OPM_TYPE_SSH;
274 return PROTOCOLTYPE;
275 }
276
277 TRUE {
278 yylval.number=1;
279 return NUMBER;
280 }
281 YES {
282 yylval.number=1;
283 return NUMBER;
284 }
285 ON {
286 yylval.number=1;
287 return NUMBER;
288 }
289
290
291
292 FALSE {
293 yylval.number=0;
294 return NUMBER;
295 }
296
297 NO {
298 yylval.number=0;
299 return NUMBER;
300 }
301
302 OFF {
303 yylval.number=0;
304 return NUMBER;
305 }
306
307 . { return yytext[0]; }
308 <<EOF>> { if (conf_eof()) yyterminate(); }
309
310 %%
311
312 static void
313 conf_include(void)
314 {
315 char *p = NULL;
316 char filenamebuf[512];
317
318 if ((p = strchr(yytext, '<')) == NULL)
319 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
320 else
321 *strchr(++p, '>') = '\0';
322
323 /* do stacking and co. */
324 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
325 {
326 log_printf("CONFIG -> Includes nested too deep in %s", p);
327 return;
328 }
329
330 if (*p == '/') /* if it is an absolute path */
331 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
332 else
333 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", HOPM_ETCDIR, p);
334
335 FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
336 if (!tmp_fbfile_in)
337 {
338 log_printf("CONFIG -> Unable to read configuration file '%s': %s",
339 filenamebuf, strerror(errno));
340 return;
341 }
342
343 struct included_file *file = &include_stack[include_stack_ptr++];
344 file->lineno = lineno;
345 file->file = conf_file;
346 file->state = YY_CURRENT_BUFFER;
347 strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
348
349 lineno = 1;
350 conf_file = tmp_fbfile_in;
351 strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
352
353 yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
354 }
355
356 static int
357 conf_eof(void)
358 {
359 if (include_stack_ptr == 0)
360 return 1;
361
362 /* switch buffer */
363 struct included_file *file = &include_stack[--include_stack_ptr];
364
365 /* close current file */
366 fclose(conf_file);
367
368 /* switch buffers */
369 yy_delete_buffer(YY_CURRENT_BUFFER);
370 yy_switch_to_buffer(file->state);
371
372 /* switch lineno */
373 lineno = file->lineno;
374
375 /* switch file */
376 conf_file = file->file;
377
378 strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
379 return 0;
380 }

Properties

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