Use module-style parameters with filters
Filters now use the module-style parameters to automate the type checking and default value assignment.
This commit is contained in:
@ -3534,29 +3534,16 @@ int create_new_listener(CONFIG_CONTEXT *obj)
|
|||||||
int create_new_filter(CONFIG_CONTEXT *obj)
|
int create_new_filter(CONFIG_CONTEXT *obj)
|
||||||
{
|
{
|
||||||
int error_count = 0;
|
int error_count = 0;
|
||||||
char *module = config_get_value(obj->parameters, CN_MODULE);
|
const char* module = config_get_value(obj->parameters, CN_MODULE);
|
||||||
|
ss_dassert(*module);
|
||||||
|
|
||||||
if (module)
|
if (const MXS_MODULE* mod = get_module(module, MODULE_FILTER))
|
||||||
{
|
{
|
||||||
if ((obj->element = filter_alloc(obj->object, module)))
|
config_add_defaults(obj, mod->parameters);
|
||||||
|
|
||||||
|
if (MXS_FILTER_DEF* filter = filter_alloc(obj->object, module, obj->parameters))
|
||||||
{
|
{
|
||||||
MXS_FILTER_DEF* filter_def = (MXS_FILTER_DEF*)obj->element;
|
obj->element = filter;
|
||||||
|
|
||||||
const MXS_MODULE *mod = get_module(module, MODULE_FILTER);
|
|
||||||
|
|
||||||
if (mod)
|
|
||||||
{
|
|
||||||
config_add_defaults(obj, mod->parameters);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MXS_CONFIG_PARAMETER *p = obj->parameters; p; p = p->next)
|
|
||||||
{
|
|
||||||
filter_add_parameter(filter_def, p->name, p->value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3567,7 +3554,7 @@ int create_new_filter(CONFIG_CONTEXT *obj)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Filter '%s' has no module defined to load.", obj->object);
|
MXS_ERROR("Failed to load filter module '%s'", module);
|
||||||
error_count++;
|
error_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,16 +44,15 @@ static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters
|
|||||||
static void filter_free_parameters(MXS_FILTER_DEF *filter);
|
static void filter_free_parameters(MXS_FILTER_DEF *filter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a new filter within MaxScale
|
* Allocate a new filter
|
||||||
*
|
*
|
||||||
|
* @param name The filter name
|
||||||
|
* @param module The module to load
|
||||||
|
* @param params Module parameters
|
||||||
*
|
*
|
||||||
* @param name The filter name
|
* @return The newly created filter or NULL if an error occurred
|
||||||
* @param module The module to load
|
|
||||||
*
|
|
||||||
* @return The newly created filter or NULL if an error occured
|
|
||||||
*/
|
*/
|
||||||
MXS_FILTER_DEF *
|
MXS_FILTER_DEF* filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params)
|
||||||
filter_alloc(const char *name, const char *module)
|
|
||||||
{
|
{
|
||||||
char* my_name = MXS_STRDUP(name);
|
char* my_name = MXS_STRDUP(name);
|
||||||
char* my_module = MXS_STRDUP(module);
|
char* my_module = MXS_STRDUP(module);
|
||||||
@ -72,9 +71,13 @@ filter_alloc(const char *name, const char *module)
|
|||||||
filter->filter = NULL;
|
filter->filter = NULL;
|
||||||
filter->obj = NULL;
|
filter->obj = NULL;
|
||||||
filter->parameters = NULL;
|
filter->parameters = NULL;
|
||||||
|
|
||||||
spinlock_init(&filter->spin);
|
spinlock_init(&filter->spin);
|
||||||
|
|
||||||
|
for (MXS_CONFIG_PARAMETER* p = params; p; p = p->next)
|
||||||
|
{
|
||||||
|
filter_add_parameter(filter, p->name, p->value);
|
||||||
|
}
|
||||||
|
|
||||||
spinlock_acquire(&filter_spin);
|
spinlock_acquire(&filter_spin);
|
||||||
filter->next = allFilters;
|
filter->next = allFilters;
|
||||||
allFilters = filter;
|
allFilters = filter;
|
||||||
|
@ -37,7 +37,7 @@ struct mxs_filter_def
|
|||||||
};
|
};
|
||||||
|
|
||||||
void filter_add_parameter(MXS_FILTER_DEF *filter_def, const char *name, const char *value);
|
void filter_add_parameter(MXS_FILTER_DEF *filter_def, const char *name, const char *value);
|
||||||
MXS_FILTER_DEF *filter_alloc(const char *name, const char *module_name);
|
MXS_FILTER_DEF *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(MXS_FILTER_DEF *filter_def, MXS_SESSION *session, MXS_DOWNSTREAM *downstream);
|
||||||
void filter_free(MXS_FILTER_DEF *filter_def);
|
void filter_free(MXS_FILTER_DEF *filter_def);
|
||||||
bool filter_load(MXS_FILTER_DEF *filter_def);
|
bool filter_load(MXS_FILTER_DEF *filter_def);
|
||||||
|
@ -45,7 +45,7 @@ test1()
|
|||||||
{
|
{
|
||||||
MXS_FILTER_DEF *f1, *f2;
|
MXS_FILTER_DEF *f1, *f2;
|
||||||
|
|
||||||
if ((f1 = filter_alloc("test1", "module")) == NULL)
|
if ((f1 = filter_alloc("test1", "module", NULL)) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "filter_alloc: test 1 failed.\n");
|
fprintf(stderr, "filter_alloc: test 1 failed.\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -78,7 +78,7 @@ test2()
|
|||||||
{
|
{
|
||||||
MXS_FILTER_DEF *f1;
|
MXS_FILTER_DEF *f1;
|
||||||
|
|
||||||
if ((f1 = filter_alloc("test1", "module")) == NULL)
|
if ((f1 = filter_alloc("test1", "module", NULL)) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "filter_alloc: test 1 failed.\n");
|
fprintf(stderr, "filter_alloc: test 1 failed.\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -106,7 +106,7 @@ 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_alloc(name, "module")) == NULL)
|
if ((f1 = filter_alloc(name, "module", NULL)) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"filter_alloc: test 3 failed with %s.\n", name);
|
"filter_alloc: test 3 failed with %s.\n", name);
|
||||||
|
Reference in New Issue
Block a user