mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
Rename cross-format config.c stuff to config_* and or_options_t-specific stuff to option[s]_*
svn:r4641
This commit is contained in:
parent
3cb7b97660
commit
2bd6040f62
@ -371,7 +371,7 @@ options_act(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mark_logs_temp(); /* Close current logs once new logs are open. */
|
mark_logs_temp(); /* Close current logs once new logs are open. */
|
||||||
if (config_init_logs(options, 0)<0) /* Configure the log(s) */
|
if (options_init_logs(options, 0)<0) /* Configure the log(s) */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Close the temporary log we used while starting up, if it isn't already
|
/* Close the temporary log we used while starting up, if it isn't already
|
||||||
@ -741,7 +741,7 @@ config_reset_line(config_format_t *fmt, or_options_t *options, const char *key)
|
|||||||
|
|
||||||
/** Return true iff key is a valid configuration option. */
|
/** Return true iff key is a valid configuration option. */
|
||||||
int
|
int
|
||||||
config_option_is_recognized(const char *key)
|
option_is_recognized(const char *key)
|
||||||
{
|
{
|
||||||
config_var_t *var = config_find_option(&config_format, key);
|
config_var_t *var = config_find_option(&config_format, key);
|
||||||
return (var != NULL);
|
return (var != NULL);
|
||||||
@ -749,7 +749,7 @@ config_option_is_recognized(const char *key)
|
|||||||
|
|
||||||
/** Return the canonical name of a configuration option. */
|
/** Return the canonical name of a configuration option. */
|
||||||
const char *
|
const char *
|
||||||
config_option_get_canonical_name(const char *key)
|
option_get_canonical_name(const char *key)
|
||||||
{
|
{
|
||||||
config_var_t *var = config_find_option(&config_format, key);
|
config_var_t *var = config_find_option(&config_format, key);
|
||||||
return var->name;
|
return var->name;
|
||||||
@ -758,7 +758,7 @@ config_option_get_canonical_name(const char *key)
|
|||||||
/** Return a canonicalized list of the options assigned for key.
|
/** Return a canonicalized list of the options assigned for key.
|
||||||
*/
|
*/
|
||||||
config_line_t *
|
config_line_t *
|
||||||
config_get_assigned_option(or_options_t *options, const char *key)
|
option_get_assignment(or_options_t *options, const char *key)
|
||||||
{
|
{
|
||||||
return get_assigned_option(&config_format, options, key);
|
return get_assigned_option(&config_format, options, key);
|
||||||
}
|
}
|
||||||
@ -904,7 +904,7 @@ config_assign(config_format_t *fmt,
|
|||||||
* keys, -2 on bad values, -3 on bad transition.
|
* keys, -2 on bad values, -3 on bad transition.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
config_trial_assign(config_line_t *list, int reset)
|
options_trial_assign(config_line_t *list, int reset)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
or_options_t *trial_options = options_dup(&config_format, get_options());
|
or_options_t *trial_options = options_dup(&config_format, get_options());
|
||||||
@ -1300,7 +1300,7 @@ config_dump(config_format_t *fmt, or_options_t *options, int minimal)
|
|||||||
* include options that are the same as Tor's defaults.
|
* include options that are the same as Tor's defaults.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
config_dump_options(or_options_t *options, int minimal)
|
options_dump(or_options_t *options, int minimal)
|
||||||
{
|
{
|
||||||
return config_dump(&config_format, options, minimal);
|
return config_dump(&config_format, options, minimal);
|
||||||
}
|
}
|
||||||
@ -1386,7 +1386,7 @@ options_validate(or_options_t *options)
|
|||||||
config_line_append(&options->Logs, "Log", "notice stdout");
|
config_line_append(&options->Logs, "Log", "notice stdout");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_init_logs(options, 1)<0) /* Validate the log(s) */
|
if (options_init_logs(options, 1)<0) /* Validate the log(s) */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (server_mode(options)) {
|
if (server_mode(options)) {
|
||||||
@ -1672,7 +1672,7 @@ options_validate(or_options_t *options)
|
|||||||
log_fn(LOG_WARN, "Error in Exit Policy entry.");
|
log_fn(LOG_WARN, "Error in Exit Policy entry.");
|
||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
config_append_default_exit_policy(&addr_policy);
|
options_append_default_exit_policy(&addr_policy);
|
||||||
if (server_mode(options)) {
|
if (server_mode(options)) {
|
||||||
exit_policy_implicitly_allows_local_networks(addr_policy, 1);
|
exit_policy_implicitly_allows_local_networks(addr_policy, 1);
|
||||||
}
|
}
|
||||||
@ -1853,7 +1853,7 @@ check_nickname_list(const char *lst, const char *name)
|
|||||||
* validate them for consistency, then take actions based on them.
|
* validate them for consistency, then take actions based on them.
|
||||||
* Return 0 if success, -1 if failure. */
|
* Return 0 if success, -1 if failure. */
|
||||||
int
|
int
|
||||||
init_from_config(int argc, char **argv)
|
options_init_from_torrc(int argc, char **argv)
|
||||||
{
|
{
|
||||||
or_options_t *oldoptions, *newoptions;
|
or_options_t *oldoptions, *newoptions;
|
||||||
config_line_t *cl;
|
config_line_t *cl;
|
||||||
@ -2117,7 +2117,7 @@ convert_log_option(or_options_t *options, config_line_t *level_opt,
|
|||||||
* Initialize the logs based on the configuration file.
|
* Initialize the logs based on the configuration file.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
config_init_logs(or_options_t *options, int validate_only)
|
options_init_logs(or_options_t *options, int validate_only)
|
||||||
{
|
{
|
||||||
config_line_t *opt;
|
config_line_t *opt;
|
||||||
int ok;
|
int ok;
|
||||||
@ -2277,7 +2277,7 @@ normalize_log_options(or_options_t *options)
|
|||||||
/** Add the default exit policy entries to <b>policy</b>
|
/** Add the default exit policy entries to <b>policy</b>
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
config_append_default_exit_policy(addr_policy_t **policy)
|
options_append_default_exit_policy(addr_policy_t **policy)
|
||||||
{
|
{
|
||||||
config_line_t tmp;
|
config_line_t tmp;
|
||||||
addr_policy_t *ap;
|
addr_policy_t *ap;
|
||||||
@ -2552,7 +2552,7 @@ write_configuration_file(const char *fname, or_options_t *options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new_conf = config_dump_options(options, 1))) {
|
if (!(new_conf = options_dump(options, 1))) {
|
||||||
log_fn(LOG_WARN, "Couldn't get configuration string");
|
log_fn(LOG_WARN, "Couldn't get configuration string");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -2599,7 +2599,7 @@ write_configuration_file(const char *fname, or_options_t *options)
|
|||||||
* success, -1 on failure.
|
* success, -1 on failure.
|
||||||
**/
|
**/
|
||||||
int
|
int
|
||||||
save_current_config(void)
|
options_save_current(void)
|
||||||
{
|
{
|
||||||
char *fn;
|
char *fn;
|
||||||
if (config_fname) {
|
if (config_fname) {
|
||||||
|
@ -657,7 +657,7 @@ handle_control_setconf(connection_t *conn, uint32_t len, char *body)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r=config_trial_assign(lines, 1)) < 0) {
|
if ((r=options_trial_assign(lines, 1)) < 0) {
|
||||||
log_fn(LOG_WARN,"Controller gave us config lines that didn't validate.");
|
log_fn(LOG_WARN,"Controller gave us config lines that didn't validate.");
|
||||||
if (r==-1) {
|
if (r==-1) {
|
||||||
if (v0)
|
if (v0)
|
||||||
@ -709,7 +709,7 @@ handle_control_getconf(connection_t *conn, uint32_t body_len, const char *body)
|
|||||||
unrecognized = smartlist_create();
|
unrecognized = smartlist_create();
|
||||||
SMARTLIST_FOREACH(questions, char *, q,
|
SMARTLIST_FOREACH(questions, char *, q,
|
||||||
{
|
{
|
||||||
if (!config_option_is_recognized(q)) {
|
if (!option_is_recognized(q)) {
|
||||||
if (v0) {
|
if (v0) {
|
||||||
send_control0_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, q);
|
send_control0_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, q);
|
||||||
goto done;
|
goto done;
|
||||||
@ -717,9 +717,9 @@ handle_control_getconf(connection_t *conn, uint32_t body_len, const char *body)
|
|||||||
smartlist_add(unrecognized, q);
|
smartlist_add(unrecognized, q);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config_line_t *answer = config_get_assigned_option(options,q);
|
config_line_t *answer = option_get_assignment(options,q);
|
||||||
if (!v0 && !answer) {
|
if (!v0 && !answer) {
|
||||||
const char *name = config_option_get_canonical_name(q);
|
const char *name = option_get_canonical_name(q);
|
||||||
size_t alen = strlen(name)+8;
|
size_t alen = strlen(name)+8;
|
||||||
char *astr = tor_malloc(alen);
|
char *astr = tor_malloc(alen);
|
||||||
tor_snprintf(astr, alen, "250-%s\r\n", name);
|
tor_snprintf(astr, alen, "250-%s\r\n", name);
|
||||||
@ -959,7 +959,7 @@ static int
|
|||||||
handle_control_saveconf(connection_t *conn, uint32_t len,
|
handle_control_saveconf(connection_t *conn, uint32_t len,
|
||||||
const char *body)
|
const char *body)
|
||||||
{
|
{
|
||||||
if (save_current_config()<0) {
|
if (options_save_current()<0) {
|
||||||
if (STATE_IS_V0(conn->state))
|
if (STATE_IS_V0(conn->state))
|
||||||
send_control0_error(conn, ERR_INTERNAL,
|
send_control0_error(conn, ERR_INTERNAL,
|
||||||
"Unable to write configuration to disk.");
|
"Unable to write configuration to disk.");
|
||||||
|
@ -911,7 +911,7 @@ do_hup(void)
|
|||||||
addressmap_clear_transient();
|
addressmap_clear_transient();
|
||||||
/* first, reload config variables, in case they've changed */
|
/* first, reload config variables, in case they've changed */
|
||||||
/* no need to provide argc/v, they've been cached inside init_from_config */
|
/* no need to provide argc/v, they've been cached inside init_from_config */
|
||||||
if (init_from_config(0, NULL) < 0) {
|
if (options_init_from_torrc(0, NULL) < 0) {
|
||||||
log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1303,7 +1303,7 @@ tor_init(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
atexit(exit_function);
|
atexit(exit_function);
|
||||||
|
|
||||||
if (init_from_config(argc,argv) < 0) {
|
if (options_init_from_torrc(argc,argv) < 0) {
|
||||||
log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
18
src/or/or.h
18
src/or/or.h
@ -1333,21 +1333,21 @@ const char *safe_str(const char *address);
|
|||||||
|
|
||||||
int config_get_lines(char *string, config_line_t **result);
|
int config_get_lines(char *string, config_line_t **result);
|
||||||
void config_free_lines(config_line_t *front);
|
void config_free_lines(config_line_t *front);
|
||||||
int config_trial_assign(config_line_t *list, int reset);
|
int options_trial_assign(config_line_t *list, int reset);
|
||||||
int resolve_my_address(or_options_t *options, uint32_t *addr);
|
int resolve_my_address(or_options_t *options, uint32_t *addr);
|
||||||
void options_init(or_options_t *options);
|
void options_init(or_options_t *options);
|
||||||
int init_from_config(int argc, char **argv);
|
int options_init_from_torrc(int argc, char **argv);
|
||||||
int config_init_logs(or_options_t *options, int validate_only);
|
int options_init_logs(or_options_t *options, int validate_only);
|
||||||
int config_parse_addr_policy(config_line_t *cfg,
|
int config_parse_addr_policy(config_line_t *cfg,
|
||||||
addr_policy_t **dest);
|
addr_policy_t **dest);
|
||||||
void config_append_default_exit_policy(addr_policy_t **policy);
|
void options_append_default_exit_policy(addr_policy_t **policy);
|
||||||
void addr_policy_free(addr_policy_t *p);
|
void addr_policy_free(addr_policy_t *p);
|
||||||
int config_option_is_recognized(const char *key);
|
int option_is_recognized(const char *key);
|
||||||
const char *config_option_get_canonical_name(const char *key);
|
const char *option_get_canonical_name(const char *key);
|
||||||
config_line_t *config_get_assigned_option(or_options_t *options,
|
config_line_t *option_get_assignment(or_options_t *options,
|
||||||
const char *key);
|
const char *key);
|
||||||
char *config_dump_options(or_options_t *options, int minimal);
|
char *options_dump(or_options_t *options, int minimal);
|
||||||
int save_current_config(void);
|
int options_save_current(void);
|
||||||
|
|
||||||
/********************************* connection.c ***************************/
|
/********************************* connection.c ***************************/
|
||||||
|
|
||||||
|
@ -752,7 +752,7 @@ router_rebuild_descriptor(int force)
|
|||||||
ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
|
ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
|
||||||
|
|
||||||
config_parse_addr_policy(get_options()->ExitPolicy, &ri->exit_policy);
|
config_parse_addr_policy(get_options()->ExitPolicy, &ri->exit_policy);
|
||||||
config_append_default_exit_policy(&ri->exit_policy);
|
options_append_default_exit_policy(&ri->exit_policy);
|
||||||
|
|
||||||
if (desc_routerinfo) /* inherit values */
|
if (desc_routerinfo) /* inherit values */
|
||||||
ri->is_verified = desc_routerinfo->is_verified;
|
ri->is_verified = desc_routerinfo->is_verified;
|
||||||
|
@ -1406,7 +1406,7 @@ test_exit_policies(void)
|
|||||||
|
|
||||||
/* Copied from router.c */
|
/* Copied from router.c */
|
||||||
policy = NULL;
|
policy = NULL;
|
||||||
config_append_default_exit_policy(&policy);
|
options_append_default_exit_policy(&policy);
|
||||||
test_assert(policy);
|
test_assert(policy);
|
||||||
test_assert(!exit_policy_implicitly_allows_local_networks(policy, 1));
|
test_assert(!exit_policy_implicitly_allows_local_networks(policy, 1));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user