]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/lhash.h.in
threads_pthread.c: change inline to ossl_inline
[thirdparty/openssl.git] / include / openssl / lhash.h.in
CommitLineData
21dcbebc 1/*
b6461792 2 * Copyright 1995-2024 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{-
11use 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
34extern "C" {
35#endif
36
739a1eb1
RS
37typedef struct lhash_node_st OPENSSL_LH_NODE;
38typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *);
5c42ced0 39typedef int (*OPENSSL_LH_COMPFUNCTHUNK) (const void *, const void *, OPENSSL_LH_COMPFUNC cfn);
739a1eb1 40typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *);
5c42ced0 41typedef unsigned long (*OPENSSL_LH_HASHFUNCTHUNK) (const void *, OPENSSL_LH_HASHFUNC hfn);
739a1eb1 42typedef void (*OPENSSL_LH_DOALL_FUNC) (void *);
5c42ced0 43typedef void (*OPENSSL_LH_DOALL_FUNC_THUNK) (void *, OPENSSL_LH_DOALL_FUNC doall);
739a1eb1 44typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *);
5c42ced0 45typedef void (*OPENSSL_LH_DOALL_FUNCARG_THUNK) (void *, void *, OPENSSL_LH_DOALL_FUNCARG doall);
739a1eb1 46typedef struct lhash_st OPENSSL_LHASH;
0f113f3e
MC
47
48/*
49 * Macros for declaring and implementing type-safe wrappers for LHASH
50 * callbacks. This way, callbacks can be provided to LHASH structures without
51 * function pointer casting and the macro-defined callbacks provide
52 * per-variable casting before deferring to the underlying type-specific
53 * callbacks. NB: It is possible to place a "static" in front of both the
54 * DECLARE and IMPLEMENT macros if the functions are strictly internal.
55 */
dfa46e50
GT
56
57/* First: "hash" functions */
0f113f3e
MC
58# define DECLARE_LHASH_HASH_FN(name, o_type) \
59 unsigned long name##_LHASH_HASH(const void *);
60# define IMPLEMENT_LHASH_HASH_FN(name, o_type) \
61 unsigned long name##_LHASH_HASH(const void *arg) { \
62 const o_type *a = arg; \
63 return name##_hash(a); }
64# define LHASH_HASH_FN(name) name##_LHASH_HASH
dfa46e50
GT
65
66/* Second: "compare" functions */
0f113f3e
MC
67# define DECLARE_LHASH_COMP_FN(name, o_type) \
68 int name##_LHASH_COMP(const void *, const void *);
69# define IMPLEMENT_LHASH_COMP_FN(name, o_type) \
70 int name##_LHASH_COMP(const void *arg1, const void *arg2) { \
71 const o_type *a = arg1; \
72 const o_type *b = arg2; \
73 return name##_cmp(a,b); }
74# define LHASH_COMP_FN(name) name##_LHASH_COMP
dfa46e50 75
18602745 76/* Fourth: "doall_arg" functions */
0f113f3e
MC
77# define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
78 void name##_LHASH_DOALL_ARG(void *, void *);
79# define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
80 void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
81 o_type *a = arg1; \
82 a_type *b = arg2; \
83 name##_doall_arg(a, b); }
84# define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG
85
0f113f3e
MC
86
87# define LH_LOAD_MULT 256
88
739a1eb1
RS
89int OPENSSL_LH_error(OPENSSL_LHASH *lh);
90OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c);
5c42ced0
NH
91OPENSSL_LHASH *OPENSSL_LH_set_thunks(OPENSSL_LHASH *lh,
92 OPENSSL_LH_HASHFUNCTHUNK hw,
93 OPENSSL_LH_COMPFUNCTHUNK cw,
94 OPENSSL_LH_DOALL_FUNC_THUNK daw,
95 OPENSSL_LH_DOALL_FUNCARG_THUNK daaw);
739a1eb1 96void OPENSSL_LH_free(OPENSSL_LHASH *lh);
1bdbdaff 97void OPENSSL_LH_flush(OPENSSL_LHASH *lh);
739a1eb1
RS
98void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data);
99void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data);
100void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data);
101void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func);
5c42ced0
NH
102void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh,
103 OPENSSL_LH_DOALL_FUNCARG func, void *arg);
104void OPENSSL_LH_doall_arg_thunk(OPENSSL_LHASH *lh,
105 OPENSSL_LH_DOALL_FUNCARG_THUNK daaw,
106 OPENSSL_LH_DOALL_FUNCARG fn, void *arg);
107
739a1eb1
RS
108unsigned long OPENSSL_LH_strhash(const char *c);
109unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh);
110unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh);
111void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load);
d02b48c6 112
474e469b 113# ifndef OPENSSL_NO_STDIO
6a92159d
TM
114# ifndef OPENSSL_NO_DEPRECATED_3_1
115OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp);
116OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp);
117OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp);
5317b6ee
HL
118# endif
119# endif
6a92159d
TM
120# ifndef OPENSSL_NO_DEPRECATED_3_1
121OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
122OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
123OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
739a1eb1 124# endif
739a1eb1 125
00db8c60 126# ifndef OPENSSL_NO_DEPRECATED_1_1_0
739a1eb1
RS
127# define _LHASH OPENSSL_LHASH
128# define LHASH_NODE OPENSSL_LH_NODE
129# define lh_error OPENSSL_LH_error
b3c42fc2 130# define lh_new OPENSSL_LH_new
739a1eb1
RS
131# define lh_free OPENSSL_LH_free
132# define lh_insert OPENSSL_LH_insert
133# define lh_delete OPENSSL_LH_delete
134# define lh_retrieve OPENSSL_LH_retrieve
135# define lh_doall OPENSSL_LH_doall
136# define lh_doall_arg OPENSSL_LH_doall_arg
137# define lh_strhash OPENSSL_LH_strhash
138# define lh_num_items OPENSSL_LH_num_items
139# ifndef OPENSSL_NO_STDIO
140# define lh_stats OPENSSL_LH_stats
141# define lh_node_stats OPENSSL_LH_node_stats
142# define lh_node_usage_stats OPENSSL_LH_node_usage_stats
143# endif
144# define lh_stats_bio OPENSSL_LH_stats_bio
145# define lh_node_stats_bio OPENSSL_LH_node_stats_bio
146# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio
474e469b 147# endif
3c1d6bbc 148
220903f9 149/* Type checking... */
3c1d6bbc 150
0f113f3e 151# define LHASH_OF(type) struct lhash_st_##type
3c1d6bbc 152
726b3293
MC
153/* Helper macro for internal use */
154# define DEFINE_LHASH_OF_INTERNAL(type) \
5317b6ee
HL
155 LHASH_OF(type) { \
156 union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \
157 }; \
726b3293
MC
158 typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \
159 typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \
160 typedef void (*lh_##type##_doallfunc)(type *a); \
5c42ced0
NH
161 static ossl_inline unsigned long lh_##type##_hash_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \
162 { \
163 unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \
164 return hfn_conv((const type *)data); \
165 } \
166 static ossl_inline int lh_##type##_comp_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \
167 { \
168 int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \
169 return cfn_conv((const type *)da, (const type *)db); \
170 } \
171 static ossl_inline void lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \
172 { \
173 void (*doall_conv)(type *) = (void (*)(type *))doall; \
174 doall_conv((type *)node); \
175 } \
176 static ossl_inline void lh_##type##_doall_arg_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG doall) \
177 { \
178 void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \
179 doall_conv((type *)node, arg); \
180 } \
5317b6ee
HL
181 static ossl_unused ossl_inline type *\
182 ossl_check_##type##_lh_plain_type(type *ptr) \
726b3293
MC
183 { \
184 return ptr; \
185 } \
5317b6ee
HL
186 static ossl_unused ossl_inline const type * \
187 ossl_check_const_##type##_lh_plain_type(const type *ptr) \
726b3293
MC
188 { \
189 return ptr; \
190 } \
5317b6ee
HL
191 static ossl_unused ossl_inline const OPENSSL_LHASH * \
192 ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \
726b3293
MC
193 { \
194 return (const OPENSSL_LHASH *)lh; \
195 } \
5317b6ee
HL
196 static ossl_unused ossl_inline OPENSSL_LHASH * \
197 ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \
726b3293
MC
198 { \
199 return (OPENSSL_LHASH *)lh; \
200 } \
5317b6ee
HL
201 static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC \
202 ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \
726b3293
MC
203 { \
204 return (OPENSSL_LH_COMPFUNC)cmp; \
205 } \
5317b6ee
HL
206 static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC \
207 ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \
726b3293
MC
208 { \
209 return (OPENSSL_LH_HASHFUNC)hfn; \
210 } \
5317b6ee
HL
211 static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC \
212 ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \
726b3293
MC
213 { \
214 return (OPENSSL_LH_DOALL_FUNC)dfn; \
215 } \
216 LHASH_OF(type)
217
6a92159d 218# ifndef OPENSSL_NO_DEPRECATED_3_1
5317b6ee
HL
219# define DEFINE_LHASH_OF_DEPRECATED(type) \
220 static ossl_unused ossl_inline void \
221 lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
222 { \
223 OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \
224 } \
225 static ossl_unused ossl_inline void \
226 lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
227 { \
228 OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \
229 } \
230 static ossl_unused ossl_inline void \
231 lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
232 { \
233 OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \
234 }
235# else
236# define DEFINE_LHASH_OF_DEPRECATED(type)
237# endif
238
239# define DEFINE_LHASH_OF_EX(type) \
240 LHASH_OF(type) { \
241 union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \
242 }; \
5c42ced0
NH
243 static unsigned long \
244 lh_##type##_hfn_thunk(const void *data, OPENSSL_LH_HASHFUNC hfn) \
62d0577e 245 { \
5c42ced0
NH
246 unsigned long (*hfn_conv)(const type *) = (unsigned long (*)(const type *))hfn; \
247 return hfn_conv((const type *)data); \
248 } \
249 static int lh_##type##_cfn_thunk(const void *da, const void *db, OPENSSL_LH_COMPFUNC cfn) \
250 { \
251 int (*cfn_conv)(const type *, const type *) = (int (*)(const type *, const type *))cfn; \
252 return cfn_conv((const type *)da, (const type *)db); \
62d0577e 253 } \
5317b6ee
HL
254 static ossl_unused ossl_inline void \
255 lh_##type##_free(LHASH_OF(type) *lh) \
e6b5c341 256 { \
739a1eb1 257 OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
e6b5c341 258 } \
5317b6ee
HL
259 static ossl_unused ossl_inline void \
260 lh_##type##_flush(LHASH_OF(type) *lh) \
1bdbdaff
P
261 { \
262 OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \
263 } \
5317b6ee
HL
264 static ossl_unused ossl_inline type * \
265 lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
e6b5c341 266 { \
739a1eb1 267 return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \
e6b5c341 268 } \
5317b6ee
HL
269 static ossl_unused ossl_inline type * \
270 lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
e6b5c341 271 { \
739a1eb1 272 return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \
e6b5c341 273 } \
5317b6ee
HL
274 static ossl_unused ossl_inline type * \
275 lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
e6b5c341 276 { \
739a1eb1 277 return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \
e6b5c341 278 } \
5317b6ee
HL
279 static ossl_unused ossl_inline int \
280 lh_##type##_error(LHASH_OF(type) *lh) \
e6b5c341 281 { \
739a1eb1 282 return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \
e6b5c341 283 } \
5317b6ee
HL
284 static ossl_unused ossl_inline unsigned long \
285 lh_##type##_num_items(LHASH_OF(type) *lh) \
e6b5c341 286 { \
739a1eb1 287 return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \
e6b5c341 288 } \
5317b6ee
HL
289 static ossl_unused ossl_inline unsigned long \
290 lh_##type##_get_down_load(LHASH_OF(type) *lh) \
e6b5c341 291 { \
739a1eb1 292 return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \
e6b5c341 293 } \
5317b6ee
HL
294 static ossl_unused ossl_inline void \
295 lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
e6b5c341 296 { \
739a1eb1 297 OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \
e6b5c341 298 } \
5317b6ee 299 static ossl_unused ossl_inline void \
5c42ced0
NH
300 lh_##type##_doall_thunk(void *node, OPENSSL_LH_DOALL_FUNC doall) \
301 { \
302 void (*doall_conv)(type *) = (void (*)(type *))doall; \
303 doall_conv((type *)node); \
304 } \
305 static ossl_unused ossl_inline void \
306 lh_##type##_doall_arg_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG doall) \
307 { \
308 void (*doall_conv)(type *, void *) = (void (*)(type *, void *))doall; \
309 doall_conv((type *)node, arg); \
310 } \
311 static ossl_unused ossl_inline void \
5317b6ee 312 lh_##type##_doall(LHASH_OF(type) *lh, void (*doall)(type *)) \
63c75cd6 313 { \
739a1eb1 314 OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \
63c75cd6 315 } \
5c42ced0
NH
316 static ossl_unused ossl_inline LHASH_OF(type) * \
317 lh_##type##_new(unsigned long (*hfn)(const type *), \
318 int (*cfn)(const type *, const type *)) \
319 { \
320 return (LHASH_OF(type) *)OPENSSL_LH_set_thunks(OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn), \
321 lh_##type##_hfn_thunk, lh_##type##_cfn_thunk, \
322 lh_##type##_doall_thunk, \
323 lh_##type##_doall_arg_thunk); \
324 } \
5317b6ee
HL
325 static ossl_unused ossl_inline void \
326 lh_##type##_doall_arg(LHASH_OF(type) *lh, \
327 void (*doallarg)(type *, void *), void *arg) \
e2ed740e
MC
328 { \
329 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \
330 (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \
331 } \
e6b5c341 332 LHASH_OF(type)
3c1d6bbc 333
5317b6ee
HL
334# define DEFINE_LHASH_OF(type) \
335 DEFINE_LHASH_OF_EX(type); \
336 DEFINE_LHASH_OF_DEPRECATED(type) \
337 LHASH_OF(type)
338
2a056de8
DSH
339#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \
340 int_implement_lhash_doall(type, argtype, const type)
341
342#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \
343 int_implement_lhash_doall(type, argtype, type)
344
345#define int_implement_lhash_doall(type, argtype, cbargtype) \
5c42ced0
NH
346 static ossl_unused ossl_inline void \
347 lh_##type##_doall_##argtype##_thunk(void *node, void *arg, OPENSSL_LH_DOALL_FUNCARG fn) \
348 { \
349 void (*fn_conv)(cbargtype *, argtype *) = (void (*)(cbargtype *, argtype *))fn; \
350 fn_conv((cbargtype *)node, (argtype *)arg); \
351 } \
48fe4ce1 352 static ossl_unused ossl_inline void \
2a056de8
DSH
353 lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \
354 void (*fn)(cbargtype *, argtype *), \
355 argtype *arg) \
356 { \
5c42ced0
NH
357 OPENSSL_LH_doall_arg_thunk((OPENSSL_LHASH *)lh, \
358 lh_##type##_doall_##argtype##_thunk, \
359 (OPENSSL_LH_DOALL_FUNCARG)fn, \
360 (void *)arg); \
2a056de8
DSH
361 } \
362 LHASH_OF(type)
363
e82f4598
MC
364{-
365 generate_lhash_macros("OPENSSL_STRING")
366 .generate_lhash_macros("OPENSSL_CSTRING");
367-}
05004f36 368
d02b48c6
RE
369#ifdef __cplusplus
370}
371#endif
372
373#endif