summaryrefslogtreecommitdiff
path: root/src/app/config/confparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-06-21 09:58:40 -0400
committerNick Mathewson <nickm@torproject.org>2019-06-25 12:51:25 -0400
commita7835202cf871f68854494df904058a6e644c0b0 (patch)
tree0da40c2c861d44374de01f58902e17a913326993 /src/app/config/confparse.c
parentb6457d4c08f601c4e42e64aad47ac9c30c36306e (diff)
downloadtor-a7835202cf871f68854494df904058a6e644c0b0.tar.gz
tor-a7835202cf871f68854494df904058a6e644c0b0.zip
Turn several properties of types or variables into flags.
"unsettable" is a property of types. LINELIST_V and OBSOLETE are unsettable, meaning that they cannot be set by name. "contained" is a property of types. I'm hoping to find a better name here. LINELIST_S is "contained" because it always appears within a LINELIST_V, and as such doesn't need to be dumped ore copied independently. "cumulative" is a property of types. Cumulative types can appear more than once in a torrc without causing a warning, because they add to each other rather than replacing each other. "obsolete" is a property of variables. "marking fragile" is now a command that struct members can accept. With these changes, confparse and config no longer ever need to mention CONFIG_TYPE_XYZ values by name.
Diffstat (limited to 'src/app/config/confparse.c')
-rw-r--r--src/app/config/confparse.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 2890d8c81b..0d19974d70 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -148,6 +148,24 @@ config_count_options(const config_format_t *fmt)
return i;
}
+bool
+config_var_is_cumulative(const config_var_t *var)
+{
+ return struct_var_is_cumulative(&var->member);
+}
+bool
+config_var_is_settable(const config_var_t *var)
+{
+ if (var->flags & CVFLAG_OBSOLETE)
+ return false;
+ return struct_var_is_settable(&var->member);
+}
+bool
+config_var_is_contained(const config_var_t *var)
+{
+ return struct_var_is_contained(&var->member);
+}
+
/*
* Functions to assign config options.
*/
@@ -183,14 +201,7 @@ config_mark_lists_fragile(const config_format_t *fmt, void *options)
for (i = 0; fmt->vars[i].member.name; ++i) {
const config_var_t *var = &fmt->vars[i];
- config_line_t *list;
- if (var->member.type != CONFIG_TYPE_LINELIST &&
- var->member.type != CONFIG_TYPE_LINELIST_V)
- continue;
-
- list = *(config_line_t **)STRUCT_VAR_P(options, var->member.offset);
- if (list)
- list->fragile = 1;
+ struct_var_mark_fragile(options, &var->member);
}
}
@@ -255,9 +266,7 @@ config_assign_line(const config_format_t *fmt, void *options,
if (!strlen(c->value)) {
/* reset or clear it, then return */
if (!clear_first) {
- if ((var->member.type == CONFIG_TYPE_LINELIST ||
- var->member.type == CONFIG_TYPE_LINELIST_S) &&
- c->command != CONFIG_LINE_CLEAR) {
+ if (config_var_is_cumulative(var) && c->command != CONFIG_LINE_CLEAR) {
/* We got an empty linelist from the torrc or command line.
As a special case, call this an error. Warn and ignore. */
log_warn(LD_CONFIG,
@@ -273,8 +282,7 @@ config_assign_line(const config_format_t *fmt, void *options,
config_reset(fmt, options, var, use_defaults); // LCOV_EXCL_LINE
}
- if (options_seen && (var->member.type != CONFIG_TYPE_LINELIST &&
- var->member.type != CONFIG_TYPE_LINELIST_S)) {
+ if (options_seen && ! config_var_is_cumulative(var)) {
/* We're tracking which options we've seen, and this option is not
* supposed to occur more than once. */
int var_index = (int)(var - fmt->vars);
@@ -562,10 +570,10 @@ config_dup(const config_format_t *fmt, const void *old)
newopts = config_new(fmt);
for (i=0; fmt->vars[i].member.name; ++i) {
- if (fmt->vars[i].member.type == CONFIG_TYPE_LINELIST_S)
- continue;
- if (fmt->vars[i].member.type == CONFIG_TYPE_OBSOLETE)
+ if (config_var_is_contained(&fmt->vars[i])) {
+ // Something else will copy this option, or it doesn't need copying.
continue;
+ }
if (struct_var_copy(newopts, old, &fmt->vars[i].member) < 0) {
// LCOV_EXCL_START
log_err(LD_BUG, "Unable to copy value for %s.",
@@ -629,9 +637,10 @@ config_dump(const config_format_t *fmt, const void *default_options,
elements = smartlist_new();
for (i=0; fmt->vars[i].member.name; ++i) {
int comment_option = 0;
- if (fmt->vars[i].member.type == CONFIG_TYPE_OBSOLETE ||
- fmt->vars[i].member.type == CONFIG_TYPE_LINELIST_S)
+ if (config_var_is_contained(&fmt->vars[i])) {
+ // Something else will dump this option, or it doesn't need dumping.
continue;
+ }
/* Don't save 'hidden' control variables. */
if (!strcmpstart(fmt->vars[i].member.name, "__"))
continue;