Commit | Line | Data |
---|---|---|
953192ba MD |
1 | /* |
2 | * filter-visitor-ir-check-binary-comparator.c | |
3 | * | |
4 | * LTTng filter IR check binary comparator | |
5 | * | |
6 | * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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 | |
20 | */ | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <unistd.h> | |
24 | #include <string.h> | |
25 | #include <stdlib.h> | |
26 | #include <assert.h> | |
27 | #include <errno.h> | |
28 | #include <inttypes.h> | |
29 | #include "filter-parser.h" | |
30 | #include "filter-ast.h" | |
31 | #include "filter-ir.h" | |
32 | ||
33 | static | |
34 | int check_bin_comparator(struct ir_op *node) | |
35 | { | |
36 | switch (node->op) { | |
37 | case IR_OP_UNKNOWN: | |
38 | default: | |
39 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
40 | return -EINVAL; | |
41 | ||
42 | case IR_OP_ROOT: | |
43 | return check_bin_comparator(node->u.root.child); | |
44 | case IR_OP_LOAD: | |
45 | return 0; | |
46 | case IR_OP_UNARY: | |
47 | return check_bin_comparator(node->u.unary.child); | |
48 | case IR_OP_BINARY: | |
49 | { | |
50 | int ret; | |
51 | ||
52 | if (node->u.binary.left->data_type == IR_DATA_STRING | |
53 | || node->u.binary.right->data_type | |
54 | == IR_DATA_STRING) { | |
55 | if (node->u.binary.type != AST_OP_EQ | |
56 | && node->u.binary.type != AST_OP_NE) { | |
57 | fprintf(stderr, "[error] Only '==' and '!=' comparators are allowed for strings\n"); | |
58 | return -EINVAL; | |
59 | } | |
60 | } | |
61 | ||
62 | ret = check_bin_comparator(node->u.binary.left); | |
63 | if (ret) | |
64 | return ret; | |
65 | return check_bin_comparator(node->u.binary.right); | |
66 | } | |
67 | case IR_OP_LOGICAL: | |
68 | { | |
69 | int ret; | |
70 | ||
71 | ret = check_bin_comparator(node->u.logical.left); | |
72 | if (ret) | |
73 | return ret; | |
74 | return check_bin_comparator(node->u.logical.right); | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | int filter_visitor_ir_check_binary_comparator(struct filter_parser_ctx *ctx) | |
80 | { | |
81 | return check_bin_comparator(ctx->ir_root); | |
82 | } |