diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-11-05 10:18:47 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-11-07 07:28:43 -0500 |
commit | 0f0a9bdf332002bb0542dae6bb00e922af5dcf63 (patch) | |
tree | 4a25bc3928f62bd08c49c55ff1345db5fa8b91f6 /src/lib | |
parent | 0d8504e70b0c6ff92f38fc7f4b4c38037d121e69 (diff) | |
download | tor-0f0a9bdf332002bb0542dae6bb00e922af5dcf63.tar.gz tor-0f0a9bdf332002bb0542dae6bb00e922af5dcf63.zip |
Stop using "config_suite_offset=-1" to indicate "no config suite."
Instead, create a separate "has_config_suite" boolean, so that only
top-level formats with config_suites need to declare an offset at
all.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/conf/conftypes.h | 10 | ||||
-rw-r--r-- | src/lib/confmgt/confmgt.c | 9 | ||||
-rw-r--r-- | src/lib/crypt_ops/crypto_init.c | 1 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h index d4e2ea218a..dfe51cfba1 100644 --- a/src/lib/conf/conftypes.h +++ b/src/lib/conf/conftypes.h @@ -335,8 +335,14 @@ typedef struct config_format_t { /** If present, extra denotes a LINELIST variable for unrecognized * lines. Otherwise, unrecognized lines are an error. */ const struct_member_t *extra; - /** The position of a config_suite_t pointer within the toplevel object, - * or -1 if there is no such pointer. */ + /** + * If true, this format describes a top-level configuration, with + * a suite containing multiple sub-configuration objects. + */ + bool has_config_suite; + /** The position of a config_suite_t pointer within the toplevel object. + * Ignored unless have_config_suite is true. + */ ptrdiff_t config_suite_offset; } config_format_t; diff --git a/src/lib/confmgt/confmgt.c b/src/lib/confmgt/confmgt.c index 1c1a1595ec..a96c7f96bf 100644 --- a/src/lib/confmgt/confmgt.c +++ b/src/lib/confmgt/confmgt.c @@ -169,9 +169,14 @@ config_mgr_register_fmt(config_mgr_t *mgr, "it had been frozen."); if (object_idx != IDX_TOPLEVEL) { - tor_assertf(fmt->config_suite_offset < 0, + tor_assertf(! fmt->has_config_suite, "Tried to register a toplevel format in a non-toplevel position"); } + if (fmt->config_suite_offset) { + tor_assertf(fmt->has_config_suite, + "config_suite_offset was set, but has_config_suite was not."); + } + tor_assertf(fmt != mgr->toplevel && ! smartlist_contains(mgr->subconfigs, fmt), "Tried to register an already-registered format."); @@ -223,7 +228,7 @@ config_mgr_add_format(config_mgr_t *mgr, static inline config_suite_t ** config_mgr_get_suite_ptr(const config_mgr_t *mgr, void *toplevel) { - if (mgr->toplevel->config_suite_offset < 0) + if (! mgr->toplevel->has_config_suite) return NULL; return STRUCT_VAR_P(toplevel, mgr->toplevel->config_suite_offset); } diff --git a/src/lib/crypt_ops/crypto_init.c b/src/lib/crypt_ops/crypto_init.c index 4b08456197..fbd4da4704 100644 --- a/src/lib/crypt_ops/crypto_init.c +++ b/src/lib/crypt_ops/crypto_init.c @@ -293,7 +293,6 @@ static const config_format_t crypto_options_fmt = { offsetof(crypto_options_t, magic) }, .vars = crypto_options_t_vars, .validate_fn = crypto_options_validate, - .config_suite_offset = -1, }; /** |