--- app_queue.c.orig 2006-05-03 08:39:20.000000000 -0500 +++ app_queue.c 2006-05-03 08:36:32.000000000 -0500 @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -1572,6 +1573,11 @@ { int res = 0; time_t now; + struct stat statinfo; + struct dirent **namelist; + int filenum,randnum,filefound = 0; + char randaname[256]; + char fullaname[512]; /* Get the current time */ time(&now); @@ -1586,8 +1592,33 @@ if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Playing periodic announcement\n"); - /* play the announcement */ - res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce); + /* Get file stats for directory based random periodic announcements */ + sprintf(fullaname, "%s/%s/", ast_config_AST_VAR_DIR, "sounds"); + strcat(fullaname, qe->parent->sound_periodicannounce); + if(stat(fullaname,&statinfo) != -1) + filefound = 1; + + if(filefound == 1 && (statinfo.st_mode & S_IFMT) == S_IFDIR) { + filenum = scandir(fullaname, &namelist, 0, alphasort); + if (filenum < 0) { + ast_log(LOG_ERROR, "scandir: Periodic Announce scandir on (%s) FAILED!\n", fullaname); + qe->last_periodic_announce_time = now; + return(res); + } else { + srand(time(NULL)); + randnum = (rand() % (filenum-2))+2; + strcpy(randaname, qe->parent->sound_periodicannounce); + if(randaname[strlen(randaname)-1] != '/') + strcat(randaname, "/"); + strncat(randaname, namelist[randnum]->d_name, (strlen(namelist[randnum]->d_name)-4)); + free(namelist); + res = background_file(qe, qe->chan, randaname); + } + } else { + + /* play the announcement */ + res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce); + } /* Resume Music on Hold */ ast_moh_start(qe->chan, qe->moh);