make dtmf duration defaults tweakable

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8126 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-04-18 17:03:34 +00:00
parent 56f6d7f17a
commit 96ff2abcd7
15 changed files with 97 additions and 39 deletions

View 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;

View 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);
///\}

View 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;

View 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) {

View 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");

View 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);

View 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));
}

View 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");

View 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;
}

View 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);
}
}

View 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;

View 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) {

View 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++) {

View 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++;
}

View 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) {