summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-03-12 11:45:16 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-03-12 11:45:16 (GMT)
commit1e2722460b9a67713484903bf6382d08f7e09278 (patch)
treebbce2e9524f927c754ddfedd99f0b9444273c8ff
parent137d42c7081fc31deb76446b2f6ef72ae21eeff5 (diff)
downloadswift-1e2722460b9a67713484903bf6382d08f7e09278.zip
swift-1e2722460b9a67713484903bf6382d08f7e09278.tar.bz2
Moved vcard photo hash management into vcard storage.
This makes it easy to adapt the code to cache photo hashes if we want to.
-rw-r--r--Swiften/Avatars/AvatarFileStorage.cpp4
-rw-r--r--Swiften/Avatars/VCardAvatarManager.cpp13
-rw-r--r--Swiften/VCards/VCardManager.cpp5
-rw-r--r--Swiften/VCards/VCardManager.h3
-rw-r--r--Swiften/VCards/VCardStorage.cpp13
-rw-r--r--Swiften/VCards/VCardStorage.h5
6 files changed, 35 insertions, 8 deletions
diff --git a/Swiften/Avatars/AvatarFileStorage.cpp b/Swiften/Avatars/AvatarFileStorage.cpp
index 44a6a7f..5caf794 100644
--- a/Swiften/Avatars/AvatarFileStorage.cpp
+++ b/Swiften/Avatars/AvatarFileStorage.cpp
@@ -12,6 +12,8 @@
#include <boost/property_tree/xml_parser.hpp>
#include <Swiften/Base/foreach.h>
+#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/StringCodecs/Hexify.h>
namespace Swift {
@@ -44,6 +46,8 @@ bool AvatarFileStorage::hasAvatar(const std::string& hash) const {
}
void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) {
+ assert(Hexify::hexify(SHA1::getHash(avatar)) == hash);
+
boost::filesystem::path avatarPath = getAvatarPath(hash);
if (!boost::filesystem::exists(avatarPath.parent_path())) {
try {
diff --git a/Swiften/Avatars/VCardAvatarManager.cpp b/Swiften/Avatars/VCardAvatarManager.cpp
index ce732db..046e6f3 100644
--- a/Swiften/Avatars/VCardAvatarManager.cpp
+++ b/Swiften/Avatars/VCardAvatarManager.cpp
@@ -29,17 +29,16 @@ void VCardAvatarManager::handleVCardChanged(const JID& from) {
}
std::string VCardAvatarManager::getAvatarHash(const JID& jid) const {
- VCard::ref vCard = vcardManager_->getVCard(getAvatarJID(jid));
- if (vCard && !vCard->getPhoto().isEmpty()) {
- std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ JID avatarJID = getAvatarJID(jid);
+ std::string hash = vcardManager_->getPhotoHash(avatarJID);
+ if (!hash.empty()) {
if (!avatarStorage_->hasAvatar(hash)) {
+ VCard::ref vCard = vcardManager_->getVCard(avatarJID);
+ assert(vCard);
avatarStorage_->addAvatar(hash, vCard->getPhoto());
}
- return hash;
- }
- else {
- return "";
}
+ return hash;
}
JID VCardAvatarManager::getAvatarJID(const JID& jid) const {
diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp
index de53238..b9602ab 100644
--- a/Swiften/VCards/VCardManager.cpp
+++ b/Swiften/VCards/VCardManager.cpp
@@ -12,6 +12,7 @@
#include "Swiften/VCards/VCardStorage.h"
#include "Swiften/VCards/GetVCardRequest.h"
+
namespace Swift {
VCardManager::VCardManager(const JID& ownJID, IQRouter* iqRouter, VCardStorage* vcardStorage) : ownJID(ownJID), iqRouter(iqRouter), storage(vcardStorage) {
@@ -77,4 +78,8 @@ void VCardManager::setVCard(const JID& jid, VCard::ref vcard) {
}
}
+std::string VCardManager::getPhotoHash(const JID& jid) const {
+ return storage->getPhotoHash(jid);
+}
+
}
diff --git a/Swiften/VCards/VCardManager.h b/Swiften/VCards/VCardManager.h
index 5cdf82e..1dd16ae 100644
--- a/Swiften/VCards/VCardManager.h
+++ b/Swiften/VCards/VCardManager.h
@@ -29,6 +29,9 @@ namespace Swift {
void requestVCard(const JID& jid);
void requestOwnVCard();
+ std::string getPhotoHash(const JID& jid) const;
+
+
SetVCardRequest::ref createSetVCardRequest(VCard::ref);
public:
diff --git a/Swiften/VCards/VCardStorage.cpp b/Swiften/VCards/VCardStorage.cpp
index cacd083..b14ee60 100644
--- a/Swiften/VCards/VCardStorage.cpp
+++ b/Swiften/VCards/VCardStorage.cpp
@@ -6,9 +6,22 @@
#include "Swiften/VCards/VCardStorage.h"
+#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/StringCodecs/SHA1.h>
+
namespace Swift {
VCardStorage::~VCardStorage() {
}
+std::string VCardStorage::getPhotoHash(const JID& jid) const {
+ VCard::ref vCard = getVCard(jid);
+ if (vCard && !vCard->getPhoto().isEmpty()) {
+ return Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
+ }
+ else {
+ return "";
+ }
+}
+
}
diff --git a/Swiften/VCards/VCardStorage.h b/Swiften/VCards/VCardStorage.h
index 854ccc6..977a40c 100644
--- a/Swiften/VCards/VCardStorage.h
+++ b/Swiften/VCards/VCardStorage.h
@@ -6,9 +6,10 @@
#pragma once
+#include <string>
#include <boost/shared_ptr.hpp>
-#include "Swiften/Elements/VCard.h"
+#include <Swiften/Elements/VCard.h>
namespace Swift {
class JID;
@@ -19,5 +20,7 @@ namespace Swift {
virtual VCard::ref getVCard(const JID& jid) const = 0;
virtual void setVCard(const JID&, VCard::ref) = 0;
+
+ virtual std::string getPhotoHash(const JID&) const;
};
}