dect
/
asterisk
Archived
13
0
Fork 0

simplify pbx_builtin_execiftime

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@21906 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
rizzo 2006-04-21 13:44:15 +00:00
parent 00c7615742
commit 8ebf64bddd
1 changed files with 24 additions and 30 deletions

54
pbx.c
View File

@ -5119,49 +5119,43 @@ static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
*/ */
static int pbx_builtin_execiftime(struct ast_channel *chan, void *data) static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
{ {
int res = 0; char *s, *appname;
char *ptr1, *ptr2;
struct ast_timing timing; struct ast_timing timing;
struct ast_app *app; struct ast_app *app;
const char *usage = "ExecIfTime requires an argument:\n <time range>|<days of week>|<days of month>|<months>?<appname>[|<appargs>]"; static const char *usage = "ExecIfTime requires an argument:\n <time range>|<days of week>|<days of month>|<months>?<appname>[|<appargs>]";
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "%s\n", usage); ast_log(LOG_WARNING, "%s\n", usage);
return -1; return -1;
} }
if (!(ptr1 = ast_strdupa(data))) if (!(appname = ast_strdupa(data)))
return -1; return -1;
ptr2 = ptr1; s = strsep(&appname,"?"); /* Separate the timerange and application name/data */
/* Separate the Application data ptr1 is the time spec ptr2 is the app|data */ if (!appname) { /* missing application */
strsep(&ptr2,"?"); ast_log(LOG_WARNING, "%s\n", usage);
if(!ast_build_timing(&timing, ptr1)) { return -1;
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 if (!ast_build_timing(&timing, s)) {
we're done with ptr1 now so recycle it and use it to point to the app args */ ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", s, usage);
if((ptr1 = strchr(ptr2, '|'))) { return -1;
*ptr1 = '\0'; }
ptr1++;
} if (!ast_check_timing(&timing)) /* outside the valid time window, just return */
return 0;
if ((app = pbx_findapp(ptr2))) {
res = pbx_exec(chan, app, ptr1 ? ptr1 : ""); /* now split appname|appargs */
} else { if ((s = strchr(appname, '|')))
ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2); *s++ = '\0';
res = -1;
} if ((app = pbx_findapp(appname))) {
return pbx_exec(chan, app, S_OR(s, ""));
} else {
ast_log(LOG_WARNING, "Cannot locate application %s\n", appname);
return -1;
} }
return res;
} }
/*! /*!