diff --git a/Documentation/filters/QLA Filter.pdf b/Documentation/filters/QLA Filter.pdf index 967aa4592..94818c426 100644 Binary files a/Documentation/filters/QLA Filter.pdf and b/Documentation/filters/QLA Filter.pdf differ diff --git a/Documentation/filters/Regex Filter.pdf b/Documentation/filters/Regex Filter.pdf index c589aba3e..fb73468a4 100644 Binary files a/Documentation/filters/Regex Filter.pdf and b/Documentation/filters/Regex Filter.pdf differ diff --git a/Documentation/filters/Top Filter.pdf b/Documentation/filters/Top Filter.pdf index 9013f67c1..03ff3d561 100644 Binary files a/Documentation/filters/Top Filter.pdf and b/Documentation/filters/Top Filter.pdf differ diff --git a/server/modules/filter/qlafilter.c b/server/modules/filter/qlafilter.c index 8e999c9aa..ce07e7a17 100644 --- a/server/modules/filter/qlafilter.c +++ b/server/modules/filter/qlafilter.c @@ -31,6 +31,7 @@ * Date Who Description * 03/06/2014 Mark Riddoch Initial implementation * 11/06/2014 Mark Riddoch Addition of source and match parameters + * 19/06/2014 Mark Riddoch Addition of user parameter * */ #include @@ -54,7 +55,7 @@ MODULE_INFO info = { "A simple query logging filter" }; -static char *version_str = "V1.1.0"; +static char *version_str = "V1.1.1"; /* * The filter entry points @@ -92,6 +93,7 @@ typedef struct { int sessions; /* The count of sessions */ char *filebase; /* The filemane base */ char *source; /* The source of the client connection */ + char *userName; /* The user name to filter on */ char *match; /* Optional text to match against */ regex_t re; /* Compiled regex text */ char *nomatch; /* Optional text to match against for exclusion */ @@ -168,6 +170,7 @@ int i; else my_instance->filebase = strdup("qla"); my_instance->source = NULL; + my_instance->userName = NULL; my_instance->match = NULL; my_instance->nomatch = NULL; if (params) @@ -184,6 +187,8 @@ int i; } else if (!strcmp(params[i]->name, "source")) my_instance->source = strdup(params[i]->value); + else if (!strcmp(params[i]->name, "user")) + my_instance->userName = strdup(params[i]->value); else if (!strcmp(params[i]->name, "filebase")) { if (my_instance->filebase) @@ -247,7 +252,7 @@ newSession(FILTER *instance, SESSION *session) { QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance; QLA_SESSION *my_session; -char *remote; +char *remote, *userName; if ((my_session = calloc(1, sizeof(QLA_SESSION))) != NULL) { @@ -265,6 +270,13 @@ char *remote; if (strcmp(remote, my_instance->source)) my_session->active = 0; } + if (session && session->client && session->client->user) + userName = session->client->user; + else + userName = NULL; + if (my_instance->userName && strcmp(userName, + my_instance->userName)) + my_session->active = 0; sprintf(my_session->filename, "%s.%d", my_instance->filebase, my_instance->sessions); my_instance->sessions++; diff --git a/server/modules/filter/regexfilter.c b/server/modules/filter/regexfilter.c index 106dd73d8..44287dbbe 100644 --- a/server/modules/filter/regexfilter.c +++ b/server/modules/filter/regexfilter.c @@ -33,6 +33,12 @@ extern int lm_enabled_logfiles_bitmask; * Two parameters should be defined in the filter configuration * match= * replace= + * Two optional parameters + * source= + * user= + * + * Date Who Description + * 19/06/2014 Mark Riddoch Addition of source and user parameters */ MODULE_INFO info = { @@ -42,7 +48,7 @@ MODULE_INFO info = { "A query rewrite filter that uses regular expressions to rewite queries" }; -static char *version_str = "V1.0.0"; +static char *version_str = "V1.1.0"; static FILTER *createInstance(char **options, FILTER_PARAMETER **params); static void *newSession(FILTER *instance, SESSION *session); @@ -70,6 +76,8 @@ static FILTER_OBJECT MyObject = { * Instance structure */ typedef struct { + char *source; /* Source address to restrict matches */ + char *user; /* User name to restrict matches */ char *match; /* Regular expression to match */ char *replace; /* Replacement text */ regex_t re; /* Compiled regex text */ @@ -79,9 +87,10 @@ typedef struct { * The session structure for this regex filter */ typedef struct { - DOWNSTREAM down; - int no_change; - int replacements; + DOWNSTREAM down; /* The downstream filter */ + int no_change; /* No. of unchanged requests */ + int replacements; /* No. of changed requests */ + int active; /* Is filter active */ } REGEX_SESSION; /** @@ -143,6 +152,10 @@ int i, cflags = REG_ICASE; my_instance->match = strdup(params[i]->value); else if (!strcmp(params[i]->name, "replace")) my_instance->replace = strdup(params[i]->value); + else if (!strcmp(params[i]->name, "source")) + my_instance->source = strdup(params[i]->value); + else if (!strcmp(params[i]->name, "user")) + my_instance->user = strdup(params[i]->value); else if (!filter_standard_parameter(params[i]->name)) { LOGIF(LE, (skygw_log_write_flush( @@ -203,12 +216,28 @@ int i, cflags = REG_ICASE; static void * newSession(FILTER *instance, SESSION *session) { +REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *)instance; REGEX_SESSION *my_session; +char *remote; if ((my_session = calloc(1, sizeof(REGEX_SESSION))) != NULL) { my_session->no_change = 0; my_session->replacements = 0; + my_session->active = 1; + if (my_instance->source + && (remote = session_get_remote(session)) != NULL) + { + if (strcmp(remote, my_instance->source)) + my_session->active = 0; + } + if (my_instance->user + && session && session->client && session->client->user + && strcmp(session->client->user, + my_instance->user)) + { + my_session->active = 0; + } } return my_session; diff --git a/server/modules/filter/topfilter.c b/server/modules/filter/topfilter.c index 63a2299c1..45741c011 100644 --- a/server/modules/filter/topfilter.c +++ b/server/modules/filter/topfilter.c @@ -27,6 +27,9 @@ * A single option may be passed to the filter, this is the name of the * file to which the queries are logged. A serial number is appended to this * name in order that each session logs to a different file. + * + * Date Who Description + * 18/06/2014 Mark Riddoch Addition of source and user filters */ #include #include @@ -49,7 +52,7 @@ MODULE_INFO info = { "A top N query logging filter" }; -static char *version_str = "V1.0.0"; +static char *version_str = "V1.0.1"; /* * The filter entry points @@ -357,7 +360,7 @@ FILE *fp; } fprintf(fp, "-----------+-----------------------------------------------------------------\n"); fprintf(fp, "\n\nSession started %s", - asctime(localtime(&my_session->connect))); + asctime(localtime(&my_session->connect.tv_sec))); if (my_session->clientHost) fprintf(fp, "Connection from %s\n", my_session->clientHost);