Core changes to support tee filter.

This commit is contained in:
Mark Riddoch
2014-06-20 17:49:40 +01:00
parent e98b5d411e
commit 7067e43b44
5 changed files with 62 additions and 3 deletions

Binary file not shown.

View File

@ -48,6 +48,7 @@
* This fixes a bug with many reads from * This fixes a bug with many reads from
* backend * backend
* 07/05/2014 Mark Riddoch Addition of callback mechanism * 07/05/2014 Mark Riddoch Addition of callback mechanism
* 20/06/2014 Mark Riddoch Addition of dcb_clone
* *
* @endverbatim * @endverbatim
*/ */
@ -84,6 +85,9 @@ static bool dcb_set_state_nomutex(
dcb_state_t* old_state); dcb_state_t* old_state);
static void dcb_call_callback(DCB *dcb, DCB_REASON reason); static void dcb_call_callback(DCB *dcb, DCB_REASON reason);
static DCB* dcb_get_next (DCB* dcb); static DCB* dcb_get_next (DCB* dcb);
static int dcb_null_write(DCB *dcb, GWBUF *buf);
static int dcb_null_close(DCB *dcb);
static int dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf);
DCB* dcb_get_zombies(void) DCB* dcb_get_zombies(void)
{ {
@ -248,7 +252,38 @@ dcb_add_to_zombieslist(DCB *dcb)
spinlock_release(&zombiespin); spinlock_release(&zombiespin);
} }
/*
* Clone a DCB for internal use, mostly used for specialist filters
* to create dummy clients based on real clients.
*
* @param orig The DCB to clone
* @return A DCB that can be used as a client
*/
DCB *
dcb_clone(DCB *orig)
{
DCB *clone;
if ((clone = dcb_alloc(DCB_ROLE_REQUEST_HANDLER)) == NULL)
{
return NULL;
}
clone->fd = -1;
clone->state = orig->state;
clone->data = orig->data;
if (orig->remote)
clone->remote = strdup(orig->remote);
if (orig->user)
clone->user = strdup(orig->user);
clone->protocol = orig->protocol;
clone->func.write = dcb_null_write;
clone->func.close = dcb_null_close;
clone->func.auth = dcb_null_auth;
return clone;
}
/** /**
* Free a DCB and remove it from the chain of all DCBs * Free a DCB and remove it from the chain of all DCBs
@ -1822,3 +1857,21 @@ void dcb_call_foreach (
return; return;
} }
static int
dcb_null_write(DCB *dcb, GWBUF *buf)
{
return 1;
}
static int
dcb_null_close(DCB *dcb)
{
return 0;
}
static int
dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf)
{
return 0;
}

View File

@ -271,6 +271,7 @@ int dcb_write(DCB *, GWBUF *);
DCB *dcb_alloc(dcb_role_t); DCB *dcb_alloc(dcb_role_t);
void dcb_free(DCB *); void dcb_free(DCB *);
DCB *dcb_connect(struct server *, struct session *, const char *); DCB *dcb_connect(struct server *, struct session *, const char *);
DCB *dcb_clone(DCB *);
int dcb_read(DCB *, GWBUF **); int dcb_read(DCB *, GWBUF **);
int dcb_drain_writeq(DCB *); int dcb_drain_writeq(DCB *);
void dcb_close(DCB *); void dcb_close(DCB *);

View File

@ -40,10 +40,12 @@ REGEXSRCS=regexfilter.c
REGEXOBJ=$(REGEXSRCS:.c=.o) REGEXOBJ=$(REGEXSRCS:.c=.o)
TOPNSRCS=topfilter.c TOPNSRCS=topfilter.c
TOPNOBJ=$(TOPNSRCS:.c=.o) TOPNOBJ=$(TOPNSRCS:.c=.o)
SRCS=$(TESTSRCS) $(QLASRCS) $(REGEXSRCS) $(TOPNSRCS) TEESRCS=tee.c
TEEOBJ=$(TEESRCS:.c=.o)
SRCS=$(TESTSRCS) $(QLASRCS) $(REGEXSRCS) $(TOPNSRCS) $(TEESRCS)
OBJ=$(SRCS:.c=.o) OBJ=$(SRCS:.c=.o)
LIBS=$(UTILSPATH)/skygw_utils.o -lssl -llog_manager LIBS=$(UTILSPATH)/skygw_utils.o -lssl -llog_manager
MODULES= libtestfilter.so libqlafilter.so libregexfilter.so libtopfilter.so MODULES= libtestfilter.so libqlafilter.so libregexfilter.so libtopfilter.so libtee.so
all: $(MODULES) all: $(MODULES)
@ -60,6 +62,9 @@ libregexfilter.so: $(REGEXOBJ)
libtopfilter.so: $(TOPNOBJ) libtopfilter.so: $(TOPNOBJ)
$(CC) $(LDFLAGS) $(TOPNOBJ) $(LIBS) -o $@ $(CC) $(LDFLAGS) $(TOPNOBJ) $(LIBS) -o $@
libtee.so: $(TEEOBJ)
$(CC) $(LDFLAGS) $(TEEOBJ) $(LIBS) -o $@
.c.o: .c.o:
$(CC) $(CFLAGS) $< -o $@ $(CC) $(CFLAGS) $< -o $@