]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/lhash.h.in
Add deprecation macro for 3.1 and deprecate OPENSSL_LH_stats
[thirdparty/openssl.git] / include / openssl / lhash.h.in
CommitLineData
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{-
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 *);
39typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *);
40typedef void (*OPENSSL_LH_DOALL_FUNC) (void *);
41typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *);
42typedef 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
85int OPENSSL_LH_error(OPENSSL_LHASH *lh);
86OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c);
87void OPENSSL_LH_free(OPENSSL_LHASH *lh);
1bdbdaff 88void OPENSSL_LH_flush(OPENSSL_LHASH *lh);
739a1eb1
RS
89void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data);
90void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data);
91void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data);
92void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func);
93void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg);
94unsigned long OPENSSL_LH_strhash(const char *c);
95unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh);
96unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh);
97void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load);
d02b48c6 98
474e469b 99# ifndef OPENSSL_NO_STDIO
5317b6ee
HL
100# ifndef OPENSSL_NO_DEPRECATED_3_1
101OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp);
102OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp);
103OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp);
104# endif
105# endif
106# ifndef OPENSSL_NO_DEPRECATED_3_1
107OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
108OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
109OSSL_DEPRECATEDIN_3_1 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
739a1eb1 110# endif
739a1eb1 111
00db8c60 112# ifndef OPENSSL_NO_DEPRECATED_1_1_0
739a1eb1
RS
113# define _LHASH OPENSSL_LHASH
114# define LHASH_NODE OPENSSL_LH_NODE
115# define lh_error OPENSSL_LH_error
b3c42fc2 116# define lh_new OPENSSL_LH_new
739a1eb1
RS
117# define lh_free OPENSSL_LH_free
118# define lh_insert OPENSSL_LH_insert
119# define lh_delete OPENSSL_LH_delete
120# define lh_retrieve OPENSSL_LH_retrieve
121# define lh_doall OPENSSL_LH_doall
122# define lh_doall_arg OPENSSL_LH_doall_arg
123# define lh_strhash OPENSSL_LH_strhash
124# define lh_num_items OPENSSL_LH_num_items
125# ifndef OPENSSL_NO_STDIO
126# define lh_stats OPENSSL_LH_stats
127# define lh_node_stats OPENSSL_LH_node_stats
128# define lh_node_usage_stats OPENSSL_LH_node_usage_stats
129# endif
130# define lh_stats_bio OPENSSL_LH_stats_bio
131# define lh_node_stats_bio OPENSSL_LH_node_stats_bio
132# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio
474e469b 133# endif
3c1d6bbc 134
220903f9 135/* Type checking... */
3c1d6bbc 136
0f113f3e 137# define LHASH_OF(type) struct lhash_st_##type
3c1d6bbc 138
726b3293
MC
139/* Helper macro for internal use */
140# define DEFINE_LHASH_OF_INTERNAL(type) \
5317b6ee
HL
141 LHASH_OF(type) { \
142 union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \
143 }; \
726b3293
MC
144 typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \
145 typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \
146 typedef void (*lh_##type##_doallfunc)(type *a); \
5317b6ee
HL
147 static ossl_unused ossl_inline type *\
148 ossl_check_##type##_lh_plain_type(type *ptr) \
726b3293
MC
149 { \
150 return ptr; \
151 } \
5317b6ee
HL
152 static ossl_unused ossl_inline const type * \
153 ossl_check_const_##type##_lh_plain_type(const type *ptr) \
726b3293
MC
154 { \
155 return ptr; \
156 } \
5317b6ee
HL
157 static ossl_unused ossl_inline const OPENSSL_LHASH * \
158 ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \
726b3293
MC
159 { \
160 return (const OPENSSL_LHASH *)lh; \
161 } \
5317b6ee
HL
162 static ossl_unused ossl_inline OPENSSL_LHASH * \
163 ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \
726b3293
MC
164 { \
165 return (OPENSSL_LHASH *)lh; \
166 } \
5317b6ee
HL
167 static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC \
168 ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \
726b3293
MC
169 { \
170 return (OPENSSL_LH_COMPFUNC)cmp; \
171 } \
5317b6ee
HL
172 static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC \
173 ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \
726b3293
MC
174 { \
175 return (OPENSSL_LH_HASHFUNC)hfn; \
176 } \
5317b6ee
HL
177 static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC \
178 ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \
726b3293
MC
179 { \
180 return (OPENSSL_LH_DOALL_FUNC)dfn; \
181 } \
182 LHASH_OF(type)
183
5317b6ee
HL
184# ifndef OPENSSL_NO_DEPRECATED_3_1
185# define DEFINE_LHASH_OF_DEPRECATED(type) \
186 static ossl_unused ossl_inline void \
187 lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
188 { \
189 OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \
190 } \
191 static ossl_unused ossl_inline void \
192 lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
193 { \
194 OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \
195 } \
196 static ossl_unused ossl_inline void \
197 lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
198 { \
199 OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \
200 }
201# else
202# define DEFINE_LHASH_OF_DEPRECATED(type)
203# endif
204
205# define DEFINE_LHASH_OF_EX(type) \
206 LHASH_OF(type) { \
207 union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; \
208 }; \
209 static ossl_unused ossl_inline LHASH_OF(type) * \
210 lh_##type##_new(unsigned long (*hfn)(const type *), \
211 int (*cfn)(const type *, const type *)) \
62d0577e
DSH
212 { \
213 return (LHASH_OF(type) *) \
739a1eb1 214 OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \
62d0577e 215 } \
5317b6ee
HL
216 static ossl_unused ossl_inline void \
217 lh_##type##_free(LHASH_OF(type) *lh) \
e6b5c341 218 { \
739a1eb1 219 OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
e6b5c341 220 } \
5317b6ee
HL
221 static ossl_unused ossl_inline void \
222 lh_##type##_flush(LHASH_OF(type) *lh) \
1bdbdaff
P
223 { \
224 OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \
225 } \
5317b6ee
HL
226 static ossl_unused ossl_inline type * \
227 lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
e6b5c341 228 { \
739a1eb1 229 return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \
e6b5c341 230 } \
5317b6ee
HL
231 static ossl_unused ossl_inline type * \
232 lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
e6b5c341 233 { \
739a1eb1 234 return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \
e6b5c341 235 } \
5317b6ee
HL
236 static ossl_unused ossl_inline type * \
237 lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
e6b5c341 238 { \
739a1eb1 239 return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \
e6b5c341 240 } \
5317b6ee
HL
241 static ossl_unused ossl_inline int \
242 lh_##type##_error(LHASH_OF(type) *lh) \
e6b5c341 243 { \
739a1eb1 244 return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \
e6b5c341 245 } \
5317b6ee
HL
246 static ossl_unused ossl_inline unsigned long \
247 lh_##type##_num_items(LHASH_OF(type) *lh) \
e6b5c341 248 { \
739a1eb1 249 return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \
e6b5c341 250 } \
5317b6ee
HL
251 static ossl_unused ossl_inline unsigned long \
252 lh_##type##_get_down_load(LHASH_OF(type) *lh) \
e6b5c341 253 { \
739a1eb1 254 return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \
e6b5c341 255 } \
5317b6ee
HL
256 static ossl_unused ossl_inline void \
257 lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
e6b5c341 258 { \
739a1eb1 259 OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \
e6b5c341 260 } \
5317b6ee
HL
261 static ossl_unused ossl_inline void \
262 lh_##type##_doall(LHASH_OF(type) *lh, void (*doall)(type *)) \
63c75cd6 263 { \
739a1eb1 264 OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \
63c75cd6 265 } \
5317b6ee
HL
266 static ossl_unused ossl_inline void \
267 lh_##type##_doall_arg(LHASH_OF(type) *lh, \
268 void (*doallarg)(type *, void *), void *arg) \
e2ed740e
MC
269 { \
270 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \
271 (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \
272 } \
e6b5c341 273 LHASH_OF(type)
3c1d6bbc 274
5317b6ee
HL
275# define DEFINE_LHASH_OF(type) \
276 DEFINE_LHASH_OF_EX(type); \
277 DEFINE_LHASH_OF_DEPRECATED(type) \
278 LHASH_OF(type)
279
2a056de8
DSH
280#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \
281 int_implement_lhash_doall(type, argtype, const type)
282
283#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \
284 int_implement_lhash_doall(type, argtype, type)
285
286#define int_implement_lhash_doall(type, argtype, cbargtype) \
48fe4ce1 287 static ossl_unused ossl_inline void \
2a056de8
DSH
288 lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \
289 void (*fn)(cbargtype *, argtype *), \
290 argtype *arg) \
291 { \
5317b6ee
HL
292 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \
293 (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \
2a056de8
DSH
294 } \
295 LHASH_OF(type)
296
e82f4598
MC
297{-
298 generate_lhash_macros("OPENSSL_STRING")
299 .generate_lhash_macros("OPENSSL_CSTRING");
300-}
05004f36 301
d02b48c6
RE
302#ifdef __cplusplus
303}
304#endif
305
306#endif