From bbb77132775e69b6df7df4ddf38a429aff733d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 21 Oct 2010 21:44:13 +0200 Subject: Moving queries & responders around. diff --git a/3rdParty/Snarl/SnarlInterface.cpp b/3rdParty/Snarl/SnarlInterface.cpp index f287b8e..b780140 100644 --- a/3rdParty/Snarl/SnarlInterface.cpp +++ b/3rdParty/Snarl/SnarlInterface.cpp @@ -809,4 +809,4 @@ LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr) WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, szUTF8, nSize, NULL, NULL); return szUTF8; -} \ No newline at end of file +} diff --git a/Swift/Controllers/Chat/MUCSearchController.cpp b/Swift/Controllers/Chat/MUCSearchController.cpp index dc81031..0cf02c7 100644 --- a/Swift/Controllers/Chat/MUCSearchController.cpp +++ b/Swift/Controllers/Chat/MUCSearchController.cpp @@ -11,8 +11,8 @@ #include #include -#include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" -#include "Swiften/Queries/Requests/GetDiscoItemsRequest.h" +#include "Swiften/Disco/GetDiscoInfoRequest.h" +#include "Swiften/Disco/GetDiscoItemsRequest.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/RequestMUCSearchUIEvent.h" diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 6b9c447..837e576 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -48,10 +48,10 @@ #include "Swiften/Elements/VCardUpdate.h" #include "Swift/Controllers/Settings/SettingsProvider.h" #include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Queries/Responders/DiscoInfoResponder.h" +#include "Swiften/Disco/DiscoInfoResponder.h" #include "Swiften/Disco/CapsInfoGenerator.h" -#include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" -#include "Swiften/Queries/Requests/GetVCardRequest.h" +#include "Swiften/Disco/GetDiscoInfoRequest.h" +#include "Swiften/VCards/GetVCardRequest.h" #include "Swiften/Avatars/AvatarStorage.h" #include "Swiften/Avatars/AvatarManagerImpl.h" #include "Swiften/Disco/CapsFileStorage.h" diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index e79fad1..defd1c6 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -12,8 +12,8 @@ #include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "Swift/Controllers/UIInterfaces/MainWindowFactory.h" #include "Swift/Controllers/NickResolver.h" -#include "Swiften/Queries/Requests/GetRosterRequest.h" -#include "Swiften/Queries/Requests/SetRosterRequest.h" +#include "Swiften/Roster/GetRosterRequest.h" +#include "Swiften/Roster/SetRosterRequest.h" #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" #include "Swiften/Presence/PresenceOracle.h" diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index c830b54..b2b4635 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -10,7 +10,7 @@ #include "Swiften/Client/StanzaChannel.h" #include "Swiften/Elements/VCardUpdate.h" -#include "Swiften/Queries/Requests/GetVCardRequest.h" +#include "Swiften/VCards/GetVCardRequest.h" #include "Swiften/StringCodecs/SHA1.h" #include "Swiften/StringCodecs/Hexify.h" #include "Swiften/Avatars/AvatarStorage.h" diff --git a/Swiften/Disco/CapsManager.cpp b/Swiften/Disco/CapsManager.cpp index a9920a2..43c2805 100644 --- a/Swiften/Disco/CapsManager.cpp +++ b/Swiften/Disco/CapsManager.cpp @@ -12,7 +12,7 @@ #include "Swiften/Disco/CapsStorage.h" #include "Swiften/Disco/CapsInfoGenerator.h" #include "Swiften/Elements/CapsInfo.h" -#include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" +#include "Swiften/Disco/GetDiscoInfoRequest.h" namespace Swift { diff --git a/Swiften/Disco/DiscoInfoResponder.cpp b/Swiften/Disco/DiscoInfoResponder.cpp new file mode 100644 index 0000000..154eded --- /dev/null +++ b/Swiften/Disco/DiscoInfoResponder.cpp @@ -0,0 +1,42 @@ +/* + * 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/DiscoInfoResponder.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Elements/DiscoInfo.h" + +namespace Swift { + +DiscoInfoResponder::DiscoInfoResponder(IQRouter* router) : GetResponder(router) { +} + +void DiscoInfoResponder::setDiscoInfo(const DiscoInfo& info) { + info_ = info; +} + +void DiscoInfoResponder::setDiscoInfo(const String& node, const DiscoInfo& info) { + DiscoInfo newInfo(info); + newInfo.setNode(node); + nodeInfo_[node] = newInfo; +} + +bool DiscoInfoResponder::handleGetRequest(const JID& from, const String& id, boost::shared_ptr info) { + if (info->getNode().isEmpty()) { + sendResponse(from, id, boost::shared_ptr(new DiscoInfo(info_))); + } + else { + std::map::const_iterator i = nodeInfo_.find(info->getNode()); + if (i != nodeInfo_.end()) { + sendResponse(from, id, boost::shared_ptr(new DiscoInfo((*i).second))); + } + else { + sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel); + } + } + return true; +} + +} diff --git a/Swiften/Disco/DiscoInfoResponder.h b/Swiften/Disco/DiscoInfoResponder.h new file mode 100644 index 0000000..4a7d271 --- /dev/null +++ b/Swiften/Disco/DiscoInfoResponder.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#ifndef SWIFTEN_DiscoInfoResponder_H +#define SWIFTEN_DiscoInfoResponder_H + +#include + +#include "Swiften/Queries/GetResponder.h" +#include "Swiften/Elements/DiscoInfo.h" + +namespace Swift { + class IQRouter; + + class DiscoInfoResponder : public GetResponder { + public: + DiscoInfoResponder(IQRouter* router); + + void setDiscoInfo(const DiscoInfo& info); + void setDiscoInfo(const String& node, const DiscoInfo& info); + + private: + virtual bool handleGetRequest(const JID& from, const String& id, boost::shared_ptr payload); + + private: + DiscoInfo info_; + std::map nodeInfo_; + }; +} + +#endif diff --git a/Swiften/Disco/GetDiscoInfoRequest.h b/Swiften/Disco/GetDiscoInfoRequest.h new file mode 100644 index 0000000..d1ed279 --- /dev/null +++ b/Swiften/Disco/GetDiscoInfoRequest.h @@ -0,0 +1,33 @@ +/* + * 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/Queries/GenericRequest.h" +#include "Swiften/Elements/DiscoInfo.h" + +namespace Swift { + class GetDiscoInfoRequest : public GenericRequest, public Shared { + public: + static ref create(const JID& jid, IQRouter* router) { + return ref(new GetDiscoInfoRequest(jid, router)); + } + + static ref create(const JID& jid, const String& node, IQRouter* router) { + return ref(new GetDiscoInfoRequest(jid, node, router)); + } + + private: + GetDiscoInfoRequest(const JID& jid, IQRouter* router) : + GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoInfo()), router) { + } + + GetDiscoInfoRequest(const JID& jid, const String& node, IQRouter* router) : + GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoInfo()), router) { + getPayloadGeneric()->setNode(node); + } + }; +} diff --git a/Swiften/Disco/GetDiscoItemsRequest.h b/Swiften/Disco/GetDiscoItemsRequest.h new file mode 100644 index 0000000..ed565ac --- /dev/null +++ b/Swiften/Disco/GetDiscoItemsRequest.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Queries/GenericRequest.h" +#include "Swiften/Elements/DiscoItems.h" + +namespace Swift { + class GetDiscoItemsRequest : public GenericRequest, public Shared { + public: + static ref create(const JID& jid, IQRouter* router) { + return ref(new GetDiscoItemsRequest(jid, router)); + } + + private: + GetDiscoItemsRequest(const JID& jid, IQRouter* router) : + GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoItems()), router) { + } + }; +} diff --git a/Swiften/Disco/SConscript b/Swiften/Disco/SConscript index 9da3fb3..d07d490 100644 --- a/Swiften/Disco/SConscript +++ b/Swiften/Disco/SConscript @@ -6,5 +6,6 @@ objects = swiften_env.StaticObject([ "EntityCapsManager.cpp", "CapsStorage.cpp", "CapsFileStorage.cpp", + "DiscoInfoResponder.cpp", ]) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp b/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp new file mode 100644 index 0000000..a9e85c0 --- /dev/null +++ b/Swiften/Disco/UnitTest/DiscoInfoResponderTest.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include +#include +#include + +#include "Swiften/Disco/DiscoInfoResponder.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Queries/DummyIQChannel.h" + +using namespace Swift; + +class DiscoInfoResponderTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(DiscoInfoResponderTest); + CPPUNIT_TEST(testHandleRequest_GetToplevelInfo); + CPPUNIT_TEST(testHandleRequest_GetNodeInfo); + CPPUNIT_TEST(testHandleRequest_GetInvalidNodeInfo); + CPPUNIT_TEST_SUITE_END(); + + public: + DiscoInfoResponderTest() {} + + void setUp() { + channel_ = new DummyIQChannel(); + router_ = new IQRouter(channel_); + } + + void tearDown() { + delete router_; + delete channel_; + } + + void testHandleRequest_GetToplevelInfo() { + DiscoInfoResponder testling(router_); + testling.start(); + DiscoInfo discoInfo; + discoInfo.addFeature("foo"); + testling.setDiscoInfo(discoInfo); + + boost::shared_ptr query(new DiscoInfo()); + channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); + + CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); + boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(String(""), payload->getNode()); + CPPUNIT_ASSERT(payload->hasFeature("foo")); + + testling.stop(); + } + + void testHandleRequest_GetNodeInfo() { + DiscoInfoResponder testling(router_); + testling.start(); + DiscoInfo discoInfo; + discoInfo.addFeature("foo"); + testling.setDiscoInfo(discoInfo); + DiscoInfo discoInfoBar; + discoInfoBar.addFeature("bar"); + testling.setDiscoInfo("bar-node", discoInfoBar); + + boost::shared_ptr query(new DiscoInfo()); + query->setNode("bar-node"); + channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); + + CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); + boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(String("bar-node"), payload->getNode()); + CPPUNIT_ASSERT(payload->hasFeature("bar")); + + testling.stop(); + } + + void testHandleRequest_GetInvalidNodeInfo() { + DiscoInfoResponder testling(router_); + + boost::shared_ptr query(new DiscoInfo()); + query->setNode("bar-node"); + channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); + + CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); + boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); + CPPUNIT_ASSERT(payload); + } + + private: + IQRouter* router_; + DummyIQChannel* channel_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoResponderTest); diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp index 3d814a8..e796e66 100644 --- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp +++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp @@ -14,7 +14,7 @@ #include "Swiften/EventLoop/SimpleEventLoop.h" #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/MainBoostIOServiceThread.h" -#include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" +#include "Swiften/Disco/GetDiscoInfoRequest.h" using namespace Swift; diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp index 7b2c7f4..f504d2c 100644 --- a/Swiften/QA/ClientTest/ClientTest.cpp +++ b/Swiften/QA/ClientTest/ClientTest.cpp @@ -11,7 +11,7 @@ #include "Swiften/Network/BoostTimer.h" #include "Swiften/EventLoop/MainEventLoop.h" #include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Queries/Requests/GetRosterRequest.h" +#include "Swiften/Roster/GetRosterRequest.h" #include "Swiften/Client/ClientXMLTracer.h" #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/MainBoostIOServiceThread.h" diff --git a/Swiften/QA/ReconnectTest/ReconnectTest.cpp b/Swiften/QA/ReconnectTest/ReconnectTest.cpp index 24be849..c4e34ac 100644 --- a/Swiften/QA/ReconnectTest/ReconnectTest.cpp +++ b/Swiften/QA/ReconnectTest/ReconnectTest.cpp @@ -11,7 +11,7 @@ #include "Swiften/Network/BoostTimer.h" #include "Swiften/EventLoop/MainEventLoop.h" #include "Swiften/EventLoop/SimpleEventLoop.h" -#include "Swiften/Queries/Requests/GetRosterRequest.h" +#include "Swiften/Roster/GetRosterRequest.h" #include "Swiften/Client/ClientXMLTracer.h" #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/MainBoostIOServiceThread.h" diff --git a/Swiften/Queries/Requests/GetDiscoInfoRequest.h b/Swiften/Queries/Requests/GetDiscoInfoRequest.h deleted file mode 100644 index d1ed279..0000000 --- a/Swiften/Queries/Requests/GetDiscoInfoRequest.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/Queries/GenericRequest.h" -#include "Swiften/Elements/DiscoInfo.h" - -namespace Swift { - class GetDiscoInfoRequest : public GenericRequest, public Shared { - public: - static ref create(const JID& jid, IQRouter* router) { - return ref(new GetDiscoInfoRequest(jid, router)); - } - - static ref create(const JID& jid, const String& node, IQRouter* router) { - return ref(new GetDiscoInfoRequest(jid, node, router)); - } - - private: - GetDiscoInfoRequest(const JID& jid, IQRouter* router) : - GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoInfo()), router) { - } - - GetDiscoInfoRequest(const JID& jid, const String& node, IQRouter* router) : - GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoInfo()), router) { - getPayloadGeneric()->setNode(node); - } - }; -} diff --git a/Swiften/Queries/Requests/GetDiscoItemsRequest.h b/Swiften/Queries/Requests/GetDiscoItemsRequest.h deleted file mode 100644 index ed565ac..0000000 --- a/Swiften/Queries/Requests/GetDiscoItemsRequest.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swiften/Queries/GenericRequest.h" -#include "Swiften/Elements/DiscoItems.h" - -namespace Swift { - class GetDiscoItemsRequest : public GenericRequest, public Shared { - public: - static ref create(const JID& jid, IQRouter* router) { - return ref(new GetDiscoItemsRequest(jid, router)); - } - - private: - GetDiscoItemsRequest(const JID& jid, IQRouter* router) : - GenericRequest(IQ::Get, jid, boost::shared_ptr(new DiscoItems()), router) { - } - }; -} diff --git a/Swiften/Queries/Requests/GetRosterRequest.h b/Swiften/Queries/Requests/GetRosterRequest.h deleted file mode 100644 index 271b2fb..0000000 --- a/Swiften/Queries/Requests/GetRosterRequest.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/Queries/GenericRequest.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Base/Shared.h" - -namespace Swift { - class GetRosterRequest : public GenericRequest, public Shared { - public: - static ref create(IQRouter* router) { - return ref(new GetRosterRequest(router)); - } - - private: - GetRosterRequest(IQRouter* router) : - GenericRequest(IQ::Get, JID(), boost::shared_ptr(new RosterPayload()), router) { - } - }; -} diff --git a/Swiften/Queries/Requests/GetVCardRequest.h b/Swiften/Queries/Requests/GetVCardRequest.h deleted file mode 100644 index 2c40cd1..0000000 --- a/Swiften/Queries/Requests/GetVCardRequest.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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/Queries/GenericRequest.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Base/Shared.h" - -namespace Swift { - class GetVCardRequest : public GenericRequest, public Shared { - public: - static ref create(const JID& jid, IQRouter* router) { - return ref(new GetVCardRequest(jid, router)); - } - - private: - GetVCardRequest(const JID& jid, IQRouter* router) : GenericRequest(IQ::Get, jid, boost::shared_ptr(new VCard()), router) { - } - }; -} diff --git a/Swiften/Queries/Requests/SetRosterRequest.h b/Swiften/Queries/Requests/SetRosterRequest.h deleted file mode 100644 index 7b1bf8c..0000000 --- a/Swiften/Queries/Requests/SetRosterRequest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swiften/Base/boost_bsignals.h" -#include - -#include "Swiften/Queries/Request.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Base/Shared.h" - -namespace Swift { - class SetRosterRequest : public Request, public Shared { - public: - static ref create(RosterPayload::ref payload, IQRouter* router) { - return ref(new SetRosterRequest(payload, router)); - } - - private: - SetRosterRequest(boost::shared_ptr payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr(payload), router) { - } - - virtual void handleResponse(boost::shared_ptr /*payload*/, boost::optional error) { - onResponse(error); - } - - public: - boost::signal&)> onResponse; - }; -} diff --git a/Swiften/Queries/Responders/DiscoInfoResponder.cpp b/Swiften/Queries/Responders/DiscoInfoResponder.cpp deleted file mode 100644 index 63014c7..0000000 --- a/Swiften/Queries/Responders/DiscoInfoResponder.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include "Swiften/Queries/Responders/DiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/DiscoInfo.h" - -namespace Swift { - -DiscoInfoResponder::DiscoInfoResponder(IQRouter* router) : GetResponder(router) { -} - -void DiscoInfoResponder::setDiscoInfo(const DiscoInfo& info) { - info_ = info; -} - -void DiscoInfoResponder::setDiscoInfo(const String& node, const DiscoInfo& info) { - DiscoInfo newInfo(info); - newInfo.setNode(node); - nodeInfo_[node] = newInfo; -} - -bool DiscoInfoResponder::handleGetRequest(const JID& from, const String& id, boost::shared_ptr info) { - if (info->getNode().isEmpty()) { - sendResponse(from, id, boost::shared_ptr(new DiscoInfo(info_))); - } - else { - std::map::const_iterator i = nodeInfo_.find(info->getNode()); - if (i != nodeInfo_.end()) { - sendResponse(from, id, boost::shared_ptr(new DiscoInfo((*i).second))); - } - else { - sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel); - } - } - return true; -} - -} diff --git a/Swiften/Queries/Responders/DiscoInfoResponder.h b/Swiften/Queries/Responders/DiscoInfoResponder.h deleted file mode 100644 index 4a7d271..0000000 --- a/Swiften/Queries/Responders/DiscoInfoResponder.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_DiscoInfoResponder_H -#define SWIFTEN_DiscoInfoResponder_H - -#include - -#include "Swiften/Queries/GetResponder.h" -#include "Swiften/Elements/DiscoInfo.h" - -namespace Swift { - class IQRouter; - - class DiscoInfoResponder : public GetResponder { - public: - DiscoInfoResponder(IQRouter* router); - - void setDiscoInfo(const DiscoInfo& info); - void setDiscoInfo(const String& node, const DiscoInfo& info); - - private: - virtual bool handleGetRequest(const JID& from, const String& id, boost::shared_ptr payload); - - private: - DiscoInfo info_; - std::map nodeInfo_; - }; -} - -#endif diff --git a/Swiften/Queries/Responders/RosterPushResponder.h b/Swiften/Queries/Responders/RosterPushResponder.h deleted file mode 100644 index 48111a7..0000000 --- a/Swiften/Queries/Responders/RosterPushResponder.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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/Base/boost_bsignals.h" - -#include "Swiften/Queries/SetResponder.h" -#include "Swiften/Elements/RosterPayload.h" - -namespace Swift { - class RosterPushResponder : public SetResponder { - public: - RosterPushResponder(IQRouter* router) : SetResponder(router) {} - - public: - boost::signal)> onRosterReceived; - - private: - virtual bool handleSetRequest(const JID& from, const String& id, boost::shared_ptr payload) { - onRosterReceived(payload); - sendResponse(from, id, boost::shared_ptr()); - return true; - } - }; -} diff --git a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp b/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp deleted file mode 100644 index 20fa9ff..0000000 --- a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include -#include -#include - -#include "Swiften/Queries/Responders/DiscoInfoResponder.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/DummyIQChannel.h" - -using namespace Swift; - -class DiscoInfoResponderTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoInfoResponderTest); - CPPUNIT_TEST(testHandleRequest_GetToplevelInfo); - CPPUNIT_TEST(testHandleRequest_GetNodeInfo); - CPPUNIT_TEST(testHandleRequest_GetInvalidNodeInfo); - CPPUNIT_TEST_SUITE_END(); - - public: - DiscoInfoResponderTest() {} - - void setUp() { - channel_ = new DummyIQChannel(); - router_ = new IQRouter(channel_); - } - - void tearDown() { - delete router_; - delete channel_; - } - - void testHandleRequest_GetToplevelInfo() { - DiscoInfoResponder testling(router_); - testling.start(); - DiscoInfo discoInfo; - discoInfo.addFeature("foo"); - testling.setDiscoInfo(discoInfo); - - boost::shared_ptr query(new DiscoInfo()); - channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); - - CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); - boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(String(""), payload->getNode()); - CPPUNIT_ASSERT(payload->hasFeature("foo")); - - testling.stop(); - } - - void testHandleRequest_GetNodeInfo() { - DiscoInfoResponder testling(router_); - testling.start(); - DiscoInfo discoInfo; - discoInfo.addFeature("foo"); - testling.setDiscoInfo(discoInfo); - DiscoInfo discoInfoBar; - discoInfoBar.addFeature("bar"); - testling.setDiscoInfo("bar-node", discoInfoBar); - - boost::shared_ptr query(new DiscoInfo()); - query->setNode("bar-node"); - channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); - - CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); - boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(String("bar-node"), payload->getNode()); - CPPUNIT_ASSERT(payload->hasFeature("bar")); - - testling.stop(); - } - - void testHandleRequest_GetInvalidNodeInfo() { - DiscoInfoResponder testling(router_); - - boost::shared_ptr query(new DiscoInfo()); - query->setNode("bar-node"); - channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); - - CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); - boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); - CPPUNIT_ASSERT(payload); - } - - private: - IQRouter* router_; - DummyIQChannel* channel_; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoResponderTest); diff --git a/Swiften/Roster/GetRosterRequest.h b/Swiften/Roster/GetRosterRequest.h new file mode 100644 index 0000000..271b2fb --- /dev/null +++ b/Swiften/Roster/GetRosterRequest.h @@ -0,0 +1,25 @@ +/* + * 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/Queries/GenericRequest.h" +#include "Swiften/Elements/RosterPayload.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class GetRosterRequest : public GenericRequest, public Shared { + public: + static ref create(IQRouter* router) { + return ref(new GetRosterRequest(router)); + } + + private: + GetRosterRequest(IQRouter* router) : + GenericRequest(IQ::Get, JID(), boost::shared_ptr(new RosterPayload()), router) { + } + }; +} diff --git a/Swiften/Roster/RosterPushResponder.h b/Swiften/Roster/RosterPushResponder.h new file mode 100644 index 0000000..48111a7 --- /dev/null +++ b/Swiften/Roster/RosterPushResponder.h @@ -0,0 +1,29 @@ +/* + * 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/Base/boost_bsignals.h" + +#include "Swiften/Queries/SetResponder.h" +#include "Swiften/Elements/RosterPayload.h" + +namespace Swift { + class RosterPushResponder : public SetResponder { + public: + RosterPushResponder(IQRouter* router) : SetResponder(router) {} + + public: + boost::signal)> onRosterReceived; + + private: + virtual bool handleSetRequest(const JID& from, const String& id, boost::shared_ptr payload) { + onRosterReceived(payload); + sendResponse(from, id, boost::shared_ptr()); + return true; + } + }; +} diff --git a/Swiften/Roster/SetRosterRequest.h b/Swiften/Roster/SetRosterRequest.h new file mode 100644 index 0000000..7b1bf8c --- /dev/null +++ b/Swiften/Roster/SetRosterRequest.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Base/boost_bsignals.h" +#include + +#include "Swiften/Queries/Request.h" +#include "Swiften/Elements/RosterPayload.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class SetRosterRequest : public Request, public Shared { + public: + static ref create(RosterPayload::ref payload, IQRouter* router) { + return ref(new SetRosterRequest(payload, router)); + } + + private: + SetRosterRequest(boost::shared_ptr payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr(payload), router) { + } + + virtual void handleResponse(boost::shared_ptr /*payload*/, boost::optional error) { + onResponse(error); + } + + public: + boost::signal&)> onResponse; + }; +} diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp index feaa7d4..024cb1d 100644 --- a/Swiften/Roster/XMPPRosterController.cpp +++ b/Swiften/Roster/XMPPRosterController.cpp @@ -11,7 +11,7 @@ #include "Swiften/Base/foreach.h" #include "Swiften/Elements/RosterItemPayload.h" #include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/Requests/GetRosterRequest.h" +#include "Swiften/Roster/GetRosterRequest.h" #include "Swiften/EventLoop/MainEventLoop.h" #include "Swiften/Roster/Roster.h" #include "Swiften/Roster/SetPresence.h" diff --git a/Swiften/Roster/XMPPRosterController.h b/Swiften/Roster/XMPPRosterController.h index 22a63ad..d846b86 100644 --- a/Swiften/Roster/XMPPRosterController.h +++ b/Swiften/Roster/XMPPRosterController.h @@ -12,7 +12,7 @@ #include "Swiften/Base/String.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Queries/Responders/RosterPushResponder.h" +#include "Swiften/Roster/RosterPushResponder.h" #include "Swiften/Base/boost_bsignals.h" namespace Swift { diff --git a/Swiften/SConscript b/Swiften/SConscript index b371826..e96a868 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -54,7 +54,6 @@ if env["SCONS_STAGE"] == "build" : "Queries/IQHandler.cpp", "Queries/IQRouter.cpp", "Queries/Request.cpp", - "Queries/Responders/DiscoInfoResponder.cpp", "Queries/Responders/SoftwareVersionResponder.cpp", "Roster/ContactRosterItem.cpp", "Roster/GroupRosterItem.cpp", @@ -217,7 +216,7 @@ if env["SCONS_STAGE"] == "build" : File("Presence/UnitTest/PresenceOracleTest.cpp"), File("Presence/UnitTest/PresenceSenderTest.cpp"), File("Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp"), - File("Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp"), + File("Disco/UnitTest/DiscoInfoResponderTest.cpp"), File("Queries/UnitTest/IQRouterTest.cpp"), File("Queries/UnitTest/RequestTest.cpp"), File("Queries/UnitTest/ResponderTest.cpp"), @@ -266,7 +265,7 @@ if env["SCONS_STAGE"] == "build" : # Generate the Swiften header swiften_header = "#pragma once\n" top_path = env.Dir("..").abspath - public_dirs = ["Queries", "Client", "Component", "Elements"] + public_dirs = ["Queries", "Client", "Component", "Elements", "Roster"] for public_dir in public_dirs : for root, dirs, files in os.walk(env.Dir(public_dir).abspath) : if root.endswith("UnitTest") : diff --git a/Swiften/VCards/GetVCardRequest.h b/Swiften/VCards/GetVCardRequest.h new file mode 100644 index 0000000..2c40cd1 --- /dev/null +++ b/Swiften/VCards/GetVCardRequest.h @@ -0,0 +1,24 @@ +/* + * 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/Queries/GenericRequest.h" +#include "Swiften/Elements/VCard.h" +#include "Swiften/Base/Shared.h" + +namespace Swift { + class GetVCardRequest : public GenericRequest, public Shared { + public: + static ref create(const JID& jid, IQRouter* router) { + return ref(new GetVCardRequest(jid, router)); + } + + private: + GetVCardRequest(const JID& jid, IQRouter* router) : GenericRequest(IQ::Get, jid, boost::shared_ptr(new VCard()), router) { + } + }; +} diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp index c189717..5c26635 100644 --- a/Swiften/VCards/VCardManager.cpp +++ b/Swiften/VCards/VCardManager.cpp @@ -10,7 +10,7 @@ #include "Swiften/JID/JID.h" #include "Swiften/VCards/VCardStorage.h" -#include "Swiften/Queries/Requests/GetVCardRequest.h" +#include "Swiften/VCards/GetVCardRequest.h" namespace Swift { diff --git a/Swiften/VCards/VCardMemoryStorageFactory.h b/Swiften/VCards/VCardMemoryStorageFactory.h index 4b4d2c0..d48794d 100644 --- a/Swiften/VCards/VCardMemoryStorageFactory.h +++ b/Swiften/VCards/VCardMemoryStorageFactory.h @@ -21,4 +21,4 @@ namespace Swift { return new VCardMemoryStorage(); } }; -} \ No newline at end of file +} -- cgit v0.10.2-6-g49f6