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:
Markus Mäkelä 2018-07-12 22:12:55 +03:00
parent ddaf300783
commit 177f7357e0
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
4 changed files with 23 additions and 33 deletions

View File

@ -3534,29 +3534,16 @@ int create_new_listener(CONFIG_CONTEXT *obj)
int create_new_filter(CONFIG_CONTEXT *obj)
{
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;
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);
}
obj->element = filter;
}
else
{
@ -3567,7 +3554,7 @@ int create_new_filter(CONFIG_CONTEXT *obj)
}
else
{
MXS_ERROR("Filter '%s' has no module defined to load.", obj->object);
MXS_ERROR("Failed to load filter module '%s'", module);
error_count++;
}

View File

@ -44,16 +44,15 @@ static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters
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
* @param module The module to load
*
* @return The newly created filter or NULL if an error occured
* @return The newly created filter or NULL if an error occurred
*/
MXS_FILTER_DEF *
filter_alloc(const char *name, const char *module)
MXS_FILTER_DEF* filter_alloc(const char *name, const char *module, MXS_CONFIG_PARAMETER* params)
{
char* my_name = MXS_STRDUP(name);
char* my_module = MXS_STRDUP(module);
@ -72,9 +71,13 @@ filter_alloc(const char *name, const char *module)
filter->filter = NULL;
filter->obj = NULL;
filter->parameters = NULL;
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);
filter->next = allFilters;
allFilters = filter;

View File

@ -37,7 +37,7 @@ struct mxs_filter_def
};
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);
void filter_free(MXS_FILTER_DEF *filter_def);
bool filter_load(MXS_FILTER_DEF *filter_def);

View File

@ -45,7 +45,7 @@ test1()
{
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");
return 1;
@ -78,7 +78,7 @@ test2()
{
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");
return 1;
@ -106,7 +106,7 @@ test3()
for (i = 0; i < n_filters; i++)
{
sprintf(name, "filter%d", i);
if ((f1 = filter_alloc(name, "module")) == NULL)
if ((f1 = filter_alloc(name, "module", NULL)) == NULL)
{
fprintf(stderr,
"filter_alloc: test 3 failed with %s.\n", name);