From 96ff2abcd7eee6052a99e6a8d2751586d78ee32a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 Apr 2008 17:03:34 +0000 Subject: [PATCH] make dtmf duration defaults tweakable git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8126 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/private/switch_core_pvt.h | 2 + src/include/switch_core.h | 2 + src/include/switch_types.h | 4 +- .../applications/mod_commands/mod_commands.c | 14 ++++++- src/mod/endpoints/mod_alsa/mod_alsa.c | 2 +- .../endpoints/mod_dingaling/mod_dingaling.c | 2 +- src/mod/endpoints/mod_iax/mod_iax.c | 2 +- .../endpoints/mod_portaudio/mod_portaudio.c | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 4 +- .../mod_spidermonkey/mod_spidermonkey.c | 4 +- src/switch_channel.c | 24 +++++------ src/switch_core.c | 40 +++++++++++++++++++ src/switch_core_io.c | 24 +++++------ src/switch_ivr_async.c | 2 +- src/switch_rtp.c | 8 ++-- 15 files changed, 97 insertions(+), 39 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 18fe82b6ea..d50d93dcb7 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -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; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 1d38acaad4..0a0633e0bc 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -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); ///\} diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 09868da572..0fd77976f0 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 26a94dba40..fa1d62d388 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -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) { diff --git a/src/mod/endpoints/mod_alsa/mod_alsa.c b/src/mod/endpoints/mod_alsa/mod_alsa.c index 88d7f528a9..df661b805a 100644 --- a/src/mod/endpoints/mod_alsa/mod_alsa.c +++ b/src/mod/endpoints/mod_alsa/mod_alsa.c @@ -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"); diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index bf432a2c1d..bb95732f0a 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -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); diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index b91d362163..a8950d2228 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -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)); } diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 5f0fd644a2..a0645408b2 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -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"); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index d28655d3f4..c814d9f09d 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -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; } diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 40490d5b09..caf963bbd5 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -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); } } diff --git a/src/switch_channel.c b/src/switch_channel.c index a0b2f31031..977f58a0fe 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -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; diff --git a/src/switch_core.c b/src/switch_core.c index 4f2fe0ab26..34a4176beb 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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) { diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 5f8a76189d..ff402bc967 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -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++) { diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index f47230032c..deeea2d206 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -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++; } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index b91722d14b..4302c3192c 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -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) {