Move length-encoded integer/string functions to maxsql

This commit is contained in:
Esa Korhonen
2018-11-29 14:41:10 +02:00
parent 5e03ff35eb
commit 655e5fab5b
12 changed files with 170 additions and 173 deletions

View File

@ -573,7 +573,7 @@ int CacheFilterSession::handle_expecting_response()
{
// mxs_leint_bytes() returns the length of the int type field + the size of the
// integer.
size_t n_bytes = mxs_leint_bytes(&header[4]);
size_t n_bytes = mxq::leint_bytes(&header[4]);
if (MYSQL_HEADER_LEN + n_bytes <= buflen)
{
@ -581,7 +581,7 @@ int CacheFilterSession::handle_expecting_response()
// need to copy some more data.
copy_data(MYSQL_HEADER_LEN + 1, n_bytes - 1, &header[MYSQL_HEADER_LEN + 1]);
m_res.nTotalFields = mxs_leint_value(&header[4]);
m_res.nTotalFields = mxq::leint_value(&header[4]);
m_res.offset = MYSQL_HEADER_LEN + n_bytes;
m_state = CACHE_EXPECTING_FIELDS;

View File

@ -37,7 +37,7 @@ public:
*/
LEncInt(uint8_t* pData)
{
m_value = mxs_leint_value(pData);
m_value = mxq::leint_value(pData);
}
/**
@ -49,8 +49,8 @@ public:
*/
LEncInt(uint8_t** ppData)
{
size_t nBytes = mxs_leint_bytes(*ppData);
m_value = mxs_leint_value(*ppData);
size_t nBytes = mxq::leint_bytes(*ppData);
m_value = mxq::leint_value(*ppData);
*ppData += nBytes;
}
@ -226,7 +226,7 @@ public:
// NULL is sent as 0xfb. See https://dev.mysql.com/doc/internals/en/com-query-response.html
if (*pData != 0xfb)
{
m_pString = mxs_lestr_consume(&pData, &m_length);
m_pString = mxq::lestr_consume(&pData, &m_length);
}
else
{
@ -247,7 +247,7 @@ public:
// NULL is sent as 0xfb. See https://dev.mysql.com/doc/internals/en/com-query-response.html
if (**ppData != 0xfb)
{
m_pString = mxs_lestr_consume(ppData, &m_length);
m_pString = mxq::lestr_consume(ppData, &m_length);
}
else
{

View File

@ -768,7 +768,7 @@ static int handle_expecting_response(MAXROWS_SESSION_DATA* csdata)
{
// mxs_leint_bytes() returns the length of the int type field + the size of the
// integer.
size_t n_bytes = mxs_leint_bytes(&header[4]);
size_t n_bytes = mxq::leint_bytes(&header[4]);
if (MYSQL_HEADER_LEN + n_bytes <= buflen)
{
@ -779,7 +779,7 @@ static int handle_expecting_response(MAXROWS_SESSION_DATA* csdata)
n_bytes - 1,
&header[MYSQL_HEADER_LEN + 1]);
csdata->res.n_totalfields = mxs_leint_value(&header[4]);
csdata->res.n_totalfields = mxq::leint_value(&header[4]);
csdata->res.offset += MYSQL_HEADER_LEN + n_bytes;
csdata->state = MAXROWS_EXPECTING_FIELDS;

View File

@ -21,6 +21,7 @@
#include <sstream>
#include <map>
#include <maxsql/mariadb.hh>
#include <maxscale/alloc.h>
#include <maxscale/clock.h>
#include <maxscale/modutil.hh>
@ -1245,8 +1246,8 @@ bool mxs_mysql_more_results_after_ok(GWBUF* buffer)
gwbuf_copy_data(buffer, MYSQL_HEADER_LEN + 1, sizeof(data), data);
uint8_t* ptr = data;
ptr += mxs_leint_bytes(ptr);
ptr += mxs_leint_bytes(ptr);
ptr += mxq::leint_bytes(ptr);
ptr += mxq::leint_bytes(ptr);
uint16_t* status = (uint16_t*)ptr;
rval = (*status) & SERVER_MORE_RESULTS_EXIST;
}
@ -1482,8 +1483,8 @@ void mxs_mysql_parse_ok_packet(GWBUF* buff, size_t packet_offset, size_t packet_
gwbuf_copy_data(buff, packet_offset, packet_len, local_buf);
ptr += (MYSQL_HEADER_LEN + 1); // Header and Command type
mxs_leint_consume(&ptr); // Affected rows
mxs_leint_consume(&ptr); // Last insert-id
mxq::leint_consume(&ptr); // Affected rows
mxq::leint_consume(&ptr); // Last insert-id
uint16_t server_status = gw_mysql_get_byte2(ptr);
ptr += 2; // status
ptr += 2; // number of warnings
@ -1491,19 +1492,18 @@ void mxs_mysql_parse_ok_packet(GWBUF* buff, size_t packet_offset, size_t packet_
if (ptr < (local_buf + packet_len))
{
size_t size;
mxs_lestr_consume(&ptr, &size); // info
mxq::lestr_consume(&ptr, &size); // info
if (server_status & SERVER_SESSION_STATE_CHANGED)
{
MXB_AT_DEBUG(uint64_t data_size = ) mxs_leint_consume(&ptr); // total
MXB_AT_DEBUG(uint64_t data_size = ) mxq::leint_consume(&ptr); // total
// SERVER_SESSION_STATE_CHANGED
// length
mxb_assert(data_size == packet_len - (ptr - local_buf));
while (ptr < (local_buf + packet_len))
{
enum_session_state_type type =
(enum enum_session_state_type)mxs_leint_consume(&ptr);
enum_session_state_type type = (enum enum_session_state_type)mxq::leint_consume(&ptr);
#if defined (SS_DEBUG)
mxb_assert(type <= SESSION_TRACK_TRANSACTION_TYPE);
#endif
@ -1511,30 +1511,30 @@ void mxs_mysql_parse_ok_packet(GWBUF* buff, size_t packet_offset, size_t packet_
{
case SESSION_TRACK_STATE_CHANGE:
case SESSION_TRACK_SCHEMA:
size = mxs_leint_consume(&ptr); // Length of the overall entity.
size = mxq::leint_consume(&ptr); // Length of the overall entity.
ptr += size;
break;
case SESSION_TRACK_GTIDS:
mxs_leint_consume(&ptr); // Length of the overall entity.
mxs_leint_consume(&ptr); // encoding specification
var_value = mxs_lestr_consume_dup(&ptr);
mxq::leint_consume(&ptr); // Length of the overall entity.
mxq::leint_consume(&ptr); // encoding specification
var_value = mxq::lestr_consume_dup(&ptr);
gwbuf_add_property(buff, MXS_LAST_GTID, var_value);
MXS_FREE(var_value);
break;
case SESSION_TRACK_TRANSACTION_CHARACTERISTICS:
mxs_leint_consume(&ptr); // length
var_value = mxs_lestr_consume_dup(&ptr);
mxq::leint_consume(&ptr); // length
var_value = mxq::lestr_consume_dup(&ptr);
gwbuf_add_property(buff, "trx_characteristics", var_value);
MXS_FREE(var_value);
break;
case SESSION_TRACK_SYSTEM_VARIABLES:
mxs_leint_consume(&ptr); // lenth
mxq::leint_consume(&ptr); // lenth
// system variables like autocommit, schema, charset ...
var_name = mxs_lestr_consume_dup(&ptr);
var_value = mxs_lestr_consume_dup(&ptr);
var_name = mxq::lestr_consume_dup(&ptr);
var_value = mxq::lestr_consume_dup(&ptr);
gwbuf_add_property(buff, var_name, var_value);
MXS_DEBUG("SESSION_TRACK_SYSTEM_VARIABLES, name:%s, value:%s", var_name, var_value);
MXS_FREE(var_name);
@ -1542,15 +1542,15 @@ void mxs_mysql_parse_ok_packet(GWBUF* buff, size_t packet_offset, size_t packet_
break;
case SESSION_TRACK_TRANSACTION_TYPE:
mxs_leint_consume(&ptr); // length
trx_info = mxs_lestr_consume_dup(&ptr);
mxq::leint_consume(&ptr); // length
trx_info = mxq::lestr_consume_dup(&ptr);
MXS_DEBUG("get trx_info:%s", trx_info);
gwbuf_add_property(buff, (char*)"trx_state", trx_info);
MXS_FREE(trx_info);
break;
default:
mxs_lestr_consume(&ptr, &size);
mxq::lestr_consume(&ptr, &size);
MXS_WARNING("recieved unexpecting session track type:%d", type);
break;
}

View File

@ -588,7 +588,7 @@ bool Rpl::handle_row_event(REP_HEADER* hdr, uint8_t* ptr)
}
/** Number of columns in the table */
uint64_t ncolumns = mxs_leint_consume(&ptr);
uint64_t ncolumns = mxq::leint_consume(&ptr);
/** If full row image is used, all columns are present. Currently only full
* row image is supported and thus the bitfield should be all ones. In

View File

@ -585,15 +585,15 @@ TableMapEvent* table_map_alloc(uint8_t* ptr, uint8_t hdr_len, TableCreateEvent*
memcpy(table_name, ptr, table_name_len + 1);
ptr += table_name_len + 1;
uint64_t column_count = mxs_leint_value(ptr);
ptr += mxs_leint_bytes(ptr);
uint64_t column_count = mxq::leint_value(ptr);
ptr += mxq::leint_bytes(ptr);
/** Column types */
uint8_t* column_types = ptr;
ptr += column_count;
size_t metadata_size = 0;
uint8_t* metadata = (uint8_t*)mxs_lestr_consume(&ptr, &metadata_size);
uint8_t* metadata = (uint8_t*) mxq::lestr_consume(&ptr, &metadata_size);
uint8_t* nullmap = ptr;
size_t nullmap_size = (column_count + 7) / 8;