[asterisk-commits] tilghman: branch group/dialplan_aesthetics r71950 - /team/group/dialplan_aest...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 26 16:44:46 CDT 2007


Author: tilghman
Date: Tue Jun 26 16:44:46 2007
New Revision: 71950

URL: http://svn.digium.com/view/asterisk?view=rev&rev=71950
Log:
Still more conversions

Modified:
    team/group/dialplan_aesthetics/apps/app_chanspy.c
    team/group/dialplan_aesthetics/apps/app_controlplayback.c
    team/group/dialplan_aesthetics/apps/app_dial.c
    team/group/dialplan_aesthetics/apps/app_exec.c
    team/group/dialplan_aesthetics/apps/app_externalivr.c

Modified: team/group/dialplan_aesthetics/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/group/dialplan_aesthetics/apps/app_chanspy.c?view=diff&rev=71950&r1=71949&r2=71950
==============================================================================
--- team/group/dialplan_aesthetics/apps/app_chanspy.c (original)
+++ team/group/dialplan_aesthetics/apps/app_chanspy.c Tue Jun 26 16:44:46 2007
@@ -626,35 +626,29 @@
 static int chanspy_exec(struct ast_channel *chan, void *data)
 {
 	struct ast_module_user *u;
-	char *options = NULL;
-	char *spec = NULL;
-	char *argv[2];
 	char *mygroup = NULL;
 	char *recbase = NULL;
 	int fd = 0;
 	struct ast_flags flags;
 	int oldwf = 0;
-	int argc = 0;
 	int volfactor = 0;
 	int res;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(spec);
+		AST_APP_ARG(options);
+	);
+	char *opts[OPT_ARG_ARRAY_SIZE];
+
+	u = ast_module_user_add(chan);
 
 	data = ast_strdupa(data);
-
-	u = ast_module_user_add(chan);
-
-	if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
-		spec = argv[0];
-		if (argc > 1)
-			options = argv[1];
-
-		if (ast_strlen_zero(spec) || !strcmp(spec, "all"))
-			spec = NULL;
-	}
-
-	if (options) {
-		char *opts[OPT_ARG_ARRAY_SIZE];
-		
-		ast_app_parse_options(spy_opts, &flags, opts, options);
+	AST_STANDARD_APP_ARGS(args, data);
+
+	if (args.spec && !strcmp(args.spec, "all"))
+		args.spec = NULL;
+
+	if (args.options) {
+		ast_app_parse_options(spy_opts, &flags, opts, args.options);
 		if (ast_test_flag(&flags, OPTION_GROUP))
 			mygroup = opts[OPT_ARG_GROUP];
 
@@ -692,7 +686,7 @@
 		}
 	}
 
-	res = common_exec(chan, &flags, volfactor, fd, mygroup, spec, NULL, NULL);
+	res = common_exec(chan, &flags, volfactor, fd, mygroup, args.spec, NULL, NULL);
 
 	if (fd)
 		close(fd);
@@ -708,37 +702,37 @@
 static int extenspy_exec(struct ast_channel *chan, void *data)
 {
 	struct ast_module_user *u;
-	char *options = NULL;
-	char *exten = NULL;
-	char *context = NULL;
-	char *argv[2];
+	char *ptr, *exten = NULL;
 	char *mygroup = NULL;
 	char *recbase = NULL;
 	int fd = 0;
 	struct ast_flags flags;
 	int oldwf = 0;
-	int argc = 0;
 	int volfactor = 0;
 	int res;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(context);
+		AST_APP_ARG(options);
+	);
 
 	data = ast_strdupa(data);
 
 	u = ast_module_user_add(chan);
 
-	if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
-		context = argv[0];
-		if (!ast_strlen_zero(argv[0]))
-			exten = strsep(&context, "@");
-		if (ast_strlen_zero(context))
-			context = ast_strdupa(chan->context);
-		if (argc > 1)
-			options = argv[1];
-	}
-
-	if (options) {
+	AST_STANDARD_APP_ARGS(args, data);
+	if (!ast_strlen_zero(args.context) && (ptr = strchr(args.context, '@'))) {
+		exten = args.context;
+		*ptr++ = '\0';
+		args.context = ptr;
+	}
+
+	if (ast_strlen_zero(args.context))
+		args.context = ast_strdupa(chan->context);
+
+	if (args.options) {
 		char *opts[OPT_ARG_ARRAY_SIZE];
 		
-		ast_app_parse_options(spy_opts, &flags, opts, options);
+		ast_app_parse_options(spy_opts, &flags, opts, args.options);
 		if (ast_test_flag(&flags, OPTION_GROUP))
 			mygroup = opts[OPT_ARG_GROUP];
 
@@ -776,7 +770,7 @@
 		}
 	}
 
