summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-05-15 19:44:37 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-05-17 19:00:55 (GMT)
commitde39ce6ec44647cee92853e2928cf5475af992e6 (patch)
tree1f86dd075900aeeb9b91cdd120d71052458ca6ff /Swift/Controllers/Storages
parent927d62cc54c8a5087dba6b61afa9ad30dc528a23 (diff)
downloadswift-de39ce6ec44647cee92853e2928cf5475af992e6.zip
swift-de39ce6ec44647cee92853e2928cf5475af992e6.tar.bz2
Fixed unicode path handling.
- Use boost::filesystem::path consistently for referring to files. - Use boost::filesystem streams for I/O, such that paths are always handled correctly. - Use stringToPath and pathToString for conversion between strings and boost::filesystem::path, to ensure we have consistent unicode handling across platforms and environments. The default constructor and string conversion uses platform-dependent encoding, depending on the global locale set in the application, which causes problems. So, unless you are in platform dependent code, the default constructor and string() function should not be used. When constructing paths from other paths (e.g. using operator/), also use stringToPath (instead of string arguments) if the path can contain unicode characters. Change-Id: If286bd9e71c8414afc0b24ba67e26ab7608ef6ea
Diffstat (limited to 'Swift/Controllers/Storages')
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.cpp2
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorage.cpp2
-rw-r--r--Swift/Controllers/Storages/FileStorages.cpp5
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.cpp3
4 files changed, 7 insertions, 5 deletions
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp
index 792b77b..671e0cb 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.cpp
+++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp
@@ -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/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp
index b5e85d2..34d1f76 100644
--- a/Swift/Controllers/Storages/CertificateFileStorage.cpp
+++ b/Swift/Controllers/Storages/CertificateFileStorage.cpp
@@ -24,7 +24,7 @@ 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;
diff --git a/Swift/Controllers/Storages/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp
index 357c213..52a5e00 100644
--- a/Swift/Controllers/Storages/FileStorages.cpp
+++ b/Swift/Controllers/Storages/FileStorages.cpp
@@ -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, CryptoProvider* crypto) {
- std::string profile = jid.toBare();
+ 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", 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/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp
index 633ed58..b22e235 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.cpp
+++ b/Swift/Controllers/Storages/VCardFileStorage.cpp
@@ -14,6 +14,7 @@
#include <Swiften/Base/String.h>
#include <Swiften/StringCodecs/Hexify.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"
@@ -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;