summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ex_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ex_data.c')
-rw-r--r--src/lib/libcrypto/ex_data.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
index e2bc8298d0..3b11e7a556 100644
--- a/src/lib/libcrypto/ex_data.c
+++ b/src/lib/libcrypto/ex_data.c
@@ -245,21 +245,18 @@ typedef struct st_ex_class_item {
245static int ex_class = CRYPTO_EX_INDEX_USER; 245static int ex_class = CRYPTO_EX_INDEX_USER;
246 246
247/* The global hash table of EX_CLASS_ITEM items */ 247/* The global hash table of EX_CLASS_ITEM items */
248DECLARE_LHASH_OF(EX_CLASS_ITEM); 248static LHASH *ex_data = NULL;
249static LHASH_OF(EX_CLASS_ITEM) *ex_data = NULL;
250 249
251/* The callbacks required in the "ex_data" hash table */ 250/* The callbacks required in the "ex_data" hash table */
252static unsigned long ex_class_item_hash(const EX_CLASS_ITEM *a) 251static unsigned long ex_hash_cb(const void *a_void)
253 { 252 {
254 return a->class_index; 253 return ((const EX_CLASS_ITEM *)a_void)->class_index;
255 } 254 }
256static IMPLEMENT_LHASH_HASH_FN(ex_class_item, EX_CLASS_ITEM) 255static int ex_cmp_cb(const void *a_void, const void *b_void)
257
258static int ex_class_item_cmp(const EX_CLASS_ITEM *a, const EX_CLASS_ITEM *b)
259 { 256 {
260 return a->class_index - b->class_index; 257 return (((const EX_CLASS_ITEM *)a_void)->class_index -
258 ((const EX_CLASS_ITEM *)b_void)->class_index);
261 } 259 }
262static IMPLEMENT_LHASH_COMP_FN(ex_class_item, EX_CLASS_ITEM)
263 260
264/* Internal functions used by the "impl_default" implementation to access the 261/* Internal functions used by the "impl_default" implementation to access the
265 * state */ 262 * state */
@@ -268,8 +265,7 @@ static int ex_data_check(void)
268 { 265 {
269 int toret = 1; 266 int toret = 1;
270 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); 267 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
271 if(!ex_data 268 if(!ex_data && ((ex_data = lh_new(ex_hash_cb, ex_cmp_cb)) == NULL))
272 && (ex_data = lh_EX_CLASS_ITEM_new()) == NULL)
273 toret = 0; 269 toret = 0;
274 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); 270 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
275 return toret; 271 return toret;
@@ -302,7 +298,7 @@ static EX_CLASS_ITEM *def_get_class(int class_index)
302 EX_DATA_CHECK(return NULL;) 298 EX_DATA_CHECK(return NULL;)
303 d.class_index = class_index; 299 d.class_index = class_index;
304 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); 300 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
305 p = lh_EX_CLASS_ITEM_retrieve(ex_data, &d); 301 p = lh_retrieve(ex_data, &d);
306 if(!p) 302 if(!p)
307 { 303 {
308 gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM)); 304 gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM));
@@ -317,7 +313,7 @@ static EX_CLASS_ITEM *def_get_class(int class_index)
317 { 313 {
318 /* Because we're inside the ex_data lock, the 314 /* Because we're inside the ex_data lock, the
319 * return value from the insert will be NULL */ 315 * return value from the insert will be NULL */
320 (void)lh_EX_CLASS_ITEM_insert(ex_data, gen); 316 lh_insert(ex_data, gen);
321 p = gen; 317 p = gen;
322 } 318 }
323 } 319 }
@@ -379,8 +375,8 @@ static int int_new_class(void)
379static void int_cleanup(void) 375static void int_cleanup(void)
380 { 376 {
381 EX_DATA_CHECK(return;) 377 EX_DATA_CHECK(return;)
382 lh_EX_CLASS_ITEM_doall(ex_data, def_cleanup_cb); 378 lh_doall(ex_data, def_cleanup_cb);
383 lh_EX_CLASS_ITEM_free(ex_data); 379 lh_free(ex_data);
384 ex_data = NULL; 380 ex_data = NULL;
385 impl = NULL; 381 impl = NULL;
386 } 382 }
@@ -456,7 +452,7 @@ static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
456 return 0; 452 return 0;
457 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); 453 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
458 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); 454 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
459 j = sk_void_num(from->sk); 455 j = sk_num(from->sk);
460 if(j < mx) 456 if(j < mx)
461 mx = j; 457 mx = j;
462 if(mx > 0) 458 if(mx > 0)
@@ -527,7 +523,7 @@ skip:
527 OPENSSL_free(storage); 523 OPENSSL_free(storage);
528 if(ad->sk) 524 if(ad->sk)
529 { 525 {
530 sk_void_free(ad->sk); 526 sk_free(ad->sk);
531 ad->sk=NULL; 527 ad->sk=NULL;
532 } 528 }
533 } 529 }
@@ -600,24 +596,24 @@ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
600 596
601 if (ad->sk == NULL) 597 if (ad->sk == NULL)
602 { 598 {
603 if ((ad->sk=sk_void_new_null()) == NULL) 599 if ((ad->sk=sk_new_null()) == NULL)
604 { 600 {
605 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); 601 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
606 return(0); 602 return(0);
607 } 603 }
608 } 604 }
609 i=sk_void_num(ad->sk); 605 i=sk_num(ad->sk);
610 606
611 while (i <= idx) 607 while (i <= idx)
612 { 608 {
613 if (!sk_void_push(ad->sk,NULL)) 609 if (!sk_push(ad->sk,NULL))
614 { 610 {
615 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); 611 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
616 return(0); 612 return(0);
617 } 613 }
618 i++; 614 i++;
619 } 615 }
620 sk_void_set(ad->sk,idx,val); 616 sk_set(ad->sk,idx,val);
621 return(1); 617 return(1);
622 } 618 }
623 619
@@ -627,10 +623,10 @@ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
627 { 623 {
628 if (ad->sk == NULL) 624 if (ad->sk == NULL)
629 return(0); 625 return(0);
630 else if (idx >= sk_void_num(ad->sk)) 626 else if (idx >= sk_num(ad->sk))
631 return(0); 627 return(0);
632 else 628 else
633 return(sk_void_value(ad->sk,idx)); 629 return(sk_value(ad->sk,idx));
634 } 630 }
635 631
636IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS) 632IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS)