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 */
@ -141,8 +146,8 @@ GetModuleObject()
static FILTER * static FILTER *
createInstance(char **options, FILTER_PARAMETER **params) createInstance(char **options, FILTER_PARAMETER **params)
{ {
REGEXHINT_INSTANCE *my_instance; REGEXHINT_INSTANCE *my_instance;
int i, cflags = REG_ICASE; int i, cflags = REG_ICASE;
if ((my_instance = calloc(1, sizeof(REGEXHINT_INSTANCE))) != NULL) if ((my_instance = calloc(1, sizeof(REGEXHINT_INSTANCE))) != NULL)
{ {
@ -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'.",
@ -207,7 +220,7 @@ int i, cflags = REG_ICASE;
return NULL; return NULL;
} }
} }
return (FILTER *)my_instance; return(FILTER *) my_instance;
} }
/** /**
@ -220,9 +233,9 @@ int i, cflags = REG_ICASE;
static void * static void *
newSession(FILTER *instance, SESSION *session) newSession(FILTER *instance, SESSION *session)
{ {
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance; REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
REGEXHINT_SESSION *my_session; REGEXHINT_SESSION *my_session;
char *remote, *user; char *remote, *user;
if ((my_session = calloc(1, sizeof(REGEXHINT_SESSION))) != NULL) if ((my_session = calloc(1, sizeof(REGEXHINT_SESSION))) != NULL)
{ {
@ -281,8 +294,7 @@ freeSession(FILTER *instance, void *session)
static void 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;
} }
@ -303,9 +315,9 @@ REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)session;
static int static int
routeQuery(FILTER *instance, void *session, GWBUF *queue) routeQuery(FILTER *instance, void *session, GWBUF *queue)
{ {
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance; REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)session; REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) session;
char *sql; char *sql;
if (modutil_is_SQL(queue)) if (modutil_is_SQL(queue))
{ {
@ -315,7 +327,7 @@ char *sql;
} }
if ((sql = modutil_get_SQL(queue)) != NULL) if ((sql = modutil_get_SQL(queue)) != NULL)
{ {
if (regexec(&my_instance->re,sql,0,NULL, 0) == 0) if (regexec(&my_instance->re, sql, 0, NULL, 0) == 0)
{ {
queue->hint = hint_create_route(queue->hint, queue->hint = hint_create_route(queue->hint,
HINT_ROUTE_TO_NAMED_SERVER, HINT_ROUTE_TO_NAMED_SERVER,
@ -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);
@ -346,8 +359,8 @@ char *sql;
static void static void
diagnostic(FILTER *instance, void *fsession, DCB *dcb) diagnostic(FILTER *instance, void *fsession, DCB *dcb)
{ {
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance; REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)fsession; REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) fsession;
dcb_printf(dcb, "\t\tMatch and route: /%s/ -> %s\n", dcb_printf(dcb, "\t\tMatch and route: /%s/ -> %s\n",
my_instance->match, my_instance->server); my_instance->match, my_instance->server);
@ -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);
}
} }