diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2020-01-15 16:57:00 +0000 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2020-01-15 16:57:03 +0000 |
commit | 5dd514af93675602cdece2b7b2112989b87d5d51 (patch) | |
tree | 3f175638fa5c62364627df97aa8a1035c0fa8154 | |
parent | 27d96df99900c5a62ab0fdf2a37565e78f256d6a (diff) |
conf: fix loading of default values
previously, default values were stored once into a static struct,
then on each reload item by item copied manually into a "new"
config struct.
this has proven to be errorprone, as additions in one of the 2
locations were not propagated to the second one, apart from
being simply a lot of gratuitous code.
we now simply load the default values directly into the config
struct to be used on each reload.
closes #283
-rw-r--r-- | src/conf.c | 104 | ||||
-rw-r--r-- | src/conf.h | 5 | ||||
-rw-r--r-- | src/main.c | 5 |
3 files changed, 5 insertions, 109 deletions
@@ -441,7 +441,7 @@ done: return ret; } -void initialize_config_defaults (struct config_s *conf) +static void initialize_config_defaults (struct config_s *conf) { memset (conf, 0, sizeof(*conf)); @@ -457,108 +457,10 @@ void initialize_config_defaults (struct config_s *conf) conf->maxclients = 100; } -static void initialize_with_defaults (struct config_s *conf, - struct config_s *defaults) -{ - if (defaults->logf_name) { - conf->logf_name = safestrdup (defaults->logf_name); - } - - conf->syslog = defaults->syslog; - conf->port = defaults->port; - - if (defaults->stathost) { - conf->stathost = safestrdup (defaults->stathost); - } - - conf->quit = defaults->quit; - - if (defaults->user) { - conf->user = safestrdup (defaults->user); - } - - if (defaults->group) { - conf->group = safestrdup (defaults->group); - } - - if (defaults->listen_addrs) { - ssize_t i; - - conf->listen_addrs = vector_create(); - for (i=0; i < vector_length(defaults->listen_addrs); i++) { - char *addr; - size_t size; - addr = (char *)vector_getentry(defaults->listen_addrs, - i, &size); - vector_append(conf->listen_addrs, addr, size); - } - - } - -#ifdef FILTER_ENABLE - if (defaults->filter) { - conf->filter = safestrdup (defaults->filter); - } - - conf->filter_url = defaults->filter_url; - conf->filter_extended = defaults->filter_extended; - conf->filter_casesensitive = defaults->filter_casesensitive; -#endif /* FILTER_ENABLE */ - -#ifdef XTINYPROXY_ENABLE - conf->add_xtinyproxy = defaults->add_xtinyproxy; -#endif - -#ifdef REVERSE_SUPPORT - /* struct reversepath *reversepath_list; */ - conf->reverseonly = defaults->reverseonly; - conf->reversemagic = defaults->reversemagic; - - if (defaults->reversebaseurl) { - conf->reversebaseurl = safestrdup (defaults->reversebaseurl); - } -#endif - -#ifdef UPSTREAM_SUPPORT - /* struct upstream *upstream_list; */ -#endif /* UPSTREAM_SUPPORT */ - - if (defaults->pidpath) { - conf->pidpath = safestrdup (defaults->pidpath); - } - - conf->idletimeout = defaults->idletimeout; - - if (defaults->bind_address) { - conf->bind_address = safestrdup (defaults->bind_address); - } - - conf->bindsame = defaults->bindsame; - - if (defaults->via_proxy_name) { - conf->via_proxy_name = safestrdup (defaults->via_proxy_name); - } - - conf->disable_viaheader = defaults->disable_viaheader; - - if (defaults->errorpage_undef) { - conf->errorpage_undef = safestrdup (defaults->errorpage_undef); - } - - if (defaults->statpage) { - conf->statpage = safestrdup (defaults->statpage); - } - - /* vector_t access_list; */ - /* vector_t connect_ports; */ - /* hashmap_t anonymous_map; */ -} - /** * Load the configuration. */ -int reload_config_file (const char *config_fname, struct config_s *conf, - struct config_s *defaults) +int reload_config_file (const char *config_fname, struct config_s *conf) { int ret; @@ -566,7 +468,7 @@ int reload_config_file (const char *config_fname, struct config_s *conf, free_config (conf); - initialize_with_defaults (conf, defaults); + initialize_config_defaults (conf); ret = load_config_file (config_fname, conf); if (ret != 0) { @@ -112,10 +112,7 @@ struct config_s { vector_t add_headers; }; -void initialize_config_defaults (struct config_s *conf); - -extern int reload_config_file (const char *config_fname, struct config_s *conf, - struct config_s *defaults); +extern int reload_config_file (const char *config_fname, struct config_s *conf); int config_compile_regex (void); @@ -250,8 +250,7 @@ int reload_config (int reload_logging) if (reload_logging) shutdown_logging (); - ret = reload_config_file (config_file, &config_main, - &config_defaults); + ret = reload_config_file (config_file, &config_main); if (ret != 0) { goto done; @@ -309,8 +308,6 @@ main (int argc, char **argv) } } - initialize_config_defaults (&config_defaults); - if (reload_config(0)) { exit (EX_SOFTWARE); } |