|
Tor 0.4.9.8
|
#include "lib/conf/conftypes.h"#include "lib/conf/confmacros.h"#include "lib/testsupport/testsupport.h"Go to the source code of this file.
Macros | |
| #define | config_mgr_free(mgr) |
| #define | CAL_USE_DEFAULTS (1u<<0) |
| #define | CAL_CLEAR_FIRST (1u<<1) |
| #define | CAL_WARN_DEPRECATIONS (1u<<2) |
| #define | config_free(mgr, options) |
| #define | CFG_EQ_BOOL(a, b, opt) |
| #define | CFG_EQ_INT(a, b, opt) |
| #define | CFG_EQ_STRING(a, b, opt) |
| #define | CFG_EQ_SMARTLIST(a, b, opt) |
| #define | CFG_EQ_LINELIST(a, b, opt) |
| #define | CFG_EQ_ROUTERSET(a, b, opt) |
Enumerations | |
| enum | validation_status_t { VSTAT_PRE_NORMALIZE_ERR = -5 , VSTAT_VALIDATE_ERR = -4 , VSTAT_LEGACY_ERR = -3 , VSTAT_TRANSITION_ERR = -2 , VSTAT_POST_NORMALIZE_ERR = -1 , VSTAT_OK = 0 } |
Functions | |
| config_mgr_t * | config_mgr_new (const config_format_t *toplevel_fmt) |
| void | config_mgr_free_ (config_mgr_t *mgr) |
| int | config_mgr_add_format (config_mgr_t *mgr, const config_format_t *fmt) |
| void | config_mgr_freeze (config_mgr_t *mgr) |
| struct smartlist_t * | config_mgr_list_vars (const config_mgr_t *mgr) |
| struct smartlist_t * | config_mgr_list_deprecated_vars (const config_mgr_t *mgr) |
| void * | config_new (const config_mgr_t *fmt) |
| void | config_free_ (const config_mgr_t *fmt, void *options) |
| struct config_line_t * | config_get_assigned_option (const config_mgr_t *mgr, const void *options, const char *key, int escape_val) |
| int | config_is_same (const config_mgr_t *fmt, const void *o1, const void *o2, const char *name) |
| struct config_line_t * | config_get_changes (const config_mgr_t *mgr, const void *options1, const void *options2) |
| void | config_init (const config_mgr_t *mgr, void *options) |
| validation_status_t | config_validate (const config_mgr_t *mgr, const void *old_options, void *options, char **msg_out) |
| void * | config_dup (const config_mgr_t *mgr, const void *old) |
| char * | config_dump (const config_mgr_t *mgr, const void *default_options, const void *options, int minimal, int comment_defaults) |
| void | config_check_toplevel_magic (const config_mgr_t *mgr, const void *object) |
| bool | config_check_ok (const config_mgr_t *mgr, const void *options, int severity) |
| int | config_assign (const config_mgr_t *mgr, void *options, struct config_line_t *list, unsigned flags, char **msg) |
| const char * | config_find_deprecation (const config_mgr_t *mgr, const char *key) |
| const char * | config_find_option_name (const config_mgr_t *mgr, const char *key) |
| const char * | config_expand_abbrev (const config_mgr_t *mgr, const char *option, int command_line, int warn_obsolete) |
| void | warn_deprecated_option (const char *what, const char *why) |
| bool | config_var_is_settable (const config_var_t *var) |
| bool | config_var_is_listable (const config_var_t *var) |
| void * | config_mgr_get_obj_mutable (const config_mgr_t *mgr, void *toplevel, int idx) |
| const void * | config_mgr_get_obj (const config_mgr_t *mgr, const void *toplevel, int idx) |
| #define CAL_CLEAR_FIRST (1u<<1) |
Flag for config_assign: if set, then we reset every provided config option before we set it.
For example, if this flag is not set, then passing a multi-line option to config_assign will cause any previous value to be extended. But if this flag is set, then a multi-line option will replace any previous value.
Definition at line 59 of file confmgt.h.
Referenced by config_assign(), config_assign_line(), and control_setconf_helper().
| #define CAL_USE_DEFAULTS (1u<<0) |
Flag for config_assign: if set, then "resetting" an option changes it to its default value, as specified in the config_var_t. Otherwise, "resetting" an option changes it to a type-dependent null value – typically 0 or NULL.
(An option is "reset" when it is set to an empty value, or as described in CAL_CLEAR_FIRST).
Definition at line 50 of file confmgt.h.
Referenced by config_assign(), config_assign_line(), and control_setconf_helper().
| #define CAL_WARN_DEPRECATIONS (1u<<2) |
Flag for config_assign: if set, we warn about deprecated options.
Definition at line 63 of file confmgt.h.
Referenced by config_assign_line(), options_init(), and options_init_from_string().
| #define CFG_EQ_BOOL | ( | a, | |
| b, | |||
| opt ) |
| #define CFG_EQ_INT | ( | a, | |
| b, | |||
| opt ) |
| #define CFG_EQ_LINELIST | ( | a, | |
| b, | |||
| opt ) |
| #define CFG_EQ_ROUTERSET | ( | a, | |
| b, | |||
| opt ) |
| #define CFG_EQ_SMARTLIST | ( | a, | |
| b, | |||
| opt ) |
| #define CFG_EQ_STRING | ( | a, | |
| b, | |||
| opt ) |
| #define config_free | ( | mgr, | |
| options ) |
| #define config_mgr_free | ( | mgr | ) |
| enum validation_status_t |
| int config_assign | ( | const config_mgr_t * | mgr, |
| void * | options, | ||
| config_line_t * | list, | ||
| unsigned | config_assign_flags, | ||
| char ** | msg ) |
Iterate through the linked list of requested options list. For each item, convert as appropriate and assign to options. If an item is unrecognized, set *msg and return -1 immediately, else return 0 for success.
If clear_first, interpret config options as replacing (not extending) their previous values. If clear_first is set, then use_defaults to decide if you set to defaults after clearing, or make the value 0 or NULL.
Here are the use cases:
Use_defaults Clear_first 0 0 "append" 1 0 undefined, don't use 0 1 "set to null first" 1 1 "set to defaults first" Return 0 on success, -1 on bad key, -2 on bad value.
As an additional special case, if a LINELIST config option has no value and clear_first is 0, then warn and ignore it.
Now we're done assigning a group of options to the configuration. Subsequent group assignments should replace linelists, not extend them.
Definition at line 937 of file confmgt.c.
Referenced by config_service(), disk_state_load_from_disk_impl(), hs_ob_parse_config_file(), options_init(), options_init_from_string(), options_trial_assign(), and or_state_load().
| bool config_check_ok | ( | const config_mgr_t * | mgr, |
| const void * | options, | ||
| int | severity ) |
| void config_check_toplevel_magic | ( | const config_mgr_t * | mgr, |
| const void * | object ) |
| char * config_dump | ( | const config_mgr_t * | mgr, |
| const void * | default_options, | ||
| const void * | options, | ||
| int | minimal, | ||
| int | comment_defaults ) |
Allocate and return a new string holding the written-out values of the vars in 'options'. If 'minimal', do not write out any default-valued vars. Else, if comment_defaults, write default values as comments.
Definition at line 1314 of file confmgt.c.
Referenced by disk_state_save_to_disk(), options_dump(), and or_state_save().
| void * config_dup | ( | const config_mgr_t * | mgr, |
| const void * | old ) |
Copy storage held by old into a new or_options_t and return it.
Definition at line 1132 of file confmgt.c.
Referenced by options_init_from_string(), and options_trial_assign().
| const char * config_expand_abbrev | ( | const config_mgr_t * | mgr, |
| const char * | option, | ||
| int | command_line, | ||
| int | warn_obsolete ) |
If option is an official abbreviation for a longer option, return the longer option. Otherwise return option. If command_line is set, apply all abbreviations. Otherwise, only apply abbreviations that work for the config file and the command line. If warn_obsolete is set, warn about deprecated names.
Definition at line 415 of file confmgt.c.
Referenced by config_assign(), config_find_option_name(), and config_parse_commandline().
| const char * config_find_deprecation | ( | const config_mgr_t * | mgr, |
| const char * | key ) |
If key is a deprecated configuration option, return the message explaining why it is deprecated (which may be an empty string). Return NULL if it is not deprecated. The key field must be fully expanded.
Definition at line 442 of file confmgt.c.
Referenced by config_assign_line().
| const char * config_find_option_name | ( | const config_mgr_t * | mgr, |
| const char * | key ) |
If key is a name or an abbreviation configuration option, return the corresponding canonical name for it. Warn if the abbreviation is non-standard. Return NULL if the option does not exist.
Definition at line 513 of file confmgt.c.
Referenced by option_get_canonical_name(), and option_is_recognized().
| void config_free_ | ( | const config_mgr_t * | mgr, |
| void * | options ) |
| struct config_line_t * config_get_assigned_option | ( | const config_mgr_t * | mgr, |
| const void * | options, | ||
| const char * | key, | ||
| int | escape_val ) |
Return newly allocated line or lines corresponding to key in the configuration options. If escape_val is true and a value needs to be quoted before it's put in a config file, quote and escape that value. Return NULL if no such key exists.
Definition at line 843 of file confmgt.c.
Referenced by config_dump(), config_get_changes(), option_get_assignment(), and warn_about_relative_paths().
| struct config_line_t * config_get_changes | ( | const config_mgr_t * | mgr, |
| const void * | options1, | ||
| const void * | options2 ) |
Return a list of the options which have changed between options1 and options2. If an option has reverted to its default value, it has a value entry of NULL.
options1 and options2 must be top-level configuration objects of the type managed by mgr.
Definition at line 1096 of file confmgt.c.
Referenced by set_options().
| void config_init | ( | const config_mgr_t * | mgr, |
| void * | options ) |
Set all vars in the configuration object options to their default values.
Definition at line 1158 of file confmgt.c.
Referenced by config_dump(), disk_state_new(), hs_opts_new(), ob_option_new(), and options_init().
| int config_is_same | ( | const config_mgr_t * | mgr, |
| const void * | o1, | ||
| const void * | o2, | ||
| const char * | name ) |
Return true iff the option name has the same value in o1 and o2. Must not be called for LINELIST_S or OBSOLETE options.
Definition at line 1070 of file confmgt.c.
Referenced by config_dump().
| int config_mgr_add_format | ( | config_mgr_t * | mgr, |
| const config_format_t * | fmt ) |
Add a new format to this configuration object. Asserts on failure.
Returns an internal "index" value used to identify this format within all of those formats contained in mgr. This index value should not generally be used outside of this module.
Definition at line 216 of file confmgt.c.
Referenced by subsystems_register_options_formats(), and subsystems_register_state_formats().
| void config_mgr_free_ | ( | config_mgr_t * | mgr | ) |
| void config_mgr_freeze | ( | config_mgr_t * | mgr | ) |
Mark a configuration manager as "frozen", so that no more formats can be added, and so that it can be used for manipulating configuration objects.
Definition at line 285 of file confmgt.c.
Referenced by get_hs_opts_mgr(), get_options_mgr(), get_srs_mgr(), and get_state_mgr().
| const void * config_mgr_get_obj | ( | const config_mgr_t * | mgr, |
| const void * | toplevel, | ||
| int | idx ) |
As config_mgr_get_obj_mutable(), but return a const pointer.
Definition at line 265 of file confmgt.c.
Referenced by config_dup(), config_get_assigned_option(), config_get_changes(), and config_is_same().
| void * config_mgr_get_obj_mutable | ( | const config_mgr_t * | mgr, |
| void * | toplevel, | ||
| int | idx ) |
Return a pointer to the configuration object within toplevel whose index is idx.
NOTE: XXXX Eventually, there will be multiple objects supported within the toplevel object. For example, the or_options_t will contain pointers to configuration objects for other modules. This function gets the sub-object for a particular module.
Definition at line 246 of file confmgt.c.
Referenced by config_assign_value(), config_clear(), config_dup(), config_mark_lists_fragile(), config_mgr_get_obj(), subsystems_flush_state(), subsystems_set_options(), and subsystems_set_state().
| struct smartlist_t * config_mgr_list_deprecated_vars | ( | const config_mgr_t * | mgr | ) |
Return a new smartlist_t containing the names of all deprecated variables. The elements of this smartlist do not need to be freed; they have the same lifespan as mgr.
Definition at line 333 of file confmgt.c.
Referenced by list_deprecated_options().
| struct smartlist_t * config_mgr_list_vars | ( | const config_mgr_t * | mgr | ) |
Return a new smartlist_t containing a config_var_t for every variable that mgr knows about. The elements of this smartlist do not need to be freed; they have the same lifespan as mgr.
Definition at line 319 of file confmgt.c.
Referenced by getinfo_helper_config(), list_torrc_options(), and warn_about_relative_paths().
| config_mgr_t * config_mgr_new | ( | const config_format_t * | toplevel_fmt | ) |
Create a new config_mgr_t to manage a set of configuration objects to be wrapped under toplevel_fmt.
Definition at line 145 of file confmgt.c.
Referenced by get_hs_opts_mgr(), get_options_mgr(), get_srs_mgr(), and get_state_mgr().
| void * config_new | ( | const config_mgr_t * | mgr | ) |
Allocate an empty configuration object of a given format type.
Definition at line 387 of file confmgt.c.
Referenced by config_dump(), config_dup(), disk_state_new(), hs_opts_new(), ob_option_new(), and options_new().
| validation_status_t config_validate | ( | const config_mgr_t * | mgr, |
| const void * | old_options, | ||
| void * | options, | ||
| char ** | msg_out ) |
Normalize and validate all the options in configuration object options and its sub-objects. options may be modified as appropriate in order to set ancillary data. If old_options is provided, make sure that the transition from old_options to options is permitted.
On success return VSTAT_OK; on failure set *msg_out to a newly allocated string explaining what is wrong, and return a different validation_status_t to describe which step failed.
Definition at line 1272 of file confmgt.c.
Referenced by config_dump(), config_service(), options_validate_and_set(), and or_state_validate().
| bool config_var_is_listable | ( | const config_var_t * | var | ) |
Return true iff variable var should appear on list of variable names given to the controller or the CLI.
(Note that this option is imperfectly obeyed. The –list-torrc-options command looks at the "settable" flag, whereas "GETINFO config/defaults" and "list_deprecated_*()" do not filter their results. It would be good for consistency to try to converge these behaviors in the future.)
Definition at line 619 of file confmgt.c.
Referenced by getinfo_helper_config().
| bool config_var_is_settable | ( | const config_var_t * | var | ) |
Return true iff var may be assigned by name (e.g., via the CLI, the configuration files, or the controller API).
Definition at line 558 of file confmgt.c.
Referenced by list_torrc_options().
| void warn_deprecated_option | ( | const char * | what, |
| const char * | why ) |
Log a warning that declaring that the option called what is deprecated because of the reason in why.
(Both arguments must be non-NULL.)
Definition at line 692 of file confmgt.c.
Referenced by config_assign_line().