summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--switchctl.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/switchctl.c b/switchctl.c
index 7917a89..8928a12 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -81,6 +81,22 @@ int send_response(int fd, const char* response)
return ret;
}
+void send_usage(int fd)
+{
+ if(fd < 0)
+ return 0;
+
+ send_response(fd, "Usage: ");
+ send_response(fd, " help prints this");
+ send_response(fd, " switch send raw commands to the switch");
+ send_response(fd, " channel tba...");
+ send_response(fd, " type tba...");
+ send_response(fd, " mode tba...");
+ send_response(fd, " status tba...");
+ send_response(fd, " log tba...");
+ send_response(fd, " listen tba...");
+}
+
int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
client_t* c = client_find(client_lst, fd);
@@ -512,12 +528,15 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
cmd_id = STATUS;
else if(!strncmp(cmd, "log", 3))
cmd_id = LOG;
- else if(!strncmp(cmd, "listen", 6)) {
+ else if(!strncmp(cmd, "listen", 6))
cmd_id = LISTEN;
- }
else {
- log_printf(WARNING, "unknown command '%s'", cmd);
- send_response(fd, "EEE: unknown command");
+ if(!strncmp(cmd, "help", 4)) {
+ send_usage(fd);
+ } else {
+ log_printf(WARNING, "unknown command '%s'", cmd);
+ send_response(fd, "EEE: unknown command");
+ }
return 0;
}
char* param = strchr(cmd, ' ');
@@ -608,12 +627,12 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
}
#define SEND_TO_LISTENER(STRING, LEN, FLAG) \
- if(!strncmp((char *)(buffer->buf), STRING, LEN)) { \
+ if(!strncmp((char *)(buffer->buf), STRING, LEN)) { \
client_t* client; \
int listener_cnt = 0; \
for(client = client_lst; client; client = client->next) \
if(client->FLAG && client->fd != cmd_fd) { \
- send_response(client->fd, (char *)(buffer->buf)); \
+ send_response(client->fd, (char *)(buffer->buf)); \
listener_cnt++; \
} \
log_printf(DEBUG, "sent message to %d additional listeners", listener_cnt); \