Uncrustify maxscale

See script directory for method. The script to run in the top level
MaxScale directory is called maxscale-uncrustify.sh, which uses
another script, list-src, from the same directory (so you need to set
your PATH). The uncrustify version was 0.66.
This commit is contained in:
Niclas Antti
2018-09-09 22:26:19 +03:00
parent fa7ec95069
commit c447e5cf15
849 changed files with 35002 additions and 27238 deletions

View File

@ -58,31 +58,31 @@
#include "../../../core/internal/session.hh"
#include "../../../core/internal/poll.hh"
extern char *create_hex_sha1_sha1_passwd(char *passwd);
extern char* create_hex_sha1_sha1_passwd(char* passwd);
static int maxinfo_statistics(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
static int maxinfo_ping(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
static int maxinfo_execute_query(INFO_INSTANCE *, INFO_SESSION *, char *);
static int maxinfo_send_ok(DCB *dcb);
static int maxinfo_statistics(INFO_INSTANCE*, INFO_SESSION*, GWBUF*);
static int maxinfo_ping(INFO_INSTANCE*, INFO_SESSION*, GWBUF*);
static int maxinfo_execute_query(INFO_INSTANCE*, INFO_SESSION*, char*);
static int maxinfo_send_ok(DCB* dcb);
/* The router entry points */
static MXS_ROUTER *createInstance(SERVICE *service, MXS_CONFIG_PARAMETER* params);
static MXS_ROUTER_SESSION *newSession(MXS_ROUTER *instance, MXS_SESSION *session);
static void closeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session);
static void freeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session);
static int execute(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queue);
static void diagnostics(MXS_ROUTER *instance, DCB *dcb);
static json_t* diagnostics_json(const MXS_ROUTER *instance);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static void handleError(MXS_ROUTER *instance,
MXS_ROUTER_SESSION *router_session,
GWBUF *errbuf,
DCB *backend_dcb,
mxs_error_action_t action,
bool *succp);
static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params);
static MXS_ROUTER_SESSION* newSession(MXS_ROUTER* instance, MXS_SESSION* session);
static void closeSession(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_session);
static void freeSession(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_session);
static int execute(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_session, GWBUF* queue);
static void diagnostics(MXS_ROUTER* instance, DCB* dcb);
static json_t* diagnostics_json(const MXS_ROUTER* instance);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static void handleError(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* errbuf,
DCB* backend_dcb,
mxs_error_action_t action,
bool* succp);
static SPINLOCK instlock;
static INFO_INSTANCE *instances;
static SPINLOCK instlock;
static INFO_INSTANCE* instances;
/**
* The module entry point routine. It is this routine that
@ -122,10 +122,10 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
"V1.0.0",
RCAP_TYPE_NO_AUTH,
&MyObject,
NULL, /* Process init. */
NULL, /* Process finish. */
NULL, /* Thread init. */
NULL, /* Thread finish. */
NULL, /* Process init. */
NULL, /* Process finish. */
NULL, /* Thread init. */
NULL, /* Thread finish. */
{
{MXS_END_MODULE_PARAMS}
}
@ -143,9 +143,9 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
*
* @return The instance data for this new instance
*/
static MXS_ROUTER* createInstance(SERVICE *service, MXS_CONFIG_PARAMETER* params)
static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params)
{
INFO_INSTANCE *inst;
INFO_INSTANCE* inst;
int i;
if ((inst = static_cast<INFO_INSTANCE*>(MXS_MALLOC(sizeof(INFO_INSTANCE)))) == NULL)
@ -167,7 +167,7 @@ static MXS_ROUTER* createInstance(SERVICE *service, MXS_CONFIG_PARAMETER* params
instances = inst;
spinlock_release(&instlock);
return (MXS_ROUTER *)inst;
return (MXS_ROUTER*)inst;
}
/**
@ -177,13 +177,12 @@ static MXS_ROUTER* createInstance(SERVICE *service, MXS_CONFIG_PARAMETER* params
* @param session The session itself
* @return Session specific data for this session
*/
static MXS_ROUTER_SESSION *
newSession(MXS_ROUTER *instance, MXS_SESSION *session)
static MXS_ROUTER_SESSION* newSession(MXS_ROUTER* instance, MXS_SESSION* session)
{
INFO_INSTANCE *inst = (INFO_INSTANCE *)instance;
INFO_SESSION *client;
INFO_INSTANCE* inst = (INFO_INSTANCE*)instance;
INFO_SESSION* client;
if ((client = (INFO_SESSION *)MXS_MALLOC(sizeof(INFO_SESSION))) == NULL)
if ((client = (INFO_SESSION*)MXS_MALLOC(sizeof(INFO_SESSION))) == NULL)
{
return NULL;
}
@ -208,11 +207,10 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session)
* @param instance The router instance data
* @param router_session The session being closed
*/
static void
closeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session)
static void closeSession(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_session)
{
INFO_INSTANCE *inst = (INFO_INSTANCE *)instance;
INFO_SESSION *session = (INFO_SESSION *)router_session;
INFO_INSTANCE* inst = (INFO_INSTANCE*)instance;
INFO_SESSION* session = (INFO_SESSION*)router_session;
spinlock_acquire(&inst->lock);
@ -222,7 +220,7 @@ closeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session)
}
else
{
INFO_SESSION *ptr = inst->sessions;
INFO_SESSION* ptr = inst->sessions;
while (ptr && ptr->next != session)
{
ptr = ptr->next;
@ -265,17 +263,17 @@ static void freeSession(MXS_ROUTER* router_instance,
* @param succp Result of action: true iff router can continue
*
*/
static void handleError(MXS_ROUTER *instance,
MXS_ROUTER_SESSION *router_session,
GWBUF *errbuf,
DCB *backend_dcb,
static void handleError(MXS_ROUTER* instance,
MXS_ROUTER_SESSION* router_session,
GWBUF* errbuf,
DCB* backend_dcb,
mxs_error_action_t action,
bool *succp)
bool* succp)
{
mxb_assert(backend_dcb->dcb_role == DCB_ROLE_BACKEND_HANDLER);
DCB *client_dcb;
MXS_SESSION *session = backend_dcb->session;
DCB* client_dcb;
MXS_SESSION* session = backend_dcb->session;
client_dcb = session->client_dcb;
@ -298,14 +296,13 @@ static void handleError(MXS_ROUTER *instance,
* @param queue The queue of data buffers to route
* @return The number of bytes sent
*/
static int
execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue)
static int execute(MXS_ROUTER* rinstance, MXS_ROUTER_SESSION* router_session, GWBUF* queue)
{
INFO_INSTANCE *instance = (INFO_INSTANCE *)rinstance;
INFO_SESSION *session = (INFO_SESSION *)router_session;
uint8_t *data;
INFO_INSTANCE* instance = (INFO_INSTANCE*)rinstance;
INFO_SESSION* session = (INFO_SESSION*)router_session;
uint8_t* data;
int length, len, residual;
char *sql;
char* sql;
if (GWBUF_TYPE(queue) == GWBUF_TYPE_HTTP)
{
@ -318,7 +315,7 @@ execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue)
session->queue = NULL;
queue = gwbuf_make_contiguous(queue);
}
data = (uint8_t *)GWBUF_DATA(queue);
data = (uint8_t*)GWBUF_DATA(queue);
length = data[0] + (data[1] << 8) + (data[2] << 16);
if (length + 4 > static_cast<int>(GWBUF_LENGTH(queue)))
{
@ -342,11 +339,14 @@ execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue)
case MXS_COM_PING:
rc = maxinfo_send_ok(session->dcb);
break;
case MXS_COM_STATISTICS:
rc = maxinfo_statistics(instance, session, queue);
break;
case MXS_COM_QUIT:
break;
default:
MXS_ERROR("Unexpected MySQL command 0x%x",
MYSQL_COMMAND(queue));
@ -364,10 +364,9 @@ execute(MXS_ROUTER *rinstance, MXS_ROUTER_SESSION *router_session, GWBUF *queue)
* @param instance Instance of the router
* @param dcb DCB to send diagnostics to
*/
static void
diagnostics(MXS_ROUTER *instance, DCB *dcb)
static void diagnostics(MXS_ROUTER* instance, DCB* dcb)
{
return; /* Nothing to do currently */
return; /* Nothing to do currently */
}
/**
@ -376,8 +375,7 @@ diagnostics(MXS_ROUTER *instance, DCB *dcb)
* @param instance Instance of the router
* @param dcb DCB to send diagnostics to
*/
static json_t*
diagnostics_json(const MXS_ROUTER *instance)
static json_t* diagnostics_json(const MXS_ROUTER* instance)
{
return NULL;
}
@ -387,8 +385,7 @@ diagnostics_json(const MXS_ROUTER *instance)
*
* Not used for the maxinfo router
*/
static uint64_t
getCapabilities(MXS_ROUTER* instance)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_NONE;
}
@ -405,15 +402,15 @@ getCapabilities(MXS_ROUTER* instance)
*
* @return non-zero on sucessful send
*/
static int
maxinfo_statistics(INFO_INSTANCE *router, INFO_SESSION *session, GWBUF *queue)
static int maxinfo_statistics(INFO_INSTANCE* router, INFO_SESSION* session, GWBUF* queue)
{
char result[1000];
uint8_t *ptr;
GWBUF *ret;
uint8_t* ptr;
GWBUF* ret;
int len;
snprintf(result, 1000,
snprintf(result,
1000,
"Uptime: %u Threads: %u Sessions: %u ",
maxscale_uptime(),
config_threadcount(),
@ -440,11 +437,10 @@ maxinfo_statistics(INFO_INSTANCE *router, INFO_SESSION *session, GWBUF *queue)
* @param session The connection that requested the ping
* @param queue The ping request
*/
static int
maxinfo_ping(INFO_INSTANCE *router, INFO_SESSION *session, GWBUF *queue)
static int maxinfo_ping(INFO_INSTANCE* router, INFO_SESSION* session, GWBUF* queue)
{
uint8_t *ptr;
GWBUF *ret;
uint8_t* ptr;
GWBUF* ret;
int len;
if ((ret = gwbuf_alloc(5)) == NULL)
@ -466,8 +462,7 @@ maxinfo_ping(INFO_INSTANCE *router, INFO_SESSION *session, GWBUF *queue)
*
* @param dcb The DCB of the client
*/
static void
respond_vercom(DCB *dcb)
static void respond_vercom(DCB* dcb)
{
std::unique_ptr<ResultSet> set = ResultSet::create({"@@version_comment"});
set->add_row({MAXSCALE_VERSION});
@ -479,8 +474,7 @@ respond_vercom(DCB *dcb)
*
* @param dcb The DCB of the client
*/
static void
respond_starttime(DCB *dcb)
static void respond_starttime(DCB* dcb)
{
std::unique_ptr<ResultSet> set = ResultSet::create({"starttime"});
set->add_row({std::to_string(maxscale_started())});
@ -493,22 +487,21 @@ respond_starttime(DCB *dcb)
* @param dcb The DCB to send the OK packet to
* @return result of a write call, non-zero if write was successful
*/
static int
maxinfo_send_ok(DCB *dcb)
static int maxinfo_send_ok(DCB* dcb)
{
GWBUF *buf;
uint8_t *ptr;
GWBUF* buf;
uint8_t* ptr;
if ((buf = gwbuf_alloc(11)) == NULL)
{
return 0;
}
ptr = GWBUF_DATA(buf);
*ptr++ = 7; // Payload length
*ptr++ = 7; // Payload length
*ptr++ = 0;
*ptr++ = 0;
*ptr++ = 1; // Seqno
*ptr++ = 0; // ok
*ptr++ = 1; // Seqno
*ptr++ = 0; // ok
*ptr++ = 0;
*ptr++ = 0;
*ptr++ = 2;
@ -525,14 +518,14 @@ maxinfo_send_ok(DCB *dcb)
* @param session The session pointer
* @param sql The SQL to execute
*/
static int
maxinfo_execute_query(INFO_INSTANCE *instance, INFO_SESSION *session, char *sql)
static int maxinfo_execute_query(INFO_INSTANCE* instance, INFO_SESSION* session, char* sql)
{
MAXINFO_TREE *tree;
MAXINFO_TREE* tree;
PARSE_ERROR err;
MXS_INFO("SQL statement: '%s' for 0x%p.",
sql, session->dcb);
sql,
session->dcb);
if (strcmp(sql, "select @@version_comment limit 1") == 0)
{
respond_vercom(session->dcb);
@ -542,7 +535,8 @@ maxinfo_execute_query(INFO_INSTANCE *instance, INFO_SESSION *session, char *sql)
* select unix_timestamp... as starttime
* just return the starttime of MaxScale
*/
if (strncasecmp(sql, "select UNIX_TIMESTAMP",
if (strncasecmp(sql,
"select UNIX_TIMESTAMP",
strlen("select UNIX_TIMESTAMP")) == 0
&& (strstr(sql, "as starttime") != NULL || strstr(sql, "AS starttime") != NULL))
{

View File

@ -42,12 +42,12 @@ struct maxinfo_session;
*/
typedef struct maxinfo_instance
{
SPINLOCK lock; /*< The instance spinlock */
SERVICE *service; /*< The debug cli service */
SPINLOCK lock; /*< The instance spinlock */
SERVICE* service; /*< The debug cli service */
struct maxinfo_session
*sessions; /*< Linked list of sessions within this instance */
* sessions; /*< Linked list of sessions within this instance */
struct maxinfo_instance
*next; /*< The next pointer for the list of instances */
* next; /*< The next pointer for the list of instances */
} INFO_INSTANCE;
/**
@ -57,11 +57,11 @@ typedef struct maxinfo_instance
typedef struct maxinfo_session
{
MXS_SESSION *session; /*< The MaxScale session */
DCB *dcb; /*< DCB of the client side */
GWBUF *queue; /*< Queue for building contiguous requests */
MXS_SESSION* session; /*< The MaxScale session */
DCB* dcb; /*< DCB of the client side */
GWBUF* queue; /*< Queue for building contiguous requests */
struct maxinfo_session
*next; /*< The next pointer for the list of sessions */
* next; /*< The next pointer for the list of sessions */
} INFO_SESSION;
/**
@ -90,33 +90,33 @@ typedef enum
*/
typedef struct maxinfo_tree
{
MAXINFO_OPERATOR op; /*< The operator */
char *value; /*< The value */
struct maxinfo_tree *left; /*< The left hand side of the operator */
struct maxinfo_tree *right; /*< The right hand side of the operator */
MAXINFO_OPERATOR op; /*< The operator */
char* value; /*< The value */
struct maxinfo_tree* left; /*< The left hand side of the operator */
struct maxinfo_tree* right; /*< The right hand side of the operator */
} MAXINFO_TREE;
#define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4))
#define MYSQL_COMMAND(buf) (*((uint8_t*)GWBUF_DATA(buf) + 4))
/**
* Token values for the tokeniser used by the parser for maxinfo
*/
#define LT_STRING 1
#define LT_SHOW 2
#define LT_LIKE 3
#define LT_SELECT 4
#define LT_EQUAL 5
#define LT_COMMA 6
#define LT_FROM 7
#define LT_STAR 8
#define LT_VARIABLE 9
#define LT_FLUSH 10
#define LT_SET 11
#define LT_CLEAR 12
#define LT_SHUTDOWN 13
#define LT_RESTART 14
#define LT_STRING 1
#define LT_SHOW 2
#define LT_LIKE 3
#define LT_SELECT 4
#define LT_EQUAL 5
#define LT_COMMA 6
#define LT_FROM 7
#define LT_STAR 8
#define LT_VARIABLE 9
#define LT_FLUSH 10
#define LT_SET 11
#define LT_CLEAR 12
#define LT_SHUTDOWN 13
#define LT_RESTART 14
/**
@ -131,11 +131,11 @@ typedef enum
} PARSE_ERROR;
extern MAXINFO_TREE *maxinfo_parse(char *, PARSE_ERROR *);
extern void maxinfo_free_tree(MAXINFO_TREE *);
extern void maxinfo_execute(DCB *, MAXINFO_TREE *);
extern void maxinfo_send_error(DCB *, int, const char *);
extern void maxinfo_send_parse_error(DCB *, char *, PARSE_ERROR);
extern MAXINFO_TREE* maxinfo_parse(char*, PARSE_ERROR*);
extern void maxinfo_free_tree(MAXINFO_TREE*);
extern void maxinfo_execute(DCB*, MAXINFO_TREE*);
extern void maxinfo_send_error(DCB*, int, const char*);
extern void maxinfo_send_parse_error(DCB*, char*, PARSE_ERROR);
extern std::unique_ptr<ResultSet> maxinfo_variables();
extern std::unique_ptr<ResultSet> maxinfo_status();

View File

@ -48,11 +48,10 @@
* @param sql The SQL that had the parse error
* @param err The parse error code
*/
void
maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err)
void maxinfo_send_parse_error(DCB* dcb, char* sql, PARSE_ERROR err)
{
const char *desc = "";
char *msg;
const char* desc = "";
char* msg;
int len;
switch (err)
@ -60,19 +59,22 @@ maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err)
case PARSE_NOERROR:
desc = "No error";
break;
case PARSE_MALFORMED_SHOW:
desc = "Expected show <command> [like <pattern>]";
break;
case PARSE_EXPECTED_LIKE:
desc = "Expected LIKE <pattern>";
break;
case PARSE_SYNTAX_ERROR:
desc = "Syntax error";
break;
}
len = strlen(sql) + strlen(desc) + 20;
msg = (char *)MXS_MALLOC(len);
msg = (char*)MXS_MALLOC(len);
MXS_ABORT_IF_NULL(msg);
sprintf(msg, "%s in query '%s'", desc, sql);
maxinfo_send_error(dcb, 1149, msg);
@ -85,11 +87,10 @@ maxinfo_send_parse_error(DCB *dcb, char *sql, PARSE_ERROR err)
* @param dcb The DCB to send the error packet to
* @param msg The slave server instance
*/
void
maxinfo_send_error(DCB *dcb, int errcode, const char *msg)
void maxinfo_send_error(DCB* dcb, int errcode, const char* msg)
{
GWBUF *pkt;
unsigned char *data;
GWBUF* pkt;
unsigned char* data;
int len;
len = strlen(msg) + 9;
@ -105,8 +106,8 @@ maxinfo_send_error(DCB *dcb, int errcode, const char *msg)
// Payload
data[4] = 0xff; // Error indicator
data[5] = errcode & 0xff; // Error Code
data[6] = (errcode >> 8) & 0xff; // Error Code
data[6] = (errcode >> 8) & 0xff;// Error Code
memcpy(&data[7], "#42000", 6);
memcpy(&data[13], msg, strlen(msg)); // Error Message
memcpy(&data[13], msg, strlen(msg)); // Error Message
dcb->func.write(dcb, pkt);
}

View File

@ -55,31 +55,31 @@
#include "../../../core/internal/server.hh"
#include "../../../core/internal/service.hh"
static void exec_show(DCB *dcb, MAXINFO_TREE *tree);
static void exec_select(DCB *dcb, MAXINFO_TREE *tree);
static void exec_show_variables(DCB *dcb, MAXINFO_TREE *filter);
static void exec_show_status(DCB *dcb, MAXINFO_TREE *filter);
static int maxinfo_pattern_match(const char *pattern, const char *str);
static void exec_flush(DCB *dcb, MAXINFO_TREE *tree);
static void exec_set(DCB *dcb, MAXINFO_TREE *tree);
static void exec_clear(DCB *dcb, MAXINFO_TREE *tree);
static void exec_shutdown(DCB *dcb, MAXINFO_TREE *tree);
static void exec_restart(DCB *dcb, MAXINFO_TREE *tree);
void maxinfo_send_ok(DCB *dcb);
static void exec_show(DCB* dcb, MAXINFO_TREE* tree);
static void exec_select(DCB* dcb, MAXINFO_TREE* tree);
static void exec_show_variables(DCB* dcb, MAXINFO_TREE* filter);
static void exec_show_status(DCB* dcb, MAXINFO_TREE* filter);
static int maxinfo_pattern_match(const char* pattern, const char* str);
static void exec_flush(DCB* dcb, MAXINFO_TREE* tree);
static void exec_set(DCB* dcb, MAXINFO_TREE* tree);
static void exec_clear(DCB* dcb, MAXINFO_TREE* tree);
static void exec_shutdown(DCB* dcb, MAXINFO_TREE* tree);
static void exec_restart(DCB* dcb, MAXINFO_TREE* tree);
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
*/
void
maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree)
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;
@ -87,15 +87,19 @@ maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree)
case MAXOP_FLUSH:
exec_flush(dcb, tree);
break;
case MAXOP_SET:
exec_set(dcb, tree);
break;
case MAXOP_CLEAR:
exec_clear(dcb, tree);
break;
case MAXOP_SHUTDOWN:
exec_shutdown(dcb, tree);
break;
case MAXOP_RESTART:
exec_restart(dcb, tree);
break;
@ -117,8 +121,7 @@ maxinfo_execute(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_services(DCB* dcb, MAXINFO_TREE* tree)
{
serviceGetList()->write(dcb);
}
@ -129,8 +132,7 @@ exec_show_services(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_listeners(DCB* dcb, MAXINFO_TREE* tree)
{
serviceGetListenerList()->write(dcb);
}
@ -141,8 +143,7 @@ exec_show_listeners(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_sessions(DCB* dcb, MAXINFO_TREE* tree)
{
sessionGetList()->write(dcb);
}
@ -153,8 +154,7 @@ exec_show_sessions(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_clients(DCB* dcb, MAXINFO_TREE* tree)
{
sessionGetList()->write(dcb);
}
@ -165,8 +165,7 @@ exec_show_clients(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_servers(DCB* dcb, MAXINFO_TREE* tree)
{
serverGetList()->write(dcb);
}
@ -177,8 +176,7 @@ exec_show_servers(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_modules(DCB* dcb, MAXINFO_TREE* tree)
{
moduleGetList()->write(dcb);
}
@ -189,8 +187,7 @@ exec_show_modules(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_monitors(DCB* dcb, MAXINFO_TREE* tree)
{
monitor_get_list()->write(dcb);
}
@ -201,8 +198,7 @@ exec_show_monitors(DCB *dcb, MAXINFO_TREE *tree)
* @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)
static void exec_show_eventTimes(DCB* dcb, MAXINFO_TREE* tree)
{
eventTimesGetList()->write(dcb);
}
@ -212,21 +208,21 @@ exec_show_eventTimes(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const 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 }
{"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 }
};
/**
@ -235,8 +231,7 @@ static struct
* @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)
static void exec_show(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
@ -263,7 +258,7 @@ exec_show(DCB *dcb, MAXINFO_TREE *tree)
* @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)
void exec_flush_logs(DCB* dcb, MAXINFO_TREE* tree)
{
mxs_log_rotate();
maxinfo_send_ok(dcb);
@ -274,12 +269,12 @@ void exec_flush_logs(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const char* name;
void (* func)(DCB*, MAXINFO_TREE*);
} flush_commands[] =
{
{ "logs", exec_flush_logs},
{ NULL, NULL}
{"logs", exec_flush_logs},
{NULL, NULL }
};
/**
@ -288,14 +283,13 @@ static struct
* @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)
static void exec_flush(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
sprintf(errmsg, "Unsupported flush command '%s'", tree->value);
if(!tree)
if (!tree)
{
maxinfo_send_error(dcb, 0, errmsg);
MXS_ERROR("%s", errmsg);
@ -309,7 +303,7 @@ exec_flush(DCB *dcb, MAXINFO_TREE *tree)
return;
}
}
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -322,7 +316,7 @@ exec_flush(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_set_server(DCB *dcb, MAXINFO_TREE *tree)
void exec_set_server(DCB* dcb, MAXINFO_TREE* tree)
{
SERVER* server = server_find_by_unique_name(tree->value);
char errmsg[120];
@ -344,7 +338,7 @@ void exec_set_server(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->right->value) > 80) // Prevent buffer overrun
if (strlen(tree->right->value) > 80) // Prevent buffer overrun
{
tree->right->value[80] = 0;
}
@ -354,7 +348,7 @@ void exec_set_server(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -368,12 +362,12 @@ void exec_set_server(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const char* name;
void (* func)(DCB*, MAXINFO_TREE*);
} set_commands[] =
{
{ "server", exec_set_server},
{ NULL, NULL}
{"server", exec_set_server},
{NULL, NULL }
};
/**
@ -382,8 +376,7 @@ static struct
* @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)
static void exec_set(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
@ -396,7 +389,7 @@ exec_set(DCB *dcb, MAXINFO_TREE *tree)
return;
}
}
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -410,7 +403,7 @@ exec_set(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_clear_server(DCB *dcb, MAXINFO_TREE *tree)
void exec_clear_server(DCB* dcb, MAXINFO_TREE* tree)
{
SERVER* server = server_find_by_unique_name(tree->value);
char errmsg[120];
@ -432,7 +425,7 @@ void exec_clear_server(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->right->value) > 80) // Prevent buffer overrun
if (strlen(tree->right->value) > 80) // Prevent buffer overrun
{
tree->right->value[80] = 0;
}
@ -442,7 +435,7 @@ void exec_clear_server(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -456,12 +449,12 @@ void exec_clear_server(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const char* name;
void (* func)(DCB*, MAXINFO_TREE*);
} clear_commands[] =
{
{ "server", exec_clear_server},
{ NULL, NULL}
{"server", exec_clear_server},
{NULL, NULL }
};
/**
@ -470,8 +463,7 @@ static struct
* @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)
static void exec_clear(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
@ -484,7 +476,7 @@ exec_clear(DCB *dcb, MAXINFO_TREE *tree)
return;
}
}
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -498,7 +490,7 @@ exec_clear(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_shutdown_maxscale(DCB *dcb, MAXINFO_TREE *tree)
void exec_shutdown_maxscale(DCB* dcb, MAXINFO_TREE* tree)
{
maxscale_shutdown();
maxinfo_send_ok(dcb);
@ -509,7 +501,7 @@ void exec_shutdown_maxscale(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_shutdown_monitor(DCB *dcb, MAXINFO_TREE *tree)
void exec_shutdown_monitor(DCB* dcb, MAXINFO_TREE* tree)
{
char errmsg[120];
if (tree && tree->value)
@ -522,7 +514,7 @@ void exec_shutdown_monitor(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -542,7 +534,7 @@ void exec_shutdown_monitor(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_shutdown_service(DCB *dcb, MAXINFO_TREE *tree)
void exec_shutdown_service(DCB* dcb, MAXINFO_TREE* tree)
{
char errmsg[120];
if (tree && tree->value)
@ -555,7 +547,7 @@ void exec_shutdown_service(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -575,14 +567,14 @@ void exec_shutdown_service(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const char* name;
void (* func)(DCB*, MAXINFO_TREE*);
} shutdown_commands[] =
{
{ "maxscale", exec_shutdown_maxscale},
{ "monitor", exec_shutdown_monitor},
{ "service", exec_shutdown_service},
{ NULL, NULL}
{"maxscale", exec_shutdown_maxscale},
{"monitor", exec_shutdown_monitor },
{"service", exec_shutdown_service },
{NULL, NULL }
};
/**
@ -591,8 +583,7 @@ static struct
* @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)
static void exec_shutdown(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
@ -605,7 +596,7 @@ exec_shutdown(DCB *dcb, MAXINFO_TREE *tree)
return;
}
}
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -619,7 +610,7 @@ exec_shutdown(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_restart_monitor(DCB *dcb, MAXINFO_TREE *tree)
void exec_restart_monitor(DCB* dcb, MAXINFO_TREE* tree)
{
char errmsg[120];
if (tree && tree->value)
@ -632,7 +623,7 @@ void exec_restart_monitor(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -652,7 +643,7 @@ void exec_restart_monitor(DCB *dcb, MAXINFO_TREE *tree)
* @param dcb Client DCB
* @param tree Parse tree
*/
void exec_restart_service(DCB *dcb, MAXINFO_TREE *tree)
void exec_restart_service(DCB* dcb, MAXINFO_TREE* tree)
{
char errmsg[120];
if (tree && tree->value)
@ -665,7 +656,7 @@ void exec_restart_service(DCB *dcb, MAXINFO_TREE *tree)
}
else
{
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -685,13 +676,13 @@ void exec_restart_service(DCB *dcb, MAXINFO_TREE *tree)
*/
static struct
{
const char *name;
void (*func)(DCB *, MAXINFO_TREE *);
const char* name;
void (* func)(DCB*, MAXINFO_TREE*);
} restart_commands[] =
{
{ "monitor", exec_restart_monitor},
{ "service", exec_restart_service},
{ NULL, NULL}
{"monitor", exec_restart_monitor},
{"service", exec_restart_service},
{NULL, NULL }
};
/**
@ -700,8 +691,7 @@ static struct
* @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)
static void exec_restart(DCB* dcb, MAXINFO_TREE* tree)
{
int i;
char errmsg[120];
@ -714,7 +704,7 @@ exec_restart(DCB *dcb, MAXINFO_TREE *tree)
return;
}
}
if (strlen(tree->value) > 80) // Prevent buffer overrun
if (strlen(tree->value) > 80) // Prevent buffer overrun
{
tree->value[80] = 0;
}
@ -728,20 +718,18 @@ exec_restart(DCB *dcb, MAXINFO_TREE *tree)
*
* @return The version string for MaxScale
*/
static char *
getVersion()
static char* getVersion()
{
return const_cast<char*>(MAXSCALE_VERSION);
}
static const char *versionComment = "MariaDB MaxScale";
static const char* versionComment = "MariaDB MaxScale";
/**
* Return the current MaxScale version
*
* @return The version string for MaxScale
*/
static char *
getVersionComment()
static char* getVersionComment()
{
return const_cast<char*>(versionComment);
}
@ -751,37 +739,36 @@ getVersionComment()
*
* @return The version string for MaxScale
*/
static char *
getMaxScaleHome()
static char* getMaxScaleHome()
{
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)();
typedef void* (* STATSFUNC)();
/**
* Variables that may be sent in a show variables
*/
static struct
{
const char *name;
int type;
const 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 }
{"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 }
};
std::string value_to_string(int type, STATSFUNC func)
@ -827,8 +814,7 @@ static void variable_row(std::unique_ptr<ResultSet>& set, const char* like)
* @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)
static void exec_show_variables(DCB* dcb, MAXINFO_TREE* filter)
{
std::unique_ptr<ResultSet> set = ResultSet::create({"Variable_name", "Value"});
variable_row(set, filter ? filter->value : NULL);
@ -850,8 +836,7 @@ std::unique_ptr<ResultSet> maxinfo_variables()
/**
* Interface to dcb_count_by_usage for all dcbs
*/
static int
maxinfo_all_dcbs()
static int maxinfo_all_dcbs()
{
return dcb_count_by_usage(DCB_USAGE_ALL);
}
@ -859,8 +844,7 @@ maxinfo_all_dcbs()
/**
* Interface to dcb_count_by_usage for client dcbs
*/
static int
maxinfo_client_dcbs()
static int maxinfo_client_dcbs()
{
return dcb_count_by_usage(DCB_USAGE_CLIENT);
}
@ -868,8 +852,7 @@ maxinfo_client_dcbs()
/**
* Interface to dcb_count_by_usage for listener dcbs
*/
static int
maxinfo_listener_dcbs()
static int maxinfo_listener_dcbs()
{
return dcb_count_by_usage(DCB_USAGE_LISTENER);
}
@ -877,8 +860,7 @@ maxinfo_listener_dcbs()
/**
* Interface to dcb_count_by_usage for backend dcbs
*/
static int
maxinfo_backend_dcbs()
static int maxinfo_backend_dcbs()
{
return dcb_count_by_usage(DCB_USAGE_BACKEND);
}
@ -886,8 +868,7 @@ maxinfo_backend_dcbs()
/**
* Interface to dcb_count_by_usage for internal dcbs
*/
static int
maxinfo_internal_dcbs()
static int maxinfo_internal_dcbs()
{
return dcb_count_by_usage(DCB_USAGE_INTERNAL);
}
@ -895,8 +876,7 @@ maxinfo_internal_dcbs()
/**
* Interface to poll stats for reads
*/
static int64_t
maxinfo_read_events()
static int64_t maxinfo_read_events()
{
return poll_get_stat(POLL_STAT_READ);
}
@ -904,8 +884,7 @@ maxinfo_read_events()
/**
* Interface to poll stats for writes
*/
static int64_t
maxinfo_write_events()
static int64_t maxinfo_write_events()
{
return poll_get_stat(POLL_STAT_WRITE);
}
@ -913,8 +892,7 @@ maxinfo_write_events()
/**
* Interface to poll stats for errors
*/
static int64_t
maxinfo_error_events()
static int64_t maxinfo_error_events()
{
return poll_get_stat(POLL_STAT_ERROR);
}
@ -922,8 +900,7 @@ maxinfo_error_events()
/**
* Interface to poll stats for hangup
*/
static int64_t
maxinfo_hangup_events()
static int64_t maxinfo_hangup_events()
{
return poll_get_stat(POLL_STAT_HANGUP);
}
@ -931,8 +908,7 @@ maxinfo_hangup_events()
/**
* Interface to poll stats for accepts
*/
static int64_t
maxinfo_accept_events()
static int64_t maxinfo_accept_events()
{
return poll_get_stat(POLL_STAT_ACCEPT);
}
@ -940,8 +916,7 @@ maxinfo_accept_events()
/**
* Interface to poll stats for event queue length
*/
static int64_t
maxinfo_avg_event_queue_length()
static int64_t maxinfo_avg_event_queue_length()
{
return poll_get_stat(POLL_STAT_EVQ_AVG);
}
@ -949,8 +924,7 @@ maxinfo_avg_event_queue_length()
/**
* Interface to poll stats for max event queue length
*/
static int64_t
maxinfo_max_event_queue_length()
static int64_t maxinfo_max_event_queue_length()
{
return poll_get_stat(POLL_STAT_EVQ_MAX);
}
@ -958,8 +932,7 @@ maxinfo_max_event_queue_length()
/**
* Interface to poll stats for max queue time
*/
static int64_t
maxinfo_max_event_queue_time()
static int64_t maxinfo_max_event_queue_time()
{
return poll_get_stat(POLL_STAT_MAX_QTIME);
}
@ -967,8 +940,7 @@ maxinfo_max_event_queue_time()
/**
* Interface to poll stats for max event execution time
*/
static int64_t
maxinfo_max_event_exec_time()
static int64_t maxinfo_max_event_exec_time()
{
return poll_get_stat(POLL_STAT_MAX_EXECTIME);
}
@ -978,32 +950,32 @@ maxinfo_max_event_exec_time()
*/
static struct
{
const char *name;
const 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 },
{ "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 },
{ "Avg_event_queue_length", VT_INT, (STATSFUNC)maxinfo_avg_event_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 }
{"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 },
{"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 },
{"Avg_event_queue_length", VT_INT, (STATSFUNC)maxinfo_avg_event_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 }
};
/**
@ -1030,7 +1002,7 @@ static void status_row(std::unique_ptr<ResultSet>& set, const char* like)
* @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)
static void exec_show_status(DCB* dcb, MAXINFO_TREE* filter)
{
std::unique_ptr<ResultSet> set = ResultSet::create({"Variable_name", "Value"});
status_row(set, filter ? filter->value : NULL);
@ -1056,8 +1028,7 @@ std::unique_ptr<ResultSet> maxinfo_status()
* @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)
static void exec_select(DCB* dcb, MAXINFO_TREE* tree)
{
maxinfo_send_error(dcb, 0, "Select not yet implemented");
}
@ -1069,11 +1040,10 @@ exec_select(DCB *dcb, MAXINFO_TREE *tree)
* @param str String to match against pattern
* @return Zero on match
*/
static int
maxinfo_pattern_match(const char *pattern, const char *str)
static int maxinfo_pattern_match(const char* pattern, const char* str)
{
int anchor = 0, len, trailing;
const char *fixed;
const char* fixed;
if (*pattern != '%')
{
@ -1103,7 +1073,7 @@ maxinfo_pattern_match(const char *pattern, const char *str)
}
else
{
char *portion = static_cast<char*>(MXS_MALLOC(len + 1));
char* portion = static_cast<char*>(MXS_MALLOC(len + 1));
MXS_ABORT_IF_NULL(portion);
int rval;
strncpy(portion, fixed, len - trailing);
@ -1118,7 +1088,7 @@ maxinfo_pattern_match(const char *pattern, const char *str)
* Send an OK packet to the client.
* @param dcb The DCB that connects to the client
*/
void maxinfo_send_ok(DCB *dcb)
void maxinfo_send_ok(DCB* dcb)
{
static const char ok_packet[] =
{

View File

@ -42,13 +42,15 @@
#include <maxscale/poll.h>
#include <maxscale/log.h>
static MAXINFO_TREE *make_tree_node(MAXINFO_OPERATOR, char *, MAXINFO_TREE *, MAXINFO_TREE *);
void maxinfo_free_tree(MAXINFO_TREE *); // This function is needed by maxinfo.c
static char *fetch_token(char *, int *, char **);
static MAXINFO_TREE *parse_column_list(char **sql);
static MAXINFO_TREE *parse_table_name(char **sql);
MAXINFO_TREE* maxinfo_parse_literals(MAXINFO_TREE *tree, int min_args, char *ptr,
PARSE_ERROR *parse_error);
static MAXINFO_TREE* make_tree_node(MAXINFO_OPERATOR, char*, MAXINFO_TREE*, MAXINFO_TREE*);
void maxinfo_free_tree(MAXINFO_TREE*); // This function is needed by maxinfo.c
static char* fetch_token(char*, int*, char**);
static MAXINFO_TREE* parse_column_list(char** sql);
static MAXINFO_TREE* parse_table_name(char** sql);
MAXINFO_TREE* maxinfo_parse_literals(MAXINFO_TREE* tree,
int min_args,
char* ptr,
PARSE_ERROR* parse_error);
/**
* Parse a SQL subset for the maxinfo plugin and return a parse tree
@ -56,13 +58,12 @@ MAXINFO_TREE* maxinfo_parse_literals(MAXINFO_TREE *tree, int min_args, char *ptr
* @param sql The SQL query
* @return Parse tree or NULL on error
*/
MAXINFO_TREE *
maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
MAXINFO_TREE* maxinfo_parse(char* sql, PARSE_ERROR* parse_error)
{
int token;
char *ptr, *text;
MAXINFO_TREE *tree = NULL;
MAXINFO_TREE *col, *table;
char* ptr, * text;
MAXINFO_TREE* tree = NULL;
MAXINFO_TREE* col, * table;
*parse_error = PARSE_NOERROR;
while ((ptr = fetch_token(sql, &token, &text)) != NULL)
@ -70,7 +71,7 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
switch (token)
{
case LT_SHOW:
MXS_FREE(text); // not needed
MXS_FREE(text); // not needed
ptr = fetch_token(ptr, &token, &text);
if (ptr == NULL || token != LT_STRING)
{
@ -88,7 +89,9 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
if ((ptr = fetch_token(ptr, &token, &text)) != NULL)
{
tree->right = make_tree_node(MAXOP_LIKE,
text, NULL, NULL);
text,
NULL,
NULL);
return tree;
}
else
@ -104,15 +107,17 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
maxinfo_free_tree(tree);
*parse_error = PARSE_MALFORMED_SHOW;
return NULL;
#if 0
case LT_SELECT:
MXS_FREE(text); // not needed
MXS_FREE(text); // not needed
col = parse_column_list(&ptr);
table = parse_table_name(&ptr);
return make_tree_node(MAXOP_SELECT, NULL, col, table);
#endif
case LT_FLUSH:
MXS_FREE(text); // not needed
MXS_FREE(text); // not needed
ptr = fetch_token(ptr, &token, &text);
return make_tree_node(MAXOP_FLUSH, text, NULL, NULL);
@ -162,17 +167,18 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
return tree;
case LT_SET:
MXS_FREE(text); // not needed
MXS_FREE(text); // not needed
ptr = fetch_token(ptr, &token, &text);
tree = make_tree_node(MAXOP_SET, text, NULL, NULL);
return maxinfo_parse_literals(tree, 2, ptr, parse_error);
case LT_CLEAR:
MXS_FREE(text); // not needed
MXS_FREE(text); // not needed
ptr = fetch_token(ptr, &token, &text);
tree = make_tree_node(MAXOP_CLEAR, text, NULL, NULL);
return maxinfo_parse_literals(tree, 2, ptr, parse_error);
break;
default:
*parse_error = PARSE_SYNTAX_ERROR;
return NULL;
@ -189,13 +195,12 @@ maxinfo_parse(char *sql, PARSE_ERROR *parse_error)
* @param sql Pointer to pointer to column list updated to point to the table name
* @return A tree of column names
*/
static MAXINFO_TREE *
parse_column_list(char **ptr)
static MAXINFO_TREE* parse_column_list(char** ptr)
{
int token, lookahead;
char *text, *text2;
MAXINFO_TREE *tree = NULL;
MAXINFO_TREE *rval = NULL;
char* text, * text2;
MAXINFO_TREE* tree = NULL;
MAXINFO_TREE* rval = NULL;
*ptr = fetch_token(*ptr, &token, &text);
*ptr = fetch_token(*ptr, &lookahead, &text2);
switch (token)
@ -204,22 +209,34 @@ parse_column_list(char **ptr)
switch (lookahead)
{
case LT_COMMA:
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
rval = make_tree_node(MAXOP_COLUMNS,
text,
NULL,
parse_column_list(ptr));
break;
case LT_FROM:
rval = make_tree_node(MAXOP_COLUMNS, text, NULL,
rval = make_tree_node(MAXOP_COLUMNS,
text,
NULL,
NULL);
break;
default:
break;
}
break;
case LT_STAR:
if (lookahead != LT_FROM)
rval = make_tree_node(MAXOP_ALL_COLUMNS, NULL, NULL,
{
rval = make_tree_node(MAXOP_ALL_COLUMNS,
NULL,
NULL,
NULL);
}
break;
default:
break;
}
@ -235,15 +252,14 @@ parse_column_list(char **ptr)
* @param sql Pointer to pointer to column list updated to point to the table name
* @return A tree of table names
*/
static MAXINFO_TREE *
parse_table_name(char **ptr)
static MAXINFO_TREE* parse_table_name(char** ptr)
{
int token;
char *text;
MAXINFO_TREE *tree = NULL;
char* text;
MAXINFO_TREE* tree = NULL;
*ptr = fetch_token(*ptr, &token, &text);
if (token == LT_STRING)
if (token == LT_STRING)
{
return make_tree_node(MAXOP_TABLE, text, NULL, NULL);
}
@ -260,12 +276,11 @@ parse_table_name(char **ptr)
* @param right The right branch of the parse tree
* @return The new parse tree node
*/
static MAXINFO_TREE *
make_tree_node(MAXINFO_OPERATOR op, char *value, MAXINFO_TREE *left, MAXINFO_TREE *right)
static MAXINFO_TREE* make_tree_node(MAXINFO_OPERATOR op, char* value, MAXINFO_TREE* left, MAXINFO_TREE* right)
{
MAXINFO_TREE *node;
MAXINFO_TREE* node;
if ((node = (MAXINFO_TREE *)MXS_MALLOC(sizeof(MAXINFO_TREE))) == NULL)
if ((node = (MAXINFO_TREE*)MXS_MALLOC(sizeof(MAXINFO_TREE))) == NULL)
{
return NULL;
}
@ -282,8 +297,7 @@ make_tree_node(MAXINFO_OPERATOR op, char *value, MAXINFO_TREE *left, MAXINFO_TRE
*
* @param tree The parse tree to free
*/
void
maxinfo_free_tree(MAXINFO_TREE *tree)
void maxinfo_free_tree(MAXINFO_TREE* tree)
{
if (tree->left)
{
@ -305,23 +319,23 @@ maxinfo_free_tree(MAXINFO_TREE *tree)
*/
static struct
{
const char *text;
int token;
const char* text;
int token;
} keywords[] =
{
{ "show", LT_SHOW},
{ "select", LT_SELECT},
{ "from", LT_FROM},
{ "like", LT_LIKE},
{ "=", LT_EQUAL},
{ ",", LT_COMMA},
{ "*", LT_STAR},
{ "flush", LT_FLUSH},
{ "set", LT_SET},
{ "clear", LT_CLEAR},
{ "shutdown", LT_SHUTDOWN},
{ "restart", LT_RESTART},
{ NULL, 0}
{"show", LT_SHOW },
{"select", LT_SELECT },
{"from", LT_FROM },
{"like", LT_LIKE },
{"=", LT_EQUAL },
{",", LT_COMMA },
{"*", LT_STAR },
{"flush", LT_FLUSH },
{"set", LT_SET },
{"clear", LT_CLEAR },
{"shutdown", LT_SHUTDOWN},
{"restart", LT_RESTART },
{NULL, 0 }
};
/**
@ -333,10 +347,9 @@ static struct
* @param text The matching text
* @return The next position to tokenise from
*/
static char *
fetch_token(char *sql, int *token, char **text)
static char* fetch_token(char* sql, int* token, char** text)
{
char *s1, *s2, quote = '\0';
char* s1, * s2, quote = '\0';
int i;
s1 = sql;
@ -419,16 +432,18 @@ fetch_token(char *sql, int *token, char **text)
* @param parse_error Pointer to parsing error to fill
* @return Parsed tree or NULL if parsing failed
*/
MAXINFO_TREE* maxinfo_parse_literals(MAXINFO_TREE *tree, int min_args, char *ptr,
PARSE_ERROR *parse_error)
MAXINFO_TREE* maxinfo_parse_literals(MAXINFO_TREE* tree,
int min_args,
char* ptr,
PARSE_ERROR* parse_error)
{
int token;
MAXINFO_TREE* node = tree;
char *text;
char* text;
for (int i = 0; i < min_args; i++)
{
if ((ptr = fetch_token(ptr, &token, &text)) == NULL ||
(node->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL)) == NULL)
if ((ptr = fetch_token(ptr, &token, &text)) == NULL
|| (node->right = make_tree_node(MAXOP_LITERAL, text, NULL, NULL)) == NULL)
{
*parse_error = PARSE_SYNTAX_ERROR;
maxinfo_free_tree(tree);