forked from Mirrors/freeswitch
cleanup, reduce large stack allocation, bounds checking, etc.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6827 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
baa3d3884b
commit
85f28ac6ab
@ -30,6 +30,9 @@
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
|
||||
#define MULTICAST_BUFFSIZE 65536
|
||||
|
||||
static char *MARKER = "1";
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load);
|
||||
@ -116,7 +119,9 @@ static switch_status_t load_config(void)
|
||||
globals.event_list[x] = 0;
|
||||
}
|
||||
}
|
||||
globals.event_list[type] = 1;
|
||||
if (type <= SWITCH_EVENT_ALL) {
|
||||
globals.event_list[type] = 1;
|
||||
}
|
||||
if (type == SWITCH_EVENT_CUSTOM) {
|
||||
custom++;
|
||||
}
|
||||
@ -136,10 +141,12 @@ static switch_status_t load_config(void)
|
||||
|
||||
static void event_handler(switch_event_t *event)
|
||||
{
|
||||
char buf[65536];
|
||||
char *buf;
|
||||
size_t len;
|
||||
uint8_t send = 0;
|
||||
|
||||
buf = (char *) malloc(MULTICAST_BUFFSIZE);
|
||||
switch_assert(buf);
|
||||
|
||||
if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
|
||||
/* ignore our own events to avoid ping pong */
|
||||
@ -251,9 +258,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown)
|
||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
|
||||
{
|
||||
switch_event_t *local_event;
|
||||
char buf[65536] = { 0 };
|
||||
char *buf;
|
||||
switch_sockaddr_t *addr;
|
||||
|
||||
buf = (char *) malloc(MULTICAST_BUFFSIZE);
|
||||
switch_assert(buf);
|
||||
switch_sockaddr_info_get(&addr, NULL, SWITCH_UNSPEC, 0, 0, module_pool);
|
||||
globals.running = 1;
|
||||
while (globals.running == 1) {
|
||||
|
@ -122,7 +122,7 @@ static void event_handler(switch_event_t *event)
|
||||
switch_event_t *clone = NULL;
|
||||
listener_t *l;
|
||||
|
||||
assert(event != NULL);
|
||||
switch_assert(event != NULL);
|
||||
|
||||
if (!listen_list.ready) {
|
||||
return;
|
||||
@ -465,18 +465,18 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
|
||||
if (switch_test_flag(listener, LFLAG_EVENTS)) {
|
||||
if (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||
char hbuf[512];
|
||||
switch_event_t *event = (switch_event_t *) pop;
|
||||
switch_event_t *pevent = (switch_event_t *) pop;
|
||||
char *etype;
|
||||
|
||||
do_sleep = 0;
|
||||
if (listener->format == EVENT_FORMAT_PLAIN) {
|
||||
etype = "plain";
|
||||
switch_event_serialize(event, &listener->ebuf, SWITCH_TRUE);
|
||||
switch_event_serialize(pevent, &listener->ebuf, SWITCH_TRUE);
|
||||
} else {
|
||||
switch_xml_t xml;
|
||||
etype = "xml";
|
||||
|
||||
if ((xml = switch_event_xmlize(event, "%s", ""))) {
|
||||
if ((xml = switch_event_xmlize(pevent, "%s", ""))) {
|
||||
listener->ebuf = switch_xml_toxml(xml, SWITCH_FALSE);
|
||||
switch_xml_free(xml);
|
||||
} else {
|
||||
@ -618,7 +618,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
|
||||
|
||||
if (listener->session) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(listener->session);
|
||||
assert(channel != NULL);
|
||||
switch_assert(channel != NULL);
|
||||
|
||||
if (!strncasecmp(cmd, "connect", 7)) {
|
||||
switch_snprintf(reply, reply_len, "+OK");
|
||||
@ -785,7 +785,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
|
||||
|
||||
switch_core_new_memory_pool(&pool);
|
||||
acs = switch_core_alloc(pool, sizeof(*acs));
|
||||
assert(acs);
|
||||
switch_assert(acs);
|
||||
acs->pool = pool;
|
||||
acs->listener = listener;
|
||||
if (api_cmd) {
|
||||
@ -882,7 +882,9 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
|
||||
listener->event_list[x] = 1;
|
||||
}
|
||||
}
|
||||
listener->event_list[type] = 1;
|
||||
if (type <= SWITCH_EVENT_ALL) {
|
||||
listener->event_list[type] = 1;
|
||||
}
|
||||
if (type == SWITCH_EVENT_CUSTOM) {
|
||||
custom++;
|
||||
}
|
||||
@ -1004,7 +1006,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
|
||||
prefs.threads++;
|
||||
switch_mutex_unlock(listen_list.mutex);
|
||||
|
||||
assert(listener != NULL);
|
||||
switch_assert(listener != NULL);
|
||||
|
||||
if ((session = listener->session)) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
@ -1018,14 +1020,14 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
|
||||
add_listener(listener);
|
||||
|
||||
if (session && switch_test_flag(listener, LFLAG_AUTHED)) {
|
||||
switch_event_t *event = NULL, *call_event;
|
||||
switch_event_t *ievent = NULL, *call_event;
|
||||
char *event_str;
|
||||
|
||||
|
||||
switch_set_flag_locked(listener, LFLAG_SESSION);
|
||||
status = read_packet(listener, &event, 25);
|
||||
status = read_packet(listener, &ievent, 25);
|
||||
|
||||
if (status != SWITCH_STATUS_SUCCESS || !event) {
|
||||
if (status != SWITCH_STATUS_SUCCESS || !ievent) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Socket Error!\n");
|
||||
switch_clear_flag_locked(listener, LFLAG_RUNNING);
|
||||
goto done;
|
||||
@ -1037,7 +1039,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
|
||||
if (parse_command(listener, ievent, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_clear_flag_locked(listener, LFLAG_RUNNING);
|
||||
goto done;
|
||||
}
|
||||
@ -1088,21 +1090,21 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
|
||||
}
|
||||
|
||||
while (switch_test_flag(listener, LFLAG_RUNNING) && listen_list.ready) {
|
||||
switch_event_t *event;
|
||||
switch_event_t *revent;
|
||||
|
||||
len = sizeof(buf);
|
||||
memset(buf, 0, len);
|
||||
status = read_packet(listener, &event, 0);
|
||||
status = read_packet(listener, &revent, 0);
|
||||
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!event) {
|
||||
if (!revent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parse_command(listener, event, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
|
||||
if (parse_command(listener, revent, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_clear_flag_locked(listener, LFLAG_RUNNING);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user