1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00
profanity/src/xmpp/iq.c

1772 lines
58 KiB
C
Raw Normal View History

2013-01-24 00:26:53 +00:00
/*
2013-02-02 19:47:41 +00:00
* iq.c
2013-01-24 00:26:53 +00:00
*
2015-02-10 23:16:09 +00:00
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
2013-01-24 00:26:53 +00:00
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
2013-01-24 00:26:53 +00:00
*/
2013-02-02 20:55:58 +00:00
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
2013-01-24 00:26:53 +00:00
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
2013-05-06 21:00:11 +00:00
#include <glib.h>
#ifdef HAVE_LIBMESODE
#include <mesode.h>
#endif
#ifdef HAVE_LIBSTROPHE
2013-01-24 00:26:53 +00:00
#include <strophe.h>
#endif
2013-01-24 00:26:53 +00:00
#include "log.h"
#include "muc.h"
#include "profanity.h"
#include "ui/ui.h"
#include "window_list.h"
2014-01-26 00:15:34 +00:00
#include "config/preferences.h"
2015-04-19 15:54:16 +00:00
#include "event/server_events.h"
2013-02-02 20:55:58 +00:00
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
2013-02-02 20:55:58 +00:00
#include "xmpp/stanza.h"
2014-09-05 20:04:16 +00:00
#include "xmpp/form.h"
#include "roster_list.h"
#include "xmpp/xmpp.h"
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx)
typedef struct p_room_info_data_t {
char *room;
gboolean display;
} ProfRoomInfoData;
2015-10-26 00:14:23 +00:00
static int _error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _ping_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _version_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _version_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _disco_info_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _disco_info_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _last_activity_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _last_activity_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_info_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _disco_items_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _disco_items_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _destroy_room_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_config_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_config_submit_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_affiliation_list_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_affiliation_set_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_role_set_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_role_list_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _room_kick_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _enable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _disable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _ping_timed_handler(xmpp_conn_t *const conn, void *const userdata);
static int _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
void
iq_add_handlers(void)
2013-01-24 00:26:53 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
2014-01-25 21:41:17 +00:00
2015-09-29 22:55:01 +00:00
HANDLE(NULL, STANZA_TYPE_ERROR, _error_handler);
2014-01-25 21:41:17 +00:00
2015-09-29 22:55:01 +00:00
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _disco_info_get_handler);
2014-01-25 21:41:17 +00:00
2015-09-29 22:55:01 +00:00
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _disco_items_get_handler);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _disco_items_result_handler);
2014-01-25 21:41:17 +00:00
2015-09-29 22:55:01 +00:00
HANDLE(STANZA_NS_LASTACTIVITY, STANZA_TYPE_GET, _last_activity_get_handler);
2015-09-29 22:55:01 +00:00
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _version_get_handler);
2014-01-25 21:41:17 +00:00
2015-09-29 22:55:01 +00:00
HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler);
2014-01-26 00:15:34 +00:00
if (prefs_get_autoping() != 0) {
int millis = prefs_get_autoping() * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx);
}
}
2014-12-22 22:13:42 +00:00
void
iq_set_autoping(const int seconds)
2014-01-26 00:15:34 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (jabber_get_connection_status() == JABBER_CONNECTED) {
xmpp_timed_handler_delete(conn, _ping_timed_handler);
if (seconds != 0) {
int millis = seconds * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis,
ctx);
}
}
}
2013-01-24 00:26:53 +00:00
2014-12-22 22:13:42 +00:00
void
iq_room_list_request(gchar *conferencejid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "confreq", conferencejid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2015-02-02 10:10:05 +00:00
void
2015-10-26 00:14:23 +00:00
iq_enable_carbons(void)
2015-02-02 10:10:05 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_enable_carbons(ctx);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _enable_carbons_handler, id, NULL);
2015-02-02 10:10:05 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void
2015-10-26 00:14:23 +00:00
iq_disable_carbons(void)
2015-02-02 10:10:05 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_disable_carbons(ctx);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _disable_carbons_handler, id, NULL);
2015-02-02 10:10:05 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
iq_disco_info_request(gchar *jid)
2013-03-14 20:50:09 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
2014-09-18 23:49:48 +00:00
char *id = create_unique_id("disco_info");
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, jid, NULL);
xmpp_id_handler_add(conn, _disco_info_response_handler, id, NULL);
2014-11-01 01:48:36 +00:00
free(id);
2014-09-18 23:49:48 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void
iq_last_activity_request(gchar *jid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("lastactivity");
xmpp_stanza_t *iq = stanza_create_last_activity_iq(ctx, id, jid);
xmpp_id_handler_add(conn, _last_activity_response_handler, id, NULL);
free(id);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_info_request(const char *const room, gboolean display_result)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("room_disco_info");
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
ProfRoomInfoData *cb_data = malloc(sizeof(ProfRoomInfoData));
cb_data->room = strdup(room);
cb_data->display = display_result;
xmpp_id_handler_add(conn, _room_info_response_handler, id, cb_data);
2014-11-01 01:48:36 +00:00
free(id);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_send_caps_request_for_jid(const char *const to, const char *const id,
const char *const node, const char *const ver)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (!node) {
log_error("Could not create caps request, no node");
return;
}
if (!ver) {
log_error("Could not create caps request, no ver");
return;
}
GString *node_str = g_string_new("");
g_string_printf(node_str, "%s#%s", node, ver);
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, to, node_str->str);
g_string_free(node_str, TRUE);
2014-11-30 00:37:36 +00:00
xmpp_id_handler_add(conn, _caps_response_handler_for_jid, id, strdup(to));
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_send_caps_request(const char *const to, const char *const id,
const char *const node, const char *const ver)
2014-09-18 23:49:48 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (!node) {
log_error("Could not create caps request, no node");
return;
}
if (!ver) {
log_error("Could not create caps request, no ver");
return;
}
GString *node_str = g_string_new("");
g_string_printf(node_str, "%s#%s", node, ver);
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, to, node_str->str);
g_string_free(node_str, TRUE);
xmpp_id_handler_add(conn, _caps_response_handler, id, NULL);
2013-03-14 20:50:09 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_send_caps_request_legacy(const char *const to, const char *const id,
const char *const node, const char *const ver)
2014-11-30 00:37:36 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (!node) {
log_error("Could not create caps request, no node");
return;
}
if (!ver) {
log_error("Could not create caps request, no ver");
return;
}
GString *node_str = g_string_new("");
g_string_printf(node_str, "%s#%s", node, ver);
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, to, node_str->str);
xmpp_id_handler_add(conn, _caps_response_handler_legacy, id, node_str->str);
g_string_free(node_str, FALSE);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
iq_disco_items_request(gchar *jid)
2013-03-14 20:50:09 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_send_software_version(const char *const fulljid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_software_version_iq(ctx, fulljid);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _version_result_handler, id, strdup(fulljid));
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_confirm_instant_room(const char *const room_jid)
2014-09-03 12:55:06 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_instant_room_request_iq(ctx, room_jid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_destroy_room(const char *const room_jid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_instant_room_destroy_iq(ctx, room_jid);
2014-09-03 21:00:08 +00:00
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _destroy_room_result_handler, id, NULL);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_request_room_config_form(const char *const room_jid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_config_request_iq(ctx, room_jid);
2014-09-04 21:41:10 +00:00
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_config_handler, id, NULL);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_submit_room_config(const char *const room, DataForm *form)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, room, form);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_config_submit_handler, id, NULL);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_config_cancel(const char *const room_jid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, room_jid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_affiliation_list(const char *const room, char *affiliation)
2014-10-04 20:38:31 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_affiliation_list_iq(ctx, room, affiliation);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_affiliation_list_result_handler, id, strdup(affiliation));
2014-10-04 20:38:31 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_kick_occupant(const char *const room, const char *const nick, const char *const reason)
2014-10-05 02:52:55 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_kick_iq(ctx, room, nick, reason);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_kick_result_handler, id, strdup(nick));
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-10-06 20:42:09 +00:00
struct privilege_set_t {
char *item;
char *privilege;
};
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_affiliation_set(const char *const room, const char *const jid, char *affiliation,
const char *const reason)
2014-10-04 20:38:31 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_affiliation_set_iq(ctx, room, jid, affiliation, reason);
char *id = xmpp_stanza_get_id(iq);
2014-10-06 20:42:09 +00:00
struct privilege_set_t *affiliation_set = malloc(sizeof(struct privilege_set_t));
affiliation_set->item = strdup(jid);
affiliation_set->privilege = strdup(affiliation);
xmpp_id_handler_add(conn, _room_affiliation_set_result_handler, id, affiliation_set);
2014-10-04 20:38:31 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_role_set(const char *const room, const char *const nick, char *role,
const char *const reason)
2014-10-06 20:42:09 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_role_set_iq(ctx, room, nick, role, reason);
char *id = xmpp_stanza_get_id(iq);
struct privilege_set_t *role_set = malloc(sizeof(struct privilege_set_t));
role_set->item = strdup(nick);
role_set->privilege = strdup(role);
xmpp_id_handler_add(conn, _room_role_set_result_handler, id, role_set);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_room_role_list(const char *const room, char *role)
2014-10-06 20:42:09 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_room_role_list_iq(ctx, room, role);
char *id = xmpp_stanza_get_id(iq);
xmpp_id_handler_add(conn, _room_role_list_result_handler, id, strdup(role));
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
2014-12-22 22:13:42 +00:00
void
2015-10-26 00:14:23 +00:00
iq_send_ping(const char *const target)
2014-09-04 00:08:10 +00:00
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, target);
char *id = xmpp_stanza_get_id(iq);
GDateTime *now = g_date_time_new_now_local();
xmpp_id_handler_add(conn, _manual_pong_handler, id, now);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
static int
2015-10-26 00:14:23 +00:00
_error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
char *error_msg = stanza_get_error_message(stanza);
2013-01-24 00:26:53 +00:00
2015-05-04 22:19:10 +00:00
if (id) {
log_debug("IQ error handler fired, id: %s, error: %s", id, error_msg);
log_error("IQ error received, id: %s, error: %s", id, error_msg);
} else {
log_debug("IQ error handler fired, error: %s", error_msg);
log_error("IQ error received, error: %s", error_msg);
2013-01-24 00:26:53 +00:00
}
free(error_msg);
return 1;
}
2013-01-24 00:26:53 +00:00
static int
2015-10-26 00:14:23 +00:00
_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
char *id = xmpp_stanza_get_id(stanza);
char *type = xmpp_stanza_get_type(stanza);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ pong handler fired, id: %s.", id);
} else {
log_debug("IQ pong handler fired.");
}
2015-05-04 22:19:10 +00:00
if (id && type) {
// show warning if error
if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
char *error_msg = stanza_get_error_message(stanza);
log_warning("Server ping (id=%s) responded with error: %s", id, error_msg);
free(error_msg);
// turn off autoping if error type is 'cancel'
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
2015-05-04 22:19:10 +00:00
if (error) {
char *errtype = xmpp_stanza_get_type(error);
2015-05-04 22:19:10 +00:00
if (errtype) {
if (strcmp(errtype, "cancel") == 0) {
log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id);
prefs_set_autoping(0);
cons_show_error("Server ping not supported, autoping disabled.");
xmpp_timed_handler_delete(conn, _ping_timed_handler);
}
}
}
}
}
// remove this handler
return 0;
}
2014-09-18 23:49:48 +00:00
static int
2015-10-26 00:14:23 +00:00
_caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-09-18 23:49:48 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
char *type = xmpp_stanza_get_type(stanza);
// ignore non result
if ((g_strcmp0(type, "get") == 0) || (g_strcmp0(type, "set") == 0)) {
return 1;
}
2014-09-18 23:49:48 +00:00
if (id) {
log_info("Capabilities response handler fired for id %s", id);
} else {
log_info("Capabilities response handler fired");
}
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!from) {
log_info("No from attribute");
return 0;
}
2014-09-21 15:51:35 +00:00
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_warning("Error received for capabilities response from %s: ", from, error_message);
free(error_message);
return 0;
}
if (query == NULL) {
log_warning("No query element found.");
return 0;
}
2014-09-18 23:49:48 +00:00
char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
if (node == NULL) {
log_warning("No node attribute found");
return 0;
}
2014-11-30 00:37:36 +00:00
// validate sha1
gchar **split = g_strsplit(node, "#", -1);
char *given_sha1 = split[1];
char *generated_sha1 = caps_create_sha1_str(query);
if (g_strcmp0(given_sha1, generated_sha1) != 0) {
log_warning("Generated sha-1 does not match given:");
log_warning("Generated : %s", generated_sha1);
log_warning("Given : %s", given_sha1);
2014-09-18 23:49:48 +00:00
} else {
2014-11-30 00:37:36 +00:00
log_info("Valid SHA-1 hash found: %s", given_sha1);
if (caps_contains(given_sha1)) {
log_info("Capabilties already cached: %s", given_sha1);
2014-09-18 23:49:48 +00:00
} else {
2014-11-30 00:37:36 +00:00
log_info("Capabilities not cached: %s, storing", given_sha1);
Capabilities *capabilities = caps_create(query);
caps_add_by_ver(given_sha1, capabilities);
caps_destroy(capabilities);
}
caps_map_jid_to_ver(from, given_sha1);
}
2014-11-30 00:37:36 +00:00
g_free(generated_sha1);
g_strfreev(split);
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-11-30 00:37:36 +00:00
{
2015-02-11 00:17:07 +00:00
char *jid = (char *)userdata;
2014-11-30 00:37:36 +00:00
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
char *type = xmpp_stanza_get_type(stanza);
// ignore non result
if ((g_strcmp0(type, "get") == 0) || (g_strcmp0(type, "set") == 0)) {
2015-02-11 00:17:07 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 1;
}
if (id) {
log_info("Capabilities response handler fired for id %s", id);
} else {
log_info("Capabilities response handler fired");
}
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!from) {
log_info("No from attribute");
2015-02-11 00:17:07 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 0;
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_warning("Error received for capabilities response from %s: ", from, error_message);
free(error_message);
2015-02-11 00:17:07 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 0;
}
if (query == NULL) {
log_warning("No query element found.");
2015-02-11 00:17:07 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 0;
}
char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
if (node == NULL) {
log_warning("No node attribute found");
2015-02-11 00:17:07 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 0;
}
log_info("Associating capabilities with: %s", jid);
Capabilities *capabilities = caps_create(query);
caps_add_by_jid(jid, capabilities);
2015-02-09 21:59:17 +00:00
free(jid);
2014-11-30 00:37:36 +00:00
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-11-30 00:37:36 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
2015-02-09 21:59:17 +00:00
char *expected_node = (char *)userdata;
2014-11-30 00:37:36 +00:00
char *type = xmpp_stanza_get_type(stanza);
// ignore non result
if ((g_strcmp0(type, "get") == 0) || (g_strcmp0(type, "set") == 0)) {
2015-02-09 21:59:17 +00:00
free(expected_node);
2014-11-30 00:37:36 +00:00
return 1;
}
if (id) {
log_info("Capabilities response handler fired for id %s", id);
} else {
log_info("Capabilities response handler fired");
}
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!from) {
log_info("No from attribute");
2015-02-09 21:59:17 +00:00
free(expected_node);
2014-11-30 00:37:36 +00:00
return 0;
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_warning("Error received for capabilities response from %s: ", from, error_message);
free(error_message);
2015-02-09 21:59:17 +00:00
free(expected_node);
2014-11-30 00:37:36 +00:00
return 0;
}
if (query == NULL) {
log_warning("No query element found.");
2015-02-09 21:59:17 +00:00
free(expected_node);
2014-11-30 00:37:36 +00:00
return 0;
}
char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
if (node == NULL) {
log_warning("No node attribute found");
2015-02-09 21:59:17 +00:00
free(expected_node);
2014-11-30 00:37:36 +00:00
return 0;
}
// nodes match
if (g_strcmp0(expected_node, node) == 0) {
log_info("Legacy capabilities, nodes match %s", node);
if (caps_contains(node)) {
log_info("Capabilties already cached: %s", node);
} else {
log_info("Capabilities not cached: %s, storing", node);
Capabilities *capabilities = caps_create(query);
caps_add_by_ver(node, capabilities);
caps_destroy(capabilities);
2014-09-18 23:49:48 +00:00
}
2014-11-30 00:37:36 +00:00
caps_map_jid_to_ver(from, node);
// node match fail
} else {
log_info("Legacy Capabilities nodes do not match, expeceted %s, given %s.", expected_node, node);
2014-09-18 23:49:48 +00:00
}
2014-11-30 00:37:36 +00:00
free(expected_node);
2014-09-18 23:49:48 +00:00
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_enable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
{
char *type = xmpp_stanza_get_type(stanza);
if (g_strcmp0(type, "error") == 0) {
char *error_message = stanza_get_error_message(stanza);
cons_show_error("Server error enabling message carbons: %s", error_message);
log_debug("Error enabling carbons: %s", error_message);
2015-08-08 23:43:00 +00:00
free(error_message);
} else {
log_debug("Message carbons enabled.");
}
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_disable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
{
char *type = xmpp_stanza_get_type(stanza);
if (g_strcmp0(type, "error") == 0) {
char *error_message = stanza_get_error_message(stanza);
cons_show_error("Server error disabling message carbons: %s", error_message);
log_debug("Error disabling carbons: %s", error_message);
2015-08-08 23:43:00 +00:00
free(error_message);
} else {
log_debug("Message carbons disabled.");
}
return 0;
}
2014-09-04 00:08:10 +00:00
static int
2015-10-26 00:14:23 +00:00
_manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-09-04 00:08:10 +00:00
{
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *type = xmpp_stanza_get_type(stanza);
2014-11-03 21:09:49 +00:00
GDateTime *sent = (GDateTime *)userdata;
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
if (!error_message) {
cons_show_error("Error returned from pinging %s.", from);
} else {
cons_show_error("Error returned from pinging %s: %s.", from, error_message);
}
free(error_message);
2014-11-03 21:09:49 +00:00
g_date_time_unref(sent);
return 0;
}
2014-09-04 00:08:10 +00:00
GDateTime *now = g_date_time_new_now_local();
GTimeSpan elapsed = g_date_time_difference(now, sent);
int elapsed_millis = elapsed / 1000;
g_date_time_unref(sent);
g_date_time_unref(now);
if (from == NULL) {
cons_show("Ping response from server: %dms.", elapsed_millis);
} else {
cons_show("Ping response from %s: %dms.", from, elapsed_millis);
}
2014-09-04 00:08:10 +00:00
return 0;
}
2014-01-26 00:15:34 +00:00
static int
2015-10-26 00:14:23 +00:00
_ping_timed_handler(xmpp_conn_t *const conn, void *const userdata)
2014-01-26 00:15:34 +00:00
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
if (jabber_get_connection_status() == JABBER_CONNECTED) {
2014-09-04 00:08:10 +00:00
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL);
char *id = xmpp_stanza_get_id(iq);
// add pong handler
xmpp_id_handler_add(conn, _pong_handler, id, ctx);
2014-01-26 00:15:34 +00:00
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
return 1;
}
static int
2015-10-26 00:14:23 +00:00
_version_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
2014-09-03 21:00:08 +00:00
char *id = xmpp_stanza_get_id(stanza);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ version result handler fired, id: %s.", id);
} else {
log_debug("IQ version result handler fired.");
}
char *type = xmpp_stanza_get_type(stanza);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (g_strcmp0(type, STANZA_TYPE_RESULT) != 0) {
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
ui_handle_software_version_error(from, error_message);
free(error_message);
} else {
ui_handle_software_version_error(from, "unknown error");
log_error("Software version result with unrecognised type attribute.");
}
return 0;
}
const char *jid = xmpp_stanza_get_attribute(stanza, "from");
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query == NULL) {
2015-09-27 17:32:21 +00:00
log_error("Software version result received with no query element.");
return 0;
}
char *ns = xmpp_stanza_get_ns(query);
if (g_strcmp0(ns, STANZA_NS_VERSION) != 0) {
2015-09-27 17:32:21 +00:00
log_error("Software version result received without namespace.");
return 0;
}
char *name_str = NULL;
char *version_str = NULL;
char *os_str = NULL;
xmpp_stanza_t *name = xmpp_stanza_get_child_by_name(query, "name");
xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version");
xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os");
2015-05-04 22:19:10 +00:00
if (name) {
name_str = xmpp_stanza_get_text(name);
}
2015-05-04 22:19:10 +00:00
if (version) {
version_str = xmpp_stanza_get_text(version);
}
2015-05-04 22:19:10 +00:00
if (os) {
os_str = xmpp_stanza_get_text(os);
}
if (g_strcmp0(jid, (char*)userdata) != 0) {
log_warning("From attribute specified different JID, using original JID.");
}
xmpp_ctx_t *ctx = xmpp_conn_get_context(conn);
Jid *jidp = jid_create((char*)userdata);
const char *presence = NULL;
2014-09-28 21:09:20 +00:00
if (muc_active(jidp->barejid)) {
Occupant *occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
presence = string_from_resource_presence(occupant->presence);
} else {
PContact contact = roster_get_contact(jidp->barejid);
Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
if (!resource) {
ui_handle_software_version_error(jidp->fulljid, "Unknown resource");
if (name_str) xmpp_free(ctx, name_str);
if (version_str) xmpp_free(ctx, version_str);
if (os_str) xmpp_free(ctx, os_str);
return 0;
}
presence = string_from_resource_presence(resource->presence);
}
ui_show_software_version(jidp->fulljid, presence, name_str, version_str, os_str);
jid_destroy(jidp);
free(userdata);
if (name_str) xmpp_free(ctx, name_str);
if (version_str) xmpp_free(ctx, version_str);
if (os_str) xmpp_free(ctx, os_str);
return 0;
}
2013-01-24 00:26:53 +00:00
static int
2015-10-26 00:14:23 +00:00
_ping_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2013-01-24 00:26:53 +00:00
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *to = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TO);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2013-01-24 00:26:53 +00:00
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ ping get handler fired, id: %s.", id);
} else {
log_debug("IQ ping get handler fired.");
}
if ((from == NULL) || (to == NULL)) {
return 1;
}
2013-01-24 00:26:53 +00:00
xmpp_stanza_t *pong = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(pong, STANZA_NAME_IQ);
xmpp_stanza_set_attribute(pong, STANZA_ATTR_TO, from);
xmpp_stanza_set_attribute(pong, STANZA_ATTR_FROM, to);
xmpp_stanza_set_attribute(pong, STANZA_ATTR_TYPE, STANZA_TYPE_RESULT);
2013-01-24 00:26:53 +00:00
2015-05-04 22:19:10 +00:00
if (id) {
xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id);
2013-01-24 00:26:53 +00:00
}
xmpp_send(conn, pong);
xmpp_stanza_release(pong);
2013-01-24 00:26:53 +00:00
return 1;
}
static int
2015-10-26 00:14:23 +00:00
_version_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2013-01-24 00:26:53 +00:00
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ version get handler fired, id: %s.", id);
} else {
log_debug("IQ version get handler fired.");
}
2015-05-04 22:19:10 +00:00
if (from) {
2013-01-24 00:26:53 +00:00
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
2015-05-04 22:19:10 +00:00
if (id) {
2013-01-24 00:26:53 +00:00
xmpp_stanza_set_id(response, id);
}
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, STANZA_NS_VERSION);
xmpp_stanza_t *name = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(name, "name");
xmpp_stanza_t *name_txt = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(name_txt, "Profanity");
xmpp_stanza_add_child(name, name_txt);
xmpp_stanza_t *version = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(version, "version");
xmpp_stanza_t *version_txt = xmpp_stanza_new(ctx);
GString *version_str = g_string_new(PACKAGE_VERSION);
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
g_string_append(version_str, "dev.");
g_string_append(version_str, PROF_GIT_BRANCH);
g_string_append(version_str, ".");
g_string_append(version_str, PROF_GIT_REVISION);
#else
2013-01-24 00:26:53 +00:00
g_string_append(version_str, "dev");
#endif
2013-01-24 00:26:53 +00:00
}
xmpp_stanza_set_text(version_txt, version_str->str);
xmpp_stanza_add_child(version, version_txt);
xmpp_stanza_add_child(query, name);
xmpp_stanza_add_child(query, version);
xmpp_stanza_add_child(response, query);
xmpp_send(conn, response);
g_string_free(version_str, TRUE);
2013-08-25 11:54:34 +00:00
xmpp_stanza_release(name_txt);
xmpp_stanza_release(version_txt);
xmpp_stanza_release(name);
xmpp_stanza_release(version);
xmpp_stanza_release(query);
2013-01-24 00:26:53 +00:00
xmpp_stanza_release(response);
}
return 1;
}
2013-03-24 17:40:46 +00:00
static int
2015-10-26 00:14:23 +00:00
_disco_items_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2013-03-24 17:40:46 +00:00
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
2014-09-03 21:00:08 +00:00
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
2013-03-24 17:40:46 +00:00
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ disco items get handler fired, id: %s.", id);
} else {
log_debug("IQ disco items get handler fired.");
}
2015-05-04 22:19:10 +00:00
if (from) {
2013-03-24 17:40:46 +00:00
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
xmpp_stanza_add_child(response, query);
xmpp_send(conn, response);
xmpp_stanza_release(response);
}
return 1;
}
static int
2015-10-26 00:14:23 +00:00
_last_activity_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
2015-09-28 23:53:58 +00:00
xmpp_ctx_t *ctx = connection_get_ctx();
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!from) {
return 1;
}
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
int idls_secs = ui_get_idle_time() / 1000;
char str[50];
sprintf(str, "%d", idls_secs);
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
2015-09-28 23:53:58 +00:00
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
2015-09-29 22:55:01 +00:00
xmpp_stanza_set_attribute(query, STANZA_ATTR_XMLNS, STANZA_NS_LASTACTIVITY);
xmpp_stanza_set_attribute(query, "seconds", str);
xmpp_stanza_add_child(response, query);
xmpp_stanza_release(query);
xmpp_send(conn, response);
xmpp_stanza_release(response);
} else {
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_ERROR);
xmpp_stanza_t *error = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(error, STANZA_NAME_ERROR);
xmpp_stanza_set_type(error, "cancel");
xmpp_stanza_t *service_unavailable = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(service_unavailable, "service-unavailable");
xmpp_stanza_set_ns(service_unavailable, "urn:ietf:params:xml:ns:xmpp-stanzas");
xmpp_stanza_add_child(error, service_unavailable);
xmpp_stanza_release(service_unavailable);
xmpp_stanza_add_child(response, error);
xmpp_stanza_release(error);
2015-09-28 23:53:58 +00:00
xmpp_send(conn, response);
xmpp_stanza_release(response);
}
return 1;
}
2013-03-24 17:40:46 +00:00
2013-01-24 00:26:53 +00:00
static int
2015-10-26 00:14:23 +00:00
_disco_info_get_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2013-01-24 00:26:53 +00:00
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2013-01-24 00:26:53 +00:00
xmpp_stanza_t *incoming_query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
const char *node_str = xmpp_stanza_get_attribute(incoming_query, STANZA_ATTR_NODE);
2013-01-24 00:26:53 +00:00
2014-09-03 21:00:08 +00:00
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ disco info get handler fired, id: %s.", id);
} else {
log_debug("IQ disco info get handler fired.");
}
2015-05-04 22:19:10 +00:00
if (from) {
2013-01-24 00:26:53 +00:00
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
2015-05-04 22:19:10 +00:00
if (node_str) {
xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str);
}
2013-01-24 00:26:53 +00:00
xmpp_stanza_add_child(response, query);
xmpp_send(conn, response);
xmpp_stanza_release(query);
2013-01-24 00:26:53 +00:00
xmpp_stanza_release(response);
}
return 1;
}
2014-09-03 21:00:08 +00:00
static int
2015-10-26 00:14:23 +00:00
_destroy_room_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-09-03 21:00:08 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-03 21:00:08 +00:00
log_debug("IQ destroy room result handler fired, id: %s.", id);
} else {
log_debug("IQ destroy room result handler fired.");
}
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (from == NULL) {
log_error("No from attribute for IQ destroy room result");
} else {
2015-04-28 22:38:56 +00:00
sv_ev_room_destroy(from);
2014-09-03 21:00:08 +00:00
}
return 0;
}
2014-09-04 21:41:10 +00:00
static int
2015-10-26 00:14:23 +00:00
_room_config_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-09-04 21:41:10 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
2014-09-09 22:16:12 +00:00
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2014-09-04 21:41:10 +00:00
2015-05-04 22:19:10 +00:00
if (id) {
2014-09-04 21:41:10 +00:00
log_debug("IQ room config handler fired, id: %s.", id);
} else {
log_debug("IQ room config handler fired.");
}
2014-09-09 22:16:12 +00:00
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
ui_handle_room_configuration_form_error(from, error_message);
2014-09-09 22:16:12 +00:00
free(error_message);
return 0;
}
2014-09-04 21:41:10 +00:00
if (from == NULL) {
log_warning("No from attribute for IQ config request result");
ui_handle_room_configuration_form_error(from, "No from attribute for room cofig response.");
2014-09-09 22:16:12 +00:00
return 0;
}
2014-09-04 21:41:10 +00:00
2014-09-09 22:16:12 +00:00
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query == NULL) {
log_warning("No query element found parsing room config response");
ui_handle_room_configuration_form_error(from, "No query element found parsing room config response");
2014-09-09 22:16:12 +00:00
return 0;
}
2014-09-04 21:41:10 +00:00
2014-09-09 22:16:12 +00:00
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA);
if (x == NULL) {
log_warning("No x element found with %s namespace parsing room config response", STANZA_NS_DATA);
ui_handle_room_configuration_form_error(from, "No form configuration options available");
2014-09-09 22:16:12 +00:00
return 0;
}
2014-09-04 21:41:10 +00:00
2014-09-09 22:16:12 +00:00
char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE);
if (g_strcmp0(form_type, "form") != 0) {
log_warning("x element not of type 'form' parsing room config response");
ui_handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response.");
2014-09-09 22:16:12 +00:00
return 0;
2014-09-04 21:41:10 +00:00
}
2014-09-09 22:16:12 +00:00
DataForm *form = form_create(x);
ui_handle_room_configuration(from, form);
2014-09-09 22:16:12 +00:00
2014-09-04 21:41:10 +00:00
return 0;
}
2015-10-26 00:14:23 +00:00
static int
_room_affiliation_set_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2014-10-06 20:42:09 +00:00
struct privilege_set_t *affiliation_set = (struct privilege_set_t *)userdata;
2015-05-04 22:19:10 +00:00
if (id) {
log_debug("IQ affiliation set handler fired, id: %s.", id);
} else {
log_debug("IQ affiliation set handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation_set->privilege, from, affiliation_set->item, error_message);
mucwin_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message);
free(error_message);
}
2014-10-06 20:42:09 +00:00
free(affiliation_set->item);
free(affiliation_set->privilege);
free(affiliation_set);
return 0;
}
2015-10-26 00:14:23 +00:00
static int
_room_role_set_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2014-10-06 20:42:09 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
struct privilege_set_t *role_set = (struct privilege_set_t *)userdata;
2015-05-04 22:19:10 +00:00
if (id) {
2014-10-06 20:42:09 +00:00
log_debug("IQ role set handler fired, id: %s.", id);
} else {
log_debug("IQ role set handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_debug("Error setting role %s list for room %s, user %s: %s", role_set->privilege, from, role_set->item, error_message);
mucwin_role_set_error(from, role_set->item, role_set->privilege, error_message);
2014-10-06 20:42:09 +00:00
free(error_message);
}
free(role_set->item);
free(role_set->privilege);
free(role_set);
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_room_affiliation_list_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *affiliation = (char *)userdata;
2015-05-04 22:19:10 +00:00
if (id) {
log_debug("IQ affiliation list result handler fired, id: %s.", id);
} else {
log_debug("IQ affiliation list result handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_debug("Error retrieving %s list for room %s: %s", affiliation, from, error_message);
ProfMucWin *mucwin = wins_get_muc(from);
if (mucwin) {
mucwin_affiliation_list_error(mucwin, affiliation, error_message);
}
free(error_message);
free(affiliation);
return 0;
}
GSList *jids = NULL;
xmpp_stanza_t *query = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_ADMIN);
if (query) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
while (child) {
char *name = xmpp_stanza_get_name(child);
if (g_strcmp0(name, "item") == 0) {
char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (jid) {
jids = g_slist_insert_sorted(jids, jid, (GCompareFunc)g_strcmp0);
}
}
child = xmpp_stanza_get_next(child);
}
}
muc_jid_autocomplete_add_all(from, jids);
ProfMucWin *mucwin = wins_get_muc(from);
if (mucwin) {
mucwin_handle_affiliation_list(mucwin, affiliation, jids);
}
free(affiliation);
2014-11-03 20:57:22 +00:00
g_slist_free(jids);
return 0;
}
2014-10-06 20:42:09 +00:00
static int
2015-10-26 00:14:23 +00:00
_room_role_list_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
2014-10-06 20:42:09 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *role = (char *)userdata;
2015-05-04 22:19:10 +00:00
if (id) {
2014-10-06 20:42:09 +00:00
log_debug("IQ role list result handler fired, id: %s.", id);
} else {
log_debug("IQ role list result handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
log_debug("Error retrieving %s list for room %s: %s", role, from, error_message);
ProfMucWin *mucwin = wins_get_muc(from);
if (mucwin) {
mucwin_role_list_error(mucwin, role, error_message);
}
2014-10-06 20:42:09 +00:00
free(error_message);
free(role);
return 0;
}
GSList *nicks = NULL;
xmpp_stanza_t *query = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_ADMIN);
if (query) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
while (child) {
char *name = xmpp_stanza_get_name(child);
if (g_strcmp0(name, "item") == 0) {
char *nick = xmpp_stanza_get_attribute(child, STANZA_ATTR_NICK);
if (nick) {
nicks = g_slist_insert_sorted(nicks, nick, (GCompareFunc)g_strcmp0);
}
}
child = xmpp_stanza_get_next(child);
}
}
ProfMucWin *mucwin = wins_get_muc(from);
if (mucwin) {
mucwin_handle_role_list(mucwin, role, nicks);
}
2014-10-06 20:42:09 +00:00
free(role);
2014-11-03 20:57:22 +00:00
g_slist_free(nicks);
2014-10-06 20:42:09 +00:00
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_room_config_submit_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2015-05-04 22:19:10 +00:00
if (id) {
log_debug("IQ room config submit handler fired, id: %s.", id);
} else {
log_debug("IQ room config submit handler fired.");
}
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
ui_handle_room_config_submit_result_error(from, error_message);
free(error_message);
return 0;
}
ui_handle_room_config_submit_result(from);
return 0;
}
2014-10-05 02:52:55 +00:00
static int
2015-10-26 00:14:23 +00:00
_room_kick_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
2014-10-05 02:52:55 +00:00
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *type = xmpp_stanza_get_type(stanza);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *nick = (char *)userdata;
2015-05-04 22:19:10 +00:00
if (id) {
2014-10-05 02:52:55 +00:00
log_debug("IQ kick result handler fired, id: %s.", id);
} else {
log_debug("IQ kick result handler fired.");
}
// handle error responses
2015-11-02 00:33:31 +00:00
ProfMucWin *mucwin = wins_get_muc(from);
if (mucwin && (g_strcmp0(type, STANZA_TYPE_ERROR) == 0)) {
2014-10-05 02:52:55 +00:00
char *error_message = stanza_get_error_message(stanza);
2015-11-02 00:33:31 +00:00
mucwin_kick_error(mucwin, nick, error_message);
2014-10-05 02:52:55 +00:00
free(error_message);
}
free(nick);
return 0;
}
2013-03-14 23:41:36 +00:00
static void
_identity_destroy(DiscoIdentity *identity)
{
2015-05-04 22:19:10 +00:00
if (identity) {
free(identity->name);
free(identity->type);
free(identity->category);
free(identity);
2013-03-14 23:41:36 +00:00
}
}
static void
_item_destroy(DiscoItem *item)
{
2015-05-04 22:19:10 +00:00
if (item) {
free(item->jid);
free(item->name);
free(item);
2013-03-14 23:41:36 +00:00
}
}
static int
2015-10-26 00:14:23 +00:00
_room_info_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
const char *type = xmpp_stanza_get_type(stanza);
ProfRoomInfoData *cb_data = (ProfRoomInfoData *)userdata;
log_info("Received diso#info response for room: %s", cb_data->room);
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
ProfMucWin *mucwin = wins_get_muc(cb_data->room);
if (mucwin && cb_data->display) {
char *error_message = stanza_get_error_message(stanza);
mucwin_room_info_error(mucwin, error_message);
free(error_message);
}
free(cb_data->room);
free(cb_data);
return 0;
}
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
2015-05-04 22:19:10 +00:00
if (query) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
GSList *identities = NULL;
GSList *features = NULL;
2015-05-04 22:19:10 +00:00
while (child) {
const char *stanza_name = xmpp_stanza_get_name(child);
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
2015-05-04 22:19:10 +00:00
if (var) {
features = g_slist_append(features, strdup(var));
}
} else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) {
const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE);
const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
2015-05-04 22:19:10 +00:00
if (name || category || type) {
DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
2015-05-04 22:19:10 +00:00
if (name) {
identity->name = strdup(name);
} else {
identity->name = NULL;
}
2015-05-04 22:19:10 +00:00
if (category) {
identity->category = strdup(category);
} else {
identity->category = NULL;
}
2015-05-04 22:19:10 +00:00
if (type) {
identity->type = strdup(type);
} else {
identity->type = NULL;
}
identities = g_slist_append(identities, identity);
}
}
child = xmpp_stanza_get_next(child);
}
muc_set_features(cb_data->room, features);
ProfMucWin *mucwin = wins_get_muc(cb_data->room);
if (mucwin && cb_data->display) {
mucwin_room_disco_info(mucwin, identities, features);
}
g_slist_free_full(features, free);
g_slist_free_full(identities, (GDestroyNotify)_identity_destroy);
}
free(cb_data->room);
free(cb_data);
return 0;
}
static int
2015-10-26 00:14:23 +00:00
_last_activity_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!from) {
cons_show_error("Invalid last activity response received.");
log_info("Received last activity response with no from attribute.");
return 0;
}
const char *type = xmpp_stanza_get_type(stanza);
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
if (from) {
cons_show_error("Last activity request failed for %s: %s", from, error_message);
} else {
cons_show_error("Last activity request failed: %s", error_message);
}
free(error_message);
return 0;
}
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (!query) {
cons_show_error("Invalid last activity response received.");
log_info("Received last activity response with no query element.");
return 0;
}
char *seconds_str = xmpp_stanza_get_attribute(query, "seconds");
if (!seconds_str) {
cons_show_error("Invalid last activity response received.");
log_info("Received last activity response with no seconds attribute.");
return 0;
}
int seconds = atoi(seconds_str);
if (seconds < 0) {
cons_show_error("Invalid last activity response received.");
log_info("Received last activity response with negative value.");
return 0;
}
char *msg = xmpp_stanza_get_text(query);
sv_ev_lastactivity_response(from, seconds, msg);
xmpp_free(connection_get_ctx(), msg);
return 0;
}
2013-01-24 00:26:53 +00:00
static int
2015-10-26 00:14:23 +00:00
_disco_info_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
2013-01-24 00:26:53 +00:00
{
2013-03-14 23:41:36 +00:00
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2014-09-23 23:30:05 +00:00
const char *type = xmpp_stanza_get_type(stanza);
if (from) {
log_info("Received diso#info response from: %s", from);
} else {
log_info("Received diso#info response");
}
2014-09-23 23:30:05 +00:00
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
char *error_message = stanza_get_error_message(stanza);
if (from) {
cons_show_error("Service discovery failed for %s: %s", from, error_message);
} else {
cons_show_error("Service discovery failed: %s", error_message);
}
2014-09-23 23:30:05 +00:00
free(error_message);
return 0;
}
2013-01-24 00:26:53 +00:00
2014-09-18 23:49:48 +00:00
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
2013-03-14 23:41:36 +00:00
2015-05-04 22:19:10 +00:00
if (query) {
2014-09-18 23:49:48 +00:00
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
GSList *identities = NULL;
GSList *features = NULL;
2015-05-04 22:19:10 +00:00
while (child) {
2014-09-18 23:49:48 +00:00
const char *stanza_name = xmpp_stanza_get_name(child);
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
2015-05-04 22:19:10 +00:00
if (var) {
2014-09-18 23:49:48 +00:00
features = g_slist_append(features, strdup(var));
}
} else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) {
const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE);
const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
2015-05-04 22:19:10 +00:00
if (name || category || type) {
2014-09-18 23:49:48 +00:00
DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
2015-05-04 22:19:10 +00:00
if (name) {
2014-09-18 23:49:48 +00:00
identity->name = strdup(name);
} else {
identity->name = NULL;
2013-03-14 23:41:36 +00:00
}
2015-05-04 22:19:10 +00:00
if (category) {
2014-09-18 23:49:48 +00:00
identity->category = strdup(category);
} else {
identity->category = NULL;
2013-03-14 23:41:36 +00:00
}
2015-05-04 22:19:10 +00:00
if (type) {
2014-09-18 23:49:48 +00:00
identity->type = strdup(type);
} else {
identity->type = NULL;
}
2013-01-24 00:26:53 +00:00
2014-09-18 23:49:48 +00:00
identities = g_slist_append(identities, identity);
}
2013-02-17 01:04:10 +00:00
}
child = xmpp_stanza_get_next(child);
}
cons_show_disco_info(from, identities, features);
2014-09-18 23:49:48 +00:00
g_slist_free_full(features, free);
g_slist_free_full(identities, (GDestroyNotify)_identity_destroy);
2013-01-24 00:26:53 +00:00
}
return 0;
2013-01-24 00:26:53 +00:00
}
static int
2015-10-26 00:14:23 +00:00
_disco_items_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
void *const userdata)
{
log_debug("Received diso#items response");
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
2013-03-14 22:18:21 +00:00
GSList *items = NULL;
2013-03-14 22:18:21 +00:00
if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0)) {
log_debug("Response to query: %s", id);
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
2013-03-14 20:50:09 +00:00
2015-05-04 22:19:10 +00:00
if (query) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
2015-05-04 22:19:10 +00:00
while (child) {
2014-04-25 23:36:36 +00:00
const char *stanza_name = xmpp_stanza_get_name(child);
2015-05-04 22:19:10 +00:00
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
2014-04-25 23:36:36 +00:00
const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
2015-05-04 22:19:10 +00:00
if (item_jid) {
2013-03-14 22:03:38 +00:00
DiscoItem *item = malloc(sizeof(struct disco_item_t));
item->jid = strdup(item_jid);
2014-04-25 23:36:36 +00:00
const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
2015-05-04 22:19:10 +00:00
if (item_name) {
2013-03-14 22:03:38 +00:00
item->name = strdup(item_name);
} else {
item->name = NULL;
}
items = g_slist_append(items, item);
}
}
child = xmpp_stanza_get_next(child);
}
}
2013-03-14 22:18:21 +00:00
}
2013-03-14 22:18:21 +00:00
if (g_strcmp0(id, "confreq") == 0) {
cons_show_room_list(items, from);
2013-03-14 22:18:21 +00:00
} else if (g_strcmp0(id, "discoitemsreq") == 0) {
cons_show_disco_items(items, from);
2013-03-14 20:50:09 +00:00
}
2013-03-14 23:41:36 +00:00
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
2013-03-14 22:18:21 +00:00
return 1;
}