diff options
Diffstat (limited to 'Swiften/Disco')
-rw-r--r-- | Swiften/Disco/ClientDiscoManager.cpp | 39 | ||||
-rw-r--r-- | Swiften/Disco/ClientDiscoManager.h | 67 | ||||
-rw-r--r-- | Swiften/Disco/DiscoInfoResponder.cpp | 5 | ||||
-rw-r--r-- | Swiften/Disco/DiscoInfoResponder.h | 6 | ||||
-rw-r--r-- | Swiften/Disco/SConscript | 1 |
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]) |