From cc448f4bb96785661ae245baa559fea65b9fdfd7 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 14 Jun 2013 18:28:34 +0200 Subject: [PATCH 1/2] Updated testroute after modification to entry point definition --- modules/routing/testroute.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/routing/testroute.c b/modules/routing/testroute.c index 56314c053..db51d668f 100644 --- a/modules/routing/testroute.c +++ b/modules/routing/testroute.c @@ -22,8 +22,8 @@ static char *version_str = "V1.0.0"; static ROUTER *createInstance(SERVICE *service); static void *newSession(ROUTER *instance, SESSION *session); -static void closeSession(ROUTER *instance, SESSION *session); -static int routeQuery(ROUTER *instance, SESSION *session, GWBUF *queue); +static void closeSession(ROUTER *instance, void *session); +static int routeQuery(ROUTER *instance, void *session, GWBUF *queue); static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery }; @@ -96,12 +96,12 @@ newSession(ROUTER *instance, SESSION *session) * @param session The session being closed */ static void -closeSession(ROUTER *instance, SESSION *session) +closeSession(ROUTER *instance, void *session) { } static int -routeQuery(ROUTER *instance, SESSION *session, GWBUF *queue) +routeQuery(ROUTER *instance, void *session, GWBUF *queue) { } From 0a5becbe81352239d1948bd70032a97085244562 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 14 Jun 2013 18:29:08 +0200 Subject: [PATCH 2/2] Added skeletons for the two MySQL protocol modules. The actual code still needs to be moved into the modules --- Makefile | 2 + modules/protocol/Makefile | 47 ++++++++++++++++++ modules/protocol/mysql_backend.c | 82 ++++++++++++++++++++++++++++++++ modules/protocol/mysql_client.c | 82 ++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 modules/protocol/Makefile create mode 100644 modules/protocol/mysql_backend.c create mode 100644 modules/protocol/mysql_client.c diff --git a/Makefile b/Makefile index 6231773a9..2f8a8200b 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,9 @@ all: (cd core; make) (cd modules/routing; make) + (cd modules/protocol; make) clean: (cd core; make clean) (cd modules/routing; make clean) + (cd modules/protocol; make clean) diff --git a/modules/protocol/Makefile b/modules/protocol/Makefile new file mode 100644 index 000000000..a96ee10a8 --- /dev/null +++ b/modules/protocol/Makefile @@ -0,0 +1,47 @@ +# This file is distributed as part of the SkySQL Gateway. It is free +# software: you can redistribute it and/or modify it under the terms of the +# GNU General Public License as published by the Free Software Foundation, +# version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright SkySQL Ab 2013 +# +# Revision History +# Date Who Description +# 13/06/13 Mark Riddoch Initial protocol module development + +CC=cc +CFLAGS=-c -fPIC -I/usr/include -I../include -I../../include +LDFLAGS=-shared +MYSQLCLIENTSRCS=mysql_client.c +MYSQLCLIENTOBJ=$(MYSQLCLIENTSRCS:.c=.o) +MYSQLBACKENDSRCS=mysql_backend.c +MYSQLBACKENDOBJ=$(MYSQLBACKENDSRCS:.c=.o) +SRCS=$(MYSQLCLIENTSRCS) $(MYSQLBACKENDSRCS) +OBJ=$(SRCS:.c=.o) +LIBS= + +all: libMySQLClient.so libMySQLBackend.so + +libMySQLClient.so: $(MYSQLCLIENTOBJ) + $(CC) $(LDFLAGS) $(MYSQLCLIENTOBJ) $(LIBS) -o $@ + +libMySQLBackend.so: $(MYSQLBACKENDOBJ) + $(CC) $(LDFLAGS) $(MYSQLBACKENDOBJ) $(LIBS) -o $@ + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -f $(OBJ) libMySQLClient.so libMySQLBackend.so + +tags: + ctags $(SRCS) $(HDRS) diff --git a/modules/protocol/mysql_backend.c b/modules/protocol/mysql_backend.c new file mode 100644 index 000000000..7848585fb --- /dev/null +++ b/modules/protocol/mysql_backend.c @@ -0,0 +1,82 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ +#include +#include +#include + +/* + * MySQL Protocol module for handling the protocol between the gateway + * and the backend MySQL database. + * + * Revision History + * Date Who Description + * 14/06/2013 Mark Riddoch Initial version + */ + +static char *version_str = "V1.0.0"; + +extern int gw_read_backend_event(DCB* dcb, int epfd); +extern int gw_write_backend_event(DCB *dcb, int epfd); +extern int MySQLWrite(DCB *dcb, GWBUF *queue); +extern int handle_event_errors_backend(DCB *dcb, int event); + +static GWPROTOCOL MyObject = { + gw_read_backend_event, /* Read - EPOLLIN handler */ + MySQLWrite, /* Write - data from gateway */ + gw_write_backend_event, /* WriteReady - EPOLLOUT handler */ + handle_event_errors_backend, /* Error - EPOLLERR handler */ + NULL, /* HangUp - EPOLLHUP handler */ + NULL, /* Accept */ + NULL, /* Connect */ + NULL /* Close */ + }; + +/* + * Implementation of the mandatory version entry point + * + * @return version string of the module + */ +char * +version() +{ + return version_str; +} + +/* + * The module initialisation routine, called when the module + * is first loaded. + */ +void +ModuleInit() +{ + fprintf(stderr, "Initial MySQL Client Protcol module.\n"); +} + +/* + * The module entry point routine. It is this routine that + * must populate the structure that is referred to as the + * "module object", this is a structure with the set of + * external entry points for this module. + * + * @return The module object + */ +GWPROTOCOL * +GetModuleObject() +{ + return &MyObject; +} diff --git a/modules/protocol/mysql_client.c b/modules/protocol/mysql_client.c new file mode 100644 index 000000000..90b113ed0 --- /dev/null +++ b/modules/protocol/mysql_client.c @@ -0,0 +1,82 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ +#include +#include +#include + +/* + * MySQL Protocol module for handling the protocol between the gateway + * and the client. + * + * Revision History + * Date Who Description + * 14/06/2013 Mark Riddoch Initial version + */ + +static char *version_str = "V1.0.0"; + +extern int gw_route_read_event(DCB* dcb, int epfd); +extern int gw_handle_write_event(DCB *dcb, int epfd); +extern int MySQLWrite(DCB *dcb, GWBUF *queue); +extern int handle_event_errors(DCB *dcb, int event); + +static GWPROTOCOL MyObject = { + gw_route_read_event, /* Read - EPOLLIN handler */ + MySQLWrite, /* Write - data from gateway */ + gw_handle_write_event, /* WriteReady - EPOLLOUT handler */ + handle_event_errors, /* Error - EPOLLERR handler */ + NULL, /* HangUp - EPOLLHUP handler */ + NULL, /* Accept */ + NULL, /* Connect */ + NULL /* Close */ + }; + +/* + * Implementation of the mandatory version entry point + * + * @return version string of the module + */ +char * +version() +{ + return version_str; +} + +/* + * The module initialisation routine, called when the module + * is first loaded. + */ +void +ModuleInit() +{ + fprintf(stderr, "Initial MySQL Client Protcol module.\n"); +} + +/* + * The module entry point routine. It is this routine that + * must populate the structure that is referred to as the + * "module object", this is a structure with the set of + * external entry points for this module. + * + * @return The module object + */ +GWPROTOCOL * +GetModuleObject() +{ + return &MyObject; +}