]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Support enumeration of key/value pairs in a section of strongswan.conf
authorMartin Willi <martin@strongswan.org>
Tue, 17 Nov 2009 15:52:36 +0000 (15:52 +0000)
committerMartin Willi <martin@strongswan.org>
Tue, 17 Nov 2009 15:52:36 +0000 (15:52 +0000)
src/libstrongswan/settings.c
src/libstrongswan/settings.h

index d0937dd52b6c19d41df96a1c9aadf5d492c02c0c..e961c78d8ef79c043a7dcdf0516aaead29beb72a 100644 (file)
@@ -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;
index 7a28225d39ecd775ea6255b61c699adb8f985eec..a032c5cd96a30418e6e0e6b457e7d7451c67d84d 100644 (file)
@@ -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.
         */