Updated structure and added makefile
This commit is contained in:
6
compila
6
compila
@ -1,6 +0,0 @@
|
|||||||
rm *.o
|
|
||||||
gcc -c gateway_mysql_protocol.c
|
|
||||||
gcc -c utils.c
|
|
||||||
gcc -c gw_utils.c
|
|
||||||
gcc -c gateway.c
|
|
||||||
gcc -o gateway gw_utils.o gateway.o utils.o gateway_mysql_protocol.o -lssl
|
|
27
core/Makefile
Normal file
27
core/Makefile
Normal 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
|
||||||
|
|
||||||
|
CC=cc
|
||||||
|
CFLAGS=-c -I../include
|
||||||
|
SRCS= atomic.c buffer.c spinlock.c gateway.c gateway_mysql_protocol.c gw_utils.c utils.c
|
||||||
|
OBJ=$(SRCS:.c=.o)
|
||||||
|
LIBS=-lssl
|
||||||
|
|
||||||
|
gateway: $(OBJ)
|
||||||
|
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
49
core/atomic.c
Normal file
49
core/atomic.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* atomic.c - Implementation of atomic opertions for the gateway
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 10/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implementation of an atomic add operation for the X86 processor.
|
||||||
|
* Adds a value to the contents of a location pointed to by the first parameter.
|
||||||
|
* The add operation is atomic and the return value is the value stored in the location
|
||||||
|
* prior to the operation. The number that is added may be signed, therefore atomic_subtract
|
||||||
|
* is merely an atomic add with a negative value.
|
||||||
|
*
|
||||||
|
* @param variable Pointer the the variable to add to
|
||||||
|
* @param value Value to be added
|
||||||
|
* @return The value of *variable before the add occured
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
atomic_add(int *variable, int value)
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"lock; xaddl %%eax, %2;"
|
||||||
|
:"=a" (value)
|
||||||
|
: "a" (value), "m" (*variable)
|
||||||
|
: "memory" );
|
||||||
|
return value;
|
||||||
|
}
|
151
core/buffer.c
Normal file
151
core/buffer.c
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* buffer.h - The Gateway buffer management functions
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 10/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <buffer.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate a new gateway buffer structure of size bytes.
|
||||||
|
*
|
||||||
|
* For now we allocate memory directly from malloc for buffer the management
|
||||||
|
* structure and the actual data buffer itself. We may swap at a future date
|
||||||
|
* to a more effecient mechanism.
|
||||||
|
*
|
||||||
|
* @param size The size in bytes of the data area required
|
||||||
|
* @return Pointer to the buffer structure or NULL if memory could not
|
||||||
|
* be allocated.
|
||||||
|
*/
|
||||||
|
GWBUF *
|
||||||
|
gwbuf_alloc(unsigned int size)
|
||||||
|
{
|
||||||
|
GWBUF *rval;
|
||||||
|
|
||||||
|
// Allocate the buffer header
|
||||||
|
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate the space for the actual data
|
||||||
|
if ((rval->data = (unsigned char *)malloc(size)) == NULL)
|
||||||
|
{
|
||||||
|
free(rval);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
rval->start = rval->data;
|
||||||
|
rval->end = rval->start + size;
|
||||||
|
rval->next = NULL;
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free a gateway buffer
|
||||||
|
*
|
||||||
|
* @param buf The buffer to free
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gwbuf_free(GWBUF *buf)
|
||||||
|
{
|
||||||
|
free(buf->data);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append a buffer onto a linked list of buffer structures.
|
||||||
|
*
|
||||||
|
* This call should be made with the caller holding the lock for the linked
|
||||||
|
* list.
|
||||||
|
*
|
||||||
|
* @param head The current head of the linked list
|
||||||
|
* @param tail The new buffer to make the tail of the linked list
|
||||||
|
* @return The new head of the linked list
|
||||||
|
*/
|
||||||
|
GWBUF *
|
||||||
|
gwbuf_append(GWBUF *head, GWBUF *tail)
|
||||||
|
{
|
||||||
|
GWBUF *ptr = head;
|
||||||
|
|
||||||
|
if (!head)
|
||||||
|
return tail;
|
||||||
|
while (ptr->next)
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
ptr->next = tail;
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Consume data from a buffer in the linked list. The assumption is to consume
|
||||||
|
* n bytes from the buffer chain.
|
||||||
|
*
|
||||||
|
* If after consuming the bytes from the first buffer that buffer becomes
|
||||||
|
* empty it will be freed and the linked list updated.
|
||||||
|
*
|
||||||
|
* The return value is the new head of the linked list.
|
||||||
|
*
|
||||||
|
* This call should be made with the caller holding the lock for the linked
|
||||||
|
* list.
|
||||||
|
*
|
||||||
|
* @param head The head of the linked list
|
||||||
|
* @param length The amount of data to consume
|
||||||
|
* @return The head of the linked list
|
||||||
|
*/
|
||||||
|
GWBUF *
|
||||||
|
gwbuf_consume(GWBUF *head, unsigned int length)
|
||||||
|
{
|
||||||
|
GWBUF *rval = head;
|
||||||
|
|
||||||
|
GWBUF_CONSUME(head, length);
|
||||||
|
if (GWBUF_EMPTY(head))
|
||||||
|
{
|
||||||
|
rval = head->next;
|
||||||
|
gwbuf_free(head);
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the number of bytes of data in the linked list.
|
||||||
|
*
|
||||||
|
* @param head The current head of the linked list
|
||||||
|
* @return The number of bytes of data in the linked list
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
gwbuf_length(GWBUF *head)
|
||||||
|
{
|
||||||
|
int rval = 0;
|
||||||
|
|
||||||
|
while (head)
|
||||||
|
{
|
||||||
|
rval += GWBUF_LENGTH(head);
|
||||||
|
head = head->next;
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
This file is distributed as part of the SkySQL Gateway. It is free
|
* 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
|
* 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,
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
version 2.
|
* version 2.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
* details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License along with
|
* 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
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
23-05-2013
|
* Revision History
|
||||||
epoll loop test
|
*
|
||||||
Massimiliano Pinto
|
* Date Who Description
|
||||||
*/
|
* 23-05-2013 Massimiliano Pinto epoll loop test
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "gw.h"
|
#include <gw.h>
|
||||||
#include "dcb.h"
|
#include <dcb.h>
|
||||||
#include "session.h"
|
#include <session.h>
|
||||||
|
|
||||||
// epoll fd, global!
|
// epoll fd, global!
|
||||||
static int epollfd;
|
static int epollfd;
|
@ -1,37 +1,37 @@
|
|||||||
/*
|
/*
|
||||||
This file is distributed as part of the SkySQL Gateway. It is free
|
* 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
|
* 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,
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
version 2.
|
* version 2.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
* details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License along with
|
* 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
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
23-05-2013
|
* Revision History
|
||||||
Empty mysql_protocol_handling
|
*
|
||||||
1)send handshake in accept
|
* Date Who Description
|
||||||
|
* 23-05-2013 Massimiliano Pinto Empty mysql_protocol_handling
|
||||||
|
* 1)send handshake in accept
|
||||||
|
* 2) read data
|
||||||
|
* 3) alway send OK
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
2) read data
|
|
||||||
3) alway send OK
|
|
||||||
|
|
||||||
Massimiliano Pinto
|
#include <gw.h>
|
||||||
*/
|
#include <dcb.h>
|
||||||
|
#include <session.h>
|
||||||
#include "gw.h"
|
|
||||||
#include "dcb.h"
|
|
||||||
#include "session.h"
|
|
||||||
|
|
||||||
#define MYSQL_CONN_DEBUG
|
#define MYSQL_CONN_DEBUG
|
||||||
//#undef MYSQL_CONN_DEBUG
|
//#undef MYSQL_CONN_DEBUG
|
@ -1,30 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
This file is distributed as part of the SkySQL Gateway. It is free
|
* 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
|
* 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,
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
version 2.
|
* version 2.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
* details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License along with
|
* 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
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
03-06-2013
|
* Revision History
|
||||||
gateway utils
|
*
|
||||||
Massimiliano Pinto
|
* Date Who Description
|
||||||
*/
|
* 03-06-2013 Massimiliano Pinto gateway utils
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "gw.h"
|
#include <gw.h>
|
||||||
#include "dcb.h"
|
#include <dcb.h>
|
||||||
|
|
||||||
///
|
///
|
||||||
// set ip address in sockect struct
|
// set ip address in sockect struct
|
98
core/spinlock.c
Normal file
98
core/spinlock.c
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* spinlock.c - Spinlock operations for the SkySQL Gateway
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 10/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <spinlock.h>
|
||||||
|
#include <atomic.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialise a spinlock.
|
||||||
|
*
|
||||||
|
* @param lock The spinlock to initialise.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spinlock_init(SPINLOCK *lock)
|
||||||
|
{
|
||||||
|
lock->lock = 0;
|
||||||
|
#ifdef DEBUG
|
||||||
|
lock->spins = 0;
|
||||||
|
lock->acquired = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Acquire a spinlock.
|
||||||
|
*
|
||||||
|
* @param lock The spinlock to acquire
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spinlock_acquire(SPINLOCK *lock)
|
||||||
|
{
|
||||||
|
while (atomic_add(&(lock->lock), 1) != 0)
|
||||||
|
{
|
||||||
|
atomic_add(&(lock->lock), -1);
|
||||||
|
#ifdef DEBUG
|
||||||
|
atomic_add(&(lock->spins), 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
lock->acquired++;
|
||||||
|
lock->owner = THREAD_SHELF();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Acquire a spinlock if it is not already locked.
|
||||||
|
*
|
||||||
|
* @param lock The spinlock to acquire
|
||||||
|
* @return True ifthe spinlock was acquired, otherwise false
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
spinlock_acquire_nowait(SPINLOCK *lock)
|
||||||
|
{
|
||||||
|
if (atomic_add(&(lock->lock), 1) != 0)
|
||||||
|
{
|
||||||
|
atomic_add(&(lock->lock), -1);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
lock->acquired++;
|
||||||
|
lock->owner = THREAD_SHELF();
|
||||||
|
#endif
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Release a spinlock.
|
||||||
|
*
|
||||||
|
* @param lock The spinlock to release
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spinlock_release(SPINLOCK *lock)
|
||||||
|
{
|
||||||
|
atomic_add(&(lock->lock), -1);
|
||||||
|
}
|
@ -1,26 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
This file is distributed as part of the SkySQL Gateway. It is free
|
* 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
|
* 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,
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
version 2.
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
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
|
* Revision History
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
*
|
||||||
details.
|
* Date Who Description
|
||||||
|
* 10/06/13 Massimiliano Pinto Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
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
|
#include <gw.h>
|
||||||
|
#include <dcb.h>
|
||||||
*/
|
#include <session.h>
|
||||||
|
#include <mysql_protocol.h>
|
||||||
#include "gw.h"
|
|
||||||
#include "dcb.h"
|
|
||||||
#include "session.h"
|
|
||||||
#include "mysql_protocol.h"
|
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
// used in the hex2bin function
|
// used in the hex2bin function
|
32
include/atomic.h
Normal file
32
include/atomic.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The atomic operations used within the gateway
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 10/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int atomic_add(int *variable, int value);
|
||||||
|
#endif
|
64
include/buffer.h
Normal file
64
include/buffer.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 10/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
unsigned char *data; // Physical memory that was allocated
|
||||||
|
} GWBUF;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros to access the data in the buffers
|
||||||
|
*/
|
||||||
|
#define GWBUF_DATA(b) ((b)->start)
|
||||||
|
#define GWBUF_LENGTH(b) ((b)->end - (b)->start)
|
||||||
|
#define GWBUF_EMPTY(b) ((b)->start == (b)->end)
|
||||||
|
#define GWBUF_CONSUME(b, bytes) (b)->start += bytes
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_append(GWBUF *head, GWBUF *tail);
|
||||||
|
extern GWBUF *gwbuf_consume(GWBUF *head, unsigned int length);
|
||||||
|
extern unsigned int gwbuf_length(GWBUF *head);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -15,7 +15,7 @@
|
|||||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct session;
|
struct session;
|
||||||
@ -23,6 +23,13 @@ struct session;
|
|||||||
/*
|
/*
|
||||||
* The function pointer table used by descriptors to call relevant functions
|
* The function pointer table used by descriptors to call relevant functions
|
||||||
* within the protocol specific code.
|
* within the protocol specific code.
|
||||||
|
*
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 1/06/13 Mark Riddoch Initial implementation
|
||||||
|
*
|
||||||
|
*/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct dcb;
|
struct dcb;
|
||||||
@ -33,9 +40,10 @@ typedef struct gw_protocol {
|
|||||||
*/
|
*/
|
||||||
int (*read)(struct dcb *, int);
|
int (*read)(struct dcb *, int);
|
||||||
int (*write)(struct dcb *, int);
|
int (*write)(struct dcb *, int);
|
||||||
|
int (*write_ready)(struct dcb *);
|
||||||
int (*error)(struct dcb *, int);
|
int (*error)(struct dcb *, int);
|
||||||
int (*accept)(struct dcb *, int);
|
int (*accept)(struct dcb *, int);
|
||||||
//int (*close)(struct dcb *);
|
int (*close)(struct dcb *);
|
||||||
} GWPROTOCOL;
|
} GWPROTOCOL;
|
||||||
|
|
||||||
/*
|
/*
|
@ -1,26 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
This file is distributed as part of the SkySQL Gateway. It is free
|
* 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
|
* 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,
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
version 2.
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
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
|
* MYSQL mysql protocol header file
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* Revision History
|
||||||
details.
|
*
|
||||||
|
* Date Who Description
|
||||||
You should have received a copy of the GNU General Public License along with
|
* 10/06/13 Massimiliano Pinto Initial implementation
|
||||||
this program; if not, write to the Free Software Foundation, Inc., 51
|
*
|
||||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
*/
|
||||||
|
|
||||||
Copyright SkySQL Ab
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
// MYSQL mysql protocol header file
|
|
||||||
// By Massimiliano Pinto 2012/2013
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
/* Protocol packing macros. */
|
/* Protocol packing macros. */
|
||||||
#define gw_mysql_set_byte2(__buffer, __int) do { \
|
#define gw_mysql_set_byte2(__buffer, __int) do { \
|
@ -15,7 +15,7 @@
|
|||||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MYSQL_SCRAMBLE_LEN
|
#ifndef MYSQL_SCRAMBLE_LEN
|
@ -15,7 +15,7 @@
|
|||||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright SkySQL Ab
|
* Copyright SkySQL Ab 2013
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct dcb;
|
struct dcb;
|
51
include/spinlock.h
Normal file
51
include/spinlock.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
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
|
25
include/thread.h
Normal file
25
include/thread.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#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>
|
||||||
|
|
||||||
|
#define THREAD pthread_t
|
||||||
|
#define THREAD_SHELF pthread_self
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user