spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-03-29 22:31:56 +00:00
1 parent a021945cef
commit 3a54126261
143 files changed
+22413 -31567

No files matched your search

@@ -46,17 +46,13 @@ static struct {
switch_sockaddr_t *addr;
switch_socket_t *udp_socket;
switch_hash_t *event_hash;
uint8_t event_list[SWITCH_EVENT_ALL+1];
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)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
#define MULTICAST_EVENT "multicast::event"
static switch_status_t load_config(void)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -80,7 +76,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
return SWITCH_STATUS_GENERR;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -91,7 +87,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
} else if (!strcasecmp(var, "bindings")) {
set_global_bindings(val);
} else if (!strcasecmp(var, "port")) {
globals.port = (switch_port_t)atoi(val);
globals.port = (switch_port_t) atoi(val);
}
}
}
@@ -100,13 +96,13 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
if (globals.bindings) {
for(cur = globals.bindings; cur; count++) {
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) {
@@ -143,14 +139,14 @@ static void event_handler(switch_event_t *event)
if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
/* ignore our own events to avoid ping pong*/
/* ignore our own events to avoid ping pong */
return;
}
if (globals.event_list[(uint8_t)SWITCH_EVENT_ALL]) {
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 ||
} 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;
}
@@ -158,7 +154,7 @@ static void event_handler(switch_event_t *event)
if (send) {
char *packet;
switch (event->event_id) {
case SWITCH_EVENT_LOG:
return;
@@ -188,7 +184,8 @@ static switch_loadable_module_interface_t event_test_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
memset(&globals, 0, sizeof(globals));
@@ -199,13 +196,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
}
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) {
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;
}
@@ -214,7 +212,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error\n");
return SWITCH_STATUS_TERM;
}
if (switch_socket_opt_set(globals.udp_socket, SWITCH_SO_REUSEADDR, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Option Error\n");
switch_socket_close(globals.udp_socket);
@@ -224,7 +222,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
if (switch_mcast_join(globals.udp_socket, globals.addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Multicast Error\n");
switch_socket_close(globals.udp_socket);
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) {
@@ -238,7 +236,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
/* 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");
@@ -258,7 +256,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE);
globals.running = -1;
while(x < 100000 && globals.running) {
while (x < 100000 && globals.running) {
x++;
switch_yield(1000);
}
@@ -269,16 +267,16 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
switch_event_t *local_event;
char buf[65536] = {0};
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) {
while (globals.running == 1) {
char *myaddr;
size_t len = sizeof(buf);
memset(buf, 0, len);
switch_sockaddr_ip_get(&myaddr, globals.addr);
if (switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) {
@@ -287,25 +285,25 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
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) {
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) ==
SWITCH_STATUS_SUCCESS) {
char *var, *val, *term = NULL, tmpname[128];
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
var = packet;
while(*var) {
while (*var) {
if ((val = strchr(var, ':')) != 0) {
*val++ = '\0';
while(*val == ' ') {
while (*val == ' ') {
val++;
}
if ((term = strchr(val, '\r')) != 0 || (term=strchr(val, '\n')) != 0) {
if ((term = strchr(val, '\r')) != 0 || (term = strchr(val, '\n')) != 0) {
*term = '\0';
while(*term == '\r' || *term == '\n') {
while (*term == '\r' || *term == '\n') {
term++;
}
}
@@ -315,18 +313,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
} else {
break;
}
}
}
if (var && strlen(var) > 1) {
switch_event_add_body(local_event, var);
}
switch_event_fire(&local_event);
}
}
}
globals.running = 0;
return SWITCH_STATUS_TERM;
}