MXS-2304 Use get_enum() instead of config_get_enum()
This commit is contained in:
parent
c8a84cebd0
commit
f2d2202ea3
@ -166,7 +166,7 @@ RRRouter::RRRouter(SERVICE* service)
|
||||
m_max_backends = params->get_integer(MAX_BACKENDS);
|
||||
m_write_server = config_get_server(params, WRITE_BACKEND);
|
||||
m_print_on_routing = config_get_bool(params, PRINT_ON_ROUTING);
|
||||
m_example_enum = config_get_enum(params, DUMMY, enum_example);
|
||||
m_example_enum = params->get_enum(DUMMY, enum_example);
|
||||
|
||||
RR_DEBUG("Settings read:");
|
||||
RR_DEBUG("'%s': %d", MAX_BACKENDS, m_max_backends);
|
||||
|
@ -248,6 +248,17 @@ public:
|
||||
*/
|
||||
int64_t get_integer(const std::string& key) const;
|
||||
|
||||
/**
|
||||
* Get a enumeration value.
|
||||
*
|
||||
* @param key Parameter name
|
||||
* @param enum_mapping Enum string->integer mapping
|
||||
* @return The enumeration value converted to an int or -1 if the parameter was not found
|
||||
*
|
||||
* @note The enumeration values should not use -1 so that an undefined parameter is
|
||||
* detected. If -1 is used, config_get_param() should be used to detect whether
|
||||
* the parameter exists
|
||||
*/
|
||||
int64_t get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const;
|
||||
|
||||
char* name; /**< The name of the parameter */
|
||||
@ -404,23 +415,6 @@ uint64_t config_get_size(const MXS_CONFIG_PARAMETER* params, const char* key);
|
||||
*/
|
||||
const char* config_get_string(const MXS_CONFIG_PARAMETER* params, const char* key);
|
||||
|
||||
/**
|
||||
* @brief Get a enumeration value
|
||||
*
|
||||
* @param params List of configuration parameters
|
||||
* @param key Parameter name
|
||||
* @param values All possible enumeration values
|
||||
*
|
||||
* @return The enumeration value converted to an int or -1 if the parameter was not found
|
||||
*
|
||||
* @note The enumeration values should not use -1 so that an undefined parameter is
|
||||
* detected. If -1 is used, config_get_param() should be used to detect whether
|
||||
* the parameter exists
|
||||
*/
|
||||
int config_get_enum(const MXS_CONFIG_PARAMETER* params,
|
||||
const char* key,
|
||||
const MXS_ENUM_VALUE* values);
|
||||
|
||||
/**
|
||||
* @brief Get a service value
|
||||
*
|
||||
|
@ -1742,11 +1742,11 @@ const char* config_get_string(const MXS_CONFIG_PARAMETER* params, const char* ke
|
||||
return config_get_value_string(params, key);
|
||||
}
|
||||
|
||||
int config_get_enum(const MXS_CONFIG_PARAMETER* params, const char* key, const MXS_ENUM_VALUE* enum_values)
|
||||
int64_t MXS_CONFIG_PARAMETER::get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const
|
||||
{
|
||||
const char* value = config_get_value_string(params, key);
|
||||
char tmp_val[strlen(value) + 1];
|
||||
strcpy(tmp_val, value);
|
||||
string param_value = get_string(key);
|
||||
char tmp_val[param_value.length() + 1];
|
||||
strcpy(tmp_val, param_value.c_str());
|
||||
|
||||
int rv = 0;
|
||||
bool found = false;
|
||||
@ -1756,12 +1756,12 @@ int config_get_enum(const MXS_CONFIG_PARAMETER* params, const char* key, const M
|
||||
|
||||
while (tok)
|
||||
{
|
||||
for (int i = 0; enum_values[i].name; i++)
|
||||
for (int i = 0; enum_mapping[i].name; i++)
|
||||
{
|
||||
if (strcmp(enum_values[i].name, tok) == 0)
|
||||
if (strcmp(enum_mapping[i].name, tok) == 0)
|
||||
{
|
||||
found = true;
|
||||
rv |= enum_values[i].enum_value;
|
||||
rv |= enum_mapping[i].enum_value;
|
||||
}
|
||||
}
|
||||
tok = strtok_r(NULL, delim, &endptr);
|
||||
@ -1910,11 +1910,6 @@ int64_t MXS_CONFIG_PARAMETER::get_integer(const std::string& key) const
|
||||
return value.empty() ? 0 : strtoll(value.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
int64_t MXS_CONFIG_PARAMETER::get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const
|
||||
{
|
||||
return config_get_enum(this, key.c_str(), enum_mapping);
|
||||
}
|
||||
|
||||
MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* p2 = (MXS_CONFIG_PARAMETER*)MXS_MALLOC(sizeof(MXS_CONFIG_PARAMETER));
|
||||
@ -2697,7 +2692,7 @@ bool config_create_ssl(const char* name,
|
||||
SSL_LISTENER* ssl = NULL;
|
||||
|
||||
// The enum values convert to bool
|
||||
int value = config_get_enum(params, CN_SSL, ssl_values);
|
||||
int value = params->get_enum(CN_SSL, ssl_values);
|
||||
mxb_assert(value != -1);
|
||||
|
||||
if (value)
|
||||
@ -2745,7 +2740,7 @@ bool config_create_ssl(const char* name,
|
||||
ssl = (SSL_LISTENER*)MXS_CALLOC(1, sizeof(SSL_LISTENER));
|
||||
MXS_ABORT_IF_NULL(ssl);
|
||||
|
||||
int ssl_version = config_get_enum(params, CN_SSL_VERSION, ssl_version_values);
|
||||
int ssl_version = params->get_enum(CN_SSL_VERSION, ssl_version_values);
|
||||
|
||||
ssl->ssl_method_type = (ssl_method_type_t)ssl_version;
|
||||
ssl->ssl_init_done = false;
|
||||
|
@ -195,7 +195,7 @@ bool Monitor::configure_base(const MXS_CONFIG_PARAMETER* params)
|
||||
m_settings.journal_max_age = params->get_integer(CN_JOURNAL_MAX_AGE);
|
||||
m_settings.script_timeout = params->get_integer(CN_SCRIPT_TIMEOUT);
|
||||
m_settings.script = config_get_string(params, CN_SCRIPT);
|
||||
m_settings.events = config_get_enum(params, CN_EVENTS, mxs_monitor_event_enum_values);
|
||||
m_settings.events = params->get_enum(CN_EVENTS, mxs_monitor_event_enum_values);
|
||||
m_settings.disk_space_check_interval = params->get_integer(CN_DISK_SPACE_CHECK_INTERVAL);
|
||||
m_settings.conn_settings.username = config_get_string(params, CN_USER);
|
||||
m_settings.conn_settings.password = config_get_string(params, CN_PASSWORD);
|
||||
|
@ -159,7 +159,7 @@ int test_add_parameter()
|
||||
TEST(ctx.parameters->get_integer("p2") == 123);
|
||||
TEST(config_get_bool(ctx.parameters, "p3") == true);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "default") == 0);
|
||||
TEST(config_get_enum(ctx.parameters, "p5", enum_values) == 1);
|
||||
TEST(ctx.parameters->get_enum("p5", enum_values) == 1);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p6"), "/tmp") == 0);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p7"), "my-service") == 0);
|
||||
|
||||
@ -181,7 +181,7 @@ int test_add_parameter()
|
||||
TEST(ctx.parameters->get_integer("p2") == 321);
|
||||
TEST(config_get_param(ctx.parameters, "p3") && config_get_bool(ctx.parameters, "p3") == false);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "strange") == 0);
|
||||
int val = config_get_enum(ctx.parameters, "p5", enum_values);
|
||||
int val = ctx.parameters->get_enum("p5", enum_values);
|
||||
TEST(val == 5);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p6"), "/dev/null") == 0);
|
||||
TEST(strcmp(config_get_string(ctx.parameters, "p7"), "some-service") == 0);
|
||||
|
15
server/modules/filter/cache/cachefilter.cc
vendored
15
server/modules/filter/cache/cachefilter.cc
vendored
@ -353,15 +353,12 @@ bool CacheFilter::process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& c
|
||||
config.storage = MXS_STRDUP(config_get_string(ppParams, "storage"));
|
||||
config.max_resultset_rows = ppParams->get_integer("max_resultset_rows");
|
||||
config.max_resultset_size = config_get_size(ppParams, "max_resultset_size");
|
||||
config.thread_model = static_cast<cache_thread_model_t>(config_get_enum(ppParams,
|
||||
"cached_data",
|
||||
parameter_cached_data_values));
|
||||
config.selects = static_cast<cache_selects_t>(config_get_enum(ppParams,
|
||||
"selects",
|
||||
parameter_selects_values));
|
||||
config.cache_in_trxs = static_cast<cache_in_trxs_t>(config_get_enum(ppParams,
|
||||
"cache_in_transactions",
|
||||
parameter_cache_in_trxs_values));
|
||||
config.thread_model = static_cast<cache_thread_model_t>(ppParams->get_enum("cached_data",
|
||||
parameter_cached_data_values));
|
||||
config.selects = static_cast<cache_selects_t>(ppParams->get_enum("selects",
|
||||
parameter_selects_values));
|
||||
config.cache_in_trxs = static_cast<cache_in_trxs_t>(ppParams->get_enum("cache_in_transactions",
|
||||
parameter_cache_in_trxs_values));
|
||||
config.enabled = config_get_bool(ppParams, "enabled");
|
||||
|
||||
if (!config.storage)
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
new_instance->m_match = config_get_string(params, PARAM_MATCH);
|
||||
new_instance->m_nomatch = config_get_string(params, PARAM_IGNORE);
|
||||
|
||||
int cflags = config_get_enum(params, "options", option_values);
|
||||
int cflags = params->get_enum("options", option_values);
|
||||
const char* keys[] = {PARAM_MATCH, PARAM_IGNORE};
|
||||
pcre2_code** code_arr[] = {&new_instance->re, &new_instance->nore};
|
||||
if (!config_get_compiled_regexes(params, keys, sizeof(keys) / sizeof(char*),
|
||||
|
@ -1197,7 +1197,7 @@ int global_version = 1;
|
||||
}
|
||||
|
||||
Dbfw::Dbfw(MXS_CONFIG_PARAMETER* params)
|
||||
: m_action((enum fw_actions)config_get_enum(params, "action", action_values))
|
||||
: m_action((enum fw_actions)params->get_enum("action", action_values))
|
||||
, m_log_match(0)
|
||||
, m_filename(config_get_string(params, "rules"))
|
||||
, m_version(atomic_add(&global_version, 1))
|
||||
|
@ -92,7 +92,7 @@ const char* MaskingFilterConfig::prevent_function_usage_default = config_value_t
|
||||
MaskingFilterConfig::large_payload_t MaskingFilterConfig::get_large_payload(
|
||||
const MXS_CONFIG_PARAMETER* pParams)
|
||||
{
|
||||
int value = config_get_enum(pParams, large_payload_name, large_payload_values);
|
||||
int value = pParams->get_enum(large_payload_name, large_payload_values);
|
||||
return static_cast<large_payload_t>(value);
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ std::string MaskingFilterConfig::get_rules(const MXS_CONFIG_PARAMETER* pParams)
|
||||
MaskingFilterConfig::warn_type_mismatch_t MaskingFilterConfig::get_warn_type_mismatch(
|
||||
const MXS_CONFIG_PARAMETER* pParams)
|
||||
{
|
||||
int value = config_get_enum(pParams, warn_type_mismatch_name, warn_type_mismatch_values);
|
||||
int value = pParams->get_enum(warn_type_mismatch_name, warn_type_mismatch_values);
|
||||
return static_cast<warn_type_mismatch_t>(value);
|
||||
}
|
||||
|
||||
|
@ -237,9 +237,8 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
|
||||
cinstance->config.max_resultset_size = config_get_size(params,
|
||||
"max_resultset_size");
|
||||
cinstance->config.m_return =
|
||||
static_cast<maxrows_return_mode>(config_get_enum(params,
|
||||
"max_resultset_return",
|
||||
return_option_values));
|
||||
static_cast<maxrows_return_mode>(params->get_enum("max_resultset_return",
|
||||
return_option_values));
|
||||
cinstance->config.debug = params->get_integer("debug");
|
||||
}
|
||||
|
||||
|
@ -585,7 +585,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
|
||||
|
||||
my_instance->port = params->get_integer("port");
|
||||
my_instance->trgtype =
|
||||
static_cast<log_trigger_t>(config_get_enum(params, "logging_trigger", trigger_values));
|
||||
static_cast<log_trigger_t>(params->get_enum("logging_trigger", trigger_values));
|
||||
my_instance->log_all = config_get_bool(params, "logging_log_all");
|
||||
my_instance->strict_logging = config_get_bool(params, "logging_strict");
|
||||
my_instance->hostname = MXS_STRDUP_A(config_get_string(params, "hostname"));
|
||||
|
@ -257,7 +257,7 @@ RegexHintFilter* RegexHintFilter::create(const char* name, MXS_CONFIG_PARAMETER*
|
||||
set_source_addresses(source, source_addresses, source_hostnames);
|
||||
}
|
||||
|
||||
int pcre_ops = config_get_enum(params, "options", option_values);
|
||||
int pcre_ops = params->get_enum("options", option_values);
|
||||
|
||||
std::string match_val_legacy(config_get_string(params, MATCH_STR));
|
||||
std::string server_val_legacy(config_get_string(params, SERVER_STR));
|
||||
|
@ -129,7 +129,7 @@ NullFilter* NullFilter::create(const char* zName, MXS_CONFIG_PARAMETER* pParams)
|
||||
{
|
||||
NullFilter* pFilter = NULL;
|
||||
|
||||
uint64_t capabilities = config_get_enum(pParams, CAPABILITIES_PARAM, capability_values);
|
||||
uint64_t capabilities = pParams->get_enum(CAPABILITIES_PARAM, capability_values);
|
||||
|
||||
return new NullFilter(zName, capabilities);
|
||||
}
|
||||
|
@ -226,8 +226,8 @@ public:
|
||||
|
||||
QlaInstance::QlaInstance(const char* name, MXS_CONFIG_PARAMETER* params)
|
||||
: name(name)
|
||||
, log_mode_flags(config_get_enum(params, PARAM_LOG_TYPE, log_type_values))
|
||||
, log_file_data_flags(config_get_enum(params, PARAM_LOG_DATA, log_data_values))
|
||||
, log_mode_flags(params->get_enum(PARAM_LOG_TYPE, log_type_values))
|
||||
, log_file_data_flags(params->get_enum(PARAM_LOG_DATA, log_data_values))
|
||||
, filebase(config_get_string(params, PARAM_FILEBASE))
|
||||
, unified_fp(NULL)
|
||||
, flush_writes(config_get_bool(params, PARAM_FLUSH))
|
||||
@ -468,7 +468,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
|
||||
pcre2_code* re_match = NULL;
|
||||
pcre2_code* re_exclude = NULL;
|
||||
uint32_t ovec_size = 0;
|
||||
int cflags = config_get_enum(params, PARAM_OPTIONS, option_values);
|
||||
int cflags = params->get_enum(PARAM_OPTIONS, option_values);
|
||||
pcre2_code** code_arr[] = {&re_match, &re_exclude};
|
||||
if (config_get_compiled_regexes(params,
|
||||
keys,
|
||||
|
@ -227,7 +227,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
|
||||
fflush(my_instance->logfile);
|
||||
}
|
||||
|
||||
int cflags = config_get_enum(params, "options", option_values);
|
||||
int cflags = params->get_enum("options", option_values);
|
||||
|
||||
if (!(my_instance->re = config_get_compiled_regex(params, "match", cflags, nullptr)))
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ Tee* Tee::create(const char* name, MXS_CONFIG_PARAMETER* params)
|
||||
SERVICE* service = config_get_service(params, "service");
|
||||
const char* source = config_get_string(params, "source");
|
||||
const char* user = config_get_string(params, "user");
|
||||
uint32_t cflags = config_get_enum(params, "options", option_values);
|
||||
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");
|
||||
|
@ -219,7 +219,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
|
||||
my_instance->user = config_copy_string(params, "user");
|
||||
my_instance->filebase = MXS_STRDUP_A(config_get_string(params, "filebase"));
|
||||
|
||||
int cflags = config_get_enum(params, "options", option_values);
|
||||
int cflags = params->get_enum("options", option_values);
|
||||
bool error = false;
|
||||
|
||||
if (my_instance->match
|
||||
|
@ -61,9 +61,8 @@ static bool conversion_task_ctl(Avro* inst, bool start);
|
||||
MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
uint64_t block_size = config_get_size(service->svc_config_param, "block_size");
|
||||
mxs_avro_codec_type codec = static_cast<mxs_avro_codec_type>(config_get_enum(service->svc_config_param,
|
||||
"codec",
|
||||
codec_values));
|
||||
mxs_avro_codec_type codec = static_cast<mxs_avro_codec_type>(
|
||||
service->svc_config_param->get_enum("codec", codec_values));
|
||||
std::string avrodir = config_get_string(service->svc_config_param, "avrodir");
|
||||
SRowEventHandler handler(new AvroConverter(avrodir, block_size, codec));
|
||||
|
||||
|
@ -381,9 +381,7 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
|
||||
|
||||
/* Binlog encryption */
|
||||
inst->encryption.enabled = config_get_bool(params, "encrypt_binlog");
|
||||
inst->encryption.encryption_algorithm = config_get_enum(params,
|
||||
"encryption_algorithm",
|
||||
enc_algo_values);
|
||||
inst->encryption.encryption_algorithm = params->get_enum("encryption_algorithm", enc_algo_values);
|
||||
inst->encryption.key_management_filename = config_copy_string(params,
|
||||
"encryption_key_file");
|
||||
|
||||
|
@ -60,9 +60,7 @@ HintRouter* HintRouter::create(SERVICE* pService, MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
HR_ENTRY();
|
||||
|
||||
HINT_TYPE default_action = (HINT_TYPE)config_get_enum(params,
|
||||
DEFAULT_ACTION,
|
||||
default_action_values);
|
||||
HINT_TYPE default_action = (HINT_TYPE)params->get_enum(DEFAULT_ACTION, default_action_values);
|
||||
string default_server(config_get_string(params, DEFAULT_SERVER));
|
||||
int max_slaves = params->get_integer(MAX_SLAVES);
|
||||
return new HintRouter(pService, default_action, default_server, max_slaves);
|
||||
|
@ -134,15 +134,12 @@ struct Config
|
||||
{
|
||||
Config(MXS_CONFIG_PARAMETER* params)
|
||||
: slave_selection_criteria(
|
||||
(select_criteria_t)config_get_enum(
|
||||
params, "slave_selection_criteria", slave_selection_criteria_values))
|
||||
(select_criteria_t)params->get_enum("slave_selection_criteria", slave_selection_criteria_values))
|
||||
, backend_select_fct(get_backend_select_function(slave_selection_criteria))
|
||||
, use_sql_variables_in(
|
||||
(mxs_target_t)config_get_enum(
|
||||
params, "use_sql_variables_in", use_sql_variables_in_values))
|
||||
(mxs_target_t)params->get_enum("use_sql_variables_in", use_sql_variables_in_values))
|
||||
, master_failure_mode(
|
||||
(enum failure_mode)config_get_enum(
|
||||
params, "master_failure_mode", master_failure_mode_values))
|
||||
(enum failure_mode)params->get_enum("master_failure_mode", master_failure_mode_values))
|
||||
, max_sescmd_history(params->get_integer("max_sescmd_history"))
|
||||
, disable_sescmd_history(config_get_bool(params, "disable_sescmd_history"))
|
||||
, master_accept_reads(config_get_bool(params, "master_accept_reads"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user