button does not need user
[svn42.git] / go / door_daemon_zmq / handle_commands.go
index 35c3b02..e8c3334 100644 (file)
@@ -15,14 +15,14 @@ var cmdToDoorCmdHandler = map[string]DoorCmdHandler {
   "open": DoorCmdHandler{ checkCmdDoorControl, "o"},
   "close": DoorCmdHandler{ checkCmdDoorControl, "c"},
   "toggle": DoorCmdHandler{ checkCmdDoorControl, "t"},
-  "status": DoorCmdHandler{ checkCmdDoorControl, "s"},
+  "status": DoorCmdHandler{ checkCmdNoArgs, "s"},
 }
 
 // ---------- Command Handling Code -------------
 
 func checkCmdDoorControl(tokens [][]byte) (error) {
     doorctrl_usage := "syntax: <open|close|toggle> <method> <nickname>"
-    if len(tokens) != 3 {
+    if len(tokens) < 2  || len(tokens) > 3 {
         return errors.New(doorctrl_usage)
     }
     cmd := string(tokens[0])
@@ -33,15 +33,15 @@ func checkCmdDoorControl(tokens [][]byte) (error) {
     if ! (method == "Button" || method == "ssh" || method == "SSH" || method == "Phone") {
         return errors.New("method must be one either Button, SSH or Phone")
     }
-    if len(tokens[2]) == 0 && method != "Button" {
+    if (len(tokens) == 2 || len(tokens[2]) == 0) && method != "Button" {
         return errors.New("Operator nickname must be given")
     }
     return nil
 }
 
-func checkCmdStatus(tokens [][]byte) (error) {
+func checkCmdNoArgs(tokens [][]byte) (error) {
     if len(tokens) != 1 {
-        return errors.New("status command does not accept arguments")
+        return errors.New("command does not accept arguments")
     }
     return nil
 }
@@ -57,8 +57,7 @@ func HandleCommand(tokens [][]byte, serial_wr chan string, serial_rd chan [][]by
     }
 
     if err := dch.Checker(tokens); err != nil {
-        //return error to sender
-        return nil
+        return err
     }
 
     serial_wr <- dch.FirmwareChar