Reindented server/core/modutil.c

This commit is contained in:
Johan Wikman
2015-11-30 15:30:16 +02:00
parent 17eb80072f
commit c0615408aa
2 changed files with 507 additions and 490 deletions

View File

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

View File

@ -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);
int modutil_count_statements(GWBUF* buffer);
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 merrno,
const char *statemsg,
const char *msg);
int modutil_count_signal_packets(GWBUF*,int,int,int*);
mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string);
#endif