aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/config/confparse.c29
-rw-r--r--src/lib/confmgt/structvar.c23
-rw-r--r--src/lib/confmgt/structvar.h5
-rw-r--r--src/lib/confmgt/typedvar.c29
-rw-r--r--src/lib/confmgt/typedvar.h4
5 files changed, 24 insertions, 66 deletions
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 2c8779bbea..7579d9ef8e 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -512,6 +512,18 @@ config_count_options(const config_mgr_t *mgr)
}
/**
+ * Return true iff at least one bit from <b>flag</b> is set on <b>var</b>,
+ * either in <b>var</b>'s flags, or on the flags of its type.
+ **/
+static bool
+config_var_has_flag(const config_var_t *var, uint32_t flag)
+{
+ uint32_t have_flags = var->flags | struct_var_get_flags(&var->member);
+
+ return (have_flags & flag) != 0;
+}
+
+/**
* Return true if assigning a value to <b>var</b> replaces the previous
* value. Return false if assigning a value to <b>var</b> appends
* to the previous value.
@@ -519,7 +531,7 @@ config_count_options(const config_mgr_t *mgr)
static bool
config_var_is_replaced_on_set(const config_var_t *var)
{
- return ! struct_var_is_cumulative(&var->member);
+ return ! config_var_has_flag(var, VTFLAG_CUMULATIVE);
}
/**
@@ -529,9 +541,7 @@ config_var_is_replaced_on_set(const config_var_t *var)
bool
config_var_is_settable(const config_var_t *var)
{
- if (var->flags & CVFLAG_OBSOLETE)
- return false;
- return struct_var_is_settable(&var->member);
+ return ! config_var_has_flag(var, CVFLAG_OBSOLETE | VTFLAG_UNSETTABLE);
}
/**
@@ -546,7 +556,7 @@ config_var_is_gettable(const config_var_t *var)
* have compatibility effects. For now, let's leave them alone.
*/
- // return (var->flags & (CVFLAG_OBSOLETE|CFGLAGS_INVISIBLE)) == 0;
+ // return ! config_var_has_flag(var, CVFLAG_OBSOLETE|CFGLAGS_INVISIBLE);
(void)var;
return true;
}
@@ -565,7 +575,7 @@ config_var_is_gettable(const config_var_t *var)
static bool
config_var_is_derived(const config_var_t *var)
{
- return struct_var_is_contained(&var->member);
+ return config_var_has_flag(var, VTFLAG_CONTAINED);
}
/**
@@ -603,7 +613,7 @@ config_var_needs_copy(const config_var_t *var)
bool
config_var_is_listable(const config_var_t *var)
{
- return (var->flags & CVFLAG_INVISIBLE) == 0;
+ return ! config_var_has_flag(var, CVFLAG_INVISIBLE);
}
/**
@@ -617,10 +627,7 @@ config_var_is_listable(const config_var_t *var)
static bool
config_var_is_dumpable(const config_var_t *var)
{
- if (config_var_is_derived(var)) {
- return false;
- }
- return (var->flags & CVFLAG_NODUMP) == 0;
+ return ! config_var_has_flag(var, VTFLAG_CONTAINED | CVFLAG_NODUMP);
}
/*
diff --git a/src/lib/confmgt/structvar.c b/src/lib/confmgt/structvar.c
index 6b725f613e..cb37f540b6 100644
--- a/src/lib/confmgt/structvar.c
+++ b/src/lib/confmgt/structvar.c
@@ -238,26 +238,11 @@ struct_var_get_typename(const struct_member_t *member)
return def ? def->name : NULL;
}
-bool
-struct_var_is_cumulative(const struct_member_t *member)
-{
- const var_type_def_t *def = get_type_def(member);
-
- return def ? var_type_is_cumulative(def) : false;
-}
-
-bool
-struct_var_is_settable(const struct_member_t *member)
-{
- const var_type_def_t *def = get_type_def(member);
-
- return def ? var_type_is_settable(def) : true;
-}
-
-bool
-struct_var_is_contained(const struct_member_t *member)
+/** Return all of the flags set for this struct member. */
+uint32_t
+struct_var_get_flags(const struct_member_t *member)
{
const var_type_def_t *def = get_type_def(member);
- return def ? var_type_is_contained(def) : false;
+ return def ? def->flags : 0;
}
diff --git a/src/lib/confmgt/structvar.h b/src/lib/confmgt/structvar.h
index e6dbc6d6ec..201211f795 100644
--- a/src/lib/confmgt/structvar.h
+++ b/src/lib/confmgt/structvar.h
@@ -17,6 +17,7 @@ struct struct_member_t;
struct config_line_t;
#include <stdbool.h>
+#include "lib/cc/torint.h"
void struct_set_magic(void *object,
const struct struct_magic_decl_t *decl);
@@ -45,9 +46,7 @@ void struct_var_mark_fragile(void *object,
const char *struct_var_get_name(const struct struct_member_t *member);
const char *struct_var_get_typename(const struct struct_member_t *member);
-bool struct_var_is_cumulative(const struct struct_member_t *member);
-bool struct_var_is_settable(const struct struct_member_t *member);
-bool struct_var_is_contained(const struct struct_member_t *member);
+uint32_t struct_var_get_flags(const struct struct_member_t *member);
int struct_var_kvassign(void *object, const struct config_line_t *line,
char **errmsg,
diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c
index 751d15827f..219a2d15bc 100644
--- a/src/lib/confmgt/typedvar.c
+++ b/src/lib/confmgt/typedvar.c
@@ -225,32 +225,3 @@ typed_var_mark_fragile(void *value, const var_type_def_t *def)
if (def->fns->mark_fragile)
def->fns->mark_fragile(value, def->params);
}
-
-/**
- * Return true iff multiple assignments to a variable will extend its
- * value, rather than replacing it.
- **/
-bool
-var_type_is_cumulative(const var_type_def_t *def)
-{
- return (def->flags & VTFLAG_CUMULATIVE) != 0;
-}
-
-/**
- * Return true iff this variable type is always contained in another variable,
- * and as such doesn't need to be dumped or copied independently.
- **/
-bool
-var_type_is_contained(const var_type_def_t *def)
-{
- return (def->flags & VTFLAG_CONTAINED) != 0;
-}
-
-/**
- * Return true iff this type can not be assigned directly by the user.
- **/
-bool
-var_type_is_settable(const var_type_def_t *def)
-{
- return (def->flags & VTFLAG_UNSETTABLE) == 0;
-}
diff --git a/src/lib/confmgt/typedvar.h b/src/lib/confmgt/typedvar.h
index 23fd8c13e4..22f2e3c58e 100644
--- a/src/lib/confmgt/typedvar.h
+++ b/src/lib/confmgt/typedvar.h
@@ -35,8 +35,4 @@ struct config_line_t *typed_var_kvencode(const char *key, const void *value,
void typed_var_mark_fragile(void *value, const var_type_def_t *def);
-bool var_type_is_cumulative(const var_type_def_t *def);
-bool var_type_is_contained(const var_type_def_t *def);
-bool var_type_is_settable(const var_type_def_t *def);
-
#endif /* !defined(TOR_LIB_CONFMGT_TYPEDVAR_H) */