QXmppEntityCapsStorage Class

Storage backend used by QXmppDiscoveryManager to keep verified service discovery information of entity capabilities between sessions. More...

Header: #include <QXmppEntityCapsStorage.h>
Since: QXmpp 1.17

Public Types

struct Key
enum class Method { EntityCapabilities }

Public Functions

virtual QXmppTask<std::optional<QString>> load(const QXmppEntityCapsStorage::Key &key) = 0
virtual QXmppTask<void> store(const QList<QXmppEntityCapsStorage::Key> &keys, const QString &xml) = 0

Detailed Description

Entities announce a hash of their service discovery information in their presence (XEP-0115: Entity Capabilities). Once the information of a hash has been received and verified, it is the same for all entities and accounts, so it can be stored permanently and shared between multiple clients. With a storage, the information of most contacts is known without any request after the start of the application.

The information is stored as the XML of the received disco#info <query/> element. QXmppDiscoveryManager verifies it again after loading it, so information that does not match its key is requested from the entity instead.

QXmppDiscoveryManager has no storage by default. Implement this interface and pass an instance via QXmppDiscoveryManager::setEntityCapsStorage(). The returned tasks must always finish, also on errors: entities with the same capabilities wait for load() to finish.

Removing unused entries

QXmppDiscoveryManager never removes entries from the storage. The implementation is responsible for deleting old and unused entries, otherwise the storage grows without limit: entities announce new capabilities whenever their features change, e.g. after a software update, so entries that are no longer used accumulate over time.

The best indicator for that is the time of the last use of an entry. QXmppDiscoveryManager keeps recently used information in memory and only calls load() when it needs the information of a key that is not in memory, and store() after it has requested and verified new information. Implementations should record the time of the last load() or store() of each key and regularly remove entries that have not been used for a while, e.g. for 90 days. Information that has been removed although it is still in use is requested from the entities again and stored anew, so removing too much only causes additional requests.

Member Type Documentation

enum class QXmppEntityCapsStorage::Method

The specification the hash of stored information has been generated with.

Other methods may be added in the future. The values are stable, so they can be stored as integers.

ConstantValueDescription
QXmppEntityCapsStorage::Method::EntityCapabilities0XEP-0115: Entity Capabilities

Member Function Documentation

[pure virtual] QXmppTask<std::optional<QString>> QXmppEntityCapsStorage::load(const QXmppEntityCapsStorage::Key &key)

Loads the information stored under key, i.e. the XML of the disco#info <query/> element, or nothing if there is none.

Implementations should update the time of the last use of the entry, see Removing unused entries.

[pure virtual] QXmppTask<void> QXmppEntityCapsStorage::store(const QList<QXmppEntityCapsStorage::Key> &keys, const QString &xml)

Stores the information xml, i.e. the XML of the disco#info <query/> element, under all keys, the hashes of the information using different methods or hash algorithms.

Implementations should record the time of the last use of the entry, see Removing unused entries.