]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 11 Mar 2008 21:32:56 +0000 (21:32 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 11 Mar 2008 21:32:56 +0000 (21:32 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7865 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_channel.c
src/switch_ivr_async.c

index a8e8f284caa058744f60fb4978117ae2e63c8956..4544c51e60c69f6cbee4be3a86f30e54debf585a 100644 (file)
@@ -747,6 +747,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
                                                                                                uint32_t timeout,
                                                                                                const char *valid_terminators);
 
+SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, const char *app);
+SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session);
+
+
 /** @} */
 
 SWITCH_END_EXTERN_C
index 31ab5a21017ce5e330b377f33248bfff090c048a..9e9337200d95ebea31fd800abacdb9c7c8133886 100644 (file)
@@ -79,6 +79,26 @@ SWITCH_STANDARD_APP(exe_function)
        }
 }
 
+#define BIND_SYNTAX "<key> <app>"
+SWITCH_STANDARD_APP(dtmf_bind_function)
+{
+       char *argv[2] = { 0 };
+       int argc;
+       char *lbuf = NULL;
+       
+       if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
+               && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 2) {
+               int kval = atoi(argv[0]);
+               if (switch_ivr_bind_dtmf_meta_session(session, kval, argv[1]) == SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound: %s %s\n", argv[0], argv[1]);
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error!\n");
+               }
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", BIND_SYNTAX);
+       }
+}
+
 #define INTERCEPT_SYNTAX "<uuid>"
 SWITCH_STANDARD_APP(intercept_function)
 {
@@ -1609,6 +1629,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
+       SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, eavesdrop_SYNTAX, SAF_NONE);
index defba010606bb25e304e44f7a5cab0e8d63d3720..98e5200ff6a3a4a1df98dd2284b60a519b802198 100644 (file)
@@ -1913,15 +1913,17 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
        switch_time_t uduration = 0, legbillusec = 0, billusec = 0;
        time_t tt_created = 0, tt_answered = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_hungup = 0, tt_prof_created, mtt_prof_created;
 
+       if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
+               return SWITCH_STATUS_FALSE;
+       }
 
-       caller_profile = switch_channel_get_caller_profile(channel);
        if (!(ocp = switch_channel_get_originatee_caller_profile(channel))) {
                ocp = switch_channel_get_originator_caller_profile(channel);
        }
 
        if (!switch_strlen_zero(caller_profile->caller_id_name)) {
                cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name, 
-                       switch_str_nil(caller_profile->caller_id_number));
+                                                                                         switch_str_nil(caller_profile->caller_id_number));
        } else {
                cid_buf = caller_profile->caller_id_number;
        }
index e11c7a730b4312ed1dfaf37a101e74f5c1411124..ed3cb193851821321d3f0e9cc67c430742e35851 100644 (file)
@@ -1258,6 +1258,104 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
   return SWITCH_STATUS_SUCCESS;
 }
 
+typedef struct {
+       const char *app;
+} dtmf_meta_app_t;
+
+typedef struct {
+       dtmf_meta_app_t map[10];
+       time_t last_digit;
+       switch_bool_t meta_on;
+} dtmf_meta_data_t;
+
+#define SWITCH_META_VAR_KEY "__dtmf_meta"
+
+static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
+{
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+       dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
+       time_t now = switch_timestamp(NULL);
+       char digit[2] = "";
+       int dval;
+
+       if (!md) {
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       if (md->meta_on && now - md->last_digit > 5) {
+               md->meta_on = SWITCH_FALSE;
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit);
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       md->last_digit = now;
+
+       if (dtmf->digit == '*') {
+               if (md->meta_on) {
+                       md->meta_on = SWITCH_FALSE;
+                       return SWITCH_STATUS_SUCCESS;
+               } else {
+                       md->meta_on = SWITCH_TRUE;
+                       return SWITCH_STATUS_FALSE;
+               }
+       }
+
+       if (md->meta_on) {
+               if (dtmf->digit >= '0' && dtmf->digit <= '9') {
+                       *digit = dtmf->digit;
+                       dval = atoi(digit);
+                       if (md->map[dval].app) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n", 
+                                                                 switch_channel_get_name(channel), dtmf->digit, md->map[dval].app);
+                               switch_ivr_broadcast(switch_core_session_get_uuid(session), md->map[dval].app, SMF_ECHO_ALEG);
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Ignoring meta digit '%c' not mapped\n", 
+                                                                 switch_channel_get_name(channel), dtmf->digit);
+                                                                 
+                       }
+               }
+               md->meta_on = SWITCH_FALSE;
+               return SWITCH_STATUS_FALSE;
+       }
+
+       return SWITCH_STATUS_SUCCESS;   
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session)
+{
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+    switch_channel_set_private(channel, SWITCH_META_VAR_KEY, NULL);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, const char *app)
+{
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+       dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
+       
+       if (key > 9) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid key %u\n", key);
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (!md) {
+               md = switch_core_session_alloc(session, sizeof(*md));
+               switch_channel_set_private(channel, SWITCH_META_VAR_KEY, md);
+               switch_core_event_hook_add_recv_dtmf(session, meta_on_dtmf);
+       }
+
+       if (!switch_strlen_zero(app)) {
+               md->map[key].app = switch_core_session_strdup(session, app);
+       } else {
+               md->map[key].app = NULL;
+       }
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
+
 struct speech_thread_handle {
        switch_core_session_t *session;
        switch_asr_handle_t *ah;