[asterisk-commits] dlee: trunk r383579 - in /trunk: ./ apps/ include/asterisk/ main/ pbx/ res/ t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 22 09:06:53 CDT 2013


Author: dlee
Date: Fri Mar 22 09:06:46 2013
New Revision: 383579

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383579
Log:
Move more channel events to Stasis; move res_json.c to main/json.c.

This patch started out simply as fixing the bouncing tests introduced
in r382685, but required some other changes to give it a decent
implementation.

To fix the bouncing tests, the UserEvent and Newexten AMI events
needed to be refactored to dispatch via Stasis. Dispatching directly
to AMI resulted in those events sometimes getting ahead of the
associated Newchannel events, which would understandably confuse anyone.

I found that instead of creating a zillion different message types and
structures associated with them, it would be preferable to define a
message type that has a channel snapshot and a blob of structured data
with a small bit of additional information. The JSON object model
provides a very nice way of representing structured data, so I went
with that.

 * Move JSON support from res_json.c to main/json.c
   * Made libjansson-dev a required dependency
 * Added an ast_channel_blob message type, which has a channel
   snapshot and JSON blob of data.
 * Changed UserEvent and Newexten events so that they are dispatched
   via ast_channel_blob messages on the channel's topic.
 * Got rid of the ast_channel_varset message; used ast_channel_blob
   instead.
 * Extracted the manager functions converting Stasis channel events to
   AMI events into manager_channel.c.

(issue ASTERISK-21096)
Review: https://reviewboard.asterisk.org/r/2381/

Added:
    trunk/main/json.c
      - copied unchanged from r383578, team/dlee/json_main/main/json.c
    trunk/main/manager_channels.c
      - copied, changed from r383578, team/dlee/json_main/main/manager_channels.c
Removed:
    trunk/res/res_json.c
    trunk/res/res_json.exports.in
Modified:
    trunk/CHANGES
    trunk/apps/app_userevent.c
    trunk/configure
    trunk/configure.ac
    trunk/include/asterisk/autoconfig.h.in
    trunk/include/asterisk/channel.h
    trunk/include/asterisk/manager.h
    trunk/main/channel.c
    trunk/main/manager.c
    trunk/main/pbx.c
    trunk/pbx/pbx_realtime.c
    trunk/tests/test_json.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri Mar 22 09:06:46 2013
@@ -40,6 +40,15 @@
    stopped, restarted, reversed, or skipped forward. When initiated by other
    mechanisms (such as the Playback application), the audio can be stopped,
    reversed, or skipped forward.
+
+ * Channel related events now contain a snapshot of channel state, adding new
+   fields to many of these events.
+
+ * The AMI event 'Newexten' field 'Extension' is deprecated, and may be removed
+   in a future release. Please use the common 'Exten' field instead.
+
+ * The AMI event 'UserEvent' from app_userevent now contains the channel state
+   fields. The channel state fields will come before the body fields.
 
 Channel Drivers
 ------------------

Modified: trunk/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_userevent.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/apps/app_userevent.c (original)
+++ trunk/apps/app_userevent.c Fri Mar 22 09:06:46 2013
@@ -33,6 +33,7 @@
 #include "asterisk/module.h"
 #include "asterisk/manager.h"
 #include "asterisk/app.h"
