diff --git a/conf/freeswitch.xml b/conf/freeswitch.xml index 6d1b836a98..acb7f438a6 100644 --- a/conf/freeswitch.xml +++ b/conf/freeswitch.xml @@ -36,6 +36,7 @@ + diff --git a/modules.conf.in b/modules.conf.in index 246db48909..fb96edc301 100644 --- a/modules.conf.in +++ b/modules.conf.in @@ -1,5 +1,6 @@ loggers/mod_console loggers/mod_syslog +applications/mod_dptools applications/mod_commands applications/mod_conference applications/mod_bridgecall diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index d663ebb9ba..b04703e581 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -50,6 +50,15 @@ BEGIN_EXTERN_C * @{ */ + +/*! + \brief Wait for time to pass for a specified number of milliseconds + \param session the session to wait for. + \param ms the number of milliseconds + \return SWITCH_STATUS_SUCCESS if the channel is still up +*/ +SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms); + /*! \brief Wait for DTMF digits calling a pluggable callback function when digits are collected. \param session the session to read. diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c new file mode 100644 index 0000000000..ccef8b2ce3 --- /dev/null +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -0,0 +1,111 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * mod_dptools.c -- Raw Audio File Streaming Application Module + * + */ +#include + +static const char modname[] = "mod_dptools"; + + +static void sleep_function(switch_core_session_t *session, char *data) +{ + + if (switch_strlen_zero(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No timeout specified.\n"); + } else { + uint32_t ms = atoi(data); + switch_ivr_sleep(session, ms); + } +} + +static void set_function(switch_core_session_t *session, char *data) +{ + switch_channel_t *channel; + char *var, *val = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + if (switch_strlen_zero(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); + } else { + var = switch_core_session_strdup(session, data); + val = strchr(var, '='); + + if (val) { + *val++ = '\0'; + if (!strcmp(val, "_UNDEF_")) { + val = NULL; + } + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var, val ? val : "UNDEF"); + switch_channel_set_variable(channel, var, val); + } +} + +static const switch_application_interface_t set_application_interface = { + /*.interface_name */ "set", + /*.application_function */ set_function +}; + +static const switch_application_interface_t sleep_application_interface = { + /*.interface_name */ "sleep", + /*.application_function */ sleep_function, + NULL,NULL,NULL, + &set_application_interface +}; + +static const switch_loadable_module_interface_t mod_dptools_module_interface = { + /*.module_name = */ modname, + /*.endpoint_interface = */ NULL, + /*.timer_interface = */ NULL, + /*.dialplan_interface = */ NULL, + /*.codec_interface = */ NULL, + /*.application_interface */ &sleep_application_interface +}; + +SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) +{ + + /* connect my internal structure to the blank pointer passed to me */ + *module_interface = &mod_dptools_module_interface; + + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; +} + +/* 'switch_module_runtime' will start up in a thread by itself just by having it exist +if it returns anything but SWITCH_STATUS_TERM it will be called again automaticly +*/ + + +//switch_status_t switch_module_runtime(void) diff --git a/src/mod/applications/mod_dptools/mod_dptools.vcproj b/src/mod/applications/mod_dptools/mod_dptools.vcproj new file mode 100644 index 0000000000..01cbeb287e --- /dev/null +++ b/src/mod/applications/mod_dptools/mod_dptools.vcproj @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/switch_channel.c b/src/switch_channel.c index 9ac3b376ba..69926368bc 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -339,11 +339,18 @@ SWITCH_DECLARE(char *) switch_channel_get_name(switch_channel_t *channel) SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value) { assert(channel != NULL); - switch_core_hash_delete(channel->variables, varname); - switch_core_hash_insert_dup(channel->variables, varname, switch_core_session_strdup(channel->session, value)); + if (varname) { + switch_core_hash_delete(channel->variables, varname); + if (value) { + switch_core_hash_insert_dup(channel->variables, varname, switch_core_session_strdup(channel->session, value)); + } else { + switch_core_hash_delete(channel->variables, varname); + } + return SWITCH_STATUS_SUCCESS; + } - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_FALSE; } SWITCH_DECLARE(int) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flags) diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 7eac7403d5..a2fec65758 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -34,6 +34,46 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers; +SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms) +{ + switch_channel_t *channel; + switch_status_t status = SWITCH_STATUS_SUCCESS; + switch_time_t start, now, done = switch_time_now() + (ms * 1000); + switch_frame_t *read_frame; + int32_t left, elapsed; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + start = switch_time_now(); + + for(;;) { + now = switch_time_now(); + elapsed = (int32_t)((now - start) / 1000); + left = ms - elapsed; + + if (!switch_channel_ready(channel)) { + status = SWITCH_STATUS_FALSE; + break; + } + + if (now > done || left <= 0) { + break; + } + + if (switch_channel_test_flag(channel, CF_SERVICE)) { + switch_yield(1000); + } else { + status = switch_core_session_read_frame(session, &read_frame, left, 0); + if (!SWITCH_READ_ACCEPTABLE(status)) { + break; + } + } + } + + + return status; +} SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_callback_function_t input_callback,