summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/BlockList.cpp9
-rw-r--r--Swiften/Client/BlockList.h9
-rw-r--r--Swiften/Client/BlockListImpl.cpp32
-rw-r--r--Swiften/Client/BlockListImpl.h4
-rw-r--r--Swiften/Client/Client.cpp29
-rw-r--r--Swiften/Client/Client.h15
-rw-r--r--Swiften/Client/ClientBlockListManager.cpp32
-rw-r--r--Swiften/Client/ClientBlockListManager.h10
-rw-r--r--Swiften/Client/ClientSession.cpp15
-rw-r--r--Swiften/Client/ClientSession.h18
-rw-r--r--Swiften/Client/ClientXMLTracer.cpp20
-rw-r--r--Swiften/Client/CoreClient.cpp2
-rw-r--r--Swiften/Client/CoreClient.h3
-rw-r--r--Swiften/Client/MemoryStorages.cpp6
-rw-r--r--Swiften/Client/MemoryStorages.h5
-rw-r--r--Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp190
-rw-r--r--Swiften/Client/UnitTest/ClientSessionTest.cpp10
-rw-r--r--Swiften/Client/UnitTest/NickResolverTest.cpp13
18 files changed, 369 insertions, 53 deletions
diff --git a/Swiften/Client/BlockList.cpp b/Swiften/Client/BlockList.cpp
index 0b2fc12..3ee7864 100644
--- a/Swiften/Client/BlockList.cpp
+++ b/Swiften/Client/BlockList.cpp
@@ -6,8 +6,17 @@
#include <Swiften/Client/BlockList.h>
+#include <algorithm>
+
using namespace Swift;
BlockList::~BlockList() {
}
+
+bool BlockList::isBlocked(const JID& jid) const {
+ const std::vector<JID>& items = getItems();
+ return (std::find(items.begin(), items.end(), jid.toBare()) != items.end()) ||
+ (std::find(items.begin(), items.end(), JID(jid.getDomain())) != items.end()) ||
+ (std::find(items.begin(), items.end(), jid) != items.end());
+}
diff --git a/Swiften/Client/BlockList.h b/Swiften/Client/BlockList.h
index 39a211d..99c83c1 100644
--- a/Swiften/Client/BlockList.h
+++ b/Swiften/Client/BlockList.h
@@ -6,7 +6,7 @@
#pragma once
-#include <set>
+#include <vector>
#include <Swiften/JID/JID.h>
#include <Swiften/Base/boost_bsignals.h>
@@ -15,15 +15,18 @@ namespace Swift {
class BlockList {
public:
enum State {
+ Init,
Requesting,
Available,
- Error,
+ Error
};
virtual ~BlockList();
virtual State getState() const = 0;
- virtual const std::set<JID>& getItems() const = 0;
+ virtual const std::vector<JID>& getItems() const = 0;
+
+ bool isBlocked(const JID& jid) const;
public:
boost::signal<void ()> onStateChanged;
diff --git a/Swiften/Client/BlockListImpl.cpp b/Swiften/Client/BlockListImpl.cpp
index dfaaaf1..5950233 100644
--- a/Swiften/Client/BlockListImpl.cpp
+++ b/Swiften/Client/BlockListImpl.cpp
@@ -8,30 +8,47 @@
#include <Swiften/Base/foreach.h>
+#include <algorithm>
+
using namespace Swift;
-BlockListImpl::BlockListImpl() {
+BlockListImpl::BlockListImpl() : state(Init) {
}
void BlockListImpl::setItems(const std::vector<JID>& items) {
- this->items = std::set<JID>(items.begin(), items.end());
+ foreach (const JID& jid, this->items) {
+ if (std::find(items.begin(), items.end(), jid) != items.end()) {
+ onItemRemoved(jid);
+ }
+ }
+
+ foreach (const JID& jid, items) {
+ if (std::find(this->items.begin(), this->items.end(), jid) != this->items.end()) {
+ onItemAdded(jid);
+ }
+ }
+ this->items = items;
}
void BlockListImpl::addItem(const JID& item) {
- if (items.insert(item).second) {
+ if (std::find(items.begin(), items.end(), item) == items.end()) {
+ items.push_back(item);
onItemAdded(item);
}
}
void BlockListImpl::removeItem(const JID& item) {
- if (items.erase(item)) {
+ size_t oldSize = items.size();
+ items.erase(std::remove(items.begin(), items.end(), item), items.end());
+ if (items.size() != oldSize) {
onItemRemoved(item);
}
}
void BlockListImpl::setState(State state) {
if (this->state != state) {
+ this->state = state;
onStateChanged();
}
}
@@ -43,14 +60,13 @@ void BlockListImpl::addItems(const std::vector<JID>& items) {
}
void BlockListImpl::removeItems(const std::vector<JID>& items) {
- foreach (const JID& item, items) {
+ std::vector<JID> itemsToRemove = items;
+ foreach (const JID& item, itemsToRemove) {
removeItem(item);
}
}
void BlockListImpl::removeAllItems() {
- foreach (const JID& item, items) {
- removeItem(item);
- }
+ removeItems(items);
}
diff --git a/Swiften/Client/BlockListImpl.h b/Swiften/Client/BlockListImpl.h
index ef08340..2a799ae 100644
--- a/Swiften/Client/BlockListImpl.h
+++ b/Swiften/Client/BlockListImpl.h
@@ -19,7 +19,7 @@ namespace Swift {
void setState(State state);
- virtual const std::set<JID>& getItems() const {
+ virtual const std::vector<JID>& getItems() const {
return items;
}
@@ -32,6 +32,6 @@ namespace Swift {
private:
State state;
- std::set<JID> items;
+ std::vector<JID> items;
};
}
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 1a6c64b..f158370 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2012 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -14,6 +14,7 @@
#include <Swiften/Presence/DirectedPresenceSender.h>
#include <Swiften/MUC/MUCRegistry.h>
#include <Swiften/MUC/MUCManager.h>
+#include <Swiften/PubSub/PubSubManagerImpl.h>
#include <Swiften/Client/MemoryStorages.h>
#include <Swiften/VCards/VCardManager.h>
#include <Swiften/VCards/VCardManager.h>
@@ -30,6 +31,7 @@
#include <Swiften/Network/NetworkFactories.h>
#include <Swiften/FileTransfer/FileTransferManagerImpl.h>
#include <Swiften/Whiteboard/WhiteboardSessionManager.h>
+#include <Swiften/Client/ClientBlockListManager.h>
#ifndef SWIFT_EXPERIMENTAL_FT
#include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h>
#endif
@@ -37,7 +39,7 @@
namespace Swift {
Client::Client(const JID& jid, const SafeString& password, NetworkFactories* networkFactories, Storages* storages) : CoreClient(jid, password, networkFactories), storages(storages) {
- memoryStorages = new MemoryStorages();
+ memoryStorages = new MemoryStorages(networkFactories->getCryptoProvider());
softwareVersionResponder = new SoftwareVersionResponder(getIQRouter());
softwareVersionResponder->start();
@@ -52,14 +54,14 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net
stanzaChannelPresenceSender = new StanzaChannelPresenceSender(getStanzaChannel());
directedPresenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
- discoManager = new ClientDiscoManager(getIQRouter(), directedPresenceSender);
+ discoManager = new ClientDiscoManager(getIQRouter(), directedPresenceSender, networkFactories->getCryptoProvider());
mucRegistry = new MUCRegistry();
mucManager = new MUCManager(getStanzaChannel(), getIQRouter(), directedPresenceSender, mucRegistry);
vcardManager = new VCardManager(jid, getIQRouter(), getStorages()->getVCardStorage());
- avatarManager = new AvatarManagerImpl(vcardManager, getStanzaChannel(), getStorages()->getAvatarStorage(), mucRegistry);
- capsManager = new CapsManager(getStorages()->getCapsStorage(), getStanzaChannel(), getIQRouter());
+ avatarManager = new AvatarManagerImpl(vcardManager, getStanzaChannel(), getStorages()->getAvatarStorage(), networkFactories->getCryptoProvider(), mucRegistry);
+ capsManager = new CapsManager(getStorages()->getCapsStorage(), getStanzaChannel(), getIQRouter(), networkFactories->getCryptoProvider());
entityCapsManager = new EntityCapsManager(capsManager, getStanzaChannel());
nickManager = new NickManagerImpl(jid.toBare(), vcardManager);
@@ -68,15 +70,19 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net
blindCertificateTrustChecker = new BlindCertificateTrustChecker();
jingleSessionManager = new JingleSessionManager(getIQRouter());
+ blockListManager = new ClientBlockListManager(getIQRouter());
fileTransferManager = NULL;
whiteboardSessionManager = NULL;
#ifdef SWIFT_EXPERIMENTAL_WB
whiteboardSessionManager = new WhiteboardSessionManager(getIQRouter(), getStanzaChannel(), presenceOracle, getEntityCapsProvider());
#endif
+
+ pubsubManager = new PubSubManagerImpl(getStanzaChannel(), getIQRouter());
}
Client::~Client() {
+ delete pubsubManager;
delete whiteboardSessionManager;
delete fileTransferManager;
@@ -120,7 +126,18 @@ void Client::setSoftwareVersion(const std::string& name, const std::string& vers
void Client::handleConnected() {
#ifdef SWIFT_EXPERIMENTAL_FT
- fileTransferManager = new FileTransferManagerImpl(getJID(), jingleSessionManager, getIQRouter(), getEntityCapsProvider(), presenceOracle, getNetworkFactories()->getConnectionFactory(), getNetworkFactories()->getConnectionServerFactory(), getNetworkFactories()->getTimerFactory(), getNetworkFactories()->getNATTraverser());
+ fileTransferManager = new FileTransferManagerImpl(
+ getJID(),
+ jingleSessionManager,
+ getIQRouter(),
+ getEntityCapsProvider(),
+ presenceOracle,
+ getNetworkFactories()->getConnectionFactory(),
+ getNetworkFactories()->getConnectionServerFactory(),
+ getNetworkFactories()->getTimerFactory(),
+ getNetworkFactories()->getNetworkEnvironment(),
+ getNetworkFactories()->getNATTraverser(),
+ getNetworkFactories()->getCryptoProvider());
#else
fileTransferManager = new DummyFileTransferManager();
#endif
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 126572a..9253074 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -37,6 +37,8 @@ namespace Swift {
class JingleSessionManager;
class FileTransferManager;
class WhiteboardSessionManager;
+ class ClientBlockListManager;
+ class PubSubManager;
/**
* Provides the core functionality for writing XMPP client software.
@@ -135,6 +137,10 @@ namespace Swift {
ClientDiscoManager* getDiscoManager() const {
return discoManager;
}
+
+ ClientBlockListManager* getClientBlockListManager() const {
+ return blockListManager;
+ }
/**
* Returns a FileTransferManager for the client. This is only available after the onConnected
@@ -153,6 +159,11 @@ namespace Swift {
void setAlwaysTrustCertificates();
WhiteboardSessionManager* getWhiteboardSessionManager() const;
+
+ PubSubManager* getPubSubManager() const {
+ return pubsubManager;
+ }
+
public:
/**
@@ -188,6 +199,8 @@ namespace Swift {
JingleSessionManager* jingleSessionManager;
FileTransferManager* fileTransferManager;
BlindCertificateTrustChecker* blindCertificateTrustChecker;
- WhiteboardSessionManager* whiteboardSessionManager;
+ WhiteboardSessionManager* whiteboardSessionManager;
+ ClientBlockListManager* blockListManager;
+ PubSubManager* pubsubManager;
};
}
diff --git a/Swiften/Client/ClientBlockListManager.cpp b/Swiften/Client/ClientBlockListManager.cpp
index 7222cea..6646a5c 100644
--- a/Swiften/Client/ClientBlockListManager.cpp
+++ b/Swiften/Client/ClientBlockListManager.cpp
@@ -66,11 +66,14 @@ namespace {
}
ClientBlockListManager::ClientBlockListManager(IQRouter* iqRouter) : iqRouter(iqRouter) {
+
}
ClientBlockListManager::~ClientBlockListManager() {
- unblockResponder->stop();
- blockResponder->stop();
+ if (blockList && blockList->getState() == BlockList::Available) {
+ unblockResponder->stop();
+ blockResponder->stop();
+ }
if (getRequest) {
getRequest->onResponse.disconnect(boost::bind(&ClientBlockListManager::handleBlockListReceived, this, _1, _2));
}
@@ -88,13 +91,36 @@ boost::shared_ptr<BlockList> ClientBlockListManager::getBlockList() {
return blockList;
}
+GenericRequest<BlockPayload>::ref ClientBlockListManager::createBlockJIDRequest(const JID& jid) {
+ return createBlockJIDsRequest(std::vector<JID>(1, jid));
+}
+
+GenericRequest<BlockPayload>::ref ClientBlockListManager::createBlockJIDsRequest(const std::vector<JID>& jids) {
+ boost::shared_ptr<BlockPayload> payload = boost::make_shared<BlockPayload>(jids);
+ return boost::make_shared< GenericRequest<BlockPayload> >(IQ::Set, JID(), payload, iqRouter);
+}
+
+GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockJIDRequest(const JID& jid) {
+ return createUnblockJIDsRequest(std::vector<JID>(1, jid));
+}
+
+GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockJIDsRequest(const std::vector<JID>& jids) {
+ boost::shared_ptr<UnblockPayload> payload = boost::make_shared<UnblockPayload>(jids);
+ return boost::make_shared< GenericRequest<UnblockPayload> >(IQ::Set, JID(), payload, iqRouter);
+}
+
+GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockAllRequest() {
+ return createUnblockJIDsRequest(std::vector<JID>());
+}
+
+
void ClientBlockListManager::handleBlockListReceived(boost::shared_ptr<BlockListPayload> payload, ErrorPayload::ref error) {
if (error || !payload) {
blockList->setState(BlockList::Error);
}
else {
- blockList->setState(BlockList::Available);
blockList->setItems(payload->getItems());
+ blockList->setState(BlockList::Available);
blockResponder = boost::make_shared<BlockResponder>(blockList, iqRouter);
blockResponder->start();
unblockResponder = boost::make_shared<UnblockResponder>(blockList, iqRouter);
diff --git a/Swiften/Client/ClientBlockListManager.h b/Swiften/Client/ClientBlockListManager.h
index 21d35e3..e8d4ac6 100644
--- a/Swiften/Client/ClientBlockListManager.h
+++ b/Swiften/Client/ClientBlockListManager.h
@@ -12,6 +12,7 @@
#include <Swiften/Elements/BlockPayload.h>
#include <Swiften/Elements/BlockListPayload.h>
#include <Swiften/Elements/UnblockPayload.h>
+#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Queries/SetResponder.h>
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Client/BlockList.h>
@@ -25,13 +26,18 @@ namespace Swift {
ClientBlockListManager(IQRouter *iqRouter);
~ClientBlockListManager();
- bool isSupported() const;
-
/**
* Returns the blocklist.
*/
boost::shared_ptr<BlockList> getBlockList();
+ GenericRequest<BlockPayload>::ref createBlockJIDRequest(const JID& jid);
+ GenericRequest<BlockPayload>::ref createBlockJIDsRequest(const std::vector<JID>& jids);
+
+ GenericRequest<UnblockPayload>::ref createUnblockJIDRequest(const JID& jid);
+ GenericRequest<UnblockPayload>::ref createUnblockJIDsRequest(const std::vector<JID>& jids);
+ GenericRequest<UnblockPayload>::ref createUnblockAllRequest();
+
private:
void handleBlockListReceived(boost::shared_ptr<BlockListPayload> payload, ErrorPayload::ref);
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 48e38b9..f03cbaa 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -40,6 +40,7 @@
#include <Swiften/SASL/EXTERNALClientAuthenticator.h>
#include <Swiften/SASL/SCRAMSHA1ClientAuthenticator.h>
#include <Swiften/SASL/DIGESTMD5ClientAuthenticator.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/Session/SessionStream.h>
#include <Swiften/TLS/CertificateTrustChecker.h>
#include <Swiften/TLS/ServerIdentityVerifier.h>
@@ -56,10 +57,14 @@ namespace Swift {
ClientSession::ClientSession(
const JID& jid,
- boost::shared_ptr<SessionStream> stream) :
+ boost::shared_ptr<SessionStream> stream,
+ IDNConverter* idnConverter,
+ CryptoProvider* crypto) :
localJID(jid),
state(Initial),
stream(stream),
+ idnConverter(idnConverter),
+ crypto(crypto),
allowPLAINOverNonTLS(false),
useStreamCompression(true),
useTLS(UseTLSWhenAvailable),
@@ -224,7 +229,7 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
plus &= !finishMessage.empty();
}
s << boost::uuids::random_generator()();
- SCRAMSHA1ClientAuthenticator* scramAuthenticator = new SCRAMSHA1ClientAuthenticator(s.str(), plus);
+ SCRAMSHA1ClientAuthenticator* scramAuthenticator = new SCRAMSHA1ClientAuthenticator(s.str(), plus, idnConverter, crypto);
if (plus) {
scramAuthenticator->setTLSChannelBindingData(finishMessage);
}
@@ -237,11 +242,11 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
state = WaitingForCredentials;
onNeedCredentials();
}
- else if (streamFeatures->hasAuthenticationMechanism("DIGEST-MD5") && DIGESTMD5ClientAuthenticator::canBeUsed()) {
+ else if (streamFeatures->hasAuthenticationMechanism("DIGEST-MD5") && crypto->isMD5AllowedForCrypto()) {
std::ostringstream s;
s << boost::uuids::random_generator()();
// FIXME: Host should probably be the actual host
- authenticator = new DIGESTMD5ClientAuthenticator(localJID.getDomain(), s.str());
+ authenticator = new DIGESTMD5ClientAuthenticator(localJID.getDomain(), s.str(), crypto);
state = WaitingForCredentials;
onNeedCredentials();
}
@@ -378,7 +383,7 @@ void ClientSession::handleTLSEncrypted() {
checkTrustOrFinish(certificateChain, verificationError);
}
else {
- ServerIdentityVerifier identityVerifier(localJID);
+ ServerIdentityVerifier identityVerifier(localJID, idnConverter);
if (!certificateChain.empty() && identityVerifier.certificateVerifies(certificateChain[0])) {
continueAfterTLSEncrypted();
}
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index 2553546..4b944fc 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -22,6 +22,8 @@
namespace Swift {
class ClientAuthenticator;
class CertificateTrustChecker;
+ class IDNConverter;
+ class CryptoProvider;
class SWIFTEN_API ClientSession : public boost::enable_shared_from_this<ClientSession> {
public:
@@ -53,7 +55,7 @@ namespace Swift {
SessionStartError,
TLSClientCertificateError,
TLSError,
- StreamError,
+ StreamError
} type;
Error(Type type) : type(type) {}
};
@@ -66,8 +68,8 @@ namespace Swift {
~ClientSession();
- static boost::shared_ptr<ClientSession> create(const JID& jid, boost::shared_ptr<SessionStream> stream) {
- return boost::shared_ptr<ClientSession>(new ClientSession(jid, stream));
+ static boost::shared_ptr<ClientSession> create(const JID& jid, boost::shared_ptr<SessionStream> stream, IDNConverter* idnConverter, CryptoProvider* crypto) {
+ return boost::shared_ptr<ClientSession>(new ClientSession(jid, stream, idnConverter, crypto));
}
State getState() const {
@@ -92,7 +94,9 @@ namespace Swift {
bool getStreamManagementEnabled() const {
- return stanzaAckRequester_;
+ // Explicitly convert to bool. In C++11, it would be cleaner to
+ // compare to nullptr.
+ return static_cast<bool>(stanzaAckRequester_);
}
bool getRosterVersioningSupported() const {
@@ -131,7 +135,9 @@ namespace Swift {
private:
ClientSession(
const JID& jid,
- boost::shared_ptr<SessionStream>);
+ boost::shared_ptr<SessionStream>,
+ IDNConverter* idnConverter,
+ CryptoProvider* crypto);
void finishSession(Error::Type error);
void finishSession(boost::shared_ptr<Swift::Error> error);
@@ -161,6 +167,8 @@ namespace Swift {
JID localJID;
State state;
boost::shared_ptr<SessionStream> stream;
+ IDNConverter* idnConverter;
+ CryptoProvider* crypto;
bool allowPLAINOverNonTLS;
bool useStreamCompression;
UseTLS useTLS;
diff --git a/Swiften/Client/ClientXMLTracer.cpp b/Swiften/Client/ClientXMLTracer.cpp
index 405e3d1..b413f40 100644
--- a/Swiften/Client/ClientXMLTracer.cpp
+++ b/Swiften/Client/ClientXMLTracer.cpp
@@ -9,10 +9,16 @@
#include <iostream>
#include <boost/bind.hpp>
+#include <Swiften/Base/Platform.h>
+
namespace Swift {
ClientXMLTracer::ClientXMLTracer(CoreClient* client, bool bosh) : bosh(bosh) {
+#ifdef SWIFTEN_PLATFORM_WIN32
+ beautifier = new XMLBeautifier(true, false);
+#else
beautifier = new XMLBeautifier(true, true);
+#endif
client->onDataRead.connect(boost::bind(&ClientXMLTracer::printData, this, '<', _1));
client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, this, '>', _1));
}
@@ -25,14 +31,14 @@ void ClientXMLTracer::printData(char direction, const SafeByteArray& data) {
printLine(direction);
if (bosh) {
std::string line = byteArrayToString(ByteArray(data.begin(), data.end()));
- size_t endOfHTTP = line.find("\r\n\r\n");
- if (false && endOfHTTP != std::string::npos) {
- /* Disabled because it swallows bits of XML (namespaces, if I recall) */
- std::cerr << line.substr(0, endOfHTTP) << std::endl << beautifier->beautify(line.substr(endOfHTTP)) << std::endl;
- }
- else {
+// Disabled because it swallows bits of XML (namespaces, if I recall)
+// size_t endOfHTTP = line.find("\r\n\r\n");
+// if (false && endOfHTTP != std::string::npos) {
+// std::cerr << line.substr(0, endOfHTTP) << std::endl << beautifier->beautify(line.substr(endOfHTTP)) << std::endl;
+// }
+// else {
std::cerr << line << std::endl;
- }
+// }
}
else {
std::cerr << beautifier->beautify(byteArrayToString(ByteArray(data.begin(), data.end()))) << std::endl;
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 5e19b4b..4438135 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -142,7 +142,7 @@ void CoreClient::connect(const ClientOptions& o) {
}
void CoreClient::bindSessionToStream() {
- session_ = ClientSession::create(jid_, sessionStream_);
+ session_ = ClientSession::create(jid_, sessionStream_, networkFactories->getIDNConverter(), networkFactories->getCryptoProvider());
session_->setCertificateTrustChecker(certificateTrustChecker);
session_->setUseStreamCompression(options.useStreamCompression);
session_->setAllowPLAINOverNonTLS(options.allowPLAINWithoutTLS);
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index c9da0eb..eadfd9d 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -50,7 +50,6 @@ namespace Swift {
public:
/**
* Constructs a client for the given JID with the given password.
- * The given eventLoop will be used to post events to.
*/
CoreClient(const JID& jid, const SafeByteArray& password, NetworkFactories* networkFactories);
~CoreClient();
@@ -204,7 +203,7 @@ namespace Swift {
/**
* Called before onConnected signal is emmitted.
*/
- virtual void handleConnected() {};
+ virtual void handleConnected() {}
private:
void handleConnectorFinished(boost::shared_ptr<Connection>, boost::shared_ptr<Error> error);
diff --git a/Swiften/Client/MemoryStorages.cpp b/Swiften/Client/MemoryStorages.cpp
index 703e9ff..885d74f 100644
--- a/Swiften/Client/MemoryStorages.cpp
+++ b/Swiften/Client/MemoryStorages.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.
*/
@@ -13,8 +13,8 @@
namespace Swift {
-MemoryStorages::MemoryStorages() {
- vcardStorage = new VCardMemoryStorage();
+MemoryStorages::MemoryStorages(CryptoProvider* crypto) {
+ vcardStorage = new VCardMemoryStorage(crypto);
capsStorage = new CapsMemoryStorage();
avatarStorage = new AvatarMemoryStorage();
rosterStorage = new RosterMemoryStorage();
diff --git a/Swiften/Client/MemoryStorages.h b/Swiften/Client/MemoryStorages.h
index 403a89a..68ec285 100644
--- a/Swiften/Client/MemoryStorages.h
+++ b/Swiften/Client/MemoryStorages.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.
*/
@@ -10,6 +10,7 @@
namespace Swift {
class VCardMemoryStorage;
+ class CryptoProvider;
/**
* An implementation of Storages for storing all
@@ -17,7 +18,7 @@ namespace Swift {
*/
class MemoryStorages : public Storages {
public:
- MemoryStorages();
+ MemoryStorages(CryptoProvider*);
~MemoryStorages();
virtual VCardStorage* getVCardStorage() const;
diff --git a/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp
new file mode 100644
index 0000000..9010042
--- /dev/null
+++ b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <algorithm>
+
+#include <Swiften/Base/foreach.h>
+
+#include <Swiften/Client/StanzaChannel.h>
+#include <Swiften/Client/DummyStanzaChannel.h>
+#include <Swiften/Client/ClientBlockListManager.h>
+#include <Swiften/Queries/IQRouter.h>
+#include <Swiften/Elements/IQ.h>
+
+using namespace Swift;
+
+class ClientBlockListManagerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(ClientBlockListManagerTest);
+ CPPUNIT_TEST(testFetchBlockList);
+ CPPUNIT_TEST(testBlockCommand);
+ CPPUNIT_TEST(testUnblockCommand);
+ CPPUNIT_TEST(testUnblockAllCommand);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ ownJID_ = JID("kev@wonderland.lit");
+ stanzaChannel_ = new DummyStanzaChannel();
+ iqRouter_ = new IQRouter(stanzaChannel_);
+ iqRouter_->setJID(ownJID_);
+ clientBlockListManager_ = new ClientBlockListManager(iqRouter_);
+ }
+
+ void testFetchBlockList() {
+ std::vector<JID> blockJids;
+ blockJids.push_back(JID("romeo@montague.net"));
+ blockJids.push_back(JID("iago@shakespeare.lit"));
+ helperInitialBlockListFetch(blockJids);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), clientBlockListManager_->getBlockList()->getItems().size());
+ }
+
+ void testBlockCommand() {
+ // start with an already fetched block list
+ helperInitialBlockListFetch(std::vector<JID>(1, JID("iago@shakespeare.lit")));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), clientBlockListManager_->getBlockList()->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState());
+
+ GenericRequest<BlockPayload>::ref blockRequest = clientBlockListManager_->createBlockJIDRequest(JID("romeo@montague.net"));
+ blockRequest->send();
+ IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(2);
+ CPPUNIT_ASSERT(request.get() != NULL);
+ boost::shared_ptr<BlockPayload> blockPayload = request->getPayload<BlockPayload>();
+ CPPUNIT_ASSERT(blockPayload.get() != NULL);
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), blockPayload->getItems().at(0));
+
+ IQ::ref blockRequestResponse = IQ::createResult(request->getFrom(), JID(), request->getID());
+ stanzaChannel_->sendIQ(blockRequestResponse);
+ stanzaChannel_->onIQReceived(blockRequestResponse);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), clientBlockListManager_->getBlockList()->getItems().size());
+
+ // send block push
+ boost::shared_ptr<BlockPayload> pushPayload = boost::make_shared<BlockPayload>();
+ pushPayload->addItem(JID("romeo@montague.net"));
+ IQ::ref blockPush = IQ::createRequest(IQ::Set, ownJID_, "push1", pushPayload);
+ stanzaChannel_->sendIQ(blockPush);
+ stanzaChannel_->onIQReceived(blockPush);
+
+ std::vector<JID> blockedJIDs = clientBlockListManager_->getBlockList()->getItems();
+ CPPUNIT_ASSERT(blockedJIDs.end() != std::find(blockedJIDs.begin(), blockedJIDs.end(), JID("romeo@montague.net")));
+ }
+
+ void testUnblockCommand() {
+ // start with an already fetched block list
+ std::vector<JID> initialBlockList = std::vector<JID>(1, JID("iago@shakespeare.lit"));
+ initialBlockList.push_back(JID("romeo@montague.net"));
+ helperInitialBlockListFetch(initialBlockList);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), clientBlockListManager_->getBlockList()->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState());
+
+ GenericRequest<UnblockPayload>::ref unblockRequest = clientBlockListManager_->createUnblockJIDRequest(JID("romeo@montague.net"));
+ unblockRequest->send();
+ IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(2);
+ CPPUNIT_ASSERT(request.get() != NULL);
+ boost::shared_ptr<UnblockPayload> unblockPayload = request->getPayload<UnblockPayload>();
+ CPPUNIT_ASSERT(unblockPayload.get() != NULL);
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), unblockPayload->getItems().at(0));
+
+ IQ::ref unblockRequestResponse = IQ::createResult(request->getFrom(), JID(), request->getID());
+ stanzaChannel_->sendIQ(unblockRequestResponse);
+ stanzaChannel_->onIQReceived(unblockRequestResponse);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), clientBlockListManager_->getBlockList()->getItems().size());
+
+ // send block push
+ boost::shared_ptr<UnblockPayload> pushPayload = boost::make_shared<UnblockPayload>();
+ pushPayload->addItem(JID("romeo@montague.net"));
+ IQ::ref unblockPush = IQ::createRequest(IQ::Set, ownJID_, "push1", pushPayload);
+ stanzaChannel_->sendIQ(unblockPush);
+ stanzaChannel_->onIQReceived(unblockPush);
+
+ std::vector<JID> blockedJIDs = clientBlockListManager_->getBlockList()->getItems();
+ CPPUNIT_ASSERT(blockedJIDs.end() == std::find(blockedJIDs.begin(), blockedJIDs.end(), JID("romeo@montague.net")));
+ }
+
+ void testUnblockAllCommand() {
+ // start with an already fetched block list
+ std::vector<JID> initialBlockList = std::vector<JID>(1, JID("iago@shakespeare.lit"));
+ initialBlockList.push_back(JID("romeo@montague.net"));
+ initialBlockList.push_back(JID("benvolio@montague.net"));
+ helperInitialBlockListFetch(initialBlockList);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), clientBlockListManager_->getBlockList()->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState());
+
+ GenericRequest<UnblockPayload>::ref unblockRequest = clientBlockListManager_->createUnblockAllRequest();
+ unblockRequest->send();
+ IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(2);
+ CPPUNIT_ASSERT(request.get() != NULL);
+ boost::shared_ptr<UnblockPayload> unblockPayload = request->getPayload<UnblockPayload>();
+ CPPUNIT_ASSERT(unblockPayload.get() != NULL);
+ CPPUNIT_ASSERT_EQUAL(true, unblockPayload->getItems().empty());
+
+ IQ::ref unblockRequestResponse = IQ::createResult(request->getFrom(), JID(), request->getID());
+ stanzaChannel_->sendIQ(unblockRequestResponse);
+ stanzaChannel_->onIQReceived(unblockRequestResponse);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), clientBlockListManager_->getBlockList()->getItems().size());
+
+ // send block push
+ boost::shared_ptr<UnblockPayload> pushPayload = boost::make_shared<UnblockPayload>();
+ IQ::ref unblockPush = IQ::createRequest(IQ::Set, ownJID_, "push1", pushPayload);
+ stanzaChannel_->sendIQ(unblockPush);
+ stanzaChannel_->onIQReceived(unblockPush);
+
+ CPPUNIT_ASSERT_EQUAL(true, clientBlockListManager_->getBlockList()->getItems().empty());
+ }
+
+ void tearDown() {
+ delete clientBlockListManager_;
+ delete iqRouter_;
+ delete stanzaChannel_;
+ }
+
+ private:
+ void helperInitialBlockListFetch(const std::vector<JID>& blockedJids) {
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ CPPUNIT_ASSERT(blockList);
+
+ // check for IQ request
+ IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(0);
+ CPPUNIT_ASSERT(request.get() != NULL);
+ boost::shared_ptr<BlockListPayload> requestPayload = request->getPayload<BlockListPayload>();
+ CPPUNIT_ASSERT(requestPayload.get() != NULL);
+
+ CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, blockList->getState());
+ CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, clientBlockListManager_->getBlockList()->getState());
+
+ // build IQ response
+ boost::shared_ptr<BlockListPayload> responsePayload = boost::make_shared<BlockListPayload>();
+ foreach(const JID& jid, blockedJids) {
+ responsePayload->addItem(jid);
+ }
+
+ IQ::ref response = IQ::createResult(ownJID_, JID(), request->getID(), responsePayload);
+ stanzaChannel_->sendIQ(response);
+ stanzaChannel_->onIQReceived(response);
+
+ CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState());
+ CPPUNIT_ASSERT(responsePayload->getItems() == clientBlockListManager_->getBlockList()->getItems());
+ }
+
+
+ private:
+ JID ownJID_;
+ IQRouter* iqRouter_;
+ DummyStanzaChannel* stanzaChannel_;
+ ClientBlockListManager* clientBlockListManager_;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ClientBlockListManagerTest);
+
diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp
index a8cd53c..4ef6727 100644
--- a/Swiften/Client/UnitTest/ClientSessionTest.cpp
+++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp
@@ -11,6 +11,8 @@
#include <boost/optional.hpp>
#include <boost/smart_ptr/make_shared.hpp>
+#include <Swiften/IDN/IDNConverter.h>
+#include <Swiften/IDN/PlatformIDNConverter.h>
#include <Swiften/Session/SessionStream.h>
#include <Swiften/Client/ClientSession.h>
#include <Swiften/Elements/Message.h>
@@ -31,6 +33,8 @@
#include <Swiften/Elements/ResourceBind.h>
#include <Swiften/TLS/SimpleCertificate.h>
#include <Swiften/TLS/BlindCertificateTrustChecker.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -69,6 +73,8 @@ class ClientSessionTest : public CppUnit::TestFixture {
public:
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+ idnConverter = boost::shared_ptr<IDNConverter>(PlatformIDNConverter::create());
server = boost::make_shared<MockSessionStream>();
sessionFinishedReceived = false;
needCredentials = false;
@@ -339,7 +345,7 @@ class ClientSessionTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<ClientSession> createSession() {
- boost::shared_ptr<ClientSession> session = ClientSession::create(JID("me@foo.com"), server);
+ boost::shared_ptr<ClientSession> session = ClientSession::create(JID("me@foo.com"), server, idnConverter.get(), crypto.get());
session->onFinished.connect(boost::bind(&ClientSessionTest::handleSessionFinished, this, _1));
session->onNeedCredentials.connect(boost::bind(&ClientSessionTest::handleSessionNeedCredentials, this));
session->setAllowPLAINOverNonTLS(true);
@@ -616,11 +622,13 @@ class ClientSessionTest : public CppUnit::TestFixture {
std::deque<Event> receivedEvents;
};
+ boost::shared_ptr<IDNConverter> idnConverter;
boost::shared_ptr<MockSessionStream> server;
bool sessionFinishedReceived;
bool needCredentials;
boost::shared_ptr<Error> sessionFinishedError;
BlindCertificateTrustChecker* blindCertificateTrustChecker;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ClientSessionTest);
diff --git a/Swiften/Client/UnitTest/NickResolverTest.cpp b/Swiften/Client/UnitTest/NickResolverTest.cpp
index dfc90fe..a8b011c 100644
--- a/Swiften/Client/UnitTest/NickResolverTest.cpp
+++ b/Swiften/Client/UnitTest/NickResolverTest.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -14,6 +20,8 @@
#include <Swiften/VCards/VCardMemoryStorage.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Client/DummyStanzaChannel.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -34,11 +42,12 @@ class NickResolverTest : public CppUnit::TestFixture {
public:
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
ownJID_ = JID("kev@wonderland.lit");
xmppRoster_ = new XMPPRosterImpl();
stanzaChannel_ = new DummyStanzaChannel();
iqRouter_ = new IQRouter(stanzaChannel_);
- vCardStorage_ = new VCardMemoryStorage();
+ vCardStorage_ = new VCardMemoryStorage(crypto.get());
vCardManager_ = new VCardManager(ownJID_, iqRouter_, vCardStorage_);
registry_ = new MUCRegistry();
resolver_ = new NickResolver(ownJID_, xmppRoster_, vCardManager_, registry_);
@@ -144,7 +153,7 @@ class NickResolverTest : public CppUnit::TestFixture {
MUCRegistry* registry_;
NickResolver* resolver_;
JID ownJID_;
-
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(NickResolverTest);