MXS-1203: Improve resultset processing functions

The functions used to track the resultset EOF packets now expose the
position of the end of the result set. This allows the modules that use
them to check if more results exist in the same buffer.

Added the status bits for OK and EOF packets to the mysql.h protocol
header. This can be used to check for various state changes that happen in
the session. Currently the status bits are only used to detect if more
results are expected.
This commit is contained in:
Markus Mäkelä
2017-04-03 14:40:06 +03:00
parent a1c7ee438d
commit d7258fffd0
5 changed files with 131 additions and 75 deletions

View File

@ -48,6 +48,7 @@
#include <maxscale/log_manager.h>
#include <netinet/tcp.h>
#include <maxscale/modutil.h>
#include <maxscale/mysql_utils.h>
uint8_t null_client_sha1[MYSQL_SCRAMBLE_LEN] = "";
@ -966,7 +967,7 @@ char *create_auth_fail_str(char *username,
if (db_len > 0)
{
sprintf(errstr, ferrstr, username, hostaddr, password ? "YES": "NO", db);
sprintf(errstr, ferrstr, username, hostaddr, password ? "YES" : "NO", db);
}
else if (errcode == MXS_AUTH_FAILED_SSL)
{
@ -1537,12 +1538,12 @@ bool mxs_mysql_is_ok_packet(GWBUF *buffer)
return rval;
}
bool mxs_mysql_is_result_set(GWBUF *buffer)
bool mxs_mysql_is_result_set(GWBUF *buffer, size_t offset)
{
bool rval = false;
uint8_t cmd;
if (gwbuf_copy_data(buffer, MYSQL_HEADER_LEN, 1, &cmd))
if (gwbuf_copy_data(buffer, offset + MYSQL_HEADER_LEN, 1, &cmd))
{
switch (cmd)
{
@ -1563,6 +1564,51 @@ bool mxs_mysql_is_result_set(GWBUF *buffer)
return rval;
}
bool mxs_mysql_more_results_after_ok(GWBUF *buffer, size_t extra_offset)
{
bool rval = false;
size_t buflen = gwbuf_length(buffer);
size_t offset = extra_offset;
while (offset < buflen)
{
// Copy the header
uint8_t header[MYSQL_HEADER_LEN + 1];
if (gwbuf_copy_data(buffer, offset, sizeof(header), header) != sizeof(header))
{
break;
}
size_t len = gw_mysql_get_byte3(header);
if (header[4] == MYSQL_REPLY_OK)
{
// Copy the payload without the command byte
uint8_t data[len - 1];
gwbuf_copy_data(buffer, offset + MYSQL_HEADER_LEN + 1, sizeof(data), data);
uint8_t* ptr = data;
ptr += mxs_leint_bytes(ptr);
ptr += mxs_leint_bytes(ptr);
uint16_t* status = (uint16_t*)ptr;
rval = (*status) & MXS_MYSQL_MORE_RESULTS_EXISTS;
}
else
{
break;
}
offset += len + MYSQL_HEADER_LEN;
if (offset < buflen)
{
MXS_DEBUG("More data after an OK packet, expecting results: %s", rval ? "YES" : "NO");
}
}
return rval;
}
mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session)
{
MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol;