Formatted qlafilter

Qlafilter formatted according to the style guide.
This commit is contained in:
Markus Makela
2015-11-18 14:31:02 +02:00
parent a7c0952e66
commit 036fd6f16c

View File

@ -38,6 +38,7 @@
*
* @endverbatim
*/
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
@ -52,7 +53,8 @@
#include <string.h>
#include <atomic.h>
MODULE_INFO info = {
MODULE_INFO info =
{
MODULE_API_FILTER,
MODULE_GA,
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 FILTER_OBJECT MyObject = {
static FILTER_OBJECT MyObject =
{
createInstance,
newSession,
closeSession,
@ -93,7 +96,8 @@ static FILTER_OBJECT MyObject = {
* To this base a session number is attached such that each session will
* have a unique name.
*/
typedef struct {
typedef struct
{
int sessions; /* The count of sessions */
char *filebase; /* The filename base */
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.
*/
typedef struct {
typedef struct
{
DOWNSTREAM down;
char *filename;
FILE *fp;
@ -165,14 +170,17 @@ GetModuleObject()
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
{
QLA_INSTANCE *my_instance;
int i;
QLA_INSTANCE *my_instance;
int i;
if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL)
{
if (options){
if (options)
{
my_instance->filebase = strdup(options[0]);
}else{
}
else
{
my_instance->filebase = strdup("qla");
}
my_instance->source = NULL;
@ -192,12 +200,17 @@ int i;
my_instance->nomatch = 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->userName = strdup(params[i]->value);
}
else if (!strcmp(params[i]->name, "filebase"))
{
if (my_instance->filebase){
if (my_instance->filebase)
{
free(my_instance->filebase);
my_instance->filebase = NULL;
}
@ -219,7 +232,8 @@ int i;
my_instance->match);
free(my_instance->match);
free(my_instance->source);
if(my_instance->filebase){
if (my_instance->filebase)
{
free(my_instance->filebase);
}
free(my_instance);
@ -233,17 +247,20 @@ int i;
" for the nomatch paramter.",
my_instance->match);
if (my_instance->match)
{
regfree(&my_instance->re);
}
free(my_instance->match);
free(my_instance->source);
if(my_instance->filebase){
if (my_instance->filebase)
{
free(my_instance->filebase);
}
free(my_instance);
return NULL;
}
}
return (FILTER *)my_instance;
return(FILTER *) my_instance;
}
/**
@ -258,14 +275,14 @@ int i;
static void *
newSession(FILTER *instance, SESSION *session)
{
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
QLA_SESSION *my_session;
char *remote, *userName;
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
QLA_SESSION *my_session;
char *remote, *userName;
if ((my_session = calloc(1, sizeof(QLA_SESSION))) != NULL)
{
if ((my_session->filename =
(char *)malloc(strlen(my_instance->filebase) + 20))
(char *) malloc(strlen(my_instance->filebase) + 20))
== NULL)
{
char errbuf[STRERROR_BUFLEN];
@ -282,13 +299,15 @@ char *remote, *userName;
&& (remote = session_get_remote(session)) != NULL)
{
if (strcmp(remote, my_instance->source))
{
my_session->active = 0;
}
}
userName = session_getUser(session);
if (my_instance->userName &&
userName &&
strcmp(userName,my_instance->userName))
strcmp(userName, my_instance->userName))
{
my_session->active = 0;
}
@ -338,10 +357,12 @@ char *remote, *userName;
static void
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)
{
fclose(my_session->fp);
}
}
/**
@ -353,7 +374,7 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
static void
freeSession(FILTER *instance, void *session)
{
QLA_SESSION *my_session = (QLA_SESSION *)session;
QLA_SESSION *my_session = (QLA_SESSION *) session;
free(my_session->filename);
free(session);
@ -371,7 +392,7 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
static void
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;
}
@ -389,12 +410,12 @@ QLA_SESSION *my_session = (QLA_SESSION *)session;
static int
routeQuery(FILTER *instance, void *session, GWBUF *queue)
{
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
QLA_SESSION *my_session = (QLA_SESSION *)session;
char *ptr;
int length = 0;
struct tm t;
struct timeval tv;
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
QLA_SESSION *my_session = (QLA_SESSION *) session;
char *ptr;
int length = 0;
struct tm t;
struct timeval tv;
if (my_session->active)
{
@ -407,15 +428,15 @@ struct timeval tv;
if ((my_instance->match == NULL ||
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
(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);
localtime_r(&tv.tv_sec, &t);
fprintf(my_session->fp,
"%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);
fprintf(my_session->fp,"%s\n",ptr);
fprintf(my_session->fp, "%s\n", ptr);
}
free(ptr);
@ -440,8 +461,8 @@ struct timeval tv;
static void
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
{
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
QLA_SESSION *my_session = (QLA_SESSION *)fsession;
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
QLA_SESSION *my_session = (QLA_SESSION *) fsession;
if (my_session)
{
@ -449,15 +470,23 @@ QLA_SESSION *my_session = (QLA_SESSION *)fsession;
my_session->filename);
}
if (my_instance->source)
{
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
my_instance->source);
}
if (my_instance->userName)
{
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
my_instance->userName);
}
if (my_instance->match)
{
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
my_instance->match);
}
if (my_instance->nomatch)
{
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
my_instance->nomatch);
}
}