summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
committerTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
commitcfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch)
tree18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Roster
parent1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff)
downloadswift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip
swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines in the process. Changed CheckTabs.py tool to disallow hard tabs in source files. Test-Information: Manually checked 30 random files that the conversion worked as expected. Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Roster')
-rw-r--r--Swiften/Roster/GetRosterRequest.h32
-rw-r--r--Swiften/Roster/RosterMemoryStorage.cpp8
-rw-r--r--Swiften/Roster/RosterMemoryStorage.h20
-rw-r--r--Swiften/Roster/RosterPushResponder.h34
-rw-r--r--Swiften/Roster/RosterStorage.h12
-rw-r--r--Swiften/Roster/SetRosterRequest.h36
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp668
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp166
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp20
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h76
-rw-r--r--Swiften/Roster/XMPPRoster.h152
-rw-r--r--Swiften/Roster/XMPPRosterController.cpp106
-rw-r--r--Swiften/Roster/XMPPRosterController.h52
-rw-r--r--Swiften/Roster/XMPPRosterImpl.cpp112
-rw-r--r--Swiften/Roster/XMPPRosterImpl.h44
-rw-r--r--Swiften/Roster/XMPPRosterItem.h70
16 files changed, 804 insertions, 804 deletions
diff --git a/Swiften/Roster/GetRosterRequest.h b/Swiften/Roster/GetRosterRequest.h
index 05863d3..6ca16cb 100644
--- a/Swiften/Roster/GetRosterRequest.h
+++ b/Swiften/Roster/GetRosterRequest.h
@@ -11,23 +11,23 @@
#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetRosterRequest : public GenericRequest<RosterPayload> {
- public:
- typedef boost::shared_ptr<GetRosterRequest> ref;
+ class SWIFTEN_API GetRosterRequest : public GenericRequest<RosterPayload> {
+ public:
+ typedef boost::shared_ptr<GetRosterRequest> ref;
- static ref create(IQRouter* router) {
- return ref(new GetRosterRequest(router));
- }
+ static ref create(IQRouter* router) {
+ return ref(new GetRosterRequest(router));
+ }
- static ref create(IQRouter* router, const std::string& version) {
- ref result(new GetRosterRequest(router));
- result->getPayloadGeneric()->setVersion(version);
- return result;
- }
+ static ref create(IQRouter* router, const std::string& version) {
+ ref result(new GetRosterRequest(router));
+ result->getPayloadGeneric()->setVersion(version);
+ return result;
+ }
- private:
- GetRosterRequest(IQRouter* router) :
- GenericRequest<RosterPayload>(IQ::Get, JID(), boost::shared_ptr<Payload>(new RosterPayload()), router) {
- }
- };
+ private:
+ GetRosterRequest(IQRouter* router) :
+ GenericRequest<RosterPayload>(IQ::Get, JID(), boost::shared_ptr<Payload>(new RosterPayload()), router) {
+ }
+ };
}
diff --git a/Swiften/Roster/RosterMemoryStorage.cpp b/Swiften/Roster/RosterMemoryStorage.cpp
index abaac5e..f187116 100644
--- a/Swiften/Roster/RosterMemoryStorage.cpp
+++ b/Swiften/Roster/RosterMemoryStorage.cpp
@@ -14,10 +14,10 @@ RosterMemoryStorage::RosterMemoryStorage() {
}
void RosterMemoryStorage::setRoster(boost::shared_ptr<RosterPayload> r) {
- roster.reset();
- if (r) {
- roster = boost::make_shared<RosterPayload>(*r);
- }
+ roster.reset();
+ if (r) {
+ roster = boost::make_shared<RosterPayload>(*r);
+ }
}
}
diff --git a/Swiften/Roster/RosterMemoryStorage.h b/Swiften/Roster/RosterMemoryStorage.h
index 9e1ca76..4058f84 100644
--- a/Swiften/Roster/RosterMemoryStorage.h
+++ b/Swiften/Roster/RosterMemoryStorage.h
@@ -10,17 +10,17 @@
#include <Swiften/Roster/RosterStorage.h>
namespace Swift {
- class SWIFTEN_API RosterMemoryStorage : public RosterStorage {
- public:
- RosterMemoryStorage();
+ class SWIFTEN_API RosterMemoryStorage : public RosterStorage {
+ public:
+ RosterMemoryStorage();
- virtual boost::shared_ptr<RosterPayload> getRoster() const {
- return roster;
- }
+ virtual boost::shared_ptr<RosterPayload> getRoster() const {
+ return roster;
+ }
- virtual void setRoster(boost::shared_ptr<RosterPayload>);
+ virtual void setRoster(boost::shared_ptr<RosterPayload>);
- private:
- boost::shared_ptr<RosterPayload> roster;
- };
+ private:
+ boost::shared_ptr<RosterPayload> roster;
+ };
}
diff --git a/Swiften/Roster/RosterPushResponder.h b/Swiften/Roster/RosterPushResponder.h
index 1e99bea..06ba797 100644
--- a/Swiften/Roster/RosterPushResponder.h
+++ b/Swiften/Roster/RosterPushResponder.h
@@ -12,23 +12,23 @@
#include <Swiften/Queries/SetResponder.h>
namespace Swift {
- class SWIFTEN_API RosterPushResponder : public SetResponder<RosterPayload> {
- public:
- RosterPushResponder(IQRouter* router) : SetResponder<RosterPayload>(router) {}
+ class SWIFTEN_API RosterPushResponder : public SetResponder<RosterPayload> {
+ public:
+ RosterPushResponder(IQRouter* router) : SetResponder<RosterPayload>(router) {}
- public:
- boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterReceived;
+ public:
+ boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterReceived;
- private:
- virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<RosterPayload> payload) {
- if (getIQRouter()->isAccountJID(from)) {
- onRosterReceived(payload);
- sendResponse(from, id, boost::shared_ptr<RosterPayload>());
- }
- else {
- sendError(from, id, ErrorPayload::NotAuthorized, ErrorPayload::Cancel);
- }
- return true;
- }
- };
+ private:
+ virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<RosterPayload> payload) {
+ if (getIQRouter()->isAccountJID(from)) {
+ onRosterReceived(payload);
+ sendResponse(from, id, boost::shared_ptr<RosterPayload>());
+ }
+ else {
+ sendError(from, id, ErrorPayload::NotAuthorized, ErrorPayload::Cancel);
+ }
+ return true;
+ }
+ };
}
diff --git a/Swiften/Roster/RosterStorage.h b/Swiften/Roster/RosterStorage.h
index c7e92d2..92c40f9 100644
--- a/Swiften/Roster/RosterStorage.h
+++ b/Swiften/Roster/RosterStorage.h
@@ -12,11 +12,11 @@
#include <Swiften/Elements/RosterPayload.h>
namespace Swift {
- class SWIFTEN_API RosterStorage {
- public:
- virtual ~RosterStorage();
+ class SWIFTEN_API RosterStorage {
+ public:
+ virtual ~RosterStorage();
- virtual boost::shared_ptr<RosterPayload> getRoster() const = 0;
- virtual void setRoster(boost::shared_ptr<RosterPayload>) = 0;
- };
+ virtual boost::shared_ptr<RosterPayload> getRoster() const = 0;
+ virtual void setRoster(boost::shared_ptr<RosterPayload>) = 0;
+ };
}
diff --git a/Swiften/Roster/SetRosterRequest.h b/Swiften/Roster/SetRosterRequest.h
index 4d89836..64c0984 100644
--- a/Swiften/Roster/SetRosterRequest.h
+++ b/Swiften/Roster/SetRosterRequest.h
@@ -14,27 +14,27 @@
#include <Swiften/Queries/Request.h>
namespace Swift {
- class SWIFTEN_API SetRosterRequest : public Request {
- public:
- typedef boost::shared_ptr<SetRosterRequest> ref;
+ class SWIFTEN_API SetRosterRequest : public Request {
+ public:
+ typedef boost::shared_ptr<SetRosterRequest> ref;
- static ref create(RosterPayload::ref payload, IQRouter* router) {
- return ref(new SetRosterRequest(JID(), payload, router));
- }
+ static ref create(RosterPayload::ref payload, IQRouter* router) {
+ return ref(new SetRosterRequest(JID(), payload, router));
+ }
- static ref create(RosterPayload::ref payload, const JID& to, IQRouter* router) {
- return ref(new SetRosterRequest(to, payload, router));
- }
+ static ref create(RosterPayload::ref payload, const JID& to, IQRouter* router) {
+ return ref(new SetRosterRequest(to, payload, router));
+ }
- private:
- SetRosterRequest(const JID& to, boost::shared_ptr<RosterPayload> payload, IQRouter* router) : Request(IQ::Set, to, boost::shared_ptr<RosterPayload>(payload), router) {
- }
+ private:
+ SetRosterRequest(const JID& to, boost::shared_ptr<RosterPayload> payload, IQRouter* router) : Request(IQ::Set, to, boost::shared_ptr<RosterPayload>(payload), router) {
+ }
- virtual void handleResponse(boost::shared_ptr<Payload> /*payload*/, ErrorPayload::ref error) {
- onResponse(error);
- }
+ virtual void handleResponse(boost::shared_ptr<Payload> /*payload*/, ErrorPayload::ref error) {
+ onResponse(error);
+ }
- public:
- boost::signal<void (ErrorPayload::ref)> onResponse;
- };
+ public:
+ boost::signal<void (ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp
index 3e2f85e..6850c21 100644
--- a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp
+++ b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp
@@ -22,340 +22,340 @@
using namespace Swift;
class XMPPRosterControllerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(XMPPRosterControllerTest);
- CPPUNIT_TEST(testGet_Response);
- CPPUNIT_TEST(testGet_EmptyResponse);
- CPPUNIT_TEST(testGet_NoRosterInStorage);
- CPPUNIT_TEST(testGet_NoVersionInStorage);
- CPPUNIT_TEST(testGet_VersionInStorage);
- CPPUNIT_TEST(testGet_ServerDoesNotSupportVersion);
- CPPUNIT_TEST(testGet_ResponseWithoutNewVersion);
- CPPUNIT_TEST(testGet_ResponseWithNewVersion);
- CPPUNIT_TEST(testAdd);
- CPPUNIT_TEST(testAddFromNonAccount);
- CPPUNIT_TEST(testModify);
- CPPUNIT_TEST(testRemove);
- CPPUNIT_TEST(testRemove_RosterStorageUpdated);
- CPPUNIT_TEST(testMany);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- channel_ = new DummyStanzaChannel();
- router_ = new IQRouter(channel_);
- router_->setJID("me@bla.com");
- xmppRoster_ = new XMPPRosterImpl();
- handler_ = new XMPPRosterSignalHandler(xmppRoster_);
- rosterStorage_ = new RosterMemoryStorage();
- jid1_ = JID("foo@bar.com");
- jid2_ = JID("alice@wonderland.lit");
- jid3_ = JID("jane@austen.lit");
- }
-
- void tearDown() {
- delete rosterStorage_;
- delete handler_;
- delete xmppRoster_;
- delete router_;
- delete channel_;
- }
-
- void testGet_Response() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
-
- testling->requestRoster();
- boost::shared_ptr<RosterPayload> payload = boost::make_shared<RosterPayload>();
- payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- payload->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), payload));
-
- CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_));
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
- }
-
- void testGet_EmptyResponse() {
- XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
-
- controller.requestRoster();
-
- channel_->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
- }
-
- void testAdd() {
- XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
-
- boost::shared_ptr<RosterPayload> payload(new RosterPayload());
- payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "eou", payload));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), xmppRoster_->getGroupsForJID(jid1_).size());
- CPPUNIT_ASSERT(xmppRoster_->containsJID(jid1_));
- CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(jid1_));
- }
-
- void testGet_NoRosterInStorage() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
-
- testling->requestRoster();
-
- boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT(roster->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion());
- }
-
- void testGet_NoVersionInStorage() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
- rosterStorage_->setRoster(boost::make_shared<RosterPayload>());
-
- testling->requestRoster();
-
- boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT(roster->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion());
- }
-
- void testGet_VersionInStorage() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
- boost::shared_ptr<RosterPayload> payload(new RosterPayload());
- payload->setVersion("foover");
- rosterStorage_->setRoster(payload);
-
- testling->requestRoster();
-
- boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT(roster->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string("foover"), *roster->getVersion());
- }
-
- void testGet_ServerDoesNotSupportVersion() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- boost::shared_ptr<RosterPayload> payload(new RosterPayload());
- payload->setVersion("foover");
- rosterStorage_->setRoster(payload);
-
- testling->requestRoster();
-
- boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT(!roster->getVersion());
- }
-
- void testGet_ResponseWithoutNewVersion() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
- boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
- storedRoster->setVersion("version10");
- storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
- rosterStorage_->setRoster(storedRoster);
- testling->requestRoster();
-
- channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
-
- CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_));
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
- CPPUNIT_ASSERT(rosterStorage_->getRoster());
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string("version10"), *rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid1_));
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
- }
-
- void testGet_ResponseWithNewVersion() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
- boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
- storedRoster->setVersion("version10");
- storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- rosterStorage_->setRoster(storedRoster);
- testling->requestRoster();
-
- boost::shared_ptr<RosterPayload> serverRoster(new RosterPayload());
- serverRoster->setVersion("version12");
- serverRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
- std::vector<std::string> groups;
- groups.push_back("foo");
- groups.push_back("bar");
- serverRoster->addItem(RosterItemPayload(jid3_, "Rabbit", RosterItemPayload::Both, groups));
- channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), serverRoster));
-
-
- CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
- CPPUNIT_ASSERT(!xmppRoster_->getItem(jid1_));
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
- CPPUNIT_ASSERT(xmppRoster_->getItem(jid3_));
- CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT(rosterStorage_->getRoster());
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string("version12"), *rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_));
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid3_));
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterStorage_->getRoster()->getItem(jid3_)->getGroups().size()));
- }
-
- void testAddFromNonAccount() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
-
- boost::shared_ptr<RosterPayload> payload(new RosterPayload());
- payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- IQ::ref request = IQ::createRequest(IQ::Set, JID(), "eou", payload);
- request->setFrom(jid2_);
- channel_->onIQReceived(request);
-
- CPPUNIT_ASSERT_EQUAL(None, handler_->getLastEvent());
- }
-
- void testModify() {
- XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
- boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
- payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
- payload2->addItem(RosterItemPayload(jid1_, "Bob2", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
-
- CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
-
- CPPUNIT_ASSERT_EQUAL(std::string("Bob2"), xmppRoster_->getNameForJID(jid1_));
- }
-
- void testRemove() {
- XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
- boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
- payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
- payload2->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
- CPPUNIT_ASSERT(!xmppRoster_->containsJID(jid1_));
- CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
-
- }
-
- void testRemove_RosterStorageUpdated() {
- boost::shared_ptr<XMPPRosterController> testling(createController());
- testling->setUseVersioning(true);
- boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
- storedRoster->setVersion("version10");
- storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
- rosterStorage_->setRoster(storedRoster);
- testling->requestRoster();
- channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
-
- boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
- payload2->setVersion("version15");
- payload2->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
-
- CPPUNIT_ASSERT(rosterStorage_->getRoster());
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT_EQUAL(std::string("version15"), *rosterStorage_->getRoster()->getVersion());
- CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_));
- CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
- }
-
- void testMany() {
- XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
- boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
- payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
- payload2->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload3(new RosterPayload());
- payload3->addItem(RosterItemPayload(jid1_, "Ernie", RosterItemPayload::Both));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id3", payload3));
-
- CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload4(new RosterPayload());
- RosterItemPayload item(jid3_, "Jane", RosterItemPayload::Both);
- std::string janesGroup("Jane's Group");
- item.addGroup(janesGroup);
- payload4->addItem(item);
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id4", payload4));
-
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid3_).size());
- CPPUNIT_ASSERT_EQUAL(janesGroup, xmppRoster_->getGroupsForJID(jid3_)[0]);
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload5(new RosterPayload());
- payload5->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id5", payload5));
- CPPUNIT_ASSERT(!xmppRoster_->containsJID(jid1_));
- CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
-
- boost::shared_ptr<RosterPayload> payload6(new RosterPayload());
- RosterItemPayload item2(jid2_, "Little Alice", RosterItemPayload::Both);
- std::string alicesGroup("Alice's Group");
- item2.addGroup(alicesGroup);
- payload6->addItem(item2);
- channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id6", payload6));
- CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("Little Alice"), xmppRoster_->getNameForJID(jid2_));
- CPPUNIT_ASSERT_EQUAL(std::string("Jane"), xmppRoster_->getNameForJID(jid3_));
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid2_).size());
- CPPUNIT_ASSERT_EQUAL(alicesGroup, xmppRoster_->getGroupsForJID(jid2_)[0]);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid3_).size());
- CPPUNIT_ASSERT_EQUAL(janesGroup, xmppRoster_->getGroupsForJID(jid3_)[0]);
- handler_->reset();
-
- }
-
- private:
- XMPPRosterController* createController() {
- return new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
- }
-
- private:
- DummyStanzaChannel* channel_;
- IQRouter* router_;
- XMPPRosterImpl* xmppRoster_;
- XMPPRosterSignalHandler* handler_;
- RosterMemoryStorage* rosterStorage_;
- JID jid1_;
- JID jid2_;
- JID jid3_;
+ CPPUNIT_TEST_SUITE(XMPPRosterControllerTest);
+ CPPUNIT_TEST(testGet_Response);
+ CPPUNIT_TEST(testGet_EmptyResponse);
+ CPPUNIT_TEST(testGet_NoRosterInStorage);
+ CPPUNIT_TEST(testGet_NoVersionInStorage);
+ CPPUNIT_TEST(testGet_VersionInStorage);
+ CPPUNIT_TEST(testGet_ServerDoesNotSupportVersion);
+ CPPUNIT_TEST(testGet_ResponseWithoutNewVersion);
+ CPPUNIT_TEST(testGet_ResponseWithNewVersion);
+ CPPUNIT_TEST(testAdd);
+ CPPUNIT_TEST(testAddFromNonAccount);
+ CPPUNIT_TEST(testModify);
+ CPPUNIT_TEST(testRemove);
+ CPPUNIT_TEST(testRemove_RosterStorageUpdated);
+ CPPUNIT_TEST(testMany);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ channel_ = new DummyStanzaChannel();
+ router_ = new IQRouter(channel_);
+ router_->setJID("me@bla.com");
+ xmppRoster_ = new XMPPRosterImpl();
+ handler_ = new XMPPRosterSignalHandler(xmppRoster_);
+ rosterStorage_ = new RosterMemoryStorage();
+ jid1_ = JID("foo@bar.com");
+ jid2_ = JID("alice@wonderland.lit");
+ jid3_ = JID("jane@austen.lit");
+ }
+
+ void tearDown() {
+ delete rosterStorage_;
+ delete handler_;
+ delete xmppRoster_;
+ delete router_;
+ delete channel_;
+ }
+
+ void testGet_Response() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+
+ testling->requestRoster();
+ boost::shared_ptr<RosterPayload> payload = boost::make_shared<RosterPayload>();
+ payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ payload->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), payload));
+
+ CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_));
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
+ }
+
+ void testGet_EmptyResponse() {
+ XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
+
+ controller.requestRoster();
+
+ channel_->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
+ }
+
+ void testAdd() {
+ XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
+
+ boost::shared_ptr<RosterPayload> payload(new RosterPayload());
+ payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "eou", payload));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), xmppRoster_->getGroupsForJID(jid1_).size());
+ CPPUNIT_ASSERT(xmppRoster_->containsJID(jid1_));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(jid1_));
+ }
+
+ void testGet_NoRosterInStorage() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+
+ testling->requestRoster();
+
+ boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT(roster->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion());
+ }
+
+ void testGet_NoVersionInStorage() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+ rosterStorage_->setRoster(boost::make_shared<RosterPayload>());
+
+ testling->requestRoster();
+
+ boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT(roster->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), *roster->getVersion());
+ }
+
+ void testGet_VersionInStorage() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+ boost::shared_ptr<RosterPayload> payload(new RosterPayload());
+ payload->setVersion("foover");
+ rosterStorage_->setRoster(payload);
+
+ testling->requestRoster();
+
+ boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT(roster->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string("foover"), *roster->getVersion());
+ }
+
+ void testGet_ServerDoesNotSupportVersion() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ boost::shared_ptr<RosterPayload> payload(new RosterPayload());
+ payload->setVersion("foover");
+ rosterStorage_->setRoster(payload);
+
+ testling->requestRoster();
+
+ boost::shared_ptr<RosterPayload> roster = channel_->sentStanzas[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT(!roster->getVersion());
+ }
+
+ void testGet_ResponseWithoutNewVersion() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+ boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
+ storedRoster->setVersion("version10");
+ storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
+ rosterStorage_->setRoster(storedRoster);
+ testling->requestRoster();
+
+ channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
+
+ CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid1_));
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string("version10"), *rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid1_));
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
+ }
+
+ void testGet_ResponseWithNewVersion() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+ boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
+ storedRoster->setVersion("version10");
+ storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ rosterStorage_->setRoster(storedRoster);
+ testling->requestRoster();
+
+ boost::shared_ptr<RosterPayload> serverRoster(new RosterPayload());
+ serverRoster->setVersion("version12");
+ serverRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
+ std::vector<std::string> groups;
+ groups.push_back("foo");
+ groups.push_back("bar");
+ serverRoster->addItem(RosterItemPayload(jid3_, "Rabbit", RosterItemPayload::Both, groups));
+ channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), serverRoster));
+
+
+ CPPUNIT_ASSERT_EQUAL(2, handler_->getEventCount());
+ CPPUNIT_ASSERT(!xmppRoster_->getItem(jid1_));
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid2_));
+ CPPUNIT_ASSERT(xmppRoster_->getItem(jid3_));
+ CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string("version12"), *rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_));
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid3_));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterStorage_->getRoster()->getItem(jid3_)->getGroups().size()));
+ }
+
+ void testAddFromNonAccount() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+
+ boost::shared_ptr<RosterPayload> payload(new RosterPayload());
+ payload->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ IQ::ref request = IQ::createRequest(IQ::Set, JID(), "eou", payload);
+ request->setFrom(jid2_);
+ channel_->onIQReceived(request);
+
+ CPPUNIT_ASSERT_EQUAL(None, handler_->getLastEvent());
+ }
+
+ void testModify() {
+ XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
+ boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
+ payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
+ payload2->addItem(RosterItemPayload(jid1_, "Bob2", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
+
+ CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+
+ CPPUNIT_ASSERT_EQUAL(std::string("Bob2"), xmppRoster_->getNameForJID(jid1_));
+ }
+
+ void testRemove() {
+ XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
+ boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
+ payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
+ payload2->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
+ CPPUNIT_ASSERT(!xmppRoster_->containsJID(jid1_));
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+
+ }
+
+ void testRemove_RosterStorageUpdated() {
+ boost::shared_ptr<XMPPRosterController> testling(createController());
+ testling->setUseVersioning(true);
+ boost::shared_ptr<RosterPayload> storedRoster(new RosterPayload());
+ storedRoster->setVersion("version10");
+ storedRoster->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ storedRoster->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
+ rosterStorage_->setRoster(storedRoster);
+ testling->requestRoster();
+ channel_->onIQReceived(IQ::createResult("foo@bar.com", channel_->sentStanzas[0]->getID(), boost::shared_ptr<RosterPayload>()));
+
+ boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
+ payload2->setVersion("version15");
+ payload2->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
+
+ CPPUNIT_ASSERT(rosterStorage_->getRoster());
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT_EQUAL(std::string("version15"), *rosterStorage_->getRoster()->getVersion());
+ CPPUNIT_ASSERT(!rosterStorage_->getRoster()->getItem(jid1_));
+ CPPUNIT_ASSERT(rosterStorage_->getRoster()->getItem(jid2_));
+ }
+
+ void testMany() {
+ XMPPRosterController controller(router_, xmppRoster_, rosterStorage_);
+ boost::shared_ptr<RosterPayload> payload1(new RosterPayload());
+ payload1->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload2(new RosterPayload());
+ payload2->addItem(RosterItemPayload(jid2_, "Alice", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload3(new RosterPayload());
+ payload3->addItem(RosterItemPayload(jid1_, "Ernie", RosterItemPayload::Both));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id3", payload3));
+
+ CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload4(new RosterPayload());
+ RosterItemPayload item(jid3_, "Jane", RosterItemPayload::Both);
+ std::string janesGroup("Jane's Group");
+ item.addGroup(janesGroup);
+ payload4->addItem(item);
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id4", payload4));
+
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid3_).size());
+ CPPUNIT_ASSERT_EQUAL(janesGroup, xmppRoster_->getGroupsForJID(jid3_)[0]);
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload5(new RosterPayload());
+ payload5->addItem(RosterItemPayload(jid1_, "Bob", RosterItemPayload::Remove));
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id5", payload5));
+ CPPUNIT_ASSERT(!xmppRoster_->containsJID(jid1_));
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+
+ boost::shared_ptr<RosterPayload> payload6(new RosterPayload());
+ RosterItemPayload item2(jid2_, "Little Alice", RosterItemPayload::Both);
+ std::string alicesGroup("Alice's Group");
+ item2.addGroup(alicesGroup);
+ payload6->addItem(item2);
+ channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id6", payload6));
+ CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("Little Alice"), xmppRoster_->getNameForJID(jid2_));
+ CPPUNIT_ASSERT_EQUAL(std::string("Jane"), xmppRoster_->getNameForJID(jid3_));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid2_).size());
+ CPPUNIT_ASSERT_EQUAL(alicesGroup, xmppRoster_->getGroupsForJID(jid2_)[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xmppRoster_->getGroupsForJID(jid3_).size());
+ CPPUNIT_ASSERT_EQUAL(janesGroup, xmppRoster_->getGroupsForJID(jid3_)[0]);
+ handler_->reset();
+
+ }
+
+ private:
+ XMPPRosterController* createController() {
+ return new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+ }
+
+ private:
+ DummyStanzaChannel* channel_;
+ IQRouter* router_;
+ XMPPRosterImpl* xmppRoster_;
+ XMPPRosterSignalHandler* handler_;
+ RosterMemoryStorage* rosterStorage_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterControllerTest);
diff --git a/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp
index d485596..f611fec 100644
--- a/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp
+++ b/Swiften/Roster/UnitTest/XMPPRosterImplTest.cpp
@@ -18,95 +18,95 @@ using namespace Swift;
class XMPPRosterImplTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(XMPPRosterImplTest);
- CPPUNIT_TEST(testJIDAdded);
- CPPUNIT_TEST(testJIDRemoved);
- CPPUNIT_TEST(testJIDUpdated);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(XMPPRosterImplTest);
+ CPPUNIT_TEST(testJIDAdded);
+ CPPUNIT_TEST(testJIDRemoved);
+ CPPUNIT_TEST(testJIDUpdated);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void setUp() {
- jid1_ = JID("a@b.c");
- jid2_ = JID("b@c.d");
- jid3_ = JID("c@d.e");
- roster_ = new XMPPRosterImpl();
- handler_ = new XMPPRosterSignalHandler(roster_);
- groups1_.push_back("bobs");
- groups1_.push_back("berts");
- groups2_.push_back("ernies");
- }
+ public:
+ void setUp() {
+ jid1_ = JID("a@b.c");
+ jid2_ = JID("b@c.d");
+ jid3_ = JID("c@d.e");
+ roster_ = new XMPPRosterImpl();
+ handler_ = new XMPPRosterSignalHandler(roster_);
+ groups1_.push_back("bobs");
+ groups1_.push_back("berts");
+ groups2_.push_back("ernies");
+ }
- void tearDown() {
- delete handler_;
- delete roster_;
- }
+ void tearDown() {
+ delete handler_;
+ delete roster_;
+ }
- void testJIDAdded() {
- roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
- CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
- handler_->reset();
- roster_->addContact(jid2_, "NameTwo", groups1_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NameTwo"), roster_->getNameForJID(jid2_));
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
- CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid2_));
- CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
- handler_->reset();
- roster_->addContact(jid3_, "NewName", groups2_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid3_));
- CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid3_));
- }
+ void testJIDAdded() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid2_, "NameTwo", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NameTwo"), roster_->getNameForJID(jid2_));
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid2_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid3_, "NewName", groups2_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid3_));
+ CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid3_));
+ }
- void testJIDRemoved() {
- roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
- handler_->reset();
- roster_->removeContact(jid1_);
- CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- handler_->reset();
- roster_->addContact(jid1_, "NewName2", groups1_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NewName2"), roster_->getNameForJID(jid1_));
- roster_->addContact(jid2_, "NewName3", groups1_, RosterItemPayload::Both);
- handler_->reset();
- roster_->removeContact(jid2_);
- CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
- handler_->reset();
- roster_->removeContact(jid1_);
- CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- }
+ void testJIDRemoved() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ handler_->reset();
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+ roster_->addContact(jid1_, "NewName2", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName2"), roster_->getNameForJID(jid1_));
+ roster_->addContact(jid2_, "NewName3", groups1_, RosterItemPayload::Both);
+ handler_->reset();
+ roster_->removeContact(jid2_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ handler_->reset();
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ }
- void testJIDUpdated() {
- roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
- CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
- handler_->reset();
- roster_->addContact(jid1_, "NameTwo", groups2_, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
- CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
- CPPUNIT_ASSERT_EQUAL(std::string("NameTwo"), roster_->getNameForJID(jid1_));
- CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid1_));
- }
+ void testJIDUpdated() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid1_, "NameTwo", groups2_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("NameTwo"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid1_));
+ }
- private:
- XMPPRosterImpl* roster_;
- XMPPRosterSignalHandler* handler_;
- JID jid1_;
- JID jid2_;
- JID jid3_;
- std::vector<std::string> groups1_;
- std::vector<std::string> groups2_;
+ private:
+ XMPPRosterImpl* roster_;
+ XMPPRosterSignalHandler* handler_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
+ std::vector<std::string> groups1_;
+ std::vector<std::string> groups2_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterImplTest);
diff --git a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp
index 102e31b..add34a0 100644
--- a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp
+++ b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.cpp
@@ -13,17 +13,17 @@
using namespace Swift;
XMPPRosterSignalHandler::XMPPRosterSignalHandler(Swift::XMPPRoster* roster) : eventCount(0) {
- lastEvent_ = None;
- roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1));
- roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1));
- roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3));
+ lastEvent_ = None;
+ roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1));
+ roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1));
+ roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3));
}
void XMPPRosterSignalHandler::handleJIDUpdated(const Swift::JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups) {
- assert(lastEvent_ == None);
- lastJID_ = jid;
- lastOldName_ = oldName;
- lastOldGroups_ = oldGroups;
- lastEvent_ = Update;
- eventCount++;
+ assert(lastEvent_ == None);
+ lastJID_ = jid;
+ lastOldName_ = oldName;
+ lastOldGroups_ = oldGroups;
+ lastEvent_ = Update;
+ eventCount++;
}
diff --git a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
index d2beecf..9c9afad 100644
--- a/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
+++ b/Swiften/Roster/UnitTest/XMPPRosterSignalHandler.h
@@ -16,50 +16,50 @@ enum XMPPRosterEvents {None, Add, Remove, Update};
class XMPPRosterSignalHandler {
public:
- XMPPRosterSignalHandler(Swift::XMPPRoster* roster);
+ XMPPRosterSignalHandler(Swift::XMPPRoster* roster);
- XMPPRosterEvents getLastEvent() {
- return lastEvent_;
- }
+ XMPPRosterEvents getLastEvent() {
+ return lastEvent_;
+ }
- Swift::JID getLastJID() {
- return lastJID_;
- }
+ Swift::JID getLastJID() {
+ return lastJID_;
+ }
- std::string getLastOldName() {
- return lastOldName_;
- }
+ std::string getLastOldName() {
+ return lastOldName_;
+ }
- std::vector<std::string> getLastOldGroups() {
- return lastOldGroups_;
- }
+ std::vector<std::string> getLastOldGroups() {
+ return lastOldGroups_;
+ }
- void reset() {
- lastEvent_ = None;
- }
+ void reset() {
+ lastEvent_ = None;
+ }
- int getEventCount() const {
- return eventCount;
- }
+ int getEventCount() const {
+ return eventCount;
+ }
private:
- void handleJIDAdded(const Swift::JID& jid) {
- lastJID_ = jid;
- lastEvent_ = Add;
- eventCount++;
- }
-
- void handleJIDRemoved(const Swift::JID& jid) {
- lastJID_ = jid;
- lastEvent_ = Remove;
- eventCount++;
- }
-
- void handleJIDUpdated(const Swift::JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups);
-
- XMPPRosterEvents lastEvent_;
- Swift::JID lastJID_;
- std::string lastOldName_;
- std::vector<std::string> lastOldGroups_;
- int eventCount;
+ void handleJIDAdded(const Swift::JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Add;
+ eventCount++;
+ }
+
+ void handleJIDRemoved(const Swift::JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Remove;
+ eventCount++;
+ }
+
+ void handleJIDUpdated(const Swift::JID& jid, const std::string& oldName, const std::vector<std::string>& oldGroups);
+
+ XMPPRosterEvents lastEvent_;
+ Swift::JID lastJID_;
+ std::string lastOldName_;
+ std::vector<std::string> lastOldGroups_;
+ int eventCount;
};
diff --git a/Swiften/Roster/XMPPRoster.h b/Swiften/Roster/XMPPRoster.h
index fdd1f9a..5e3a6b1 100644
--- a/Swiften/Roster/XMPPRoster.h
+++ b/Swiften/Roster/XMPPRoster.h
@@ -19,80 +19,80 @@
#include <Swiften/Roster/XMPPRosterItem.h>
namespace Swift {
- /**
- * This class represents the roster of an account, as stored on the XMPP server.
- *
- * Changes to the roster (either due to subscription requests or by going online/offline) are
- * emitted through signals.
- */
- class SWIFTEN_API XMPPRoster {
- public:
- XMPPRoster();
- virtual ~XMPPRoster();
-
- /**
- * Checks whether the bare jid of the given jid is in the roster.
- */
- virtual bool containsJID(const JID& jid) = 0;
-
- /**
- * Retrieves the subscription state for the given jid.
- */
- virtual RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid) = 0;
-
- /**
- * Retrieves the stored roster name for the given jid.
- */
- virtual std::string getNameForJID(const JID& jid) const = 0;
-
- /**
- * Returns the list of groups for the given JID.
- */
- virtual std::vector<std::string> getGroupsForJID(const JID& jid) = 0;
-
- /**
- * Retrieve the items in the roster.
- */
- virtual std::vector<XMPPRosterItem> getItems() const = 0;
-
- /**
- * Retrieve the item with the given JID.
- */
- virtual boost::optional<XMPPRosterItem> getItem(const JID&) const = 0;
-
- /**
- * Retrieve the list of (existing) groups.
- */
- virtual std::set<std::string> getGroups() const = 0;
-
- public:
- /**
- * Emitted when the given JID is added to the roster.
- */
- boost::signal<void (const JID&)> onJIDAdded;
-
- /**
- * Emitted when the given JID is removed from the roster.
- */
- boost::signal<void (const JID&)> onJIDRemoved;
-
- /**
- * Emitted when the name or the groups of the roster item with the
- * given JID changes.
- */
- boost::signal<void (const JID&, const std::string&, const std::vector<std::string>&)> onJIDUpdated;
-
- /**
- * Emitted when the roster is reset (e.g. due to logging in/logging out).
- * After this signal is emitted, the roster is empty. It will be repopulated through
- * onJIDAdded and onJIDRemoved events.
- */
- boost::signal<void ()> onRosterCleared;
-
- /**
- * Emitted after the last contact of the initial roster request response
- * was added.
- */
- boost::signal<void ()> onInitialRosterPopulated;
- };
+ /**
+ * This class represents the roster of an account, as stored on the XMPP server.
+ *
+ * Changes to the roster (either due to subscription requests or by going online/offline) are
+ * emitted through signals.
+ */
+ class SWIFTEN_API XMPPRoster {
+ public:
+ XMPPRoster();
+ virtual ~XMPPRoster();
+
+ /**
+ * Checks whether the bare jid of the given jid is in the roster.
+ */
+ virtual bool containsJID(const JID& jid) = 0;
+
+ /**
+ * Retrieves the subscription state for the given jid.
+ */
+ virtual RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid) = 0;
+
+ /**
+ * Retrieves the stored roster name for the given jid.
+ */
+ virtual std::string getNameForJID(const JID& jid) const = 0;
+
+ /**
+ * Returns the list of groups for the given JID.
+ */
+ virtual std::vector<std::string> getGroupsForJID(const JID& jid) = 0;
+
+ /**
+ * Retrieve the items in the roster.
+ */
+ virtual std::vector<XMPPRosterItem> getItems() const = 0;
+
+ /**
+ * Retrieve the item with the given JID.
+ */
+ virtual boost::optional<XMPPRosterItem> getItem(const JID&) const = 0;
+
+ /**
+ * Retrieve the list of (existing) groups.
+ */
+ virtual std::set<std::string> getGroups() const = 0;
+
+ public:
+ /**
+ * Emitted when the given JID is added to the roster.
+ */
+ boost::signal<void (const JID&)> onJIDAdded;
+
+ /**
+ * Emitted when the given JID is removed from the roster.
+ */
+ boost::signal<void (const JID&)> onJIDRemoved;
+
+ /**
+ * Emitted when the name or the groups of the roster item with the
+ * given JID changes.
+ */
+ boost::signal<void (const JID&, const std::string&, const std::vector<std::string>&)> onJIDUpdated;
+
+ /**
+ * Emitted when the roster is reset (e.g. due to logging in/logging out).
+ * After this signal is emitted, the roster is empty. It will be repopulated through
+ * onJIDAdded and onJIDRemoved events.
+ */
+ boost::signal<void ()> onRosterCleared;
+
+ /**
+ * Emitted after the last contact of the initial roster request response
+ * was added.
+ */
+ boost::signal<void ()> onInitialRosterPopulated;
+ };
}
diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp
index 359e2ce..10803f3 100644
--- a/Swiften/Roster/XMPPRosterController.cpp
+++ b/Swiften/Roster/XMPPRosterController.cpp
@@ -18,76 +18,76 @@
#include <Swiften/Roster/XMPPRosterImpl.h>
namespace Swift {
-
+
/**
* The controller does not gain ownership of these parameters.
*/
XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, XMPPRosterImpl* xmppRoster, RosterStorage* rosterStorage) : iqRouter_(iqRouter), rosterPushResponder_(iqRouter), xmppRoster_(xmppRoster), rosterStorage_(rosterStorage), useVersioning(false) {
- rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, false, boost::shared_ptr<RosterPayload>()));
- rosterPushResponder_.start();
+ rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, false, boost::shared_ptr<RosterPayload>()));
+ rosterPushResponder_.start();
}
XMPPRosterController::~XMPPRosterController() {
- rosterPushResponder_.stop();
+ rosterPushResponder_.stop();
}
void XMPPRosterController::requestRoster() {
- xmppRoster_->clear();
+ xmppRoster_->clear();
- boost::shared_ptr<RosterPayload> storedRoster = rosterStorage_->getRoster();
- GetRosterRequest::ref rosterRequest;
- if (useVersioning) {
- std::string version = "";
- if (storedRoster && storedRoster->getVersion()) {
- version = *storedRoster->getVersion();
- }
- rosterRequest = GetRosterRequest::create(iqRouter_, version);
- }
- else {
- rosterRequest = GetRosterRequest::create(iqRouter_);
- }
- rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, true, storedRoster));
- rosterRequest->send();
+ boost::shared_ptr<RosterPayload> storedRoster = rosterStorage_->getRoster();
+ GetRosterRequest::ref rosterRequest;
+ if (useVersioning) {
+ std::string version = "";
+ if (storedRoster && storedRoster->getVersion()) {
+ version = *storedRoster->getVersion();
+ }
+ rosterRequest = GetRosterRequest::create(iqRouter_, version);
+ }
+ else {
+ rosterRequest = GetRosterRequest::create(iqRouter_);
+ }
+ rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1, true, storedRoster));
+ rosterRequest->send();
}
void XMPPRosterController::handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial, boost::shared_ptr<RosterPayload> previousRoster) {
- if (rosterPayload) {
- foreach(const RosterItemPayload& item, rosterPayload->getItems()) {
- //Don't worry about the updated case, the XMPPRoster sorts that out.
- if (item.getSubscription() == RosterItemPayload::Remove) {
- xmppRoster_->removeContact(item.getJID());
- } else {
- xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription());
- }
- }
- }
- else if (previousRoster) {
- // The cached version hasn't changed; emit all items
- foreach(const RosterItemPayload& item, previousRoster->getItems()) {
- if (item.getSubscription() != RosterItemPayload::Remove) {
- xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription());
- }
- else {
- std::cerr << "ERROR: Stored invalid roster item" << std::endl;
- }
- }
- }
- if (initial) {
- xmppRoster_->onInitialRosterPopulated();
- }
- if (rosterPayload && rosterPayload->getVersion() && useVersioning) {
- saveRoster(*rosterPayload->getVersion());
- }
+ if (rosterPayload) {
+ foreach(const RosterItemPayload& item, rosterPayload->getItems()) {
+ //Don't worry about the updated case, the XMPPRoster sorts that out.
+ if (item.getSubscription() == RosterItemPayload::Remove) {
+ xmppRoster_->removeContact(item.getJID());
+ } else {
+ xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription());
+ }
+ }
+ }
+ else if (previousRoster) {
+ // The cached version hasn't changed; emit all items
+ foreach(const RosterItemPayload& item, previousRoster->getItems()) {
+ if (item.getSubscription() != RosterItemPayload::Remove) {
+ xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription());
+ }
+ else {
+ std::cerr << "ERROR: Stored invalid roster item" << std::endl;
+ }
+ }
+ }
+ if (initial) {
+ xmppRoster_->onInitialRosterPopulated();
+ }
+ if (rosterPayload && rosterPayload->getVersion() && useVersioning) {
+ saveRoster(*rosterPayload->getVersion());
+ }
}
void XMPPRosterController::saveRoster(const std::string& version) {
- std::vector<XMPPRosterItem> items = xmppRoster_->getItems();
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->setVersion(version);
- foreach(const XMPPRosterItem& item, items) {
- roster->addItem(RosterItemPayload(item.getJID(), item.getName(), item.getSubscription(), item.getGroups()));
- }
- rosterStorage_->setRoster(roster);
+ std::vector<XMPPRosterItem> items = xmppRoster_->getItems();
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->setVersion(version);
+ foreach(const XMPPRosterItem& item, items) {
+ roster->addItem(RosterItemPayload(item.getJID(), item.getName(), item.getSubscription(), item.getGroups()));
+ }
+ rosterStorage_->setRoster(roster);
}
}
diff --git a/Swiften/Roster/XMPPRosterController.h b/Swiften/Roster/XMPPRosterController.h
index a23ed39..d40ba1e 100644
--- a/Swiften/Roster/XMPPRosterController.h
+++ b/Swiften/Roster/XMPPRosterController.h
@@ -18,31 +18,31 @@
#include <Swiften/Roster/RosterPushResponder.h>
namespace Swift {
- class IQRouter;
- class XMPPRosterImpl;
- class RosterStorage;
-
- class SWIFTEN_API XMPPRosterController {
- public:
- XMPPRosterController(IQRouter *iqRouter, XMPPRosterImpl* xmppRoster, RosterStorage* storage);
- ~XMPPRosterController();
-
- void requestRoster();
-
- void setUseVersioning(bool b) {
- useVersioning = b;
- }
-
- private:
- void handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial, boost::shared_ptr<RosterPayload> previousRoster);
- void saveRoster(const std::string& version);
-
- private:
- IQRouter* iqRouter_;
- RosterPushResponder rosterPushResponder_;
- XMPPRosterImpl* xmppRoster_;
- RosterStorage* rosterStorage_;
- bool useVersioning;
- };
+ class IQRouter;
+ class XMPPRosterImpl;
+ class RosterStorage;
+
+ class SWIFTEN_API XMPPRosterController {
+ public:
+ XMPPRosterController(IQRouter *iqRouter, XMPPRosterImpl* xmppRoster, RosterStorage* storage);
+ ~XMPPRosterController();
+
+ void requestRoster();
+
+ void setUseVersioning(bool b) {
+ useVersioning = b;
+ }
+
+ private:
+ void handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload, bool initial, boost::shared_ptr<RosterPayload> previousRoster);
+ void saveRoster(const std::string& version);
+
+ private:
+ IQRouter* iqRouter_;
+ RosterPushResponder rosterPushResponder_;
+ XMPPRosterImpl* xmppRoster_;
+ RosterStorage* rosterStorage_;
+ bool useVersioning;
+ };
}
diff --git a/Swiften/Roster/XMPPRosterImpl.cpp b/Swiften/Roster/XMPPRosterImpl.cpp
index 96b9949..9a2ea7a 100644
--- a/Swiften/Roster/XMPPRosterImpl.cpp
+++ b/Swiften/Roster/XMPPRosterImpl.cpp
@@ -18,89 +18,89 @@ XMPPRosterImpl::~XMPPRosterImpl() {
}
void XMPPRosterImpl::addContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription) {
- JID bareJID(jid.toBare());
- std::map<JID, XMPPRosterItem>::iterator i = entries_.find(bareJID);
- if (i != entries_.end()) {
- std::string oldName = i->second.getName();
- std::vector<std::string> oldGroups = i->second.getGroups();
- i->second = XMPPRosterItem(jid, name, groups, subscription);
- onJIDUpdated(bareJID, oldName, oldGroups);
- }
- else {
- entries_.insert(std::make_pair(bareJID, XMPPRosterItem(jid, name, groups, subscription)));
- onJIDAdded(bareJID);
- }
+ JID bareJID(jid.toBare());
+ std::map<JID, XMPPRosterItem>::iterator i = entries_.find(bareJID);
+ if (i != entries_.end()) {
+ std::string oldName = i->second.getName();
+ std::vector<std::string> oldGroups = i->second.getGroups();
+ i->second = XMPPRosterItem(jid, name, groups, subscription);
+ onJIDUpdated(bareJID, oldName, oldGroups);
+ }
+ else {
+ entries_.insert(std::make_pair(bareJID, XMPPRosterItem(jid, name, groups, subscription)));
+ onJIDAdded(bareJID);
+ }
}
void XMPPRosterImpl::removeContact(const JID& jid) {
- entries_.erase(JID(jid.toBare()));
- onJIDRemoved(jid);
+ entries_.erase(JID(jid.toBare()));
+ onJIDRemoved(jid);
}
void XMPPRosterImpl::clear() {
- entries_.clear();
- onRosterCleared();
+ entries_.clear();
+ onRosterCleared();
}
bool XMPPRosterImpl::containsJID(const JID& jid) {
- return entries_.find(JID(jid.toBare())) != entries_.end();
+ return entries_.find(JID(jid.toBare())) != entries_.end();
}
std::string XMPPRosterImpl::getNameForJID(const JID& jid) const {
- std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare());
- if (i != entries_.end()) {
- return i->second.getName();
- }
- else {
- return "";
- }
+ std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare());
+ if (i != entries_.end()) {
+ return i->second.getName();
+ }
+ else {
+ return "";
+ }
}
std::vector<std::string> XMPPRosterImpl::getGroupsForJID(const JID& jid) {
- std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare());
- if (i != entries_.end()) {
- return i->second.getGroups();
- }
- else {
- return std::vector<std::string>();
- }
+ std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare());
+ if (i != entries_.end()) {
+ return i->second.getGroups();
+ }
+ else {
+ return std::vector<std::string>();
+ }
}
RosterItemPayload::Subscription XMPPRosterImpl::getSubscriptionStateForJID(const JID& jid) {
- std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare());
- if (i != entries_.end()) {
- return i->second.getSubscription();
- }
- else {
- return RosterItemPayload::None;
- }
+ std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare());
+ if (i != entries_.end()) {
+ return i->second.getSubscription();
+ }
+ else {
+ return RosterItemPayload::None;
+ }
}
std::vector<XMPPRosterItem> XMPPRosterImpl::getItems() const {
- std::vector<XMPPRosterItem> result;
- foreach(const RosterMap::value_type& entry, entries_) {
- result.push_back(entry.second);
- }
- return result;
+ std::vector<XMPPRosterItem> result;
+ foreach(const RosterMap::value_type& entry, entries_) {
+ result.push_back(entry.second);
+ }
+ return result;
}
boost::optional<XMPPRosterItem> XMPPRosterImpl::getItem(const JID& jid) const {
- std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare());
- if (i != entries_.end()) {
- return i->second;
- }
- else {
- return boost::optional<XMPPRosterItem>();
- }
+ std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare());
+ if (i != entries_.end()) {
+ return i->second;
+ }
+ else {
+ return boost::optional<XMPPRosterItem>();
+ }
}
std::set<std::string> XMPPRosterImpl::getGroups() const {
- std::set<std::string> result;
- foreach(const RosterMap::value_type& entry, entries_) {
- std::vector<std::string> groups = entry.second.getGroups();
- result.insert(groups.begin(), groups.end());
- }
- return result;
+ std::set<std::string> result;
+ foreach(const RosterMap::value_type& entry, entries_) {
+ std::vector<std::string> groups = entry.second.getGroups();
+ result.insert(groups.begin(), groups.end());
+ }
+ return result;
}
}
diff --git a/Swiften/Roster/XMPPRosterImpl.h b/Swiften/Roster/XMPPRosterImpl.h
index 284b18a..28e3919 100644
--- a/Swiften/Roster/XMPPRosterImpl.h
+++ b/Swiften/Roster/XMPPRosterImpl.h
@@ -13,26 +13,26 @@
#include <Swiften/Roster/XMPPRoster.h>
namespace Swift {
- class SWIFTEN_API XMPPRosterImpl : public XMPPRoster {
- public:
- XMPPRosterImpl();
- virtual ~XMPPRosterImpl();
-
- void addContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription);
- void removeContact(const JID& jid);
- void clear();
-
- bool containsJID(const JID& jid);
- RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid);
- std::string getNameForJID(const JID& jid) const;
- std::vector<std::string> getGroupsForJID(const JID& jid);
-
- virtual std::vector<XMPPRosterItem> getItems() const;
- virtual boost::optional<XMPPRosterItem> getItem(const JID&) const;
- virtual std::set<std::string> getGroups() const;
-
- private:
- typedef std::map<JID, XMPPRosterItem> RosterMap;
- RosterMap entries_;
- };
+ class SWIFTEN_API XMPPRosterImpl : public XMPPRoster {
+ public:
+ XMPPRosterImpl();
+ virtual ~XMPPRosterImpl();
+
+ void addContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription);
+ void removeContact(const JID& jid);
+ void clear();
+
+ bool containsJID(const JID& jid);
+ RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid);
+ std::string getNameForJID(const JID& jid) const;
+ std::vector<std::string> getGroupsForJID(const JID& jid);
+
+ virtual std::vector<XMPPRosterItem> getItems() const;
+ virtual boost::optional<XMPPRosterItem> getItem(const JID&) const;
+ virtual std::set<std::string> getGroups() const;
+
+ private:
+ typedef std::map<JID, XMPPRosterItem> RosterMap;
+ RosterMap entries_;
+ };
}
diff --git a/Swiften/Roster/XMPPRosterItem.h b/Swiften/Roster/XMPPRosterItem.h
index d46a678..53b3781 100644
--- a/Swiften/Roster/XMPPRosterItem.h
+++ b/Swiften/Roster/XMPPRosterItem.h
@@ -14,40 +14,40 @@
#include <Swiften/JID/JID.h>
namespace Swift {
- class SWIFTEN_API XMPPRosterItem {
- public:
- XMPPRosterItem(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription) : jid(jid), name(name), groups(groups), subscription(subscription) {
- }
-
- const JID& getJID() const {
- return jid;
- }
-
- const std::string& getName() const {
- return name;
- }
-
- void setName(const std::string& name) {
- this->name = name;
- }
-
- const std::vector<std::string>& getGroups() const {
- return groups;
- }
-
- void setGroups(const std::vector<std::string>& groups) {
- this->groups = groups;
- }
-
- RosterItemPayload::Subscription getSubscription() const {
- return subscription;
- }
-
- private:
- JID jid;
- std::string name;
- std::vector<std::string> groups;
- RosterItemPayload::Subscription subscription;
- };
+ class SWIFTEN_API XMPPRosterItem {
+ public:
+ XMPPRosterItem(const JID& jid, const std::string& name, const std::vector<std::string>& groups, RosterItemPayload::Subscription subscription) : jid(jid), name(name), groups(groups), subscription(subscription) {
+ }
+
+ const JID& getJID() const {
+ return jid;
+ }
+
+ const std::string& getName() const {
+ return name;
+ }
+
+ void setName(const std::string& name) {
+ this->name = name;
+ }
+
+ const std::vector<std::string>& getGroups() const {
+ return groups;
+ }
+
+ void setGroups(const std::vector<std::string>& groups) {
+ this->groups = groups;
+ }
+
+ RosterItemPayload::Subscription getSubscription() const {
+ return subscription;
+ }
+
+ private:
+ JID jid;
+ std::string name;
+ std::vector<std::string> groups;
+ RosterItemPayload::Subscription subscription;
+ };
}