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 5080 by michael, Mon Dec 22 19:00:47 2014 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
2 > *  Copyright (c) 2002 Erik Fears
3 > *  Copyright (c) 2014-2016 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 nounput
24 + %option never-interactive
25  
26   %{
27   #include <stdio.h>
28   #include <string.h>
29  
35 #include "inet.h"
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 < 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 < int linenum = 1;
42 >
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]
49 < comment                ("//"|"#").*
50 < whitespace             [ \t\r]*
55 > static unsigned int include_stack_ptr;
56  
52 %%
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 > %}
69  
70 < {string}                {
71 <                           /* QSTRING from Hybrid7. Why re-invent the wheel? */
70 > WS        [[:blank:]]*
71 > DIGIT     [[:digit:]]+
72 > COMMENT   ("//"|"#").*
73 > qstring   \"[^\"\n]*[\"\n]
74 > include   \.include{WS}(\<.*\>|\".*\")
75  
76 <                           if(yytext[yyleng-2] == '\\')
77 <                           {
78 <                              yyless(yyleng-1); /* return last quote */
79 <                              yymore();         /* append next string */
80 <                           }
81 <                           else
82 <                           {
83 <                              yylval.string = yytext+1;
84 <                              if(yylval.string[yyleng-2] != '"') ; /* log error */
85 <                              else
86 <                              {
87 <                                 int i,j;
88 <
89 <                                 yylval.string[yyleng-2] = '\0'; /* remove close
90 <                                                                  *  quote
91 <                                                                  */
92 <
93 <                                 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
94 <                                 {
95 <                                    if (yylval.string[i] != '\\')
96 <                                    {
97 <                                       yylval.string[j] = yylval.string[i];
98 <                                    }
99 <                                    else
100 <                                    {
101 <                                        i++;
102 <                                        yylval.string[j] = yylval.string[i];
103 <                                    }
104 <                                 }
105 <                                 yylval.string[j] = '\0';
106 <                                 return STRING;
107 <                              }
108 <                           }
109 <            
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 >                          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 113 | Line 144 | MAX_READ                { return MAX_REA
144   MODE                    { return MODE;         }
145   NAME                    { return NAME;         }
146   NEGCACHE                { return NEGCACHE;     }
147 + NEGCACHE_REBUILD        { return NEGCACHE_REBUILD; }
148   NICK                    { return NICK;         }
149   NICKSERV                { return NICKSERV;     }
150 + NOTICE                  { return NOTICE;       }
151   OPER                    { return OPER;         }
152   OPM                     { return OPM;          }
153   OPTIONS                 { return OPTIONS;      }
# Line 123 | Line 156 | PERFORM                 { return PERFORM
156   PIDFILE                 { return PIDFILE;      }
157   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 176 | 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 196 | Line 241 | ROUTER                  {
241                            return PROTOCOLTYPE;
242                          }
243  
244 <
245 < [0-9]+                  {
246 <                           yylval.number=atoi(yytext);
202 <                           return NUMBER;
244 > DREAMBOX                {
245 >                          yylval.number = OPM_TYPE_DREAMBOX;
246 >                          return PROTOCOLTYPE;
247                          }
248  
249  
206
207
208
250   TRUE                     {
251                             yylval.number=1;
252                             return NUMBER;
# Line 236 | Line 277 | OFF                      {
277                             return NUMBER;
278                           }
279  
280 <
281 < \n.*                     {
241 <                           strlcpy(linebuf, yytext + 1, sizeof(linebuf));
242 <                           ++linenum;
243 <                           yyless(1);
244 <                         }
245 <
246 < {whitespace}            /* ignore whitespace */;
247 <
248 < .                       return yytext[0];
280 > .                       { return yytext[0]; }
281 > <<EOF>>                 { if (conf_eof()) yyterminate(); }
282  
283   %%
284  
285  
286   /* C-comment ignoring routine -kre*/
287 < void ccomment(void)
287 > static void
288 > ccomment(void)
289   {
290 <  int c;
290 >  int c = 0;
291  
292    /* log(L_NOTICE, "got comment"); */
293    while (1)
294    {
295 <     while ((c = input()) != '*' && c != EOF)
296 <        if (c == '\n') ++linenum;
297 <     if (c == '*')
298 <     {
299 <        while ((c = input()) == '*');
300 <        if (c == '/') break;
301 <     }
295 >    while ((c = input()) != '*' && c != EOF)
296 >      if (c == '\n')
297 >        ++lineno;
298 >
299 >    if (c == '*')
300 >    {
301 >      while ((c = input()) == '*')
302 >        /* Nothing */ ;
303 >      if (c == '/')
304 >        break;
305 >      else if (c == '\n')
306 >        ++lineno;
307 >    }
308 >
309      if (c == EOF)
310      {
311 <       YY_FATAL_ERROR("EOF in comment");
312 <       /* XXX hack alert this disables
313 <        * the stupid unused function warning
314 <        * gcc generates
315 <        */
316 <       if(1 == 0)
317 <          yy_fatal_error("EOF in comment");
318 <       break;
311 >      YY_FATAL_ERROR("EOF in comment");
312 >
313 >      /* XXX hack alert this disables
314 >       * the stupid unused function warning
315 >       * gcc generates
316 >       */
317 >      if (1 == 0)
318 >        yy_fatal_error("EOF in comment");
319 >      break;
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 + }

Comparing hopm/trunk/src/config-lexer.l (property svn:eol-style):
Revision 5080 by michael, Mon Dec 22 19:00:47 2014 UTC vs.
Revision 7716 by michael, Mon Sep 26 12:08:43 2016 UTC

# Line 0 | Line 1
1 + native

Comparing hopm/trunk/src/config-lexer.l (property svn:keywords):
Revision 5080 by michael, Mon Dec 22 19:00:47 2014 UTC vs.
Revision 7716 by michael, Mon Sep 26 12:08:43 2016 UTC

# Line 0 | Line 1
1 + Id

Diff Legend

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