From 78d9ef291069a90a72c4094f3c039b94e103a779 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Mon, 4 Feb 2019 16:07:09 +0200 Subject: [PATCH] MXS-2304 Remove remaining uses of config_get_string() from module code The function returns a pointer to an internal string and should not be used. --- include/maxscale/config.hh | 19 ------------------- server/core/config.cc | 5 ----- server/core/internal/config.hh | 10 ++++++++++ .../namedserverfilter/namedserverfilter.cc | 4 ++-- .../modules/filter/regexfilter/regexfilter.cc | 8 ++++---- server/modules/filter/tee/tee.cc | 12 ++++-------- .../routing/readwritesplit/readwritesplit.cc | 4 ++-- 7 files changed, 22 insertions(+), 40 deletions(-) diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index 20bd3e8c1..861c762b0 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -231,15 +231,6 @@ public: */ std::string get_string(const std::string& key) const; - /** - * Get value of key as c-string. The pointer is valid as long as the underlying configuration - * is not changed. - * - * @param key Parameter name - * @return Parameter value. Empty string if key not found. - */ - const char* get_c_str(const std::string& key) const; - /** * @brief Get copy of parameter value if it is defined * @@ -431,16 +422,6 @@ bool config_param_is_valid(const MXS_MODULE_PARAM* params, const char* value, const CONFIG_CONTEXT* context); -/** - * @brief Get a string value - * - * @param params List of configuration parameters - * @param key Parameter name - * - * @return The raw string value or an empty string if no parameter was found - */ -const char* config_get_string(const MXS_CONFIG_PARAMETER* params, const char* key); - /** * @brief Get an array of servers. The caller should free the produced array, * but not the array elements. diff --git a/server/core/config.cc b/server/core/config.cc index 976d0cee8..9052d0a97 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -1909,11 +1909,6 @@ bool config_get_compiled_regexes(const MXS_CONFIG_PARAMETER* params, } string MXS_CONFIG_PARAMETER::get_string(const std::string& key) const -{ - return get_c_str(key); -} - -const char* MXS_CONFIG_PARAMETER::get_c_str(const std::string& key) const { return config_get_string(this, key.c_str()); } diff --git a/server/core/internal/config.hh b/server/core/internal/config.hh index 16fa46292..261b4e083 100644 --- a/server/core/internal/config.hh +++ b/server/core/internal/config.hh @@ -245,3 +245,13 @@ bool config_can_modify_at_runtime(const char* name); * @return The parameter or NULL if the parameter was not found */ MXS_CONFIG_PARAMETER* config_get_param(MXS_CONFIG_PARAMETER* params, const char* name); + +/** + * @brief Get a string value + * + * @param params List of configuration parameters + * @param key Parameter name + * + * @return The raw string value or an empty string if no parameter was found + */ +const char* config_get_string(const MXS_CONFIG_PARAMETER* params, const char* key); diff --git a/server/modules/filter/namedserverfilter/namedserverfilter.cc b/server/modules/filter/namedserverfilter/namedserverfilter.cc index 56a9f174e..9edcd66d1 100644 --- a/server/modules/filter/namedserverfilter/namedserverfilter.cc +++ b/server/modules/filter/namedserverfilter/namedserverfilter.cc @@ -250,9 +250,9 @@ RegexHintFilter* RegexHintFilter::create(const char* name, MXS_CONFIG_PARAMETER* SourceHostVector source_addresses; StringVector source_hostnames; - const char* source = config_get_string(params, "source"); + std::string source = params->get_string("source"); - if (*source) + if (!source.empty()) { set_source_addresses(source, source_addresses, source_hostnames); } diff --git a/server/modules/filter/regexfilter/regexfilter.cc b/server/modules/filter/regexfilter/regexfilter.cc index 5b03de3c1..0d8d8d565 100644 --- a/server/modules/filter/regexfilter/regexfilter.cc +++ b/server/modules/filter/regexfilter/regexfilter.cc @@ -212,13 +212,13 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params my_instance->user = params->get_c_str_copy("user"); my_instance->log_trace = params->get_bool("log_trace"); - const char* logfile = config_get_string(params, "log_file"); + std::string logfile = params->get_string("log_file"); - if (*logfile) + if (!logfile.empty()) { - if ((my_instance->logfile = fopen(logfile, "a")) == NULL) + if ((my_instance->logfile = fopen(logfile.c_str(), "a")) == NULL) { - MXS_ERROR("Failed to open file '%s'.", logfile); + MXS_ERROR("Failed to open file '%s'.", logfile.c_str()); free_instance(my_instance); return NULL; } diff --git a/server/modules/filter/tee/tee.cc b/server/modules/filter/tee/tee.cc index 49b423541..9c2198223 100644 --- a/server/modules/filter/tee/tee.cc +++ b/server/modules/filter/tee/tee.cc @@ -65,21 +65,17 @@ Tee::Tee(SERVICE* service, Tee* Tee::create(const char* name, MXS_CONFIG_PARAMETER* params) { SERVICE* service = params->get_service("service"); - const char* source = config_get_string(params, "source"); - const char* user = config_get_string(params, "user"); uint32_t cflags = params->get_enum("options", option_values); pcre2_code* match = config_get_compiled_regex(params, "match", cflags, NULL); pcre2_code* exclude = config_get_compiled_regex(params, "exclude", cflags, NULL); - const char* match_str = config_get_string(params, "match"); - const char* exclude_str = config_get_string(params, "exclude"); Tee* my_instance = new(std::nothrow) Tee(service, - source, - user, + params->get_string("source"), + params->get_string("user"), match, - match_str, + params->get_string("match"), exclude, - exclude_str); + params->get_string("exclude")); if (my_instance == NULL) { diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index 8366a9e0c..9d4835296 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -223,7 +223,7 @@ RWSplit* RWSplit::create(SERVICE* service, MXS_CONFIG_PARAMETER* params) Config config(params); - if (!handle_max_slaves(config, config_get_string(params, "max_slave_connections"))) + if (!handle_max_slaves(config, params->get_string("max_slave_connections").c_str())) { return NULL; } @@ -447,7 +447,7 @@ bool RWSplit::configure(MXS_CONFIG_PARAMETER* params) bool rval = false; Config cnf(params); - if (handle_max_slaves(cnf, config_get_string(params, "max_slave_connections"))) + if (handle_max_slaves(cnf, params->get_string("max_slave_connections").c_str())) { m_config.assign(cnf); rval = true;