]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Make sure ExecIf stuff returns properly (bug #3864)
authorMark Spencer <markster@digium.com>
Tue, 29 Mar 2005 06:18:58 +0000 (06:18 +0000)
committerMark Spencer <markster@digium.com>
Tue, 29 Mar 2005 06:18:58 +0000 (06:18 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5297 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_exec.c
apps/app_while.c
pbx.c

index 8a46c07973ca9aea09838d70a056dad73efbc3e3..f4e156927a44407eae67ad045621ca8c9d0afa9f 100755 (executable)
@@ -37,7 +37,7 @@ static char *exec_descrip =
 "Exec(appname(arguments))\n"
 "  Allows an arbitrary application to be invoked even when not\n"
 "hardcoded into the dialplan.  Returns whatever value the\n"
-"app returns or -2 when the app cannot be found.\n";
+"app returns or a non-zero value when the app cannot be found.\n";
 
 STANDARD_LOCAL_USER;
 
@@ -71,7 +71,7 @@ static int exec_exec(struct ast_channel *chan, void *data)
                                        res = pbx_exec(chan, app, args, 1);
                                } else {
                                        ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
-                                       res = -2;
+                                       res = -1;
                                }
                        }
                } else {
index e33bae52f9281a7700c0e60af8bc5b30d9804ac7..5822c2ff53d21a3671a6963d57e80987bd31da52 100755 (executable)
@@ -29,7 +29,9 @@
 
 static char *exec_app = "ExecIf";
 static char *exec_desc = "  ExecIF (<expr>|<app>|<data>)\n"
-"If <expr> is true, execute and return the result of <app>(<data>)\n\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.";
 static char *exec_synopsis = "ExecIF (<expr>|<app>|<data>)";
 
 static char *start_app = "While";
@@ -73,8 +75,13 @@ static int execif_exec(struct ast_channel *chan, void *data) {
                } else
                        mydata = "";
 
-               if(ast_true(expr) && (app = pbx_findapp(myapp))) {
-                       res = pbx_exec(chan, app, mydata, 1);
+               if (ast_true(expr)) { 
+                       if ((app = pbx_findapp(myapp))) {
+                               res = pbx_exec(chan, app, mydata, 1);
+                       } else {
+                               ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp);
+                               res = -1;
+                       }
                }
        } else {
                ast_log(LOG_ERROR,"Invalid Syntax.\n");
diff --git a/pbx.c b/pbx.c
index d2f1699d62399db3f14de1a32600fe5e9bfba9cd..dd9e98feb8e8ef9c7e7fce69437efa3fa35ef300 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -300,7 +300,8 @@ static struct pbx_builtin {
        "  ExecIfTime(<times>|<weekdays>|<mdays>|<months>?<appname>[|<appdata>]):\n"
        "If the current time matches the specified time, then execute the specified\n"
        "application. Each of the elements may be specified either as '*' (for always)\n"
-       "or as a range. See the 'include' syntax for details." 
+       "or as a range. See the 'include' syntax for details. It will return whatever\n"
+       "<appname> returns, or a non-zero value if the application is not found.\n"
        },
        
        { "Hangup", pbx_builtin_hangup,
@@ -5372,10 +5373,10 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
        int res = 0;
        char *ptr1, *ptr2;
        struct ast_timing timing;
-       const char *usage = "ExecIfTime requires an argument:\n  <time range>|<days of week>|<days of month>|<months>?<appname>[|<ptr1>]";
+       const char *usage = "ExecIfTime requires an argument:\n  <time range>|<days of week>|<days of month>|<months>?<appname>[|<appargs>]";
 
        if (!data || ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "%s\n", usage);
+               ast_log(LOG_WARNING, "%s\n", usage);    
                return -1;
        }
 
@@ -5393,18 +5394,21 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
                                        ptr1++;
                                }
                                if ((app = pbx_findapp(ptr2))) {
-                                       pbx_exec(chan, app, ptr1 ? ptr1 : "", 1);
+                                       res = pbx_exec(chan, app, ptr1 ? ptr1 : "", 1);
                                } else {
                                        ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2);
+                                       res = -1;
                                }
                        } else {
                                ast_log(LOG_WARNING, "%s\n", usage);
                        }
                } else {
-                       ast_log(LOG_WARNING, "Invalid Time Spec: %s\n%s\n", ptr1, usage);
+                       ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
+                       res = -1;
                }
        } else {
                ast_log(LOG_ERROR, "Memory Error!\n");
+               res = -1;
        }
        return res;
 }