diff options
| author | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) | 
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) | 
| commit | cfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch) | |
| tree | 18d94153a302445196fc0c18586abf44a1ce4a38 /Swift/Controllers/Storages | |
| parent | 1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff) | |
| download | swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2  | |
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines
in the process.
Changed CheckTabs.py tool to disallow hard tabs in source
files.
Test-Information:
Manually checked 30 random files that the conversion worked
as expected.
Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swift/Controllers/Storages')
21 files changed, 391 insertions, 391 deletions
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp index 56e27e1..cded945 100644 --- a/Swift/Controllers/Storages/AvatarFileStorage.cpp +++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp @@ -19,88 +19,88 @@  namespace Swift {  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); -			std::string line; -			if (file.is_open()) { -				while (!file.eof()) { -					getline(file, line); -					std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' '); -					JID jid(r.second); -					if (jid.isValid()) { -						jidAvatars.insert(std::make_pair(jid, r.first)); -					} -					else if (!r.first.empty() || !r.second.empty()) { -						std::cerr << "Invalid entry in avatars file: " << r.second << std::endl; -					} -				} -			} -		} -		catch (...) { -			std::cerr << "Error reading avatars file" << std::endl; -		} -	} +    if (boost::filesystem::exists(avatarsFile)) { +        try { +            boost::filesystem::ifstream file(avatarsFile); +            std::string line; +            if (file.is_open()) { +                while (!file.eof()) { +                    getline(file, line); +                    std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' '); +                    JID jid(r.second); +                    if (jid.isValid()) { +                        jidAvatars.insert(std::make_pair(jid, r.first)); +                    } +                    else if (!r.first.empty() || !r.second.empty()) { +                        std::cerr << "Invalid entry in avatars file: " << r.second << std::endl; +                    } +                } +            } +        } +        catch (...) { +            std::cerr << "Error reading avatars file" << std::endl; +        } +    }  } -bool AvatarFileStorage::hasAvatar(const std::string& hash) const {  -	return boost::filesystem::exists(getAvatarPath(hash)); +bool AvatarFileStorage::hasAvatar(const std::string& hash) const { +    return boost::filesystem::exists(getAvatarPath(hash));  }  void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) { -	assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash); +    assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash); -	boost::filesystem::path avatarPath = getAvatarPath(hash); -	if (!boost::filesystem::exists(avatarPath.parent_path())) { -		try { -			boost::filesystem::create_directories(avatarPath.parent_path()); -		} -		catch (const boost::filesystem::filesystem_error& e) { -			std::cerr << "ERROR: " << e.what() << std::endl; -		} -	} -	boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out); -	file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size())); -	file.close(); +    boost::filesystem::path avatarPath = getAvatarPath(hash); +    if (!boost::filesystem::exists(avatarPath.parent_path())) { +        try { +            boost::filesystem::create_directories(avatarPath.parent_path()); +        } +        catch (const boost::filesystem::filesystem_error& e) { +            std::cerr << "ERROR: " << e.what() << std::endl; +        } +    } +    boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out); +    file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size())); +    file.close();  }  boost::filesystem::path AvatarFileStorage::getAvatarPath(const std::string& hash) const { -	return avatarsDir / hash; +    return avatarsDir / hash;  }  ByteArray AvatarFileStorage::getAvatar(const std::string& hash) const { -	ByteArray data; -	readByteArrayFromFile(data, getAvatarPath(hash)); -	return data; +    ByteArray data; +    readByteArrayFromFile(data, getAvatarPath(hash)); +    return data;  }  void AvatarFileStorage::setAvatarForJID(const JID& jid, const std::string& hash) { -	std::pair<JIDAvatarMap::iterator, bool> r = jidAvatars.insert(std::make_pair(jid, hash)); -	if (r.second) { -		saveJIDAvatars(); -	} -	else if (r.first->second != hash) { -		r.first->second = hash; -		saveJIDAvatars(); -	} +    std::pair<JIDAvatarMap::iterator, bool> r = jidAvatars.insert(std::make_pair(jid, hash)); +    if (r.second) { +        saveJIDAvatars(); +    } +    else if (r.first->second != hash) { +        r.first->second = hash; +        saveJIDAvatars(); +    }  }  std::string AvatarFileStorage::getAvatarForJID(const JID& jid) const { -	JIDAvatarMap::const_iterator i = jidAvatars.find(jid); -	return i == jidAvatars.end() ? "" : i->second; +    JIDAvatarMap::const_iterator i = jidAvatars.find(jid); +    return i == jidAvatars.end() ? "" : i->second;  }  void AvatarFileStorage::saveJIDAvatars() { -	try { -		boost::filesystem::ofstream file(avatarsFile); -		for (JIDAvatarMap::const_iterator i = jidAvatars.begin(); i != jidAvatars.end(); ++i) { -			file << i->second << " " << i->first.toString() << std::endl; -		} -		file.close(); -	} -	catch (...) { -		std::cerr << "Error writing avatars file" << std::endl; -	} +    try { +        boost::filesystem::ofstream file(avatarsFile); +        for (JIDAvatarMap::const_iterator i = jidAvatars.begin(); i != jidAvatars.end(); ++i) { +            file << i->second << " " << i->first.toString() << std::endl; +        } +        file.close(); +    } +    catch (...) { +        std::cerr << "Error writing avatars file" << std::endl; +    }  }  } diff --git a/Swift/Controllers/Storages/AvatarFileStorage.h b/Swift/Controllers/Storages/AvatarFileStorage.h index 9c6f617..41c7106 100644 --- a/Swift/Controllers/Storages/AvatarFileStorage.h +++ b/Swift/Controllers/Storages/AvatarFileStorage.h @@ -16,30 +16,30 @@  #include <Swiften/JID/JID.h>  namespace Swift { -	class CryptoProvider; +    class CryptoProvider; -	class AvatarFileStorage : public AvatarStorage { -		public: -			AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto); +    class AvatarFileStorage : public AvatarStorage { +        public: +            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); -			virtual ByteArray getAvatar(const std::string& hash) const; +            virtual bool hasAvatar(const std::string& hash) const; +            virtual void addAvatar(const std::string& hash, const ByteArray& avatar); +            virtual ByteArray getAvatar(const std::string& hash) const; -			virtual boost::filesystem::path getAvatarPath(const std::string& hash) const; +            virtual boost::filesystem::path getAvatarPath(const std::string& hash) const; -			virtual void setAvatarForJID(const JID& jid, const std::string& hash); -			virtual std::string getAvatarForJID(const JID& jid) const; +            virtual void setAvatarForJID(const JID& jid, const std::string& hash); +            virtual std::string getAvatarForJID(const JID& jid) const; -		private: -			void saveJIDAvatars(); +        private: +            void saveJIDAvatars(); -		private: -			boost::filesystem::path avatarsDir; -			boost::filesystem::path avatarsFile; -			CryptoProvider* crypto; -			typedef std::map<JID, std::string> JIDAvatarMap; -			JIDAvatarMap jidAvatars; -	}; +        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/CapsFileStorage.cpp b/Swift/Controllers/Storages/CapsFileStorage.cpp index 7b99fe0..21a99bc 100644 --- a/Swift/Controllers/Storages/CapsFileStorage.cpp +++ b/Swift/Controllers/Storages/CapsFileStorage.cpp @@ -20,15 +20,15 @@ CapsFileStorage::CapsFileStorage(const boost::filesystem::path& path) : path(pat  }  DiscoInfo::ref CapsFileStorage::getDiscoInfo(const std::string& hash) const { -	return DiscoInfoPersister().loadPayloadGeneric(getCapsPath(hash)); +    return DiscoInfoPersister().loadPayloadGeneric(getCapsPath(hash));  }  void CapsFileStorage::setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo) { -	DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get())); -	bareDiscoInfo->setNode(""); -	DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash)); +    DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get())); +    bareDiscoInfo->setNode(""); +    DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash));  }  boost::filesystem::path CapsFileStorage::getCapsPath(const std::string& hash) const { -	return path / (Hexify::hexify(Base64::decode(hash)) + ".xml"); +    return path / (Hexify::hexify(Base64::decode(hash)) + ".xml");  } diff --git a/Swift/Controllers/Storages/CapsFileStorage.h b/Swift/Controllers/Storages/CapsFileStorage.h index 06dfd91..7df23f1 100644 --- a/Swift/Controllers/Storages/CapsFileStorage.h +++ b/Swift/Controllers/Storages/CapsFileStorage.h @@ -13,17 +13,17 @@  #include <Swiften/Disco/CapsStorage.h>  namespace Swift { -	class CapsFileStorage : public CapsStorage { -		public: -			CapsFileStorage(const boost::filesystem::path& path); +    class CapsFileStorage : public CapsStorage { +        public: +            CapsFileStorage(const boost::filesystem::path& path); -			virtual DiscoInfo::ref getDiscoInfo(const std::string& hash) const; -			virtual void setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo); +            virtual DiscoInfo::ref getDiscoInfo(const std::string& hash) const; +            virtual void setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo); -		private: -			boost::filesystem::path getCapsPath(const std::string& hash) const; +        private: +            boost::filesystem::path getCapsPath(const std::string& hash) const; -		private: -			boost::filesystem::path path; -	}; +        private: +            boost::filesystem::path path; +    };  } diff --git a/Swift/Controllers/Storages/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp index a549165..3fe6d54 100644 --- a/Swift/Controllers/Storages/CertificateFileStorage.cpp +++ b/Swift/Controllers/Storages/CertificateFileStorage.cpp @@ -22,42 +22,42 @@ CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& pa  }  bool CertificateFileStorage::hasCertificate(Certificate::ref certificate) const { -	boost::filesystem::path certificatePath = getCertificatePath(certificate); -	if (boost::filesystem::exists(certificatePath)) { -		ByteArray data; -		readByteArrayFromFile(data, certificatePath); -		Certificate::ref storedCertificate(certificateFactory->createCertificateFromDER(data)); -		if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) { -			return true; -		} -		else { -			SWIFT_LOG(warning) << "Stored certificate does not match received certificate" << std::endl; -			return false; -		} -	} -	else { -		return false; -	} +    boost::filesystem::path certificatePath = getCertificatePath(certificate); +    if (boost::filesystem::exists(certificatePath)) { +        ByteArray data; +        readByteArrayFromFile(data, certificatePath); +        Certificate::ref storedCertificate(certificateFactory->createCertificateFromDER(data)); +        if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) { +            return true; +        } +        else { +            SWIFT_LOG(warning) << "Stored certificate does not match received certificate" << std::endl; +            return false; +        } +    } +    else { +        return false; +    }  }  void CertificateFileStorage::addCertificate(Certificate::ref certificate) { -	boost::filesystem::path certificatePath = getCertificatePath(certificate); -	if (!boost::filesystem::exists(certificatePath.parent_path())) { -		try { -			boost::filesystem::create_directories(certificatePath.parent_path()); -		} -		catch (const boost::filesystem::filesystem_error& e) { -			std::cerr << "ERROR: " << e.what() << std::endl; -		} -	} -	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)), boost::numeric_cast<std::streamsize>(data.size())); -	file.close(); +    boost::filesystem::path certificatePath = getCertificatePath(certificate); +    if (!boost::filesystem::exists(certificatePath.parent_path())) { +        try { +            boost::filesystem::create_directories(certificatePath.parent_path()); +        } +        catch (const boost::filesystem::filesystem_error& e) { +            std::cerr << "ERROR: " << e.what() << std::endl; +        } +    } +    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)), boost::numeric_cast<std::streamsize>(data.size())); +    file.close();  }  boost::filesystem::path CertificateFileStorage::getCertificatePath(Certificate::ref certificate) const { -	return path / Hexify::hexify(crypto->getSHA1Hash(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 f7d3cb3..d2c228d 100644 --- a/Swift/Controllers/Storages/CertificateFileStorage.h +++ b/Swift/Controllers/Storages/CertificateFileStorage.h @@ -11,23 +11,23 @@  #include <Swift/Controllers/Storages/CertificateStorage.h>  namespace Swift { -	class CertificateFactory; -	class CryptoProvider; +    class CertificateFactory; +    class CryptoProvider; -	class CertificateFileStorage : public CertificateStorage { -		public: -			CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto); +    class CertificateFileStorage : public CertificateStorage { +        public: +            CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto); -			virtual bool hasCertificate(Certificate::ref certificate) const; -			virtual void addCertificate(Certificate::ref certificate); +            virtual bool hasCertificate(Certificate::ref certificate) const; +            virtual void addCertificate(Certificate::ref certificate); -		private: -			boost::filesystem::path getCertificatePath(Certificate::ref certificate) const; +        private: +            boost::filesystem::path getCertificatePath(Certificate::ref certificate) const; -		private: -			boost::filesystem::path path; -			CertificateFactory* certificateFactory; -			CryptoProvider* crypto; -	}; +        private: +            boost::filesystem::path path; +            CertificateFactory* certificateFactory; +            CryptoProvider* crypto; +    };  } diff --git a/Swift/Controllers/Storages/CertificateFileStorageFactory.h b/Swift/Controllers/Storages/CertificateFileStorageFactory.h index da8e66e..8ab99f4 100644 --- a/Swift/Controllers/Storages/CertificateFileStorageFactory.h +++ b/Swift/Controllers/Storages/CertificateFileStorageFactory.h @@ -10,21 +10,21 @@  #include <Swift/Controllers/Storages/CertificateStorageFactory.h>  namespace Swift { -	class CertificateFactory; -	class CryptoProvider; +    class CertificateFactory; +    class CryptoProvider; -	class CertificateFileStorageFactory : public CertificateStorageFactory { -		public: -			CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory, CryptoProvider* crypto) : basePath(basePath), certificateFactory(certificateFactory), crypto(crypto) {} +    class CertificateFileStorageFactory : public CertificateStorageFactory { +        public: +            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, crypto); -			} +            virtual CertificateStorage* createCertificateStorage(const JID& profile) const { +                boost::filesystem::path profilePath = basePath / profile.toString(); +                return new CertificateFileStorage(profilePath / "certificates", certificateFactory, crypto); +            } -		private: -			boost::filesystem::path basePath; -			CertificateFactory* certificateFactory; -			CryptoProvider* crypto; -	}; +        private: +            boost::filesystem::path basePath; +            CertificateFactory* certificateFactory; +            CryptoProvider* crypto; +    };  } diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp index cd3c8fa..08c6ee7 100644 --- a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp +++ b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp @@ -14,14 +14,14 @@ CertificateMemoryStorage::CertificateMemoryStorage() {  }  bool CertificateMemoryStorage::hasCertificate(Certificate::ref certificate) const { -	foreach(Certificate::ref storedCert, certificates) { -		if (storedCert->toDER() == certificate->toDER()) { -			return true; -		} -	} -	return false; +    foreach(Certificate::ref storedCert, certificates) { +        if (storedCert->toDER() == certificate->toDER()) { +            return true; +        } +    } +    return false;  }  void CertificateMemoryStorage::addCertificate(Certificate::ref certificate) { -	certificates.push_back(certificate); +    certificates.push_back(certificate);  } diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.h b/Swift/Controllers/Storages/CertificateMemoryStorage.h index 8bf7986..4870385 100644 --- a/Swift/Controllers/Storages/CertificateMemoryStorage.h +++ b/Swift/Controllers/Storages/CertificateMemoryStorage.h @@ -11,15 +11,15 @@  #include <Swift/Controllers/Storages/CertificateStorage.h>  namespace Swift { -	class CertificateMemoryStorage : public CertificateStorage { -		public: -			CertificateMemoryStorage(); +    class CertificateMemoryStorage : public CertificateStorage { +        public: +            CertificateMemoryStorage(); -			virtual bool hasCertificate(Certificate::ref certificate) const; -			virtual void addCertificate(Certificate::ref certificate); +            virtual bool hasCertificate(Certificate::ref certificate) const; +            virtual void addCertificate(Certificate::ref certificate); -		private: -			std::vector<Certificate::ref> certificates; -	}; +        private: +            std::vector<Certificate::ref> certificates; +    };  } diff --git a/Swift/Controllers/Storages/CertificateStorage.h b/Swift/Controllers/Storages/CertificateStorage.h index 470b420..87a566b 100644 --- a/Swift/Controllers/Storages/CertificateStorage.h +++ b/Swift/Controllers/Storages/CertificateStorage.h @@ -11,12 +11,12 @@  #include <Swiften/TLS/Certificate.h>  namespace Swift { -	class CertificateStorage { -		public: -			virtual ~CertificateStorage(); +    class CertificateStorage { +        public: +            virtual ~CertificateStorage(); -			virtual bool hasCertificate(Certificate::ref certificate) const = 0; -			virtual void addCertificate(Certificate::ref certificate) = 0; -	}; +            virtual bool hasCertificate(Certificate::ref certificate) const = 0; +            virtual void addCertificate(Certificate::ref certificate) = 0; +    };  } diff --git a/Swift/Controllers/Storages/CertificateStorageFactory.h b/Swift/Controllers/Storages/CertificateStorageFactory.h index 44605df..25fa232 100644 --- a/Swift/Controllers/Storages/CertificateStorageFactory.h +++ b/Swift/Controllers/Storages/CertificateStorageFactory.h @@ -7,13 +7,13 @@  #pragma once  namespace Swift { -	class CertificateStorage; -	class JID; +    class CertificateStorage; +    class JID; -	class CertificateStorageFactory { -		public: -			virtual ~CertificateStorageFactory(); +    class CertificateStorageFactory { +        public: +            virtual ~CertificateStorageFactory(); -			virtual CertificateStorage* createCertificateStorage(const JID& profile) const = 0; -	}; +            virtual CertificateStorage* createCertificateStorage(const JID& profile) const = 0; +    };  } diff --git a/Swift/Controllers/Storages/CertificateStorageTrustChecker.h b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h index 7f2f43e..3c708a3 100644 --- a/Swift/Controllers/Storages/CertificateStorageTrustChecker.h +++ b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h @@ -11,25 +11,25 @@  #include <Swift/Controllers/Storages/CertificateStorage.h>  namespace Swift { -	/** -	 * A certificate trust checker that trusts certificates in a certificate storage. -	 */ -	class CertificateStorageTrustChecker : public CertificateTrustChecker { -		public: -			CertificateStorageTrustChecker(CertificateStorage* storage) : storage(storage) { -			} +    /** +     * A certificate trust checker that trusts certificates in a certificate storage. +     */ +    class CertificateStorageTrustChecker : public CertificateTrustChecker { +        public: +            CertificateStorageTrustChecker(CertificateStorage* storage) : storage(storage) { +            } -			virtual bool isCertificateTrusted(const std::vector<Certificate::ref>& certificateChain) { -				lastCertificateChain = std::vector<Certificate::ref>(certificateChain.begin(), certificateChain.end()); -				return certificateChain.empty() ? false : storage->hasCertificate(certificateChain[0]); -			} +            virtual bool isCertificateTrusted(const std::vector<Certificate::ref>& certificateChain) { +                lastCertificateChain = std::vector<Certificate::ref>(certificateChain.begin(), certificateChain.end()); +                return certificateChain.empty() ? false : storage->hasCertificate(certificateChain[0]); +            } -			const std::vector<Certificate::ref>& getLastCertificateChain() const { -				return lastCertificateChain; -			} +            const std::vector<Certificate::ref>& getLastCertificateChain() const { +                return lastCertificateChain; +            } -		private: -			CertificateStorage* storage; -			std::vector<Certificate::ref> lastCertificateChain; -	}; +        private: +            CertificateStorage* storage; +            std::vector<Certificate::ref> lastCertificateChain; +    };  } diff --git a/Swift/Controllers/Storages/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp index 7e564bf..7ba2b0f 100644 --- a/Swift/Controllers/Storages/FileStorages.cpp +++ b/Swift/Controllers/Storages/FileStorages.cpp @@ -17,47 +17,47 @@  namespace Swift {  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", crypto); -	rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml"); +    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"); +    historyStorage = new SQLiteHistoryStorage(baseDir / "history.db");  #else -	historyStorage = NULL; +    historyStorage = NULL;  #endif  }  FileStorages::~FileStorages() { -	delete rosterStorage; -	delete avatarStorage; -	delete capsStorage; -	delete vcardStorage; -	delete historyStorage; +    delete rosterStorage; +    delete avatarStorage; +    delete capsStorage; +    delete vcardStorage; +    delete historyStorage;  }  VCardStorage* FileStorages::getVCardStorage() const { -	return vcardStorage; +    return vcardStorage;  }  CapsStorage* FileStorages::getCapsStorage() const { -	return capsStorage; +    return capsStorage;  }  AvatarStorage* FileStorages::getAvatarStorage() const { -	return avatarStorage; +    return avatarStorage;  }  RosterStorage* FileStorages::getRosterStorage() const { -	return rosterStorage; +    return rosterStorage;  }  HistoryStorage* FileStorages::getHistoryStorage() const {  #ifdef SWIFT_EXPERIMENTAL_HISTORY -	return historyStorage; +    return historyStorage;  #else -	return NULL; +    return NULL;  #endif  } diff --git a/Swift/Controllers/Storages/FileStorages.h b/Swift/Controllers/Storages/FileStorages.h index 195d0fa..e71d665 100644 --- a/Swift/Controllers/Storages/FileStorages.h +++ b/Swift/Controllers/Storages/FileStorages.h @@ -11,47 +11,47 @@  #include <Swiften/Client/Storages.h>  namespace Swift { -	class VCardFileStorage; -	class AvatarFileStorage; -	class CapsFileStorage; -	class RosterFileStorage; -	class HistoryStorage; -	class JID; -	class CryptoProvider; +    class VCardFileStorage; +    class AvatarFileStorage; +    class CapsFileStorage; +    class RosterFileStorage; +    class HistoryStorage; +    class JID; +    class CryptoProvider; -	/** -	 * A storages implementation that stores all controller data on disk. -	 */ -	class FileStorages : public Storages { -		public: -			/** -			 * Creates the storages interface. -			 * -			 * All data will be stored relative to a base directory, and -			 * for some controllers, in a subdirectory for the given profile. -			 * The data is stored in the following places: -			 * - Avatars: $basedir/avatars -			 * - VCards:  $basedir/$profile/vcards -			 * - Entity capabilities: $basedir/caps -			 * -			 * \param baseDir the base dir to store data relative to -			 * \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, CryptoProvider*); -			~FileStorages(); +    /** +     * A storages implementation that stores all controller data on disk. +     */ +    class FileStorages : public Storages { +        public: +            /** +             * Creates the storages interface. +             * +             * All data will be stored relative to a base directory, and +             * for some controllers, in a subdirectory for the given profile. +             * The data is stored in the following places: +             * - Avatars: $basedir/avatars +             * - VCards:  $basedir/$profile/vcards +             * - Entity capabilities: $basedir/caps +             * +             * \param baseDir the base dir to store data relative to +             * \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, CryptoProvider*); +            ~FileStorages(); -			virtual VCardStorage* getVCardStorage() const; -			virtual AvatarStorage* getAvatarStorage() const; -			virtual CapsStorage* getCapsStorage() const; -			virtual RosterStorage* getRosterStorage() const; -			virtual HistoryStorage* getHistoryStorage() const; +            virtual VCardStorage* getVCardStorage() const; +            virtual AvatarStorage* getAvatarStorage() const; +            virtual CapsStorage* getCapsStorage() const; +            virtual RosterStorage* getRosterStorage() const; +            virtual HistoryStorage* getHistoryStorage() const; -		private: -			VCardFileStorage* vcardStorage; -			AvatarFileStorage* avatarStorage; -			CapsFileStorage* capsStorage; -			RosterFileStorage* rosterStorage; -			HistoryStorage* historyStorage; -	}; +        private: +            VCardFileStorage* vcardStorage; +            AvatarFileStorage* avatarStorage; +            CapsFileStorage* capsStorage; +            RosterFileStorage* rosterStorage; +            HistoryStorage* historyStorage; +    };  } diff --git a/Swift/Controllers/Storages/FileStoragesFactory.h b/Swift/Controllers/Storages/FileStoragesFactory.h index 66b3841..ec0106e 100644 --- a/Swift/Controllers/Storages/FileStoragesFactory.h +++ b/Swift/Controllers/Storages/FileStoragesFactory.h @@ -10,18 +10,18 @@  #include <Swift/Controllers/Storages/StoragesFactory.h>  namespace Swift { -	class CryptoProvider; +    class CryptoProvider; -	class FileStoragesFactory : public StoragesFactory { -		public: -			FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {} +    class FileStoragesFactory : public StoragesFactory { +        public: +            FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {} -			virtual Storages* createStorages(const JID& profile) const { -				return new FileStorages(basePath, profile, crypto); -			} +            virtual Storages* createStorages(const JID& profile) const { +                return new FileStorages(basePath, profile, crypto); +            } -		private: -			boost::filesystem::path basePath; -			CryptoProvider* crypto; -	}; +        private: +            boost::filesystem::path basePath; +            CryptoProvider* crypto; +    };  } diff --git a/Swift/Controllers/Storages/MemoryStoragesFactory.h b/Swift/Controllers/Storages/MemoryStoragesFactory.h index 6f6523c..28e9138 100644 --- a/Swift/Controllers/Storages/MemoryStoragesFactory.h +++ b/Swift/Controllers/Storages/MemoryStoragesFactory.h @@ -11,17 +11,17 @@  #include <Swift/Controllers/Storages/StoragesFactory.h>  namespace Swift { -	class JID; -	class CryptoProvider; +    class JID; +    class CryptoProvider; -	class MemoryStoragesFactory : public StoragesFactory { -		public: -			MemoryStoragesFactory(CryptoProvider* cryptoProvider) : cryptoProvider_(cryptoProvider) {} +    class MemoryStoragesFactory : public StoragesFactory { +        public: +            MemoryStoragesFactory(CryptoProvider* cryptoProvider) : cryptoProvider_(cryptoProvider) {} -			virtual Storages* createStorages(const JID& /*profile*/) const { -				return new MemoryStorages(cryptoProvider_); -			} -		private: -			CryptoProvider* cryptoProvider_; -	}; +            virtual Storages* createStorages(const JID& /*profile*/) const { +                return new MemoryStorages(cryptoProvider_); +            } +        private: +            CryptoProvider* cryptoProvider_; +    };  } diff --git a/Swift/Controllers/Storages/RosterFileStorage.cpp b/Swift/Controllers/Storages/RosterFileStorage.cpp index c55bcf1..6cc5c61 100644 --- a/Swift/Controllers/Storages/RosterFileStorage.cpp +++ b/Swift/Controllers/Storages/RosterFileStorage.cpp @@ -18,9 +18,9 @@ RosterFileStorage::RosterFileStorage(const boost::filesystem::path& path) : path  }  boost::shared_ptr<RosterPayload> RosterFileStorage::getRoster() const { -	return RosterPersister().loadPayloadGeneric(path); +    return RosterPersister().loadPayloadGeneric(path);  }  void RosterFileStorage::setRoster(boost::shared_ptr<RosterPayload> roster) { -	RosterPersister().savePayload(roster, path); +    RosterPersister().savePayload(roster, path);  } diff --git a/Swift/Controllers/Storages/RosterFileStorage.h b/Swift/Controllers/Storages/RosterFileStorage.h index d100793..dd1a6c9 100644 --- a/Swift/Controllers/Storages/RosterFileStorage.h +++ b/Swift/Controllers/Storages/RosterFileStorage.h @@ -11,14 +11,14 @@  #include <Swiften/Roster/RosterStorage.h>  namespace Swift { -	class RosterFileStorage : public RosterStorage { -		public: -			RosterFileStorage(const boost::filesystem::path& path); +    class RosterFileStorage : public RosterStorage { +        public: +            RosterFileStorage(const boost::filesystem::path& path); -			virtual boost::shared_ptr<RosterPayload> getRoster() const; -			virtual void setRoster(boost::shared_ptr<RosterPayload>); +            virtual boost::shared_ptr<RosterPayload> getRoster() const; +            virtual void setRoster(boost::shared_ptr<RosterPayload>); -		private: -			boost::filesystem::path path; -	}; +        private: +            boost::filesystem::path path; +    };  } diff --git a/Swift/Controllers/Storages/StoragesFactory.h b/Swift/Controllers/Storages/StoragesFactory.h index 4eb991b..771230b 100644 --- a/Swift/Controllers/Storages/StoragesFactory.h +++ b/Swift/Controllers/Storages/StoragesFactory.h @@ -7,13 +7,13 @@  #pragma once  namespace Swift { -	class Storages; -	class JID; +    class Storages; +    class JID; -	class StoragesFactory { -		public: -			virtual ~StoragesFactory() {} +    class StoragesFactory { +        public: +            virtual ~StoragesFactory() {} -			virtual Storages* createStorages(const JID& profile) const = 0; -	}; +            virtual Storages* createStorages(const JID& profile) const = 0; +    };  } diff --git a/Swift/Controllers/Storages/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp index a93e286..720165a 100644 --- a/Swift/Controllers/Storages/VCardFileStorage.cpp +++ b/Swift/Controllers/Storages/VCardFileStorage.cpp @@ -28,100 +28,100 @@ using namespace Swift;  typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister;  VCardFileStorage::VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto) : VCardStorage(crypto), vcardsPath(dir), crypto(crypto) { -	cacheFile = vcardsPath / "phashes"; -	if (boost::filesystem::exists(cacheFile)) { -		try { -			boost::filesystem::ifstream file(cacheFile); -			std::string line; -			if (file.is_open()) { -				while (!file.eof()) { -					getline(file, line); -					std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' '); -					JID jid(r.second); -					if (jid.isValid()) { -						photoHashes.insert(std::make_pair(jid, r.first)); -					} -					else if (!r.first.empty() || !r.second.empty()) { -						std::cerr << "Invalid entry in phashes file" << std::endl; -					} -				} -			} -		} -		catch (...) { -			std::cerr << "Error reading phashes file" << std::endl; -		} -	} +    cacheFile = vcardsPath / "phashes"; +    if (boost::filesystem::exists(cacheFile)) { +        try { +            boost::filesystem::ifstream file(cacheFile); +            std::string line; +            if (file.is_open()) { +                while (!file.eof()) { +                    getline(file, line); +                    std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' '); +                    JID jid(r.second); +                    if (jid.isValid()) { +                        photoHashes.insert(std::make_pair(jid, r.first)); +                    } +                    else if (!r.first.empty() || !r.second.empty()) { +                        std::cerr << "Invalid entry in phashes file" << std::endl; +                    } +                } +            } +        } +        catch (...) { +            std::cerr << "Error reading phashes file" << std::endl; +        } +    }  }  boost::shared_ptr<VCard> VCardFileStorage::getVCard(const JID& jid) const { -	boost::shared_ptr<VCard> result = VCardPersister().loadPayloadGeneric(getVCardPath(jid)); -	getAndUpdatePhotoHash(jid, result); -	return result; +    boost::shared_ptr<VCard> result = VCardPersister().loadPayloadGeneric(getVCardPath(jid)); +    getAndUpdatePhotoHash(jid, result); +    return result;  }  boost::posix_time::ptime VCardFileStorage::getVCardWriteTime(const JID& jid) const { -	if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) { -		return boost::posix_time::ptime(); -	} -	else { -		return vcardWriteTimes.at(jid); -	} +    if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) { +        return boost::posix_time::ptime(); +    } +    else { +        return vcardWriteTimes.at(jid); +    }  }  void VCardFileStorage::setVCard(const JID& jid, VCard::ref v) { -	vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time(); -	VCardPersister().savePayload(v, getVCardPath(jid)); -	getAndUpdatePhotoHash(jid, v); +    vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time(); +    VCardPersister().savePayload(v, getVCardPath(jid)); +    getAndUpdatePhotoHash(jid, v);  }  boost::filesystem::path VCardFileStorage::getVCardPath(const JID& jid) const { -	try { -		std::string file(jid.toString()); -		String::replaceAll(file, '/', "%2f"); -		return boost::filesystem::path(vcardsPath / stringToPath(file + ".xml")); -	} -	catch (const boost::filesystem::filesystem_error& e) { -		std::cerr << "ERROR: " << e.what() << std::endl; -		return boost::filesystem::path(); -	} +    try { +        std::string file(jid.toString()); +        String::replaceAll(file, '/', "%2f"); +        return boost::filesystem::path(vcardsPath / stringToPath(file + ".xml")); +    } +    catch (const boost::filesystem::filesystem_error& e) { +        std::cerr << "ERROR: " << e.what() << std::endl; +        return boost::filesystem::path(); +    }  }  std::string VCardFileStorage::getPhotoHash(const JID& jid) const { -	PhotoHashMap::const_iterator i = photoHashes.find(jid); -	if (i != photoHashes.end()) { -		return i->second; -	} -	else { -		VCard::ref vCard = getVCard(jid); -		return getAndUpdatePhotoHash(jid, vCard); -	} +    PhotoHashMap::const_iterator i = photoHashes.find(jid); +    if (i != photoHashes.end()) { +        return i->second; +    } +    else { +        VCard::ref vCard = getVCard(jid); +        return getAndUpdatePhotoHash(jid, vCard); +    }  }  std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref vCard) const { -	std::string hash; -	if (vCard && !vCard->getPhoto().empty()) { -		hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto())); -	} -	std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash)); -	if (r.second) { -		savePhotoHashes(); -	} -	else if (r.first->second != hash) { -		r.first->second = hash; -		savePhotoHashes(); -	} -	return hash; +    std::string hash; +    if (vCard && !vCard->getPhoto().empty()) { +        hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto())); +    } +    std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash)); +    if (r.second) { +        savePhotoHashes(); +    } +    else if (r.first->second != hash) { +        r.first->second = hash; +        savePhotoHashes(); +    } +    return hash;  }  void VCardFileStorage::savePhotoHashes() const { -	try { -		boost::filesystem::ofstream file(cacheFile); -		for (PhotoHashMap::const_iterator i = photoHashes.begin(); i != photoHashes.end(); ++i) { -			file << i->second << " " << i->first.toString() << std::endl; -		} -		file.close(); -	} -	catch (...) { -		std::cerr << "Error writing vcards file" << std::endl; -	} +    try { +        boost::filesystem::ofstream file(cacheFile); +        for (PhotoHashMap::const_iterator i = photoHashes.begin(); i != photoHashes.end(); ++i) { +            file << i->second << " " << i->first.toString() << std::endl; +        } +        file.close(); +    } +    catch (...) { +        std::cerr << "Error writing vcards file" << std::endl; +    }  } diff --git a/Swift/Controllers/Storages/VCardFileStorage.h b/Swift/Controllers/Storages/VCardFileStorage.h index 56e06f2..971a3f9 100644 --- a/Swift/Controllers/Storages/VCardFileStorage.h +++ b/Swift/Controllers/Storages/VCardFileStorage.h @@ -15,30 +15,30 @@  #include <Swiften/VCards/VCardStorage.h>  namespace Swift { -	class CryptoProvider; +    class CryptoProvider; -	class VCardFileStorage : public VCardStorage { -		public: -			VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto); +    class VCardFileStorage : public VCardStorage { +        public: +            VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto); -			virtual VCard::ref getVCard(const JID& jid) const; -			virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const; -			virtual void setVCard(const JID& jid, VCard::ref v); +            virtual VCard::ref getVCard(const JID& jid) const; +            virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const; +            virtual void setVCard(const JID& jid, VCard::ref v); -			virtual std::string getPhotoHash(const JID&) const; +            virtual std::string getPhotoHash(const JID&) const; -		private: -			boost::filesystem::path getVCardPath(const JID&) const; +        private: +            boost::filesystem::path getVCardPath(const JID&) const; -			std::string getAndUpdatePhotoHash(const JID& jid, VCard::ref vcard) const; -			void savePhotoHashes() const; +            std::string getAndUpdatePhotoHash(const JID& jid, VCard::ref vcard) const; +            void savePhotoHashes() const; -		private: -			boost::filesystem::path vcardsPath; -			CryptoProvider* crypto; -			boost::filesystem::path cacheFile; -			typedef std::map<JID, std::string> PhotoHashMap; -			mutable PhotoHashMap photoHashes; -			std::map<JID, boost::posix_time::ptime> vcardWriteTimes; -	}; +        private: +            boost::filesystem::path vcardsPath; +            CryptoProvider* crypto; +            boost::filesystem::path cacheFile; +            typedef std::map<JID, std::string> PhotoHashMap; +            mutable PhotoHashMap photoHashes; +            std::map<JID, boost::posix_time::ptime> vcardWriteTimes; +    };  }  | 
 Swift