From ab15b4e43aadd283f3491b2a23e6af6da052860e Mon Sep 17 00:00:00 2001 From: bqv Date: Sun, 20 Mar 2022 14:44:06 +0000 Subject: [PATCH] chipping away at c cruft --- connection.cpp | 29 +++++++++++++---------------- xmpp/node.hh | 9 ++++++++- xmpp/xep-0030.inl | 2 ++ xmpp/xep-0280.inl | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 xmpp/xep-0280.inl diff --git a/connection.cpp b/connection.cpp index ae85420..6342720 100644 --- a/connection.cpp +++ b/connection.cpp @@ -1254,7 +1254,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, { account->disconnected = 0; - xmpp_stanza_t *pres, *pres__c, *pres__status, *pres__status__text, + xmpp_stanza_t *pres__c, *pres__status, *pres__status__text, *pres__x, *pres__x__text, **children; xmpp_handler_add(conn, &connection__version_handler, @@ -1315,22 +1315,19 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, children[3] = NULL; } - pres = stanza__presence(account->context, NULL, - children, NULL, strdup(account_jid(account)), - NULL, NULL); - xmpp_send(conn, pres); - xmpp_stanza_release(pres); - - children[1] = NULL; - children[0] = - stanza__iq_enable(account->context, NULL, with_noop("urn:xmpp:carbons:2")); - children[0] = - stanza__iq(account->context, NULL, children, - strdup("jabber:client"), strdup("enable1"), - strdup(account_jid(account)), NULL, strdup("set")); + xmpp_send(conn, stanza::presence() + .from(account_jid(account)) + .build(account->context) + .get()); - xmpp_send(conn, children[0]); - xmpp_stanza_release(children[0]); + xmpp_send(conn, stanza::iq() + .from(account_jid(account)) + .type("set") + .id(stanza::uuid(account->context)) + .xep0280() + .enable() + .build(account->context) + .get()); children[1] = NULL; children[0] = diff --git a/xmpp/node.hh b/xmpp/node.hh index 758f400..4d627e2 100644 --- a/xmpp/node.hh +++ b/xmpp/node.hh @@ -166,6 +166,7 @@ namespace stanza { #include "xep-0030.inl" #include "xep-0045.inl" #include "xep-0115.inl" +#include "xep-0280.inl" #include "xep-0319.inl" namespace stanza { @@ -190,10 +191,16 @@ namespace stanza { struct presence : virtual public spec { presence() : spec("presence") {} + + presence& id(std::string_view s) { attr("id", s); return *this; } + presence& from(std::string_view s) { attr("from", s); return *this; } + presence& to(std::string_view s) { attr("to", s); return *this; } + presence& lang(std::string_view s) { attr("lang", s); return *this; } }; struct iq : virtual public spec, - public xep0030::iq { + public xep0030::iq, + public xep0280::iq { iq() : spec("iq") {} iq& id(std::string_view s) { attr("id", s); return *this; } diff --git a/xmpp/xep-0030.inl b/xmpp/xep-0030.inl index 35dc626..23382a0 100644 --- a/xmpp/xep-0030.inl +++ b/xmpp/xep-0030.inl @@ -25,6 +25,8 @@ namespace stanza { struct iq : virtual public spec { iq() : spec("iq") {} + iq& xep0030() { return *this; } + iq& query(query q = xep0030::query()) { child(q); return *this; } }; }; diff --git a/xmpp/xep-0280.inl b/xmpp/xep-0280.inl new file mode 100644 index 0000000..3379728 --- /dev/null +++ b/xmpp/xep-0280.inl @@ -0,0 +1,34 @@ +// 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 { + + /* Message Carbons */ + struct xep0280 { + struct enable : virtual public spec { + enable() : spec("enable") { + xmlns(); + } + }; + + struct iq : virtual public spec { + iq() : spec("iq") {} + + iq& xep0280() { xmlns(); return *this; } + + iq& enable(enable e = xep0280::enable()) { child(e); return *this; } + }; + }; + +}