summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/Client.cpp20
-rw-r--r--Swiften/Client/Client.h18
-rw-r--r--Swiften/Client/FileStorages.cpp39
-rw-r--r--Swiften/Client/FileStorages.h33
-rw-r--r--Swiften/Client/MemoryStorages.cpp38
-rw-r--r--Swiften/Client/MemoryStorages.h28
-rw-r--r--Swiften/Client/Storages.h22
7 files changed, 196 insertions, 2 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 63cd89f..7363c3f 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -12,10 +12,14 @@
#include "Swiften/Presence/PresenceOracle.h"
#include "Swiften/Presence/PresenceSender.h"
#include "Swiften/MUC/MUCRegistry.h"
+#include "Swiften/Client/MemoryStorages.h"
+#include "Swiften/VCards/VCardManager.h"
namespace Swift {
-Client::Client(const JID& jid, const String& password) : CoreClient(jid, password) {
+Client::Client(const JID& jid, const String& password, Storages* storages) : CoreClient(jid, password), storages(storages) {
+ memoryStorages = new MemoryStorages();
+
softwareVersionResponder = new SoftwareVersionResponder(getIQRouter());
softwareVersionResponder->start();
@@ -29,9 +33,13 @@ Client::Client(const JID& jid, const String& password) : CoreClient(jid, passwor
presenceSender = new PresenceSender(getStanzaChannel());
mucRegistry = new MUCRegistry();
+
+ vcardManager = new VCardManager(jid, getIQRouter(), getStorages()->getVCardStorage());
}
Client::~Client() {
+ delete vcardManager;
+
delete mucRegistry;
delete presenceSender;
@@ -42,6 +50,8 @@ Client::~Client() {
softwareVersionResponder->stop();
delete softwareVersionResponder;
+
+ delete memoryStorages;
}
XMPPRoster* Client::getRoster() const {
@@ -65,4 +75,12 @@ Presence::ref Client::getHighestPriorityPresence(const JID& bareJID) const {
return presenceOracle->getHighestPriorityPresence(bareJID);
}
+Storages* Client::getStorages() const {
+ if (storages) {
+ return storages;
+ }
+ return memoryStorages;
+}
+
+
}
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 2b4aa45..22fc636 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -16,16 +16,22 @@ namespace Swift {
class PresenceOracle;
class PresenceSender;
class MUCRegistry;
+ class Storages;
+ class MemoryStorages;
+ class VCardManager;
/**
* Provides the core functionality for writing XMPP client software.
*
* Besides connecting to an XMPP server, this class also provides interfaces for
* performing most tasks on the XMPP network.
+ *
+ * \param storages The interfaces for storing cache information etc. If this is NULL,
+ * all data will be stored in memory (and be lost on shutdown)
*/
class Client : public CoreClient {
public:
- Client(const JID& jid, const String& password);
+ Client(const JID& jid, const String& password, Storages* storages = NULL);
~Client();
@@ -80,6 +86,10 @@ namespace Swift {
return mucRegistry;
}
+ VCardManager* getVCardManager() const {
+ return vcardManager;
+ }
+
public:
/**
* This signal is emitted when a JID changes presence.
@@ -92,11 +102,17 @@ namespace Swift {
boost::signal<void (const JID&, const String&)> onPresenceSubscriptionRequest;
private:
+ Storages* getStorages() const;
+
+ private:
+ Storages* storages;
+ MemoryStorages* memoryStorages;
SoftwareVersionResponder* softwareVersionResponder;
XMPPRosterImpl* roster;
XMPPRosterController* rosterController;
PresenceOracle* presenceOracle;
PresenceSender* presenceSender;
MUCRegistry* mucRegistry;
+ VCardManager* vcardManager;
};
}
diff --git a/Swiften/Client/FileStorages.cpp b/Swiften/Client/FileStorages.cpp
new file mode 100644
index 0000000..9f2dda0
--- /dev/null
+++ b/Swiften/Client/FileStorages.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/Client/FileStorages.h"
+#include "Swiften/VCards/VCardFileStorage.h"
+#include "Swiften/Avatars/AvatarFileStorage.h"
+#include "Swiften/Disco/CapsFileStorage.h"
+
+namespace Swift {
+
+FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid) {
+ String profile = jid.toBare();
+ vcardStorage = new VCardFileStorage(baseDir / profile.getUTF8String() / "vcards");
+ capsStorage = new CapsFileStorage(baseDir / "caps");
+ avatarStorage = new AvatarFileStorage(baseDir / "avatars");
+}
+
+FileStorages::~FileStorages() {
+ delete avatarStorage;
+ delete capsStorage;
+ delete vcardStorage;
+}
+
+VCardStorage* FileStorages::getVCardStorage() const {
+ return vcardStorage;
+}
+
+CapsStorage* FileStorages::getCapsStorage() const {
+ return capsStorage;
+}
+
+AvatarStorage* FileStorages::getAvatarStorage() const {
+ return avatarStorage;
+}
+
+}
diff --git a/Swiften/Client/FileStorages.h b/Swiften/Client/FileStorages.h
new file mode 100644
index 0000000..f8c3162
--- /dev/null
+++ b/Swiften/Client/FileStorages.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/filesystem.hpp>
+
+#include "Swiften/Client/Storages.h"
+
+namespace Swift {
+ class VCardFileStorage;
+ class AvatarFileStorage;
+ class CapsFileStorage;
+ class JID;
+
+ class FileStorages : public Storages {
+ public:
+ FileStorages(const boost::filesystem::path& baseDir, const JID& jid);
+ ~FileStorages();
+
+ virtual VCardStorage* getVCardStorage() const;
+ virtual AvatarStorage* getAvatarStorage() const;
+ virtual CapsStorage* getCapsStorage() const;
+
+ private:
+ VCardFileStorage* vcardStorage;
+ AvatarFileStorage* avatarStorage;
+ CapsFileStorage* capsStorage;
+ };
+}
diff --git a/Swiften/Client/MemoryStorages.cpp b/Swiften/Client/MemoryStorages.cpp
new file mode 100644
index 0000000..5f6371b
--- /dev/null
+++ b/Swiften/Client/MemoryStorages.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/Client/MemoryStorages.h"
+#include "Swiften/VCards/VCardMemoryStorage.h"
+#include "Swiften/Avatars/AvatarMemoryStorage.h"
+#include "Swiften/Disco/CapsMemoryStorage.h"
+
+namespace Swift {
+
+MemoryStorages::MemoryStorages() {
+ vcardStorage = new VCardMemoryStorage();
+ capsStorage = new CapsMemoryStorage();
+ avatarStorage = new AvatarMemoryStorage();
+}
+
+MemoryStorages::~MemoryStorages() {
+ delete avatarStorage;
+ delete capsStorage;
+ delete vcardStorage;
+}
+
+VCardStorage* MemoryStorages::getVCardStorage() const {
+ return vcardStorage;
+}
+
+CapsStorage* MemoryStorages::getCapsStorage() const {
+ return capsStorage;
+}
+
+AvatarStorage* MemoryStorages::getAvatarStorage() const {
+ return avatarStorage;
+}
+
+}
diff --git a/Swiften/Client/MemoryStorages.h b/Swiften/Client/MemoryStorages.h
new file mode 100644
index 0000000..13f41d1
--- /dev/null
+++ b/Swiften/Client/MemoryStorages.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Client/Storages.h"
+
+namespace Swift {
+ class VCardMemoryStorage;
+
+ class MemoryStorages : public Storages {
+ public:
+ MemoryStorages();
+ ~MemoryStorages();
+
+ virtual VCardStorage* getVCardStorage() const;
+ virtual AvatarStorage* getAvatarStorage() const;
+ virtual CapsStorage* getCapsStorage() const;
+
+ private:
+ VCardMemoryStorage* vcardStorage;
+ AvatarStorage* avatarStorage;
+ CapsStorage* capsStorage;
+ };
+}
diff --git a/Swiften/Client/Storages.h b/Swiften/Client/Storages.h
new file mode 100644
index 0000000..6f286ca
--- /dev/null
+++ b/Swiften/Client/Storages.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+namespace Swift {
+ class VCardStorage;
+ class AvatarStorage;
+ class CapsStorage;
+
+ class Storages {
+ public:
+ virtual ~Storages() {}
+
+ virtual VCardStorage* getVCardStorage() const = 0;
+ virtual AvatarStorage* getAvatarStorage() const = 0;
+ virtual CapsStorage* getCapsStorage() const = 0;
+ };
+}