summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Badea <catalin.badea392@gmail.com>2012-06-27 12:02:47 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-11 15:52:56 (GMT)
commitfc40104bf6e6d915561f95015e0b5617d97880e4 (patch)
treebbe91142e4c4dfcdaf32d4041694a8834a6683d8 /Swiften
parent9f11ec4954b7c860623c799827e73c40e73acfac (diff)
downloadswift-contrib-fc40104bf6e6d915561f95015e0b5617d97880e4.zip
swift-contrib-fc40104bf6e6d915561f95015e0b5617d97880e4.tar.bz2
Log messages to the sqlite db and dump all messages in the history viewer
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/History/HistoryMessage.h31
-rw-r--r--Swiften/History/SQLiteHistoryManager.cpp22
-rw-r--r--Swiften/SConscript2
3 files changed, 38 insertions, 17 deletions
diff --git a/Swiften/History/HistoryMessage.h b/Swiften/History/HistoryMessage.h
index 461f5de..03e9206 100644
--- a/Swiften/History/HistoryMessage.h
+++ b/Swiften/History/HistoryMessage.h
@@ -12,19 +12,33 @@
namespace Swift {
class HistoryMessage {
public:
- HistoryMessage(const std::string& message, const JID& from, const JID& to, const boost::posix_time::ptime time) : message_(message), from_(from), to_(to), time_(time) {
+ HistoryMessage(
+ const std::string& message,
+ const JID& baseJID,
+ const JID& fromJID,
+ const std::string& displayNick,
+ const boost::posix_time::ptime time) :
+ message_(message),
+ baseJID_(baseJID),
+ fromJID_(fromJID),
+ displayNick_(displayNick),
+ time_(time) {
}
const std::string& getMessage() const {
return message_;
}
- const JID& getFrom() const {
- return from_;
+ const JID& getBaseJID() const {
+ return baseJID_;
}
- const JID& getTo() const {
- return to_;
+ const JID& getFromJID() const {
+ return fromJID_;
+ }
+
+ const std::string& getDisplayNick() const {
+ return displayNick_;
}
boost::posix_time::ptime getTime() const {
@@ -32,13 +46,14 @@ namespace Swift {
}
bool operator==(const HistoryMessage& o) const {
- return message_ == o.message_ && from_ == o.from_ && to_ == o.to_ && time_ == o.time_;
+ return baseJID_ == o.baseJID_ && message_ == o.message_ && fromJID_ == o.fromJID_ && displayNick_ == o.displayNick_ && time_ == o.time_;
}
private:
std::string message_;
- JID from_;
- JID to_;
+ JID baseJID_;
+ JID fromJID_;
+ std::string displayNick_;
boost::posix_time::ptime time_;
};
}
diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryManager.cpp
index a24dec2..e10de07 100644
--- a/Swiften/History/SQLiteHistoryManager.cpp
+++ b/Swiften/History/SQLiteHistoryManager.cpp
@@ -25,7 +25,7 @@ SQLiteHistoryManager::SQLiteHistoryManager(const std::string& file) : db_(0) {
}
char* errorMessage;
- int result = sqlite3_exec(db_, "CREATE TABLE IF NOT EXISTS messages('from' INTEGER, 'to' INTEGER, 'message' STRING, 'time' INTEGER)", 0, 0, &errorMessage);
+ int result = sqlite3_exec(db_, "CREATE TABLE IF NOT EXISTS messages('baseID' INTEGER, 'from' INTEGER, 'nick' STRING, 'message' STRING, 'time' INTEGER)", 0, 0, &errorMessage);
if (result != SQLITE_OK) {
std::cerr << "SQL Error: " << errorMessage << std::endl;
sqlite3_free(errorMessage);
@@ -44,7 +44,12 @@ SQLiteHistoryManager::~SQLiteHistoryManager() {
void SQLiteHistoryManager::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('from', 'to', 'message', 'time') VALUES(") + boost::lexical_cast<std::string>(getIDForJID(message.getFrom())) + ", " + boost::lexical_cast<std::string>(getIDForJID(message.getTo())) + ", '" + getEscapedString(message.getMessage()) + "', " + boost::lexical_cast<std::string>(secondsSinceEpoch) + ")";
+ std::string statement = std::string("INSERT INTO messages('baseID', 'from', 'nick', 'message', 'time') VALUES(") +
+ boost::lexical_cast<std::string>(getIDForJID(message.getBaseJID())) + ", " +
+ boost::lexical_cast<std::string>(getIDForJID(message.getFromJID())) + ", '" +
+ message.getDisplayNick() + "', '" +
+ getEscapedString(message.getMessage()) + "', " +
+ boost::lexical_cast<std::string>(secondsSinceEpoch) + ")";
char* errorMessage;
int result = sqlite3_exec(db_, statement.c_str(), 0, 0, &errorMessage);
if (result != SQLITE_OK) {
@@ -56,20 +61,21 @@ void SQLiteHistoryManager::addMessage(const HistoryMessage& message) {
std::vector<HistoryMessage> SQLiteHistoryManager::getMessages() const {
std::vector<HistoryMessage> result;
sqlite3_stmt* selectStatement;
- std::string selectQuery("SELECT messages.'from', messages.'to', messages.'message', messages.'time' FROM messages");
+ std::string selectQuery("SELECT messages.'baseID', messages.'from', messages.'nick', messages.'message', messages.'time' FROM messages");
int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
r = sqlite3_step(selectStatement);
while (r == SQLITE_ROW) {
- boost::optional<JID> from(getJIDFromID(sqlite3_column_int(selectStatement, 0)));
- boost::optional<JID> to(getJIDFromID(sqlite3_column_int(selectStatement, 1)));
- std::string message(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 2)));
- int secondsSinceEpoch(sqlite3_column_int(selectStatement, 3));
+ boost::optional<JID> baseJID(getJIDFromID(sqlite3_column_int(selectStatement, 0)));
+ boost::optional<JID> from(getJIDFromID(sqlite3_column_int(selectStatement, 1)));
+ std::string nick(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 2)));
+ std::string message(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 3)));
+ int secondsSinceEpoch(sqlite3_column_int(selectStatement, 4));
boost::posix_time::ptime time(boost::gregorian::date(1970, 1, 1), boost::posix_time::seconds(secondsSinceEpoch));
- result.push_back(HistoryMessage(message, (from ? *from : JID()), (to ? *to : JID()), time));
+ result.push_back(HistoryMessage(message, (baseJID ? *baseJID : JID()), (from ? *from : JID()), nick, time));
r = sqlite3_step(selectStatement);
}
if (r != SQLITE_DONE) {
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 9996728..7e8eb9e 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -6,7 +6,7 @@ Import("env")
# Flags
################################################################################
-swiften_dep_modules = ["BOOST", "GCONF", "ICU", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP"]
+swiften_dep_modules = ["BOOST", "GCONF", "ICU", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP", "SQLITE"]
if env["SCONS_STAGE"] == "flags" :
env["SWIFTEN_DLL"] = ARGUMENTS.get("swiften_dll")