From 87316b70b979da8e32493b5a45ecb9b4e0fd54ec Mon Sep 17 00:00:00 2001 From: bqv Date: Mon, 21 Mar 2022 13:46:29 +0000 Subject: [PATCH] better bookmarks (keep chipping) --- connection.cpp | 148 ++++++++++++++++++++++------------------------ xmpp/node.hh | 2 + xmpp/xep-0049.inl | 42 +++++++++++++ 3 files changed, 114 insertions(+), 78 deletions(-) create mode 100644 xmpp/xep-0049.inl diff --git a/connection.cpp b/connection.cpp index 6342720..9cc149f 100644 --- a/connection.cpp +++ b/connection.cpp @@ -110,6 +110,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void .value_or(std::string())) .type("get") .id(stanza::uuid(account->context)) + .xep0030() .query() .build(account->context) .get()); @@ -1004,6 +1005,66 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd } } } + query = xmpp_stanza_get_child_by_name_and_ns( + stanza, "query", "jabber:iq:private"); + if (query && type) + { + storage = xmpp_stanza_get_child_by_name_and_ns( + query, "storage", "storage:bookmarks"); + if (storage) + { + for (conference = xmpp_stanza_get_children(storage); + conference; conference = xmpp_stanza_get_next(conference)) + { + const char *name = xmpp_stanza_get_name(conference); + if (weechat_strcasecmp(name, "conference") != 0) + continue; + + const char *jid = xmpp_stanza_get_attribute(conference, "jid"); + const char *autojoin = xmpp_stanza_get_attribute(conference, "autojoin"); + name = xmpp_stanza_get_attribute(conference, "name"); + nick = xmpp_stanza_get_child_by_name(conference, "nick"); + char *intext; + if (nick) + { + text = xmpp_stanza_get_children(nick); + intext = xmpp_stanza_get_text(text); + } + + xmpp_send(conn, stanza::iq() + .from(to) + .to(jid) + .type("get") + .id(stanza::uuid(account->context)) + .xep0030() + .query() + .build(account->context) + .get()); + if (weechat_strcasecmp(autojoin, "true") == 0) + { + char **command = weechat_string_dyn_alloc(256); + weechat_string_dyn_concat(command, "/enter ", -1); + weechat_string_dyn_concat(command, jid, -1); + if (nick) + { + weechat_string_dyn_concat(command, "/", -1); + weechat_string_dyn_concat(command, intext, -1); + } + weechat_command(account->buffer, *command); + struct t_channel *ptr_channel = + channel__search(account, jid); + struct t_gui_buffer *ptr_buffer = + ptr_channel ? ptr_channel->buffer : NULL; + if (ptr_buffer) + weechat_buffer_set(ptr_buffer, "short_name", name); + weechat_string_dyn_free(command, 1); + } + + if (nick) + free(intext); + } + } + } pubsub = xmpp_stanza_get_child_by_name_and_ns( stanza, "pubsub", "http://jabber.org/protocol/pubsub"); @@ -1139,70 +1200,6 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd } } } - if (items_node - && weechat_strcasecmp(items_node, "storage:bookmarks") == 0) - { - item = xmpp_stanza_get_child_by_name(items, "item"); - if (item) - item_id = xmpp_stanza_get_id(item); - if (item && item_id && weechat_strcasecmp(item_id, "current") == 0) - { - storage = xmpp_stanza_get_child_by_name_and_ns( - item, "storage", "storage:bookmarks"); - if (storage) - { - for (conference = xmpp_stanza_get_children(storage); - conference; conference = xmpp_stanza_get_next(conference)) - { - const char *name = xmpp_stanza_get_name(conference); - if (weechat_strcasecmp(name, "conference") != 0) - continue; - - const char *jid = xmpp_stanza_get_attribute(conference, "jid"); - const char *autojoin = xmpp_stanza_get_attribute(conference, "autojoin"); - name = xmpp_stanza_get_attribute(conference, "name"); - nick = xmpp_stanza_get_child_by_name(conference, "nick"); - char *intext; - if (nick) - { - text = xmpp_stanza_get_children(nick); - intext = xmpp_stanza_get_text(text); - } - - xmpp_send(conn, stanza::iq() - .from(to) - .to(jid) - .type("get") - .id(stanza::uuid(account->context)) - .query() - .build(account->context) - .get()); - if (weechat_strcasecmp(autojoin, "true") == 0) - { - char **command = weechat_string_dyn_alloc(256); - weechat_string_dyn_concat(command, "/enter ", -1); - weechat_string_dyn_concat(command, jid, -1); - if (nick) - { - weechat_string_dyn_concat(command, "/", -1); - weechat_string_dyn_concat(command, intext, -1); - } - weechat_command(account->buffer, *command); - struct t_channel *ptr_channel = - channel__search(account, jid); - struct t_gui_buffer *ptr_buffer = - ptr_channel ? ptr_channel->buffer : NULL; - if (ptr_buffer) - weechat_buffer_set(ptr_buffer, "short_name", name); - weechat_string_dyn_free(command, 1); - } - - if (nick) - free(intext); - } - } - } - } } } @@ -1329,20 +1326,15 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, .build(account->context) .get()); - children[1] = NULL; - children[0] = - stanza__iq_pubsub_items(account->context, NULL, - strdup("storage:bookmarks")); - children[0] = - stanza__iq_pubsub(account->context, NULL, children, - with_noop("http://jabber.org/protocol/pubsub")); - children[0] = - stanza__iq(account->context, NULL, children, NULL, strdup("retrieve1"), - strdup(account_jid(account)), strdup(account_jid(account)), - strdup("get")); - - xmpp_send(conn, children[0]); - xmpp_stanza_release(children[0]); + xmpp_send(conn, stanza::iq() + .from(account_jid(account)) + .to(account_jid(account)) + .type("get") + .id(stanza::uuid(account->context)) + .xep0049() + .query(stanza::xep0049::query().bookmarks()) + .build(account->context) + .get()); children[1] = NULL; children[0] = diff --git a/xmpp/node.hh b/xmpp/node.hh index 4d627e2..fd785ab 100644 --- a/xmpp/node.hh +++ b/xmpp/node.hh @@ -165,6 +165,7 @@ namespace stanza { #include "xep-0027.inl" #include "xep-0030.inl" #include "xep-0045.inl" +#include "xep-0049.inl" #include "xep-0115.inl" #include "xep-0280.inl" #include "xep-0319.inl" @@ -200,6 +201,7 @@ namespace stanza { struct iq : virtual public spec, public xep0030::iq, + public xep0049::iq, public xep0280::iq { iq() : spec("iq") {} diff --git a/xmpp/xep-0049.inl b/xmpp/xep-0049.inl new file mode 100644 index 0000000..f9f82a2 --- /dev/null +++ b/xmpp/xep-0049.inl @@ -0,0 +1,42 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, version 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include +#include + +#include "node.hh" +#pragma GCC visibility push(default) +#include "ns.hh" +#pragma GCC visibility pop + +namespace stanza { + + /* Private XML Storage */ + struct xep0049 { + struct storage : virtual public spec { + storage() : spec("storage") { + xmlns<::storage::bookmarks>(); + } + }; + + struct query : virtual public spec { + query() : spec("query") { + xmlns(); + } + + query& bookmarks(storage s = xep0049::storage()) { child(s); return *this; } + }; + + struct iq : virtual public spec { + iq() : spec("iq") {} + + iq& xep0049() { return *this; } + + iq& query(query q = xep0049::query()) { child(q); return *this; } + }; + }; + +}