event socket / ESL improvements

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12228 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2009-02-21 23:19:58 +00:00
1 parent c7d6662d08
commit 99026e02e7
18 files changed
+156 -57

No files matched your search

@@ -1900,7 +1900,7 @@ static void conference_loop_output(conference_member_t *member)
switch_mutex_lock(member->control_mutex);
if (switch_core_session_dequeue_event(member->session, &event) == SWITCH_STATUS_SUCCESS) {
if (switch_core_session_dequeue_event(member->session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
if (event->event_id == SWITCH_EVENT_MESSAGE) {
char *from = switch_event_get_header(event, "from");
char *to = switch_event_get_header(event, "to");
@@ -218,7 +218,7 @@ static void event_handler(switch_event_t *event)
if (!listen_list.ready) {
return;
}
lp = listen_list.listeners;
switch_mutex_lock(globals.listener_mutex);
@@ -328,7 +328,6 @@ static void event_handler(switch_event_t *event)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
}
}
}
switch_mutex_unlock(globals.listener_mutex);
}
@@ -988,8 +987,9 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
while (listener->sock && !prefs.done) {
uint8_t do_sleep = 1;
mlen = 1;
status = switch_socket_recv(listener->sock, ptr, &mlen);
status = switch_socket_recv(listener->sock, ptr, &mlen);
if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
return SWITCH_STATUS_FALSE;
}
@@ -1129,12 +1129,26 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
}
}
if (listener->session) {
switch_channel_t *channel = switch_core_session_get_channel(listener->session);
if (switch_channel_get_state(channel) < CS_HANGUP && switch_channel_test_flag(channel, CF_DIVERT_EVENTS)) {
switch_event_t *e = NULL;
while (switch_core_session_dequeue_event(listener->session, &e, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
if (switch_queue_trypush(listener->event_queue, e) != SWITCH_STATUS_SUCCESS) {
switch_core_session_queue_event(listener->session, &e);
break;
}
}
}
}
if (switch_test_flag(listener, LFLAG_EVENTS)) {
while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
char hbuf[512];
switch_event_t *pevent = (switch_event_t *) pop;
char *etype;
do_sleep = 0;
if (listener->format == EVENT_FORMAT_PLAIN) {
etype = "plain";
@@ -1473,6 +1487,47 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even
}
if (!strncasecmp(cmd, "divert_events", 13)) {
char *onoff = cmd + 13;
switch_channel_t *channel;
if (!listener->session) {
switch_snprintf(reply, reply_len, "-ERR not controlling a session.");
goto done;
}
channel = switch_core_session_get_channel(listener->session);
if (onoff) {
while(*onoff == ' ') {
onoff++;
}
if (*onoff == '\r' || *onoff == '\n') {
onoff = NULL;
} else {
strip_cr(onoff);
}
}
if (switch_strlen_zero(onoff)) {
switch_snprintf(reply, reply_len, "-ERR missing value.");
goto done;
}
if (!strcasecmp(onoff, "on")) {
switch_snprintf(reply, reply_len, "+OK events diverted");
switch_channel_set_flag(channel, CF_DIVERT_EVENTS);
} else {
switch_snprintf(reply, reply_len, "+OK events not diverted");
switch_channel_clear_flag(channel, CF_DIVERT_EVENTS);
}
goto done;
}
if (!strncasecmp(cmd, "sendmsg", 7)) {
switch_core_session_t *session;
char *uuid = cmd + 7;