diff options
| author | Linus Jahn <lnj@kaidan.im> | 2021-09-03 18:35:38 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2021-09-03 20:42:34 +0200 |
| commit | 09571ab88bbf8aa7f29b09036efe2b86688bd7d3 (patch) | |
| tree | 2d3493109f978cb675b690e0171a0c3ec1a00bb5 /src/base | |
| parent | 040b7d9a8c7625f93e93690e47dbabb71ff87fd7 (diff) | |
| download | qxmpp-09571ab88bbf8aa7f29b09036efe2b86688bd7d3.tar.gz | |
Adapt IQ parsing to new packet sending
Remove now unused QXmpp::PacketState.
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppFutureUtils_p.h | 7 | ||||
| -rw-r--r-- | src/base/QXmppGlobal.h.in | 11 | ||||
| -rw-r--r-- | src/base/QXmppStream.cpp | 19 | ||||
| -rw-r--r-- | src/base/QXmppStream.h | 2 |
4 files changed, 17 insertions, 22 deletions
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 <QXmppIq.h> +#include "QXmppIq.h" +#include "QXmppSendResult.h" #include <memory> #include <variant> @@ -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 @@ -89,17 +89,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. /// /// \since QXmpp 1.5 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<QXmpp::SendResult> QXmppStream::send(const QXmppNonza &nonza, bool &writ /// QFuture<QXmppStream::IqResult> 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::IqResult> QXmppStream::sendIq(const QXmppIq &iq) auto sendFuture = send(iq); if (sendFuture.isFinished()) { - if (std::holds_alternative<QXmpp::SendError>(sendFuture.result())) { + if (std::holds_alternative<SendError>(sendFuture.result())) { // early exit (saves QFutureWatcher) - return makeReadyFuture<IqResult>(QXmpp::NotSent); + return makeReadyFuture<IqResult>(std::get<SendError>(sendFuture.result())); } } else { - awaitLast(sendFuture, this, [this, id = iq.id()](QXmpp::SendResult result) { - if (std::holds_alternative<QXmpp::SendError>(result)) { + awaitLast(sendFuture, this, [this, id = iq.id()](SendResult result) { + if (std::holds_alternative<SendError>(result)) { if (auto itr = d->runningIqs.find(id); itr != d->runningIqs.end()) { - itr.value().reportResult(QXmpp::NotSent); + itr.value().reportResult(std::get<SendError>(result)); itr.value().reportFinished(); d->runningIqs.erase(itr); @@ -252,14 +254,17 @@ QFuture<QXmppStream::IqResult> 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<QXmpp::SendResult> send(const QXmppNonza &); - using IqResult = std::variant<QDomElement, QXmpp::PacketState>; + using IqResult = std::variant<QDomElement, QXmpp::SendError>; QFuture<IqResult> sendIq(const QXmppIq &); void cancelOngoingIqs(); |
