summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Disco')
-rw-r--r--Swiften/Disco/CapsInfoGenerator.cpp10
-rw-r--r--Swiften/Disco/CapsInfoGenerator.h4
-rw-r--r--Swiften/Disco/CapsManager.cpp6
-rw-r--r--Swiften/Disco/CapsManager.h6
-rw-r--r--Swiften/Disco/ClientDiscoManager.cpp6
-rw-r--r--Swiften/Disco/ClientDiscoManager.h6
-rw-r--r--Swiften/Disco/DiscoServiceWalker.cpp1
-rw-r--r--Swiften/Disco/DiscoServiceWalker.h3
-rw-r--r--Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp38
-rw-r--r--Swiften/Disco/UnitTest/CapsManagerTest.cpp14
-rw-r--r--Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp13
11 files changed, 64 insertions, 43 deletions
diff --git a/Swiften/Disco/CapsInfoGenerator.cpp b/Swiften/Disco/CapsInfoGenerator.cpp
index 6d84984..4332f76 100644
--- a/Swiften/Disco/CapsInfoGenerator.cpp
+++ b/Swiften/Disco/CapsInfoGenerator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -11,7 +11,7 @@
#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/FormField.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/StringCodecs/Base64.h>
namespace {
@@ -22,7 +22,7 @@ namespace {
namespace Swift {
-CapsInfoGenerator::CapsInfoGenerator(const std::string& node) : node_(node) {
+CapsInfoGenerator::CapsInfoGenerator(const std::string& node, CryptoProvider* crypto) : node_(node), crypto_(crypto) {
}
CapsInfo CapsInfoGenerator::generateCapsInfo(const DiscoInfo& discoInfo) const {
@@ -49,7 +49,7 @@ CapsInfo CapsInfoGenerator::generateCapsInfo(const DiscoInfo& discoInfo) const {
continue;
}
serializedCaps += field->getName() + "<";
- std::vector<std::string> values(field->getRawValues());
+ std::vector<std::string> values(field->getValues());
std::sort(values.begin(), values.end());
foreach(const std::string& value, values) {
serializedCaps += value + "<";
@@ -57,7 +57,7 @@ CapsInfo CapsInfoGenerator::generateCapsInfo(const DiscoInfo& discoInfo) const {
}
}
- std::string version(Base64::encode(SHA1::getHash(createByteArray(serializedCaps))));
+ std::string version(Base64::encode(crypto_->getSHA1Hash(createByteArray(serializedCaps))));
return CapsInfo(node_, version, "sha-1");
}
diff --git a/Swiften/Disco/CapsInfoGenerator.h b/Swiften/Disco/CapsInfoGenerator.h
index 62958e7..17a01dd 100644
--- a/Swiften/Disco/CapsInfoGenerator.h
+++ b/Swiften/Disco/CapsInfoGenerator.h
@@ -12,14 +12,16 @@
namespace Swift {
class DiscoInfo;
+ class CryptoProvider;
class SWIFTEN_API CapsInfoGenerator {
public:
- CapsInfoGenerator(const std::string& node);
+ CapsInfoGenerator(const std::string& node, CryptoProvider* crypto);
CapsInfo generateCapsInfo(const DiscoInfo& discoInfo) const;
private:
std::string node_;
+ CryptoProvider* crypto_;
};
}
diff --git a/Swiften/Disco/CapsManager.cpp b/Swiften/Disco/CapsManager.cpp
index 66eb47e..18f8745 100644
--- a/Swiften/Disco/CapsManager.cpp
+++ b/Swiften/Disco/CapsManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -17,7 +17,7 @@
namespace Swift {
-CapsManager::CapsManager(CapsStorage* capsStorage, StanzaChannel* stanzaChannel, IQRouter* iqRouter) : iqRouter(iqRouter), capsStorage(capsStorage), warnOnInvalidHash(true) {
+CapsManager::CapsManager(CapsStorage* capsStorage, StanzaChannel* stanzaChannel, IQRouter* iqRouter, CryptoProvider* crypto) : iqRouter(iqRouter), crypto(crypto), capsStorage(capsStorage), warnOnInvalidHash(true) {
stanzaChannel->onPresenceReceived.connect(boost::bind(&CapsManager::handlePresenceReceived, this, _1));
stanzaChannel->onAvailableChanged.connect(boost::bind(&CapsManager::handleStanzaChannelAvailableChanged, this, _1));
}
@@ -51,7 +51,7 @@ void CapsManager::handleStanzaChannelAvailableChanged(bool available) {
void CapsManager::handleDiscoInfoReceived(const JID& from, const std::string& hash, DiscoInfo::ref discoInfo, ErrorPayload::ref error) {
requestedDiscoInfos.erase(hash);
- if (error || !discoInfo || CapsInfoGenerator("").generateCapsInfo(*discoInfo.get()).getVersion() != hash) {
+ if (error || !discoInfo || CapsInfoGenerator("", crypto).generateCapsInfo(*discoInfo.get()).getVersion() != hash) {
if (warnOnInvalidHash && !error && discoInfo) {
std::cerr << "Warning: Caps from " << from.toString() << " do not verify" << std::endl;
}
diff --git a/Swiften/Disco/CapsManager.h b/Swiften/Disco/CapsManager.h
index 9f1d83b..3529812 100644
--- a/Swiften/Disco/CapsManager.h
+++ b/Swiften/Disco/CapsManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -22,10 +22,11 @@ namespace Swift {
class IQRouter;
class JID;
class CapsStorage;
+ class CryptoProvider;
class SWIFTEN_API CapsManager : public CapsProvider, public boost::bsignals::trackable {
public:
- CapsManager(CapsStorage*, StanzaChannel*, IQRouter*);
+ CapsManager(CapsStorage*, StanzaChannel*, IQRouter*, CryptoProvider*);
DiscoInfo::ref getCaps(const std::string&) const;
@@ -42,6 +43,7 @@ namespace Swift {
private:
IQRouter* iqRouter;
+ CryptoProvider* crypto;
CapsStorage* capsStorage;
bool warnOnInvalidHash;
std::set<std::string> requestedDiscoInfos;
diff --git a/Swiften/Disco/ClientDiscoManager.cpp b/Swiften/Disco/ClientDiscoManager.cpp
index cca0144..f6683a8 100644
--- a/Swiften/Disco/ClientDiscoManager.cpp
+++ b/Swiften/Disco/ClientDiscoManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -12,7 +12,7 @@
namespace Swift {
-ClientDiscoManager::ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender) {
+ClientDiscoManager::ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender, CryptoProvider* crypto) : crypto(crypto) {
discoInfoResponder = new DiscoInfoResponder(iqRouter);
discoInfoResponder->start();
this->presenceSender = new PayloadAddingPresenceSender(presenceSender);
@@ -29,7 +29,7 @@ void ClientDiscoManager::setCapsNode(const std::string& node) {
}
void ClientDiscoManager::setDiscoInfo(const DiscoInfo& discoInfo) {
- capsInfo = CapsInfo::ref(new CapsInfo(CapsInfoGenerator(capsNode).generateCapsInfo(discoInfo)));
+ capsInfo = CapsInfo::ref(new CapsInfo(CapsInfoGenerator(capsNode, crypto).generateCapsInfo(discoInfo)));
discoInfoResponder->clearDiscoInfo();
discoInfoResponder->setDiscoInfo(discoInfo);
discoInfoResponder->setDiscoInfo(capsInfo->getNode() + "#" + capsInfo->getVersion(), discoInfo);
diff --git a/Swiften/Disco/ClientDiscoManager.h b/Swiften/Disco/ClientDiscoManager.h
index 0cae40e..a9ed10a 100644
--- a/Swiften/Disco/ClientDiscoManager.h
+++ b/Swiften/Disco/ClientDiscoManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -16,6 +16,7 @@ namespace Swift {
class DiscoInfoResponder;
class PayloadAddingPresenceSender;
class PresenceSender;
+ class CryptoProvider;
/**
* Class responsible for managing outgoing disco information for a client.
@@ -36,7 +37,7 @@ namespace Swift {
* \param presenceSender the presence sender to which all outgoing presence
* (with caps information) will be sent.
*/
- ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender);
+ ClientDiscoManager(IQRouter* iqRouter, PresenceSender* presenceSender, CryptoProvider* crypto);
~ClientDiscoManager();
/**
@@ -68,6 +69,7 @@ namespace Swift {
private:
PayloadAddingPresenceSender* presenceSender;
+ CryptoProvider* crypto;
DiscoInfoResponder* discoInfoResponder;
std::string capsNode;
CapsInfo::ref capsInfo;
diff --git a/Swiften/Disco/DiscoServiceWalker.cpp b/Swiften/Disco/DiscoServiceWalker.cpp
index c8c3e1b..0f27111 100644
--- a/Swiften/Disco/DiscoServiceWalker.cpp
+++ b/Swiften/Disco/DiscoServiceWalker.cpp
@@ -35,6 +35,7 @@ void DiscoServiceWalker::endWalk() {
request->onResponse.disconnect(boost::bind(&DiscoServiceWalker::handleDiscoItemsResponse, this, _1, _2, request));
}
active_ = false;
+ onWalkAborted();
}
}
diff --git a/Swiften/Disco/DiscoServiceWalker.h b/Swiften/Disco/DiscoServiceWalker.h
index 1853b57..ea55a78 100644
--- a/Swiften/Disco/DiscoServiceWalker.h
+++ b/Swiften/Disco/DiscoServiceWalker.h
@@ -49,6 +49,9 @@ namespace Swift {
/** Emitted for each service found. */
boost::signal<void(const JID&, boost::shared_ptr<DiscoInfo>)> onServiceFound;
+ /** Emitted when walking is aborted. */
+ boost::signal<void()> onWalkAborted;
+
/** Emitted when walking is complete.*/
boost::signal<void()> onWalkComplete;
diff --git a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp
index 52fdbaa..67d27c0 100644
--- a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp
+++ b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,6 +9,8 @@
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Disco/CapsInfoGenerator.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -19,6 +21,10 @@ class CapsInfoGeneratorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
public:
+ void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+ }
+
void testGenerate_XEP0115SimpleExample() {
DiscoInfo discoInfo;
discoInfo.addIdentity(DiscoInfo::Identity("Exodus 0.9.1", "client", "pc"));
@@ -27,7 +33,7 @@ class CapsInfoGeneratorTest : public CppUnit::TestFixture {
discoInfo.addFeature("http://jabber.org/protocol/disco#info");
discoInfo.addFeature("http://jabber.org/protocol/muc");
- CapsInfoGenerator testling("http://code.google.com/p/exodus");
+ CapsInfoGenerator testling("http://code.google.com/p/exodus", crypto.get());
CapsInfo result = testling.generateCapsInfo(discoInfo);
CPPUNIT_ASSERT_EQUAL(std::string("http://code.google.com/p/exodus"), result.getNode());
@@ -45,40 +51,36 @@ class CapsInfoGeneratorTest : public CppUnit::TestFixture {
discoInfo.addFeature("http://jabber.org/protocol/muc");
Form::ref extension(new Form(Form::ResultType));
- FormField::ref field = HiddenFormField::create("urn:xmpp:dataforms:softwareinfo");
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "urn:xmpp:dataforms:softwareinfo");
field->setName("FORM_TYPE");
extension->addField(field);
- std::vector<std::string> ipVersions;
- ipVersions.push_back("ipv6");
- ipVersions.push_back("ipv4");
- field = ListMultiFormField::create(ipVersions);
- field->addRawValue("ipv6");
- field->addRawValue("ipv4");
+ field = boost::make_shared<FormField>(FormField::ListMultiType);
+ field->addValue("ipv6");
+ field->addValue("ipv4");
field->setName("ip_version");
extension->addField(field);
- field = TextSingleFormField::create("Psi");
- field->addRawValue("Psi");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Psi");
field->setName("software");
extension->addField(field);
- field = TextSingleFormField::create("0.11");
- field->addRawValue("0.11");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "0.11");
field->setName("software_version");
extension->addField(field);
- field = TextSingleFormField::create("Mac");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "Mac");
field->setName("os");
- field->addRawValue("Mac");
extension->addField(field);
- field = TextSingleFormField::create("10.5.1");
+ field = boost::make_shared<FormField>(FormField::TextSingleType, "10.5.1");
field->setName("os_version");
- field->addRawValue("10.5.1");
extension->addField(field);
discoInfo.addExtension(extension);
- CapsInfoGenerator testling("http://psi-im.org");
+ CapsInfoGenerator testling("http://psi-im.org", crypto.get());
CapsInfo result = testling.generateCapsInfo(discoInfo);
CPPUNIT_ASSERT_EQUAL(std::string("q07IKJEyjvHSyhy//CH0CxmKi8w="), result.getVersion());
}
+
+ private:
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(CapsInfoGeneratorTest);
diff --git a/Swiften/Disco/UnitTest/CapsManagerTest.cpp b/Swiften/Disco/UnitTest/CapsManagerTest.cpp
index ca55c48..303fd78 100644
--- a/Swiften/Disco/UnitTest/CapsManagerTest.cpp
+++ b/Swiften/Disco/UnitTest/CapsManagerTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -16,6 +16,8 @@
#include <Swiften/Elements/CapsInfo.h>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Client/DummyStanzaChannel.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -41,18 +43,19 @@ class CapsManagerTest : public CppUnit::TestFixture {
public:
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
stanzaChannel = new DummyStanzaChannel();
iqRouter = new IQRouter(stanzaChannel);
storage = new CapsMemoryStorage();
user1 = JID("user1@bar.com/bla");
discoInfo1 = boost::make_shared<DiscoInfo>();
discoInfo1->addFeature("http://swift.im/feature1");
- capsInfo1 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node1.im").generateCapsInfo(*discoInfo1.get()));
- capsInfo1alt = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im").generateCapsInfo(*discoInfo1.get()));
+ capsInfo1 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node1.im", crypto.get()).generateCapsInfo(*discoInfo1.get()));
+ capsInfo1alt = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im", crypto.get()).generateCapsInfo(*discoInfo1.get()));
user2 = JID("user2@foo.com/baz");
discoInfo2 = boost::make_shared<DiscoInfo>();
discoInfo2->addFeature("http://swift.im/feature2");
- capsInfo2 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im").generateCapsInfo(*discoInfo2.get()));
+ capsInfo2 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im", crypto.get()).generateCapsInfo(*discoInfo2.get()));
user3 = JID("user3@foo.com/baz");
legacyCapsInfo = boost::make_shared<CapsInfo>("http://swift.im", "ver1", "");
}
@@ -246,7 +249,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<CapsManager> createManager() {
- boost::shared_ptr<CapsManager> manager(new CapsManager(storage, stanzaChannel, iqRouter));
+ boost::shared_ptr<CapsManager> manager(new CapsManager(storage, stanzaChannel, iqRouter, crypto.get()));
manager->setWarnOnInvalidHash(false);
//manager->onCapsChanged.connect(boost::bind(&CapsManagerTest::handleCapsChanged, this, _1));
return manager;
@@ -281,6 +284,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
boost::shared_ptr<CapsInfo> capsInfo2;
boost::shared_ptr<CapsInfo> legacyCapsInfo;
JID user3;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(CapsManagerTest);
diff --git a/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp b/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp
index 0fd966d..940f043 100644
--- a/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp
+++ b/Swiften/Disco/UnitTest/EntityCapsManagerTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -14,6 +14,8 @@
#include <Swiften/Elements/CapsInfo.h>
#include <Swiften/Client/DummyStanzaChannel.h>
#include <Swiften/Disco/CapsInfoGenerator.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -30,18 +32,20 @@ class EntityCapsManagerTest : public CppUnit::TestFixture {
public:
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+
stanzaChannel = new DummyStanzaChannel();
capsProvider = new DummyCapsProvider();
user1 = JID("user1@bar.com/bla");
discoInfo1 = boost::make_shared<DiscoInfo>();
discoInfo1->addFeature("http://swift.im/feature1");
- capsInfo1 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node1.im").generateCapsInfo(*discoInfo1.get()));
- capsInfo1alt = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im").generateCapsInfo(*discoInfo1.get()));
+ capsInfo1 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node1.im", crypto.get()).generateCapsInfo(*discoInfo1.get()));
+ capsInfo1alt = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im", crypto.get()).generateCapsInfo(*discoInfo1.get()));
user2 = JID("user2@foo.com/baz");
discoInfo2 = boost::make_shared<DiscoInfo>();
discoInfo2->addFeature("http://swift.im/feature2");
- capsInfo2 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im").generateCapsInfo(*discoInfo2.get()));
+ capsInfo2 = boost::make_shared<CapsInfo>(CapsInfoGenerator("http://node2.im", crypto.get()).generateCapsInfo(*discoInfo2.get()));
user3 = JID("user3@foo.com/baz");
legacyCapsInfo = boost::make_shared<CapsInfo>("http://swift.im", "ver1", "");
}
@@ -183,6 +187,7 @@ class EntityCapsManagerTest : public CppUnit::TestFixture {
boost::shared_ptr<CapsInfo> legacyCapsInfo;
JID user3;
std::vector<JID> changes;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(EntityCapsManagerTest);