Author: anthm Date: Tue Mar 4 13:55:16 2008 New Revision: 7784 Modified: freeswitch/trunk/src/include/switch_ivr.h freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c freeswitch/trunk/src/switch_ivr.c freeswitch/trunk/src/switch_ivr_play_say.c Log: add read app Modified: freeswitch/trunk/src/include/switch_ivr.h ============================================================================== --- freeswitch/trunk/src/include/switch_ivr.h (original) +++ freeswitch/trunk/src/include/switch_ivr.h Tue Mar 4 13:55:16 2008 @@ -735,6 +735,16 @@ SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t *session, switch_core_session_t *peer_session); +SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session, + uint32_t min_digits, + uint32_t max_digits, + const char *prompt_audio_file, + const char *var_name, + char *digit_buffer, + switch_size_t digit_buffer_length, + uint32_t timeout, + const char *valid_terminators); + /** @} */ SWITCH_END_EXTERN_C Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original) +++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Tue Mar 4 13:55:16 2008 @@ -1057,6 +1057,70 @@ switch_ivr_speak_text(session, engine, voice, text, &args); } + +SWITCH_STANDARD_APP(read_function) +{ + char *mydata; + char *argv[6] = { 0 }; + int argc; + int32_t min_digits = 0; + int32_t max_digits = 0; + int timeout = 1000; + char digit_buffer[128] = ""; + const char *prompt_audio_file = NULL; + const char *var_name = NULL; + const char *valid_terminators = NULL; + + if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) { + argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No file specified.\n"); + return; + } + + min_digits = atoi(argv[0]); + + if (argc > 1) { + max_digits = atoi(argv[1]); + } + + if (argc > 2) { + prompt_audio_file = argv[2]; + } + + if (argc > 3) { + var_name = argv[3]; + } + + if (argc > 4) { + timeout = atoi(argv[4]); + } + + if (argc > 5) { + valid_terminators = argv[5]; + } + + if (min_digits <= 1) { + min_digits = 1; + } + + if (max_digits < min_digits) { + max_digits = min_digits; + } + + if (timeout <= 1000) { + timeout = 1000; + } + + if (switch_strlen_zero(valid_terminators)) { + valid_terminators = "#"; + } + + switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, var_name, digit_buffer, sizeof(digit_buffer), timeout, valid_terminators); + +} + + SWITCH_STANDARD_APP(playback_function) { switch_input_args_t args = { 0 }; @@ -1550,6 +1614,7 @@ SWITCH_ADD_APP(app_interface, "park_state", "Park State", "Park State", park_state_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "gentones", "Generate Tones", "Generate tones to the channel", gentones_function, "<tgml_script>[|<loops>]", SAF_NONE); SWITCH_ADD_APP(app_interface, "playback", "Playback File", "Playback a file to the channel", playback_function, "<path>", SAF_NONE); + SWITCH_ADD_APP(app_interface, "read", "Read Digits", "Read Digits", read_function, "<min> <max> <file> <var name> <timeout> <terminators>", SAF_NONE); SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "<path>", SAF_NONE); SWITCH_ADD_APP(app_interface, "record_session", "Record Session", SESS_REC_DESC, record_session_function, "<path>", SAF_NONE); SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function, "<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]", SAF_NONE); Modified: freeswitch/trunk/src/switch_ivr.c ============================================================================== --- freeswitch/trunk/src/switch_ivr.c (original) +++ freeswitch/trunk/src/switch_ivr.c Tue Mar 4 13:55:16 2008 @@ -647,7 +647,7 @@ digit_started = switch_timestamp_now(); } - for (y = 0; y < maxdigits; y++) { + for (y = 0; y <= maxdigits; y++) { if (switch_channel_dequeue_dtmf(channel, &dtmf) != SWITCH_STATUS_SUCCESS) { break; } Modified: freeswitch/trunk/src/switch_ivr_play_say.c ============================================================================== --- freeswitch/trunk/src/switch_ivr_play_say.c (original) +++ freeswitch/trunk/src/switch_ivr_play_say.c Tue Mar 4 13:55:16 2008 @@ -887,7 +887,7 @@ if (args->input_callback) { status = args->input_callback(session, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); } else { - switch_copy_string((char *) args->buf, (void *)&dtmf, args->buflen); + *((char *)args->buf) = dtmf.digit; status = SWITCH_STATUS_BREAK; } } @@ -1081,6 +1081,65 @@ return status; } +SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session, + uint32_t min_digits, + uint32_t max_digits, + const char *prompt_audio_file, + const char *var_name, + char *digit_buffer, + switch_size_t digit_buffer_length, + uint32_t timeout, + const char *valid_terminators) +{ + switch_channel_t *channel; + switch_input_args_t args = { 0 }; + switch_status_t status = SWITCH_STATUS_SUCCESS; + char terminator; + int len; + + switch_assert(session); + + channel = switch_core_session_get_channel(session); + + if (digit_buffer_length < min_digits || digit_buffer_length < max_digits) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Buffer too small!\n"); + return SWITCH_STATUS_FALSE; + } + + switch_channel_pre_answer(channel); + + memset(digit_buffer, 0, digit_buffer_length); + args.buf = digit_buffer; + args.buflen = digit_buffer_length; + + if (!switch_strlen_zero(prompt_audio_file)) { + status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args); + } + + if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { + goto end; + } + + len = strlen(digit_buffer); + + if (len < min_digits && len < max_digits) { + args.buf = digit_buffer + len; + args.buflen = digit_buffer_length - len; + status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0); + } + + + end: + + if (var_name && !switch_strlen_zero(digit_buffer)) { + switch_channel_set_variable(channel, var_name, digit_buffer); + } + + return status; + +} + + SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session, uint32_t min_digits, uint32_t max_digits,