diff options
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.h')
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.h | 92 |
1 files changed, 71 insertions, 21 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h index b8ff021906..dee8207333 100644 --- a/src/lib/libcrypto/lhash/lhash.h +++ b/src/lib/libcrypto/lhash/lhash.h | |||
@@ -63,11 +63,11 @@ | |||
63 | #ifndef HEADER_LHASH_H | 63 | #ifndef HEADER_LHASH_H |
64 | #define HEADER_LHASH_H | 64 | #define HEADER_LHASH_H |
65 | 65 | ||
66 | #ifndef NO_FP_API | 66 | #ifndef OPENSSL_NO_FP_API |
67 | #include <stdio.h> | 67 | #include <stdio.h> |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | #ifndef NO_BIO | 70 | #ifndef OPENSSL_NO_BIO |
71 | #include <openssl/bio.h> | 71 | #include <openssl/bio.h> |
72 | #endif | 72 | #endif |
73 | 73 | ||
@@ -77,18 +77,68 @@ extern "C" { | |||
77 | 77 | ||
78 | typedef struct lhash_node_st | 78 | typedef struct lhash_node_st |
79 | { | 79 | { |
80 | void *data; | 80 | const void *data; |
81 | struct lhash_node_st *next; | 81 | struct lhash_node_st *next; |
82 | #ifndef NO_HASH_COMP | 82 | #ifndef OPENSSL_NO_HASH_COMP |
83 | unsigned long hash; | 83 | unsigned long hash; |
84 | #endif | 84 | #endif |
85 | } LHASH_NODE; | 85 | } LHASH_NODE; |
86 | 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 | |||
87 | typedef struct lhash_st | 137 | typedef struct lhash_st |
88 | { | 138 | { |
89 | LHASH_NODE **b; | 139 | LHASH_NODE **b; |
90 | int (*comp)(); | 140 | LHASH_COMP_FN_TYPE comp; |
91 | unsigned long (*hash)(); | 141 | LHASH_HASH_FN_TYPE hash; |
92 | unsigned int num_nodes; | 142 | unsigned int num_nodes; |
93 | unsigned int num_alloc_nodes; | 143 | unsigned int num_alloc_nodes; |
94 | unsigned int p; | 144 | unsigned int p; |
@@ -120,26 +170,26 @@ typedef struct lhash_st | |||
120 | * in lh_insert(). */ | 170 | * in lh_insert(). */ |
121 | #define lh_error(lh) ((lh)->error) | 171 | #define lh_error(lh) ((lh)->error) |
122 | 172 | ||
123 | LHASH *lh_new(unsigned long (*h)(/* void *a */), int (*c)(/* void *a,void *b */)); | 173 | LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c); |
124 | void lh_free(LHASH *lh); | 174 | void lh_free(LHASH *lh); |
125 | void *lh_insert(LHASH *lh, void *data); | 175 | void *lh_insert(LHASH *lh, const void *data); |
126 | void *lh_delete(LHASH *lh, void *data); | 176 | void *lh_delete(LHASH *lh, const void *data); |
127 | void *lh_retrieve(LHASH *lh, void *data); | 177 | void *lh_retrieve(LHASH *lh, const void *data); |
128 | void lh_doall(LHASH *lh, void (*func)(/*void *b*/)); | 178 | void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func); |
129 | void lh_doall_arg(LHASH *lh, void (*func)(/*void *a,void *b*/),void *arg); | 179 | void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg); |
130 | unsigned long lh_strhash(const char *c); | 180 | unsigned long lh_strhash(const char *c); |
131 | unsigned long lh_num_items(LHASH *lh); | 181 | unsigned long lh_num_items(const LHASH *lh); |
132 | 182 | ||
133 | #ifndef NO_FP_API | 183 | #ifndef OPENSSL_NO_FP_API |
134 | void lh_stats(LHASH *lh, FILE *out); | 184 | void lh_stats(const LHASH *lh, FILE *out); |
135 | void lh_node_stats(LHASH *lh, FILE *out); | 185 | void lh_node_stats(const LHASH *lh, FILE *out); |
136 | void lh_node_usage_stats(LHASH *lh, FILE *out); | 186 | void lh_node_usage_stats(const LHASH *lh, FILE *out); |
137 | #endif | 187 | #endif |
138 | 188 | ||
139 | #ifndef NO_BIO | 189 | #ifndef OPENSSL_NO_BIO |
140 | void lh_stats_bio(LHASH *lh, BIO *out); | 190 | void lh_stats_bio(const LHASH *lh, BIO *out); |
141 | void lh_node_stats_bio(LHASH *lh, BIO *out); | 191 | void lh_node_stats_bio(const LHASH *lh, BIO *out); |
142 | void lh_node_usage_stats_bio(LHASH *lh, BIO *out); | 192 | void lh_node_usage_stats_bio(const LHASH *lh, BIO *out); |
143 | #endif | 193 | #endif |
144 | #ifdef __cplusplus | 194 | #ifdef __cplusplus |
145 | } | 195 | } |