~ubuntu-branches/ubuntu/oneiric/syslog-ng/oneiric

« back to all changes in this revision

Viewing changes to lib/cfg-parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2011-05-16 22:02:46 UTC
  • mfrom: (26.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110516220246-nknmeu831n49bx1z
Tags: 3.2.4-1
* New upstream release, fixing infinite loop via PCRE and global. No CVE
  number yet, Vigil@nce id is 10648.
* Remove all patches, they were applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2010 BalaBit IT Ltd, Budapest, Hungary
 
3
 * Copyright (c) 1998-2010 Balázs Scheidler
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library 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 GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 *
 
19
 * As an additional exemption you are allowed to compile & link against the
 
20
 * OpenSSL libraries as published by the OpenSSL project. See the file
 
21
 * COPYING for details.
 
22
 *
 
23
 */
 
24
 
 
25
#ifndef CFG_PARSER_H_INCLUDED
 
26
#define CFG_PARSER_H_INCLUDED
 
27
 
 
28
#include "syslog-ng.h"
 
29
#include "cfg-lexer.h"
 
30
 
 
31
/* high level interface to a configuration file parser, it encapsulates the
 
32
 * grammar/lexer pair. */
 
33
typedef struct _CfgParser
 
34
{
 
35
  /* how to enable bison debug in the parser */
 
36
  gint *debug_flag;
 
37
  gint context;
 
38
  const gchar *name;
 
39
 
 
40
  /* parser specific keywords to be pushed to the lexer */
 
41
  CfgLexerKeyword *keywords;
 
42
 
 
43
  /* the parser entry point, returns the parsed object in *instance */
 
44
  gint (*parse)(CfgLexer *lexer, gpointer *instance);
 
45
 
 
46
  /* in case of parse failure and instance != NULL, this should free instance */
 
47
  void (*cleanup)(gpointer instance);
 
48
} CfgParser;
 
49
 
 
50
enum
 
51
{
 
52
  CFH_SET,
 
53
  CFH_CLEAR,
 
54
};
 
55
 
 
56
typedef struct _CfgFlagHandler
 
57
{
 
58
  const gchar *name;
 
59
  gint op;
 
60
  gint ofs;
 
61
  guint32 param;
 
62
} CfgFlagHandler;
 
63
 
 
64
gboolean
 
65
cfg_process_flag(CfgFlagHandler *handlers, gpointer base, gchar *flag);
 
66
 
 
67
/* the debug flag for the main parser will be used for all parsers */
 
68
extern int cfg_parser_debug;
 
69
 
 
70
static inline gboolean
 
71
cfg_parser_parse(CfgParser *self, CfgLexer *lexer, gpointer *instance)
 
72
{
 
73
  gboolean success;
 
74
 
 
75
  if (cfg_parser_debug)
 
76
    {
 
77
      fprintf(stderr, "\n\nStarting parser %s\n", self->name);
 
78
    }
 
79
  if (self->debug_flag)
 
80
    (*self->debug_flag) = cfg_parser_debug;
 
81
  cfg_lexer_push_context(lexer, self->context, self->keywords, self->name);
 
82
  success = (self->parse(lexer, instance) == 0);
 
83
  cfg_lexer_pop_context(lexer);
 
84
  if (cfg_parser_debug)
 
85
    {
 
86
      fprintf(stderr, "\nStopping parser %s, result: %d\n", self->name, success);
 
87
    }
 
88
  return success;
 
89
}
 
90
 
 
91
static inline void
 
92
cfg_parser_cleanup(CfgParser *self, gpointer instance)
 
93
{
 
94
  if (instance && self->cleanup)
 
95
    self->cleanup(instance);
 
96
}
 
97
 
 
98
extern CfgParser main_parser;
 
99
 
 
100
#define CFG_PARSER_DECLARE_LEXER_BINDING(parser_prefix, root_type)             \
 
101
    int                                                                        \
 
102
    parser_prefix ## lex(YYSTYPE *yylval, YYLTYPE *yylloc, CfgLexer *lexer);   \
 
103
                                                                               \
 
104
    void                                                                       \
 
105
    parser_prefix ## error(YYLTYPE *yylloc, CfgLexer *lexer, root_type instance, const char *msg);
 
106
 
 
107
 
 
108
#define CFG_PARSER_IMPLEMENT_LEXER_BINDING(parser_prefix, root_type)          \
 
109
    int                                                                       \
 
110
    parser_prefix ## lex(YYSTYPE *yylval, YYLTYPE *yylloc, CfgLexer *lexer)   \
 
111
    {                                                                         \
 
112
      int token;                                                              \
 
113
                                                                              \
 
114
      token = cfg_lexer_lex(lexer, yylval, yylloc);                           \
 
115
      return token;                                                           \
 
116
    }                                                                         \
 
117
                                                                              \
 
118
    void                                                                      \
 
119
    parser_prefix ## error(YYLTYPE *yylloc, CfgLexer *lexer, root_type instance, const char *msg) \
 
120
    {                                                                                             \
 
121
      report_syntax_error(lexer, yylloc, cfg_lexer_get_context_description(lexer), msg);          \
 
122
    }
 
123
 
 
124
void report_syntax_error(CfgLexer *lexer, YYLTYPE *yylloc, const char *what, const char *msg);
 
125
 
 
126
CFG_PARSER_DECLARE_LEXER_BINDING(main_, gpointer *)
 
127
 
 
128
#endif