[Freeswitch-branches] [commit] r2854 - in freeswitch/branches/mishehu: conf libs/win32/pcre libs/win32/sqlite src/mod/endpoints/mod_sofia src/mod/event_handlers/mod_cdr src/mod/event_handlers/mod_event_multicast src/mod/event_handlers/mod_event_socket
Freeswitch SVN
mishehu at freeswitch.org
Wed Sep 27 23:53:25 EDT 2006
Author: mishehu
Date: Wed Sep 27 23:53:21 2006
New Revision: 2854
Modified:
freeswitch/branches/mishehu/conf/freeswitch.xml
freeswitch/branches/mishehu/libs/win32/pcre/libpcre.vcproj
freeswitch/branches/mishehu/libs/win32/sqlite/sqlite.vcproj
freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/Makefile
freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
Log:
Fixed a few of the typos from the previous commit in basecdr.cpp. Merged to trunk r2853.
Modified: freeswitch/branches/mishehu/conf/freeswitch.xml
==============================================================================
--- freeswitch/branches/mishehu/conf/freeswitch.xml (original)
+++ freeswitch/branches/mishehu/conf/freeswitch.xml Wed Sep 27 23:53:21 2006
@@ -74,6 +74,14 @@
</modules>
</configuration>
+ <configuration name="event_multicast.conf" description="Multicast Event">
+ <settings>
+ <param name="address" value="225.1.1.1"/>
+ <param name="port" value="424242"/>
+ <param name="bindings" value="all"/>
+ </settings>
+ </configuration>
+
<configuration name="event_socket.conf" description="Socket Client">
<settings>
<param name="listen-ip" value="127.0.0.1"/>
Modified: freeswitch/branches/mishehu/libs/win32/pcre/libpcre.vcproj
==============================================================================
--- freeswitch/branches/mishehu/libs/win32/pcre/libpcre.vcproj (original)
+++ freeswitch/branches/mishehu/libs/win32/pcre/libpcre.vcproj Wed Sep 27 23:53:21 2006
@@ -97,7 +97,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)pcre.h" $(ProjectDir)..\..\include\ /C /D /Y
"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)pcre.h" "$(ProjectDir)..\..\include\" /C /D /Y
"
/>
</Configuration>
<Configuration
@@ -183,7 +183,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)pcre.h" $(ProjectDir)..\..\include\ /C /D /Y
"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)pcre.h" "$(ProjectDir)..\..\include\" /C /D /Y
"
/>
</Configuration>
<Configuration
@@ -285,7 +285,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)pcre.h" $(ProjectDir)..\..\include\ /C /D /Y
"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)pcre.h" "$(ProjectDir)..\..\include\" /C /D /Y
"
/>
</Configuration>
<Configuration
@@ -386,7 +386,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)pcre.h" $(ProjectDir)..\..\include\ /C /D /Y
"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)pcre.h" "$(ProjectDir)..\..\include\" /C /D /Y
"
/>
</Configuration>
</Configurations>
Modified: freeswitch/branches/mishehu/libs/win32/sqlite/sqlite.vcproj
==============================================================================
--- freeswitch/branches/mishehu/libs/win32/sqlite/sqlite.vcproj (original)
+++ freeswitch/branches/mishehu/libs/win32/sqlite/sqlite.vcproj Wed Sep 27 23:53:21 2006
@@ -77,7 +77,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" $(ProjectDir)..\..\include\ /C /D /Y

"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" "$(ProjectDir)..\..\include\" /C /D /Y

"
/>
</Configuration>
<Configuration
@@ -140,7 +140,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" $(ProjectDir)..\..\include\ /C /D /Y

"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" "$(ProjectDir)..\..\include\" /C /D /Y

"
/>
</Configuration>
<Configuration
@@ -221,7 +221,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" $(ProjectDir)..\..\include\ /C /D /Y

"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" "$(ProjectDir)..\..\include\" /C /D /Y

"
/>
</Configuration>
<Configuration
@@ -295,7 +295,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist $(ProjectDir)..\..\include\ md $(ProjectDir)..\..\include\
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" $(ProjectDir)..\..\include\ /C /D /Y

