[asterisk-commits] dlee: branch dlee/endpoints r386255 - in /team/dlee/endpoints: ./ apps/ confi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 22 10:28:42 CDT 2013


Author: dlee
Date: Mon Apr 22 10:28:35 2013
New Revision: 386255

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386255
Log:
Merged revisions 385835-386232 from http://svn.asterisk.org/svn/asterisk/trunk

Added:
    team/dlee/endpoints/configs/stasis_http.conf.sample
      - copied unchanged from r386232, trunk/configs/stasis_http.conf.sample
    team/dlee/endpoints/include/asterisk/stasis_http.h
      - copied unchanged from r386232, trunk/include/asterisk/stasis_http.h
    team/dlee/endpoints/res/res_stasis_http.c
      - copied unchanged from r386232, trunk/res/res_stasis_http.c
    team/dlee/endpoints/res/res_stasis_http.exports.in
      - copied unchanged from r386232, trunk/res/res_stasis_http.exports.in
    team/dlee/endpoints/res/res_stasis_http_asterisk.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_asterisk.c
    team/dlee/endpoints/res/res_stasis_http_bridges.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_bridges.c
    team/dlee/endpoints/res/res_stasis_http_channels.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_channels.c
    team/dlee/endpoints/res/res_stasis_http_endpoints.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_endpoints.c
    team/dlee/endpoints/res/res_stasis_http_events.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_events.c
    team/dlee/endpoints/res/res_stasis_http_playback.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_playback.c
    team/dlee/endpoints/res/res_stasis_http_recordings.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_recordings.c
    team/dlee/endpoints/res/res_stasis_http_sounds.c
      - copied unchanged from r386232, trunk/res/res_stasis_http_sounds.c
    team/dlee/endpoints/res/stasis_http/   (props changed)
      - copied from r386232, trunk/res/stasis_http/
    team/dlee/endpoints/res/stasis_http.make
      - copied unchanged from r386232, trunk/res/stasis_http.make
    team/dlee/endpoints/rest-api/
      - copied from r386232, trunk/rest-api/
    team/dlee/endpoints/rest-api-templates/   (props changed)
      - copied from r386232, trunk/rest-api-templates/
    team/dlee/endpoints/tests/test_stasis_http.c
      - copied unchanged from r386232, trunk/tests/test_stasis_http.c
Modified:
    team/dlee/endpoints/   (props changed)
    team/dlee/endpoints/Makefile
    team/dlee/endpoints/apps/app_meetme.c
    team/dlee/endpoints/apps/app_queue.c
    team/dlee/endpoints/funcs/func_presencestate.c
    team/dlee/endpoints/include/asterisk/devicestate.h
    team/dlee/endpoints/include/asterisk/http.h
    team/dlee/endpoints/include/asterisk/http_websocket.h
    team/dlee/endpoints/include/asterisk/json.h
    team/dlee/endpoints/include/asterisk/presencestate.h
    team/dlee/endpoints/include/asterisk/srv.h
    team/dlee/endpoints/include/asterisk/stasis_app.h
    team/dlee/endpoints/include/asterisk/stasis_channels.h
    team/dlee/endpoints/include/asterisk/strings.h
    team/dlee/endpoints/include/asterisk/xmpp.h
    team/dlee/endpoints/main/asterisk.c
    team/dlee/endpoints/main/ccss.c
    team/dlee/endpoints/main/cli.c
    team/dlee/endpoints/main/devicestate.c
    team/dlee/endpoints/main/http.c
    team/dlee/endpoints/main/json.c
    team/dlee/endpoints/main/message.c
    team/dlee/endpoints/main/pbx.c
    team/dlee/endpoints/main/presencestate.c
    team/dlee/endpoints/res/Makefile
    team/dlee/endpoints/res/res_corosync.c
    team/dlee/endpoints/res/res_http_websocket.c
    team/dlee/endpoints/res/res_jabber.c
    team/dlee/endpoints/res/res_stasis.c
    team/dlee/endpoints/res/res_timing_pthread.c
    team/dlee/endpoints/res/res_xmpp.c
    team/dlee/endpoints/tests/test_devicestate.c
    team/dlee/endpoints/tests/test_stasis.c
    team/dlee/endpoints/tests/test_strings.c

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

Propchange: team/dlee/endpoints/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Apr 22 10:28:35 2013
@@ -1,1 +1,1 @@
-/trunk:1-385833
+/trunk:1-386236

