Make modutil_create_query parameters const

The parameters to modutil_create_query are not modified so they can be
declared const.
This commit is contained in:
Markus Mäkelä
2016-12-19 10:11:06 +02:00
parent cfaf03de3c
commit 875766cf62
3 changed files with 12 additions and 18 deletions

View File

@ -57,7 +57,7 @@ int modutil_MySQL_query_len(GWBUF* buf, int* nbytes_missing);
void modutil_reply_parse_error(DCB* backend_dcb, char* errstr, uint32_t flags); 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(const 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,

View File

@ -987,25 +987,20 @@ bool is_mysql_sp_end(const char* start, int len)
/** /**
* Create a COM_QUERY packet from a string. * Create a COM_QUERY packet from a string.
* @param query Query to create. * @param query Query to create.
* @return Pointer to GWBUF with the query or NULL if an error occurred. * @return Pointer to GWBUF with the query or NULL if memory allocation failed
*/ */
GWBUF* modutil_create_query(char* query) GWBUF* modutil_create_query(const char* query)
{ {
if (query == NULL) ss_dassert(query);
{ size_t len = strlen(query) + 1; // Query plus the command byte
return NULL; GWBUF* rval = gwbuf_alloc(len + MYSQL_HEADER_LEN);
}
GWBUF* rval = gwbuf_alloc(strlen(query) + 5);
int pktlen = strlen(query) + 1;
unsigned char* ptr;
if (rval) if (rval)
{ {
ptr = (unsigned char*)rval->start; uint8_t *ptr = (uint8_t*)rval->start;
*ptr++ = (pktlen); *ptr++ = (len);
*ptr++ = (pktlen) >> 8; *ptr++ = (len) >> 8;
*ptr++ = (pktlen) >> 16; *ptr++ = (len) >> 16;
*ptr++ = 0x0; *ptr++ = 0x0;
*ptr++ = 0x03; *ptr++ = 0x03;
memcpy(ptr, query, strlen(query)); memcpy(ptr, query, strlen(query));

View File

@ -587,7 +587,7 @@ static int routeQuery(FILTER *instance, void *session, GWBUF *queue)
if (lua_isstring(my_session->lua_state, -1)) if (lua_isstring(my_session->lua_state, -1))
{ {
gwbuf_free(forward); gwbuf_free(forward);
forward = modutil_create_query((char*)lua_tostring(my_session->lua_state, -1)); forward = modutil_create_query(lua_tostring(my_session->lua_state, -1));
} }
else if (lua_isboolean(my_session->lua_state, -1)) else if (lua_isboolean(my_session->lua_state, -1))
{ {
@ -622,8 +622,7 @@ static int routeQuery(FILTER *instance, void *session, GWBUF *queue)
if (lua_isstring(my_instance->global_lua_state, -1)) if (lua_isstring(my_instance->global_lua_state, -1))
{ {
gwbuf_free(forward); gwbuf_free(forward);
forward = modutil_create_query((char*) forward = modutil_create_query(lua_tostring(my_instance->global_lua_state, -1));
lua_tostring(my_instance->global_lua_state, -1));
} }
else if (lua_isboolean(my_instance->global_lua_state, -1)) else if (lua_isboolean(my_instance->global_lua_state, -1))
{ {