"
+ CommandLine="if not exist "$(ProjectDir)..\..\include\" md "$(ProjectDir)..\..\include\"
xcopy "$(ProjectDir)..\..\sqlite-source-3_3_6\*.h" "$(ProjectDir)..\..\include\" /C /D /Y

"
/>
</Configuration>
</Configurations>
Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/Makefile (original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/Makefile Wed Sep 27 23:53:21 2006
@@ -1,5 +1,5 @@
VERSION = sofia-sip-1.12
-TARBALL = sofia-sip-1.12.1.tar.gz
+TARBALL = sofia-sip-1.12.2.tar.gz
CFLAGS += -I. -I$(PREFIX)/include/$(VERSION)
LDFLAGS += -lsofia-sip-ua
LINKER=$(CC)
Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/branches/mishehu/src/mod/endpoints/mod_sofia/mod_sofia.c Wed Sep 27 23:53:21 2006
@@ -49,6 +49,9 @@
#define MY_EVENT_REGISTER "sofia::register"
#define MY_EVENT_EXPIRE "sofia::expire"
+#define MULTICAST_EVENT "multicast::event"
+
+
#include <sofia-sip/nua.h>
#include <sofia-sip/sip_status.h>
#include <sofia-sip/sdp.h>
@@ -142,7 +145,6 @@
switch_payload_t te;
uint32_t codec_flags;
switch_mutex_t *reg_mutex;
- switch_core_db_t *db;
};
@@ -296,10 +298,11 @@
if (argc >=3 ) {
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_EXPIRE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[0]);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "host", "%s", argv[1]);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", argv[2]);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%d", argv[3]);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", argv[0]);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[1]);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "host", "%s", argv[2]);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", argv[3]);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%d", argv[4]);
switch_event_fire(&s_event);
}
}
@@ -310,10 +313,16 @@
{
char sql[1024];
char *errmsg;
+ switch_core_db_t *db;
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ return;
+ }
+
switch_mutex_lock(profile->reg_mutex);
- snprintf(sql, sizeof(sql), "select * from sip_registrations where expires > 0 and expires < %ld", (long) now);
- switch_core_db_exec(profile->db, sql, del_callback, NULL, &errmsg);
+ snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires < %ld", profile->name, (long) now);
+ switch_core_db_exec(db, sql, del_callback, NULL, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", sql, errmsg);
@@ -322,15 +331,22 @@
}
snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires < %ld", (long) now);
- switch_core_db_persistant_execute(profile->db, sql, 1);
+ switch_core_db_persistant_execute(db, sql, 1);
switch_mutex_unlock(profile->reg_mutex);
+
+ switch_core_db_close(db);
}
static char *find_reg_url(sofia_profile_t *profile, char *user, char *host, char *val, switch_size_t len)
{
char *errmsg;
struct callback_t cbt = {0};
+ switch_core_db_t *db;
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ return NULL;
+ }
cbt.val = val;
cbt.len = len;
@@ -341,7 +357,7 @@
snprintf(val, len, "select contact from sip_registrations where user='%s'", user);
}
- switch_core_db_exec(profile->db, val, find_callback, &cbt, &errmsg);
+ switch_core_db_exec(db, val, find_callback, &cbt, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", val, errmsg);
@@ -350,6 +366,8 @@
}
switch_mutex_unlock(profile->reg_mutex);
+
+ switch_core_db_close(db);
return cbt.matches ? val : NULL;
}
@@ -1732,19 +1750,27 @@
}
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from_user", "%s", from_user);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from_host", "%s", from_host);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact_user", "%s", contact_user);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact_host", "%s", contact_host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", profile->name);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-user", "%s", from_user);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", from_host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact-user", "%s", contact_user);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact-host", "%s", contact_host);
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long)expires->ex_delta);
switch_event_fire(&s_event);
}
if (sql) {
+ switch_core_db_t *db;
+
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ return;
+ }
switch_mutex_lock(profile->reg_mutex);
- switch_core_db_persistant_execute(profile->db, sql, 25);
- switch_core_db_free(sql);
- sql = NULL;
- switch_mutex_unlock(profile->reg_mutex);
+ switch_core_db_persistant_execute(db, sql, 25);
+ switch_core_db_free(sql);
+ sql = NULL;
+ switch_mutex_unlock(profile->reg_mutex);
+ switch_core_db_close(db);
}
switch_xml_free(xml);
@@ -1915,8 +1941,8 @@
switch_memory_pool_t *pool;
sip_alias_node_t *node;
uint32_t loops = 0;
+ switch_core_db_t *db;
-
profile->s_root = su_root_create(NULL);
profile->nua = nua_create(profile->s_root, /* Event loop */
event_callback, /* Callback for processing events */
@@ -1951,12 +1977,13 @@
}
- if ((profile->db = switch_core_db_open_file(profile->dbname))) {
- switch_core_db_test_reactive(profile->db, "select * from sip_registrations", reg_sql);
+ if ((db = switch_core_db_open_file(profile->dbname))) {
+ switch_core_db_test_reactive(db, "select * from sip_registrations", reg_sql);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
return NULL;
}
+ switch_core_db_close(db);
switch_mutex_init(&profile->reg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
@@ -2159,6 +2186,66 @@
}
+static void event_handler(switch_event_t *event)
+{
+ char *subclass, *sql;
+
+ if ((subclass = switch_event_get_header(event, "orig-event-subclass")) && !strcmp(subclass, MY_EVENT_REGISTER)) {
+ char *from_user = switch_event_get_header(event, "orig-from-user");
+ char *from_host = switch_event_get_header(event, "orig-from-host");
+ char *contact_user = switch_event_get_header(event, "orig-contact-user");
+ char *contact_host = switch_event_get_header(event, "orig-contact-host");
+ char *exp_str = switch_event_get_header(event, "orig-expires");
+ long expires = time(NULL) + atol(exp_str);
+ char *profile_name = switch_event_get_header(event, "orig-profile-name");
+ sofia_profile_t *profile;
+ char buf[512];
+
+ if (!profile_name || !(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, profile_name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
+ return;
+ }
+
+
+ if (!find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
+ sql = switch_core_db_mprintf("insert into sip_registrations values ('%q','%q','sip:%q@%q',%ld)",
+ from_user,
+ from_host,
+ contact_user,
+ contact_host,
+ expires);
+ } else {
+ sql = switch_core_db_mprintf("update sip_registrations set contact='sip:%q@%q', expires=%ld where user='%q' and host='%q'",
+ contact_user,
+ contact_host,
+ expires,
+ from_user,
+ from_host);
+
+ }
+
+ if (sql) {
+ switch_core_db_t *db;
+
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ return;
+ }
+ switch_mutex_lock(profile->reg_mutex);
+ switch_core_db_persistant_execute(db, sql, 25);
+ switch_core_db_free(sql);
+ sql = NULL;
+ switch_mutex_unlock(profile->reg_mutex);
+ switch_core_db_close(db);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Propagating registration for %s@%s->%s@%s\n",
+ from_user, from_host, contact_user, contact_host);
+
+ }
+
+ }
+}
+
+
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
{
@@ -2170,6 +2257,12 @@
memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+
+ if (switch_event_bind((char *) modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+ return SWITCH_STATUS_TERM;
+ }
+
su_init();
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp Wed Sep 27 23:53:21 2006
@@ -95,7 +95,7 @@
// Get the ANI information if it's set
if(newchannel->callerprofile->ani != 0)
- strncpy(ani,newchannel->callerprofile->ani,sizeof(ani)));
+ strncpy(ani,newchannel->callerprofile->ani,sizeof(ani));
if(newchannel->callerprofile->ani2 != 0)
strncpy(ani2,newchannel->callerprofile->ani2,sizeof(ani2));
@@ -109,7 +109,7 @@
originated = newchannel->originate;
if(newchannel->originateprofile && newchannel->originateprofile->uuid != 0)
- strncpy(destuuid,newchannel->originateprofile->uuid,sizeof(uuid));
+ strncpy(destuuid,newchannel->originateprofile->uuid,sizeof(destuuid));
// We still need to check if this is originated or not
if(originated == 0)
@@ -117,27 +117,27 @@
if (newchannel->callerprofile)
{
if(newchannel->callerprofile->destination_number != 0)
- strncpy(src,newchannel->callerprofile->destination_number,sizeof(destination_number));
+ strncpy(src,newchannel->callerprofile->destination_number,sizeof(src));
if(newchannel->callerprofile->caller_id_number != 0)
- strncpy(dst,newchannel->callerprofile->caller_id_number,sizeof(caller_id_number));
+ strncpy(dst,newchannel->callerprofile->caller_id_number,sizeof(dst));
}
if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
- strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(chan_name));
+ strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(dstchannel));
}
else
{
if (newchannel->callerprofile) {
if(newchannel->callerprofile->caller_id_number != 0)
- strncpy(src,newchannel->callerprofile->caller_id_number,sizeof(caller_id_number));
+ strncpy(src,newchannel->callerprofile->caller_id_number,sizeof(src));
if(newchannel->callerprofile->destination_number != 0)
- strncpy(dst,newchannel->callerprofile->destination_number,sizeof(destination_number));
+ strncpy(dst,newchannel->callerprofile->destination_number,sizeof(dst));
}
if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
- strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(chan_name));
+ strncpy(dstchannel,newchannel->originateprofile->chan_name,sizeof(dstchannel));
}
- strncpy(myuuid,newchannel->callerprofile->uuid,sizeof(uuid));
- strncpy(srcchannel,newchannel->callerprofile->chan_name,sizeof(chan_name));
+ strncpy(myuuid,newchannel->callerprofile->uuid,sizeof(myuuid));
+ strncpy(srcchannel,newchannel->callerprofile->chan_name,sizeof(srcchannel));
if(switch_channel_test_flag(newchannel->channel,CF_ANSWERED))
{
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c Wed Sep 27 23:53:21 2006
@@ -30,6 +30,7 @@
*
*/
#include <switch.h>
+static char *MARKER = "1";
static const char modname[] = "mod_event_multicast";
@@ -37,23 +38,39 @@
static struct {
char *address;
+ char *bindings;
+ uint32_t key_count;
+ char hostname[80];
+ uint64_t host_hash;
switch_port_t port;
switch_sockaddr_t *addr;
switch_socket_t *udp_socket;
+ switch_hash_t *event_hash;
+ uint8_t event_list[SWITCH_EVENT_ALL+1];
int running;
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address)
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
+
#define MULTICAST_EVENT "multicast::event"
-static switch_status_t load_config(void)
+ static switch_status_t load_config(void)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *cf = "event_multicast.conf";
switch_xml_t cfg, xml, settings, param;
+ char *next, *cur;
+ uint32_t count = 0;
+ uint8_t custom = 0;
+ apr_ssize_t hlen = APR_HASH_KEY_STRING;
+ gethostname(globals.hostname, sizeof(globals.hostname));
+ globals.host_hash = apr_hashfunc_default(globals.hostname, &hlen);
+ globals.key_count = 0;
+
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;
@@ -71,6 +88,8 @@
if (!strcasecmp(var, "address")) {
set_global_address(val);
+ } else if (!strcasecmp(var, "bindings")) {
+ set_global_bindings(val);
} else if (!strcasecmp(var, "port")) {
globals.port = (switch_port_t)atoi(val);
}
@@ -79,30 +98,79 @@
switch_xml_free(xml);
+
+ if (globals.bindings) {
+ for(cur = globals.bindings; cur; count++) {
+ switch_event_types_t type;
+
+ if ((next = strchr(cur, ' '))) {
+ *next++ = '\0';
+ }
+
+ if (custom) {
+ switch_core_hash_insert_dup(globals.event_hash, cur, MARKER);
+ } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
+ globals.key_count++;
+ if (type == SWITCH_EVENT_ALL) {
+ uint32_t x = 0;
+ for (x = 0; x < SWITCH_EVENT_ALL; x++) {
+ globals.event_list[x] = 0;
+ }
+ }
+ globals.event_list[type] = 1;
+ if (type == SWITCH_EVENT_CUSTOM) {
+ custom++;
+ }
+ }
+
+ cur = next;
+ }
+ }
+
+ if (!globals.key_count) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "No Bindings\n");
+ }
+
return status;
}
static void event_handler(switch_event_t *event)
{
- char buf[1024];
+ char buf[65536];
size_t len;
+ uint8_t send = 0;
+
if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
/* ignore our own events to avoid ping pong*/
return;
}
+ if (globals.event_list[(uint8_t)SWITCH_EVENT_ALL]) {
+ send = 1;
+ } else if ((globals.event_list[(uint8_t)event->event_id])) {
+ if (event->event_id != SWITCH_EVENT_CUSTOM ||
+ (event->subclass && switch_core_hash_find(globals.event_hash, event->subclass->name))) {
+ send = 1;
+ }
+ }
- switch (event->event_id) {
- case SWITCH_EVENT_LOG:
- return;
- default:
- switch_event_serialize(event, buf, sizeof(buf), NULL);
- len = strlen(buf);
- //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf);
- switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
- break;
+ if (send) {
+ char *packet;
+ memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
+ packet = buf + sizeof(globals.host_hash);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", globals.hostname);
+ switch (event->event_id) {
+ case SWITCH_EVENT_LOG:
+ return;
+ default:
+ switch_event_serialize(event, packet, sizeof(buf) - sizeof(globals.host_hash), NULL);
+ len = strlen(packet) + sizeof(globals.host_hash);;
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf);
+ switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
+ break;
+ }
}
}
@@ -119,18 +187,21 @@
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
{
+
memset(&globals, 0, sizeof(globals));
-
- if (load_config() != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Configure\n");
- return SWITCH_STATUS_TERM;
- }
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
+ switch_core_hash_init(&globals.event_hash, module_pool);
+
+ if (load_config() != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Configure\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_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find address\n");
return SWITCH_STATUS_TERM;
@@ -160,9 +231,11 @@
}
+
/* connect my internal structure to the blank pointer passed to me */
*module_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_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
@@ -170,6 +243,7 @@
return SWITCH_STATUS_GENERR;
}
+
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
@@ -192,21 +266,36 @@
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
switch_event_t *local_event;
- char buf[1024];
-
+ char buf[65536] = {0};
+ switch_sockaddr_t *addr;
+
+ switch_sockaddr_info_get(&addr, NULL, SWITCH_UNSPEC, 0, 0, module_pool);
globals.running = 1;
while(globals.running == 1) {
- switch_sockaddr_t addr = {0};
+ char *myaddr;
size_t len = sizeof(buf);
memset(buf, 0, len);
- if (switch_socket_recvfrom(&addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) {
+
+ switch_sockaddr_ip_get(&myaddr, globals.addr);
+
+ if (switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) {
+ char *packet;
+ uint64_t host_hash = 0;
+
+ memcpy(&host_hash, buf, sizeof(host_hash));
+ packet = buf + sizeof(host_hash);
+
+ if (host_hash == globals.host_hash) {
+ continue;
+ }
+
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
- char *var, *val, *term = NULL;
+ char *var, *val, *term = NULL, tmpname[128];
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
- var = buf;
+ var = packet;
while(*var) {
if ((val = strchr(var, ':')) != 0) {
- char varname[512];
*val++ = '\0';
while(*val == ' ') {
val++;
@@ -217,18 +306,22 @@
term++;
}
}
- snprintf(varname, sizeof(varname), "Remote-%s", var);
- switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, varname, val);
+ snprintf(tmpname, sizeof(tmpname), "Orig-%s", var);
+ switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, tmpname, val);
var = term + 1;
} else {
break;
}
}
+ if (var && strlen(var) > 1) {
+ switch_event_add_body(local_event, var);
+ }
+
switch_event_fire(&local_event);
+
}
}
-
}
globals.running = 0;
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Wed Sep 27 23:53:21 2006
@@ -227,12 +227,12 @@
static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout)
{
- switch_size_t mlen;
+ switch_size_t mlen, bytes = 0;
char mbuf[2048] = "";
char buf[1024] = "";
switch_size_t len;
switch_status_t status = SWITCH_STATUS_SUCCESS;
- int count = 0, bytes = 0;
+ int count = 0;
uint32_t elapsed = 0;
time_t start = 0;
void *pop;
More information about the Freeswitch-branches
mailing list