mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
Use config_new() to construct configuration objects.
We'll need to do it this way once the objects become more complex.
This commit is contained in:
parent
a1b2817abe
commit
57e87cc86c
@ -5404,8 +5404,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
|||||||
oldoptions = global_options; /* get_options unfortunately asserts if
|
oldoptions = global_options; /* get_options unfortunately asserts if
|
||||||
this is the first time we run*/
|
this is the first time we run*/
|
||||||
|
|
||||||
newoptions = tor_malloc_zero(sizeof(or_options_t));
|
newoptions = options_new();
|
||||||
newoptions->magic_ = OR_OPTIONS_MAGIC;
|
|
||||||
options_init(newoptions);
|
options_init(newoptions);
|
||||||
newoptions->command = command;
|
newoptions->command = command;
|
||||||
newoptions->command_arg = command_arg ? tor_strdup(command_arg) : NULL;
|
newoptions->command_arg = command_arg ? tor_strdup(command_arg) : NULL;
|
||||||
|
@ -376,8 +376,7 @@ or_state_save_broken(char *fname)
|
|||||||
STATIC or_state_t *
|
STATIC or_state_t *
|
||||||
or_state_new(void)
|
or_state_new(void)
|
||||||
{
|
{
|
||||||
or_state_t *new_state = tor_malloc_zero(sizeof(or_state_t));
|
or_state_t *new_state = config_new(get_state_mgr());
|
||||||
new_state->magic_ = OR_STATE_MAGIC;
|
|
||||||
config_init(get_state_mgr(), new_state);
|
config_init(get_state_mgr(), new_state);
|
||||||
|
|
||||||
return new_state;
|
return new_state;
|
||||||
|
@ -285,9 +285,8 @@ disk_state_free_(sr_disk_state_t *state)
|
|||||||
static sr_disk_state_t *
|
static sr_disk_state_t *
|
||||||
disk_state_new(time_t now)
|
disk_state_new(time_t now)
|
||||||
{
|
{
|
||||||
sr_disk_state_t *new_state = tor_malloc_zero(sizeof(*new_state));
|
sr_disk_state_t *new_state = config_new(get_srs_mgr());
|
||||||
|
|
||||||
new_state->magic_ = SR_DISK_STATE_MAGIC;
|
|
||||||
new_state->Version = SR_PROTO_VERSION;
|
new_state->Version = SR_PROTO_VERSION;
|
||||||
new_state->TorVersion = tor_strdup(get_version());
|
new_state->TorVersion = tor_strdup(get_version());
|
||||||
new_state->ValidUntil = get_state_valid_until_time(now);
|
new_state->ValidUntil = get_state_valid_until_time(now);
|
||||||
@ -599,11 +598,12 @@ disk_state_reset(void)
|
|||||||
config_free_lines(sr_disk_state->ExtraLines);
|
config_free_lines(sr_disk_state->ExtraLines);
|
||||||
tor_free(sr_disk_state->TorVersion);
|
tor_free(sr_disk_state->TorVersion);
|
||||||
|
|
||||||
/* Clean up the struct */
|
/* Clear other fields. */
|
||||||
memset(sr_disk_state, 0, sizeof(*sr_disk_state));
|
sr_disk_state->ValidAfter = 0;
|
||||||
|
sr_disk_state->ValidUntil = 0;
|
||||||
|
sr_disk_state->Version = 0;
|
||||||
|
|
||||||
/* Reset it with useful data */
|
/* Reset it with useful data */
|
||||||
sr_disk_state->magic_ = SR_DISK_STATE_MAGIC;
|
|
||||||
sr_disk_state->TorVersion = tor_strdup(get_version());
|
sr_disk_state->TorVersion = tor_strdup(get_version());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ global_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set up the options. */
|
/* set up the options. */
|
||||||
mock_options = tor_malloc_zero(sizeof(or_options_t));
|
mock_options = options_new();
|
||||||
MOCK(get_options, mock_get_options);
|
MOCK(get_options, mock_get_options);
|
||||||
|
|
||||||
/* Make BUG() and nonfatal asserts crash */
|
/* Make BUG() and nonfatal asserts crash */
|
||||||
|
@ -1762,7 +1762,7 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
/* allocate options */
|
/* allocate options */
|
||||||
or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
|
or_options_t *options = options_new();
|
||||||
|
|
||||||
/* Allocate and populate configuration lines:
|
/* Allocate and populate configuration lines:
|
||||||
*
|
*
|
||||||
@ -3533,7 +3533,7 @@ test_config_default_dir_servers(void *arg)
|
|||||||
int fallback_count = 0;
|
int fallback_count = 0;
|
||||||
|
|
||||||
/* new set of options should stop fallback parsing */
|
/* new set of options should stop fallback parsing */
|
||||||
opts = tor_malloc_zero(sizeof(or_options_t));
|
opts = options_new();
|
||||||
opts->UseDefaultFallbackDirs = 0;
|
opts->UseDefaultFallbackDirs = 0;
|
||||||
/* set old_options to NULL to force dir update */
|
/* set old_options to NULL to force dir update */
|
||||||
consider_adding_dir_servers(opts, NULL);
|
consider_adding_dir_servers(opts, NULL);
|
||||||
@ -3547,7 +3547,7 @@ test_config_default_dir_servers(void *arg)
|
|||||||
/* if we disable the default fallbacks, there must not be any extra */
|
/* if we disable the default fallbacks, there must not be any extra */
|
||||||
tt_assert(fallback_count == trusted_count);
|
tt_assert(fallback_count == trusted_count);
|
||||||
|
|
||||||
opts = tor_malloc_zero(sizeof(or_options_t));
|
opts = options_new();
|
||||||
opts->UseDefaultFallbackDirs = 1;
|
opts->UseDefaultFallbackDirs = 1;
|
||||||
consider_adding_dir_servers(opts, opts);
|
consider_adding_dir_servers(opts, opts);
|
||||||
trusted_count = smartlist_len(router_get_trusted_dir_servers());
|
trusted_count = smartlist_len(router_get_trusted_dir_servers());
|
||||||
@ -3607,7 +3607,7 @@ test_config_directory_fetch(void *arg)
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
/* Test Setup */
|
/* Test Setup */
|
||||||
or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
|
or_options_t *options = options_new();
|
||||||
routerinfo_t routerinfo;
|
routerinfo_t routerinfo;
|
||||||
memset(&routerinfo, 0, sizeof(routerinfo));
|
memset(&routerinfo, 0, sizeof(routerinfo));
|
||||||
mock_router_pick_published_address_result = -1;
|
mock_router_pick_published_address_result = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user