Loading...
Searching...
No Matches
QXmppClient.h
// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
//
// 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 <memory>
#include <variant>
#include <QAbstractSocket>
#include <QObject>
#include <QSslError>
template<typename T>
class QXmppTask;
class QXmppE2eeExtension;
class QXmppClientExtension;
class QXmppClientPrivate;
class QXmppPresence;
class QXmppMessage;
class QXmppIq;
class QXmppStream;
class QXmppInternalClientExtension;
// managers
class QXmppDiscoveryIq;
class QXmppRosterManager;
class QXmppVCardManager;
class QXmppVersionManager;
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
};
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();
template<typename T>
T *findExtension()
{
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()
{
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> & = {});
#if QXMPP_DEPRECATED_SINCE(1, 1)
QT_DEPRECATED_X("Use QXmppClient::findExtension<QXmppRosterManager>() instead")
QXmppRosterManager &rosterManager();
QT_DEPRECATED_X("Use QXmppClient::findExtension<QXmppVCardManager>() instead")
QXmppVCardManager &vCardManager();
QT_DEPRECATED_X("Use QXmppClient::findExtension<QXmppVersionManager>() instead")
QXmppVersionManager &versionManager();
#endif
Q_SIGNALS:
void connected();
void disconnected();
void error(QXmppClient::Error);
void loggerChanged(QXmppLogger *logger);
void messageReceived(const QXmppMessage &message);
void presenceReceived(const QXmppPresence &presence);
void iqReceived(const QXmppIq &iq);
void sslErrors(const QList<QSslError> &errors);
void stateChanged(QXmppClient::State state);
public Q_SLOTS:
void connectToServer(const QXmppConfiguration &,
const QXmppPresence &initialPresence =
QXmppPresence());
void connectToServer(const QString &jid,
const QString &password);
void disconnectFromServer();
bool sendPacket(const QXmppNonza &);
void sendMessage(const QString &bareJid, const QString &message);
private:
void injectIq(const QDomElement &element, const std::optional<QXmppE2eeMetadata> &e2eeMetadata);
bool injectMessage(QXmppMessage &&message);
private Q_SLOTS:
void _q_elementReceived(const QDomElement &element, bool &handled);
void _q_reconnect();
void _q_socketStateChanged(QAbstractSocket::SocketState state);
void _q_streamConnected();
void _q_streamDisconnected();
void _q_streamError(QXmppClient::Error error);
private:
const std::unique_ptr<QXmppClientPrivate> d;
friend class QXmppClientExtension;
friend class QXmppInternalClientExtension;
friend class TestClient;
};
#endif // QXMPPCLIENT_H
QXmppClientExtension
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:33
QXmppClient
The QXmppClient class is the main class for using QXmpp.
Definition QXmppClient.h:84
QXmppClient::presenceReceived
void presenceReceived(const QXmppPresence &presence)
QXmppClient::error
void error(QXmppClient::Error)
QXmppClient::connected
void connected()
QXmppClient::IqResult
std::variant< QDomElement, QXmppError > IqResult
Definition QXmppClient.h:93
QXmppClient::State
State
This enumeration describes a client state.
Definition QXmppClient.h:107
QXmppClient::DisconnectedState
@ DisconnectedState
Disconnected from the server.
Definition QXmppClient.h:108
QXmppClient::ConnectingState
@ ConnectingState
Trying to connect to the server.
Definition QXmppClient.h:109
QXmppClient::loggerChanged
void loggerChanged(QXmppLogger *logger)
This signal is emitted when the logger changes.
QXmppClient::Error
Error
Definition QXmppClient.h:98
QXmppClient::NoError
@ NoError
No error.
Definition QXmppClient.h:99
QXmppClient::XmppStreamError
@ XmppStreamError
Error due to XML stream.
Definition QXmppClient.h:102
QXmppClient::KeepAliveError
@ KeepAliveError
Error due to no response to a keep alive.
Definition QXmppClient.h:101
QXmppClient::SocketError
@ SocketError
Error due to TCP socket.
Definition QXmppClient.h:100
QXmppClient::sslErrors
void sslErrors(const QList< QSslError > &errors)
QXmppClient::stateChanged
void stateChanged(QXmppClient::State state)
This signal is emitted when the client state changes.
QXmppClient::messageReceived
void messageReceived(const QXmppMessage &message)
QXmppClient::StreamManagementState
StreamManagementState
Describes the use of XEP-0198: Stream Management.
Definition QXmppClient.h:115
QXmppClient::NoStreamManagement
@ NoStreamManagement
Stream Management is not used.
Definition QXmppClient.h:117
QXmppClient::NewStream
@ NewStream
Stream Management is used and the previous stream has not been resumed.
Definition QXmppClient.h:119
QXmppClient::iqReceived
void iqReceived(const QXmppIq &iq)
QXmppClient::addNewExtension
T * addNewExtension(Args... args)
Definition QXmppClient.h:129
QXmppClient::findExtension
T * findExtension()
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Definition QXmppClient.h:157
QXmppClient::disconnected
void disconnected()
This signal is emitted when the XMPP connection disconnects.
QXmppClient::EmptyResult
std::variant< QXmpp::Success, QXmppError > EmptyResult
Definition QXmppClient.h:94
QXmppClient::indexOfExtension
int indexOfExtension()
Returns the index of an extension.
Definition QXmppClient.h:185
QXmppConfiguration
The QXmppConfiguration class holds configuration options.
Definition QXmppConfiguration.h:29
QXmppDiscoveryIq
Definition QXmppDiscoveryIq.h:18
QXmppE2eeExtension
Definition QXmppE2eeExtension.h:23
QXmppIq
The QXmppIq class is the base class for all IQs.
Definition QXmppIq.h:23
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition QXmppLogger.h:105
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition QXmppLogger.h:27
QXmppMessage
The QXmppMessage class represents an XMPP message.
Definition QXmppMessage.h:35
QXmppNonza
Definition QXmppNonza.h:14
QXmppPresence
The QXmppPresence class represents an XMPP presence stanza.
Definition QXmppPresence.h:21
QXmppRosterManager
The QXmppRosterManager class provides access to a connected client's roster.
Definition QXmppRosterManager.h:56
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition QXmppStanza.h:110
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition QXmppStanza.h:88
QXmppStream
The QXmppStream class is the base class for all XMPP streams.
Definition QXmppStream.h:36
QXmppTask
Definition QXmppTask.h:62
QXmppVCardManager
The QXmppVCardManager class gets/sets XMPP vCards. It is an implementation of XEP-0054: vcard-temp.
Definition QXmppVCardManager.h:38
QXmppVersionManager
The QXmppVersionManager class makes it possible to request for the software version of an entity as d...
Definition QXmppVersionManager.h:24
QXmpp
QXmppError
Definition QXmppError.h:18