Index: res/res_agi.c =================================================================== RCS file: /usr/cvsroot/asterisk/res/res_agi.c,v retrieving revision 1.54 diff -u -r1.54 res_agi.c --- res/res_agi.c 8 Nov 2005 01:55:30 -0000 1.54 +++ res/res_agi.c 9 Nov 2005 22:05:31 -0000 @@ -348,7 +348,7 @@ /* User information */ fdprintf(fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : ""); - + /* End with empty return */ fdprintf(fd, "\n"); } @@ -571,10 +571,10 @@ /* get option - really similar to the handle_streamfile, but with a timeout */ static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) { - int res; - struct ast_filestream *fs; - long sample_offset = 0; - long max_length; + int res; + struct ast_filestream *fs; + long sample_offset = 0; + long max_length; int timeout = 0; char *edigits = NULL; @@ -591,50 +591,50 @@ timeout = chan->pbx->dtimeout * 1000; /* in msec */ } - fs = ast_openstream(chan, argv[2], chan->language); - if (!fs){ - fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset); - ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]); + fs = ast_openstream(chan, argv[2], chan->language); + if (!fs){ + fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset); + ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]); return RESULT_SUCCESS; - } + } if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout); - ast_seekstream(fs, 0, SEEK_END); - max_length = ast_tellstream(fs); - ast_seekstream(fs, sample_offset, SEEK_SET); - res = ast_applystream(chan, fs); - res = ast_playstream(fs); - if (res) { - fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset); - if (res >= 0) - return RESULT_SHOWUSAGE; - else - return RESULT_FAILURE; - } - res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl); - /* this is to check for if ast_waitstream closed the stream, we probably are at - * the end of the stream, return that amount, else check for the amount */ - sample_offset = (chan->stream)?ast_tellstream(fs):max_length; - ast_stopstream(chan); - if (res == 1) { - /* Stop this command, don't print a result line, as there is a new command */ - return RESULT_SUCCESS; - } + ast_seekstream(fs, 0, SEEK_END); + max_length = ast_tellstream(fs); + ast_seekstream(fs, sample_offset, SEEK_SET); + res = ast_applystream(chan, fs); + res = ast_playstream(fs); + if (res) { + fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset); + if (res >= 0) + return RESULT_SHOWUSAGE; + else + return RESULT_FAILURE; + } + res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl); + /* this is to check for if ast_waitstream closed the stream, we probably are at + * the end of the stream, return that amount, else check for the amount */ + sample_offset = (chan->stream)?ast_tellstream(fs):max_length; + ast_stopstream(chan); + if (res == 1) { + /* Stop this command, don't print a result line, as there is a new command */ + return RESULT_SUCCESS; + } /* If the user didnt press a key, wait for digitTimeout*/ if (res == 0 ) { res = ast_waitfordigit_full(chan, timeout, agi->audio, agi->ctrl); /* Make sure the new result is in the escape digits of the GET OPTION */ if ( !strchr(edigits,res) ) - res=0; + res=0; } - fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset); - if (res >= 0) - return RESULT_SUCCESS; - else - return RESULT_FAILURE; + fdprintf(agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset); + if (res >= 0) + return RESULT_SUCCESS; + else + return RESULT_FAILURE; } @@ -861,13 +861,13 @@ int res = 0; int ms; - struct ast_dsp *sildet=NULL; /* silence detector dsp */ - int totalsilence = 0; - int dspsilence = 0; - int silence = 0; /* amount of silence to allow */ - int gotsilence = 0; /* did we timeout for silence? */ - char *silencestr=NULL; - int rfmt=0; + struct ast_dsp *sildet=NULL; /* silence detector dsp */ + int totalsilence = 0; + int dspsilence = 0; + int silence = 0; /* amount of silence to allow */ + int gotsilence = 0; /* did we timeout for silence? */ + char *silencestr=NULL; + int rfmt=0; /* XXX EAGI FIXME XXX */ @@ -890,27 +890,27 @@ silencestr++; silencestr++; if (silencestr) - silence = atoi(silencestr); - if (silence > 0) - silence *= 1000; - } + silence = atoi(silencestr); + if (silence > 0) + silence *= 1000; + } } } - if (silence > 0) { - rfmt = chan->readformat; - res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); - if (res < 0) { - ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); - return -1; - } - sildet = ast_dsp_new(); - if (!sildet) { - ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); - return -1; - } - ast_dsp_set_threshold(sildet, 256); - } + if (silence > 0) { + rfmt = chan->readformat; + res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); + if (res < 0) { + ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); + return -1; + } + sildet = ast_dsp_new(); + if (!sildet) { + ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); + return -1; + } + ast_dsp_set_threshold(sildet, 256); + } /* backward compatibility, if no offset given, arg[6] would have been * caught below and taken to be a beep, else if it is a digit then it is a @@ -982,43 +982,43 @@ * is valid after a write, and it will then have our current * location */ sample_offset = ast_tellstream(fs); - if (silence > 0) { - dspsilence = 0; - ast_dsp_silence(sildet, f, &dspsilence); - if (dspsilence) { - totalsilence = dspsilence; - } else { - totalsilence = 0; - } - if (totalsilence > silence) { - /* Ended happily with silence */ - ast_frfree(f); - gotsilence = 1; - break; - } - } + if (silence > 0) { + dspsilence = 0; + ast_dsp_silence(sildet, f, &dspsilence); + if (dspsilence) { + totalsilence = dspsilence; + } else { + totalsilence = 0; + } + if (totalsilence > silence) { + /* Ended happily with silence */ + ast_frfree(f); + gotsilence = 1; + break; + } + } break; } ast_frfree(f); if (gotsilence) break; - } + } - if (gotsilence) { - ast_stream_rewind(fs, silence-1000); - ast_truncstream(fs); + if (gotsilence) { + ast_stream_rewind(fs, silence-1000); + ast_truncstream(fs); sample_offset = ast_tellstream(fs); } fdprintf(agi->fd, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset); ast_closestream(fs); } - if (silence > 0) { - res = ast_set_read_format(chan, rfmt); - if (res) - ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name); - ast_dsp_free(sildet); - } + if (silence > 0) { + res = ast_set_read_format(chan, rfmt); + if (res) + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name); + ast_dsp_free(sildet); + } return RESULT_SUCCESS; } @@ -1289,11 +1289,11 @@ static char debug_usage[] = "Usage: agi debug\n" -" Enables dumping of AGI transactions for debugging purposes\n"; +" Enables dumping of AGI transactions for debugging purposes\n"; static char no_debug_usage[] = "Usage: agi no debug\n" -" Disables dumping of AGI transactions for debugging purposes\n"; +" Disables dumping of AGI transactions for debugging purposes\n"; static int agi_do_debug(int fd, int argc, char *argv[]) { @@ -1567,7 +1567,7 @@ static char usage_recordfile[] = " Usage: RECORD FILE \\\n" -" [offset samples] [BEEP] [s=silence]\n" +" [offset samples] [BEEP] [s=silence]\n" " Record to a file until a given dtmf digit in the sequence is received\n" " Returns -1 on hangup or error. The format will specify what kind of file\n" " will be recorded. The timeout is the maximum record time in milliseconds, or\n" @@ -2006,7 +2006,7 @@ int fds[2]; int efd = -1; int pid; - char *stringp; + char *stringp; AGI agi; if (ast_strlen_zero(data)) { @@ -2016,15 +2016,15 @@ ast_copy_string(buf, data, sizeof(buf)); memset(&agi, 0, sizeof(agi)); - while ((stringp = strsep(&tmp, "|"))) { + while ((stringp = strsep(&tmp, "|"))) { argv[argc++] = stringp; - } + } argv[argc] = NULL; LOCAL_USER_ADD(u); #if 0 /* Answer if need be */ - if (chan->_state != AST_STATE_UP) { + if (chan->_state != AST_STATE_UP) { if (ast_answer(chan)) { LOCAL_USER_REMOVE(u); return -1; @@ -2080,9 +2080,9 @@ static char showagi_help[] = "Usage: show agi [topic]\n" -" When called with a topic as an argument, displays usage\n" -" information on the given command. If called without a\n" -" topic, it provides a list of AGI commands.\n"; +" When called with a topic as an argument, displays usage\n" +" information on the given command. If called without a\n" +" topic, it provides a list of AGI commands.\n"; static char dumpagihtml_help[] =