Merge branch 'develop' into MAX-59
This commit is contained in:
@ -1090,7 +1090,7 @@ SERVER *server;
|
||||
s = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
if (filters)
|
||||
if (filters && obj->element)
|
||||
serviceSetFilters(obj->element, filters);
|
||||
}
|
||||
else if (!strcmp(type, "listener"))
|
||||
|
@ -134,6 +134,9 @@ DCB *rval;
|
||||
rval->next = NULL;
|
||||
rval->callbacks = NULL;
|
||||
|
||||
rval->remote = NULL;
|
||||
rval->user = NULL;
|
||||
|
||||
spinlock_acquire(&dcbspin);
|
||||
if (allDCBs == NULL)
|
||||
allDCBs = rval;
|
||||
@ -313,6 +316,8 @@ DCB_CALLBACK *cb;
|
||||
free(dcb->data);
|
||||
if (dcb->remote)
|
||||
free(dcb->remote);
|
||||
if (dcb->user)
|
||||
free(dcb->user);
|
||||
|
||||
/* Clear write and read buffers */
|
||||
if (dcb->delayq) {
|
||||
@ -1113,6 +1118,8 @@ printDCB(DCB *dcb)
|
||||
printf("\tDCB state: %s\n", gw_dcb_state2string(dcb->state));
|
||||
if (dcb->remote)
|
||||
printf("\tConnected to: %s\n", dcb->remote);
|
||||
if (dcb->user)
|
||||
printf("\tUsername to: %s\n", dcb->user);
|
||||
if (dcb->writeq)
|
||||
printf("\tQueued write data: %d\n",gwbuf_length(dcb->writeq));
|
||||
printf("\tStatistics:\n");
|
||||
@ -1170,6 +1177,9 @@ DCB *dcb;
|
||||
if (dcb->remote)
|
||||
dcb_printf(pdcb, "\tConnected to: %s\n",
|
||||
dcb->remote);
|
||||
if (dcb->user)
|
||||
dcb_printf(pdcb, "\tUsername: %s\n",
|
||||
dcb->user);
|
||||
if (dcb->writeq)
|
||||
dcb_printf(pdcb, "\tQueued write data: %d\n",
|
||||
gwbuf_length(dcb->writeq));
|
||||
|
@ -135,6 +135,19 @@ FILTER_DEF *filter;
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a parameter to see if it is a standard filter parameter
|
||||
*
|
||||
* @param name Parameter name to check
|
||||
*/
|
||||
int
|
||||
filter_standard_parameter(char *name)
|
||||
{
|
||||
if (strcmp(name, "type") == 0 || strcmp(name, "module") == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print all filters to a DCB
|
||||
*
|
||||
@ -289,6 +302,17 @@ int i;
|
||||
spinlock_release(&filter->spin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect the downstream filter chain for a filter.
|
||||
*
|
||||
* This will create the filter instance, loading the filter module, and
|
||||
* conenct the fitler into the downstream chain.
|
||||
*
|
||||
* @param filter The filter to add into the chain
|
||||
* @param session The client session
|
||||
* @param downstream The filter downstream of this filter
|
||||
* @return The downstream component for the next filter
|
||||
*/
|
||||
DOWNSTREAM *
|
||||
filterApply(FILTER_DEF *filter, SESSION *session, DOWNSTREAM *downstream)
|
||||
{
|
||||
@ -318,3 +342,42 @@ DOWNSTREAM *me;
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect a filter in the up stream filter chain for a session
|
||||
*
|
||||
* Note, the filter will have been created when the downstream chian was
|
||||
* previously setup.
|
||||
* Note all filters require to be in the upstream chain, so this routine
|
||||
* may skip a filter if it does not provide an upstream interface.
|
||||
*
|
||||
* @param filter The fitler to add to the chain
|
||||
* @param fsession The filter session
|
||||
* @param upstream The filter that should be upstream of this filter
|
||||
* @return The upstream component for the next filter
|
||||
*/
|
||||
UPSTREAM *
|
||||
filterUpstream(FILTER_DEF *filter, void *fsession, UPSTREAM *upstream)
|
||||
{
|
||||
UPSTREAM *me;
|
||||
|
||||
/*
|
||||
* The the filter has no setUpstream entry point then is does
|
||||
* not require to see results and can be left out of the chain.
|
||||
*/
|
||||
if (filter->obj->setUpstream == NULL)
|
||||
return upstream;
|
||||
|
||||
if (filter->obj->clientReply != NULL)
|
||||
{
|
||||
if ((me = (UPSTREAM *)calloc(1, sizeof(UPSTREAM))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
me->instance = filter->filter;
|
||||
me->session = fsession;
|
||||
me->clientReply = filter->obj->clientReply;
|
||||
filter->obj->setUpstream(me->instance, me->session, upstream);
|
||||
}
|
||||
return me;
|
||||
}
|
||||
|
@ -167,6 +167,10 @@ session_alloc(SERVICE *service, DCB *client_dcb)
|
||||
|
||||
session->head.routeQuery = (void *)(service->router->routeQuery);
|
||||
|
||||
session->tail.instance = session;
|
||||
session->tail.session = session;
|
||||
session->tail.clientReply = session_reply;
|
||||
|
||||
if (service->n_filters > 0)
|
||||
{
|
||||
if (!session_setup_filters(session))
|
||||
@ -315,6 +319,12 @@ bool session_free(
|
||||
}
|
||||
if (session->n_filters)
|
||||
{
|
||||
for (i = 0; i < session->n_filters; i++)
|
||||
{
|
||||
session->filters[i].filter->obj->closeSession(
|
||||
session->filters[i].instance,
|
||||
session->filters[i].session);
|
||||
}
|
||||
for (i = 0; i < session->n_filters; i++)
|
||||
{
|
||||
session->filters[i].filter->obj->freeSession(
|
||||
@ -616,6 +626,7 @@ session_setup_filters(SESSION *session)
|
||||
{
|
||||
SERVICE *service = session->service;
|
||||
DOWNSTREAM *head;
|
||||
UPSTREAM *tail;
|
||||
int i;
|
||||
|
||||
if ((session->filters = calloc(service->n_filters,
|
||||
@ -646,9 +657,54 @@ int i;
|
||||
session->head = *head;
|
||||
}
|
||||
|
||||
for (i = 0; i < service->n_filters; i++)
|
||||
{
|
||||
if ((tail = filterUpstream(service->filters[i],
|
||||
session->filters[i].session,
|
||||
&session->tail)) == NULL)
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Failed to create filter '%s' for service '%s'.\n",
|
||||
service->filters[i]->name,
|
||||
service->name)));
|
||||
return 0;
|
||||
}
|
||||
session->tail = *tail;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for the final element int he upstream filter, i.e. the writing
|
||||
* of the data to the client.
|
||||
*
|
||||
* @param instance The "instance" data
|
||||
* @param session The session
|
||||
* @param data The buffer chain to write
|
||||
*/
|
||||
int
|
||||
session_reply(void *instance, void *session, GWBUF *data)
|
||||
{
|
||||
SESSION *the_session = (SESSION *)session;
|
||||
|
||||
return the_session->client->func.write(the_session->client, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the client connection address or name
|
||||
*
|
||||
* @param session The session whose client address to return
|
||||
*/
|
||||
char *
|
||||
session_get_remote(SESSION *session)
|
||||
{
|
||||
if (session && session->client)
|
||||
return session->client->remote;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool session_route_query (
|
||||
SESSION* ses,
|
||||
GWBUF* buf)
|
||||
@ -674,4 +730,17 @@ bool session_route_query (
|
||||
return_succp:
|
||||
return succp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the username of the user connected to the client side of the
|
||||
* session.
|
||||
*
|
||||
* @param session The session pointer.
|
||||
* @return The user name or NULL if it can not be determined.
|
||||
*/
|
||||
char *
|
||||
session_getUser(SESSION *session)
|
||||
{
|
||||
return (session && session->client) ? session->client->user : NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user