From dc4cf3ab17b592988ddd80941320c38bcb6e6851 Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Mon, 10 Jun 2013 10:22:53 +0200 Subject: [PATCH] New files --- dcb.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ mysql_protocol.h | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 dcb.h create mode 100644 mysql_protocol.h diff --git a/dcb.h b/dcb.h new file mode 100644 index 000000000..0af7ca906 --- /dev/null +++ b/dcb.h @@ -0,0 +1,74 @@ +#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 + */ + +struct session; + +/* + * The function pointer table used by descriptors to call relevant functions + * within the protocol specific code. + */ + +struct dcb; + +typedef struct gw_protocol { + /* + * The operations that can be performed on the descriptor + */ + int (*read)(struct dcb *, int); + int (*write)(struct dcb *, int); + int (*error)(struct dcb *, int); + int (*accept)(struct dcb *, int); + //int (*close)(struct dcb *); +} GWPROTOCOL; + +/* + * Descriptor Control Block + */ +typedef struct dcb { + int fd; /* The descriptor */ + int state; /* Current descriptor state */ + void *protocol; /* The protocol specific state */ + struct session *session; /* The owning session */ + GWPROTOCOL func; /* The functions for this descrioptor */ + + /* queue buffer for write + is now a two buffer implementation + Only used in client write + */ + uint8_t buffer[MAX_BUFFER_SIZE]; /* network buffer */ + int buff_bytes; /* bytes in buffer */ + uint8_t *buffer_ptr; /* buffer pointer */ + uint8_t second_buffer[MAX_BUFFER_SIZE]; /* 2nd network buffer */ + int second_buff_bytes; /* 2nd bytes in buffer */ + uint8_t *second_buffer_ptr; /* 2nd buffer pointer */ +} 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 */ + +/* A few useful macros */ +#define DCB_SESSION(x) (x)->session +#define DCB_PROTOCOL(x, type) (type *)((x)->protocol) + +#endif diff --git a/mysql_protocol.h b/mysql_protocol.h new file mode 100644 index 000000000..000fe3c0b --- /dev/null +++ b/mysql_protocol.h @@ -0,0 +1,49 @@ +#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 + */ + +#ifndef MYSQL_SCRAMBLE_LEN +#define MYSQL_SCRAMBLE_LEN GW_MYSQL_SCRAMBLE_SIZE +#endif + +struct dcb; + +/* + * MySQL Protocol specific state data + */ +typedef struct { + int fd; + struct dcb *descriptor; /* The DCB of the socket we are running on */ + int state; /* Current descriptor state */ + char scramble[MYSQL_SCRAMBLE_LEN]; + uint32_t server_capabilities; /* server capabilities */ + uint32_t client_capabilities; /* client capabilities */ + unsigned long tid; /* MySQL Thread ID */ +} MySQLProtocol; + +/* 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 +#define MYSQL_WAITING_RESULT 6 + +#endif