summaryrefslogtreecommitdiff
path: root/apps/app_exec.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2007-07-23 19:51:41 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2007-07-23 19:51:41 +0000
commit55b1ee298e926c594f45456e5afbc25c79e3889b (patch)
treec9c73917bfd120da30c16650000c7296781fae50 /apps/app_exec.c
parentd8d1b6c8f242dbc1be319ceef5442378a5bda885 (diff)
Merge the dialplan_aesthetics branch. Most of this patch simply converts applications
using old methods of parsing arguments to using the standard macros. However, the big change is that the really old way of specifying application and arguments separated by a comma will no longer work (e.g. NoOp,foo|bar). Instead, the way that has been recommended since long before 1.0 will become the only method available (e.g. NoOp(foo,bar). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@76703 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_exec.c')
-rw-r--r--apps/app_exec.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/apps/app_exec.c b/apps/app_exec.c
index b953e8129..2423580fe 100644
--- a/apps/app_exec.c
+++ b/apps/app_exec.c
@@ -41,6 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 *tryexec_descrip =
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";
@@ -152,33 +153,47 @@ static int tryexec_exec(struct ast_channel *chan, void *data)
static int execif_exec(struct ast_channel *chan, void *data)
{
int res = 0;
- 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);
+
+ 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';
+ }
- 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;
- }
+ 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;
+ }
}
return res;