summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2013-07-08 14:42:57 +0000
committerJason Parker <jparker@digium.com>2013-07-08 14:42:57 +0000
commit7422581b6d4921cebfcf177fc63b2ef852fdef58 (patch)
treefd0fbaa5ca5cdef688476d46a942a8260bf756e9 /main
parent30d379851e2d614d1b8bcc65fdb5952feb6d62de (diff)
Move channel driver Registry manager events to core.
This also shuffles the stasis system topic and related handling. (closes issue ASTERISK-21488) Review: https://reviewboard.asterisk.org/r/2631/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393804 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c42
-rw-r--r--main/file.c1
-rw-r--r--main/manager.c4
-rw-r--r--main/manager_system.c81
-rw-r--r--main/sounds_index.c1
-rw-r--r--main/stasis_system.c170
6 files changed, 259 insertions, 40 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index b8cf43e37..c7c67e795 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -243,6 +243,7 @@ int daemon(int, int); /* defined in libresolv of all places */
#include "asterisk/stasis.h"
#include "asterisk/json.h"
#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_system.h"
#include "asterisk/security_events.h"
#include "../defaults.h"
@@ -448,12 +449,6 @@ static struct {
unsigned int need_quit_handler:1;
} sig_flags;
-/*! \brief The \ref stasis topic for system level changes */
-static struct stasis_topic *system_topic;
-
-/*!\ brief The \ref stasis_message_type for network changes */
-STASIS_MESSAGE_TYPE_DEFN(ast_network_change_type);
-
#if !defined(LOW_MEMORY)
struct file_version {
AST_RWLIST_ENTRY(file_version) list;
@@ -461,9 +456,6 @@ struct file_version {
char *version;
};
-/*! \brief The \ref stasis topic for system level changes */
-static struct stasis_topic *system_topic;
-
static AST_RWLIST_HEAD_STATIC(file_versions, file_version);
void ast_register_file_version(const char *file, const char *version)
@@ -1098,36 +1090,6 @@ static char *handle_show_version_files(struct ast_cli_entry *e, int cmd, struct
#endif /* ! LOW_MEMORY */
-struct stasis_topic *ast_system_topic(void)
-{
- return system_topic;
-}
-
-/*! \brief Cleanup the \ref stasis system level items */
-static void stasis_system_topic_cleanup(void)
-{
- ao2_cleanup(system_topic);
- system_topic = NULL;
- STASIS_MESSAGE_TYPE_CLEANUP(ast_network_change_type);
-}
-
-/*! \brief Initialize the system level items for \ref stasis */
-static int stasis_system_topic_init(void)
-{
- ast_register_cleanup(stasis_system_topic_cleanup);
-
- system_topic = stasis_topic_create("ast_system");
- if (!system_topic) {
- return 1;
- }
-
- if (STASIS_MESSAGE_TYPE_INIT(ast_network_change_type) != 0) {
- return -1;
- }
-
- return 0;
-}
-
static void publish_fully_booted(void)
{
RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
@@ -4218,7 +4180,7 @@ int main(int argc, char *argv[])
exit(1);
}
- if (stasis_system_topic_init()) {
+ if (ast_stasis_system_init()) {
printf("Stasis system-level information initialization failed.\n%s", term_quit());
exit(1);
}
diff --git a/main/file.c b/main/file.c
index cb495b310..a351fd4ec 100644
--- a/main/file.c
+++ b/main/file.c
@@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/test.h"
#include "asterisk/stasis.h"
#include "asterisk/json.h"
+#include "asterisk/stasis_system.h"
/*! \brief
* The following variable controls the layout of localized sound files.
diff --git a/main/manager.c b/main/manager.c
index b1c7b5361..b8b067dea 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -7827,6 +7827,10 @@ static int __init_manager(int reload, int by_external_config)
ast_log(AST_LOG_ERROR, "Failed to initialize manager subscriptions\n");
return -1;
}
+ if (manager_system_init()) {
+ ast_log(AST_LOG_ERROR, "Failed to initialize manager system handling\n");
+ return -1;
+ }
if (manager_channels_init()) {
ast_log(AST_LOG_ERROR, "Failed to initialize manager channel handling\n");
return -1;
diff --git a/main/manager_system.c b/main/manager_system.c
new file mode 100644
index 000000000..4fef11da4
--- /dev/null
+++ b/main/manager_system.c
@@ -0,0 +1,81 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jason Parker <jparker@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief System AMI event handling
+ *
+ * \author Jason Parker <jparker@digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/stasis.h"
+#include "asterisk/stasis_message_router.h"
+#include "asterisk/stasis_system.h"
+
+/*! \brief The \ref stasis subscription returned by the forwarding of the system topic
+ * to the manager topic
+ */
+static struct stasis_subscription *topic_forwarder;
+
+static void manager_system_shutdown(void)
+{
+ stasis_unsubscribe(topic_forwarder);
+ topic_forwarder = NULL;
+}
+
+int manager_system_init(void)
+{
+ int ret = 0;
+ struct stasis_topic *manager_topic;
+ struct stasis_topic *system_topic;
+ struct stasis_message_router *message_router;
+
+ manager_topic = ast_manager_get_topic();
+ if (!manager_topic) {
+ return -1;
+ }
+ message_router = ast_manager_get_message_router();
+ if (!message_router) {
+ return -1;
+ }
+ system_topic = ast_system_topic();
+ if (!system_topic) {
+ return -1;
+ }
+
+ topic_forwarder = stasis_forward_all(system_topic, manager_topic);
+ if (!topic_forwarder) {
+ return -1;
+ }
+
+ ast_register_atexit(manager_system_shutdown);
+
+ /* If somehow we failed to add any routes, just shut down the whole
+ * thing and fail it.
+ */
+ if (ret) {
+ manager_system_shutdown();
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/main/sounds_index.c b/main/sounds_index.c
index a627f68ce..ff9a45802 100644
--- a/main/sounds_index.c
+++ b/main/sounds_index.c
@@ -36,6 +36,7 @@
#include "asterisk/cli.h"
#include "asterisk/_private.h"
#include "asterisk/stasis_message_router.h"
+#include "asterisk/stasis_system.h"
/*** MODULEINFO
<support_level>core</support_level>
diff --git a/main/stasis_system.c b/main/stasis_system.c
new file mode 100644
index 000000000..15451ed1b
--- /dev/null
+++ b/main/stasis_system.c
@@ -0,0 +1,170 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jason Parker <jparker@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Stasis Messages and Data Types for System events
+ *
+ * \author Jason Parker <jparker@digium.com>
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/astobj2.h"
+#include "asterisk/stasis.h"
+#include "asterisk/stasis_system.h"
+
+/*** DOCUMENTATION
+ <managerEvent language="en_US" name="Registry">
+ <managerEventInstance class="EVENT_FLAG_SYSTEM">
+ <synopsis>Raised when an outbound registration completes.</synopsis>
+ <syntax>
+ <parameter name="ChannelType">
+ <para>The type of channel that was registered (or not).</para>
+ </parameter>
+ <parameter name="Username">
+ <para>The username portion of the registration.</para>
+ </parameter>
+ <parameter name="Domain">
+ <para>The address portion of the registration.</para>
+ </parameter>
+ <parameter name="Status">
+ <para>The status of the registration request.</para>
+ <enumlist>
+ <enum name="Registered"/>
+ <enum name="Unregistered"/>
+ <enum name="Rejected"/>
+ <enum name="Failed"/>
+ </enumlist>
+ </parameter>
+ <parameter name="Cause">
+ <para>What caused the rejection of the request, if available.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ ***/
+
+/*! \brief The \ref stasis topic for system level changes */
+static struct stasis_topic *system_topic;
+
+static struct ast_manager_event_blob *system_registry_to_ami(struct stasis_message *message);
+
+STASIS_MESSAGE_TYPE_DEFN(ast_network_change_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_system_registry_type,
+ .to_ami = system_registry_to_ami,
+ );
+
+void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
+{
+ RAII_VAR(struct ast_json *, registry, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+ registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s}",
+ "type", "registry",
+ "channeltype", channeltype,
+ "username", username,
+ "domain", domain,
+ "status", status,
+ "cause", S_OR(cause, ""));
+
+ if (!(payload = ast_json_payload_create(registry))) {
+ return;
+ }
+
+ if (!(message = stasis_message_create(ast_system_registry_type(), payload))) {
+ return;
+ }
+
+ stasis_publish(ast_system_topic(), message);
+}
+
+static struct ast_manager_event_blob *system_registry_to_ami(struct stasis_message *message)
+{
+ struct ast_json_payload *payload = stasis_message_data(message);
+ const char *channeltype;
+ const char *username;
+ const char *domain;
+ const char *status;
+ const char *cause;
+ RAII_VAR(struct ast_str *, cause_string, ast_str_create(32), ast_free);
+
+ if (!cause_string) {
+ return NULL;
+ }
+
+ channeltype = ast_json_string_get(ast_json_object_get(payload->json, "channeltype"));
+ username = ast_json_string_get(ast_json_object_get(payload->json, "username"));
+ domain = ast_json_string_get(ast_json_object_get(payload->json, "domain"));
+ status = ast_json_string_get(ast_json_object_get(payload->json, "status"));
+ cause = ast_json_string_get(ast_json_object_get(payload->json, "cause"));
+
+ if (!ast_strlen_zero(cause)) {
+ ast_str_set(&cause_string, 0, "Cause: %s\r\n", cause);
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "Registry",
+ "ChannelType: %s\r\n"
+ "Username: %s\r\n"
+ "Domain: %s\r\n"
+ "Status: %s\r\n"
+ "%s",
+ channeltype, username, domain, status, ast_str_buffer(cause_string));
+}
+
+struct stasis_topic *ast_system_topic(void)
+{
+ return system_topic;
+}
+
+/*! \brief Cleanup the \ref stasis system level items */
+static void stasis_system_cleanup(void)
+{
+ ao2_cleanup(system_topic);
+ system_topic = NULL;
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_network_change_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_system_registry_type);
+}
+
+/*! \brief Initialize the system level items for \ref stasis */
+int ast_stasis_system_init(void)
+{
+ ast_register_cleanup(stasis_system_cleanup);
+
+ system_topic = stasis_topic_create("ast_system");
+ if (!system_topic) {
+ return 1;
+ }
+
+ if (STASIS_MESSAGE_TYPE_INIT(ast_network_change_type) != 0) {
+ return -1;
+ }
+
+ if (STASIS_MESSAGE_TYPE_INIT(ast_system_registry_type) != 0) {
+ return -1;
+ }
+
+ return 0;
+}