[asterisk-commits] qwell: branch qwell/system_registry r391901 - in /team/qwell/system_registry:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 14 16:50:59 CDT 2013


Author: qwell
Date: Fri Jun 14 16:50:57 2013
New Revision: 391901

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391901
Log:
Commit progress.  Doesn't compile.  Need to actually add ast_system_register_type().

Added:
    team/qwell/system_registry/main/manager_system.c
      - copied, changed from r391884, team/qwell/system_registry/main/manager_mwi.c
Modified:
    team/qwell/system_registry/channels/chan_iax2.c
    team/qwell/system_registry/channels/chan_sip.c
    team/qwell/system_registry/include/asterisk/manager.h
    team/qwell/system_registry/main/manager.c

Modified: team/qwell/system_registry/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/channels/chan_iax2.c?view=diff&rev=391901&r1=391900&r2=391901
==============================================================================
--- team/qwell/system_registry/channels/chan_iax2.c (original)
+++ team/qwell/system_registry/channels/chan_iax2.c Fri Jun 14 16:50:57 2013
@@ -8390,6 +8390,31 @@
 	return 0;
 }
 
+static void iax2_publish_registry(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", "IAX2",
+		"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);
+}
+
 /*! \brief Acknowledgment received for OUR registration */
 static int iax2_ack_registry(struct iax_ies *ies, struct sockaddr_in *sin, int callno)
 {
@@ -8451,7 +8476,7 @@
 		}
 		snprintf(ourip, sizeof(ourip), "%s:%d", ast_inet_ntoa(reg->us.sin_addr), ntohs(reg->us.sin_port));
 		ast_verb(3, "Registered IAX2 to '%s', who sees us as %s%s\n", ast_inet_ntoa(sin->sin_addr), ourip, msgstatus);
-		manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: IAX2\r\nDomain: %s\r\nStatus: Registered\r\n", ast_inet_ntoa(sin->sin_addr));
+		iax2_publish_registry(reg->username, ast_inet_ntoa(sin->sin_addr), "Registered", NULL);
 	}
 	reg->regstate = REG_STATE_REGISTERED;
 	return 0;
@@ -11186,8 +11211,8 @@
 				if (iaxs[fr->callno]->reg) {
 					if (authdebug) {
 						ast_log(LOG_NOTICE, "Registration of '%s' rejected: '%s' from: '%s'\n", iaxs[fr->callno]->reg->username, ies.cause ? ies.cause : "<unknown>", ast_inet_ntoa(sin.sin_addr));
-						manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: IAX2\r\nUsername: %s\r\nStatus: Rejected\r\nCause: %s\r\n", iaxs[fr->callno]->reg->username, ies.cause ? ies.cause : "<unknown>");
 					}
+					iax2_publish_registry(iaxs[fr->callno]->reg->username, ast_inet_ntoa(sin.sin_addr), "Rejected", S_OR(ies.cause, "<unknown>"));
 					iaxs[fr->callno]->reg->regstate = REG_STATE_REJECTED;
 				}
 				/* Send ack immediately, before we destroy */

Modified: team/qwell/system_registry/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/channels/chan_sip.c?view=diff&rev=391901&r1=391900&r2=391901
==============================================================================
--- team/qwell/system_registry/channels/chan_sip.c (original)
+++ team/qwell/system_registry/channels/chan_sip.c Fri Jun 14 16:50:57 2013
@@ -15058,6 +15058,30 @@
 	return map_x_s(regstatestrings, regstate, "Unknown");
 }
 
+static void sip_publish_registry(const char *username, const char *domain, const char *status)
+{
+	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}",
+		"type", "registry",
+		"channeltype", "SIP",
+		"username", username,
+		"domain", domain,
+		"status", status);
+
+	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);
+}
+
 /*! \brief Update registration with SIP Proxy.
  * Called from the scheduler when the previous registration expires,
  * so we don't have to cancel the pending event.
@@ -15158,7 +15182,7 @@
 		transmit_register(r, SIP_REGISTER, NULL, NULL);
 		ast_log(LOG_NOTICE, "   -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts);
 	}
-	manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
+	sip_publish_registry(r->username, r->hostname, regstate2str(r->regstate));
 	registry_unref(r, "unreffing registry_unref r");
 	return 0;
 }
@@ -23692,7 +23716,7 @@
 			r->regstate = REG_STATE_UNREGISTERED;
 			transmit_register(r, SIP_REGISTER, NULL, NULL);
 		}
-		manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
+		sip_publish_registry(r->username, r->hostname, regstate2str(r->regstate));
 		break;
 	case 479:	/* SER: Not able to process the URI - address is wrong in register*/
 		ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username, p->registry->hostname);
