mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
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.
This commit is contained in:
parent
47654d3249
commit
38b770bbbb
@ -864,6 +864,7 @@ static const config_format_t options_format = {
|
||||
options_validate_cb,
|
||||
options_clear_cb,
|
||||
NULL,
|
||||
offsetof(or_options_t, subconfigs_),
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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) */
|
||||
|
@ -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) */
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user