Loading...
Searching...
No Matches
QXmppDiscoveryIq.h
// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
// SPDX-FileCopyrightText: 2025 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPDISCOVERY_H
#define QXMPPDISCOVERY_H
#include "QXmppDataFormBase.h"
#include "QXmppIq.h"
#include <QSharedDataPointer>
class QXmppDiscoveryIdentityPrivate;
class QXmppDiscoveryItemPrivate;
class QXmppDiscoveryIqPrivate;
class QXMPP_EXPORT QXmppDiscoItem
{
public:
QXmppDiscoItem() { }
explicit QXmppDiscoItem(const QString &jid, const QString &name = {}, const QString &node = {})
: m_jid(jid), m_name(name), m_node(node) { }
const QString &jid() const { return m_jid; }
void setJid(const QString &newJid) { m_jid = newJid; }
const QString &name() const { return m_name; }
void setName(const QString &newName) { m_name = newName; }
const QString &node() const { return m_node; }
void setNode(const QString &newNode) { m_node = newNode; }
static constexpr std::tuple XmlTag = { u"item", QXmpp::Private::ns_disco_items };
static std::optional<QXmppDiscoItem> fromDom(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
private:
QString m_jid;
QString m_name;
QString m_node;
};
class QXMPP_EXPORT QXmppDiscoItems
{
public:
QXmppDiscoItems() { }
explicit QXmppDiscoItems(const QString &node, const QList<QXmppDiscoItem> &items = {})
: m_node(node), m_items(items) { }
const QList<QXmppDiscoItem> &items() const { return m_items; }
void setItems(const QList<QXmppDiscoItem> &newItems) { m_items = newItems; }
const QString &node() const { return m_node; }
void setNode(const QString &newNode) { m_node = newNode; }
static constexpr std::tuple XmlTag = { u"query", QXmpp::Private::ns_disco_items };
static std::optional<QXmppDiscoItems> fromDom(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
private:
QList<QXmppDiscoItem> m_items;
QString m_node;
};
class QXMPP_EXPORT QXmppDiscoIdentity
{
public:
QXmppDiscoIdentity() { }
explicit QXmppDiscoIdentity(const QString &category, const QString &type = {}, const QString &name = {}, const QString &lang = {})
: m_category(category), m_type(type), m_name(name), m_language(lang) { }
const QString &category() const { return m_category; }
void setCategory(const QString &newCategory) { m_category = newCategory; }
const QString &type() const { return m_type; }
void setType(const QString &newType) { m_type = newType; }
const QString &name() const { return m_name; }
void setName(const QString &newName) { m_name = newName; }
const QString &language() const { return m_language; }
void setLanguage(const QString &newLanguage) { m_language = newLanguage; }
static constexpr std::tuple XmlTag = { u"identity", QXmpp::Private::ns_disco_info };
static std::optional<QXmppDiscoIdentity> fromDom(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
private:
QString m_category;
QString m_type;
QString m_name;
QString m_language;
};
class QXMPP_EXPORT QXmppDiscoInfo
{
public:
QXmppDiscoInfo() { }
explicit QXmppDiscoInfo(const QString &node, const QList<QXmppDiscoIdentity> &identities = {}, const QList<QString> &features = {}, const QList<QXmppDataForm> &dataForms = {})
: m_node(node), m_identities(identities), m_features(features), m_dataForms(dataForms) { }
const QString &node() const { return m_node; }
void setNode(const QString &newNode) { m_node = newNode; }
const QList<QXmppDiscoIdentity> &identities() const { return m_identities; }
void setIdentities(const QList<QXmppDiscoIdentity> &newIdentities) { m_identities = newIdentities; }
const QList<QString> &features() const { return m_features; }
void setFeatures(const QList<QString> &newFeatures) { m_features = newFeatures; }
const QList<QXmppDataForm> &dataForms() const { return m_dataForms; }
void setDataForms(const QList<QXmppDataForm> &newDataForms) { m_dataForms = newDataForms; }
std::optional<QXmppDataForm> dataForm(QStringView formType) const;
template<QXmpp::Private::DataFormConvertible FormType>
std::optional<FormType> dataForm() const
{
if (auto form = dataForm(QXmpp::Private::DataFormType<FormType>)) {
if (auto result = FormType::fromDataForm(*form)) {
return *result;
}
}
return {};
}
QByteArray calculateEntityCapabilitiesHash() const;
static constexpr std::tuple XmlTag = { u"query", QXmpp::Private::ns_disco_info };
static std::optional<QXmppDiscoInfo> fromDom(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
private:
QString m_node;
QList<QXmppDiscoIdentity> m_identities;
QList<QString> m_features;
QList<QXmppDataForm> m_dataForms;
};
#if QXMPP_DEPRECATED_SINCE(1, 12)
class QXMPP_EXPORT QXmppDiscoveryIq : public QXmppIq
{
public:
using Identity [[deprecated]] = QXmppDiscoIdentity;
using Item [[deprecated]] = QXmppDiscoItem;
[[deprecated("Use QXmppDiscoInfo/Items")]]
QXmppDiscoveryIq();
QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppDiscoveryIq)
enum QueryType {
InfoQuery,
ItemsQuery
};
QStringList features() const;
void setFeatures(const QStringList &features);
QList<QXmppDiscoIdentity> identities() const;
void setIdentities(const QList<QXmppDiscoIdentity> &identities);
QList<QXmppDiscoItem> items() const;
void setItems(const QList<QXmppDiscoItem> &items);
[[deprecated("Use dataForms() instead")]]
QXmppDataForm form() const;
[[deprecated("Use setDataForms() instead")]]
void setForm(const QXmppDataForm &form);
const QList<QXmppDataForm> &dataForms() const;
void setDataForms(const QList<QXmppDataForm> &dataForms);
std::optional<QXmppDataForm> dataForm(QStringView formType) const;
template<QXmpp::Private::DataFormConvertible FormT>
std::optional<FormT> dataForm() const
{
if (auto form = dataForm(QXmpp::Private::DataFormType<FormT>)) {
if (auto result = FormT::fromDataForm(*form)) {
return *result;
}
}
return {};
}
QString queryNode() const;
void setQueryNode(const QString &node);
enum QueryType queryType() const;
void setQueryType(enum QueryType type);
QByteArray verificationString() const;
[[deprecated("Use QXmpp::isIqElement()")]]
static bool isDiscoveryIq(const QDomElement &element);
static bool checkIqType(const QString &tagName, const QString &xmlNamespace);
protected:
void parseElementFromChild(const QDomElement &element) override;
void toXmlElementFromChild(QXmlStreamWriter *writer) const override;
private:
QSharedDataPointer<QXmppDiscoveryIqPrivate> d;
};
#endif
#endif
QXmppDataForm
Definition QXmppDataForm.h:28
QXmppDiscoIdentity
Definition QXmppDiscoveryIq.h:83
QXmppDiscoIdentity::setName
void setName(const QString &newName)
Sets the human-readable name of the service.
Definition QXmppDiscoveryIq.h:111
QXmppDiscoIdentity::setType
void setType(const QString &newType)
Definition QXmppDiscoveryIq.h:106
QXmppDiscoIdentity::QXmppDiscoIdentity
QXmppDiscoIdentity(const QString &category, const QString &type={}, const QString &name={}, const QString &lang={})
Default constructor.
Definition QXmppDiscoveryIq.h:87
QXmppDiscoIdentity::type
const QString & type() const
Definition QXmppDiscoveryIq.h:100
QXmppDiscoIdentity::setLanguage
void setLanguage(const QString &newLanguage)
Definition QXmppDiscoveryIq.h:126
QXmppDiscoIdentity::name
const QString & name() const
Returns the human-readable name of the service.
Definition QXmppDiscoveryIq.h:109
QXmppDiscoIdentity::language
const QString & language() const
Definition QXmppDiscoveryIq.h:119
QXmppDiscoIdentity::category
const QString & category() const
Returns the category of the identity.
Definition QXmppDiscoveryIq.h:91
QXmppDiscoIdentity::setCategory
void setCategory(const QString &newCategory)
Sets the category of the identity.
Definition QXmppDiscoveryIq.h:93
QXmppDiscoInfo::dataForm
std::optional< FormType > dataForm() const
Looks for a form with the form type of FormType and parses it if found.
Definition QXmppDiscoveryIq.h:173
QXmppDiscoInfo::setNode
void setNode(const QString &newNode)
Sets the node of the query.
Definition QXmppDiscoveryIq.h:152
QXmppDiscoInfo::setDataForms
void setDataForms(const QList< QXmppDataForm > &newDataForms)
Definition QXmppDiscoveryIq.h:168
QXmppDiscoInfo::dataForm
std::optional< QXmppDataForm > dataForm(QStringView formType) const
Definition QXmppDiscoveryIq.cpp:126
QXmppDiscoInfo::QXmppDiscoInfo
QXmppDiscoInfo(const QString &node, const QList< QXmppDiscoIdentity > &identities={}, const QList< QString > &features={}, const QList< QXmppDataForm > &dataForms={})
Default constructor.
Definition QXmppDiscoveryIq.h:146
QXmppDiscoInfo::node
const QString & node() const
Returns the node of the query.
Definition QXmppDiscoveryIq.h:150
QXmppDiscoInfo::dataForms
const QList< QXmppDataForm > & dataForms() const
Returns additional data forms as specified in XEP-0128: Service Discovery Extensions.
Definition QXmppDiscoveryIq.h:165
QXmppDiscoInfo::identities
const QList< QXmppDiscoIdentity > & identities() const
Returns the identities of the entity.
Definition QXmppDiscoveryIq.h:155
QXmppDiscoInfo::setFeatures
void setFeatures(const QList< QString > &newFeatures)
Sets the features supported by the entity.
Definition QXmppDiscoveryIq.h:162
QXmppDiscoInfo::features
const QList< QString > & features() const
Returns the features supported by the entity.
Definition QXmppDiscoveryIq.h:160
QXmppDiscoInfo::setIdentities
void setIdentities(const QList< QXmppDiscoIdentity > &newIdentities)
Sets the identities of the entity.
Definition QXmppDiscoveryIq.h:157
QXmppDiscoItem
Definition QXmppDiscoveryIq.h:19
QXmppDiscoItem::setNode
void setNode(const QString &newNode)
Sets the node for querying the information.
Definition QXmppDiscoveryIq.h:39
QXmppDiscoItem::setJid
void setJid(const QString &newJid)
Sets the JID of the item.
Definition QXmppDiscoveryIq.h:29
QXmppDiscoItem::jid
const QString & jid() const
Returns the JID of the item.
Definition QXmppDiscoveryIq.h:27
QXmppDiscoItem::setName
void setName(const QString &newName)
Sets the name of the item.
Definition QXmppDiscoveryIq.h:34
QXmppDiscoItem::node
const QString & node() const
Returns the node for querying the information.
Definition QXmppDiscoveryIq.h:37
QXmppDiscoItem::name
const QString & name() const
Returns the name of the item.
Definition QXmppDiscoveryIq.h:32
QXmppDiscoItem::QXmppDiscoItem
QXmppDiscoItem(const QString &jid, const QString &name={}, const QString &node={})
Default constructor.
Definition QXmppDiscoveryIq.h:23
QXmppDiscoItems::setNode
void setNode(const QString &newNode)
Sets the node of the query.
Definition QXmppDiscoveryIq.h:69
QXmppDiscoItems::setItems
void setItems(const QList< QXmppDiscoItem > &newItems)
Sets the items.
Definition QXmppDiscoveryIq.h:64
QXmppDiscoItems::node
const QString & node() const
Returns the node of the query.
Definition QXmppDiscoveryIq.h:67
QXmppDiscoItems::QXmppDiscoItems
QXmppDiscoItems(const QString &node, const QList< QXmppDiscoItem > &items={})
Default constructor.
Definition QXmppDiscoveryIq.h:58
QXmppDiscoItems::items
const QList< QXmppDiscoItem > & items() const
Returns the items.
Definition QXmppDiscoveryIq.h:62
QXmppDiscoveryIq::form
QXmppDataForm form() const
Definition base/compat/removed_api.cpp:265
QXmppDiscoveryIq::dataForm
std::optional< QXmppDataForm > dataForm(QStringView formType) const
Definition base/compat/removed_api.cpp:328
QXmppDiscoveryIq::dataForm
std::optional< FormT > dataForm() const
Definition QXmppDiscoveryIq.h:237
QXmppDiscoveryIq::QueryType
QueryType
Definition QXmppDiscoveryIq.h:211
QXmppIq::QXmppIq
QXmppIq(QXmppIq::Type type=QXmppIq::Get)
Definition QXmppIq.cpp:39