mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Add new warn_deprecated option to config_assign*().
Also, collapse all the config_assign*() options into a flags argument, since having two boolean arguments was already confusing.
This commit is contained in:
parent
f3314aa6e1
commit
f5dcab8072
@ -2186,14 +2186,13 @@ option_get_assignment(const or_options_t *options, const char *key)
|
||||
* what went wrong.
|
||||
*/
|
||||
setopt_err_t
|
||||
options_trial_assign(config_line_t *list, int use_defaults,
|
||||
int clear_first, char **msg)
|
||||
options_trial_assign(config_line_t *list, unsigned flags, char **msg)
|
||||
{
|
||||
int r;
|
||||
or_options_t *trial_options = config_dup(&options_format, get_options());
|
||||
|
||||
if ((r=config_assign(&options_format, trial_options,
|
||||
list, use_defaults, clear_first, msg)) < 0) {
|
||||
list, flags, msg)) < 0) {
|
||||
config_free(&options_format, trial_options);
|
||||
return r;
|
||||
}
|
||||
@ -4899,7 +4898,8 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
err = SETOPT_ERR_PARSE;
|
||||
goto err;
|
||||
}
|
||||
retval = config_assign(&options_format, newoptions, cl, 0, 0, msg);
|
||||
retval = config_assign(&options_format, newoptions, cl,
|
||||
CAL_WARN_DEPRECATIONS, msg);
|
||||
config_free_lines(cl);
|
||||
if (retval < 0) {
|
||||
err = SETOPT_ERR_PARSE;
|
||||
@ -4915,7 +4915,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
|
||||
/* Go through command-line variables too */
|
||||
retval = config_assign(&options_format, newoptions,
|
||||
global_cmdline_options, 0, 0, msg);
|
||||
global_cmdline_options, CAL_WARN_DEPRECATIONS, msg);
|
||||
if (retval < 0) {
|
||||
err = SETOPT_ERR_PARSE;
|
||||
goto err;
|
||||
@ -4963,7 +4963,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
err = SETOPT_ERR_PARSE;
|
||||
goto err;
|
||||
}
|
||||
retval = config_assign(&options_format, newoptions, cl, 0, 0, msg);
|
||||
retval = config_assign(&options_format, newoptions, cl, 0, msg);
|
||||
config_free_lines(cl);
|
||||
if (retval < 0) {
|
||||
err = SETOPT_ERR_PARSE;
|
||||
@ -4974,7 +4974,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
}
|
||||
/* Assign command-line variables a second time too */
|
||||
retval = config_assign(&options_format, newoptions,
|
||||
global_cmdline_options, 0, 0, msg);
|
||||
global_cmdline_options, 0, msg);
|
||||
if (retval < 0) {
|
||||
err = SETOPT_ERR_PARSE;
|
||||
goto err;
|
||||
|
@ -29,8 +29,8 @@ const char *escaped_safe_str_client(const char *address);
|
||||
const char *escaped_safe_str(const char *address);
|
||||
const char *get_version(void);
|
||||
const char *get_short_version(void);
|
||||
setopt_err_t options_trial_assign(config_line_t *list, int use_defaults,
|
||||
int clear_first, char **msg);
|
||||
setopt_err_t options_trial_assign(config_line_t *list, unsigned flags,
|
||||
char **msg);
|
||||
|
||||
uint32_t get_last_resolved_addr(void);
|
||||
void reset_last_resolved_addr(void);
|
||||
|
@ -504,9 +504,12 @@ warn_deprecated_option(const char *what, const char *why)
|
||||
*/
|
||||
static int
|
||||
config_assign_line(const config_format_t *fmt, void *options,
|
||||
config_line_t *c, int use_defaults,
|
||||
int clear_first, bitarray_t *options_seen, char **msg)
|
||||
config_line_t *c, unsigned flags,
|
||||
bitarray_t *options_seen, char **msg)
|
||||
{
|
||||
const unsigned use_defaults = flags & CAL_USE_DEFAULTS;
|
||||
const unsigned clear_first = flags & CAL_CLEAR_FIRST;
|
||||
const unsigned warn_deprecations = flags & CAL_WARN_DEPRECATIONS;
|
||||
const config_var_t *var;
|
||||
|
||||
CONFIG_CHECK(fmt, options);
|
||||
@ -532,8 +535,9 @@ config_assign_line(const config_format_t *fmt, void *options,
|
||||
c->key = tor_strdup(var->name);
|
||||
}
|
||||
|
||||
const char *deprecation_msg = config_find_deprecation(fmt, var->name);
|
||||
if (deprecation_msg) {
|
||||
const char *deprecation_msg;
|
||||
if (warn_deprecations &&
|
||||
(deprecation_msg = config_find_deprecation(fmt, var->name))) {
|
||||
warn_deprecated_option(var->name, deprecation_msg);
|
||||
}
|
||||
|
||||
@ -639,7 +643,7 @@ config_lines_dup(const config_line_t *inp)
|
||||
* escape that value. Return NULL if no such key exists. */
|
||||
config_line_t *
|
||||
config_get_assigned_option(const config_format_t *fmt, const void *options,
|
||||
const char *key, int escape_val)
|
||||
const char *key, int escape_val)
|
||||
{
|
||||
const config_var_t *var;
|
||||
const void *value;
|
||||
@ -839,11 +843,13 @@ options_trial_assign() calls config_assign(1, 1)
|
||||
*/
|
||||
int
|
||||
config_assign(const config_format_t *fmt, void *options, config_line_t *list,
|
||||
int use_defaults, int clear_first, char **msg)
|
||||
unsigned config_assign_flags, char **msg)
|
||||
{
|
||||
config_line_t *p;
|
||||
bitarray_t *options_seen;
|
||||
const int n_options = config_count_options(fmt);
|
||||
const unsigned clear_first = config_assign_flags & CAL_CLEAR_FIRST;
|
||||
const unsigned use_defaults = config_assign_flags & CAL_USE_DEFAULTS;
|
||||
|
||||
CONFIG_CHECK(fmt, options);
|
||||
|
||||
@ -867,8 +873,8 @@ config_assign(const config_format_t *fmt, void *options, config_line_t *list,
|
||||
/* pass 3: assign. */
|
||||
while (list) {
|
||||
int r;
|
||||
if ((r=config_assign_line(fmt, options, list, use_defaults,
|
||||
clear_first, options_seen, msg))) {
|
||||
if ((r=config_assign_line(fmt, options, list, config_assign_flags,
|
||||
options_seen, msg))) {
|
||||
bitarray_free(options_seen);
|
||||
return r;
|
||||
}
|
||||
@ -1064,7 +1070,7 @@ config_dup(const config_format_t *fmt, const void *old)
|
||||
line = config_get_assigned_option(fmt, old, fmt->vars[i].name, 0);
|
||||
if (line) {
|
||||
char *msg = NULL;
|
||||
if (config_assign(fmt, newopts, line, 0, 0, &msg) < 0) {
|
||||
if (config_assign(fmt, newopts, line, 0, &msg) < 0) {
|
||||
log_err(LD_BUG, "config_get_assigned_option() generated "
|
||||
"something we couldn't config_assign(): %s", msg);
|
||||
tor_free(msg);
|
||||
|
@ -98,6 +98,10 @@ typedef struct config_format_t {
|
||||
*(uint32_t*)STRUCT_VAR_P(cfg,fmt->magic_offset)); \
|
||||
STMT_END
|
||||
|
||||
#define CAL_USE_DEFAULTS (1u<<0)
|
||||
#define CAL_CLEAR_FIRST (1u<<1)
|
||||
#define CAL_WARN_DEPRECATIONS (1u<<2)
|
||||
|
||||
void *config_new(const config_format_t *fmt);
|
||||
void config_line_append(config_line_t **lst,
|
||||
const char *key, const char *val);
|
||||
@ -120,7 +124,7 @@ char *config_dump(const config_format_t *fmt, const void *default_options,
|
||||
int comment_defaults);
|
||||
int config_assign(const config_format_t *fmt, void *options,
|
||||
config_line_t *list,
|
||||
int use_defaults, int clear_first, char **msg);
|
||||
unsigned flags, char **msg);
|
||||
config_var_t *config_find_option_mutable(config_format_t *fmt,
|
||||
const char *key);
|
||||
const config_var_t *config_find_option(const config_format_t *fmt,
|
||||
|
@ -871,7 +871,8 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
|
||||
config_line_t *lines=NULL;
|
||||
char *start = body;
|
||||
char *errstring = NULL;
|
||||
const int clear_first = 1;
|
||||
const unsigned flags =
|
||||
CAL_CLEAR_FIRST | (use_defaults ? CAL_USE_DEFAULTS : 0);
|
||||
|
||||
char *config;
|
||||
smartlist_t *entries = smartlist_new();
|
||||
@ -931,7 +932,7 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
|
||||
}
|
||||
tor_free(config);
|
||||
|
||||
opt_err = options_trial_assign(lines, use_defaults, clear_first, &errstring);
|
||||
opt_err = options_trial_assign(lines, flags, &errstring);
|
||||
{
|
||||
const char *msg;
|
||||
switch (opt_err) {
|
||||
|
@ -701,7 +701,7 @@ disk_state_load_from_disk_impl(const char *fname)
|
||||
}
|
||||
|
||||
disk_state = disk_state_new(time(NULL));
|
||||
config_assign(&state_format, disk_state, lines, 0, 0, &errmsg);
|
||||
config_assign(&state_format, disk_state, lines, 0, &errmsg);
|
||||
config_free_lines(lines);
|
||||
if (errmsg) {
|
||||
log_warn(LD_DIR, "SR: Reading state error: %s", errmsg);
|
||||
|
@ -350,7 +350,7 @@ or_state_load(void)
|
||||
if (config_get_lines(contents, &lines, 0)<0)
|
||||
goto done;
|
||||
assign_retval = config_assign(&state_format, new_state,
|
||||
lines, 0, 0, &errmsg);
|
||||
lines, 0, &errmsg);
|
||||
config_free_lines(lines);
|
||||
if (assign_retval<0)
|
||||
badstate = 1;
|
||||
|
@ -121,7 +121,7 @@ test_options_validate_impl(const char *configuration,
|
||||
r = config_get_lines(configuration, &cl, 1);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
r = config_assign(&options_format, opt, cl, 0, 0, &msg);
|
||||
r = config_assign(&options_format, opt, cl, 0, &msg);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
r = options_validate(NULL, opt, dflt, 0, &msg);
|
||||
@ -223,7 +223,7 @@ test_have_enough_mem_for_dircache(void *arg)
|
||||
r = config_get_lines(configuration, &cl, 1);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
r = config_assign(&options_format, opt, cl, 0, 0, &msg);
|
||||
r = config_assign(&options_format, opt, cl, 0, &msg);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
/* 300 MB RAM available, DirCache enabled */
|
||||
@ -246,7 +246,7 @@ test_have_enough_mem_for_dircache(void *arg)
|
||||
r = config_get_lines(configuration, &cl, 1);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
r = config_assign(&options_format, opt, cl, 0, 0, &msg);
|
||||
r = config_assign(&options_format, opt, cl, 0, &msg);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
/* 300 MB RAM available, DirCache enabled, Bridge */
|
||||
@ -269,7 +269,7 @@ test_have_enough_mem_for_dircache(void *arg)
|
||||
r = config_get_lines(configuration, &cl, 1);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
r = config_assign(&options_format, opt, cl, 0, 0, &msg);
|
||||
r = config_assign(&options_format, opt, cl, 0, &msg);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
|
||||
/* 200 MB RAM available, DirCache disabled */
|
||||
@ -354,7 +354,7 @@ get_options_test_data(const char *conf)
|
||||
result->def_opt = options_new();
|
||||
rv = config_get_lines(conf, &cl, 1);
|
||||
tt_assert(rv == 0);
|
||||
rv = config_assign(&options_format, result->opt, cl, 0, 0, &msg);
|
||||
rv = config_assign(&options_format, result->opt, cl, 0, &msg);
|
||||
if (msg) {
|
||||
/* Display the parse error message by comparing it with an empty string */
|
||||
tt_str_op(msg, OP_EQ, "");
|
||||
@ -365,7 +365,7 @@ get_options_test_data(const char *conf)
|
||||
result->opt->TokenBucketRefillInterval = 1;
|
||||
rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
|
||||
tt_assert(rv == 0);
|
||||
rv = config_assign(&options_format, result->def_opt, cl, 0, 0, &msg);
|
||||
rv = config_assign(&options_format, result->def_opt, cl, 0, &msg);
|
||||
if (msg) {
|
||||
/* Display the parse error message by comparing it with an empty string */
|
||||
tt_str_op(msg, OP_EQ, "");
|
||||
|
Loading…
Reference in New Issue
Block a user