diff options
Diffstat (limited to 'src/lib/libcrypto/lhash')
-rw-r--r-- | src/lib/libcrypto/lhash/Makefile.ssl | 17 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lh_stats.c | 22 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lh_test.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.c | 63 | ||||
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.h | 92 |
5 files changed, 127 insertions, 68 deletions
diff --git a/src/lib/libcrypto/lhash/Makefile.ssl b/src/lib/libcrypto/lhash/Makefile.ssl index 79849d7d6e..1eef09f3fa 100644 --- a/src/lib/libcrypto/lhash/Makefile.ssl +++ b/src/lib/libcrypto/lhash/Makefile.ssl | |||
@@ -11,7 +11,8 @@ INSTALL_PREFIX= | |||
11 | OPENSSLDIR= /usr/local/ssl | 11 | OPENSSLDIR= /usr/local/ssl |
12 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
13 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) | 14 | MAKEDEPPROG= makedepend |
15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
15 | MAKEFILE= Makefile.ssl | 16 | MAKEFILE= Makefile.ssl |
16 | AR= ar r | 17 | AR= ar r |
17 | 18 | ||
@@ -39,8 +40,7 @@ all: lib | |||
39 | 40 | ||
40 | lib: $(LIBOBJ) | 41 | lib: $(LIBOBJ) |
41 | $(AR) $(LIB) $(LIBOBJ) | 42 | $(AR) $(LIB) $(LIBOBJ) |
42 | @echo You may get an error following this line. Please ignore. | 43 | $(RANLIB) $(LIB) || echo Never mind. |
43 | - $(RANLIB) $(LIB) | ||
44 | @touch lib | 44 | @touch lib |
45 | 45 | ||
46 | files: | 46 | files: |
@@ -79,14 +79,15 @@ clean: | |||
79 | 79 | ||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 80 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
81 | 81 | ||
82 | lh_stats.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 82 | lh_stats.o: ../../e_os.h ../../include/openssl/bio.h |
83 | lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 83 | lh_stats.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h |
84 | lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 84 | lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
85 | lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | 85 | lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
86 | lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | 86 | lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
87 | lh_stats.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 87 | lh_stats.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
88 | lh_stats.o: ../cryptlib.h | 88 | lh_stats.o: ../cryptlib.h lh_stats.c |
89 | lhash.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 89 | lhash.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h |
90 | lhash.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h | 90 | lhash.o: ../../include/openssl/e_os2.h ../../include/openssl/lhash.h |
91 | lhash.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
91 | lhash.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 92 | lhash.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
92 | lhash.o: ../../include/openssl/symhacks.h | 93 | lhash.o: ../../include/openssl/symhacks.h lhash.c |
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c index ee0600060e..39ea2885f4 100644 --- a/src/lib/libcrypto/lhash/lh_stats.c +++ b/src/lib/libcrypto/lhash/lh_stats.c | |||
@@ -63,12 +63,12 @@ | |||
63 | * and things should work as expected */ | 63 | * and things should work as expected */ |
64 | #include "cryptlib.h" | 64 | #include "cryptlib.h" |
65 | 65 | ||
66 | #ifndef NO_BIO | 66 | #ifndef OPENSSL_NO_BIO |
67 | #include <openssl/bio.h> | 67 | #include <openssl/bio.h> |
68 | #endif | 68 | #endif |
69 | #include <openssl/lhash.h> | 69 | #include <openssl/lhash.h> |
70 | 70 | ||
71 | #ifdef NO_BIO | 71 | #ifdef OPENSSL_NO_BIO |
72 | 72 | ||
73 | void lh_stats(LHASH *lh, FILE *out) | 73 | void lh_stats(LHASH *lh, FILE *out) |
74 | { | 74 | { |
@@ -88,7 +88,7 @@ void lh_stats(LHASH *lh, FILE *out) | |||
88 | fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve); | 88 | fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve); |
89 | fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | 89 | fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); |
90 | fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); | 90 | fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); |
91 | #ifdef DEBUG | 91 | #if 0 |
92 | fprintf(out,"p = %u\n",lh->p); | 92 | fprintf(out,"p = %u\n",lh->p); |
93 | fprintf(out,"pmax = %u\n",lh->pmax); | 93 | fprintf(out,"pmax = %u\n",lh->pmax); |
94 | fprintf(out,"up_load = %lu\n",lh->up_load); | 94 | fprintf(out,"up_load = %lu\n",lh->up_load); |
@@ -138,8 +138,8 @@ void lh_node_usage_stats(LHASH *lh, FILE *out) | |||
138 | 138 | ||
139 | #else | 139 | #else |
140 | 140 | ||
141 | #ifndef NO_FP_API | 141 | #ifndef OPENSSL_NO_FP_API |
142 | void lh_stats(LHASH *lh, FILE *fp) | 142 | void lh_stats(const LHASH *lh, FILE *fp) |
143 | { | 143 | { |
144 | BIO *bp; | 144 | BIO *bp; |
145 | 145 | ||
@@ -151,7 +151,7 @@ void lh_stats(LHASH *lh, FILE *fp) | |||
151 | end:; | 151 | end:; |
152 | } | 152 | } |
153 | 153 | ||
154 | void lh_node_stats(LHASH *lh, FILE *fp) | 154 | void lh_node_stats(const LHASH *lh, FILE *fp) |
155 | { | 155 | { |
156 | BIO *bp; | 156 | BIO *bp; |
157 | 157 | ||
@@ -163,7 +163,7 @@ void lh_node_stats(LHASH *lh, FILE *fp) | |||
163 | end:; | 163 | end:; |
164 | } | 164 | } |
165 | 165 | ||
166 | void lh_node_usage_stats(LHASH *lh, FILE *fp) | 166 | void lh_node_usage_stats(const LHASH *lh, FILE *fp) |
167 | { | 167 | { |
168 | BIO *bp; | 168 | BIO *bp; |
169 | 169 | ||
@@ -177,7 +177,7 @@ end:; | |||
177 | 177 | ||
178 | #endif | 178 | #endif |
179 | 179 | ||
180 | void lh_stats_bio(LHASH *lh, BIO *out) | 180 | void lh_stats_bio(const LHASH *lh, BIO *out) |
181 | { | 181 | { |
182 | char buf[128]; | 182 | char buf[128]; |
183 | 183 | ||
@@ -213,7 +213,7 @@ void lh_stats_bio(LHASH *lh, BIO *out) | |||
213 | BIO_puts(out,buf); | 213 | BIO_puts(out,buf); |
214 | sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps); | 214 | sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps); |
215 | BIO_puts(out,buf); | 215 | BIO_puts(out,buf); |
216 | #ifdef DEBUG | 216 | #if 0 |
217 | sprintf(buf,"p = %u\n",lh->p); | 217 | sprintf(buf,"p = %u\n",lh->p); |
218 | BIO_puts(out,buf); | 218 | BIO_puts(out,buf); |
219 | sprintf(buf,"pmax = %u\n",lh->pmax); | 219 | sprintf(buf,"pmax = %u\n",lh->pmax); |
@@ -225,7 +225,7 @@ void lh_stats_bio(LHASH *lh, BIO *out) | |||
225 | #endif | 225 | #endif |
226 | } | 226 | } |
227 | 227 | ||
228 | void lh_node_stats_bio(LHASH *lh, BIO *out) | 228 | void lh_node_stats_bio(const LHASH *lh, BIO *out) |
229 | { | 229 | { |
230 | LHASH_NODE *n; | 230 | LHASH_NODE *n; |
231 | unsigned int i,num; | 231 | unsigned int i,num; |
@@ -240,7 +240,7 @@ void lh_node_stats_bio(LHASH *lh, BIO *out) | |||
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | void lh_node_usage_stats_bio(LHASH *lh, BIO *out) | 243 | void lh_node_usage_stats_bio(const LHASH *lh, BIO *out) |
244 | { | 244 | { |
245 | LHASH_NODE *n; | 245 | LHASH_NODE *n; |
246 | unsigned long num; | 246 | unsigned long num; |
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c index 6008781e57..85700c859b 100644 --- a/src/lib/libcrypto/lhash/lh_test.c +++ b/src/lib/libcrypto/lhash/lh_test.c | |||
@@ -75,7 +75,6 @@ main() | |||
75 | buf[0]='\0'; | 75 | buf[0]='\0'; |
76 | fgets(buf,256,stdin); | 76 | fgets(buf,256,stdin); |
77 | if (buf[0] == '\0') break; | 77 | if (buf[0] == '\0') break; |
78 | buf[256]='\0'; | ||
79 | i=strlen(buf); | 78 | i=strlen(buf); |
80 | p=OPENSSL_malloc(i+1); | 79 | p=OPENSSL_malloc(i+1); |
81 | memcpy(p,buf,i+1); | 80 | memcpy(p,buf,i+1); |
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c index 7da14620a4..0a16fcf27d 100644 --- a/src/lib/libcrypto/lhash/lhash.c +++ b/src/lib/libcrypto/lhash/lhash.c | |||
@@ -109,9 +109,9 @@ const char *lh_version="lhash" OPENSSL_VERSION_PTEXT; | |||
109 | 109 | ||
110 | static void expand(LHASH *lh); | 110 | static void expand(LHASH *lh); |
111 | static void contract(LHASH *lh); | 111 | static void contract(LHASH *lh); |
112 | static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash); | 112 | static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash); |
113 | 113 | ||
114 | LHASH *lh_new(unsigned long (*h)(), int (*c)()) | 114 | LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c) |
115 | { | 115 | { |
116 | LHASH *ret; | 116 | LHASH *ret; |
117 | int i; | 117 | int i; |
@@ -122,8 +122,8 @@ LHASH *lh_new(unsigned long (*h)(), int (*c)()) | |||
122 | goto err1; | 122 | goto err1; |
123 | for (i=0; i<MIN_NODES; i++) | 123 | for (i=0; i<MIN_NODES; i++) |
124 | ret->b[i]=NULL; | 124 | ret->b[i]=NULL; |
125 | ret->comp=((c == NULL)?(int (*)())strcmp:c); | 125 | ret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c); |
126 | ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h); | 126 | ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h); |
127 | ret->num_nodes=MIN_NODES/2; | 127 | ret->num_nodes=MIN_NODES/2; |
128 | ret->num_alloc_nodes=MIN_NODES; | 128 | ret->num_alloc_nodes=MIN_NODES; |
129 | ret->p=0; | 129 | ret->p=0; |
@@ -176,11 +176,11 @@ void lh_free(LHASH *lh) | |||
176 | OPENSSL_free(lh); | 176 | OPENSSL_free(lh); |
177 | } | 177 | } |
178 | 178 | ||
179 | void *lh_insert(LHASH *lh, void *data) | 179 | void *lh_insert(LHASH *lh, const void *data) |
180 | { | 180 | { |
181 | unsigned long hash; | 181 | unsigned long hash; |
182 | LHASH_NODE *nn,**rn; | 182 | LHASH_NODE *nn,**rn; |
183 | void *ret; | 183 | const void *ret; |
184 | 184 | ||
185 | lh->error=0; | 185 | lh->error=0; |
186 | if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) | 186 | if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) |
@@ -197,7 +197,7 @@ void *lh_insert(LHASH *lh, void *data) | |||
197 | } | 197 | } |
198 | nn->data=data; | 198 | nn->data=data; |
199 | nn->next=NULL; | 199 | nn->next=NULL; |
200 | #ifndef NO_HASH_COMP | 200 | #ifndef OPENSSL_NO_HASH_COMP |
201 | nn->hash=hash; | 201 | nn->hash=hash; |
202 | #endif | 202 | #endif |
203 | *rn=nn; | 203 | *rn=nn; |
@@ -211,14 +211,14 @@ void *lh_insert(LHASH *lh, void *data) | |||
211 | (*rn)->data=data; | 211 | (*rn)->data=data; |
212 | lh->num_replace++; | 212 | lh->num_replace++; |
213 | } | 213 | } |
214 | return(ret); | 214 | return((void *)ret); |
215 | } | 215 | } |
216 | 216 | ||
217 | void *lh_delete(LHASH *lh, void *data) | 217 | void *lh_delete(LHASH *lh, const void *data) |
218 | { | 218 | { |
219 | unsigned long hash; | 219 | unsigned long hash; |
220 | LHASH_NODE *nn,**rn; | 220 | LHASH_NODE *nn,**rn; |
221 | void *ret; | 221 | const void *ret; |
222 | 222 | ||
223 | lh->error=0; | 223 | lh->error=0; |
224 | rn=getrn(lh,data,&hash); | 224 | rn=getrn(lh,data,&hash); |
@@ -242,14 +242,14 @@ void *lh_delete(LHASH *lh, void *data) | |||
242 | (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) | 242 | (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) |
243 | contract(lh); | 243 | contract(lh); |
244 | 244 | ||
245 | return(ret); | 245 | return((void *)ret); |
246 | } | 246 | } |
247 | 247 | ||
248 | void *lh_retrieve(LHASH *lh, void *data) | 248 | void *lh_retrieve(LHASH *lh, const void *data) |
249 | { | 249 | { |
250 | unsigned long hash; | 250 | unsigned long hash; |
251 | LHASH_NODE **rn; | 251 | LHASH_NODE **rn; |
252 | void *ret; | 252 | const void *ret; |
253 | 253 | ||
254 | lh->error=0; | 254 | lh->error=0; |
255 | rn=getrn(lh,data,&hash); | 255 | rn=getrn(lh,data,&hash); |
@@ -264,15 +264,11 @@ void *lh_retrieve(LHASH *lh, void *data) | |||
264 | ret= (*rn)->data; | 264 | ret= (*rn)->data; |
265 | lh->num_retrieve++; | 265 | lh->num_retrieve++; |
266 | } | 266 | } |
267 | return(ret); | 267 | return((void *)ret); |
268 | } | ||
269 | |||
270 | void lh_doall(LHASH *lh, void (*func)()) | ||
271 | { | ||
272 | lh_doall_arg(lh,func,NULL); | ||
273 | } | 268 | } |
274 | 269 | ||
275 | void lh_doall_arg(LHASH *lh, void (*func)(), void *arg) | 270 | static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, |
271 | LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) | ||
276 | { | 272 | { |
277 | int i; | 273 | int i; |
278 | LHASH_NODE *a,*n; | 274 | LHASH_NODE *a,*n; |
@@ -287,12 +283,25 @@ void lh_doall_arg(LHASH *lh, void (*func)(), void *arg) | |||
287 | /* 28/05/91 - eay - n added so items can be deleted | 283 | /* 28/05/91 - eay - n added so items can be deleted |
288 | * via lh_doall */ | 284 | * via lh_doall */ |
289 | n=a->next; | 285 | n=a->next; |
290 | func(a->data,arg); | 286 | if(use_arg) |
287 | func_arg(a->data,arg); | ||
288 | else | ||
289 | func(a->data); | ||
291 | a=n; | 290 | a=n; |
292 | } | 291 | } |
293 | } | 292 | } |
294 | } | 293 | } |
295 | 294 | ||
295 | void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func) | ||
296 | { | ||
297 | doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL); | ||
298 | } | ||
299 | |||
300 | void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) | ||
301 | { | ||
302 | doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg); | ||
303 | } | ||
304 | |||
296 | static void expand(LHASH *lh) | 305 | static void expand(LHASH *lh) |
297 | { | 306 | { |
298 | LHASH_NODE **n,**n1,**n2,*np; | 307 | LHASH_NODE **n,**n1,**n2,*np; |
@@ -309,10 +318,10 @@ static void expand(LHASH *lh) | |||
309 | 318 | ||
310 | for (np= *n1; np != NULL; ) | 319 | for (np= *n1; np != NULL; ) |
311 | { | 320 | { |
312 | #ifndef NO_HASH_COMP | 321 | #ifndef OPENSSL_NO_HASH_COMP |
313 | hash=np->hash; | 322 | hash=np->hash; |
314 | #else | 323 | #else |
315 | hash=(*(lh->hash))(np->data); | 324 | hash=lh->hash(np->data); |
316 | lh->num_hash_calls++; | 325 | lh->num_hash_calls++; |
317 | #endif | 326 | #endif |
318 | if ((hash%nni) != p) | 327 | if ((hash%nni) != p) |
@@ -388,7 +397,7 @@ static void contract(LHASH *lh) | |||
388 | } | 397 | } |
389 | } | 398 | } |
390 | 399 | ||
391 | static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash) | 400 | static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash) |
392 | { | 401 | { |
393 | LHASH_NODE **ret,*n1; | 402 | LHASH_NODE **ret,*n1; |
394 | unsigned long hash,nn; | 403 | unsigned long hash,nn; |
@@ -406,7 +415,7 @@ static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash) | |||
406 | ret= &(lh->b[(int)nn]); | 415 | ret= &(lh->b[(int)nn]); |
407 | for (n1= *ret; n1 != NULL; n1=n1->next) | 416 | for (n1= *ret; n1 != NULL; n1=n1->next) |
408 | { | 417 | { |
409 | #ifndef NO_HASH_COMP | 418 | #ifndef OPENSSL_NO_HASH_COMP |
410 | lh->num_hash_comps++; | 419 | lh->num_hash_comps++; |
411 | if (n1->hash != hash) | 420 | if (n1->hash != hash) |
412 | { | 421 | { |
@@ -415,7 +424,7 @@ static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash) | |||
415 | } | 424 | } |
416 | #endif | 425 | #endif |
417 | lh->num_comp_calls++; | 426 | lh->num_comp_calls++; |
418 | if ((*cf)(n1->data,data) == 0) | 427 | if(cf(n1->data,data) == 0) |
419 | break; | 428 | break; |
420 | ret= &(n1->next); | 429 | ret= &(n1->next); |
421 | } | 430 | } |
@@ -455,7 +464,7 @@ unsigned long lh_strhash(const char *c) | |||
455 | return((ret>>16)^ret); | 464 | return((ret>>16)^ret); |
456 | } | 465 | } |
457 | 466 | ||
458 | unsigned long lh_num_items(LHASH *lh) | 467 | unsigned long lh_num_items(const LHASH *lh) |
459 | { | 468 | { |
460 | return lh ? lh->num_items : 0; | 469 | return lh ? lh->num_items : 0; |
461 | } | 470 | } |
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 | } |