]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
make dtmf duration defaults tweakable
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 18 Apr 2008 17:03:34 +0000 (17:03 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 18 Apr 2008 17:03:34 +0000 (17:03 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8126 d0543943-73ff-0310-b7d9-9358b9ac24b2

15 files changed:
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/endpoints/mod_alsa/mod_alsa.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_channel.c
src/switch_core.c
src/switch_core_io.c
src/switch_ivr_async.c
src/switch_rtp.c

index 18fe82b6eaea7afe26a8fd6404b72f21fa7589c0..d50d93dcb7c32b1107e3102d2f878d999aa2b46d 100644 (file)
@@ -184,6 +184,8 @@ struct switch_runtime {
        switch_log_level_t hard_log_level;
        char *mailer_app;
        char *mailer_app_args;
+       uint32_t max_dtmf_duration;
+       uint32_t default_dtmf_duration;
 };
 
 extern struct switch_runtime runtime;
index 1d38acaad4b8e10b8675d71e193d2cc27a17c576..0a0633e0bc6647d4bc12b1888ff516f68e898ebd 100644 (file)
@@ -1598,6 +1598,8 @@ SWITCH_DECLARE(time_t) switch_timestamp(time_t *t);
 SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload);
 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip(const char *ip_str, const char *list_name);
 SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
+SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration);
+SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
 
 ///\}
 
index 09868da572e0348f23009f4bbe07bd70e6fb7726..0fd77976f0a85e84703c829287bc20b05ffe1715 100644 (file)
@@ -1137,7 +1137,9 @@ typedef enum {
        SCSC_LAST_SPS,
        SCSC_RECLAIM,
        SCSC_MAX_SESSIONS,
-       SCSC_SYNC_CLOCK
+       SCSC_SYNC_CLOCK,
+       SCSC_MAX_DTMF_DURATION,
+       SCSC_DEFAULT_DTMF_DURATION
 } switch_session_ctl_t;
 
 typedef struct apr_pool_t switch_memory_pool_t;
