[asterisk-commits] dvossel: branch russell/ast_channel_ao2 r189425 - /team/russell/ast_channel_a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 20 14:52:27 CDT 2009


Author: dvossel
Date: Mon Apr 20 14:52:24 2009
New Revision: 189425

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=189425
Log:
Integrate DAHDIScan into chanspy

This patch moves DAHDIScan into app_chanspy to use chanspy's common_exec logic.  No need for app_dahdiscan.c, so it is deleted.


Removed:
    team/russell/ast_channel_ao2/apps/app_dahdiscan.c
Modified:
    team/russell/ast_channel_ao2/apps/app_chanspy.c

Modified: team/russell/ast_channel_ao2/apps/app_chanspy.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/ast_channel_ao2/apps/app_chanspy.c?view=diff&rev=189425&r1=189424&r2=189425
==============================================================================
--- team/russell/ast_channel_ao2/apps/app_chanspy.c (original)
+++ team/russell/ast_channel_ao2/apps/app_chanspy.c Mon Apr 20 14:52:24 2009
@@ -141,6 +141,16 @@
 						specified by the <variable>SPY_EXIT_CONTEXT</variable> channel variable. The
 						name of the last channel that was spied on will be stored
 						in the <variable>SPY_CHANNEL</variable> variable.</para>
+					</option>
+					<option name="x">
+						<argument name="digit" required="true">
+							<para>Specify a DTMF digit that can be used to exit the application.</para>
+						</argument>
+					</option>
+					<option name="c">
+						<argument name="digit" required="true">
+							<para>Specify a DTMF digit that can be used to spy on the next available channel.</para>
+						</argument>
 					</option>
 					<option name="e">
 						<argument name="ext" required="true" />
@@ -263,6 +273,16 @@
 						name of the last channel that was spied on will be stored
 						in the <variable>SPY_CHANNEL</variable> variable.</para>
 					</option>
+					<option name="x">
+						<argument name="digit" required="true">
+							<para>Specify a DTMF digit that can be used to exit the application.</para>
+						</argument>
+					</option>
+					<option name="c">
+						<argument name="digit" required="true">
+							<para>Specify a DTMF digit that can be used to spy on the next available channel.</para>
+						</argument>
+					</option>
 					<option name="e">
 						<argument name="ext" required="true" />
 						<para>Enable <emphasis>enforced</emphasis> mode, so the spying channel can
@@ -288,11 +308,28 @@
 			<ref type="application">ChanSpy</ref>
 		</see-also>
 	</application>
-
+	
+	<application name="DAHDIScan" language="en_US">
+		<synopsis>
+			Scan DAHDI channels to monitor calls.
+		</synopsis>
+		<syntax>
+			<parameter name="group">
+				<para>Limit scanning to a channel <replaceable>group</replaceable> by setting this option.</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Allows a call center manager to monitor DAHDI channels in a
+			convenient way.  Use <literal>#</literal> to select the next channel and use <literal>*</literal> to exit.</para>
+		</description>
+	</application>
  ***/
+
 static const char *app_chan = "ChanSpy";
 
 static const char *app_ext = "ExtenSpy";
