]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add mod_dptools, for set variable and sleep from the dialplan
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 13 Jul 2006 13:20:20 +0000 (13:20 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 13 Jul 2006 13:20:20 +0000 (13:20 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1864 d0543943-73ff-0310-b7d9-9358b9ac24b2

conf/freeswitch.xml
modules.conf.in
src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c [new file with mode: 0644]
src/mod/applications/mod_dptools/mod_dptools.vcproj [new file with mode: 0644]
src/switch_channel.c
src/switch_ivr.c

index 6d1b836a98640ee7df99d7df4577b1ecf2b85c0e..acb7f438a6f8eff041595ebd4c0ec68aa53edea9 100644 (file)
@@ -36,6 +36,7 @@
         <!-- Applications -->
         <load module="mod_bridgecall"/>
         <load module="mod_echo"/>
+        <load module="mod_dptools"/>
         <!-- <load module="mod_ivrtest"/> -->
         <load module="mod_playback"/>
         <load module="mod_commands"/>
index 246db489096b8857a9624704258e54e81f8a310f..fb96edc3017f652db4305c375701c0e1cfe25a45 100644 (file)
@@ -1,5 +1,6 @@
 loggers/mod_console
 loggers/mod_syslog
+applications/mod_dptools
 applications/mod_commands
 applications/mod_conference
 applications/mod_bridgecall
index d663ebb9ba4122faaa4d8aa5dd95265c8daef766..b04703e581d5d6b26a3757d80ddaaa0e8619419e 100644 (file)
@@ -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 (file)
index 0000000..ccef8b2
--- /dev/null
@@ -0,0 +1,111 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
+ *
+ * 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 <anthmct@yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct@yahoo.com>
+ *
+ *
+ * mod_dptools.c -- Raw Audio File Streaming Application Module
+ *
+ */
+#include <switch.h>
+
+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 (file)
index 0000000..01cbeb2
--- /dev/null
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="mod_dptools"\r
+       ProjectGUID="{78100236-7CEA-4948-96CC-E8ED3160329C}"\r
+       RootNamespace="mod_dptools"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="Debug"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="&quot;$(InputDir)..\..\..\include&quot;;&quot;$(InputDir)include&quot;;&quot;$(InputDir)..\..\..\..\libs\include&quot;"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="4"\r
+                               WarnAsError="true"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_dptools.dll"\r
+                               LinkIncremental="2"\r
+                               AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"\r
+                               GenerateDebugInformation="true"\r
+                               ProgramDatabaseFile="$(OutDir)/mod_dptools.pdb"\r
+                               SubSystem="2"\r
+                               ImportLibrary="$(OutDir)/mod_dptools.lib"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="Release"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="&quot;$(InputDir)..\..\..\include&quot;;&quot;$(InputDir)include&quot;;&quot;$(InputDir)..\..\..\..\libs\include&quot;"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"\r
+                               RuntimeLibrary="0"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="4"\r
+                               WarnAsError="true"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_dptools.dll"\r
+                               LinkIncremental="1"\r
+                               AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               ImportLibrary="$(OutDir)/mod_dptools.lib"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\mod_dptools.c"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index 9ac3b376ba073b14625de736d16964131245a8b9..69926368bcb70ea0a3adb08e07f6981f9da95672 100644 (file)
@@ -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)
index 7eac7403d50571d4cd4842574e884cafb12a22cc..a2fec657586a5205bd68b9775b0dced9b96a2128 100644 (file)
 
 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,