Removed protocol_1.0, the Apache APR prototype

This commit is contained in:
Massimiliano Pinto 2013-07-29 10:08:53 +02:00
parent 636e5b619c
commit d2432ab307
11 changed files with 0 additions and 3443 deletions

View File

View File

@ -1,50 +0,0 @@
##
## Makefile -- Build procedure for sample skysql Apache module
## Autogenerated via ``apxs -n skysql -g''.
##
builddir=.
top_srcdir=/packages/inst/apache_2.4.2
top_builddir=/packages/inst/apache_2.4.2
include /packages/inst/apache_2.4.2/build/special.mk
# the used tools
APXS=apxs
APACHECTL=apachectl
# additional defines, includes and libraries
#DEFS=-Dmy_define=my_value
#INCLUDES=
#LIBS=-lskysqlclient -lmysqlcompat
#LDFLAGS=
# the default target
all: local-shared-build
# install the shared object file into Apache
install: install-modules-yes
# cleanup
clean:
-rm -f mod_skysql.o mod_skysql.lo mod_skysql.slo mod_skysql.la skysql_utils.o skysql_utils.lo skysql_utils.slo skysql_utils.la
# simple test
test: reload
lynx -mime_header http://localhost/skysql
# install and activate shared object by reloading Apache to
# force a reload of the shared object file
reload: install restart
# the general Apache start/restart/stop
# procedures
start:
$(APACHECTL) start
restart:
$(APACHECTL) restart
stop:
$(APACHECTL) stop

View File

@ -1,20 +0,0 @@
/*
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
*/
Apache 2.4.2

View File

@ -1,27 +0,0 @@
#Apache 2.4.2 configuration
########################
# The Mysql protocol enabled in the main server
#
AcceptFilter http httpready
AcceptFilter mysqld none
LoadModule skysql_module modules/mod_skysql.so
Listen 4402 mysqld
Timeout 300
SkySQLProtocol On
SkySQLPool Off
SkySQLSingleDBbresource "Master/Slaves" "127.0.0.1:3306,127.0.0.1:3307,127.0.0.1:3308;test"
SkySQLTimeout 300
<VirtualHost *:81>
## HTTP on port 81, in this virtual host
SkySQLProtocol Off
<Location /skycc>
SetHandler skysql
</Location>
</VirtualHost>
########################

View File

@ -1,2 +0,0 @@
curl 'http://127.0.0.1:81/skycc?show=1'
curl 'http://127.0.0.1:81/skycc?update=127.0.0.1:3306,127.0.0.1:3307,127.0.0.1:3308'

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
mod_skysql.la: mod_skysql.slo skysql_utils.slo skysql_backend.slo
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_skysql.lo skysql_utils.lo skysql_backend.lo
DISTCLEAN_TARGETS = modules.mk
shared = mod_skysql.la

View File

@ -1,143 +0,0 @@
/*
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
*/
////////////////////////////////////////
// SKYSQL Backend
// By Massimiliano Pinto 2012/2013
////////////////////////////////////////
#include "skysql_gw.h"
int skysql_ext_file_ver(void) {
int ret = 13;
return ret;
}
//////////////////////////////////////////////////////////////
// The function takes the server list,
// find the total server number
// and return a random selection for slaves (from total -1)
//////////////////////////////////////////////////////////////
int select_random_slave_server(const char *server_list, int *num_slaves) {
int nslaves = 0;
int random_balancer = 0;
char *p = (char *)server_list;
while( (p = strchr(p, ',')) != NULL) {
p++;
nslaves++;
}
memcpy(num_slaves, &nslaves, sizeof(int));
if (nslaves == 1) {
return 1;
}
// random selection
random_balancer = (int) ((nslaves+1) * (rand() / (RAND_MAX + 1.0)));
return random_balancer;
}
///////////////////////////////////////////////////////////////
// This takes a server from the list
// index 0 is always the Master
// the others refer to the salve,
// the slave number comes from: select_random_slave_server()
///////////////////////////////////////////////////////////////
int get_server_from_list(char **selected_host, int *selected_port, char *server_list, int num, apr_pool_t *p) {
int ret = -1;
int curr_srv = 0;
char *next = NULL;
char *tmp = NULL;
int port;
if (num == 0) {
port = atoi(strchr(server_list, ':') + 1), sizeof(port);
memcpy(selected_port, &port, sizeof(int));
*selected_host = apr_pstrndup(p, server_list, strchr(server_list, ':') - server_list);
return 1;
}
next = server_list;
while (curr_srv < num) {
tmp = strchr(next, ',');
if (tmp != NULL) {
curr_srv++;
next = tmp+1;
} else {
return -1;
}
if (curr_srv == num) {
port = atoi(strchr(next, ':') + 1);
memcpy(selected_port, &port, sizeof(port));
// the host string must be allocated in the memory pool!
*selected_host = apr_pstrndup(p, next, strchr(next, ':') - next);
ret = 0;
break;
}
}
return ret;
}
//////////////////////////////////////////////
// This funcion take the master from the list
// The index is always 0
//////////////////////////////////////////////
int get_master_from_list(char **selected_host, int *selected_port, char *server_list, apr_pool_t *p) {
int ret = -1;
int curr_srv = 0;
char *next = NULL;
char *tmp = NULL;
int port;
port = atoi(strchr(server_list, ':') + 1), sizeof(port);
memcpy(selected_port, &port, sizeof(int));
// the host string must be allocated in the memory pool!
*selected_host = apr_pstrndup(p, server_list, strchr(server_list, ':') - server_list);
return 1;
}
///////////////////////////////////////
// Query Routing basic implementation
///////////////////////////////////////
int query_routing(const char *server_list, const char *sql_command, int procotol_command, int current_slave) {
if (strstr(sql_command, "select ")) {
// to the slave
return SKYSQL_READ;
} else {
// to the master
return SKYSQL_WRITE;
}
}
//////////////////

