From: Martin Willi Date: Mon, 11 Jan 2010 15:39:28 +0000 (+0100) Subject: Added a "double" getter to libstrongswan settings X-Git-Tag: 4.3.6~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=527f7f9b1cebfdd3880ac510a7d7b4f2956b1815;p=thirdparty%2Fstrongswan.git Added a "double" getter to libstrongswan settings --- diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c index e961c78d8e..4a822bcbf6 100644 --- a/src/libstrongswan/settings.c +++ b/src/libstrongswan/settings.c @@ -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; diff --git a/src/libstrongswan/settings.h b/src/libstrongswan/settings.h index a032c5cd96..9e8d75cc08 100644 --- a/src/libstrongswan/settings.h +++ b/src/libstrongswan/settings.h @@ -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. *