From cd1e3f26cff49361f2d36ba50bbda0f42bcbd9c4 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 26 May 2017 11:55:14 +0300 Subject: [PATCH] MXS-1275: Compile mysql_client as C++ A custom parser for detecting "set sql_mode=ORACLE" is needed and writing that is C++ is more convenient than writing it in C. Consequently, so as to be able to use that parser, mysql_client must be compiled as C++. --- .../protocol/MySQL/MySQLClient/CMakeLists.txt | 2 +- .../{mysql_client.c => mysql_client.cc} | 61 ++++++------------- 2 files changed, 21 insertions(+), 42 deletions(-) rename server/modules/protocol/MySQL/MySQLClient/{mysql_client.c => mysql_client.cc} (94%) diff --git a/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt b/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt index 31f7c937f..beafaacc4 100644 --- a/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt +++ b/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(MySQLClient SHARED mysql_client.c) +add_library(MySQLClient SHARED mysql_client.cc) target_link_libraries(MySQLClient maxscale-common MySQLCommon) set_target_properties(MySQLClient PROPERTIES VERSION "1.0.0") install_module(MySQLClient core) diff --git a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc similarity index 94% rename from server/modules/protocol/MySQL/MySQLClient/mysql_client.c rename to server/modules/protocol/MySQL/MySQLClient/mysql_client.cc index 51cae36ad..42bcd3778 100644 --- a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c +++ b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc @@ -17,33 +17,6 @@ * * MySQL Protocol module for handling the protocol between the gateway * and the client. - * - * Revision History - * Date Who Description - * 14/06/2013 Mark Riddoch Initial version - * 17/06/2013 Massimiliano Pinto Added Client To MaxScale routines - * 24/06/2013 Massimiliano Pinto Added: fetch passwords from service users' hashtable - * 02/09/2013 Massimiliano Pinto Added: session refcount - * 16/12/2013 Massimiliano Pinto Added: client closed socket detection with recv(..., MSG_PEEK) - * 24/02/2014 Massimiliano Pinto Added: on failed authentication a new users' table is loaded - * with time and frequency limitations - * If current user is authenticated the new users' table will - * replace the old one - * 28/02/2014 Massimiliano Pinto Added: client IPv4 in dcb->ipv4 and inet_ntop for string - * representation - * 11/03/2014 Massimiliano Pinto Added: Unix socket support - * 07/05/2014 Massimiliano Pinto Added: specific version string in server handshake - * 09/09/2014 Massimiliano Pinto Added: 777 permission for socket path - * 13/10/2014 Massimiliano Pinto Added: dbname authentication check - * 10/11/2014 Massimiliano Pinto Added: client charset added to protocol struct - * 29/05/2015 Markus Makela Added SSL support - * 11/06/2015 Martin Brampton COM_QUIT suppressed for persistent connections - * 04/09/2015 Martin Brampton Introduce DUMMY session to fulfill guarantee DCB always has session - * 09/09/2015 Martin Brampton Modify error handler calls - * 11/01/2016 Martin Brampton Remove SSL write code, now handled at lower level; - * replace gwbuf_consume by gwbuf_free (multiple). - * 07/02/2016 Martin Brampton Split off authentication and SSL. - * 31/05/2016 Martin Brampton Implement connection throttling */ #define MXS_MODULE_NAME "MySQLClient" @@ -99,6 +72,10 @@ static void gw_process_one_new_client(DCB *client_dcb); * * @return The module object */ + +extern "C" +{ + MXS_MODULE* MXS_CREATE_MODULE() { static MXS_PROTOCOL MyObject = @@ -137,6 +114,8 @@ MXS_MODULE* MXS_CREATE_MODULE() return &info; } + +} /*lint +e14 */ /** @@ -197,7 +176,7 @@ static void thread_finish(void) */ static char *gw_default_auth() { - return "MySQLAuth"; + return (char*)"MySQLAuth"; } /** @@ -255,7 +234,7 @@ int MySQLSendHandshake(DCB* dcb) } else { - version_string = GW_MYSQL_VERSION; + version_string = (char*)GW_MYSQL_VERSION; len_version_string = strlen(GW_MYSQL_VERSION); } @@ -503,7 +482,7 @@ int gw_read_client_event(DCB* dcb) case MXS_AUTH_STATE_MESSAGE_READ: /* After this call read_buffer will point to freed data */ if (nbytes_read < 3 || (0 == max_bytes && nbytes_read < - (MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) || + (int)(MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) || (0 != max_bytes && nbytes_read < max_bytes)) { @@ -688,7 +667,7 @@ gw_read_do_authentication(DCB *dcb, GWBUF *read_buffer, int nbytes_read) if (dcb->user == NULL) { /** User authentication complete, copy the username to the DCB */ - MYSQL_session *ses = dcb->data; + MYSQL_session *ses = (MYSQL_session*)dcb->data; if ((dcb->user = MXS_STRDUP(ses->user)) == NULL) { dcb_close(dcb); @@ -862,7 +841,7 @@ static bool process_client_commands(DCB* dcb, int bytes_available, GWBUF** buffe if (dcb->protocol_packet_length - MYSQL_HEADER_LEN != GW_MYSQL_MAX_PACKET_LEN) { /** We're processing the first packet of a command */ - proto->current_command = cmd; + proto->current_command = (mysql_server_cmd_t)cmd; } dcb->protocol_packet_length = pktlen + MYSQL_HEADER_LEN; @@ -935,7 +914,7 @@ gw_read_normal_data(DCB *dcb, GWBUF *read_buffer, int nbytes_read) if (rcap_type_required(capabilities, RCAP_TYPE_STMT_INPUT)) { if (nbytes_read < 3 || nbytes_read < - (MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) + (int)(MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) { dcb->dcb_readqueue = read_buffer; @@ -951,7 +930,7 @@ gw_read_normal_data(DCB *dcb, GWBUF *read_buffer, int nbytes_read) * The option is stored as a two byte integer with the values 0 for enabling * multi-statements and 1 for disabling it. */ - MySQLProtocol *proto = dcb->protocol; + MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol; uint8_t opt; if (proto->current_command == MYSQL_COM_SET_OPTION && @@ -1033,8 +1012,8 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities) * Ensure that there are enough backends * available for router to continue operation. */ - session->service->router->handleError(session->service->router_instance, - session->router_session, + session->service->router->handleError((MXS_ROUTER*)session->service->router_instance, + (MXS_ROUTER_SESSION*)session->router_session, errbuf, dcb, ERRACT_NEW_CONNECTION, @@ -1089,7 +1068,7 @@ mysql_client_auth_error_handling(DCB *dcb, int auth_val, int packet_number) /** Send error 1049 to client */ message_len = 25 + MYSQL_DATABASE_MAXLEN; - fail_str = MXS_CALLOC(1, message_len + 1); + fail_str = (char*)MXS_CALLOC(1, message_len + 1); MXS_ABORT_IF_NULL(fail_str); snprintf(fail_str, message_len, "Unknown database '%s'", session->db); @@ -1395,7 +1374,7 @@ gw_client_close(DCB *dcb) if (session->router_session != NULL) { /** Close router session and all its connections */ - router->closeSession(router_instance, session->router_session); + router->closeSession((MXS_ROUTER*)router_instance, (MXS_ROUTER_SESSION*)session->router_session); } } return 1; @@ -1553,9 +1532,9 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF } else if ((type & QUERY_TYPE_COMMIT) || (type & QUERY_TYPE_ROLLBACK)) { - mxs_session_trx_state_t trx_state = session_get_trx_state(session); + uint32_t trx_state = session_get_trx_state(session); trx_state |= SESSION_TRX_ENDING_BIT; - session_set_trx_state(session, trx_state); + session_set_trx_state(session, (mxs_session_trx_state_t)trx_state); if (type & QUERY_TYPE_ENABLE_AUTOCOMMIT) { @@ -1618,7 +1597,7 @@ static bool ensure_complete_packet(DCB *dcb, GWBUF **read_buffer, int nbytes_rea { uint8_t* data = (uint8_t *) GWBUF_DATA(*read_buffer); - if (nbytes_read < 3 || nbytes_read < MYSQL_GET_PAYLOAD_LEN(data) + 4) + if (nbytes_read < 3 || nbytes_read < (int)MYSQL_GET_PAYLOAD_LEN(data) + 4) { dcb->dcb_readqueue = gwbuf_append(dcb->dcb_readqueue, *read_buffer); return false;