LHASH revamp. make depend.
[openssl.git] / crypto / conf / conf_lib.c
index 2005c87350b7a65dcdbedbcf5c493faeda83fa81..54046defca8b2db4852cc386cec2686730126582 100644 (file)
 #include <openssl/conf_api.h>
 #include <openssl/lhash.h>
 
-const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
+const char CONF_version[]="CONF" OPENSSL_VERSION_PTEXT;
 
 static CONF_METHOD *default_CONF_method=NULL;
 
+/* Init a 'CONF' structure from an old LHASH */
+
+void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash)
+       {
+       if (default_CONF_method == NULL)
+               default_CONF_method = NCONF_default();
+
+       default_CONF_method->init(conf);
+       conf->data = hash;
+       }
+
 /* The following section contains the "CONF classic" functions,
    rewritten in terms of the new CONF interface. */
 
@@ -76,12 +87,13 @@ int CONF_set_default_method(CONF_METHOD *meth)
        return 1;
        }
 
-LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
+LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
+                               long *eline)
        {
-       LHASH *ltmp;
+       LHASH_OF(CONF_VALUE) *ltmp;
        BIO *in=NULL;
 
-#ifdef VMS
+#ifdef OPENSSL_SYS_VMS
        in=BIO_new_file(file, "r");
 #else
        in=BIO_new_file(file, "rb");
@@ -98,11 +110,12 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
        return ltmp;
        }
 
-#ifndef NO_FP_API
-LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
+#ifndef OPENSSL_NO_FP_API
+LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
+                                  long *eline)
        {
        BIO *btmp;
-       LHASH *ltmp;
+       LHASH_OF(CONF_VALUE) *ltmp;
        if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
                CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
                return NULL;
@@ -113,80 +126,84 @@ LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
        }
 #endif
 
-LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
+LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
+                                   long *eline)
        {
        CONF ctmp;
        int ret;
 
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
+       CONF_set_nconf(&ctmp, conf);
 
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
        ret = NCONF_load_bio(&ctmp, bp, eline);
        if (ret)
                return ctmp.data;
        return NULL;
        }
 
-STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
+STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
+                                      const char *section)
        {
-       CONF ctmp;
-
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
-
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
-       return NCONF_get_section(&ctmp, section);
+       if (conf == NULL)
+               {
+               return NULL;
+               }
+       else
+               {
+               CONF ctmp;
+               CONF_set_nconf(&ctmp, conf);
+               return NCONF_get_section(&ctmp, section);
+               }
        }
 
-char *CONF_get_string(LHASH *conf,char *group,char *name)
+char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                     const char *name)
        {
-       CONF ctmp;
-
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
-
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
-       return NCONF_get_string(&ctmp, group, name);
+       if (conf == NULL)
+               {
+               return NCONF_get_string(NULL, group, name);
+               }
+       else
+               {
+               CONF ctmp;
+               CONF_set_nconf(&ctmp, conf);
+               return NCONF_get_string(&ctmp, group, name);
+               }
        }
 
-long CONF_get_number(LHASH *conf,char *group,char *name)
+long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group,
+                    const char *name)
        {
-       CONF ctmp;
        int status;
        long result = 0;
 
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
+       if (conf == NULL)
+               {
+               status = NCONF_get_number_e(NULL, group, name, &result);
+               }
+       else
+               {
+               CONF ctmp;
+               CONF_set_nconf(&ctmp, conf);
+               status = NCONF_get_number_e(&ctmp, group, name, &result);
+               }
 
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
-       status = NCONF_get_number_e(&ctmp, group, name, &result);
        if (status == 0)
                {
                /* This function does not believe in errors... */
-               ERR_get_error();
+               ERR_clear_error();
                }
        return result;
        }
 
-void CONF_free(LHASH *conf)
+void CONF_free(LHASH_OF(CONF_VALUE) *conf)
        {
        CONF ctmp;
-
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
-
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
+       CONF_set_nconf(&ctmp, conf);
        NCONF_free_data(&ctmp);
        }
 
-#ifndef NO_FP_API
-int CONF_dump_fp(LHASH *conf, FILE *out)
+#ifndef OPENSSL_NO_FP_API
+int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out)
        {
        BIO *btmp;
        int ret;
@@ -201,15 +218,10 @@ int CONF_dump_fp(LHASH *conf, FILE *out)
        }
 #endif
 
-int CONF_dump_bio(LHASH *conf, BIO *out)
+int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out)
        {
        CONF ctmp;
-
-       if (default_CONF_method == NULL)
-               default_CONF_method = NCONF_default();
-
-       default_CONF_method->init(&ctmp);
-       ctmp.data = conf;
+       CONF_set_nconf(&ctmp, conf);
        return NCONF_dump_bio(&ctmp, out);
        }
 
@@ -261,7 +273,7 @@ int NCONF_load(CONF *conf, const char *file, long *eline)
        return conf->meth->load(conf, file, eline);
        }
 
-#ifndef NO_FP_API
+#ifndef OPENSSL_NO_FP_API
 int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
        {
        BIO *btmp;
@@ -288,7 +300,7 @@ int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
        return conf->meth->load_bio(conf, bp, eline);
        }
 
-STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
+STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section)
        {
        if (conf == NULL)
                {
@@ -305,7 +317,7 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
        return _CONF_get_section_values(conf, section);
        }
 
-char *NCONF_get_string(CONF *conf,char *group,char *name)
+char *NCONF_get_string(const CONF *conf,const char *group,const char *name)
        {
        char *s = _CONF_get_string(conf, group, name);
 
@@ -321,10 +333,12 @@ char *NCONF_get_string(CONF *conf,char *group,char *name)
                }
        CONFerr(CONF_F_NCONF_GET_STRING,
                CONF_R_NO_VALUE);
+       ERR_add_error_data(4,"group=",group," name=",name);
        return NULL;
        }
 
-int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result)
+int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
+                      long *result)
        {
        char *str;
 
@@ -339,7 +353,7 @@ int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result)
        if (str == NULL)
                return 0;
 
-       for (;conf->meth->is_number(conf, *str);)
+       for (*result = 0;conf->meth->is_number(conf, *str);)
                {
                *result = (*result)*10 + conf->meth->to_int(conf, *str);
                str++;
@@ -348,8 +362,8 @@ int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result)
        return 1;
        }
 
-#ifndef NO_FP_API
-int NCONF_dump_fp(CONF *conf, FILE *out)
+#ifndef OPENSSL_NO_FP_API
+int NCONF_dump_fp(const CONF *conf, FILE *out)
        {
        BIO *btmp;
        int ret;
@@ -363,7 +377,7 @@ int NCONF_dump_fp(CONF *conf, FILE *out)
        }
 #endif
 
-int NCONF_dump_bio(CONF *conf, BIO *out)
+int NCONF_dump_bio(const CONF *conf, BIO *out)
        {
        if (conf == NULL)
                {
@@ -374,8 +388,9 @@ int NCONF_dump_bio(CONF *conf, BIO *out)
        return conf->meth->dump(conf, out);
        }
 
+
 /* This function should be avoided */
-#undef NCONF_get_number
+#if 0
 long NCONF_get_number(CONF *conf,char *group,char *name)
        {
        int status;
@@ -389,4 +404,4 @@ long NCONF_get_number(CONF *conf,char *group,char *name)
                }
        return ret;
        }
-
+#endif