MXS-1929: Make filters fully opaque

The filter implementation is now fully hidden. Also converted it to a C++
struct allocated with new and stored the filters in a global list instead
of embedding the list in the object itself.
This commit is contained in:
Markus Mäkelä
2018-07-25 11:02:46 +03:00
parent 5c4fe263ba
commit 829fdcff83
12 changed files with 172 additions and 188 deletions

View File

@ -220,7 +220,10 @@ typedef struct mxs_filter_object
* Its exact definition is private to MaxScale. * Its exact definition is private to MaxScale.
*/ */
struct mxs_filter_def; struct mxs_filter_def;
typedef struct mxs_filter_def MXS_FILTER_DEF;
typedef struct mxs_filter_def
{
} MXS_FILTER_DEF;
/** /**
* Lookup a filter definition using the unique section name in * Lookup a filter definition using the unique section name in
@ -258,40 +261,6 @@ const char* filter_def_get_module_name(const MXS_FILTER_DEF* filter_def);
*/ */
MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def); MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def);
/**
* @brief Convert a filter to JSON
*
* @param filter Filter to convert
* @param host Hostname of this server
*
* @return Filter converted to JSON format
*/
json_t* filter_to_json(const MXS_FILTER_DEF* filter, const char* host);
/**
* @brief Convert all filters into JSON
*
* @param host Hostname of this server
*
* @return A JSON array containing all filters
*/
json_t* filter_list_to_json(const char* host);
/**
* @brief Serialize a filter to a file
*
* This converts the static configuration of the filter into an INI format file.
*
* @param filter Monitor to serialize
*
* @return True if serialization was successful
*/
bool filter_serialize(const MXS_FILTER_DEF *filter);
void dprintAllFilters(DCB *);
void dprintFilter(DCB *, const MXS_FILTER_DEF *);
void dListFilters(DCB *);
/** /**
* Specifies capabilities specific for filters. Common capabilities * Specifies capabilities specific for filters. Common capabilities
* are defined by @c routing_capability_t. * are defined by @c routing_capability_t.

View File

@ -52,7 +52,7 @@
#include "internal/config.h" #include "internal/config.h"
#include "internal/event.hh" #include "internal/event.hh"
#include "internal/filter.h" #include "internal/filter.hh"
#include "internal/modules.h" #include "internal/modules.h"
#include "internal/monitor.h" #include "internal/monitor.h"
#include "internal/service.h" #include "internal/service.h"

View File

@ -38,7 +38,7 @@
#include "internal/monitor.h" #include "internal/monitor.h"
#include "internal/modules.h" #include "internal/modules.h"
#include "internal/service.h" #include "internal/service.h"
#include "internal/filter.h" #include "internal/filter.hh"
typedef std::set<std::string> StringSet; typedef std::set<std::string> StringSet;
@ -1038,7 +1038,7 @@ bool runtime_create_filter(const char *name, const char *module, MXS_CONFIG_PARA
if (filter_def_find(name) == NULL) if (filter_def_find(name) == NULL)
{ {
MXS_FILTER_DEF* filter = NULL; FilterDef* filter = NULL;
CONFIG_CONTEXT ctx{(char*)""}; CONFIG_CONTEXT ctx{(char*)""};
ctx.parameters = load_defaults(module, MODULE_FILTER, CN_FILTER); ctx.parameters = load_defaults(module, MODULE_FILTER, CN_FILTER);
@ -1078,8 +1078,9 @@ bool runtime_create_filter(const char *name, const char *module, MXS_CONFIG_PARA
return rval; return rval;
} }
bool runtime_destroy_filter(MXS_FILTER_DEF* filter) bool runtime_destroy_filter(MXS_FILTER_DEF* filter_def)
{ {
FilterDef* filter = static_cast<FilterDef*>(filter_def);
ss_dassert(filter); ss_dassert(filter);
bool rval = false; bool rval = false;
mxs::SpinLockGuard guard(crt_lock); mxs::SpinLockGuard guard(crt_lock);

View File

@ -15,7 +15,7 @@
* @file filter.c - A representation of a filter within MaxScale. * @file filter.c - A representation of a filter within MaxScale.
*/ */
#include "internal/filter.h" #include "internal/filter.hh"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -25,6 +25,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <string> #include <string>
#include <set> #include <set>
#include <vector>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
@ -34,6 +35,7 @@
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/filter.hh> #include <maxscale/filter.hh>
#include <maxscale/json_api.h> #include <maxscale/json_api.h>
#include <algorithm>
#include "internal/config.h" #include "internal/config.h"
#include "internal/modules.h" #include "internal/modules.h"
@ -42,10 +44,19 @@
using std::string; using std::string;
using std::set; using std::set;
static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */ using namespace maxscale;
static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters */
static void filter_free_parameters(MXS_FILTER_DEF *filter); static SpinLock filter_spin; /**< Protects the list of all filters */
static std::vector<FilterDef*> allFilters; /**< The list of all filters */
/**
* Free filter parameters
* @param filter FilterDef whose parameters are to be freed
*/
static void filter_free_parameters(FilterDef* filter)
{
config_parameter_free(filter->parameters);
}
/** /**
* Allocate a new filter * Allocate a new filter
@ -56,7 +67,7 @@ static void filter_free_parameters(MXS_FILTER_DEF *filter);
* *
* @return The newly created filter or NULL if an error occurred * @return The newly created filter or NULL if an error occurred
*/ */
MXS_FILTER_DEF* filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params) FilterDef* filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params)
{ {
MXS_FILTER_OBJECT* object = (MXS_FILTER_OBJECT*)load_module(module, MODULE_FILTER); MXS_FILTER_OBJECT* object = (MXS_FILTER_OBJECT*)load_module(module, MODULE_FILTER);
@ -69,13 +80,13 @@ MXS_FILTER_DEF* filter_alloc(const char *name, const char *module, MXS_CONFIG_PA
char* my_name = MXS_STRDUP(name); char* my_name = MXS_STRDUP(name);
char* my_module = MXS_STRDUP(module); char* my_module = MXS_STRDUP(module);
MXS_FILTER_DEF *filter = (MXS_FILTER_DEF *)MXS_MALLOC(sizeof(MXS_FILTER_DEF)); FilterDef* filter = new (std::nothrow) FilterDef;
if (!my_name || !my_module || !filter) if (!my_name || !my_module || !filter)
{ {
MXS_FREE(my_name); MXS_FREE(my_name);
MXS_FREE(my_module); MXS_FREE(my_module);
MXS_FREE(filter); delete filter;
return NULL; return NULL;
} }
filter->name = my_name; filter->name = my_name;
@ -99,47 +110,28 @@ MXS_FILTER_DEF* filter_alloc(const char *name, const char *module, MXS_CONFIG_PA
return NULL; return NULL;
} }
spinlock_acquire(&filter_spin); filter_spin.acquire();
filter->next = allFilters; allFilters.push_back(filter);
allFilters = filter; filter_spin.release();
spinlock_release(&filter_spin);
return filter; return filter;
} }
/** /**
* Deallocate the specified filter * Free the specified filter
* *
* @param filter The filter to deallocate * @param filter The filter to free
* @return Returns true if the server was freed
*/ */
void void filter_free(FilterDef* filter)
filter_free(MXS_FILTER_DEF *filter)
{ {
MXS_FILTER_DEF *ptr;
if (filter) if (filter)
{ {
/* First of all remove from the linked list */ /* First of all remove from the linked list */
spinlock_acquire(&filter_spin);
if (allFilters == filter) filter_spin.acquire();
{ auto it = std::remove(allFilters.begin(), allFilters.end(), filter);
allFilters = filter->next; allFilters.erase(it);
} filter_spin.release();
else
{
ptr = allFilters;
while (ptr && ptr->next != filter)
{
ptr = ptr->next;
}
if (ptr)
{
ptr->next = filter->next;
}
}
spinlock_release(&filter_spin);
/* Clean up session and free the memory */ /* Clean up session and free the memory */
MXS_FREE(filter->name); MXS_FREE(filter->name);
@ -147,27 +139,31 @@ filter_free(MXS_FILTER_DEF *filter)
filter_free_parameters(filter); filter_free_parameters(filter);
MXS_FREE(filter); delete filter;
} }
} }
MXS_FILTER_DEF * FilterDef* filter_find(const char *name)
filter_def_find(const char *name)
{ {
MXS_FILTER_DEF *filter; FilterDef* rval = NULL;
filter_spin.acquire();
spinlock_acquire(&filter_spin); for (FilterDef* filter: allFilters)
filter = allFilters;
while (filter)
{ {
if (strcmp(filter->name, name) == 0) if (strcmp(filter->name, name) == 0)
{ {
rval = filter;
break; break;
} }
filter = filter->next;
} }
spinlock_release(&filter_spin);
return filter; filter_spin.release();
return rval;
}
MXS_FILTER_DEF* filter_def_find(const char *name)
{
return filter_find(name);
} }
bool filter_can_be_destroyed(MXS_FILTER_DEF *filter) bool filter_can_be_destroyed(MXS_FILTER_DEF *filter)
@ -183,9 +179,9 @@ void filter_destroy(MXS_FILTER_DEF *filter)
void filter_destroy_instances() void filter_destroy_instances()
{ {
spinlock_acquire(&filter_spin); filter_spin.acquire();
for (MXS_FILTER_DEF* filter = allFilters; filter; filter = filter->next) for (FilterDef* filter: allFilters)
{ {
// NOTE: replace this with filter_destroy // NOTE: replace this with filter_destroy
if (filter->obj->destroyInstance) if (filter->obj->destroyInstance)
@ -194,22 +190,25 @@ void filter_destroy_instances()
} }
} }
spinlock_release(&filter_spin); filter_spin.release();
} }
const char* filter_def_get_name(const MXS_FILTER_DEF* filter_def) const char* filter_def_get_name(const MXS_FILTER_DEF* filter_def)
{ {
return filter_def->name; const FilterDef* filter = static_cast<const FilterDef*>(filter_def);
return filter->name;
} }
const char* filter_def_get_module_name(const MXS_FILTER_DEF* filter_def) const char* filter_def_get_module_name(const MXS_FILTER_DEF* filter_def)
{ {
return filter_def->module; const FilterDef* filter = static_cast<const FilterDef*>(filter_def);
return filter->module;
} }
MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def) MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def)
{ {
return filter_def->filter; const FilterDef* filter = static_cast<const FilterDef*>(filter_def);
return filter->filter;
} }
/** /**
@ -236,14 +235,11 @@ filter_standard_parameter(const char *name)
void void
dprintAllFilters(DCB *dcb) dprintAllFilters(DCB *dcb)
{ {
MXS_FILTER_DEF *ptr; filter_spin.acquire();
int i;
spinlock_acquire(&filter_spin); for (FilterDef* ptr: allFilters)
ptr = allFilters;
while (ptr)
{ {
dcb_printf(dcb, "Filter %p (%s)\n", ptr, ptr->name); dcb_printf(dcb, "FilterDef %p (%s)\n", ptr, ptr->name);
dcb_printf(dcb, "\tModule: %s\n", ptr->module); dcb_printf(dcb, "\tModule: %s\n", ptr->module);
if (ptr->obj && ptr->filter) if (ptr->obj && ptr->filter)
{ {
@ -253,9 +249,9 @@ dprintAllFilters(DCB *dcb)
{ {
dcb_printf(dcb, "\tModule not loaded.\n"); dcb_printf(dcb, "\tModule not loaded.\n");
} }
ptr = ptr->next;
} }
spinlock_release(&filter_spin);
filter_spin.release();
} }
/** /**
@ -264,12 +260,9 @@ dprintAllFilters(DCB *dcb)
* Designed to be called within a debug CLI in order * Designed to be called within a debug CLI in order
* to display all active filters in MaxScale * to display all active filters in MaxScale
*/ */
void void dprintFilter(DCB *dcb, const FilterDef *filter)
dprintFilter(DCB *dcb, const MXS_FILTER_DEF *filter)
{ {
int i; dcb_printf(dcb, "FilterDef %p (%s)\n", filter, filter->name);
dcb_printf(dcb, "Filter %p (%s)\n", filter, filter->name);
dcb_printf(dcb, "\tModule: %s\n", filter->module); dcb_printf(dcb, "\tModule: %s\n", filter->module);
if (filter->obj && filter->filter) if (filter->obj && filter->filter)
{ {
@ -284,32 +277,29 @@ dprintFilter(DCB *dcb, const MXS_FILTER_DEF *filter)
void void
dListFilters(DCB *dcb) dListFilters(DCB *dcb)
{ {
MXS_FILTER_DEF *ptr; filter_spin.acquire();
int i;
spinlock_acquire(&filter_spin); if (!allFilters.empty())
ptr = allFilters;
if (ptr)
{ {
dcb_printf(dcb, "Filters\n"); dcb_printf(dcb, "FilterDefs\n");
dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n"); dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n");
dcb_printf(dcb, "%-19s | %-15s | Options\n", dcb_printf(dcb, "%-19s | %-15s | Options\n",
"Filter", "Module"); "FilterDef", "Module");
dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n"); dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n");
} }
while (ptr)
for (FilterDef* ptr: allFilters)
{ {
dcb_printf(dcb, "%-19s | %-15s | ", dcb_printf(dcb, "%-19s | %-15s | ",
ptr->name, ptr->module); ptr->name, ptr->module);
dcb_printf(dcb, "\n"); dcb_printf(dcb, "\n");
ptr = ptr->next;
} }
if (allFilters) if (!allFilters.empty())
{ {
dcb_printf(dcb, dcb_printf(dcb,
"--------------------+-----------------+----------------------------------------\n\n"); "--------------------+-----------------+----------------------------------------\n\n");
} }
spinlock_release(&filter_spin); filter_spin.release();
} }
/** /**
@ -320,7 +310,7 @@ dListFilters(DCB *dcb)
* @param value The parameter value * @param value The parameter value
*/ */
void void
filter_add_parameter(MXS_FILTER_DEF *filter, const char *name, const char *value) filter_add_parameter(FilterDef *filter, const char *name, const char *value)
{ {
CONFIG_CONTEXT ctx = {}; CONFIG_CONTEXT ctx = {};
ctx.object = (char*)""; ctx.object = (char*)"";
@ -330,15 +320,6 @@ filter_add_parameter(MXS_FILTER_DEF *filter, const char *name, const char *value
filter->parameters = ctx.parameters; filter->parameters = ctx.parameters;
} }
/**
* Free filter parameters
* @param filter Filter whose parameters are to be freed
*/
static void filter_free_parameters(MXS_FILTER_DEF *filter)
{
config_parameter_free(filter->parameters);
}
/** /**
* Connect the downstream filter chain for a filter. * Connect the downstream filter chain for a filter.
* *
@ -351,8 +332,7 @@ static void filter_free_parameters(MXS_FILTER_DEF *filter)
* @return The downstream component for the next filter or NULL * @return The downstream component for the next filter or NULL
* if the filter could not be created * if the filter could not be created
*/ */
MXS_DOWNSTREAM * MXS_DOWNSTREAM* filter_apply(FilterDef* filter, MXS_SESSION *session, MXS_DOWNSTREAM *downstream)
filter_apply(MXS_FILTER_DEF *filter, MXS_SESSION *session, MXS_DOWNSTREAM *downstream)
{ {
MXS_DOWNSTREAM *me; MXS_DOWNSTREAM *me;
@ -386,8 +366,7 @@ filter_apply(MXS_FILTER_DEF *filter, MXS_SESSION *session, MXS_DOWNSTREAM *downs
* @param upstream The filter that should be upstream of this filter * @param upstream The filter that should be upstream of this filter
* @return The upstream component for the next filter * @return The upstream component for the next filter
*/ */
MXS_UPSTREAM * MXS_UPSTREAM* filter_upstream(FilterDef* filter, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *upstream)
filter_upstream(MXS_FILTER_DEF *filter, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *upstream)
{ {
MXS_UPSTREAM *me = NULL; MXS_UPSTREAM *me = NULL;
@ -413,7 +392,7 @@ filter_upstream(MXS_FILTER_DEF *filter, MXS_FILTER_SESSION *fsession, MXS_UPSTRE
} }
return me; return me;
} }
json_t* filter_parameters_to_json(const MXS_FILTER_DEF* filter) json_t* filter_parameters_to_json(const FilterDef* filter)
{ {
json_t* rval = json_object(); json_t* rval = json_object();
@ -424,7 +403,7 @@ json_t* filter_parameters_to_json(const MXS_FILTER_DEF* filter)
return rval; return rval;
} }
json_t* filter_json_data(const MXS_FILTER_DEF* filter, const char* host) json_t* filter_json_data(const FilterDef* filter, const char* host)
{ {
json_t* rval = json_object(); json_t* rval = json_object();
@ -457,7 +436,7 @@ json_t* filter_json_data(const MXS_FILTER_DEF* filter, const char* host)
return rval; return rval;
} }
json_t* filter_to_json(const MXS_FILTER_DEF* filter, const char* host) json_t* filter_to_json(const FilterDef* filter, const char* host)
{ {
string self = MXS_JSON_API_FILTERS; string self = MXS_JSON_API_FILTERS;
self += filter->name; self += filter->name;
@ -468,9 +447,9 @@ json_t* filter_list_to_json(const char* host)
{ {
json_t* rval = json_array(); json_t* rval = json_array();
spinlock_acquire(&filter_spin); filter_spin.acquire();
for (MXS_FILTER_DEF* f = allFilters; f; f = f->next) for (FilterDef* f: allFilters)
{ {
json_t* json = filter_json_data(f, host); json_t* json = filter_json_data(f, host);
@ -480,7 +459,7 @@ json_t* filter_list_to_json(const char* host)
} }
} }
spinlock_release(&filter_spin); filter_spin.release();
return mxs_json_resource(host, MXS_JSON_API_FILTERS, rval); return mxs_json_resource(host, MXS_JSON_API_FILTERS, rval);
} }
@ -536,7 +515,7 @@ json_t* FilterSession::diagnostics_json() const
} }
static bool create_filter_config(const MXS_FILTER_DEF *filter, const char *filename) static bool create_filter_config(const FilterDef *filter, const char *filename)
{ {
int file = open(filename, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int file = open(filename, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@ -568,7 +547,7 @@ static bool create_filter_config(const MXS_FILTER_DEF *filter, const char *filen
return true; return true;
} }
bool filter_serialize(const MXS_FILTER_DEF *filter) bool filter_serialize(const FilterDef *filter)
{ {
bool rval = false; bool rval = false;
char filename[PATH_MAX]; char filename[PATH_MAX];

View File

@ -18,14 +18,12 @@
#include <maxscale/filter.h> #include <maxscale/filter.h>
MXS_BEGIN_DECLS
/** /**
* The definition of a filter from the configuration file. * The definition of a filter from the configuration file.
* This is basically the link between a plugin to load and the * This is basically the link between a plugin to load and the
* options to pass to that plugin. * options to pass to that plugin.
*/ */
struct mxs_filter_def struct FilterDef: public MXS_FILTER_DEF
{ {
char *name; /**< The Filter name */ char *name; /**< The Filter name */
char *module; /**< The module to load */ char *module; /**< The module to load */
@ -33,18 +31,21 @@ struct mxs_filter_def
MXS_FILTER* filter; /**< The runtime filter */ MXS_FILTER* filter; /**< The runtime filter */
MXS_FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */ MXS_FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */
SPINLOCK spin; /**< Spinlock to protect the filter definition */ SPINLOCK spin; /**< Spinlock to protect the filter definition */
struct mxs_filter_def *next; /**< Next filter in the chain of all filters */ struct FilterDef *next; /**< Next filter in the chain of all filters */
}; };
void filter_add_parameter(MXS_FILTER_DEF *filter_def, const char *name, const char *value); void filter_add_parameter(FilterDef *filter_def, const char *name, const char *value);
MXS_FILTER_DEF *filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params); FilterDef* filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params);
MXS_DOWNSTREAM *filter_apply(MXS_FILTER_DEF *filter_def, MXS_SESSION *session, MXS_DOWNSTREAM *downstream); MXS_DOWNSTREAM *filter_apply(FilterDef* filter_def, MXS_SESSION *session, MXS_DOWNSTREAM *downstream);
void filter_free(MXS_FILTER_DEF *filter_def); void filter_free(FilterDef *filter);
int filter_standard_parameter(const char *name); int filter_standard_parameter(const char *name);
MXS_UPSTREAM *filter_upstream(MXS_FILTER_DEF *filter_def, MXS_UPSTREAM *filter_upstream(FilterDef* filter_def,
MXS_FILTER_SESSION *fsession, MXS_FILTER_SESSION *fsession,
MXS_UPSTREAM *upstream); MXS_UPSTREAM *upstream);
// Find the internal filter representation
FilterDef* filter_find(const char *name);
/** /**
* Check if filter can be destroyed * Check if filter can be destroyed
* *
@ -68,4 +69,36 @@ void filter_destroy(MXS_FILTER_DEF *filter);
*/ */
void filter_destroy_instances(); void filter_destroy_instances();
MXS_END_DECLS /**
* @brief Serialize a filter to a file
*
* This converts the static configuration of the filter into an INI format file.
*
* @param filter Monitor to serialize
*
* @return True if serialization was successful
*/
bool filter_serialize(const FilterDef *filter);
void dprintAllFilters(DCB *);
void dprintFilter(DCB *, const FilterDef *);
void dListFilters(DCB *);
/**
* @brief Convert a filter to JSON
*
* @param filter Filter to convert
* @param host Hostname of this server
*
* @return Filter converted to JSON format
*/
json_t* filter_to_json(const FilterDef* filter, const char* host);
/**
* @brief Convert all filters into JSON
*
* @param host Hostname of this server
*
* @return A JSON array containing all filters
*/
json_t* filter_list_to_json(const char* host);

View File

@ -26,7 +26,7 @@
#include "httpresponse.hh" #include "httpresponse.hh"
#include "monitor.h" #include "monitor.h"
#include "service.h" #include "service.h"
#include "filter.h" #include "filter.hh"
#include "session.h" #include "session.h"
typedef HttpResponse (*ResourceCallback)(const HttpRequest& request); typedef HttpResponse (*ResourceCallback)(const HttpRequest& request);

View File

@ -21,7 +21,7 @@
#include <maxscale/platform.h> #include <maxscale/platform.h>
#include <maxscale/spinlock.h> #include <maxscale/spinlock.h>
#include "internal/filter.h" #include "internal/filter.hh"
#include "internal/modules.h" #include "internal/modules.h"
#include "internal/monitor.h" #include "internal/monitor.h"
@ -342,7 +342,8 @@ static bool process_argument(const MODULECMD *cmd, modulecmd_arg_type_t *type, c
case MODULECMD_ARG_FILTER: case MODULECMD_ARG_FILTER:
if ((arg->value.filter = filter_def_find((char*)value))) if ((arg->value.filter = filter_def_find((char*)value)))
{ {
const char* eff_name = mxs_module_get_effective_name(arg->value.filter->module); const char* orig_name = filter_def_get_module_name(arg->value.filter);
const char* eff_name = mxs_module_get_effective_name(orig_name);
if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcasecmp(cmd->domain, eff_name) == 0) if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcasecmp(cmd->domain, eff_name) == 0)
{ {
arg->type.type = MODULECMD_ARG_FILTER; arg->type.type = MODULECMD_ARG_FILTER;

View File

@ -30,7 +30,7 @@
#include "internal/httprequest.hh" #include "internal/httprequest.hh"
#include "internal/httpresponse.hh" #include "internal/httpresponse.hh"
#include "internal/session.h" #include "internal/session.h"
#include "internal/filter.h" #include "internal/filter.hh"
#include "internal/monitor.h" #include "internal/monitor.h"
#include "internal/service.h" #include "internal/service.h"
#include "internal/config_runtime.h" #include "internal/config_runtime.h"
@ -486,7 +486,7 @@ HttpResponse cb_delete_service(const HttpRequest& request)
HttpResponse cb_delete_filter(const HttpRequest& request) HttpResponse cb_delete_filter(const HttpRequest& request)
{ {
MXS_FILTER_DEF* filter = filter_def_find(request.uri_part(1).c_str()); FilterDef* filter = filter_find(request.uri_part(1).c_str());
ss_dassert(filter); ss_dassert(filter);
if (runtime_destroy_filter(filter)) if (runtime_destroy_filter(filter))
@ -549,7 +549,7 @@ HttpResponse cb_all_filters(const HttpRequest& request)
HttpResponse cb_get_filter(const HttpRequest& request) HttpResponse cb_get_filter(const HttpRequest& request)
{ {
MXS_FILTER_DEF* filter = filter_def_find(request.uri_part(1).c_str()); FilterDef* filter = filter_find(request.uri_part(1).c_str());
ss_dassert(filter); ss_dassert(filter);
return HttpResponse(MHD_HTTP_OK, filter_to_json(filter, request.host())); return HttpResponse(MHD_HTTP_OK, filter_to_json(filter, request.host()));
} }

View File

@ -56,7 +56,7 @@
#include <maxscale/routingworker.h> #include <maxscale/routingworker.h>
#include "internal/config.h" #include "internal/config.h"
#include "internal/filter.h" #include "internal/filter.hh"
#include "internal/modules.h" #include "internal/modules.h"
#include "internal/service.h" #include "internal/service.h"
#include "internal/routingworker.hh" #include "internal/routingworker.hh"
@ -1251,7 +1251,7 @@ bool service_set_filters(SERVICE* service, const char* filters)
{ {
fix_object_name(&f[0]); fix_object_name(&f[0]);
if (MXS_FILTER_DEF* def = filter_def_find(f.c_str())) if (FilterDef* def = filter_find(f.c_str()))
{ {
flist.push_back(def); flist.push_back(def);
@ -1373,7 +1373,7 @@ void dprintService(DCB *dcb, SERVICE *service)
dcb_printf(dcb, "\tFilter chain: "); dcb_printf(dcb, "\tFilter chain: ");
for (i = 0; i < service->n_filters; i++) for (i = 0; i < service->n_filters; i++)
{ {
dcb_printf(dcb, "%s %s ", service->filters[i]->name, dcb_printf(dcb, "%s %s ", filter_def_get_name(service->filters[i]),
i + 1 < service->n_filters ? "|" : ""); i + 1 < service->n_filters ? "|" : "");
} }
dcb_printf(dcb, "\n"); dcb_printf(dcb, "\n");
@ -2448,7 +2448,7 @@ json_t* service_relationships(const SERVICE* service, const char* host)
for (int i = 0; i < service->n_filters; i++) for (int i = 0; i < service->n_filters; i++)
{ {
mxs_json_add_relation(filters, service->filters[i]->name, CN_FILTERS); mxs_json_add_relation(filters, filter_def_get_name(service->filters[i]), CN_FILTERS);
} }
json_object_set_new(rel, CN_FILTERS, filters); json_object_set_new(rel, CN_FILTERS, filters);

View File

@ -41,7 +41,7 @@
#include <maxscale/protocol/mysql.h> #include <maxscale/protocol/mysql.h>
#include "internal/dcb.h" #include "internal/dcb.h"
#include "internal/filter.h" #include "internal/filter.hh"
#include "internal/routingworker.hh" #include "internal/routingworker.hh"
#include "internal/session.h" #include "internal/session.h"
#include "internal/service.h" #include "internal/service.h"
@ -393,16 +393,18 @@ static void session_free(MXS_SESSION *session)
{ {
if (session->filters[i].filter) if (session->filters[i].filter)
{ {
session->filters[i].filter->obj->closeSession(session->filters[i].instance, FilterDef* filter = static_cast<FilterDef*>(session->filters[i].filter);
session->filters[i].session); filter->obj->closeSession(session->filters[i].instance,
session->filters[i].session);
} }
} }
for (i = 0; i < session->n_filters; i++) for (i = 0; i < session->n_filters; i++)
{ {
if (session->filters[i].filter) if (session->filters[i].filter)
{ {
session->filters[i].filter->obj->freeSession(session->filters[i].instance, FilterDef* filter = static_cast<FilterDef*>(session->filters[i].filter);
session->filters[i].session); filter->obj->freeSession(session->filters[i].instance,
session->filters[i].session);
} }
} }
MXS_FREE(session->filters); MXS_FREE(session->filters);
@ -558,11 +560,10 @@ dprintSession(DCB *dcb, MXS_SESSION *print_session)
{ {
for (i = 0; i < print_session->n_filters; i++) for (i = 0; i < print_session->n_filters; i++)
{ {
dcb_printf(dcb, "\tFilter: %s\n", FilterDef* filter = static_cast<FilterDef*>(print_session->filters[i].filter);
print_session->filters[i].filter->name); dcb_printf(dcb, "\tFilter: %s\n", filter->name);
print_session->filters[i].filter->obj->diagnostics(print_session->filters[i].instance, filter->obj->diagnostics(print_session->filters[i].instance,
print_session->filters[i].session, print_session->filters[i].session, dcb);
dcb);
} }
} }
} }
@ -670,12 +671,12 @@ session_setup_filters(MXS_SESSION *session)
MXS_ERROR("Service '%s' contians an unresolved filter.", service->name); MXS_ERROR("Service '%s' contians an unresolved filter.", service->name);
return 0; return 0;
} }
if ((head = filter_apply(service->filters[i], session, if ((head = filter_apply((FilterDef*)service->filters[i], session,
&session->head)) == NULL) &session->head)) == NULL)
{ {
MXS_ERROR("Failed to create filter '%s' for " MXS_ERROR("Failed to create filter '%s' for "
"service '%s'.\n", "service '%s'.\n",
service->filters[i]->name, filter_def_get_name(service->filters[i]),
service->name); service->name);
return 0; return 0;
} }
@ -688,12 +689,12 @@ session_setup_filters(MXS_SESSION *session)
for (i = 0; i < service->n_filters; i++) for (i = 0; i < service->n_filters; i++)
{ {
if ((tail = filter_upstream(service->filters[i], if ((tail = filter_upstream((FilterDef*)service->filters[i],
session->filters[i].session, session->filters[i].session,
&session->tail)) == NULL) &session->tail)) == NULL)
{ {
MXS_ERROR("Failed to create filter '%s' for service '%s'.", MXS_ERROR("Failed to create filter '%s' for service '%s'.",
service->filters[i]->name, filter_def_get_name(service->filters[i]),
service->name); service->name);
return 0; return 0;
} }
@ -1034,7 +1035,7 @@ json_t* session_json_data(const MXS_SESSION *session, const char *host)
for (int i = 0; i < session->n_filters; i++) for (int i = 0; i < session->n_filters; i++)
{ {
mxs_json_add_relation(filters, session->filters[i].filter->name, CN_FILTERS); mxs_json_add_relation(filters, filter_def_get_name(session->filters[i].filter), CN_FILTERS);
} }
json_object_set_new(rel, CN_FILTERS, filters); json_object_set_new(rel, CN_FILTERS, filters);
} }

View File

@ -36,7 +36,7 @@
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/paths.h> #include <maxscale/paths.h>
#include "../internal/filter.h" #include "../internal/filter.hh"
/** /**
@ -46,22 +46,22 @@
static int static int
test1() test1()
{ {
MXS_FILTER_DEF *f1, *f2; FilterDef *f1, *f2;
if ((f1 = filter_alloc("test1", "qlafilter", NULL)) == NULL) if ((f1 = filter_alloc("test1", "qlafilter", NULL)) == NULL)
{ {
fprintf(stderr, "filter_alloc: test 1 failed.\n"); fprintf(stderr, "filter_alloc: test 1 failed.\n");
return 1; return 1;
} }
if ((f2 = filter_def_find("test1")) == NULL) if ((f2 = filter_find("test1")) == NULL)
{ {
fprintf(stderr, "filter_def_find: test 2 failed.\n"); fprintf(stderr, "filter_find: test 2 failed.\n");
return 1; return 1;
} }
filter_free(f1); filter_free(f1);
if ((f2 = filter_def_find("test1")) != NULL) if ((f2 = filter_find("test1")) != NULL)
{ {
fprintf(stderr, "filter_def_find: test 3 failed delete.\n"); fprintf(stderr, "filter_find: test 3 failed delete.\n");
return 1; return 1;
} }
@ -79,7 +79,7 @@ test1()
static int static int
test2() test2()
{ {
MXS_FILTER_DEF *f1; FilterDef *f1;
if ((f1 = filter_alloc("test1", "qlafilter", NULL)) == NULL) if ((f1 = filter_alloc("test1", "qlafilter", NULL)) == NULL)
{ {
@ -102,7 +102,7 @@ test2()
static int static int
test3() test3()
{ {
MXS_FILTER_DEF *f1; FilterDef *f1;
char name[40]; char name[40];
int i, n_filters = 1000; int i, n_filters = 1000;
@ -119,25 +119,25 @@ test3()
for (i = 0; i < n_filters; i++) for (i = 0; i < n_filters; i++)
{ {
sprintf(name, "filter%d", i); sprintf(name, "filter%d", i);
if ((f1 = filter_def_find(name)) == NULL) if ((f1 = filter_find(name)) == NULL)
{ {
fprintf(stderr, "filter_def_find: test 3 failed.\n"); fprintf(stderr, "filter_find: test 3 failed.\n");
return 1; return 1;
} }
} }
for (i = 0; i < n_filters; i++) for (i = 0; i < n_filters; i++)
{ {
sprintf(name, "filter%d", i); sprintf(name, "filter%d", i);
if ((f1 = filter_def_find(name)) == NULL) if ((f1 = filter_find(name)) == NULL)
{ {
fprintf(stderr, "filter_def_find: test 3 failed.\n"); fprintf(stderr, "filter_find: test 3 failed.\n");
return 1; return 1;
} }
filter_free(f1); filter_free(f1);
if ((f1 = filter_def_find(name)) != NULL) if ((f1 = filter_find(name)) != NULL)
{ {
fprintf(stderr, fprintf(stderr,
"filter_def_find: test 3 failed - found deleted filter.\n"); "filter_find: test 3 failed - found deleted filter.\n");
return 1; return 1;
} }
} }
@ -157,4 +157,3 @@ main(int argc, char **argv)
exit(result); exit(result);
} }

View File

@ -63,6 +63,7 @@
#include "../../../core/internal/monitor.h" #include "../../../core/internal/monitor.h"
#include "../../../core/internal/poll.h" #include "../../../core/internal/poll.h"
#include "../../../core/internal/session.h" #include "../../../core/internal/session.h"
#include "../../../core/internal/filter.hh"
#define MAXARGS 14 #define MAXARGS 14