aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-08-19 07:12:53 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-08-19 07:12:53 +0000
commit08b6c1f394b302f4731497398be811963f4415f9 (patch)
treef8ee6dc160b5049522ed3ca5c46e347283eff616 /pbx.c
parent2fb6594e2910f30d296d25854b7b41abd31048b7 (diff)
fix execiftime and include some code cleanup while we're at it (bug #4380)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6343 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rwxr-xr-xpbx.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/pbx.c b/pbx.c
index b0b339862..3a60fccfd 100755
--- a/pbx.c
+++ b/pbx.c
@@ -5319,6 +5319,7 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
int res = 0;
char *ptr1, *ptr2;
struct ast_timing timing;
+ struct ast_app *app;
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)) {
@@ -5326,38 +5327,41 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
return -1;
}
- if ((ptr1 = ast_strdupa((char *) data))) {
- ptr2 = ptr1;
- /* Separate the Application data ptr1 is the time spec ptr2 is the app|data*/
- strsep(&ptr2,"?");
- if(!(res = ast_build_timing(&timing, ptr1))) {
- ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
- res = -1;
+ ptr1 = ast_strdupa(data);
+
+ if (!ptr1) {
+ ast_log(LOG_ERROR, "Out of Memory!\n");
+ return -1;
+ }
+
+ ptr2 = ptr1;
+ /* Separate the Application data ptr1 is the time spec ptr2 is the app|data */
+ strsep(&ptr2,"?");
+ if(!ast_build_timing(&timing, ptr1)) {
+ ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
+ res = -1;
+ }
+
+ if (!res && ast_check_timing(&timing)) {
+ if (!ptr2) {
+ ast_log(LOG_WARNING, "%s\n", usage);
+ }
+
+ /* ptr2 is now the app name
+ we're done with ptr1 now so recycle it and use it to point to the app args */
+ if((ptr1 = strchr(ptr2, '|'))) {
+ *ptr1 = '\0';
+ ptr1++;
}
- if (!res && ast_check_timing(&timing)) {
- if (ptr2) {
- /* ptr2 is now the app name
- we're done with ptr1 now so recycle it and use it to point to the app args*/
- struct ast_app *app;
- if((ptr1 = strchr(ptr2, '|'))) {
- *ptr1 = '\0';
- ptr1++;
- }
- if ((app = pbx_findapp(ptr2))) {
- 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);
- }
+ if ((app = pbx_findapp(ptr2))) {
+ 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_ERROR, "Memory Error!\n");
- res = -1;
}
+
return res;
}