From 7cffbc1b2e8361093f0b0311857df0545680611e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 2 May 2015 15:07:14 +0200 Subject: config: implement config_load() --- common.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/common.c b/common.c index 03c6356..57518d9 100644 --- a/common.c +++ b/common.c @@ -1421,7 +1421,7 @@ end: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this doesn't necessarily have to be well designed at all +// XXX: this doesn't necessarily have to be well designed at all typedef void (*config_module_load_fn) (struct config_item_ *subtree, void *user_data); @@ -1481,8 +1481,25 @@ config_register_module (struct config *self, str_map_set (&self->modules, name, module); } -static bool -config_load (struct config *self, struct config_item_ *root, struct error **e) +static void +config_load (struct config *self, struct config_item_ *root) { - // TODO + hard_assert (root->type == CONFIG_ITEM_OBJECT); + + struct str_map_iter iter; + str_map_iter_init (&iter, &self->modules); + + struct config_module *module; + while ((module = str_map_iter_next (&iter))) + { + struct config_item_ *subtree = str_map_find + (&root->value.object, module->name); + // Silently fix inputs that only a lunatic user could create + if (!subtree || subtree->type != CONFIG_ITEM_OBJECT) + { + subtree = config_item_object (); + str_map_set (&root->value.object, module->name, subtree); + } + module->loader (subtree, module->user_data); + } } -- cgit v1.2.3-70-g09d2