fix execiftime and include some code cleanup while we're at it (bug #4380)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6343 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2005-08-19 07:12:53 +00:00
parent 47334c3193
commit 6e9eaaf217

64
pbx.c
View File

@@ -5319,6 +5319,7 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
int res = 0; int res = 0;
char *ptr1, *ptr2; char *ptr1, *ptr2;
struct ast_timing timing; 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>]"; 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)) { if (!data || ast_strlen_zero(data)) {
@@ -5326,38 +5327,41 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
return -1; return -1;
} }
if ((ptr1 = ast_strdupa((char *) data))) { ptr1 = ast_strdupa(data);
ptr2 = ptr1;
/* Separate the Application data ptr1 is the time spec ptr2 is the app|data*/ if (!ptr1) {
strsep(&ptr2,"?"); ast_log(LOG_ERROR, "Out of Memory!\n");
if(!(res = ast_build_timing(&timing, ptr1))) { return -1;
ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage); }
res = -1;
} ptr2 = ptr1;
/* Separate the Application data ptr1 is the time spec ptr2 is the app|data */
if (!res && ast_check_timing(&timing)) { strsep(&ptr2,"?");
if (ptr2) { if(!ast_build_timing(&timing, ptr1)) {
/* ptr2 is now the app name ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
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);
}
}
} else {
ast_log(LOG_ERROR, "Memory Error!\n");
res = -1; 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 ((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;
}
}
return res; return res;
} }