aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/settings.c69
-rw-r--r--src/libstrongswan/settings.h42
2 files changed, 92 insertions, 19 deletions
diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c
index cc24312a7..a7766643e 100644
--- a/src/libstrongswan/settings.c
+++ b/src/libstrongswan/settings.c
@@ -352,15 +352,11 @@ METHOD(settings_t, get_str, char*,
return def;
}
-METHOD(settings_t, get_bool, bool,
- private_settings_t *this, char *key, bool def, ...)
+/**
+ * Described in header
+ */
+inline bool settings_value_as_bool(char *value, bool def)
{
- char *value;
- va_list args;
-
- va_start(args, def);
- value = find_value(this, this->top, key, args);
- va_end(args);
if (value)
{
if (strcaseeq(value, "true") ||
@@ -381,16 +377,24 @@ METHOD(settings_t, get_bool, bool,
return def;
}
-METHOD(settings_t, get_int, int,
- private_settings_t *this, char *key, int def, ...)
+METHOD(settings_t, get_bool, bool,
+ private_settings_t *this, char *key, bool def, ...)
{
char *value;
- int intval;
va_list args;
va_start(args, def);
value = find_value(this, this->top, key, args);
va_end(args);
+ return settings_value_as_bool(value, def);
+}
+
+/**
+ * Described in header
+ */
+inline int settings_value_as_int(char *value, int def)
+{
+ int intval;
if (value)
{
errno = 0;
@@ -403,16 +407,24 @@ METHOD(settings_t, get_int, int,
return def;
}
-METHOD(settings_t, get_double, double,
- private_settings_t *this, char *key, double def, ...)
+METHOD(settings_t, get_int, int,
+ private_settings_t *this, char *key, int def, ...)
{
char *value;
- double dval;
va_list args;
va_start(args, def);
value = find_value(this, this->top, key, args);
va_end(args);
+ return settings_value_as_int(value, def);
+}
+
+/**
+ * Described in header
+ */
+inline double settings_value_as_double(char *value, double def)
+{
+ double dval;
if (value)
{
errno = 0;
@@ -425,16 +437,25 @@ METHOD(settings_t, get_double, double,
return def;
}
-METHOD(settings_t, get_time, u_int32_t,
- private_settings_t *this, char *key, u_int32_t def, ...)
+METHOD(settings_t, get_double, double,
+ private_settings_t *this, char *key, double def, ...)
{
- char *value, *endptr;
- u_int32_t timeval;
+ char *value;
va_list args;
va_start(args, def);
value = find_value(this, this->top, key, args);
va_end(args);
+ return settings_value_as_double(value, def);
+}
+
+/**
+ * Described in header
+ */
+inline u_int32_t settings_value_as_time(char *value, u_int32_t def)
+{
+ char *endptr;
+ u_int32_t timeval;
if (value)
{
errno = 0;
@@ -462,6 +483,18 @@ METHOD(settings_t, get_time, u_int32_t,
return def;
}
+METHOD(settings_t, get_time, u_int32_t,
+ private_settings_t *this, char *key, u_int32_t def, ...)
+{
+ char *value;
+ va_list args;
+
+ va_start(args, def);
+ value = find_value(this, this->top, key, args);
+ va_end(args);
+ return settings_value_as_time(value, def);
+}
+
/**
* Enumerate section names, not sections
*/
diff --git a/src/libstrongswan/settings.h b/src/libstrongswan/settings.h
index 70aa96fb5..ad66fed58 100644
--- a/src/libstrongswan/settings.h
+++ b/src/libstrongswan/settings.h
@@ -28,6 +28,46 @@ typedef struct settings_t settings_t;
#include "utils/enumerator.h"
/**
+ * Convert a string value returned by a key/value enumerator to a boolean.
+ *
+ * @see settings_t.create_key_value_enumerator()
+ * @see settings_t.get_bool()
+ * @param value the string value
+ * @param def the default value, if value is NULL or invalid
+ */
+bool settings_value_as_bool(char *value, bool def);
+
+/**
+ * Convert a string value returned by a key/value enumerator to an integer.
+ *
+ * @see settings_t.create_key_value_enumerator()
+ * @see settings_t.get_int()
+ * @param value the string value
+ * @param def the default value, if value is NULL or invalid
+ */
+int settings_value_as_int(char *value, int def);
+
+/**
+ * Convert a string value returned by a key/value enumerator to a double.
+ *
+ * @see settings_t.create_key_value_enumerator()
+ * @see settings_t.get_double()
+ * @param value the string value
+ * @param def the default value, if value is NULL or invalid
+ */
+double settings_value_as_double(char *value, double def);
+
+/**
+ * Convert a string value returned by a key/value enumerator to a time value.
+ *
+ * @see settings_t.create_key_value_enumerator()
+ * @see settings_t.get_time()
+ * @param value the string value
+ * @param def the default value, if value is NULL or invalid
+ */
+u_int32_t settings_value_as_time(char *value, u_int32_t def);
+
+/**
* Generic configuration options read from a config file.
*
* The syntax is quite simple:
@@ -167,7 +207,7 @@ struct settings_t {
* Create an enumerator over key/value pairs in a section.
*
* @param section section name to list key/value pairs of, printf style
- * @param ... argmuent list for section
+ * @param ... argument list for section
* @return enumerator over (char *key, char *value)
*/
enumerator_t* (*create_key_value_enumerator)(settings_t *this,