Add ability to hangup all channels from the CLI.
authorLeif Madsen <leif@leifmadsen.com>
Wed, 19 May 2010 15:12:18 +0000 (15:12 +0000)
committerLeif Madsen <leif@leifmadsen.com>
Wed, 19 May 2010 15:12:18 +0000 (15:12 +0000)
Added the keyword 'all' to the 'channel hangup request' CLI command
so that you can request all channels to be hungup without having to
restart Asterisk.

(closes issue #16009)
Reported by: moy
Patches:
      hangup-all-rev-221688.patch uploaded by moy (license 222)
Tested by: moy, russell

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@264117 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
main/cli.c

diff --git a/CHANGES b/CHANGES
index 238f250..ddb3eb7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -455,6 +455,8 @@ CLI Changes
    files it was built from.
  * New 'manager show settings' command showing the current settings loaded from
    manager.conf. 
    files it was built from.
  * New 'manager show settings' command showing the current settings loaded from
    manager.conf. 
+ * Added 'all' keyword to the CLI command "channel request hangup" so that you can send
+   the channel hangup request to all channels.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.6.1 to Asterisk 1.6.2  -------------
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.6.1 to Asterisk 1.6.2  -------------
index acb1f6b..841082d 100644 (file)
@@ -936,9 +936,11 @@ static char *handle_softhangup(struct ast_cli_entry *e, int cmd, struct ast_cli_
        case CLI_INIT:
                e->command = "channel request hangup";
                e->usage =
        case CLI_INIT:
                e->command = "channel request hangup";
                e->usage =
-                       "Usage: channel request hangup <channel>\n"
+                       "Usage: channel request hangup <channel>|<all>\n"
                        "       Request that a channel be hung up. The hangup takes effect\n"
                        "       Request that a channel be hung up. The hangup takes effect\n"
-                       "       the next time the driver reads or writes from the channel\n";
+                       "       the next time the driver reads or writes from the channel.\n"
+                       "       If 'all' is specified instead of a channel name, all channels\n"
+                       "       will see the hangup request.\n";
                return NULL;
        case CLI_GENERATE:
                return ast_complete_channels(a->line, a->word, a->pos, a->n, e->args);
                return NULL;
        case CLI_GENERATE:
                return ast_complete_channels(a->line, a->word, a->pos, a->n, e->args);
@@ -948,7 +950,19 @@ static char *handle_softhangup(struct ast_cli_entry *e, int cmd, struct ast_cli_
                return CLI_SHOWUSAGE;
        }
 
                return CLI_SHOWUSAGE;
        }
 
-       if ((c = ast_channel_get_by_name(a->argv[3]))) {
+       if (!strcasecmp(a->argv[3], "all")) {
+               struct ast_channel_iterator *iter = NULL;
+               if (!(iter = ast_channel_iterator_all_new(0))) {
+                       return CLI_FAILURE;
+               }
+               for (; iter && (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
+                       ast_channel_lock(c);
+                       ast_cli(a->fd, "Requested Hangup on channel '%s'\n", c->name);
+                       ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
+                       ast_channel_unlock(c);
+               }
+               ast_channel_iterator_destroy(iter);
+       } else if ((c = ast_channel_get_by_name(a->argv[3]))) {
                ast_channel_lock(c);
                ast_cli(a->fd, "Requested Hangup on channel '%s'\n", c->name);
                ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
                ast_channel_lock(c);
                ast_cli(a->fd, "Requested Hangup on channel '%s'\n", c->name);
                ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);