-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})
/***************************************************************************
- * 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 *
/* 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);
--- /dev/null
+/***************************************************************************
+ * 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"
+
--- /dev/null
+/***************************************************************************
+ * 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 <QtCore>
+
+#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<BufferId> requestBuffers(UserId user, QDateTime since = QDateTime());
+
+ /* Message handling */
+
+ virtual MsgId logMessage(Message msg);
+ virtual QList<Message> requestMsgs(BufferId buffer, int lastmsgs = -1, int offset = -1);
+ virtual QList<Message> requestMsgs(BufferId buffer, QDateTime since, int offset = -1);
+ virtual QList<Message> 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
*/
// 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());
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);
}
-/** 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;
-}
-
-
-
#include <QtCore>
#include "global.h"
+#include "message.h"
class Storage : public QObject {
Q_OBJECT
* 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 */
* 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
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.
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;
};
-#endif
\ No newline at end of file
+#endif