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.
This commit is contained in:
Esa Korhonen 2019-02-04 16:07:09 +02:00
parent 5ab7734e9d
commit 78d9ef2910
7 changed files with 22 additions and 40 deletions

View File

@ -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.

View File

@ -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());
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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;