QXmpp Version: 1.10.0
|
Main class for starting and managing connections to XMPP servers. More...
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... | |
enum | InitialExtensions { NoExtensions , BasicExtensions } |
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) |
Q_SIGNAL void | errorOccurred (const QXmppError &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. | |
Q_SIGNAL void | credentialsChanged () |
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 (InitialExtensions, QObject *parent=nullptr) | |
QXmppClient (QObject *parent=nullptr) | |
bool | addExtension (QXmppClientExtension *extension) |
Registers a new extension with the client. | |
template<typename T , typename... Args> | |
T * | addNewExtension (Args... args) |
bool | insertExtension (int index, QXmppClientExtension *extension) |
Registers a new extension with the client at the given index. | |
bool | removeExtension (QXmppClientExtension *extension) |
QXmppE2eeExtension * | encryptionExtension () const |
void | setEncryptionExtension (QXmppE2eeExtension *) |
QList< QXmppClientExtension * > | extensions () const |
Returns a list containing all the client's extensions. | |
template<typename T > | |
T * | findExtension () const |
Returns the extension which can be cast into type T*, or 0 if there is no such extension. More... | |
template<typename T > | |
int | indexOfExtension () const |
Returns the index of an extension. More... | |
bool | isAuthenticated () const |
Returns true if the client has authenticated with the XMPP server. | |
bool | isConnected () const |
Returns true if the client is connected to the XMPP server. | |
bool | isActive () const |
void | setActive (bool active) |
StreamManagementState | streamManagementState () const |
QXmppPresence | clientPresence () const |
Returns the client's current presence. | |
void | setClientPresence (const QXmppPresence &presence) |
QXmppConfiguration & | configuration () |
Returns a modifiable reference to the current configuration of QXmppClient. | |
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 () |
Returns the socket error if error() is QXmppClient::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 | QXmppCarbonManagerV2 |
class | QXmppRegistrationManager |
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) |
Main class for starting and managing connections to XMPP servers.
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:
If no explicit host and port are configured, the client will look up the SRV records of the domain of the configured JID. Since QXmpp 1.8 both TCP and direct TLS records are looked up and connection via direct TLS is preferred as it saves the extra round trip from STARTTLS. See also XEP-0368: SRV records for XMPP over TLS.
On connection errors the other SRV records are tested too (if multiple are available).
For servers without SRV records or if looking up the records did not succeed, domain and the default port of 5223 (TLS) and 5222 (TCP/STARTTLS) are tried.
QXmpp uses XEP-0484: Fast Authentication Streamlining Tokens if enabled and supported by the server. FAST tokens can be requested after a first time authentication using a password or another strong authentication mechanism. The tokens can then be used to log in, without a password. The tokens are linked to a specific device ID (set via the SASL 2 user agent) and only this device can use the token. Tokens also expire and are rotated by the server.
The advantage of this mechanism is that a client does not necessarily need to store the password of an account and in the future clients that are logged in could be listed and logged out manually. FAST also allows for performance improvements as it only requires one round trip for authentication (and may be included in TLS 0-RTT data although that is not implemented in QXmpp) while other mechanisms like SCRAM need multiple round trips.
FAST itself is enabled by default (see QXmppConfiguration::useFastTokenAuthentication()), but you also need to set a SASL user agent with a stable device ID, so FAST can be used. After that you can login and use QXmppCredentials to serialize the token data and store it permanently. Note that the token may change over time, though.
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 |
Used to decide which extensions should be added by default.
Enumerator | |
---|---|
NoExtensions | Creates a client without any extensions. |
BasicExtensions | Creates a client with the default set of extensions. |
enum QXmppClient::State |
Describes the use of XEP-0198: Stream Management.
QXmppClient::QXmppClient | ( | InitialExtensions | initialExtensions, |
QObject * | parent = nullptr |
||
) |
Creates a QXmppClient object.
initialExtensions | can be used to set the initial set of extensions. |
parent | is passed to the QObject's constructor. The default value is 0. |
QXmppClient::QXmppClient | ( | QObject * | parent = nullptr | ) |
Creates a QXmppClient object.
parent | is passed to the QObject's constructor. |
|
inline |
Creates a new extension and adds it to the client.
|
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 |
|
signal |
Emitted when the credentials, e.g. tokens have changed.
This means that the QXmppCredentials in the QXmppConfiguration of this client has changed.
|
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.
|
signal |
This signal is emitted when the XMPP connection encounters any fatal error.
error | Detailed error object with a description. It may contain
|
|
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:
|
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 |
Returns true if the current client state is "active", false if it is "inactive". See XEP-0352: Client State Indication for details.
|
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.
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 | ) |
Sets the client state as described in XEP-0352: Client State Indication.
Since QXmpp 1.8, the state is restored across reconnects. QXmpp will re-send the state of 'inactive' on connection if that was set before. Stream resumptions are also handled.
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.
|
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.
QXmppClient::findExtension<QXmppVCardManager>()
instead. QXmppVersionManager & QXmppClient::versionManager | ( | ) |
Returns the reference to QXmppVersionManager, implementation of XEP-0092.
QXmppClient::findExtension<QXmppVersionManager>()
instead.