From 771dfab12354bc509af9163fca0c599ec9e58433 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 18 Dec 2019 10:14:46 +0100 Subject: [PATCH] Start implementing XEP-0084 So far we just subscribe and get the IDs. --- Makefile.am | 1 + src/event/server_events.c | 3 ++ src/xmpp/avatar.c | 94 +++++++++++++++++++++++++++++++++++++++ src/xmpp/avatar.h | 38 ++++++++++++++++ src/xmpp/stanza.h | 3 ++ src/xmpp/xmpp.h | 2 + 6 files changed, 141 insertions(+) create mode 100644 src/xmpp/avatar.c create mode 100644 src/xmpp/avatar.h diff --git a/Makefile.am b/Makefile.am index c49b6ba6..6fe31446 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,7 @@ core_sources = \ src/xmpp/bookmark.c src/xmpp/bookmark.h \ src/xmpp/blocking.c src/xmpp/blocking.h \ src/xmpp/form.c src/xmpp/form.h \ + src/xmpp/avatar.c src/xmpp/avatar.h \ src/event/common.c src/event/common.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ diff --git a/src/event/server_events.c b/src/event/server_events.c index 40cc1240..62d64869 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -54,6 +54,7 @@ #include "xmpp/muc.h" #include "xmpp/chat_session.h" #include "xmpp/roster_list.h" +#include "xmpp/avatar.h" #ifdef HAVE_LIBOTR #include "otr/otr.h" @@ -90,6 +91,8 @@ sv_ev_login_account_success(char *account_name, gboolean secured) omemo_on_connect(account); #endif + avatar_pep_subscribe(); + ui_handle_login_account_success(account, secured); // attempt to rejoin all rooms diff --git a/src/xmpp/avatar.c b/src/xmpp/avatar.c new file mode 100644 index 00000000..29ec453b --- /dev/null +++ b/src/xmpp/avatar.c @@ -0,0 +1,94 @@ +/* + * omemo.c + * vim: expandtab:ts=4:sts=4:sw=4 + * + * Copyright (C) 2019 Michael Vetter + * + * 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 . + * + * 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. + * + */ + +#include + +#include "log.h" +#include "xmpp/connection.h" +#include "xmpp/form.h" +#include "xmpp/iq.h" +#include "xmpp/message.h" +#include "xmpp/stanza.h" + +static int _avatar_metadata_nofication(xmpp_stanza_t *const stanza, void *const userdata); + +void +avatar_pep_subscribe(void) +{ + message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_METADATA, _avatar_metadata_nofication, NULL, NULL); + message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_DATA, _avatar_metadata_nofication, NULL, NULL); + + caps_add_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY); +} + +static int +_avatar_metadata_nofication(xmpp_stanza_t *const stanza, void *const userdata) +{ + const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + from = from; + + xmpp_stanza_t *root = NULL; + xmpp_stanza_t *event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT); + if (event) { + root = event; + } + + xmpp_stanza_t *pubsub = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB); + if (pubsub) { + root = pubsub; + } + + if (!root) { + return 1; + } + + xmpp_stanza_t *items = xmpp_stanza_get_child_by_name(root, "items"); + if (!items) { + return 1; + } + + xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item"); + if (item) { + xmpp_stanza_t *metadata = xmpp_stanza_get_child_by_name(item, "metadata"); + if (!metadata) + return 1; + + xmpp_stanza_t *info = xmpp_stanza_get_child_by_name(metadata, "info"); + const char *id = xmpp_stanza_get_id(info); + id = id; + } + + return 1; +} diff --git a/src/xmpp/avatar.h b/src/xmpp/avatar.h new file mode 100644 index 00000000..dcaaf24a --- /dev/null +++ b/src/xmpp/avatar.h @@ -0,0 +1,38 @@ +/* + * omemo.h + * vim: expandtab:ts=4:sts=4:sw=4 + * + * Copyright (C) 2019 Michael Vetter + * + * 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 . + * + * 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. + * + */ + +#include + +void avatar_pep_subscribe(void); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 31078ae8..c7e04703 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -2,6 +2,7 @@ * stanza.h * * Copyright (C) 2012 - 2019 James Booth + * Copyright (C) 2019 Michael Vetter * * This file is part of Profanity. * @@ -198,6 +199,8 @@ #define STANZA_NS_OMEMO_DEVICELIST "eu.siacs.conversations.axolotl.devicelist" #define STANZA_NS_OMEMO_BUNDLES "eu.siacs.conversations.axolotl.bundles" #define STANZA_NS_STABLE_ID "urn:xmpp:sid:0" +#define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data" +#define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index cb5ae9d6..c48da210 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -2,6 +2,7 @@ * xmpp.h * * Copyright (C) 2012 - 2019 James Booth + * Copyright (C) 2019 Michael Vetter * * This file is part of Profanity. * @@ -66,6 +67,7 @@ #define XMPP_FEATURE_OMEMO_DEVICELIST_NOTIFY "eu.siacs.conversations.axolotl.devicelist+notify" #define XMPP_FEATURE_PUBSUB "http://jabber.org/protocol/pubsub" #define XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS "http://jabber.org/protocol/pubsub#publish-options" +#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify" typedef enum { JABBER_CONNECTING,