moving files to /server to make merge possible
This commit is contained in:
40
server/include/adminusers.h
Normal file
40
server/include/adminusers.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef _ADMINUSERS_H
|
||||
#define _ADMINUSERS_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file adminusers.h - Administration users support routines
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 18/07/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
#define ADMIN_SALT "MS"
|
||||
|
||||
extern int admin_verify(char *, char *);
|
||||
extern char *admin_add_user(char *, char *);
|
||||
extern int admin_test_user(char *);
|
||||
extern void dcb_PrintAdminUsers(DCB *dcb);
|
||||
|
||||
|
||||
#endif
|
||||
34
server/include/atomic.h
Normal file
34
server/include/atomic.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef _ATOMIC_H
|
||||
#define _ATOMIC_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file atomic.h The atomic operations used within the gateway
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 10/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
extern int atomic_add(int *variable, int value);
|
||||
#endif
|
||||
98
server/include/buffer.h
Normal file
98
server/include/buffer.h
Normal file
@ -0,0 +1,98 @@
|
||||
#ifndef _BUFFER_H
|
||||
#define _BUFFER_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file buffer.h Definitions relating the gateway buffer manipulation facilities.
|
||||
*
|
||||
* These are used to store all data coming in form or going out to the client and the
|
||||
* backend structures.
|
||||
*
|
||||
* The buffers are designed to be used in linked lists and such that they may be passed
|
||||
* from one side of the gateway to another without the need to copy data. It may be the case
|
||||
* that not all of the data in the buffer is valid, to this end a start and end pointer are
|
||||
* included that point to the first valid byte in the buffer and the first byte after the
|
||||
* last valid byte. This allows data to be consumed from either end of the buffer whilst
|
||||
* still allowing for the copy free semantics of the buffering system.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 10/06/2013 Mark Riddoch Initial implementation
|
||||
* 11/07/2013 Mark Riddoch Addition of reference count in the gwbuf
|
||||
* 16/07/2013 Massimiliano Pinto Added command type for the queue
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
/**
|
||||
* A structure to encapsualte the data in a form that the data itself can be
|
||||
* shared between multiple GWBUF's without the need to make multiple copies
|
||||
* but still maintain separate data pointers.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned char *data; /**< Physical memory that was allocated */
|
||||
int refcount; /**< Reference count on the buffer */
|
||||
} SHARED_BUF;
|
||||
|
||||
/**
|
||||
* The buffer structure used by the descriptor control blocks.
|
||||
*
|
||||
* Linked lists of buffers are created as data is read from a descriptor
|
||||
* or written to a descriptor. The use of linked lists of buffers with
|
||||
* flexible data pointers is designed to minimise the need for data to
|
||||
* be copied within the gateway.
|
||||
*/
|
||||
typedef struct gwbuf {
|
||||
struct gwbuf *next; /**< Next buffer in a linked chain of buffers */
|
||||
void *start; /**< Start of the valid data */
|
||||
void *end; /**< First byte after the valid data */
|
||||
SHARED_BUF *sbuf; /**< The shared buffer with the real data */
|
||||
int command; /**< The command type for the queue */
|
||||
} GWBUF;
|
||||
|
||||
/*
|
||||
* Macros to access the data in the buffers
|
||||
*/
|
||||
#define GWBUF_DATA(b) ((b)->start) /**< First valid, uncomsumed
|
||||
* byte in the buffer
|
||||
*/
|
||||
#define GWBUF_LENGTH(b) ((b)->end - (b)->start) /**< Number of bytes in the
|
||||
* individual buffer
|
||||
*/
|
||||
#define GWBUF_EMPTY(b) ((b)->start == (b)->end) /**< True if all bytes in the
|
||||
* buffer have been consumed
|
||||
*/
|
||||
#define GWBUF_CONSUME(b, bytes) (b)->start += bytes /**< Consume a number of bytes
|
||||
* in the buffer
|
||||
*/
|
||||
|
||||
/*
|
||||
* Function prototypes for the API to maniplate the buffers
|
||||
*/
|
||||
extern GWBUF *gwbuf_alloc(unsigned int size);
|
||||
extern void gwbuf_free(GWBUF *buf);
|
||||
extern GWBUF *gwbuf_clone(GWBUF *buf);
|
||||
extern GWBUF *gwbuf_append(GWBUF *head, GWBUF *tail);
|
||||
extern GWBUF *gwbuf_consume(GWBUF *head, unsigned int length);
|
||||
extern unsigned int gwbuf_length(GWBUF *head);
|
||||
|
||||
|
||||
#endif
|
||||
63
server/include/config.h
Normal file
63
server/include/config.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file config.h The configuration handling elements
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 21/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
/**
|
||||
* The config parameter
|
||||
*/
|
||||
typedef struct config_parameter {
|
||||
char *name; /**< The name of the parameter */
|
||||
char *value; /**< The value of the parameter */
|
||||
struct config_parameter *next; /**< Next pointer in the linked list */
|
||||
} CONFIG_PARAMETER;
|
||||
|
||||
/**
|
||||
* The config context structure, used to build the configuration
|
||||
* data during the parse process
|
||||
*/
|
||||
typedef struct config_context {
|
||||
char *object; /**< The name of the object being configured */
|
||||
CONFIG_PARAMETER *parameters; /**< The list of parameter values */
|
||||
void *element; /**< The element created from the data */
|
||||
struct config_context *next; /**< Next pointer in the linked list */
|
||||
} CONFIG_CONTEXT;
|
||||
|
||||
/**
|
||||
* The gateway global configuration data
|
||||
*/
|
||||
typedef struct {
|
||||
int n_threads; /**< Number of polling threads */
|
||||
} GATEWAY_CONF;
|
||||
|
||||
extern int config_load(char *);
|
||||
extern int config_reload();
|
||||
extern int config_threadcount();
|
||||
#endif
|
||||
36
server/include/dbusers.h
Normal file
36
server/include/dbusers.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef _DBUSERS_H
|
||||
#define _DBUSERS_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
|
||||
*/
|
||||
#include <service.h>
|
||||
|
||||
/**
|
||||
* @file dbusers.h Extarct user information form the backend database
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 25/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
extern int load_mysql_users(SERVICE *service);
|
||||
extern int reload_mysql_users(SERVICE *service);
|
||||
#endif
|
||||
189
server/include/dcb.h
Normal file
189
server/include/dcb.h
Normal file
@ -0,0 +1,189 @@
|
||||
#ifndef _DCB_H
|
||||
#define _DCB_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
|
||||
*/
|
||||
#include <spinlock.h>
|
||||
#include <buffer.h>
|
||||
#include <gwbitmask.h>
|
||||
|
||||
struct session;
|
||||
struct server;
|
||||
struct service;
|
||||
|
||||
/**
|
||||
* @file dcb.h The Descriptor Control Block
|
||||
*
|
||||
* The function pointer table used by descriptors to call relevant functions
|
||||
* within the protocol specific code.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 01/06/2013 Mark Riddoch Initial implementation
|
||||
* 11/06/2013 Mark Riddoch Updated GWPROTOCOL structure with new
|
||||
* entry points
|
||||
* 18/06/2013 Mark Riddoch Addition of the listener entry point
|
||||
* 02/07/2013 Massimiliano Pinto Addition of delayqlock, delayq and authlock
|
||||
* for handling backend asynchronous protocol connection
|
||||
* and a generic lock for backend authentication
|
||||
* 12/07/2013 Massimiliano Pinto Added auth entry point
|
||||
* 15/07/2013 Massimiliano Pinto Added session entry point
|
||||
* 16/07/2013 Massimiliano Pinto Added command type for dcb
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
struct dcb;
|
||||
|
||||
/**
|
||||
* @verbatim
|
||||
* The operations that can be performed on the descriptor
|
||||
*
|
||||
* read EPOLLIN handler for the socket
|
||||
* write Gateway data write entry point
|
||||
* write_ready EPOLLOUT handler for the socket, indicates
|
||||
* that the socket is ready to send more data
|
||||
* error EPOLLERR handler for the socket
|
||||
* hangup EPOLLHUP handler for the socket
|
||||
* accept Accept handler for listener socket only
|
||||
* connect Create a connection to the specified server
|
||||
* for the session pased in
|
||||
* close Gateway close entry point for the socket
|
||||
* listen Create a listener for the protocol
|
||||
* auth Authentication entry point
|
||||
* session Session handling entry point
|
||||
* @endverbatim
|
||||
*
|
||||
* This forms the "module object" for protocol modules within the gateway.
|
||||
*
|
||||
* @see load_module
|
||||
*/
|
||||
typedef struct gw_protocol {
|
||||
int (*read)(struct dcb *);
|
||||
int (*write)(struct dcb *, GWBUF *);
|
||||
int (*write_ready)(struct dcb *);
|
||||
int (*error)(struct dcb *);
|
||||
int (*hangup)(struct dcb *);
|
||||
int (*accept)(struct dcb *);
|
||||
int (*connect)(struct dcb *, struct server *, struct session *);
|
||||
int (*close)(struct dcb *);
|
||||
int (*listen)(struct dcb *, char *);
|
||||
int (*auth)(struct dcb *, struct server *, struct session *, GWBUF *);
|
||||
int (*session)(struct dcb *, void *);
|
||||
} GWPROTOCOL;
|
||||
|
||||
/**
|
||||
* The statitics gathered on a descriptor control block
|
||||
*/
|
||||
typedef struct dcbstats {
|
||||
int n_reads; /**< Number of reads on this descriptor */
|
||||
int n_writes; /**< Number of writes on this descriptor */
|
||||
int n_accepts; /**< Number of accepts on this descriptor */
|
||||
int n_buffered; /**< Number of buffered writes */
|
||||
} DCBSTATS;
|
||||
|
||||
/**
|
||||
* The data structure that is embedded witin a DCB and manages the complex memory
|
||||
* management issues of a DCB.
|
||||
*
|
||||
* The DCB structures are used as the user data within the polling loop. This means that
|
||||
* polling threads may aschronously wake up and access these structures. It is not possible
|
||||
* to simple remove the DCB from the epoll system and then free the data, as every thread
|
||||
* that is currently running an epoll call must wake up and re-issue the epoll_wait system
|
||||
* call, the is the only way we can be sure that no polling thread is pending a wakeup or
|
||||
* processing an event that will access the DCB.
|
||||
*
|
||||
* We solve this issue by making the dcb_free routine merely mark a DCB as a zombie and
|
||||
* place it on a special zombie list. Before placing the DCB on the zombie list we create
|
||||
* a bitmask with a bit set in it for each active polling thread. Each thread will call
|
||||
* a routine to process the zombie list at the end of the polling loop. This routine
|
||||
* will clear the bit value that corresponds to the calling thread. Once the bitmask
|
||||
* is completely cleared the DCB can finally be freed and removed from the zombie list.
|
||||
*/
|
||||
typedef struct {
|
||||
GWBITMASK bitmask; /**< The bitmask of threads */
|
||||
struct dcb *next; /**< Next pointer for the zombie list */
|
||||
} DCBMM;
|
||||
|
||||
/**
|
||||
* Descriptor Control Block
|
||||
*
|
||||
* A wrapper for a network descriptor within the gateway, it contains all the
|
||||
* state information necessary to allow for the implementation of the asynchronous
|
||||
* operation of the potocol and gateway functions. It also provides links to the service
|
||||
* and session data that is required to route the information within the gateway.
|
||||
*
|
||||
* It is important to hold the state information here such that any thread within the
|
||||
* gateway may be selected to execute the required actions when a network event occurs.
|
||||
*/
|
||||
typedef struct dcb {
|
||||
int fd; /**< The descriptor */
|
||||
int state; /**< Current descriptor state */
|
||||
char *remote; /**< Address of remote end */
|
||||
void *protocol; /**< The protocol specific state */
|
||||
struct session *session; /**< The owning session */
|
||||
GWPROTOCOL func; /**< The functions for this descrioptor */
|
||||
|
||||
SPINLOCK writeqlock; /**< Write Queue spinlock */
|
||||
GWBUF *writeq; /**< Write Data Queue */
|
||||
SPINLOCK delayqlock; /**< Delay Backend Write Queue spinlock */
|
||||
GWBUF *delayq; /**< Delay Backend Write Data Queue */
|
||||
SPINLOCK authlock; /**< Generic Authorization spinlock */
|
||||
|
||||
DCBSTATS stats; /**< DCB related statistics */
|
||||
|
||||
struct dcb *next; /**< Next DCB in the chain of allocated DCB's */
|
||||
struct service *service; /**< The related service */
|
||||
void *data; /**< Specific client data */
|
||||
DCBMM memdata; /**< The data related to DCB memory management */
|
||||
int command; /**< Specific client command type */
|
||||
} DCB;
|
||||
|
||||
/* DCB states */
|
||||
#define DCB_STATE_ALLOC 0 /**< Memory allocated but not populated */
|
||||
#define DCB_STATE_IDLE 1 /**< Not yet in the poll mask */
|
||||
#define DCB_STATE_POLLING 2 /**< Waiting in the poll loop */
|
||||
#define DCB_STATE_PROCESSING 4 /**< Processing an event */
|
||||
#define DCB_STATE_LISTENING 5 /**< The DCB is for a listening socket */
|
||||
#define DCB_STATE_DISCONNECTED 6 /**< The socket is now closed */
|
||||
#define DCB_STATE_FREED 7 /**< Memory freed */
|
||||
#define DCB_STATE_ZOMBIE 8 /**< DCB is no longer active, waiting to free it */
|
||||
|
||||
/* A few useful macros */
|
||||
#define DCB_SESSION(x) (x)->session
|
||||
#define DCB_PROTOCOL(x, type) (type *)((x)->protocol)
|
||||
#define DCB_ISZOMBIE(x) ((x)->state == DCB_STATE_ZOMBIE)
|
||||
|
||||
extern DCB *dcb_alloc(); /* Allocate a DCB */
|
||||
extern void dcb_free(DCB *); /* Free a DCB */
|
||||
extern DCB *dcb_connect(struct server *, struct session *, const char *); /* prepare Backend connection */
|
||||
extern int dcb_read(DCB *, GWBUF **); /* Generic read routine */
|
||||
extern int dcb_write(DCB *, GWBUF *); /* Generic write routine */
|
||||
extern int dcb_drain_writeq(DCB *); /* Generic write routine */
|
||||
extern void dcb_close(DCB *); /* Generic close functionality */
|
||||
extern void dcb_process_zombies(int); /* Process Zombies */
|
||||
extern void printAllDCBs(); /* Debug to print all DCB in the system */
|
||||
extern void printDCB(DCB *); /* Debug print routine */
|
||||
extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
|
||||
extern void dprintDCB(DCB *, DCB *); /* Debug to print a DCB in the system */
|
||||
extern const char *gw_dcb_state2string(int); /* DCB state to string */
|
||||
extern void dcb_printf(DCB *, const char *, ...); /* DCB version of printf */
|
||||
extern int dcb_isclient(DCB *); /* the DCB is the client of the session */
|
||||
|
||||
#endif
|
||||
126
server/include/gateway_mysql.h
Normal file
126
server/include/gateway_mysql.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* MYSQL mysql protocol header file
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 10/06/13 Massimiliano Pinto Initial implementation
|
||||
*
|
||||
*/
|
||||
#include <dcb.h>
|
||||
|
||||
/* Protocol packing macros. */
|
||||
#define gw_mysql_set_byte2(__buffer, __int) do { \
|
||||
(__buffer)[0]= (uint8_t)((__int) & 0xFF); \
|
||||
(__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); } while (0)
|
||||
#define gw_mysql_set_byte3(__buffer, __int) do { \
|
||||
(__buffer)[0]= (uint8_t)((__int) & 0xFF); \
|
||||
(__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); \
|
||||
(__buffer)[2]= (uint8_t)(((__int) >> 16) & 0xFF); } while (0)
|
||||
#define gw_mysql_set_byte4(__buffer, __int) do { \
|
||||
(__buffer)[0]= (uint8_t)((__int) & 0xFF); \
|
||||
(__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); \
|
||||
(__buffer)[2]= (uint8_t)(((__int) >> 16) & 0xFF); \
|
||||
(__buffer)[3]= (uint8_t)(((__int) >> 24) & 0xFF); } while (0)
|
||||
|
||||
|
||||
/* Protocol unpacking macros. */
|
||||
#define gw_mysql_get_byte2(__buffer) \
|
||||
(uint16_t)((__buffer)[0] | \
|
||||
((__buffer)[1] << 8))
|
||||
#define gw_mysql_get_byte3(__buffer) \
|
||||
(uint32_t)((__buffer)[0] | \
|
||||
((__buffer)[1] << 8) | \
|
||||
((__buffer)[2] << 16))
|
||||
#define gw_mysql_get_byte4(__buffer) \
|
||||
(uint32_t)((__buffer)[0] | \
|
||||
((__buffer)[1] << 8) | \
|
||||
((__buffer)[2] << 16) | \
|
||||
((__buffer)[3] << 24))
|
||||
#define gw_mysql_get_byte8(__buffer) \
|
||||
((uint64_t)(__buffer)[0] | \
|
||||
((uint64_t)(__buffer)[1] << 8) | \
|
||||
((uint64_t)(__buffer)[2] << 16) | \
|
||||
((uint64_t)(__buffer)[3] << 24) | \
|
||||
((uint64_t)(__buffer)[4] << 32) | \
|
||||
((uint64_t)(__buffer)[5] << 40) | \
|
||||
((uint64_t)(__buffer)[6] << 48) | \
|
||||
((uint64_t)(__buffer)[7] << 56))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GW_MYSQL_CAPABILITIES_NONE= 0,
|
||||
GW_MYSQL_CAPABILITIES_LONG_PASSWORD= (1 << 0),
|
||||
GW_MYSQL_CAPABILITIES_FOUND_ROWS= (1 << 1),
|
||||
GW_MYSQL_CAPABILITIES_LONG_FLAG= (1 << 2),
|
||||
GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB= (1 << 3),
|
||||
GW_MYSQL_CAPABILITIES_NO_SCHEMA= (1 << 4),
|
||||
GW_MYSQL_CAPABILITIES_COMPRESS= (1 << 5),
|
||||
GW_MYSQL_CAPABILITIES_ODBC= (1 << 6),
|
||||
GW_MYSQL_CAPABILITIES_LOCAL_FILES= (1 << 7),
|
||||
GW_MYSQL_CAPABILITIES_IGNORE_SPACE= (1 << 8),
|
||||
GW_MYSQL_CAPABILITIES_PROTOCOL_41= (1 << 9),
|
||||
GW_MYSQL_CAPABILITIES_INTERACTIVE= (1 << 10),
|
||||
GW_MYSQL_CAPABILITIES_SSL= (1 << 11),
|
||||
GW_MYSQL_CAPABILITIES_IGNORE_SIGPIPE= (1 << 12),
|
||||
GW_MYSQL_CAPABILITIES_TRANSACTIONS= (1 << 13),
|
||||
GW_MYSQL_CAPABILITIES_RESERVED= (1 << 14),
|
||||
GW_MYSQL_CAPABILITIES_SECURE_CONNECTION= (1 << 15),
|
||||
GW_MYSQL_CAPABILITIES_MULTI_STATEMENTS= (1 << 16),
|
||||
GW_MYSQL_CAPABILITIES_MULTI_RESULTS= (1 << 17),
|
||||
GW_MYSQL_CAPABILITIES_PS_MULTI_RESULTS= (1 << 18),
|
||||
GW_MYSQL_CAPABILITIES_PLUGIN_AUTH= (1 << 19),
|
||||
GW_MYSQL_CAPABILITIES_SSL_VERIFY_SERVER_CERT= (1 << 30),
|
||||
GW_MYSQL_CAPABILITIES_REMEMBER_OPTIONS= (1 << 31),
|
||||
GW_MYSQL_CAPABILITIES_CLIENT= (GW_MYSQL_CAPABILITIES_LONG_PASSWORD |
|
||||
GW_MYSQL_CAPABILITIES_FOUND_ROWS |
|
||||
GW_MYSQL_CAPABILITIES_LONG_FLAG |
|
||||
GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB |
|
||||
GW_MYSQL_CAPABILITIES_LOCAL_FILES |
|
||||
GW_MYSQL_CAPABILITIES_PLUGIN_AUTH |
|
||||
GW_MYSQL_CAPABILITIES_TRANSACTIONS |
|
||||
GW_MYSQL_CAPABILITIES_PROTOCOL_41 |
|
||||
GW_MYSQL_CAPABILITIES_MULTI_STATEMENTS |
|
||||
GW_MYSQL_CAPABILITIES_MULTI_RESULTS |
|
||||
GW_MYSQL_CAPABILITIES_PS_MULTI_RESULTS |
|
||||
GW_MYSQL_CAPABILITIES_SECURE_CONNECTION),
|
||||
GW_MYSQL_CAPABILITIES_CLIENT_COMPRESS= (GW_MYSQL_CAPABILITIES_LONG_PASSWORD |
|
||||
GW_MYSQL_CAPABILITIES_FOUND_ROWS |
|
||||
GW_MYSQL_CAPABILITIES_LONG_FLAG |
|
||||
GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB |
|
||||
GW_MYSQL_CAPABILITIES_LOCAL_FILES |
|
||||
GW_MYSQL_CAPABILITIES_PLUGIN_AUTH |
|
||||
GW_MYSQL_CAPABILITIES_TRANSACTIONS |
|
||||
GW_MYSQL_CAPABILITIES_PROTOCOL_41 |
|
||||
GW_MYSQL_CAPABILITIES_MULTI_STATEMENTS |
|
||||
GW_MYSQL_CAPABILITIES_MULTI_RESULTS |
|
||||
GW_MYSQL_CAPABILITIES_PS_MULTI_RESULTS |
|
||||
GW_MYSQL_CAPABILITIES_COMPRESS
|
||||
),
|
||||
} gw_mysql_capabilities_t;
|
||||
|
||||
|
||||
#define SMALL_CHUNK 1024
|
||||
#define MAX_CHUNK SMALL_CHUNK * 8 * 4
|
||||
#define ToHex(Y) (Y>='0'&&Y<='9'?Y-'0':Y-'A'+10)
|
||||
|
||||
extern int mysql_send_ok(DCB *, int, int, const char *);
|
||||
extern int MySQLSendHandshake(DCB *);
|
||||
67
server/include/gw.h
Normal file
67
server/include/gw.h
Normal file
@ -0,0 +1,67 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
|
||||
// network buffer is 32K
|
||||
#define MAX_BUFFER_SIZE 32768
|
||||
// socket send buffer for backend
|
||||
#define GW_BACKEND_SO_SNDBUF 1024
|
||||
|
||||
#define GW_NOINTR_CALL(A) do { errno = 0; A; } while (errno == EINTR)
|
||||
#define GW_VERSION "0.1.0"
|
||||
#define GW_MYSQL_VERSION "5.5.22-SKYSQL-" GW_VERSION
|
||||
#define GW_MYSQL_LOOP_TIMEOUT 300000000
|
||||
#define GW_MYSQL_READ 0
|
||||
#define GW_MYSQL_WRITE 1
|
||||
|
||||
#define GW_MYSQL_PROTOCOL_VERSION 10 // version is 10
|
||||
#define GW_MYSQL_HANDSHAKE_FILLER 0x00
|
||||
#define GW_MYSQL_SERVER_CAPABILITIES_BYTE1 0xff
|
||||
#define GW_MYSQL_SERVER_CAPABILITIES_BYTE2 0xf7
|
||||
#define GW_MYSQL_SERVER_LANGUAGE 0x08
|
||||
#define GW_MYSQL_MAX_PACKET_LEN 0xffffffL;
|
||||
#define GW_MYSQL_SCRAMBLE_SIZE 20
|
||||
|
||||
// debug for mysql_* functions
|
||||
#define MYSQL_CONN_DEBUG
|
||||
#undef MYSQL_CONN_DEBUG
|
||||
|
||||
#include "gateway_mysql.h"
|
||||
#include "mysql_protocol.h"
|
||||
#include "dcb.h"
|
||||
|
||||
extern void gw_daemonize(void);
|
||||
extern int do_read_dcb(DCB *dcb);
|
||||
extern int handle_event_errors(DCB *dcb);
|
||||
extern int handle_event_errors_backend(DCB *dcb);
|
||||
extern void MySQLListener(int epfd, char *config_bind);
|
||||
extern int MySQLAccept(DCB *listener);
|
||||
extern int gw_mysql_do_authentication(DCB *dcb, GWBUF *);
|
||||
extern void gw_mysql_close(MySQLProtocol **ptr);
|
||||
extern char *gw_strend(register const char *s);
|
||||
extern int do_read_dcb(DCB *dcb);
|
||||
extern int do_read_10(DCB *dcb, uint8_t *buffer);
|
||||
extern MySQLProtocol * gw_mysql_init(MySQLProtocol *ptr);
|
||||
extern int MySQLWrite(DCB *dcb, GWBUF *queue);
|
||||
extern int gw_write_backend_event(DCB *dcb);
|
||||
extern int gw_read_backend_event(DCB *dcb);
|
||||
extern int setnonblocking(int fd);
|
||||
53
server/include/gwbitmask.h
Normal file
53
server/include/gwbitmask.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef _GWBITMASK_H
|
||||
#define _GWBITMASK_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
|
||||
*/
|
||||
#include <spinlock.h>
|
||||
|
||||
/**
|
||||
* @file gwbitmask.h An implementation of an arbitarly long bitmask
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 28/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#define BIT_LENGTH_INITIAL 32 /**< Initial number of bits in the bitmask */
|
||||
#define BIT_LENGTH_INC 32 /**< Number of bits to add on each increment */
|
||||
|
||||
/**
|
||||
* The bitmask structure used to store an arbitary large bitmask
|
||||
*/
|
||||
typedef struct {
|
||||
SPINLOCK lock; /**< Lock to protect the bitmask */
|
||||
unsigned char *bits; /**< Pointer to the bits themselves */
|
||||
unsigned int length; /**< The number of bits in the bitmask */
|
||||
} GWBITMASK;
|
||||
|
||||
extern void bitmask_init(GWBITMASK *);
|
||||
extern void bitmask_free(GWBITMASK *);
|
||||
extern void bitmask_set(GWBITMASK *, int);
|
||||
extern void bitmask_clear(GWBITMASK *, int);
|
||||
extern int bitmask_isset(GWBITMASK *, int);
|
||||
extern int bitmask_isallclear(GWBITMASK *);
|
||||
extern void bitmask_copy(GWBITMASK *, GWBITMASK *);
|
||||
#endif
|
||||
100
server/include/hashtable.h
Normal file
100
server/include/hashtable.h
Normal file
@ -0,0 +1,100 @@
|
||||
#ifndef _HASTABLE_H
|
||||
#define _HASTABLE_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hashtable.h A general purpose hashtable mechanism for use within the
|
||||
* gateway
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 23/06/13 Mark Riddoch Initial implementation
|
||||
* 23/07/13 Mark Riddoch Addition of iterator mechanism
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
#include <spinlock.h>
|
||||
#include <atomic.h>
|
||||
#include <dcb.h>
|
||||
|
||||
/**
|
||||
* The entries within a hashtable.
|
||||
*
|
||||
* A NULL value for key indicates an empty entry.
|
||||
* The next pointer is the overflow chain for this hashentry.
|
||||
*/
|
||||
typedef struct hashentry {
|
||||
void *key; /**< The value of the key or NULL if empty entry */
|
||||
void *value; /**< The value associated with key */
|
||||
struct hashentry *next; /**< The overflow chain */
|
||||
} HASHENTRIES;
|
||||
|
||||
/**
|
||||
* HASHTABLE iterator - used to walk the hashtable in a thread safe
|
||||
* way
|
||||
*/
|
||||
typedef struct hashiterator {
|
||||
struct hashtable
|
||||
*table; /**< The hashtable the iterator refers to */
|
||||
int chain; /**< The current chain we are walking */
|
||||
int depth; /**< The current depth down the chain */
|
||||
} HASHITERATOR;
|
||||
|
||||
/**
|
||||
* The type definition for the memory allocation functions
|
||||
*/
|
||||
typedef void *(*HASHMEMORYFN)(void *);
|
||||
|
||||
/**
|
||||
* The general purpose hashtable struct.
|
||||
*/
|
||||
typedef struct hashtable {
|
||||
int hashsize; /**< The number of HASHENTRIES */
|
||||
HASHENTRIES **entries; /**< The entries themselves */
|
||||
int (*hashfn)(void *); /**< The hash function */
|
||||
int (*cmpfn)(void *, void *); /**< The key comparison function */
|
||||
HASHMEMORYFN copyfn; /**< Optional copy function */
|
||||
HASHMEMORYFN freefn; /**< Optional free function */
|
||||
SPINLOCK spin; /**< Internal spinlock for the hashtable */
|
||||
int n_readers; /**< Number of clients reading the table */
|
||||
int writelock; /**< The table is locked by a writer */
|
||||
} HASHTABLE;
|
||||
|
||||
extern HASHTABLE *hashtable_alloc(int, int (*hashfn)(), int (*cmpfn)());
|
||||
/**< Allocate a hashtable */
|
||||
extern void hashtable_memory_fns(HASHTABLE *, HASHMEMORYFN, HASHMEMORYFN);
|
||||
/**< Provide an interface to control key/value memory
|
||||
* manipulation
|
||||
*/
|
||||
extern void hashtable_free(HASHTABLE *); /**< Free a hashtable */
|
||||
extern int hashtable_add(HASHTABLE *, void *, void *); /**< Add an entry */
|
||||
extern int hashtable_delete(HASHTABLE *, void *);
|
||||
/**< Delete an entry table */
|
||||
extern void *hashtable_fetch(HASHTABLE *, void *);
|
||||
/**< Fetch the data for a given key */
|
||||
extern void hashtable_stats(HASHTABLE *); /**< Print statisitics */
|
||||
extern void dcb_hashtable_stats(DCB *, HASHTABLE *); /**< Print statisitics */
|
||||
extern HASHITERATOR *hashtable_iterator(HASHTABLE *);
|
||||
/**< Allocate an iterator on the hashtable */
|
||||
extern void *hashtable_next(HASHITERATOR *);
|
||||
/**< Return the key of the hash table iterator */
|
||||
extern void hashtable_iterator_free(HASHITERATOR *);
|
||||
#endif
|
||||
58
server/include/modules.h
Normal file
58
server/include/modules.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef _MODULES_H
|
||||
#define _MODULES_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
|
||||
*/
|
||||
#include <dcb.h>
|
||||
|
||||
/**
|
||||
* @file modules.h Utilities for loading modules
|
||||
*
|
||||
* The module interface used within the gateway
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 13/06/13 Mark Riddoch Initial implementation
|
||||
* 08/07/13 Mark Riddoch Addition of monitor modules
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
typedef struct modules {
|
||||
char *module; /**< The name of the module */
|
||||
char *type; /**< The module type */
|
||||
char *version; /**< Module version */
|
||||
void *handle; /**< The handle returned by dlopen */
|
||||
void *modobj; /**< The module "object" this is the set of entry points */
|
||||
struct modules
|
||||
*next; /**< Next module in the linked list */
|
||||
} MODULES;
|
||||
|
||||
/**
|
||||
* Module types
|
||||
*/
|
||||
#define MODULE_PROTOCOL "Protocol" /**< A protocol module type */
|
||||
#define MODULE_ROUTER "Router" /**< A router module type */
|
||||
#define MODULE_MONITOR "Monitor" /**< A database monitor module type */
|
||||
|
||||
|
||||
extern void *load_module(const char *module, const char *type);
|
||||
extern void unload_module(const char *module);
|
||||
extern void printModules();
|
||||
extern void dprintAllModules(DCB *);
|
||||
#endif
|
||||
88
server/include/monitor.h
Normal file
88
server/include/monitor.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef _MONITOR_H
|
||||
#define _MONITOR_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
|
||||
*/
|
||||
#include <server.h>
|
||||
#include <dcb.h>
|
||||
|
||||
/**
|
||||
* @file monitor.h The interface to the monitor module
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 07/07/13 Mark Riddoch Initial implementation
|
||||
* 25/07/13 Mark Riddoch Addition of diagnotics
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
/**
|
||||
* The "Module Object" for a monitor module.
|
||||
*
|
||||
* The monitor modules are designed to monitor the backend databases that the gateway
|
||||
* connects to and provide information regarding the status of the databases that
|
||||
* is used in the routing decisions.
|
||||
*
|
||||
* startMonitor is called to start the monitoring process, it is called on the main
|
||||
* thread of the gateway and is responsible for creating a thread for the monitor
|
||||
* itself to run on. This should use the entry points defined in the thread.h
|
||||
* header file rather than make direct calls to the operating system thrading libraries.
|
||||
* The return from startMonitor is a void * handle that will be passed to all other monitor
|
||||
* API calls.
|
||||
*
|
||||
* stopMonitor is responsible for shuting down and destroying a monitor, it is called
|
||||
* with the void * handle that was returned by startMonitor.
|
||||
*
|
||||
* registerServer is called to register a server that must be monitored with a running
|
||||
* monitor. this will be called with the handle returned from the startMonitor call and
|
||||
* the SERVER structure that the monitor must update and monitor. The SERVER structure
|
||||
* contains the information required to connect to the monitored server.
|
||||
*
|
||||
* unregisterServer is called to remove a server from the set of servers that need to be
|
||||
* monitored.
|
||||
*/
|
||||
typedef struct {
|
||||
void *(*startMonitor)(void *);
|
||||
void (*stopMonitor)(void *);
|
||||
void (*registerServer)(void *, SERVER *);
|
||||
void (*unregisterServer)(void *, SERVER *);
|
||||
void (*defaultUser)(void *, char *, char *);
|
||||
void (*diagnostics)(DCB *, void *);
|
||||
} MONITOR_OBJECT;
|
||||
|
||||
/**
|
||||
* Representation of the running monitor.
|
||||
*/
|
||||
typedef struct monitor {
|
||||
char *name; /**< The name of the monitor module */
|
||||
MONITOR_OBJECT *module; /**< The "monitor object" */
|
||||
void *handle; /**< Handle returned from startMonitor */
|
||||
struct monitor *next; /**< Next monitor in the linked list */
|
||||
} MONITOR;
|
||||
|
||||
extern MONITOR *monitor_alloc(char *, char *);
|
||||
extern void monitor_free(MONITOR *);
|
||||
extern void monitorAddServer(MONITOR *, SERVER *);
|
||||
extern void monitorAddUser(MONITOR *, char *, char *);
|
||||
extern void monitorStop(MONITOR *);
|
||||
extern void monitorStart(MONITOR *);
|
||||
extern void monitorStopAll();
|
||||
extern void monitorShowAll(DCB *);
|
||||
#endif
|
||||
71
server/include/mysql_protocol.h
Normal file
71
server/include/mysql_protocol.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef _MYSQL_PROTOCOL_H
|
||||
#define _MYSQL_PROTOCOL_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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 01-06-2013 Mark Riddoch Initial implementation
|
||||
* 14-06-2013 Massimiliano Pinto Added specific data
|
||||
* for MySQL session
|
||||
*/
|
||||
|
||||
#ifndef MYSQL_SCRAMBLE_LEN
|
||||
#define MYSQL_SCRAMBLE_LEN GW_MYSQL_SCRAMBLE_SIZE
|
||||
#endif
|
||||
|
||||
#define MYSQL_USER_MAXLEN 128
|
||||
#define MYSQL_DATABASE_MAXLEN 128
|
||||
|
||||
struct dcb;
|
||||
|
||||
/**
|
||||
* MySQL Protocol specific state data
|
||||
*/
|
||||
typedef struct {
|
||||
int fd; /**< The socket descriptor */
|
||||
struct dcb *descriptor; /**< The DCB of the socket we are running on */
|
||||
int state; /**< Current descriptor state */
|
||||
char scramble[MYSQL_SCRAMBLE_LEN]; /**< server scramble, created or received */
|
||||
uint32_t server_capabilities; /**< server capabilities, created or received */
|
||||
uint32_t client_capabilities; /**< client capabilities, created or received */
|
||||
unsigned long tid; /**< MySQL Thread ID, in handshake */
|
||||
} MySQLProtocol;
|
||||
|
||||
/**
|
||||
* MySQL session specific data
|
||||
*
|
||||
*/
|
||||
typedef struct mysql_session {
|
||||
uint8_t client_sha1[MYSQL_SCRAMBLE_LEN]; /**< SHA1(passowrd) */
|
||||
char user[MYSQL_USER_MAXLEN]; /**< username */
|
||||
char db[MYSQL_DATABASE_MAXLEN]; /**< database */
|
||||
} MYSQL_session;
|
||||
|
||||
/* MySQL Protocol States */
|
||||
#define MYSQL_ALLOC 0 /**< Allocate data */
|
||||
#define MYSQL_AUTH_SENT 1 /**< Authentication handshake has been sent */
|
||||
#define MYSQL_AUTH_RECV 2 /**< Received user, password, db and capabilities */
|
||||
#define MYSQL_AUTH_FAILED 3 /**< Auth failed, return error packet */
|
||||
#define MYSQL_IDLE 4 /**< Auth done. Protocol is idle, waiting for statements */
|
||||
#define MYSQL_ROUTING 5 /**< The received command has been routed to backend(s) */
|
||||
#define MYSQL_WAITING_RESULT 6 /**< Waiting for result set */
|
||||
|
||||
#endif
|
||||
44
server/include/poll.h
Normal file
44
server/include/poll.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef _POLL_H
|
||||
#define _POLL_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
|
||||
*/
|
||||
#include <dcb.h>
|
||||
#include <gwbitmask.h>
|
||||
|
||||
/**
|
||||
* @file poll.h The poll related functionality
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 19/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
#define MAX_EVENTS 1000
|
||||
#define EPOLL_TIMEOUT 1000 /**< The epoll timeout we use (milliseconds) */
|
||||
|
||||
extern void poll_init();
|
||||
extern int poll_add_dcb(DCB *);
|
||||
extern int poll_remove_dcb(DCB *);
|
||||
extern void poll_waitevents(void *);
|
||||
extern void poll_shutdown();
|
||||
extern GWBITMASK *poll_bitmask();
|
||||
extern void dprintPollStats(DCB *);
|
||||
#endif
|
||||
78
server/include/router.h
Normal file
78
server/include/router.h
Normal file
@ -0,0 +1,78 @@
|
||||
#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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file router.h - The query router interface mechanisms
|
||||
*
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 14/06/2013 Mark Riddoch Initial implementation
|
||||
* 26/06/2013 Mark Riddoch Addition of router options
|
||||
* and the diagnostic entry point
|
||||
* 15/07/2013 Massimiliano Pinto Added clientReply entry point
|
||||
* 16/07/2013 Massimiliano Pinto Added router commands values
|
||||
*
|
||||
*/
|
||||
#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;
|
||||
|
||||
|
||||
/**
|
||||
* @verbatim
|
||||
* 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
|
||||
* diagnostics Called to force the router to print
|
||||
* diagnostic output
|
||||
* clientReply Called to reply to client the data from one or all backends
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
* @see load_module
|
||||
*/
|
||||
typedef struct router_object {
|
||||
ROUTER *(*createInstance)(SERVICE *service, char **options);
|
||||
void *(*newSession)(ROUTER *instance, SESSION *session);
|
||||
void (*closeSession)(ROUTER *instance, void *router_session);
|
||||
int (*routeQuery)(ROUTER *instance, void *router_session, GWBUF *queue);
|
||||
void (*diagnostics)(ROUTER *instance, DCB *dcb);
|
||||
void (*clientReply)(ROUTER* instance, void* router_session, GWBUF* queue, DCB *backend_dcb);
|
||||
} ROUTER_OBJECT;
|
||||
|
||||
/* Router commands */
|
||||
#define ROUTER_DEFAULT 0 /**< Standard routing */
|
||||
#define ROUTER_CHANGE_SESSION 1 /**< Route a change session */
|
||||
|
||||
#endif
|
||||
57
server/include/secrets.h
Normal file
57
server/include/secrets.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef _SECRETS_H
|
||||
#define _SECRETS_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file secrets.h
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 23/06/2013 Massimiliano Pinto Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <openssl/aes.h>
|
||||
|
||||
#define MAXSCALE_KEYLEN 32
|
||||
#define MAXSCALE_IV_LEN 16
|
||||
|
||||
/**
|
||||
* The key structure held in the secrets file
|
||||
*/
|
||||
typedef struct maxkeys {
|
||||
unsigned char enckey[MAXSCALE_KEYLEN];
|
||||
unsigned char initvector[MAXSCALE_IV_LEN];
|
||||
} MAXKEYS;
|
||||
|
||||
extern int secrets_writeKeys(char *filename);
|
||||
extern char *decryptPassword(char *);
|
||||
extern char *encryptPassword(char *);
|
||||
#endif
|
||||
111
server/include/server.h
Normal file
111
server/include/server.h
Normal file
@ -0,0 +1,111 @@
|
||||
#ifndef _SERVER_H
|
||||
#define _SERVER_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
|
||||
*/
|
||||
#include <dcb.h>
|
||||
|
||||
/**
|
||||
* @file service.h
|
||||
*
|
||||
* The server level definitions within the gateway
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 14/06/13 Mark Riddoch Initial implementation
|
||||
* 21/06/13 Mark Riddoch Addition of server status flags
|
||||
* 22/07/13 Mark Riddoch Addition of JOINED status for Galera
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
/**
|
||||
* The server statistics structure
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int n_connections; /**< Number of connections */
|
||||
int n_current; /**< Current connections */
|
||||
} SERVER_STATS;
|
||||
|
||||
/**
|
||||
* The SERVER structure defines a backend server. Each server has a name
|
||||
* or IP address for the server, a port that the server listens on and
|
||||
* the name of a protocol module that is loaded to implement the protocol
|
||||
* between the gateway and the server.
|
||||
*/
|
||||
typedef struct server {
|
||||
char *name; /**< Server name/IP address*/
|
||||
unsigned short port; /**< Port to listen on */
|
||||
char *protocol; /**< Protocol module to use */
|
||||
unsigned int status; /**< Status flag bitmap for the server */
|
||||
char *monuser; /**< User name to use to monitor the db */
|
||||
char *monpw; /**< Password to use to monitor the db */
|
||||
SERVER_STATS stats; /**< The server statistics */
|
||||
struct server *next; /**< Next server */
|
||||
struct server *nextdb; /**< Next server in list attached to a service */
|
||||
} SERVER;
|
||||
|
||||
/**
|
||||
* Status bits in the server->status member.
|
||||
*
|
||||
* These are a bitmap of attributes that may be applied to a server
|
||||
*/
|
||||
#define SERVER_RUNNING 0x0001 /**<< The server is up and running */
|
||||
#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */
|
||||
#define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */
|
||||
#define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */
|
||||
|
||||
/**
|
||||
* Is the server running - the macro returns true if the server is marked as running
|
||||
* regardless of it's state as a master or slave
|
||||
*/
|
||||
#define SERVER_IS_RUNNING(server) ((server)->status & SERVER_RUNNING)
|
||||
/**
|
||||
* Is the server marked as down - the macro returns true if the server is beleived
|
||||
* to be inoperable.
|
||||
*/
|
||||
#define SERVER_IS_DOWN(server) (((server)->status & SERVER_RUNNING) == 0)
|
||||
/**
|
||||
* Is the server a master? The server must be both running and marked as master
|
||||
* in order for the macro to return true
|
||||
*/
|
||||
#define SERVER_IS_MASTER(server) \
|
||||
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE)) == (SERVER_RUNNING|SERVER_MASTER))
|
||||
/**
|
||||
* Is the server a slave? The server must be both running and marked as a slave
|
||||
* in order for the macro to return true
|
||||
*/
|
||||
#define SERVER_IS_SLAVE(server) \
|
||||
(((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE)) == (SERVER_RUNNING|SERVER_SLAVE))
|
||||
|
||||
|
||||
extern SERVER *server_alloc(char *, char *, unsigned short);
|
||||
extern int server_free(SERVER *);
|
||||
extern SERVER *server_find(char *, unsigned short);
|
||||
extern void printServer(SERVER *);
|
||||
extern void printAllServers();
|
||||
extern void dprintAllServers(DCB *);
|
||||
extern void dprintServer(DCB *, SERVER *);
|
||||
extern char *server_status(SERVER *);
|
||||
extern void server_set_status(SERVER *, int);
|
||||
extern void server_clear_status(SERVER *, int);
|
||||
extern void serverAddMonUser(SERVER *, char *, char *);
|
||||
extern void server_update(SERVER *, char *, char *, char *);
|
||||
#endif
|
||||
130
server/include/service.h
Normal file
130
server/include/service.h
Normal file
@ -0,0 +1,130 @@
|
||||
#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
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <spinlock.h>
|
||||
#include <dcb.h>
|
||||
#include <server.h>
|
||||
|
||||
/**
|
||||
* @file service.h
|
||||
*
|
||||
* The service level definitions within the gateway
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 14/06/13 Mark Riddoch Initial implementation
|
||||
* 18/06/13 Mark Riddoch Addition of statistics and function
|
||||
* prototypes
|
||||
* 23/06/13 Mark Riddoch Added service user and users
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
struct server;
|
||||
struct router;
|
||||
struct router_object;
|
||||
struct users;
|
||||
|
||||
/**
|
||||
* The servprotocol structure is used to link a service to the protocols that
|
||||
* are used to support that service. It defines the name of the protocol module
|
||||
* that should be loaded to support the client connection and the port that the
|
||||
* protocol should use to listen for incoming client connections.
|
||||
*/
|
||||
typedef struct servprotocol {
|
||||
char *protocol; /**< Protocol module to load */
|
||||
unsigned short port; /**< Port to listen on */
|
||||
DCB *listener; /**< The DCB for the listener */
|
||||
struct servprotocol
|
||||
*next; /**< Next service protocol */
|
||||
} SERV_PROTOCOL;
|
||||
|
||||
/**
|
||||
* The service statistics structure
|
||||
*/
|
||||
typedef struct {
|
||||
time_t started; /**< The time when the service was started */
|
||||
int n_sessions; /**< Number of sessions created on service since start */
|
||||
int n_current; /**< Current number of sessions */
|
||||
} SERVICE_STATS;
|
||||
|
||||
/**
|
||||
* The service user structure holds the information that is needed for this service to
|
||||
* allow the gateway to login to the backend database and extact information such as
|
||||
* the user table or other database status or configuration data.
|
||||
*/
|
||||
typedef struct {
|
||||
char *name; /**< The user name to use to extract information */
|
||||
char *authdata; /**< The authentication data requied */
|
||||
} SERVICE_USER;
|
||||
|
||||
/**
|
||||
* Defines a service within the gateway.
|
||||
*
|
||||
* A service is a combination of a set of backend servers, a routing mechanism
|
||||
* and a set of client side protocol/port pairs used to listen for new connections
|
||||
* to the service.
|
||||
*/
|
||||
typedef struct service {
|
||||
char *name; /**< The service name */
|
||||
int state; /**< The service state */
|
||||
SERV_PROTOCOL *ports; /**< Linked list of ports and protocols
|
||||
* that this service will listen on.
|
||||
*/
|
||||
char *routerModule; /**< Name of router module to use */
|
||||
char **routerOptions;/**< Router specific option strings */
|
||||
struct router_object
|
||||
*router; /**< The router we are using */
|
||||
void *router_instance;
|
||||
/**< The router instance for this service */
|
||||
struct server *databases; /**< The set of servers in the backend */
|
||||
SERVICE_USER credentials; /**< The cedentials of the service user */
|
||||
SPINLOCK spin; /**< The service spinlock */
|
||||
SERVICE_STATS stats; /**< The service statistics */
|
||||
struct users *users; /**< The user data for this service */
|
||||
struct service *next; /**< The next service in the linked list */
|
||||
} SERVICE;
|
||||
|
||||
#define SERVICE_STATE_ALLOC 1 /**< The service has been allocated */
|
||||
#define SERVICE_STATE_STARTED 2 /**< The service has been started */
|
||||
|
||||
extern SERVICE *service_alloc(char *, char *);
|
||||
extern int service_free(SERVICE *);
|
||||
extern SERVICE *service_find(char *);
|
||||
extern int serviceAddProtocol(SERVICE *, char *, unsigned short);
|
||||
extern int serviceHasProtocol(SERVICE *, char *, unsigned short);
|
||||
extern void serviceAddBackend(SERVICE *, SERVER *);
|
||||
extern int serviceHasBackend(SERVICE *, SERVER *);
|
||||
extern void serviceAddRouterOption(SERVICE *, char *);
|
||||
extern void serviceClearRouterOptions(SERVICE *);
|
||||
extern int serviceStart(SERVICE *);
|
||||
extern int serviceStartAll();
|
||||
extern void serviceStartProtocol(SERVICE *, char *, int);
|
||||
extern int serviceStop(SERVICE *);
|
||||
extern int serviceRestart(SERVICE *);
|
||||
extern int serviceSetUser(SERVICE *, char *, char *);
|
||||
extern int serviceGetUser(SERVICE *, char **, char **);
|
||||
extern void service_update(SERVICE *, char *, char *, char *);
|
||||
extern void printService(SERVICE *);
|
||||
extern void printAllServices();
|
||||
extern void dprintAllServices(DCB *);
|
||||
#endif
|
||||
79
server/include/session.h
Normal file
79
server/include/session.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef _SESSION_H
|
||||
#define _SESSION_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file session.h
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 01-06-2013 Mark Riddoch Initial implementation
|
||||
* 14-06-2013 Massimiliano Pinto Added void *data to session
|
||||
* for session specific data
|
||||
* 01-07-2013 Massimiliano Pinto Removed backends pointer
|
||||
from struct session
|
||||
* @endverbatim
|
||||
*/
|
||||
#include <time.h>
|
||||
|
||||
struct dcb;
|
||||
struct service;
|
||||
|
||||
/**
|
||||
* The session statistics structure
|
||||
*/
|
||||
typedef struct {
|
||||
time_t connect; /**< Time when the session was started */
|
||||
} SESSION_STATS;
|
||||
|
||||
/**
|
||||
* The session status block
|
||||
*
|
||||
* A session status block is created for each user (client) connection
|
||||
* to the database, it links the descriptors, routing implementation
|
||||
* and originating service together for the client session.
|
||||
*/
|
||||
typedef struct session {
|
||||
int state; /**< Current descriptor state */
|
||||
struct dcb *client; /**< The client connection */
|
||||
struct dcb *backends; /**< The set of backend servers */
|
||||
void *data; /**< The session data */
|
||||
void *router_session;/**< The router instance data */
|
||||
SESSION_STATS stats; /**< Session statistics */
|
||||
struct service *service; /**< The service this session is using */
|
||||
struct session *next; /**< Linked list of all sessions */
|
||||
} SESSION;
|
||||
|
||||
#define SESSION_STATE_ALLOC 0 /**< The session has been allocated */
|
||||
#define SESSION_STATE_READY 1 /**< The session is ready to route queries */
|
||||
#define SESSION_STATE_LISTENER 2 /**< The session is a running listener */
|
||||
#define SESSION_STATE_LISTENER_STOPPED 3 /**< The session listener is stopped */
|
||||
|
||||
#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client, type)
|
||||
|
||||
extern SESSION *session_alloc(struct service *, struct dcb *);
|
||||
extern void session_free(SESSION *);
|
||||
extern void printAllSessions();
|
||||
extern void printSession(SESSION *);
|
||||
extern void dprintAllSessions(struct dcb *);
|
||||
extern void dprintSession(struct dcb *, SESSION *);
|
||||
extern char *session_state(int);
|
||||
#endif
|
||||
59
server/include/spinlock.h
Normal file
59
server/include/spinlock.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef _SPINLOCK_H
|
||||
#define _SPINLOCK_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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file spinlock.h
|
||||
*
|
||||
* Spinlock implementation for ther gateway.
|
||||
*
|
||||
* Spinlocks are cheap locks that can be used to protect short code blocks, they are
|
||||
* generally wasteful as any blocked threads will spin, consuming CPU cycles, waiting
|
||||
* for the lock to be released. However they are useful in that they do not involve
|
||||
* system calls and are light weight when the expected wait time for a lock is low.
|
||||
*/
|
||||
#include <thread.h>
|
||||
|
||||
typedef struct spinlock {
|
||||
int lock;
|
||||
#if DEBUG
|
||||
int spins;
|
||||
int acquired;
|
||||
THREAD owner;
|
||||
#endif
|
||||
} SPINLOCK;
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1 == 1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (1 == 0)
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
#define SPINLOCK_INIT { 0, 0, 0, NULL }
|
||||
#else
|
||||
#define SPINLOCK_INIT { 0 }
|
||||
#endif
|
||||
|
||||
extern void spinlock_init(SPINLOCK *lock);
|
||||
extern void spinlock_acquire(SPINLOCK *lock);
|
||||
extern int spinlock_acquire_nowait(SPINLOCK *lock);
|
||||
extern void spinlock_release(SPINLOCK *lock);
|
||||
#endif
|
||||
38
server/include/thread.h
Normal file
38
server/include/thread.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef _THREAD_H
|
||||
#define _THREAD_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
|
||||
*/
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* @file thread.h The gateway threading interface
|
||||
*
|
||||
* An encapsulation of the threading used by the gateway. This is designed to
|
||||
* isolate the majority of the gateway code from th epthread library, enabling
|
||||
* the gateway to be ported to a different threading package with the minimum
|
||||
* of changes.
|
||||
*/
|
||||
|
||||
#define THREAD pthread_t
|
||||
#define THREAD_SHELF pthread_self
|
||||
|
||||
extern void *thread_start(void (*entry)(void *), void *arg);
|
||||
extern void thread_wait(void *thd);
|
||||
extern void thread_millisleep(int ms);
|
||||
|
||||
#endif
|
||||
63
server/include/users.h
Normal file
63
server/include/users.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef _USERS_H
|
||||
#define _USERS_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
|
||||
*/
|
||||
#include <hashtable.h>
|
||||
#include <dcb.h>
|
||||
|
||||
/**
|
||||
* @file users.h The functions to manipulate the table of users maintained
|
||||
* for each service
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 23/06/13 Mark Riddoch Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
/**
|
||||
* The users table statistics structure
|
||||
*/
|
||||
typedef struct {
|
||||
int n_entries; /**< The number of entries */
|
||||
int n_adds; /**< The number of inserts */
|
||||
int n_deletes; /**< The number of deletes */
|
||||
int n_fetches; /**< The number of fetchs */
|
||||
} USERS_STATS;
|
||||
|
||||
/**
|
||||
* The user table, this contains the username and authentication data required
|
||||
* for the authentication implementation within the gateway.
|
||||
*/
|
||||
typedef struct users {
|
||||
HASHTABLE *data; /**< The hashtable containing the actual data */
|
||||
USERS_STATS stats; /**< The statistics for the users table */
|
||||
} USERS;
|
||||
|
||||
extern USERS *users_alloc(); /**< Allocate a users table */
|
||||
extern void users_free(USERS *); /**< Free a users table */
|
||||
extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */
|
||||
extern int users_delete(USERS *, char *); /**< Delete a user from the users table */
|
||||
extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */
|
||||
extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in the users table */
|
||||
extern void usersPrint(USERS *); /**< Print data about the users loaded */
|
||||
extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */
|
||||
#endif
|
||||
Reference in New Issue
Block a user