-	res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, exten, context);
+	res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, exten, args.context);
 
 	if (fd)
 		close(fd);

Modified: team/group/dialplan_aesthetics/apps/app_controlplayback.c
URL: http://svn.digium.com/view/asterisk/team/group/dialplan_aesthetics/apps/app_controlplayback.c?view=diff&rev=71950&r1=71949&r2=71950
==============================================================================
--- team/group/dialplan_aesthetics/apps/app_controlplayback.c (original)
+++ team/group/dialplan_aesthetics/apps/app_controlplayback.c Tue Jun 26 16:44:46 2007
@@ -95,20 +95,18 @@
 	char offsetbuf[20];
 	struct ast_module_user *u;
 	char *tmp;
-	int argc;
-	char *argv[8] = { NULL, };
-	enum arg_ids {
-		arg_file = 0,
-		arg_skip = 1,
-		arg_fwd = 2,
-		arg_rev = 3,
-		arg_stop = 4,
-		arg_pause = 5,
-		arg_restart = 6,
-		options = 7,
-	};
 	struct ast_flags opts = { 0, };
 	char *opt_args[OPT_ARG_ARRAY_LEN];
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(filename);
+		AST_APP_ARG(skip);
+		AST_APP_ARG(fwd);
+		AST_APP_ARG(rev);
+		AST_APP_ARG(stop);
+		AST_APP_ARG(pause);
+		AST_APP_ARG(restart);
+		AST_APP_ARG(options);
+	);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
@@ -118,40 +116,37 @@
 	u = ast_module_user_add(chan);
 	
 	tmp = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, tmp);
 
-	argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
-
-	if (argc < 1) {
+	if (args.argc < 1) {
 		ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
 		ast_module_user_remove(u);
 		return -1;
 	}
 
-	skipms = argv[arg_skip] ? atoi(argv[arg_skip]) : 3000;
-	if (!skipms)
-		skipms = 3000;
+	skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;
 
-	if (!argv[arg_fwd] || !is_on_phonepad(*argv[arg_fwd]))
-		argv[arg_fwd] = "#";
-	if (!argv[arg_rev] || !is_on_phonepad(*argv[arg_rev]))
-		argv[arg_rev] = "*";
-	if (argv[arg_stop] && !is_on_phonepad(*argv[arg_stop]))
-		argv[arg_stop] = NULL;
-	if (argv[arg_pause] && !is_on_phonepad(*argv[arg_pause]))
-		argv[arg_pause] = NULL;
-	if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart]))
-		argv[arg_restart] = NULL;
+	if (!args.fwd || !is_on_phonepad(*args.fwd))
+		args.fwd = "#";
+	if (!args.rev || !is_on_phonepad(*args.rev))
+		args.rev = "*";
+	if (args.stop && !is_on_phonepad(*args.stop))
+		args.stop = NULL;
+	if (args.pause && !is_on_phonepad(*args.pause))
+		args.pause = NULL;
+	if (args.restart && !is_on_phonepad(*args.restart))
+		args.restart = NULL;
 
-	if (argv[options]) {
-		ast_app_parse_options(cpb_opts, &opts, opt_args, argv[options]);		
+	if (args.options) {
+		ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);		
 		if (ast_test_flag(&opts, OPT_OFFSET))
 			offsetms = atol(opt_args[OPT_ARG_OFFSET]);
 	}
 
-	res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms, &offsetms);
+	res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);
 
 	/* If we stopped on one of our stop keys, return 0  */