Modified: team/dlee/endpoints/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/Makefile?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/Makefile (original)
+++ team/dlee/endpoints/Makefile Mon Apr 22 10:28:35 2013
@@ -453,6 +453,9 @@
 		$(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/images" ; \
 	done
 	$(MAKE) -C sounds install
+	find rest-api -name "*.json" | while read x; do \
+		$(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/rest-api" ; \
+	done
 
 ifneq ($(GREP),)
   XML_core_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
@@ -537,8 +540,8 @@
 	"$(ASTLOGDIR)/cel-custom" "$(ASTDATADIR)" "$(ASTDATADIR)/documentation" \
 	"$(ASTDATADIR)/documentation/thirdparty" "$(ASTDATADIR)/firmware" \
 	"$(ASTDATADIR)/firmware/iax" "$(ASTDATADIR)/images" "$(ASTDATADIR)/keys" \
-	"$(ASTDATADIR)/phoneprov" "$(ASTDATADIR)/static-http" "$(ASTDATADIR)/sounds" \
-	"$(ASTDATADIR)/moh" "$(ASTMANDIR)/man8" "$(AGI_DIR)" "$(ASTDBDIR)"
+	"$(ASTDATADIR)/phoneprov" "$(ASTDATADIR)/rest-api" "$(ASTDATADIR)/static-http" \
+	"$(ASTDATADIR)/sounds" "$(ASTDATADIR)/moh" "$(ASTMANDIR)/man8" "$(AGI_DIR)" "$(ASTDBDIR)"
 
 installdirs:
 	@for i in $(INSTALLDIRS); do \
@@ -958,6 +961,19 @@
 	@cat sounds/sounds.xml >> $@
 	@echo "</menu>" >> $@
 
+# We don't want to require Python or Pystache for every build, so this is its
+# own target.
+stasis-stubs:
+ifeq ($(PYTHON),:)
+	@echo "--------------------------------------------------------------------------"
+	@echo "---        Please install python to build Stasis HTTP stubs            ---"
+	@echo "--------------------------------------------------------------------------"
+	@false
+else
+	$(PYTHON) rest-api-templates/make_stasis_http_stubs.py \
+		rest-api/resources.json res/
+endif
+
 .PHONY: menuselect
 .PHONY: main
 .PHONY: sounds
@@ -977,6 +993,7 @@
 .PHONY: installdirs
 .PHONY: validate-docs
 .PHONY: _clean
+.PHONY: stasis-stubs
 .PHONY: $(SUBDIRS_INSTALL)
 .PHONY: $(SUBDIRS_DIST_CLEAN)
 .PHONY: $(SUBDIRS_CLEAN)

Modified: team/dlee/endpoints/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/apps/app_meetme.c?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/apps/app_meetme.c (original)
+++ team/dlee/endpoints/apps/app_meetme.c Mon Apr 22 10:28:35 2013
@@ -6437,17 +6437,18 @@
 
 static int sla_load_config(int reload);
 
-/*! \brief Check if we can do a reload of SLA, and do it if we can */
+/*!
+ * \internal
+ * \brief Check if we can do a reload of SLA, and do it if we can
+ * \pre sla.lock is locked.
+ */
 static void sla_check_reload(void)
 {
 	struct sla_station *station;
 	struct sla_trunk *trunk;
 
-	ast_mutex_lock(&sla.lock);
-
 	if (!AST_LIST_EMPTY(&sla.event_q) || !AST_LIST_EMPTY(&sla.ringing_trunks) 
 		|| !AST_LIST_EMPTY(&sla.ringing_stations)) {
-		ast_mutex_unlock(&sla.lock);
 		return;
 	}
 
@@ -6458,7 +6459,6 @@
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);
 	if (station) {
-		ast_mutex_unlock(&sla.lock);
 		return;
 	}
 
@@ -6469,15 +6469,12 @@
 	}
 	AST_RWLIST_UNLOCK(&sla_trunks);
 	if (trunk) {
-		ast_mutex_unlock(&sla.lock);
 		return;
 	}
 
 	/* yay */
 	sla_load_config(1);
 	sla.reload = 0;
-
-	ast_mutex_unlock(&sla.lock);
 }
 
 static void *sla_thread(void *data)

Modified: team/dlee/endpoints/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/apps/app_queue.c?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/apps/app_queue.c (original)
+++ team/dlee/endpoints/apps/app_queue.c Mon Apr 22 10:28:35 2013
@@ -990,9 +990,6 @@
 	{ QUEUE_AUTOPAUSE_ALL,"all" },
 };
 
-
-static struct ast_taskprocessor *devicestate_tps;
-
 #define DEFAULT_RETRY		5
 #define DEFAULT_TIMEOUT		15
 #define RECHECK			1		/*!< Recheck every second to see we we're at the top yet */
@@ -1037,8 +1034,8 @@
 /*! \brief queues.conf [general] option */
 static int shared_lastcall = 1;
 
-/*! \brief Subscription to device state change events */
-static struct ast_event_sub *device_state_sub;
+/*! \brief Subscription to device state change messages */
+static struct stasis_subscription *device_state_sub;
 
 /*! \brief queues.conf [general] option */
 static int update_cdr = 0;
@@ -1618,12 +1615,6 @@
 	return -1;
 }
 
