diff options
author | Martin Willi <martin@revosec.ch> | 2011-04-21 10:10:26 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-04-21 10:10:26 +0200 |
commit | 17ce69b47a1efd6234960cf7d1f50712aee61db5 (patch) | |
tree | a8d5ae3aa63090a0e031f96a097e52f4cbab6e1a /src/libstrongswan/settings.c | |
parent | 6d41218ced77cc4c72d399d5642e5e3f9524cd24 (diff) | |
download | strongswan-17ce69b47a1efd6234960cf7d1f50712aee61db5.tar.bz2 strongswan-17ce69b47a1efd6234960cf7d1f50712aee61db5.tar.xz |
Added a thread save, allocating settings get_str variant called alloc_str
Diffstat (limited to 'src/libstrongswan/settings.c')
-rw-r--r-- | src/libstrongswan/settings.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c index 8a2248b46..395ae65e3 100644 --- a/src/libstrongswan/settings.c +++ b/src/libstrongswan/settings.c @@ -444,6 +444,25 @@ METHOD(settings_t, get_str, char*, return def; } +METHOD(settings_t, alloc_str, char*, + private_settings_t *this, char *key, char *def, ...) +{ + char *value; + va_list args; + + va_start(args, def); + /* additional lock to savely strdup */ + this->lock->read_lock(this->lock); + value = strdupnull(find_value(this, this->top, key, args)); + this->lock->unlock(this->lock); + va_end(args); + if (value) + { + return value; + } + return def; +} + /** * Described in header */ @@ -1192,6 +1211,7 @@ settings_t *settings_create(char *file) INIT(this, .public = { .get_str = _get_str, + .alloc_str = _alloc_str, .get_int = _get_int, .get_double = _get_double, .get_time = _get_time, |