MXS-580: Added more options for filters

The tee, qlafilter, namedserverfilter and topfilter now support the same filter
options: case, ignorecase and extended. The extended filter option enables
the Extended Regular Expression syntax for the filters which is used when
matching queries.
This commit is contained in:
Markus Makela
2016-02-22 15:48:30 +02:00
parent 19356be848
commit aec1310c52
8 changed files with 154 additions and 41 deletions

View File

@ -26,7 +26,19 @@ filters=NamedServerFilter
## Filter Options ## Filter Options
The named server filter accepts the options ignorecase or case. These define if the pattern text should take the case of the string it is matching against into consideration or not. The named server filter accepts the following options.
|Option |Description |
|----------|--------------------------------------------|
|ignorecase|Use case-insensitive matching |
|case |Use case-sensitive matching |
|extended |Use extended regular expression syntax (ERE)|
To use multiple filter options, list them in a comma-separated list.
```
options=case,extended
```
## Filter Parameters ## Filter Parameters

View File

@ -23,15 +23,23 @@ filters=MyLogFilter
## Filter Options ## Filter Options
The QLA filter accepts one option value, this is the name that is used for the log files that are written. The file that is created appends the session number to the name given in the options entry. For example: The QLA filter accepts the following options.
|Option |Description |
|----------|--------------------------------------------|
|ignorecase|Use case-insensitive matching |
|case |Use case-sensitive matching |
|extended |Use extended regular expression syntax (ERE)|
To use multiple filter options, list them in a comma-separated list.
``` ```
options=/tmp/QueryLog options=case,extended
``` ```
would create log files /tmp/QueryLog.1 etc. **Note**: older the version of the QLA filter in 0.7 of MaxScale used the `options`
to define the location of the log files. This functionality is not supported
Note, this is included for backward compatibility with the version of the QLA filter that was provided in the initial filters implementation preview in 0.7 of MaxScale. The filebase parameter can now be used and will take precedence over the filter option. anymore and the `filebase` parameter should be used instead.
## Filter Parameters ## Filter Parameters

View File

@ -25,7 +25,19 @@ filters=DataMartFilter
## Filter Options ## Filter Options
The tee filter does not support any filter options. The tee filter accepts the following options.
|Option |Description |
|----------|--------------------------------------------|
|ignorecase|Use case-insensitive matching |
|case |Use case-sensitive matching |
|extended |Use extended regular expression syntax (ERE)|
To use multiple filter options, list them in a comma-separated list.
```
options=case,extended
```
## Filter Parameters ## Filter Parameters

View File

@ -24,7 +24,19 @@ filters=MyLogFilter
## Filter Options ## Filter Options
The top filter does not support any filter options currently. The top filter accepts the following options.
|Option |Description |
|----------|--------------------------------------------|
|ignorecase|Use case-insensitive matching |
|case |Use case-sensitive matching |
|extended |Use extended regular expression syntax (ERE)|
To use multiple filter options, list them in a comma-separated list.
```
options=case,extended
```
## Filter Parameters ## Filter Parameters

View File

