aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2022-12-30 23:35:47 +0100
committerLinus Jahn <lnj@kaidan.im>2022-12-30 23:35:47 +0100
commit6efebe555d30170c2ecfc2372113f342c513b0c2 (patch)
tree146535dd164abe60d28a020a2680e17c0de2b055 /src/base
parent93c35b3f1260f3dfafbc77609fcadb9a40a7b97f (diff)
downloadqxmpp-6efebe555d30170c2ecfc2372113f342c513b0c2.tar.gz
Replace QXmpp::SendError with QXmppError everywhere
Part of #501.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppFutureUtils_p.h4
-rw-r--r--src/base/QXmppSendResult.h30
-rw-r--r--src/base/QXmppStream.cpp14
-rw-r--r--src/base/QXmppStream.h2
-rw-r--r--src/base/QXmppStreamManagement.cpp4
5 files changed, 25 insertions, 29 deletions
diff --git a/src/base/QXmppFutureUtils_p.h b/src/base/QXmppFutureUtils_p.h
index d69ec7fd..311e7019 100644
--- a/src/base/QXmppFutureUtils_p.h
+++ b/src/base/QXmppFutureUtils_p.h
@@ -150,10 +150,10 @@ auto parseIq(Input &&sendResult, Converter convert) -> decltype(convert({}))
}
return convert(std::move(iq));
},
- [](QXmpp::SendError error) -> Result {
+ [](QXmppError error) -> Result {
using Error = QXmppStanza::Error;
return Error(Error::Wait, Error::UndefinedCondition,
- QStringLiteral("Couldn't send request: ") + error.text);
+ QStringLiteral("Couldn't send request: ") + error.description);
},
},
sendResult);
diff --git a/src/base/QXmppSendResult.h b/src/base/QXmppSendResult.h
index b4b4ce81..451387ac 100644
--- a/src/base/QXmppSendResult.h
+++ b/src/base/QXmppSendResult.h
@@ -5,30 +5,24 @@
#ifndef QXMPPSENDRESULT_H
#define QXMPPSENDRESULT_H
-#include "QXmppGlobal.h"
+#include "QXmppError.h"
#include <variant>
namespace QXmpp {
///
-/// A struct containing a packet send error type and error message.
+/// Describes the type of a packet sending error.
///
/// \since QXmpp 1.5
///
-struct SendError
-{
- /// Describes the type of an error.
- enum Type : uint8_t {
- SocketWriteError, ///< The packet was written to the socket with no success (only happens when Stream Management is disabled).
- Disconnected, ///< The packet couldn't be sent because the connection hasn't been (re)established.
- EncryptionError, ///< The packet couldn't be sent because prior encryption failed.
- };
-
- /// Text describing the error.
- QString text;
- /// Type of the occured error.
- Type type;
+enum class SendError : uint8_t {
+ /// The packet was written to the socket with no success (only happens when Stream Management is disabled).
+ SocketWriteError,
+ /// The packet couldn't be sent because the connection hasn't been (re)established.
+ Disconnected,
+ /// The packet couldn't be sent because prior encryption failed.
+ EncryptionError,
};
///
@@ -43,9 +37,11 @@ struct SendSuccess
};
///
-/// A variant containing either a SendSuccess object or a SendError.
+/// A variant containing either a SendSuccess object or a QXmppError.
+///
+/// The QXmppError will likely contain a SendError.
///
-using SendResult = std::variant<SendSuccess, SendError>;
+using SendResult = std::variant<SendSuccess, QXmppError>;
} // namespace QXmpp
diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp
index c650b8ac..cbe40b8a 100644
--- a/src/base/QXmppStream.cpp
+++ b/src/base/QXmppStream.cpp
@@ -238,28 +238,28 @@ QFuture<QXmppStream::IqResult> QXmppStream::sendIq(QXmppPacket &&packet, const Q
using namespace QXmpp;
if (id.isEmpty() || d->runningIqs.contains(id)) {
- return makeReadyFuture<IqResult>(QXmpp::SendError {
+ return makeReadyFuture<IqResult>(QXmppError {
QStringLiteral("Invalid IQ id: empty or in use."),
SendError::Disconnected });
}
if (to.isEmpty()) {
- return makeReadyFuture<IqResult>(SendError {
+ return makeReadyFuture<IqResult>(QXmppError {
QStringLiteral("The 'to' address must be set so the stream can match the response."),
SendError::Disconnected });
}
auto sendFuture = send(std::move(packet));
if (sendFuture.isFinished()) {
- if (std::holds_alternative<SendError>(sendFuture.result())) {
+ if (std::holds_alternative<QXmppError>(sendFuture.result())) {
// early exit (saves QFutureWatcher)
- return makeReadyFuture<IqResult>(std::get<SendError>(sendFuture.result()));
+ return makeReadyFuture<IqResult>(std::get<QXmppError>(sendFuture.result()));
}
} else {
awaitLast(sendFuture, this, [this, id](SendResult result) {
- if (std::holds_alternative<SendError>(result)) {
+ if (std::holds_alternative<QXmppError>(result)) {
if (auto itr = d->runningIqs.find(id); itr != d->runningIqs.end()) {
- itr.value().interface.reportResult(std::get<SendError>(result));
+ itr.value().interface.reportResult(std::get<QXmppError>(result));
itr.value().interface.reportFinished();
d->runningIqs.erase(itr);
@@ -285,7 +285,7 @@ QFuture<QXmppStream::IqResult> QXmppStream::sendIq(QXmppPacket &&packet, const Q
void QXmppStream::cancelOngoingIqs()
{
for (auto &state : d->runningIqs) {
- state.interface.reportResult(QXmpp::SendError {
+ state.interface.reportResult(QXmppError {
QStringLiteral("IQ has been cancelled."),
QXmpp::SendError::Disconnected });
state.interface.reportFinished();
diff --git a/src/base/QXmppStream.h b/src/base/QXmppStream.h
index f8c4e548..464d576d 100644
--- a/src/base/QXmppStream.h
+++ b/src/base/QXmppStream.h
@@ -44,7 +44,7 @@ public:
QFuture<QXmpp::SendResult> send(QXmppNonza &&);
QFuture<QXmpp::SendResult> send(QXmppPacket &&);
- using IqResult = std::variant<QDomElement, QXmpp::SendError>;
+ using IqResult = std::variant<QDomElement, QXmppError>;
QFuture<IqResult> sendIq(QXmppIq &&);
QFuture<IqResult> sendIq(QXmppPacket &&, const QString &id, const QString &to);
void cancelOngoingIqs();
diff --git a/src/base/QXmppStreamManagement.cpp b/src/base/QXmppStreamManagement.cpp
index 67a28ef8..853327f9 100644
--- a/src/base/QXmppStreamManagement.cpp
+++ b/src/base/QXmppStreamManagement.cpp
@@ -355,7 +355,7 @@ void QXmppStreamManager::handlePacketSent(QXmppPacket &packet, bool sentData)
if (sentData) {
packet.reportResult(QXmpp::SendSuccess { false });
} else {
- packet.reportResult(QXmpp::SendError {
+ packet.reportResult(QXmppError {
QStringLiteral("Couldn't write data to socket. No stream management enabled."),
QXmpp::SendError::SocketWriteError });
}
@@ -472,7 +472,7 @@ void QXmppStreamManager::sendAcknowledgementRequest()
void QXmppStreamManager::resetCache()
{
for (auto &packet : m_unacknowledgedStanzas) {
- packet.reportResult(QXmpp::SendError { QStringLiteral("Disconnected"), QXmpp::SendError::Disconnected });
+ packet.reportResult(QXmppError { QStringLiteral("Disconnected"), QXmpp::SendError::Disconnected });
packet.reportFinished();
}