Sort openssl.ec, the configuration file for mkerr.pl.
[openssl.git] / crypto / conf / conf_api.c
index 2998927..9615df5 100644 (file)
 
 /* Part of the code in here was originally in conf.c, which is now removed */
 
 
 /* Part of the code in here was originally in conf.c, which is now removed */
 
+#ifndef CONF_DEBUG
+# undef NDEBUG /* avoid conflicting definitions */
+# define NDEBUG
+#endif
+
+#include <assert.h>
+#include <string.h>
 #include <openssl/conf.h>
 #include <openssl/conf_api.h>
 #include <openssl/conf.h>
 #include <openssl/conf_api.h>
+#include "e_os.h"
 
 static void value_free_hash(CONF_VALUE *a, LHASH *conf);
 static void value_free_stack(CONF_VALUE *a,LHASH *conf);
 
 static void value_free_hash(CONF_VALUE *a, LHASH *conf);
 static void value_free_stack(CONF_VALUE *a,LHASH *conf);
-static unsigned long hash(CONF_VALUE *v);
-static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b);
+static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *)
+static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *)
+/* We don't use function pointer casting or wrapper functions - but cast each
+ * callback parameter inside the callback functions. */
+/* static unsigned long hash(CONF_VALUE *v); */
+static unsigned long hash(const void *v_void);
+/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */
+static int cmp_conf(const void *a_void,const void *b_void);
 
 /* Up until OpenSSL 0.9.5a, this was get_section */
 CONF_VALUE *_CONF_get_section(CONF *conf, char *section)
 
 /* Up until OpenSSL 0.9.5a, this was get_section */
 CONF_VALUE *_CONF_get_section(CONF *conf, char *section)
@@ -107,9 +121,9 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
        if (v != NULL)
                {
                sk_CONF_VALUE_delete_ptr(ts,v);
        if (v != NULL)
                {
                sk_CONF_VALUE_delete_ptr(ts,v);
-               Free(v->name);
-               Free(v->value);
-               Free(v);
+               OPENSSL_free(v->name);
+               OPENSSL_free(v->value);
+               OPENSSL_free(v);
                }
        return 1;
        }
                }
        return 1;
        }
@@ -146,6 +160,9 @@ char *_CONF_get_string(CONF *conf, char *section, char *name)
                return(Getenv(name));
        }
 
                return(Getenv(name));
        }
 
+#if 0 /* There's no way to provide error checking with this function, so
+        force implementors of the higher levels to get a string and read
+        the number themselves. */
 long _CONF_get_number(CONF *conf, char *section, char *name)
        {
        char *str;
 long _CONF_get_number(CONF *conf, char *section, char *name)
        {
        char *str;
@@ -162,6 +179,7 @@ long _CONF_get_number(CONF *conf, char *section, char *name)
                str++;
                }
        }
                str++;
                }
        }
+#endif
 
 int _CONF_new_data(CONF *conf)
        {
 
 int _CONF_new_data(CONF *conf)
        {
@@ -170,7 +188,7 @@ int _CONF_new_data(CONF *conf)
                return 0;
                }
        if (conf->data == NULL)
                return 0;
                }
        if (conf->data == NULL)
-               if ((conf->data = lh_new(hash,cmp_conf)) == NULL)
+               if ((conf->data = lh_new(hash, cmp_conf)) == NULL)
                        {
                        return 0;
                        }
                        {
                        return 0;
                        }
@@ -181,14 +199,16 @@ void _CONF_free_data(CONF *conf)
        {
        if (conf == NULL || conf->data == NULL) return;
 
        {
        if (conf == NULL || conf->data == NULL) return;
 
-       conf->data->down_load=0; /* evil thing to make sure the 'Free()'
+       conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
                                  * works as expected */
                                  * works as expected */
-       lh_doall_arg(conf->data,(void (*)())value_free_hash,conf->data);
+       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash),
+                       conf->data);
 
        /* We now have only 'section' entries in the hash table.
         * Due to problems with */
 
 
        /* We now have only 'section' entries in the hash table.
         * Due to problems with */
 
-       lh_doall_arg(conf->data,(void (*)())value_free_stack,conf->data);
+       lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack),
+                       conf->data);
        lh_free(conf->data);
        }
 
        lh_free(conf->data);
        }
 
@@ -212,23 +232,28 @@ static void value_free_stack(CONF_VALUE *a, LHASH *conf)
        for (i=sk_num(sk)-1; i>=0; i--)
                {
                vv=(CONF_VALUE *)sk_value(sk,i);
        for (i=sk_num(sk)-1; i>=0; i--)
                {
                vv=(CONF_VALUE *)sk_value(sk,i);
-               Free(vv->value);
-               Free(vv->name);
-               Free(vv);
+               OPENSSL_free(vv->value);
+               OPENSSL_free(vv->name);
+               OPENSSL_free(vv);
                }
        if (sk != NULL) sk_free(sk);
                }
        if (sk != NULL) sk_free(sk);
-       Free(a->section);
-       Free(a);
+       OPENSSL_free(a->section);
+       OPENSSL_free(a);
        }
 
        }
 
-static unsigned long hash(CONF_VALUE *v)
+/* static unsigned long hash(CONF_VALUE *v) */
+static unsigned long hash(const void *v_void)
        {
        {
+       CONF_VALUE *v = (CONF_VALUE *)v_void;
        return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
        }
 
        return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
        }
 
-static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
+/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */
+static int cmp_conf(const void *a_void,const  void *b_void)
        {
        int i;
        {
        int i;
+       CONF_VALUE *a = (CONF_VALUE *)a_void;
+       CONF_VALUE *b = (CONF_VALUE *)b_void;
 
        if (a->section != b->section)
                {
 
        if (a->section != b->section)
                {
@@ -256,10 +281,10 @@ CONF_VALUE *_CONF_new_section(CONF *conf, char *section)
 
        if ((sk=sk_new_null()) == NULL)
                goto err;
 
        if ((sk=sk_new_null()) == NULL)
                goto err;
-       if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)
+       if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
                goto err;
        i=strlen(section)+1;
                goto err;
        i=strlen(section)+1;
-       if ((v->section=(char *)Malloc(i)) == NULL)
+       if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
                goto err;
 
        memcpy(v->section,section,i);
                goto err;
 
        memcpy(v->section,section,i);
@@ -267,19 +292,13 @@ CONF_VALUE *_CONF_new_section(CONF *conf, char *section)
        v->value=(char *)sk;
        
        vv=(CONF_VALUE *)lh_insert(conf->data,v);
        v->value=(char *)sk;
        
        vv=(CONF_VALUE *)lh_insert(conf->data,v);
-       if (vv != NULL)
-               {
-#if !defined(NO_STDIO) && !defined(WIN16)
-               fprintf(stderr,"internal fault\n");
-#endif
-               abort();
-               }
+       assert(vv == NULL);
        ok=1;
 err:
        if (!ok)
                {
                if (sk != NULL) sk_free(sk);
        ok=1;
 err:
        if (!ok)
                {
                if (sk != NULL) sk_free(sk);
-               if (v != NULL) Free(v);
+               if (v != NULL) OPENSSL_free(v);
                v=NULL;
                }
        return(v);
                v=NULL;
                }
        return(v);