1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
/*
* Copyright (c) 2014 Balabit
* Copyright (c) 2014 Gergely Nagy <algernon@balabit.hu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
%code requires {
#include "python-parser.h"
#include "python-dest.h"
#include "python-source.h"
#include "python-fetcher.h"
#include "python-logparser.h"
#include "python-http-header.h"
#include "python-global.h"
#include "value-pairs/value-pairs.h"
#include "string-list.h"
#include "logthrsource/logthrsourcedrv.h"
}
%code {
#include "cfg-grammar-internal.h"
#include "cfg-parser.h"
#include "plugin.h"
#include "syslog-names.h"
PythonHttpHeaderPlugin *last_header;
PythonOptions *last_python_options;
PythonBinding *last_python_binding;
static inline void
_warn_if_config_version_is_old(CfgLexer *lexer, const CFG_LTYPE *yylloc, const gchar *type, const gchar *option_name)
{
if (!cfg_is_config_version_older(configuration, VERSION_VALUE_4_2))
return;
msg_warning("WARNING: The parsing of python options has been changed with " VERSION_4_2 ". "
"Previously values were converted to strings if possible, now they are passed "
"to the python class with their real type. Make sure to follow up these changes "
"in your python code",
cfg_lexer_format_location_tag(lexer, yylloc),
evt_tag_str("type", type),
evt_tag_str("option_name", option_name));
};
}
%define api.prefix {python_}
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {void **instance}
%parse-param {gpointer arg}
/* INCLUDE_DECLS */
%token KW_PYTHON
%token KW_PYTHON_FETCHER
%token KW_PYTHON_HTTP_HEADER
%token KW_CLASS
%token KW_IMPORTS
%token KW_LOADERS
%token KW_MARK_ERRORS_AS_CRITICAL
%token KW_TRUE
%token KW_FALSE
%token KW_LOG_TEMPLATE
%type <ptr> python_options_block
%type <ptr> python_option
%type <num> python_yesno
%%
start
: LL_CONTEXT_DESTINATION KW_PYTHON
{
last_driver = *instance = python_dd_new(configuration);
last_python_binding = python_dd_get_binding(last_driver);
}
'(' _inner_dest_context_push python_dd_options _inner_dest_context_pop ')' { YYACCEPT; }
| LL_CONTEXT_PARSER KW_PYTHON
{
last_parser = *instance = python_parser_new(configuration);
last_python_binding = python_parser_get_binding(last_parser);
}
'(' python_parser_options ')' { YYACCEPT; }
| LL_CONTEXT_SOURCE KW_PYTHON
{
last_driver = *instance = python_sd_new(configuration);
last_python_binding = python_sd_get_binding(last_driver);
}
'(' _inner_src_context_push python_sd_options _inner_src_context_pop ')' { YYACCEPT; }
| LL_CONTEXT_SOURCE KW_PYTHON_FETCHER
{
last_driver = *instance = python_fetcher_new(configuration);
last_python_binding = python_fetcher_get_binding(last_driver);
}
'(' _inner_src_context_push python_fetcher_options _inner_src_context_pop ')' { YYACCEPT; }
| LL_CONTEXT_INNER_DEST KW_PYTHON_HTTP_HEADER
{
last_header = *instance = python_http_header_new();
last_python_binding = python_http_header_get_binding(last_header);
}
'(' python_http_header_options ')' { YYACCEPT; }
| LL_CONTEXT_ROOT KW_PYTHON _block_content_context_push LL_BLOCK _block_content_context_pop
{
gboolean result;
result = python_evaluate_global_code(configuration, $4, &@2);
free($4);
CHECK_ERROR(result, @1, "Error processing global python block");
*instance = (void *) 1;
YYACCEPT;
}
;
python_dd_options
: python_dd_option python_dd_options
|
;
python_dd_option
: python_binding_option
| threaded_dest_driver_general_option
| threaded_dest_driver_batch_option
| value_pair_option
{
python_dd_set_value_pairs(last_driver, $1);
}
| { last_template_options = python_dd_get_template_options(last_driver); } template_option
;
python_sd_options
: python_sd_option python_sd_options
|
;
python_sd_option
: python_binding_option
| threaded_source_driver_option
;
python_fetcher_options
: python_fetcher_option python_fetcher_options
|
;
python_fetcher_option
: python_binding_option
| threaded_source_driver_option
| threaded_fetcher_driver_option
;
python_parser_options
: python_parser_option python_parser_options
|
;
python_parser_option
: python_binding_option
| parser_opt
;
python_http_header_options
: python_http_header_option python_http_header_options
|
;
python_http_header_option
: python_binding_option
| KW_MARK_ERRORS_AS_CRITICAL '(' yesno ')'
{
python_http_header_set_mark_errors_as_critical(last_header, $3);
}
;
optional_arrow
: LL_ARROW
|
;
python_yesno
: yesno_strict
| KW_TRUE { $$ = 1; }
| KW_FALSE { $$ = 0; }
;
python_binding_option
: KW_CLASS '(' string ')'
{
python_binding_set_class(last_python_binding, $3);
free($3);
}
| KW_LOADERS '(' string_list ')'
{
python_binding_set_loaders(last_python_binding, $3);
}
| KW_IMPORTS '(' string_list ')'
{
python_binding_set_loaders(last_python_binding, $3);
}
| { last_python_options = last_python_binding->options; } python_options_block
;
python_option
: string optional_arrow string
{
$$ = python_option_string_new($1, $3);
free($1);
free($3);
}
| string optional_arrow LL_NUMBER
{
$$ = python_option_long_new($1, $3);
_warn_if_config_version_is_old(lexer, &@3, "int", $1);
free($1);
}
| string optional_arrow LL_FLOAT
{
$$ = python_option_double_new($1, $3);
_warn_if_config_version_is_old(lexer, &@3, "float", $1);
free($1);
}
| string optional_arrow python_yesno
{
$$ = python_option_boolean_new($1, $3);
_warn_if_config_version_is_old(lexer, &@3, "bool", $1);
free($1);
}
| string optional_arrow '[' string_list ']'
{
$$ = python_option_string_list_new($1, $4);
free($1);
string_list_free($4);
}
| string optional_arrow KW_LOG_TEMPLATE '(' optional_string ')'
{
$$ = python_option_template_new($1, $5 ? $5 : "");
free($1);
if ($5)
free($5);
}
;
python_options
: python_option
{
python_options_add_option(last_python_options, $1);
python_option_unref($1);
}
python_options
|
;
python_options_block
: KW_OPTIONS '(' python_options ')'
;
/* INCLUDE_RULES */
%%
|