diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-07-23 11:32:52 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-08-28 09:40:53 -0400 |
commit | 38b770bbbb37aef6cd3cef5fd6f425cd951affe2 (patch) | |
tree | 65a613a67a7f9baf09c4f8cdcbe1e7efb8b613bb | |
parent | 47654d32497acae23aafbe3316ae73d3c00429c8 (diff) | |
download | tor-38b770bbbb37aef6cd3cef5fd6f425cd951affe2.tar.gz tor-38b770bbbb37aef6cd3cef5fd6f425cd951affe2.zip |
Make a config_suite_t type to hold multiple config sub-objects
Right now, it doesn't do anything; this patch is meant to make sure
that we're doing memory management correctly.
-rw-r--r-- | src/app/config/config.c | 1 | ||||
-rw-r--r-- | src/app/config/confparse.c | 49 | ||||
-rw-r--r-- | src/app/config/confparse.h | 6 | ||||
-rw-r--r-- | src/app/config/or_options_st.h | 4 | ||||
-rw-r--r-- | src/app/config/or_state_st.h | 4 | ||||
-rw-r--r-- | src/app/config/statefile.c | 1 | ||||
-rw-r--r-- | src/feature/dirauth/shared_random_state.c | 1 | ||||
-rw-r--r-- | src/test/test_confparse.c | 2 |
8 files changed, 68 insertions, 0 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c index cdf5fa266c..bff403a990 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -864,6 +864,7 @@ static const config_format_t options_format = { options_validate_cb, options_clear_cb, NULL, + offsetof(or_options_t, subconfigs_), }; /* diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c index 8e3ad7fafd..d94a1d9ec9 100644 --- a/src/app/config/confparse.c +++ b/src/app/config/confparse.c @@ -72,6 +72,36 @@ managed_var_free_(managed_var_t *mv) #define managed_var_free(mv) \ FREE_AND_NULL(managed_var_t, managed_var_free_, (mv)) +struct config_suite_t { + /* NOTE: This object isn't implemented yet; it's just a placeholder + * to make sure we have our memory menagement right. + */ + int foo; +}; + +/** + * Allocate a new empty config_suite_t. + **/ +static config_suite_t * +config_suite_new(void) +{ + config_suite_t *suite = tor_malloc_zero(sizeof(config_suite_t)); + return suite; +} + +/** Release all storage held by a config_suite_t. (Does not free + * any configuration objects it holds; the caller must do that first.) */ +static void +config_suite_free_(config_suite_t *suite) +{ + if (!suite) + return; + tor_free(suite); +} + +#define config_suite_free(suite) \ + FREE_AND_NULL(config_suite_t, config_suite_free_, (suite)) + struct config_mgr_t { /** The 'top-level' configuration format. This one is used for legacy * options that have not yet been assigned to different sub-modules. @@ -152,6 +182,16 @@ config_mgr_register_fmt(config_mgr_t *mgr, } } +/** Return a pointer to the config_suite_t * pointer inside a + * configuration object; returns NULL if there is no such member. */ +static inline config_suite_t ** +config_mgr_get_suite_ptr(const config_mgr_t *mgr, void *toplevel) +{ + if (mgr->toplevel->config_suite_offset < 0) + return NULL; + return STRUCT_VAR_P(toplevel, mgr->toplevel->config_suite_offset); +} + /** * Return a pointer to the configuration object within <b>toplevel</b> whose * index is <b>idx</b>. @@ -272,6 +312,10 @@ config_new(const config_mgr_t *mgr) const config_format_t *fmt = mgr->toplevel; void *opts = tor_malloc_zero(fmt->size); struct_set_magic(opts, &mgr->toplevel_magic); + config_suite_t **suitep = config_mgr_get_suite_ptr(mgr, opts); + if (suitep) { + *suitep = config_suite_new(); + } CONFIG_CHECK(mgr, opts); return opts; } @@ -802,6 +846,11 @@ config_free_(const config_mgr_t *mgr, void *options) config_free_lines(*linep); *linep = NULL; } + + config_suite_t **suitep = config_mgr_get_suite_ptr(mgr, options); + if (suitep) + config_suite_free(*suitep); + tor_free(options); } diff --git a/src/app/config/confparse.h b/src/app/config/confparse.h index 2e1a4b4f57..c18e854237 100644 --- a/src/app/config/confparse.h +++ b/src/app/config/confparse.h @@ -61,6 +61,9 @@ 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. */ + int config_suite_offset; } config_format_t; /** @@ -79,6 +82,9 @@ void config_mgr_freeze(config_mgr_t *mgr); struct smartlist_t *config_mgr_list_vars(const config_mgr_t *mgr); struct smartlist_t *config_mgr_list_deprecated_vars(const config_mgr_t *mgr); +/** A collection of managed configuration objects. */ +typedef struct config_suite_t config_suite_t; + #define CAL_USE_DEFAULTS (1u<<0) #define CAL_CLEAR_FIRST (1u<<1) #define CAL_WARN_DEPRECATIONS (1u<<2) diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h index 8156d2ca11..2c1a8f0c00 100644 --- a/src/app/config/or_options_st.h +++ b/src/app/config/or_options_st.h @@ -18,6 +18,7 @@ struct smartlist_t; struct config_line_t; +struct config_suite_t; /** Enumeration of outbound address configuration types: * Exit-only, OR-only, or both */ @@ -1107,6 +1108,9 @@ struct or_options_t { * a possible previous dormant state. **/ int DormantCanceledByStartup; + + /**DOCDOC*/ + struct config_suite_t *subconfigs_; }; #endif /* !defined(TOR_OR_OPTIONS_ST_H) */ diff --git a/src/app/config/or_state_st.h b/src/app/config/or_state_st.h index f45c6196cc..54390fa2d2 100644 --- a/src/app/config/or_state_st.h +++ b/src/app/config/or_state_st.h @@ -15,6 +15,7 @@ #include "lib/cc/torint.h" struct smartlist_t; +struct config_suite_t; /** Persistent state for an onion router, as saved to disk. */ struct or_state_t { @@ -94,6 +95,9 @@ struct or_state_t { /** True if we were dormant when we last wrote the file; false if we * weren't. "auto" on initial startup. */ int Dormant; + + /**DOCDOC*/ + struct config_suite_t *substates_; }; #endif /* !defined(TOR_OR_STATE_ST_H) */ diff --git a/src/app/config/statefile.c b/src/app/config/statefile.c index ede35e6ced..bcc06809b3 100644 --- a/src/app/config/statefile.c +++ b/src/app/config/statefile.c @@ -170,6 +170,7 @@ static const config_format_t state_format = { or_state_validate_cb, NULL, &state_extra_var, + offsetof(or_state_t, substates_), }; /* A global configuration manager for state-file objects */ diff --git a/src/feature/dirauth/shared_random_state.c b/src/feature/dirauth/shared_random_state.c index fac1efc54d..f2a626c738 100644 --- a/src/feature/dirauth/shared_random_state.c +++ b/src/feature/dirauth/shared_random_state.c @@ -100,6 +100,7 @@ static const config_format_t state_format = { disk_state_validate_cb, NULL, &state_extra_var, + -1, }; /* Global configuration manager for the shared-random state file */ diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c index 273232fe5d..eaa257aedd 100644 --- a/src/test/test_confparse.c +++ b/src/test/test_confparse.c @@ -134,6 +134,7 @@ static const config_format_t test_fmt = { test_validate_cb, NULL, NULL, + -1, }; /* Make sure that config_init sets everything to the right defaults. */ @@ -815,6 +816,7 @@ static config_format_t etest_fmt = { test_validate_cb, NULL, &extra, + -1, }; /* Try out the feature where we can store unrecognized lines and dump them |