[asterisk-commits] file: trunk r383283 - in /trunk: CHANGES res/res_xmpp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Mar 16 10:40:32 CDT 2013


Author: file
Date: Sat Mar 16 10:40:31 2013
New Revision: 383283

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383283
Log:
Add support for using XMPP buddy state via device state.

This change allows you to use XMPP buddy state in places where device state
can be used be used, such as dialplan hints. If at least one resource is
available the buddy is considered available. Now your phone can reflect
their IM status too!

Modified:
    trunk/CHANGES
    trunk/res/res_xmpp.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=383283&r1=383282&r2=383283
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Sat Mar 16 10:40:31 2013
@@ -116,6 +116,14 @@
  * ICE/STUN/TURN support in res_rtp_asterisk has been made optional.  To enable
    them, an Asterisk-specific version of pjproject needs to be installed.
    Tarballs are available from https://github.com/asterisk/pjproject/tags/.
+
+XMPP
+------------------
+ * Device state for XMPP buddies is now available using the following format:
+   XMPP/<client name>/<buddy address>
+   If any resource is available the device state is considered to be not in use.
+   If no resources exist or all are unavailable the device state is considered
+   to be unavailable.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 10 to Asterisk 11 --------------------

Modified: trunk/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_xmpp.c?view=diff&rev=383283&r1=383282&r2=383283
==============================================================================
--- trunk/res/res_xmpp.c (original)
+++ trunk/res/res_xmpp.c Sat Mar 16 10:40:31 2013
@@ -3244,6 +3244,14 @@
 	return res;
 }
 
+/*! \brief Callback function which returns when the resource is available */
+static int xmpp_resource_is_available(void *obj, void *arg, int flags)
+{
+	struct ast_xmpp_resource *resource = obj;
+
+	return (resource->status == IKS_SHOW_AVAILABLE) ? CMP_MATCH | CMP_STOP : 0;
+}
+
 /*! \brief Internal function called when a presence message is received */
 static int xmpp_pak_presence(struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, iks *node, ikspak *pak)
 {
@@ -3251,6 +3259,7 @@
 	struct ast_xmpp_resource *resource;
 	char *type = iks_find_attrib(pak->x, "type");
 	int status = pak->show ? pak->show : STATUS_DISAPPEAR;
+	enum ast_device_state state = AST_DEVICE_UNAVAILABLE;
 
 	/* If no resource is available this is a general buddy presence update, which we will ignore */
 	if (!pak->from->resource) {
@@ -3357,9 +3366,17 @@
 			      client->name, pak->from->partial, pak->show ? pak->show : IKS_SHOW_UNAVAILABLE);
 	}
 
+	/* Determine if at least one resource is available for device state purposes */
+	if ((resource = ao2_callback(buddy->resources, OBJ_NOLOCK, xmpp_resource_is_available, NULL))) {
+		state = AST_DEVICE_NOT_INUSE;
+		ao2_ref(resource, -1);
+	}
+
 	ao2_unlock(buddy->resources);
 
 	ao2_ref(buddy, -1);
+
+	ast_devstate_changed(state, AST_DEVSTATE_CACHABLE, "XMPP/%s/%s", client->name, pak->from->partial);
 
 	return 0;
 }




More information about the asterisk-commits mailing list