-	if (argv[arg_stop] && strchr(argv[arg_stop], res)) {
+	if (args.stop && strchr(args.stop, res)) {
 		res = 0;
 		pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
 	} else {

Modified: team/group/dialplan_aesthetics/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/group/dialplan_aesthetics/apps/app_dial.c?view=diff&rev=71950&r1=71949&r2=71950
==============================================================================
--- team/group/dialplan_aesthetics/apps/app_dial.c (original)
+++ team/group/dialplan_aesthetics/apps/app_dial.c Tue Jun 26 16:44:46 2007
@@ -66,7 +66,7 @@
 static char *synopsis = "Place a call and connect to the current channel";
 
 static char *descrip =
-"  Dial(Technology/resource[&Tech2/resource2...][|timeout][|options][|URL]):\n"
+"  Dial(Technology/resource[&Tech2/resource2...][,timeout][,options][,URL]):\n"
 "This application will place calls to one or more specified channels. As soon\n"
 "as one of the requested channels answers, the originating channel will be\n"
 "answered, if it has not already been answered. These two channels will then\n"
@@ -212,7 +212,7 @@
 static char *rapp = "RetryDial";
 static char *rsynopsis = "Place a call, retrying on failure allowing optional exit extension.";
 static char *rdescrip =
-"  RetryDial(announce|sleep|retries|dialargs): This application will attempt to\n"
+"  RetryDial(announce,sleep,retries,dialargs): This application will attempt to\n"
 "place a call using the normal Dial application. If no channel can be reached,\n"
 "the 'announce' file will be played. Then, it will wait 'sleep' number of\n"
 "seconds before retying the call. After 'retires' number of attempts, the\n"
@@ -830,7 +830,7 @@
 {
 	for (; *s; s++)
 		if (*s == '^')
-			*s = '|';
+			*s = ',';
 }
 
 
@@ -1827,11 +1827,17 @@
 
 static int retrydial_exec(struct ast_channel *chan, void *data)
 {
-	char *announce = NULL, *dialdata = NULL;
+	char *parse;
 	const char *context = NULL;
 	int sleep = 0, loops = 0, res = -1;
 	struct ast_module_user *u;
-	struct ast_flags peerflags;
+	struct ast_flags peerflags = { 0, };
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(announce);
+		AST_APP_ARG(sleep);
+		AST_APP_ARG(retries);
+		AST_APP_ARG(dialdata);
+	);
 	
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
@@ -1840,31 +1846,17 @@
 
 	u = ast_module_user_add(chan);
 
-	announce = ast_strdupa(data);
-
-	memset(&peerflags, 0, sizeof(peerflags));
-
-	if ((dialdata = strchr(announce, '|'))) {
-		*dialdata++ = '\0';
-		if ((sleep = atoi(dialdata))) {
-			sleep *= 1000;
-		} else {
-			ast_log(LOG_ERROR, "%s requires the numerical argument <sleep>\n",rapp);
-			goto done;
-		}
-		if ((dialdata = strchr(dialdata, '|'))) {
-			*dialdata++ = '\0';
-			if (!(loops = atoi(dialdata))) {
-				ast_log(LOG_ERROR, "%s requires the numerical argument <loops>\n",rapp);
-				goto done;
-			}
-		}
-	}
-	
-	if ((dialdata = strchr(dialdata, '|'))) {
-		*dialdata++ = '\0';
-	} else {
-		ast_log(LOG_ERROR, "%s requires more arguments\n",rapp);
+	parse = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if ((sleep = atoi(args.sleep))) {
+		sleep *= 1000;
+	}
+
+	loops = atoi(args.retries);
+
+	if (!args.dialdata) {
+		ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
 		goto done;
 	}
 		
@@ -1884,12 +1876,12 @@
 		if (ast_test_flag(chan, AST_FLAG_MOH))
 			ast_moh_stop(chan);
 
-		res = dial_exec_full(chan, dialdata, &peerflags, &continue_exec);
+		res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
 		if (continue_exec)
 			break;
 		if (res == 0) {
 			if (ast_test_flag(&peerflags, OPT_DTMF_EXIT)) {
-				if (!(res = ast_streamfile(chan, announce, chan->language)))
+				if (!(res = ast_streamfile(chan, args.announce, chan->language)))
 					res = ast_waitstream(chan, AST_DIGIT_ANY);
 				if (!res && sleep) {
 					if (!ast_test_flag(chan, AST_FLAG_MOH))
@@ -1897,7 +1889,7 @@
 					res = ast_waitfordigit(chan, sleep);
 				}
 			} else {
-				if (!(res = ast_streamfile(chan, announce, chan->language)))
+				if (!(res = ast_streamfile(chan, args.announce, chan->language)))
 					res = ast_waitstream(chan, "");
 				if (sleep) {
 					if (!ast_test_flag(chan, AST_FLAG_MOH))

Modified: team/group/dialplan_aesthetics/apps/app_exec.c
URL: http://svn.digium.com/view/asterisk/team/group/dialplan_aesthetics/apps/app_exec.c?view=diff&rev=71950&r1=71949&r2=71950
==============================================================================
--- team/group/dialplan_aesthetics/apps/app_exec.c (original)
+++ team/group/dialplan_aesthetics/apps/app_exec.c Tue Jun 26 16:44:46 2007
@@ -41,6 +41,7 @@
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
+#include "asterisk/app.h"
 
 /* Maximum length of any variable */
 #define MAXRESULT	1024
@@ -83,7 +84,7 @@
 static char *app_execif = "ExecIf";
 static char *execif_synopsis = "Executes dialplan application, conditionally";
 static char *execif_descrip = 
-"Usage:  ExecIF (<expr>|<app>|<data>)\n"
+"Usage:  ExecIF (<expr>?<app>(<data>):<app2>(<data2>))\n"
 "If <expr> is true, execute and return the result of <app>(<data>).\n"
 "If <expr> is true, but <app> is not found, then the application\n"
 "will return a non-zero value.\n";
@@ -163,37 +164,51 @@
 {
 	int res = 0;
 	struct ast_module_user *u;
-	char *myapp = NULL;
-	char *mydata = NULL;
-	char *expr = NULL;
+	char *truedata = NULL, *falsedata = NULL, *end;
 	struct ast_app *app = NULL;
+	AST_DECLARE_APP_ARGS(expr,
+		AST_APP_ARG(expr);
+		AST_APP_ARG(remainder);
+	);
+	AST_DECLARE_APP_ARGS(apps,
+		AST_APP_ARG(true);
+		AST_APP_ARG(false);
+	);
+	char *parse = ast_strdupa(data);
 
 	u = ast_module_user_add(chan);
 
-	expr = ast_strdupa(data);
-
-	if ((myapp = strchr(expr,'|'))) {
-		*myapp = '\0';
-		myapp++;
-		if ((mydata = strchr(myapp,'|'))) {
-			*mydata = '\0';
-			mydata++;
-		} else
-			mydata = "";
-
-		if (pbx_checkcondition(expr)) { 
-			if ((app = pbx_findapp(myapp))) {
-				res = pbx_exec(chan, app, mydata);
-			} else {
-				ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp);
-				res = -1;
-			}
+	AST_NONSTANDARD_APP_ARGS(expr, parse, '?');
+	AST_NONSTANDARD_APP_ARGS(apps, expr.remainder, ':');
+
+	if (apps.true && (truedata = strchr(apps.true, '('))) {
+		*truedata++ = '\0';
+		if ((end = strrchr(truedata, ')')))
+			*end = '\0';
+	}
+
+	if (apps.false && (falsedata = strchr(apps.false, '('))) {
+		*falsedata++ = '\0';
+		if ((end = strrchr(falsedata, ')')))
+			*end = '\0';
+	}
+
+	if (pbx_checkcondition(expr.expr)) { 
+		if (!ast_strlen_zero(apps.true) && (app = pbx_findapp(apps.true))) {
+			res = pbx_exec(chan, app, S_OR(truedata, ""));
+		} else {
+			ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.true);
+			res = -1;
 		}
 	} else {
-		ast_log(LOG_ERROR,"Invalid Syntax.\n");
-		res = -1;
-	}
-		
+		if (!ast_strlen_zero(apps.false) && (app = pbx_findapp(apps.false))) {
+			res = pbx_exec(chan, app, S_OR(falsedata, ""));
+		} else {
+			ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.false);
+			res = -1;
+		}
+	}
+
 	ast_module_user_remove(u);
 
 	return res;

Modified: team/group/dialplan_aesthetics/apps/app_externalivr.c
URL: http://svn.digium.com/view/asterisk/team/group/dialplan_aesthetics/apps/app_externalivr.c?view=diff&rev=71950&r1=71949&r2=71950
==============================================================================
--- team/group/dialplan_aesthetics/apps/app_externalivr.c (original)
+++ team/group/dialplan_aesthetics/apps/app_externalivr.c Tue Jun 26 16:44:46 2007
@@ -58,7 +58,7 @@
 static const char *synopsis = "Interfaces with an external IVR application";
 
 static const char *descrip = 
-"  ExternalIVR(command[|arg[|arg...]]): Forks an process to run the supplied command,\n"
+"  ExternalIVR(command[,arg[,arg...]]): Forks an process to run the supplied command,\n"
 "and starts a generator on the channel. The generator's play list is\n"
 "controlled by the external application, which can add and clear entries\n"
 "via simple commands issued over its stdout. The external application\n"
@@ -245,7 +245,6 @@
 {
 	struct ast_module_user *lu;
 	struct playlist_entry *entry;
-	const char *args = data;
 	int child_stdin[2] = { 0,0 };
 	int child_stdout[2] = { 0,0 };
 	int child_stderr[2] = { 0,0 };
@@ -253,7 +252,6 @@
 	int gen_active = 0;
 	int pid;
 	char *argv[32];
-	int argc = 1;
 	char *buf, *command;
 	FILE *child_commands = NULL;
 	FILE *child_errors = NULL;
@@ -264,6 +262,9 @@
 	};
 	struct ivr_localuser *u = &foo;
 	sigset_t fullset, oldset;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(cmd)[32];
+	);
 
 	lu = ast_module_user_add(chan);
 
@@ -273,15 +274,14 @@
 	u->abort_current_sound = 0;
 	u->chan = chan;
 	
-	if (ast_strlen_zero(args)) {
+	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n");
 		ast_module_user_remove(lu);
 		return -1;	
 	}
 
 	buf = ast_strdupa(data);
-
-	argc = ast_app_separate_args(buf, '|', argv, sizeof(argv) / sizeof(argv[0]));
+	AST_STANDARD_APP_ARGS(args, buf);
 
 	if (pipe(child_stdin)) {
 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));




More information about the asterisk-commits mailing list