aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent93c35b3f1260f3dfafbc77609fcadb9a40a7b97f (diff)
downloadqxmpp-6efebe555d30170c2ecfc2372113f342c513b0c2.tar.gz
Replace QXmpp::SendError with QXmppError everywhere
Part of #501.
Diffstat (limited to 'src')
-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
-rw-r--r--src/client/QXmppCarbonManagerV2.cpp16
-rw-r--r--src/client/QXmppClient.cpp12
-rw-r--r--src/client/QXmppClient.h2
-rw-r--r--src/client/QXmppE2eeExtension.h6
-rw-r--r--src/client/QXmppMamManager.cpp3
-rw-r--r--src/omemo/QXmppOmemoManager.cpp20
-rw-r--r--src/omemo/QXmppOmemoManager_p.cpp19
12 files changed, 68 insertions, 64 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();
}
diff --git a/src/client/QXmppCarbonManagerV2.cpp b/src/client/QXmppCarbonManagerV2.cpp
index fa162612..1c3a6fcc 100644
--- a/src/client/QXmppCarbonManagerV2.cpp
+++ b/src/client/QXmppCarbonManagerV2.cpp
@@ -62,7 +62,7 @@ auto firstChildElement(const QDomElement &el, const char *tagName, const char *x
return QDomElement();
}
-auto parseIq(std::variant<QDomElement, SendError> &&sendResult) -> std::optional<QXmppStanza::Error>
+auto parseIq(std::variant<QDomElement, QXmppError> &&sendResult) -> std::optional<QXmppError>
{
if (auto el = std::get_if<QDomElement>(&sendResult)) {
auto iqType = el->attribute(QStringLiteral("type"));
@@ -71,11 +71,13 @@ auto parseIq(std::variant<QDomElement, SendError> &&sendResult) -> std::optional
}
QXmppIq iq;
iq.parse(*el);
- return iq.error();
- } else if (auto err = std::get_if<SendError>(&sendResult)) {
- using Error = QXmppStanza::Error;
- return Error(Error::Wait, Error::UndefinedCondition,
- QStringLiteral("Couldn't send request: ") + err->text);
+ if (auto error = iq.errorOptional()) {
+ return QXmppError { error->text(), std::move(*error) };
+ }
+ // Only happens with IQs with type=error, but no <error/> element
+ return QXmppError { QStringLiteral("Unknown error received."), QXmppStanza::Error() };
+ } else if (auto err = std::get_if<QXmppError>(&sendResult)) {
+ return *err;
}
return {};
}
@@ -163,7 +165,7 @@ void QXmppCarbonManagerV2::enableCarbons()
await(client()->sendIq(CarbonEnableIq()), this, [this](QXmppClient::IqResult domResult) {
if (auto err = parseIq(std::move(domResult))) {
- warning("Could not enable message carbons: " % err->text());
+ warning("Could not enable message carbons: " % err->description);
} else {
info("Message Carbons enabled.");
}
diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp
index a6d55fa8..c0d7ee42 100644
--- a/src/client/QXmppClient.cpp
+++ b/src/client/QXmppClient.cpp
@@ -423,7 +423,7 @@ QFuture<QXmpp::SendResult> QXmppClient::send(QXmppStanza &&stanza, const std::op
reportFinishedResult(interface, result);
});
} else {
- reportFinishedResult(interface, { std::get<QXmpp::SendError>(result) });
+ reportFinishedResult(interface, { std::get<QXmppError>(result) });
}
});
@@ -526,7 +526,7 @@ QFuture<QXmppClient::IqResult> QXmppClient::sendSensitiveIq(QXmppIq &&iq, const
await(future, this, [this, interface](QXmppStream::IqResult result) mutable {
if (const auto encryptedDom = std::get_if<QDomElement>(&result)) {
if (!isIqResponse(*encryptedDom)) {
- QXmpp::SendError err {
+ QXmppError err {
QStringLiteral("Invalid IQ response received."),
QXmpp::SendError::EncryptionError
};
@@ -543,24 +543,24 @@ QFuture<QXmppClient::IqResult> QXmppClient::sendSensitiveIq(QXmppIq &&iq, const
// the IQ response from the other entity was not encrypted
// then report IQ response without modifications
interface.reportResult(encryptedDom);
- } else if (const auto error = std::get_if<QXmpp::SendError>(&result)) {
+ } else if (const auto error = std::get_if<QXmppError>(&result)) {
interface.reportResult(*error);
}
interface.reportFinished();
});
} else {
- interface.reportResult(QXmpp::SendError {
+ interface.reportResult(QXmppError {
QStringLiteral("No decryption extension found."),
QXmpp::SendError::EncryptionError });
interface.reportFinished();
}
} else {
- interface.reportResult(std::get<QXmpp::SendError>(result));
+ interface.reportResult(std::get<QXmppError>(result));
interface.reportFinished();
}
});
} else {
- interface.reportResult(std::get<QXmpp::SendError>(result));
+ interface.reportResult(std::get<QXmppError>(result));
interface.reportFinished();
}
});
diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h
index daca8cc9..e99937cb 100644
--- a/src/client/QXmppClient.h
+++ b/src/client/QXmppClient.h
@@ -90,7 +90,7 @@ class QXMPP_EXPORT QXmppClient : public QXmppLoggable
Q_PROPERTY(State state READ state NOTIFY stateChanged)
public:
- using IqResult = std::variant<QDomElement, QXmpp::SendError>;
+ using IqResult = std::variant<QDomElement, QXmppError>;
using EmptyResult = std::variant<QXmpp::Success, QXmppStanza::Error>;
/// An enumeration for type of error.
diff --git a/src/client/QXmppE2eeExtension.h b/src/client/QXmppE2eeExtension.h
index 295de1a3..f65fec45 100644
--- a/src/client/QXmppE2eeExtension.h
+++ b/src/client/QXmppE2eeExtension.h
@@ -25,10 +25,10 @@ public:
{
};
- using MessageEncryptResult = std::variant<QByteArray, QXmpp::SendError>;
+ using MessageEncryptResult = std::variant<QByteArray, QXmppError>;
using MessageDecryptResult = std::variant<QXmppMessage, NotEncrypted, QXmppError>;
- using IqEncryptResult = std::variant<QByteArray, QXmpp::SendError>;
- using IqDecryptResult = std::variant<QDomElement, NotEncrypted, QXmpp::SendError>;
+ using IqEncryptResult = std::variant<QByteArray, QXmppError>;
+ using IqDecryptResult = std::variant<QDomElement, NotEncrypted, QXmppError>;
virtual QFuture<MessageEncryptResult> encryptMessage(QXmppMessage &&, const std::optional<QXmppSendStanzaParams> &) = 0;
virtual QFuture<MessageDecryptResult> decryptMessage(QXmppMessage &&) = 0;
diff --git a/src/client/QXmppMamManager.cpp b/src/client/QXmppMamManager.cpp
index 9050c02f..125e9a48 100644
--- a/src/client/QXmppMamManager.cpp
+++ b/src/client/QXmppMamManager.cpp
@@ -300,8 +300,7 @@ QFuture<QXmppMamManager::RetrieveResult> QXmppMamManager::retrieveMessages(const
d->ongoingRequests.erase(itr);
}
} else {
- auto &error = std::get<QXmpp::SendError>(result);
- itr->second.interface.reportResult(QXmppError { error.text, error });
+ itr->second.interface.reportResult(std::get<QXmppError>(result));
itr->second.interface.reportFinished();
d->ongoingRequests.erase(itr);
}
diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp
index 856e00a5..11a7ec36 100644
--- a/src/omemo/QXmppOmemoManager.cpp
+++ b/src/omemo/QXmppOmemoManager.cpp
@@ -1030,10 +1030,10 @@ QFuture<QXmppE2eeExtension::IqEncryptResult> Manager::encryptIq(QXmppIq &&iq, co
QFutureInterface<QXmppE2eeExtension::IqEncryptResult> interface(QFutureInterfaceBase::Started);
if (!d->isStarted) {
- QXmpp::SendError error;
- error.text = QStringLiteral("OMEMO manager must be started before encrypting");
- error.type = QXmpp::SendError::EncryptionError;
- reportFinishedResult(interface, { error });
+ interface.reportResult(QXmppError {
+ QStringLiteral("OMEMO manager must be started before encrypting"),
+ SendError::EncryptionError });
+ interface.reportFinished();
} else {
std::optional<TrustLevels> acceptedTrustLevels;
@@ -1048,10 +1048,10 @@ QFuture<QXmppE2eeExtension::IqEncryptResult> Manager::encryptIq(QXmppIq &&iq, co
auto future = d->encryptStanza(iq, { QXmppUtils::jidToBareJid(iq.to()) }, *acceptedTrustLevels);
await(future, this, [=, iq = std::move(iq)](std::optional<QXmppOmemoElement> omemoElement) mutable {
if (!omemoElement) {
- QXmpp::SendError error;
- error.text = QStringLiteral("OMEMO element could not be created");
- error.type = QXmpp::SendError::EncryptionError;
- reportFinishedResult(interface, { error });
+ interface.reportResult(QXmppError {
+ QStringLiteral("OMEMO element could not be created"),
+ SendError::EncryptionError });
+ interface.reportFinished();
} else {
QXmppOmemoIq omemoIq;
omemoIq.setId(iq.id());
@@ -1077,7 +1077,7 @@ QFuture<QXmppE2eeExtension::IqDecryptResult> Manager::decryptIq(const QDomElemen
{
if (!d->isStarted) {
// TODO: Add decryption queue to avoid this error
- return makeReadyFuture<IqDecryptResult>(SendError {
+ return makeReadyFuture<IqDecryptResult>(QXmppError {
QStringLiteral("OMEMO manager must be started before decrypting"),
SendError::EncryptionError });
}
@@ -1088,7 +1088,7 @@ QFuture<QXmppE2eeExtension::IqDecryptResult> Manager::decryptIq(const QDomElemen
if (result) {
return result->iq;
}
- return SendError {
+ return QXmppError {
QStringLiteral("OMEMO message could not be decrypted"),
SendError::EncryptionError
};
diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp
index 805f0b56..01981fad 100644
--- a/src/omemo/QXmppOmemoManager_p.cpp
+++ b/src/omemo/QXmppOmemoManager_p.cpp
@@ -1031,7 +1031,10 @@ QFuture<QXmppE2eeExtension::MessageEncryptResult> ManagerPrivate::encryptMessage
QFutureInterface<QXmppE2eeExtension::MessageEncryptResult> interface(QFutureInterfaceBase::Started);
if (!isStarted) {
- QXmpp::SendError error = { QStringLiteral("OMEMO manager must be started before encrypting"), QXmpp::SendError::EncryptionError };
+ QXmppError error {
+ QStringLiteral("OMEMO manager must be started before encrypting"),
+ SendError::EncryptionError
+ };
reportFinishedResult(interface, { error });
} else {
recipientJids.append(ownBareJid());
@@ -1039,9 +1042,10 @@ QFuture<QXmppE2eeExtension::MessageEncryptResult> ManagerPrivate::encryptMessage
auto future = encryptStanza(message, recipientJids, acceptedTrustLevels);
await(future, q, [=, message = std::move(message)](std::optional<QXmppOmemoElement> omemoElement) mutable {
if (!omemoElement) {
- QXmpp::SendError error;
- error.text = QStringLiteral("OMEMO element could not be created");
- error.type = QXmpp::SendError::EncryptionError;
+ QXmppError error {
+ QStringLiteral("OMEMO element could not be created"),
+ QXmpp::SendError::EncryptionError,
+ };
reportFinishedResult(interface, { error });
} else {
const auto areDeliveryReceiptsUsed = message.isReceiptRequested() || !message.receiptId().isEmpty();
@@ -3336,7 +3340,7 @@ QFuture<bool> ManagerPrivate::buildSessionWithDeviceBundle(const QString &jid, u
} else {
auto future = sendEmptyMessage(jid, deviceId, true);
await(future, q, [=](QXmpp::SendResult result) mutable {
- if (std::holds_alternative<QXmpp::SendError>(result)) {
+ if (std::holds_alternative<QXmppError>(result)) {
warning("Session could be created but empty message could not be sent to JID '" %
jid % "' and device ID '" % QString::number(deviceId) % "'");
reportFinishedResult(interface, false);
@@ -3580,7 +3584,10 @@ QFuture<QXmpp::SendResult> ManagerPrivate::sendEmptyMessage(const QString &recip
warning("OMEMO envelope for recipient JID '" % recipientJid % "' and device ID '" %
QString::number(recipientDeviceId) %
"' could not be created because its data could not be encrypted");
- SendError error = { QStringLiteral("OMEMO envelope could not be created"), SendError::EncryptionError };
+ QXmppError error {
+ QStringLiteral("OMEMO envelope could not be created"),
+ SendError::EncryptionError
+ };
reportFinishedResult(interface, { error });
} else {
QXmppOmemoEnvelope omemoEnvelope;