aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2022-04-07 18:10:42 +0200
committerLinus Jahn <lnj@kaidan.im>2022-04-09 22:27:12 +0200
commita42c11570b9bba3465fb79dc936de6cb3c7c48cb (patch)
tree0d5a417e9fa1972fd89797c074bbbef3113fd51f /src
parentd306ed08aa9d681a0b51ebbf2ec2a00b70b61018 (diff)
downloadqxmpp-a42c11570b9bba3465fb79dc936de6cb3c7c48cb.tar.gz
PubSubManager: Add requestFeatures()
Diffstat (limited to 'src')
-rw-r--r--src/client/QXmppPubSubManager.cpp59
-rw-r--r--src/client/QXmppPubSubManager.h18
2 files changed, 77 insertions, 0 deletions
diff --git a/src/client/QXmppPubSubManager.cpp b/src/client/QXmppPubSubManager.cpp
index 8e2a1b6f..00d537db 100644
--- a/src/client/QXmppPubSubManager.cpp
+++ b/src/client/QXmppPubSubManager.cpp
@@ -79,6 +79,13 @@ using namespace QXmpp::Private;
///
///
+/// \typedef QXmppPubSubManager::FeaturesResult
+///
+/// Type containing service discovery features, InvalidServiceType if the service is not of the
+/// desired type or the returned IQ error (QXmppStanza::Error).
+///
+
+///
/// \typedef QXmppPubSubManager::NodesResult
///
/// Type containing a list of node names or the returned IQ error
@@ -171,6 +178,58 @@ QXmppPubSubManager::~QXmppPubSubManager()
}
///
+/// Requests all features of a pubsub service and checks the identities via service discovery.
+///
+/// This uses a \xep{0030, Service Discovery} info request to get the service
+/// identities and features.
+///
+/// The features are only returned if the service is of type serviceType,
+/// otherwise InvalidServiceType is returned.
+///
+/// \warning THIS API IS NOT FINALIZED YET!
+///
+/// \param serviceJid JID of the entity hosting the pubsub service
+/// \param serviceType type of service to retrieve features for
+///
+QFuture<QXmppPubSubManager::FeaturesResult> QXmppPubSubManager::requestFeatures(const QString &serviceJid, ServiceType serviceType)
+{
+ QXmppDiscoveryIq request;
+ request.setType(QXmppIq::Get);
+ request.setQueryType(QXmppDiscoveryIq::InfoQuery);
+ request.setTo(serviceJid);
+
+ return chainIq(client()->sendIq(std::move(request)), this, [=](QXmppDiscoveryIq &&iq) -> FeaturesResult {
+ const auto identities = iq.identities();
+
+ const auto isPubSubServiceFound = std::any_of(identities.cbegin(), identities.cend(), [=](const QXmppDiscoveryIq::Identity &identity) {
+ if (identity.category() == QStringLiteral("pubsub")) {
+ const auto identityType = identity.type();
+
+ switch (serviceType) {
+ case PubSubOrPep:
+ return identityType == QStringLiteral("service") || identityType == QStringLiteral("pep");
+ case PubSub:
+ return identityType == QStringLiteral("service");
+ case Pep:
+ return identityType == QStringLiteral("pep");
+ }
+ }
+ return false;
+ });
+
+ if (isPubSubServiceFound) {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ return iq.features();
+#else
+ return iq.features().toVector();
+#endif
+ }
+
+ return InvalidServiceType();
+ });
+}
+
+///
/// Requests all listed nodes of a pubsub service via service discovery.
///
/// This uses a \xep{0030, Service Discovery} items request to get a list of
diff --git a/src/client/QXmppPubSubManager.h b/src/client/QXmppPubSubManager.h
index 8e02f801..8c7a014b 100644
--- a/src/client/QXmppPubSubManager.h
+++ b/src/client/QXmppPubSubManager.h
@@ -26,12 +26,28 @@ class QXMPP_EXPORT QXmppPubSubManager : public QXmppClientExtension
public:
///
+ /// Type of PubSub service
+ ///
+ enum ServiceType {
+ PubSubOrPep, ///< PubSub service or PEP service
+ PubSub, ///< PubSub service only
+ Pep ///< PEP service only
+ };
+
+ ///
/// Pre-defined ID of a PubSub item
///
enum StandardItemId {
Current ///< Item of a singleton node
};
+ ///
+ /// Used to indicate a service type mismatch.
+ ///
+ struct InvalidServiceType
+ {
+ };
+
template<typename T>
struct Items
{
@@ -40,6 +56,7 @@ public:
};
using Result = std::variant<QXmpp::Success, QXmppStanza::Error>;
+ using FeaturesResult = std::variant<QVector<QString>, InvalidServiceType, QXmppStanza::Error>;
using NodesResult = std::variant<QVector<QString>, QXmppStanza::Error>;
using InstantNodeResult = std::variant<QString, QXmppStanza::Error>;
template<typename T>
@@ -58,6 +75,7 @@ public:
~QXmppPubSubManager();
// Generic PubSub (the PubSub service is the given entity)
+ QFuture<FeaturesResult> requestFeatures(const QString &serviceJid, ServiceType serviceType = PubSubOrPep);
QFuture<NodesResult> fetchNodes(const QString &jid);
QFuture<Result> createNode(const QString &jid, const QString &nodeName);
QFuture<Result> createNode(const QString &jid, const QString &nodeName, const QXmppPubSubNodeConfig &config);