[asterisk-commits] dlee: branch dlee/stasis-http r383776 - in /team/dlee/stasis-http: ./ apps/ c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 25 15:47:37 CDT 2013


Author: dlee
Date: Mon Mar 25 15:47:33 2013
New Revision: 383776

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383776
Log:
Merged revisions 383323-383772 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app

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

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

Propchange: team/dlee/stasis-http/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Mar 25 15:47:33 2013
@@ -1,1 +1,1 @@
-/team/dlee/stasis-app:1-383317 /trunk:1-383057
+/team/dlee/stasis-app:1-383772 /trunk:1-383765

Modified: team/dlee/stasis-http/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/CHANGES?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/CHANGES (original)
+++ team/dlee/stasis-http/CHANGES Mon Mar 25 15:47:33 2013
@@ -40,6 +40,18 @@
    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.
+
+ * The deprecated use of | (pipe) as a separator in the channelvars setting in
+   manager.conf has been removed.
 
 Channel Drivers
 ------------------

Modified: team/dlee/stasis-http/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/apps/app_mixmonitor.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/apps/app_mixmonitor.c (original)
+++ team/dlee/stasis-http/apps/app_mixmonitor.c Mon Mar 25 15:47:33 2013
@@ -1042,7 +1042,7 @@
 	return 0;
 }
 
-static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
+static int stop_mixmonitor_full(struct ast_channel *chan, const char *data)
 {
 	struct ast_datastore *datastore = NULL;
 	char *parse = "";
@@ -1093,6 +1093,12 @@
 	}
 	ast_channel_unlock(chan);
 
+	return 0;
+}
+
+static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
+{
+	stop_mixmonitor_full(chan, data);
 	return 0;
 }
 
@@ -1315,7 +1321,7 @@
 		return AMI_SUCCESS;
 	}
 
-	res = stop_mixmonitor_exec(c, mixmonitor_id);
+	res = stop_mixmonitor_full(c, mixmonitor_id);
 
 	if (res) {
 		astman_send_error(s, m, "Could not stop monitoring channel");

Modified: team/dlee/stasis-http/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/apps/app_stasis.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/apps/app_stasis.c (original)
+++ team/dlee/stasis-http/apps/app_stasis.c Mon Mar 25 15:47:33 2013
@@ -24,7 +24,6 @@
  */
 
 /*** MODULEINFO
-	<depend>res_json</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -103,7 +102,7 @@
 	return __app_controls;
 }
 
-struct stasis_app {
+struct app {
 	/*! Callback function for this application. */
 	stasis_app_cb handler;
 	/*! Opaque data to hand to callback function. */
@@ -112,11 +111,10 @@
 	char name[];
 };
 
