Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the users of the library. The fact that the protocol, and other, modules used it was in violation of how the library is intended to be used. Adding an internal mapping into MaxScale also removes some of the dependencies that the core has on the connector.
This commit is contained in:
@ -387,7 +387,7 @@ static inline void prepare_for_write(DCB *dcb, GWBUF *buffer)
|
||||
|
||||
if (GWBUF_IS_TYPE_SESCMD(buffer))
|
||||
{
|
||||
mysql_server_cmd_t cmd = mxs_mysql_get_command(buffer);
|
||||
mxs_mysql_cmd_t cmd = mxs_mysql_get_command(buffer);
|
||||
protocol_add_srv_command(proto, cmd);
|
||||
}
|
||||
if (GWBUF_SHOULD_COLLECT_RESULT(buffer))
|
||||
@ -616,13 +616,13 @@ static inline bool session_ok_to_route(DCB *dcb)
|
||||
|
||||
static inline bool expecting_resultset(MySQLProtocol *proto)
|
||||
{
|
||||
return proto->current_command == MYSQL_COM_QUERY ||
|
||||
proto->current_command == MYSQL_COM_STMT_FETCH;
|
||||
return proto->current_command == MXS_COM_QUERY ||
|
||||
proto->current_command == MXS_COM_STMT_FETCH;
|
||||
}
|
||||
|
||||
static inline bool expecting_ps_response(MySQLProtocol *proto)
|
||||
{
|
||||
return proto->current_command == MYSQL_COM_STMT_PREPARE;
|
||||
return proto->current_command == MXS_COM_STMT_PREPARE;
|
||||
}
|
||||
|
||||
static inline bool complete_ps_response(GWBUF *buffer)
|
||||
@ -887,7 +887,7 @@ gw_read_and_write(DCB *dcb)
|
||||
* If protocol has session command set, concatenate whole
|
||||
* response into one buffer.
|
||||
*/
|
||||
if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, true) != MYSQL_COM_UNDEFINED)
|
||||
if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, true) != MXS_COM_UNDEFINED)
|
||||
{
|
||||
if (result_collected)
|
||||
{
|
||||
@ -1139,14 +1139,14 @@ static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
|
||||
case MXS_AUTH_STATE_COMPLETE:
|
||||
{
|
||||
uint8_t* ptr = GWBUF_DATA(queue);
|
||||
mysql_server_cmd_t cmd = mxs_mysql_get_command(queue);
|
||||
mxs_mysql_cmd_t cmd = mxs_mysql_get_command(queue);
|
||||
|
||||
MXS_DEBUG("write to dcb %p fd %d protocol state %s.",
|
||||
dcb, dcb->fd, STRPROTOCOLSTATE(backend_protocol->protocol_auth_state));
|
||||
|
||||
prepare_for_write(dcb, queue);
|
||||
|
||||
if (cmd == MYSQL_COM_QUIT && dcb->server->persistpoolmax)
|
||||
if (cmd == MXS_COM_QUIT && dcb->server->persistpoolmax)
|
||||
{
|
||||
/** We need to keep the pooled connections alive so we just ignore the COM_QUIT packet */
|
||||
gwbuf_free(queue);
|
||||
@ -1538,7 +1538,7 @@ static int gw_change_user(DCB *backend,
|
||||
* packet and add it to client's read buffer.
|
||||
*/
|
||||
protocol_add_srv_command((MySQLProtocol*)backend->protocol,
|
||||
MYSQL_COM_CHANGE_USER);
|
||||
MXS_COM_CHANGE_USER);
|
||||
modutil_reply_auth_error(backend, message, 0);
|
||||
rv = 1;
|
||||
}
|
||||
@ -1601,7 +1601,7 @@ static GWBUF* process_response_data(DCB* dcb,
|
||||
*/
|
||||
while (nbytes_to_process != 0)
|
||||
{
|
||||
mysql_server_cmd_t srvcmd;
|
||||
mxs_mysql_cmd_t srvcmd;
|
||||
bool succp;
|
||||
|
||||
srvcmd = protocol_get_srv_command(p, false);
|
||||
|
@ -808,7 +808,7 @@ static bool process_client_commands(DCB* dcb, int bytes_available, GWBUF** buffe
|
||||
if (protocol_is_idle(dcb))
|
||||
{
|
||||
int pktlen;
|
||||
uint8_t cmd = (uint8_t)MYSQL_COM_QUERY; // Treat empty packets as COM_QUERY
|
||||
uint8_t cmd = (uint8_t)MXS_COM_QUERY; // Treat empty packets as COM_QUERY
|
||||
|
||||
/**
|
||||
* Buffer has at least 5 bytes, the packet is in contiguous memory
|
||||
@ -861,7 +861,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 = (mysql_server_cmd_t)cmd;
|
||||
proto->current_command = (mxs_mysql_cmd_t)cmd;
|
||||
}
|
||||
|
||||
dcb->protocol_packet_length = pktlen + MYSQL_HEADER_LEN;
|
||||
@ -1041,7 +1041,7 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities)
|
||||
/** Reset error handler when routing of the new query begins */
|
||||
dcb->dcb_errhandle_called = false;
|
||||
|
||||
if (proto->current_command == MYSQL_COM_QUIT)
|
||||
if (proto->current_command == MXS_COM_QUIT)
|
||||
{
|
||||
/** The client is closing the connection. We know that this will be the
|
||||
* last command the client sends so the backend connections are very likely
|
||||
@ -1089,7 +1089,7 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities)
|
||||
MXS_ERROR("Routing the query failed. Session will be closed.");
|
||||
}
|
||||
|
||||
if (proto->current_command == MYSQL_COM_QUIT)
|
||||
if (proto->current_command == MXS_COM_QUIT)
|
||||
{
|
||||
/** Close router session which causes closing of backends */
|
||||
dcb_close(dcb);
|
||||
@ -1458,7 +1458,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF
|
||||
CHK_GWBUF(packetbuf);
|
||||
|
||||
MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol;
|
||||
proto->current_command = (mysql_server_cmd_t)mxs_mysql_get_command(packetbuf);
|
||||
proto->current_command = (mxs_mysql_cmd_t)mxs_mysql_get_command(packetbuf);
|
||||
|
||||
/**
|
||||
* This means that buffer includes exactly one MySQL
|
||||
@ -1500,7 +1500,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF
|
||||
session_set_trx_state(session, SESSION_TRX_INACTIVE);
|
||||
}
|
||||
|
||||
if (mxs_mysql_get_command(packetbuf) == MYSQL_COM_QUERY)
|
||||
if (mxs_mysql_get_command(packetbuf) == MXS_COM_QUERY)
|
||||
{
|
||||
uint32_t type = qc_get_trx_type_mask(packetbuf);
|
||||
|
||||
@ -1635,7 +1635,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int
|
||||
MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol;
|
||||
uint8_t opt;
|
||||
|
||||
if (proto->current_command == MYSQL_COM_SET_OPTION &&
|
||||
if (proto->current_command == MXS_COM_SET_OPTION &&
|
||||
gwbuf_copy_data(read_buffer, MYSQL_HEADER_LEN + 2, 1, &opt))
|
||||
{
|
||||
if (opt)
|
||||
@ -1650,7 +1650,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int
|
||||
/**
|
||||
* Handle COM_PROCESS_KILL
|
||||
*/
|
||||
else if (proto->current_command == MYSQL_COM_PROCESS_KILL)
|
||||
else if (proto->current_command == MXS_COM_PROCESS_KILL)
|
||||
{
|
||||
/* Make sure we have a complete SQL packet before trying to read the
|
||||
* process id. If not, try again next time. */
|
||||
@ -1672,7 +1672,7 @@ static spec_com_res_t process_special_commands(DCB *dcb, GWBUF *read_buffer, int
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (proto->current_command == MYSQL_COM_QUERY)
|
||||
else if (proto->current_command == MXS_COM_QUERY)
|
||||
{
|
||||
/* Limits on the length of the queries in which "KILL" is searched for. Reducing
|
||||
* LONGEST_KILL will reduce overhead but also limit the range of accepted queries. */
|
||||
|
@ -115,7 +115,7 @@ public:
|
||||
|
||||
uint8_t command = pPayload[0];
|
||||
|
||||
if (command == MYSQL_COM_QUERY)
|
||||
if (command == MXS_COM_QUERY)
|
||||
{
|
||||
const uint8_t* pStmt = &pPayload[1];
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
uint8_t null_client_sha1[MYSQL_SCRAMBLE_LEN] = "";
|
||||
|
||||
static server_command_t* server_command_init(server_command_t* srvcmd, mysql_server_cmd_t cmd);
|
||||
static server_command_t* server_command_init(server_command_t* srvcmd, mxs_mysql_cmd_t cmd);
|
||||
|
||||
/**
|
||||
* @brief Allocate a new MySQL_session
|
||||
@ -74,8 +74,8 @@ MySQLProtocol* mysql_protocol_init(DCB* dcb, int fd)
|
||||
}
|
||||
p->protocol_state = MYSQL_PROTOCOL_ALLOC;
|
||||
p->protocol_auth_state = MXS_AUTH_STATE_INIT;
|
||||
p->current_command = MYSQL_COM_UNDEFINED;
|
||||
p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED;
|
||||
p->current_command = MXS_COM_UNDEFINED;
|
||||
p->protocol_command.scom_cmd = MXS_COM_UNDEFINED;
|
||||
p->protocol_command.scom_nresponse_packets = 0;
|
||||
p->protocol_command.scom_nbytes_to_read = 0;
|
||||
p->stored_query = NULL;
|
||||
@ -584,7 +584,7 @@ GWBUF* gw_MySQL_get_packets(GWBUF** p_srcbuf,
|
||||
|
||||
|
||||
static server_command_t* server_command_init(server_command_t* srvcmd,
|
||||
mysql_server_cmd_t cmd)
|
||||
mxs_mysql_cmd_t cmd)
|
||||
{
|
||||
server_command_t* c;
|
||||
|
||||
@ -667,7 +667,7 @@ void protocol_archive_srv_command(MySQLProtocol* p)
|
||||
/** Remove from command list */
|
||||
if (s1->scom_next == NULL)
|
||||
{
|
||||
p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED;
|
||||
p->protocol_command.scom_cmd = MXS_COM_UNDEFINED;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -685,7 +685,7 @@ retblock:
|
||||
* to MySQLProtocol structure. It is removed when response has arrived.
|
||||
*/
|
||||
void protocol_add_srv_command(MySQLProtocol* p,
|
||||
mysql_server_cmd_t cmd)
|
||||
mxs_mysql_cmd_t cmd)
|
||||
{
|
||||
#if defined(EXTRA_SS_DEBUG)
|
||||
server_command_t* c;
|
||||
@ -696,7 +696,7 @@ void protocol_add_srv_command(MySQLProtocol* p,
|
||||
return;
|
||||
}
|
||||
/** this is the only server command in protocol */
|
||||
if (p->protocol_command.scom_cmd == MYSQL_COM_UNDEFINED)
|
||||
if (p->protocol_command.scom_cmd == MXS_COM_UNDEFINED)
|
||||
{
|
||||
/** write into structure */
|
||||
server_command_init(&p->protocol_command, cmd);
|
||||
@ -713,7 +713,7 @@ void protocol_add_srv_command(MySQLProtocol* p,
|
||||
|
||||
c = &p->protocol_command;
|
||||
|
||||
while (c != NULL && c->scom_cmd != MYSQL_COM_UNDEFINED)
|
||||
while (c != NULL && c->scom_cmd != MXS_COM_UNDEFINED)
|
||||
{
|
||||
MXS_INFO("fd %d : %d %s",
|
||||
p->owner_dcb->fd,
|
||||
@ -743,7 +743,7 @@ void protocol_remove_srv_command(MySQLProtocol* p)
|
||||
#endif
|
||||
if (s->scom_next == NULL)
|
||||
{
|
||||
p->protocol_command.scom_cmd = MYSQL_COM_UNDEFINED;
|
||||
p->protocol_command.scom_cmd = MXS_COM_UNDEFINED;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -752,10 +752,10 @@ void protocol_remove_srv_command(MySQLProtocol* p)
|
||||
}
|
||||
}
|
||||
|
||||
mysql_server_cmd_t protocol_get_srv_command(MySQLProtocol* p,
|
||||
mxs_mysql_cmd_t protocol_get_srv_command(MySQLProtocol* p,
|
||||
bool removep)
|
||||
{
|
||||
mysql_server_cmd_t cmd;
|
||||
mxs_mysql_cmd_t cmd;
|
||||
|
||||
cmd = p->protocol_command.scom_cmd;
|
||||
|
||||
@ -784,7 +784,7 @@ void mysql_num_response_packets(GWBUF *buf, uint8_t cmd, int *npackets, size_t *
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case MYSQL_COM_STMT_PREPARE:
|
||||
case MXS_COM_STMT_PREPARE:
|
||||
gwbuf_copy_data(buf, 9, 2, readbuf);
|
||||
nparam = gw_mysql_get_byte2(readbuf);
|
||||
gwbuf_copy_data(buf, 11, 2, readbuf);
|
||||
@ -792,9 +792,9 @@ void mysql_num_response_packets(GWBUF *buf, uint8_t cmd, int *npackets, size_t *
|
||||
*npackets = 1 + nparam + MXS_MIN(1, nparam) + nattr + MXS_MIN(nattr, 1);
|
||||
break;
|
||||
|
||||
case MYSQL_COM_QUIT:
|
||||
case MYSQL_COM_STMT_SEND_LONG_DATA:
|
||||
case MYSQL_COM_STMT_CLOSE:
|
||||
case MXS_COM_QUIT:
|
||||
case MXS_COM_STMT_SEND_LONG_DATA:
|
||||
case MXS_COM_STMT_CLOSE:
|
||||
*npackets = 0; /*< these don't reply anything */
|
||||
break;
|
||||
|
||||
@ -1611,7 +1611,7 @@ bool mxs_mysql_more_results_after_ok(GWBUF *buffer)
|
||||
return rval;
|
||||
}
|
||||
|
||||
mysql_server_cmd_t mxs_mysql_current_command(MXS_SESSION* session)
|
||||
mxs_mysql_cmd_t mxs_mysql_current_command(MXS_SESSION* session)
|
||||
{
|
||||
MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol;
|
||||
return proto->current_command;
|
||||
@ -1681,8 +1681,8 @@ uint32_t mxs_mysql_extract_ps_id(GWBUF* buffer)
|
||||
|
||||
bool mxs_mysql_command_will_respond(uint8_t cmd)
|
||||
{
|
||||
return cmd != MYSQL_COM_STMT_SEND_LONG_DATA &&
|
||||
cmd != MYSQL_COM_QUIT &&
|
||||
cmd != MYSQL_COM_STMT_CLOSE &&
|
||||
cmd != MYSQL_COM_STMT_FETCH;
|
||||
return cmd != MXS_COM_STMT_SEND_LONG_DATA &&
|
||||
cmd != MXS_COM_QUIT &&
|
||||
cmd != MXS_COM_STMT_CLOSE &&
|
||||
cmd != MXS_COM_STMT_FETCH;
|
||||
}
|
||||
|
Reference in New Issue
Block a user