Added backend connections via session_alloc called after AUTH_OK

the newSession calls connect_dcb and then the connect() in mysql_backend.c

The selected backend is always the last  one ath the moment.

For the transparent Authentication dcb->data is used to store MySQL session data before starting the session.

This could be revisited.


Please note the COM_QUIT in mysql_client.c has the close functionalities but they are now disabled for testing/debug
This commit is contained in:
Massimiliano Pinto
2013-06-21 13:05:51 +02:00
parent ccf658d905
commit e767c70acb
4 changed files with 113 additions and 136 deletions

View File

@ -28,9 +28,8 @@
static char *version_str = "V1.0.0";
//static int gw_create_backend_connection(DCB *client_dcb, int efd);
static MySQLProtocol *gw_mysql_init(MySQLProtocol *data);
static void gw_mysql_close(MySQLProtocol **ptr);
MySQLProtocol *gw_mysql_init(MySQLProtocol *data);
void gw_mysql_close(MySQLProtocol **ptr);
extern gw_read_backend_event(DCB* dcb);
extern gw_write_backend_event(DCB *dcb);
@ -97,76 +96,3 @@ void gw_mysql_close(MySQLProtocol **ptr) {
#endif
}
/*
* Create a new MySQL backend connection.
*
* This routine performs the MySQL connection to the backend and fills the session->backends of the callier dcb
* with the new allocatetd dcb and adds the new socket to the poll set
*
* - backend dcb allocation
* - MySQL session data fetch
* - backend connection using data in MySQL session
*
* @param client_dcb The client DCB struct
* @return 0 on Success or 1 on Failure.
*/
/*
* This function cannot work as it will be called from mysql_client.c but it needs function pointers from mysql_backend.c
* They are modules loaded separately!!
*
int gw_create_backend_connection(DCB *client_dcb) {
DCB *backend = NULL;
MySQLProtocol *ptr_proto = NULL;
MySQLProtocol *client_protocol = NULL;
SESSION *session = NULL;
MYSQL_session *s_data = NULL;
backend = (DCB *) calloc(1, sizeof(DCB));
backend->state = DCB_STATE_ALLOC;
backend->session = NULL;
backend->protocol = (MySQLProtocol *)gw_mysql_init(NULL);
ptr_proto = (MySQLProtocol *)backend->protocol;
client_protocol = (MySQLProtocol *)client_dcb->protocol;
session = DCB_SESSION(client_dcb);
s_data = (MYSQL_session *)session->data;
// this is blocking until auth done
if (gw_mysql_connect("127.0.0.1", 3306, s_data->db, s_data->user, s_data->client_sha1, backend->protocol) == 0) {
fprintf(stderr, "Connected to backend mysql server\n");
backend->fd = ptr_proto->fd;
setnonblocking(backend->fd);
} else {
fprintf(stderr, "<<<< NOT Connected to backend mysql server!!!\n");
backend->fd = -1;
}
// edge triggering flag added
ee.events = EPOLLIN | EPOLLET | EPOLLOUT;
ee.data.ptr = backend;
// if connected, add it to the epoll
if (backend->fd > 0) {
if (epoll_ctl(efd, EPOLL_CTL_ADD, backend->fd, &ee) == -1) {
perror("epoll_ctl: backend sock");
} else {
fprintf(stderr, "--> Backend conn added, bk_fd [%i], scramble [%s], is session with client_fd [%i]\n", ptr_proto->fd, ptr_proto->scramble, client_dcb->fd);
backend->state = DCB_STATE_POLLING;
backend->session = DCB_SESSION(client_dcb);
(backend->func).read = gw_read_backend_event;
(backend->func).write = gw_MySQLWrite_backend;
(backend->func).write_ready = gw_write_backend_event;
(backend->func).error = gw_error_backend_event;
// assume here one backend only.
// in session.h
// struct dcb *backends;
// instead of a list **backends;
client_dcb->session->backends = backend;
}
return 0;
}
return 1;
}
*/