View File

@ -1,169 +0,0 @@
/*
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
*/
////////////////////////////////////////
// SKYSQL mysql protocol header file
// By Massimiliano Pinto 2012/2013
////////////////////////////////////////
#include "ap_config.h"
#include "ap_mmn.h"
#include "httpd.h"
#include "http_core.h"
#include "http_main.h"
#include "http_config.h"
#include "http_connection.h"
#include "http_request.h"
#include "http_log.h"
#include "http_protocol.h"
#include "ap_config_auto.h"
#include "http_connection.h"
#include "util_filter.h"
#include "util_script.h"
#include "apr.h"
#include "apr_general.h"
#include "apr_buckets.h"
#include "apr_optional.h"
#include "apr_strings.h"
#include "apr_tables.h"
#include "apr_lib.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_dbm.h"
#include "apr_rmm.h"
#include "apr_shm.h"
#include "apr_global_mutex.h"
#include "apr_time.h"
#include "scoreboard.h"
// sha1
#include "apr_sha1.h"
// getpid
#include <unistd.h>
/* Protocol packing macros. */
#define skysql_set_byte2(__buffer, __int) do { \
(__buffer)[0]= (uint8_t)((__int) & 0xFF); \
(__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); } while (0)
#define skysql_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 skysql_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 skysql_get_byte2(__buffer) \
(uint16_t)((__buffer)[0] | \
((__buffer)[1] << 8))
#define skysql_get_byte3(__buffer) \
(uint32_t)((__buffer)[0] | \
((__buffer)[1] << 8) | \
((__buffer)[2] << 16))
#define skysql_get_byte4(__buffer) \
(uint32_t)((__buffer)[0] | \
((__buffer)[1] << 8) | \
((__buffer)[2] << 16) | \
((__buffer)[3] << 24))
#define skysql_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
{
SKYSQL_CAPABILITIES_NONE= 0,
SKYSQL_CAPABILITIES_LONG_PASSWORD= (1 << 0),
SKYSQL_CAPABILITIES_FOUND_ROWS= (1 << 1),
SKYSQL_CAPABILITIES_LONG_FLAG= (1 << 2),
SKYSQL_CAPABILITIES_CONNECT_WITH_DB= (1 << 3),
SKYSQL_CAPABILITIES_NO_SCHEMA= (1 << 4),
SKYSQL_CAPABILITIES_COMPRESS= (1 << 5),
SKYSQL_CAPABILITIES_ODBC= (1 << 6),
SKYSQL_CAPABILITIES_LOCAL_FILES= (1 << 7),
SKYSQL_CAPABILITIES_IGNORE_SPACE= (1 << 8),
SKYSQL_CAPABILITIES_PROTOCOL_41= (1 << 9),
SKYSQL_CAPABILITIES_INTERACTIVE= (1 << 10),
SKYSQL_CAPABILITIES_SSL= (1 << 11),
SKYSQL_CAPABILITIES_IGNORE_SIGPIPE= (1 << 12),
SKYSQL_CAPABILITIES_TRANSACTIONS= (1 << 13),
SKYSQL_CAPABILITIES_RESERVED= (1 << 14),
SKYSQL_CAPABILITIES_SECURE_CONNECTION= (1 << 15),
SKYSQL_CAPABILITIES_MULTI_STATEMENTS= (1 << 16),
SKYSQL_CAPABILITIES_MULTI_RESULTS= (1 << 17),
SKYSQL_CAPABILITIES_PS_MULTI_RESULTS= (1 << 18),
SKYSQL_CAPABILITIES_PLUGIN_AUTH= (1 << 19),
SKYSQL_CAPABILITIES_SSL_VERIFY_SERVER_CERT= (1 << 30),
SKYSQL_CAPABILITIES_REMEMBER_OPTIONS= (1 << 31),
SKYSQL_CAPABILITIES_CLIENT= (SKYSQL_CAPABILITIES_LONG_PASSWORD |
SKYSQL_CAPABILITIES_FOUND_ROWS |
SKYSQL_CAPABILITIES_LONG_FLAG |
SKYSQL_CAPABILITIES_CONNECT_WITH_DB |
SKYSQL_CAPABILITIES_LOCAL_FILES |
SKYSQL_CAPABILITIES_PLUGIN_AUTH |
SKYSQL_CAPABILITIES_TRANSACTIONS |
SKYSQL_CAPABILITIES_PROTOCOL_41 |
SKYSQL_CAPABILITIES_MULTI_STATEMENTS |
SKYSQL_CAPABILITIES_MULTI_RESULTS |
SKYSQL_CAPABILITIES_PS_MULTI_RESULTS |
SKYSQL_CAPABILITIES_SECURE_CONNECTION),
SKYSQL_CAPABILITIES_CLIENT_COMPRESS= (SKYSQL_CAPABILITIES_LONG_PASSWORD |
SKYSQL_CAPABILITIES_FOUND_ROWS |
SKYSQL_CAPABILITIES_LONG_FLAG |
SKYSQL_CAPABILITIES_CONNECT_WITH_DB |
SKYSQL_CAPABILITIES_LOCAL_FILES |
SKYSQL_CAPABILITIES_PLUGIN_AUTH |
SKYSQL_CAPABILITIES_TRANSACTIONS |
SKYSQL_CAPABILITIES_PROTOCOL_41 |
SKYSQL_CAPABILITIES_MULTI_STATEMENTS |
SKYSQL_CAPABILITIES_MULTI_RESULTS |
SKYSQL_CAPABILITIES_PS_MULTI_RESULTS |
SKYSQL_CAPABILITIES_COMPRESS
),
} skysql_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)
#define MYSQL_CONN_DEBUG
#undef MYSQL_CONN_DEBUG
typedef struct {
apr_socket_t *socket;
char scramble[33];
uint32_t server_capabs;
uint32_t client_capabs;
unsigned long tid;
apr_pool_t *pool;
} MYSQL_conn;

