From bd66d7eaa624f193d7caa8abdd1ca73ffd424df7 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Mon, 23 Jul 2012 21:15:53 +0800 Subject: [PATCH] show bindings and handlers --- .../mod_erlang_event/mod_erlang_event.c | 78 ++++++++++++++++++- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index bf20478cf0..c462cf30e1 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1612,7 +1612,12 @@ SWITCH_STANDARD_API(erlang_cmd) const char *usage_string = "USAGE:\n" "--------------------------------------------------------------------------------\n" - "erlang listeners\n" "erlang sessions \n" "--------------------------------------------------------------------------------\n"; + "erlang listeners\n" + "erlang sessions \n" + "erlang bindings\n" + "erlang handlers\n" + "erlang debug \n" + "--------------------------------------------------------------------------------\n"; if (zstr(cmd)) { stream->write_function(stream, "%s", usage_string); @@ -1679,6 +1684,73 @@ SWITCH_STANDARD_API(erlang_cmd) if (!found) stream->write_function(stream, "Could not find a listener for %s\n", argv[1]); + } else if (!strcasecmp(argv[0], "handlers")) { + listener_t *l; + + switch_thread_rwlock_rdlock(globals.listener_rwlock); + + if (listen_list.listeners) { + for (l = listen_list.listeners; l; l = l->next) { + int x; + switch_hash_index_t *iter; + const void *key; + void *val; + + stream->write_function(stream, "Listener %s:\n--------------------------------\n", l->peer_nodename); + + for (x = SWITCH_EVENT_CUSTOM + 1; x < SWITCH_EVENT_ALL; x++) { + if (l->event_list[x] == 1) { + stream->write_function(stream, "%s\n", switch_event_name(x)); + } + } + stream->write_function(stream, "CUSTOM:\n", switch_event_name(x)); + + for (iter = switch_hash_first(NULL, l->event_hash); iter; iter = switch_hash_next(iter)) { + switch_hash_this(iter, &key, NULL, &val); + stream->write_function(stream, "\t%s\n", (char *)key); + } + stream->write_function(stream, "\n", (char *)key); + } + } else { + stream->write_function(stream, "No active handlers\n"); + } + + switch_thread_rwlock_unlock(globals.listener_rwlock); + + } else if (!strcasecmp(argv[0], "bindings")) { + int found = 0; + struct erlang_binding *ptr; + switch_thread_rwlock_wrlock(globals.bindings_rwlock); + switch_xml_set_binding_sections(bindings.search_binding, SWITCH_XML_SECTION_MAX); + + for (ptr = bindings.head; ptr; ptr = ptr->next) { + + if (ptr->process.type == ERLANG_PID) { + stream->write_function(stream, "%s ", ptr->process.pid.node); + } + + if (ptr->section == SWITCH_XML_SECTION_CONFIG) { + stream->write_function(stream, "config\n"); + }else if (ptr->section == SWITCH_XML_SECTION_DIRECTORY) { + stream->write_function(stream, "directory\n"); + } else if (ptr->section == SWITCH_XML_SECTION_DIALPLAN) { + stream->write_function(stream, "dialplan\n"); + } else if (ptr->section == SWITCH_XML_SECTION_PHRASES) { + stream->write_function(stream, "phrases\n"); + } else if (ptr->section == SWITCH_XML_SECTION_CHATPLAN) { + stream->write_function(stream, "chatplan\n"); + } else { + stream->write_function(stream, "unknown %d\n", ptr->section); + } + found++; + } + + switch_thread_rwlock_unlock(globals.bindings_rwlock); + + if (!found) { + stream->write_function(stream, "No bindings\n"); + } + } else if (!strcasecmp(argv[0], "debug")) { if (argc == 2) { if (!strcasecmp(argv[1], "on")) { @@ -1690,9 +1762,7 @@ SWITCH_STANDARD_API(erlang_cmd) stream->write_function(stream, "+OK debug %s\n", globals.debug ? "on" : "off"); } else { - stream->write_function(stream, "USAGE: erlang sessions \n" - " erlang listeners\n" - " erlang debug \n"); + stream->write_function(stream, usage_string); goto done; }