Move all the existing function pointer casts associated with LHASH's two
[openssl.git] / crypto / conf / conf_def.c
index 368a31a92f070fd20f957c76bfbde67d315cb85c..59f9476dc6c77209a9f06424d0cd43fdd0d184e5 100644 (file)
@@ -59,6 +59,7 @@
 /* Part of the code in here was originally in conf.c, which is now removed */
 
 #include <stdio.h>
+#include <string.h>
 #include <openssl/stack.h>
 #include <openssl/lhash.h>
 #include <openssl/conf.h>
@@ -73,14 +74,15 @@ static void clear_comments(CONF *conf, char *p);
 static int str_copy(CONF *conf,char *section,char **to, char *from);
 static char *scan_quote(CONF *conf, char *p);
 static char *scan_dquote(CONF *conf, char *p);
-#define scan_esc(p)    (((IS_EOF((conf),(p)[1]))?(p+=1):(p+=2)))
+#define scan_esc(conf,p)       (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
 
 static CONF *def_create(CONF_METHOD *meth);
 static int def_init_default(CONF *conf);
 static int def_init_WIN32(CONF *conf);
 static int def_destroy(CONF *conf);
 static int def_destroy_data(CONF *conf);
-static int def_load(CONF *conf, BIO *bp, long *eline);
+static int def_load(CONF *conf, const char *name, long *eline);
+static int def_load_bio(CONF *conf, BIO *bp, long *eline);
 static int def_dump(CONF *conf, BIO *bp);
 static int def_is_number(CONF *conf, char c);
 static int def_to_int(CONF *conf, char c);
@@ -93,10 +95,11 @@ static CONF_METHOD default_method = {
        def_init_default,
        def_destroy,
        def_destroy_data,
-       def_load,
+       def_load_bio,
        def_dump,
        def_is_number,
-       def_to_int
+       def_to_int,
+       def_load
        };
 
 static CONF_METHOD WIN32_method = {
@@ -105,10 +108,11 @@ static CONF_METHOD WIN32_method = {
        def_init_WIN32,
        def_destroy,
        def_destroy_data,
-       def_load,
+       def_load_bio,
        def_dump,
        def_is_number,
-       def_to_int
+       def_to_int,
+       def_load
        };
 
 CONF_METHOD *NCONF_default()
@@ -124,11 +128,11 @@ static CONF *def_create(CONF_METHOD *meth)
        {
        CONF *ret;
 
-       ret = (CONF *)Malloc(sizeof(CONF) + sizeof(unsigned short *));
+       ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
        if (ret)
                if (meth->init(ret) == 0)
                        {
-                       Free(ret);
+                       OPENSSL_free(ret);
                        ret = NULL;
                        }
        return ret;
@@ -162,7 +166,7 @@ static int def_destroy(CONF *conf)
        {
        if (def_destroy_data(conf))
                {
-               Free(conf);
+               OPENSSL_free(conf);
                return 1;
                }
        return 0;
@@ -176,7 +180,29 @@ static int def_destroy_data(CONF *conf)
        return 1;
        }
 
-static int def_load(CONF *conf, BIO *in, long *line)
+static int def_load(CONF *conf, const char *name, long *line)
+       {
+       int ret;
+       BIO *in=NULL;
+
+#ifdef VMS
+       in=BIO_new_file(name, "r");
+#else
+       in=BIO_new_file(name, "rb");
+#endif
+       if (in == NULL)
+               {
+               CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+               return 0;
+               }
+
+       ret = def_load_bio(conf, in, line);
+       BIO_free(in);
+
+       return ret;
+       }
+
+static int def_load_bio(CONF *conf, BIO *in, long *line)
        {
 #define BUFSIZE        512
        char btmp[16];
@@ -198,7 +224,7 @@ static int def_load(CONF *conf, BIO *in, long *line)
                goto err;
                }
 
-       section=(char *)Malloc(10);
+       section=(char *)OPENSSL_malloc(10);
        if (section == NULL)
                {
                CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
@@ -345,14 +371,14 @@ again:
                        p++;
                        *p='\0';
 
-                       if (!(v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))))
+                       if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
                                {
                                CONFerr(CONF_F_CONF_LOAD_BIO,
                                                        ERR_R_MALLOC_FAILURE);
                                goto err;
                                }
                        if (psection == NULL) psection=section;
-                       v->name=(char *)Malloc(strlen(pname)+1);
+                       v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
                        v->value=NULL;
                        if (v->name == NULL)
                                {
@@ -400,29 +426,29 @@ again:
                        if (vv != NULL)
                                {
                                sk_CONF_VALUE_delete_ptr(ts,vv);
-                               Free(vv->name);
-                               Free(vv->value);
-                               Free(vv);
+                               OPENSSL_free(vv->name);
+                               OPENSSL_free(vv->value);
+                               OPENSSL_free(vv);
                                }
 #endif
                        v=NULL;
                        }
                }
        if (buff != NULL) BUF_MEM_free(buff);
-       if (section != NULL) Free(section);
+       if (section != NULL) OPENSSL_free(section);
        return(1);
 err:
        if (buff != NULL) BUF_MEM_free(buff);
-       if (section != NULL) Free(section);
+       if (section != NULL) OPENSSL_free(section);
        if (line != NULL) *line=eline;
        sprintf(btmp,"%ld",eline);
        ERR_add_error_data(2,"line ",btmp);
        if ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data);
        if (v != NULL)
                {
-               if (v->name != NULL) Free(v->name);
-               if (v->value != NULL) Free(v->value);
-               if (v != NULL) Free(v);
+               if (v->name != NULL) OPENSSL_free(v->name);
+               if (v->value != NULL) OPENSSL_free(v->value);
+               if (v != NULL) OPENSSL_free(v);
                }
        return(0);
        }
@@ -465,7 +491,7 @@ static void clear_comments(CONF *conf, char *p)
                        }
                if (IS_ESC(conf,*p))
                        {
-                       p=scan_esc(p);
+                       p=scan_esc(conf,p);
                        continue;
                        }
                if (IS_EOF(conf,*p))
@@ -602,9 +628,9 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
                        buf->data[to++]= *(from++);
                }
        buf->data[to]='\0';
-       if (*pto != NULL) Free(*pto);
+       if (*pto != NULL) OPENSSL_free(*pto);
        *pto=buf->data;
-       Free(buf);
+       OPENSSL_free(buf);
        return(1);
 err:
        if (buf != NULL) BUF_MEM_free(buf);
@@ -624,7 +650,7 @@ static char *eat_alpha_numeric(CONF *conf, char *p)
                {
                if (IS_ESC(conf,*p))
                        {
-                       p=scan_esc(p);
+                       p=scan_esc(conf,p);
                        continue;
                        }
                if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
@@ -684,9 +710,11 @@ static void dump_value(CONF_VALUE *a, BIO *out)
                BIO_printf(out, "[[%s]]\n", a->section);
        }
 
+static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
+
 static int def_dump(CONF *conf, BIO *out)
        {
-       lh_doall_arg(conf->data, (void (*)())dump_value, out);
+       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
        return 1;
        }