1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*  Fluent Bit
4  *  ==========
5  *  Copyright (C) 2019-2021 The Fluent Bit Authors
6  *  Copyright (C) 2015-2018 Treasure Data Inc.
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  */
20 
21 #ifndef FLB_FILTER_MODIFY_H
22 #define FLB_FILTER_MODIFY_H
23 
24 #include <fluent-bit/flb_info.h>
25 #include <fluent-bit/flb_filter.h>
26 #include <fluent-bit/flb_record_accessor.h>
27 #include <fluent-bit/flb_sds.h>
28 
29 enum FLB_FILTER_MODIFY_RULETYPE {
30   RENAME,
31   HARD_RENAME,
32   ADD,
33   SET,
34   REMOVE,
35   REMOVE_WILDCARD,
36   REMOVE_REGEX,
37   COPY,
38   HARD_COPY
39 };
40 
41 enum FLB_FILTER_MODIFY_CONDITIONTYPE {
42   KEY_EXISTS,
43   KEY_DOES_NOT_EXIST,
44   A_KEY_MATCHES,
45   NO_KEY_MATCHES,
46   KEY_VALUE_EQUALS,
47   KEY_VALUE_DOES_NOT_EQUAL,
48   KEY_VALUE_MATCHES,
49   KEY_VALUE_DOES_NOT_MATCH,
50   MATCHING_KEYS_HAVE_MATCHING_VALUES,
51   MATCHING_KEYS_DO_NOT_HAVE_MATCHING_VALUES
52 };
53 
54 struct filter_modify_ctx
55 {
56     int rules_cnt;
57     struct mk_list rules;
58     int conditions_cnt;
59     struct mk_list conditions;
60     struct flb_filter_instance *ins;
61 };
62 
63 struct modify_rule
64 {
65     enum FLB_FILTER_MODIFY_RULETYPE ruletype;
66     int key_len;
67     int val_len;
68     char *key;
69     char *val;
70     bool key_is_regex;
71     bool val_is_regex;
72     struct flb_regex *key_regex;
73     struct flb_regex *val_regex;
74     char *raw_k;
75     char *raw_v;
76     struct mk_list _head;
77 };
78 
79 struct modify_condition
80 {
81     enum FLB_FILTER_MODIFY_CONDITIONTYPE conditiontype;
82     int a_len;
83     int b_len;
84     flb_sds_t a;
85     char *b;
86     bool a_is_regex;
87     bool b_is_regex;
88     struct flb_regex *a_regex;
89     struct flb_regex *b_regex;
90     struct flb_record_accessor *ra_a;
91     char *raw_k;
92     char *raw_v;
93     struct mk_list _head;
94 };
95 #endif
96