ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-lexer.l
(Generate patch)

Comparing hopm/trunk/src/config-lexer.l (file contents):
Revision 5135 by michael, Thu Dec 25 18:51:51 2014 UTC vs.
Revision 8564 by michael, Wed Sep 26 19:23:54 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (C) 2002  Erik Fears
2 > *  Copyright (c) 2002 Erik Fears
3 > *  Copyright (c) 2014-2018 ircd-hybrid development team
4   *
5 < *    QSTRING , ccomment and hashcomment taken from Hybrid7:
6 < *    Copyright (C) 2002 by the past and present ircd coders, and others.
7 < *
8 < * This program is free software; you can redistribute it and/or
8 < * modify it under the terms of the GNU General Public License
9 < * as published by the Free Software Foundation; either version 2
10 < * of the License, or (at your option) any later version.
11 < *
12 < * This program is distributed in the hope that it will be useful,
13 < * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 < * GNU General Public License for more details.
16 < *
17 < * You should have received a copy of the GNU General Public License
18 < * along with this program; if not, write to
19 < *
20 < *       The Free Software Foundation, Inc.
21 < *       59 Temple Place - Suite 330
22 < *       Boston, MA  02111-1307, USA.
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  
35 #include "inet.h"
33   #include "compat.h"
34   #include "config.h"
35 < #include "config-parser.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  
41 void ccomment(void);
50  
51 < int linenum = 1;
51 > unsigned int lineno = 1;
52   char linebuf[512];
53 + char conffilebuf[512];
54  
55 < %}
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 < string                 \"[^\"\n]*[\"\n]
49 < comment                ("//"|"#").*
50 < whitespace             [ \t\r]*
63 > static unsigned int include_stack_ptr;
64  
52 %%
65  
66 < "/*"                    { ccomment(); }
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 < {comment}               ;
82 > WS        [[:blank:]]*
83 > DIGIT     [[:digit:]]+
84 > COMMENT   ("//"|"#").*
85 > qstring   \"[^\"\n]*[\"\n]
86 > include   \.include{WS}(\<.*\>|\".*\")
87  
88 < {string}                {
89 <                           /* QSTRING from Hybrid7. Why re-invent the wheel? */
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 <                           if(yytext[yyleng-2] == '\\')
62 <                           {
63 <                              yyless(yyleng-1); /* return last quote */
64 <                              yymore();         /* append next string */
65 <                           }
66 <                           else
67 <                           {
68 <                              yylval.string = yytext+1;
69 <                              if(yylval.string[yyleng-2] != '"') ; /* log error */
70 <                              else
71 <                              {
72 <                                 int i,j;
73 <
74 <                                 yylval.string[yyleng-2] = '\0'; /* remove close
75 <                                                                  *  quote
76 <                                                                  */
77 <
78 <                                 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
79 <                                 {
80 <                                    if (yylval.string[i] != '\\')
81 <                                    {
82 <                                       yylval.string[j] = yylval.string[i];
83 <                                    }
84 <                                    else
85 <                                    {
86 <                                        i++;
87 <                                        yylval.string[j] = yylval.string[i];
88 <                                    }
89 <                                 }
90 <                                 yylval.string[j] = '\0';
91 <                                 return STRING;
92 <                              }
93 <                           }
94 <            
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;          }
# Line 113 | Line 165 | MAX_READ                { return MAX_REA
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;      }
# Line 123 | Line 177 | 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;      }
# Line 176 | Line 232 | 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;
# Line 196 | Line 262 | ROUTER                  {
262                            return PROTOCOLTYPE;
263                          }
264  
265 <
266 < [0-9]+                  {
267 <                           yylval.number=atoi(yytext);
202 <                           return NUMBER;
265 > DREAMBOX                {
266 >                          yylval.number = OPM_TYPE_DREAMBOX;
267 >                          return PROTOCOLTYPE;
268                          }
269  
270  
271 <
272 <
271 > SSH                     {
272 >                          yylval.number = OPM_TYPE_SSH;
273 >                          return PROTOCOLTYPE;
274 >                        }
275  
276   TRUE                     {
277                             yylval.number=1;
# Line 236 | Line 303 | OFF                      {
303                             return NUMBER;
304                           }
305  
306 + .                       { return yytext[0]; }
307 + <<EOF>>                 { if (conf_eof()) yyterminate(); }
308  
309 < \n.*                     {
241 <                           strlcpy(linebuf, yytext + 1, sizeof(linebuf));
242 <                           ++linenum;
243 <                           yyless(1);
244 <                         }
245 <
246 < {whitespace}            /* ignore whitespace */;
309 > %%
310  
311 < .                       return yytext[0];
311 > static void
312 > conf_include(void)
313 > {
314 >  char *p = NULL;
315 >  char filenamebuf[512];
316  
317 < %%
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 < /* C-comment ignoring routine -kre*/
330 < void ccomment(void)
331 < {
332 <  int c;
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 <  /* log(L_NOTICE, "got comment"); */
335 <  while (1)
334 >  FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
335 >  if (!tmp_fbfile_in)
336    {
337 <     while ((c = input()) != '*' && c != EOF)
338 <        if (c == '\n') ++linenum;
339 <     if (c == '*')
264 <     {
265 <        while ((c = input()) == '*');
266 <        if (c == '/') break;
267 <     }
268 <    if (c == EOF)
269 <    {
270 <       YY_FATAL_ERROR("EOF in comment");
271 <       /* XXX hack alert this disables
272 <        * the stupid unused function warning
273 <        * gcc generates
274 <        */
275 <       if(1 == 0)
276 <          yy_fatal_error("EOF in comment");
277 <       break;
278 <    }
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)