From: Martin Willi Date: Tue, 17 Nov 2009 15:52:36 +0000 (+0000) Subject: Support enumeration of key/value pairs in a section of strongswan.conf X-Git-Tag: 4.3.6~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3797b8e767a247f64a706b0a4dc8656e8377fbab;p=thirdparty%2Fstrongswan.git Support enumeration of key/value pairs in a section of strongswan.conf --- diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c index d0937dd52b..e961c78d8e 100644 --- a/src/libstrongswan/settings.c +++ b/src/libstrongswan/settings.c @@ -324,6 +324,39 @@ static enumerator_t* create_section_enumerator(private_settings_t *this, (void*)section_filter, NULL, NULL); } +/** + * Enumerate key and values, not kv_t entries + */ +static bool kv_filter(void *null, kv_t **in, char **key, + void *none, char **value) +{ + *key = (*in)->key; + *value = (*in)->value; + return TRUE; +} + +/** + * Implementation of settings_t.create_key_value_enumerator + */ +static enumerator_t* create_key_value_enumerator(private_settings_t *this, + char *key, ...) +{ + section_t *section; + va_list args; + + va_start(args, key); + section = find_section(this->top, key, args); + va_end(args); + + if (!section) + { + return enumerator_create_empty(); + } + return enumerator_create_filter( + section->kv->create_enumerator(section->kv), + (void*)kv_filter, NULL, NULL); +} + /** * destroy a section */ @@ -495,6 +528,7 @@ settings_t *settings_create(char *file) 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; + this->public.create_key_value_enumerator = (enumerator_t*(*)(settings_t*, char *key, ...))create_key_value_enumerator; this->public.destroy = (void(*)(settings_t*))destroy; this->top = NULL; diff --git a/src/libstrongswan/settings.h b/src/libstrongswan/settings.h index 7a28225d39..a032c5cd96 100644 --- a/src/libstrongswan/settings.h +++ b/src/libstrongswan/settings.h @@ -103,6 +103,17 @@ struct settings_t { */ enumerator_t* (*create_section_enumerator)(settings_t *this, char *section, ...); + + /** + * 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 + * @return enumerator over (char *key, char *value) + */ + enumerator_t* (*create_key_value_enumerator)(settings_t *this, + char *section, ...); + /** * Destroy a settings instance. */