From b245a60021ef93b0157f6445aa152e808763a145 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 18 Jul 2011 08:18:37 +0000 Subject: [PATCH] aaded new function to iterate over section entries --- src/include/gnunet_configuration_lib.h | 14 +++++++++++ src/util/configuration.c | 33 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 3cdd54c8f..642bbde53 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -276,6 +276,20 @@ int GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_FileNameCallback cb, void *cb_cls); +/** + * Iterate over values of a section in the configuration. + * + * @param cfg configuration to inspect + * @param section the section + * @param iter function to call on each option + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls); + /** * Get a configuration value that should be in a set of * predefined strings diff --git a/src/util/configuration.c b/src/util/configuration.c index 978765970..88bde1c38 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -389,6 +389,39 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, } +/** + * Iterate over values of a section in the configuration. + * + * @param cfg configuration to inspect + * @param section the section + * @param iter function to call on each option + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls) +{ + struct ConfigSection *spos; + struct ConfigEntry *epos; + + spos = cfg->sections; + while ((spos != NULL) && (0 != strcmp (spos->name, section))) + spos = spos->next; + + if (spos == NULL) + return; + + epos = spos->entries; + while (epos != NULL) + { + iter (iter_cls, spos->name, epos->key, epos->val); + epos = epos->next; + } +} + + /** * Iterate over all sections in the configuration. * -- 2.25.1