@@ -23711,7 +23735,7 @@
 
 		r->regstate = REG_STATE_REGISTERED;
 		r->regtime = ast_tvnow();		/* Reset time of last successful registration */
-		manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
+		sip_publish_registry(r->username, r->hostname, regstate2str(r->regstate));
 		r->regattempts = 0;
 		ast_debug(1, "Registration successful\n");
 		if (r->timeout > -1) {

Modified: team/qwell/system_registry/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/include/asterisk/manager.h?view=diff&rev=391901&r1=391900&r2=391901
==============================================================================
--- team/qwell/system_registry/include/asterisk/manager.h (original)
+++ team/qwell/system_registry/include/asterisk/manager.h Fri Jun 14 16:50:57 2013
@@ -440,6 +440,14 @@
 #define NO_EXTRA_FIELDS "%s", ""
 
 /*!
+ * \since 12
+ * \brief Initialize support for AMI system events.
+ * \retval 0 on success
+ * \retval non-zero on error
+ */
+int manager_system_init(void);
+
+/*!
  * \brief Initialize support for AMI channel events.
  * \retval 0 on success.
  * \retval non-zero on error.

Modified: team/qwell/system_registry/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/manager.c?view=diff&rev=391901&r1=391900&r2=391901
==============================================================================
--- team/qwell/system_registry/main/manager.c (original)
+++ team/qwell/system_registry/main/manager.c Fri Jun 14 16:50:57 2013
@@ -7760,6 +7760,10 @@
 			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;

Copied: team/qwell/system_registry/main/manager_system.c (from r391884, team/qwell/system_registry/main/manager_mwi.c)
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/manager_system.c?view=diff&rev=391901&p1=team/qwell/system_registry/main/manager_mwi.c&r1=391884&p2=team/qwell/system_registry/main/manager_system.c&r2=391901
==============================================================================
--- team/qwell/system_registry/main/manager_mwi.c (original)
+++ team/qwell/system_registry/main/manager_system.c Fri Jun 14 16:50:57 2013
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2013, Digium, Inc.
  *
- * Matt Jordan <mjordan at digium.com>
+ * Jason Parker <jparker at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -18,146 +18,96 @@
 
 /*! \file
  *
- * \brief The Asterisk Management Interface - AMI (MWI event handling)
+ * \brief System AMI event handling
  *
- * \author Matt Jordan <mjordan at digium.com>
+ * \author Jason Parker <jparker at digium.com>
  */
 
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include "asterisk/manager.h"
+//#include "asterisk/manager.h"
 #include "asterisk/app.h"
-#include "asterisk/channel.h"
+//#include "asterisk/channel.h"
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/stasis.h"
-
-struct stasis_message_router *mwi_state_router;
 
 /*** DOCUMENTATION
  ***/
 
-/*! \brief The \ref stasis subscription returned by the forwarding of the MWI topic
+/*! \brief The \ref stasis subscription returned by the forwarding of the system topic
  * to the manager topic
  */
 static struct stasis_subscription *topic_forwarder;
 
-/*! \brief Callback function used by \ref mwi_app_event_cb to weed out "Event" keys */
-static int exclude_event_cb(const char *key)
+static void system_registry_cb(struct ast_json *obj)
 {
-	if (!strcmp(key, "Event")) {
-		return -1;
-	}
-	return 0;
-}
+	const char *channeltype;
+	const char *username;
+	const char *domain;
+	const char *status;
+	const char *cause;
+	RAII_VAR(struct ast_str *, cause_string, NULL, ast_free);
 
-/*! \brief Generic MWI event callback used for one-off events from voicemail modules */
-static void mwi_app_event_cb(void *data, struct stasis_subscription *sub,
-				    struct stasis_topic *topic,
-				    struct stasis_message *message)
-{
-	struct ast_mwi_blob *payload = stasis_message_data(message);
-	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-	RAII_VAR(struct ast_str *, event_buffer, NULL, ast_free);
-	struct ast_json *event_json = ast_json_object_get(payload->blob, "Event");
-
-	if (!event_json) {
+	if (!(cause_string = ast_str_create(32))) {
 		return;
 	}
 
-	if (payload->mwi_state && payload->mwi_state->snapshot) {
-		channel_event_string = ast_manager_build_channel_state_string(payload->mwi_state->snapshot);
-	}
+	channeltype = ast_json_string_get(ast_json_object_get(obj, "channeltype"));
+	username = ast_json_string_get(ast_json_object_get(obj, "username"));
+	domain = ast_json_string_get(ast_json_object_get(obj, "domain"));
+	status = ast_json_string_get(ast_json_object_get(obj, "status"));
+	cause = ast_json_string_get(ast_json_object_get(obj, "cause"));
 
-	event_buffer = ast_manager_str_from_json_object(payload->blob, exclude_event_cb);
-	if (!event_buffer) {
-		ast_log(AST_LOG_WARNING, "Failed to create payload for event %s\n", ast_json_string_get(event_json));
-		return;
-	}
-
-	manager_event(EVENT_FLAG_CALL, ast_json_string_get(event_json),
-			"Mailbox: %s\r\n"
-			"%s"
-			"%s",
-			payload->mwi_state ? payload->mwi_state->uniqueid : "Unknown",
-			ast_str_buffer(event_buffer),
-			channel_event_string ? ast_str_buffer(channel_event_string) : "");
-}
-
-static void mwi_update_cb(void *data, struct stasis_subscription *sub,
-				    struct stasis_topic *topic,
-				    struct stasis_message *message)
-{
-	struct ast_mwi_state *mwi_state;
-	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
-	if (ast_mwi_state_type() != stasis_message_type(message)) {
-		return;
-	}
-
-	mwi_state = stasis_message_data(message);
-	if (!mwi_state) {
-		return;
-	}
-
-	if (mwi_state->snapshot) {
-		channel_event_string = ast_manager_build_channel_state_string(mwi_state->snapshot);
+	if (!ast_strlen_zero(cause)) {
+		ast_str_set(&cause_string, 0, "Cause: %s\r\n", cause);
 	}
 
 	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when the state of messages in a voicemail mailbox
-			has changed or when a channel has finished interacting with a
-			mailbox.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-				<parameter name="Mailbox">
-					<para>The mailbox with the new message, specified as <literal>mailbox</literal>@<literal>context</literal></para>
-				</parameter>
-				<parameter name="Waiting">
-					<para>Whether or not the mailbox has messages waiting for it.</para>
-				</parameter>
-				<parameter name="New">
-					<para>The number of new messages.</para>
-				</parameter>
-				<parameter name="Old">
-					<para>The number of old messages.</para>
-				</parameter>
-			</syntax>
-			<description>
-				<note><para>The Channel related parameters are only present if a
-				channel was involved in the manipulation of a mailbox. If no
-				channel is involved, the parameters are not included with the
-				event.</para>
-				</note>
-			</description>
-		</managerEventInstance>
+		<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>
+					</parameter>
+					<parameter name="Cause">
+						<para>What caused the rejection of the request, if available.</para>
+					</parameter>
+				</syntax>
+			</managerEventInstance>
+		</managerEvent>
 	***/
-	manager_event(EVENT_FLAG_CALL, "MessageWaiting",
-			"%s"
-			"Mailbox: %s\r\n"
-			"Waiting: %d\r\n"
-			"New: %d\r\n"
-			"Old: %d\r\n",
-			AS_OR(channel_event_string, ""),
-			mwi_state->uniqueid,
-			ast_app_has_voicemail(mwi_state->uniqueid, NULL),
-			mwi_state->new_msgs,
-			mwi_state->old_msgs);
+	manager_event(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));
 }
 
-static void manager_mwi_shutdown(void)
+static void manager_system_shutdown(void)
 {
 	stasis_unsubscribe(topic_forwarder);
 	topic_forwarder = NULL;
 }
 
-int manager_mwi_init(void)
+int manager_system_init(void)
 {
 	int ret = 0;
 	struct stasis_topic *manager_topic;
-	struct stasis_topic *mwi_topic;
+	struct stasis_topic *system_topic;
 	struct stasis_message_router *message_router;
 
 	manager_topic = ast_manager_get_topic();
@@ -168,33 +118,28 @@
 	if (!message_router) {
 		return -1;
 	}
-	mwi_topic = ast_mwi_topic_all();
-	if (!mwi_topic) {
+	system_topic = ast_system_topic();
+	if (!system_topic) {
 		return -1;
 	}
 
-	topic_forwarder = stasis_forward_all(mwi_topic, manager_topic);
+	topic_forwarder = stasis_forward_all(system_topic, manager_topic);
 	if (!topic_forwarder) {
 		return -1;
 	}
 
-	ast_register_atexit(manager_mwi_shutdown);
+	ast_register_atexit(manager_system_shutdown);
 
 	ret |= stasis_message_router_add(message_router,
-					 ast_mwi_state_type(),
-					 mwi_update_cb,
-					 NULL);
-
-	ret |= stasis_message_router_add(message_router,
-					 ast_mwi_vm_app_type(),
-					 mwi_app_event_cb,
+					 ast_system_register_type(),
+					 system_registry_cb,
 					 NULL);
 
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.
 	 */
 	if (ret) {
-		manager_mwi_shutdown();
+		manager_system_shutdown();
 		return -1;
 	}
 




More information about the asterisk-commits mailing list