File: rewrite-expr-grammar.ym

package info (click to toggle)
syslog-ng 3.28.1-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,028 kB
  • sloc: ansic: 132,531; python: 5,838; makefile: 5,195; sh: 4,580; java: 3,555; xml: 3,344; yacc: 1,209; lex: 493; perl: 193; awk: 184
file content (229 lines) | stat: -rw-r--r-- 6,631 bytes parent folder | download
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
/*
 * Copyright (c) 2002-2012 Balabit
 * Copyright (c) 1998-2012 Balázs Scheidler
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; 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 "rewrite/rewrite-expr-parser.h"

}

%code {

#include "rewrite/rewrite-expr-grammar.h"
#include "rewrite/rewrite-set-tag.h"
#include "rewrite/rewrite-set.h"
#include "rewrite/rewrite-unset.h"
#include "rewrite/rewrite-subst.h"
#include "rewrite/rewrite-groupset.h"
#include "rewrite/rewrite-set-severity.h"
#include "rewrite/rewrite-set-facility.h"
#include "filter/filter-expr.h"
#include "filter/filter-expr-parser.h"
#include "cfg-grammar.h"
#include "syslog-names.h"
#include "plugin.h"

#include <string.h>

}

%name-prefix "rewrite_expr_"
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogExprNode **result}
%parse-param {gpointer arg}

%type   <ptr> rewrite_expr
%type   <ptr> rewrite_expr_list

/* INCLUDE_DECLS */

%token KW_SET_TAG
%token KW_CLEAR_TAG
%token KW_GROUP_SET
%token KW_GROUP_UNSET
%token KW_SET
%token KW_UNSET
%token KW_SUBST
%token KW_VALUES
%token KW_SET_SEVERITY
%token KW_SET_FACILITY

%%

start
        : rewrite_expr_list log_last_junction        { *result = log_expr_node_append_tail($1, $2); if (yychar != YYEMPTY) { cfg_lexer_unput_token(lexer, &yylval); } YYACCEPT; }
	;

rewrite_expr_list
        : rewrite_expr semicolons rewrite_expr_list  { $$ = log_expr_node_append_tail(log_expr_node_new_pipe($1, &@1), $3); }
        | log_junction semicolons rewrite_expr_list      { $$ = log_expr_node_append_tail($1,  $3); }
        |                                           { $$ = NULL; }
        ;

rewrite_expr
        : KW_SUBST '(' string template_content
          {
            last_rewrite = log_rewrite_subst_new($4, configuration);
            log_template_unref($4);
          }
          rewrite_subst_opts ')'
          {
            GError *error = NULL;
            CHECK_ERROR_GERROR(log_rewrite_subst_compile_pattern(last_rewrite, $3, &error), @3, error, "error compiling search pattern");
            free($3);
            $$ = last_rewrite;
          }
        | KW_SET '(' template_content
          {
            last_rewrite = log_rewrite_set_new($3, configuration);
            last_template_options = log_rewrite_set_get_template_options(last_rewrite);
            log_template_unref($3);
          }
          rewrite_set_opts ')'                 { $$ = last_rewrite; }
        | KW_UNSET
          {
            last_rewrite = log_rewrite_unset_new(configuration);
          }
          '(' rewrite_set_opts ')'              { $$ = last_rewrite; }
	| KW_SET_TAG '(' string 
	  { 
	    last_rewrite = log_rewrite_set_tag_new($3, TRUE, configuration);
            free($3);
          }
	  rewrite_settag_opts ')'             	{ $$ = last_rewrite; }
	| KW_CLEAR_TAG '(' string
          {
            last_rewrite = log_rewrite_set_tag_new($3, FALSE, configuration);
            free($3);
          }
          rewrite_settag_opts ')'               { $$ = last_rewrite; }
        | KW_GROUP_SET '(' template_content
          {
            last_rewrite = log_rewrite_groupset_new($3, configuration);
            log_template_unref($3);
          }
          rewrite_groupset_opts ')'             { $$ = last_rewrite; }
        | KW_GROUP_UNSET '('
          {
            last_rewrite = log_rewrite_groupunset_new(configuration);
          }
          rewrite_groupset_opts ')'             { $$ = last_rewrite; }
        | KW_SET_SEVERITY '(' template_content
          {
            last_rewrite = log_rewrite_set_severity_new($3, configuration);
            log_template_unref($3);
          } rewrite_set_severity_opts ')'	{ $$ = last_rewrite; };
        | KW_SET_FACILITY '(' template_content
          {
            last_rewrite = log_rewrite_set_facility_new($3, configuration);
            log_template_unref($3);
          } rewrite_set_facility_opts ')'       { $$ = last_rewrite; };
        | LL_IDENTIFIER
          {
            Plugin *p;
            gint context = LL_CONTEXT_REWRITE;

            p = cfg_find_plugin(configuration, context, $1);
            CHECK_ERROR(p, @1, "%s plugin %s not found", cfg_lexer_lookup_context_name_by_type(context), $1);

            last_rewrite = (LogRewrite *) cfg_parse_plugin(configuration, p, &@1, NULL);
            free($1);
            if (!last_rewrite)
              {
                YYERROR;
              }
            $$ = last_rewrite;
          }
        ;

rewrite_settag_opts
        : rewrite_settag_opt rewrite_settag_opts
        |
        ;

rewrite_settag_opt
        : rewrite_condition_opt
        ;

rewrite_groupset_opts
        : rewrite_groupset_opt rewrite_groupset_opts
        |
        ;

rewrite_groupset_opt
        : KW_VALUES '(' string_list ')'
          {
            log_rewrite_groupset_add_fields(last_rewrite, $3);
          }
        | rewrite_condition_opt
        ;

rewrite_subst_opts
        : rewrite_subst_opt rewrite_subst_opts
        |
        ;

rewrite_subst_opt
	: { last_matcher_options = log_rewrite_subst_get_matcher_options(last_rewrite); } matcher_option
	| rewrite_expr_opt
        ;

rewrite_set_opts
        : rewrite_set_opt rewrite_set_opts
        |
        ;

rewrite_set_opt
        : rewrite_expr_opt
        | template_option
        ;

rewrite_expr_opts
        : rewrite_expr_opt rewrite_expr_opts
        |
        ;

rewrite_set_severity_opts
        : rewrite_set_severity_opt rewrite_set_severity_opts
        |
        ;

rewrite_set_severity_opt
        : rewrite_condition_opt
        ;

rewrite_set_facility_opts
        : rewrite_set_facility_opt rewrite_set_facility_opts
        |
        ;

rewrite_set_facility_opt
        : rewrite_condition_opt
        ;


/* INCLUDE_RULES */

%%