aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2010-01-11 16:39:28 +0100
committerMartin Willi <martin@strongswan.org>2010-01-11 16:39:28 +0100
commit527f7f9b1cebfdd3880ac510a7d7b4f2956b1815 (patch)
treee4e342719d75223a9fd2bccd39dda7533e672bba /src
parentdbee988e289081d0ee2f183b9e309c9bcfafb934 (diff)
downloadstrongswan-527f7f9b1cebfdd3880ac510a7d7b4f2956b1815.tar.bz2
strongswan-527f7f9b1cebfdd3880ac510a7d7b4f2956b1815.tar.xz
Added a "double" getter to libstrongswan settings
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/settings.c25
-rw-r--r--src/libstrongswan/settings.h10
2 files changed, 35 insertions, 0 deletions
diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c
index e961c78d8..4a822bcbf 100644
--- a/src/libstrongswan/settings.c
+++ b/src/libstrongswan/settings.c
@@ -255,6 +255,30 @@ static int get_int(private_settings_t *this, char *key, int 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.
*/
static u_int32_t get_time(private_settings_t *this, char *key, u_int32_t def, ...)
@@ -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 a032c5cd9..9e8d75cc0 100644
--- a/src/libstrongswan/settings.h
+++ b/src/libstrongswan/settings.h
@@ -85,6 +85,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.
*
* @param key key including sections, printf style format