diff options
author | George Kadianakis <desnacked@riseup.net> | 2019-09-05 17:13:29 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-09-05 17:13:29 +0300 |
commit | 545c21e23dcb2c73ab9d9f33e2ea6906a230b4b5 (patch) | |
tree | b15fa818f1fac84559b6e967c0bed81f65e6ae0a /src/lib | |
parent | ddd01541b909a84396e2d9ba31266ae63670c938 (diff) | |
parent | 88839ab2ac489af7b80c2812fc87ab8b89075fbb (diff) | |
download | tor-545c21e23dcb2c73ab9d9f33e2ea6906a230b4b5.tar.gz tor-545c21e23dcb2c73ab9d9f33e2ea6906a230b4b5.zip |
Merge branch 'tor-github/pr/1295'
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/confmgt/structvar.c | 18 | ||||
-rw-r--r-- | src/lib/confmgt/typedvar.c | 134 | ||||
-rw-r--r-- | src/lib/confmgt/typedvar.h | 29 |
3 files changed, 36 insertions, 145 deletions
diff --git a/src/lib/confmgt/structvar.c b/src/lib/confmgt/structvar.c index 97a8fb3633..32f616c214 100644 --- a/src/lib/confmgt/structvar.c +++ b/src/lib/confmgt/structvar.c @@ -103,7 +103,7 @@ struct_var_assign(void *object, const char *value, char **errmsg, void *p = struct_get_mptr(object, member); const var_type_def_t *def = get_type_def(member); - return typed_var_assign_ex(p, value, errmsg, def); + return typed_var_assign(p, value, errmsg, def); } /** @@ -116,7 +116,7 @@ struct_var_free(void *object, const struct_member_t *member) void *p = struct_get_mptr(object, member); const var_type_def_t *def = get_type_def(member); - typed_var_free_ex(p, def); + typed_var_free(p, def); } /** @@ -129,7 +129,7 @@ struct_var_encode(const void *object, const struct_member_t *member) const void *p = struct_get_ptr(object, member); const var_type_def_t *def = get_type_def(member); - return typed_var_encode_ex(p, def); + return typed_var_encode(p, def); } /** @@ -143,7 +143,7 @@ struct_var_copy(void *dest, const void *src, const struct_member_t *member) const void *p_src = struct_get_ptr(src, member); const var_type_def_t *def = get_type_def(member); - return typed_var_copy_ex(p_dest, p_src, def); + return typed_var_copy(p_dest, p_src, def); } /** @@ -157,7 +157,7 @@ struct_var_eq(const void *a, const void *b, const struct_member_t *member) const void *p_b = struct_get_ptr(b, member); const var_type_def_t *def = get_type_def(member); - return typed_var_eq_ex(p_a, p_b, def); + return typed_var_eq(p_a, p_b, def); } /** @@ -170,7 +170,7 @@ struct_var_ok(const void *object, const struct_member_t *member) const void *p = struct_get_ptr(object, member); const var_type_def_t *def = get_type_def(member); - return typed_var_ok_ex(p, def); + return typed_var_ok(p, def); } /** @@ -185,7 +185,7 @@ struct_var_kvassign(void *object, const struct config_line_t *line, void *p = struct_get_mptr(object, member); const var_type_def_t *def = get_type_def(member); - return typed_var_kvassign_ex(p, line, errmsg, def); + return typed_var_kvassign(p, line, errmsg, def); } /** @@ -198,7 +198,7 @@ struct_var_kvencode(const void *object, const struct_member_t *member) const void *p = struct_get_ptr(object, member); const var_type_def_t *def = get_type_def(member); - return typed_var_kvencode_ex(member->name, p, def); + return typed_var_kvencode(member->name, p, def); } /** @@ -211,7 +211,7 @@ 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 typed_var_mark_fragile(p, def); } /** diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c index 3cba075390..43040e1e05 100644 --- a/src/lib/confmgt/typedvar.c +++ b/src/lib/confmgt/typedvar.c @@ -40,13 +40,13 @@ * string holding an error message, and return -1. **/ int -typed_var_assign_ex(void *target, const char *value, char **errmsg, +typed_var_assign(void *target, const char *value, char **errmsg, const var_type_def_t *def) { if (BUG(!def)) return -1; // LCOV_EXCL_LINE // clear old value if needed. - typed_var_free_ex(target, def); + typed_var_free(target, def); tor_assert(def->fns->parse); return def->fns->parse(target, value, errmsg, def->params); @@ -55,7 +55,7 @@ typed_var_assign_ex(void *target, const char *value, char **errmsg, /** * Try to parse a single line from the head of<b>line</b> that encodes an * object of the type defined in <b>def</b>. On success and failure, behave as - * typed_var_assign_ex(). + * typed_var_assign(). * * All types for which keys are significant should use this function. * @@ -63,7 +63,7 @@ typed_var_assign_ex(void *target, const char *value, char **errmsg, * only the first one is handled by this function. **/ int -typed_var_kvassign_ex(void *target, const config_line_t *line, +typed_var_kvassign(void *target, const config_line_t *line, char **errmsg, const var_type_def_t *def) { if (BUG(!def)) @@ -75,7 +75,7 @@ typed_var_kvassign_ex(void *target, const config_line_t *line, return def->fns->kv_parse(target, line, errmsg, def->params); } - return typed_var_assign_ex(target, line->value, errmsg, def); + return typed_var_assign(target, line->value, errmsg, def); } /** @@ -83,7 +83,7 @@ typed_var_kvassign_ex(void *target, const config_line_t *line, * <b>def</b>, and set <b>target</b> to a reasonable default. **/ void -typed_var_free_ex(void *target, const var_type_def_t *def) +typed_var_free(void *target, const var_type_def_t *def) { if (BUG(!def)) return; // LCOV_EXCL_LINE @@ -99,7 +99,7 @@ typed_var_free_ex(void *target, const var_type_def_t *def) * Returns NULL if this option has a NULL value, or on internal error. **/ char * -typed_var_encode_ex(const void *value, const var_type_def_t *def) +typed_var_encode(const void *value, const var_type_def_t *def) { if (BUG(!def)) return NULL; // LCOV_EXCL_LINE @@ -108,7 +108,7 @@ typed_var_encode_ex(const void *value, const var_type_def_t *def) } /** - * As typed_var_encode_ex(), but returns a newly allocated config_line_t + * As typed_var_encode(), but returns a newly allocated config_line_t * object. The provided <b>key</b> is used as the key of the lines, unless * the type is one (line a linelist) that encodes its own keys. * @@ -117,7 +117,7 @@ typed_var_encode_ex(const void *value, const var_type_def_t *def) * Returns NULL if there are no lines to encode, or on internal error. */ config_line_t * -typed_var_kvencode_ex(const char *key, const void *value, +typed_var_kvencode(const char *key, const void *value, const var_type_def_t *def) { if (BUG(!def)) @@ -125,7 +125,7 @@ typed_var_kvencode_ex(const char *key, const void *value, if (def->fns->kv_encode) { return def->fns->kv_encode(key, value, def->params); } - char *encoded_value = typed_var_encode_ex(value, def); + char *encoded_value = typed_var_encode(value, def); if (!encoded_value) return NULL; @@ -142,7 +142,7 @@ typed_var_kvencode_ex(const char *key, const void *value, * Return 0 on success, and -1 on failure. **/ int -typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def) +typed_var_copy(void *dest, const void *src, const var_type_def_t *def) { if (BUG(!def)) return -1; // LCOV_EXCL_LINE @@ -152,13 +152,13 @@ typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def) } // Otherwise, encode 'src' and parse the result into 'def'. - char *enc = typed_var_encode_ex(src, def); + char *enc = typed_var_encode(src, def); if (!enc) { - typed_var_free_ex(dest, def); + typed_var_free(dest, def); return 0; } char *err = NULL; - int rv = typed_var_assign_ex(dest, enc, &err, def); + int rv = typed_var_assign(dest, enc, &err, def); if (BUG(rv < 0)) { // LCOV_EXCL_START log_warn(LD_BUG, "Encoded value %s was not parseable as a %s: %s", @@ -175,7 +175,7 @@ typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def) * Both types must be as defined by <b>def</b>. **/ bool -typed_var_eq_ex(const void *a, const void *b, const var_type_def_t *def) +typed_var_eq(const void *a, const void *b, const var_type_def_t *def) { if (BUG(!def)) return false; // LCOV_EXCL_LINE @@ -186,8 +186,8 @@ typed_var_eq_ex(const void *a, const void *b, const var_type_def_t *def) } // Otherwise, encode the values and compare them. - char *enc_a = typed_var_encode_ex(a, def); - char *enc_b = typed_var_encode_ex(b, def); + char *enc_a = typed_var_encode(a, def); + char *enc_b = typed_var_encode(b, def); bool eq = !strcmp_opt(enc_a,enc_b); tor_free(enc_a); tor_free(enc_b); @@ -199,7 +199,7 @@ typed_var_eq_ex(const void *a, const void *b, const var_type_def_t *def) * type definition in <b>def</b>. */ bool -typed_var_ok_ex(const void *value, const var_type_def_t *def) +typed_var_ok(const void *value, const var_type_def_t *def) { if (BUG(!def)) return false; // LCOV_EXCL_LINE @@ -216,7 +216,7 @@ typed_var_ok_ex(const void *value, const var_type_def_t *def) * assignment instead. **/ void -typed_var_mark_fragile_ex(void *value, const var_type_def_t *def) +typed_var_mark_fragile(void *value, const var_type_def_t *def) { if (BUG(!def)) { return; // LCOV_EXCL_LINE @@ -254,99 +254,3 @@ var_type_is_settable(const var_type_def_t *def) { return ! def->is_unsettable; } - -/* ===== - * The functions below take a config_type_t instead of a var_type_def_t. - * I'd like to deprecate them eventually and use var_type_def_t everywhere, - * but for now they make migration easier. - * ===== */ - -/** - * As typed_var_assign_ex(), but look up the definition of the configuration - * type from a provided config_type_t enum. - */ -int -typed_var_assign(void *target, const char *value, char **errmsg, - config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_assign_ex(target, value, errmsg, def); -} - -/** - * As typed_var_kvassign_ex(), but look up the definition of the configuration - * type from a provided config_type_t enum. - */ -int -typed_var_kvassign(void *target, const config_line_t *line, char **errmsg, - config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_kvassign_ex(target, line, errmsg, def); -} - -/** - * As typed_var_free_ex(), but look up the definition of the configuration - * type from a provided config_type_t enum. - */ -void -typed_var_free(void *target, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_free_ex(target, def); -} - -/** - * As typed_var_encode_ex(), but look up the definition of the configuration - * type from a provided config_type_t enum. - */ -char * -typed_var_encode(const void *value, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_encode_ex(value, def); -} - -/** - * As typed_var_kvencode_ex(), but look up the definition of the configuration - * type from a provided config_type_t enum. - */ -config_line_t * -typed_var_kvencode(const char *key, const void *value, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_kvencode_ex(key, value, def); -} - -/** - * As typed_var_copy_ex(), but look up the definition of the configuration type - * from a provided config_type_t enum. - */ -int -typed_var_copy(void *dest, const void *src, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_copy_ex(dest, src, def); -} - -/** - * As typed_var_eq_ex(), but look up the definition of the configuration type - * from a provided config_type_t enum. - */ -bool -typed_var_eq(const void *a, const void *b, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_eq_ex(a, b, def); -} - -/** - * As typed_var_ok_ex(), but look up the definition of the configuration type - * from a provided config_type_t enum. - */ -bool -typed_var_ok(const void *value, config_type_t type) -{ - const var_type_def_t *def = lookup_type_def(type); - return typed_var_ok_ex(value, def); -} diff --git a/src/lib/confmgt/typedvar.h b/src/lib/confmgt/typedvar.h index 2e36f9d673..23fd8c13e4 100644 --- a/src/lib/confmgt/typedvar.h +++ b/src/lib/confmgt/typedvar.h @@ -21,32 +21,19 @@ typedef struct var_type_fns_t var_type_fns_t; typedef struct var_type_def_t var_type_def_t; int typed_var_assign(void *target, const char *value, char **errmsg, - enum config_type_t type); -void typed_var_free(void *target, enum config_type_t type); -char *typed_var_encode(const void *value, enum config_type_t type); -int typed_var_copy(void *dest, const void *src, enum config_type_t type); -bool typed_var_eq(const void *a, const void *b, enum config_type_t type); -bool typed_var_ok(const void *value, enum config_type_t type); - -int typed_var_kvassign(void *target, const struct config_line_t *line, - char **errmsg, enum config_type_t type); -struct config_line_t *typed_var_kvencode(const char *key, const void *value, - enum config_type_t type); - -int typed_var_assign_ex(void *target, const char *value, char **errmsg, const var_type_def_t *def); -void typed_var_free_ex(void *target, const var_type_def_t *def); -char *typed_var_encode_ex(const void *value, const var_type_def_t *def); -int typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def); -bool typed_var_eq_ex(const void *a, const void *b, const var_type_def_t *def); -bool typed_var_ok_ex(const void *value, const var_type_def_t *def); +void typed_var_free(void *target, const var_type_def_t *def); +char *typed_var_encode(const void *value, const var_type_def_t *def); +int typed_var_copy(void *dest, const void *src, const var_type_def_t *def); +bool typed_var_eq(const void *a, const void *b, const var_type_def_t *def); +bool typed_var_ok(const void *value, const var_type_def_t *def); -int typed_var_kvassign_ex(void *target, const struct config_line_t *line, +int typed_var_kvassign(void *target, const struct config_line_t *line, char **errmsg, const var_type_def_t *def); -struct config_line_t *typed_var_kvencode_ex(const char *key, const void *value, +struct config_line_t *typed_var_kvencode(const char *key, const void *value, const var_type_def_t *def); -void typed_var_mark_fragile_ex(void *value, const var_type_def_t *def); +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); |