Formatted namedserverfilter

Namedserverfilter formatted according to the style guide.
This commit is contained in:
Markus Makela
2015-11-18 14:44:05 +02:00
parent 036fd6f16c
commit cbeead7c43

View File

@ -15,6 +15,7 @@
* *
* Copyright MariaDB Corporation Ab 2014 * Copyright MariaDB Corporation Ab 2014
*/ */
#include <stdio.h> #include <stdio.h>
#include <filter.h> #include <filter.h>
#include <modinfo.h> #include <modinfo.h>
@ -43,7 +44,8 @@
* @endverbatim * @endverbatim
*/ */
MODULE_INFO info = { MODULE_INFO info =
{
MODULE_API_FILTER, MODULE_API_FILTER,
MODULE_GA, MODULE_GA,
FILTER_VERSION, FILTER_VERSION,
@ -61,7 +63,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,
@ -76,7 +79,8 @@ static FILTER_OBJECT MyObject = {
/** /**
* Instance structure * Instance structure
*/ */
typedef struct { typedef struct
{
char *source; /* Source address to restrict matches */ char *source; /* Source address to restrict matches */
char *user; /* User name to restrict matches */ char *user; /* User name to restrict matches */
char *match; /* Regular expression to match */ char *match; /* Regular expression to match */
@ -88,7 +92,8 @@ typedef struct {
/** /**
* The session structuee for this regex filter * The session structuee for this regex filter
*/ */
typedef struct { typedef struct
{
DOWNSTREAM down; /* The downstream filter */ DOWNSTREAM down; /* The downstream filter */
int n_diverted; /* No. of statements diverted */ int n_diverted; /* No. of statements diverted */
int n_undiverted; /* No. of statements not diverted */ int n_undiverted; /* No. of statements not diverted */
@ -152,13 +157,21 @@ int i, cflags = REG_ICASE;
for (i = 0; params && params[i]; i++) for (i = 0; params && params[i]; i++)
{ {
if (!strcmp(params[i]->name, "match")) if (!strcmp(params[i]->name, "match"))
{
my_instance->match = strdup(params[i]->value); my_instance->match = strdup(params[i]->value);
}
else if (!strcmp(params[i]->name, "server")) else if (!strcmp(params[i]->name, "server"))
{
my_instance->server = strdup(params[i]->value); my_instance->server = 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->user = strdup(params[i]->value); my_instance->user = strdup(params[i]->value);
}
else if (!filter_standard_parameter(params[i]->name)) else if (!filter_standard_parameter(params[i]->name))
{ {
MXS_ERROR("namedserverfilter: Unexpected parameter '%s'.", MXS_ERROR("namedserverfilter: Unexpected parameter '%s'.",
@ -282,7 +295,6 @@ static void
setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream) setDownstream(FILTER *instance, void *session, DOWNSTREAM *downstream)
{ {
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) session; REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) session;
my_session->down = *downstream; my_session->down = *downstream;
} }
@ -323,10 +335,11 @@ char *sql;
my_session->n_diverted++; my_session->n_diverted++;
} }
else else
{
my_session->n_undiverted++; my_session->n_undiverted++;
}
free(sql); free(sql);
} }
} }
return my_session->down.routeQuery(my_session->down.instance, return my_session->down.routeQuery(my_session->down.instance,
my_session->down.session, queue); my_session->down.session, queue);
@ -359,11 +372,15 @@ REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)fsession;
my_session->n_undiverted); my_session->n_undiverted);
} }
if (my_instance->source) if (my_instance->source)
{
dcb_printf(dcb, dcb_printf(dcb,
"\t\tReplacement limited to connections from %s\n", "\t\tReplacement limited to connections from %s\n",
my_instance->source); my_instance->source);
}
if (my_instance->user) if (my_instance->user)
{
dcb_printf(dcb, dcb_printf(dcb,
"\t\tReplacement limit to user %s\n", "\t\tReplacement limit to user %s\n",
my_instance->user); my_instance->user);
} }
}