From 3c20b47a8d1e2c3717ee9c38c1b796cbcc58dfaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 15 Aug 2018 22:44:33 +0300 Subject: [PATCH] Change parameters in dump_param Putting the file descriptor first keeps it in line with dprintf. Making the parameter set an initializer list allows matching against multiple sets of parameters in one function call. This will compact the parameter serialization by using the same code for the common service parameters and the module parameters. --- server/core/internal/config.hh | 17 ++++++++++++----- server/core/service.cc | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/server/core/internal/config.hh b/server/core/internal/config.hh index dc779da95..faa8093d2 100644 --- a/server/core/internal/config.hh +++ b/server/core/internal/config.hh @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -239,13 +240,13 @@ void dump_if_changed(const MXS_MODULE_PARAM* params, int file, * Note: Does not work with enum type parameters, they'll get converted into * integers. Convert them to string format at the call site. * - * @param params Module parameter to use * @param file File descriptor where the line is written * @param key Name of the parameter * @param value The parameter value + * @param params List of module parameters to use */ template -inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::string& key, const T value) +inline void dump_param(int file, const std::string& key, const T value, std::initializer_list params) { std::stringstream ss; ss << value; @@ -254,7 +255,10 @@ inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::stri if (!strval.empty()) { // Don't dump empty values - dump_if_changed(params, file, key, strval); + for (auto a : params) + { + dump_if_changed(a, file, key, strval); + } } } @@ -262,9 +266,12 @@ inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::stri // the defaults. This requires that all defaults use either "true" or "false" // for the values. template <> -inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::string& key, bool value) +inline void dump_param(int file, const std::string& key, bool value, std::initializer_list params) { - dump_if_changed(params, file, key, value ? "true" : "false"); + for (auto a : params) + { + dump_if_changed(a, file, key, value ? "true" : "false"); + } } } diff --git a/server/core/service.cc b/server/core/service.cc index 0e0cf94b3..3a7822c2b 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -1785,17 +1785,17 @@ bool Service::dump_config(const char *filename) const const MXS_MODULE_PARAM* mp = config_service_params; - dump_param(mp, file, CN_ENABLE_ROOT_USER, enable_root); - dump_param(mp, file, CN_MAX_RETRY_INTERVAL, max_retry_interval); - dump_param(mp, file, CN_MAX_CONNECTIONS, max_connections); - dump_param(mp, file, CN_CONNECTION_TIMEOUT, conn_idle_timeout); - dump_param(mp, file, CN_AUTH_ALL_SERVERS, users_from_all); - dump_param(mp, file, CN_STRIP_DB_ESC, strip_db_esc); - dump_param(mp, file, CN_LOCALHOST_MATCH_WILDCARD_HOST, localhost_match_wildcard_host); - dump_param(mp, file, CN_LOG_AUTH_WARNINGS, log_auth_warnings); - dump_param(mp, file, CN_RETRY_ON_FAILURE, retry_start); - dump_param(mp, file, CN_VERSION_STRING, m_version_string); - dump_param(mp, file, CN_WEIGHTBY, m_weightby); + dump_param(file, CN_ENABLE_ROOT_USER, enable_root, {mp}); + dump_param(file, CN_MAX_RETRY_INTERVAL, max_retry_interval, {mp}); + dump_param(file, CN_MAX_CONNECTIONS, max_connections, {mp}); + dump_param(file, CN_CONNECTION_TIMEOUT, conn_idle_timeout, {mp}); + dump_param(file, CN_AUTH_ALL_SERVERS, users_from_all, {mp}); + dump_param(file, CN_STRIP_DB_ESC, strip_db_esc, {mp}); + dump_param(file, CN_LOCALHOST_MATCH_WILDCARD_HOST, localhost_match_wildcard_host, {mp}); + dump_param(file, CN_LOG_AUTH_WARNINGS, log_auth_warnings, {mp}); + dump_param(file, CN_RETRY_ON_FAILURE, retry_start, {mp}); + dump_param(file, CN_VERSION_STRING, m_version_string, {mp}); + dump_param(file, CN_WEIGHTBY, m_weightby, {mp}); if (!m_filters.empty()) { @@ -1848,14 +1848,13 @@ bool Service::dump_config(const char *filename) const const MXS_MODULE* mod = get_module(m_router_name.c_str(), NULL); ss_dassert(mod); - mp = mod->parameters; // Dump router specific parameters for (auto p = svc_config_param; p; p = p->next) { if (common_params.count(p->name) == 0) { - dump_param(mp, file, p->name, p->value); + dump_param(file, p->name, p->value, {mod->parameters}); } }