From 3caffcebf16680576d8dd785437eed16a6c5f36d Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 9 Sep 2020 15:05:23 +0200 Subject: Add reporting of IQ responses with QFutures --- src/client/QXmppClient.cpp | 21 +++++++++++++++++++++ src/client/QXmppClient.h | 3 +++ src/client/QXmppOutgoingClient.cpp | 16 +++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src/client') diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 6933a0a6..4f8bfc26 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -38,6 +38,7 @@ #include "QXmppVCardManager.h" #include "QXmppVersionManager.h" +#include #include #include #include @@ -109,6 +110,14 @@ QStringList QXmppClientPrivate::discoveryFeatures() } /// \endcond +/// +/// \typedef QXmppClient::IqResult +/// +/// Result of an IQ request, either contains the QDomElement of the IQ answer +/// (with type 'error' or 'result') or it contains the packet error, if the +/// request couldn't be sent. +/// + /// Creates a QXmppClient object. /// \param parent is passed to the QObject's constructor. /// The default value is 0. @@ -333,6 +342,18 @@ QFuture QXmppClient::send(const QXmppStanza &stanza) return d->stream->send(stanza); } +/// +/// Sends an IQ packet and returns the response asynchronously. +/// +/// \warning THIS API IS NOT FINALIZED YET! +/// +/// \since QXmpp 1.5 +/// +QFuture QXmppClient::sendIq(const QXmppIq &iq) +{ + return d->stream->sendIq(iq); +} + /// Disconnects the client and the current presence of client changes to /// QXmppPresence::Unavailable and status text changes to "Logged out". /// diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h index 56da95ee..202c9c5a 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -221,6 +221,9 @@ public: QFuture send(const QXmppStanza &); + using IqResult = std::variant; + QFuture sendIq(const QXmppIq &); + #if QXMPP_DEPRECATED_SINCE(1, 1) QT_DEPRECATED_X("Use QXmppClient::findExtension() instead") QXmppRosterManager &rosterManager(); diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index a8bfb62d..6479f334 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -213,6 +213,20 @@ QXmppOutgoingClient::QXmppOutgoingClient(QObject *parent) connect(this, &QXmppStream::connected, this, &QXmppOutgoingClient::pingStart); connect(this, &QXmppStream::disconnected, this, &QXmppOutgoingClient::pingStop); + + // IQ response handling + connect(this, &QXmppStream::connected, this, [=]() { + if (!d->streamResumed) { + // we can't expect a response because this is a new stream + cancelOngoingIqs(); + } + }); + connect(this, &QXmppStream::disconnected, this, [=]() { + if (!d->canResume) { + // this stream can't be resumed; we can cancel all ongoing IQs + cancelOngoingIqs(); + } + }); } /// Destroys an outgoing client stream. @@ -510,7 +524,7 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) d->bindModeAvailable = (features.bindMode() != QXmppStreamFeatures::Disabled); d->streamManagementAvailable = (features.streamManagementMode() != QXmppStreamFeatures::Disabled); - // chech whether the stream can be resumed + // check whether the stream can be resumed if (d->streamManagementAvailable && d->canResume) { d->isResuming = true; QXmppStreamManagementResume streamManagementResume(lastIncomingSequenceNumber(), d->smId); -- cgit v1.2.3