summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/lhash/lhash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.h')
-rw-r--r--src/lib/libcrypto/lhash/lhash.h92
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
78typedef struct lhash_node_st 78typedef 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
87typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
88typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
89typedef void (*LHASH_DOALL_FN_TYPE)(const void *);
90typedef 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
87typedef struct lhash_st 137typedef 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
123LHASH *lh_new(unsigned long (*h)(/* void *a */), int (*c)(/* void *a,void *b */)); 173LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
124void lh_free(LHASH *lh); 174void lh_free(LHASH *lh);
125void *lh_insert(LHASH *lh, void *data); 175void *lh_insert(LHASH *lh, const void *data);
126void *lh_delete(LHASH *lh, void *data); 176void *lh_delete(LHASH *lh, const void *data);
127void *lh_retrieve(LHASH *lh, void *data); 177void *lh_retrieve(LHASH *lh, const void *data);
128 void lh_doall(LHASH *lh, void (*func)(/*void *b*/)); 178void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
129void lh_doall_arg(LHASH *lh, void (*func)(/*void *a,void *b*/),void *arg); 179void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
130unsigned long lh_strhash(const char *c); 180unsigned long lh_strhash(const char *c);
131unsigned long lh_num_items(LHASH *lh); 181unsigned long lh_num_items(const LHASH *lh);
132 182
133#ifndef NO_FP_API 183#ifndef OPENSSL_NO_FP_API
134void lh_stats(LHASH *lh, FILE *out); 184void lh_stats(const LHASH *lh, FILE *out);
135void lh_node_stats(LHASH *lh, FILE *out); 185void lh_node_stats(const LHASH *lh, FILE *out);
136void lh_node_usage_stats(LHASH *lh, FILE *out); 186void lh_node_usage_stats(const LHASH *lh, FILE *out);
137#endif 187#endif
138 188
139#ifndef NO_BIO 189#ifndef OPENSSL_NO_BIO
140void lh_stats_bio(LHASH *lh, BIO *out); 190void lh_stats_bio(const LHASH *lh, BIO *out);
141void lh_node_stats_bio(LHASH *lh, BIO *out); 191void lh_node_stats_bio(const LHASH *lh, BIO *out);
142void lh_node_usage_stats_bio(LHASH *lh, BIO *out); 192void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
143#endif 193#endif
144#ifdef __cplusplus 194#ifdef __cplusplus
145} 195}