--- app_playback.orig 2004-02-22 12:25:27.000000000 -0800 +++ app_playback.c 2004-02-22 12:23:16.000000000 -0800 @@ -39,6 +39,15 @@ "is played. Not all channels support playing messages while on hook. Returns -1\n" "if the channel was hung up, or if the file does not exist. Returns 0 otherwise.\n"; +static char *app2 = "PlayFirst"; + +static char *synopsis2 = "Play the first file that exists from a list"; + +static char *descrip2 = +" PlayFirst(filename[|filename[|filename[|...]]]): Plays back the first file\n" +" it finds from a list (do not put extension). Calls Playback on the first file\n" +" it finds and passes the return value through.\n"; + STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -89,14 +98,51 @@ return res; } +static int playfirst_exec(struct ast_channel *chan, void *data) +{ + char tmp[512]; + char *curr; + char *stringp; + int res = -1; + struct localuser *u; + int found = 0; + + if (!data || !strlen((char *)data)) { + ast_log(LOG_WARNING, "PlayFirst requires an argument (filename)\n"); + return -1; + } + + strncpy(tmp, (char *)data, sizeof(tmp)-1); + stringp = tmp; + + LOCAL_USER_ADD(u); // Not sure if this is necessary... + + while ((curr = strsep(&stringp, "|")) && !found) { + if (0 < ast_fileexists(curr,NULL,NULL)) { + ast_log(LOG_WARNING, "PlayFirst found %s on %s\n", curr, chan->name); + res = playback_exec(chan, curr); + found = 1; + } + else { + ast_log(LOG_WARNING, "PlayFirst could not find %s on %s\n", curr, chan->name); + } + } + + LOCAL_USER_REMOVE(u); + + return res; +} + int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; + ast_unregister_application(app2); return ast_unregister_application(app); } int load_module(void) { + ast_register_application(app2, playfirst_exec, synopsis2, descrip2); return ast_register_application(app, playback_exec, synopsis, descrip); }