diff options
author | Christian Pointner <equinox@helsinki.at> | 2013-09-16 15:31:26 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2013-09-16 15:31:26 (GMT) |
commit | b2d6dd99684a3260d4b719c28819d4c61da0f8ba (patch) | |
tree | 3d4b171e86a15014a6c0f2601e78af827f44d40b | |
parent | 4dbc730656002f93cbbc0824e4b2d46d1ede6983 (diff) |
added help command
-rw-r--r-- | switchctl.c | 31 |
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); \ |