+
+static const char *app_dahdiscan = "DAHDIScan";
 
 enum {
 	OPTION_QUIET             = (1 << 0),    /* Quiet, no announcement */
@@ -308,7 +345,10 @@
 	OPTION_NOTECH            = (1 << 10),   /* Skip technology name playback */
 	OPTION_BARGE             = (1 << 11),   /* Barge mode (whisper to both channels) */
 	OPTION_NAME              = (1 << 12),   /* Say the name of the person on whom we will spy */
-	OPTION_DTMF_SWITCH_MODES = (1 << 13),   /*Allow numeric DTMF to switch between chanspy modes */
+	OPTION_DTMF_SWITCH_MODES = (1 << 13),   /* Allow numeric DTMF to switch between chanspy modes */
+	OPTION_DTMF_EXIT         = (1 << 14),	/* Set DTMF to exit, added for DAHDIScan integration */
+	OPTION_DTMF_CYCLE        = (1 << 15),	/* Custom DTMF for cycling next avaliable channel, (default is '*') */
+	OPTION_DAHDI_SCAN        = (1 << 16),	/* Scan groups in DAHDIScan mode */
 } chanspy_opt_flags;
 
 enum {
@@ -317,6 +357,8 @@
 	OPT_ARG_RECORD,
 	OPT_ARG_ENFORCED,
 	OPT_ARG_NAME,
+	OPT_ARG_EXIT,
+	OPT_ARG_CYCLE,
 	OPT_ARG_ARRAY_SIZE,
 } chanspy_opt_args;
 
@@ -335,6 +377,8 @@
 	AST_APP_OPTION('s', OPTION_NOTECH),
 	AST_APP_OPTION_ARG('n', OPTION_NAME, OPT_ARG_NAME),
 	AST_APP_OPTION('d', OPTION_DTMF_SWITCH_MODES),
+	AST_APP_OPTION_ARG('x', OPTION_DTMF_EXIT, OPT_ARG_EXIT),
+	AST_APP_OPTION_ARG('c', OPTION_DTMF_CYCLE, OPT_ARG_CYCLE),
 });
 
 struct chanspy_translation_helper {
@@ -344,6 +388,12 @@
 	struct ast_audiohook bridge_whisper_audiohook;
 	int fd;
 	int volfactor;
+};
+
+struct spy_dtmf_options {
+	char exit;
+	char cycle;
+	char volume;
 };
 
 static void *spy_alloc(struct ast_channel *chan, void *data)
@@ -428,7 +478,8 @@
 }
 
 static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_autochan,
-	int *volfactor, int fd, struct ast_flags *flags, char *exitcontext)
+	int *volfactor, int fd, struct spy_dtmf_options *user_options, struct ast_flags *flags,
+	char *exitcontext)
 {
 	struct chanspy_translation_helper csth;
 	int running = 0, res, x = 0;
@@ -569,10 +620,13 @@
 			}
 		}
 
