rewrite switch_play_and_get_digits MODAPP-166
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10380 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
c8e4831d26
commit
9d600b5cea
|
@ -626,6 +626,7 @@ typedef enum {
|
||||||
SWITCH_STATUS_UNLOAD,
|
SWITCH_STATUS_UNLOAD,
|
||||||
SWITCH_STATUS_NOUNLOAD,
|
SWITCH_STATUS_NOUNLOAD,
|
||||||
SWITCH_STATUS_IGNORE,
|
SWITCH_STATUS_IGNORE,
|
||||||
|
SWITCH_STATUS_TOO_SMALL,
|
||||||
SWITCH_STATUS_NOT_INITALIZED
|
SWITCH_STATUS_NOT_INITALIZED
|
||||||
} switch_status_t;
|
} switch_status_t;
|
||||||
|
|
||||||
|
|
|
@ -1380,7 +1380,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
|
||||||
uint32_t max_digits,
|
uint32_t max_digits,
|
||||||
const char *prompt_audio_file,
|
const char *prompt_audio_file,
|
||||||
const char *var_name,
|
const char *var_name,
|
||||||
char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators)
|
char *digit_buffer,
|
||||||
|
switch_size_t digit_buffer_length,
|
||||||
|
uint32_t timeout,
|
||||||
|
const char *valid_terminators)
|
||||||
{
|
{
|
||||||
switch_channel_t *channel;
|
switch_channel_t *channel;
|
||||||
switch_input_args_t args = { 0 };
|
switch_input_args_t args = { 0 };
|
||||||
|
@ -1421,6 +1424,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
|
||||||
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
|
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = strlen(digit_buffer);
|
||||||
|
if ((min_digits && len < min_digits)) {
|
||||||
|
status = SWITCH_STATUS_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
if (status == SWITCH_STATUS_SUCCESS) {
|
if (status == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "success");
|
switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "success");
|
||||||
} else if (status == SWITCH_STATUS_TIMEOUT) {
|
} else if (status == SWITCH_STATUS_TIMEOUT) {
|
||||||
|
@ -1440,7 +1448,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
|
SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
|
||||||
uint32_t min_digits,
|
uint32_t min_digits,
|
||||||
uint32_t max_digits,
|
uint32_t max_digits,
|
||||||
|
@ -1448,114 +1455,42 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
|
||||||
uint32_t timeout,
|
uint32_t timeout,
|
||||||
char *valid_terminators,
|
char *valid_terminators,
|
||||||
char *prompt_audio_file,
|
char *prompt_audio_file,
|
||||||
char *bad_input_audio_file, void *digit_buffer, uint32_t digit_buffer_length,
|
char *bad_input_audio_file,
|
||||||
|
void *digit_buffer,
|
||||||
|
uint32_t digit_buffer_length,
|
||||||
char *digits_regex)
|
char *digits_regex)
|
||||||
{
|
{
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
|
||||||
char terminator; /* used to hold terminator recieved from */
|
while(switch_channel_ready(channel) && max_tries) {
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session); /* the channel contained in session */
|
switch_status_t status;
|
||||||
switch_status_t status; /* used to recieve state out of called functions */
|
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
|
||||||
"switch_play_and_get_digits(session, %d, %d, %d, %d, %s, %s, %s, digit_buffer, %d, %s)\n",
|
|
||||||
min_digits, max_digits, max_tries, timeout, valid_terminators, prompt_audio_file,
|
|
||||||
bad_input_audio_file, digit_buffer_length, digits_regex);
|
|
||||||
|
|
||||||
/* Answer the channel if it hasn't already been answered */
|
|
||||||
switch_channel_pre_answer(channel);
|
|
||||||
|
|
||||||
/* Start pestering the user for input */
|
|
||||||
for (; switch_channel_ready(channel) && max_tries > 0; max_tries--) {
|
|
||||||
switch_input_args_t args = { 0 };
|
|
||||||
/* make the buffer so fresh and so clean clean */
|
|
||||||
memset(digit_buffer, 0, digit_buffer_length);
|
|
||||||
|
|
||||||
args.buf = digit_buffer;
|
|
||||||
args.buflen = digit_buffer_length;
|
|
||||||
/* Play the file */
|
|
||||||
status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args);
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "play gave up %s\n", (char *) digit_buffer);
|
|
||||||
|
|
||||||
/* Make sure we made it out alive */
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
/* we only get one digit out of playback, see if thats all we needed and what we got */
|
|
||||||
if (max_digits == 1 && status == SWITCH_STATUS_BREAK) {
|
|
||||||
/* Check the digit if we have a regex */
|
|
||||||
if (digits_regex != NULL) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking regex [%s] on [%s]\n", digits_regex, (char *) digit_buffer);
|
|
||||||
|
|
||||||
/* Make sure the digit is allowed */
|
|
||||||
if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Match found!\n");
|
|
||||||
/* jobs done */
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
/* See if a bad input prompt was specified, if so, play it */
|
|
||||||
if (strlen(bad_input_audio_file) > 0) {
|
|
||||||
status = switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
|
|
||||||
|
|
||||||
/* Make sure we made it out alive */
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* jobs done */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Calling more digits try %d\n", max_tries);
|
|
||||||
|
|
||||||
/* Try to grab some more digits for the timeout period */
|
|
||||||
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
|
|
||||||
if (status == SWITCH_STATUS_TIMEOUT) {
|
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure we made it out alive */
|
memset(digit_buffer, 0, digit_buffer_length);
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
switch_channel_flush_dtmf(channel);
|
||||||
/* Bail */
|
status = switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, NULL,
|
||||||
goto done;
|
digit_buffer, digit_buffer_length, timeout, valid_terminators);
|
||||||
}
|
if (status == SWITCH_STATUS_SUCCESS) {
|
||||||
/* see if we got enough */
|
if (!switch_strlen_zero((char *)digit_buffer)) {
|
||||||
if (min_digits <= strlen(digit_buffer)) {
|
if (switch_strlen_zero(digits_regex)) {
|
||||||
/* See if we need to test a regex */
|
return SWITCH_STATUS_SUCCESS;
|
||||||
if (digits_regex != NULL) {
|
}
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking regex [%s] on [%s]\n", digits_regex, (char *) digit_buffer);
|
if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
|
||||||
/* Test the regex */
|
|
||||||
if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Match found!\n");
|
|
||||||
/* Jobs done */
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
} else {
|
|
||||||
/* See if a bad input prompt was specified, if so, play it */
|
|
||||||
if (strlen(bad_input_audio_file) > 0) {
|
|
||||||
status = switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
|
|
||||||
|
|
||||||
/* Make sure we made it out alive */
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* Jobs done */
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!switch_channel_ready(channel)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_ivr_play_file(session, NULL, bad_input_audio_file, NULL);
|
||||||
|
max_tries--;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
/* if we got here, we got no digits or lost the channel */
|
|
||||||
digit_buffer = "\0";
|
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session_t *session,
|
SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session_t *session,
|
||||||
switch_speech_handle_t *sh,
|
switch_speech_handle_t *sh,
|
||||||
switch_codec_t *codec, switch_timer_t *timer, char *text, switch_input_args_t *args)
|
switch_codec_t *codec, switch_timer_t *timer, char *text, switch_input_args_t *args)
|
||||||
|
|
Loading…
Reference in New Issue