Commiting these files

This commit is contained in:
Massimiliano Pinto 2013-06-14 14:27:43 +02:00
commit 6690320542
8 changed files with 301 additions and 4 deletions

27
Makefile Normal file
View File

@ -0,0 +1,27 @@
# 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
# 14/06/13 Mark Riddoch Initial implementation
all:
(cd core; make)
(cd modules/routing; make)
clean:
(cd core; make clean)
(cd modules/routing; make clean)

View File

@ -179,6 +179,8 @@ int main(int argc, char **argv) {
fprintf(stderr, "(C) SkySQL Ab 2013\n");
load_module("testroute", "Router");
if (sigfillset(&sigset) != 0) {
fprintf(stderr, "sigfillset() error %s\n", strerror(errno));
return 1;

View File

@ -24,6 +24,9 @@
*
* Date Who Description
* 13/06/13 Mark Riddoch Initial implementation
* 14/06/13 Mark Riddoch Updated to add call to ModuleInit if one is defined
* in the loaded module.
* Also updated to call fixed GetModuleObject
*
*/
#include <sys/param.h>
@ -51,7 +54,7 @@ static void unregister_module(const char *module);
* @return The module specific entry point structure or NULL
*/
void *
load_module(const char *module, const char *type, const char *entry)
load_module(const char *module, const char *type)
{
char *home, *version;
char fname[MAXPATHLEN];
@ -67,7 +70,7 @@ MODULES *mod;
*
* Search of the shared object.
*/
sprintf(fname, "lib%s.so", module);
sprintf(fname, "./lib%s.so", module);
if (access(fname, F_OK) == -1)
{
if ((home = getenv("GATEWAY_HOME")) == NULL)
@ -94,7 +97,16 @@ MODULES *mod;
ver = sym;
version = ver();
if ((sym = dlsym(dlhandle, entry)) == NULL)
/*
* If the module has a ModuleInit function cal it now.
*/
if ((sym = dlsym(dlhandle, "ModuleInit")) != NULL)
{
void (*ModuleInit)() = sym;
ModuleInit();
}
if ((sym = dlsym(dlhandle, "GetModuleObject")) == NULL)
{
fprintf(stderr, "Expected entry point interface missing from module: %s, %s\n", module, dlerror());
dlclose(dlhandle);

View File

@ -38,7 +38,7 @@ typedef struct modules {
*next; /* Next module in the linked list */
} MODULES;
extern void *load_module(const char *module, const char *type, const char *entry);
extern void *load_module(const char *module, const char *type);
extern void unload_module(const char *module);
extern void printModules();
#endif

59
include/router.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef _ROUTER_H
#define _ROUTER_H
/*
* 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
*/
/*
* The query router interface mechanisms
*
* Revision History
*
* Date Who Description
* 14/06/13 Mark Riddoch Initial implementation
*
*/
#include <service.h>
#include <session.h>
#include <buffer.h>
/*
* the ROUTER handle points to module specific data, so the best we can do
* is to make it a void * externally.
*/
typedef void *ROUTER;
/*
* The "module object" structure for a query router module
*
* The entry points are:
* createInstance Called by the service to create a new
* instance of the query router
* newSession Called to create a new user session
* within the query router
* closeSession Called when a session is closed
* routeQuery Called on each query that requires
* routing
*/
typedef struct {
ROUTER *(*createInstance)(SERVICE *service);
void *(*newSession)(ROUTER *instance, SESSION *session);
void (*closeSession)(ROUTER *instance, SESSION *session);
int (*routeQuery)(ROUTER *instance, SESSION *session, GWBUF *queue);
} ROUTER_OBJECT;
#endif

52
include/service.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef _SERVICE_H
#define _SERVICE_H
/*
* 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
*/
/*
* The service level definitions within the gateway
*
* Revision History
*
* Date Who Description
* 14/06/13 Mark Riddoch Initial implementation
*
*/
struct server;
struct router;
typedef struct servprotocol {
char *protocol; /* Protocol name */
int port; /* Port to listen on */
char *routerModule; /* Name of router module to use */
struct router *router;
struct servprotocol
*next; /* Next service protocol */
} SERV_PROTOCOL;
typedef struct service {
char *name; /* The service name */
SERV_PROTOCOL *ports; /* Linked list of ports and protocols
* that this service will listen on.
*/
struct server *servers; /* Linked list of databases associated
* with this service
*/
} SERVICE;
#endif

38
modules/routing/Makefile Normal file
View File

@ -0,0 +1,38 @@
# 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 routing module development
CC=cc
CFLAGS=-c -fPIC -I/usr/include -I../include -I../../include
LDFLAGS=-shared
SRCS=testroute.c
OBJ=$(SRCS:.c=.o)
LIBS=-lssl
libtestroute.so: $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f $(OBJ) libtestroute.so
tags:
ctags $(SRCS) $(HDRS)

107
modules/routing/testroute.c Normal file
View File

@ -0,0 +1,107 @@
/*
* 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 <stdio.h>
#include <router.h>
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 ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery };
/*
* 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 test router 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
*/
ROUTER_OBJECT *
GetModuleObject()
{
fprintf(stderr, "Returing test router module object.\n");
return &MyObject;
}
/*
* Create an instance of the router for a particular service
* within the gateway.
*
* @param service The service this router is being create for
*
* @return The instance data for this new instance
*/
static ROUTER *
createInstance(SERVICE *service)
{
}
/*
* Associate a new session with this instance of the router.
*
* @param instance The router instance data
* @param session The session itself
* @return Session specific data for this session
*/
static void *
newSession(ROUTER *instance, SESSION *session)
{
}
/*
* Close a session with the router, this is the mechanism
* by which a router may cleanup data structure etc.
*
* @param instance The router instance data
* @param session The session being closed
*/
static void
closeSession(ROUTER *instance, SESSION *session)
{
}
static int
routeQuery(ROUTER *instance, SESSION *session, GWBUF *queue)
{
}