diff options
| author | Linus Jahn <lnj@kaidan.im> | 2022-10-16 21:57:01 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-10-17 16:26:03 +0200 |
| commit | b0a7853a956e7d05ef4c0832675d47961fc43125 (patch) | |
| tree | 015841ada7f2a7b15c5e7a61003a9fca140c9636 /src/client/QXmppDiscoveryManager.cpp | |
| parent | c85c9c460907e26604554f1b2c6f54734bc8f303 (diff) | |
| download | qxmpp-b0a7853a956e7d05ef4c0832675d47961fc43125.tar.gz | |
DiscoveryManager: Use new IQ request handling
Diffstat (limited to 'src/client/QXmppDiscoveryManager.cpp')
| -rw-r--r-- | src/client/QXmppDiscoveryManager.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
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 <QCoreApplication> @@ -307,28 +307,17 @@ QStringList QXmppDiscoveryManager::discoveryFeatures() const bool QXmppDiscoveryManager::handleStanza(const QDomElement &element) { + if (QXmpp::handleIqRequests<QXmppDiscoveryIq>(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<QXmppDiscoveryIq, QXmppStanza::Error> 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 |
