MXS-2304 Move last config_get_x() functions inside class

This commit is contained in:
Esa Korhonen
2019-02-20 14:45:53 +02:00
parent 019c8fc2e1
commit 900cbb4cff
13 changed files with 127 additions and 139 deletions

View File

@ -15,15 +15,16 @@
#include <string>
#include <maxscale/ccdefs.hh>
#include <maxscale/filter.hh>
#include <maxscale/pcre2.hh>
#include "binlogfiltersession.hh"
// Binlog Filter configuration
struct BinlogConfig
{
BinlogConfig(const MXS_CONFIG_PARAMETER* pParams)
: match(config_get_compiled_regex(pParams, "match", 0, nullptr))
: match(pParams->get_compiled_regex("match", 0, nullptr).release())
, md_match(match ? pcre2_match_data_create_from_pattern(match, nullptr) : nullptr)
, exclude(config_get_compiled_regex(pParams, "exclude", 0, nullptr))
, exclude(pParams->get_compiled_regex("exclude", 0, nullptr).release())
, md_exclude(exclude ? pcre2_match_data_create_from_pattern(exclude, nullptr) : nullptr)
{
}

View File

@ -22,7 +22,7 @@
#include <maxscale/hint.h>
#include <maxscale/modinfo.h>
#include <maxscale/modutil.hh>
#include <maxscale/pcre2.h>
#include <maxscale/pcre2.hh>
#include <maxscale/query_classifier.hh>
using std::string;
@ -97,11 +97,14 @@ public:
new_instance->m_nomatch = params->get_string(PARAM_IGNORE);
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*),
cflags, &new_instance->ovector_size,
code_arr))
bool compile_error = false;
auto code_arr = params->get_compiled_regexes({PARAM_MATCH, PARAM_IGNORE},
cflags,
&new_instance->ovector_size,
&compile_error);
new_instance->re = code_arr[0].release();
new_instance->nore = code_arr[1].release();
if (compile_error)
{
delete new_instance;
new_instance = nullptr;

View File

@ -167,29 +167,24 @@ void QlaFilterSession::close()
QlaInstance* QlaInstance::create(const std::string name, MXS_CONFIG_PARAMETER* params)
{
bool error = false;
QlaInstance* my_instance = NULL;
const char* keys[] = {PARAM_MATCH, PARAM_EXCLUDE};
pcre2_code* re_match = NULL;
pcre2_code* re_exclude = NULL;
uint32_t ovec_size = 0;
int cflags = params->get_enum(PARAM_OPTIONS, option_values);
pcre2_code** code_arr[] = {&re_match, &re_exclude};
if (config_get_compiled_regexes(params,
keys,
sizeof(keys) / sizeof(char*),
cflags,
&ovec_size,
code_arr))
bool compile_error = false;
auto code_arr = params->get_compiled_regexes({PARAM_MATCH, PARAM_EXCLUDE}, cflags,
&ovec_size, &compile_error);
auto re_match = std::move(code_arr[0]);
auto re_exclude = std::move(code_arr[1]);
if (!compile_error)
{
// The instance is allocated before opening the file since open_log_file() takes the instance as a
// parameter. Will be fixed (or at least cleaned) with a later refactoring of functions/methods.
my_instance = new(std::nothrow) QlaInstance(name, params);
if (my_instance)
{
my_instance->m_re_match = re_match;
my_instance->m_re_exclude = re_exclude;
my_instance->m_re_match = re_match.release();
my_instance->m_re_exclude = re_exclude.release();
my_instance->m_ovec_size = ovec_size;
// Try to open the unified log file
if (my_instance->m_settings.write_unified_log)
@ -200,24 +195,9 @@ QlaInstance* QlaInstance::create(const std::string name, MXS_CONFIG_PARAMETER* p
{
delete my_instance;
my_instance = NULL;
error = true;
}
}
}
else
{
error = true;
}
}
else
{
error = true;
}
if (error)
{
pcre2_code_free(re_match);
pcre2_code_free(re_exclude);
}
return my_instance;

View File

@ -19,7 +19,7 @@
#include <maxbase/stopwatch.hh>
#include <maxscale/config.hh>
#include <maxscale/filter.hh>
#include <maxscale/pcre2.h>
#include <maxscale/pcre2.hh>
class QlaFilterSession;
struct LogEventElems;

View File

@ -22,7 +22,7 @@
#include <maxscale/filter.hh>
#include <maxscale/modinfo.h>
#include <maxscale/modutil.hh>
#include <maxscale/pcre2.h>
#include <maxscale/pcre2.hh>
/**
* @file regexfilter.c - a very simple regular expression rewrite filter.
@ -229,7 +229,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
int cflags = params->get_enum("options", option_values);
if (!(my_instance->re = config_get_compiled_regex(params, "match", cflags, nullptr)))
if (!(my_instance->re = params->get_compiled_regex("match", cflags, nullptr).release()))
{
free_instance(my_instance);
return NULL;

View File

@ -22,6 +22,7 @@
#include <maxscale/alloc.h>
#include <maxscale/modinfo.h>
#include <maxscale/modulecmd.hh>
#include <maxscale/pcre2.hh>
#include "tee.hh"
#include "teesession.hh"
@ -66,8 +67,8 @@ Tee* Tee::create(const char* name, MXS_CONFIG_PARAMETER* params)
{
SERVICE* service = params->get_service("service");
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);
pcre2_code* match = params->get_compiled_regex("match", cflags, NULL).release();
pcre2_code* exclude = params->get_compiled_regex("exclude", cflags, NULL).release();
Tee* my_instance = new(std::nothrow) Tee(service,
params->get_string("source"),