summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/VCards')
-rw-r--r--Swiften/VCards/GetVCardRequest.h24
-rw-r--r--Swiften/VCards/SConscript6
-rw-r--r--Swiften/VCards/SetVCardRequest.h24
-rw-r--r--Swiften/VCards/UnitTest/VCardManagerTest.cpp370
-rw-r--r--Swiften/VCards/VCardManager.cpp79
-rw-r--r--Swiften/VCards/VCardManager.h81
-rw-r--r--Swiften/VCards/VCardMemoryStorage.h73
-rw-r--r--Swiften/VCards/VCardStorage.cpp18
-rw-r--r--Swiften/VCards/VCardStorage.h30
9 files changed, 356 insertions, 349 deletions
diff --git a/Swiften/VCards/GetVCardRequest.h b/Swiften/VCards/GetVCardRequest.h
index 47c302d..1b575c0 100644
--- a/Swiften/VCards/GetVCardRequest.h
+++ b/Swiften/VCards/GetVCardRequest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,20 +7,20 @@
#pragma once
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/VCard.h>
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetVCardRequest : public GenericRequest<VCard> {
- public:
- typedef boost::shared_ptr<GetVCardRequest> ref;
+ class SWIFTEN_API GetVCardRequest : public GenericRequest<VCard> {
+ public:
+ typedef std::shared_ptr<GetVCardRequest> ref;
- static ref create(const JID& jid, IQRouter* router) {
- return ref(new GetVCardRequest(jid, router));
- }
+ static ref create(const JID& jid, IQRouter* router) {
+ return ref(new GetVCardRequest(jid, router));
+ }
- private:
- GetVCardRequest(const JID& jid, IQRouter* router) : GenericRequest<VCard>(IQ::Get, jid, boost::shared_ptr<Payload>(new VCard()), router) {
- }
- };
+ private:
+ GetVCardRequest(const JID& jid, IQRouter* router) : GenericRequest<VCard>(IQ::Get, jid, std::make_shared<VCard>(), router) {
+ }
+ };
}
diff --git a/Swiften/VCards/SConscript b/Swiften/VCards/SConscript
index c20c17d..d8189cb 100644
--- a/Swiften/VCards/SConscript
+++ b/Swiften/VCards/SConscript
@@ -1,7 +1,7 @@
Import("swiften_env")
objects = swiften_env.SwiftenObject([
- "VCardManager.cpp",
- "VCardStorage.cpp",
- ])
+ "VCardManager.cpp",
+ "VCardStorage.cpp",
+ ])
swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/VCards/SetVCardRequest.h b/Swiften/VCards/SetVCardRequest.h
index d59c3bc..15cc78b 100644
--- a/Swiften/VCards/SetVCardRequest.h
+++ b/Swiften/VCards/SetVCardRequest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,20 +7,20 @@
#pragma once
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/VCard.h>
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API SetVCardRequest : public GenericRequest<VCard> {
- public:
- typedef boost::shared_ptr<SetVCardRequest> ref;
+ class SWIFTEN_API SetVCardRequest : public GenericRequest<VCard> {
+ public:
+ typedef std::shared_ptr<SetVCardRequest> ref;
- static ref create(VCard::ref vcard, IQRouter* router) {
- return ref(new SetVCardRequest(vcard, router));
- }
+ static ref create(VCard::ref vcard, IQRouter* router) {
+ return ref(new SetVCardRequest(vcard, router));
+ }
- private:
- SetVCardRequest(VCard::ref vcard, IQRouter* router) : GenericRequest<VCard>(IQ::Set, JID(), vcard, router) {
- }
- };
+ private:
+ SetVCardRequest(VCard::ref vcard, IQRouter* router) : GenericRequest<VCard>(IQ::Set, JID(), vcard, router) {
+ }
+ };
}
diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
index 278449b..3d5338d 100644
--- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp
+++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
@@ -1,13 +1,13 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
#include <vector>
#include <boost/bind.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -23,189 +23,189 @@
using namespace Swift;
class VCardManagerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(VCardManagerTest);
- CPPUNIT_TEST(testGet_NewVCardRequestsVCard);
- CPPUNIT_TEST(testGet_ExistingVCard);
- CPPUNIT_TEST(testRequest_RequestsVCard);
- CPPUNIT_TEST(testRequest_ReceiveEmitsNotification);
- CPPUNIT_TEST(testRequest_Error);
- CPPUNIT_TEST(testRequest_VCardAlreadyRequested);
- CPPUNIT_TEST(testRequest_AfterPreviousRequest);
- CPPUNIT_TEST(testRequestOwnVCard);
- CPPUNIT_TEST(testCreateSetVCardRequest);
- CPPUNIT_TEST(testCreateSetVCardRequest_Error);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- changes.clear();
- ownChanges.clear();
- ownJID = JID("baz@fum.com/dum");
- crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
- stanzaChannel = new DummyStanzaChannel();
- iqRouter = new IQRouter(stanzaChannel);
- vcardStorage = new VCardMemoryStorage(crypto.get());
- }
-
- void tearDown() {
- delete vcardStorage;
- delete iqRouter;
- delete stanzaChannel;
- }
-
- void testGet_NewVCardRequestsVCard() {
- boost::shared_ptr<VCardManager> testling = createManager();
- VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
-
- CPPUNIT_ASSERT(!result);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
- CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
- }
-
- void testGet_ExistingVCard() {
- boost::shared_ptr<VCardManager> testling = createManager();
- VCard::ref vcard(new VCard());
- vcard->setFullName("Foo Bar");
- vcardStorage->setVCard(JID("foo@bar.com/baz"), vcard);
-
- VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
-
- CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), result->getFullName());
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel->sentStanzas.size()));
- }
-
- void testRequest_RequestsVCard() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(JID("foo@bar.com/baz"));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
- CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
- }
-
- void testRequest_ReceiveEmitsNotification() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(JID("foo@bar.com/baz"));
- stanzaChannel->onIQReceived(createVCardResult());
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first);
- CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), changes[0].second->getFullName());
- CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), vcardStorage->getVCard(JID("foo@bar.com/baz"))->getFullName());
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(ownChanges.size()));
- }
-
- void testRequest_Error() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(JID("foo@bar.com/baz"));
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
-
- // On error, cached vCards should not be changed.
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
- }
-
- void testRequest_VCardAlreadyRequested() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(JID("foo@bar.com/baz"));
- VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
-
- CPPUNIT_ASSERT(!result);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
- }
-
- void testRequest_AfterPreviousRequest() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(JID("foo@bar.com/baz"));
- stanzaChannel->onIQReceived(createVCardResult());
- testling->requestVCard(JID("foo@bar.com/baz"));
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(stanzaChannel->sentStanzas.size()));
- CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(1, JID("foo@bar.com/baz"), IQ::Get));
- }
-
- void testRequestOwnVCard() {
- boost::shared_ptr<VCardManager> testling = createManager();
- testling->requestVCard(ownJID);
- stanzaChannel->onIQReceived(createOwnVCardResult());
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
- CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
- CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first);
- CPPUNIT_ASSERT_EQUAL(std::string("Myself"), changes[0].second->getFullName());
- CPPUNIT_ASSERT_EQUAL(std::string("Myself"), vcardStorage->getVCard(ownJID.toBare())->getFullName());
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(ownChanges.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Myself"), ownChanges[0]->getFullName());
- }
-
- void testCreateSetVCardRequest() {
- boost::shared_ptr<VCardManager> testling = createManager();
- VCard::ref vcard = boost::make_shared<VCard>();
- vcard->setFullName("New Name");
- SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
- request->send();
-
- stanzaChannel->onIQReceived(createSetVCardResult());
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
- CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first);
- CPPUNIT_ASSERT_EQUAL(std::string("New Name"), changes[0].second->getFullName());
- }
-
- void testCreateSetVCardRequest_Error() {
- boost::shared_ptr<VCardManager> testling = createManager();
- VCard::ref vcard = boost::make_shared<VCard>();
- vcard->setFullName("New Name");
- SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
- request->send();
-
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
- }
-
- private:
- boost::shared_ptr<VCardManager> createManager() {
- boost::shared_ptr<VCardManager> manager(new VCardManager(ownJID, iqRouter, vcardStorage));
- manager->onVCardChanged.connect(boost::bind(&VCardManagerTest::handleVCardChanged, this, _1, _2));
- manager->onOwnVCardChanged.connect(boost::bind(&VCardManagerTest::handleOwnVCardChanged, this, _1));
- return manager;
- }
-
- void handleVCardChanged(const JID& jid, VCard::ref vcard) {
- changes.push_back(std::pair<JID, VCard::ref>(jid, vcard));
- }
-
- void handleOwnVCardChanged(VCard::ref vcard) {
- ownChanges.push_back(vcard);
- }
-
- IQ::ref createVCardResult() {
- VCard::ref vcard(new VCard());
- vcard->setFullName("Foo Bar");
- return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
- }
-
- IQ::ref createOwnVCardResult() {
- VCard::ref vcard(new VCard());
- vcard->setFullName("Myself");
- return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
- }
-
- IQ::ref createSetVCardResult() {
- return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), VCard::ref());
- }
-
-
- private:
- JID ownJID;
- DummyStanzaChannel* stanzaChannel;
- IQRouter* iqRouter;
- VCardMemoryStorage* vcardStorage;
- std::vector< std::pair<JID, VCard::ref> > changes;
- std::vector<VCard::ref> ownChanges;
- boost::shared_ptr<CryptoProvider> crypto;
+ CPPUNIT_TEST_SUITE(VCardManagerTest);
+ CPPUNIT_TEST(testGet_NewVCardRequestsVCard);
+ CPPUNIT_TEST(testGet_ExistingVCard);
+ CPPUNIT_TEST(testRequest_RequestsVCard);
+ CPPUNIT_TEST(testRequest_ReceiveEmitsNotification);
+ CPPUNIT_TEST(testRequest_Error);
+ CPPUNIT_TEST(testRequest_VCardAlreadyRequested);
+ CPPUNIT_TEST(testRequest_AfterPreviousRequest);
+ CPPUNIT_TEST(testRequestOwnVCard);
+ CPPUNIT_TEST(testCreateSetVCardRequest);
+ CPPUNIT_TEST(testCreateSetVCardRequest_Error);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ changes.clear();
+ ownChanges.clear();
+ ownJID = JID("baz@fum.com/dum");
+ crypto = std::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+ stanzaChannel = new DummyStanzaChannel();
+ iqRouter = new IQRouter(stanzaChannel);
+ vcardStorage = new VCardMemoryStorage(crypto.get());
+ }
+
+ void tearDown() {
+ delete vcardStorage;
+ delete iqRouter;
+ delete stanzaChannel;
+ }
+
+ void testGet_NewVCardRequestsVCard() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
+
+ CPPUNIT_ASSERT(!result);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
+ }
+
+ void testGet_ExistingVCard() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ VCard::ref vcard(new VCard());
+ vcard->setFullName("Foo Bar");
+ vcardStorage->setVCard(JID("foo@bar.com/baz"), vcard);
+
+ VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
+
+ CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), result->getFullName());
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ }
+
+ void testRequest_RequestsVCard() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(JID("foo@bar.com/baz"));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
+ }
+
+ void testRequest_ReceiveEmitsNotification() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(JID("foo@bar.com/baz"));
+ stanzaChannel->onIQReceived(createVCardResult());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first);
+ CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), changes[0].second->getFullName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), vcardStorage->getVCard(JID("foo@bar.com/baz"))->getFullName());
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(ownChanges.size()));
+ }
+
+ void testRequest_Error() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(JID("foo@bar.com/baz"));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
+
+ // On error, cached vCards should not be changed.
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
+ }
+
+ void testRequest_VCardAlreadyRequested() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(JID("foo@bar.com/baz"));
+ VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
+
+ CPPUNIT_ASSERT(!result);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ }
+
+ void testRequest_AfterPreviousRequest() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(JID("foo@bar.com/baz"));
+ stanzaChannel->onIQReceived(createVCardResult());
+ testling->requestVCard(JID("foo@bar.com/baz"));
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(1, JID("foo@bar.com/baz"), IQ::Get));
+ }
+
+ void testRequestOwnVCard() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ testling->requestVCard(ownJID);
+ stanzaChannel->onIQReceived(createOwnVCardResult());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
+ CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
+ CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first);
+ CPPUNIT_ASSERT_EQUAL(std::string("Myself"), changes[0].second->getFullName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Myself"), vcardStorage->getVCard(ownJID.toBare())->getFullName());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(ownChanges.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Myself"), ownChanges[0]->getFullName());
+ }
+
+ void testCreateSetVCardRequest() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ VCard::ref vcard = std::make_shared<VCard>();
+ vcard->setFullName("New Name");
+ SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
+ request->send();
+
+ stanzaChannel->onIQReceived(createSetVCardResult());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
+ CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first);
+ CPPUNIT_ASSERT_EQUAL(std::string("New Name"), changes[0].second->getFullName());
+ }
+
+ void testCreateSetVCardRequest_Error() {
+ std::shared_ptr<VCardManager> testling = createManager();
+ VCard::ref vcard = std::make_shared<VCard>();
+ vcard->setFullName("New Name");
+ SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
+ request->send();
+
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
+ }
+
+ private:
+ std::shared_ptr<VCardManager> createManager() {
+ std::shared_ptr<VCardManager> manager(new VCardManager(ownJID, iqRouter, vcardStorage));
+ manager->onVCardChanged.connect(boost::bind(&VCardManagerTest::handleVCardChanged, this, _1, _2));
+ manager->onOwnVCardChanged.connect(boost::bind(&VCardManagerTest::handleOwnVCardChanged, this, _1));
+ return manager;
+ }
+
+ void handleVCardChanged(const JID& jid, VCard::ref vcard) {
+ changes.push_back(std::pair<JID, VCard::ref>(jid, vcard));
+ }
+
+ void handleOwnVCardChanged(VCard::ref vcard) {
+ ownChanges.push_back(vcard);
+ }
+
+ IQ::ref createVCardResult() {
+ VCard::ref vcard(new VCard());
+ vcard->setFullName("Foo Bar");
+ return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
+ }
+
+ IQ::ref createOwnVCardResult() {
+ VCard::ref vcard(new VCard());
+ vcard->setFullName("Myself");
+ return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
+ }
+
+ IQ::ref createSetVCardResult() {
+ return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), VCard::ref());
+ }
+
+
+ private:
+ JID ownJID;
+ DummyStanzaChannel* stanzaChannel;
+ IQRouter* iqRouter;
+ VCardMemoryStorage* vcardStorage;
+ std::vector< std::pair<JID, VCard::ref> > changes;
+ std::vector<VCard::ref> ownChanges;
+ std::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(VCardManagerTest);
diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp
index 5fa44ae..95b96fa 100644
--- a/Swiften/VCards/VCardManager.cpp
+++ b/Swiften/VCards/VCardManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -22,68 +22,71 @@ VCardManager::~VCardManager() {
}
VCard::ref VCardManager::getVCard(const JID& jid) const {
- return storage->getVCard(jid);
+ return storage->getVCard(jid);
}
VCard::ref VCardManager::getVCardAndRequestWhenNeeded(const JID& jid, const boost::posix_time::time_duration& allowedAge) {
- VCard::ref vcard = storage->getVCard(jid);
- boost::posix_time::ptime vcardFetchedTime = storage->getVCardWriteTime(jid);
- bool vcardTooOld = vcard && (vcardFetchedTime.is_special() || ((boost::posix_time::second_clock::universal_time() - vcardFetchedTime) > allowedAge));
- if (!vcard || vcardTooOld) {
- requestVCard(jid);
- }
- return vcard;
+ VCard::ref vcard = storage->getVCard(jid);
+ boost::posix_time::ptime vcardFetchedTime = storage->getVCardWriteTime(jid);
+ bool vcardTooOld = vcard && (vcardFetchedTime.is_special() || ((boost::posix_time::second_clock::universal_time() - vcardFetchedTime) > allowedAge));
+ if (!vcard || vcardTooOld) {
+ requestVCard(jid);
+ }
+ return vcard;
}
void VCardManager::requestVCard(const JID& requestedJID) {
- JID jid = requestedJID.equals(ownJID, JID::WithoutResource) ? JID() : requestedJID;
- if (requestedVCards.find(jid) != requestedVCards.end()) {
- return;
- }
- GetVCardRequest::ref request = GetVCardRequest::create(jid, iqRouter);
- request->onResponse.connect(boost::bind(&VCardManager::handleVCardReceived, this, jid, _1, _2));
- request->send();
- requestedVCards.insert(jid);
+ JID jid = requestedJID.equals(ownJID, JID::WithoutResource) ? JID() : requestedJID;
+ if (requestedVCards.find(jid) != requestedVCards.end()) {
+ return;
+ }
+ GetVCardRequest::ref request = GetVCardRequest::create(jid, iqRouter);
+ request->onResponse.connect(boost::bind(&VCardManager::handleVCardReceived, this, jid, _1, _2));
+ request->send();
+ requestedVCards.insert(jid);
}
void VCardManager::requestOwnVCard() {
- requestVCard(JID());
+ requestVCard(JID());
}
void VCardManager::handleVCardReceived(const JID& actualJID, VCard::ref vcard, ErrorPayload::ref error) {
- requestedVCards.erase(actualJID);
- if (!error) {
- if (!vcard) {
- vcard = VCard::ref(new VCard());
- }
- JID jid = actualJID.isValid() ? actualJID : ownJID.toBare();
- setVCard(jid, vcard);
- }
+ requestedVCards.erase(actualJID);
+ if (!error) {
+ if (!vcard) {
+ vcard = VCard::ref(new VCard());
+ }
+ JID jid = actualJID.isValid() ? actualJID : ownJID.toBare();
+ setVCard(jid, vcard);
+ }
+ else {
+ onVCardRetrievalError(actualJID, error);
+ }
}
SetVCardRequest::ref VCardManager::createSetVCardRequest(VCard::ref vcard) {
- SetVCardRequest::ref request = SetVCardRequest::create(vcard, iqRouter);
- request->onResponse.connect(boost::bind(&VCardManager::handleSetVCardResponse, this, vcard, _2));
- return request;
+ SetVCardRequest::ref request = SetVCardRequest::create(vcard, iqRouter);
+ request->onResponse.connect(boost::bind(&VCardManager::handleSetVCardResponse, this, vcard, _2));
+ return request;
}
void VCardManager::handleSetVCardResponse(VCard::ref vcard, ErrorPayload::ref error) {
- if (!error) {
- setVCard(ownJID.toBare(), vcard);
- }
+ if (!error) {
+ setVCard(ownJID.toBare(), vcard);
+ }
}
void VCardManager::setVCard(const JID& jid, VCard::ref vcard) {
- storage->setVCard(jid, vcard);
- onVCardChanged(jid, vcard);
- if (jid.compare(ownJID, JID::WithoutResource) == 0) {
- onOwnVCardChanged(vcard);
- }
+ storage->setVCard(jid, vcard);
+ onVCardChanged(jid, vcard);
+ if (jid.compare(ownJID, JID::WithoutResource) == 0) {
+ onOwnVCardChanged(vcard);
+ }
}
std::string VCardManager::getPhotoHash(const JID& jid) const {
- return storage->getPhotoHash(jid);
+ return storage->getPhotoHash(jid);
}
}
diff --git a/Swiften/VCards/VCardManager.h b/Swiften/VCards/VCardManager.h
index 8b3075a..d987862 100644
--- a/Swiften/VCards/VCardManager.h
+++ b/Swiften/VCards/VCardManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -9,56 +9,61 @@
#include <set>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/JID/JID.h>
-#include <Swiften/Elements/VCard.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/VCard.h>
+#include <Swiften/JID/JID.h>
#include <Swiften/VCards/SetVCardRequest.h>
-#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class JID;
- class VCardStorage;
- class IQRouter;
+ class IQRouter;
+ class JID;
+ class VCardStorage;
+
+ class SWIFTEN_API VCardManager : public boost::signals2::trackable {
+ public:
+ VCardManager(const JID& ownJID, IQRouter* iqRouter, VCardStorage* vcardStorage);
+ ~VCardManager();
- class SWIFTEN_API VCardManager : public boost::bsignals::trackable {
- public:
- VCardManager(const JID& ownJID, IQRouter* iqRouter, VCardStorage* vcardStorage);
- ~VCardManager();
+ VCard::ref getVCard(const JID& jid) const;
+ VCard::ref getVCardAndRequestWhenNeeded(const JID& jid, const boost::posix_time::time_duration& allowedAge = boost::posix_time::time_duration(boost::date_time::pos_infin));
+ void requestVCard(const JID& jid);
+ void requestOwnVCard();
- VCard::ref getVCard(const JID& jid) const;
- VCard::ref getVCardAndRequestWhenNeeded(const JID& jid, const boost::posix_time::time_duration& allowedAge = boost::posix_time::time_duration(boost::date_time::pos_infin));
- void requestVCard(const JID& jid);
- void requestOwnVCard();
+ std::string getPhotoHash(const JID& jid) const;
- std::string getPhotoHash(const JID& jid) const;
+ SetVCardRequest::ref createSetVCardRequest(VCard::ref);
- SetVCardRequest::ref createSetVCardRequest(VCard::ref);
+ public:
+ /**
+ * The JID will always be bare.
+ */
+ boost::signals2::signal<void (const JID&, VCard::ref)> onVCardChanged;
- public:
- /**
- * The JID will always be bare.
- */
- boost::signal<void (const JID&, VCard::ref)> onVCardChanged;
+ /**
+ * Emitted when we received an error on looking up a vCard.
+ */
+ boost::signals2::signal<void (const JID&, ErrorPayload::ref)> onVCardRetrievalError;
- /**
- * Emitted when our own vcard changes.
- *
- * onVCardChanged will also be emitted.
- */
- boost::signal<void (VCard::ref)> onOwnVCardChanged;
+ /**
+ * Emitted when our own vcard changes.
+ *
+ * onVCardChanged will also be emitted.
+ */
+ boost::signals2::signal<void (VCard::ref)> onOwnVCardChanged;
- private:
- void handleVCardReceived(const JID& from, VCard::ref, ErrorPayload::ref);
- void handleSetVCardResponse(VCard::ref, ErrorPayload::ref);
- void setVCard(const JID& jid, VCard::ref vcard);
+ private:
+ void handleVCardReceived(const JID& from, VCard::ref, ErrorPayload::ref);
+ void handleSetVCardResponse(VCard::ref, ErrorPayload::ref);
+ void setVCard(const JID& jid, VCard::ref vcard);
- private:
- JID ownJID;
- IQRouter* iqRouter;
- VCardStorage* storage;
- std::set<JID> requestedVCards;
- };
+ private:
+ JID ownJID;
+ IQRouter* iqRouter;
+ VCardStorage* storage;
+ std::set<JID> requestedVCards;
+ };
}
diff --git a/Swiften/VCards/VCardMemoryStorage.h b/Swiften/VCards/VCardMemoryStorage.h
index 989d46e..9a79edc 100644
--- a/Swiften/VCards/VCardMemoryStorage.h
+++ b/Swiften/VCards/VCardMemoryStorage.h
@@ -1,52 +1,51 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/shared_ptr.hpp>
-
#include <map>
+#include <memory>
#include <Swiften/Base/API.h>
#include <Swiften/JID/JID.h>
#include <Swiften/VCards/VCardStorage.h>
namespace Swift {
- class SWIFTEN_API VCardMemoryStorage : public VCardStorage {
- public:
- VCardMemoryStorage(CryptoProvider* crypto) : VCardStorage(crypto) {}
-
- virtual VCard::ref getVCard(const JID& jid) const {
- VCardMap::const_iterator i = vcards.find(jid);
- if (i != vcards.end()) {
- return i->second;
- }
- else {
- return VCard::ref();
- }
- }
-
- virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const {
- if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) {
- return boost::posix_time::ptime();
- }
- else {
- return vcardWriteTimes.at(jid);
- }
- }
-
- virtual void setVCard(const JID& jid, VCard::ref v) {
- vcards[jid] = v;
- vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time();
- }
-
- private:
- typedef std::map<JID, VCard::ref> VCardMap;
- typedef std::map<JID, boost::posix_time::ptime> VCardWriteTimeMap;
- VCardMap vcards;
- VCardWriteTimeMap vcardWriteTimes;
- };
+ class SWIFTEN_API VCardMemoryStorage : public VCardStorage {
+ public:
+ VCardMemoryStorage(CryptoProvider* crypto) : VCardStorage(crypto) {}
+
+ virtual VCard::ref getVCard(const JID& jid) const {
+ VCardMap::const_iterator i = vcards.find(jid);
+ if (i != vcards.end()) {
+ return i->second;
+ }
+ else {
+ return VCard::ref();
+ }
+ }
+
+ virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const {
+ if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) {
+ return boost::posix_time::ptime();
+ }
+ else {
+ return vcardWriteTimes.at(jid);
+ }
+ }
+
+ virtual void setVCard(const JID& jid, VCard::ref v) {
+ vcards[jid] = v;
+ vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time();
+ }
+
+ private:
+ typedef std::map<JID, VCard::ref> VCardMap;
+ typedef std::map<JID, boost::posix_time::ptime> VCardWriteTimeMap;
+ VCardMap vcards;
+ VCardWriteTimeMap vcardWriteTimes;
+ };
}
diff --git a/Swiften/VCards/VCardStorage.cpp b/Swiften/VCards/VCardStorage.cpp
index 5e8cca5..2a4f04c 100644
--- a/Swiften/VCards/VCardStorage.cpp
+++ b/Swiften/VCards/VCardStorage.cpp
@@ -1,13 +1,13 @@
/*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/VCards/VCardStorage.h>
-#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/StringCodecs/Hexify.h>
namespace Swift {
@@ -18,13 +18,13 @@ VCardStorage::~VCardStorage() {
}
std::string VCardStorage::getPhotoHash(const JID& jid) const {
- VCard::ref vCard = getVCard(jid);
- if (vCard && !vCard->getPhoto().empty()) {
- return Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
- }
- else {
- return "";
- }
+ VCard::ref vCard = getVCard(jid);
+ if (vCard && !vCard->getPhoto().empty()) {
+ return Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
+ }
+ else {
+ return "";
+ }
}
}
diff --git a/Swiften/VCards/VCardStorage.h b/Swiften/VCards/VCardStorage.h
index 13554d0..632e9e3 100644
--- a/Swiften/VCards/VCardStorage.h
+++ b/Swiften/VCards/VCardStorage.h
@@ -1,35 +1,35 @@
/*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
+#include <memory>
#include <string>
-#include <boost/shared_ptr.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/Elements/VCard.h>
namespace Swift {
- class JID;
- class CryptoProvider;
+ class JID;
+ class CryptoProvider;
- class SWIFTEN_API VCardStorage {
- public:
- VCardStorage(CryptoProvider*);
- virtual ~VCardStorage();
+ class SWIFTEN_API VCardStorage {
+ public:
+ VCardStorage(CryptoProvider*);
+ virtual ~VCardStorage();
- virtual VCard::ref getVCard(const JID& jid) const = 0;
- virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const = 0;
- virtual void setVCard(const JID&, VCard::ref) = 0;
+ virtual VCard::ref getVCard(const JID& jid) const = 0;
+ virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const = 0;
+ virtual void setVCard(const JID&, VCard::ref) = 0;
- virtual std::string getPhotoHash(const JID&) const;
+ virtual std::string getPhotoHash(const JID&) const;
- private:
- CryptoProvider* crypto;
- };
+ private:
+ CryptoProvider* crypto;
+ };
}