-		if (res == '*') {
+		if (res == user_options->cycle) {
 			running = 0;
 			break;
-		} else if (res == '#') {
+		} else if (res == user_options->exit) {
+			running = -2;
+			break;
+		} else if (res == user_options->volume) {
 			if (!ast_strlen_zero(inp)) {
 				running = atoi(inp);
 				break;
@@ -634,7 +688,6 @@
 	}
 
 redo:
-
 	if (!(next = ast_channel_iterator_next(iter))) {
 		return NULL;
 	}
@@ -649,9 +702,9 @@
 }
 
 static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
-	int volfactor, const int fd, const char *mygroup, const char *myenforced,
-	const char *spec, const char *exten, const char *context, const char *mailbox,
-	const char *name_context)
+	int volfactor, const int fd, struct spy_dtmf_options *user_options,
+	const char *mygroup, const char *myenforced, const char *spec, const char *exten,
+	const char *context, const char *mailbox, const char *name_context)
 {
 	char nameprefix[AST_NAME_STRLEN];
 	char peer_name[AST_NAME_STRLEN + 5];
@@ -773,14 +826,22 @@
 				char dup_mygroup[512];
 				char *groups[NUM_SPYGROUPS];
 				char *mygroups[NUM_SPYGROUPS];
-				const char *group;
+				const char *group = NULL;
 				int x;
 				int y;
 				ast_copy_string(dup_mygroup, mygroup, sizeof(dup_mygroup));
 				num_mygroups = ast_app_separate_args(dup_mygroup, ':', mygroups,
 					ARRAY_LEN(mygroups));
 
-				if ((group = pbx_builtin_getvar_helper(autochan->chan, "SPYGROUP"))) {
+				/* Before dahdi scan was part of chanspy, it would use the "GROUP" variable 
+				 * rather than "SPYGROUP", this check is done to preserve expected behavior */
+				if (ast_test_flag(flags, OPTION_DAHDI_SCAN)) {
+					group = pbx_builtin_getvar_helper(autochan->chan, "GROUP");
+				} else {
+					group = pbx_builtin_getvar_helper(autochan->chan, "SPYGROUP");
+				}
+
+				if (!ast_strlen_zero(group)) {
 					ast_copy_string(dup_group, group, sizeof(dup_group));
 					num_groups = ast_app_separate_args(dup_group, ':', groups,
 						ARRAY_LEN(groups));
@@ -799,7 +860,6 @@
 			if (!igrp) {
 				continue;
 			}
-
 			if (myenforced) {
 				char ext[AST_CHANNEL_NAME + 3];
 				char buffer[512];
@@ -859,8 +919,8 @@
 				}
 			}
 
-			res = channel_spy(chan, autochan, &volfactor, fd, flags, exitcontext);
-			num_spyed_upon++;	
+			res = channel_spy(chan, autochan, &volfactor, fd, user_options, flags, exitcontext);
+			num_spyed_upon++;
 
 			if (res == -1) {
 				ast_autochan_destroy(autochan);
@@ -910,6 +970,7 @@
 	char *recbase = NULL;
 	int fd = 0;
 	struct ast_flags flags;
+	struct spy_dtmf_options user_options;
 	int oldwf = 0;
 	int volfactor = 0;
 	int res;
@@ -921,6 +982,10 @@
 	);
 	char *opts[OPT_ARG_ARRAY_SIZE];
 
+	user_options.cycle = '*';
+	user_options.volume = '#';
+	user_options.exit = '\0';
+
 	data = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, data);
 
@@ -928,6 +993,7 @@
 		args.spec = NULL;
 
 	if (args.options) {
+		char tmp;
 		ast_app_parse_options(spy_opts, &flags, opts, args.options);
 		if (ast_test_flag(&flags, OPTION_GROUP))
 			mygroup = opts[OPT_ARG_GROUP];
@@ -935,6 +1001,24 @@
 		if (ast_test_flag(&flags, OPTION_RECORD) &&
 			!(recbase = opts[OPT_ARG_RECORD]))
 			recbase = "chanspy";
+
+		if (ast_test_flag(&flags, OPTION_DTMF_EXIT) && opts[OPT_ARG_EXIT]) {
+			tmp = opts[OPT_ARG_EXIT][0];
+			if (tmp >= '0' || tmp <= '9' || tmp == '#' || tmp == '*') {
+				user_options.exit = tmp;
+			} else {
+				ast_log(LOG_NOTICE, "Argument for option 'x' must be a valid DTMF digit.");
+			}
+		}
+
+		if (ast_test_flag(&flags, OPTION_DTMF_CYCLE) && opts[OPT_ARG_CYCLE]) {
+			tmp = opts[OPT_ARG_CYCLE][0];
+			if (tmp >= '0' || tmp <= '9' || tmp == '#' || tmp == '*') {
+				user_options.cycle = tmp;
+			} else {
+				ast_log(LOG_NOTICE, "Argument for option 'c' must be a valid DTMF digit.");
+			}
+		}
 
 		if (ast_test_flag(&flags, OPTION_VOLUME) && opts[OPT_ARG_VOLUME]) {
 			int vol;
@@ -950,7 +1034,7 @@
 
 		if (ast_test_flag(&flags, OPTION_ENFORCED))
 			myenforced = opts[OPT_ARG_ENFORCED];
-		
+
 		if (ast_test_flag(&flags, OPTION_NAME)) {
 			if (!ast_strlen_zero(opts[OPT_ARG_NAME])) {
 				char *delimiter;
@@ -963,10 +1047,9 @@
 				}
 			}
 		}
-
-
-	} else
+	} else {
 		ast_clear_flag(&flags, AST_FLAGS_ALL);
+	}
 
 	oldwf = chan->writeformat;
 	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
