Code clean up for issue #14

pull/190/head
René Cannaò 12 years ago
parent 7b5b95d0d4
commit 66a4b4481b

@ -172,6 +172,58 @@ typedef struct _main_args {
/*
* returns false if the command is a valid one and is processed
* return true if the command is not a valid one and needs to be executed by SQLite (that will return an error)
*/
bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_space_length, MySQL_Session *sess, ProxySQL_Admin *pa) {
if (query_no_space_length==strlen("PROXYSQL START") && !strncasecmp("PROXYSQL START",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL START command\n");
Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa;
bool rc=false;
if (nostart_) {
rc=__sync_bool_compare_and_swap(&GloVars.global.nostart,1,0);
}
if (rc) {
//nostart_=false;
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Starting ProxySQL following PROXYSQL START command\n");
SPA->send_MySQL_OK(&sess->myprot_client, NULL);
} else {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "ProxySQL was already started when received PROXYSQL START command\n");
SPA->send_MySQL_ERR(&sess->myprot_client, (char *)"ProxySQL already started");
}
return false;
}
if (query_no_space_length==strlen("PROXYSQL RESTART") && !strncasecmp("PROXYSQL RESTART",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL RESTART command\n");
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=1;
return false;
}
if (query_no_space_length==strlen("PROXYSQL STOP") && !strncasecmp("PROXYSQL STOP",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL STOP command\n");
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=2;
return false;
}
if (query_no_space_length==strlen("PROXYSQL SHUTDOWN") && !strncasecmp("PROXYSQL SHUTDOWN",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL SHUTDOWN command\n");
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=0;
return false;
}
if (query_no_space_length==strlen("PROXYSQL KILL") && !strncasecmp("PROXYSQL KILL",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL KILL command\n");
exit(EXIT_SUCCESS);
}
return true;
}
void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *pkt) {
char *error=NULL;
@ -197,65 +249,18 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p
if ((query_no_space_length>8) && (!strncmp("PROXYSQL ", query_no_space, 8))) {
if ((query_no_space_length>8) && (!strncasecmp("PROXYSQL ", query_no_space, 8))) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL command\n");
if (query_no_space_length==strlen("PROXYSQL START") && !strncasecmp("PROXYSQL START",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL START command\n");
run_query=false;
Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa;
bool rc=false;
if (nostart_) {
rc=__sync_bool_compare_and_swap(&GloVars.global.nostart,1,0);
}
if (rc) {
//nostart_=false;
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Starting ProxySQL following PROXYSQL START command\n");
SPA->send_MySQL_OK(&sess->myprot_client, NULL);
} else {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "ProxySQL was already started when received PROXYSQL START command\n");
SPA->send_MySQL_ERR(&sess->myprot_client, (char *)"ProxySQL already started");
}
goto __run_query;
}
if (query_no_space_length==strlen("PROXYSQL RESTART") && !strncasecmp("PROXYSQL RESTART",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL RESTART command\n");
run_query=false;
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=1;
goto __run_query;
}
if (query_no_space_length==strlen("PROXYSQL STOP") && !strncasecmp("PROXYSQL STOP",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL STOP command\n");
run_query=false;
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=2;
goto __run_query;
}
if (query_no_space_length==strlen("PROXYSQL SHUTDOWN") && !strncasecmp("PROXYSQL SHUTDOWN",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL SHUTDOWN command\n");
run_query=false;
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
glovars.reload=0;
goto __run_query;
}
if (query_no_space_length==strlen("PROXYSQL KILL") && !strncasecmp("PROXYSQL KILL",query_no_space, query_no_space_length)) {
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received PROXYSQL KILL command\n");
exit(EXIT_SUCCESS);
}
if (query_no_space_length==strlen("SHOW TABLES") && !strncasecmp("SHOW TABLES",query_no_space, query_no_space_length)) {
l_free(query_length,query);
query=l_strdup("SELECT name AS tables FROM sqlite_master WHERE type='table'");
query_length=strlen(query)+1;
goto __run_query;
}
run_query=admin_handler_command_proxysql(query_no_space, query_no_space_length, sess, pa);
goto __run_query;
}
if (query_no_space_length==strlen("SHOW TABLES") && !strncasecmp("SHOW TABLES",query_no_space, query_no_space_length)) {
l_free(query_length,query);
query=l_strdup("SELECT name AS tables FROM sqlite_master WHERE type='table'");
query_length=strlen(query)+1;
goto __run_query;
}
strA=(char *)"SHOW CREATE TABLE ";
strB=(char *)"SELECT name AS 'table' , sql AS 'Create Table' FROM sqlite_master WHERE type='table' AND name='%s'";

Loading…
Cancel
Save