Formatted namedserverfilter
Namedserverfilter formatted according to the style guide.
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
*
|
||||
* Copyright MariaDB Corporation Ab 2014
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <filter.h>
|
||||
#include <modinfo.h>
|
||||
@ -43,7 +44,8 @@
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
MODULE_INFO info = {
|
||||
MODULE_INFO info =
|
||||
{
|
||||
MODULE_API_FILTER,
|
||||
MODULE_GA,
|
||||
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 FILTER_OBJECT MyObject = {
|
||||
static FILTER_OBJECT MyObject =
|
||||
{
|
||||
createInstance,
|
||||
newSession,
|
||||
closeSession,
|
||||
@ -76,7 +79,8 @@ static FILTER_OBJECT MyObject = {
|
||||
/**
|
||||
* Instance structure
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
char *source; /* Source address to restrict matches */
|
||||
char *user; /* User name to restrict matches */
|
||||
char *match; /* Regular expression to match */
|
||||
@ -88,7 +92,8 @@ typedef struct {
|
||||
/**
|
||||
* The session structuee for this regex filter
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
DOWNSTREAM down; /* The downstream filter */
|
||||
int n_diverted; /* No. of statements diverted */
|
||||
int n_undiverted; /* No. of statements not diverted */
|
||||
@ -141,8 +146,8 @@ GetModuleObject()
|
||||
static FILTER *
|
||||
createInstance(char **options, FILTER_PARAMETER **params)
|
||||
{
|
||||
REGEXHINT_INSTANCE *my_instance;
|
||||
int i, cflags = REG_ICASE;
|
||||
REGEXHINT_INSTANCE *my_instance;
|
||||
int i, cflags = REG_ICASE;
|
||||
|
||||
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++)
|
||||
{
|
||||
if (!strcmp(params[i]->name, "match"))
|
||||
{
|
||||
my_instance->match = strdup(params[i]->value);
|
||||
}
|
||||
else if (!strcmp(params[i]->name, "server"))
|
||||
{
|
||||
my_instance->server = 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))
|
||||
{
|
||||
MXS_ERROR("namedserverfilter: Unexpected parameter '%s'.",
|
||||
@ -207,7 +220,7 @@ int i, cflags = REG_ICASE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return (FILTER *)my_instance;
|
||||
return(FILTER *) my_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,9 +233,9 @@ int i, cflags = REG_ICASE;
|
||||
static void *
|
||||
newSession(FILTER *instance, SESSION *session)
|
||||
{
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance;
|
||||
REGEXHINT_SESSION *my_session;
|
||||
char *remote, *user;
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
|
||||
REGEXHINT_SESSION *my_session;
|
||||
char *remote, *user;
|
||||
|
||||
if ((my_session = calloc(1, sizeof(REGEXHINT_SESSION))) != NULL)
|
||||
{
|
||||
@ -281,8 +294,7 @@ freeSession(FILTER *instance, void *session)
|
||||
static void
|
||||
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;
|
||||
}
|
||||
|
||||
@ -303,9 +315,9 @@ REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)session;
|
||||
static int
|
||||
routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||
{
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance;
|
||||
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)session;
|
||||
char *sql;
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
|
||||
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) session;
|
||||
char *sql;
|
||||
|
||||
if (modutil_is_SQL(queue))
|
||||
{
|
||||
@ -315,7 +327,7 @@ char *sql;
|
||||
}
|
||||
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,
|
||||
HINT_ROUTE_TO_NAMED_SERVER,
|
||||
@ -323,10 +335,11 @@ char *sql;
|
||||
my_session->n_diverted++;
|
||||
}
|
||||
else
|
||||
{
|
||||
my_session->n_undiverted++;
|
||||
}
|
||||
free(sql);
|
||||
}
|
||||
|
||||
}
|
||||
return my_session->down.routeQuery(my_session->down.instance,
|
||||
my_session->down.session, queue);
|
||||
@ -346,8 +359,8 @@ char *sql;
|
||||
static void
|
||||
diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
||||
{
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *)instance;
|
||||
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)fsession;
|
||||
REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE *) instance;
|
||||
REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *) fsession;
|
||||
|
||||
dcb_printf(dcb, "\t\tMatch and route: /%s/ -> %s\n",
|
||||
my_instance->match, my_instance->server);
|
||||
@ -359,11 +372,15 @@ REGEXHINT_SESSION *my_session = (REGEXHINT_SESSION *)fsession;
|
||||
my_session->n_undiverted);
|
||||
}
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"\t\tReplacement limited to connections from %s\n",
|
||||
my_instance->source);
|
||||
}
|
||||
if (my_instance->user)
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"\t\tReplacement limit to user %s\n",
|
||||
my_instance->user);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user