]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add read app
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Mar 2008 18:55:16 +0000 (18:55 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Mar 2008 18:55:16 +0000 (18:55 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7784 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr.c
src/switch_ivr_play_say.c

index 75d12c7167e6bbc0aafa93f47f3841cc43e0bdde..99bac572eb99c5a4155e4a8e34dd04c11b575966 100644 (file)
@@ -735,6 +735,16 @@ SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session
 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
index 35973a74f8ffd14ec1cf3b829a987dd6a4e0409f..ec3ccf2d245f5ba49979d89f7c28500ee2c37995 100644 (file)
@@ -1057,6 +1057,70 @@ SWITCH_STANDARD_APP(speak_function)
        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_MODULE_LOAD_FUNCTION(mod_dptools_load)
        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);
index 4f0d1204cb861035e90277bdb25744fa1e150d6f..bb935f268e6574ea2aa1d637c84b2ba4fbecfe1d 100644 (file)
@@ -647,7 +647,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
                                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;
                                }
index c50d572e9cb773abf8db0e85eb1baf2643c6a547..292316f5f501db8d2b851e6803e0c1b3b44f7b7f 100644 (file)
@@ -887,7 +887,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
                                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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
        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,