-struct statechange {
-	AST_LIST_ENTRY(statechange) entry;
-	int state;
-	char dev[0];
-};
-
 /*! \brief set a member's status based on device state of that member's state_interface.
  *
  * Lock interface list find sc, iterate through each queues queue_member list for member to
@@ -1742,10 +1733,10 @@
 }
 
 /*! \brief set a member's status based on device state of that member's interface*/
-static int handle_statechange(void *datap)
-{
-	struct statechange *sc = datap;
+static void device_state_cb(void *unused, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
+{
 	struct ao2_iterator miter, qiter;
+	struct ast_device_state_message *dev_state;
 	struct member *m;
 	struct call_queue *q;
 	char interface[80], *slash_pos;
@@ -1753,6 +1744,16 @@
 	int found_member;		/* Found this member in this queue */
 	int avail = 0;			/* Found an available member in this queue */
 
+	if (ast_device_state_message_type() != stasis_message_type(msg)) {
+		return;
+	}
+
+	dev_state = stasis_message_data(msg);
+	if (dev_state->eid) {
+		/* ignore non-aggregate states */
+		return;
+	}
+
 	qiter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) {
 		ao2_lock(q);
@@ -1770,9 +1771,9 @@
 					}
 				}
 
-				if (!strcasecmp(interface, sc->dev)) {
+				if (!strcasecmp(interface, dev_state->device)) {
 					found_member = 1;
-					update_status(q, m, sc->state);
+					update_status(q, m, dev_state->state);
 				}
 			}
 
@@ -1804,39 +1805,18 @@
 	ao2_iterator_destroy(&qiter);
 
 	if (found) {
-		ast_debug(1, "Device '%s' changed to state '%d' (%s)\n", sc->dev, sc->state, ast_devstate2str(sc->state));
+		ast_debug(1, "Device '%s' changed to state '%d' (%s)\n",
+			dev_state->device,
+			dev_state->state,
+			ast_devstate2str(dev_state->state));
 	} else {
-		ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", sc->dev, sc->state, ast_devstate2str(sc->state));
-	}
-
-	ast_free(sc);
-	return 0;
-}
-
-static void device_state_cb(const struct ast_event *event, void *unused)
-{
-	enum ast_device_state state;
-	const char *device;
-	struct statechange *sc;
-	size_t datapsize;
-
-	state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
-	device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE);
-
-	if (ast_strlen_zero(device)) {
-		ast_log(LOG_ERROR, "Received invalid event that had no device IE\n");
-		return;
-	}
-	datapsize = sizeof(*sc) + strlen(device) + 1;
-	if (!(sc = ast_calloc(1, datapsize))) {
-		ast_log(LOG_ERROR, "failed to calloc a state change struct\n");
-		return;
-	}
-	sc->state = state;
-	strcpy(sc->dev, device);
-	if (ast_taskprocessor_push(devicestate_tps, handle_statechange, sc) < 0) {
-		ast_free(sc);
-	}
+		ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n",
+			dev_state->device,
+			dev_state->state,
+			ast_devstate2str(dev_state->state));
+	}
+
+	return;
 }
 
 /*! \brief Helper function which converts from extension state to device state values */
@@ -9876,8 +9856,9 @@
 
 	res |= ast_data_unregister(NULL);
 
-	if (device_state_sub)
-		ast_event_unsubscribe(device_state_sub);
+	if (device_state_sub) {
+		device_state_sub = stasis_unsubscribe(device_state_sub);
+	}
 
 	ast_extension_state_del(0, extension_state_cb);
 
@@ -9887,7 +9868,6 @@
 		queue_t_unref(q, "Done with iterator");
 	}
 	ao2_iterator_destroy(&q_iter);
-	devicestate_tps = ast_taskprocessor_unreference(devicestate_tps);
 	ao2_ref(queues, -1);
 	ast_unload_realtime("queue_members");
 	return res;
@@ -9948,12 +9928,8 @@
 	res |= ast_custom_function_register(&queuewaitingcount_function);
 	res |= ast_custom_function_register(&queuememberpenalty_function);
 
-	if (!(devicestate_tps = ast_taskprocessor_get("app_queue", 0))) {
-		ast_log(LOG_WARNING, "devicestate taskprocessor reference failed - devicestate notifications will not occur\n");
-	}
-
 	/* in the following subscribe call, do I use DEVICE_STATE, or DEVICE_STATE_CHANGE? */
-	if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, "AppQueue Device state", NULL, AST_EVENT_IE_END))) {
+	if (!(device_state_sub = stasis_subscribe(ast_device_state_topic_all(), device_state_cb, NULL))) {
 		res = -1;
 	}
 

Modified: team/dlee/endpoints/funcs/func_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/funcs/func_presencestate.c?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/funcs/func_presencestate.c (original)
+++ team/dlee/endpoints/funcs/func_presencestate.c Mon Apr 22 10:28:35 2013
@@ -645,21 +645,20 @@
 }
 
 struct test_cb_data {
-	enum ast_presence_state presence;
-	const char *provider;
-	const char *subtype;
-	const char *message;
+	struct ast_presence_state_message *presence_state;
 	/* That's right. I'm using a semaphore */
 	sem_t sem;
 };
 
