diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-03-12 18:28:37 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-03-12 18:28:37 (GMT) |
commit | 2ce0df7571c5c05a6944635eceb68668f2f640fd (patch) | |
tree | e33604f66953604c8128e6e2ac56bdb28875e8c5 /Swiften | |
parent | 16f5905b4f14f41239c34480888305ab5bfaf60e (diff) | |
download | swift-2ce0df7571c5c05a6944635eceb68668f2f640fd.zip swift-2ce0df7571c5c05a6944635eceb68668f2f640fd.tar.bz2 |
Remove dependency on boost::property_tree again.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Avatars/AvatarFileStorage.cpp | 51 | ||||
-rw-r--r-- | Swiften/Client/FileStorages.cpp | 2 | ||||
-rw-r--r-- | Swiften/VCards/VCardFileStorage.cpp | 52 |
3 files changed, 49 insertions, 56 deletions
diff --git a/Swiften/Avatars/AvatarFileStorage.cpp b/Swiften/Avatars/AvatarFileStorage.cpp index 500bb78..3ff78e4 100644 --- a/Swiften/Avatars/AvatarFileStorage.cpp +++ b/Swiften/Avatars/AvatarFileStorage.cpp @@ -8,10 +8,9 @@ #include <iostream> #include <boost/filesystem/fstream.hpp> -#include <boost/property_tree/ptree.hpp> -#include <boost/property_tree/xml_parser.hpp> #include <Swiften/Base/foreach.h> +#include <Swiften/Base/String.h> #include <Swiften/StringCodecs/SHA1.h> #include <Swiften/StringCodecs/Hexify.h> @@ -19,24 +18,25 @@ namespace Swift { AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile) : avatarsDir(avatarsDir), avatarsFile(avatarsFile) { if (boost::filesystem::exists(avatarsFile)) { - boost::property_tree::ptree tree; try { - boost::property_tree::xml_parser::read_xml(avatarsFile.string(), tree); - } - catch (const boost::property_tree::xml_parser::xml_parser_error& e) { - std::cerr << "Error reading avatars file: " << e.filename() << ":" << e.line() << ": " << e.message() << std::endl; - } - foreach(const boost::property_tree::ptree::value_type &v, tree.get_child("avatars")) { - try { - JID jid(v.second.get<std::string>("jid")); - std::string hash(v.second.get<std::string>("hash")); - if (jid.isValid()) { - jidAvatars.insert(std::make_pair(jid, hash)); + 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() && !r.first.empty()) { + jidAvatars.insert(std::make_pair(jid, r.first)); + } + else { + std::cerr << "Invalid entry in avatars file" << std::endl; + } } } - catch (const boost::property_tree::ptree_error& e) { - std::cerr << "Invalid avatar value: " << e.what() << std::endl; - } + } + catch (...) { + std::cerr << "Error reading avatars file" << std::endl; } } } @@ -89,18 +89,15 @@ std::string AvatarFileStorage::getAvatarForJID(const JID& jid) const { } void AvatarFileStorage::saveJIDAvatars() { - boost::property_tree::ptree tree; - for (JIDAvatarMap::const_iterator i = jidAvatars.begin(); i != jidAvatars.end(); ++i) { - boost::property_tree::ptree entry; - entry.put("jid", i->first.toString()); - entry.put("hash", i->second); - tree.add_child("avatars.avatar", entry); - } try { - boost::property_tree::xml_parser::write_xml(avatarsFile.string(), tree); + 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 (const boost::property_tree::xml_parser::xml_parser_error& e) { - std::cerr << "Error writing avatars file: " << e.filename() << ": " << e.message() << std::endl; + catch (...) { + std::cerr << "Error writing avatars file" << std::endl; } } diff --git a/Swiften/Client/FileStorages.cpp b/Swiften/Client/FileStorages.cpp index 54a109d..3c76c46 100644 --- a/Swiften/Client/FileStorages.cpp +++ b/Swiften/Client/FileStorages.cpp @@ -15,7 +15,7 @@ FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& ji std::string profile = jid.toBare(); vcardStorage = new VCardFileStorage(baseDir / profile / "vcards"); capsStorage = new CapsFileStorage(baseDir / "caps"); - avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars.xml"); + avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars"); } FileStorages::~FileStorages() { diff --git a/Swiften/VCards/VCardFileStorage.cpp b/Swiften/VCards/VCardFileStorage.cpp index e18b7a0..444ce3f 100644 --- a/Swiften/VCards/VCardFileStorage.cpp +++ b/Swiften/VCards/VCardFileStorage.cpp @@ -7,8 +7,6 @@ #include "Swiften/VCards/VCardFileStorage.h" #include <boost/filesystem/fstream.hpp> -#include <boost/property_tree/ptree.hpp> -#include <boost/property_tree/xml_parser.hpp> #include <Swiften/Base/String.h> #include <Swiften/StringCodecs/Hexify.h> @@ -24,26 +22,27 @@ namespace Swift { VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) { - cacheFile = vcardsPath / "vcards.xml"; + cacheFile = vcardsPath / "phashes"; if (boost::filesystem::exists(cacheFile)) { - boost::property_tree::ptree tree; try { - boost::property_tree::xml_parser::read_xml(cacheFile.string(), tree); - } - catch (const boost::property_tree::xml_parser::xml_parser_error& e) { - std::cerr << "Error reading vcards file: " << e.filename() << ":" << e.line() << ": " << e.message() << std::endl; - } - foreach(const boost::property_tree::ptree::value_type &v, tree.get_child("vcards")) { - try { - JID jid(v.second.get<std::string>("jid")); - std::string hash(v.second.get<std::string>("phash")); - if (jid.isValid()) { - photoHashes.insert(std::make_pair(jid, hash)); + 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() && !r.first.empty()) { + photoHashes.insert(std::make_pair(jid, r.first)); + } + else { + std::cerr << "Invalid entry in phashes file" << std::endl; + } } } - catch (const boost::property_tree::ptree_error& e) { - std::cerr << "Invalid vcard value: " << e.what() << std::endl; - } + } + catch (...) { + std::cerr << "Error reading phashes file" << std::endl; } } } @@ -114,18 +113,15 @@ std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref v } void VCardFileStorage::savePhotoHashes() const { - boost::property_tree::ptree tree; - for (PhotoHashMap::const_iterator i = photoHashes.begin(); i != photoHashes.end(); ++i) { - boost::property_tree::ptree entry; - entry.put("jid", i->first.toString()); - entry.put("phash", i->second); - tree.add_child("vcards.vcard", entry); - } try { - boost::property_tree::xml_parser::write_xml(cacheFile.string(), tree); + 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 (const boost::property_tree::xml_parser::xml_parser_error& e) { - std::cerr << "Error writing vcards file: " << e.filename() << ": " << e.message() << std::endl; + catch (...) { + std::cerr << "Error writing vcards file" << std::endl; } } |