From 5198c3e45671cdd1d90f078825f1ac5fabf3c471 Mon Sep 17 00:00:00 2001 From: ekorh475 Date: Fri, 18 Nov 2016 10:54:14 +0200 Subject: [PATCH] Run astyle on httpd.c and maxinfo_exec.c --- server/modules/protocol/httpd.c | 21 +- server/modules/routing/maxinfo/maxinfo_exec.c | 769 ++++++++++-------- 2 files changed, 420 insertions(+), 370 deletions(-) diff --git a/server/modules/protocol/httpd.c b/server/modules/protocol/httpd.c index 8c98d8bba..83407c9ed 100644 --- a/server/modules/protocol/httpd.c +++ b/server/modules/protocol/httpd.c @@ -39,9 +39,9 @@ #include #include - /* @see function load_module in load_utils.c for explanation of the following - * lint directives. - */ +/* @see function load_module in load_utils.c for explanation of the following + * lint directives. +*/ /*lint -e14 */ MODULE_INFO info = { @@ -145,9 +145,9 @@ static int httpd_read_event(DCB* dcb) SESSION *session = dcb->session; int numchars = 1; - char buf[HTTPD_REQUESTLINE_MAXLEN-1] = ""; + char buf[HTTPD_REQUESTLINE_MAXLEN - 1] = ""; char *query_string = NULL; - char method[HTTPD_METHOD_MAXLEN-1] = ""; + char method[HTTPD_METHOD_MAXLEN - 1] = ""; char url[HTTPD_SMALL_BUFFER] = ""; size_t i, j; int headers_read = 0; @@ -163,11 +163,13 @@ static int httpd_read_event(DCB* dcb) numchars = httpd_get_line(dcb->fd, buf, sizeof(buf)); - i = 0; j = 0; + i = 0; + j = 0; while (!ISspace(buf[j]) && (i < sizeof(method) - 1)) { method[i] = buf[j]; - i++; j++; + i++; + j++; } method[i] = '\0'; @@ -190,7 +192,8 @@ static int httpd_read_event(DCB* dcb) while ((j < sizeof(buf) - 1) && !ISspace(buf[j]) && (i < sizeof(url) - 1)) { url[i] = buf[j]; - i++; j++; + i++; + j++; } url[i] = '\0'; @@ -225,7 +228,7 @@ static int httpd_read_event(DCB* dcb) { *value = '\0'; value++; - end = &value[strlen(value) -1]; + end = &value[strlen(value) - 1]; *end = '\0'; if (strncasecmp(buf, "Hostname", 6) == 0) diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index 8f77d2aec..bbe8a782e 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -18,8 +18,8 @@ * @verbatim * Revision History * - * Date Who Description - * 17/02/15 Mark Riddoch Initial implementation + * Date Who Description + * 17/02/15 Mark Riddoch Initial implementation * * @endverbatim */ @@ -59,20 +59,20 @@ void maxinfo_send_ok(DCB *dcb); /** * Execute a parse tree and return the result set or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ void maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree) { - switch (tree->op) - { - case MAXOP_SHOW: - exec_show(dcb, tree); - break; - case MAXOP_SELECT: - exec_select(dcb, tree); - break; + switch (tree->op) + { + case MAXOP_SHOW: + exec_show(dcb, tree); + break; + case MAXOP_SELECT: + exec_select(dcb, tree); + break; case MAXOP_FLUSH: exec_flush(dcb, tree); @@ -90,212 +90,232 @@ maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree) exec_restart(dcb, tree); break; - case MAXOP_TABLE: - case MAXOP_COLUMNS: - case MAXOP_LITERAL: - case MAXOP_PREDICATE: - case MAXOP_LIKE: - case MAXOP_EQUAL: - default: - maxinfo_send_error(dcb, 0, "Unexpected operator in parse tree"); - } + case MAXOP_TABLE: + case MAXOP_COLUMNS: + case MAXOP_LITERAL: + case MAXOP_PREDICATE: + case MAXOP_LIKE: + case MAXOP_EQUAL: + default: + maxinfo_send_error(dcb, 0, "Unexpected operator in parse tree"); + } } /** * Fetch the list of services and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_services(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = serviceGetList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = serviceGetList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of listeners and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_listeners(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = serviceGetListenerList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = serviceGetListenerList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of sessions and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_sessions(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = sessionGetList(SESSION_LIST_ALL)) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = sessionGetList(SESSION_LIST_ALL)) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of client sessions and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_clients(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = sessionGetList(SESSION_LIST_CONNECTION)) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = sessionGetList(SESSION_LIST_CONNECTION)) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of servers and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_servers(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = serverGetList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = serverGetList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of modules and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_modules(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = moduleGetList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = moduleGetList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the list of monitors and stream as a result set * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_monitors(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = monitorGetList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = monitorGetList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * Fetch the event times data * - * @param dcb DCB to which to stream result set - * @param tree Potential like clause (currently unused) + * @param dcb DCB to which to stream result set + * @param tree Potential like clause (currently unused) */ static void exec_show_eventTimes(DCB *dcb, MAXINFO_TREE *tree) { -RESULTSET *set; + RESULTSET *set; - if ((set = eventTimesGetList()) == NULL) - return; - - resultset_stream_mysql(set, dcb); - resultset_free(set); + if ((set = eventTimesGetList()) == NULL) + { + return; + } + + resultset_stream_mysql(set, dcb); + resultset_free(set); } /** * The table of show commands that are supported */ -static struct { - char *name; - void (*func)(DCB *, MAXINFO_TREE *); -} show_commands[] = { - { "variables", exec_show_variables }, - { "status", exec_show_status }, - { "services", exec_show_services }, - { "listeners", exec_show_listeners }, - { "sessions", exec_show_sessions }, - { "clients", exec_show_clients }, - { "servers", exec_show_servers }, - { "modules", exec_show_modules }, - { "monitors", exec_show_monitors }, - { "eventTimes", exec_show_eventTimes }, - { NULL, NULL } +static struct +{ + char *name; + void (*func)(DCB *, MAXINFO_TREE *); +} show_commands[] = +{ + { "variables", exec_show_variables }, + { "status", exec_show_status }, + { "services", exec_show_services }, + { "listeners", exec_show_listeners }, + { "sessions", exec_show_sessions }, + { "clients", exec_show_clients }, + { "servers", exec_show_servers }, + { "modules", exec_show_modules }, + { "monitors", exec_show_monitors }, + { "eventTimes", exec_show_eventTimes }, + { NULL, NULL } }; /** * Execute a show command parse tree and return the result set or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_show(DCB *dcb, MAXINFO_TREE *tree) { -int i; -char errmsg[120]; + int i; + char errmsg[120]; - for (i = 0; show_commands[i].name; i++) - { - if (strcasecmp(show_commands[i].name, tree->value) == 0) - { - (*show_commands[i].func)(dcb, tree->right); - return; - } - } - if (strlen(tree->value) > 80) // Prevent buffer overrun - tree->value[80] = 0; - sprintf(errmsg, "Unsupported show command '%s'", tree->value); - maxinfo_send_error(dcb, 0, errmsg); - MXS_NOTICE("%s", errmsg); + for (i = 0; show_commands[i].name; i++) + { + if (strcasecmp(show_commands[i].name, tree->value) == 0) + { + (*show_commands[i].func)(dcb, tree->right); + return; + } + } + if (strlen(tree->value) > 80) // Prevent buffer overrun + { + tree->value[80] = 0; + } + sprintf(errmsg, "Unsupported show command '%s'", tree->value); + maxinfo_send_error(dcb, 0, errmsg); + MXS_NOTICE("%s", errmsg); } /** * Flush all logs to disk and rotate them. - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ void exec_flush_logs(DCB *dcb, MAXINFO_TREE *tree) { @@ -310,7 +330,8 @@ static struct { char *name; void (*func)(DCB *, MAXINFO_TREE *); -} flush_commands[] = { +} flush_commands[] = +{ { "logs", exec_flush_logs}, { NULL, NULL} }; @@ -318,8 +339,8 @@ static struct /** * Execute a flush command parse tree and return the result set or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_flush(DCB *dcb, MAXINFO_TREE *tree) @@ -390,7 +411,8 @@ static struct { char *name; void (*func)(DCB *, MAXINFO_TREE *); -} set_commands[] = { +} set_commands[] = +{ { "server", exec_set_server}, { NULL, NULL} }; @@ -398,8 +420,8 @@ static struct /** * Execute a set command parse tree and return the result set or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_set(DCB *dcb, MAXINFO_TREE *tree) @@ -470,7 +492,8 @@ static struct { char *name; void (*func)(DCB *, MAXINFO_TREE *); -} clear_commands[] = { +} clear_commands[] = +{ { "server", exec_clear_server}, { NULL, NULL} }; @@ -478,8 +501,8 @@ static struct /** * Execute a clear command parse tree and return the result set or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_clear(DCB *dcb, MAXINFO_TREE *tree) @@ -590,7 +613,8 @@ static struct { char *name; void (*func)(DCB *, MAXINFO_TREE *); -} shutdown_commands[] = { +} shutdown_commands[] = +{ { "maxscale", exec_shutdown_maxscale}, { "monitor", exec_shutdown_monitor}, { "service", exec_shutdown_service}, @@ -600,8 +624,8 @@ static struct /** * Execute a shutdown command parse tree and return OK or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_shutdown(DCB *dcb, MAXINFO_TREE *tree) @@ -699,7 +723,8 @@ static struct { char *name; void (*func)(DCB *, MAXINFO_TREE *); -} restart_commands[] = { +} restart_commands[] = +{ { "monitor", exec_restart_monitor}, { "service", exec_restart_service}, { NULL, NULL} @@ -708,8 +733,8 @@ static struct /** * Execute a restart command parse tree and return OK or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_restart(DCB *dcb, MAXINFO_TREE *tree) @@ -742,7 +767,7 @@ exec_restart(DCB *dcb, MAXINFO_TREE *tree) static char * getVersion() { - return MAXSCALE_VERSION; + return MAXSCALE_VERSION; } static char *versionComment = "MariaDB MaxScale"; @@ -754,7 +779,7 @@ static char *versionComment = "MariaDB MaxScale"; static char * getVersionComment() { - return versionComment; + return versionComment; } /** @@ -765,109 +790,116 @@ getVersionComment() static char * getMaxScaleHome() { - return getenv("MAXSCALE_HOME"); + return getenv("MAXSCALE_HOME"); } /* The various methods to fetch the variables */ -#define VT_STRING 1 -#define VT_INT 2 +#define VT_STRING 1 +#define VT_INT 2 typedef void *(*STATSFUNC)(); /** * Variables that may be sent in a show variables */ -static struct { - char *name; - int type; - STATSFUNC func; -} variables[] = { - { "version", VT_STRING, (STATSFUNC)getVersion }, - { "version_comment", VT_STRING, (STATSFUNC)getVersionComment }, - { "basedir", VT_STRING, (STATSFUNC)getMaxScaleHome}, - { "MAXSCALE_VERSION", VT_STRING, (STATSFUNC)getVersion }, - { "MAXSCALE_THREADS", VT_INT, (STATSFUNC)config_threadcount }, - { "MAXSCALE_NBPOLLS", VT_INT, (STATSFUNC)config_nbpolls }, - { "MAXSCALE_POLLSLEEP", VT_INT, (STATSFUNC)config_pollsleep }, - { "MAXSCALE_UPTIME", VT_INT, (STATSFUNC)maxscale_uptime }, - { "MAXSCALE_SESSIONS", VT_INT, (STATSFUNC)serviceSessionCountAll }, - { NULL, 0, NULL } +static struct +{ + char *name; + int type; + STATSFUNC func; +} variables[] = +{ + { "version", VT_STRING, (STATSFUNC)getVersion }, + { "version_comment", VT_STRING, (STATSFUNC)getVersionComment }, + { "basedir", VT_STRING, (STATSFUNC)getMaxScaleHome}, + { "MAXSCALE_VERSION", VT_STRING, (STATSFUNC)getVersion }, + { "MAXSCALE_THREADS", VT_INT, (STATSFUNC)config_threadcount }, + { "MAXSCALE_NBPOLLS", VT_INT, (STATSFUNC)config_nbpolls }, + { "MAXSCALE_POLLSLEEP", VT_INT, (STATSFUNC)config_pollsleep }, + { "MAXSCALE_UPTIME", VT_INT, (STATSFUNC)maxscale_uptime }, + { "MAXSCALE_SESSIONS", VT_INT, (STATSFUNC)serviceSessionCountAll }, + { NULL, 0, NULL } }; -typedef struct { - int index; - char *like; +typedef struct +{ + int index; + char *like; } VARCONTEXT; /** * Callback function to populate rows of the show variable * command * - * @param data The context point - * @return The next row or NULL if end of rows + * @param data The context point + * @return The next row or NULL if end of rows */ static RESULT_ROW * variable_row(RESULTSET *result, void *data) { -VARCONTEXT *context = (VARCONTEXT *)data; -RESULT_ROW *row; -char buf[80]; + VARCONTEXT *context = (VARCONTEXT *)data; + RESULT_ROW *row; + char buf[80]; - if (variables[context->index].name) - { - if (context->like && - maxinfo_pattern_match(context->like, - variables[context->index].name)) - { - context->index++; - return variable_row(result, data); - } - row = resultset_make_row(result); - resultset_row_set(row, 0, variables[context->index].name); - switch (variables[context->index].type) - { - case VT_STRING: - resultset_row_set(row, 1, - (char *)(*variables[context->index].func)()); - break; - case VT_INT: - snprintf(buf, 80, "%ld", - (long)(*variables[context->index].func)()); - resultset_row_set(row, 1, buf); - break; - } - context->index++; - return row; - } - return NULL; + if (variables[context->index].name) + { + if (context->like && + maxinfo_pattern_match(context->like, + variables[context->index].name)) + { + context->index++; + return variable_row(result, data); + } + row = resultset_make_row(result); + resultset_row_set(row, 0, variables[context->index].name); + switch (variables[context->index].type) + { + case VT_STRING: + resultset_row_set(row, 1, + (char *)(*variables[context->index].func)()); + break; + case VT_INT: + snprintf(buf, 80, "%ld", + (long)(*variables[context->index].func)()); + resultset_row_set(row, 1, buf); + break; + } + context->index++; + return row; + } + return NULL; } /** * Execute a show variables command applying an optional filter * - * @param dcb The DCB connected to the client - * @param filter A potential like clause or NULL + * @param dcb The DCB connected to the client + * @param filter A potential like clause or NULL */ static void exec_show_variables(DCB *dcb, MAXINFO_TREE *filter) { -RESULTSET *result; -VARCONTEXT context; + RESULTSET *result; + VARCONTEXT context; - if (filter) - context.like = filter->value; - else - context.like = NULL; - context.index = 0; + if (filter) + { + context.like = filter->value; + } + else + { + context.like = NULL; + } + context.index = 0; - if ((result = resultset_create(variable_row, &context)) == NULL) - { - maxinfo_send_error(dcb, 0, "No resources available"); - return; - } - resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); - resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); - resultset_stream_mysql(result, dcb); - resultset_free(result); + if ((result = resultset_create(variable_row, &context)) == NULL) + { + maxinfo_send_error(dcb, 0, "No resources available"); + return; + } + resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); + resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); + resultset_stream_mysql(result, dcb); + resultset_free(result); } /** @@ -878,19 +910,19 @@ VARCONTEXT context; RESULTSET * maxinfo_variables() { -RESULTSET *result; -static VARCONTEXT context; + RESULTSET *result; + static VARCONTEXT context; - context.like = NULL; - context.index = 0; + context.like = NULL; + context.index = 0; - if ((result = resultset_create(variable_row, &context)) == NULL) - { - return NULL; - } - resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); - resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); - return result; + if ((result = resultset_create(variable_row, &context)) == NULL) + { + return NULL; + } + resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); + resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); + return result; } /** @@ -899,7 +931,7 @@ static VARCONTEXT context; static int maxinfo_all_dcbs() { - return dcb_count_by_usage(DCB_USAGE_ALL); + return dcb_count_by_usage(DCB_USAGE_ALL); } /** @@ -908,7 +940,7 @@ maxinfo_all_dcbs() static int maxinfo_client_dcbs() { - return dcb_count_by_usage(DCB_USAGE_CLIENT); + return dcb_count_by_usage(DCB_USAGE_CLIENT); } /** @@ -917,7 +949,7 @@ maxinfo_client_dcbs() static int maxinfo_listener_dcbs() { - return dcb_count_by_usage(DCB_USAGE_LISTENER); + return dcb_count_by_usage(DCB_USAGE_LISTENER); } /** @@ -926,7 +958,7 @@ maxinfo_listener_dcbs() static int maxinfo_backend_dcbs() { - return dcb_count_by_usage(DCB_USAGE_BACKEND); + return dcb_count_by_usage(DCB_USAGE_BACKEND); } /** @@ -935,7 +967,7 @@ maxinfo_backend_dcbs() static int maxinfo_internal_dcbs() { - return dcb_count_by_usage(DCB_USAGE_INTERNAL); + return dcb_count_by_usage(DCB_USAGE_INTERNAL); } /** @@ -944,7 +976,7 @@ maxinfo_internal_dcbs() static int maxinfo_zombie_dcbs() { - return dcb_count_by_usage(DCB_USAGE_ZOMBIE); + return dcb_count_by_usage(DCB_USAGE_ZOMBIE); } /** @@ -953,7 +985,7 @@ maxinfo_zombie_dcbs() static int maxinfo_read_events() { - return poll_get_stat(POLL_STAT_READ); + return poll_get_stat(POLL_STAT_READ); } /** @@ -962,7 +994,7 @@ maxinfo_read_events() static int maxinfo_write_events() { - return poll_get_stat(POLL_STAT_WRITE); + return poll_get_stat(POLL_STAT_WRITE); } /** @@ -971,7 +1003,7 @@ maxinfo_write_events() static int maxinfo_error_events() { - return poll_get_stat(POLL_STAT_ERROR); + return poll_get_stat(POLL_STAT_ERROR); } /** @@ -980,7 +1012,7 @@ maxinfo_error_events() static int maxinfo_hangup_events() { - return poll_get_stat(POLL_STAT_HANGUP); + return poll_get_stat(POLL_STAT_HANGUP); } /** @@ -989,7 +1021,7 @@ maxinfo_hangup_events() static int maxinfo_accept_events() { - return poll_get_stat(POLL_STAT_ACCEPT); + return poll_get_stat(POLL_STAT_ACCEPT); } /** @@ -998,7 +1030,7 @@ maxinfo_accept_events() static int maxinfo_event_queue_length() { - return poll_get_stat(POLL_STAT_EVQ_LEN); + return poll_get_stat(POLL_STAT_EVQ_LEN); } /** @@ -1007,7 +1039,7 @@ maxinfo_event_queue_length() static int maxinfo_event_pending_queue_length() { - return poll_get_stat(POLL_STAT_EVQ_PENDING); + return poll_get_stat(POLL_STAT_EVQ_PENDING); } /** @@ -1016,7 +1048,7 @@ maxinfo_event_pending_queue_length() static int maxinfo_max_event_queue_length() { - return poll_get_stat(POLL_STAT_EVQ_MAX); + return poll_get_stat(POLL_STAT_EVQ_MAX); } /** @@ -1025,7 +1057,7 @@ maxinfo_max_event_queue_length() static int maxinfo_max_event_queue_time() { - return poll_get_stat(POLL_STAT_MAX_QTIME); + return poll_get_stat(POLL_STAT_MAX_QTIME); } /** @@ -1034,112 +1066,118 @@ maxinfo_max_event_queue_time() static int maxinfo_max_event_exec_time() { - return poll_get_stat(POLL_STAT_MAX_EXECTIME); + return poll_get_stat(POLL_STAT_MAX_EXECTIME); } /** * Variables that may be sent in a show status */ -static struct { - char *name; - int type; - STATSFUNC func; -} status[] = { - { "Uptime", VT_INT, (STATSFUNC)maxscale_uptime }, - { "Uptime_since_flush_status", VT_INT, (STATSFUNC)maxscale_uptime }, - { "Threads_created", VT_INT, (STATSFUNC)config_threadcount }, - { "Threads_running", VT_INT, (STATSFUNC)config_threadcount }, - { "Threadpool_threads", VT_INT, (STATSFUNC)config_threadcount }, - { "Threads_connected", VT_INT, (STATSFUNC)serviceSessionCountAll }, - { "Connections", VT_INT, (STATSFUNC)maxinfo_all_dcbs }, - { "Client_connections", VT_INT, (STATSFUNC)maxinfo_client_dcbs }, - { "Backend_connections", VT_INT, (STATSFUNC)maxinfo_backend_dcbs }, - { "Listeners", VT_INT, (STATSFUNC)maxinfo_listener_dcbs }, - { "Zombie_connections", VT_INT, (STATSFUNC)maxinfo_zombie_dcbs }, - { "Internal_descriptors", VT_INT, (STATSFUNC)maxinfo_internal_dcbs }, - { "Read_events", VT_INT, (STATSFUNC)maxinfo_read_events }, - { "Write_events", VT_INT, (STATSFUNC)maxinfo_write_events }, - { "Hangup_events", VT_INT, (STATSFUNC)maxinfo_hangup_events }, - { "Error_events", VT_INT, (STATSFUNC)maxinfo_error_events }, - { "Accept_events", VT_INT, (STATSFUNC)maxinfo_accept_events }, - { "Event_queue_length", VT_INT, (STATSFUNC)maxinfo_event_queue_length }, - { "Pending_events", VT_INT, (STATSFUNC)maxinfo_event_pending_queue_length }, - { "Max_event_queue_length", VT_INT, (STATSFUNC)maxinfo_max_event_queue_length }, - { "Max_event_queue_time", VT_INT, (STATSFUNC)maxinfo_max_event_queue_time }, - { "Max_event_execution_time", VT_INT, (STATSFUNC)maxinfo_max_event_exec_time }, - { NULL, 0, NULL } +static struct +{ + char *name; + int type; + STATSFUNC func; +} status[] = +{ + { "Uptime", VT_INT, (STATSFUNC)maxscale_uptime }, + { "Uptime_since_flush_status", VT_INT, (STATSFUNC)maxscale_uptime }, + { "Threads_created", VT_INT, (STATSFUNC)config_threadcount }, + { "Threads_running", VT_INT, (STATSFUNC)config_threadcount }, + { "Threadpool_threads", VT_INT, (STATSFUNC)config_threadcount }, + { "Threads_connected", VT_INT, (STATSFUNC)serviceSessionCountAll }, + { "Connections", VT_INT, (STATSFUNC)maxinfo_all_dcbs }, + { "Client_connections", VT_INT, (STATSFUNC)maxinfo_client_dcbs }, + { "Backend_connections", VT_INT, (STATSFUNC)maxinfo_backend_dcbs }, + { "Listeners", VT_INT, (STATSFUNC)maxinfo_listener_dcbs }, + { "Zombie_connections", VT_INT, (STATSFUNC)maxinfo_zombie_dcbs }, + { "Internal_descriptors", VT_INT, (STATSFUNC)maxinfo_internal_dcbs }, + { "Read_events", VT_INT, (STATSFUNC)maxinfo_read_events }, + { "Write_events", VT_INT, (STATSFUNC)maxinfo_write_events }, + { "Hangup_events", VT_INT, (STATSFUNC)maxinfo_hangup_events }, + { "Error_events", VT_INT, (STATSFUNC)maxinfo_error_events }, + { "Accept_events", VT_INT, (STATSFUNC)maxinfo_accept_events }, + { "Event_queue_length", VT_INT, (STATSFUNC)maxinfo_event_queue_length }, + { "Pending_events", VT_INT, (STATSFUNC)maxinfo_event_pending_queue_length }, + { "Max_event_queue_length", VT_INT, (STATSFUNC)maxinfo_max_event_queue_length }, + { "Max_event_queue_time", VT_INT, (STATSFUNC)maxinfo_max_event_queue_time }, + { "Max_event_execution_time", VT_INT, (STATSFUNC)maxinfo_max_event_exec_time }, + { NULL, 0, NULL } }; /** * Callback function to populate rows of the show variable * command * - * @param data The context point - * @return The next row or NULL if end of rows + * @param data The context point + * @return The next row or NULL if end of rows */ static RESULT_ROW * status_row(RESULTSET *result, void *data) { -VARCONTEXT *context = (VARCONTEXT *)data; -RESULT_ROW *row; -char buf[80]; + VARCONTEXT *context = (VARCONTEXT *)data; + RESULT_ROW *row; + char buf[80]; - if (status[context->index].name) - { - if (context->like && - maxinfo_pattern_match(context->like, - status[context->index].name)) - { - context->index++; - return status_row(result, data); - } - row = resultset_make_row(result); - resultset_row_set(row, 0, status[context->index].name); - switch (status[context->index].type) - { - case VT_STRING: - resultset_row_set(row, 1, - (char *)(*status[context->index].func)()); - break; - case VT_INT: - snprintf(buf, 80, "%ld", - (long)(*status[context->index].func)()); - resultset_row_set(row, 1, buf); - break; - } - context->index++; - return row; - } - return NULL; + if (status[context->index].name) + { + if (context->like && + maxinfo_pattern_match(context->like, + status[context->index].name)) + { + context->index++; + return status_row(result, data); + } + row = resultset_make_row(result); + resultset_row_set(row, 0, status[context->index].name); + switch (status[context->index].type) + { + case VT_STRING: + resultset_row_set(row, 1, + (char *)(*status[context->index].func)()); + break; + case VT_INT: + snprintf(buf, 80, "%ld", + (long)(*status[context->index].func)()); + resultset_row_set(row, 1, buf); + break; + } + context->index++; + return row; + } + return NULL; } /** * Execute a show status command applying an optional filter * - * @param dcb The DCB connected to the client - * @param filter A potential like clause or NULL + * @param dcb The DCB connected to the client + * @param filter A potential like clause or NULL */ static void exec_show_status(DCB *dcb, MAXINFO_TREE *filter) { -RESULTSET *result; -VARCONTEXT context; + RESULTSET *result; + VARCONTEXT context; - if (filter) - context.like = filter->value; - else - context.like = NULL; - context.index = 0; + if (filter) + { + context.like = filter->value; + } + else + { + context.like = NULL; + } + context.index = 0; - if ((result = resultset_create(status_row, &context)) == NULL) - { - maxinfo_send_error(dcb, 0, "No resources available"); - return; - } - resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); - resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); - resultset_stream_mysql(result, dcb); - resultset_free(result); + if ((result = resultset_create(status_row, &context)) == NULL) + { + maxinfo_send_error(dcb, 0, "No resources available"); + return; + } + resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); + resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); + resultset_stream_mysql(result, dcb); + resultset_free(result); } /** @@ -1150,19 +1188,19 @@ VARCONTEXT context; RESULTSET * maxinfo_status() { -RESULTSET *result; -static VARCONTEXT context; + RESULTSET *result; + static VARCONTEXT context; - context.like = NULL; - context.index = 0; + context.like = NULL; + context.index = 0; - if ((result = resultset_create(status_row, &context)) == NULL) - { - return NULL; - } - resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); - resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); - return result; + if ((result = resultset_create(status_row, &context)) == NULL) + { + return NULL; + } + resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR); + resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR); + return result; } @@ -1170,57 +1208,65 @@ static VARCONTEXT context; * Execute a select command parse tree and return the result set * or runtime error * - * @param dcb The DCB that connects to the client - * @param tree The parse tree for the query + * @param dcb The DCB that connects to the client + * @param tree The parse tree for the query */ static void exec_select(DCB *dcb, MAXINFO_TREE *tree) { - maxinfo_send_error(dcb, 0, "Select not yet implemented"); + maxinfo_send_error(dcb, 0, "Select not yet implemented"); } /** * Perform a "like" pattern match. Only works for leading and trailing % * - * @param pattern Pattern to match - * @param str String to match against pattern - * @return Zero on match + * @param pattern Pattern to match + * @param str String to match against pattern + * @return Zero on match */ static int maxinfo_pattern_match(char *pattern, char *str) { -int anchor = 0, len, trailing; -char *fixed; -extern char *strcasestr(); + int anchor = 0, len, trailing; + char *fixed; + extern char *strcasestr(); - if (*pattern != '%') - { - fixed = pattern; - anchor = 1; - } - else - { - fixed = &pattern[1]; - } - len = strlen(fixed); - if (fixed[len - 1] == '%') - trailing = 1; - else - trailing = 0; - if (anchor == 1 && trailing == 0) // No wildcard - return strcasecmp(pattern, str); - else if (anchor == 1) - return strncasecmp(str, pattern, len - trailing); - else - { - char *portion = malloc(len + 1); - int rval; - strncpy(portion, fixed, len - trailing); - portion[len - trailing] = 0; - rval = (strcasestr(str, portion) != NULL ? 0 : 1); - free(portion); - return rval; - } + if (*pattern != '%') + { + fixed = pattern; + anchor = 1; + } + else + { + fixed = &pattern[1]; + } + len = strlen(fixed); + if (fixed[len - 1] == '%') + { + trailing = 1; + } + else + { + trailing = 0; + } + if (anchor == 1 && trailing == 0) // No wildcard + { + return strcasecmp(pattern, str); + } + else if (anchor == 1) + { + return strncasecmp(str, pattern, len - trailing); + } + else + { + char *portion = malloc(len + 1); + int rval; + strncpy(portion, fixed, len - trailing); + portion[len - trailing] = 0; + rval = (strcasestr(str, portion) != NULL ? 0 : 1); + free(portion); + return rval; + } } /** @@ -1229,7 +1275,8 @@ extern char *strcasestr(); */ void maxinfo_send_ok(DCB *dcb) { - static const char ok_packet[] ={ + static const char ok_packet[] = + { 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,