diff options
| author | Linus Jahn <lnj@kaidan.im> | 2021-07-05 15:17:12 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2021-07-05 18:07:28 +0200 |
| commit | 28aad17d6d928ee0a983d7032ae0f11fbc71bb06 (patch) | |
| tree | 84ddbf79ec563dca6698eb711cdaa7d6eb08cc5c /src | |
| parent | a35d7e7b8eac25d0cb088d60cb2f00ec05a41800 (diff) | |
| download | qxmpp-28aad17d6d928ee0a983d7032ae0f11fbc71bb06.tar.gz | |
Add QXmppClient::sendGenericIq() just returning Success/StanzaError
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppGlobal.h.in | 5 | ||||
| -rw-r--r-- | src/client/QXmppClient.cpp | 38 | ||||
| -rw-r--r-- | src/client/QXmppClient.h | 6 |
3 files changed, 47 insertions, 2 deletions
diff --git a/src/base/QXmppGlobal.h.in b/src/base/QXmppGlobal.h.in index ac249558..2e1a6be6 100644 --- a/src/base/QXmppGlobal.h.in +++ b/src/base/QXmppGlobal.h.in @@ -92,6 +92,11 @@ enum PacketState : quint8 { NotSent, ///< The packet could not be sent (e.g. connection broke or user disconnected). }; +/// +/// An empty struct indicating success in results. +/// +struct Success {}; + } #endif // QXMPPGLOBAL_H diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 4f8bfc26..74875275 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -29,6 +29,7 @@ #include "QXmppDiscoveryIq.h" #include "QXmppDiscoveryManager.h" #include "QXmppEntityTimeManager.h" +#include "QXmppFutureUtils_p.h" #include "QXmppLogger.h" #include "QXmppMessage.h" #include "QXmppOutgoingClient.h" @@ -117,6 +118,18 @@ QStringList QXmppClientPrivate::discoveryFeatures() /// (with type 'error' or 'result') or it contains the packet error, if the /// request couldn't be sent. /// +/// \since QXmpp 1.5 +/// + +/// +/// \typedef QXmppClient::EmptyResult +/// +/// Result of a generic request without a return value. Contains Success in case +/// everything went well. If the returned IQ contained an error a +/// QXmppStanza::Error is reported. +/// +/// \since QXmpp 1.5 +/// /// Creates a QXmppClient object. /// \param parent is passed to the QObject's constructor. @@ -345,6 +358,10 @@ QFuture<QXmpp::PacketState> QXmppClient::send(const QXmppStanza &stanza) /// /// Sends an IQ packet and returns the response asynchronously. /// +/// This is useful for further processing and parsing of the returned +/// QDomElement. If you don't expect a special response, you may want use +/// sendGenericIq(). +/// /// \warning THIS API IS NOT FINALIZED YET! /// /// \since QXmpp 1.5 @@ -354,6 +371,27 @@ QFuture<QXmppClient::IqResult> QXmppClient::sendIq(const QXmppIq &iq) return d->stream->sendIq(iq); } +/// +/// Sends an IQ and returns possible stanza errors. +/// +/// If you want to parse a special IQ response in the result case, you can use +/// sendIq() and parse the returned QDomElement. +/// +/// \returns Returns QXmpp::Success (on response type 'result') or the contained +/// QXmppStanza::Error (on response type 'error') +/// +/// \warning THIS API IS NOT FINALIZED YET! +/// +/// \since QXmpp 1.5 +/// +QFuture<QXmppClient::EmptyResult> QXmppClient::sendGenericIq(const QXmppIq &iq) +{ + using namespace QXmpp::Private; + return chainIq<EmptyResult, QXmppIq>(sendIq(iq), this, [](const QXmppIq &) { + return QXmpp::Success(); + }); +} + /// 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 202c9c5a..e341fad7 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -105,6 +105,9 @@ class QXMPP_EXPORT QXmppClient : public QXmppLoggable Q_PROPERTY(State state READ state NOTIFY stateChanged) public: + using IqResult = std::variant<QDomElement, QXmpp::PacketState>; + using EmptyResult = std::variant<QXmpp::Success, QXmppStanza::Error>; + /// An enumeration for type of error. /// Error could come due a TCP socket or XML stream or due to various stanzas. enum Error { @@ -220,9 +223,8 @@ public: QXmppStanza::Error::Condition xmppStreamError(); QFuture<QXmpp::PacketState> send(const QXmppStanza &); - - using IqResult = std::variant<QDomElement, QXmpp::PacketState>; QFuture<IqResult> sendIq(const QXmppIq &); + QFuture<EmptyResult> sendGenericIq(const QXmppIq &iq); #if QXMPP_DEPRECATED_SINCE(1, 1) QT_DEPRECATED_X("Use QXmppClient::findExtension<QXmppRosterManager>() instead") |