@ -191,6 +191,10 @@ createInstance(char **options, FILTER_PARAMETER **params)
{ {
cflags &= ~REG_ICASE; cflags &= ~REG_ICASE;
} }
else if (!strcasecmp(options[i], "extended"))
{
cflags |= REG_EXTENDED;
}
else else
{ {
MXS_ERROR("namedserverfilter: unsupported option '%s'.", MXS_ERROR("namedserverfilter: unsupported option '%s'.",

View File

@ -177,14 +177,6 @@ createInstance(char **options, FILTER_PARAMETER **params)
if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL) if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL)
{ {
if (options)
{
my_instance->filebase = strdup(options[0]);
}
else
{
my_instance->filebase = strdup("qla");
}
my_instance->source = NULL; my_instance->source = NULL;
my_instance->userName = NULL; my_instance->userName = NULL;
my_instance->match = NULL; my_instance->match = NULL;
@ -225,9 +217,36 @@ createInstance(char **options, FILTER_PARAMETER **params)
} }
} }
} }
int cflags = REG_ICASE;
if (options)
{
for (i = 0; options[i]; i++)
{
if (!strcasecmp(options[i], "ignorecase"))
{
cflags |= REG_ICASE;
}
else if (!strcasecmp(options[i], "case"))
{
cflags &= ~REG_ICASE;
}
else if (!strcasecmp(options[i], "extended"))
{
cflags |= REG_EXTENDED;
}
else
{
MXS_ERROR("qlafilter: unsupported option '%s'.",
options[i]);
}
}
}
my_instance->sessions = 0; my_instance->sessions = 0;
if (my_instance->match && if (my_instance->match &&
regcomp(&my_instance->re, my_instance->match, REG_ICASE)) regcomp(&my_instance->re, my_instance->match, cflags))
{ {
MXS_ERROR("qlafilter: Invalid regular expression '%s'" MXS_ERROR("qlafilter: Invalid regular expression '%s'"
" for the match parameter.\n", " for the match parameter.\n",
@ -242,8 +261,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
return NULL; return NULL;
} }
if (my_instance->nomatch && if (my_instance->nomatch &&
regcomp(&my_instance->nore, my_instance->nomatch, regcomp(&my_instance->nore, my_instance->nomatch, cflags))
REG_ICASE))
{ {
MXS_ERROR("qlafilter: Invalid regular expression '%s'" MXS_ERROR("qlafilter: Invalid regular expression '%s'"
" for the nomatch paramter.", " for the nomatch paramter.",

View File

@ -407,6 +407,33 @@ createInstance(char **options, FILTER_PARAMETER **params)
} }
} }
} }
int cflags = REG_ICASE;
if (options)
{
for (i = 0; options[i]; i++)
{
if (!strcasecmp(options[i], "ignorecase"))
{
cflags |= REG_ICASE;
}
else if (!strcasecmp(options[i], "case"))
{
cflags &= ~REG_ICASE;
}
else if (!strcasecmp(options[i], "extended"))
{
cflags |= REG_EXTENDED;
}
else
{
MXS_ERROR("tee: unsupported option '%s'.",
options[i]);
}
}
}
if (my_instance->service == NULL) if (my_instance->service == NULL)
{ {
free(my_instance->match); free(my_instance->match);
@ -416,7 +443,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
} }
if (my_instance->match && if (my_instance->match &&
regcomp(&my_instance->re, my_instance->match, REG_ICASE)) regcomp(&my_instance->re, my_instance->match, cflags))
{ {
MXS_ERROR("tee: Invalid regular expression '%s'" MXS_ERROR("tee: Invalid regular expression '%s'"
" for the match parameter.", " for the match parameter.",
@ -427,8 +454,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
return NULL; return NULL;
} }
if (my_instance->nomatch && if (my_instance->nomatch &&
regcomp(&my_instance->nore, my_instance->nomatch, regcomp(&my_instance->nore, my_instance->nomatch, cflags))
REG_ICASE))
{ {
MXS_ERROR("tee: Invalid regular expression '%s'" MXS_ERROR("tee: Invalid regular expression '%s'"
" for the nomatch paramter.\n", " for the nomatch paramter.\n",

View File

@ -233,14 +233,36 @@ createInstance(char **options, FILTER_PARAMETER **params)
params[i]->name); params[i]->name);
} }
} }
int cflags = REG_ICASE;
if (options) if (options)
{ {
MXS_ERROR("topfilter: Options are not supported by this " for (i = 0; options[i]; i++)
" filter. They will be ignored."); {
if (!strcasecmp(options[i], "ignorecase"))
{
cflags |= REG_ICASE;
} }
else if (!strcasecmp(options[i], "case"))
{
cflags &= ~REG_ICASE;
}
else if (!strcasecmp(options[i], "extended"))
{
cflags |= REG_EXTENDED;
}
else
{
MXS_ERROR("topfilter: unsupported option '%s'.",
options[i]);
}
}
}
my_instance->sessions = 0; my_instance->sessions = 0;
if (my_instance->match && if (my_instance->match &&
regcomp(&my_instance->re, my_instance->match, REG_ICASE)) regcomp(&my_instance->re, my_instance->match, cflags))
{ {
MXS_ERROR("topfilter: Invalid regular expression '%s'" MXS_ERROR("topfilter: Invalid regular expression '%s'"
" for the match parameter.", " for the match parameter.",
@ -253,8 +275,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
return NULL; return NULL;
} }
if (my_instance->exclude && if (my_instance->exclude &&
regcomp(&my_instance->exre, my_instance->exclude, regcomp(&my_instance->exre, my_instance->exclude, cflags))
REG_ICASE))
{ {
MXS_ERROR("qlafilter: Invalid regular expression '%s'" MXS_ERROR("qlafilter: Invalid regular expression '%s'"
" for the nomatch paramter.\n", " for the nomatch paramter.\n",