-static void test_cb(const struct ast_event *event, void *userdata)
+static void test_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
 {
 	struct test_cb_data *cb_data = userdata;
-	cb_data->presence = ast_event_get_ie_uint(event, AST_EVENT_IE_PRESENCE_STATE);
-	cb_data->provider = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_PROVIDER));
-	cb_data->subtype = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_SUBTYPE));
-	cb_data->message = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_MESSAGE));
+	if (stasis_message_type(msg) != ast_presence_state_message_type()) {
+		return;
+	}
+	cb_data->presence_state = stasis_message_data(msg);
+	ao2_ref(cb_data->presence_state, +1);
+
 	sem_post(&cb_data->sem);
 }
 
@@ -670,7 +669,7 @@
  */
 AST_TEST_DEFINE(test_presence_state_change)
 {
-	struct ast_event_sub *test_sub;
+	struct stasis_subscription *test_sub;
 	struct test_cb_data *cb_data;
 
 	switch (cmd) {
@@ -690,8 +689,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (!(test_sub = ast_event_subscribe(AST_EVENT_PRESENCE_STATE,
-			test_cb, "Test presence state callbacks", cb_data, AST_EVENT_IE_END))) {
+	if (!(test_sub = stasis_subscribe(ast_presence_state_topic_all(), test_cb, cb_data))) {
 		return AST_TEST_FAIL;
 	}
 
@@ -701,16 +699,16 @@
 
 	presence_write(NULL, "PRESENCESTATE", "CustomPresence:TestPresenceStateChange", "away,down the hall,Quarterly financial meeting");
 	sem_wait(&cb_data->sem);
-	if (cb_data->presence != AST_PRESENCE_AWAY ||
-			strcmp(cb_data->provider, "CustomPresence:TestPresenceStateChange") ||
-			strcmp(cb_data->subtype, "down the hall") ||
-			strcmp(cb_data->message, "Quarterly financial meeting")) {
+	if (cb_data->presence_state->state != AST_PRESENCE_AWAY ||
+			strcmp(cb_data->presence_state->provider, "CustomPresence:TestPresenceStateChange") ||
+			strcmp(cb_data->presence_state->subtype, "down the hall") ||
+			strcmp(cb_data->presence_state->message, "Quarterly financial meeting")) {
 		return AST_TEST_FAIL;
 	}
 
-	ast_free((char *)cb_data->provider);
-	ast_free((char *)cb_data->subtype);
-	ast_free((char *)cb_data->message);
+	test_sub = stasis_unsubscribe(test_sub);
+
+	ao2_cleanup(cb_data->presence_state);
 	ast_free((char *)cb_data);
 
 	ast_db_del("CustomPresence", "TestPresenceStateChange");

Modified: team/dlee/endpoints/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/devicestate.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/devicestate.h (original)
+++ team/dlee/endpoints/include/asterisk/devicestate.h Mon Apr 22 10:28:35 2013
@@ -38,6 +38,7 @@
 #define _ASTERISK_DEVICESTATE_H
 
 #include "asterisk/channelstate.h"
+#include "asterisk/utils.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
@@ -270,19 +271,87 @@
 };
 
 /*!
- * \brief Enable distributed device state processing.
- *
- * \details
- * By default, Asterisk assumes that device state change events will only be
- * originating from one instance.  If a module gets loaded and configured such
- * that multiple instances of Asterisk will be sharing device state, this
- * function should be called to enable distributed device state processing.
- * It is off by default to save on unnecessary processing.
- *
- * \retval 0 success
- * \retval -1 failure
- */
-int ast_enable_distributed_devstate(void);
+ * \brief The structure that contains device state
+ * \since 12
+ */
+struct ast_device_state_message {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(cache_id);	/*!< A unique ID used for hashing */
+		AST_STRING_FIELD(device);	/*!< The name of the device */
+	);
+	enum ast_device_state state;		/*!< The state of the device */
+	struct ast_eid *eid;			/*!< The EID of the server where this message originated, NULL EID means aggregate state */
+	enum ast_devstate_cache cachable;	/*!< Flag designating the cachability of this device state */
+};
+
+/*!
+ * \brief Get the Stasis topic for device state messages
+ * \retval The topic for device state messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_topic *ast_device_state_topic_all(void);
+
+/*!
+ * \brief Get the Stasis topic for device state messages for a specific device
+ * \param uniqueid The device for which to get the topic
+ * \retval The topic structure for MWI messages for a given device
+ * \retval NULL if it failed to be found or allocated
+ * \since 12
+ */
+struct stasis_topic *ast_device_state_topic(const char *device);
+
+/*!
+ * \brief Get the Stasis caching topic for device state messages
+ * \retval The caching topic for device state messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_caching_topic *ast_device_state_topic_cached(void);
+
+/*!
+ * \brief Get the Stasis message type for device state messages
+ * \retval The message type for device state messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_message_type *ast_device_state_message_type(void);
+
+/*!
+ * \brief Initialize the device state core
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+int devstate_init(void);
+
+/*!
+ * \brief Publish a device state update
+ * \param[in] device The device name
+ * \param[in] state The state of the device
+ * \param[in] cachable Whether the device state can be cached
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+#define ast_publish_device_state(device, state, cachable) \
+	ast_publish_device_state_full(device, state, cachable, &ast_eid_default)
+
+/*!
+ * \brief Publish a device state update with EID
+ * \param[in] device The device name
+ * \param[in] state The state of the device
+ * \param[in] cachable Whether the device state can be cached
+ * \param[in] eid The EID of the server that originally published the message
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+int ast_publish_device_state_full(
+			const char *device,
+			enum ast_device_state state,
+			enum ast_devstate_cache cachable,
+			struct ast_eid *eid);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/dlee/endpoints/include/asterisk/http.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/http.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/http.h (original)
+++ team/dlee/endpoints/include/asterisk/http.h Mon Apr 22 10:28:35 2013
@@ -58,7 +58,10 @@
 	AST_HTTP_GET = 0,
 	AST_HTTP_POST,
 	AST_HTTP_HEAD,
-	AST_HTTP_PUT,            /*!< Not supported in Asterisk */
+	AST_HTTP_PUT,
+	AST_HTTP_DELETE,
+	AST_HTTP_OPTIONS,
+	AST_HTTP_MAX_METHOD, /*!< Last entry in ast_http_method enum */
 };
 
 struct ast_http_uri;

Modified: team/dlee/endpoints/include/asterisk/http_websocket.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/http_websocket.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/http_websocket.h (original)
+++ team/dlee/endpoints/include/asterisk/http_websocket.h Mon Apr 22 10:28:35 2013
@@ -19,6 +19,7 @@
 #ifndef _ASTERISK_HTTP_WEBSOCKET_H
 #define _ASTERISK_HTTP_WEBSOCKET_H
 
+#include "asterisk/http.h"
 #include "asterisk/optional_api.h"
 
 /*!
@@ -40,7 +41,13 @@
 };
 
 /*!
- * \brief Opaque structure for WebSocket sessions
+ * \brief Opaque structure for WebSocket server.
+ * \since 12
+ */
+struct ast_websocket_server;
+
+/*!
+ * \brief Opaque structure for WebSocket sessions.
  */
 struct ast_websocket;
 
@@ -58,7 +65,24 @@
 typedef void (*ast_websocket_callback)(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers);
 
 /*!
- * \brief Add a sub-protocol handler to the server
+ * \brief Creates a \ref websocket_server
+ *
+ * \retval New \ref websocket_server instance
+ * \retval \c NULL on error
+ * \since 12
+ */
+struct ast_websocket_server *ast_websocket_server_create(void);
+
+/*!
+ * \brief Callback suitable for use with a \ref ast_http_uri.
+ *
+ * Set the data field of the ast_http_uri to \ref ast_websocket_server.
+ * \since 12
+ */
+int ast_websocket_uri_cb(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers);
+
+/*!
+ * \brief Add a sub-protocol handler to the default /ws server
  *
  * \param name Name of the sub-protocol to register
  * \param callback Callback called when a new connection requesting the sub-protocol is established
@@ -69,7 +93,7 @@
 AST_OPTIONAL_API(int, ast_websocket_add_protocol, (const char *name, ast_websocket_callback callback), {return -1;});
 
 /*!
- * \brief Remove a sub-protocol handler from the server
+ * \brief Remove a sub-protocol handler from the default /ws server.
  *
  * \param name Name of the sub-protocol to unregister
  * \param callback Callback that was previously registered with the sub-protocol
@@ -78,6 +102,30 @@
  * \retval -1 if sub-protocol was not found or if callback did not match
  */
 AST_OPTIONAL_API(int, ast_websocket_remove_protocol, (const char *name, ast_websocket_callback callback), {return -1;});
+
+/*!
+ * \brief Add a sub-protocol handler to the given server.
+ *
+ * \param name Name of the sub-protocol to register
+ * \param callback Callback called when a new connection requesting the sub-protocol is established
+ *
+ * \retval 0 success
+ * \retval -1 if sub-protocol handler could not be registered
+ * \since 12
+ */
+AST_OPTIONAL_API(int, ast_websocket_server_add_protocol, (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback), {return -1;});
+
+/*!
+ * \brief Remove a sub-protocol handler from the given server.
+ *
+ * \param name Name of the sub-protocol to unregister
+ * \param callback Callback that was previously registered with the sub-protocol
+ *
+ * \retval 0 success
+ * \retval -1 if sub-protocol was not found or if callback did not match
+ * \since 12
+ */
+AST_OPTIONAL_API(int, ast_websocket_server_remove_protocol, (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback), {return -1;});
 
 /*!
  * \brief Read a WebSocket frame and handle it

Modified: team/dlee/endpoints/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/json.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/json.h (original)
+++ team/dlee/endpoints/include/asterisk/json.h Mon Apr 22 10:28:35 2013
@@ -586,16 +586,33 @@
 /*!@{*/
 
 /*!
+ * \brief Encoding format type.
+ * \since 12.0.0
+ */
+enum ast_json_encoding_format
+{
+	/*! Compact format, low human readability */
+	AST_JSON_COMPACT,
+	/*! Formatted for human readability */
+	AST_JSON_PRETTY,
+};
+
+#define ast_json_dump_string(root) ast_json_dump_string_format(root, AST_JSON_COMPACT)
+
+/*!
  * \brief Encode a JSON value to a string.
  * \since 12.0.0
  *
  * Returned string must be freed by calling ast_free().
  *
- * \param JSON value.
+ * \param root JSON value.
+ * \param format encoding format type.
  * \return String encoding of \a root.
  * \return \c NULL on error.
  */
-char *ast_json_dump_string(struct ast_json *root);
+char *ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format);
+
+#define ast_json_dump_str(root, dst) ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
 
 /*!
  * \brief Encode a JSON value to an \ref ast_str.
@@ -605,10 +622,13 @@
  *
  * \param root JSON value.
  * \param dst \ref ast_str to store JSON encoding.
+ * \param format encoding format type.
  * \return 0 on success.
  * \return -1 on error. The contents of \a dst are undefined.
  */