@@ -984,7 +1067,7 @@
 		}
 	}
 
-	res = common_exec(chan, &flags, volfactor, fd, mygroup, myenforced, args.spec, NULL, NULL, mailbox, name_context);
+	res = common_exec(chan, &flags, volfactor, fd, &user_options, mygroup, myenforced, args.spec, NULL, NULL, mailbox, name_context);
 
 	if (fd)
 		close(fd);
@@ -1002,6 +1085,7 @@
 	char *recbase = NULL;
 	int fd = 0;
 	struct ast_flags flags;
+	struct spy_dtmf_options user_options;
 	int oldwf = 0;
 	int volfactor = 0;
 	int res;
@@ -1012,6 +1096,10 @@
 		AST_APP_ARG(options);
 	);
 
+	user_options.cycle = '*';
+	user_options.volume = '#';
+	user_options.exit = '\0';
+
 	data = ast_strdupa(data);
 
 	AST_STANDARD_APP_ARGS(args, data);
@@ -1047,7 +1135,6 @@
 		if (ast_test_flag(&flags, OPTION_PRIVATE))
 			ast_set_flag(&flags, OPTION_WHISPER);
 
-		
 		if (ast_test_flag(&flags, OPTION_NAME)) {
 			if (!ast_strlen_zero(opts[OPT_ARG_NAME])) {
 				char *delimiter;
@@ -1061,8 +1148,9 @@
 			}
 		}
 
-	} else
+	} else {
 		ast_clear_flag(&flags, AST_FLAGS_ALL);
+	}
 
 	oldwf = chan->writeformat;
 	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
@@ -1081,10 +1169,46 @@
 	}
 
 
-	res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, NULL, exten, args.context, mailbox, name_context);
+	res = common_exec(chan, &flags, volfactor, fd, &user_options, mygroup, NULL, NULL, exten, args.context, mailbox, name_context);
 
 	if (fd)
 		close(fd);
+
+	if (oldwf && ast_set_write_format(chan, oldwf) < 0)
+		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+
+	return res;
+}
+
+static int dahdiscan_exec(struct ast_channel *chan, void *data)
+{
+	const char *spec = "DAHDI";
+	struct ast_flags flags;
+	struct spy_dtmf_options user_options;
+	int oldwf = 0;
+	int res;
+	char *mygroup = NULL;
+
+	user_options.cycle = '#';
+	user_options.volume = '\0';
+	user_options.exit = '*';
+
+	ast_clear_flag(&flags, AST_FLAGS_ALL);
+
+	if (!ast_strlen_zero(data)) {
+		mygroup = ast_strdupa(data);
+	}
+	ast_set_flag(&flags, OPTION_DTMF_EXIT);
+	ast_set_flag(&flags, OPTION_DTMF_CYCLE);
+	ast_set_flag(&flags, OPTION_DAHDI_SCAN);
+
+	oldwf = chan->writeformat;
+	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+		return -1;
+	}
+
+	res = common_exec(chan, &flags, 0, 0, &user_options, mygroup, NULL, spec, NULL, NULL, NULL, NULL);
 
 	if (oldwf && ast_set_write_format(chan, oldwf) < 0)
 		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
@@ -1098,6 +1222,7 @@
 
 	res |= ast_unregister_application(app_chan);
 	res |= ast_unregister_application(app_ext);
+	res |= ast_unregister_application(app_dahdiscan);
 
 	return res;
 }
@@ -1108,6 +1233,7 @@
 
 	res |= ast_register_application_xml(app_chan, chanspy_exec);
 	res |= ast_register_application_xml(app_ext, extenspy_exec);
+	res |= ast_register_application_xml(app_dahdiscan, dahdiscan_exec);
 
 	return res;
 }




More information about the asterisk-commits mailing list