inbound connection to event_socket can now take over an existing channel with 'myevents <uuid>' to take on the behaviour of an outbound socket

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10110 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-10-22 16:32:55 +00:00
parent 3906afe4d1
commit 22210f41ce
1 changed files with 32 additions and 5 deletions

View File

@ -743,8 +743,12 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even
} }
if (listener->session) { if (listener->session || !strncasecmp(cmd, "myevents ", 9)) {
switch_channel_t *channel = switch_core_session_get_channel(listener->session); switch_channel_t *channel = NULL;
if (listener->session) {
channel = switch_core_session_get_channel(listener->session);
}
if (!strncasecmp(cmd, "connect", 7)) { if (!strncasecmp(cmd, "connect", 7)) {
switch_snprintf(reply, reply_len, "+OK"); switch_snprintf(reply, reply_len, "+OK");
@ -777,6 +781,29 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even
switch_snprintf(reply, reply_len, "%s", val); switch_snprintf(reply, reply_len, "%s", val);
goto done; goto done;
} else if (!strncasecmp(cmd, "myevents", 8)) { } else if (!strncasecmp(cmd, "myevents", 8)) {
if (switch_test_flag(listener, LFLAG_MYEVENTS)) {
switch_snprintf(reply, reply_len, "-ERR aready enabled.");
goto done;
}
if (!listener->session) {
char *uuid;
if ((uuid = cmd + 9)) {
strip_cr(uuid);
if (!(listener->session = switch_core_session_locate(uuid))) {
switch_snprintf(reply, reply_len, "-ERR invalid uuid");
goto done;
}
switch_set_flag_locked(listener, LFLAG_SESSION);
switch_set_flag_locked(listener, LFLAG_ASYNC);
}
}
listener->event_list[SWITCH_EVENT_CHANNEL_CREATE] = 1; listener->event_list[SWITCH_EVENT_CHANNEL_CREATE] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_DESTROY] = 1; listener->event_list[SWITCH_EVENT_CHANNEL_DESTROY] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_STATE] = 1; listener->event_list[SWITCH_EVENT_CHANNEL_STATE] = 1;
@ -1314,10 +1341,10 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n");
switch_core_hash_destroy(&listener->event_hash); switch_core_hash_destroy(&listener->event_hash);
if (session) { if (listener->session) {
switch_channel_clear_flag(switch_core_session_get_channel(session), CF_CONTROLLED); switch_channel_clear_flag(switch_core_session_get_channel(listener->session), CF_CONTROLLED);
switch_clear_flag_locked(listener, LFLAG_SESSION); switch_clear_flag_locked(listener, LFLAG_SESSION);
switch_core_session_rwunlock(session); switch_core_session_rwunlock(listener->session);
} else if (listener->pool) { } else if (listener->pool) {
switch_memory_pool_t *pool = listener->pool; switch_memory_pool_t *pool = listener->pool;
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);