QXmpp Version: 1.5.6
|
The QXmppClient class is the main class for using QXmpp. More...
#include <QXmppClient.h>
Public Types | |
enum | Error { NoError , SocketError , KeepAliveError , XmppStreamError } |
enum | State { DisconnectedState , ConnectingState , ConnectedState } |
This enumeration describes a client state. More... | |
enum | StreamManagementState { NoStreamManagement , NewStream , ResumedStream } |
Describes the use of XEP-0198: Stream Management. More... | |
using | IqResult = std::variant< QDomElement, QXmppError > |
using | EmptyResult = std::variant< QXmpp::Success, QXmppError > |
Public 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) |
Signals | |
void | connected () |
void | disconnected () |
This signal is emitted when the XMPP connection disconnects. | |
void | error (QXmppClient::Error) |
void | loggerChanged (QXmppLogger *logger) |
This signal is emitted when the logger changes. | |
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) |
This signal is emitted when the client state changes. | |
Signals inherited from QXmppLoggable | |
void | setGauge (const QString &gauge, double value) |
Sets the given gauge to value. | |
void | logMessage (QXmppLogger::MessageType type, const QString &msg) |
This signal is emitted to send logging messages. | |
void | updateCounter (const QString &counter, qint64 amount=1) |
Updates the given counter by amount. | |
Public Member Functions | |
QXmppClient (QObject *parent=nullptr) | |
bool | addExtension (QXmppClientExtension *extension) |
template<typename T , typename... Args> | |
T * | addNewExtension (Args... args) |
bool | insertExtension (int index, QXmppClientExtension *extension) |
bool | removeExtension (QXmppClientExtension *extension) |
QXmppE2eeExtension * | encryptionExtension () const |
void | setEncryptionExtension (QXmppE2eeExtension *) |
QList< QXmppClientExtension * > | extensions () |
template<typename T > | |
T * | findExtension () |
Returns the extension which can be cast into type T*, or 0 if there is no such extension. | |
template<typename T > | |
int | indexOfExtension () |
Returns the index of an extension. | |
bool | isAuthenticated () const |
Returns true if the client has authenticated with the XMPP server. | |
bool | isConnected () const |
bool | isActive () const |
void | setActive (bool active) |
StreamManagementState | streamManagementState () const |
QXmppPresence | clientPresence () const |
void | setClientPresence (const QXmppPresence &presence) |
QXmppConfiguration & | configuration () |
QXmppLogger * | logger () const |
Returns the QXmppLogger associated with the current QXmppClient. | |
void | setLogger (QXmppLogger *logger) |
Sets the QXmppLogger associated with the current QXmppClient. | |
QAbstractSocket::SocketError | socketError () |
QString | socketErrorString () const |
Returns the human-readable description of the last socket error if error() is QXmppClient::SocketError. | |
State | state () const |
Returns the client's current state. | |
QXmppStanza::Error::Condition | xmppStreamError () |
Returns the XMPP stream error if QXmppClient::Error is QXmppClient::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 > &={}) |
QXmppRosterManager & | rosterManager () |
QXmppVCardManager & | vCardManager () |
QXmppVersionManager & | versionManager () |
Public Member Functions inherited from QXmppLoggable | |
QXmppLoggable (QObject *parent=nullptr) | |
Properties | |
QXmppLogger * | logger |
The QXmppLogger associated with the current QXmppClient. | |
State | state |
The client's current state. | |
Friends | |
class | QXmppClientExtension |
class | QXmppInternalClientExtension |
class | TestClient |
Additional Inherited Members | |
Protected Member Functions inherited from QXmppLoggable | |
void | debug (const QString &message) |
void | info (const QString &message) |
void | warning (const QString &message) |
void | logReceived (const QString &message) |
void | logSent (const QString &message) |
The QXmppClient class is the main class for using QXmpp.
It provides the user all the required functionality to connect to the server and perform operations afterwards.
This class will provide the handle/reference to QXmppRosterManager (roster management), QXmppVCardManager (vCard manager), and QXmppVersionManager (software version information).
By default, the client will automatically try reconnecting to the server. You can change that behaviour using QXmppConfiguration::setAutoReconnectionEnabled().
Not all the managers or extensions have been enabled by default. One can enable/disable the managers using the functions addExtension()
and removeExtension()
. findExtension()
can be used to find a reference/pointer to a particular instantiated and enabled manager.
List of managers enabled by default:
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.
Result of an IQ request, either contains the QDomElement of the IQ reponse (in case of an 'result' IQ type) or it contains an QXmppError with a QXmppStanza::Error (on type 'error') or a QXmpp::SendError.
enum QXmppClient::Error |
enum QXmppClient::State |
Describes the use of XEP-0198: Stream Management.
QXmppClient::QXmppClient | ( | QObject * | parent = nullptr | ) |
Creates a QXmppClient object.
parent | is passed to the QObject's constructor. The default value is 0. |
bool QXmppClient::addExtension | ( | QXmppClientExtension * | extension | ) |
Registers a new extension with the client.
extension |
|
inline |
Creates a new extension and adds it to the client.
QXmppPresence QXmppClient::clientPresence | ( | ) | const |
Returns the client's current presence.
QXmppConfiguration & QXmppClient::configuration | ( | ) |
Returns a modifiable reference to the current configuration of QXmppClient.
|
signal |
This signal is emitted when the client connects successfully to the XMPP server i.e. when a successful XMPP connection is established. XMPP Connection involves following sequential steps:
After all these steps a successful XMPP connection is established and connected() signal is emitted.
After the connected() signal is emitted QXmpp will send the roster request to the server. On receiving the roster, QXmpp will emit QXmppRosterManager::rosterReceived(). After this signal, QXmppRosterManager object gets populated and you can use findExtension<QXmppRosterManager>()
to get the handle of QXmppRosterManager object.
|
slot |
Overloaded function to simply connect to an XMPP server with a JID and password.
jid | JID for the account. |
password | Password for the account. |
|
slot |
Attempts to connect to the XMPP server. Server details and other configurations are specified using the config parameter. Use signals connected(), error(QXmppClient::Error) and disconnected() to know the status of the connection.
config | Specifies the configuration object for connecting the XMPP server. This contains the host name, user, password etc. See QXmppConfiguration for details. |
initialPresence | The initial presence which will be set for this user after establishing the session. The default value is QXmppPresence::Available |
|
slot |
Disconnects the client and the current presence of client changes to QXmppPresence::Unavailable and status text changes to "Logged out".
QXmppE2eeExtension * QXmppClient::encryptionExtension | ( | ) | const |
Returns the currently used encryption extension.
|
signal |
This signal is emitted when the XMPP connection encounters any error. The QXmppClient::Error parameter specifies the type of error occurred. It could be due to TCP socket or the xml stream or the stanza. Depending upon the type of error occurred use the respective get function to know the error.
QList< QXmppClientExtension * > QXmppClient::extensions | ( | ) |
Returns a list containing all the client's extensions.
|
inline |
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Usage example:
|
inline |
Returns the index of an extension.
Usage example:
bool QXmppClient::insertExtension | ( | int | index, |
QXmppClientExtension * | extension | ||
) |
Registers a new extension with the client at the given index.
index | |
extension |
|
signal |
This signal is emitted when IQs of type result or error are received by the client and no registered QXmppClientExtension could handle it.
This is useful when it is only important to check whether the response of an IQ was successful. However, the recommended way is still to use an additional QXmppClientExtension for this kind of tasks.
bool QXmppClient::isActive | ( | ) | const |
bool QXmppClient::isConnected | ( | ) | const |
Returns true if the client is connected to the XMPP server.
|
signal |
Notifies that an XMPP message stanza is received. The QXmppMessage parameter contains the details of the message sent to this client. In other words whenever someone sends you a message this signal is emitted.
|
signal |
Notifies that an XMPP presence stanza is received. The QXmppPresence parameter contains the details of the presence sent to this client. This signal is emitted when someone login/logout or when someone's status changes Busy, Idle, Invisible etc.
bool QXmppClient::removeExtension | ( | QXmppClientExtension * | extension | ) |
Unregisters the given extension from the client. If the extension is found, it will be destroyed.
extension |
QXmppTask< QXmpp::SendResult > QXmppClient::reply | ( | QXmppStanza && | stanza, |
const std::optional< QXmppE2eeMetadata > & | e2eeMetadata, | ||
const std::optional< QXmppSendStanzaParams > & | params = {} |
||
) |
Sends the stanza with the same encryption as e2eeMetadata
.
When there is no e2eeMetadata given this always sends the stanza without end-to-end encryption. Intended to be used for replies to IQs and messages.
QXmppRosterManager & QXmppClient::rosterManager | ( | ) |
Returns the reference to QXmppRosterManager object of the client.
QXmppClient::findExtension<QXmppRosterManager>()
instead. QXmppTask< QXmpp::SendResult > QXmppClient::send | ( | QXmppStanza && | stanza, |
const std::optional< QXmppSendStanzaParams > & | = {} |
||
) |
QXmppTask< QXmppClient::EmptyResult > QXmppClient::sendGenericIq | ( | QXmppIq && | iq, |
const std::optional< QXmppSendStanzaParams > & | = {} |
||
) |
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.
QXmppTask< QXmppClient::IqResult > QXmppClient::sendIq | ( | QXmppIq && | iq, |
const std::optional< QXmppSendStanzaParams > & | = {} |
||
) |
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().
IQs of type 'error' are parsed automatically and returned as QXmppError with a contained QXmppStanza::Error.
This does not do any end-to-encryption on the IQ.
|
slot |
Utility function to send message to all the resources associated with the specified bareJid. If there are no resources available, that is the contact is offline or not present in the roster, it will still send a message to the bareJid.
QXmppClient::sendPacket()
should be used instead with a QXmppMessage
.bareJid | bareJid of the receiving entity |
message | Message string to be sent. |
|
slot |
After successfully connecting to the server use this function to send stanzas to the server. This function can solely be used to send various kind of stanzas to the server. QXmppStanza is a parent class of all the stanzas QXmppMessage, QXmppPresence, QXmppIq, QXmppBind, QXmppRosterIq, QXmppSession and QXmppVCard.
This function does not end-to-end encrypt the packets.
Following code snippet illustrates how to send a message using this function:
packet | A valid XMPP stanza. It can be an iq, a message or a presence stanza. |
QXmppTask< QXmpp::SendResult > QXmppClient::sendSensitive | ( | QXmppStanza && | stanza, |
const std::optional< QXmppSendStanzaParams > & | params = {} |
||
) |
Sends a packet and reports the result via QXmppTask.
If stream management is enabled, the task continues to be active until the server acknowledges the packet. On success, QXmpp::SendSuccess with acknowledged == true is reported and the task finishes.
If connection errors occur, the packet is resent if possible. If reconnecting is not possible, an error is reported.
QXmppTask< QXmppClient::IqResult > QXmppClient::sendSensitiveIq | ( | QXmppIq && | iq, |
const std::optional< QXmppSendStanzaParams > & | params = {} |
||
) |
Tries to encrypt and send an IQ packet and returns the response asynchronously.
This can be used for sensitive IQ requests performed from client to client. Most IQ requests like service discovery requests cannot be end-to-end encrypted or it only makes little sense to do so. This is why the default sendIq() does not do any additional end-to-end encryption.
IQs of type 'error' are parsed automatically and returned as QXmppError with a contained QXmppStanza::Error.
void QXmppClient::setActive | ( | bool | active | ) |
void QXmppClient::setClientPresence | ( | const QXmppPresence & | presence | ) |
Changes the presence of the connected client.
The connection to the server will be updated accordingly:
presence | QXmppPresence object |
void QXmppClient::setEncryptionExtension | ( | QXmppE2eeExtension * | extension | ) |
Sets the extension to be used for end-to-end-encryption.
QAbstractSocket::SocketError QXmppClient::socketError | ( | ) |
Returns the socket error if error() is QXmppClient::SocketError.
|
signal |
This signal is emitted to indicate that one or more SSL errors were encountered while establishing the identity of the server.
QXmppClient::StreamManagementState QXmppClient::streamManagementState | ( | ) | const |
QXmppVCardManager & QXmppClient::vCardManager | ( | ) |
Returns the reference to QXmppVCardManager, implementation of XEP-0054. http://xmpp.org/extensions/xep-0054.html
QXmppClient::findExtension<QXmppVCardManager>()
instead. QXmppVersionManager & QXmppClient::versionManager | ( | ) |
Returns the reference to QXmppVersionManager, implementation of XEP-0092. http://xmpp.org/extensions/xep-0092.html
QXmppClient::findExtension<QXmppVersionManager>()
instead.