Formatted qlafilter
Qlafilter formatted according to the style guide.
This commit is contained in:
@ -38,6 +38,7 @@
|
|||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -52,7 +53,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <atomic.h>
|
#include <atomic.h>
|
||||||
|
|
||||||
MODULE_INFO info = {
|
MODULE_INFO info =
|
||||||
|
{
|
||||||
MODULE_API_FILTER,
|
MODULE_API_FILTER,
|
||||||
MODULE_GA,
|
MODULE_GA,
|
||||||
FILTER_VERSION,
|
FILTER_VERSION,
|
||||||
@ -73,7 +75,8 @@ static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
|||||||
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
||||||
|
|
||||||
|
|
||||||
static FILTER_OBJECT MyObject = {
|
static FILTER_OBJECT MyObject =
|
||||||
|
{
|
||||||
createInstance,
|
createInstance,
|
||||||
newSession,
|
newSession,
|
||||||
closeSession,
|
closeSession,
|
||||||
@ -93,7 +96,8 @@ static FILTER_OBJECT MyObject = {
|
|||||||
* To this base a session number is attached such that each session will
|
* To this base a session number is attached such that each session will
|
||||||
* have a unique name.
|
* have a unique name.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
int sessions; /* The count of sessions */
|
int sessions; /* The count of sessions */
|
||||||
char *filebase; /* The filename base */
|
char *filebase; /* The filename base */
|
||||||
char *source; /* The source of the client connection */
|
char *source; /* The source of the client connection */
|
||||||
@ -112,7 +116,8 @@ typedef struct {
|
|||||||
*
|
*
|
||||||
* It also holds the file descriptor to which queries are written.
|
* It also holds the file descriptor to which queries are written.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
DOWNSTREAM down;
|
DOWNSTREAM down;
|
||||||
char *filename;
|
char *filename;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -165,14 +170,17 @@ GetModuleObject()
|
|||||||
static FILTER *
|
static FILTER *
|
||||||
createInstance(char **options, FILTER_PARAMETER **params)
|
createInstance(char **options, FILTER_PARAMETER **params)
|
||||||
{
|
{
|
||||||
QLA_INSTANCE *my_instance;
|
QLA_INSTANCE *my_instance;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL)
|
if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL)
|
||||||
{
|
{
|
||||||
if (options){
|
if (options)
|
||||||
|
{
|
||||||
my_instance->filebase = strdup(options[0]);
|
my_instance->filebase = strdup(options[0]);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
my_instance->filebase = strdup("qla");
|
my_instance->filebase = strdup("qla");
|
||||||
}
|
}
|
||||||
my_instance->source = NULL;
|
my_instance->source = NULL;
|
||||||
@ -192,12 +200,17 @@ int i;
|
|||||||
my_instance->nomatch = strdup(params[i]->value);
|
my_instance->nomatch = strdup(params[i]->value);
|
||||||
}
|
}
|
||||||
else if (!strcmp(params[i]->name, "source"))
|
else if (!strcmp(params[i]->name, "source"))
|
||||||
|
{
|
||||||
my_instance->source = strdup(params[i]->value);
|
my_instance->source = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "user"))
|
else if (!strcmp(params[i]->name, "user"))
|
||||||
|
{
|
||||||
my_instance->userName = strdup(params[i]->value);
|
my_instance->userName = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "filebase"))
|
else if (!strcmp(params[i]->name, "filebase"))
|
||||||
{
|
{
|
||||||
if (my_instance->filebase){
|
if (my_instance->filebase)
|
||||||
|
{
|
||||||
free(my_instance->filebase);
|
free(my_instance->filebase);
|
||||||
my_instance->filebase = NULL;
|
my_instance->filebase = NULL;
|
||||||
}
|
}
|
||||||
@ -219,7 +232,8 @@ int i;
|
|||||||
my_instance->match);
|
my_instance->match);
|
||||||
free(my_instance->match);
|
free(my_instance->match);
|
||||||
free(my_instance->source);
|
free(my_instance->source);
|
||||||
if(my_instance->filebase){
|
if (my_instance->filebase)
|
||||||
|
{
|
||||||
free(my_instance->filebase);
|
free(my_instance->filebase);
|
||||||
}
|
}
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
@ -233,17 +247,20 @@ int i;
|
|||||||
" for the nomatch paramter.",
|
" for the nomatch paramter.",
|
||||||
my_instance->match);
|
my_instance->match);
|
||||||
if (my_instance->match)
|
if (my_instance->match)
|
||||||
|
{
|
||||||
regfree(&my_instance->re);
|
regfree(&my_instance->re);
|
||||||
|
}
|
||||||
free(my_instance->match);
|
free(my_instance->match);
|
||||||
free(my_instance->source);
|
free(my_instance->source);
|
||||||
if(my_instance->filebase){
|
if (my_instance->filebase)
|
||||||
|
{
|
||||||
free(my_instance->filebase);
|
free(my_instance->filebase);
|
||||||
}
|
}
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (FILTER *)my_instance;
|
return(FILTER *) my_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -258,14 +275,14 @@ int i;
|
|||||||
static void *
|
static void *
|
||||||
newSession(FILTER *instance, SESSION *session)
|
newSession(FILTER *instance, SESSION *session)
|
||||||
{
|
{
|
||||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
|
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
|
||||||
QLA_SESSION *my_session;
|
QLA_SESSION *my_session;
|
||||||
char *remote, *userName;
|
char *remote, *userName;
|
||||||
|
|
||||||
if ((my_session = calloc(1, sizeof(QLA_SESSION))) != NULL)
|
if ((my_session = calloc(1, sizeof(QLA_SESSION))) != NULL)
|
||||||
{
|
{
|
||||||
if ((my_session->filename =
|
if ((my_session->filename =
|
||||||
(char *)malloc(strlen(my_instance->filebase) + 20))
|
(char *) malloc(strlen(my_instance->filebase) + 20))
|
||||||
== NULL)
|
== NULL)
|
||||||
{
|
{
|
||||||
char errbuf[STRERROR_BUFLEN];
|
char errbuf[STRERROR_BUFLEN];
|
||||||
@ -282,13 +299,15 @@ char *remote, *userName;
|
|||||||
&& (remote = session_get_remote(session)) != NULL)
|
&& (remote = session_get_remote(session)) != NULL)
|
||||||
{
|
{
|
||||||
if (strcmp(remote, my_instance->source))
|
if (strcmp(remote, my_instance->source))
|
||||||
|
{
|
||||||
my_session->active = 0;
|
my_session->active = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
userName = session_getUser(session);
|
userName = session_getUser(session);
|
||||||
|
|
||||||
if (my_instance->userName &&
|
if (my_instance->userName &&
|
||||||
userName &&
|
userName &&
|
||||||
strcmp(userName,my_instance->userName))
|
strcmp(userName, my_instance->userName))
|
||||||
{
|
{
|
||||||
my_session->active = 0;
|
my_session->active = 0;
|
||||||
}
|
}
|
||||||
@ -338,10 +357,12 @@ char *remote, *userName;
|
|||||||
static void
|
static void
|
||||||
closeSession(FILTER *instance, void *session)
|
closeSession(FILTER *instance, void *session)
|
||||||
{
|
{
|
||||||
QLA_SESSION *my_session = (QLA_SESSION *)session;
|
QLA_SESSION *my_session = (QLA_SESSION *) session;
|
||||||
|
|
||||||
if (my_session->active && my_session->fp)
|
if (my_session->active && my_session->fp)
|
||||||
|
{
|
||||||
fclose(my_session->fp);
|
fclose(my_session->fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +374,7 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
|
|||||||
static void
|
static void
|
||||||
freeSession(FILTER *instance, void *session)
|
freeSession(FILTER *instance, void *session)
|
||||||
{
|
{
|
||||||
QLA_SESSION *my_session = (QLA_SESSION *)session;
|
QLA_SESSION *my_session = (QLA_SESSION *) session;
|
||||||
|
|
||||||
free(my_session->filename);
|
free(my_session->filename);
|
||||||
free(session);
|
free(session);
|
||||||
@ -371,7 +392,7 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
|
|||||||
static void
|
static void
|
||||||
setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream)
|
setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream)
|
||||||
{
|
{
|
||||||
QLA_SESSION *my_session = (QLA_SESSION *)session;
|
QLA_SESSION *my_session = (QLA_SESSION *) session;
|
||||||
|
|
||||||
my_session->down = *downstream;
|
my_session->down = *downstream;
|
||||||
}
|
}
|
||||||
@ -389,12 +410,12 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
|
|||||||
static int
|
static int
|
||||||
routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||||
{
|
{
|
||||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
|
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
|
||||||
QLA_SESSION *my_session = (QLA_SESSION *)session;
|
QLA_SESSION *my_session = (QLA_SESSION *) session;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
struct tm t;
|
struct tm t;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
if (my_session->active)
|
if (my_session->active)
|
||||||
{
|
{
|
||||||
@ -407,15 +428,15 @@ struct timeval tv;
|
|||||||
if ((my_instance->match == NULL ||
|
if ((my_instance->match == NULL ||
|
||||||
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
|
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
|
||||||
(my_instance->nomatch == NULL ||
|
(my_instance->nomatch == NULL ||
|
||||||
regexec(&my_instance->nore,ptr,0,NULL, 0) != 0))
|
regexec(&my_instance->nore, ptr, 0, NULL, 0) != 0))
|
||||||
{
|
{
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
localtime_r(&tv.tv_sec, &t);
|
localtime_r(&tv.tv_sec, &t);
|
||||||
fprintf(my_session->fp,
|
fprintf(my_session->fp,
|
||||||
"%02d:%02d:%02d.%-3d %d/%02d/%d, ",
|
"%02d:%02d:%02d.%-3d %d/%02d/%d, ",
|
||||||
t.tm_hour, t.tm_min, t.tm_sec, (int)(tv.tv_usec / 1000),
|
t.tm_hour, t.tm_min, t.tm_sec, (int) (tv.tv_usec / 1000),
|
||||||
t.tm_mday, t.tm_mon + 1, 1900 + t.tm_year);
|
t.tm_mday, t.tm_mon + 1, 1900 + t.tm_year);
|
||||||
fprintf(my_session->fp,"%s\n",ptr);
|
fprintf(my_session->fp, "%s\n", ptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(ptr);
|
free(ptr);
|
||||||
@ -440,8 +461,8 @@ struct timeval tv;
|
|||||||
static void
|
static void
|
||||||
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
||||||
{
|
{
|
||||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
|
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
|
||||||
QLA_SESSION *my_session = (QLA_SESSION *)fsession;
|
QLA_SESSION *my_session = (QLA_SESSION *) fsession;
|
||||||
|
|
||||||
if (my_session)
|
if (my_session)
|
||||||
{
|
{
|
||||||
@ -449,15 +470,23 @@ QLA_SESSION *my_session = (QLA_SESSION *)fsession;
|
|||||||
my_session->filename);
|
my_session->filename);
|
||||||
}
|
}
|
||||||
if (my_instance->source)
|
if (my_instance->source)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
|
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
|
||||||
my_instance->source);
|
my_instance->source);
|
||||||
|
}
|
||||||
if (my_instance->userName)
|
if (my_instance->userName)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
|
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
|
||||||
my_instance->userName);
|
my_instance->userName);
|
||||||
|
}
|
||||||
if (my_instance->match)
|
if (my_instance->match)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
||||||
my_instance->match);
|
my_instance->match);
|
||||||
|
}
|
||||||
if (my_instance->nomatch)
|
if (my_instance->nomatch)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
||||||
my_instance->nomatch);
|
my_instance->nomatch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user