From a114df9a040dbdedfc89f7d2ff777476e204a2cf Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 19 Jun 2019 16:06:15 -0400 Subject: [PATCH] Add a function to make sure all values in a config object are ok --- src/app/config/confparse.c | 18 ++++++++++++++++++ src/app/config/confparse.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c index b9b5fddb96..2890d8c81b 100644 --- a/src/app/config/confparse.c +++ b/src/app/config/confparse.c @@ -673,3 +673,21 @@ config_dump(const config_format_t *fmt, const void *default_options, } return result; } + +/** + * Return true if every member of options is in-range and well-formed. + * Return false otherwise. Log errors at level severity. + */ +bool +config_check_ok(const config_format_t *fmt, const void *options, int severity) +{ + bool all_ok = true; + for (int i=0; fmt->vars[i].member.name; ++i) { + if (!struct_var_ok(options, &fmt->vars[i].member)) { + log_fn(severity, LD_BUG, "Invalid value for %s", + fmt->vars[i].member.name); + all_ok = false; + } + } + return all_ok; +} diff --git a/src/app/config/confparse.h b/src/app/config/confparse.h index 4ef4e708f3..b91ea1c13d 100644 --- a/src/app/config/confparse.h +++ b/src/app/config/confparse.h @@ -138,6 +138,8 @@ void *config_dup(const config_format_t *fmt, const void *old); char *config_dump(const config_format_t *fmt, const void *default_options, const void *options, int minimal, int comment_defaults); +bool config_check_ok(const config_format_t *fmt, const void *options, + int severity); int config_assign(const config_format_t *fmt, void *options, struct config_line_t *list, unsigned flags, char **msg);