mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
Refactor management command list to allow it to be declared const with no warnings
This commit is contained in:
parent
3e2c2d63bc
commit
06b8f1a08f
|
@ -301,7 +301,7 @@ static void mgmt_unimplemented (mgmt_req_t *req, char *udp_buf, char *argv0, cha
|
||||||
// Forward define so we can include this in the mgmt_handlers[] table
|
// Forward define so we can include this in the mgmt_handlers[] table
|
||||||
static void mgmt_help (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv);
|
static void mgmt_help (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv);
|
||||||
|
|
||||||
static mgmt_handler_t mgmt_handlers[] = {
|
static const mgmt_handler_t mgmt_handlers[] = {
|
||||||
{ .cmd = "reload_communities", .flags = FLAG_WROK, .help = "Reserved for supernode", .func = mgmt_unimplemented},
|
{ .cmd = "reload_communities", .flags = FLAG_WROK, .help = "Reserved for supernode", .func = mgmt_unimplemented},
|
||||||
|
|
||||||
{ .cmd = "stop", .flags = FLAG_WROK, .help = "Gracefully exit edge", .func = mgmt_stop},
|
{ .cmd = "stop", .flags = FLAG_WROK, .help = "Gracefully exit edge", .func = mgmt_stop},
|
||||||
|
@ -313,7 +313,6 @@ static mgmt_handler_t mgmt_handlers[] = {
|
||||||
{ .cmd = "packetstats", .help = "traffic counters", .func = mgmt_packetstats},
|
{ .cmd = "packetstats", .help = "traffic counters", .func = mgmt_packetstats},
|
||||||
{ .cmd = "help", .flags = FLAG_WROK, .help = "Show JSON commands", .func = mgmt_help},
|
{ .cmd = "help", .flags = FLAG_WROK, .help = "Show JSON commands", .func = mgmt_help},
|
||||||
// TODO: help_events
|
// TODO: help_events
|
||||||
{ .cmd = NULL },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Current subscriber for each event topic */
|
/* Current subscriber for each event topic */
|
||||||
|
@ -332,14 +331,15 @@ static mgmt_events_t mgmt_event_names[] = {
|
||||||
|
|
||||||
static void mgmt_help (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv) {
|
static void mgmt_help (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv) {
|
||||||
size_t msg_len;
|
size_t msg_len;
|
||||||
mgmt_handler_t *handler;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Even though this command is readonly, we deliberately do not check
|
* Even though this command is readonly, we deliberately do not check
|
||||||
* the type - allowing help replies to both read and write requests
|
* the type - allowing help replies to both read and write requests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( handler=mgmt_handlers; handler->cmd; handler++ ) {
|
int i;
|
||||||
|
int nr_handlers = sizeof(mgmt_handlers) / sizeof(mgmt_handler_t);
|
||||||
|
for( i=0; i < nr_handlers; i++ ) {
|
||||||
msg_len = snprintf(udp_buf, N2N_PKT_BUF_SIZE,
|
msg_len = snprintf(udp_buf, N2N_PKT_BUF_SIZE,
|
||||||
"{"
|
"{"
|
||||||
"\"_tag\":\"%s\","
|
"\"_tag\":\"%s\","
|
||||||
|
@ -347,8 +347,8 @@ static void mgmt_help (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv)
|
||||||
"\"cmd\":\"%s\","
|
"\"cmd\":\"%s\","
|
||||||
"\"help\":\"%s\"}\n",
|
"\"help\":\"%s\"}\n",
|
||||||
req->tag,
|
req->tag,
|
||||||
handler->cmd,
|
mgmt_handlers[i].cmd,
|
||||||
handler->help);
|
mgmt_handlers[i].help);
|
||||||
|
|
||||||
send_reply(req, udp_buf, msg_len);
|
send_reply(req, udp_buf, msg_len);
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,6 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
|
||||||
char *flagstr;
|
char *flagstr;
|
||||||
int flags;
|
int flags;
|
||||||
char *auth;
|
char *auth;
|
||||||
mgmt_handler_t *handler;
|
|
||||||
size_t msg_len;
|
size_t msg_len;
|
||||||
|
|
||||||
/* Initialise the tag field until we extract it from the cmdline */
|
/* Initialise the tag field until we extract it from the cmdline */
|
||||||
|
@ -463,17 +462,19 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( handler=mgmt_handlers; handler->cmd; handler++ ) {
|
int handler;
|
||||||
if(0 == strcmp(handler->cmd, argv0)) {
|
int nr_handlers = sizeof(mgmt_handlers) / sizeof(mgmt_handler_t);
|
||||||
|
for( handler=0; handler < nr_handlers; handler++ ) {
|
||||||
|
if(0 == strcmp(mgmt_handlers[handler].cmd, argv0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!handler->cmd) {
|
if(handler >= nr_handlers) {
|
||||||
mgmt_error(req, udp_buf, "unknowncmd");
|
mgmt_error(req, udp_buf, "unknowncmd");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((req->type==N2N_MGMT_WRITE) && !(handler->flags & FLAG_WROK)) {
|
if((req->type==N2N_MGMT_WRITE) && !(mgmt_handlers[handler].flags & FLAG_WROK)) {
|
||||||
mgmt_error(req, udp_buf, "readonly");
|
mgmt_error(req, udp_buf, "readonly");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -488,7 +489,7 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
|
||||||
"{\"_tag\":\"%s\",\"_type\":\"begin\",\"cmd\":\"%s\"}\n", req->tag, argv0);
|
"{\"_tag\":\"%s\",\"_type\":\"begin\",\"cmd\":\"%s\"}\n", req->tag, argv0);
|
||||||
send_reply(req, udp_buf, msg_len);
|
send_reply(req, udp_buf, msg_len);
|
||||||
|
|
||||||
handler->func(req, udp_buf, argv0, argv);
|
mgmt_handlers[handler].func(req, udp_buf, argv0, argv);
|
||||||
|
|
||||||
msg_len = snprintf(udp_buf, N2N_PKT_BUF_SIZE,
|
msg_len = snprintf(udp_buf, N2N_PKT_BUF_SIZE,
|
||||||
"{\"_tag\":\"%s\",\"_type\":\"end\"}\n", req->tag);
|
"{\"_tag\":\"%s\",\"_type\":\"end\"}\n", req->tag);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user