-int ast_json_dump_str(struct ast_json *root, struct ast_str **dst);
+int ast_json_dump_str_format(struct ast_json *root, struct ast_str **dst, enum ast_json_encoding_format format);
+
+#define ast_json_dump_file(root, output) ast_json_dump_file_format(root, output, AST_JSON_COMPACT)
 
 /*!
  * \brief Encode a JSON value to a \c FILE.
@@ -616,10 +636,13 @@
  *
  * \param root JSON value.
  * \param output File to write JSON encoding to.
+ * \param format encoding format type.
  * \return 0 on success.
  * \return -1 on error. The contents of \a output are undefined.
  */
-int ast_json_dump_file(struct ast_json *root, FILE *output);
+int ast_json_dump_file_format(struct ast_json *root, FILE *output, enum ast_json_encoding_format format);
+
+#define ast_json_dump_new_file(root, path) ast_json_dump_new_file_format(root, path, AST_JSON_COMPACT)
 
 /*!
  * \brief Encode a JSON value to a file at the given location.
@@ -627,10 +650,11 @@
  *
  * \param root JSON value.
  * \param path Path to file to write JSON encoding to.
+ * \param format encoding format type.
  * \return 0 on success.
  * \return -1 on error. The contents of \a output are undefined.
  */
-int ast_json_dump_new_file(struct ast_json *root, const char *path);
+int ast_json_dump_new_file_format(struct ast_json *root, const char *path, enum ast_json_encoding_format format);
 
 #define AST_JSON_ERROR_TEXT_LENGTH    160
 #define AST_JSON_ERROR_SOURCE_LENGTH   80

