QXmpp: QXmppDiscoveryIq.h Source File

QXmpp Version: 1.14.4

Loading...
Searching...
No Matches
QXmppDiscoveryIq.h
1// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
2// SPDX-FileCopyrightText: 2025 Linus Jahn <lnj@kaidan.im>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6#ifndef QXMPPDISCOVERY_H
7#define QXMPPDISCOVERY_H
8
9#include "QXmppDataFormBase.h"
10#include "QXmppIq.h"
11
12#include <QSharedDataPointer>
13
14class QXmppDiscoveryIdentityPrivate;
15class QXmppDiscoveryItemPrivate;
16class QXmppDiscoveryIqPrivate;
17
18 class QXMPP_EXPORT QXmppDiscoItem
19{
20public:
21 QXmppDiscoItem() { }
23 explicit QXmppDiscoItem(const QString &jid, const QString &name = {}, const QString &node = {})
24 : m_jid(jid), m_name(name), m_node(node) { }
25
27 const QString &jid() const { return m_jid; }
29 void setJid(const QString &newJid) { m_jid = newJid; }
30
32 const QString &name() const { return m_name; }
34 void setName(const QString &newName) { m_name = newName; }
35
37 const QString &node() const { return m_node; }
39 void setNode(const QString &newNode) { m_node = newNode; }
40
42 static constexpr std::tuple XmlTag = { u"item", QXmpp::Private::ns_disco_items };
43 static std::optional<QXmppDiscoItem> fromDom(const QDomElement &el);
44 void toXml(QXmlStreamWriter *writer) const;
46
47private:
48 QString m_jid;
49 QString m_name;
50 QString m_node;
51};
52
53 class QXMPP_EXPORT QXmppDiscoItems
54{
55public:
56 QXmppDiscoItems() { }
58 explicit QXmppDiscoItems(const QString &node, const QList<QXmppDiscoItem> &items = {})
59 : m_node(node), m_items(items) { }
60
62 const QList<QXmppDiscoItem> &items() const { return m_items; }
64 void setItems(const QList<QXmppDiscoItem> &newItems) { m_items = newItems; }
65
67 const QString &node() const { return m_node; }
69 void setNode(const QString &newNode) { m_node = newNode; }
70
72 static constexpr std::tuple XmlTag = { u"query", QXmpp::Private::ns_disco_items };
73 static std::optional<QXmppDiscoItems> fromDom(const QDomElement &el);
74 void toXml(QXmlStreamWriter *writer) const;
76
77private:
78 QList<QXmppDiscoItem> m_items;
79 QString m_node;
80};
81
82 class QXMPP_EXPORT QXmppDiscoIdentity
83{
84public:
85 QXmppDiscoIdentity() { }
87 explicit QXmppDiscoIdentity(const QString &category, const QString &type = {}, const QString &name = {}, const QString &lang = {})
88 : m_category(category), m_type(type), m_name(name), m_language(lang) { }
89
91 const QString &category() const { return m_category; }
93 void setCategory(const QString &newCategory) { m_category = newCategory; }
94
100 const QString &type() const { return m_type; }
106 void setType(const QString &newType) { m_type = newType; }
107
109 const QString &name() const { return m_name; }
111 void setName(const QString &newName) { m_name = newName; }
112
119 const QString &language() const { return m_language; }
126 void setLanguage(const QString &newLanguage) { m_language = newLanguage; }
127
129 static constexpr std::tuple XmlTag = { u"identity", QXmpp::Private::ns_disco_info };
130 static std::optional<QXmppDiscoIdentity> fromDom(const QDomElement &el);
131 void toXml(QXmlStreamWriter *writer) const;
133
134private:
135 QString m_category;
136 QString m_type;
137 QString m_name;
138 QString m_language;
139};
140
141 class QXMPP_EXPORT QXmppDiscoInfo
142{
143public:
144 QXmppDiscoInfo() { }
146 explicit QXmppDiscoInfo(const QString &node, const QList<QXmppDiscoIdentity> &identities = {}, const QList<QString> &features = {}, const QList<QXmppDataForm> &dataForms = {})
147 : m_node(node), m_identities(identities), m_features(features), m_dataForms(dataForms) { }
148
150 const QString &node() const { return m_node; }
152 void setNode(const QString &newNode) { m_node = newNode; }
153
155 const QList<QXmppDiscoIdentity> &identities() const { return m_identities; }
157 void setIdentities(const QList<QXmppDiscoIdentity> &newIdentities) { m_identities = newIdentities; }
158
160 const QList<QString> &features() const { return m_features; }
162 void setFeatures(const QList<QString> &newFeatures) { m_features = newFeatures; }
163
165 const QList<QXmppDataForm> &dataForms() const { return m_dataForms; }
168 void setDataForms(const QList<QXmppDataForm> &newDataForms) { m_dataForms = newDataForms; }
169 std::optional<QXmppDataForm> dataForm(QStringView formType) const;
170
172 template<QXmpp::Private::DataFormConvertible FormType>
173 std::optional<FormType> dataForm() const
174 {
175 if (auto form = dataForm(QXmpp::Private::DataFormType<FormType>)) {
176 if (auto result = FormType::fromDataForm(*form)) {
177 return *result;
178 }
179 }
180 return {};
181 }
182
183 QByteArray calculateEntityCapabilitiesHash() const;
184
186 static constexpr std::tuple XmlTag = { u"query", QXmpp::Private::ns_disco_info };
187 static std::optional<QXmppDiscoInfo> fromDom(const QDomElement &el);
188 void toXml(QXmlStreamWriter *writer) const;
190
191private:
192 QString m_node;
193 QList<QXmppDiscoIdentity> m_identities;
194 QList<QString> m_features;
195 QList<QXmppDataForm> m_dataForms;
196};
197
198#if QXMPP_DEPRECATED_SINCE(1, 12)
199 class QXMPP_EXPORT QXmppDiscoveryIq : public QXmppIq
200{
201public:
203 using Identity [[deprecated]] = QXmppDiscoIdentity;
205 using Item [[deprecated]] = QXmppDiscoItem;
206
207 [[deprecated("Use QXmppDiscoInfo/Items")]]
208 QXmppDiscoveryIq();
209 QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppDiscoveryIq)
210
211 enum QueryType {
212 InfoQuery,
213 ItemsQuery
214 };
215
216 QStringList features() const;
217 void setFeatures(const QStringList &features);
218
219 QList<QXmppDiscoIdentity> identities() const;
220 void setIdentities(const QList<QXmppDiscoIdentity> &identities);
221
222 QList<QXmppDiscoItem> items() const;
223 void setItems(const QList<QXmppDiscoItem> &items);
224
225 [[deprecated("Use dataForms() instead")]]
226 QXmppDataForm form() const;
227 [[deprecated("Use setDataForms() instead")]]
228 void setForm(const QXmppDataForm &form);
229
230 const QList<QXmppDataForm> &dataForms() const;
231 void setDataForms(const QList<QXmppDataForm> &dataForms);
232 std::optional<QXmppDataForm> dataForm(QStringView formType) const;
233
236 template<QXmpp::Private::DataFormConvertible FormT>
237 std::optional<FormT> dataForm() const
238 {
239 if (auto form = dataForm(QXmpp::Private::DataFormType<FormT>)) {
240 if (auto result = FormT::fromDataForm(*form)) {
241 return *result;
242 }
243 }
244 return {};
245 }
246
247 QString queryNode() const;
248 void setQueryNode(const QString &node);
249
250 enum QueryType queryType() const;
251 void setQueryType(enum QueryType type);
252
253 QByteArray verificationString() const;
254
256 [[deprecated("Use QXmpp::isIqElement()")]]
257 static bool isDiscoveryIq(const QDomElement &element);
258 static bool checkIqType(const QString &tagName, const QString &xmlNamespace);
259
260protected:
261 void parseElementFromChild(const QDomElement &element) override;
262 void toXmlElementFromChild(QXmlStreamWriter *writer) const override;
264
265private:
266 QSharedDataPointer<QXmppDiscoveryIqPrivate> d;
267};
268#endif
269
270#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