Mega Changes

adding mod_park for putting channels in limbo state for remote control.
adding stuff to mod_event_socket to let you do the bgapi <command> <args>
this will let you execute a job in the bg and the result will be sent as an event with an
indicated uuid to match the reply to the command

adding switch_core_port_allocator (to be used soon)
adding "make sure" to do a full rebild of the freeswitch object files

There will be more to this committed as the week progresses

make sure you do a rebuild after this update or you'll be sowwie
./configure && make sure




git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2540 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2006-09-07 03:58:01 +00:00
1 parent cd3b46dd02
commit 80722357a6
20 files changed
+2228 -1993

No files matched your search

@@ -260,7 +260,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
return SWITCH_STATUS_SUCCESS;
}
if (switch_ivr_originate(NULL, &caller_session, aleg, timeout, NULL, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_ivr_originate(NULL, &caller_session, aleg, timeout, &noop_state_handler, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg);
return SWITCH_STATUS_SUCCESS;
}
@@ -268,9 +268,32 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
caller_channel = switch_core_session_get_channel(caller_session);
assert(caller_channel != NULL);
switch_channel_clear_state_handler(caller_channel, NULL);
switch_core_session_rwunlock(caller_session);
switch_ivr_session_transfer(caller_session, exten, dp, context);
if (*exten == '&') {
switch_caller_extension_t *extension = NULL;
char *app_name = switch_core_session_strdup(caller_session, (exten + 1));
char *arg, *e;
if ((e = strchr(app_name, ')'))) {
*e = '\0';
}
if ((arg = strchr(app_name, '('))) {
*arg++ = '\0';
}
if ((extension = switch_caller_extension_new(caller_session, app_name, arg)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_MEMERR;
}
switch_caller_extension_add_application(caller_session, extension, app_name, arg);
switch_channel_set_caller_extension(caller_channel, extension);
switch_channel_set_state(caller_channel, CS_EXECUTE);
} else {
switch_ivr_session_transfer(caller_session, exten, dp, context);
}
return SWITCH_STATUS_SUCCESS;;
}
+67
View File
@@ -0,0 +1,67 @@
/*
* 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_park.c -- Park application
*
*/
#include <switch.h>
static const char modname[] = "mod_park";
static void park_function(switch_core_session_t *session, char *data)
{
switch_ivr_park(session);
}
static const switch_application_interface_t park_application_interface = {
/*.interface_name */ "park",
/*.application_function */ park_function,
NULL,NULL,NULL,NULL
};
static switch_loadable_module_interface_t park_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ &park_application_interface,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
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 = &park_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
@@ -0,0 +1,210 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="mod_park"
ProjectGUID="{0E2C6395-13B9-46E5-9264-8859D346018D}"
RootNamespace="mod_park"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(InputDir)..\..\..\include&quot;;&quot;$(InputDir)include&quot;;&quot;$(InputDir)..\..\..\..\libs\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(OutDir)/mod/$(InputName).dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)$(TargetName).pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/mod_park.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(InputDir)..\..\..\include&quot;;&quot;$(InputDir)include&quot;;&quot;$(InputDir)..\..\..\..\libs\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="4"
WarnAsError="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(OutDir)/mod/$(InputName).dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\..\w32\vsnet\$(OutDir)"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)$(TargetName).pdb"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/mod_park.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\mod_park.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -56,10 +56,10 @@ struct listener {
switch_mutex_t *flag_mutex;
uint32_t flags;
switch_log_level_t level;
char *retbuf;
char *ebuf;
uint8_t event_list[SWITCH_EVENT_ALL+1];
switch_hash_t *event_hash;
switch_thread_rwlock_t *rwlock;
struct listener *next;
};
@@ -282,17 +282,20 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
if (count == 1) {
switch_event_create(event, SWITCH_EVENT_MESSAGE);
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Command", mbuf);
} else {
} else if (cur) {
char *var, *val;
var = mbuf;
if ((val = strchr(var, ':'))) {
*val++ = '\0';
while(*val == ' ') {
val++;
var = cur;
strip_cr(var);
if (!switch_strlen_zero(var)) {
if ((val = strchr(var, ':'))) {
*val++ = '\0';
while(*val == ' ') {
val++;
}
}
if (var && val) {
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, var, val);
}
}
if (var && val) {
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, var, val);
}
}
@@ -385,6 +388,71 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
}
struct api_command_struct {
char *api_cmd;
char *arg;
listener_t *listener;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
uint8_t bg;
};
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
{
struct api_command_struct *acs = (struct api_command_struct *) obj;
switch_stream_handle_t stream = {0};
if (switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error! cannot get read lock.\n");
goto done;
}
SWITCH_STANDARD_STREAM(stream);
if (stream.data) {
if (switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
if (acs->bg) {
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Job-UUID", acs->uuid_str);
switch_event_add_body(event, stream.data);
switch_event_fire(&event);
}
} else {
switch_size_t len;
char buf[1024];
len = strlen(stream.data) + 1;
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", len);
len = strlen(buf) + 1;
switch_socket_send(acs->listener->sock, buf, &len);
len = strlen(stream.data) + 1;
switch_socket_send(acs->listener->sock, stream.data, &len);
}
}
free(stream.data);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
}
switch_thread_rwlock_unlock(acs->listener->rwlock);
done:
if (acs && acs->bg) {
if (acs->api_cmd) {
free(acs->api_cmd);
}
if (acs->arg) {
free(acs->arg);
}
free(acs);
}
return NULL;
}
static switch_status_t parse_command(listener_t *listener, switch_event_t *event, char *reply, uint32_t reply_len)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -419,38 +487,98 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t *event
goto done;
}
if (!strncasecmp(cmd, "api ", 4)) {
char *api_cmd = cmd + 4;
switch_stream_handle_t stream = {0};
char *arg;
if (!strncasecmp(cmd, "sendmsg", 7)) {
switch_core_session_t *session;
char *uuid = cmd + 8;
if (!listener->retbuf) {
listener->retbuf = switch_core_alloc(listener->pool, CMD_BUFLEN);
if (uuid) {
while(*uuid == ' ') {
uuid++;
}
strip_cr(uuid);
}
stream.data = listener->retbuf;
stream.end = stream.data;
stream.data_size = CMD_BUFLEN;
stream.write_function = switch_console_stream_write;
if (!uuid) {
uuid = switch_event_get_header(event, "session-id");
}
if ((session = switch_core_session_locate(uuid))) {
switch_channel_t *channel = switch_core_session_get_channel(session);
if (!switch_channel_test_flag(channel, CF_CONTROLLED)) {
switch_core_session_rwunlock(session);
session = NULL;
}
}
if (session) {
if ((status = switch_core_session_queue_private_event(session, &event)) == SWITCH_STATUS_SUCCESS) {
snprintf(reply, reply_len, "+OK");
} else {
snprintf(reply, reply_len, "-ERR memory error");
}
switch_core_session_rwunlock(session);
} else {
snprintf(reply, reply_len, "-ERR invalid session id [%s]", uuid);
}
goto done;
} else if (!strncasecmp(cmd, "api ", 4)) {
struct api_command_struct acs = {0};
char *api_cmd = cmd + 4;
char *arg = NULL;
strip_cr(api_cmd);
if ((arg = strchr(api_cmd, ' '))) {
*arg++ = '\0';
}
if (switch_api_execute(api_cmd, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
switch_size_t len;
char buf[1024];
len = strlen(listener->retbuf) + 1;
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", len);
len = strlen(buf) + 1;
switch_socket_send(listener->sock, buf, &len);
len = strlen(listener->retbuf) + 1;
switch_socket_send(listener->sock, listener->retbuf, &len);
return SWITCH_STATUS_SUCCESS;
}
acs.listener = listener;
acs.api_cmd = api_cmd;
acs.arg = arg;
acs.bg = 0;
api_exec(NULL, (void *) &acs);
snprintf(reply, reply_len, "+OK");
return SWITCH_STATUS_SUCCESS;
} else if (!strncasecmp(cmd, "bgapi ", 6)) {
struct api_command_struct *acs;
char *api_cmd = cmd + 6;
char *arg = NULL;
strip_cr(api_cmd);
if ((arg = strchr(api_cmd, ' '))) {
*arg++ = '\0';
}
if ((acs = malloc(sizeof(*acs)))) {
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
switch_uuid_t uuid;
memset(acs, 0, sizeof(*acs));
acs->listener = listener;
if (api_cmd) {
acs->api_cmd = strdup(api_cmd);
}
if (arg) {
acs->arg = strdup(arg);
}
acs->bg = 1;
switch_threadattr_create(&thd_attr, listener->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, api_exec, acs, listener->pool);
switch_uuid_get(&uuid);
switch_uuid_format(acs->uuid_str, &uuid);
snprintf(reply, reply_len, "+OK Job-UUID: %s", acs->uuid_str);
} else {
snprintf(reply, reply_len, "-ERR memory error!");
}
return SWITCH_STATUS_SUCCESS;
} else if (!strncasecmp(cmd, "log", 3)) {
char *level_s;
@@ -643,8 +771,16 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
remove_listener(listener);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread done, waiting for children\n");
switch_thread_rwlock_wrlock(listener->rwlock);
switch_thread_rwlock_unlock(listener->rwlock);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n");
if (listener->pool) {
switch_memory_pool_t *pool = listener->pool;
switch_core_destroy_memory_pool(&pool);
@@ -734,6 +870,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if (rv) goto fail;
rv = switch_socket_create(&listen_list.sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, pool);
if (rv) goto sock_fail;
rv = switch_socket_opt_set(listen_list.sock, SWITCH_SO_REUSEADDR, 1);
if (rv) goto sock_fail;
rv = switch_socket_bind(listen_list.sock, sa);
if (rv) goto sock_fail;
rv = switch_socket_listen(listen_list.sock, 5);
@@ -742,7 +880,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
sock_fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
switch_yield(1000000);
switch_yield(100000);
}
listen_list.ready = 1;
@@ -771,6 +909,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
}
switch_thread_rwlock_create(&listener->rwlock, listener_pool);
switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);
switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);