]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/lhash.h
Fix header file include guard names
[thirdparty/openssl.git] / include / openssl / lhash.h
CommitLineData
21dcbebc 1/*
6638b221 2 * Copyright 1995-2019 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
0f113f3e
MC
10/*
11 * Header for dynamic hash table routines Author - Eric Young
d02b48c6
RE
12 */
13
ae4186b0
DMSP
14#ifndef OPENSSL_LHASH_H
15# define OPENSSL_LHASH_H
d02b48c6 16
0f113f3e 17# include <openssl/e_os2.h>
a00ae6c4 18# include <openssl/bio.h>
ef33b970 19
82271cee
RL
20#ifdef __cplusplus
21extern "C" {
22#endif
23
739a1eb1
RS
24typedef struct lhash_node_st OPENSSL_LH_NODE;
25typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *);
26typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *);
27typedef void (*OPENSSL_LH_DOALL_FUNC) (void *);
28typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *);
29typedef 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
72int OPENSSL_LH_error(OPENSSL_LHASH *lh);
73OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c);
74void OPENSSL_LH_free(OPENSSL_LHASH *lh);
1bdbdaff 75void OPENSSL_LH_flush(OPENSSL_LHASH *lh);
739a1eb1
RS
76void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data);
77void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data);
78void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data);
79void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func);
80void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg);
81unsigned long OPENSSL_LH_strhash(const char *c);
82unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh);
83unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh);
84void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load);
d02b48c6 85
474e469b 86# ifndef OPENSSL_NO_STDIO
739a1eb1
RS
87void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp);
88void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp);
89void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp);
90# endif
91void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
92void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
93void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
94
fcd2d5a6 95# if !OPENSSL_API_1_1_0
739a1eb1
RS
96# define _LHASH OPENSSL_LHASH
97# define LHASH_NODE OPENSSL_LH_NODE
98# define lh_error OPENSSL_LH_error
b3c42fc2 99# define lh_new OPENSSL_LH_new
739a1eb1
RS
100# define lh_free OPENSSL_LH_free
101# define lh_insert OPENSSL_LH_insert
102# define lh_delete OPENSSL_LH_delete
103# define lh_retrieve OPENSSL_LH_retrieve
104# define lh_doall OPENSSL_LH_doall
105# define lh_doall_arg OPENSSL_LH_doall_arg
106# define lh_strhash OPENSSL_LH_strhash
107# define lh_num_items OPENSSL_LH_num_items
108# ifndef OPENSSL_NO_STDIO
109# define lh_stats OPENSSL_LH_stats
110# define lh_node_stats OPENSSL_LH_node_stats
111# define lh_node_usage_stats OPENSSL_LH_node_usage_stats
112# endif
113# define lh_stats_bio OPENSSL_LH_stats_bio
114# define lh_node_stats_bio OPENSSL_LH_node_stats_bio
115# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio
474e469b 116# endif
3c1d6bbc 117
220903f9 118/* Type checking... */
3c1d6bbc 119
0f113f3e 120# define LHASH_OF(type) struct lhash_st_##type
3c1d6bbc 121
89d6aa10 122# define DEFINE_LHASH_OF(type) \
703f44e7 123 LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \
89d6aa10 124 static ossl_inline LHASH_OF(type) * \
62d0577e
DSH
125 lh_##type##_new(unsigned long (*hfn)(const type *), \
126 int (*cfn)(const type *, const type *)) \
127 { \
128 return (LHASH_OF(type) *) \
739a1eb1 129 OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \
62d0577e 130 } \
48fe4ce1 131 static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \
e6b5c341 132 { \
739a1eb1 133 OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
e6b5c341 134 } \
1bdbdaff
P
135 static ossl_unused ossl_inline void lh_##type##_flush(LHASH_OF(type) *lh) \
136 { \
137 OPENSSL_LH_flush((OPENSSL_LHASH *)lh); \
138 } \
48fe4ce1 139 static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
e6b5c341 140 { \
739a1eb1 141 return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \
e6b5c341 142 } \
48fe4ce1 143 static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
e6b5c341 144 { \
739a1eb1 145 return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \
e6b5c341 146 } \
48fe4ce1 147 static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
e6b5c341 148 { \
739a1eb1 149 return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \
e6b5c341 150 } \
48fe4ce1 151 static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \
e6b5c341 152 { \
739a1eb1 153 return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \
e6b5c341 154 } \
48fe4ce1 155 static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \
e6b5c341 156 { \
739a1eb1 157 return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \
e6b5c341 158 } \
48fe4ce1 159 static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
e6b5c341 160 { \
4591e5fb 161 OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \
e6b5c341 162 } \
48fe4ce1 163 static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
e6b5c341 164 { \
4591e5fb 165 OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \
e6b5c341 166 } \
48fe4ce1 167 static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
e6b5c341 168 { \
4591e5fb 169 OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \
e6b5c341 170 } \
48fe4ce1 171 static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \
e6b5c341 172 { \
739a1eb1 173 return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \
e6b5c341 174 } \
48fe4ce1 175 static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
e6b5c341 176 { \
739a1eb1 177 OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \
e6b5c341 178 } \
48fe4ce1
RL
179 static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \
180 void (*doall)(type *)) \
63c75cd6 181 { \
739a1eb1 182 OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \
63c75cd6 183 } \
e6b5c341 184 LHASH_OF(type)
3c1d6bbc 185
2a056de8
DSH
186#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \
187 int_implement_lhash_doall(type, argtype, const type)
188
189#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \
190 int_implement_lhash_doall(type, argtype, type)
191
192#define int_implement_lhash_doall(type, argtype, cbargtype) \
48fe4ce1 193 static ossl_unused ossl_inline void \
2a056de8
DSH
194 lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \
195 void (*fn)(cbargtype *, argtype *), \
196 argtype *arg) \
197 { \
739a1eb1 198 OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \
2a056de8
DSH
199 } \
200 LHASH_OF(type)
201
89d6aa10 202DEFINE_LHASH_OF(OPENSSL_STRING);
05004f36
RS
203# ifdef _MSC_VER
204/*
205 * push and pop this warning:
206 * warning C4090: 'function': different 'const' qualifiers
207 */
208# pragma warning (push)
209# pragma warning (disable: 4090)
210# endif
211
89d6aa10 212DEFINE_LHASH_OF(OPENSSL_CSTRING);
3c1d6bbc 213
05004f36
RS
214# ifdef _MSC_VER
215# pragma warning (pop)
216# endif
217
6638b221
MK
218/*
219 * If called without higher optimization (min. -xO3) the Oracle Developer
220 * Studio compiler generates code for the defined (static inline) functions
221 * above.
222 * This would later lead to the linker complaining about missing symbols when
223 * this header file is included but the resulting object is not linked against
224 * the Crypto library (openssl#6912).
225 */
226# ifdef __SUNPRO_C
227# pragma weak OPENSSL_LH_new
228# pragma weak OPENSSL_LH_free
229# pragma weak OPENSSL_LH_insert
230# pragma weak OPENSSL_LH_delete
231# pragma weak OPENSSL_LH_retrieve
232# pragma weak OPENSSL_LH_error
233# pragma weak OPENSSL_LH_num_items
234# pragma weak OPENSSL_LH_node_stats_bio
235# pragma weak OPENSSL_LH_node_usage_stats_bio
236# pragma weak OPENSSL_LH_stats_bio
237# pragma weak OPENSSL_LH_get_down_load
238# pragma weak OPENSSL_LH_set_down_load
239# pragma weak OPENSSL_LH_doall
240# pragma weak OPENSSL_LH_doall_arg
241# endif /* __SUNPRO_C */
242
d02b48c6
RE
243#ifdef __cplusplus
244}
245#endif
246
247#endif