res_agi: Add AGIEXITONHANGUP variable.
authorRussell Bryant <russell@russellbryant.com>
Tue, 14 Feb 2012 00:43:50 +0000 (00:43 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 14 Feb 2012 00:43:50 +0000 (00:43 +0000)
This patch adds a variable AGIEXITONHANGUP for res_agi.  If this variable is
set to "yes" on a channel, AGI() will exit immediately once a channel hangup
has been detected.  This was the behavior of AGI() in Asterisk 1.4 and earlier
and is still desired by some people.

Review: https://reviewboard.asterisk.org/r/1734/

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

CHANGES
res/res_agi.c

diff --git a/CHANGES b/CHANGES
index e40ed41..4b6e3d2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -188,6 +188,12 @@ res_corosync
    is a replacement for the res_ais module that was in previous releases of
    Asterisk.
 
+AGI
+---
+ * A new channel variable, AGIEXITONHANGUP, has been added which allows
+   Asterisk to behave like it did in Asterisk 1.4 and earlier where the
+   AGI application would exit immediately after a channel hangup is detected.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.8 to Asterisk 10 -------------------
 ------------------------------------------------------------------------------
index 511f440..4440291 100644 (file)
@@ -819,7 +819,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        hangup from the channel except when using DeadAGI. A fast AGI server will
                        correspondingly receive a HANGUP inline with the command dialog. Both of theses
                        signals may be disabled by setting the <variable>AGISIGHUP</variable> channel
-                       variable to <literal>no</literal> before executing the AGI application.</para>
+                       variable to <literal>no</literal> before executing the AGI application.
+                       Alternatively, if you would like the AGI application to exit immediately
+                       after a channel hangup is detected, set the <variable>AGIEXITONHANGUP</variable>
+                       variable to <literal>yes</literal>.</para>
                        <para>Use the CLI command <literal>agi show commands</literal> to list available agi
                        commands.</para>
                        <para>This application sets the following channel variable upon completion:</para>
@@ -3477,10 +3480,14 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
        int retry = AGI_NANDFS_RETRY;
        int send_sighup;
        const char *sighup_str;
+       const char *exit_on_hangup_str;
+       int exit_on_hangup;
        
        ast_channel_lock(chan);
        sighup_str = pbx_builtin_getvar_helper(chan, "AGISIGHUP");
-       send_sighup = ast_strlen_zero(sighup_str) || !ast_false(sighup_str);
+       send_sighup = !ast_false(sighup_str);
+       exit_on_hangup_str = pbx_builtin_getvar_helper(chan, "AGIEXITONHANGUP");
+       exit_on_hangup = ast_true(exit_on_hangup_str);
        ast_channel_unlock(chan);
 
        if (!(readf = fdopen(agi->ctrl, "r"))) {
@@ -3504,6 +3511,9 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi
                                        ast_agi_send(agi->fd, chan, "HANGUP\n");
                                }
                        }
+                       if (exit_on_hangup) {
+                               break;
+                       }
                }
                ms = -1;
                if (dead) {