diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/block.h | 5 | ||||
| -rw-r--r-- | src/blocks/date.c | 8 | ||||
| -rw-r--r-- | src/blocks/fs.c | 31 | ||||
| -rw-r--r-- | src/blocks/group.c | 1 | ||||
| -rw-r--r-- | src/blocks/ram.c | 29 | ||||
| -rw-r--r-- | src/blocks/script.c | 8 | ||||
| -rw-r--r-- | src/blocks/text.c | 8 | ||||
| -rw-r--r-- | src/config.c | 7 |
8 files changed, 44 insertions, 53 deletions
diff --git a/src/block.h b/src/block.h index 09ef3fc..c12cea6 100644 --- a/src/block.h +++ b/src/block.h @@ -104,9 +104,7 @@ typedef void (*block_clean_t)(block_t *block); // Called to validate the block after parsing the config // -typedef bool (*block_validate_t)(block_t *block, const block_scheme_t *scheme); - -typedef bool (*block_resolve_t)(block_t *block, config_t *config); +typedef int (*block_validate_t)(block_t *block, const block_scheme_t *scheme); struct block_scheme { const char *name; @@ -114,7 +112,6 @@ struct block_scheme { block_alloc_t alloc_fn; block_clean_t clean_fn; block_validate_t validate_fn; - block_resolve_t resolve_fn; }; extern const block_scheme_t *block_schemes[]; diff --git a/src/blocks/date.c b/src/blocks/date.c index 17441a6..4fcdb2a 100644 --- a/src/blocks/date.c +++ b/src/blocks/date.c @@ -47,18 +47,19 @@ static void block_date_clean(block_t *block) free(date->block.text); } -static bool block_date_validate(block_t *block, const block_scheme_t *scheme) +static int block_date_validate(block_t *block, const block_scheme_t *scheme) { block_date_t *date = (block_date_t *)block; + int errors = 0; if (date->block.text == NULL) { log_error("Block '%s' requires key '%s'", block->label, "text"); - return false; + errors++; } date->format = date->block.text; date->block.text = strcopy("?"); - return true; + return errors; } const block_scheme_t block_date_scheme = { @@ -67,5 +68,4 @@ const block_scheme_t block_date_scheme = { .alloc_fn = block_date_alloc, .clean_fn = block_date_clean, .validate_fn = block_date_validate, - .resolve_fn = NULL, }; diff --git a/src/blocks/fs.c b/src/blocks/fs.c index 188f14a..7163cc5 100644 --- a/src/blocks/fs.c +++ b/src/blocks/fs.c @@ -110,40 +110,40 @@ static void block_fs_clean(block_t *block) free(fs->block.text); } -static bool block_fs_validate(block_t *block, const block_scheme_t *scheme) +static int block_fs_validate(block_t *block, const block_scheme_t *scheme) { block_fs_t *fs = (block_fs_t *)block; + int errors = 0; if (fs->block.text == NULL) { log_error("Block '%s' requires key '%s'", block->label, "text"); - return false; + errors++; } if (!format_init(&fs->format, fs->block.text, '%')) { log_error("Block '%s' has an invalid format", block->label); - return false; - } - - int marked = format_remark(&fs->format, block->label, block_fs_options); - if (marked < 0) - return false; + errors++; + } else { + int marked = format_remark(&fs->format, block->label, block_fs_options); + if (marked < 0) + errors += -marked; - if (marked == 0) { - log_warn("Block '%s' does not use any fs option", block->label); + if (marked == 0) { + log_warn("Block '%s' does not use any fs option", block->label); - block->update_fn = NULL; - log_debug("Disabled updates for block '%s'", block->label); - return true; + block->update_fn = NULL; + log_debug("Disabled updates for block '%s'", block->label); + } } struct stat sbuf; if (fs->path == NULL || stat(fs->path, &sbuf) < 0) { log_trace("Failed to read file '%s': %s", fs->path, strerror(errno)); log_error("Block '%s' was given an invalid path '%s'", block->label, fs->path); - return false; + errors++; } - return true; + return errors; } static const config_entry_t block_fs_entries[] = { @@ -157,5 +157,4 @@ const block_scheme_t block_fs_scheme = { .alloc_fn = block_fs_alloc, .clean_fn = block_fs_clean, .validate_fn = block_fs_validate, - .resolve_fn = NULL, }; diff --git a/src/blocks/group.c b/src/blocks/group.c index bf377f5..4fdff64 100644 --- a/src/blocks/group.c +++ b/src/blocks/group.c @@ -19,5 +19,4 @@ const block_scheme_t block_group_scheme = { .alloc_fn = block_group_alloc, .clean_fn = block_group_clean, .validate_fn = NULL, - .resolve_fn = NULL, }; diff --git a/src/blocks/ram.c b/src/blocks/ram.c index 4841860..8790ee3 100644 --- a/src/blocks/ram.c +++ b/src/blocks/ram.c @@ -124,33 +124,33 @@ static void block_ram_clean(block_t *block) free(ram->block.text); } -static bool block_ram_validate(block_t *block, const block_scheme_t *scheme) +static int block_ram_validate(block_t *block, const block_scheme_t *scheme) { block_ram_t *ram = (block_ram_t *)block; + int errors = 0; if (ram->block.text == NULL) { log_error("Block '%s' requires key '%s'", block->label, "text"); - return false; + errors++; } if (!format_init(&ram->format, ram->block.text, '%')) { log_error("Block '%s' has an invalid format", block->label); - return false; - } - - int marked = format_remark(&ram->format, block->label, block_ram_options); - if (marked < 0) - return false; + errors++; + } else { + int marked = format_remark(&ram->format, block->label, block_ram_options); + if (marked < 0) + errors += -marked; - if (marked == 0) { - log_warn("Block '%s' does not use any ram option", block->label); + if (marked == 0) { + log_warn("Block '%s' does not use any ram option", block->label); - block->update_fn = NULL; - log_debug("Disabled updates for block '%s'", block->label); - return true; + block->update_fn = NULL; + log_debug("Disabled updates for block '%s'", block->label); + } } - return true; + return errors; } const block_scheme_t block_ram_scheme = { @@ -159,5 +159,4 @@ const block_scheme_t block_ram_scheme = { .alloc_fn = block_ram_alloc, .clean_fn = block_ram_clean, .validate_fn = block_ram_validate, - .resolve_fn = NULL, }; diff --git a/src/blocks/script.c b/src/blocks/script.c index b2064eb..08ed9e3 100644 --- a/src/blocks/script.c +++ b/src/blocks/script.c @@ -59,18 +59,19 @@ static void block_script_clean(block_t *block) free(script->block.text); } -static bool block_script_validate(block_t *block, const block_scheme_t *scheme) +static int block_script_validate(block_t *block, const block_scheme_t *scheme) { block_script_t *script = (block_script_t *)block; + int errors = 0; if (script->block.text == NULL) { log_error("Block '%s' requires key '%s'", block->label, "text"); - return false; + errors++; } script->script = script->block.text; script->block.text = strcopy("?"); - return true; + return errors; } static const config_entry_t block_script_entries[] = { @@ -83,5 +84,4 @@ const block_scheme_t block_script_scheme = { .alloc_fn = block_script_alloc, .clean_fn = block_script_clean, .validate_fn = block_script_validate, - .resolve_fn = NULL, }; diff --git a/src/blocks/text.c b/src/blocks/text.c index 115beb0..0acb1de 100644 --- a/src/blocks/text.c +++ b/src/blocks/text.c @@ -15,16 +15,17 @@ static void block_text_clean(block_t *block) free(text->text); } -static bool block_text_validate(block_t *block, const block_scheme_t *scheme) +static int block_text_validate(block_t *block, const block_scheme_t *scheme) { block_text_t *text = (block_text_t *)block; + int errors = 0; if (text->text == NULL) { log_error("Block '%s' requires key '%s'", block->label, "text"); - return false; + errors++; } - return true; + return errors; } const block_scheme_t block_text_scheme = { @@ -33,5 +34,4 @@ const block_scheme_t block_text_scheme = { .alloc_fn = block_text_alloc, .clean_fn = block_text_clean, .validate_fn = block_text_validate, - .resolve_fn = NULL, }; diff --git a/src/config.c b/src/config.c index 615c833..32666a8 100644 --- a/src/config.c +++ b/src/config.c @@ -522,8 +522,8 @@ skip_pair: if (errors != 0) log_trace("Skipped validation for block '%s'", section); else { - block->validated = scheme->validate_fn(block, scheme); - errors += !block->validated; + errors = scheme->validate_fn(block, scheme); + block->validated = errors == 0; } } @@ -538,9 +538,6 @@ bool config_resolve_children(config_t *config, block_t *block) { block->resolved = true; - if (block->scheme != NULL && block->scheme->resolve_fn != NULL) - return block->scheme->resolve_fn(block, config); - if (block->type != BLOCK_GROUP) return true; |
