QXmppClient.h
/*
* Copyright (C) 2008-2021 The QXmpp developers
*
* Author:
* Manjeet Dahiya
*
* Source:
* https://github.com/qxmpp-project/qxmpp
*
* This file is a part of QXmpp library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
#ifndef QXMPPCLIENT_H
#define QXMPPCLIENT_H
#include "QXmppConfiguration.h"
#include "QXmppLogger.h"
#include "QXmppPresence.h"
#include <QAbstractSocket>
#include <QObject>
#include <QSslError>
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:
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);
bool insertExtension(int index, QXmppClientExtension *extension);
bool removeExtension(QXmppClientExtension *extension);
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();
#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 QXmppStanza &);
void sendMessage(const QString &bareJid, const QString &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:
QXmppClientPrivate *const d;
friend class QXmppInternalClientExtension;
};
#endif // QXMPPCLIENT_H
QXmppClientExtension
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:47
QXmppClient
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:94
QXmppClient::presenceReceived
void presenceReceived(const QXmppPresence &presence)
QXmppClient::error
void error(QXmppClient::Error)
QXmppClient::connected
void connected()
QXmppClient::State
State
This enumeration describes a client state.
Definition: QXmppClient.h:114
QXmppClient::DisconnectedState
@ DisconnectedState
Disconnected from the server.
Definition: QXmppClient.h:115
QXmppClient::ConnectingState
@ ConnectingState
Trying to connect to the server.
Definition: QXmppClient.h:116
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:154
QXmppClient::loggerChanged
void loggerChanged(QXmppLogger *logger)
This signal is emitted when the logger changes.
QXmppClient::Error
Error
Definition: QXmppClient.h:105
QXmppClient::NoError
@ NoError
No error.
Definition: QXmppClient.h:106
QXmppClient::XmppStreamError
@ XmppStreamError
Error due to XML stream.
Definition: QXmppClient.h:109
QXmppClient::KeepAliveError
@ KeepAliveError
Error due to no response to a keep alive.
Definition: QXmppClient.h:108
QXmppClient::SocketError
@ SocketError
Error due to TCP socket.
Definition: QXmppClient.h:107
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:122
QXmppClient::NoStreamManagement
@ NoStreamManagement
Stream Management is not used.
Definition: QXmppClient.h:124
QXmppClient::NewStream
@ NewStream
Stream Management is used and the previous stream has not been resumed.
Definition: QXmppClient.h:126
QXmppClient::iqReceived
void iqReceived(const QXmppIq &iq)
QXmppClient::disconnected
void disconnected()
This signal is emitted when the XMPP connection disconnects.
QXmppClient::indexOfExtension
int indexOfExtension()
Returns the index of an extension.
Definition: QXmppClient.h:181
QXmppConfiguration
The QXmppConfiguration class holds configuration options.
Definition: QXmppConfiguration.h:48
QXmppDiscoveryIq
QXmppDiscoveryIq represents a discovery IQ request or result containing a list of features and other ...
Definition: QXmppDiscoveryIq.h:44
QXmppIq
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:42
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:124
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:46
QXmppMessage
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:46
QXmppPresence
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:36
QXmppRosterManager
The QXmppRosterManager class provides access to a connected client's roster.
Definition: QXmppRosterManager.h:69
QXmppStanza::Error::Condition
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:121
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:100
QXmppStream
The QXmppStream class is the base class for all XMPP streams.
Definition: QXmppStream.h:42
QXmppVCardManager
The QXmppVCardManager class gets/sets XMPP vCards. It is an implementation of XEP-0054: vcard-temp.
Definition: QXmppVCardManager.h:57
QXmppVersionManager
The QXmppVersionManager class makes it possible to request for the software version of an entity as d...
Definition: QXmppVersionManager.h:43