QXmpp Namespace

Header: #include <Algorithms.h>
Since: QXmpp 1.5

Namespaces

namespace Disco
(since QXmpp 1.16) namespace Muc
(since QXmpp 1.8) namespace Uri
(since QXmpp 1.16) namespace Xml

Classes

(since QXmpp 1.7) struct AuthenticationError
(since QXmpp 1.7) struct BindError
(since QXmpp 1.5) struct Cancelled
(since QXmpp 1.9) struct Reply
(since QXmpp 1.5) struct SendSuccess
(since QXmpp 1.14) struct StunServer
(since QXmpp 1.5) struct Success
(since QXmpp 1.7) struct TimeoutError
(since QXmpp 1.14) struct TurnServer

Types

(since QXmpp 1.5) enum Cipher { Aes128GcmNoPad, Aes256GcmNoPad, Aes256CbcPkcs7 }
(since QXmpp 1.5) enum class HashAlgorithm { Unknown, Md2, Md5, Shake128, Shake256, …, Blake2b_512 }
(since QXmpp 1.14) enum class JingleErrorCondition { OutOfOrder, TieBreak, UnknownSession, UnsupportedInfo }
(since QXmpp 1.12) Result
(since QXmpp 1.5) enum SceMode { SceAll, ScePublic, SceSensitive }
(since QXmpp 1.5) enum class SendError { SocketWriteError, Disconnected, EncryptionError }
SendResult
(since QXmpp 1.7) enum class StreamError { BadFormat, BadNamespacePrefix, Conflict, ConnectionTimeout, HostGone, …, UnsupportedVersion }
(since QXmpp 1.5) enum class TrustLevel { Undecided, AutomaticallyDistrusted, ManuallyDistrusted, AutomaticallyTrusted, ManuallyTrusted, Authenticated }
flags TrustLevels
(since QXmpp 1.5) enum TrustSecurityPolicy { NoSecurityPolicy, Toakafa }

Functions

(since QXmpp 1.16) QString formatXmlForDebug(QStringView raw, bool indent = true, int indentWidth = 2, bool colorize = false)
(since QXmpp 1.11) QString generateSequentialStanzaId()
(since QXmpp 1.13) const QXmppError &getError(const QXmpp::Result<T> &r)
(since QXmpp 1.13) QXmppError &getError(QXmpp::Result<T> &r)
(since QXmpp 1.13) QXmppError getError(QXmpp::Result<T> &&r)
(since QXmpp 1.13) T &getValue(QXmpp::Result<T> &r)
(since QXmpp 1.13) T getValue(QXmpp::Result<T> &&r)
(since QXmpp 1.13) const T &getValue(const QXmpp::Result<T> &r)
(since QXmpp 1.5) bool handleIqRequests(const QDomElement &element, QXmppClient *client, Handler handler)
(since QXmpp 1.5) bool handleIqRequests(const QDomElement &element, const std::optional<QXmppE2eeMetadata> &e2eeMetadata, QXmppClient *client, Handler handler)
(since QXmpp 1.13) bool hasError(const QXmpp::Result<T> &r)
(since QXmpp 1.13) bool hasValue(const QXmpp::Result<T> &r)
bool isElement(const QDomElement &el)
bool isIqElement(const QDomElement &el)
(since QXmpp 1.5) bool operator&(QXmpp::SceMode mode1, QXmpp::SceMode mode2)

Detailed Description

Contains global functions and enumerations.

Namespaces

namespace QXmpp::Disco

Contains types for XEP-0030: Service Discovery.

[since QXmpp 1.16] namespace QXmpp::Muc

This namespace was introduced in QXmpp 1.16.

[since QXmpp 1.8] namespace QXmpp::Uri

Contains URI classes that can be serialized to URI queries (see QXmppUri).

This namespace was introduced in QXmpp 1.8.

[since QXmpp 1.16] namespace QXmpp::Xml

Contains types for generic and dynamically-registered XML extensions.

This namespace was introduced in QXmpp 1.16.

Classes

class AuthenticationError

Indicates an authentication error. More...

class BindError

Indicates a resource binding error. More...

class Cancelled

Unit struct used to indicate that a process has been cancelled. More...

class Reply

Message reply as defined in XEP-0461: Message Replies. More...

class SendSuccess

A struct indicating success when sending packets. More...

class StunServer

STUN server address. More...

class Success

An empty struct indicating success in results. More...

class TimeoutError

Unit struct indicating a client-side timeout (or keep-alive) error. More...

class TurnServer

TURN server address. More...

Type Documentation

[since QXmpp 1.5] enum QXmpp::Cipher

Cipher for encrypting data streams and files.

ConstantValue
QXmpp::Aes128GcmNoPad0
QXmpp::Aes256GcmNoPad1
QXmpp::Aes256CbcPkcs72

