From b0a7853a956e7d05ef4c0832675d47961fc43125 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 16 Oct 2022 21:57:01 +0200 Subject: DiscoveryManager: Use new IQ request handling --- src/client/QXmppDiscoveryManager.cpp | 47 +++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'src/client/QXmppDiscoveryManager.cpp') diff --git a/src/client/QXmppDiscoveryManager.cpp b/src/client/QXmppDiscoveryManager.cpp index 40263bbe..fa0a19da 100644 --- a/src/client/QXmppDiscoveryManager.cpp +++ b/src/client/QXmppDiscoveryManager.cpp @@ -10,7 +10,7 @@ #include "QXmppDataForm.h" #include "QXmppDiscoveryIq.h" #include "QXmppFutureUtils_p.h" -#include "QXmppGlobal.h" +#include "QXmppIqHandling.h" #include "QXmppStream.h" #include @@ -307,28 +307,17 @@ QStringList QXmppDiscoveryManager::discoveryFeatures() const bool QXmppDiscoveryManager::handleStanza(const QDomElement &element) { + if (QXmpp::handleIqRequests(element, client(), this)) { + return true; + } + if (element.tagName() == "iq" && QXmppDiscoveryIq::isDiscoveryIq(element)) { QXmppDiscoveryIq receivedIq; receivedIq.parse(element); switch (receivedIq.type()) { case QXmppIq::Get: - if (receivedIq.queryType() == QXmppDiscoveryIq::InfoQuery && - (receivedIq.queryNode().isEmpty() || - receivedIq.queryNode().startsWith(d->clientCapabilitiesNode))) { - - // respond to info queries for the client itself - QXmppDiscoveryIq qxmppFeatures = capabilities(); - qxmppFeatures.setId(receivedIq.id()); - qxmppFeatures.setTo(receivedIq.from()); - qxmppFeatures.setQueryNode(receivedIq.queryNode()); - client()->sendPacket(qxmppFeatures); - return true; - } else { - // let other managers handle other queries - return false; - } - + break; case QXmppIq::Result: case QXmppIq::Error: // handle all replies @@ -346,4 +335,28 @@ bool QXmppDiscoveryManager::handleStanza(const QDomElement &element) } return false; } + +std::variant QXmppDiscoveryManager::handleIq(QXmppDiscoveryIq &&iq) +{ + using Error = QXmppStanza::Error; + + if (!iq.queryNode().isEmpty() && !iq.queryNode().startsWith(d->clientCapabilitiesNode)) { + return Error(Error::Cancel, Error::ItemNotFound, QStringLiteral("Unknown node.")); + } + + switch (iq.queryType()) { + case QXmppDiscoveryIq::InfoQuery: { + // respond to info queries for the client itself + QXmppDiscoveryIq features = capabilities(); + features.setQueryNode(iq.queryNode()); + return features; + } + case QXmppDiscoveryIq::ItemsQuery: { + QXmppDiscoveryIq reply; + reply.setQueryType(QXmppDiscoveryIq::ItemsQuery); + return reply; + } + } + Q_UNREACHABLE(); +} /// \endcond -- cgit v1.2.3