some const fixes and cleanup
[openssl.git] / crypto / lhash / lhash.c
index 7da14620a478fd2074ca53d3c05c35b2fd8b658d..55cb05579bc786600ddeb963ddf6a2106b5a7981 100644 (file)
@@ -109,9 +109,9 @@ const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
 
 static void expand(LHASH *lh);
 static void contract(LHASH *lh);
-static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
+static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash);
 
-LHASH *lh_new(unsigned long (*h)(), int (*c)())
+LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
        {
        LHASH *ret;
        int i;
@@ -122,8 +122,8 @@ LHASH *lh_new(unsigned long (*h)(), int (*c)())
                goto err1;
        for (i=0; i<MIN_NODES; i++)
                ret->b[i]=NULL;
-       ret->comp=((c == NULL)?(int (*)())strcmp:c);
-       ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
+       ret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);
+       ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);
        ret->num_nodes=MIN_NODES/2;
        ret->num_alloc_nodes=MIN_NODES;
        ret->p=0;
@@ -197,7 +197,7 @@ void *lh_insert(LHASH *lh, void *data)
                        }
                nn->data=data;
                nn->next=NULL;
-#ifndef NO_HASH_COMP
+#ifndef OPENSSL_NO_HASH_COMP
                nn->hash=hash;
 #endif
                *rn=nn;
@@ -214,7 +214,7 @@ void *lh_insert(LHASH *lh, void *data)
        return(ret);
        }
 
-void *lh_delete(LHASH *lh, void *data)
+void *lh_delete(LHASH *lh, const void *data)
        {
        unsigned long hash;
        LHASH_NODE *nn,**rn;
@@ -245,7 +245,7 @@ void *lh_delete(LHASH *lh, void *data)
        return(ret);
        }
 
-void *lh_retrieve(LHASH *lh, void *data)
+void *lh_retrieve(LHASH *lh, const void *data)
        {
        unsigned long hash;
        LHASH_NODE **rn;
@@ -267,12 +267,8 @@ void *lh_retrieve(LHASH *lh, void *data)
        return(ret);
        }
 
-void lh_doall(LHASH *lh, void (*func)())
-       {
-       lh_doall_arg(lh,func,NULL);
-       }
-
-void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
+static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
+                         LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
        {
        int i;
        LHASH_NODE *a,*n;
@@ -287,12 +283,25 @@ void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
                        /* 28/05/91 - eay - n added so items can be deleted
                         * via lh_doall */
                        n=a->next;
-                       func(a->data,arg);
+                       if(use_arg)
+                               func_arg(a->data,arg);
+                       else
+                               func(a->data);
                        a=n;
                        }
                }
        }
 
+void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func)
+       {
+       doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL);
+       }
+
+void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
+       {
+       doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
+       }
+
 static void expand(LHASH *lh)
        {
        LHASH_NODE **n,**n1,**n2,*np;
@@ -309,10 +318,10 @@ static void expand(LHASH *lh)
        
        for (np= *n1; np != NULL; )
                {
-#ifndef NO_HASH_COMP
+#ifndef OPENSSL_NO_HASH_COMP
                hash=np->hash;
 #else
-               hash=(*(lh->hash))(np->data);
+               hash=lh->hash(np->data);
                lh->num_hash_calls++;
 #endif
                if ((hash%nni) != p)
@@ -330,7 +339,7 @@ static void expand(LHASH *lh)
                {
                j=(int)lh->num_alloc_nodes*2;
                n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
-                       (unsigned int)sizeof(LHASH_NODE *)*j);
+                       (int)(sizeof(LHASH_NODE *)*j));
                if (n == NULL)
                        {
 /*                     fputs("realloc error in lhash",stderr); */
@@ -388,11 +397,11 @@ static void contract(LHASH *lh)
                }
        }
 
-static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
+static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash)
        {
        LHASH_NODE **ret,*n1;
        unsigned long hash,nn;
-       int (*cf)();
+       LHASH_COMP_FN_TYPE cf;
 
        hash=(*(lh->hash))(data);
        lh->num_hash_calls++;
@@ -406,7 +415,7 @@ static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
        ret= &(lh->b[(int)nn]);
        for (n1= *ret; n1 != NULL; n1=n1->next)
                {
-#ifndef NO_HASH_COMP
+#ifndef OPENSSL_NO_HASH_COMP
                lh->num_hash_comps++;
                if (n1->hash != hash)
                        {
@@ -415,7 +424,7 @@ static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
                        }
 #endif
                lh->num_comp_calls++;
-               if ((*cf)(n1->data,data) == 0)
+               if(cf(n1->data,data) == 0)
                        break;
                ret= &(n1->next);
                }
@@ -455,7 +464,7 @@ unsigned long lh_strhash(const char *c)
        return((ret>>16)^ret);
        }
 
-unsigned long lh_num_items(LHASH *lh)
+unsigned long lh_num_items(const LHASH *lh)
        {
        return lh ? lh->num_items : 0;
        }