Modified: team/dlee/endpoints/include/asterisk/presencestate.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/presencestate.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/presencestate.h (original)
+++ team/dlee/endpoints/include/asterisk/presencestate.h Mon Apr 22 10:28:35 2013
@@ -149,6 +149,40 @@
  */
 int ast_presence_state_prov_del(const char *label);
 
+/*!
+ * \brief Get presence state message type
+ * \retval Stasis message type for presence state messages
+ * \since 12
+ */
+struct stasis_message_type *ast_presence_state_message_type(void);
+
+/*!
+ * \brief Get presence state topic
+ * \retval Stasis topic for presence state messages
+ * \since 12
+ */
+struct stasis_topic *ast_presence_state_topic_all(void);
+
+/*!
+ * \brief Get caching presence state topic
+ * \retval Caching Stasis topic for presence state messages
+ * \since 12
+ */
+struct stasis_caching_topic *ast_presence_state_topic_cached(void);
+
+/*!
+ * \brief Stasis message payload representing a presence state update
+ * \since 12
+ */
+struct ast_presence_state_message {
+		AST_DECLARE_STRING_FIELDS(
+			AST_STRING_FIELD(provider);	/*!< Provider that produced this presence state message */
+			AST_STRING_FIELD(subtype);	/*!< Subtype associated with this presence state message */
+			AST_STRING_FIELD(message);	/*!< The message to convey */
+		);
+		enum ast_presence_state state;		/*!< The state associated with this presence state message */
+};
+
 int ast_presence_state_engine_init(void);
 #endif
 

