File: correlation-grammar.ym

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (241 lines) | stat: -rw-r--r-- 7,176 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2002-2013 Balabit
 * Copyright (c) 1998-2013 Balázs Scheidler
 *
 * 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 top {
#include "correlation-parser.h"

}


%code {

#include "dbparser.h"
#include "cfg-grammar-internal.h"
#include "groupingby.h"
#include "group-lines.h"
#include "cfg-parser.h"
#include "syslog-names.h"
#include "messages.h"
#include "filter/filter-expr.h"
#include <string.h>

SyntheticMessage *last_message;
}

%define api.prefix {correlation_}

/* this parameter is needed in order to instruct bison to use a complete
 * argument list for yylex/yyerror */

%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogParser **instance}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_DB_PARSER
%token KW_GROUPING_BY
%token KW_INJECT_MODE
%token KW_INHERIT_MODE
%token KW_TIMEOUT
%token KW_TRIGGER
%token KW_WHERE
%token KW_HAVING
%token KW_AGGREGATE
%token KW_DROP_UNMATCHED
%token KW_FILE
%token KW_PROGRAM_TEMPLATE
%token KW_MESSAGE_TEMPLATE
%token KW_SORT_KEY
%token KW_PREFIX
%token KW_GROUP_LINES
%token KW_LINE_SEPARATOR

%type <num> stateful_parser_inject_mode
%type <ptr> synthetic_message
%type <num> inherit_mode
%type <num> context_scope

%%

start
        : LL_CONTEXT_PARSER parser_expr_db                  { YYACCEPT; }
        ;

parser_expr_db
        : KW_DB_PARSER '('
          {
            last_parser = *instance = (LogParser *) log_db_parser_new(configuration);
          }
          parser_db_opts
          ')'
	| KW_GROUPING_BY '('
	  {
	    last_parser = *instance = grouping_by_new(configuration);
	  }
          grouping_by_opts ')'
        | KW_GROUP_LINES '('
	  {
	    last_parser = *instance = group_lines_new(configuration);
	    last_multi_line_options = group_lines_get_multi_line_options(last_parser);
	  }
          group_lines_opts ')'
        ;

parser_db_opts
        : parser_db_opt parser_db_opts
        |
        ;

/* NOTE: we don't support parser_opt as we don't want the user to specify a template */
parser_db_opt
        : KW_FILE '(' path_no_check ')'                		{ log_db_parser_set_db_file(((LogDBParser *) last_parser), $3); free($3); }
	| KW_DROP_UNMATCHED '(' yesno ')'			{ log_db_parser_set_drop_unmatched(((LogDBParser *) last_parser), $3); };
        | KW_PROGRAM_TEMPLATE '(' template_content ')'
          {
             log_db_parser_set_program_template_ref(last_parser, $3);
          }
        | KW_MESSAGE_TEMPLATE '(' template_name_or_content ')'    { log_parser_set_template(last_parser, $3); }
	| KW_PREFIX '(' string ')'				{ log_db_parser_set_prefix(((LogDBParser *) last_parser), $3); free($3); };
	| stateful_parser_opt
        ;

stateful_parser_opt
	: KW_INJECT_MODE '(' stateful_parser_inject_mode ')'	{ stateful_parser_set_inject_mode(((StatefulParser *) last_parser), $3); }
        | KW_PERSIST_NAME '(' string ')'                        { log_pipe_set_persist_name(&last_parser->super, $3); free($3); }
	| parser_opt
	;

stateful_parser_inject_mode
	: string
	  {
            $$ = stateful_parser_lookup_inject_mode($1);
            CHECK_ERROR($$ != -1, @1, "Unknown inject-mode %s", $1);
            free($1);
          }
	| KW_INTERNAL				{ $$ = stateful_parser_lookup_inject_mode("internal"); }
	;

grouping_parser_opt
        : KW_KEY '(' template_content ')'                       { grouping_parser_set_key_template(last_parser, $3); log_template_unref($3); }
        | KW_SORT_KEY '(' template_content ')'			{ grouping_parser_set_sort_key_template(last_parser, $3); log_template_unref($3); }
        | KW_SCOPE '(' context_scope ')'                        { grouping_parser_set_scope(last_parser, $3); }
	| KW_TIMEOUT '(' nonnegative_integer ')'
          {
            CHECK_ERROR($3 >= 1, @1, "timeout() needs to be greater than zero");

            grouping_parser_set_timeout(last_parser, $3);
          }
        ;


grouping_by_opts
	: grouping_by_opt grouping_by_opts
	|
	;

grouping_by_opt
        : KW_WHERE '('
          {
            FilterExprNode *filter_expr;

            CHECK_ERROR_WITHOUT_MESSAGE(cfg_parser_parse(&filter_expr_parser, lexer, (gpointer *) &filter_expr, NULL), @1);
            grouping_by_set_where_condition(last_parser, filter_expr);
          } ')'
        | KW_HAVING '('
          {
            FilterExprNode *filter_expr;

            CHECK_ERROR_WITHOUT_MESSAGE(cfg_parser_parse(&filter_expr_parser, lexer, (gpointer *) &filter_expr, NULL), @1);
            grouping_by_set_having_condition(last_parser, filter_expr);
          } ')'
	| KW_AGGREGATE '(' synthetic_message ')'		{ grouping_by_set_synthetic_message(last_parser, $3); }
	| KW_TRIGGER '('
          {
            FilterExprNode *filter_expr;

            CHECK_ERROR_WITHOUT_MESSAGE(cfg_parser_parse(&filter_expr_parser, lexer, (gpointer *) &filter_expr, NULL), @1);
            grouping_by_set_trigger_condition(last_parser, filter_expr);
          } ')'
	| KW_PREFIX '(' string ')'				{ grouping_by_set_prefix(last_parser, $3); free($3); };
	| stateful_parser_opt
        | grouping_parser_opt
	;

group_lines_opts
	: group_lines_opt group_lines_opts
	|
	;

group_lines_opt
        : multi_line_option
	| parser_opt
	| grouping_parser_opt
        | KW_LINE_SEPARATOR '(' string ')'			{ group_lines_set_separator(last_parser, $3); free($3); }
	;


synthetic_message
	: { last_message = synthetic_message_new(); } synthetic_message_opts { $$ = last_message; }
	;


synthetic_message_opts
	: synthetic_message_opt synthetic_message_opts
	|
	;

synthetic_message_opt
	: KW_INHERIT_MODE '(' inherit_mode ')'                  { synthetic_message_set_inherit_mode(last_message, $3); }
	| KW_VALUE '(' string template_content ')'
	  {
	    synthetic_message_add_value_template(last_message, $3, $4);
	    free($3);
            log_template_unref($4);
	  }
	| KW_TAGS '(' string ')'				{ synthetic_message_add_tag(last_message, $3); free($3); }
	;

inherit_mode
        : string
          {
            $$ = synthetic_message_lookup_inherit_mode($1);
            free($1);
            CHECK_ERROR($$ >= 0, @1, "unknown inherit-mode()");
          }
        ;

context_scope
        : string
          {
            $$ = correlation_key_lookup_scope($1);
            free($1);
            CHECK_ERROR($$ >= 0, @1, "unknown context-scope()");
          }
        ;


/* INCLUDE_RULES */

%%