Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 86329) +++ apps/app_queue.c (working copy) @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -461,10 +462,13 @@ int x; for (x = 0; x < sizeof(strategies) / sizeof(strategies[0]); x++) { - if (!strcasecmp(strategy, strategies[x].name)) + if (!strcasecmp(strategy, strategies[x].name)) { return strategies[x].strategy; + } } + ast_log(LOG_DEBUG, "Returning -1\n"); + return -1; } @@ -2041,6 +2045,8 @@ { int res = 0; time_t now; + struct stat statinfo; + int filefound = 0; /* Get the current time */ time(&now); @@ -2061,10 +2067,39 @@ if (qe->last_periodic_announce_sound >= MAX_PERIODIC_ANNOUNCEMENTS || ast_strlen_zero(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound])) { qe->last_periodic_announce_sound = 0; } - - /* play the announcement */ - res = play_file(qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]); + /* Get file stats for directory based random periodic announcements */ + if(stat(qe->parent->sound_periodicannounce[0],&statinfo) != -1) + filefound = 1; + else + ast_log(LOG_ERROR, "Couldn't stat '%s': %s\n", qe->parent->sound_periodicannounce[0], strerror(errno)); + if(filefound == 1 && (statinfo.st_mode & S_IFMT) == S_IFDIR) { + int filenum; + struct dirent **namelist; + filenum = scandir(qe->parent->sound_periodicannounce[0], &namelist, 0, alphasort); + if (filenum < 0) { + ast_log(LOG_ERROR, "scandir: Periodic Announce scandir on (%s) FAILED: %s\n", qe->parent->sound_periodicannounce[0], strerror(errno)); + } else { + char *filename, *dot; + size_t left = PATH_MAX; + int randnum; + struct ast_str *randname = ast_str_create(left); + randnum = (ast_random() % (filenum-2))+2; + ast_str_append(&randname, left, "%s", qe->parent->sound_periodicannounce[0]); + if(randname->str[strlen(randname->str)-1] != '/') + ast_str_append(&randname, left, "%c", '/'); + filename = ast_strdupa(namelist[randnum]->d_name); + if((dot = strrchr(filename, '.'))) + *dot = '\0'; + ast_str_append(&randname, left, "%s", filename); + res = play_file(qe->chan, randname->str); + free(namelist); + free(randname); + } + } else { + /* play the announcement */ + res = play_file(qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]); + } if ((res > 0 && !valid_exit(qe, res)) || res < 0) res = 0; @@ -2081,7 +2116,7 @@ /* Update the current periodic announcement to the next announcement */ qe->last_periodic_announce_sound++; - + return res; }