Masking: Add startup handling to masking filter
- Process parameters - Create config - Load rules
This commit is contained in:
parent
171eb3f690
commit
c25c0d688b
@ -13,6 +13,11 @@
|
||||
|
||||
#define MXS_MODULE_NAME "masking"
|
||||
#include "maskingfilter.hh"
|
||||
#include <maxscale/gwdirs.h>
|
||||
#include "maskingrules.hh"
|
||||
|
||||
using std::auto_ptr;
|
||||
using std::string;
|
||||
|
||||
//
|
||||
// Global symbols of the Module
|
||||
@ -20,7 +25,7 @@
|
||||
|
||||
extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
{
|
||||
MXS_NOTICE("Initialized masking module.");
|
||||
MXS_NOTICE("Masking module %s initialized.", VERSION_STRING);
|
||||
|
||||
static MXS_MODULE info =
|
||||
{
|
||||
@ -46,8 +51,11 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
// MaskingFilter
|
||||
//
|
||||
|
||||
MaskingFilter::MaskingFilter()
|
||||
MaskingFilter::MaskingFilter(const Config& config, auto_ptr<MaskingRules> sRules)
|
||||
: m_config(config)
|
||||
, m_sRules(sRules)
|
||||
{
|
||||
MXS_NOTICE("Masking filter [%s] created.", m_config.name().c_str());
|
||||
}
|
||||
|
||||
MaskingFilter::~MaskingFilter()
|
||||
@ -57,12 +65,17 @@ MaskingFilter::~MaskingFilter()
|
||||
// static
|
||||
MaskingFilter* MaskingFilter::create(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams)
|
||||
{
|
||||
MaskingFilter* pFilter = new MaskingFilter;
|
||||
MaskingFilter* pFilter = NULL;
|
||||
|
||||
if (!process_params(pzOptions, ppParams, pFilter->m_config))
|
||||
MaskingFilter::Config config(zName);
|
||||
if (process_params(pzOptions, ppParams, config))
|
||||
{
|
||||
delete pFilter;
|
||||
pFilter = NULL;
|
||||
auto_ptr<MaskingRules> sRules = MaskingRules::load(config.rules_file().c_str());
|
||||
|
||||
if (sRules.get())
|
||||
{
|
||||
pFilter = new MaskingFilter(config, sRules);
|
||||
}
|
||||
}
|
||||
|
||||
return pFilter;
|
||||
@ -89,5 +102,45 @@ uint64_t MaskingFilter::getCapabilities()
|
||||
// static
|
||||
bool MaskingFilter::process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config)
|
||||
{
|
||||
return true;
|
||||
bool error = false;
|
||||
|
||||
for (int i = 0; ppParams[i]; ++i)
|
||||
{
|
||||
const FILTER_PARAMETER *pParam = ppParams[i];
|
||||
|
||||
if (strcmp(pParam->name, "rules_file") == 0)
|
||||
{
|
||||
string rules_file;
|
||||
|
||||
if (*pParam->value != '/')
|
||||
{
|
||||
// A relative path is interpreted relative to the data directory.
|
||||
rules_file += get_datadir();
|
||||
rules_file += "/";
|
||||
}
|
||||
|
||||
rules_file += pParam->value;
|
||||
|
||||
config.set_rules_file(rules_file);
|
||||
}
|
||||
else if (!filter_standard_parameter(pParam->name))
|
||||
{
|
||||
MXS_ERROR("Unknown configuration entry '%s'.", pParam->name);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error)
|
||||
{
|
||||
if (config.rules_file().empty())
|
||||
{
|
||||
MXS_ERROR("In order to use the masking filter, the location of the rules file "
|
||||
"must be specified. Add a configuration entry 'rules_file=...' in "
|
||||
"the section [%s], in the MariaDB MaxScale configuration file.",
|
||||
config.name().c_str());
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !error;
|
||||
}
|
||||
|
@ -13,10 +13,13 @@
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include <memory>
|
||||
#include <maxscale/filter.hh>
|
||||
#include "maskingfilterconfig.hh"
|
||||
#include "maskingfiltersession.hh"
|
||||
|
||||
class MaskingRules;
|
||||
|
||||
|
||||
class MaskingFilter : public maxscale::Filter<MaskingFilter, MaskingFilterSession>
|
||||
{
|
||||
@ -33,7 +36,7 @@ public:
|
||||
static uint64_t getCapabilities();
|
||||
|
||||
private:
|
||||
MaskingFilter();
|
||||
MaskingFilter(const Config& config, std::auto_ptr<MaskingRules> sRules);
|
||||
|
||||
MaskingFilter(const MaskingFilter&);
|
||||
MaskingFilter& operator = (const MaskingFilter&);
|
||||
@ -41,5 +44,6 @@ private:
|
||||
static bool process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config);
|
||||
|
||||
private:
|
||||
Config m_config;
|
||||
Config m_config;
|
||||
std::auto_ptr<MaskingRules> m_sRules;
|
||||
};
|
||||
|
@ -13,8 +13,22 @@
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include <string>
|
||||
|
||||
class MaskingFilterConfig
|
||||
{
|
||||
// Placeholder
|
||||
public:
|
||||
MaskingFilterConfig(const char* zName)
|
||||
: m_name(zName)
|
||||
{}
|
||||
~MaskingFilterConfig() {}
|
||||
|
||||
const std::string& name() const { return m_name; }
|
||||
const std::string& rules_file() const { return m_rules_file; }
|
||||
|
||||
void set_rules_file(const std::string& s) { m_rules_file = s; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_rules_file;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user