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") ||
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;
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;
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;
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
*/
#include "utils.h"
#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.
*
* 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,