From 09571ab88bbf8aa7f29b09036efe2b86688bd7d3 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 3 Sep 2021 18:35:38 +0200 Subject: Adapt IQ parsing to new packet sending Remove now unused QXmpp::PacketState. --- src/base/QXmppFutureUtils_p.h | 7 ++++--- src/base/QXmppGlobal.h.in | 11 ----------- src/base/QXmppStream.cpp | 19 ++++++++++++------- src/base/QXmppStream.h | 2 +- 4 files changed, 17 insertions(+), 22 deletions(-) (limited to 'src/base') diff --git a/src/base/QXmppFutureUtils_p.h b/src/base/QXmppFutureUtils_p.h index 0cad95f5..f63e30b2 100644 --- a/src/base/QXmppFutureUtils_p.h +++ b/src/base/QXmppFutureUtils_p.h @@ -34,7 +34,8 @@ // We mean it. // -#include +#include "QXmppIq.h" +#include "QXmppSendResult.h" #include #include @@ -147,10 +148,10 @@ auto parseIq(Input &&sendResult, Converter convert) -> decltype(convert({})) } return convert(std::move(iq)); }, - [](QXmpp::PacketState) -> Result { + [](QXmpp::SendError error) -> Result { using Error = QXmppStanza::Error; return Error(Error::Wait, Error::UndefinedCondition, - QStringLiteral("Couldn't send request: lost connection.")); + QStringLiteral("Couldn't send request: ") + error.text); }, }, sendResult); diff --git a/src/base/QXmppGlobal.h.in b/src/base/QXmppGlobal.h.in index b285a35e..a83afba9 100644 --- a/src/base/QXmppGlobal.h.in +++ b/src/base/QXmppGlobal.h.in @@ -88,17 +88,6 @@ inline QLatin1String QXmppVersion() /// namespace QXmpp { -/// -/// The state of an outgoing packet. -/// -/// \since QXmpp 1.5 -/// -enum PacketState : uint8_t { - Sent, ///< The packet has been written to the socket. - Acknowledged, ///< The packet has been acknowledged by the other peer using Stream Management. - NotSent, ///< The packet could not be sent (e.g. connection broke or user disconnected). -}; - /// /// An empty struct indicating success in results. /// diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp index 0ede6b18..3443d6d4 100644 --- a/src/base/QXmppStream.cpp +++ b/src/base/QXmppStream.cpp @@ -212,6 +212,8 @@ QFuture QXmppStream::send(const QXmppNonza &nonza, bool &writ /// QFuture QXmppStream::sendIq(const QXmppIq &iq) { + using namespace QXmpp; + if (iq.id().isEmpty()) { warning(QStringLiteral("QXmppStream::sendIq() error: ID is empty. Using random ID.")); auto newIq = iq; @@ -229,15 +231,15 @@ QFuture QXmppStream::sendIq(const QXmppIq &iq) auto sendFuture = send(iq); if (sendFuture.isFinished()) { - if (std::holds_alternative(sendFuture.result())) { + if (std::holds_alternative(sendFuture.result())) { // early exit (saves QFutureWatcher) - return makeReadyFuture(QXmpp::NotSent); + return makeReadyFuture(std::get(sendFuture.result())); } } else { - awaitLast(sendFuture, this, [this, id = iq.id()](QXmpp::SendResult result) { - if (std::holds_alternative(result)) { + awaitLast(sendFuture, this, [this, id = iq.id()](SendResult result) { + if (std::holds_alternative(result)) { if (auto itr = d->runningIqs.find(id); itr != d->runningIqs.end()) { - itr.value().reportResult(QXmpp::NotSent); + itr.value().reportResult(std::get(result)); itr.value().reportFinished(); d->runningIqs.erase(itr); @@ -252,14 +254,17 @@ QFuture QXmppStream::sendIq(const QXmppIq &iq) } /// -/// Cancels all ongoing IQ requests and reports QXmpp::NotSent. +/// Cancels all ongoing IQ requests and reports QXmpp::SendError::Disconnected. /// /// \since QXmpp 1.5 /// void QXmppStream::cancelOngoingIqs() { for (auto &state : d->runningIqs) { - state.reportResult(QXmpp::NotSent); + state.reportResult(QXmpp::SendError { + QStringLiteral("IQ has been cancelled."), + QXmpp::SendError::Disconnected + }); state.reportFinished(); } d->runningIqs.clear(); diff --git a/src/base/QXmppStream.h b/src/base/QXmppStream.h index dd327a92..b5bfb95a 100644 --- a/src/base/QXmppStream.h +++ b/src/base/QXmppStream.h @@ -59,7 +59,7 @@ public: bool sendPacket(const QXmppNonza &); QFuture send(const QXmppNonza &); - using IqResult = std::variant; + using IqResult = std::variant; QFuture sendIq(const QXmppIq &); void cancelOngoingIqs(); -- cgit v1.2.3