From 1a320a5613e1108a6b1e32c09a45f5a37f144ba8 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 21 May 2007 21:56:52 +0000 Subject: [PATCH] Adding skeleton for SqliteStorage. --- core/CMakeLists.txt | 4 +-- core/server.cpp | 3 +- core/sqlitestorage.cpp | 22 ++++++++++++ core/sqlitestorage.h | 81 ++++++++++++++++++++++++++++++++++++++++++ core/storage.cpp | 47 ++---------------------- core/storage.h | 16 ++++----- 6 files changed, 118 insertions(+), 55 deletions(-) create mode 100644 core/sqlitestorage.cpp create mode 100644 core/sqlitestorage.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c7adb956..fa1e53ea 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,6 +1,6 @@ -SET(core_SRCS core.cpp coreproxy.cpp server.cpp backlog.cpp) +SET(core_SRCS core.cpp coreproxy.cpp server.cpp backlog.cpp storage.cpp sqlitestorage.cpp) SET(core_HDRS ) -SET(core_MOCS core.h coreproxy.h server.h backlog.h) +SET(core_MOCS core.h coreproxy.h server.h backlog.h storage.h sqlitestorage.h) QT4_WRAP_CPP(_MOC ${core_MOCS}) ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS}) diff --git a/core/server.cpp b/core/server.cpp index 44b85b41..f5272266 100644 --- a/core/server.cpp +++ b/core/server.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005/06 by The Quassel Team * + * Copyright (C) 2005-07 by The Quassel Team * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -738,6 +738,7 @@ void Server::handleServer001(QString prefix, QStringList params) { /* RPL_ISUPPORT */ // TODO Complete 005 handling, also use sensible defaults for non-sent stuff void Server::handleServer005(QString prefix, QStringList params) { + qDebug() << prefix << params; params.removeLast(); foreach(QString p, params) { QString key = p.section("=", 0, 0); diff --git a/core/sqlitestorage.cpp b/core/sqlitestorage.cpp new file mode 100644 index 00000000..882091e0 --- /dev/null +++ b/core/sqlitestorage.cpp @@ -0,0 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "sqlitestorage.h" + diff --git a/core/sqlitestorage.h b/core/sqlitestorage.h new file mode 100644 index 00000000..a3b63fea --- /dev/null +++ b/core/sqlitestorage.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _SQLITESTORAGE_H_ +#define _SQLITESTORAGE_H_ + +#include + +#include "global.h" +#include "storage.h" + +class SqliteStorage : public Storage { + Q_OBJECT + + public: + SqliteStorage(); + virtual ~SqliteStorage(); + + static void init(); + + /* General */ + + static bool isAvailable(); + static QString displayName(); + + // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc + + /* User handling */ + + virtual UserId addUser(QString user, QString password); + virtual void updateUser(QString user, QString password); + virtual UserId validateUser(QString user, QString password); + virtual void delUser(QString user); + + /* Buffer handling */ + + virtual BufferId getBufferId(UserId user, QString network, QString buffer = ""); + virtual QList requestBuffers(UserId user, QDateTime since = QDateTime()); + + /* Message handling */ + + virtual MsgId logMessage(Message msg); + virtual QList requestMsgs(BufferId buffer, int lastmsgs = -1, int offset = -1); + virtual QList requestMsgs(BufferId buffer, QDateTime since, int offset = -1); + virtual QList requestMsgRange(BufferId buffer, int first, int last); + + public slots: + //! This is just for importing the old file-based backlog */ + /** This slot needs to be implemented in the storage backends. + * It should first prepare (delete?) the database, then call initBackLogOld(UserId id). + * If the importing was successful, backLogEnabledOld will be true afterwards. + */ + void importOldBacklog(); + + signals: + void bufferIdUpdated(BufferId); + + protected: + + private: +}; + + +#endif diff --git a/core/storage.cpp b/core/storage.cpp index 982415a7..3c16dd3f 100644 --- a/core/storage.cpp +++ b/core/storage.cpp @@ -43,7 +43,7 @@ void Storage::importOldBacklog() { */ // file name scheme: quassel-backlog-2006-29-10.bin -void Storage::initBackLogOld() { +void Storage::initBackLogOld(UserId uid) { backLogDir = QDir(Global::quasselDir + "/backlog"); if(!backLogDir.exists()) { qWarning(QString("Creating backlog directory \"%1\"...").arg(backLogDir.absolutePath()).toAscii()); @@ -100,9 +100,9 @@ void Storage::initBackLogOld() { QString text = QString::fromUtf8(m); BufferId id; if((f & Message::PrivMsg) && !(f & Message::Self)) { - id = getBufferId(net, sender); + id = getBufferId(uid, net, sender); } else { - id = getBufferId(net, target); + id = getBufferId(uid, net, target); } Message msg(QDateTime::fromTime_t(ts), id, (Message::Type)t, text, sender, f); //backLog[net].append(m); @@ -115,44 +115,3 @@ void Storage::initBackLogOld() { } -/** Log a core message (emitted via a displayMsg() signal) to the backlog file. - * If a file for the current day does not exist, one will be created. Otherwise, messages will be appended. - * The file header is the string defined by BACKLOG_STRING, followed by a quint8 specifying the format - * version (BACKLOG_FORMAT). The rest is simply serialized Message objects. - */ -void Storage::logMessageOld(QString net, Message msg) { - backLog[net].append(msg); - if(!logFileDirs.contains(net)) { - QDir dir(backLogDir.absolutePath() + "/" + net); - if(!dir.exists()) { - qWarning(QString("Creating backlog directory \"%1\"...").arg(dir.absolutePath()).toAscii()); - if(!dir.mkpath(dir.absolutePath())) { - qWarning(QString("Could not create backlog directory!").toAscii()); - return; - } - } - logFileDirs[net] = dir; - Q_ASSERT(!logFiles.contains(net) && !logStreams.contains(net)); - if(!logFiles.contains(net)) logFiles[net] = new QFile(); - if(!logStreams.contains(net)) logStreams[net] = new QDataStream(); - } - if(!logFileDates[net].isValid() || logFileDates[net] < QDate::currentDate()) { - if(logFiles[net]->isOpen()) logFiles[net]->close(); - logFileDates[net] = QDate::currentDate(); - } - if(!logFiles[net]->isOpen()) { - logFiles[net]->setFileName(QString("%1/%2").arg(logFileDirs[net].absolutePath()) - .arg(logFileDates[net].toString("'quassel-backlog-'yyyy-MM-dd'.bin'"))); - if(!logFiles[net]->open(QIODevice::WriteOnly|QIODevice::Append|QIODevice::Unbuffered)) { - qWarning(QString("Could not open \"%1\" for writing: %2") - .arg(logFiles[net]->fileName()).arg(logFiles[net]->errorString()).toAscii()); - return; - } - logStreams[net]->setDevice(logFiles[net]); logStreams[net]->setVersion(QDataStream::Qt_4_2); - if(!logFiles[net]->size()) *logStreams[net] << BACKLOG_STRING << (quint8)BACKLOG_FORMAT; - } - *logStreams[net] << msg; -} - - - diff --git a/core/storage.h b/core/storage.h index 34ca0a88..c56cd4e7 100644 --- a/core/storage.h +++ b/core/storage.h @@ -24,6 +24,7 @@ #include #include "global.h" +#include "message.h" class Storage : public QObject { Q_OBJECT @@ -40,7 +41,7 @@ class Storage : public QObject { * For anything like this, the constructor (which is called if and when we actually create an instance * of the storage backend) is the right place. */ - virtual static void init() {}; + static void init() {}; /* General */ @@ -49,11 +50,11 @@ class Storage : public QObject { * prerequisites are in place (e.g. we have an appropriate DB driver etc.). * \return True if and only if the storage class can be successfully used. */ - virtual static bool isAvailable() = 0; + static bool isAvailable() { return false; } //! Returns the display name of the storage backend /** \return A string that can be used by the GUI to describe the storage backend */ - virtual static QString displayName() = 0; + static QString displayName() { return ""; } // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc @@ -139,10 +140,10 @@ class Storage : public QObject { public slots: //! This is just for importing the old file-based backlog */ /** This slot needs to be implemented in the storage backends. - * It should first prepare (delete?) the database, then call initBackLogOld(). + * It should first prepare (delete?) the database, then call initBackLogOld(UserId id). * If the importing was successful, backLogEnabledOld will be true afterwards. */ - void importOldBacklog() = 0; + virtual void importOldBacklog() = 0; signals: //! Sent if a new BufferId is created, or an existing one changed somehow. @@ -150,8 +151,7 @@ class Storage : public QObject { protected: // Old stuff, just for importing old file-based data - void initBackLogOld(); - void logMessageOld(QString net, Message); + void initBackLogOld(UserId id); bool backLogEnabledOld; QDir backLogDir; @@ -164,4 +164,4 @@ class Storage : public QObject { }; -#endif \ No newline at end of file +#endif -- 2.20.1