diff options
Diffstat (limited to 'res/res_xmpp.c')
-rw-r--r-- | res/res_xmpp.c | 109 |
1 files changed, 51 insertions, 58 deletions
diff --git a/res/res_xmpp.c b/res/res_xmpp.c index fa07c0dcc..11fbd2aeb 100644 --- a/res/res_xmpp.c +++ b/res/res_xmpp.c @@ -1632,6 +1632,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 @@ -1645,10 +1674,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); @@ -1687,25 +1713,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; @@ -1724,9 +1732,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); @@ -1758,25 +1763,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; } @@ -2564,10 +2551,16 @@ static void xmpp_log_hook(void *data, const char *xmpp, size_t size, int incomin static int xmpp_client_send_raw_message(struct ast_xmpp_client *client, const char *message) { int ret; -#ifdef HAVE_OPENSSL - int len = strlen(message); + if (client->state == XMPP_STATE_DISCONNECTED) { + /* iks_send_raw will crash without a connection */ + return IKS_NET_NOCONN; + } + +#ifdef HAVE_OPENSSL if (xmpp_is_secure(client)) { + int len = strlen(message); + ret = SSL_write(client->ssl_session, message, len); if (ret) { /* Log the message here, because iksemel's logHook is @@ -3754,12 +3747,12 @@ static void *xmpp_client_thread(void *data) do { if (client->state == XMPP_STATE_DISCONNECTING) { - ast_debug(1, "JABBER: Disconnecting client '%s'\n", client->name); + ast_debug(1, "[%s] Disconnecting\n", client->name); break; } if (res == IKS_NET_RWERR || client->timeout == 0) { - ast_debug(3, "Connecting client '%s'\n", client->name); + ast_debug(3, "[%s] Connecting\n", client->name); if ((res = xmpp_client_reconnect(client)) != IKS_OK) { sleep(4); res = IKS_NET_RWERR; @@ -3776,9 +3769,9 @@ static void *xmpp_client_thread(void *data) } if (res == IKS_HOOK) { - ast_debug(2, "JABBER: Got hook event.\n"); + ast_debug(2, "[%s] Got hook event\n", client->name); } else if (res == IKS_NET_TLSFAIL) { - ast_log(LOG_ERROR, "JABBER: Failure in TLS.\n"); + ast_log(LOG_ERROR, "[%s] TLS failure\n", client->name); } else if (!client->timeout && client->state == XMPP_STATE_CONNECTED) { RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup); @@ -3796,22 +3789,22 @@ static void *xmpp_client_thread(void *data) if (res == IKS_OK) { client->timeout = 50; } else { - ast_log(LOG_WARNING, "JABBER: Network Timeout\n"); + ast_log(LOG_WARNING, "[%s] Network timeout\n", client->name); } } else if (res == IKS_NET_RWERR) { - ast_log(LOG_WARNING, "JABBER: socket read error\n"); + ast_log(LOG_WARNING, "[%s] Socket read error\n", client->name); } else if (res == IKS_NET_NOSOCK) { - ast_log(LOG_WARNING, "JABBER: No Socket\n"); + ast_log(LOG_WARNING, "[%s] No socket\n", client->name); } else if (res == IKS_NET_NOCONN) { - ast_log(LOG_WARNING, "JABBER: No Connection\n"); + ast_log(LOG_WARNING, "[%s] No connection\n", client->name); } else if (res == IKS_NET_NODNS) { - ast_log(LOG_WARNING, "JABBER: No DNS\n"); + ast_log(LOG_WARNING, "[%s] No DNS\n", client->name); } else if (res == IKS_NET_NOTSUPP) { - ast_log(LOG_WARNING, "JABBER: Not Supported\n"); + ast_log(LOG_WARNING, "[%s] Not supported\n", client->name); } else if (res == IKS_NET_DROPPED) { - ast_log(LOG_WARNING, "JABBER: Dropped?\n"); + ast_log(LOG_WARNING, "[%s] Dropped?\n", client->name); } else if (res == IKS_NET_UNKNOWN) { - ast_debug(5, "JABBER: Unknown\n"); + ast_debug(5, "[%s] Unknown\n", client->name); } } while (1); |