diff options
author | Dan McGee <dpmcgee@gmail.com> | 2011-01-21 15:25:45 -0600 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2011-01-21 15:25:45 -0600 |
commit | 7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53 (patch) | |
tree | 0d82af345de7ff8eec14c176e344d212c92b01f6 | |
parent | 4cd1fdbb7c0377c9be616569036b2e52ad30ce96 (diff) | |
download | onkyocontrol-7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53.tar.gz onkyocontrol-7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53.zip |
Add quit command
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r-- | command.c | 12 | ||||
-rw-r--r-- | onkyo.c | 2 |
2 files changed, 11 insertions, 3 deletions
@@ -460,6 +460,11 @@ static int handle_raw(const struct command *cmd, const char *arg) return cmd_attempt(cmd, arg); } +static int handle_quit(UNUSED const struct command *cmd, UNUSED const char *arg) +{ + return -2; +} + /** * Add the command with the given name and handler to our command list. This * will allow process_command() to locate the correct handler for a command. @@ -539,6 +544,7 @@ void init_commands(void) add_command("zone3sleep", "SP3", handle_sleep, 1); add_command("raw", "", handle_raw, 0); + add_command("quit", "", handle_quit, 0); ptr = command_list; while(ptr) { @@ -568,7 +574,8 @@ void free_commands(void) * the work to it. If no handler is found, return an error; otherwise * return the relevant human-readable status message. * @param str the full command string, e.g. "power on" - * @return 0 if the command string was correct and sent, -1 on invalid command + * @return 0 if the command string was correct and sent, -1 on invalid command, + * -2 if we should quit/close the connection * string */ int process_command(const char *str) @@ -584,9 +591,8 @@ int process_command(const char *str) cmdstr = strdup(str); /* start by killing trailing whitespace of any sort */ c = cmdstr + strlen(cmdstr) - 1; - while(isspace(*c) && c >= cmdstr) { + while(isspace(*c) && c >= cmdstr) *c-- = '\0'; - } /* start by splitting the string after the cmd */ argstr = strchr(cmdstr, ' '); /* if we had an arg, set our pointers correctly */ @@ -600,6 +600,8 @@ static int process_input(struct conn *c) /* watch our write for a failure */ if(xwrite(c->fd, invalid_cmd, strlen(invalid_cmd)) == -1) ret = -2; + } else if(processret == -2) { + end_connection(c, 0); } /* now move our remaining buffer to the start of our buffer */ c->recv_buf_pos++; |