From 407fb0c35cec731c386bc288bf1f7852a299d498 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 26 Oct 2019 10:05:03 -0400 Subject: [PATCH] Move config_format_t and allied definitions into conftypes.h Since these are needed by every module that is _configurable_, they belong in lib/conf, not lib/confmgt. --- src/lib/conf/conftypes.h | 136 ++++++++++++++++++++++++++++++++++++ src/lib/confmgt/confparse.h | 136 ------------------------------------ 2 files changed, 136 insertions(+), 136 deletions(-) diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h index 274065cff2..69a5f79bf3 100644 --- a/src/lib/conf/conftypes.h +++ b/src/lib/conf/conftypes.h @@ -199,4 +199,140 @@ typedef struct config_var_t { #endif } config_var_t; +/** + * An abbreviation or alias for a configuration option. + **/ +typedef struct config_abbrev_t { + /** The option name as abbreviated. Not case-sensitive. */ + const char *abbreviated; + /** The full name of the option. Not case-sensitive. */ + const char *full; + /** True if this abbreviation should only be allowed on the command line. */ + int commandline_only; + /** True if we should warn whenever this abbreviation is used. */ + int warn; +} config_abbrev_t; + +/** + * A note that a configuration option is deprecated, with an explanation why. + */ +typedef struct config_deprecation_t { + /** The option that is deprecated. */ + const char *name; + /** A user-facing string explaining why the option is deprecated. */ + const char *why_deprecated; +} config_deprecation_t; + +/** + * Handy macro for declaring "In the config file or on the command line, you + * can abbreviate toks as tok". Used inside an array of + * config_abbrev_t. + * + * For example, to declare "NumCpu" as an abbreviation for "NumCPUs", + * you can say PLURAL(NumCpu). + **/ +#define PLURAL(tok) { #tok, #tok "s", 0, 0 } + +/** + * Validation function: verify whether a configuation object is well-formed + * and consistent. + * + * On success, return 0. On failure, set msg_out to a newly allocated + * string containing an error message, and return -1. */ +typedef int (*validate_fn_t)(const void *value, char **msg_out); +/** + * Validation function: verify whether a configuration object (`value`) is an + * allowable value given the previous configuration value (`old_value`). + * + * On success, return 0. On failure, set msg_out to a newly allocated + * string containing an error message, and return -1. */ +typedef int (*check_transition_fn_t)(const void *old_value, const void *value, + char **msg_out); +/** + * Validation function: normalize members of `value`, and compute derived + * members. + * + * This function is called before any other validation of `value`, and must + * not assume that validate_fn or check_transition_fn has passed. + * + * On success, return 0. On failure, set msg_out to a newly allocated + * string containing an error message, and return -1. */ +typedef int (*pre_normalize_fn_t)(void *value, char **msg_out); +/** + * Validation function: normalize members of `value`, and compute derived + * members. + * + * This function is called after validation of `value`, and may + * assume that validate_fn or check_transition_fn has passed. + * + * On success, return 0. On failure, set msg_out to a newly allocated + * string containing an error message, and return -1. */ +typedef int (*post_normalize_fn_t)(void *value, char **msg_out); + +/** + * Legacy function to validate whether a given configuration is + * well-formed and consistent. + * + * The configuration to validate is passed as newval. The previous + * configuration, if any, is provided in oldval. + * + * This API is deprecated, since it mixes the responsibilities of + * pre_normalize_fn_t, post_normalize_fn_t, validate_fn_t, and + * check_transition_fn_t. No new instances of this function type should + * be written. + * + * On success, return 0. On failure, set *msg_out to a newly allocated + * error message, and return -1. + */ +typedef int (*legacy_validate_fn_t)(const void *oldval, + void *newval, + char **msg_out); + +struct config_mgr_t; + +/** + * Callback to clear all non-managed fields of a configuration object. + * + * obj is the configuration object whose non-managed fields should be + * cleared. + * + * (Regular fields get cleared by config_reset(), but you might have fields + * in the object that do not correspond to configuration variables. If those + * fields need to be cleared or freed, this is where to do it.) + */ +typedef void (*clear_cfg_fn_t)(const struct config_mgr_t *mgr, void *obj); + +/** Information on the keys, value types, key-to-struct-member mappings, + * variable descriptions, validation functions, and abbreviations for a + * configuration or storage format. */ +typedef struct config_format_t { + size_t size; /**< Size of the struct that everything gets parsed into. */ + struct_magic_decl_t magic; /**< Magic number info for this struct. */ + const config_abbrev_t *abbrevs; /**< List of abbreviations that we expand + * when parsing this format. */ + const config_deprecation_t *deprecations; /** List of deprecated options */ + const config_var_t *vars; /**< List of variables we recognize, their default + * values, and where we stick them in the + * structure. */ + + /** Early-stage normalization callback. Invoked by config_validate(). */ + pre_normalize_fn_t pre_normalize_fn; + /** Configuration validation function. Invoked by config_validate(). */ + validate_fn_t validate_fn; + /** Legacy validation function. Invoked by config_validate(). */ + legacy_validate_fn_t legacy_validate_fn; + /** Transition checking function. Invoked by config_validate(). */ + check_transition_fn_t check_transition_fn; + /** Late-stage normalization callback. Invoked by config_validate(). */ + post_normalize_fn_t post_normalize_fn; + + clear_cfg_fn_t clear_fn; /**< Function to clear the configuration. */ + /** If present, extra denotes a LINELIST variable for unrecognized + * lines. Otherwise, unrecognized lines are an error. */ + const struct_member_t *extra; + /** The position of a config_suite_t pointer within the toplevel object, + * or -1 if there is no such pointer. */ + ptrdiff_t config_suite_offset; +} config_format_t; + #endif /* !defined(TOR_SRC_LIB_CONF_CONFTYPES_H) */ diff --git a/src/lib/confmgt/confparse.h b/src/lib/confmgt/confparse.h index f187bfc38d..246ad887cb 100644 --- a/src/lib/confmgt/confparse.h +++ b/src/lib/confmgt/confparse.h @@ -17,142 +17,6 @@ #include "lib/conf/confmacros.h" #include "lib/testsupport/testsupport.h" -/** - * An abbreviation or alias for a configuration option. - **/ -typedef struct config_abbrev_t { - /** The option name as abbreviated. Not case-sensitive. */ - const char *abbreviated; - /** The full name of the option. Not case-sensitive. */ - const char *full; - /** True if this abbreviation should only be allowed on the command line. */ - int commandline_only; - /** True if we should warn whenever this abbreviation is used. */ - int warn; -} config_abbrev_t; - -/** - * A note that a configuration option is deprecated, with an explanation why. - */ -typedef struct config_deprecation_t { - /** The option that is deprecated. */ - const char *name; - /** A user-facing string explaining why the option is deprecated. */ - const char *why_deprecated; -} config_deprecation_t; - -/** - * Handy macro for declaring "In the config file or on the command line, you - * can abbreviate toks as tok". Used inside an array of - * config_abbrev_t. - * - * For example, to declare "NumCpu" as an abbreviation for "NumCPUs", - * you can say PLURAL(NumCpu). - **/ -#define PLURAL(tok) { #tok, #tok "s", 0, 0 } - -/** - * Validation function: verify whether a configuation object is well-formed - * and consistent. - * - * On success, return 0. On failure, set msg_out to a newly allocated - * string containing an error message, and return -1. */ -typedef int (*validate_fn_t)(const void *value, char **msg_out); -/** - * Validation function: verify whether a configuration object (`value`) is an - * allowable value given the previous configuration value (`old_value`). - * - * On success, return 0. On failure, set msg_out to a newly allocated - * string containing an error message, and return -1. */ -typedef int (*check_transition_fn_t)(const void *old_value, const void *value, - char **msg_out); -/** - * Validation function: normalize members of `value`, and compute derived - * members. - * - * This function is called before any other validation of `value`, and must - * not assume that validate_fn or check_transition_fn has passed. - * - * On success, return 0. On failure, set msg_out to a newly allocated - * string containing an error message, and return -1. */ -typedef int (*pre_normalize_fn_t)(void *value, char **msg_out); -/** - * Validation function: normalize members of `value`, and compute derived - * members. - * - * This function is called after validation of `value`, and may - * assume that validate_fn or check_transition_fn has passed. - * - * On success, return 0. On failure, set msg_out to a newly allocated - * string containing an error message, and return -1. */ -typedef int (*post_normalize_fn_t)(void *value, char **msg_out); - -/** - * Legacy function to validate whether a given configuration is - * well-formed and consistent. - * - * The configuration to validate is passed as newval. The previous - * configuration, if any, is provided in oldval. - * - * This API is deprecated, since it mixes the responsibilities of - * pre_normalize_fn_t, post_normalize_fn_t, validate_fn_t, and - * check_transition_fn_t. No new instances of this function type should - * be written. - * - * On success, return 0. On failure, set *msg_out to a newly allocated - * error message, and return -1. - */ -typedef int (*legacy_validate_fn_t)(const void *oldval, - void *newval, - char **msg_out); - -struct config_mgr_t; - -/** - * Callback to clear all non-managed fields of a configuration object. - * - * obj is the configuration object whose non-managed fields should be - * cleared. - * - * (Regular fields get cleared by config_reset(), but you might have fields - * in the object that do not correspond to configuration variables. If those - * fields need to be cleared or freed, this is where to do it.) - */ -typedef void (*clear_cfg_fn_t)(const struct config_mgr_t *mgr, void *obj); - -/** Information on the keys, value types, key-to-struct-member mappings, - * variable descriptions, validation functions, and abbreviations for a - * configuration or storage format. */ -typedef struct config_format_t { - size_t size; /**< Size of the struct that everything gets parsed into. */ - struct_magic_decl_t magic; /**< Magic number info for this struct. */ - const config_abbrev_t *abbrevs; /**< List of abbreviations that we expand - * when parsing this format. */ - const config_deprecation_t *deprecations; /** List of deprecated options */ - const config_var_t *vars; /**< List of variables we recognize, their default - * values, and where we stick them in the - * structure. */ - - /** Early-stage normalization callback. Invoked by config_validate(). */ - pre_normalize_fn_t pre_normalize_fn; - /** Configuration validation function. Invoked by config_validate(). */ - validate_fn_t validate_fn; - /** Legacy validation function. Invoked by config_validate(). */ - legacy_validate_fn_t legacy_validate_fn; - /** Transition checking function. Invoked by config_validate(). */ - check_transition_fn_t check_transition_fn; - /** Late-stage normalization callback. Invoked by config_validate(). */ - post_normalize_fn_t post_normalize_fn; - - clear_cfg_fn_t clear_fn; /**< Function to clear the configuration. */ - /** If present, extra denotes a LINELIST variable for unrecognized - * lines. Otherwise, unrecognized lines are an error. */ - const struct_member_t *extra; - /** The position of a config_suite_t pointer within the toplevel object, - * or -1 if there is no such pointer. */ - ptrdiff_t config_suite_offset; -} config_format_t; - /** * A collection of config_format_t objects to describe several objects * that are all configured with the same configuration file.