Reverted versions

This commit is contained in:
Massimiliano Pinto 2013-06-26 12:07:38 +02:00
parent d5590c6d0e
commit 243c4870e7
3 changed files with 45 additions and 24 deletions

View File

@ -30,12 +30,12 @@
static char *version_str = "V1.0.0";
extern char *gw_strend(register const char *s);
int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn);
int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session);
int gw_read_backend_event(DCB* dcb);
int gw_write_backend_event(DCB *dcb);
int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
int gw_error_backend_event(DCB *dcb);
static int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn);
static int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session);
static int gw_read_backend_event(DCB* dcb);
static int gw_write_backend_event(DCB *dcb);
static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
static int gw_error_backend_event(DCB *dcb);
static int gw_backend_close(DCB *dcb);
static GWPROTOCOL MyObject = {
@ -102,10 +102,7 @@ int gw_read_backend_event(DCB *dcb) {
#endif
if ((client_protocol->state == MYSQL_WAITING_RESULT) || (client_protocol->state == MYSQL_IDLE)) {
int w;
int b = -1;
int tot_b = -1;
uint8_t *ptr_buffer;
GWBUF *buffer, *head;
if (ioctl(dcb->fd, FIONREAD, &b)) {
@ -232,7 +229,6 @@ int w, saved_errno = 0;
}
int gw_error_backend_event(DCB *dcb) {
MySQLProtocol *protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
fprintf(stderr, "#### Handle Backend error function for %i\n", dcb->fd);
@ -265,6 +261,7 @@ int gw_error_backend_event(DCB *dcb) {
fprintf(stderr, "Freeing backend MySQL conn %p, %p\n", dcb->protocol, &dcb->protocol);
}
}
return 1;
}
/*
@ -324,10 +321,11 @@ int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *session)
return -1;
}
static int
int
gw_backend_close(DCB *dcb)
{
dcb_close(dcb);
return 1;
}
/*
@ -359,7 +357,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
int rv;
int so = 0;
int ciclo = 0;
char buffer[SMALL_CHUNK];
uint8_t buffer[SMALL_CHUNK];
uint8_t packet_buffer[SMALL_CHUNK];
uint8_t *payload = NULL;
int server_protocol;
@ -385,7 +383,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
if (strlen(dbname))
curr_db = dbname;
if (strlen(passwd))
if (strlen((char *)passwd))
curr_passwd = passwd;
conn->state = MYSQL_ALLOC;
@ -668,7 +666,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
// 4 + 4 + 4 + 1 + 23 = 36
payload += 23;
strcpy(payload, user);
memcpy(payload, user, strlen(user));
// 4 + 4 + 1 + 23 = 32 + 1 (scramble_len) + 20 (fixed_scramble) + 1 (user NULL term) + 1 (db NULL term) = 55
bytes = 32;
@ -700,7 +698,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
// if the db is not NULL append it
if (curr_db) {
strcpy(payload, curr_db);
memcpy(payload, curr_db, strlen(curr_db));
payload += strlen(curr_db);
payload++;
bytes += strlen(curr_db);
@ -708,7 +706,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
bytes++;
}
strcpy(payload, "mysql_native_password");
memcpy(payload, "mysql_native_password", strlen("mysql_native_password"));
payload += strlen("mysql_native_password");
payload++;

View File

@ -112,6 +112,7 @@ GetModuleObject()
*/
int
mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message) {
int n = 0;
uint8_t *outbuf = NULL;
uint8_t mysql_payload_size = 0;
uint8_t mysql_packet_header[4];
@ -199,6 +200,8 @@ mysql_send_custom_error (DCB *dcb, int packet_number, int in_affected_rows, cons
uint8_t mysql_packet_header[4];
uint8_t *mysql_payload = NULL;
uint8_t field_count = 0;
uint8_t affected_rows = 0;
uint8_t insert_id = 0;
uint8_t mysql_err[2];
uint8_t mysql_statemsg[6];
unsigned int mysql_errno = 0;
@ -278,6 +281,8 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
uint8_t mysql_packet_header[4];
uint8_t *mysql_payload = NULL;
uint8_t field_count = 0;
uint8_t affected_rows = 0;
uint8_t insert_id = 0;
uint8_t mysql_err[2];
uint8_t mysql_statemsg[6];
unsigned int mysql_errno = 0;
@ -347,6 +352,7 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
int
MySQLSendHandshake(DCB* dcb)
{
int n = 0;
uint8_t *outbuf = NULL;
uint8_t mysql_payload_size = 0;
uint8_t mysql_packet_header[4];
@ -410,9 +416,8 @@ MySQLSendHandshake(DCB* dcb)
mysql_handshake_payload = mysql_handshake_payload + sizeof(mysql_protocol_version);
// write server version plus 0 filler
memcpy(mysql_handshake_payload, GW_MYSQL_VERSION, strlen(GW_MYSQL_VERSION));
strcpy(mysql_handshake_payload, GW_MYSQL_VERSION);
mysql_handshake_payload = mysql_handshake_payload + strlen(GW_MYSQL_VERSION);
*mysql_handshake_payload = 0x00;
mysql_handshake_payload++;
@ -502,6 +507,7 @@ MySQLSendHandshake(DCB* dcb)
static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
MySQLProtocol *protocol = NULL;
uint32_t client_capabilities;
int compress = -1;
int connect_with_db = -1;
uint8_t *client_auth_packet = GWBUF_DATA(queue);
@ -511,6 +517,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
uint8_t *auth_token = NULL;
uint8_t *stage1_hash = NULL;
int auth_ret = -1;
SESSION *session = NULL;
MYSQL_session *client_data = NULL;
if (dcb)
@ -528,7 +535,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
compress = GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(&protocol->client_capabilities);
// now get the user
strncpy(username, (char *)(client_auth_packet + 4 + 4 + 4 + 1 + 23), 128);
strncpy(username, client_auth_packet + 4 + 4 + 4 + 1 + 23, 128);
fprintf(stderr, "<<< Client username is [%s]\n", username);
// get the auth token len
@ -536,7 +543,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
if (connect_with_db) {
database = client_data->db;
strncpy(database, (char *)(client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1 + 1 + auth_token_len), 128);
strncpy(database, client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1 + 1 + auth_token_len, 128);
fprintf(stderr, "<<< Client selected db is [%s]\n", database);
} else {
fprintf(stderr, "<<< Client is NOT connected with db\n");
@ -770,7 +777,11 @@ int gw_read_client_event(DCB* dcb) {
ROUTER *router_instance = NULL;
void *rsession = NULL;
MySQLProtocol *protocol = NULL;
uint8_t buffer[MAX_BUFFER_SIZE] = "";
int n = 0;
int b = -1;
GWBUF *head = NULL;
GWBUF *gw_buffer = NULL;
if (dcb) {
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
@ -844,7 +855,7 @@ int gw_read_client_event(DCB* dcb) {
router = session->service->router;
router_instance = session->service->router_instance;
rsession = session->router_session;
}
}
//////////////////////////////////////////////////////
// read and handle errors & close, or return if busy
@ -931,6 +942,7 @@ int gw_read_client_event(DCB* dcb) {
//////////////////////////////////////////////
int gw_write_client_event(DCB *dcb) {
MySQLProtocol *protocol = NULL;
int n;
if (dcb == NULL) {
fprintf(stderr, "DCB is NULL, return\n");
@ -950,6 +962,7 @@ int gw_write_client_event(DCB *dcb) {
if(protocol->state == MYSQL_AUTH_RECV) {
SESSION *session = NULL;
MYSQL_session *s_data = dcb->data;
//write to client mysql AUTH_OK packet, packet n. is 2
mysql_send_ok(dcb, 2, 0, NULL);
@ -989,7 +1002,10 @@ int gw_write_client_event(DCB *dcb) {
///
int gw_MySQLListener(DCB *listener, char *config_bind) {
int l_so;
int fl;
struct sockaddr_in serv_addr;
struct sockaddr_in local;
socklen_t addrlen;
char *bind_address_and_port = NULL;
char *p;
char address[1024]="";
@ -1076,7 +1092,9 @@ int gw_MySQLAccept(DCB *listener) {
socklen_t addrlen;
addrlen = sizeof(local);
DCB *client;
SESSION *session;
MySQLProtocol *protocol;
MySQLProtocol *ptr_proto;
int sendbuf = GW_BACKEND_SO_SNDBUF;
socklen_t optlen = sizeof(sendbuf);
@ -1147,6 +1165,8 @@ int gw_MySQLAccept(DCB *listener) {
static int gw_error_client_event(DCB *dcb) {
MySQLProtocol *protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
fprintf(stderr, "#### Handle error function gw_error_client_event, for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
fprintf(stderr, "#### Handle error function RETURN for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
@ -1158,5 +1178,4 @@ static int
gw_client_close(DCB *dcb)
{
dcb_close(dcb);
return 1;
}

View File

@ -26,11 +26,13 @@
#include "mysql_client_server_protocol.h"
static char *version_str = "V1.0.0";
MySQLProtocol *gw_mysql_init(MySQLProtocol *data);
void gw_mysql_close(MySQLProtocol **ptr);
extern int gw_read_backend_event(DCB* dcb);
extern int gw_write_backend_event(DCB *dcb);
extern gw_read_backend_event(DCB* dcb);
extern gw_write_backend_event(DCB *dcb);
extern int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
extern int gw_error_backend_event(DCB *dcb);
@ -38,6 +40,8 @@ extern int gw_error_backend_event(DCB *dcb);
// Initialize mysql protocol struct
///////////////////////////////////////
MySQLProtocol *gw_mysql_init(MySQLProtocol *data) {
int rv = -1;
MySQLProtocol *input = NULL;
if (input == NULL) {