Modified: team/dlee/endpoints/include/asterisk/srv.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/srv.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/srv.h (original)
+++ team/dlee/endpoints/include/asterisk/srv.h Mon Apr 22 10:28:35 2013
@@ -52,8 +52,7 @@
 
 /*! Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup 
 	Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
-*/
-/*!	\param	chan Ast channel
+!	\param	chan Ast channel
 	\param	host host name (return value)
 	\param	hostlen Length of string "host"
 	\param	port Port number (return value)

Modified: team/dlee/endpoints/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis_app.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_app.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis_app.h Mon Apr 22 10:28:35 2013
@@ -66,7 +66,7 @@
  * \param argv Arguments for the application.
  */
 int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
-		    char *argv[]);
+	char *argv[]);
 
 /*! @} */
 
@@ -126,22 +126,50 @@
 struct stasis_app_control;
 
 /*!
- * \brief Returns the handler for the given channel
+ * \brief Returns the handler for the given channel.
  * \param chan Channel to handle.
- * \return NULL channel not in Stasis application
- * \return Pointer to stasis handler.
+ * \return NULL channel not in Stasis application.
+ * \return Pointer to \c res_stasis handler.
  */
 struct stasis_app_control *stasis_app_control_find_by_channel(
 	const struct ast_channel *chan);
 
 /*!
- * \brief Exit \c app_stasis and continue execution in the dialplan.
+ * \brief Returns the handler for the channel with the given id.
+ * \param channel_id Uniqueid of the channel.
+ * \return NULL channel not in Stasis application, or channel does not exist.
+ * \return Pointer to \c res_stasis handler.
+ */
+struct stasis_app_control *stasis_app_control_find_by_channel_id(
+	const char *channel_id);
+
+/*!
+ * \brief Exit \c res_stasis and continue execution in the dialplan.
  *
- * If the channel is no longer in \c app_stasis, this function does nothing.
+ * If the channel is no longer in \c res_stasis, this function does nothing.
  *
- * \param handler Handler for \c app_stasis
+ * \param control Control for \c res_stasis
  */
-void stasis_app_control_continue(struct stasis_app_control *handler);
+void stasis_app_control_continue(struct stasis_app_control *control);
+
+/*!
+ * \brief Answer the channel associated with this control.
+ * \param control Control for \c res_stasis.
+ * \return 0 for success.
+ * \return -1 for error.
+ */
+int stasis_app_control_answer(struct stasis_app_control *control);
+
+/*! @} */
+
+/*! @{ */
+
+/*!
+ * \brief Build a JSON object from a \ref ast_channel_snapshot.
+ * \return JSON object representing channel snapshot.
+ * \return \c NULL on error
+ */
+struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot);
 
 /*! @} */
 

Modified: team/dlee/endpoints/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis_channels.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_channels.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis_channels.h Mon Apr 22 10:28:35 2013
@@ -34,7 +34,7 @@
  * \brief Structure representing a snapshot of channel state.
  *
  * While not enforced programmatically, this object is shared across multiple
- * threads, and should be threated as an immutable object.
+ * threads, and should be treated as an immutable object.
  */
 struct ast_channel_snapshot {
 	AST_DECLARE_STRING_FIELDS(

Modified: team/dlee/endpoints/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/strings.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/strings.h (original)
+++ team/dlee/endpoints/include/asterisk/strings.h Mon Apr 22 10:28:35 2013
@@ -82,6 +82,48 @@
  */
 #define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
 
+/*
+  \brief Checks whether a string begins with another.
+  \since 12.0.0
+  \param str String to check.
+  \param prefix Prefix to look for.
+  \param 1 if \a str begins with \a prefix, 0 otherwise.
+ */
+static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
+{
+	ast_assert(str != NULL);
+	ast_assert(prefix != NULL);
+	while (*str == *prefix && *prefix != '\0') {
+		++str;
+		++prefix;
+	}
+	return *prefix == '\0';
+}
+
+/*
+  \brief Checks whether a string ends with another.
+  \since 12.0.0
+  \param str String to check.
+  \param suffix Suffix to look for.
+  \param 1 if \a str ends with \a suffix, 0 otherwise.
+ */
+static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
+{
+	size_t str_len;
+	size_t suffix_len;
+
+	ast_assert(str != NULL);
+	ast_assert(suffix != NULL);
+	str_len = strlen(str);
+	suffix_len = strlen(suffix);
+
+	if (suffix_len > str_len) {
+		return 0;
+	}
+
+	return strcmp(str + str_len - suffix_len, suffix) == 0;
+}
+
 /*!
  * \brief return Yes or No depending on the argument.
  *

Modified: team/dlee/endpoints/include/asterisk/xmpp.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/xmpp.h?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/include/asterisk/xmpp.h (original)
+++ team/dlee/endpoints/include/asterisk/xmpp.h Mon Apr 22 10:28:35 2013
@@ -47,6 +47,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/pbx.h"
+#include "asterisk/stasis.h"
 
 /*
  * As per RFC 3920 - section 3.1, the maximum length for a full Jabber ID
@@ -135,7 +136,7 @@
 	int timeout;
 	unsigned int reconnect:1; /*!< Reconnect this client */
 	struct stasis_subscription *mwi_sub; /*!< If distributing event information the MWI subscription */
-	struct ast_event_sub *device_state_sub; /*!< If distributing event information the device state subscription */
+	struct stasis_subscription *device_state_sub; /*!< If distributing event information the device state subscription */
 };
 
 /*!

Modified: team/dlee/endpoints/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/asterisk.c?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/main/asterisk.c (original)
+++ team/dlee/endpoints/main/asterisk.c Mon Apr 22 10:28:35 2013
@@ -4180,6 +4180,11 @@
 
 	aco_init();
 
+	if (devstate_init()) {
+		printf("Device state core initialization failed.\n%s", term_quit());
+		exit(1);
+	}
+
 	if (app_init()) {
 		printf("App core initialization failed.\n%s", term_quit());
 		exit(1);

Modified: team/dlee/endpoints/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/ccss.c?view=diff&rev=386255&r1=386254&r2=386255
==============================================================================
--- team/dlee/endpoints/main/ccss.c (original)
+++ team/dlee/endpoints/main/ccss.c Mon Apr 22 10:28:35 2013
@@ -1209,7 +1209,7 @@
 	 * recalled
 	 */
 	int fit_for_recall;
-	struct ast_event_sub *sub;
+	struct stasis_subscription *sub;
 	AST_LIST_HEAD_NOLOCK(, generic_monitor_instance) list;
 };
 
