int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);
STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section);
char *NCONF_get_string(CONF *conf,char *group,char *name);
-long NCONF_get_number(CONF *conf,char *group,char *name);
+int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result);
int NCONF_dump_fp(CONF *conf, FILE *out);
int NCONF_dump_bio(CONF *conf, BIO *out);
+#if 0 /* The following function has no error checking,
+ and should therefore be avoided */
+long NCONF_get_number(CONF *conf,char *group,char *name);
+#else
+#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r);
+#endif
+
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
#define CONF_F_NCONF_DUMP_BIO 105
#define CONF_F_NCONF_DUMP_FP 106
#define CONF_F_NCONF_GET_NUMBER 107
+#define CONF_F_NCONF_GET_NUMBER_E 112
#define CONF_F_NCONF_GET_SECTION 108
#define CONF_F_NCONF_GET_STRING 109
#define CONF_F_NCONF_LOAD_BIO 110
#define CONF_R_NO_CONF 105
#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
#define CONF_R_NO_SECTION 107
+#define CONF_R_NO_VALUE 108
#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
#define CONF_R_VARIABLE_HAS_NO_VALUE 104
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;
str++;
}
}
+#endif
int _CONF_new_data(CONF *conf)
{
{ERR_PACK(0,CONF_F_NCONF_DUMP_BIO,0), "NCONF_dump_bio"},
{ERR_PACK(0,CONF_F_NCONF_DUMP_FP,0), "NCONF_dump_fp"},
{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER,0), "NCONF_get_number"},
+{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER_E,0), "NCONF_get_number_e"},
{ERR_PACK(0,CONF_F_NCONF_GET_SECTION,0), "NCONF_get_section"},
{ERR_PACK(0,CONF_F_NCONF_GET_STRING,0), "NCONF_get_string"},
{ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"},
{CONF_R_NO_CONF ,"no conf"},
{CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE ,"no conf or environment variable"},
{CONF_R_NO_SECTION ,"no section"},
+{CONF_R_NO_VALUE ,"no value"},
{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
{0,NULL}
long CONF_get_number(LHASH *conf,char *group,char *name)
{
CONF ctmp;
+ int status;
+ long result = 0;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
- return NCONF_get_number(&ctmp, group, name);
+ status = NCONF_get_number_e(&ctmp, group, name, &result);
+ if (status == 0)
+ {
+ /* This function does not believe in errors... */
+ ERR_get_error();
+ }
+ return result;
}
void CONF_free(LHASH *conf)
CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
return NULL;
}
+ CONFerr(CONF_F_NCONF_GET_STRING,
+ CONF_R_NO_VALUE);
return NULL;
}
-long NCONF_get_number(CONF *conf,char *group,char *name)
+int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result)
{
-#if 0 /* As with _CONF_get_string(), we rely on the possibility of finding
- an environment variable with a suitable name. Unfortunately, there's
- no way with the current API to see if we found one or not...
- The meaning of this is that if a number is not found anywhere, it
- will always default to 0. */
- if (conf == NULL)
+ char *str;
+
+ if (result == NULL)
{
- CONFerr(CONF_F_NCONF_GET_NUMBER,
- CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
+ CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
-#endif
-
- return _CONF_get_number(conf, group, name);
+
+ str = NCONF_get_string(conf,group,name);
+
+ if (str == NULL)
+ return 0;
+
+ for (;conf->meth->is_number(conf, *str);)
+ {
+ *result = (*result)*10 + conf->meth->to_int(conf, *str);
+ str++;
+ }
+
+ return 1;
}
#ifndef NO_FP_API
return conf->meth->dump(conf, out);
}
+/* This function should be avoided */
+#undef NCONF_get_number
+long NCONF_get_number(CONF *conf,char *group,char *name)
+ {
+ int status;
+ long ret=0;
+
+ status = NCONF_get_number_e(conf, group, name, &ret);
+ if (status == 0)
+ {
+ /* This function does not believe in errors... */
+ ERR_get_error();
+ }
+ return ret;
+ }
+