syslog-ng source
cfg-parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2011 Balabit
3  * Copyright (c) 1998-2011 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 */
42 
43  /* the parser entry point, returns the parsed object in *instance */
44  gint (*parse)(CfgLexer *lexer, gpointer *instance, gpointer arg);
45 
46  /* in case of parse failure and instance != NULL, this should free instance */
47  void (*cleanup)(gpointer instance);
48 } CfgParser;
49 
50 gboolean cfg_parser_parse(CfgParser *self, CfgLexer *lexer, gpointer *instance, gpointer arg);
51 void cfg_parser_cleanup(CfgParser *self, gpointer instance);
52 
53 enum
54 {
57 };
58 
59 typedef struct _CfgFlagHandler
60 {
61  const gchar *name;
62  gint op;
63  gint ofs;
64  guint32 param;
65  guint32 mask;
67 
68 typedef enum _CfgYesNoAuto
69 {
70  CYNA_AUTO = -1,
71  CYNA_NO = 0,
72  CYNA_YES = 1,
73 } CfgYesNoAuto;
74 
75 gboolean cfg_process_flag(CfgFlagHandler *handlers, gpointer base, const gchar *flag);
76 gboolean cfg_process_yesno(const gchar *yesno);
77 
78 
79 extern CfgParser main_parser;
80 
81 #define CFG_PARSER_DECLARE_LEXER_BINDING(parser_prefix, PARSER_PREFIX, root_type) \
82  int \
83  parser_prefix ## lex(CFG_STYPE *yylval, CFG_LTYPE *yylloc, CfgLexer *lexer); \
84  \
85  void \
86  parser_prefix ## error(const CFG_LTYPE *yylloc, CfgLexer *lexer, root_type instance, gpointer arg, const char *msg);
87 
88 
89 #define CFG_PARSER_IMPLEMENT_LEXER_BINDING(parser_prefix, PARSER_PREFIX, root_type) \
90  int \
91  parser_prefix ## lex(CFG_STYPE *yylval, CFG_LTYPE *yylloc, CfgLexer *lexer) \
92  { \
93  int token; \
94  \
95  token = cfg_lexer_lex(lexer, yylval, yylloc); \
96  return token; \
97  } \
98  \
99  void \
100  parser_prefix ## error(const CFG_LTYPE *yylloc, CfgLexer *lexer, root_type instance, gpointer arg, const char *msg) \
101  { \
102  gboolean in_main_grammar = __builtin_strcmp( # parser_prefix, "main_") == 0; \
103  report_syntax_error(lexer, yylloc, cfg_lexer_get_context_description(lexer), msg, \
104  in_main_grammar); \
105  }
106 
107 void report_syntax_error(CfgLexer *lexer, const CFG_LTYPE *yylloc, const char *what, const char *msg,
108  gboolean in_main_grammar);
109 
110 CFG_PARSER_DECLARE_LEXER_BINDING(main_, MAIN_, gpointer *)
111 
112 #endif
CfgParser main_parser
Definition: cfg-parser.c:232
@ CFH_CLEAR
Definition: cfg-parser.h:56
@ CFH_SET
Definition: cfg-parser.h:55
CfgYesNoAuto
Definition: cfg-parser.h:69
@ CYNA_AUTO
Definition: cfg-parser.h:70
@ CYNA_NO
Definition: cfg-parser.h:71
@ CYNA_YES
Definition: cfg-parser.h:72
#define CFG_PARSER_DECLARE_LEXER_BINDING(parser_prefix, PARSER_PREFIX, root_type)
Definition: cfg-parser.h:81
void report_syntax_error(CfgLexer *lexer, const CFG_LTYPE *yylloc, const char *what, const char *msg, gboolean in_main_grammar)
Definition: cfg-parser.c:247
gboolean cfg_process_yesno(const gchar *yesno)
Definition: cfg-parser.c:383
gboolean cfg_parser_parse(CfgParser *self, CfgLexer *lexer, gpointer *instance, gpointer arg)
Definition: cfg-parser.c:298
gboolean cfg_process_flag(CfgFlagHandler *handlers, gpointer base, const gchar *flag)
Definition: cfg-parser.c:339
void cfg_parser_cleanup(CfgParser *self, gpointer instance)
Definition: cfg-parser.c:326
Definition: cfg-lexer.h:88
Definition: cfg-parser.h:60
guint32 param
Definition: cfg-parser.h:64
guint32 mask
Definition: cfg-parser.h:65
gint ofs
Definition: cfg-parser.h:63
const gchar * name
Definition: cfg-parser.h:61
gint op
Definition: cfg-parser.h:62
Definition: cfg-lexer.h:118
Definition: cfg-parser.h:34
gint context
Definition: cfg-parser.h:37
const gchar * name
Definition: cfg-parser.h:38
gint * debug_flag
Definition: cfg-parser.h:36
CfgLexerKeyword * keywords
Definition: cfg-parser.h:41
LogMessage * msg
Definition: test_rename.c:35