Commit | Line | Data |
---|---|---|
9f449915 PP |
1 | /* |
2 | * filter-visitor-ir-normalize-glob-patterns.c | |
3 | * | |
4 | * LTTng filter IR normalize string | |
5 | * | |
ab5be9fa | 6 | * Copyright 2017 Philippe Proulx <pproulx@efficios.com> |
9f449915 | 7 | * |
ab5be9fa | 8 | * SPDX-License-Identifier: LGPL-2.1-only |
9f449915 | 9 | * |
9f449915 PP |
10 | */ |
11 | ||
12 | #include <stdio.h> | |
13 | #include <unistd.h> | |
14 | #include <string.h> | |
15 | #include <stdlib.h> | |
9f449915 PP |
16 | #include <inttypes.h> |
17 | ||
edf4b93e | 18 | #include <common/compat/errno.h> |
9f449915 PP |
19 | #include <common/macros.h> |
20 | #include <common/string-utils/string-utils.h> | |
21 | ||
22 | #include "filter-ast.h" | |
348ddc5c | 23 | #include "filter-parser.hpp" |
9f449915 PP |
24 | #include "filter-ir.h" |
25 | ||
26 | static | |
27 | int normalize_glob_patterns(struct ir_op *node) | |
28 | { | |
29 | switch (node->op) { | |
30 | case IR_OP_UNKNOWN: | |
31 | default: | |
32 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
33 | return -EINVAL; | |
34 | ||
35 | case IR_OP_ROOT: | |
36 | return normalize_glob_patterns(node->u.root.child); | |
37 | case IR_OP_LOAD: | |
38 | { | |
39 | if (node->data_type == IR_DATA_STRING) { | |
40 | enum ir_load_string_type type = | |
41 | node->u.load.u.string.type; | |
42 | if (type == IR_LOAD_STRING_TYPE_GLOB_STAR_END || | |
43 | type == IR_LOAD_STRING_TYPE_GLOB_STAR) { | |
a0377dfe | 44 | LTTNG_ASSERT(node->u.load.u.string.value); |
9f449915 PP |
45 | strutils_normalize_star_glob_pattern( |
46 | node->u.load.u.string.value); | |
47 | } | |
48 | } | |
49 | ||
50 | return 0; | |
51 | } | |
52 | case IR_OP_UNARY: | |
53 | return normalize_glob_patterns(node->u.unary.child); | |
54 | case IR_OP_BINARY: | |
55 | { | |
56 | int ret = normalize_glob_patterns(node->u.binary.left); | |
57 | ||
58 | if (ret) | |
59 | return ret; | |
60 | return normalize_glob_patterns(node->u.binary.right); | |
61 | } | |
62 | case IR_OP_LOGICAL: | |
63 | { | |
64 | int ret; | |
65 | ||
66 | ret = normalize_glob_patterns(node->u.logical.left); | |
67 | if (ret) | |
68 | return ret; | |
69 | return normalize_glob_patterns(node->u.logical.right); | |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | /* | |
75 | * This function normalizes all the globbing literal strings with | |
76 | * utils_normalize_glob_pattern(). See the documentation of | |
77 | * utils_normalize_glob_pattern() for more details. | |
78 | */ | |
9f449915 PP |
79 | int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx) |
80 | { | |
81 | return normalize_glob_patterns(ctx->ir_root); | |
82 | } |