From 2ce0df7571c5c05a6944635eceb68668f2f640fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 12 Mar 2011 19:28:37 +0100 Subject: Remove dependency on boost::property_tree again. diff --git a/3rdParty/Boost/update.sh b/3rdParty/Boost/update.sh index 80b515b..6344d72 100755 --- a/3rdParty/Boost/update.sh +++ b/3rdParty/Boost/update.sh @@ -35,8 +35,6 @@ fi boost/algorithm/string.hpp \ boost/format.hpp \ assign/list_of.hpp \ - property_tree/ptree.hpp \ - property_tree/xml_parser.hpp \ $TARGET_DIR rm -rf $TARGET_DIR/libs/config 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 #include -#include -#include #include +#include #include #include @@ -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("jid")); - std::string hash(v.second.get("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 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 -#include -#include #include #include @@ -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("jid")); - std::string hash(v.second.get("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 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; } } -- cgit v0.10.2-6-g49f6