summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Storages')
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.cpp10
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.h7
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorage.cpp13
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorage.h6
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorageFactory.h8
-rw-r--r--Swift/Controllers/Storages/FileStorages.cpp13
-rw-r--r--Swift/Controllers/Storages/FileStorages.h7
-rw-r--r--Swift/Controllers/Storages/FileStoragesFactory.h9
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.cpp9
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.h7
10 files changed, 53 insertions, 36 deletions
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp
index b39e586..671e0cb 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.cpp
+++ b/Swift/Controllers/Storages/AvatarFileStorage.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,12 +12,12 @@
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/String.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Crypto/CryptoProvider.h>
namespace Swift {
-AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile) : avatarsDir(avatarsDir), avatarsFile(avatarsFile) {
+AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto) : avatarsDir(avatarsDir), avatarsFile(avatarsFile), crypto(crypto) {
if (boost::filesystem::exists(avatarsFile)) {
try {
boost::filesystem::ifstream file(avatarsFile);
@@ -47,7 +47,7 @@ bool AvatarFileStorage::hasAvatar(const std::string& hash) const {
}
void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) {
- assert(Hexify::hexify(SHA1::getHash(avatar)) == hash);
+ assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash);
boost::filesystem::path avatarPath = getAvatarPath(hash);
if (!boost::filesystem::exists(avatarPath.parent_path())) {
@@ -69,7 +69,7 @@ boost::filesystem::path AvatarFileStorage::getAvatarPath(const std::string& hash
ByteArray AvatarFileStorage::getAvatar(const std::string& hash) const {
ByteArray data;
- readByteArrayFromFile(data, getAvatarPath(hash).string());
+ readByteArrayFromFile(data, getAvatarPath(hash));
return data;
}
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.h b/Swift/Controllers/Storages/AvatarFileStorage.h
index b7e73f5..85a6463 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.h
+++ b/Swift/Controllers/Storages/AvatarFileStorage.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.
*/
@@ -15,9 +15,11 @@
#include "Swiften/Avatars/AvatarStorage.h"
namespace Swift {
+ class CryptoProvider;
+
class AvatarFileStorage : public AvatarStorage {
public:
- AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile);
+ AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto);
virtual bool hasAvatar(const std::string& hash) const;
virtual void addAvatar(const std::string& hash, const ByteArray& avatar);
@@ -34,6 +36,7 @@ namespace Swift {
private:
boost::filesystem::path avatarsDir;
boost::filesystem::path avatarsFile;
+ CryptoProvider* crypto;
typedef std::map<JID, std::string> JIDAvatarMap;
JIDAvatarMap jidAvatars;
};
diff --git a/Swift/Controllers/Storages/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp
index a4a95c7..34d1f76 100644
--- a/Swift/Controllers/Storages/CertificateFileStorage.cpp
+++ b/Swift/Controllers/Storages/CertificateFileStorage.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.
*/
@@ -8,22 +8,23 @@
#include <iostream>
#include <boost/filesystem/fstream.hpp>
+#include <boost/numeric/conversion/cast.hpp>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/TLS/CertificateFactory.h>
#include <Swiften/Base/Log.h>
+#include <Swiften/Crypto/CryptoProvider.h>
namespace Swift {
-CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory) : path(path), certificateFactory(certificateFactory) {
+CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto) : path(path), certificateFactory(certificateFactory), crypto(crypto) {
}
bool CertificateFileStorage::hasCertificate(Certificate::ref certificate) const {
boost::filesystem::path certificatePath = getCertificatePath(certificate);
if (boost::filesystem::exists(certificatePath)) {
ByteArray data;
- readByteArrayFromFile(data, certificatePath.string());
+ readByteArrayFromFile(data, certificatePath);
Certificate::ref storedCertificate = certificateFactory->createCertificateFromDER(data);
if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) {
return true;
@@ -50,12 +51,12 @@ void CertificateFileStorage::addCertificate(Certificate::ref certificate) {
}
boost::filesystem::ofstream file(certificatePath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
ByteArray data = certificate->toDER();
- file.write(reinterpret_cast<const char*>(vecptr(data)), data.size());
+ file.write(reinterpret_cast<const char*>(vecptr(data)), boost::numeric_cast<std::streamsize>(data.size()));
file.close();
}
boost::filesystem::path CertificateFileStorage::getCertificatePath(Certificate::ref certificate) const {
- return path / Hexify::hexify(SHA1::getHash(certificate->toDER()));
+ return path / Hexify::hexify(crypto->getSHA1Hash(certificate->toDER()));
}
}
diff --git a/Swift/Controllers/Storages/CertificateFileStorage.h b/Swift/Controllers/Storages/CertificateFileStorage.h
index f7a60b9..12151d0 100644
--- a/Swift/Controllers/Storages/CertificateFileStorage.h
+++ b/Swift/Controllers/Storages/CertificateFileStorage.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.
*/
@@ -12,10 +12,11 @@
namespace Swift {
class CertificateFactory;
+ class CryptoProvider;
class CertificateFileStorage : public CertificateStorage {
public:
- CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory);
+ CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto);
virtual bool hasCertificate(Certificate::ref certificate) const;
virtual void addCertificate(Certificate::ref certificate);
@@ -26,6 +27,7 @@ namespace Swift {
private:
boost::filesystem::path path;
CertificateFactory* certificateFactory;
+ CryptoProvider* crypto;
};
}
diff --git a/Swift/Controllers/Storages/CertificateFileStorageFactory.h b/Swift/Controllers/Storages/CertificateFileStorageFactory.h
index b215165..6834619 100644
--- a/Swift/Controllers/Storages/CertificateFileStorageFactory.h
+++ b/Swift/Controllers/Storages/CertificateFileStorageFactory.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.
*/
@@ -11,18 +11,20 @@
namespace Swift {
class CertificateFactory;
+ class CryptoProvider;
class CertificateFileStorageFactory : public CertificateStorageFactory {
public:
- CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory) : basePath(basePath), certificateFactory(certificateFactory) {}
+ CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory, CryptoProvider* crypto) : basePath(basePath), certificateFactory(certificateFactory), crypto(crypto) {}
virtual CertificateStorage* createCertificateStorage(const JID& profile) const {
boost::filesystem::path profilePath = basePath / profile.toString();
- return new CertificateFileStorage(profilePath / "certificates", certificateFactory);
+ return new CertificateFileStorage(profilePath / "certificates", certificateFactory, crypto);
}
private:
boost::filesystem::path basePath;
CertificateFactory* certificateFactory;
+ CryptoProvider* crypto;
};
}
diff --git a/Swift/Controllers/Storages/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp
index cff87d3..52a5e00 100644
--- a/Swift/Controllers/Storages/FileStorages.cpp
+++ b/Swift/Controllers/Storages/FileStorages.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.
*/
@@ -10,17 +10,18 @@
#include "Swift/Controllers/Storages/CapsFileStorage.h"
#include "Swift/Controllers/Storages/RosterFileStorage.h"
#include <Swiften/History/SQLiteHistoryStorage.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
-FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid) {
- std::string profile = jid.toBare();
- vcardStorage = new VCardFileStorage(baseDir / profile / "vcards");
+FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider* crypto) {
+ boost::filesystem::path profile = stringToPath(jid.toBare());
+ vcardStorage = new VCardFileStorage(baseDir / profile / "vcards", crypto);
capsStorage = new CapsFileStorage(baseDir / "caps");
- avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars");
+ avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars", crypto);
rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml");
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- historyStorage = new SQLiteHistoryStorage((baseDir / "history.db").string());
+ historyStorage = new SQLiteHistoryStorage(baseDir / "history.db");
#endif
}
diff --git a/Swift/Controllers/Storages/FileStorages.h b/Swift/Controllers/Storages/FileStorages.h
index 5e89db8..1e914b9 100644
--- a/Swift/Controllers/Storages/FileStorages.h
+++ b/Swift/Controllers/Storages/FileStorages.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.
*/
@@ -8,7 +8,7 @@
#include <boost/filesystem/path.hpp>
-#include "Swiften/Client/Storages.h"
+#include <Swiften/Client/Storages.h>
namespace Swift {
class VCardFileStorage;
@@ -17,6 +17,7 @@ namespace Swift {
class RosterFileStorage;
class HistoryStorage;
class JID;
+ class CryptoProvider;
/**
* A storages implementation that stores all controller data on disk.
@@ -37,7 +38,7 @@ namespace Swift {
* \param jid the subdir in which profile-specific data will be stored.
* The bare JID will be used as the subdir name.
*/
- FileStorages(const boost::filesystem::path& baseDir, const JID& jid);
+ FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider*);
~FileStorages();
virtual VCardStorage* getVCardStorage() const;
diff --git a/Swift/Controllers/Storages/FileStoragesFactory.h b/Swift/Controllers/Storages/FileStoragesFactory.h
index 0676bc3..c119dcf 100644
--- a/Swift/Controllers/Storages/FileStoragesFactory.h
+++ b/Swift/Controllers/Storages/FileStoragesFactory.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,15 +10,18 @@
#include "Swift/Controllers/Storages/FileStorages.h"
namespace Swift {
+ class CryptoProvider;
+
class FileStoragesFactory : public StoragesFactory {
public:
- FileStoragesFactory(const boost::filesystem::path& basePath) : basePath(basePath) {}
+ FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {}
virtual Storages* createStorages(const JID& profile) const {
- return new FileStorages(basePath, profile);
+ return new FileStorages(basePath, profile, crypto);
}
private:
boost::filesystem::path basePath;
+ CryptoProvider* crypto;
};
}
diff --git a/Swift/Controllers/Storages/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp
index d799a90..b22e235 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.cpp
+++ b/Swift/Controllers/Storages/VCardFileStorage.cpp
@@ -13,8 +13,9 @@
#include <Swiften/Entity/GenericPayloadPersister.h>
#include <Swiften/Base/String.h>
#include <Swiften/StringCodecs/Hexify.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Path.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/VCard.h"
#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h"
@@ -25,7 +26,7 @@ using namespace Swift;
typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister;
-VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) {
+VCardFileStorage::VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto) : VCardStorage(crypto), vcardsPath(dir), crypto(crypto) {
cacheFile = vcardsPath / "phashes";
if (boost::filesystem::exists(cacheFile)) {
try {
@@ -66,7 +67,7 @@ boost::filesystem::path VCardFileStorage::getVCardPath(const JID& jid) const {
try {
std::string file(jid.toString());
String::replaceAll(file, '/', "%2f");
- return boost::filesystem::path(vcardsPath / (file + ".xml"));
+ return boost::filesystem::path(vcardsPath / stringToPath(file + ".xml"));
}
catch (const boost::filesystem::filesystem_error& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
@@ -88,7 +89,7 @@ std::string VCardFileStorage::getPhotoHash(const JID& jid) const {
std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref vCard) const {
std::string hash;
if (vCard && !vCard->getPhoto().empty()) {
- hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
}
std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash));
if (r.second) {
diff --git a/Swift/Controllers/Storages/VCardFileStorage.h b/Swift/Controllers/Storages/VCardFileStorage.h
index ba422f4..2c3af3d 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.h
+++ b/Swift/Controllers/Storages/VCardFileStorage.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.
*/
@@ -14,9 +14,11 @@
#include "Swiften/VCards/VCardStorage.h"
namespace Swift {
+ class CryptoProvider;
+
class VCardFileStorage : public VCardStorage {
public:
- VCardFileStorage(boost::filesystem::path dir);
+ VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto);
virtual VCard::ref getVCard(const JID& jid) const;
virtual void setVCard(const JID& jid, VCard::ref v);
@@ -31,6 +33,7 @@ namespace Swift {
private:
boost::filesystem::path vcardsPath;
+ CryptoProvider* crypto;
boost::filesystem::path cacheFile;
typedef std::map<JID, std::string> PhotoHashMap;
mutable PhotoHashMap photoHashes;