summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-23 21:08:19 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-03 12:17:40 (GMT)
commit9d9fb66aefef85a1c5ad432391014d15011747d1 (patch)
tree55b1ebe7dcb0108008a28ebf8fee773b27e60547 /Swiften/Disco
parentd509598b0f0edf5e103caedbab8662edc834445e (diff)
downloadswift-contrib-9d9fb66aefef85a1c5ad432391014d15011747d1.zip
swift-contrib-9d9fb66aefef85a1c5ad432391014d15011747d1.tar.bz2
Added ClientDiscoManager.
Diffstat (limited to 'Swiften/Disco')
-rw-r--r--Swiften/Disco/ClientDiscoManager.cpp39
-rw-r--r--Swiften/Disco/ClientDiscoManager.h67
-rw-r--r--Swiften/Disco/DiscoInfoResponder.cpp5
-rw-r--r--Swiften/Disco/DiscoInfoResponder.h6
-rw-r--r--Swiften/Disco/SConscript1
5 files changed, 114 insertions, 4 deletions
diff --git a/Swiften/Disco/ClientDiscoManager.cpp b/Swiften/Disco/ClientDiscoManager.cpp
new file mode 100644
index 0000000..6753df2
--- /dev/null
+++ b/Swiften/Disco/ClientDiscoManager.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/Disco/ClientDiscoManager.h"
+
+#include "Swiften/Disco/DiscoInfoResponder.h"
+#include "Swiften/Disco/CapsInfoGenerator.h"
+#include "Swiften/Presence/PayloadAddingPresenceSender.h"
+
+namespace Swift {
+
+ClientDiscoManager::ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender) {
+ discoInfoResponder = new DiscoInfoResponder(iqRouter);
+ discoInfoResponder->start();
+ this->presenceSender = new PayloadAddingPresenceSender(presenceSender);
+}
+
+ClientDiscoManager::~ClientDiscoManager() {
+ delete presenceSender;
+ discoInfoResponder->stop();
+ delete discoInfoResponder;
+}
+
+void ClientDiscoManager::setCapsNode(const String& node) {
+ capsNode = node;
+}
+
+void ClientDiscoManager::setDiscoInfo(const DiscoInfo& discoInfo) {
+ capsInfo = CapsInfo::ref(new CapsInfo(CapsInfoGenerator(capsNode).generateCapsInfo(discoInfo)));
+ discoInfoResponder->clearDiscoInfo();
+ discoInfoResponder->setDiscoInfo(discoInfo);
+ discoInfoResponder->setDiscoInfo(capsInfo->getNode() + "#" + capsInfo->getVersion(), discoInfo);
+ presenceSender->setPayload(capsInfo);
+}
+
+}
diff --git a/Swiften/Disco/ClientDiscoManager.h b/Swiften/Disco/ClientDiscoManager.h
new file mode 100644
index 0000000..b997374
--- /dev/null
+++ b/Swiften/Disco/ClientDiscoManager.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Elements/CapsInfo.h"
+#include "Swiften/Elements/DiscoInfo.h"
+#include "Swiften/Presence/PayloadAddingPresenceSender.h"
+
+namespace Swift {
+ class IQRouter;
+ class DiscoInfoResponder;
+ class PayloadAddingPresenceSender;
+ class PresenceSender;
+
+ /**
+ * Class responsible for managing outgoing disco information for a client.
+ *
+ * The manager will respond to disco#info requests, and add entity capabilities information
+ * to outgoing presence.
+ *
+ * To use this class, call setCapsNode() once with the caps URI of the client. After this,
+ * call setDiscoInfo() with the capabilities for the client. This can be
+ * called whenever the capabilities change.
+ */
+ class ClientDiscoManager {
+ public:
+ /**
+ * Constructs the manager
+ *
+ * \param iqRouter the router on which requests will be answered
+ * \param presenceSender the presence sender to which all outgoing presence
+ * (with caps information) will be sent.
+ */
+ ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender);
+ ~ClientDiscoManager();
+
+ /**
+ * Needs to be called before calling setDiscoInfo().
+ */
+ void setCapsNode(const String& node);
+
+ /**
+ * Sets the capabilities of the client.
+ */
+ void setDiscoInfo(const DiscoInfo& info);
+
+ /**
+ * Returns the presence sender through which all outgoing presence
+ * should be sent.
+ * The manager will add the necessary caps information, and forward it to
+ * the presence sender passed at construction time.
+ */
+ PresenceSender* getPresenceSender() const {
+ return presenceSender;
+ }
+
+ private:
+ PayloadAddingPresenceSender* presenceSender;
+ DiscoInfoResponder* discoInfoResponder;
+ String capsNode;
+ CapsInfo::ref capsInfo;
+ };
+}
diff --git a/Swiften/Disco/DiscoInfoResponder.cpp b/Swiften/Disco/DiscoInfoResponder.cpp
index 154eded..2e686c7 100644
--- a/Swiften/Disco/DiscoInfoResponder.cpp
+++ b/Swiften/Disco/DiscoInfoResponder.cpp
@@ -13,6 +13,11 @@ namespace Swift {
DiscoInfoResponder::DiscoInfoResponder(IQRouter* router) : GetResponder<DiscoInfo>(router) {
}
+void DiscoInfoResponder::clearDiscoInfo() {
+ info_ = DiscoInfo();
+ nodeInfo_.clear();
+}
+
void DiscoInfoResponder::setDiscoInfo(const DiscoInfo& info) {
info_ = info;
}
diff --git a/Swiften/Disco/DiscoInfoResponder.h b/Swiften/Disco/DiscoInfoResponder.h
index 4a7d271..0dc1172 100644
--- a/Swiften/Disco/DiscoInfoResponder.h
+++ b/Swiften/Disco/DiscoInfoResponder.h
@@ -4,8 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_DiscoInfoResponder_H
-#define SWIFTEN_DiscoInfoResponder_H
+#pragma once
#include <map>
@@ -19,6 +18,7 @@ namespace Swift {
public:
DiscoInfoResponder(IQRouter* router);
+ void clearDiscoInfo();
void setDiscoInfo(const DiscoInfo& info);
void setDiscoInfo(const String& node, const DiscoInfo& info);
@@ -30,5 +30,3 @@ namespace Swift {
std::map<String, DiscoInfo> nodeInfo_;
};
}
-
-#endif
diff --git a/Swiften/Disco/SConscript b/Swiften/Disco/SConscript
index 3838d0e..a791946 100644
--- a/Swiften/Disco/SConscript
+++ b/Swiften/Disco/SConscript
@@ -7,6 +7,7 @@ objects = swiften_env.StaticObject([
"EntityCapsProvider.cpp",
"CapsStorage.cpp",
"CapsFileStorage.cpp",
+ "ClientDiscoManager.cpp",
"DiscoInfoResponder.cpp",
])
swiften_env.Append(SWIFTEN_OBJECTS = [objects])