+#include "asterisk/json.h"
 
 /*** DOCUMENTATION
 	<application name="UserEvent" language="en_US">
@@ -68,11 +69,12 @@
 		AST_APP_ARG(eventname);
 		AST_APP_ARG(extra)[100];
 	);
-	struct ast_str *body = ast_str_create(16);
+	RAII_VAR(struct ast_str *, body, ast_str_create(16), ast_free);
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
-		ast_free(body);
 		return -1;
 	}
 
@@ -89,24 +91,21 @@
 		ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
 	}
 
-	/*** DOCUMENTATION
-	<managerEventInstance>
-		<synopsis>A user defined event raised from the dialplan.</synopsis>
-		<parameter name="UserEvent">
-			<para>The event name, as specified in the dialplan.</para>
-		</parameter>
-		<see-also>
-			<ref type="application">UserEvent</ref>
-		</see-also>
-	</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_USER, "UserEvent",
-			"UserEvent: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"%s",
-			args.eventname, ast_channel_uniqueid(chan), ast_str_buffer(body));
+	blob = ast_json_pack("{s: s, s: s, s: s}",
+			     "type", "userevent",
+			     "eventname", args.eventname,
+			     "body", ast_str_buffer(body));
+	if (!blob) {
+		ast_log(LOG_WARNING, "Unable to create message buffer\n");
+		return -1;
+	}
 
-	ast_free(body);
+	msg = ast_channel_blob_create(chan, blob);
+	if (!msg) {
+		return -1;
+	}
+
+	stasis_publish(ast_channel_topic(chan), msg);
 
 	return 0;
 }

Modified: trunk/configure.ac
URL: http://svnview.digium.com/svn/asterisk/trunk/configure.ac?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Mar 22 09:06:46 2013
@@ -491,12 +491,13 @@
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/event.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h arpa/nameser.h sys/io.h])
 
-# Any one of these 5 packages support a mandatory requirement, so we want to check on them as early as possible.
+# Any one of these packages support a mandatory requirement, so we want to check on them as early as possible.
 AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
 AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
 AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
 AST_EXT_LIB_CHECK([UUID], [uuid], [uuid_generate_random], [uuid/uuid.h], [-luuid])
+AST_EXT_LIB_CHECK([JANSSON], [jansson], [json_dumps], [jansson.h])
 
 EDITLINE_LIB=""
 if test "x$TERMCAP_LIB" != "x" ; then
@@ -514,6 +515,10 @@
 
 if test "x$UUID_LIB" == "x"; then
   AC_MSG_ERROR([*** uuid support not found (this typically means the uuid development package is missing)])
+fi
+
+if test "x$JANSSON_LIB" == "x"; then
+  AC_MSG_ERROR([*** JSON support not found (this typically means the libjansson development package is missing)])
 fi
 
 # Another mandatory item (unless it's explicitly disabled)
@@ -1869,8 +1874,6 @@
 
 AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
 
-AST_EXT_LIB_CHECK([JANSSON], [jansson], [json_dumps], [jansson.h])
-
 # BSD (and OS X) equivalent of inotify
 AST_EXT_LIB_CHECK([KQUEUE], [c], [kqueue], [sys/event.h])
 

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Fri Mar 22 09:06:46 2013
@@ -1229,6 +1229,11 @@
 /* Define to 1 if running on Darwin. */
 #undef _DARWIN_UNLIMITED_SELECT
 
+/* Enable large inode numbers on Mac OS X 10.5.  */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
 

Modified: trunk/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Fri Mar 22 09:06:46 2013
@@ -151,6 +151,7 @@
 #include "asterisk/ccss.h"
 #include "asterisk/framehook.h"
 #include "asterisk/stasis.h"
+#include "asterisk/json.h"
 
 #define DATASTORE_INHERIT_FOREVER	INT_MAX
 
@@ -4187,24 +4188,51 @@
 
 /*!
  * \since 12
- * \brief Variable set event.
- */
-struct ast_channel_varset {
-	/*! Channel variable was set on (or NULL for global variable) */
+ * \brief Blob of data associated with a channel.
+ *
+ * The \c blob is actually a JSON object of structured data. It has a "type" field
+ * which contains the type string describing this blob.
+ */
+struct ast_channel_blob {
+	/*! Channel blob is associated with (or NULL for global/all channels) */
 	struct ast_channel_snapshot *snapshot;
-	/*! Variable name */
-	char *variable;
-	/*! New value */
-	char *value;
+	/*! JSON blob of data */
+	struct ast_json *blob;
 };
 
 /*!
  * \since 12
- * \brief Message type for \ref ast_channel_varset messages.
- *
- * \retval Message type for \ref ast_channel_varset messages.
- */
-struct stasis_message_type *ast_channel_varset(void);
+ * \brief Message type for \ref ast_channel_blob messages.
+ *
+ * \retval Message type for \ref ast_channel_blob messages.
+ */
+struct stasis_message_type *ast_channel_blob(void);
+
+/*!
+ * \since 12
+ * \brief Extracts the type field from a \ref ast_channel_blob.
+ * Returned \c char* is still owned by \a obj
+ * \param obj Channel blob object.
+ * \return Type field value from the blob.
+ * \return \c NULL on error.
+ */
+const char *ast_channel_blob_type(struct ast_channel_blob *obj);
+
+/*!
+ * \since 12
+ * \brief Creates a \ref ast_channel_blob message.
+ *
+ * The \a blob JSON object requires a \c "type" field describing the blob. It
+ * should also be treated as immutable and not modified after it is put into the
+ * message.
+ *
+ * \param chan Channel blob is associated with, or NULL for global/all channels.
+ * \param blob JSON object representing the data.
+ * \return \ref ast_channel_blob message.
+ * \return \c NULL on error
+ */
+struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
+					       struct ast_json *blob);
 
 /*!
  * \since 12

Modified: trunk/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/manager.h?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/include/asterisk/manager.h (original)
+++ trunk/include/asterisk/manager.h Fri Mar 22 09:06:46 2013
@@ -316,4 +316,12 @@
  */
 struct ast_datastore *astman_datastore_find(struct mansession *s, const struct ast_datastore_info *info, const char *uid);
 
