settings: Add a set_default_str() to set a different default for a key

The value is set only if it is not configured in strongswan.conf or has
not been set() otherwise.
This commit is contained in:
Martin Willi
2013-05-06 15:28:27 +02:00
parent 3ca58c32be
commit 69333acee0
2 changed files with 31 additions and 0 deletions
+21
View File
@@ -644,6 +644,26 @@ METHOD(settings_t, set_time, void,
va_end(args);
}
METHOD(settings_t, set_default_str, bool,
private_settings_t *this, char *key, char *value, ...)
{
char *old;
va_list args;
va_start(args, value);
old = find_value(this, this->top, key, args);
va_end(args);
if (!old)
{
va_start(args, value);
set_value(this, this->top, key, args, value);
va_end(args);
return TRUE;
}
return FALSE;
}
/**
* Enumerate section names, not sections
*/
@@ -1209,6 +1229,7 @@ settings_t *settings_create(char *file)
.set_double = _set_double,
.set_time = _set_time,
.set_bool = _set_bool,
.set_default_str = _set_default_str,
.create_section_enumerator = _create_section_enumerator,
.create_key_value_enumerator = _create_key_value_enumerator,
.load_files = _load_files,
+10
View File
@@ -238,6 +238,16 @@ struct settings_t {
*/
void (*set_time)(settings_t *this, char *key, u_int32_t value, ...);
/**
* Set a default for string value.
*
* @param key key including sections, printf style format
* @param def value to set if unconfigured
* @param ... argument list for key
* @return TRUE if a new default value for key has been set
*/
bool (*set_default_str)(settings_t *this, char *key, char *value, ...);
/**
* Create an enumerator over subsection names of a section.
*