summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/lhash/lhash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.c')
-rw-r--r--src/lib/libcrypto/lhash/lhash.c63
1 files changed, 36 insertions, 27 deletions
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
110static void expand(LHASH *lh); 110static void expand(LHASH *lh);
111static void contract(LHASH *lh); 111static void contract(LHASH *lh);
112static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash); 112static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash);
113 113
114LHASH *lh_new(unsigned long (*h)(), int (*c)()) 114LHASH *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
179void *lh_insert(LHASH *lh, void *data) 179void *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
217void *lh_delete(LHASH *lh, void *data) 217void *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
248void *lh_retrieve(LHASH *lh, void *data) 248void *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
270void lh_doall(LHASH *lh, void (*func)())
271 {
272 lh_doall_arg(lh,func,NULL);
273 } 268 }
274 269
275void lh_doall_arg(LHASH *lh, void (*func)(), void *arg) 270static 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
295void 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
300void 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
296static void expand(LHASH *lh) 305static 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
391static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash) 400static 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
458unsigned long lh_num_items(LHASH *lh) 467unsigned 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 }