This enum was introduced in QXmpp 1.5.

[since QXmpp 1.5] enum class QXmpp::HashAlgorithm

Cryptographic hash algorithm as specified in XEP-0300: Use of Cryptographic Hash Functions in XMPP.

ConstantValueDescription
QXmpp::HashAlgorithm::Unknown0The algorithm is unknown or not set.
QXmpp::HashAlgorithm::Md21MD2 hash algorithm.
QXmpp::HashAlgorithm::Md52MD5 hash algorithm.
QXmpp::HashAlgorithm::Shake1283SHAKE-128 hash algorithm.
QXmpp::HashAlgorithm::Shake2564SHAKE-256 hash algorithm.
QXmpp::HashAlgorithm::Sha15SHA-1 hash algorithm.
QXmpp::HashAlgorithm::Sha2246SHA-224 hash algorithm.
QXmpp::HashAlgorithm::Sha2567SHA-256 hash algorithm.
QXmpp::HashAlgorithm::Sha3848SHA-384 hash algorithm.
QXmpp::HashAlgorithm::Sha5129SHA-512 hash algorithm.
QXmpp::HashAlgorithm::Sha3_25610SHA3-256 hash algorithm.
QXmpp::HashAlgorithm::Sha3_51211SHA3-512 hash algorithm.
QXmpp::HashAlgorithm::Blake2b_25612BLAKE2b-256 hash algorithm.
QXmpp::HashAlgorithm::Blake2b_51213BLAKE2b-512 hash algorithm.

This enum was introduced in QXmpp 1.5.

[since QXmpp 1.14] enum class QXmpp::JingleErrorCondition

XEP-0166: Jingle-specific error condition, used in QXmppStanza::Error.

ConstantValue
QXmpp::JingleErrorCondition::OutOfOrder0
QXmpp::JingleErrorCondition::TieBreak1
QXmpp::JingleErrorCondition::UnknownSession2
QXmpp::JingleErrorCondition::UnsupportedInfo3

This enum was introduced in QXmpp 1.14.

[alias, since QXmpp 1.12] template <typename T = QXmpp::Success> QXmpp::Result

Generic result type offering value or QXmppError.

T defaults to QXmpp::Success since QXmpp 1.13.

This typedef was introduced in QXmpp 1.12.

[since QXmpp 1.5] enum QXmpp::SceMode

Parsing/serialization mode when using Stanza Content Encryption (XEP-0420: Stanza Content Encryption).

ConstantValueDescription
QXmpp::SceAll0Processes all known elements.
QXmpp::ScePublic1Only processes 'public' elements (e.g. needed for routing).
QXmpp::SceSensitive2Only processes sensitive elements that should be encrypted.

This enum was introduced in QXmpp 1.5.

[since QXmpp 1.5] enum class QXmpp::SendError

Describes the type of a packet sending error.

ConstantValueDescription
QXmpp::SendError::SocketWriteError0The packet was written to the socket with no success (only happens when Stream Management is disabled).
QXmpp::SendError::Disconnected1The packet couldn't be sent because the connection hasn't been (re)established.
QXmpp::SendError::EncryptionError2The packet couldn't be sent because prior encryption failed.

This enum was introduced in QXmpp 1.5.

[alias] QXmpp::SendResult

A variant containing either a SendSuccess object or a QXmppError.

The QXmppError will likely contain a SendError.

[since QXmpp 1.7] enum class QXmpp::StreamError

All XMPP top-level stream errors.

ConstantValue
QXmpp::StreamError::BadFormat0
QXmpp::StreamError::BadNamespacePrefix1
QXmpp::StreamError::Conflict2
QXmpp::StreamError::ConnectionTimeout3
QXmpp::StreamError::HostGone4
QXmpp::StreamError::HostUnknown5
QXmpp::StreamError::ImproperAddressing6
QXmpp::StreamError::InternalServerError7
QXmpp::StreamError::InvalidFrom8
QXmpp::StreamError::InvalidId9
QXmpp::StreamError::InvalidNamespace10
QXmpp::StreamError::InvalidXml11
QXmpp::StreamError::NotAuthorized12
QXmpp::StreamError::NotWellFormed13
QXmpp::StreamError::PolicyViolation14
QXmpp::StreamError::RemoteConnectionFailed15
QXmpp::StreamError::Reset16
QXmpp::StreamError::ResourceConstraint17
QXmpp::StreamError::RestrictedXml18
QXmpp::StreamError::SystemShutdown19
QXmpp::StreamError::UndefinedCondition20
QXmpp::StreamError::UnsupportedEncoding21
QXmpp::StreamError::UnsupportedFeature22
QXmpp::StreamError::UnsupportedStanzaType23
QXmpp::StreamError::UnsupportedVersion24

This enum was introduced in QXmpp 1.7.

