From 73e5fd52fac1321185a1565784174beea591d6bc Mon Sep 17 00:00:00 2001 From: Dapeng Huang <7xerocha@gmail.com> Date: Mon, 22 Jan 2018 22:00:27 +0800 Subject: [PATCH] misc fix and remove all tail spaces --- include/maxscale/protocol/mysql.h | 2 +- server/core/test/test_session_track.cc | 124 +++++++++--------- server/modules/protocol/MySQL/mysql_common.cc | 14 +- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index 5e8a412f8..f8d0ee410 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -353,7 +353,7 @@ typedef struct int ignore_replies; /*< How many replies should be discarded */ GWBUF* stored_query; /*< Temporarily stored queries */ bool collect_result; /*< Collect the next result set as one buffer */ - uint32_t num_eof_packets; /*< Signal number to indicate is current packet is ok packet*/ + uint32_t num_eof_packets; /*< Encountered eof packet number, used for check packet type */ #if defined(SS_DEBUG) skygw_chk_t protocol_chk_tail; #endif diff --git a/server/core/test/test_session_track.cc b/server/core/test/test_session_track.cc index d8ab2f88f..2a375eb0b 100644 --- a/server/core/test/test_session_track.cc +++ b/server/core/test/test_session_track.cc @@ -12,60 +12,60 @@ MySQLProtocol proto; static const uint8_t resultset1[] = { /* BEGIN;*/ - 0x29, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, - 0x40, 0x00, 0x00, 0x00, 0x20, 0x05, 0x09, 0x08, - 0x54, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, - 0x04, 0x13, 0x12, 0x53, 0x54, 0x41, 0x52, 0x54, + 0x29, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, + 0x40, 0x00, 0x00, 0x00, 0x20, 0x05, 0x09, 0x08, + 0x54, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, + 0x04, 0x13, 0x12, 0x53, 0x54, 0x41, 0x52, 0x54, 0x20, 0x54, 0x52, 0x41, 0x4E, 0x53, 0x41, 0x43, 0x54, 0x49, 0x4F, 0x4E, 0x3B, /* COMMIT;*/ - 0x17, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, - 0x40, 0x00, 0x00, 0x00, 0x0E, 0x05, 0x09, 0x08, - 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, + 0x17, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x40, 0x00, 0x00, 0x00, 0x0E, 0x05, 0x09, 0x08, + 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x04, 0x01, 0x00, /* START TRANSACTION;*/ - 0x29, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, - 0x40, 0x00, 0x00, 0x00, 0x20, 0x05, 0x09, 0x08, - 0x54, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, - 0x04, 0x13, 0x12, 0x53, 0x54, 0x41, 0x52, 0x54, - 0x20, 0x54, 0x52, 0x41, 0x4E, 0x53, 0x41, 0x43, + 0x29, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, + 0x40, 0x00, 0x00, 0x00, 0x20, 0x05, 0x09, 0x08, + 0x54, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, + 0x04, 0x13, 0x12, 0x53, 0x54, 0x41, 0x52, 0x54, + 0x20, 0x54, 0x52, 0x41, 0x4E, 0x53, 0x41, 0x43, 0x54, 0x49, 0x4F, 0x4E, 0x3B, /* START TRANSACTION READ ONLY;*/ - 0x28, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, - 0x60, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x1D, 0x1C, - 0x53, 0x54, 0x41, 0x52, 0x54, 0x20, 0x54, 0x52, - 0x41, 0x4E, 0x53, 0x41, 0x43, 0x54, 0x49, 0x4F, - 0x4E, 0x20, 0x52, 0x45, 0x41, 0x44, 0x20, 0x4F, + 0x28, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, + 0x60, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x1D, 0x1C, + 0x53, 0x54, 0x41, 0x52, 0x54, 0x20, 0x54, 0x52, + 0x41, 0x4E, 0x53, 0x41, 0x43, 0x54, 0x49, 0x4F, + 0x4E, 0x20, 0x52, 0x45, 0x41, 0x44, 0x20, 0x4F, 0x4E, 0x4C, 0x59, 0x3B, /* COMMIT;*/ - 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, /* SET AUTOCOMMIT=0;*/ - 0x1D, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x14, 0x00, 0x0F, 0x0A, - 0x61, 0x75, 0x74, 0x6F, 0x63, 0x6F, 0x6D, 0x6D, - 0x69, 0x74, 0x03, 0x4F, 0x46, 0x46, 0x02, 0x01, + 0x1D, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x14, 0x00, 0x0F, 0x0A, + 0x61, 0x75, 0x74, 0x6F, 0x63, 0x6F, 0x6D, 0x6D, + 0x69, 0x74, 0x03, 0x4F, 0x46, 0x46, 0x02, 0x01, 0x31, /* INSERT INTO t1 VALUES(1);*/ - 0x14, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, - 0x40, 0x00, 0x00, 0x00, 0x0B, 0x05, 0x09, 0x08, + 0x14, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x40, 0x00, 0x00, 0x00, 0x0B, 0x05, 0x09, 0x08, 0x49, 0x5F, 0x5F, 0x5F, 0x57, 0x5F, 0x5F, 0x5F, /* COMMIT;*/ 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x0B, 0x05, 0x09, 0x08, + 0x40, 0x00, 0x00, 0x00, 0x0B, 0x05, 0x09, 0x08, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F }; #define PACKET_HDR_LEN 4 #define PACKET_1_IDX 0 -#define PACKET_1_LEN (PACKET_HDR_LEN + 0x29) +#define PACKET_1_LEN (PACKET_HDR_LEN + 0x29) #define PACKET_2_IDX (PACKET_1_IDX + PACKET_1_LEN) -#define PACKET_2_LEN (PACKET_HDR_LEN + 0x17) +#define PACKET_2_LEN (PACKET_HDR_LEN + 0x17) #define PACKET_3_IDX (PACKET_2_IDX + PACKET_2_LEN) -#define PACKET_3_LEN (PACKET_HDR_LEN + 0x29) +#define PACKET_3_LEN (PACKET_HDR_LEN + 0x29) #define PACKET_4_IDX (PACKET_3_IDX + PACKET_3_LEN) -#define PACKET_4_LEN (PACKET_HDR_LEN + 0x28) +#define PACKET_4_LEN (PACKET_HDR_LEN + 0x28) #define PACKET_5_IDX (PACKET_4_IDX + PACKET_4_LEN) #define PACKET_5_LEN (PACKET_HDR_LEN + 0x07) #define PACKET_6_IDX (PACKET_5_IDX + PACKET_5_LEN) @@ -84,38 +84,38 @@ static const uint8_t resultset2[] = * insert into t1 select seq from seq_0_to_20; * select '' from t1; **/ - 0x1D, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x14, 0x00, 0x0F, 0x0A, - 0x61, 0x75, 0x74, 0x6F, 0x63, 0x6F, 0x6D, 0x6D, - 0x69, 0x74, 0x03, 0x4F, 0x46, 0x46, 0x02, 0x01, - 0x31, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x01, - 0x00, 0x15, 0x00, 0x21, 0x40, 0x00, 0x00, 0x27, - 0x52, 0x65, 0x63, 0x6F, 0x72, 0x64, 0x73, 0x3A, - 0x20, 0x32, 0x31, 0x20, 0x20, 0x44, 0x75, 0x70, - 0x6C, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x3A, - 0x20, 0x30, 0x20, 0x20, 0x57, 0x61, 0x72, 0x6E, - 0x69, 0x6E, 0x67, 0x73, 0x3A, 0x20, 0x30, 0x0B, - 0x05, 0x09, 0x08, 0x49, 0x5F, 0x52, 0x5F, 0x57, - 0x5F, 0x5F, 0x5F, 0x01, 0x00, 0x00, 0x01, 0x01, - 0x16, 0x00, 0x00, 0x02, 0x03, 0x64, 0x65, 0x66, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x21, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xFD, 0x01, 0x00, 0x27, - 0x00, 0x00, 0x05, 0x00, 0x00, 0x03, 0xFE, 0x00, - 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x04, 0x00, - 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, - 0x06, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x01, - 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x09, - 0x00, 0x01, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, - 0x00, 0x0B, 0x00, 0x01, 0x00, 0x00, 0x0C, 0x00, - 0x01, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x00, - 0x0E, 0x00, 0x01, 0x00, 0x00, 0x0F, 0x00, 0x01, - 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x11, - 0x00, 0x01, 0x00, 0x00, 0x12, 0x00, 0x01, 0x00, - 0x00, 0x13, 0x00, 0x01, 0x00, 0x00, 0x14, 0x00, - 0x01, 0x00, 0x00, 0x15, 0x00, 0x01, 0x00, 0x00, - 0x16, 0x00, 0x01, 0x00, 0x00, 0x17, 0x00, 0x01, - 0x00, 0x00, 0x18, 0x00, 0x05, 0x00, 0x00, 0x19, + 0x1D, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x14, 0x00, 0x0F, 0x0A, + 0x61, 0x75, 0x74, 0x6F, 0x63, 0x6F, 0x6D, 0x6D, + 0x69, 0x74, 0x03, 0x4F, 0x46, 0x46, 0x02, 0x01, + 0x31, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x01, + 0x00, 0x15, 0x00, 0x21, 0x40, 0x00, 0x00, 0x27, + 0x52, 0x65, 0x63, 0x6F, 0x72, 0x64, 0x73, 0x3A, + 0x20, 0x32, 0x31, 0x20, 0x20, 0x44, 0x75, 0x70, + 0x6C, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x3A, + 0x20, 0x30, 0x20, 0x20, 0x57, 0x61, 0x72, 0x6E, + 0x69, 0x6E, 0x67, 0x73, 0x3A, 0x20, 0x30, 0x0B, + 0x05, 0x09, 0x08, 0x49, 0x5F, 0x52, 0x5F, 0x57, + 0x5F, 0x5F, 0x5F, 0x01, 0x00, 0x00, 0x01, 0x01, + 0x16, 0x00, 0x00, 0x02, 0x03, 0x64, 0x65, 0x66, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x21, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFD, 0x01, 0x00, 0x27, + 0x00, 0x00, 0x05, 0x00, 0x00, 0x03, 0xFE, 0x00, + 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x04, 0x00, + 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, + 0x06, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x01, + 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x09, + 0x00, 0x01, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, + 0x00, 0x0B, 0x00, 0x01, 0x00, 0x00, 0x0C, 0x00, + 0x01, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x00, + 0x0E, 0x00, 0x01, 0x00, 0x00, 0x0F, 0x00, 0x01, + 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x11, + 0x00, 0x01, 0x00, 0x00, 0x12, 0x00, 0x01, 0x00, + 0x00, 0x13, 0x00, 0x01, 0x00, 0x00, 0x14, 0x00, + 0x01, 0x00, 0x00, 0x15, 0x00, 0x01, 0x00, 0x00, + 0x16, 0x00, 0x01, 0x00, 0x00, 0x17, 0x00, 0x01, + 0x00, 0x00, 0x18, 0x00, 0x05, 0x00, 0x00, 0x19, 0xFE, 0x00, 0x00, 0x21, 0x40 }; @@ -189,7 +189,7 @@ void test1() //START TRANSACTION READ ONLY buffer = gwbuf_alloc_and_load(PACKET_4_LEN, resultset1+PACKET_4_IDX); mxs_mysql_get_session_track_info(buffer, &proto); - ss_dassert(strncmp(gwbuf_get_property(buffer, (char *)"trx_characteristics"), + ss_dassert(strncmp(gwbuf_get_property(buffer, (char *)"trx_characteristics"), "START TRANSACTION READ ONLY;", 28) == 0); gwbuf_free(buffer); //COMMIT diff --git a/server/modules/protocol/MySQL/mysql_common.cc b/server/modules/protocol/MySQL/mysql_common.cc index 3594ae834..3c5ed0c22 100644 --- a/server/modules/protocol/MySQL/mysql_common.cc +++ b/server/modules/protocol/MySQL/mysql_common.cc @@ -1786,7 +1786,7 @@ void mxs_mysql_parse_ok_packet(GWBUF *buff, size_t packet_offset, size_t packet_ mxs_leint_consume(&ptr); // Affected rows mxs_leint_consume(&ptr); // Last insert-id uint16_t server_status = gw_mysql_get_byte2(ptr); - ptr += 2; // status + ptr += 2; // status ptr += 2; // number of warnings if (ptr < (local_buf + packet_len)) @@ -1797,7 +1797,7 @@ void mxs_mysql_parse_ok_packet(GWBUF *buff, size_t packet_offset, size_t packet_ mxs_leint_consume(&ptr); // total SERVER_SESSION_STATE_CHANGED length while (ptr < (local_buf + packet_len)) { - enum_session_state_type type = + enum_session_state_type type = (enum enum_session_state_type)mxs_leint_consume(&ptr); #if defined(SS_DEBUG) ss_dassert(type <= SESSION_TRACK_TRANSACTION_TYPE); @@ -1816,8 +1816,8 @@ void mxs_mysql_parse_ok_packet(GWBUF *buff, size_t packet_offset, size_t packet_ MXS_FREE(var_value); break; case SESSION_TRACK_SYSTEM_VARIABLES: - mxs_leint_consume(&ptr); //lenth - // system variables like autocommit, schema, charset ... + mxs_leint_consume(&ptr); //lenth + // system variables like autocommit, schema, charset ... var_name = mxs_lestr_consume_dup(&ptr); var_value = mxs_lestr_consume_dup(&ptr); gwbuf_add_property(buff, var_name, var_value); @@ -1851,19 +1851,19 @@ void mxs_mysql_get_session_track_info(GWBUF *buff, MySQLProtocol *proto) { size_t offset = 0; uint8_t header_and_command[MYSQL_HEADER_LEN+1]; - if (proto->server_capabilities & GW_MYSQL_CAPABILITIES_SESSION_TRACK) + if (proto->server_capabilities&GW_MYSQL_CAPABILITIES_SESSION_TRACK) { while (gwbuf_copy_data(buff, offset, MYSQL_HEADER_LEN+1, header_and_command) == (MYSQL_HEADER_LEN+1)) { size_t packet_len = gw_mysql_get_byte3(header_and_command); uint8_t cmd = header_and_command[MYSQL_COM_OFFSET]; - if (packet_len > MYSQL_OK_PACKET_MIN_LEN && + if (packet_len > MYSQL_OK_PACKET_MIN_LEN && cmd == MYSQL_REPLY_OK && (proto->num_eof_packets % 2) == 0) { buff->gwbuf_type |= GWBUF_TYPE_REPLY_OK; - mxs_mysql_parse_ok_packet(buff, offset, packet_len); + mxs_mysql_parse_ok_packet(buff, offset, packet_len + MYSQL_HEADER_LEN); } if ((proto->current_command == MXS_COM_QUERY ||