-/*! Constructor for \ref stasis_app. */
-static struct stasis_app *app_create(const char *name, stasis_app_cb handler,
-				     void *data)
-{
-	struct stasis_app *app;
+/*! Constructor for \ref app. */
+static struct app *app_create(const char *name, stasis_app_cb handler, void *data)
+{
+	struct app *app;
 	size_t size;
 
 	ast_assert(name != NULL);
@@ -139,7 +137,7 @@
 /*! AO2 hash function for \ref stasis_app */
 static int app_hash(const void *obj, const int flags)
 {
-	const struct stasis_app *app = obj;
+	const struct app *app = obj;
 	const char *name = flags & OBJ_KEY ? obj : app->name;
 
 	return ast_str_hash(name);
@@ -148,8 +146,8 @@
 /*! AO2 comparison function for \ref stasis_app */
 static int app_compare(void *lhs, void *rhs, int flags)
 {
-	const struct stasis_app *lhs_app = lhs;
-	const struct stasis_app *rhs_app = rhs;
+	const struct app *lhs_app = lhs;
+	const struct app *rhs_app = rhs;
 	const char *rhs_name = flags & OBJ_KEY ? rhs : rhs_app->name;
 
 	if (strcmp(lhs_app->name, rhs_name) == 0) {
@@ -164,7 +162,7 @@
  * \param app App to send the message to.
  * \param message Message to send.
  */
-static void app_send(struct stasis_app *app, struct ast_json *message)
+static void app_send(struct app *app, struct ast_json *message)
 {
 	app->handler(app->data, app->name, message);
 }
@@ -404,8 +402,7 @@
 	return ast_json_ref(message);
 }
 
-static int send_start_msg(struct stasis_app *app, struct ast_channel *chan,
-			  int argc, char *argv[])
+static int send_start_msg(struct app *app, struct ast_channel *chan, int argc, char *argv[])
 {
 	RAII_VAR(struct ast_json *, msg_info, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
@@ -451,7 +448,7 @@
 	return 0;
 }
 
-static int send_end_msg(struct stasis_app *app, struct ast_channel *chan)
+static int send_end_msg(struct app *app, struct ast_channel *chan)
 {
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
@@ -464,25 +461,29 @@
 		return -1;
 	}
 	msg = stasis_app_event_create("stasis-end", snapshot, NULL);
+	if (!msg) {
+		return -1;
+	}
 
 	app_send(app, msg);
 	return 0;
 }
 
 static void sub_handler(void *data, struct stasis_subscription *sub,
-			struct stasis_topic *topic, struct stasis_message *msg)
-{
-	struct stasis_app *app = data;
-	if (ast_channel_snapshot() == stasis_message_type(msg)) {
-		RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
-		struct ast_channel_snapshot *snapshot =
-			stasis_message_data(msg);
-
-		json = stasis_app_event_create("channel-state-change", snapshot,
-					       NULL);
-		app_send(app, json);
-	}
-	if (stasis_subscription_final_message(sub, msg)) {
+			struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct app *app = data;
+	if (ast_channel_snapshot() == stasis_message_type(message)) {
+		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+		struct ast_channel_snapshot *snapshot =	stasis_message_data(message);
+
+		msg = stasis_app_event_create("channel-state-change", snapshot, NULL);
+		if (!msg) {
+			return;
+		}
+		app_send(app, msg);
+	}
+	if (stasis_subscription_final_message(sub, message)) {
 		ao2_cleanup(data);
 	}
 }
@@ -529,7 +530,7 @@
 static int app_stasis_exec(struct ast_channel *chan, const char *data)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
 	RAII_VAR(struct stasis_subscription *, subscription, NULL,
 		 stasis_unsubscribe);
@@ -652,7 +653,7 @@
 int stasis_app_send(const char *app_name, struct ast_json *message)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 
 	app = ao2_find(apps, app_name, OBJ_KEY);
 
@@ -672,7 +673,7 @@
 int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 
 	SCOPED_LOCK(apps_lock, apps, ao2_lock, ao2_unlock);
 

Modified: team/dlee/stasis-http/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/apps/app_userevent.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/apps/app_userevent.c (original)
+++ team/dlee/stasis-http/apps/app_userevent.c Mon Mar 25 15:47:33 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-http/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/channels/chan_skinny.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/channels/chan_skinny.c (original)
+++ team/dlee/stasis-http/channels/chan_skinny.c Mon Mar 25 15:47:33 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-http/codecs/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/codecs/Makefile?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/codecs/Makefile (original)
+++ team/dlee/stasis-http/codecs/Makefile Mon Mar 25 15:47:33 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-http/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/configure.ac?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/configure.ac (original)
+++ team/dlee/stasis-http/configure.ac Mon Mar 25 15:47:33 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-http/contrib/scripts/install_prereq
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/contrib/scripts/install_prereq?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/contrib/scripts/install_prereq (original)
+++ team/dlee/stasis-http/contrib/scripts/install_prereq Mon Mar 25 15:47:33 2013
@@ -32,6 +32,7 @@
 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
 PACKAGES_RH="$PACKAGES_RH libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
 PACKAGES_RH="$PACKAGES_RH openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel libuuid-devel"
+PACKAGES_RH="$PACKAGES_RH jansson-devel"
 
 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack"
 
@@ -79,20 +80,16 @@
 }
 
 handle_debian() {
-	# echo "# Distribution is Debian or compatible"
 	extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
 	$testcmd aptitude install -y $extra_packs
 }
 
 handle_rh() {
-	# echo "# Distribution is RedHat-based or compatible"
 	extra_packs=`check_installed_rpms $PACKAGES_RH`
-        # FIXME: is there yum with RHEL 4?
 	$testcmd yum install -y $extra_packs
 }
 
 handle_obsd() {
-	# echo "# Distribution is OpenBSD or compatible"
 	extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
 	$testcmd pkg_add $extra_packs
 }

Modified: team/dlee/stasis-http/funcs/func_curl.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/funcs/func_curl.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/funcs/func_curl.c (original)
+++ team/dlee/stasis-http/funcs/func_curl.c Mon Mar 25 15:47:33 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-http/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/astobj2.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/astobj2.h (original)
+++ team/dlee/stasis-http/include/asterisk/astobj2.h Mon Mar 25 15:47:33 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-http/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/autoconfig.h.in?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/autoconfig.h.in (original)
+++ team/dlee/stasis-http/include/asterisk/autoconfig.h.in Mon Mar 25 15:47:33 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-http/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/channel.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/channel.h (original)
+++ team/dlee/stasis-http/include/asterisk/channel.h Mon Mar 25 15:47:33 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
 
@@ -4135,7 +4136,11 @@
 	int priority;			/*!< Dialplan: Current extension priority */
 	int amaflags;			/*!< AMA flags for billing */
 	int hangupcause;		/*!< Why is the channel hanged up. See causes.h */
+	int caller_pres;		/*!< Caller ID presentation. */
+
 	struct ast_flags flags;		/*!< channel flags of AST_FLAG_ type */
+
+	struct varshead *manager_vars;	/*!< Variables to be appended to manager events */
 };
 
 /*!
@@ -4152,6 +4157,27 @@
 
 /*!
  * \since 12
+ * \brief Sets the variables to be stored in the \a manager_vars field of all
+ * snapshots.
+ * \param varc Number of variable names.
+ * \param vars Array of variable names.
+ */
+void ast_channel_set_manager_vars(size_t varc, char **vars);
+
+/*!
+ * \since 12
+ * \brief Gets the variables for a given channel, as specified by ast_channel_set_manager_vars().
+ *
+ * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
+ *
+ * \param chan Channel to get variables for.
+ * \return List of channel variables.
+ * \return \c NULL on error
+ */
+struct varshead *ast_channel_get_manager_vars(struct ast_channel *chan);
+
+/*!
+ * \since 12
  * \brief Message type for \ref ast_channel_snapshot.
  *
  * \retval Message type for \ref ast_channel_snapshot.
@@ -4162,10 +4188,12 @@
  * \since 12
  * \brief A topic which publishes the events for a particular channel.
  *
- * \param chan Channel.
+ * If the given \a chan is \c NULL, ast_channel_topic_all() is returned.
+ *
+ * \param chan Channel, or \c NULL.
  *
  * \retval Topic for channel's events.
- * \retval \c NULL if \a chan is \c NULL.
+ * \retval ast_channel_topic_all() if \a chan is \c NULL.
  */
 struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
 
@@ -4187,24 +4215,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-http/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/json.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/json.h (original)
+++ team/dlee/stasis-http/include/asterisk/json.h Mon Mar 25 15:47:33 2013
@@ -31,6 +31,11 @@
  */
 
 /*!@{*/
+
+/*!
+ * \brief Initialize the JSON library.
+ */
+void ast_json_init(void);
 
 /*!
  * \brief Set custom allocators instead of the standard ast_malloc() and ast_free().

Modified: team/dlee/stasis-http/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/manager.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/manager.h (original)
+++ team/dlee/stasis-http/include/asterisk/manager.h Mon Mar 25 15:47:33 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-http/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/sorcery.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/sorcery.h (original)
+++ team/dlee/stasis-http/include/asterisk/sorcery.h Mon Mar 25 15:47:33 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-http/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/stasis.h?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-http/include/asterisk/stasis.h Mon Mar 25 15:47:33 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-http/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/Makefile?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/main/Makefile (original)
+++ team/dlee/stasis-http/main/Makefile Mon Mar 25 15:47:33 2013
@@ -151,6 +151,7 @@
 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
 asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
 cli.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
+json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
 
 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)

Modified: team/dlee/stasis-http/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/asterisk.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/main/asterisk.c (original)
+++ team/dlee/stasis-http/main/asterisk.c Mon Mar 25 15:47:33 2013
@@ -241,6 +241,7 @@
 #include "asterisk/uuid.h"
 #include "asterisk/sorcery.h"
 #include "asterisk/stasis.h"
+#include "asterisk/json.h"
 
 #include "../defaults.h"
 
@@ -4070,6 +4071,7 @@
 			ast_el_read_history(filename);
 	}
 
+	ast_json_init();
 	ast_ulaw_init();
 	ast_alaw_init();
 	tdd_init();

Modified: team/dlee/stasis-http/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/channel.c?view=diff&rev=383776&r1=383775&r2=383776
==============================================================================
--- team/dlee/stasis-http/main/channel.c (original)
+++ team/dlee/stasis-http/main/channel.c Mon Mar 25 15:47:33 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,46 +243,85 @@
 	stasis_publish(ast_channel_topic(chan), message);
 }
 
-static void channel_varset_dtor(void *obj)
-{
-	struct ast_channel_varset *event = obj;
+static void publish_channel_blob(struct ast_channel *chan, struct ast_json *blob)
+{
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+	if (blob) {
+		message = ast_channel_blob_create(chan, blob);
+	}
+	if (message) {
+		stasis_publish(ast_channel_topic(chan), message);
+	}
+}
+
+
+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) {
-		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);
-	if (!msg) {
-		return;
-	}
-
-	if (chan) {
-		stasis_publish(ast_channel_topic(chan), msg);
-	} else {
-		stasis_publish(ast_channel_topic_all(), msg);
-	}
+	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);
+	publish_channel_blob(chan, blob);
 }
 
 
@@ -1421,22 +1460,16 @@
 /*! \brief Queue a hangup frame for channel */
 int ast_queue_hangup(struct ast_channel *chan)
 {
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
 	int res;
 
 	/* Yeah, let's not change a lock-critical value without locking */
 	ast_channel_lock(chan);
 	ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a hangup is requested with no set cause.</synopsis>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_CALL, "HangupRequest",
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan));
+	blob = ast_json_pack("{s: s}", "type", "hangup_request");
+	publish_channel_blob(chan, blob);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -1446,6 +1479,8 @@
 /*! \brief Queue a hangup frame for channel */
 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
 {
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
 	int res;
 
@@ -1459,21 +1494,10 @@
 	if (cause < 0) {
 		f.data.uint32 = ast_channel_hangupcause(chan);
 	}
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a hangup is requested with a specific cause code.</synopsis>
-				<syntax>
-					<xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
-				</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_CALL, "HangupRequest",
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"Cause: %d\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan),
-		cause);
+	blob = ast_json_pack("{s: s, s: i}",
+			     "type", "hangup_request",
+			     "cause", cause);
+	publish_channel_blob(chan, blob);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -2776,25 +2800,16 @@
 /*! \brief Softly hangup a channel, lock */
 int ast_softhangup(struct ast_channel *chan, int cause)
 {
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	int res;
 
 	ast_channel_lock(chan);
 	res = ast_softhangup_nolock(chan, cause);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a soft hangup is requested with a specific cause code.</synopsis>
-				<syntax>
-					<xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
-				</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_CALL, "SoftHangupRequest",
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"Cause: %d\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan),
-		cause);
+	blob = ast_json_pack("{s: s, s: i, s: b}",
+			     "type", "hangup_request",
+			     "cause", cause,
+			     "soft", 1);
+	publish_channel_blob(chan, blob);
 	ast_channel_unlock(chan);
 
 	return res;
@@ -6795,39 +6810,6 @@
 }
 
 /*!
- * \pre chan is locked
- */
-static void report_new_callerid(struct ast_channel *chan)
-{
-	int pres;
-
-	pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel receives new Caller ID information.</synopsis>
-			<syntax>
-				<parameter name="CID-CallingPres">
-					<para>A description of the Caller ID presentation.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	ast_manager_event(chan, EVENT_FLAG_CALL, "NewCallerid",
-		"Channel: %s\r\n"
-		"CallerIDNum: %s\r\n"
-		"CallerIDName: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"CID-CallingPres: %d (%s)\r\n",
-		ast_channel_name(chan),
-		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
-		S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""),
-		ast_channel_uniqueid(chan),
-		pres,
-		ast_describe_caller_presentation(pres)
-		);
-}
-
-/*!
  * \internal
  * \brief Transfer COLP between target and transferee channels.
  * \since 1.8
@@ -7231,7 +7213,7 @@
 	ast_channel_redirecting_set(original, ast_channel_redirecting(clonechan));
 	ast_channel_redirecting_set(clonechan, &exchange.redirecting);
 
-	report_new_callerid(original);
+	publish_channel_state(original);
 
 	/* Restore original timing file descriptor */
 	ast_channel_set_fd(original, AST_TIMING_FD, ast_channel_timingfd(original));
