summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2011-01-21 15:25:45 -0600
committerDan McGee <dpmcgee@gmail.com>2011-01-21 15:25:45 -0600
commit7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53 (patch)
tree0d82af345de7ff8eec14c176e344d212c92b01f6
parent4cd1fdbb7c0377c9be616569036b2e52ad30ce96 (diff)
downloadonkyocontrol-7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53.tar.gz
onkyocontrol-7cedc8c6e81d9d1b5dc868c453a0b02d5dba1a53.zip
Add quit command
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r--command.c12
-rw-r--r--onkyo.c2
2 files changed, 11 insertions, 3 deletions
diff --git a/command.c b/command.c
index 75bbdd7..d15052b 100644
--- a/command.c
+++ b/command.c
@@ -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 */
diff --git a/onkyo.c b/onkyo.c
index a1d02b6..49fb2ba 100644
--- a/onkyo.c
+++ b/onkyo.c
@@ -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++;