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!


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383283 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/78/78/1
Joshua Colp 13 years ago
parent 2f89b7a6eb
commit 5d45596f62

@ -117,6 +117,14 @@ RTP
them, an Asterisk-specific version of pjproject needs to be installed. them, an Asterisk-specific version of pjproject needs to be installed.
Tarballs are available from https://github.com/asterisk/pjproject/tags/. 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 -------------------- --- Functionality changes from Asterisk 10 to Asterisk 11 --------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

@ -3244,6 +3244,14 @@ static int xmpp_client_send_disco_info_request(struct ast_xmpp_client *client, c
return res; 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 */ /*! \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) static int xmpp_pak_presence(struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, iks *node, ikspak *pak)
{ {
@ -3251,6 +3259,7 @@ static int xmpp_pak_presence(struct ast_xmpp_client *client, struct ast_xmpp_cli
struct ast_xmpp_resource *resource; struct ast_xmpp_resource *resource;
char *type = iks_find_attrib(pak->x, "type"); char *type = iks_find_attrib(pak->x, "type");
int status = pak->show ? pak->show : STATUS_DISAPPEAR; 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 no resource is available this is a general buddy presence update, which we will ignore */
if (!pak->from->resource) { if (!pak->from->resource) {
@ -3357,10 +3366,18 @@ static int xmpp_pak_presence(struct ast_xmpp_client *client, struct ast_xmpp_cli
client->name, pak->from->partial, pak->show ? pak->show : IKS_SHOW_UNAVAILABLE); 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_unlock(buddy->resources);
ao2_ref(buddy, -1); ao2_ref(buddy, -1);
ast_devstate_changed(state, AST_DEVSTATE_CACHABLE, "XMPP/%s/%s", client->name, pak->from->partial);
return 0; return 0;
} }

Loading…
Cancel
Save