aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-12-28 04:01:58 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-12-28 04:03:34 +0100
commit2d8a8e0b1b7034abe5efc81f86d7f67775621577 (patch)
tree4565de8191bcf83dd5f735b7c368de2f4fb96cd4
parenta4313ee4b93b8bbc75eb8d641cb895be4dcf0c8a (diff)
downloadliberty-2d8a8e0b1b7034abe5efc81f86d7f67775621577.tar.gz
liberty-2d8a8e0b1b7034abe5efc81f86d7f67775621577.tar.xz
liberty-2d8a8e0b1b7034abe5efc81f86d7f67775621577.zip
Make config_schema_initialize_item more useful
By also allowing it to set the user_data member.
-rw-r--r--liberty.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/liberty.c b/liberty.c
index 86b5698..eb7c053 100644
--- a/liberty.c
+++ b/liberty.c
@@ -4707,32 +4707,38 @@ config_item_clone (struct config_item *self)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/// "user_data" is passed so that it be immediately used by validation callbacks
static struct config_item *
config_schema_initialize_item (struct config_schema *schema,
- struct config_item *parent, struct error **warning, struct error **e)
+ struct config_item *parent, void *user_data, struct error **warning,
+ struct error **e)
{
hard_assert (parent->type == CONFIG_ITEM_OBJECT);
struct config_item *item =
str_map_find (&parent->value.object, schema->name);
- struct error *error = NULL;
- if (item && config_item_validate_by_schema (item, schema, &error))
- goto keep_current;
-
- if (error)
+ if (item)
{
+ struct error *error = NULL;
+ item->user_data = user_data;
+ if (config_item_validate_by_schema (item, schema, &error))
+ goto keep_current;
+
error_set (warning, "resetting configuration item "
"`%s' to default: %s", schema->name, error->message);
error_free (error);
- error = NULL;
}
+ struct error *error = NULL;
if (schema->default_)
item = config_item_parse
(schema->default_, strlen (schema->default_), true, &error);
else
item = config_item_null ();
+ if (item)
+ item->user_data = user_data;
+
if (error || !config_item_validate_by_schema (item, schema, &error))
{
error_set (e, "invalid default for configuration item `%s': %s",
@@ -4765,8 +4771,8 @@ config_schema_apply_to_object (struct config_schema *schema_array,
while (schema_array->name)
{
struct error *warning = NULL, *e = NULL;
- struct config_item *item = config_schema_initialize_item
- (schema_array++, object, &warning, &e);
+ config_schema_initialize_item
+ (schema_array++, object, user_data, &warning, &e);
if (warning)
{
@@ -4775,8 +4781,6 @@ config_schema_apply_to_object (struct config_schema *schema_array,
}
if (e)
print_fatal ("%s", e->message);
-
- item->user_data = user_data;
}
}