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 6046 by michael, Thu Jun 4 11:09:23 2015 UTC vs.
Revision 7716 by michael, Mon Sep 26 12:08:43 2016 UTC

# Line 1 | Line 1
1   /*
2   *  Copyright (c) 2002 Erik Fears
3 < *  Copyright (c) 2014-2015 ircd-hybrid development team
3 > *  Copyright (c) 2014-2016 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
# Line 29 | Line 29
29  
30   #include "compat.h"
31   #include "config.h"
32 < #include "config-parser.h"
32 > #include "config-parser.h"  /* autogenerated header file */
33 > #include "log.h"
34  
35  
36 < static void ccomment(void);
36 > #undef YY_INPUT
37 > #define YY_INPUT(buf,result,max_size) \
38 >  if (!(result = conf_yy_input(buf, max_size))) \
39 >    YY_FATAL_ERROR("input in flex scanner failed");
40 > #define MAX_INCLUDE_DEPTH 10
41 >
42  
43 < unsigned int linenum = 1;
43 > unsigned int lineno = 1;
44   char linebuf[512];
45 + char conffilebuf[512];
46  
47 < %}
47 > static struct included_file
48 > {
49 >  YY_BUFFER_STATE state;
50 >  unsigned int lineno;
51 >  FILE *file;
52 >  char conffile[512];
53 > } include_stack[MAX_INCLUDE_DEPTH];
54  
55 < string                 \"[^\"\n]*[\"\n]
43 < comment                ("//"|"#").*
44 < whitespace             [ \t\r]*
55 > static unsigned int include_stack_ptr;
56  
46 %%
57  
58 < "/*"                    { ccomment(); }
58 > static void ccomment(void);
59 > static void conf_include(void);
60 > static int conf_eof(void);
61  
62 < {comment}               ;
62 > static int
63 > conf_yy_input(char *lbuf, unsigned int max_size)
64 > {
65 >  return !fgets(lbuf, max_size, conf_file) ? 0 : strlen(lbuf);
66 > }
67  
68 < {string}                {
69 <                           /* QSTRING from Hybrid7. Why re-invent the wheel? */
68 > %}
69 >
70 > WS        [[:blank:]]*
71 > DIGIT     [[:digit:]]+
72 > COMMENT   ("//"|"#").*
73 > qstring   \"[^\"\n]*[\"\n]
74 > include   \.include{WS}(\<.*\>|\".*\")
75 >
76 > %%
77 > {include}       { conf_include(); }
78 > "/*"            { ccomment(); }
79 > \n.*            { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); }
80 > {WS}            ;
81 > {COMMENT}       ;
82 > {DIGIT}         { yylval.number = atoi(yytext); return NUMBER; }
83 > {qstring}       { if (yytext[yyleng - 2] == '\\')
84 >                  {
85 >                    yyless(yyleng - 1);  /* Return last quote */
86 >                    yymore();  /* Append next string */
87 >                  }
88 >                  else
89 >                  {
90 >                    yylval.string = yytext + 1;
91 >
92 >                    if (yylval.string[yyleng - 2] != '"')
93 >                      log_printf("CONFIG ->Unterminated character string");
94 >                    else
95 >                    {
96 >                      unsigned int i = 0, j = 0;
97 >
98 >                      yylval.string[yyleng - 2] = '\0';  /* Remove close quote */
99 >
100 >                      for (; yylval.string[i] != '\0'; ++i, ++j)
101 >                      {
102 >                        if (yylval.string[i] != '\\')
103 >                          yylval.string[j] = yylval.string[i];
104 >                        else
105 >                        {
106 >                          ++i;
107 >
108 >                          if (yylval.string[i] == '\0')  /* XXX: should not happen */
109 >                          {
110 >                            log_printf("CONFIG -> Unterminated character string");
111 >                            break;
112 >                          }
113  
114 <                           if(yytext[yyleng-2] == '\\')
56 <                           {
57 <                              yyless(yyleng-1); /* return last quote */
58 <                              yymore();         /* append next string */
59 <                           }
60 <                           else
61 <                           {
62 <                              yylval.string = yytext+1;
63 <                              if(yylval.string[yyleng-2] != '"') ; /* log error */
64 <                              else
65 <                              {
66 <                                 int i,j;
67 <
68 <                                 yylval.string[yyleng-2] = '\0'; /* remove close
69 <                                                                  *  quote
70 <                                                                  */
71 <
72 <                                 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
73 <                                 {
74 <                                    if (yylval.string[i] != '\\')
75 <                                    {
76 <                                       yylval.string[j] = yylval.string[i];
77 <                                    }
78 <                                    else
79 <                                    {
80 <                                        i++;
81 <                                        yylval.string[j] = yylval.string[i];
82 <                                    }
83 <                                 }
84 <                                 yylval.string[j] = '\0';
85 <                                 return STRING;
86 <                              }
87 <                           }
114 >                          yylval.string[j] = yylval.string[i];
115                          }
116 +                      }
117 +
118 +                      yylval.string[j] = '\0';
119 +                      return STRING;
120 +                    }
121 +                  }
122 +                }
123  
124   AWAY                    { return AWAY;         }
125   BAN_UNKNOWN             { return BAN_UNKNOWN;  }
126   BLACKLIST               { return BLACKLIST;    }
127   CHANNEL                 { return CHANNEL;      }
128 + COMMAND_INTERVAL        { return COMMAND_INTERVAL; }
129 + COMMAND_QUEUE_SIZE      { return COMMAND_QUEUE_SIZE; }
130 + COMMAND_TIMEOUT         { return COMMAND_TIMEOUT; }
131   CONNREGEX               { return CONNREGEX;    }
132   DNS_FDLIMIT             { return DNS_FDLIMIT;  }
133 + DNS_TIMEOUT             { return DNS_TIMEOUT;  }
134   DNSBL_FROM              { return DNSBL_FROM;   }
135   DNSBL_TO                { return DNSBL_TO;     }
136   EXEMPT                  { return EXEMPT;       }
# Line 120 | Line 158 | PORT                    { return PORT;
158   PROTOCOL                { return PROTOCOL;     }
159   READTIMEOUT             { return READTIMEOUT;  }
160   REALNAME                { return REALNAME;     }
161 + RECONNECTINTERVAL       { return RECONNECTINTERVAL; }
162   REPLY                   { return REPLY;        }
163   SCANLOG                 { return SCANLOG;      }
164   SCANNER                 { return SCANNER;      }
# Line 172 | Line 211 | HTTPPOST                {
211                            return PROTOCOLTYPE;
212                          }
213  
214 + HTTPS                   {
215 +                          yylval.number = OPM_TYPE_HTTPS;
216 +                          return PROTOCOLTYPE;
217 +                        }
218 +
219 + HTTPSPOST               {
220 +                          yylval.number = OPM_TYPE_HTTPSPOST;
221 +                          return PROTOCOLTYPE;
222 +                        }
223 +
224   SOCKS4                  {
225                            yylval.number = OPM_TYPE_SOCKS4;
226                            return PROTOCOLTYPE;
# Line 198 | Line 247 | DREAMBOX                {
247                          }
248  
249  
201
202 [0-9]+                  {
203                           yylval.number=atoi(yytext);
204                           return NUMBER;
205                        }
206
207
208
209
210
250   TRUE                     {
251                             yylval.number=1;
252                             return NUMBER;
# Line 238 | Line 277 | OFF                      {
277                             return NUMBER;
278                           }
279  
280 <
281 < \n.*                     {
243 <                           strlcpy(linebuf, yytext + 1, sizeof(linebuf));
244 <                           ++linenum;
245 <                           yyless(1);
246 <                         }
247 <
248 < {whitespace}            /* ignore whitespace */;
249 <
250 < .                       return yytext[0];
280 > .                       { return yytext[0]; }
281 > <<EOF>>                 { if (conf_eof()) yyterminate(); }
282  
283   %%
284  
# Line 263 | Line 294 | ccomment(void)
294    {
295      while ((c = input()) != '*' && c != EOF)
296        if (c == '\n')
297 <        ++linenum;
297 >        ++lineno;
298  
299      if (c == '*')
300      {
# Line 272 | Line 303 | ccomment(void)
303        if (c == '/')
304          break;
305        else if (c == '\n')
306 <        ++linenum;
306 >        ++lineno;
307      }
308  
309      if (c == EOF)
# Line 289 | Line 320 | ccomment(void)
320      }
321    }
322   }
323 +
324 + static void
325 + conf_include(void)
326 + {
327 +  char *p = NULL;
328 +  char filenamebuf[512];
329 +
330 +  if ((p = strchr(yytext, '<')) == NULL)
331 +    *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
332 +  else
333 +    *strchr(++p, '>') = '\0';
334 +
335 +  /* do stacking and co. */
336 +  if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
337 +  {
338 +    log_printf("CONFIG -> Includes nested too deep in %s", p);
339 +    return;
340 +  }
341 +
342 +  if (*p == '/')  /* if it is an absolute path */
343 +    snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
344 +  else
345 +    snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", HOPM_ETCDIR, p);
346 +
347 +  FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
348 +  if (!tmp_fbfile_in)
349 +  {
350 +    log_printf("CONFIG -> Unable to read configuration file '%s': %s",
351 +               filenamebuf, strerror(errno));
352 +    return;
353 +  }
354 +
355 +  struct included_file *file = &include_stack[include_stack_ptr++];
356 +  file->lineno = lineno;
357 +  file->file = conf_file;
358 +  file->state = YY_CURRENT_BUFFER;
359 +  strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
360 +
361 +  lineno = 1;
362 +  conf_file = tmp_fbfile_in;
363 +
364 +  snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
365 +  yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
366 + }
367 +
368 + static int
369 + conf_eof(void)
370 + {
371 +  if (include_stack_ptr == 0)
372 +  {
373 +    lineno = 1;
374 +    return 1;
375 +  }
376 +
377 +  /* switch buffer */
378 +  struct included_file *file = &include_stack[--include_stack_ptr];
379 +
380 +  /* close current file */
381 +  fclose(conf_file);
382 +
383 +  /* switch buffers */
384 +  yy_delete_buffer(YY_CURRENT_BUFFER);
385 +  yy_switch_to_buffer(file->state);
386 +
387 +  /* switch lineno */
388 +  lineno = file->lineno;
389 +
390 +  /* switch file */
391 +  conf_file = file->file;
392 +
393 +  strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
394 +  return 0;
395 + }

Diff Legend

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