16#ifndef OPENSSL_LHASH_H
17# define OPENSSL_LHASH_H
20# include <openssl/macros.h>
21# ifndef OPENSSL_NO_DEPRECATED_3_0
22# define HEADER_LHASH_H
25# include <openssl/e_os2.h>
26# include <openssl/bio.h>
32typedef struct lhash_node_st OPENSSL_LH_NODE;
33typedef int (*OPENSSL_LH_COMPFUNC) (
const void *,
const void *);
34typedef unsigned long (*OPENSSL_LH_HASHFUNC) (
const void *);
35typedef void (*OPENSSL_LH_DOALL_FUNC) (
void *);
36typedef void (*OPENSSL_LH_DOALL_FUNCARG) (
void *,
void *);
37typedef struct lhash_st OPENSSL_LHASH;
49# define DECLARE_LHASH_HASH_FN(name, o_type) \
50 unsigned long name##_LHASH_HASH(const void *);
51# define IMPLEMENT_LHASH_HASH_FN(name, o_type) \
52 unsigned long name##_LHASH_HASH(const void *arg) { \
53 const o_type *a = arg; \
54 return name##_hash(a); }
55# define LHASH_HASH_FN(name) name##_LHASH_HASH
58# define DECLARE_LHASH_COMP_FN(name, o_type) \
59 int name##_LHASH_COMP(const void *, const void *);
60# define IMPLEMENT_LHASH_COMP_FN(name, o_type) \
61 int name##_LHASH_COMP(const void *arg1, const void *arg2) { \
62 const o_type *a = arg1; \
63 const o_type *b = arg2; \
64 return name##_cmp(a,b); }
65# define LHASH_COMP_FN(name) name##_LHASH_COMP
68# define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
69 void name##_LHASH_DOALL_ARG(void *, void *);
70# define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \
71 void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
74 name##_doall_arg(a, b); }
75# define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG
78# define LH_LOAD_MULT 256
80int OPENSSL_LH_error(OPENSSL_LHASH *lh);
81OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c);
82void OPENSSL_LH_free(OPENSSL_LHASH *lh);
83void OPENSSL_LH_flush(OPENSSL_LHASH *lh);
84void *OPENSSL_LH_insert(OPENSSL_LHASH *lh,
void *data);
85void *OPENSSL_LH_delete(OPENSSL_LHASH *lh,
const void *data);
86void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh,
const void *data);
87void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func);
88void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func,
void *arg);
89unsigned long OPENSSL_LH_strhash(
const char *c);
90unsigned long OPENSSL_LH_num_items(
const OPENSSL_LHASH *lh);
91unsigned long OPENSSL_LH_get_down_load(
const OPENSSL_LHASH *lh);
92void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh,
unsigned long down_load);
94# ifndef OPENSSL_NO_STDIO
95void OPENSSL_LH_stats(
const OPENSSL_LHASH *lh, FILE *fp);
96void OPENSSL_LH_node_stats(
const OPENSSL_LHASH *lh, FILE *fp);
97void OPENSSL_LH_node_usage_stats(
const OPENSSL_LHASH *lh, FILE *fp);
99void OPENSSL_LH_stats_bio(
const OPENSSL_LHASH *lh, BIO *out);
100void OPENSSL_LH_node_stats_bio(
const OPENSSL_LHASH *lh, BIO *out);
101void OPENSSL_LH_node_usage_stats_bio(
const OPENSSL_LHASH *lh, BIO *out);
103# ifndef OPENSSL_NO_DEPRECATED_1_1_0
104# define _LHASH OPENSSL_LHASH
105# define LHASH_NODE OPENSSL_LH_NODE
106# define lh_error OPENSSL_LH_error
107# define lh_new OPENSSL_LH_new
108# define lh_free OPENSSL_LH_free
109# define lh_insert OPENSSL_LH_insert
110# define lh_delete OPENSSL_LH_delete
111# define lh_retrieve OPENSSL_LH_retrieve
112# define lh_doall OPENSSL_LH_doall
113# define lh_doall_arg OPENSSL_LH_doall_arg
114# define lh_strhash OPENSSL_LH_strhash
115# define lh_num_items OPENSSL_LH_num_items
116# ifndef OPENSSL_NO_STDIO
117# define lh_stats OPENSSL_LH_stats
118# define lh_node_stats OPENSSL_LH_node_stats
119# define lh_node_usage_stats OPENSSL_LH_node_usage_stats
121# define lh_stats_bio OPENSSL_LH_stats_bio
122# define lh_node_stats_bio OPENSSL_LH_node_stats_bio
123# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio
128# define LHASH_OF(type) struct lhash_st_##type
131# define DEFINE_LHASH_OF_INTERNAL(type) \
132 LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \
133 typedef int (*lh_##type##_compfunc)(const type *a, const type *b); \
134 typedef unsigned long (*lh_##type##_hashfunc)(const type *a); \
135 typedef void (*lh_##type##_doallfunc)(type *a); \
136 static ossl_unused ossl_inline type *ossl_check_##type##_lh_plain_type(type *ptr) \
140 static ossl_unused ossl_inline const type *ossl_check_const_##type##_lh_plain_type(const type *ptr) \
144 static ossl_unused ossl_inline const OPENSSL_LHASH *ossl_check_const_##type##_lh_type(const LHASH_OF(type) *lh) \
146 return (const OPENSSL_LHASH *)lh; \
148 static ossl_unused ossl_inline OPENSSL_LHASH *ossl_check_##type##_lh_type(LHASH_OF(type) *lh) \
150 return (OPENSSL_LHASH *)lh; \
152 static ossl_unused ossl_inline OPENSSL_LH_COMPFUNC ossl_check_##type##_lh_compfunc_type(lh_##type##_compfunc cmp) \
154 return (OPENSSL_LH_COMPFUNC)cmp; \
156 static ossl_unused ossl_inline OPENSSL_LH_HASHFUNC ossl_check_##type##_lh_hashfunc_type(lh_##type##_hashfunc hfn) \
158 return (OPENSSL_LH_HASHFUNC)hfn; \
160 static ossl_unused ossl_inline OPENSSL_LH_DOALL_FUNC ossl_check_##type##_lh_doallfunc_type(lh_##type##_doallfunc dfn) \
162 return (OPENSSL_LH_DOALL_FUNC)dfn; \
166# define DEFINE_LHASH_OF(type) \
167 LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \
168 static ossl_unused ossl_inline LHASH_OF(type) *lh_##type##_new(unsigned long (*hfn)(const type *), \
169 int (*cfn)(const type *, const type *)) \
171 return (LHASH_OF(type) *) \
172 OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \
174 static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \
176 OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
178 static ossl_unused ossl_inline void lh_##type##_flush(LHASH_OF(type) *lh) \
180 OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \
182 static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
184 return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \
186 static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
188 return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \
190 static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
192 return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \
194 static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \
196 return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \
198 static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \
200 return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \
202 static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
204 OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \
206 static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
208 OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \
210 static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
212 OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \
214 static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \
216 return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \
218 static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
220 OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \
222 static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \
223 void (*doall)(type *)) \
225 OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \
227 static ossl_unused ossl_inline void lh_##type##_doall_arg(LHASH_OF(type) *lh, \
228 void (*doallarg)(type *, void *), \
231 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, \
232 (OPENSSL_LH_DOALL_FUNCARG)doallarg, arg); \
236#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \
237 int_implement_lhash_doall(type, argtype, const type)
239#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \
240 int_implement_lhash_doall(type, argtype, type)
242#define int_implement_lhash_doall(type, argtype, cbargtype) \
243 static ossl_unused ossl_inline void \
244 lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \
245 void (*fn)(cbargtype *, argtype *), \
248 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \
252DEFINE_LHASH_OF_INTERNAL(OPENSSL_STRING);
253#define lh_OPENSSL_STRING_new(hfn, cmp) ((LHASH_OF(OPENSSL_STRING) *)OPENSSL_LH_new(ossl_check_OPENSSL_STRING_lh_hashfunc_type(hfn), ossl_check_OPENSSL_STRING_lh_compfunc_type(cmp)))
254#define lh_OPENSSL_STRING_free(lh) OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(lh))
255#define lh_OPENSSL_STRING_flush(lh) OPENSSL_LH_flush(ossl_check_OPENSSL_STRING_lh_type(lh))
256#define lh_OPENSSL_STRING_insert(lh, ptr) ((OPENSSL_STRING *)OPENSSL_LH_insert(ossl_check_OPENSSL_STRING_lh_type(lh), ossl_check_OPENSSL_STRING_lh_plain_type(ptr)))
257#define lh_OPENSSL_STRING_delete(lh, ptr) ((OPENSSL_STRING *)OPENSSL_LH_delete(ossl_check_OPENSSL_STRING_lh_type(lh), ossl_check_const_OPENSSL_STRING_lh_plain_type(ptr)))
258#define lh_OPENSSL_STRING_retrieve(lh, ptr) ((OPENSSL_STRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_STRING_lh_type(lh), ossl_check_const_OPENSSL_STRING_lh_plain_type(ptr)))
259#define lh_OPENSSL_STRING_error(lh) OPENSSL_LH_error(ossl_check_OPENSSL_STRING_lh_type(lh))
260#define lh_OPENSSL_STRING_num_items(lh) OPENSSL_LH_num_items(ossl_check_OPENSSL_STRING_lh_type(lh))
261#define lh_OPENSSL_STRING_node_stats_bio(lh, out) OPENSSL_LH_node_stats_bio(ossl_check_const_OPENSSL_STRING_lh_type(lh), out)
262#define lh_OPENSSL_STRING_node_usage_stats_bio(lh, out) OPENSSL_LH_node_usage_stats_bio(ossl_check_const_OPENSSL_STRING_lh_type(lh), out)
263#define lh_OPENSSL_STRING_stats_bio(lh, out) OPENSSL_LH_stats_bio(ossl_check_const_OPENSSL_STRING_lh_type(lh), out)
264#define lh_OPENSSL_STRING_get_down_load(lh) OPENSSL_LH_get_down_load(ossl_check_OPENSSL_STRING_lh_type(lh))
265#define lh_OPENSSL_STRING_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_OPENSSL_STRING_lh_type(lh), dl)
266#define lh_OPENSSL_STRING_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_OPENSSL_STRING_lh_type(lh), ossl_check_OPENSSL_STRING_lh_doallfunc_type(dfn))
267DEFINE_LHASH_OF_INTERNAL(OPENSSL_CSTRING);
268#define lh_OPENSSL_CSTRING_new(hfn, cmp) ((LHASH_OF(OPENSSL_CSTRING) *)OPENSSL_LH_new(ossl_check_OPENSSL_CSTRING_lh_hashfunc_type(hfn), ossl_check_OPENSSL_CSTRING_lh_compfunc_type(cmp)))
269#define lh_OPENSSL_CSTRING_free(lh) OPENSSL_LH_free(ossl_check_OPENSSL_CSTRING_lh_type(lh))
270#define lh_OPENSSL_CSTRING_flush(lh) OPENSSL_LH_flush(ossl_check_OPENSSL_CSTRING_lh_type(lh))
271#define lh_OPENSSL_CSTRING_insert(lh, ptr) ((OPENSSL_CSTRING *)OPENSSL_LH_insert(ossl_check_OPENSSL_CSTRING_lh_type(lh), ossl_check_OPENSSL_CSTRING_lh_plain_type(ptr)))
272#define lh_OPENSSL_CSTRING_delete(lh, ptr) ((OPENSSL_CSTRING *)OPENSSL_LH_delete(ossl_check_OPENSSL_CSTRING_lh_type(lh), ossl_check_const_OPENSSL_CSTRING_lh_plain_type(ptr)))
273#define lh_OPENSSL_CSTRING_retrieve(lh, ptr) ((OPENSSL_CSTRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_CSTRING_lh_type(lh), ossl_check_const_OPENSSL_CSTRING_lh_plain_type(ptr)))
274#define lh_OPENSSL_CSTRING_error(lh) OPENSSL_LH_error(ossl_check_OPENSSL_CSTRING_lh_type(lh))
275#define lh_OPENSSL_CSTRING_num_items(lh) OPENSSL_LH_num_items(ossl_check_OPENSSL_CSTRING_lh_type(lh))
276#define lh_OPENSSL_CSTRING_node_stats_bio(lh, out) OPENSSL_LH_node_stats_bio(ossl_check_const_OPENSSL_CSTRING_lh_type(lh), out)
277#define lh_OPENSSL_CSTRING_node_usage_stats_bio(lh, out) OPENSSL_LH_node_usage_stats_bio(ossl_check_const_OPENSSL_CSTRING_lh_type(lh), out)
278#define lh_OPENSSL_CSTRING_stats_bio(lh, out) OPENSSL_LH_stats_bio(ossl_check_const_OPENSSL_CSTRING_lh_type(lh), out)
279#define lh_OPENSSL_CSTRING_get_down_load(lh) OPENSSL_LH_get_down_load(ossl_check_OPENSSL_CSTRING_lh_type(lh))
280#define lh_OPENSSL_CSTRING_set_down_load(lh, dl) OPENSSL_LH_set_down_load(ossl_check_OPENSSL_CSTRING_lh_type(lh), dl)
281#define lh_OPENSSL_CSTRING_doall(lh, dfn) OPENSSL_LH_doall(ossl_check_OPENSSL_CSTRING_lh_type(lh), ossl_check_OPENSSL_CSTRING_lh_doallfunc_type(dfn))