summaryrefslogtreecommitdiff
path: root/res/res_xmpp.c
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2017-03-24 12:25:07 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-03-24 12:25:07 -0500
commitf27c1c7dc2318f57566c7cef9d701836c91fe437 (patch)
tree1b53958397c1373514327469dd4ab924fd1103da /res/res_xmpp.c
parent8982d0e0071ca1522760ad4f4f63423171398f81 (diff)
parent98a88e9ffa5f664a7f0e507f83bd9767a912dac6 (diff)
Merge "res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus"
Diffstat (limited to 'res/res_xmpp.c')
-rw-r--r--res/res_xmpp.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index 3589ea0ab..f4a5d8e05 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -1630,6 +1630,35 @@ static int xmpp_resource_immediate(void *obj, void *arg, int flags)
return CMP_MATCH | CMP_STOP;
}
+#define BUDDY_OFFLINE 6
+#define BUDDY_NOT_IN_ROSTER 7
+
+static int get_buddy_status(struct ast_xmpp_client_config *clientcfg, char *screenname, char *resource)
+{
+ int status = BUDDY_OFFLINE;
+ struct ast_xmpp_resource *res;
+ struct ast_xmpp_buddy *buddy = ao2_find(clientcfg->client->buddies, screenname, OBJ_KEY);
+
+ if (!buddy) {
+ return BUDDY_NOT_IN_ROSTER;
+ }
+
+ res = ao2_callback(
+ buddy->resources,
+ 0,
+ ast_strlen_zero(resource) ? xmpp_resource_immediate : xmpp_resource_cmp,
+ resource);
+
+ if (res) {
+ status = res->status;
+ }
+
+ ao2_cleanup(res);
+ ao2_cleanup(buddy);
+
+ return status;
+}
+
/*
* \internal
* \brief Dial plan function status(). puts the status of watched user
@@ -1643,10 +1672,7 @@ static int xmpp_status_exec(struct ast_channel *chan, const char *data)
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
- struct ast_xmpp_buddy *buddy;
- struct ast_xmpp_resource *resource;
char *s = NULL, status[2];
- int stat = 7;
static int deprecation_warning = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
@@ -1685,25 +1711,7 @@ static int xmpp_status_exec(struct ast_channel *chan, const char *data)
return -1;
}
- if (!(buddy = ao2_find(clientcfg->client->buddies, jid.screenname, OBJ_KEY))) {
- ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
- return -1;
- }
-
- if (ast_strlen_zero(jid.resource) || !(resource = ao2_callback(buddy->resources, 0, xmpp_resource_cmp, jid.resource))) {
- resource = ao2_callback(buddy->resources, OBJ_NODATA, xmpp_resource_immediate, NULL);
- }
-
- ao2_ref(buddy, -1);
-
- if (resource) {
- stat = resource->status;
- ao2_ref(resource, -1);
- } else {
- ast_log(LOG_NOTICE, "Resource '%s' of buddy '%s' was not found\n", jid.resource, jid.screenname);
- }
-
- snprintf(status, sizeof(status), "%d", stat);
+ snprintf(status, sizeof(status), "%d", get_buddy_status(clientcfg, jid.screenname, jid.resource));
pbx_builtin_setvar_helper(chan, args.variable, status);
return 0;
@@ -1722,9 +1730,6 @@ static int acf_jabberstatus_read(struct ast_channel *chan, const char *name, cha
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
- struct ast_xmpp_buddy *buddy;
- struct ast_xmpp_resource *resource;
- int stat = 7;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(jid);
@@ -1756,25 +1761,7 @@ static int acf_jabberstatus_read(struct ast_channel *chan, const char *name, cha
return -1;
}
- if (!(buddy = ao2_find(clientcfg->client->buddies, jid.screenname, OBJ_KEY))) {
- ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
- return -1;
- }
-
- if (ast_strlen_zero(jid.resource) || !(resource = ao2_callback(buddy->resources, 0, xmpp_resource_cmp, jid.resource))) {
- resource = ao2_callback(buddy->resources, OBJ_NODATA, xmpp_resource_immediate, NULL);
- }
-
- ao2_ref(buddy, -1);
-
- if (resource) {
- stat = resource->status;
- ao2_ref(resource, -1);
- } else {
- ast_log(LOG_NOTICE, "Resource %s of buddy %s was not found.\n", jid.resource, jid.screenname);
- }
-
- snprintf(buf, buflen, "%d", stat);
+ snprintf(buf, buflen, "%d", get_buddy_status(clientcfg, jid.screenname, jid.resource));
return 0;
}