First step in tidying up the LHASH code. The callback prototypes (and
[openssl.git] / crypto / txt_db / txt_db.c
index 9e7813b692e35f34b599a39c08a52a7566e75a1a..eb13f6040a7012b8e46f8926fbf2b87548e0218f 100644 (file)
@@ -60,8 +60,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include "cryptlib.h"
-#include "buffer.h"
-#include "txt_db.h"
+#include <openssl/buffer.h>
+#include <openssl/txt_db.h>
 
 #undef BUFSIZE
 #define BUFSIZE        512
@@ -83,16 +83,16 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
        if ((buf=BUF_MEM_new()) == NULL) goto err;
        if (!BUF_MEM_grow(buf,size)) goto err;
 
-       if ((ret=(TXT_DB *)Malloc(sizeof(TXT_DB))) == NULL)
+       if ((ret=(TXT_DB *)OPENSSL_malloc(sizeof(TXT_DB))) == NULL)
                goto err;
        ret->num_fields=num;
        ret->index=NULL;
        ret->qual=NULL;
        if ((ret->data=sk_new_null()) == NULL)
                goto err;
-       if ((ret->index=(LHASH **)Malloc(sizeof(LHASH *)*num)) == NULL)
+       if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL)
                goto err;
-       if ((ret->qual=(int (**)())Malloc(sizeof(int (**)())*num)) == NULL)
+       if ((ret->qual=(int (**)())OPENSSL_malloc(sizeof(int (**)())*num)) == NULL)
                goto err;
        for (i=0; i<num; i++)
                {
@@ -122,7 +122,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
                else
                        {
                        buf->data[offset-1]='\0'; /* blat the '\n' */
-                       p=(char *)Malloc(add+offset);
+                       p=(char *)OPENSSL_malloc(add+offset);
                        offset=0;
                        }
                pp=(char **)p;
@@ -177,12 +177,12 @@ err:
        if (er)
                {
 #if !defined(NO_STDIO) && !defined(WIN16)
-               if (er == 1) fprintf(stderr,"Malloc failure\n");
+               if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n");
 #endif
                if (ret->data != NULL) sk_free(ret->data);
-               if (ret->index != NULL) Free(ret->index);
-               if (ret->qual != NULL) Free((char *)ret->qual);
-               if (ret != NULL) Free(ret);
+               if (ret->index != NULL) OPENSSL_free(ret->index);
+               if (ret->qual != NULL) OPENSSL_free(ret->qual);
+               if (ret != NULL) OPENSSL_free(ret);
                return(NULL);
                }
        else
@@ -205,13 +205,13 @@ char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
                db->error=DB_ERROR_NO_INDEX;
                return(NULL);
                }
-       ret=(char **)lh_retrieve(lh,(char *)value);
+       ret=(char **)lh_retrieve(lh,value);
        db->error=DB_ERROR_OK;
        return(ret);
        }
 
 int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(),
-            unsigned long (*hash)(), int (*cmp)())
+               LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
        {
        LHASH *idx;
        char *r;
@@ -306,7 +306,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
                        {
                        if ((db->qual[i] != NULL) &&
                                (db->qual[i](row) == 0)) continue;
-                       r=(char **)lh_retrieve(db->index[i],(char *)row);
+                       r=(char **)lh_retrieve(db->index[i],row);
                        if (r != NULL)
                                {
                                db->error=DB_ERROR_INDEX_CLASH;
@@ -329,7 +329,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
                        {
                        if ((db->qual[i] != NULL) &&
                                (db->qual[i](row) == 0)) continue;
-                       lh_insert(db->index[i],(char *)row);
+                       lh_insert(db->index[i],row);
                        }
                }
        return(1);
@@ -349,10 +349,10 @@ void TXT_DB_free(TXT_DB *db)
                {
                for (i=db->num_fields-1; i>=0; i--)
                        if (db->index[i] != NULL) lh_free(db->index[i]);
-               Free(db->index);
+               OPENSSL_free(db->index);
                }
        if (db->qual != NULL)
-               Free(db->qual);
+               OPENSSL_free(db->qual);
        if (db->data != NULL)
                {
                for (i=sk_num(db->data)-1; i>=0; i--)
@@ -364,7 +364,7 @@ void TXT_DB_free(TXT_DB *db)
                        if (max == NULL) /* new row */
                                {
                                for (n=0; n<db->num_fields; n++)
-                                       if (p[n] != NULL) Free(p[n]);
+                                       if (p[n] != NULL) OPENSSL_free(p[n]);
                                }
                        else
                                {
@@ -372,12 +372,12 @@ void TXT_DB_free(TXT_DB *db)
                                        {
                                        if (((p[n] < (char *)p) || (p[n] > max))
                                                && (p[n] != NULL))
-                                               Free(p[n]);
+                                               OPENSSL_free(p[n]);
                                        }
                                }
-                       Free(sk_value(db->data,i));
+                       OPENSSL_free(sk_value(db->data,i));
                        }
                sk_free(db->data);
                }
-       Free(db);
+       OPENSSL_free(db);
        }