[since QXmpp 1.5] enum class QXmpp::TrustLevel
flags QXmpp::TrustLevels

Trust level of public long-term keys used by end-to-end encryption protocols

ConstantValueDescription
QXmpp::TrustLevel::Undecided1The key's trust is not decided.
QXmpp::TrustLevel::AutomaticallyDistrusted2The key is automatically distrusted (e.g., by the security policy TOAKAFA).
QXmpp::TrustLevel::ManuallyDistrusted4The key is manually distrusted (e.g., by clicking a button or XEP-0450: Automatic Trust Management (ATM)).
QXmpp::TrustLevel::AutomaticallyTrusted8The key is automatically trusted (e.g., by the client for all keys of a bare JID until one of it is authenticated).
QXmpp::TrustLevel::ManuallyTrusted16The key is manually trusted (e.g., by clicking a button).
QXmpp::TrustLevel::Authenticated32The key is authenticated (e.g., by QR code scanning or XEP-0450: Automatic Trust Management (ATM)).

This enum was introduced in QXmpp 1.5.

The TrustLevels type is a typedef for QFlags<TrustLevel>. It stores an OR combination of TrustLevel values.

See also QXmpp::TrustSecurityPolicy.

[since QXmpp 1.5] enum QXmpp::TrustSecurityPolicy

Security policy to decide which public long-term keys are used for encryption because they are trusted

ConstantValueDescription
QXmpp::NoSecurityPolicy0New keys must be trusted manually.
QXmpp::Toakafa1New keys are trusted automatically until the first authentication but automatically distrusted afterwards (XEP-0450: Automatic Trust Management (ATM)).

This enum was introduced in QXmpp 1.5.

Function Documentation

[since QXmpp 1.16] QString QXmpp::formatXmlForDebug(QStringView raw, bool indent = true, int indentWidth = 2, bool colorize = false)

Pretty-prints an XML fragment for debug display.

Reparses raw with QXmlStreamReader and re-emits it with line breaks and indentation. If colorize is true, ANSI 16-color escape sequences are inserted for terminal syntax highlighting (tags, attributes, text).

Tolerates XMPP stream fragments that are not standalone documents (such as inner child stanzas without their enclosing <stream:stream>). If the input cannot be parsed as XML at all, the original string is returned unchanged, so non-XML payloads (e.g. STUN packet dumps) pass through.

raw is the raw XML string. indent controls whether line breaks and indentation are added, and indentWidth sets the number of spaces per indentation level.

This function was introduced in QXmpp 1.16.

[since QXmpp 1.11] QString QXmpp::generateSequentialStanzaId()

Generates a new sequential stanza id. The ID is locally unique, not globally unique (see QXmppUtils::generateStanzaUuid()).

This is used for all QXmppStanzas automatically.

This function was introduced in QXmpp 1.11.

[since QXmpp 1.13] template <typename T> const QXmppError &QXmpp::getError(const QXmpp::Result<T> &r)

Returns the error of a result r or throws.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> QXmppError &QXmpp::getError(QXmpp::Result<T> &r)

Returns the error of a result r or throws.

This is an overloaded function.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> QXmppError QXmpp::getError(QXmpp::Result<T> &&r)

Returns the error of a result r or throws.

This is an overloaded function.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> T &QXmpp::getValue(QXmpp::Result<T> &r)

Returns the value of a result or throws

r.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> T QXmpp::getValue(QXmpp::Result<T> &&r)

Returns the value of a result or throws

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> const T &QXmpp::getValue(const QXmpp::Result<T> &r)

Returns the value of a result or throws

r.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.5] template <typename... IqTypes, typename Handler> bool QXmpp::handleIqRequests(const QDomElement &element, QXmppClient *client, Handler handler)

Parses IQ requests, calls a handler and sends an IQ result or error.

It is the easiest to explain this function with a few examples.

auto handled = QXmpp::handleIqElements<QXmppVersionIq>(element, client, [](QXmppVersionIq iq) -> std::variant<QXmppVersionIq, QXmppStanza::Error> {
if (iq.type() == QXmppIq::Get) {
QXmppVersionIq response;
response.setName("MyApp");
response.setVersion("1.0");
// id, to and type of the IQ are set automatically.
return response;
} else if (iq.type() == QXmppIq::Set) {
return QXmppStanza::Error(QXmppStanza::Error::Cancel, QXmppStanza::Error::BadRequest, "IQ must be of type 'get'.");
}
});

It is also possible to handle multiple IQ types.

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(
element, client, [](std::variant<QXmppVersionIq, QXmppVCardIq> iqVariant) {
// ...
});

It doesn't need to be a std::variant, it's only important that the object is callable with all the IQ types. You can for example use different lambdas per type using this 'overloaded' helper.

template<class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
// explicit deduction guide (not needed as of C++20)
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(
element, client, overloaded {
[](QXmppVersionIq iq) {
// ...
},
[](QXmppVCardIq iq) {
// ...
}
});

