add files to go with previous commit
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@617 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
847b7160bd
commit
ebfc333dc6
|
@ -0,0 +1,3 @@
|
|||
[settings]
|
||||
address => 225.0.0.37
|
||||
port => 12345
|
|
@ -0,0 +1,12 @@
|
|||
use IO::Socket::Multicast;
|
||||
my ($ip,$port) = @ARGV;
|
||||
|
||||
$ip and $port or die "Usage $0: <ip> <port>\n";
|
||||
|
||||
# create a new UDP socket and add a multicast group
|
||||
my $socket = IO::Socket::Multicast->new( LocalPort => $port, ReuseAddr => 1 );
|
||||
$socket->mcast_add($ip);
|
||||
|
||||
while($socket->recv($data,1024)) {
|
||||
print $data;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/local/bin/perl
|
||||
use IO::Socket::INET;
|
||||
|
||||
my ($ip, $port, $file) = @ARGV;
|
||||
|
||||
$ip and $port or die "Usage $0: <ip> <port>\n";
|
||||
|
||||
$socket = new IO::Socket::INET->new( PeerPort => $port,
|
||||
Proto => 'udp',
|
||||
PeerAddr => $ip);
|
||||
|
||||
my $buf = `cat $file`;
|
||||
|
||||
$socket->send("$buf\n");
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
/*
|
||||
* 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_event_multicast.c -- Multicast Events
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
|
||||
static const char modname[] = "mod_event_multicast";
|
||||
|
||||
static switch_memory_pool *module_pool;
|
||||
|
||||
static struct {
|
||||
char *address;
|
||||
int port;
|
||||
switch_sockaddr_t *addr;
|
||||
switch_socket_t *udp_socket;
|
||||
int running;
|
||||
} globals;
|
||||
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address)
|
||||
|
||||
#define MULTICAST_EVENT "multicast::event"
|
||||
|
||||
|
||||
static switch_status load_config(void)
|
||||
{
|
||||
switch_config cfg;
|
||||
switch_status status = SWITCH_STATUS_SUCCESS;
|
||||
char *var, *val;
|
||||
char *cf = "event_multicast.conf";
|
||||
|
||||
if (!switch_config_open_file(&cfg, cf)) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_event_reserve_subclass(MULTICAST_EVENT) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't register subclass!");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
while (switch_config_next_pair(&cfg, &var, &val)) {
|
||||
if (!strcasecmp(cfg.category, "settings")) {
|
||||
if (!strcasecmp(var, "address")) {
|
||||
set_global_address(val);
|
||||
} else if (!strcasecmp(var, "port")) {
|
||||
globals.port = atoi(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch_config_close_file(&cfg);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
static void event_handler(switch_event *event)
|
||||
{
|
||||
char buf[1024];
|
||||
int len;
|
||||
|
||||
if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
|
||||
/* ignore our own events to avoid ping pong*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (event->event_id) {
|
||||
case SWITCH_EVENT_LOG:
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
switch_event_serialize(event, buf, sizeof(buf), NULL);
|
||||
len = strlen(buf);
|
||||
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf);
|
||||
switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static switch_loadable_module_interface event_test_module_interface = {
|
||||
/*.module_name */ modname,
|
||||
/*.endpoint_interface */ NULL,
|
||||
/*.timer_interface */ NULL,
|
||||
/*.dialplan_interface */ NULL,
|
||||
/*.codec_interface */ NULL,
|
||||
/*.application_interface */ NULL
|
||||
};
|
||||
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
|
||||
{
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
|
||||
if (load_config() != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Configure\n");
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_sockaddr_info_get(&globals.addr, globals.address, SWITCH_UNSPEC, globals.port, 0, module_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot find address\n");
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_socket_create(&globals.udp_socket, AF_INET, SOCK_DGRAM, 0, module_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Socket Error\n");
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_socket_opt_set(globals.udp_socket, SWITCH_SO_REUSEADDR, 1) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Socket Option Error\n");
|
||||
switch_socket_close(globals.udp_socket);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_mcast_join(globals.udp_socket, globals.addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Multicast Error\n");
|
||||
switch_socket_close(globals.udp_socket);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bind Error\n");
|
||||
switch_socket_close(globals.udp_socket);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*interface = &event_test_module_interface;
|
||||
|
||||
if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n");
|
||||
switch_socket_close(globals.udp_socket);
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
switch_socket_shutdown(globals.udp_socket, APR_SHUTDOWN_READWRITE);
|
||||
globals.running = -1;
|
||||
while(x < 100000 && globals.running) {
|
||||
x++;
|
||||
switch_yield(1000);
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
|
||||
{
|
||||
switch_event *local_event;
|
||||
switch_status status;
|
||||
char buf[1024];
|
||||
|
||||
globals.running = 1;
|
||||
while(globals.running == 1) {
|
||||
switch_sockaddr_t addr = {0};
|
||||
int len = sizeof(buf);
|
||||
memset(buf, 0, len);
|
||||
if ((status = switch_socket_recvfrom(&addr, globals.udp_socket, 0, buf, &len)) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
|
||||
char *var, *val, *term = NULL;
|
||||
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
|
||||
var = buf;
|
||||
while(*var) {
|
||||
if ((val = strchr(var, ':'))) {
|
||||
char varname[512];
|
||||
*val++ = '\0';
|
||||
while(*val == ' ') {
|
||||
val++;
|
||||
}
|
||||
if ((term = strchr(val, '\r')) || (term=strchr(val, '\n'))) {
|
||||
*term = '\0';
|
||||
while(*term == '\r' || *term == '\n') {
|
||||
term++;
|
||||
}
|
||||
}
|
||||
snprintf(varname, sizeof(varname), "Remote-%s", var);
|
||||
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, varname, val);
|
||||
var = term + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch_event_fire(&local_event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
globals.running = 0;
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="mod_event_multicast"
|
||||
ProjectGUID="{3A2A7795-C216-4FFF-B8EF-4D17A84BACCC}"
|
||||
RootNamespace="mod_event_multicast"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
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=""$(InputDir)..\..\..\include";"$(InputDir)include";"$(InputDir)..\..\..\..\libs\include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_event_multicast.dll"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="$(InputDir)..\..\..\libs\apr\Debug"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(OutDir)/mod_event_multicast.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/mod_event_multicast.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="Release"
|
||||
IntermediateDirectory="Release"
|
||||
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=""$(InputDir)..\..\..\include";"$(InputDir)include";"$(InputDir)..\..\..\..\libs\include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="..\..\..\..\w32\vsnet\$(OutDir)/mod/mod_event_multicast.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(InputDir)..\..\..\libs\apr\Release""
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/mod_event_multicast.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_event_multicast.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>
|
Loading…
Reference in New Issue