+/*!
+ * \brief Initialize support for AMI channel events.
+ * \return 0 on success.
+ * \return non-zero on error.
+ * \since 12
+ */
+int manager_channels_init(void);
+
 #endif /* _ASTERISK_MANAGER_H */

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Fri Mar 22 09:06:46 2013
@@ -155,7 +155,7 @@
 /*! \brief Message type for channel snapshot events */
 static struct stasis_message_type *__channel_snapshot;
 
-static struct stasis_message_type *__channel_varset;
+static struct stasis_message_type *__channel_blob;
 
 struct stasis_topic *__channel_topic_all;
 
@@ -243,37 +243,79 @@
 	stasis_publish(ast_channel_topic(chan), message);
 }
 
-static void channel_varset_dtor(void *obj)
-{
-	struct ast_channel_varset *event = obj;
+static void channel_blob_dtor(void *obj)
+{
+	struct ast_channel_blob *event = obj;
 	ao2_cleanup(event->snapshot);
-	ast_free(event->variable);
-	ast_free(event->value);
+	ast_json_unref(event->blob);
+}
+
+struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
+					       struct ast_json *blob)
+{
+	RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct ast_json *type;
+
+	ast_assert(blob != NULL);
+
+	type = ast_json_object_get(blob, "type");
+	if (type == NULL) {
+		ast_log(LOG_ERROR, "Invalid ast_channel_blob; missing type field");
+		return NULL;
+	}
+
+	obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
+	if (!obj) {
+		return NULL;
+	}
+
+	if (chan) {
+		obj->snapshot = ast_channel_snapshot_create(chan);
+		if (obj->snapshot == NULL) {
+			return NULL;
+		}
+	}
+
+	obj->blob = ast_json_ref(blob);
+
+	msg = stasis_message_create(ast_channel_blob(), obj);
+	if (!msg) {
+		return NULL;
+	}
+
+	ao2_ref(msg, +1);
+	return msg;
+}
+
+const char *ast_channel_blob_type(struct ast_channel_blob *obj)
+{
+	if (obj == NULL) {
+		return NULL;
+	}
+
+	return ast_json_string_get(ast_json_object_get(obj->blob, "type"));
 }
 
 void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
 {
-	RAII_VAR(struct ast_channel_varset *, event, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
-	event = ao2_alloc(sizeof(*event), channel_varset_dtor);
-	if (!event) {
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+	ast_assert(name != NULL);
+	ast_assert(value != NULL);
+
+	blob = ast_json_pack("{s: s, s: s, s: s}",
+			     "type", "varset",
+			     "variable", name,
+			     "value", value);
+	if (!blob) {
+		ast_log(LOG_ERROR, "Error creating message\n");
 		return;
 	}
 
-	if (chan) {
-		event->snapshot = ast_channel_snapshot_create(chan);
-		if (event->snapshot == NULL) {
-			return;
-		}
-	}
-	event->variable = ast_strdup(name);
-	event->value = ast_strdup(value);
-	if (event->variable == NULL || event->value == NULL) {
-		return;
-	}
-
-	msg = stasis_message_create(ast_channel_varset(), event);
+	msg = ast_channel_blob_create(chan, ast_json_ref(blob));
+
 	if (!msg) {
 		return;
 	}
@@ -8633,8 +8675,8 @@
 {
 	ao2_cleanup(__channel_snapshot);
 	__channel_snapshot = NULL;
-	ao2_cleanup(__channel_varset);
-	__channel_varset = NULL;
+	ao2_cleanup(__channel_blob);
+	__channel_blob = NULL;
 	ao2_cleanup(__channel_topic_all);
 	__channel_topic_all = NULL;
 	__channel_topic_all_cached = stasis_caching_unsubscribe(__channel_topic_all_cached);
@@ -8666,7 +8708,7 @@
 	}
 
 	__channel_snapshot = stasis_message_type_create("ast_channel_snapshot");
-	__channel_varset = stasis_message_type_create("ast_channel_varset");
+	__channel_blob = stasis_message_type_create("ast_channel_blob");
 
 	__channel_topic_all = stasis_topic_create("ast_channel_topic_all");
 	__channel_topic_all_cached = stasis_caching_topic_create(__channel_topic_all, channel_snapshot_get_id);
@@ -11305,9 +11347,9 @@
 	return snapshot;
 }
 
-struct stasis_message_type *ast_channel_varset(void)
-{
-	return __channel_varset;
+struct stasis_message_type *ast_channel_blob(void)
+{
+	return __channel_blob;
 }
 
 struct stasis_message_type *ast_channel_snapshot(void)

Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri Mar 22 09:06:46 2013
@@ -964,73 +964,6 @@
                         manager.conf will be present upon starting a new session.</para>
 		</description>
 	</manager>
-	<managerEvent language="en_US" name="Newchannel">
-		<managerEventInstance class="EVENT_FLAG_CALL">
-			<synopsis>Raised when a new channel is created.</synopsis>
-			<syntax>
-				<parameter name="Channel">
-				</parameter>
-				<parameter name="ChannelState">
-					<para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
-				</parameter>
-				<parameter name="ChannelStateDesc">
-					<enumlist>
-						<enum name="Down"/>
-						<enum name="Rsrvd"/>
-						<enum name="OffHook"/>
-						<enum name="Dialing"/>
-						<enum name="Ring"/>
-						<enum name="Ringing"/>
-						<enum name="Up"/>
-						<enum name="Busy"/>
-						<enum name="Dialing Offhook"/>
-						<enum name="Pre-ring"/>
-						<enum name="Unknown"/>
-					</enumlist>
-				</parameter>
-				<parameter name="CallerIDNum">
-				</parameter>
-				<parameter name="CallerIDName">
-				</parameter>
-				<parameter name="ConnectedLineNum">
-				</parameter>
-				<parameter name="ConnectedLineName">
-				</parameter>
-				<parameter name="AccountCode">
-				</parameter>
-				<parameter name="Context">
-				</parameter>
-				<parameter name="Exten">
-				</parameter>
-				<parameter name="Priority">
-				</parameter>
-				<parameter name="Uniqueid">
-				</parameter>
-				<parameter name="Cause">
-					<para>A numeric cause code for why the channel was hung up.</para>
-				</parameter>
-				<parameter name="Cause-txt">
-					<para>A description of why the channel was hung up.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
-	<managerEvent language="en_US" name="Newstate">
-		<managerEventInstance class="EVENT_FLAG_CALL">
-			<synopsis>Raised when a channel's state changes.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
-	<managerEvent language="en_US" name="Hangup">
-		<managerEventInstance class="EVENT_FLAG_CALL">
-			<synopsis>Raised when a channel is hung up.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
  ***/
 
 /*! \addtogroup Group_AMI AMI functions
@@ -1127,8 +1060,6 @@
 	{{ "module", "unload", NULL }},
 	{{ "restart", "gracefully", NULL }},
 };
-
-static struct stasis_subscription *channel_state_sub;
 
 static void acl_change_event_cb(const struct ast_event *event, void *userdata);
 
@@ -7446,127 +7377,6 @@
 	AST_RWLIST_UNLOCK(&channelvars);
 }
 
-/*!
- * \brief Generate the AMI message body from a channel snapshot
- * \internal
- *
- * \param snapshot the channel snapshot for which to generate an AMI message body
- *
- * \retval NULL on error
- * \retval ast_str* on success (must be ast_freed by caller)
- */
-static struct ast_str *manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
-{
-	struct ast_str *out = ast_str_create(1024);
-	int res = 0;
-	if (!out) {
-		return NULL;
-	}
-	res = ast_str_set(&out, 0,
-		"Channel: %s\r\n"
-		"ChannelState: %d\r\n"
-		"ChannelStateDesc: %s\r\n"
-		"CallerIDNum: %s\r\n"
-		"CallerIDName: %s\r\n"
-		"ConnectedLineNum: %s\r\n"
-		"ConnectedLineName: %s\r\n"
-		"AccountCode: %s\r\n"
-		"Context: %s\r\n"
-		"Exten: %s\r\n"
-		"Priority: %d\r\n"
-		"Uniqueid: %s\r\n"
-		"Cause: %d\r\n"
-		"Cause-txt: %s\r\n",
-		snapshot->name,
-		snapshot->state,
-		ast_state2str(snapshot->state),
-		snapshot->caller_number,
-		snapshot->caller_name,
-		snapshot->connected_number,
-		snapshot->connected_name,
-		snapshot->accountcode,
-		snapshot->context,
-		snapshot->exten,
-		snapshot->priority,
-		snapshot->uniqueid,
-		snapshot->hangupcause,
-		ast_cause2str(snapshot->hangupcause));
-
-	if (!res) {
-		return NULL;
-	}
-
-	return out;
-}
-
-static void channel_snapshot_update(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot)
-{
-	int is_hungup;
-	char *manager_event = NULL;
-
-	if (!new_snapshot) {
-		/* Ignore cache clearing events; we'll see the hangup first */
-		return;
-	}
-
-	is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
-
-	if (!old_snapshot) {
-		manager_event = "Newchannel";
-	}
-
-	if (old_snapshot && old_snapshot->state != new_snapshot->state) {
-		manager_event = "Newstate";
-	}
-
-	if (old_snapshot && is_hungup) {
-		manager_event = "Hangup";
-	}
-
-	if (manager_event) {
-		RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
-		channel_event_string = manager_build_channel_state_string(new_snapshot);
-		if (channel_event_string) {
-			manager_event(EVENT_FLAG_CALL, manager_event, "%s", ast_str_buffer(channel_event_string));
-		}
-	}
-}
-
-static void channel_varset(const char *channel_name, const char *uniqueid, const char *name, const char *value)
-{
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a variable is set to a particular value.</synopsis>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
-		      "Channel: %s\r\n"
-		      "Variable: %s\r\n"
-		      "Value: %s\r\n"
-		      "Uniqueid: %s\r\n",
-		      channel_name, name, value, uniqueid);
-}
-
-static void channel_event_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
-{
-	if (stasis_message_type(message) == stasis_cache_update()) {
-		struct stasis_cache_update *update = stasis_message_data(message);
-		if (ast_channel_snapshot() == update->type) {
-			struct ast_channel_snapshot *old_snapshot =
-				stasis_message_data(update->old_snapshot);
-			struct ast_channel_snapshot *new_snapshot =
-				stasis_message_data(update->new_snapshot);
-			channel_snapshot_update(old_snapshot, new_snapshot);
-		}
-	} else if (stasis_message_type(message) == ast_channel_varset()) {
-		struct ast_channel_varset *varset = stasis_message_data(message);
-		const char *name = varset->snapshot ? varset->snapshot->name : "none";
-		const char *uniqueid = varset->snapshot ? varset->snapshot->uniqueid : "none";
-		channel_varset(name, uniqueid, varset->variable, varset->value);
-	}
-}
-
 /*! \internal \brief Free a user record.  Should already be removed from the list */
 static void manager_free_user(struct ast_manager_user *user)
 {
@@ -7589,8 +7399,6 @@
 static void manager_shutdown(void)
 {
 	struct ast_manager_user *user;
-
-	channel_state_sub = stasis_unsubscribe(channel_state_sub);
 
 	if (registered) {
 		ast_manager_unregister("Ping");
@@ -7683,10 +7491,8 @@
 
 	manager_enabled = 0;
 
-	if (!channel_state_sub) {
-		channel_state_sub = stasis_subscribe(
-			stasis_caching_get_topic(ast_channel_topic_all_cached()),
-			channel_event_cb, NULL);
+	if (manager_channels_init()) {
+		return -1;
 	}
 
 	if (!registered) {

Copied: trunk/main/manager_channels.c (from r383578, team/dlee/json_main/main/manager_channels.c)
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager_channels.c?view=diff&rev=383579&p1=team/dlee/json_main/main/manager_channels.c&r1=383578&p2=trunk/main/manager_channels.c&r2=383579
==============================================================================
--- team/dlee/json_main/main/manager_channels.c (original)
+++ trunk/main/manager_channels.c Fri Mar 22 09:06:46 2013
@@ -259,15 +259,15 @@
 				</syntax>
 			</managerEventInstance>
 		***/
-	manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
-		      "%s"
-		      "Extension: %s\r\n"
-		      "Application: %s\r\n"
-		      "AppData: %s\r\n",
-		      ast_str_buffer(channel_event_string),
-		      new_snapshot->exten,
-		      new_snapshot->appl,
-		      new_snapshot->data);
+		manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
+			      "%s"
+			      "Extension: %s\r\n"
+			      "Application: %s\r\n"
+			      "AppData: %s\r\n",
+			      ast_str_buffer(channel_event_string),
+			      new_snapshot->exten,
+			      new_snapshot->appl,
+			      new_snapshot->data);
 	}
 }
 

Modified: trunk/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/pbx.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Fri Mar 22 09:06:46 2013
@@ -4655,8 +4655,9 @@
 	int res;
 	struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
 	char passdata[EXT_DATA_SIZE];
-
 	int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 	ast_rdlock_contexts();
 	if (found)
@@ -4700,28 +4701,18 @@
 					COLORIZE(COLOR_BRMAGENTA, 0, passdata),
 					"in new stack");
 			}
-			/*** DOCUMENTATION
-				<managerEventInstance>
-					<synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
-					<syntax>
-						<parameter name="Application">
-							<para>The application about to be executed.</para>
-						</parameter>
-						<parameter name="AppData">
-							<para>The data to be passed to the application.</para>
-						</parameter>
-					</syntax>
-				</managerEventInstance>
-			***/
-			manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
-					"Channel: %s\r\n"
-					"Context: %s\r\n"
-					"Extension: %s\r\n"
-					"Priority: %d\r\n"
-					"Application: %s\r\n"
-					"AppData: %s\r\n"
-					"Uniqueid: %s\r\n",
-					ast_channel_name(c), ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), app->name, passdata, ast_channel_uniqueid(c));
+			snapshot = ast_channel_snapshot_create(c);
+			if (snapshot) {
+				/* pbx_exec sets application name and data, but we don't want to log
+				 * every exec. Just update the snapshot here instead.
+				 */
+				ast_string_field_set(snapshot, appl, app->name);
+				ast_string_field_set(snapshot, data, passdata);
+				msg = stasis_message_create(ast_channel_snapshot(), snapshot);
+				if (msg) {
+					stasis_publish(ast_channel_topic(c), msg);
+				}
+			}
 			return pbx_exec(c, app, passdata);	/* 0 on success, -1 on failure */
 		}
 	} else if (q.swo) {	/* not found here, but in another switch */

Modified: trunk/pbx/pbx_realtime.c
URL: http://svnview.digium.com/svn/asterisk/trunk/pbx/pbx_realtime.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/pbx/pbx_realtime.c (original)
+++ trunk/pbx/pbx_realtime.c Fri Mar 22 09:06:46 2013
@@ -345,6 +345,8 @@
 				char tmp1[80];
 				char tmp2[80];
 				char tmp3[EXT_DATA_SIZE];
+				RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+				RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 				appdata[0] = 0; /* just in case the substitute var func isn't called */
 				if(!ast_strlen_zero(tmp))
@@ -354,16 +356,18 @@
 						 term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
 						 term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
 						 term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
-				manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
-							  "Channel: %s\r\n"
-							  "Context: %s\r\n"
-							  "Extension: %s\r\n"
-							  "Priority: %d\r\n"
-							  "Application: %s\r\n"
-							  "AppData: %s\r\n"
-							  "Uniqueid: %s\r\n",
-							  ast_channel_name(chan), ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", ast_channel_uniqueid(chan));
-				
+				snapshot = ast_channel_snapshot_create(chan);
+				if (snapshot) {
+					/* pbx_exec sets application name and data, but we don't want to log
+					 * every exec. Just update the snapshot here instead.
+					 */
+					ast_string_field_set(snapshot, appl, app);
+					ast_string_field_set(snapshot, data, !ast_strlen_zero(appdata) ? appdata : "(NULL)");
+					msg = stasis_message_create(ast_channel_snapshot(), snapshot);
+					if (msg) {
+						stasis_publish(ast_channel_topic(chan), msg);
+					}
+				}
 				res = pbx_exec(chan, a, appdata);
 			} else
 				ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);

Modified: trunk/tests/test_json.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_json.c?view=diff&rev=383579&r1=383578&r2=383579
==============================================================================
--- trunk/tests/test_json.c (original)
+++ trunk/tests/test_json.c Fri Mar 22 09:06:46 2013
@@ -31,7 +31,6 @@
 
 /*** MODULEINFO
 	<depend>TEST_FRAMEWORK</depend>
-	<depend>res_json</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -1720,5 +1719,4 @@
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "JSON testing",
 		.load = load_module,
-		.unload = unload_module,
-		.nonoptreq = "res_json");
+		.unload = unload_module);




More information about the asterisk-commits mailing list