Reindented server/core/modutil.c
This commit is contained in:
@ -66,7 +66,9 @@ modutil_is_SQL(GWBUF *buf)
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
|
|
||||||
if (GWBUF_LENGTH(buf) < 5)
|
if (GWBUF_LENGTH(buf) < 5)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(buf);
|
ptr = GWBUF_DATA(buf);
|
||||||
return ptr[4] == 0x03; // COM_QUERY
|
return ptr[4] == 0x03; // COM_QUERY
|
||||||
}
|
}
|
||||||
@ -83,7 +85,9 @@ modutil_is_SQL_prepare(GWBUF *buf)
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
|
|
||||||
if (GWBUF_LENGTH(buf) < 5)
|
if (GWBUF_LENGTH(buf) < 5)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(buf);
|
ptr = GWBUF_DATA(buf);
|
||||||
return ptr[4] == 0x16 ; // COM_STMT_PREPARE
|
return ptr[4] == 0x16 ; // COM_STMT_PREPARE
|
||||||
}
|
}
|
||||||
@ -112,7 +116,9 @@ modutil_extract_SQL(GWBUF *buf, char **sql, int *length)
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
|
|
||||||
if (!modutil_is_SQL(buf))
|
if (!modutil_is_SQL(buf))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(buf);
|
ptr = GWBUF_DATA(buf);
|
||||||
*length = *ptr++;
|
*length = *ptr++;
|
||||||
*length += (*ptr++ << 8);
|
*length += (*ptr++ << 8);
|
||||||
@ -147,7 +153,9 @@ modutil_MySQL_Query(GWBUF *buf, char **sql, int *length, int *residual)
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
|
|
||||||
if (!modutil_is_SQL(buf))
|
if (!modutil_is_SQL(buf))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(buf);
|
ptr = GWBUF_DATA(buf);
|
||||||
*residual = *ptr++;
|
*residual = *ptr++;
|
||||||
*residual += (*ptr++ << 8);
|
*residual += (*ptr++ << 8);
|
||||||
@ -173,9 +181,7 @@ unsigned char *ptr;
|
|||||||
* @return the length of MySQL packet and writes missing bytecount to
|
* @return the length of MySQL packet and writes missing bytecount to
|
||||||
* nbytes_missing.
|
* nbytes_missing.
|
||||||
*/
|
*/
|
||||||
int modutil_MySQL_query_len(
|
int modutil_MySQL_query_len(GWBUF* buf, int* nbytes_missing)
|
||||||
GWBUF* buf,
|
|
||||||
int* nbytes_missing)
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
int buflen;
|
int buflen;
|
||||||
@ -213,7 +219,9 @@ int length, newlength;
|
|||||||
GWBUF *addition;
|
GWBUF *addition;
|
||||||
|
|
||||||
if (!modutil_is_SQL(orig))
|
if (!modutil_is_SQL(orig))
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(orig);
|
ptr = GWBUF_DATA(orig);
|
||||||
length = *ptr++;
|
length = *ptr++;
|
||||||
length += (*ptr++ << 8);
|
length += (*ptr++ << 8);
|
||||||
@ -270,14 +278,18 @@ unsigned char *ptr;
|
|||||||
char *dptr, *rval = NULL;
|
char *dptr, *rval = NULL;
|
||||||
|
|
||||||
if (!modutil_is_SQL(buf) && !modutil_is_SQL_prepare(buf))
|
if (!modutil_is_SQL(buf) && !modutil_is_SQL_prepare(buf))
|
||||||
|
{
|
||||||
return rval;
|
return rval;
|
||||||
|
}
|
||||||
ptr = GWBUF_DATA(buf);
|
ptr = GWBUF_DATA(buf);
|
||||||
length = *ptr++;
|
length = *ptr++;
|
||||||
length += (*ptr++ << 8);
|
length += (*ptr++ << 8);
|
||||||
length += (*ptr++ << 16);
|
length += (*ptr++ << 16);
|
||||||
|
|
||||||
if ((rval = (char *)malloc(length + 1)) == NULL)
|
if ((rval = (char *)malloc(length + 1)) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
dptr = rval;
|
dptr = rval;
|
||||||
ptr += 2; // Skip sequence id and COM_QUERY byte
|
ptr += 2; // Skip sequence id and COM_QUERY byte
|
||||||
len = GWBUF_LENGTH(buf) - 5;
|
len = GWBUF_LENGTH(buf) - 5;
|
||||||
@ -317,7 +329,8 @@ modutil_get_query(GWBUF *buf)
|
|||||||
packet = GWBUF_DATA(buf);
|
packet = GWBUF_DATA(buf);
|
||||||
packet_type = packet[4];
|
packet_type = packet[4];
|
||||||
|
|
||||||
switch (packet_type) {
|
switch (packet_type)
|
||||||
|
{
|
||||||
case MYSQL_COM_QUIT:
|
case MYSQL_COM_QUIT:
|
||||||
len = strlen("[Quit msg]") + 1;
|
len = strlen("[Quit msg]") + 1;
|
||||||
if ((query_str = (char *)malloc(len + 1)) == NULL)
|
if ((query_str = (char *)malloc(len + 1)) == NULL)
|
||||||
@ -363,8 +376,7 @@ retblock:
|
|||||||
* @param mysql_message The Error Message
|
* @param mysql_message The Error Message
|
||||||
* @return The allocated GWBUF or NULL on failure
|
* @return The allocated GWBUF or NULL on failure
|
||||||
*/
|
*/
|
||||||
GWBUF *modutil_create_mysql_err_msg(
|
GWBUF *modutil_create_mysql_err_msg(int packet_number,
|
||||||
int packet_number,
|
|
||||||
int affected_rows,
|
int affected_rows,
|
||||||
int merrno,
|
int merrno,
|
||||||
const char *statemsg,
|
const char *statemsg,
|
||||||
@ -453,8 +465,7 @@ GWBUF *modutil_create_mysql_err_msg(
|
|||||||
* @return 0 for successful dcb write or 1 on failure
|
* @return 0 for successful dcb write or 1 on failure
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int modutil_send_mysql_err_packet (
|
int modutil_send_mysql_err_packet(DCB *dcb,
|
||||||
DCB *dcb,
|
|
||||||
int packet_number,
|
int packet_number,
|
||||||
int in_affected_rows,
|
int in_affected_rows,
|
||||||
int mysql_errno,
|
int mysql_errno,
|
||||||
@ -463,7 +474,8 @@ int modutil_send_mysql_err_packet (
|
|||||||
{
|
{
|
||||||
GWBUF* buf;
|
GWBUF* buf;
|
||||||
|
|
||||||
buf = modutil_create_mysql_err_msg(packet_number, in_affected_rows, mysql_errno, sqlstate_msg, mysql_message);
|
buf = modutil_create_mysql_err_msg(packet_number, in_affected_rows, mysql_errno,
|
||||||
|
sqlstate_msg, mysql_message);
|
||||||
|
|
||||||
return dcb->func.write(dcb, buf);
|
return dcb->func.write(dcb, buf);
|
||||||
}
|
}
|
||||||
@ -475,8 +487,7 @@ int modutil_send_mysql_err_packet (
|
|||||||
* return pointer to gwbuf containing a complete packet or
|
* return pointer to gwbuf containing a complete packet or
|
||||||
* NULL if no complete packet was found.
|
* NULL if no complete packet was found.
|
||||||
*/
|
*/
|
||||||
GWBUF* modutil_get_next_MySQL_packet(
|
GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf)
|
||||||
GWBUF** p_readbuf)
|
|
||||||
{
|
{
|
||||||
GWBUF* packetbuf;
|
GWBUF* packetbuf;
|
||||||
GWBUF* readbuf;
|
GWBUF* readbuf;
|
||||||
@ -552,7 +563,9 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf)
|
|||||||
|
|
||||||
if (p_readbuf == NULL || (*p_readbuf) == NULL ||
|
if (p_readbuf == NULL || (*p_readbuf) == NULL ||
|
||||||
gwbuf_length(*p_readbuf) < 3)
|
gwbuf_length(*p_readbuf) < 3)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
packet = gwbuf_make_contiguous(*p_readbuf);
|
packet = gwbuf_make_contiguous(*p_readbuf);
|
||||||
packet->next = NULL;
|
packet->next = NULL;
|
||||||
@ -625,7 +638,6 @@ modutil_count_signal_packets(GWBUF *reply, int use_ok, int n_found, int* more)
|
|||||||
bool moreresults = false;
|
bool moreresults = false;
|
||||||
while (ptr < end)
|
while (ptr < end)
|
||||||
{
|
{
|
||||||
|
|
||||||
pktlen = MYSQL_GET_PACKET_LEN(ptr) + 4;
|
pktlen = MYSQL_GET_PACKET_LEN(ptr) + 4;
|
||||||
|
|
||||||
if ((iserr = PTR_IS_ERR(ptr)) || (iseof = PTR_IS_EOF(ptr)))
|
if ((iserr = PTR_IS_ERR(ptr)) || (iseof = PTR_IS_EOF(ptr)))
|
||||||
@ -664,15 +676,19 @@ modutil_count_signal_packets(GWBUF *reply, int use_ok, int n_found, int* more)
|
|||||||
{
|
{
|
||||||
ptr -= errlen;
|
ptr -= errlen;
|
||||||
if (!PTR_IS_ERR(ptr))
|
if (!PTR_IS_ERR(ptr))
|
||||||
|
{
|
||||||
err = 0;
|
err = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr -= eoflen;
|
ptr -= eoflen;
|
||||||
if (!PTR_IS_EOF(ptr))
|
if (!PTR_IS_EOF(ptr))
|
||||||
|
{
|
||||||
eof = 0;
|
eof = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*more = moreresults;
|
*more = moreresults;
|
||||||
|
|
||||||
@ -688,8 +704,7 @@ modutil_count_signal_packets(GWBUF *reply, int use_ok, int n_found, int* more)
|
|||||||
* @param errstr Plain-text string error
|
* @param errstr Plain-text string error
|
||||||
* @param flags GWBUF type flags
|
* @param flags GWBUF type flags
|
||||||
*/
|
*/
|
||||||
void modutil_reply_parse_error(
|
void modutil_reply_parse_error(DCB* backend_dcb,
|
||||||
DCB* backend_dcb,
|
|
||||||
char* errstr,
|
char* errstr,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
@ -706,8 +721,7 @@ void modutil_reply_parse_error(
|
|||||||
* @param errstr Plain-text string error
|
* @param errstr Plain-text string error
|
||||||
* @param flags GWBUF type flags
|
* @param flags GWBUF type flags
|
||||||
*/
|
*/
|
||||||
void modutil_reply_auth_error(
|
void modutil_reply_auth_error(DCB* backend_dcb,
|
||||||
DCB* backend_dcb,
|
|
||||||
char* errstr,
|
char* errstr,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
@ -727,8 +741,7 @@ void modutil_reply_auth_error(
|
|||||||
* @param errstr Plain-text string error
|
* @param errstr Plain-text string error
|
||||||
* @param flags GWBUF type flags
|
* @param flags GWBUF type flags
|
||||||
*/
|
*/
|
||||||
static void modutil_reply_routing_error(
|
static void modutil_reply_routing_error(DCB* backend_dcb,
|
||||||
DCB* backend_dcb,
|
|
||||||
int error,
|
int error,
|
||||||
char* state,
|
char* state,
|
||||||
char* errstr,
|
char* errstr,
|
||||||
@ -805,7 +818,9 @@ void* strnchr_esc(char* ptr,char c, int len)
|
|||||||
GWBUF* modutil_create_query(char* query)
|
GWBUF* modutil_create_query(char* query)
|
||||||
{
|
{
|
||||||
if (query == NULL)
|
if (query == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GWBUF* rval = gwbuf_alloc(strlen(query) + 5);
|
GWBUF* rval = gwbuf_alloc(strlen(query) + 5);
|
||||||
int pktlen = strlen(query) + 1;
|
int pktlen = strlen(query) + 1;
|
||||||
@ -841,12 +856,16 @@ int modutil_count_statements(GWBUF* buffer)
|
|||||||
{
|
{
|
||||||
num++;
|
num++;
|
||||||
while (*ptr == ';')
|
while (*ptr == ';')
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ptr = end - 1;
|
ptr = end - 1;
|
||||||
while (isspace(*ptr))
|
while (isspace(*ptr))
|
||||||
|
{
|
||||||
ptr--;
|
ptr--;
|
||||||
|
}
|
||||||
|
|
||||||
if (*ptr == ';')
|
if (*ptr == ';')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -60,14 +60,12 @@ void modutil_reply_parse_error(DCB* backend_dcb, char* errstr, uint32_t flags)
|
|||||||
void modutil_reply_auth_error(DCB* backend_dcb, char* errstr, uint32_t flags);
|
void modutil_reply_auth_error(DCB* backend_dcb, char* errstr, uint32_t flags);
|
||||||
int modutil_count_statements(GWBUF* buffer);
|
int modutil_count_statements(GWBUF* buffer);
|
||||||
GWBUF* modutil_create_query(char* query);
|
GWBUF* modutil_create_query(char* query);
|
||||||
|
GWBUF* modutil_create_mysql_err_msg(int packet_number,
|
||||||
GWBUF *modutil_create_mysql_err_msg(
|
|
||||||
int packet_number,
|
|
||||||
int affected_rows,
|
int affected_rows,
|
||||||
int merrno,
|
int merrno,
|
||||||
const char *statemsg,
|
const char *statemsg,
|
||||||
const char *msg);
|
const char *msg);
|
||||||
|
|
||||||
int modutil_count_signal_packets(GWBUF*,int,int,int*);
|
int modutil_count_signal_packets(GWBUF*,int,int,int*);
|
||||||
mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string);
|
mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user