Browse Source

Implement initial help command for subscription topics

pull/947/head
Hamish Coleman 3 years ago
parent
commit
e2a33b7571
  1. 53
      src/edge_management.c

53
src/edge_management.c

@ -20,8 +20,10 @@
#include "edge_utils_win32.h" #include "edge_utils_win32.h"
enum n2n_mgmt_type { enum n2n_mgmt_type {
N2N_MGMT_READ = 0, N2N_MGMT_UNKNOWN = 0,
N2N_MGMT_WRITE = 1, N2N_MGMT_READ = 1,
N2N_MGMT_WRITE = 2,
N2N_MGMT_SUB = 3,
}; };
/* /*
@ -305,6 +307,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 void mgmt_help_events (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv);
static const 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},
@ -317,13 +320,13 @@ static const mgmt_handler_t mgmt_handlers[] = {
{ .cmd = "timestamps", .help = "Event timestamps", .func = mgmt_timestamps}, { .cmd = "timestamps", .help = "Event timestamps", .func = mgmt_timestamps},
{ .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 { .cmd = "help.events", .help = "Show available Subscribe topics", .func = mgmt_help_events},
}; };
#define MAX_TOPICS 10
/* Current subscriber for each event topic */ /* Current subscriber for each event topic */
static mgmt_req_t *mgmt_event_subscribers[MAX_TOPICS]; static mgmt_req_t mgmt_event_subscribers[] = {
[0] = { .eee = NULL, .type = N2N_MGMT_UNKNOWN, .tag = "\0" },
};
/* Map topic number to function */ /* Map topic number to function */
static const void (*mgmt_events[])(mgmt_req_t *req, char *udp_buf) = { static const void (*mgmt_events[])(mgmt_req_t *req, char *udp_buf) = {
@ -331,11 +334,37 @@ static const void (*mgmt_events[])(mgmt_req_t *req, char *udp_buf) = {
}; };
/* Allow help and subscriptions to use topic name */ /* Allow help and subscriptions to use topic name */
static mgmt_events_t mgmt_event_names[] = { static const mgmt_events_t mgmt_event_names[] = {
{ .cmd = "debug", .topic = 0, .help = "All events - for event debugging"}, { .cmd = "debug", .topic = 0, .help = "All events - for event debugging"},
{ .cmd = NULL },
}; };
static void mgmt_help_events (mgmt_req_t *req, char *udp_buf, char *argv0, char *argv) {
size_t msg_len;
int i;
int nr_handlers = sizeof(mgmt_event_names) / sizeof(mgmt_events_t);
for( i=0; i < nr_handlers; i++ ) {
int topic = mgmt_event_names[i].topic;
mgmt_req_t *sub = &mgmt_event_subscribers[topic];
msg_len = snprintf(udp_buf, N2N_PKT_BUF_SIZE,
"{"
"\"_tag\":\"%s\","
"\"_type\":\"row\","
"\"topic\":\"%s\","
"\"tag\":\"%s\","
// "\"sockaddr\":\"%s\","
"\"help\":\"%s\"}\n",
req->tag,
mgmt_event_names[i].cmd,
sub->tag,
// "FIXME",
mgmt_event_names[i].help);
send_reply(req, udp_buf, msg_len);
}
}
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;
@ -418,8 +447,9 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
req->type=N2N_MGMT_READ; req->type=N2N_MGMT_READ;
} else if(*typechar == 'w') { } else if(*typechar == 'w') {
req->type=N2N_MGMT_WRITE; req->type=N2N_MGMT_WRITE;
} else if(*typechar == 's') {
req->type=N2N_MGMT_SUB;
} else { } else {
/* dunno how we got here */
mgmt_error(req, udp_buf, "badtype"); mgmt_error(req, udp_buf, "badtype");
return; return;
} }
@ -469,6 +499,11 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
return; return;
} }
if(req->type == N2N_MGMT_SUB) {
mgmt_error(req, udp_buf, "unimplemented");
return;
}
int handler; int handler;
int nr_handlers = sizeof(mgmt_handlers) / sizeof(mgmt_handler_t); int nr_handlers = sizeof(mgmt_handlers) / sizeof(mgmt_handler_t);
for( handler=0; handler < nr_handlers; handler++ ) { for( handler=0; handler < nr_handlers; handler++ ) {

Loading…
Cancel
Save