aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/config.c b/src/config.c
index d89bdde..c9543b7 100644
--- a/src/config.c
+++ b/src/config.c
@@ -9,7 +9,7 @@
#include "config.h"
#include "util.h"
#include "block.h"
-#include "blocks/scheme.h"
+#include "block.h"
#define ANY_INI_IMPLEMENT
#include "any_ini.h"
@@ -355,12 +355,12 @@ static block_t *config_alloc_block(config_t *config, const block_scheme_t *schem
config->blocks = realloc(config->blocks, ++config->n_blocks * sizeof(block_t *));
assert(config->blocks != NULL);
- config->blocks[config->n_blocks - 1] = calloc(1, scheme->size);
+ config->blocks[config->n_blocks - 1] = scheme->alloc_fn(scheme);
block_t *block = config->blocks[config->n_blocks - 1];
assert(block != NULL);
- memcpy(block, &scheme->block, sizeof(block_t));
block->label = label;
+ block->scheme = scheme;
return block;
}
@@ -516,32 +516,34 @@ skip_pair:
free(value);
}
- if (block != NULL && scheme != NULL && scheme->validate != NULL) {
+ if (block != NULL && scheme != NULL && scheme->validate_fn != NULL) {
if (errors != 0)
log_trace("Skipped validation for block '%s'", section);
- else
- errors += !scheme->validate(block, scheme);
+ else {
+ block->validated = scheme->validate_fn(block, scheme);
+ errors += !block->validated;
+ }
}
free(section);
n_errors += errors;
} while ((section = any_ini_stream_next_section(&ini)) != NULL);
- if (n_errors > 0)
- log_panic("Config file contained %d errors", n_errors);
+ if (n_errors > 0) {
+ log_error("Config file contained %d errors", n_errors);
+ exit(EXIT_FAILURE);
+ }
}
bool config_resolve_children(config_t *config, block_t *block)
{
block->resolved = true;
- if (block->type == BLOCK_TEXT)
- return true;
+ if (block->scheme != NULL && block->scheme->resolve_fn != NULL)
+ return block->scheme->resolve_fn(block, config);
- if (block->type == BLOCK_SPEC) {
- block_spec_t *spec = (block_spec_t *)block;
- return spec->resolve_fn == NULL || spec->resolve_fn(block, config);
- }
+ if (block->type != BLOCK_GROUP)
+ return true;
assert(block->type == BLOCK_GROUP);
block_group_t *group = (block_group_t *)block;
@@ -600,8 +602,10 @@ block_t *config_resolve(config_t *config)
errors += !config_resolve_children(config, config->blocks[0]);
}
- if (errors > 0)
- log_panic("Config could not be resolved");
+ if (errors > 0) {
+ log_error("Config could not be resolved");
+ exit(EXIT_FAILURE);
+ }
return config->blocks[0];
}