summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/common.c b/common.c
index d233b5e..b887135 100644
--- a/common.c
+++ b/common.c
@@ -675,7 +675,7 @@ config_item_string_array (const struct str *s)
static struct config_item_ *
config_item_object (void)
{
- struct config_item_ *self = config_item_new (CONFIG_ITEM_BOOLEAN);
+ struct config_item_ *self = config_item_new (CONFIG_ITEM_OBJECT);
str_map_init (&self->value.object);
self->value.object.free = (void (*)(void *)) config_item_destroy;
return self;
@@ -1150,26 +1150,6 @@ config_tokenizer_next (struct config_tokenizer *self, struct error **e)
}
}
- bool is_word = false;
- while (config_tokenizer_is_word_char (*self->p))
- {
- is_word = true;
- str_reset (&self->string);
- str_append_c (&self->string, config_tokenizer_advance (self));
- }
- if (is_word)
- {
- if (!strcmp (self->string.str, "null"))
- return CONFIG_T_NULL;
-
- bool boolean;
- if (!set_boolean_if_valid (&boolean, self->string.str))
- return CONFIG_T_WORD;
-
- self->integer = boolean;
- return CONFIG_T_BOOLEAN;
- }
-
char *end;
errno = 0;
self->integer = strtoll (self->p, &end, 10);
@@ -1185,8 +1165,26 @@ config_tokenizer_next (struct config_tokenizer *self, struct error **e)
return CONFIG_T_INTEGER;
}
- config_tokenizer_error (self, e, "invalid input");
- return CONFIG_T_ABORT;
+ if (!config_tokenizer_is_word_char (*self->p))
+ {
+ config_tokenizer_error (self, e, "invalid input");
+ return CONFIG_T_ABORT;
+ }
+
+ str_reset (&self->string);
+ do
+ str_append_c (&self->string, config_tokenizer_advance (self));
+ while (config_tokenizer_is_word_char (*self->p));
+
+ if (!strcmp (self->string.str, "null"))
+ return CONFIG_T_NULL;
+
+ bool boolean;
+ if (!set_boolean_if_valid (&boolean, self->string.str))
+ return CONFIG_T_WORD;
+
+ self->integer = boolean;
+ return CONFIG_T_BOOLEAN;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -1436,14 +1434,18 @@ config_schema_fix_value
if (replace)
{
struct error *e = NULL;
- struct config_item_ *default_ = config_item_parse
- (schema->default_, strlen (schema->default_), true, &e);
- if (e || !config_item_validate_by_schema (default_, schema, &e))
+ if (schema->default_)
+ item = config_item_parse
+ (schema->default_, strlen (schema->default_), true, &e);
+ else
+ item = config_item_null ();
+
+ if (e || !config_item_validate_by_schema (item, schema, &e))
exit_fatal ("invalid default for `%s': %s",
schema->name, e->message);
- config_item_move (item, default_);
- str_map_set (&object->value.object, schema->name, default_);
+ // This will free the old item if there was any
+ str_map_set (&object->value.object, schema->name, item);
}
// Make sure the string subtype fits the schema
@@ -1531,6 +1533,7 @@ static void
config_load (struct config *self, struct config_item_ *root)
{
hard_assert (root->type == CONFIG_ITEM_OBJECT);
+ self->root = root;
struct str_map_iter iter;
str_map_iter_init (&iter, &self->modules);