Index: apps/app_externalivr.c =================================================================== --- apps/app_externalivr.c (revision 227646) +++ apps/app_externalivr.c (working copy) @@ -191,8 +191,9 @@ u->playing_silence = 0; gen_closestream(state); + while (!state->stream) { - state->current = AST_LIST_REMOVE_HEAD(&u->playlist, list); + state->current = AST_LIST_FIRST(&u->playlist); if (state->current) { file_to_stream = state->current->filename; } else { @@ -202,6 +203,9 @@ if (!(state->stream = ast_openstream_full(u->chan, file_to_stream, u->chan->language, 1))) { ast_chan_log(LOG_WARNING, u->chan, "File '%s' could not be opened: %s\n", file_to_stream, strerror(errno)); + AST_LIST_LOCK(&u->playlist); + AST_LIST_REMOVE_HEAD(&u->playlist, list); + AST_LIST_UNLOCK(&u->playlist); if (!u->playing_silence) { continue; } else { @@ -228,6 +232,12 @@ if (!(state->stream && (f = ast_readframe(state->stream)))) { if (state->current) { + + /* remove finished file from playlist */ + AST_LIST_LOCK(&u->playlist); + AST_LIST_REMOVE_HEAD(&u->playlist, list); + AST_LIST_UNLOCK(&u->playlist); + AST_LIST_LOCK(&u->finishlist); AST_LIST_INSERT_TAIL(&u->finishlist, state->current, list); AST_LIST_UNLOCK(&u->finishlist); @@ -670,7 +680,7 @@ if (strlen(input) < 4) continue; - + if (input[0] == 'P') { struct ast_str *tmp = (struct ast_str *) args; send_eivr_event(eivr_events, 'P', ast_str_buffer(tmp), chan); @@ -698,31 +708,31 @@ send_eivr_event(eivr_events, 'Z', NULL, chan); continue; } - if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) { + if (ast_fileexists(&input[2], NULL, u->chan->language) == 0) { ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]); send_eivr_event(eivr_events, 'Z', NULL, chan); strcpy(&input[2], "exception"); } if (!u->abort_current_sound && !u->playing_silence) send_eivr_event(eivr_events, 'T', NULL, chan); - AST_LIST_LOCK(&u->playlist); - while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) { - send_eivr_event(eivr_events, 'D', entry->filename, chan); - ast_free(entry); - } + AST_LIST_LOCK(&u->playlist); + while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) { + send_eivr_event(eivr_events, 'D', entry->filename, chan); + ast_free(entry); + } if (!u->playing_silence) u->abort_current_sound = 1; entry = make_entry(&input[2]); if (entry) AST_LIST_INSERT_TAIL(&u->playlist, entry, list); - AST_LIST_UNLOCK(&u->playlist); + AST_LIST_UNLOCK(&u->playlist); } else if (input[0] == 'A') { if (chan->_state != AST_STATE_UP || ast_check_hangup(chan)) { ast_chan_log(LOG_WARNING, chan, "Queue 'A'ppend called on unanswered channel\n"); send_eivr_event(eivr_events, 'Z', NULL, chan); continue; } - if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) { + if (ast_fileexists(&input[2], NULL, u->chan->language) == 0) { ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]); send_eivr_event(eivr_events, 'Z', NULL, chan); strcpy(&input[2], "exception");