summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCătălin Badea <catalin.badea392@gmail.com>2012-08-19 18:34:48 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-19 18:34:48 (GMT)
commit7a46b1ddf4193c2f4ca789ef86b099f9d70842f9 (patch)
treebc8d7992bd6deb3967a0c868717308067174a9fa /Swiften
parent5aadc44a6f11c277a26865c7c908e3f356158fa0 (diff)
downloadswift-contrib-7a46b1ddf4193c2f4ca789ef86b099f9d70842f9.zip
swift-contrib-7a46b1ddf4193c2f4ca789ef86b099f9d70842f9.tar.bz2
Use appropriate folder for storing the history file.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/MemoryStorages.cpp7
-rw-r--r--Swiften/Client/MemoryStorages.h2
-rw-r--r--Swiften/Client/Storages.h2
-rw-r--r--Swiften/History/HistoryManager.cpp14
-rw-r--r--Swiften/History/HistoryStorage.h (renamed from Swiften/History/HistoryManager.h)5
-rw-r--r--Swiften/History/SConscript3
-rw-r--r--Swiften/History/SQLiteHistoryStorage.cpp (renamed from Swiften/History/SQLiteHistoryManager.cpp)30
-rw-r--r--Swiften/History/SQLiteHistoryStorage.h (renamed from Swiften/History/SQLiteHistoryManager.h)8
8 files changed, 33 insertions, 38 deletions
diff --git a/Swiften/Client/MemoryStorages.cpp b/Swiften/Client/MemoryStorages.cpp
index fe171f7..9bae4e3 100644
--- a/Swiften/Client/MemoryStorages.cpp
+++ b/Swiften/Client/MemoryStorages.cpp
@@ -9,6 +9,7 @@
#include <Swiften/Avatars/AvatarMemoryStorage.h>
#include <Swiften/Disco/CapsMemoryStorage.h>
#include <Swiften/Roster/RosterMemoryStorage.h>
+#include <Swiften/History/SQLiteHistoryStorage.h>
namespace Swift {
@@ -17,6 +18,7 @@ MemoryStorages::MemoryStorages() {
capsStorage = new CapsMemoryStorage();
avatarStorage = new AvatarMemoryStorage();
rosterStorage = new RosterMemoryStorage();
+ historyStorage = new SQLiteHistoryStorage(":memory:");
}
MemoryStorages::~MemoryStorages() {
@@ -24,6 +26,7 @@ MemoryStorages::~MemoryStorages() {
delete avatarStorage;
delete capsStorage;
delete vcardStorage;
+ delete historyStorage;
}
VCardStorage* MemoryStorages::getVCardStorage() const {
@@ -42,5 +45,9 @@ RosterStorage* MemoryStorages::getRosterStorage() const {
return rosterStorage;
}
+HistoryStorage* MemoryStorages::getHistoryStorage() const {
+ return historyStorage;
+}
+
}
diff --git a/Swiften/Client/MemoryStorages.h b/Swiften/Client/MemoryStorages.h
index ca01a7a..403a89a 100644
--- a/Swiften/Client/MemoryStorages.h
+++ b/Swiften/Client/MemoryStorages.h
@@ -24,11 +24,13 @@ namespace Swift {
virtual AvatarStorage* getAvatarStorage() const;
virtual CapsStorage* getCapsStorage() const;
virtual RosterStorage* getRosterStorage() const;
+ virtual HistoryStorage* getHistoryStorage() const;
private:
VCardMemoryStorage* vcardStorage;
AvatarStorage* avatarStorage;
CapsStorage* capsStorage;
RosterStorage* rosterStorage;
+ HistoryStorage* historyStorage;
};
}
diff --git a/Swiften/Client/Storages.h b/Swiften/Client/Storages.h
index 89b770c..76650a6 100644
--- a/Swiften/Client/Storages.h
+++ b/Swiften/Client/Storages.h
@@ -13,6 +13,7 @@ namespace Swift {
class AvatarStorage;
class CapsStorage;
class RosterStorage;
+ class HistoryStorage;
/**
* An interface to hold storage classes for different
@@ -26,5 +27,6 @@ namespace Swift {
virtual AvatarStorage* getAvatarStorage() const = 0;
virtual CapsStorage* getCapsStorage() const = 0;
virtual RosterStorage* getRosterStorage() const = 0;
+ virtual HistoryStorage* getHistoryStorage() const = 0;
};
}
diff --git a/Swiften/History/HistoryManager.cpp b/Swiften/History/HistoryManager.cpp
deleted file mode 100644
index 7eb66ab..0000000
--- a/Swiften/History/HistoryManager.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include <Swiften/History/HistoryManager.h>
-
-namespace Swift {
-
-HistoryManager::~HistoryManager() {
-}
-
-}
diff --git a/Swiften/History/HistoryManager.h b/Swiften/History/HistoryStorage.h
index 33e9143..fcf28b5 100644
--- a/Swiften/History/HistoryManager.h
+++ b/Swiften/History/HistoryStorage.h
@@ -16,15 +16,14 @@
namespace Swift {
typedef std::map<JID, std::set<boost::gregorian::date> > ContactsMap;
- class HistoryManager {
+ class HistoryStorage {
/**
* Messages are stored using localtime timestamps.
*/
public:
- virtual ~HistoryManager();
+ virtual ~HistoryStorage() {};
virtual void addMessage(const HistoryMessage& message) = 0;
-
virtual std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0;
virtual std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0;
virtual std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0;
diff --git a/Swiften/History/SConscript b/Swiften/History/SConscript
index 975f839..bc0d64c 100644
--- a/Swiften/History/SConscript
+++ b/Swiften/History/SConscript
@@ -5,7 +5,6 @@ if myenv["target"] == "native":
myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS", {}))
objects = myenv.SwiftenObject([
- "HistoryManager.cpp",
- "SQLiteHistoryManager.cpp",
+ "SQLiteHistoryStorage.cpp",
])
swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryStorage.cpp
index e385b1e..5e3148b 100644
--- a/Swiften/History/SQLiteHistoryManager.cpp
+++ b/Swiften/History/SQLiteHistoryStorage.cpp
@@ -8,7 +8,7 @@
#include <boost/lexical_cast.hpp>
#include <sqlite3.h>
-#include <Swiften/History/SQLiteHistoryManager.h>
+#include <Swiften/History/SQLiteHistoryStorage.h>
#include <boost/date_time/gregorian/gregorian.hpp>
inline std::string getEscapedString(const std::string& s) {
@@ -24,10 +24,10 @@ inline std::string getEscapedString(const std::string& s) {
namespace Swift {
-SQLiteHistoryManager::SQLiteHistoryManager(const std::string& file) : db_(0) {
+SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) {
sqlite3_open(file.c_str(), &db_);
if (!db_) {
- std::cerr << "Error opening database " << file << std::endl; // FIXME
+ std::cerr << "Error opening database " << file << std::endl;
}
char* errorMessage;
@@ -44,11 +44,11 @@ SQLiteHistoryManager::SQLiteHistoryManager(const std::string& file) : db_(0) {
}
}
-SQLiteHistoryManager::~SQLiteHistoryManager() {
+SQLiteHistoryStorage::~SQLiteHistoryStorage() {
sqlite3_close(db_);
}
-void SQLiteHistoryManager::addMessage(const HistoryMessage& message) {
+void SQLiteHistoryStorage::addMessage(const HistoryMessage& message) {
int secondsSinceEpoch = (message.getTime() - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))).total_seconds();
std::string statement = std::string("INSERT INTO messages('message', 'fromBare', 'fromResource', 'toBare', 'toResource', 'type', 'time', 'offset') VALUES(") +
@@ -68,7 +68,7 @@ void SQLiteHistoryManager::addMessage(const HistoryMessage& message) {
}
}
-std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
+std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
sqlite3_stmt* selectStatement;
boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
@@ -150,7 +150,7 @@ std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromDate(const JID&
return result;
}
-int SQLiteHistoryManager::getIDForJID(const JID& jid) {
+int SQLiteHistoryStorage::getIDForJID(const JID& jid) {
boost::optional<int> id = getIDFromJID(jid);
if (id) {
return *id;
@@ -160,7 +160,7 @@ int SQLiteHistoryManager::getIDForJID(const JID& jid) {
}
}
-int SQLiteHistoryManager::addJID(const JID& jid) {
+int SQLiteHistoryStorage::addJID(const JID& jid) {
std::string statement = std::string("INSERT INTO jids('jid') VALUES('") + getEscapedString(jid.toString()) + "')";
char* errorMessage;
int result = sqlite3_exec(db_, statement.c_str(), 0, 0, &errorMessage);
@@ -171,7 +171,7 @@ int SQLiteHistoryManager::addJID(const JID& jid) {
return sqlite3_last_insert_rowid(db_);
}
-boost::optional<JID> SQLiteHistoryManager::getJIDFromID(int id) const {
+boost::optional<JID> SQLiteHistoryStorage::getJIDFromID(int id) const {
boost::optional<JID> result;
sqlite3_stmt* selectStatement;
std::string selectQuery("SELECT jid FROM jids WHERE id=" + boost::lexical_cast<std::string>(id));
@@ -187,7 +187,7 @@ boost::optional<JID> SQLiteHistoryManager::getJIDFromID(int id) const {
return result;
}
-boost::optional<int> SQLiteHistoryManager::getIDFromJID(const JID& jid) const {
+boost::optional<int> SQLiteHistoryStorage::getIDFromJID(const JID& jid) const {
boost::optional<int> result;
sqlite3_stmt* selectStatement;
std::string selectQuery("SELECT id FROM jids WHERE jid='" + jid.toString() + "'");
@@ -203,7 +203,7 @@ boost::optional<int> SQLiteHistoryManager::getIDFromJID(const JID& jid) const {
return result;
}
-ContactsMap SQLiteHistoryManager::getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const {
+ContactsMap SQLiteHistoryStorage::getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const {
ContactsMap result;
sqlite3_stmt* selectStatement;
@@ -271,7 +271,7 @@ ContactsMap SQLiteHistoryManager::getContacts(const JID& selfJID, HistoryMessage
return result;
}
-boost::gregorian::date SQLiteHistoryManager::getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const {
+boost::gregorian::date SQLiteHistoryStorage::getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const {
sqlite3_stmt* selectStatement;
boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
boost::optional<int> contactID = getIDFromJID(contactJID.toBare());
@@ -319,7 +319,7 @@ boost::gregorian::date SQLiteHistoryManager::getNextDateWithLogs(const JID& self
return boost::gregorian::date(boost::gregorian::not_a_date_time);
}
-std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
+std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
boost::gregorian::date nextDate = getNextDateWithLogs(selfJID, contactJID, type, date, false);
if (nextDate.is_not_a_date()) {
@@ -329,7 +329,7 @@ std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromNextDate(const
return getMessagesFromDate(selfJID, contactJID, type, nextDate);
}
-std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
+std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
boost::gregorian::date previousDate = getNextDateWithLogs(selfJID, contactJID, type, date, true);
if (previousDate.is_not_a_date()) {
@@ -339,7 +339,7 @@ std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromPreviousDate(co
return getMessagesFromDate(selfJID, contactJID, type, previousDate);
}
-boost::posix_time::ptime SQLiteHistoryManager::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const {
+boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const {
boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
boost::optional<int> mucID = getIDFromJID(mucJID.toBare());
diff --git a/Swiften/History/SQLiteHistoryManager.h b/Swiften/History/SQLiteHistoryStorage.h
index b74fbde..aae6db8 100644
--- a/Swiften/History/SQLiteHistoryManager.h
+++ b/Swiften/History/SQLiteHistoryStorage.h
@@ -8,15 +8,15 @@
#include <boost/optional.hpp>
-#include <Swiften/History/HistoryManager.h>
+#include <Swiften/History/HistoryStorage.h>
struct sqlite3;
namespace Swift {
- class SQLiteHistoryManager : public HistoryManager {
+ class SQLiteHistoryStorage : public HistoryStorage {
public:
- SQLiteHistoryManager(const std::string& file);
- ~SQLiteHistoryManager();
+ SQLiteHistoryStorage(const std::string& file);
+ ~SQLiteHistoryStorage();
void addMessage(const HistoryMessage& message);
ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const;