aboutsummaryrefslogtreecommitdiff
path: root/src/lib/confmgt/structvar.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/lib/confmgt/structvar.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/lib/confmgt/structvar.c')
-rw-r--r--src/lib/confmgt/structvar.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/confmgt/structvar.c b/src/lib/confmgt/structvar.c
index 38f8e5dd7a..97a8fb3633 100644
--- a/src/lib/confmgt/structvar.c
+++ b/src/lib/confmgt/structvar.c
@@ -202,6 +202,19 @@ struct_var_kvencode(const void *object, const struct_member_t *member)
}
/**
+ * Mark the field in <b>object</b> determined by <b>member</b> -- a variable
+ * that ordinarily would be extended by assignment -- as "fragile", so that it
+ * will get replaced by the next assignment instead.
+ */
+void
+struct_var_mark_fragile(void *object, const struct_member_t *member)
+{
+ void *p = struct_get_mptr(object, member);
+ const var_type_def_t *def = get_type_def(member);
+ return typed_var_mark_fragile_ex(p, def);
+}
+
+/**
* Return the official name of this struct member.
**/
const char *
@@ -224,3 +237,27 @@ 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)
+{
+ const var_type_def_t *def = get_type_def(member);
+
+ return def ? def->is_contained : false;
+}