]>
Commit | Line | Data |
---|---|---|
21dcbebc | 1 | /* |
d4f4fcab | 2 | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
0f113f3e | 3 | * |
21dcbebc RS |
4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
0f113f3e MC |
10 | /* |
11 | * Header for dynamic hash table routines Author - Eric Young | |
d02b48c6 RE |
12 | */ |
13 | ||
14 | #ifndef HEADER_LHASH_H | |
0f113f3e | 15 | # define HEADER_LHASH_H |
d02b48c6 | 16 | |
0f113f3e | 17 | # include <openssl/e_os2.h> |
a00ae6c4 | 18 | # include <openssl/bio.h> |
ef33b970 | 19 | |
82271cee RL |
20 | #ifdef __cplusplus |
21 | extern "C" { | |
22 | #endif | |
23 | ||
739a1eb1 RS |
24 | typedef struct lhash_node_st OPENSSL_LH_NODE; |
25 | typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *); | |
26 | typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *); | |
27 | typedef void (*OPENSSL_LH_DOALL_FUNC) (void *); | |
28 | typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *); | |
29 | typedef struct lhash_st OPENSSL_LHASH; | |
0f113f3e MC |
30 | |
31 | /* | |
32 | * Macros for declaring and implementing type-safe wrappers for LHASH | |
33 | * callbacks. This way, callbacks can be provided to LHASH structures without | |
34 | * function pointer casting and the macro-defined callbacks provide | |
35 | * per-variable casting before deferring to the underlying type-specific | |
36 | * callbacks. NB: It is possible to place a "static" in front of both the | |
37 | * DECLARE and IMPLEMENT macros if the functions are strictly internal. | |
38 | */ | |
dfa46e50 GT |
39 | |
40 | /* First: "hash" functions */ | |
0f113f3e MC |
41 | # define DECLARE_LHASH_HASH_FN(name, o_type) \ |
42 | unsigned long name##_LHASH_HASH(const void *); | |
43 | # define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ | |
44 | unsigned long name##_LHASH_HASH(const void *arg) { \ | |
45 | const o_type *a = arg; \ | |
46 | return name##_hash(a); } | |
47 | # define LHASH_HASH_FN(name) name##_LHASH_HASH | |
dfa46e50 GT |
48 | |
49 | /* Second: "compare" functions */ | |
0f113f3e MC |
50 | # define DECLARE_LHASH_COMP_FN(name, o_type) \ |
51 | int name##_LHASH_COMP(const void *, const void *); | |
52 | # define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ | |
53 | int name##_LHASH_COMP(const void *arg1, const void *arg2) { \ | |
54 | const o_type *a = arg1; \ | |
55 | const o_type *b = arg2; \ | |
56 | return name##_cmp(a,b); } | |
57 | # define LHASH_COMP_FN(name) name##_LHASH_COMP | |
dfa46e50 | 58 | |
18602745 | 59 | /* Fourth: "doall_arg" functions */ |
0f113f3e MC |
60 | # define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ |
61 | void name##_LHASH_DOALL_ARG(void *, void *); | |
62 | # define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ | |
63 | void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ | |
64 | o_type *a = arg1; \ | |
65 | a_type *b = arg2; \ | |
66 | name##_doall_arg(a, b); } | |
67 | # define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG | |
68 | ||
0f113f3e MC |
69 | |
70 | # define LH_LOAD_MULT 256 | |
71 | ||
739a1eb1 RS |
72 | int OPENSSL_LH_error(OPENSSL_LHASH *lh); |
73 | OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); | |
74 | void OPENSSL_LH_free(OPENSSL_LHASH *lh); | |
75 | void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); | |
76 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); | |
77 | void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); | |
78 | void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); | |
79 | void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg); | |
80 | unsigned long OPENSSL_LH_strhash(const char *c); | |
81 | unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh); | |
82 | unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh); | |
83 | void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load); | |
d02b48c6 | 84 | |
474e469b | 85 | # ifndef OPENSSL_NO_STDIO |
739a1eb1 RS |
86 | void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp); |
87 | void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp); | |
88 | void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp); | |
89 | # endif | |
90 | void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
91 | void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
92 | void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
93 | ||
94 | # if OPENSSL_API_COMPAT < 0x10100000L | |
95 | # define _LHASH OPENSSL_LHASH | |
96 | # define LHASH_NODE OPENSSL_LH_NODE | |
97 | # define lh_error OPENSSL_LH_error | |
b3c42fc2 | 98 | # define lh_new OPENSSL_LH_new |
739a1eb1 RS |
99 | # define lh_free OPENSSL_LH_free |
100 | # define lh_insert OPENSSL_LH_insert | |
101 | # define lh_delete OPENSSL_LH_delete | |
102 | # define lh_retrieve OPENSSL_LH_retrieve | |
103 | # define lh_doall OPENSSL_LH_doall | |
104 | # define lh_doall_arg OPENSSL_LH_doall_arg | |
105 | # define lh_strhash OPENSSL_LH_strhash | |
106 | # define lh_num_items OPENSSL_LH_num_items | |
107 | # ifndef OPENSSL_NO_STDIO | |
108 | # define lh_stats OPENSSL_LH_stats | |
109 | # define lh_node_stats OPENSSL_LH_node_stats | |
110 | # define lh_node_usage_stats OPENSSL_LH_node_usage_stats | |
111 | # endif | |
112 | # define lh_stats_bio OPENSSL_LH_stats_bio | |
113 | # define lh_node_stats_bio OPENSSL_LH_node_stats_bio | |
114 | # define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio | |
474e469b | 115 | # endif |
3c1d6bbc | 116 | |
220903f9 | 117 | /* Type checking... */ |
3c1d6bbc | 118 | |
0f113f3e | 119 | # define LHASH_OF(type) struct lhash_st_##type |
3c1d6bbc | 120 | |
89d6aa10 | 121 | # define DEFINE_LHASH_OF(type) \ |
703f44e7 | 122 | LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ |
b04c8c06 DG |
123 | static ossl_unused ossl_inline LHASH_OF(type) *lh_##type##_new(unsigned long (*hfn)(const type *), \ |
124 | int (*cfn)(const type *, const type *)) \ | |
62d0577e DSH |
125 | { \ |
126 | return (LHASH_OF(type) *) \ | |
739a1eb1 | 127 | OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \ |
62d0577e | 128 | } \ |
ed48d203 | 129 | static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \ |
e6b5c341 | 130 | { \ |
739a1eb1 | 131 | OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 132 | } \ |
ed48d203 | 133 | static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ |
e6b5c341 | 134 | { \ |
739a1eb1 | 135 | return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 136 | } \ |
ed48d203 | 137 | static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ |
e6b5c341 | 138 | { \ |
739a1eb1 | 139 | return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 140 | } \ |
ed48d203 | 141 | static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ |
e6b5c341 | 142 | { \ |
739a1eb1 | 143 | return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 144 | } \ |
ed48d203 | 145 | static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \ |
e6b5c341 | 146 | { \ |
739a1eb1 | 147 | return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 148 | } \ |
ed48d203 | 149 | static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \ |
e6b5c341 | 150 | { \ |
739a1eb1 | 151 | return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 152 | } \ |
ed48d203 | 153 | static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 154 | { \ |
4591e5fb | 155 | OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 156 | } \ |
ed48d203 | 157 | static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 158 | { \ |
4591e5fb | 159 | OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 160 | } \ |
ed48d203 | 161 | static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 162 | { \ |
4591e5fb | 163 | OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 164 | } \ |
ed48d203 | 165 | static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \ |
e6b5c341 | 166 | { \ |
739a1eb1 | 167 | return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 168 | } \ |
ed48d203 | 169 | static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ |
e6b5c341 | 170 | { \ |
739a1eb1 | 171 | OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ |
e6b5c341 | 172 | } \ |
ed48d203 RL |
173 | static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \ |
174 | void (*doall)(type *)) \ | |
63c75cd6 | 175 | { \ |
739a1eb1 | 176 | OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ |
63c75cd6 | 177 | } \ |
e6b5c341 | 178 | LHASH_OF(type) |
3c1d6bbc | 179 | |
2a056de8 DSH |
180 | #define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \ |
181 | int_implement_lhash_doall(type, argtype, const type) | |
182 | ||
183 | #define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \ | |
184 | int_implement_lhash_doall(type, argtype, type) | |
185 | ||
186 | #define int_implement_lhash_doall(type, argtype, cbargtype) \ | |
ed48d203 | 187 | static ossl_unused ossl_inline void \ |
2a056de8 DSH |
188 | lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ |
189 | void (*fn)(cbargtype *, argtype *), \ | |
190 | argtype *arg) \ | |
191 | { \ | |
739a1eb1 | 192 | OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \ |
2a056de8 DSH |
193 | } \ |
194 | LHASH_OF(type) | |
195 | ||
89d6aa10 | 196 | DEFINE_LHASH_OF(OPENSSL_STRING); |
05004f36 RS |
197 | # ifdef _MSC_VER |
198 | /* | |
199 | * push and pop this warning: | |
200 | * warning C4090: 'function': different 'const' qualifiers | |
201 | */ | |
202 | # pragma warning (push) | |
203 | # pragma warning (disable: 4090) | |
204 | # endif | |
205 | ||
89d6aa10 | 206 | DEFINE_LHASH_OF(OPENSSL_CSTRING); |
3c1d6bbc | 207 | |
05004f36 RS |
208 | # ifdef _MSC_VER |
209 | # pragma warning (pop) | |
210 | # endif | |
211 | ||
d4f4fcab MK |
212 | /* |
213 | * If called without higher optimization (min. -xO3) the Oracle Developer | |
214 | * Studio compiler generates code for the defined (static inline) functions | |
215 | * above. | |
216 | * This would later lead to the linker complaining about missing symbols when | |
217 | * this header file is included but the resulting object is not linked against | |
218 | * the Crypto library (openssl#6912). | |
219 | */ | |
220 | # ifdef __SUNPRO_C | |
221 | # pragma weak OPENSSL_LH_new | |
222 | # pragma weak OPENSSL_LH_free | |
223 | # pragma weak OPENSSL_LH_insert | |
224 | # pragma weak OPENSSL_LH_delete | |
225 | # pragma weak OPENSSL_LH_retrieve | |
226 | # pragma weak OPENSSL_LH_error | |
227 | # pragma weak OPENSSL_LH_num_items | |
228 | # pragma weak OPENSSL_LH_node_stats_bio | |
229 | # pragma weak OPENSSL_LH_node_usage_stats_bio | |
230 | # pragma weak OPENSSL_LH_stats_bio | |
231 | # pragma weak OPENSSL_LH_get_down_load | |
232 | # pragma weak OPENSSL_LH_set_down_load | |
233 | # pragma weak OPENSSL_LH_doall | |
234 | # pragma weak OPENSSL_LH_doall_arg | |
235 | # endif /* __SUNPRO_C */ | |
236 | ||
d02b48c6 RE |
237 | #ifdef __cplusplus |
238 | } | |
239 | #endif | |
240 | ||
241 | #endif |