mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-18 09:32:34 +00:00
add mod_xml_scgi (like xml_curl minus the web server direct to an application backend that supports the SCGI protocol)
This commit is contained in:
parent
6bb33d7683
commit
d7cf0bbed0
src/mod/xml_int/mod_xml_scgi
5
src/mod/xml_int/mod_xml_scgi/Makefile
Normal file
5
src/mod/xml_int/mod_xml_scgi/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
BASE=../../../..
|
||||
LOCAL_SOURCES = $(BASE)/libs/libscgi/src/scgi.c
|
||||
LOCAL_OBJS = $(BASE)/libs/libscgi/src/scgi.o
|
||||
LOCAL_CFLAGS = -I. -I$(BASE)/libs/libscgi/src/include
|
||||
include $(BASE)/build/modmake.rules
|
@ -0,0 +1,12 @@
|
||||
<configuration name="xml_scgi.conf" description="SCGI XML Gateway">
|
||||
<bindings>
|
||||
<binding name="example">
|
||||
<!-- one or more |-delim of configuration|directory|dialplan -->
|
||||
<!-- <param name="host" value="127.0.0.1" bindings="dialplan"/> -->
|
||||
<!-- <param name="port" value="8080"/> -->
|
||||
<!-- <param name="timeout" value="10"/> -->
|
||||
<!-- one or more of these imply you want to pick the exact variables that are transmitted -->
|
||||
<!--<param name="enable-post-var" value="Unique-ID"/>-->
|
||||
</binding>
|
||||
</bindings>
|
||||
</configuration>
|
287
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.2008.vcproj
Normal file
287
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.2008.vcproj
Normal file
@ -0,0 +1,287 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="mod_xml_scgi"
|
||||
ProjectGUID="{11C9BC3D-45E9-46E3-BE84-B8CEE4685E39}"
|
||||
RootNamespace="mod_xml_scgi"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
<Platform
|
||||
Name="x64"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="17"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="17"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<File
|
||||
RelativePath=".\mod_xml_scgi.c"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
131
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.2010.vcxproj
Normal file
131
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.2010.vcxproj
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectName>mod_xml_scgi</ProjectName>
|
||||
<ProjectGuid>{11C9BC3D-45E9-46E3-BE84-B8CEE4685E39}</ProjectGuid>
|
||||
<RootNamespace>mod_xml_scgi</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\..\w32\module_release.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\..\w32\module_debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\..\w32\module_release.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\..\w32\module_debug.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Midl>
|
||||
<TargetEnvironment>X64</TargetEnvironment>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Midl>
|
||||
<TargetEnvironment>X64</TargetEnvironment>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<DataExecutionPrevention>
|
||||
</DataExecutionPrevention>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mod_xml_scgi.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\w32\Library\FreeSwitchCore.2010.vcxproj">
|
||||
<Project>{202d7a4e-760d-4d0e-afa1-d7459ced30ff}</Project>
|
||||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
340
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c
Normal file
340
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c
Normal file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
* 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 <anthm@freeswitch.org>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
* mod_xml_scgi.c -- SCGI XML Gateway
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
#include <scgi.h>
|
||||
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_xml_scgi_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_scgi_shutdown);
|
||||
SWITCH_MODULE_DEFINITION(mod_xml_scgi, mod_xml_scgi_load, mod_xml_scgi_shutdown, NULL);
|
||||
|
||||
|
||||
struct xml_binding {
|
||||
char *host;
|
||||
switch_port_t port;
|
||||
char *url;
|
||||
|
||||
int timeout;
|
||||
switch_hash_t *vars_map;
|
||||
char *bindings;
|
||||
|
||||
};
|
||||
|
||||
static int GLOBAL_DEBUG = 0;
|
||||
|
||||
typedef struct xml_binding xml_binding_t;
|
||||
|
||||
#define XML_SCGI_MAX_BYTES 1024 * 1024
|
||||
|
||||
typedef struct hash_node {
|
||||
switch_hash_t *hash;
|
||||
struct hash_node *next;
|
||||
} hash_node_t;
|
||||
|
||||
static struct {
|
||||
switch_memory_pool_t *pool;
|
||||
hash_node_t *hash_root;
|
||||
hash_node_t *hash_tail;
|
||||
} globals;
|
||||
|
||||
#define XML_SCGI_SYNTAX "[debug_on|debug_off]"
|
||||
SWITCH_STANDARD_API(xml_scgi_function)
|
||||
{
|
||||
if (session) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (zstr(cmd)) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (!strcasecmp(cmd, "debug_on")) {
|
||||
GLOBAL_DEBUG = 1;
|
||||
} else if (!strcasecmp(cmd, "debug_off")) {
|
||||
GLOBAL_DEBUG = 0;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
stream->write_function(stream, "OK\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
usage:
|
||||
stream->write_function(stream, "USAGE: %s\n", XML_SCGI_SYNTAX);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
|
||||
void *user_data)
|
||||
{
|
||||
switch_xml_t xml = NULL;
|
||||
char *data = NULL;
|
||||
xml_binding_t *binding = (xml_binding_t *) user_data;
|
||||
char hostname[256] = "";
|
||||
char basic_data[512];
|
||||
unsigned char buf[16336] = "";
|
||||
ssize_t len = -1, bytes = 0;
|
||||
scgi_handle_t handle = { 0 };
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
char *txt = NULL;
|
||||
|
||||
strncpy(hostname, switch_core_get_switchname(), sizeof(hostname));
|
||||
|
||||
if (!binding) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s§ion=%s&tag_name=%s&key_name=%s&key_value=%s",
|
||||
hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value));
|
||||
|
||||
data = switch_event_build_param_string(params, basic_data, binding->vars_map);
|
||||
switch_assert(data);
|
||||
|
||||
scgi_add_param(&handle, "REQUEST_METHOD", "POST");
|
||||
scgi_add_param(&handle, "REQUEST_URI", binding->url);
|
||||
scgi_add_body(&handle, data);
|
||||
|
||||
if (scgi_connect(&handle, binding->host, binding->port, binding->timeout * 1000) == SCGI_SUCCESS) {
|
||||
scgi_send_request(&handle);
|
||||
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
txt = (char *) stream.data;
|
||||
|
||||
while((len = scgi_recv(&handle, buf, sizeof(buf))) > 0) {
|
||||
|
||||
bytes += len;
|
||||
|
||||
if (bytes > XML_SCGI_MAX_BYTES) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Data too big!\n");
|
||||
len = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
stream.write_function(&stream, "%s", buf);
|
||||
}
|
||||
|
||||
scgi_disconnect(&handle);
|
||||
}
|
||||
|
||||
if (GLOBAL_DEBUG) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEBUG:\nURL: %s\nPOST_DATA:\n%s\n\nRESPONSE:\n%s\n\n", binding->url, data, txt);
|
||||
}
|
||||
|
||||
if (!len) {
|
||||
if (!(xml = switch_xml_parse_str(txt, strlen(txt)))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result! [%s]\ndata: [%s]\n", binding->url, data);
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received error trying to fetch %s\ndata: [%s]\n", binding->url, data);
|
||||
switch_safe_free(stream.data);
|
||||
xml = NULL;
|
||||
}
|
||||
|
||||
switch_safe_free(data);
|
||||
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
#define ENABLE_PARAM_VALUE "enabled"
|
||||
static switch_status_t do_config(void)
|
||||
{
|
||||
char *cf = "xml_scgi.conf";
|
||||
switch_xml_t cfg, xml, bindings_tag, binding_tag, param;
|
||||
xml_binding_t *binding = NULL;
|
||||
int x = 0;
|
||||
int need_vars_map = 0;
|
||||
switch_hash_t *vars_map = NULL;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (binding_tag = switch_xml_child(bindings_tag, "binding"); binding_tag; binding_tag = binding_tag->next) {
|
||||
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
|
||||
char *host = "127.0.0.1";
|
||||
char *port = "8080";
|
||||
char *bind_mask = NULL;
|
||||
int timeout = 0;
|
||||
|
||||
hash_node_t *hash_node;
|
||||
need_vars_map = 0;
|
||||
vars_map = NULL;
|
||||
|
||||
for (param = switch_xml_child(binding_tag, "param"); param; param = param->next) {
|
||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||
|
||||
if (!strcasecmp(var, "host")) {
|
||||
bind_mask = (char *) switch_xml_attr_soft(param, "bindings");
|
||||
if (val) {
|
||||
host = val;
|
||||
}
|
||||
} else if (!strcasecmp(var, "port")) {
|
||||
port = val;
|
||||
} else if (!strcasecmp(var, "timeout")) {
|
||||
int tmp = atoi(val);
|
||||
if (tmp >= 0) {
|
||||
timeout = tmp;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set a negative timeout!\n");
|
||||
}
|
||||
} else if (!strcasecmp(var, "enable-post-var")) {
|
||||
if (!vars_map && need_vars_map == 0) {
|
||||
if (switch_core_hash_init(&vars_map, globals.pool) != SWITCH_STATUS_SUCCESS) {
|
||||
need_vars_map = -1;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't init params hash!\n");
|
||||
continue;
|
||||
}
|
||||
need_vars_map = 1;
|
||||
}
|
||||
|
||||
if (vars_map && val) {
|
||||
if (switch_core_hash_insert(vars_map, val, ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't add %s to params hash!\n", val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!host) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no host!\n");
|
||||
if (vars_map) {
|
||||
switch_core_hash_destroy(&vars_map);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(binding = switch_core_alloc(globals.pool, sizeof(*binding)))) {
|
||||
if (vars_map) {
|
||||
switch_core_hash_destroy(&vars_map);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
memset(binding, 0, sizeof(*binding));
|
||||
|
||||
binding->timeout = timeout;
|
||||
binding->host = switch_core_strdup(globals.pool, host);
|
||||
binding->port = atoi(port);
|
||||
binding->vars_map = vars_map;
|
||||
binding->url = switch_mprintf("scgi://%s:%s", host, port);
|
||||
|
||||
if (bind_mask) {
|
||||
binding->bindings = switch_core_strdup(globals.pool, bind_mask);
|
||||
}
|
||||
|
||||
if (vars_map) {
|
||||
switch_zmalloc(hash_node, sizeof(hash_node_t));
|
||||
hash_node->hash = vars_map;
|
||||
hash_node->next = NULL;
|
||||
|
||||
if (!globals.hash_root) {
|
||||
globals.hash_root = hash_node;
|
||||
globals.hash_tail = globals.hash_root;
|
||||
}
|
||||
|
||||
else {
|
||||
globals.hash_tail->next = hash_node;
|
||||
globals.hash_tail = globals.hash_tail->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
|
||||
zstr(bname) ? "N/A" : bname, binding->url, binding->bindings ? binding->bindings : "all");
|
||||
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);
|
||||
x++;
|
||||
binding = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
switch_xml_free(xml);
|
||||
|
||||
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_xml_scgi_load)
|
||||
{
|
||||
switch_api_interface_t *xml_scgi_api_interface;
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
globals.pool = pool;
|
||||
globals.hash_root = NULL;
|
||||
globals.hash_tail = NULL;
|
||||
|
||||
if (do_config() != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_ADD_API(xml_scgi_api_interface, "xml_scgi", "XML SCGI", xml_scgi_function, XML_SCGI_SYNTAX);
|
||||
switch_console_set_complete("add xml_scgi debug_on");
|
||||
switch_console_set_complete("add xml_scgi debug_off");
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_scgi_shutdown)
|
||||
{
|
||||
hash_node_t *ptr = NULL;
|
||||
|
||||
while (globals.hash_root) {
|
||||
ptr = globals.hash_root;
|
||||
switch_core_hash_destroy(&ptr->hash);
|
||||
globals.hash_root = ptr->next;
|
||||
switch_safe_free(ptr);
|
||||
}
|
||||
|
||||
switch_xml_unbind_search_function_ptr(xml_url_fetch);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
93
src/mod/xml_int/mod_xml_scgi/xml_scgi_server.pl
Normal file
93
src/mod/xml_int/mod_xml_scgi/xml_scgi_server.pl
Normal file
@ -0,0 +1,93 @@
|
||||
#
|
||||
# Copyright (c) 2012-2013, Anthony Minessale II
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the original author; nor the names of any contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
### EXAMPLE SERVER SIDE FOR mod_xml_SCGI
|
||||
### You will need the SCGI module from CPAN
|
||||
|
||||
use SCGI;
|
||||
use CGI;
|
||||
use IO::Socket;
|
||||
use Data::Dumper;
|
||||
|
||||
my $socket = IO::Socket::INET->new(Listen => 5, ReuseAddr => 1, LocalPort => 8080)
|
||||
or die "cannot bind to port 8080: $!";
|
||||
|
||||
my $scgi = SCGI->new($socket, blocking => 1);
|
||||
|
||||
|
||||
my $xml = qq#
|
||||
<document type="freeswitch/xml">
|
||||
<section name="dialplan">
|
||||
<context name="default">
|
||||
<extension name="foo">
|
||||
<condition>
|
||||
<action application="answer"/>
|
||||
<action application="playback" data="/ram/swimp.raw"/>
|
||||
</condition>
|
||||
</extension>
|
||||
</context>
|
||||
|
||||
</section>
|
||||
</document>
|
||||
#;
|
||||
|
||||
|
||||
while (my $request = $scgi->accept) {
|
||||
|
||||
# fork every new req into its own process (optional)
|
||||
next unless(fork());
|
||||
my $handle = $request->connection;
|
||||
|
||||
$request->read_env;
|
||||
|
||||
# get the body that contains the PARAMS
|
||||
read $handle, $body, $request->env->{CONTENT_LENGTH};
|
||||
|
||||
# Dump SCGI HEADERS
|
||||
print Dumper $request->env;
|
||||
|
||||
# Create a CGI parser on the PARAMS
|
||||
my $cgi = CGI->new($body);
|
||||
my %params = $cgi->Vars();
|
||||
# might be big output
|
||||
print Dumper \%params;
|
||||
|
||||
|
||||
### DO something CGI-like here with %params ... I'm just going to return static xml
|
||||
|
||||
# header is not necessary but optional
|
||||
#print $handle "Content-Type: text/xml\n\n";
|
||||
|
||||
print $handle $xml;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user