View File

@ -1,161 +0,0 @@
/*
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
*/
////////////////////////////////////////
// SKYSQL header file
// By Massimiliano Pinto 2012/2013
////////////////////////////////////////
#include "ap_config.h"
#include "ap_mmn.h"
#include "httpd.h"
#include "http_core.h"
#include "http_main.h"
#include "http_config.h"
#include "http_connection.h"
#include "http_request.h"
#include "http_log.h"
#include "http_protocol.h"
#include "ap_config_auto.h"
#include "http_connection.h"
#include "util_filter.h"
#include "util_script.h"
#include "apr.h"
#include "apr_general.h"
#include "apr_buckets.h"
#include "apr_optional.h"
#include "apr_strings.h"
#include "apr_tables.h"
#include "apr_lib.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_dbm.h"
#include "apr_rmm.h"
#include "apr_shm.h"
#include "apr_global_mutex.h"
#include "apr_time.h"
#include "scoreboard.h"
// getpid
#include <unistd.h>
// mapped I/O
#include <sys/mman.h>
#include "skysql_client.h"
#define SKYSQL_GATEWAY_VERSION "0.0.1"
#define SKYSQL_VERSION "5.5.22-SKY-1.6.5"
#define SKYSQL_READ 0
#define SKYSQL_WRITE 1
#define HTTP_WELCOME_MESSAGE "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/plain\r\n\r\nSKYSQL Gateway " SKYSQL_GATEWAY_VERSION
#define SKYSQL_LISTENER_VERSION "MySQL Community Server (GPL)"
#define SKYSQL_PROTOCOL_VERSION 10 // version is 10
#define SKYSQL_THREAD_ID 11
#define SKYSQL_HANDSKAKE_FILLER 0x00
#define SKYSQL_SERVER_CAPABILITIES_BYTE1 0xff
#define SKYSQL_SERVER_CAPABILITIES_BYTE2 0xf7
#define SKYSQL_SERVER_LANGUAGE 0x08
module AP_MODULE_DECLARE_DATA skysql_module;
static unsigned char *config_area=NULL;
//const int SKY_SQL_MAX_PACKET_LEN = 0xffffffL;
typedef struct {
MYSQL_conn *conn;
unsigned long mysql_tid;
unsigned long gateway_id;
int protocol_enabled;
int pool_enabled;
char backend_servers[2][128];
char *server_list;
apr_hash_t *resources;
int loop_timeout;
} skysql_server_conf;
typedef struct
{
char *name;
char *raw_config;
char *server_list;
int r_port;
char *dbname;
char *defaults;
int nshards;
} conn_details;
typedef struct {
char *driver_name;
char *username;
char *password;
char *database;
void *driver_details;
} skysql_client_auth;
typedef struct {
uint8_t client_flags[4];
uint8_t max_packet_size[4];
uint8_t charset;
uint8_t scramble_buff;
int connect_with_db;
int compress;
} mysql_driver_details;
typedef struct {
int num;
char *list;
} backend_list;
int skysql_ext_file_ver();
int skysql_query_is_select(const char *query);
apr_status_t skysql_read_client_autentication(conn_rec *c, apr_pool_t *pool, uint8_t *scramble, int scramble_len, skysql_client_auth *mysql_client_data, uint8_t *stage1_hash);
apr_status_t skysql_send_handshake(conn_rec *c, uint8_t *scramble, int *scramble_len);
apr_status_t skysql_send_error (conn_rec *c, uint8_t packet_number, MYSQL_conn *conn);
//apr_status_t skysql_prepare_ok(conn_rec *c, uint8_t packet_number, MYSQL_STMT *statement, MYSQL_conn *conn);
apr_status_t skysql_send_ok(conn_rec *c, apr_pool_t *p, uint8_t packet_number, uint8_t in_affected_rows, const char* skysql_message);
apr_status_t skysql_send_eof(conn_rec *c, apr_pool_t *p, uint8_t packet_number);
apr_status_t skysql_send_result(conn_rec *c, uint8_t *data, uint8_t len);
int select_random_slave_server(const char *server_listi, int *num_slaves);
apr_status_t gateway_send_error (conn_rec *c, apr_pool_t *p, uint8_t packet_number);
apr_status_t gateway_reply_data(conn_rec *c, apr_pool_t *pool, void *data, int len);
char *gateway_find_user_password_sha1(char *username, void *repository, conn_rec *c, apr_pool_t *p);
void skysql_sha1_str(const uint8_t *in, int in_len, uint8_t *out);
int skygateway_query_result(conn_rec *c, apr_pool_t *p, MYSQL_conn *conn, const char *query);
char *bin2hex(char *out, const uint8_t *in, unsigned int len);
void skysql_sha1_2_str(const uint8_t *in, int in_len, const uint8_t *in2, int in2_len, uint8_t *out);
void skysql_str_xor(char *output, const uint8_t *input1, const uint8_t *input2, unsigned int len);
int get_server_from_list(char **selected_host, int *selected_port, char *server_list, int num, apr_pool_t *p);
int get_master_from_list(char **selected_host, int *selected_port, char *server_list, apr_pool_t *p);
int mysql_pass_packet(MYSQL_conn *conn, const char *command, int len);
int mysql_receive_packet(conn_rec *c, apr_pool_t *p, MYSQL_conn *conn);
int skygateway_statement_prepare_result(conn_rec *c, apr_pool_t *p, MYSQL_conn *conn, const char *query, int len);
int skygateway_statement_execute_result(conn_rec *c, apr_pool_t *p, MYSQL_conn *conn, const char *query, int len);
int mysql_send_command(MYSQL_conn *conn, const char *command, int cmd, int len);
apr_status_t skysql_change_user(conn_rec *c, apr_pool_t *p, char *username, char *database, MYSQL_conn *conn, uint8_t *stage1_hash);
int query_routing(const char *server_list, const char *sql_command, int procotol_command, int current_slave);
unsigned int mysql_errno(MYSQL_conn *mysql);
const char *mysql_error(MYSQL_conn *mysql);
const char *mysql_sqlstate(MYSQL_conn *mysql);
int mysql_query(MYSQL_conn *conn, const char *query);

File diff suppressed because it is too large Load Diff