2 * filter-visitor-ir-validate-string.c
4 * LTTng filter IR validate string
6 * Copyright 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <common/macros.h>
32 #include "filter-ast.h"
33 #include "filter-parser.h"
34 #include "filter-ir.h"
36 enum parse_char_result
{
37 PARSE_CHAR_UNKNOWN
= -2,
38 PARSE_CHAR_WILDCARD
= -1,
39 PARSE_CHAR_NORMAL
= 0,
43 enum parse_char_result
parse_char(const char **p
)
51 return PARSE_CHAR_NORMAL
;
53 return PARSE_CHAR_UNKNOWN
;
56 return PARSE_CHAR_WILDCARD
;
58 return PARSE_CHAR_NORMAL
;
63 int validate_string(struct ir_op
*node
)
68 fprintf(stderr
, "[error] %s: unknown op type\n", __func__
);
72 return validate_string(node
->u
.root
.child
);
77 if (node
->data_type
== IR_DATA_STRING
) {
80 assert(node
->u
.load
.u
.string
);
81 str
= node
->u
.load
.u
.string
;
84 * Make sure that if a non-escaped wildcard is
85 * present, it is the last character of the string.
88 enum parse_char_result res
;
94 res
= parse_char(&str
);
98 case PARSE_CHAR_WILDCARD
:
102 * Found a wildcard followed by non-null
103 * character; unsupported.
107 "Wildcards may only be used as the last character of a string in a filter.\n");
112 case PARSE_CHAR_UNKNOWN
:
115 "Unsupported escape character detected.\n");
117 case PARSE_CHAR_NORMAL
:
127 return validate_string(node
->u
.unary
.child
);
130 int ret
= validate_string(node
->u
.binary
.left
);
134 return validate_string(node
->u
.binary
.right
);
140 ret
= validate_string(node
->u
.logical
.left
);
143 return validate_string(node
->u
.logical
.right
);
149 int filter_visitor_ir_validate_string(struct filter_parser_ctx
*ctx
)
151 return validate_string(ctx
->ir_root
);
This page took 0.031495 seconds and 4 git commands to generate.