Debian Codegraph @

runtime/lookup.h

raw
1 /* header for lookup.c
2 *
3 * Copyright 2013-2023 Adiscon GmbH.
4 *
5 * This file is part of the rsyslog runtime library.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * -or-
13 * see COPYING.ASL20 in the source distribution
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21 #ifndef INCLUDED_LOOKUP_H
22 #define INCLUDED_LOOKUP_H
23 #include <libestr.h>
24 #include <regex.h>
25
26 #define STRING_LOOKUP_TABLE 1
27 #define ARRAY_LOOKUP_TABLE 2
28 #define SPARSE_ARRAY_LOOKUP_TABLE 3
29 #define STUBBED_LOOKUP_TABLE 4
30 #define REGEX_LOOKUP_TABLE 5
31
32 #define LOOKUP_KEY_TYPE_STRING 1
33 #define LOOKUP_KEY_TYPE_UINT 2
34 #define LOOKUP_KEY_TYPE_NONE 3
35
36 struct lookup_tables_s {
37 lookup_ref_t *root; /* the root of the template list */
38 lookup_ref_t *last; /* points to the last element of the template list */
39 };
40
41 struct lookup_array_tab_s {
42 uint32_t first_key;
43 uchar **interned_val_refs;
44 };
45
46 struct lookup_sparseArray_tab_entry_s {
47 uint32_t key;
48 uchar *interned_val_ref;
49 };
50
51 struct lookup_sparseArray_tab_s {
52 lookup_sparseArray_tab_entry_t *entries;
53 };
54
55 struct lookup_string_tab_entry_s {
56 uchar *key;
57 uchar *interned_val_ref;
58 };
59
60 struct lookup_string_tab_s {
61 lookup_string_tab_entry_t *entries;
62 };
63
64 struct lookup_regex_tab_entry_s {
65 regex_t regex;
66 uchar *regex_str;
67 uchar *interned_val_ref;
68 uint8_t is_compiled;
69 };
70
71 struct lookup_regex_tab_s {
72 lookup_regex_tab_entry_t *entries;
73 };
74
75 struct lookup_ref_s {
76 pthread_rwlock_t rwlock; /* protect us in case of dynamic reloads */
77 uchar *name;
78 uchar *filename;
79 lookup_t *self;
80 lookup_ref_t *next;
81 /* reload specific attributes */
82 pthread_mutex_t reloader_mut; /* signaling + access to reload-flow variables*/
83 /* rwlock(above) may be acquired inside critical-section reloader_mut guards */
84 pthread_cond_t run_reloader;
85 pthread_t reloader;
86 pthread_attr_t reloader_thd_attr;
87 uchar *stub_value_for_reload_failure;
88 uint8_t do_reload;
89 uint8_t do_stop;
90 uint8_t reload_on_hup;
91 };
92
93 typedef es_str_t *(lookup_fn_t)(lookup_t *, lookup_key_t);
94
95 /* a single lookup table */
96 struct lookup_s {
97 uint32_t nmemb;
98 uint8_t type;
99 uint8_t key_type;
100 union {
101 lookup_string_tab_t *str;
102 lookup_array_tab_t *arr;
103 lookup_sparseArray_tab_t *sprsArr;
104 lookup_regex_tab_t *regex;
105 } table;
106 uint32_t interned_val_count;
107 uchar **interned_vals;
108 uchar *nomatch;
109 lookup_fn_t *lookup;
110 };
111
112 union lookup_key_u {
113 uchar *k_str;
114 uint32_t k_uint;
115 };
116
117 /* prototypes */
118 void lookupInitCnf(lookup_tables_t *lu_tabs);
119 rsRetVal lookupTableDefProcessCnf(struct cnfobj *o);
120 lookup_ref_t *lookupFindTable(uchar *name);
121 es_str_t *lookupKey(lookup_ref_t *pThis, lookup_key_t key);
122 void lookupDestroyCnf(void);
123 void lookupClassExit(void);
124 void lookupDoHUP(void);
125 rsRetVal lookupReload(lookup_ref_t *pThis, const uchar *stub_value_if_reload_fails);
126 uint lookupPendingReloadCount(void);
127 rsRetVal lookupClassInit(void);
128 void lookupActivateConf(void);
129
130 #endif /* #ifndef INCLUDED_LOOKUP_H */