aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-09-11 09:42:31 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-09-11 09:42:31 -0400
commit41261c3b5cd505f5a601c319eb484866903814af (patch)
tree3264e3e0293865ab9012d53aaf835f3713d8c6ef /src/lib
parent049705fc1c9d1c0cee120dc8cbd1a719c6e45e85 (diff)
parent478141e617a333ac4d998e3747c073246e04b5ae (diff)
downloadtor-41261c3b5cd505f5a601c319eb484866903814af.tar.gz
tor-41261c3b5cd505f5a601c319eb484866903814af.zip
Merge branch 'tor-github/pr/1296'
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/conf/confmacros.h2
-rw-r--r--src/lib/conf/conftypes.h58
-rw-r--r--src/lib/confmgt/structvar.c23
-rw-r--r--src/lib/confmgt/structvar.h5
-rw-r--r--src/lib/confmgt/type_defs.c22
-rw-r--r--src/lib/confmgt/typedvar.c29
-rw-r--r--src/lib/confmgt/typedvar.h4
-rw-r--r--src/lib/confmgt/var_type_def_st.h16
8 files changed, 73 insertions, 86 deletions
diff --git a/src/lib/conf/confmacros.h b/src/lib/conf/confmacros.h
index 2a15f09aac..68121891f1 100644
--- a/src/lib/conf/confmacros.h
+++ b/src/lib/conf/confmacros.h
@@ -61,7 +61,7 @@
#define CONFIG_VAR_OBSOLETE(varname) \
{ .member = { .name = varname, .type = CONFIG_TYPE_OBSOLETE }, \
- .flags = CVFLAG_OBSOLETE \
+ .flags = CFLG_GROUP_OBSOLETE \
}
#endif /* !defined(TOR_LIB_CONF_CONFMACROS_H) */
diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h
index 4609564b34..274065cff2 100644
--- a/src/lib/conf/conftypes.h
+++ b/src/lib/conf/conftypes.h
@@ -132,22 +132,58 @@ typedef struct struct_magic_decl_t {
} struct_magic_decl_t;
/**
- * Flag to indicate that an option is obsolete. Any attempt to set or
- * fetch this option should produce a warning.
+ * Flag to indicate that an option or type is "undumpable". An
+ * undumpable option is never saved to disk.
+ *
+ * For historical reasons its name is usually is prefixed with __.
+ **/
+#define CFLG_NODUMP (1u<<0)
+/**
+ * Flag to indicate that an option or type is "unlisted".
+ *
+ * We don't tell the controller about unlisted options when it asks for a
+ * list of them.
**/
-#define CVFLAG_OBSOLETE (1u<<0)
+#define CFLG_NOLIST (1u<<1)
/**
- * Flag to indicate that an option is undumpable. An undumpable option is
- * never saved to disk. For historical reasons it is prefixed with __ but
- * not with ___.
+ * Flag to indicate that an option or type is "unsettable".
+ *
+ * An unsettable option can never be set directly by name.
+ **/
+#define CFLG_NOSET (1u<<2)
+/**
+ * Flag to indicate that an option or type does not need to be copied when
+ * copying the structure that contains it.
+ *
+ * (Usually, if an option does not need to be copied, then either it contains
+ * no data, or the data that it does contain is completely contained within
+ * another option.)
**/
-#define CVFLAG_NODUMP (1u<<1)
+#define CFLG_NOCOPY (1u<<3)
+/**
+ * Flag to indicate that an option or type does not need to be compared
+ * when telling the controller about the differences between two
+ * configurations.
+ *
+ * (Usually, if an option does not need to be compared, then either it
+ * contains no data, or the data that it does contain is completely contained
+ * within another option.)
+ **/
+#define CFLG_NOCMP (1u<<4)
+/**
+ * Flag to indicate that an option or type should not be replaced when setting
+ * it.
+ *
+ * For most options, setting them replaces their old value. For some options,
+ * however, setting them appends to their old value.
+ */
+#define CFLG_NOREPLACE (1u<<5)
+
/**
- * Flag to indicate that an option is "invisible". An invisible option
- * is always undumpable, and we don't tell the controller about it.
- * For historical reasons it is prefixed with ___.
+ * A group of flags that should be set on all obsolete options and types.
**/
-#define CVFLAG_INVISIBLE (1u<<2)
+#define CFLG_GROUP_OBSOLETE \
+ (CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST)
/** A variable allowed in the configuration file or on the command line. */
typedef struct config_var_t {
diff --git a/src/lib/confmgt/structvar.c b/src/lib/confmgt/structvar.c
index 75edda2c38..de678d18c8 100644
--- a/src/lib/confmgt/structvar.c
+++ b/src/lib/confmgt/structvar.c
@@ -211,26 +211,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 ? def->is_cumulative : false;
-}
-
-bool
-struct_var_is_settable(const struct_member_t *member)
-{
- const var_type_def_t *def = get_type_def(member);
-
- return def ? !def->is_unsettable : 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 ? def->is_contained : false;
+ return def ? def->flags : 0;
}
diff --git a/src/lib/confmgt/structvar.h b/src/lib/confmgt/structvar.h
index 9783d1ec27..bcb4b58c3f 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);
@@ -41,9 +42,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/type_defs.c b/src/lib/confmgt/type_defs.c
index f8b2681aa0..324b62e56c 100644
--- a/src/lib/confmgt/type_defs.c
+++ b/src/lib/confmgt/type_defs.c
@@ -725,16 +725,22 @@ static const var_type_def_t type_definitions_table[] = {
[CONFIG_TYPE_CSV_INTERVAL] = { .name="TimeInterval",
.fns=&legacy_csv_interval_fns, },
[CONFIG_TYPE_LINELIST] = { .name="LineList", .fns=&linelist_fns,
- .is_cumulative=true},
+ .flags=CFLG_NOREPLACE },
+ /*
+ * A "linelist_s" is a derived view of a linelist_v: inspecting
+ * it gets part of a linelist_v, and setting it adds to the linelist_v.
+ */
[CONFIG_TYPE_LINELIST_S] = { .name="Dependent", .fns=&linelist_s_fns,
- .is_cumulative=true,
- .is_contained=true, },
+ .flags=CFLG_NOREPLACE|
+ /* The operations we disable here are
+ * handled by the linelist_v. */
+ CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP },
[CONFIG_TYPE_LINELIST_V] = { .name="Virtual", .fns=&linelist_v_fns,
- .is_cumulative=true,
- .is_unsettable=true },
- [CONFIG_TYPE_OBSOLETE] = { .name="Obsolete", .fns=&ignore_fns,
- .is_unsettable=true,
- .is_contained=true, }
+ .flags=CFLG_NOREPLACE|CFLG_NOSET },
+ [CONFIG_TYPE_OBSOLETE] = {
+ .name="Obsolete", .fns=&ignore_fns,
+ .flags=CFLG_GROUP_OBSOLETE,
+ }
};
/**
diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c
index 43040e1e05..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->is_cumulative;
-}
-
-/**
- * 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->is_contained;
-}
-
-/**
- * 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->is_unsettable;
-}
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) */
diff --git a/src/lib/confmgt/var_type_def_st.h b/src/lib/confmgt/var_type_def_st.h
index 4157cb8ff6..f1131ff116 100644
--- a/src/lib/confmgt/var_type_def_st.h
+++ b/src/lib/confmgt/var_type_def_st.h
@@ -151,17 +151,11 @@ struct var_type_def_t {
* calling the functions in this type's function table.
*/
const void *params;
-
- /** True iff a variable of this type can never be set directly by name. */
- bool is_unsettable;
- /** True iff a variable of this type is always contained in another
- * variable, and as such doesn't need to be dumped or copied
- * independently. */
- bool is_contained;
- /** True iff a variable of this type can be set more than once without
- * destroying older values. Such variables should implement "mark_fragile".
- */
- bool is_cumulative;
+ /**
+ * A bitwise OR of one or more VTFLAG_* values, describing properties
+ * for all values of this type.
+ **/
+ uint32_t flags;
};
#endif /* !defined(TOR_LIB_CONFMGT_VAR_TYPE_DEF_ST_H) */