@@ -7397,7 +7379,7 @@
 		ast_cdr_setcid(ast_channel_cdr(chan), chan);
 	}
 
-	report_new_callerid(chan);
+	publish_channel_state(chan);
 
 	ast_channel_unlock(chan);
 }
@@ -7416,26 +7398,14 @@
 
 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 {
-	const char *pre_set_number;
-	const char *pre_set_name;
-
 	if (ast_channel_caller(chan) == caller) {
 		/* Don't set to self */
 		return;
 	}
 
 	ast_channel_lock(chan);
-	pre_set_number =
-		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL);
-	pre_set_name = S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL);
 	ast_party_caller_set(ast_channel_caller(chan), caller, update);
-	if (S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)
-			!= pre_set_number
-		|| S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL)
-			!= pre_set_name) {
-		/* The caller id name or number changed. */
-		report_new_callerid(chan);
-	}
+	publish_channel_state(chan);
 	if (ast_channel_cdr(chan)) {
 		ast_cdr_setcid(ast_channel_cdr(chan), chan);
 	}
@@ -8629,12 +8599,112 @@
 	prnt(where, "%s", ast_channel_name(chan));
 }
 
+/*!
+ * \brief List of channel variables to append to all channel-related events.
+ */

[... 1269 lines stripped ...]



More information about the asterisk-commits mailing list