Support enumeration of key/value pairs in a section of strongswan.conf
This commit is contained in:
@@ -324,6 +324,39 @@ static enumerator_t* create_section_enumerator(private_settings_t *this,
|
|||||||
(void*)section_filter, NULL, NULL);
|
(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
|
* 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_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.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_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->public.destroy = (void(*)(settings_t*))destroy;
|
||||||
|
|
||||||
this->top = NULL;
|
this->top = NULL;
|
||||||
|
|||||||
@@ -103,6 +103,17 @@ struct settings_t {
|
|||||||
*/
|
*/
|
||||||
enumerator_t* (*create_section_enumerator)(settings_t *this,
|
enumerator_t* (*create_section_enumerator)(settings_t *this,
|
||||||
char *section, ...);
|
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.
|
* Destroy a settings instance.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user