implement a 'toggle' option for 'console mute' and 'console unmute'
authorLuigi Rizzo <rizzo@icir.org>
Sun, 29 Jun 2008 13:02:54 +0000 (13:02 +0000)
committerLuigi Rizzo <rizzo@icir.org>
Sun, 29 Jun 2008 13:02:54 +0000 (13:02 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@126311 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_oss.c

index 268ff78..e665eb2 100644 (file)
@@ -1125,25 +1125,32 @@ static char *console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args
 {
        struct chan_oss_pvt *o = find_desc(oss_active);
        char *s;
+       int toggle = 0;
        
        if (cmd == CLI_INIT) {
-               e->command = "console {mute|unmute}";
+               e->command = "console {mute|unmute} [toggle]";
                e->usage =
-                       "Usage: console {mute|unmute}\n"
+                       "Usage: console {mute|unmute} [toggle]\n"
                        "       Mute/unmute the microphone.\n";
                return NULL;
        } else if (cmd == CLI_GENERATE)
                return NULL;
 
-       if (a->argc != e->args)
+       if (a->argc > e->args)
                return CLI_SHOWUSAGE;
-       s = a->argv[e->args-1];
+       if (a->argc == e->args) {
+               if (strcasecmp(a->argv[e->args-1], "toggle"))
+                       return CLI_SHOWUSAGE;
+               toggle = 1;
+       }
+       s = a->argv[e->args-2];
        if (!strcasecmp(s, "mute"))
-               o->mute = 1;
+               o->mute = toggle ? ~o->mute : 1;
        else if (!strcasecmp(s, "unmute"))
-               o->mute = 0;
+               o->mute = toggle ? ~o->mute : 0;
        else
                return CLI_SHOWUSAGE;
+       ast_cli(a->fd, "Console mic is %s\n", o->mute ? "off" : "on");
        return CLI_SUCCESS;
 }