ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-lexer.l
Revision: 7742
Committed: Fri Sep 30 18:44:33 2016 UTC (9 years, 9 months ago) by michael
File size: 12058 byte(s)
Log Message:
- config-lexer.l: replace a snprintf with strlcpy

File Contents

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

Properties

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