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> | |
16 | #include <assert.h> | |
9f449915 PP |
17 | #include <inttypes.h> |
18 | ||
edf4b93e | 19 | #include <common/compat/errno.h> |
9f449915 PP |
20 | #include <common/macros.h> |
21 | #include <common/string-utils/string-utils.h> | |
22 | ||
23 | #include "filter-ast.h" | |
24 | #include "filter-parser.h" | |
25 | #include "filter-ir.h" | |
26 | ||
27 | static | |
28 | int normalize_glob_patterns(struct ir_op *node) | |
29 | { | |
30 | switch (node->op) { | |
31 | case IR_OP_UNKNOWN: | |
32 | default: | |
33 | fprintf(stderr, "[error] %s: unknown op type\n", __func__); | |
34 | return -EINVAL; | |
35 | ||
36 | case IR_OP_ROOT: | |
37 | return normalize_glob_patterns(node->u.root.child); | |
38 | case IR_OP_LOAD: | |
39 | { | |
40 | if (node->data_type == IR_DATA_STRING) { | |
41 | enum ir_load_string_type type = | |
42 | node->u.load.u.string.type; | |
43 | if (type == IR_LOAD_STRING_TYPE_GLOB_STAR_END || | |
44 | type == IR_LOAD_STRING_TYPE_GLOB_STAR) { | |
45 | assert(node->u.load.u.string.value); | |
46 | strutils_normalize_star_glob_pattern( | |
47 | node->u.load.u.string.value); | |
48 | } | |
49 | } | |
50 | ||
51 | return 0; | |
52 | } | |
53 | case IR_OP_UNARY: | |
54 | return normalize_glob_patterns(node->u.unary.child); | |
55 | case IR_OP_BINARY: | |
56 | { | |
57 | int ret = normalize_glob_patterns(node->u.binary.left); | |
58 | ||
59 | if (ret) | |
60 | return ret; | |
61 | return normalize_glob_patterns(node->u.binary.right); | |
62 | } | |
63 | case IR_OP_LOGICAL: | |
64 | { | |
65 | int ret; | |
66 | ||
67 | ret = normalize_glob_patterns(node->u.logical.left); | |
68 | if (ret) | |
69 | return ret; | |
70 | return normalize_glob_patterns(node->u.logical.right); | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | /* | |
76 | * This function normalizes all the globbing literal strings with | |
77 | * utils_normalize_glob_pattern(). See the documentation of | |
78 | * utils_normalize_glob_pattern() for more details. | |
79 | */ | |
80 | LTTNG_HIDDEN | |
81 | int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx) | |
82 | { | |
83 | return normalize_glob_patterns(ctx->ir_root); | |
84 | } |