index 26a94dba40c4e332bc5b8112f3adcf75e0a580a2..fa1d62d388b66a3d4813b13fe4d2d51c262f19e9 100644 (file)
@@ -562,7 +562,7 @@ SWITCH_STANDARD_API(status_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define CTL_SYNTAX "[hupall|pause|resume|shutdown|sync_clock|reclaim_mem|max_sessions [num]|loglevel [level]]"
+#define CTL_SYNTAX "[hupall|pause|resume|shutdown|sync_clock|reclaim_mem|max_sessions|max_dtmf_duration [num]|loglevel [level]]"
 SWITCH_STANDARD_API(ctl_function)
 {
        int argc;
@@ -597,6 +597,18 @@ SWITCH_STANDARD_API(ctl_function)
                        }
                        switch_core_session_ctl(SCSC_MAX_SESSIONS, &arg);
                        stream->write_function(stream, "+OK max sessions: %d\n", arg);
+               } else if (!strcasecmp(argv[0], "max_dtmf_duration")) {
+                       if (argc > 1) {
+                               arg = atoi(argv[1]);
+                       }
+                       switch_core_session_ctl(SCSC_MAX_DTMF_DURATION, &arg);
+                       stream->write_function(stream, "+OK max dtmf duration: %d\n", arg);
+               } else if (!strcasecmp(argv[0], "default_dtmf_duration")) {
+                       if (argc > 1) {
+                               arg = atoi(argv[1]);
+                       }
+                       switch_core_session_ctl(SCSC_DEFAULT_DTMF_DURATION, &arg);
+                       stream->write_function(stream, "+OK default dtmf duration: %d\n", arg);
                } else if (!strcasecmp(argv[0], "loglevel")) {
                        if (argc > 1) {
                                if (*argv[1] > 47 && *argv[1] < 58) {
index 88d7f528a9a274175b32b9fffcff4ffec35c2989..df661b805a2f70426fc5d33d75416e05b8a3b1dc 100644 (file)
@@ -1212,7 +1212,7 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
 static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
        char *dtmf_str = argv[0];
-       switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+       switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
        
        if (switch_strlen_zero(dtmf_str)) {
                stream->write_function(stream, "No DTMF Supplied!\n");
index bf432a2c1d0991d720e916ee5f58ef9ada51bb33..bb95732f0a2998eb39370a4d8af56740980ec65c 100644 (file)
@@ -2706,7 +2706,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
                if (msg) {
                        if (*msg == '+') {
                                char *p = msg + 1;
-                               switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
+                               switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
                                while (p && *p) {
                                        dtmf.digit = *p;
                                        switch_channel_queue_dtmf(channel, &dtmf);
index b91d3621630dc4b5c6963f581e6906fa227e4f0f..a8950d2228e8114f7f5d1400f9f9d32942f62f93 100644 (file)
@@ -1126,7 +1126,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
                                break;
                        case IAX_EVENT_DTMF:
                                if (channel) {
-                                       switch_dtmf_t dtmf = { (char) iaxevent->subclass , SWITCH_DEFAULT_DTMF_DURATION };
+                                       switch_dtmf_t dtmf = { (char) iaxevent->subclass , switch_core_default_dtmf_duration(0) };
                                        if (globals.debug) {
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel));
                                        }
index 5f0fd644a271140c874aa10c11788d7bee362c3e..a0645408b26fd9adb05b99cd8885507c9d4a7cd9 100644 (file)
@@ -1203,7 +1203,7 @@ static switch_status_t engage_ring_device(int sample_rate, int channels)
 static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
        char *dtmf_str = argv[0];
-       switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+       switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
        
        if (switch_strlen_zero(dtmf_str)) {
                stream->write_function(stream, "No DTMF Supplied!\n");
index d28655d3f4c107b1b41cff7a96e0ee9a1d9d427a..c814d9f09d82dafd4da68d1ec81442ba5dad3d08 100644 (file)
@@ -2382,7 +2382,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
        const char *signal_ptr;
        const char *rec_header;
        const char *clientcode_header;
-       switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
+       switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
        
        if (session) {
                /* Get the channel */
@@ -2408,7 +2408,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
                                        int tmp;
                                        signal_ptr += 9;
                                        if ((tmp = atoi(signal_ptr)) <= 0) {
-                                               tmp = SWITCH_DEFAULT_DTMF_DURATION;
+                                               tmp = switch_core_default_dtmf_duration(0);
                                        } 
                                        dtmf.duration = tmp * 8;
                                }
index 40490d5b0904c0b9bdea3128b66a2241b9550c98..caf963bbd57737fe3d7555f5106bc00e7c4e4976 100644 (file)
@@ -761,7 +761,7 @@ JSClass event_class = {
 static JSBool dtmf_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
        switch_dtmf_t *dtmf;
-       int32 duration = SWITCH_DEFAULT_DTMF_DURATION;
+       int32 duration = switch_core_default_dtmf_duration(0);
        char *ename;
 
        if (argc > 0) {
@@ -774,7 +774,7 @@ static JSBool dtmf_construct(JSContext * cx, JSObject * obj, uintN argc, jsval *
        if (argc > 1) {
                JS_ValueToInt32(cx, argv[1], &duration);
                if (duration <= 0) {
-                       duration = SWITCH_DEFAULT_DTMF_DURATION;
+                       duration = switch_core_default_dtmf_duration(0);
                }
        }
 
index a0b2f31031888cbc69efdbb7f922594cc507cc36..977f58a0fe53d4fd7936887226aebe682f97236e 100644 (file)
@@ -226,12 +226,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
                switch_dtmf_t *dt;
                int x = 0;
 
-               if (new_dtmf.duration > SWITCH_MAX_DTMF_DURATION) {
+               if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", 
                                                          switch_channel_get_name(channel), new_dtmf.digit, new_dtmf.duration);
-                       new_dtmf.duration = SWITCH_MAX_DTMF_DURATION;
+                       new_dtmf.duration = switch_core_max_dtmf_duration(0);
                } else if (!new_dtmf.duration) {
-                       new_dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+                       new_dtmf.duration = switch_core_default_dtmf_duration(0);
                }
                
                switch_zmalloc(dt, sizeof(*dt));
@@ -259,7 +259,7 @@ done:
 SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string)
 {
        char *p;
-       switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+       switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
        int sent = 0, dur;
        char *string;
        int i, argc;
@@ -273,8 +273,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_
        argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
 
        for(i = 0; i < argc; i++) {
-               dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
-               dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
+               dtmf.duration = switch_core_default_dtmf_duration(0);
+               dur = switch_core_default_dtmf_duration(0) / 8;
                if ((p = strchr(argv[i], '@'))) {
                        *p++ = '\0';
                        if ((dur = atoi(p)) > 50) {
@@ -282,11 +282,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_
                        }
                }
 
-               if (dtmf.duration > SWITCH_MAX_DTMF_DURATION) {
+               if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "EXECSSIVE DTMF DIGIT LEN %c %d\n", dtmf.digit, dtmf.duration);
-                       dtmf.duration = SWITCH_MAX_DTMF_DURATION;
+                       dtmf.duration = switch_core_max_dtmf_duration(0);
                } else if (!dtmf.duration) {
-                       dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+                       dtmf.duration = switch_core_default_dtmf_duration(0);
                }
 
 
@@ -320,12 +320,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
                *dtmf = *dt;
                free(dt);
 
-               if (dtmf->duration > SWITCH_MAX_DTMF_DURATION) {
+               if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", 
                                                          switch_channel_get_name(channel), dtmf->digit, dtmf->duration);
-                       dtmf->duration = SWITCH_MAX_DTMF_DURATION;
+                       dtmf->duration = switch_core_max_dtmf_duration(0);
                } else if (!dtmf->duration) {
-                       dtmf->duration = SWITCH_DEFAULT_DTMF_DURATION;
+                       dtmf->duration = switch_core_default_dtmf_duration(0);
                }
 
                status = SWITCH_STATUS_SUCCESS;
index 4f2fe0ab26d057059d10753b0bf7b4573714fc57..34a4176beb5810ee329e5e6ac5bbbd6bfe808107 100644 (file)
@@ -812,6 +812,28 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
        switch_mutex_unlock(runtime.global_mutex);
 }
 
+SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration)
+{
+       if (duration) {
+               if (duration > SWITCH_MAX_DTMF_DURATION) {
+                       duration = SWITCH_MAX_DTMF_DURATION;
+               }
+               runtime.max_dtmf_duration = duration;
+       }
+       return runtime.max_dtmf_duration;
+}
+
+SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration)
+{
+       if (duration) {
+               if (duration < SWITCH_DEFAULT_DTMF_DURATION) {
+                       duration = SWITCH_DEFAULT_DTMF_DURATION;
+               }
+               runtime.default_dtmf_duration = duration;
+       }
+       return runtime.default_dtmf_duration;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switch_bool_t console, const char **err)
 {
        switch_xml_t xml = NULL, cfg = NULL;
@@ -824,6 +846,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        runtime.hard_log_level = SWITCH_LOG_DEBUG;
        runtime.mailer_app = "sendmail";
        runtime.mailer_app_args = "-t";
+       runtime.max_dtmf_duration = SWITCH_MAX_DTMF_DURATION;
+       runtime.default_dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION;
 
        /* INIT APR and Create the pool context */
        if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
@@ -898,6 +922,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
                                        runtime.mailer_app_args = switch_core_strdup(runtime.memory_pool, val);
                                } else if (!strcasecmp(var, "sessions-per-second")) {
                                        switch_core_sessions_per_second(atoi(val));
+                               } else if (!strcasecmp(var, "max_dtmf_duration")) {
+                                       int tmp = atoi(val);
+                                       if (tmp > 0) {
+                                               switch_core_max_dtmf_duration((uint32_t)tmp);
+                                       }
+                               } else if (!strcasecmp(var, "default_dtmf_duration")) {
+                                       int tmp = atoi(val);
+                                       if (tmp > 0) {
+                                               switch_core_default_dtmf_duration((uint32_t)tmp);
+                                       }
                                } else if (!strcasecmp(var, "disable-monotonic-timing")) {
                                        switch_time_set_monotonic(SWITCH_FALSE);
                                } else if (!strcasecmp(var, "max-sessions")) {
@@ -1137,6 +1171,12 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_
        case SCSC_LAST_SPS:
                *val = runtime.sps_last;
                break;
+       case SCSC_MAX_DTMF_DURATION:
+               *val = switch_core_max_dtmf_duration(*val);
+               break;
+       case SCSC_DEFAULT_DTMF_DURATION:
+               *val = switch_core_default_dtmf_duration(*val);
+               break;
        case SCSC_SPS:
                switch_mutex_lock(runtime.throttle_mutex);
                if (*val > 0) {
index 5f8a76189df609ecc79e04398ea1d3d483446000..ff402bc96775b2f538f7fd8cb8121bc0665a050c 100644 (file)
@@ -952,12 +952,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio
 
        new_dtmf = *dtmf;
 
-       if (new_dtmf.duration > SWITCH_MAX_DTMF_DURATION) {
+       if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", 
                                                  switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
-               new_dtmf.duration = SWITCH_MAX_DTMF_DURATION;
+               new_dtmf.duration = switch_core_max_dtmf_duration(0);
        } else if (!new_dtmf.duration) {
-               new_dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+               new_dtmf.duration = switch_core_default_dtmf_duration(0);
        }
 
        for (ptr = session->event_hooks.recv_dtmf; ptr; ptr = ptr->next) {
@@ -982,12 +982,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
 
        new_dtmf = *dtmf;
 
-       if (new_dtmf.duration > SWITCH_MAX_DTMF_DURATION) {
+       if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", 
                                                  switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
-               new_dtmf.duration = SWITCH_MAX_DTMF_DURATION;
+               new_dtmf.duration = switch_core_max_dtmf_duration(0);
        } else if (!new_dtmf.duration) {
-               new_dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+               new_dtmf.duration = switch_core_default_dtmf_duration(0);
        }
 
 
@@ -1012,7 +1012,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
 SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string)
 {
        char *p;
-       switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+       switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
        int sent = 0, dur;
        char *string;
        int i, argc;
@@ -1042,8 +1042,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
        }
 
        for(i = 0; i < argc; i++) {
-               dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
-               dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
+               dtmf.duration = switch_core_default_dtmf_duration(0);
+               dur = switch_core_default_dtmf_duration(0) / 8;
                if ((p = strchr(argv[i], '@'))) {
                        *p++ = '\0';
                        if ((dur = atoi(p)) > 50) {
@@ -1052,12 +1052,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
                }
 
 
-               if (dtmf.duration > SWITCH_MAX_DTMF_DURATION) {
+               if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", 
                                                          switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
-                       dtmf.duration = SWITCH_MAX_DTMF_DURATION;
+                       dtmf.duration = switch_core_max_dtmf_duration(0);
                } else if (!dtmf.duration) {
-                       dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+                       dtmf.duration = switch_core_default_dtmf_duration(0);
                }
 
                for (p = argv[i]; p && *p; p++) {
index f47230032cd9594092434dbf2e6b2a3d5138f51c..deeea2d206ce4c8ba330addd3c91d647af59d3af 100644 (file)
@@ -845,7 +845,7 @@ static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_da
                                while(p && *p) {
                                        switch_dtmf_t dtmf;
                                        dtmf.digit = *p;
-                                       dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+                                       dtmf.duration = switch_core_default_dtmf_duration(0);
                                        switch_channel_queue_dtmf(channel, &dtmf);
                                        p++;
                                }
index b91722d14b8548a5f108a10813009e0770fcbf45..4302c3192c7b84b59c067576fe587cf69afb9c03 100644 (file)
@@ -1467,8 +1467,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833(switch_rtp_t *rtp_sessi
 
        if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
                *rdigit = *dtmf;
-               if (rdigit->duration < SWITCH_DEFAULT_DTMF_DURATION) {
-                       rdigit->duration = SWITCH_DEFAULT_DTMF_DURATION;
+               if (rdigit->duration < switch_core_default_dtmf_duration(0)) {
+                       rdigit->duration = switch_core_default_dtmf_duration(0);
                }
                
                if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) {
@@ -1492,8 +1492,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_se
        
        if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
                *rdigit = *dtmf;
-               if (rdigit->duration < SWITCH_DEFAULT_DTMF_DURATION) {
-                       rdigit->duration = SWITCH_DEFAULT_DTMF_DURATION;
+               if (rdigit->duration < switch_core_default_dtmf_duration(0)) {
+                       rdigit->duration = switch_core_default_dtmf_duration(0);
                }
 
                if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_inqueue, rdigit)) != SWITCH_STATUS_SUCCESS) {