[asterisk-commits] jrose: trunk r402995 - in /trunk: CHANGES apps/app_directory.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 21 16:38:34 CST 2013


Author: jrose
Date: Thu Nov 21 16:38:31 2013
New Revision: 402995

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=402995
Log:
app_directory: Set variable indicating reason directory exited

By the time the directory application exits, a channel variable
DIRECTORY_RESULT will be set for the channel that invoked it which
can be used to determine the reason for exit. The changes log and
the app_directory documentation contain specific details about
each of the possible values for DIRECTORY_RESULT.

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

Modified:
    trunk/CHANGES
    trunk/apps/app_directory.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=402995&r1=402994&r2=402995
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Thu Nov 21 16:38:31 2013
@@ -25,6 +25,18 @@
    implies 'announce_join_leave' with the added effect that the user will
    be asked if they want to confirm or re-record the recording of their
    name when entering the conference
+
+Directory
+--------------------------
+ * At exit, the Directory application now sets a channel variable
+   DIRECTORY_RESULT to one of the following based on the reason for exiting:
+     OPERATOR    user requested operator by pressing '0' for operator
+     ASSISTANT   user requested assistant by pressing '*' for assistant
+     TIMEOUT     user pressed nothing and Directory stopped waiting
+     HANGUP      user's channel hung up
+     SELECTED    user selected a user from the directory and is routed
+     USEREXIT    user pressed '#' from the selection prompt to exit
+     FAILED      directory failed in a way that wasn't accounted for. Dang.
 
 Say
 --------------------------

Modified: trunk/apps/app_directory.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_directory.c?view=diff&rev=402995&r1=402994&r2=402995
==============================================================================
--- trunk/apps/app_directory.c (original)
+++ trunk/apps/app_directory.c Thu Nov 21 16:38:31 2013
@@ -111,6 +111,7 @@
 				options may be specified. <emphasis>If more than one is specified</emphasis>, then Directory will act as 
 				if <replaceable>b</replaceable> was specified.  The number
 				of characters for the user to type defaults to <literal>3</literal>.</para></note>
+
 			</parameter>
 		</syntax>
 		<description>
@@ -121,6 +122,19 @@
 			received and the extension to jump to exists:</para>
 			<para><literal>0</literal> - Jump to the 'o' extension, if it exists.</para>
 			<para><literal>*</literal> - Jump to the 'a' extension, if it exists.</para>
+			<para>This application will set the following channel variable before completion:</para>
+			<variablelist>
+				<variable name="DIRECTORY_RESULT">
+					<para>Reason Directory application exited.</para>
+					<value name="OPERATOR">User requested operator</value>
+					<value name="ASSISTANT">User requested assistant</value>
+					<value name="TIMEOUT">User allowed DTMF wait duration to pass without sending DTMF</value>
+					<value name="HANGUP">The channel hung up before the application finished</value>
+					<value name="SELECTED">User selected a user to call from the directory</value>
+					<value name="USEREXIT">User exited with '#' during selection</value>
+					<value name="FAILED">The application failed</value>
+				</variable>
+			</variablelist>
 		</description>
 	</application>
 
@@ -309,6 +323,7 @@
 		return -1;
 	}
 
+	pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "SELECTED");
 	return 0;
 }
 
@@ -349,6 +364,7 @@
 	
 			if (res == '0') { /* operator selected */
 				goto_exten(chan, dialcontext, "o");
+				pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "OPERATOR");
 				return '0';
 			} else if (res == '1') { /* Name selected */
 				return select_entry(chan, dialcontext, item, flags) ? -1 : 1;
@@ -357,6 +373,7 @@
 				break;
 			} else if (res == '#') {
 				/* Exit reading, continue in dialplan */
+				pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "USEREXIT");
 				return res;
 			}
 
@@ -422,6 +439,7 @@
 		}
 
 		if (res && res > '0' && res < '1' + limit) {
+			pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "SELECTED");
 			return select_entry(chan, dialcontext, block[res - '1'], flags) ? -1 : 1;
 		}
 
@@ -741,10 +759,12 @@
 	char ext[10] = "";
 
 	if (digit == '0' && !goto_exten(chan, dialcontext, "o")) {
+		pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "OPERATOR");
 		return digit;
 	}
 
 	if (digit == '*' && !goto_exten(chan, dialcontext, "a")) {
+		pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "ASSISTANT");
 		return digit;
 	}
 
@@ -909,8 +929,12 @@
 		if (!res)
 			res = ast_waitfordigit(chan, 5000);
 
-		if (res <= 0)
-			break;
+		if (res <= 0) {
+			if (res == 0) {
+				pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "TIMEOUT");
+			}
+			break;
+		}
 
 		res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, digit, &flags, opts);
 		if (res)
@@ -918,15 +942,22 @@
 
 		res = ast_waitstream(chan, AST_DIGIT_ANY);
 		ast_stopstream(chan);
-
-		if (res)
-			break;
+		if (res < 0) {
+			break;
+		}
 	}
 
 	if (ucfg)
 		ast_config_destroy(ucfg);
 	ast_config_destroy(cfg);
 
+	if (ast_check_hangup(chan)) {
+		pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "HANGUP");
+	} else if (res < 0) {
+		/* If the res < 0 and we didn't hangup, an unaccounted for error must have happened. */
+		pbx_builtin_setvar_helper(chan, "DIRECTORY_RESULT", "FAILED");
+	}
+
 	return res < 0 ? -1 : 0;
 }
 




More information about the asterisk-commits mailing list