Added a "double" getter to libstrongswan settings

This commit is contained in:
Martin Willi
2010-01-11 16:39:28 +01:00
parent dbee988e28
commit 527f7f9b1c
2 changed files with 35 additions and 0 deletions
+25
View File
@@ -254,6 +254,30 @@ static int get_int(private_settings_t *this, char *key, int def, ...)
return def;
}
/**
* Implementation of settings_t.get_double.
*/
static double get_double(private_settings_t *this, char *key, double def, ...)
{
char *value;
double dval;
va_list args;
va_start(args, def);
value = find_value(this->top, key, args);
va_end(args);
if (value)
{
errno = 0;
dval = strtod(value, NULL);
if (errno == 0)
{
return dval;
}
}
return def;
}
/**
* Implementation of settings_t.get_time.
*/
@@ -525,6 +549,7 @@ settings_t *settings_create(char *file)
this = malloc_thing(private_settings_t);
this->public.get_str = (char*(*)(settings_t*, char *key, char* def, ...))get_str;
this->public.get_int = (int(*)(settings_t*, char *key, int def, ...))get_int;
this->public.get_double = (double(*)(settings_t*, char *key, double def, ...))get_double;
this->public.get_time = (u_int32_t(*)(settings_t*, char *key, u_int32_t def, ...))get_time;
this->public.get_bool = (bool(*)(settings_t*, char *key, bool def, ...))get_bool;
this->public.create_section_enumerator = (enumerator_t*(*)(settings_t*,char *section, ...))create_section_enumerator;
+10
View File
@@ -84,6 +84,16 @@ struct settings_t {
*/
int (*get_int)(settings_t *this, char *key, int def, ...);
/**
* Get an double value.
*
* @param key key including sections, printf style format
* @param def value returned if key not found
* @param ... argument list for key
* @return value of the key
*/
double (*get_double)(settings_t *this, char *key, double def, ...);
/**
* Get a time value.
*