From a2e2c8ae46945097a23b23ad5f7f03db793af42f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 14 Nov 2008 17:29:14 +0000 Subject: [PATCH] add filters to event_sink git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10402 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_event_socket/mod_event_socket.c | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 484489e506..e833ec29bc 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -532,7 +532,7 @@ static void xmlize_listener(listener_t *listener, switch_stream_handle_t *stream stream->write_function(stream, " \n"); } -SWITCH_STANDARD_API(event_manager_function) +SWITCH_STANDARD_API(event_sink_function) { char *http = NULL; char *wcmd = NULL; @@ -563,9 +563,51 @@ SWITCH_STANDARD_API(event_manager_function) format = "xml"; } - - - if (!strcasecmp(wcmd, "create-listener")) { + + if (!strcasecmp(wcmd, "filter")) { + char *action = switch_event_get_header(stream->param_event, "action");; + char *header_name = switch_event_get_header(stream->param_event, "header_name");; + char *header_val = switch_event_get_header(stream->param_event, "header_val");; + + if (switch_strlen_zero(action)) { + stream->write_function(stream, "Invalid Syntax\n"); + goto end; + } + + switch_mutex_lock(listener->filter_mutex); + if (!listener->filters) { + switch_event_create(&listener->filters, SWITCH_EVENT_CHANNEL_DATA); + } + + if (!strcasecmp(action, "delete")) { + if (switch_strlen_zero(header_val)) { + stream->write_function(stream, "Invalid Syntax\n"); + goto filter_end; + } + + if (!strcasecmp(header_val, "all")) { + switch_event_destroy(&listener->filters); + switch_event_create(&listener->filters, SWITCH_EVENT_CHANNEL_DATA); + } else { + switch_event_del_header(listener->filters, header_val); + } + stream->write_function(stream, "\n filter deleted.\n\n"); + } else if (!strcasecmp(action, "add")) { + if (switch_strlen_zero(header_name) || switch_strlen_zero(header_val)) { + stream->write_function(stream, "Invalid Syntax\n"); + goto filter_end; + } + switch_event_add_header_string(listener->filters, SWITCH_STACK_BOTTOM, header_name, header_val); + stream->write_function(stream, "\n filter added.\n\n"); + } else { + stream->write_function(stream, "Invalid Syntax\n"); + } + + filter_end: + + switch_mutex_unlock(listener->filter_mutex); + + } else if (!strcasecmp(wcmd, "create-listener")) { char *events = switch_event_get_header(stream->param_event, "events"); switch_memory_pool_t *pool; char *next, *cur; @@ -769,7 +811,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_socket_load) /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); SWITCH_ADD_APP(app_interface, "socket", "Connect to a socket", "Connect to a socket", socket_function, "[:]", SAF_SUPPORT_NOMEDIA); - SWITCH_ADD_API(api_interface, "event_manager", "event_manager", event_manager_function, ""); + SWITCH_ADD_API(api_interface, "event_sink", "event_sink", event_sink_function, ""); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS;