summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/VCards')
-rw-r--r--Swiften/VCards/VCardFileStorage.cpp38
-rw-r--r--Swiften/VCards/VCardFileStorage.h2
2 files changed, 9 insertions, 31 deletions
diff --git a/Swiften/VCards/VCardFileStorage.cpp b/Swiften/VCards/VCardFileStorage.cpp
index a246838..1b23635 100644
--- a/Swiften/VCards/VCardFileStorage.cpp
+++ b/Swiften/VCards/VCardFileStorage.cpp
@@ -7,19 +7,23 @@
#include "Swiften/VCards/VCardFileStorage.h"
#include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem.hpp>
+#include <iostream>
+#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/JID/JID.h"
-#include "Swiften/Base/ByteArray.h"
#include "Swiften/Elements/VCard.h"
#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h"
#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h"
#include "Swiften/Parser/PayloadParsers/VCardParser.h"
-namespace Swift {
+using namespace Swift;
+
+typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister;
VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) {
cacheFile = vcardsPath / "phashes";
@@ -48,34 +52,11 @@ VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir
}
boost::shared_ptr<VCard> VCardFileStorage::getVCard(const JID& jid) const {
- boost::filesystem::path vcardPath(getVCardPath(jid));
- if (boost::filesystem::exists(vcardPath)) {
- ByteArray data;
- data.readFromFile(vcardPath.string());
-
- VCardParser parser;
- PayloadParserTester tester(&parser);
- tester.parse(data.toString());
- return boost::dynamic_pointer_cast<VCard>(parser.getPayload());
- }
- else {
- return boost::shared_ptr<VCard>();
- }
+ return VCardPersister().loadPayloadGeneric(getVCardPath(jid));
}
void VCardFileStorage::setVCard(const JID& jid, VCard::ref v) {
- boost::filesystem::path vcardPath(getVCardPath(jid));
- if (!boost::filesystem::exists(vcardPath.parent_path())) {
- try {
- boost::filesystem::create_directories(vcardPath.parent_path());
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- }
- }
- boost::filesystem::ofstream file(getVCardPath(jid));
- file << VCardSerializer().serializePayload(v);
- file.close();
+ VCardPersister().savePayload(v, getVCardPath(jid));
getAndUpdatePhotoHash(jid, v);
}
@@ -124,6 +105,3 @@ void VCardFileStorage::savePhotoHashes() const {
std::cerr << "Error writing vcards file" << std::endl;
}
}
-
-
-}
diff --git a/Swiften/VCards/VCardFileStorage.h b/Swiften/VCards/VCardFileStorage.h
index 26bf4b2..ba422f4 100644
--- a/Swiften/VCards/VCardFileStorage.h
+++ b/Swiften/VCards/VCardFileStorage.h
@@ -7,7 +7,7 @@
#pragma once
#include <boost/shared_ptr.hpp>
-#include <boost/filesystem.hpp>
+#include <boost/filesystem/path.hpp>
#include <string>
#include <map>