[asterisk-commits] dlee: branch dlee/stasis-app r383604 - in /team/dlee/stasis-app: ./ apps/ cha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 22 12:51:16 CDT 2013


Author: dlee
Date: Fri Mar 22 12:51:12 2013
New Revision: 383604

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383604
Log:
Merged revisions 383343-383579 from http://svn.asterisk.org/svn/asterisk/trunk

Added:
    team/dlee/stasis-app/main/json.c
      - copied unchanged from r383579, trunk/main/json.c
    team/dlee/stasis-app/main/manager_channels.c
      - copied unchanged from r383579, trunk/main/manager_channels.c
Removed:
    team/dlee/stasis-app/res/res_json.c
    team/dlee/stasis-app/res/res_json.exports.in
Modified:
    team/dlee/stasis-app/   (props changed)
    team/dlee/stasis-app/CHANGES
    team/dlee/stasis-app/apps/app_stasis.c
    team/dlee/stasis-app/apps/app_userevent.c
    team/dlee/stasis-app/channels/chan_skinny.c
    team/dlee/stasis-app/codecs/Makefile
    team/dlee/stasis-app/configure
    team/dlee/stasis-app/configure.ac
    team/dlee/stasis-app/funcs/func_curl.c
    team/dlee/stasis-app/include/asterisk/astobj2.h
    team/dlee/stasis-app/include/asterisk/autoconfig.h.in
    team/dlee/stasis-app/include/asterisk/channel.h
    team/dlee/stasis-app/include/asterisk/manager.h
    team/dlee/stasis-app/include/asterisk/sorcery.h
    team/dlee/stasis-app/include/asterisk/stasis.h
    team/dlee/stasis-app/main/channel.c
    team/dlee/stasis-app/main/manager.c
    team/dlee/stasis-app/main/pbx.c
    team/dlee/stasis-app/main/sorcery.c
    team/dlee/stasis-app/main/stasis.c
    team/dlee/stasis-app/main/stasis_message_router.c
    team/dlee/stasis-app/pbx/pbx_realtime.c
    team/dlee/stasis-app/res/res_sorcery_memory.c
    team/dlee/stasis-app/res/res_stasis_websocket.c
    team/dlee/stasis-app/tests/test_json.c
    team/dlee/stasis-app/tests/test_sorcery.c

Propchange: team/dlee/stasis-app/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/dlee/stasis-app/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Mar 22 12:51:12 2013
@@ -1,1 +1,1 @@
-/trunk:1-383316
+/trunk:1-383601

Modified: team/dlee/stasis-app/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/CHANGES?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/CHANGES (original)
+++ team/dlee/stasis-app/CHANGES Fri Mar 22 12:51:12 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: team/dlee/stasis-app/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/apps/app_stasis.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/apps/app_stasis.c (original)
+++ team/dlee/stasis-app/apps/app_stasis.c Fri Mar 22 12:51:12 2013
@@ -24,7 +24,6 @@
  */
 
 /*** MODULEINFO
-	<depend>res_json</depend>
 	<support_level>core</support_level>
  ***/
 

