diff options
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.h')
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.h | 126 |
1 files changed, 85 insertions, 41 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h index 70cbc6dfe7..dee8207333 100644 --- a/src/lib/libcrypto/lhash/lhash.h +++ b/src/lib/libcrypto/lhash/lhash.h | |||
@@ -63,24 +63,82 @@ | |||
63 | #ifndef HEADER_LHASH_H | 63 | #ifndef HEADER_LHASH_H |
64 | #define HEADER_LHASH_H | 64 | #define HEADER_LHASH_H |
65 | 65 | ||
66 | #ifndef OPENSSL_NO_FP_API | ||
67 | #include <stdio.h> | ||
68 | #endif | ||
69 | |||
70 | #ifndef OPENSSL_NO_BIO | ||
71 | #include <openssl/bio.h> | ||
72 | #endif | ||
73 | |||
66 | #ifdef __cplusplus | 74 | #ifdef __cplusplus |
67 | extern "C" { | 75 | extern "C" { |
68 | #endif | 76 | #endif |
69 | 77 | ||
70 | typedef struct lhash_node_st | 78 | typedef struct lhash_node_st |
71 | { | 79 | { |
72 | char *data; | 80 | const void *data; |
73 | struct lhash_node_st *next; | 81 | struct lhash_node_st *next; |
74 | #ifndef NO_HASH_COMP | 82 | #ifndef OPENSSL_NO_HASH_COMP |
75 | unsigned long hash; | 83 | unsigned long hash; |
76 | #endif | 84 | #endif |
77 | } LHASH_NODE; | 85 | } LHASH_NODE; |
78 | 86 | ||
87 | typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); | ||
88 | typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); | ||
89 | typedef void (*LHASH_DOALL_FN_TYPE)(const void *); | ||
90 | typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, void *); | ||
91 | |||
92 | /* Macros for declaring and implementing type-safe wrappers for LHASH callbacks. | ||
93 | * This way, callbacks can be provided to LHASH structures without function | ||
94 | * pointer casting and the macro-defined callbacks provide per-variable casting | ||
95 | * before deferring to the underlying type-specific callbacks. NB: It is | ||
96 | * possible to place a "static" in front of both the DECLARE and IMPLEMENT | ||
97 | * macros if the functions are strictly internal. */ | ||
98 | |||
99 | /* First: "hash" functions */ | ||
100 | #define DECLARE_LHASH_HASH_FN(f_name,o_type) \ | ||
101 | unsigned long f_name##_LHASH_HASH(const void *); | ||
102 | #define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \ | ||
103 | unsigned long f_name##_LHASH_HASH(const void *arg) { \ | ||
104 | o_type a = (o_type)arg; \ | ||
105 | return f_name(a); } | ||
106 | #define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH | ||
107 | |||
108 | /* Second: "compare" functions */ | ||
109 | #define DECLARE_LHASH_COMP_FN(f_name,o_type) \ | ||
110 | int f_name##_LHASH_COMP(const void *, const void *); | ||
111 | #define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \ | ||
112 | int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \ | ||
113 | o_type a = (o_type)arg1; \ | ||
114 | o_type b = (o_type)arg2; \ | ||
115 | return f_name(a,b); } | ||
116 | #define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP | ||
117 | |||
118 | /* Third: "doall" functions */ | ||
119 | #define DECLARE_LHASH_DOALL_FN(f_name,o_type) \ | ||
120 | void f_name##_LHASH_DOALL(const void *); | ||
121 | #define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \ | ||
122 | void f_name##_LHASH_DOALL(const void *arg) { \ | ||
123 | o_type a = (o_type)arg; \ | ||
124 | f_name(a); } | ||
125 | #define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL | ||
126 | |||
127 | /* Fourth: "doall_arg" functions */ | ||
128 | #define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ | ||
129 | void f_name##_LHASH_DOALL_ARG(const void *, void *); | ||
130 | #define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ | ||
131 | void f_name##_LHASH_DOALL_ARG(const void *arg1, void *arg2) { \ | ||
132 | o_type a = (o_type)arg1; \ | ||
133 | a_type b = (a_type)arg2; \ | ||
134 | f_name(a,b); } | ||
135 | #define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG | ||
136 | |||
79 | typedef struct lhash_st | 137 | typedef struct lhash_st |
80 | { | 138 | { |
81 | LHASH_NODE **b; | 139 | LHASH_NODE **b; |
82 | int (*comp)(); | 140 | LHASH_COMP_FN_TYPE comp; |
83 | unsigned long (*hash)(); | 141 | LHASH_HASH_FN_TYPE hash; |
84 | unsigned int num_nodes; | 142 | unsigned int num_nodes; |
85 | unsigned int num_alloc_nodes; | 143 | unsigned int num_alloc_nodes; |
86 | unsigned int p; | 144 | unsigned int p; |
@@ -102,51 +160,37 @@ typedef struct lhash_st | |||
102 | unsigned long num_retrieve; | 160 | unsigned long num_retrieve; |
103 | unsigned long num_retrieve_miss; | 161 | unsigned long num_retrieve_miss; |
104 | unsigned long num_hash_comps; | 162 | unsigned long num_hash_comps; |
163 | |||
164 | int error; | ||
105 | } LHASH; | 165 | } LHASH; |
106 | 166 | ||
107 | #define LH_LOAD_MULT 256 | 167 | #define LH_LOAD_MULT 256 |
108 | 168 | ||
109 | #ifndef NOPROTO | 169 | /* Indicates a malloc() error in the last call, this is only bad |
110 | LHASH *lh_new(unsigned long (*h)(), int (*c)()); | 170 | * in lh_insert(). */ |
171 | #define lh_error(lh) ((lh)->error) | ||
172 | |||
173 | LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c); | ||
111 | void lh_free(LHASH *lh); | 174 | void lh_free(LHASH *lh); |
112 | char *lh_insert(LHASH *lh, char *data); | 175 | void *lh_insert(LHASH *lh, const void *data); |
113 | char *lh_delete(LHASH *lh, char *data); | 176 | void *lh_delete(LHASH *lh, const void *data); |
114 | char *lh_retrieve(LHASH *lh, char *data); | 177 | void *lh_retrieve(LHASH *lh, const void *data); |
115 | void lh_doall(LHASH *lh, void (*func)(/* char *b */)); | 178 | void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func); |
116 | void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg); | 179 | void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg); |
117 | unsigned long lh_strhash(char *c); | 180 | unsigned long lh_strhash(const char *c); |
118 | 181 | unsigned long lh_num_items(const LHASH *lh); | |
119 | #ifndef NO_FP_API | ||
120 | void lh_stats(LHASH *lh, FILE *out); | ||
121 | void lh_node_stats(LHASH *lh, FILE *out); | ||
122 | void lh_node_usage_stats(LHASH *lh, FILE *out); | ||
123 | #endif | ||
124 | 182 | ||
125 | #ifdef HEADER_BIO_H | 183 | #ifndef OPENSSL_NO_FP_API |
126 | void lh_stats_bio(LHASH *lh, BIO *out); | 184 | void lh_stats(const LHASH *lh, FILE *out); |
127 | void lh_node_stats_bio(LHASH *lh, BIO *out); | 185 | void lh_node_stats(const LHASH *lh, FILE *out); |
128 | void lh_node_usage_stats_bio(LHASH *lh, BIO *out); | 186 | void lh_node_usage_stats(const LHASH *lh, FILE *out); |
129 | #endif | ||
130 | #else | ||
131 | LHASH *lh_new(); | ||
132 | void lh_free(); | ||
133 | char *lh_insert(); | ||
134 | char *lh_delete(); | ||
135 | char *lh_retrieve(); | ||
136 | void lh_doall(); | ||
137 | void lh_doall_arg(); | ||
138 | unsigned long lh_strhash(); | ||
139 | |||
140 | #ifndef NO_FP_API | ||
141 | void lh_stats(); | ||
142 | void lh_node_stats(); | ||
143 | void lh_node_usage_stats(); | ||
144 | #endif | ||
145 | void lh_stats_bio(); | ||
146 | void lh_node_stats_bio(); | ||
147 | void lh_node_usage_stats_bio(); | ||
148 | #endif | 187 | #endif |
149 | 188 | ||
189 | #ifndef OPENSSL_NO_BIO | ||
190 | void lh_stats_bio(const LHASH *lh, BIO *out); | ||
191 | void lh_node_stats_bio(const LHASH *lh, BIO *out); | ||
192 | void lh_node_usage_stats_bio(const LHASH *lh, BIO *out); | ||
193 | #endif | ||
150 | #ifdef __cplusplus | 194 | #ifdef __cplusplus |
151 | } | 195 | } |
152 | #endif | 196 | #endif |