@@ -1260,19 +1260,20 @@
 	struct generic_monitor_instance_list *generic_list = obj;
 	struct generic_monitor_instance *generic_instance;
 
-	generic_list->sub = ast_event_unsubscribe(generic_list->sub);
+	generic_list->sub = stasis_unsubscribe(generic_list->sub);
 	while ((generic_instance = AST_LIST_REMOVE_HEAD(&generic_list->list, next))) {
 		ast_free(generic_instance);
 	}
 	ast_free((char *)generic_list->device_name);
 }
 
-static void generic_monitor_devstate_cb(const struct ast_event *event, void *userdata);
+static void generic_monitor_devstate_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg);
 static struct generic_monitor_instance_list *create_new_generic_list(struct ast_cc_monitor *monitor)
 {
 	struct generic_monitor_instance_list *generic_list = ao2_t_alloc(sizeof(*generic_list),
 			generic_monitor_instance_list_destructor, "allocate generic monitor instance list");
 	char * device_name;
+	struct stasis_topic *device_specific_topic;
 
 	if (!generic_list) {
 		return NULL;
@@ -1285,11 +1286,12 @@
 	ast_tech_to_upper(device_name);
 	generic_list->device_name = device_name;
 
-	if (!(generic_list->sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE,
-		generic_monitor_devstate_cb, "Requesting CC", NULL,
-		AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, monitor->interface->device_name,
-		AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_EXISTS,
-		AST_EVENT_IE_END))) {
+	device_specific_topic = ast_device_state_topic(device_name);
+	if (!device_specific_topic) {
+		return NULL;
+	}
+
+	if (!(generic_list->sub = stasis_subscribe(device_specific_topic, generic_monitor_devstate_cb, NULL))) {
 		cc_unref(generic_list, "Failed to subscribe to device state");
 		return NULL;
 	}
@@ -1298,35 +1300,25 @@
 	return generic_list;
 }
 
-struct generic_tp_cb_data {
-	const char *device_name;
-	enum ast_device_state new_state;
-};
-
 static int generic_monitor_devstate_tp_cb(void *data)
 {
-	struct generic_tp_cb_data *gtcd = data;
-	enum ast_device_state new_state = gtcd->new_state;
-	enum ast_device_state previous_state = gtcd->new_state;
-	const char *monitor_name = gtcd->device_name;
+	RAII_VAR(struct ast_device_state_message *, dev_state, data, ao2_cleanup);
+	enum ast_device_state new_state = dev_state->state;
+	enum ast_device_state previous_state;
 	struct generic_monitor_instance_list *generic_list;
 	struct generic_monitor_instance *generic_instance;
 
-	if (!(generic_list = find_generic_monitor_instance_list(monitor_name))) {
+	if (!(generic_list = find_generic_monitor_instance_list(dev_state->device))) {
 		/* The most likely cause for this is that we destroyed the monitor in the
 		 * time between subscribing to its device state and the time this executes.
 		 * Not really a big deal.
 		 */
-		ast_free((char *) gtcd->device_name);
-		ast_free(gtcd);
 		return 0;
 	}
 
 	if (generic_list->current_state == new_state) {
 		/* The device state hasn't actually changed, so we don't really care */

[... 3206 lines stripped ...]



More information about the asterisk-commits mailing list