]>
Commit | Line | Data |
---|---|---|
21dcbebc | 1 | /* |
0789c7d8 | 2 | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
0f113f3e | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | ||
e82f4598 MC |
10 | {- |
11 | use OpenSSL::stackhash qw(generate_lhash_macros); | |
12 | -} | |
13 | ||
0f113f3e MC |
14 | /* |
15 | * Header for dynamic hash table routines Author - Eric Young | |
d02b48c6 RE |
16 | */ |
17 | ||
ae4186b0 DMSP |
18 | #ifndef OPENSSL_LHASH_H |
19 | # define OPENSSL_LHASH_H | |
d86167ec DMSP |
20 | # pragma once |
21 | ||
22 | # include <openssl/macros.h> | |
936c2b9e | 23 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d86167ec DMSP |
24 | # define HEADER_LHASH_H |
25 | # endif | |
d02b48c6 | 26 | |
0f113f3e | 27 | # include <openssl/e_os2.h> |
a00ae6c4 | 28 | # include <openssl/bio.h> |
eab9dbbd NS |
29 | # ifndef OPENSSL_NO_STDIO |
30 | # include <stdio.h> | |
31 | # endif | |
ef33b970 | 32 | |
82271cee RL |
33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
739a1eb1 RS |
37 | typedef struct lhash_node_st OPENSSL_LH_NODE; |
38 | typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *); | |
39 | typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *); | |
40 | typedef void (*OPENSSL_LH_DOALL_FUNC) (void *); | |
41 | typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *); | |
42 | typedef struct lhash_st OPENSSL_LHASH; | |
0f113f3e MC |
43 | |
44 | /* | |
45 | * Macros for declaring and implementing type-safe wrappers for LHASH | |
46 | * callbacks. This way, callbacks can be provided to LHASH structures without | |
47 | * function pointer casting and the macro-defined callbacks provide | |
48 | * per-variable casting before deferring to the underlying type-specific | |
49 | * callbacks. NB: It is possible to place a "static" in front of both the | |
50 | * DECLARE and IMPLEMENT macros if the functions are strictly internal. | |
51 | */ | |
dfa46e50 GT |
52 | |
53 | /* First: "hash" functions */ | |
0f113f3e MC |
54 | # define DECLARE_LHASH_HASH_FN(name, o_type) \ |
55 | unsigned long name##_LHASH_HASH(const void *); | |
56 | # define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ | |
57 | unsigned long name##_LHASH_HASH(const void *arg) { \ | |
58 | const o_type *a = arg; \ | |
59 | return name##_hash(a); } | |
60 | # define LHASH_HASH_FN(name) name##_LHASH_HASH | |
dfa46e50 GT |
61 | |
62 | /* Second: "compare" functions */ | |
0f113f3e MC |
63 | # define DECLARE_LHASH_COMP_FN(name, o_type) \ |
64 | int name##_LHASH_COMP(const void *, const void *); | |
65 | # define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ | |
66 | int name##_LHASH_COMP(const void *arg1, const void *arg2) { \ | |
67 | const o_type *a = arg1; \ | |
68 | const o_type *b = arg2; \ | |
69 | return name##_cmp(a,b); } | |
70 | # define LHASH_COMP_FN(name) name##_LHASH_COMP | |
dfa46e50 | 71 | |
18602745 | 72 | /* Fourth: "doall_arg" functions */ |
0f113f3e MC |
73 | # define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ |
74 | void name##_LHASH_DOALL_ARG(void *, void *); | |
75 | # define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ | |
76 | void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ | |
77 | o_type *a = arg1; \ | |
78 | a_type *b = arg2; \ | |
79 | name##_doall_arg(a, b); } | |
80 | # define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG | |
81 | ||
0f113f3e MC |
82 | |
83 | # define LH_LOAD_MULT 256 | |
84 | ||
739a1eb1 RS |
85 | int OPENSSL_LH_error(OPENSSL_LHASH *lh); |
86 | OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); | |
87 | void OPENSSL_LH_free(OPENSSL_LHASH *lh); | |
1bdbdaff | 88 | void OPENSSL_LH_flush(OPENSSL_LHASH *lh); |
739a1eb1 RS |
89 | void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); |
90 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); | |
91 | void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); | |
92 | void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); | |
93 | void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg); | |
94 | unsigned long OPENSSL_LH_strhash(const char *c); | |
95 | unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh); | |
96 | unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh); | |
97 | void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load); | |
d02b48c6 | 98 | |
474e469b | 99 | # ifndef OPENSSL_NO_STDIO |
739a1eb1 RS |
100 | void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp); |
101 | void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp); | |
102 | void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp); | |
103 | # endif | |
104 | void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
105 | void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
106 | void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); | |
107 | ||
00db8c60 | 108 | # ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
739a1eb1 RS |
109 | # define _LHASH OPENSSL_LHASH |
110 | # define LHASH_NODE OPENSSL_LH_NODE | |
111 | # define lh_error OPENSSL_LH_error | |
b3c42fc2 | 112 | # define lh_new OPENSSL_LH_new |
739a1eb1 RS |
113 | # define lh_free OPENSSL_LH_free |
114 | # define lh_insert OPENSSL_LH_insert | |
115 | # define lh_delete OPENSSL_LH_delete | |
116 | # define lh_retrieve OPENSSL_LH_retrieve | |
117 | # define lh_doall OPENSSL_LH_doall | |
118 | # define lh_doall_arg OPENSSL_LH_doall_arg | |
119 | # define lh_strhash OPENSSL_LH_strhash | |
120 | # define lh_num_items OPENSSL_LH_num_items | |
121 | # ifndef OPENSSL_NO_STDIO | |
122 | # define lh_stats OPENSSL_LH_stats | |
123 | # define lh_node_stats OPENSSL_LH_node_stats | |
124 | # define lh_node_usage_stats OPENSSL_LH_node_usage_stats | |
125 | # endif | |
126 | # define lh_stats_bio OPENSSL_LH_stats_bio | |
127 | # define lh_node_stats_bio OPENSSL_LH_node_stats_bio | |
128 | # define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio | |
474e469b | 129 | # endif |
3c1d6bbc | 130 | |
220903f9 | 131 | /* Type checking... */ |
3c1d6bbc | 132 | |
0f113f3e | 133 | # define LHASH_OF(type) struct lhash_st_##type |
3c1d6bbc | 134 | |
726b3293 MC |
135 | /* Helper macro for internal use */ |
136 | # define DEFINE_LHASH_OF_INTERNAL(type) \ | |
137 | LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ | |
138 | typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \ | |
139 | typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \ | |
140 | typedef void (*lh_##type##_doallfunc)(type *a); \ | |
141 | static ossl_unused ossl_inline type *ossl_check_##type##_lh_plain_type(type *ptr) \ | |
142 | { \ | |
143 | return ptr; \ | |
144 | } \ | |
145 | static ossl_unused ossl_inline const type *ossl_check_const_##type##_lh_plain_type(const type *ptr) \ | |
146 | { \ | |
147 | return ptr; \ | |
148 | } \ | |
149 | static ossl_unused ossl_inline const OPENSSL_LHASH *ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \ | |
150 | { \ | |
151 | return (const OPENSSL_LHASH *)lh; \ | |
152 | } \ | |
153 | static ossl_unused ossl_inline OPENSSL_LHASH *ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \ | |
154 | { \ | |
155 | return (OPENSSL_LHASH *)lh; \ | |
156 | } \ | |
157 | static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \ | |
158 | { \ | |
159 | return (OPENSSL_LH_COMPFUNC)cmp; \ | |
160 | } \ | |
161 | static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \ | |
162 | { \ | |
163 | return (OPENSSL_LH_HASHFUNC)hfn; \ | |
164 | } \ | |
165 | static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \ | |
166 | { \ | |
167 | return (OPENSSL_LH_DOALL_FUNC)dfn; \ | |
168 | } \ | |
169 | LHASH_OF(type) | |
170 | ||
89d6aa10 | 171 | # define DEFINE_LHASH_OF(type) \ |
703f44e7 | 172 | LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ |
7b6a7467 DG |
173 | static ossl_unused ossl_inline LHASH_OF(type) *lh_##type##_new(unsigned long (*hfn)(const type *), \ |
174 | int (*cfn)(const type *, const type *)) \ | |
62d0577e DSH |
175 | { \ |
176 | return (LHASH_OF(type) *) \ | |
739a1eb1 | 177 | OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \ |
62d0577e | 178 | } \ |
48fe4ce1 | 179 | static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \ |
e6b5c341 | 180 | { \ |
739a1eb1 | 181 | OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 182 | } \ |
1bdbdaff P |
183 | static ossl_unused ossl_inline void lh_##type##_flush(LHASH_OF(type) *lh) \ |
184 | { \ | |
185 | OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \ | |
186 | } \ | |
48fe4ce1 | 187 | static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ |
e6b5c341 | 188 | { \ |
739a1eb1 | 189 | return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 190 | } \ |
48fe4ce1 | 191 | static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ |
e6b5c341 | 192 | { \ |
739a1eb1 | 193 | return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 194 | } \ |
48fe4ce1 | 195 | static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ |
e6b5c341 | 196 | { \ |
739a1eb1 | 197 | return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ |
e6b5c341 | 198 | } \ |
48fe4ce1 | 199 | static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \ |
e6b5c341 | 200 | { \ |
739a1eb1 | 201 | return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 202 | } \ |
48fe4ce1 | 203 | static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \ |
e6b5c341 | 204 | { \ |
739a1eb1 | 205 | return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 206 | } \ |
48fe4ce1 | 207 | static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 208 | { \ |
4591e5fb | 209 | OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 210 | } \ |
48fe4ce1 | 211 | static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 212 | { \ |
4591e5fb | 213 | OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 214 | } \ |
48fe4ce1 | 215 | static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ |
e6b5c341 | 216 | { \ |
4591e5fb | 217 | OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ |
e6b5c341 | 218 | } \ |
48fe4ce1 | 219 | static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \ |
e6b5c341 | 220 | { \ |
739a1eb1 | 221 | return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ |
e6b5c341 | 222 | } \ |
48fe4ce1 | 223 | static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ |
e6b5c341 | 224 | { \ |
739a1eb1 | 225 | OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ |
e6b5c341 | 226 | } \ |
48fe4ce1 RL |
227 | static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \ |
228 | void (*doall)(type *)) \ | |
63c75cd6 | 229 | { \ |
739a1eb1 | 230 | OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ |
63c75cd6 | 231 | } \ |
e2ed740e MC |
232 | static ossl_unused ossl_inline void lh_##type##_doall_arg(LHASH_OF(type) *lh, \ |
233 | void (*doallarg)(type *, void *), \ | |
234 | void *arg) \ | |
235 | { \ | |
236 | OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \ | |
237 | (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \ | |
238 | } \ | |
e6b5c341 | 239 | LHASH_OF(type) |
3c1d6bbc | 240 | |
2a056de8 DSH |
241 | #define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \ |
242 | int_implement_lhash_doall(type, argtype, const type) | |
243 | ||
244 | #define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \ | |
245 | int_implement_lhash_doall(type, argtype, type) | |
246 | ||
247 | #define int_implement_lhash_doall(type, argtype, cbargtype) \ | |
48fe4ce1 | 248 | static ossl_unused ossl_inline void \ |
2a056de8 DSH |
249 | lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ |
250 | void (*fn)(cbargtype *, argtype *), \ | |
251 | argtype *arg) \ | |
252 | { \ | |
739a1eb1 | 253 | OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \ |
2a056de8 DSH |
254 | } \ |
255 | LHASH_OF(type) | |
256 | ||
e82f4598 MC |
257 | {- |
258 | generate_lhash_macros("OPENSSL_STRING") | |
259 | .generate_lhash_macros("OPENSSL_CSTRING"); | |
260 | -} | |
05004f36 | 261 | |
d02b48c6 RE |
262 | #ifdef __cplusplus |
263 | } | |
264 | #endif | |
265 | ||
266 | #endif |