Loading...
Searching...
No Matches
QXmppClient.h
// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
// SPDX-FileCopyrightText: 2023 Melvin Keskin <melvo@olomono.de>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPCLIENT_H
#define QXMPPCLIENT_H
#include "QXmppConfiguration.h"
#include "QXmppLogger.h"
#include "QXmppPresence.h"
#include "QXmppSendResult.h"
#include "QXmppSendStanzaParams.h"
#include "QXmppStreamError.h"
#include <memory>
#include <variant>
#include <QAbstractSocket>
#include <QObject>
#include <QSslError>
template<typename T>
class QXmppTask;
class QXmppE2eeExtension;
class QXmppClientExtension;
class QXmppClientPrivate;
class QXmppMessage;
class QXmppOutgoingClient;
class QXmppPresence;
class QXmppIq;
// managers
class QXmppDiscoveryIq;
class QXmppRosterManager;
class QXmppVCardManager;
class QXmppVersionManager;
namespace QXmpp::Private {
struct SessionBegin;
}
class QXMPP_EXPORT QXmppClient : public QXmppLoggable
{
Q_OBJECT
Q_PROPERTY(QXmppLogger *logger READ logger WRITE setLogger NOTIFY loggerChanged)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
public:
using IqResult = std::variant<QDomElement, QXmppError>;
using EmptyResult = std::variant<QXmpp::Success, QXmppError>;
enum Error {
NoError,
SocketError,
KeepAliveError,
XmppStreamError,
};
Q_ENUM(Error)
enum State {
DisconnectedState,
ConnectingState,
ConnectedState
};
Q_ENUM(State)
enum StreamManagementState {
NoStreamManagement,
NewStream,
ResumedStream
};
enum InitialExtensions {
NoExtensions,
BasicExtensions,
};
QXmppClient(InitialExtensions, QObject *parent = nullptr);
QXmppClient(QObject *parent = nullptr);
~QXmppClient() override;
bool addExtension(QXmppClientExtension *extension);
template<typename T, typename... Args>
T *addNewExtension(Args... args)
{
// it's impossible that addExtension() returns false: ext is a new object
auto *ext = new T(args...);
addExtension(ext);
return ext;
}
bool insertExtension(int index, QXmppClientExtension *extension);
bool removeExtension(QXmppClientExtension *extension);
QXmppE2eeExtension *encryptionExtension() const;
void setEncryptionExtension(QXmppE2eeExtension *);
QList<QXmppClientExtension *> extensions() const;
template<typename T>
T *findExtension() const
{
const QList<QXmppClientExtension *> list = extensions();
for (auto ext : list) {
T *extension = qobject_cast<T *>(ext);
if (extension) {
return extension;
}
}
return nullptr;
}
template<typename T>
int indexOfExtension() const
{
auto list = extensions();
for (int i = 0; i < list.size(); ++i) {
if (qobject_cast<T *>(list.at(i)) != nullptr) {
return i;
}
}
return -1;
}
bool isAuthenticated() const;
bool isConnected() const;
bool isActive() const;
void setActive(bool active);
StreamManagementState streamManagementState() const;
QXmppPresence clientPresence() const;
void setClientPresence(const QXmppPresence &presence);
QXmppConfiguration &configuration();
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QXmppLogger *logger() const;
void setLogger(QXmppLogger *logger);
QAbstractSocket::SocketError socketError();
QString socketErrorString() const;
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
State state() const;
QXmppStanza::Error::Condition xmppStreamError();
QXmppTask<QXmpp::SendResult> sendSensitive(QXmppStanza &&, const std::optional<QXmppSendStanzaParams> & = {});
QXmppTask<QXmpp::SendResult> send(QXmppStanza &&, const std::optional<QXmppSendStanzaParams> & = {});
QXmppTask<QXmpp::SendResult> reply(QXmppStanza &&stanza, const std::optional<QXmppE2eeMetadata> &e2eeMetadata, const std::optional<QXmppSendStanzaParams> & = {});
QXmppTask<IqResult> sendIq(QXmppIq &&, const std::optional<QXmppSendStanzaParams> & = {});
QXmppTask<IqResult> sendSensitiveIq(QXmppIq &&, const std::optional<QXmppSendStanzaParams> & = {});
QXmppTask<EmptyResult> sendGenericIq(QXmppIq &&, const std::optional<QXmppSendStanzaParams> & = {});
Q_SIGNAL void connected();
Q_SIGNAL void disconnected();
Q_SIGNAL void error(QXmppClient::Error);
Q_SIGNAL void errorOccurred(const QXmppError &error);
Q_SIGNAL void loggerChanged(QXmppLogger *logger);
Q_SIGNAL void messageReceived(const QXmppMessage &message);
Q_SIGNAL void presenceReceived(const QXmppPresence &presence);
Q_SIGNAL void iqReceived(const QXmppIq &iq);
Q_SIGNAL void sslErrors(const QList<QSslError> &errors);
Q_SIGNAL void stateChanged(QXmppClient::State state);
Q_SIGNAL void credentialsChanged();
Q_SLOT void connectToServer(const QXmppConfiguration &, const QXmppPresence &initialPresence = {});
Q_SLOT void connectToServer(const QString &jid, const QString &password);
Q_SLOT void disconnectFromServer();
#if QXMPP_DEPRECATED_SINCE(1, 1)
[[deprecated("Use findExtension<QXmppRosterManager>() instead")]]
QXmppRosterManager &rosterManager();
[[deprecated("Use findExtension<QXmppVCardManager>() instead")]]
QXmppVCardManager &vCardManager();
[[deprecated("Use findExtension<QXmppVersionManager>() instead")]]
QXmppVersionManager &versionManager();
#endif
#if QXMPP_DEPRECATED_SINCE(1, 12)
[[deprecated("Use async send()")]]
Q_SLOT bool sendPacket(const QXmppNonza &);
[[deprecated("Use async send()")]]
Q_SLOT void sendMessage(const QString &bareJid, const QString &message);
#endif
bool sendLegacy(const QXmppNonza &s)
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
return sendPacket(s);
QT_WARNING_POP
}
QString sendLegacyId(const QXmppStanza &s) { return sendLegacy(s) ? s.id() : QString(); }
private:
QXmppOutgoingClient *stream() const;
void injectIq(const QDomElement &element, const std::optional<QXmppE2eeMetadata> &e2eeMetadata);
bool injectMessage(QXmppMessage &&message);
void setIgnoredStreamErrors(const QVector<QXmpp::StreamError> &);
void _q_elementReceived(const QDomElement &element, bool &handled);
void _q_reconnect();
void onInternalSocketStateChanged();
void _q_streamConnected(const QXmpp::Private::SessionBegin &);
void _q_streamDisconnected();
const std::unique_ptr<QXmppClientPrivate> d;
friend class QXmppClientExtension;
friend class QXmppCarbonManagerV2;
friend class QXmppRegistrationManager;
friend class TestClient;
};
#endif // QXMPPCLIENT_H
QXmppClientExtension
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:32
QXmppClient
Main class for starting and managing connections to XMPP servers.
Definition QXmppClient.h:62
QXmppClient::connected
Q_SIGNAL void connected()
QXmppClient::credentialsChanged
Q_SIGNAL void credentialsChanged()
QXmppClient::loggerChanged
Q_SIGNAL void loggerChanged(QXmppLogger *logger)
This signal is emitted when the logger changes.
QXmppClient::indexOfExtension
int indexOfExtension() const
Returns the index of an extension.
Definition QXmppClient.h:173
QXmppClient::messageReceived
Q_SIGNAL void messageReceived(const QXmppMessage &message)
QXmppClient::findExtension
T * findExtension() const
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Definition QXmppClient.h:145
QXmppClient::error
Q_SIGNAL void error(QXmppClient::Error)
QXmppClient::InitialExtensions
InitialExtensions
Definition QXmppClient.h:104
QXmppClient::BasicExtensions
@ BasicExtensions
Creates a client with the default set of extensions.
Definition QXmppClient.h:108
QXmppClient::NoExtensions
@ NoExtensions
Creates a client without any extensions.
Definition QXmppClient.h:106
QXmppClient::disconnected
Q_SIGNAL void disconnected()
This signal is emitted when the XMPP connection disconnects.
QXmppClient::State
State
This enumeration describes a client state.
Definition QXmppClient.h:85
QXmppClient::DisconnectedState
@ DisconnectedState
Disconnected from the server.
Definition QXmppClient.h:86
QXmppClient::ConnectingState
@ ConnectingState
Trying to connect to the server.
Definition QXmppClient.h:87
QXmppClient::ConnectedState
@ ConnectedState
Connected to the server.
Definition QXmppClient.h:88
QXmppClient::addExtension
bool addExtension(QXmppClientExtension *extension)
Registers a new extension with the client.
Definition QXmppClient.cpp:378
QXmppClient::errorOccurred
Q_SIGNAL void errorOccurred(const QXmppError &error)
QXmppClient::Error
Error
Definition QXmppClient.h:76
QXmppClient::NoError
@ NoError
No error.
Definition QXmppClient.h:77
QXmppClient::XmppStreamError
@ XmppStreamError
Error due to XML stream.
Definition QXmppClient.h:80
QXmppClient::KeepAliveError
@ KeepAliveError
Error due to no response to a keep alive.
Definition QXmppClient.h:79
QXmppClient::SocketError
@ SocketError
Error due to TCP socket.
Definition QXmppClient.h:78
QXmppClient::state
State state
The client's current state.
Definition QXmppClient.h:68
QXmppClient::extensions
QList< QXmppClientExtension * > extensions() const
Returns a list containing all the client's extensions.
Definition QXmppClient.cpp:435
QXmppClient::stateChanged
Q_SIGNAL void stateChanged(QXmppClient::State state)
This signal is emitted when the client state changes.
QXmppClient::setLogger
void setLogger(QXmppLogger *logger)
Sets the QXmppLogger associated with the current QXmppClient.
Definition QXmppClient.cpp:947
QXmppClient::presenceReceived
Q_SIGNAL void presenceReceived(const QXmppPresence &presence)
QXmppClient::StreamManagementState
StreamManagementState
Describes the use of XEP-0198: Stream Management.
Definition QXmppClient.h:93
QXmppClient::ResumedStream
@ ResumedStream
Stream Management is used and the previous stream has been resumed.
Definition QXmppClient.h:99
QXmppClient::NoStreamManagement
@ NoStreamManagement
Stream Management is not used.
Definition QXmppClient.h:95
QXmppClient::NewStream
@ NewStream
Stream Management is used and the previous stream has not been resumed.
Definition QXmppClient.h:97
QXmppClient::connectToServer
Q_SLOT void connectToServer(const QXmppConfiguration &, const QXmppPresence &initialPresence={})
Definition QXmppClient.cpp:456
QXmppClient::addNewExtension
T * addNewExtension(Args... args)
Definition QXmppClient.h:117
QXmppClient::EmptyResult
std::variant< QXmpp::Success, QXmppError > EmptyResult
Definition QXmppClient.h:72
QXmppClient::QXmppClient
QXmppClient(InitialExtensions, QObject *parent=nullptr)
Definition QXmppClient.cpp:300
QXmppClient::sslErrors
Q_SIGNAL void sslErrors(const QList< QSslError > &errors)
QXmppClient::iqReceived
Q_SIGNAL void iqReceived(const QXmppIq &iq)
QXmppClient::logger
QXmppLogger * logger
The QXmppLogger associated with the current QXmppClient.
Definition QXmppClient.h:66
QXmppClient::IqResult
std::variant< QDomElement, QXmppError > IqResult
Definition QXmppClient.h:71
QXmppConfiguration
The QXmppConfiguration class holds configuration options.
Definition QXmppConfiguration.h:37
QXmppDiscoveryIq
Definition QXmppDiscoveryIq.h:200
QXmppE2eeExtension
Definition QXmppE2eeExtension.h:23
QXmppIq
The QXmppIq class is the base class for all IQs.
Definition QXmppIq.h:23
QXmppLoggable::QXmppLoggable
QXmppLoggable(QObject *parent=nullptr)
Definition QXmppLogger.cpp:57
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition QXmppLogger.h:29
QXmppMessage
The QXmppMessage class represents an XMPP message.
Definition QXmppMessage.h:64
QXmppNonza
Definition QXmppNonza.h:14
QXmppPresence
The QXmppPresence class represents an XMPP presence stanza.
Definition QXmppPresence.h:22
QXmppRosterManager
The QXmppRosterManager class provides access to a connected client's roster.
Definition QXmppRosterManager.h:84
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition QXmppStanza.h:128
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition QXmppStanza.h:106
QXmppStanza::id
QString id() const
Definition QXmppStanza.cpp:750
QXmppTask
Definition QXmppTask.h:46
QXmppVCardManager
The QXmppVCardManager class gets/sets XMPP vCards. It is an implementation of XEP-0054: vcard-temp.
Definition QXmppVCardManager.h:43
QXmppVersionManager
The QXmppVersionManager class makes it possible to request for the software version of an entity as d...
Definition QXmppVersionManager.h:24
QXmpp
Definition Algorithms.h:14
QXmppError
Definition QXmppError.h:17