And another option is to an object with handleIq() functions.

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(element, client, this);
// will call this->handleIq(QXmppVersionIq) or this->handleIq(QXmppVCardIq)

The return type of the handler function can be: 1. an QXmppIq based type 2. a std::variant of QXmppIq based types (multiple are possible) and optionally also QXmppStanza::Error 3. a QXmppTask of 1. or 2.

You don't need to set the values for id or the to address on the IQ result because that's done automatically. Unless you want to return an error IQ you also don't need to set the IQ type.

If you return an QXmppStanza::Error, a normal QXmppIq with the error will be sent.

element is the DOM element that might contain an IQ. client is the client that should be used to send the response. handler is a function that can handle the IQ types from the template parameter or an object that has handleIq() functions for each of the IQ types.

Returns whether the IQ could be parsed, handled and a response was or will be sent.

This function was introduced in QXmpp 1.5.

[since QXmpp 1.5] template <typename... IqTypes, typename Handler> bool QXmpp::handleIqRequests(const QDomElement &element, const std::optional<QXmppE2eeMetadata> &e2eeMetadata, QXmppClient *client, Handler handler)

Parses IQ requests, calls a handler and sends an IQ result or error.

It is the easiest to explain this function with a few examples.

auto handled = QXmpp::handleIqElements<QXmppVersionIq>(element, e2eeMetadata, client, [](QXmppVersionIq iq) -> std::variant<QXmppVersionIq, QXmppStanza::Error> {
if (iq.type() == QXmppIq::Get) {
QXmppVersionIq response;
response.setName("MyApp");
response.setVersion("1.0");
// id, to and type of the IQ are set automatically.
return response;
} else if (iq.type() == QXmppIq::Set) {
return QXmppStanza::Error(QXmppStanza::Error::Cancel, QXmppStanza::Error::BadRequest, "IQ must be of type 'get'.");
}
});

It is also possible to handle multiple IQ types.

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(
element, e2eeMetadata, client, [](std::variant<QXmppVersionIq, QXmppVCardIq> iqVariant) {
// ...
});

It doesn't need to be a std::variant, it's only important that the object is callable with all the IQ types. You can for example use different lambdas per type using this 'overloaded' helper.

template<class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
// explicit deduction guide (not needed as of C++20)
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(
element, e2eeMetadata, client, overloaded {
[](QXmppVersionIq iq) {
// ...
},
[](QXmppVCardIq iq) {
// ...
}
});

And another option is to an object with handleIq() functions.

auto handled = QXmpp::handleIqElements<QXmppVersionIq, QXmppVCardIq>(element, e2eeMetadata, client, this);
// will call this->handleIq(QXmppVersionIq) or this->handleIq(QXmppVCardIq)

The return type of the handler function can be: 1. an QXmppIq based type 2. a std::variant of QXmppIq based types (multiple are possible) and optionally also QXmppStanza::Error 3. a QXmppTask of 1. or 2.

You don't need to set the values for id or the to address on the IQ result because that's done automatically. Unless you want to return an error IQ you also don't need to set the IQ type.

If you return an QXmppStanza::Error, a normal QXmppIq with the error will be sent.

The provided optional QXmppE2eeMetadata is set on the parsed IQ and used to correctly encrypt the IQ response using QXmppClient::reply().

element is the DOM element that might contain an IQ. e2eeMetadata is the end-to-end encryption metadata that is used to encrypt the response correctly and to be set on the parsed IQ. client is the client that should be used to send the response. handler is a function that can handle the IQ types from the template parameter or an object that has handleIq() functions for each of the IQ types.

Returns whether the IQ could be parsed, handled and a response was or will be sent.

This function was introduced in QXmpp 1.5.

[since QXmpp 1.13] template <typename T> bool QXmpp::hasError(const QXmpp::Result<T> &r)

Returns whether a result contains an error

r.

This function was introduced in QXmpp 1.13.

[since QXmpp 1.13] template <typename T> bool QXmpp::hasValue(const QXmpp::Result<T> &r)

Returns whether a result contains the expected value

r.

This function was introduced in QXmpp 1.13.

template <HasXmlTag T> bool QXmpp::isElement(const QDomElement &el)

Returns true if an XML element has the correct tag name and namespace URI for type T.

el.

template <typename T> bool QXmpp::isIqElement(const QDomElement &el)

Returns true if a QDomElement is an IQ stanza of a specific type T.

el.

[constexpr, since QXmpp 1.5] bool QXmpp::operator&(QXmpp::SceMode mode1, QXmpp::SceMode mode2)

Returns true if a mode is enabled in both mode1 and mode2.

When an SceMode is given you can use this to check whether Public or Private elements are enabled.

This function was introduced in QXmpp 1.5.