Modified: team/dlee/stasis-app/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/apps/app_userevent.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/apps/app_userevent.c (original)
+++ team/dlee/stasis-app/apps/app_userevent.c Fri Mar 22 12:51:12 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: team/dlee/stasis-app/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/channels/chan_skinny.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/channels/chan_skinny.c (original)
+++ team/dlee/stasis-app/channels/chan_skinny.c Fri Mar 22 12:51:12 2013
@@ -8571,6 +8571,9 @@
 		   We do not want to free the line here, that
 		   will happen below. */
 		while ((l = AST_LIST_REMOVE_HEAD(&d->lines, list))) {
+			if (l->mwi_event_sub) {
+				l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
+			}
 		}
 		/* Delete all speeddials for this device */
 		while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {

Modified: team/dlee/stasis-app/codecs/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/codecs/Makefile?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/codecs/Makefile (original)
+++ team/dlee/stasis-app/codecs/Makefile Fri Mar 22 12:51:12 2013
@@ -53,8 +53,8 @@
 	for dir in $(SUB_DIRS); do \
 		$(MAKE) -C $$dir clean; \
 	done
-	rm -f g722/*.[oa]
-	rm -f speex/*.[oa]
+	rm -f g722/*.[oai]
+	rm -f speex/*.[oai]
 
 .PHONY: $(SUB_DIRS)
 

Modified: team/dlee/stasis-app/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/configure.ac?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/configure.ac (original)
+++ team/dlee/stasis-app/configure.ac Fri Mar 22 12:51:12 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: team/dlee/stasis-app/funcs/func_curl.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/funcs/func_curl.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/funcs/func_curl.c (original)
+++ team/dlee/stasis-app/funcs/func_curl.c Fri Mar 22 12:51:12 2013
@@ -581,6 +581,7 @@
 	struct ast_datastore *store = NULL;
 	int hashcompat = 0;
 	AST_LIST_HEAD(global_curl_info, curl_settings) *list = NULL;
+	char curl_errbuf[CURL_ERROR_SIZE + 1]; /* add one to be safe */
 
 	if (buf) {
 		*buf = '\0';
@@ -642,7 +643,19 @@
 		curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, args.postdata);
 	}
 
-	curl_easy_perform(*curl);
+	/* Temporarily assign a buffer for curl to write errors to. */
+	curl_errbuf[0] = curl_errbuf[CURL_ERROR_SIZE] = '\0';
+	curl_easy_setopt(*curl, CURLOPT_ERRORBUFFER, curl_errbuf);
+
+	if (curl_easy_perform(*curl) != 0) {
+		ast_log(LOG_WARNING, "%s ('%s')\n", curl_errbuf, args.url);
+	}
+
+	/* Reset buffer to NULL so curl doesn't try to write to it when the
+	 * buffer is deallocated. Documentation is vague about allowing NULL
+	 * here, but the source allows it. See: "typecheck: allow NULL to unset
+	 * CURLOPT_ERRORBUFFER" (62bcf005f4678a93158358265ba905bace33b834). */
+	curl_easy_setopt(*curl, CURLOPT_ERRORBUFFER, (char*)NULL);
 
 	if (store) {
 		AST_LIST_UNLOCK(list);
@@ -665,20 +678,11 @@
 			int rowcount = 0;
 			while (fields && values && (piece = strsep(&remainder, "&"))) {
 				char *name = strsep(&piece, "=");
-				/* Do this before the decode, because if something has encoded
-				 * a literal plus-sign, we don't want to translate that to a
-				 * space. */
-				if (hashcompat == HASHCOMPAT_LEGACY) {
-					if (piece) {
-						ast_uri_decode(piece, ast_uri_http_legacy);
-					}
-					ast_uri_decode(name, ast_uri_http_legacy);
-				} else {
-					if (piece) {
-						ast_uri_decode(piece, ast_uri_http);
-					}
-					ast_uri_decode(name, ast_uri_http);
+				struct ast_flags mode = (hashcompat == HASHCOMPAT_LEGACY ? ast_uri_http_legacy : ast_uri_http);
+				if (piece) {
+					ast_uri_decode(piece, mode);
 				}
+				ast_uri_decode(name, mode);
 				ast_str_append(&fields, 0, "%s%s", rowcount ? "," : "", ast_str_set_escapecommas(&escapebuf, 0, name, INT_MAX));
 				ast_str_append(&values, 0, "%s%s", rowcount ? "," : "", ast_str_set_escapecommas(&escapebuf, 0, S_OR(piece, ""), INT_MAX));
 				rowcount++;

Modified: team/dlee/stasis-app/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/astobj2.h?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/astobj2.h (original)
+++ team/dlee/stasis-app/include/asterisk/astobj2.h Fri Mar 22 12:51:12 2013
@@ -1433,8 +1433,8 @@
  * \param flags search_flags to control linking the object.  (OBJ_NOLOCK)
  * \param tag used for debugging.
  *
- * \retval NULL on errors.
- * \retval !NULL on success.
+ * \retval 0 on errors.
+ * \retval 1 on success.
  *
  * This function inserts an object in a container according its key.
  *

Modified: team/dlee/stasis-app/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/autoconfig.h.in?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/autoconfig.h.in (original)
+++ team/dlee/stasis-app/include/asterisk/autoconfig.h.in Fri Mar 22 12:51:12 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: team/dlee/stasis-app/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/channel.h?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/channel.h (original)
+++ team/dlee/stasis-app/include/asterisk/channel.h Fri Mar 22 12:51:12 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: team/dlee/stasis-app/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/manager.h?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/manager.h (original)
+++ team/dlee/stasis-app/include/asterisk/manager.h Fri Mar 22 12:51:12 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: team/dlee/stasis-app/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/sorcery.h?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/sorcery.h (original)
+++ team/dlee/stasis-app/include/asterisk/sorcery.h Fri Mar 22 12:51:12 2013
@@ -203,7 +203,7 @@
 	void (*reload)(void *data, const struct ast_sorcery *sorcery, const char *type);
 
 	/*! \brief Callback for creating an object */
-	int (*create)(void *data, void *object);
+	int (*create)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for retrieving an object using an id */
 	void *(*retrieve_id)(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id);
@@ -218,10 +218,10 @@
 	void (*retrieve_multiple)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields);
 
 	/*! \brief Callback for updating an object */
-	int (*update)(void *data, void *object);
+	int (*update)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for deleting an object */
-	int (*delete)(void *data, void *object);
+	int (*delete)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for closing a wizard */
 	void (*close)(void *data);

Modified: team/dlee/stasis-app/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/stasis.h?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-app/include/asterisk/stasis.h Fri Mar 22 12:51:12 2013
@@ -54,9 +54,7 @@
  * enforced in code). Messages themselves are reference-counted, AO2 objects,
  * along with their values. By being both reference counted and immutable,
  * messages can be shared throughout the system without any concerns for
- * threading. (Well, the objects must be allocated with \ref
- * AO2_ALLOC_OPT_LOCK_MUTEX so that the reference counting operations are thread
- * safe. But other than that, no worries).
+ * threading.
  *
  * The type of a message is defined by an instance of \ref stasis_message_type,
  * which can be created by calling stasis_message_type_create(). Message types

Modified: team/dlee/stasis-app/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/main/channel.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/main/channel.c (original)
+++ team/dlee/stasis-app/main/channel.c Fri Mar 22 12:51:12 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: team/dlee/stasis-app/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/main/manager.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/main/manager.c (original)
+++ team/dlee/stasis-app/main/manager.c Fri Mar 22 12:51:12 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) {

Modified: team/dlee/stasis-app/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/main/pbx.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/main/pbx.c (original)
+++ team/dlee/stasis-app/main/pbx.c Fri Mar 22 12:51:12 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: team/dlee/stasis-app/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/main/sorcery.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/main/sorcery.c (original)
+++ team/dlee/stasis-app/main/sorcery.c Fri Mar 22 12:51:12 2013
@@ -888,16 +888,25 @@
 	}
 }
 
+/*! \brief Structure used when calling create, update, or delete */
+struct sorcery_details {
+	/*! \brief Pointer to the sorcery instance */
+	const struct ast_sorcery *sorcery;
+	/*! \brief Pointer to the object itself */
+	void *obj;
+};
+
 /*! \brief Internal function used to create an object in caching wizards */
 static int sorcery_cache_create(void *obj, void *arg, int flags)
 {
-	struct ast_sorcery_object_wizard *object_wizard = obj;
+	const struct ast_sorcery_object_wizard *object_wizard = obj;
+	const struct sorcery_details *details = arg;
 
 	if (!object_wizard->caching || !object_wizard->wizard->create) {
 		return 0;
 	}
 
-	object_wizard->wizard->create(object_wizard->data, arg);
+	object_wizard->wizard->create(details->sorcery, object_wizard->data, details->obj);
 
 	return 0;
 }
@@ -1014,8 +1023,9 @@
 static int sorcery_wizard_create(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (!object_wizard->caching && !object_wizard->wizard->create(object_wizard->data, arg)) ? CMP_MATCH | CMP_STOP : 0;
+	const struct sorcery_details *details = arg;
+
+	return (!object_wizard->caching && !object_wizard->wizard->create(details->sorcery, object_wizard->data, details->obj)) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
@@ -1023,12 +1033,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }
@@ -1037,8 +1051,9 @@
 static int sorcery_wizard_update(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (object_wizard->wizard->update && !object_wizard->wizard->update(object_wizard->data, arg) &&
+	const struct sorcery_details *details = arg;
+
+	return (object_wizard->wizard->update && !object_wizard->wizard->update(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -1047,12 +1062,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_update, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_update, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }
@@ -1061,8 +1080,9 @@
 static int sorcery_wizard_delete(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (object_wizard->wizard->delete && !object_wizard->wizard->delete(object_wizard->data, arg) &&
+	const struct sorcery_details *details = arg;
+
+	return (object_wizard->wizard->delete && !object_wizard->wizard->delete(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -1071,12 +1091,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_delete, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_delete, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }

Modified: team/dlee/stasis-app/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/main/stasis.c?view=diff&rev=383604&r1=383603&r2=383604
==============================================================================
--- team/dlee/stasis-app/main/stasis.c (original)
+++ team/dlee/stasis-app/main/stasis.c Fri Mar 22 12:51:12 2013
@@ -131,7 +131,7 @@
 
 static void send_subscription_change_message(struct stasis_topic *topic, char *uniqueid, char *description);
 
-static struct stasis_subscription *__stasis_subscribe(struct stasis_topic *topic, stasis_subscription_cb callback, void *data, int needs_mailbox)
+struct stasis_subscription *stasis_subscribe(struct stasis_topic *topic, stasis_subscription_cb callback, void *data)
 {
 	RAII_VAR(struct stasis_subscription *, sub, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_uuid *, id, NULL, ast_free);
@@ -148,11 +148,10 @@
 		return NULL;
 	}
 	ast_uuid_to_str(id, uniqueid, sizeof(uniqueid));
-	if (needs_mailbox) {
-		sub->mailbox = ast_threadpool_serializer(uniqueid, pool);
-		if (!sub->mailbox) {
-			return NULL;
-		}
+
+	sub->mailbox = ast_threadpool_serializer(uniqueid, pool);
+	if (!sub->mailbox) {
+		return NULL;
 	}
 
 	sub->uniqueid = ast_strdup(uniqueid);
@@ -168,11 +167,6 @@
 
 	ao2_ref(sub, +1);
 	return sub;
-}
-
-struct stasis_subscription *stasis_subscribe(struct stasis_topic *topic, stasis_subscription_cb callback, void *data)
-{
-	return __stasis_subscribe(topic, callback, data, 1);
 }
 
 struct stasis_subscription *stasis_unsubscribe(struct stasis_subscription *sub)
@@ -338,58 +332,29 @@
 
 void stasis_forward_message(struct stasis_topic *topic, struct stasis_topic *publisher_topic, struct stasis_message *message)
 {
-	struct stasis_subscription **subscribers = NULL;
-	size_t num_subscribers, i;
+	size_t i;
+	SCOPED_AO2LOCK(lock, topic);
 
 	ast_assert(topic != NULL);
 	ast_assert(publisher_topic != NULL);
 	ast_assert(message != NULL);
 
-	/* Copy the subscribers, so we don't have to hold the mutex for long */
-	{
-		SCOPED_AO2LOCK(lock, topic);
-		num_subscribers = topic->num_subscribers_current;
-		subscribers = ast_malloc(num_subscribers * sizeof(*subscribers));
-		if (subscribers) {
-			for (i = 0; i < num_subscribers; ++i) {
-				ao2_ref(topic->subscribers[i], +1);
-				subscribers[i] = topic->subscribers[i];
-			}
+	for (i = 0; i < topic->num_subscribers_current; ++i) {
+		struct stasis_subscription *sub = topic->subscribers[i];
+		RAII_VAR(struct dispatch *, dispatch, NULL, ao2_cleanup);
+
+		ast_assert(sub != NULL);
+
+		dispatch = dispatch_create(publisher_topic, message, sub);
+		if (!dispatch) {
+			ast_log(LOG_DEBUG, "Dropping dispatch\n");
+			break;

[... 244 lines stripped ...]



More information about the asterisk-commits mailing list