X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fabstractsqlstorage.h;h=efd1ce396a75a1b95606537bc6acb73b9e11569a;hp=104c0561354690a039fd4777ab095548ffdbaa50;hb=c194ed5fb3d15e14b9364f9796d3521910dc72fe;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222 diff --git a/src/core/abstractsqlstorage.h b/src/core/abstractsqlstorage.h index 104c0561..efd1ce39 100644 --- a/src/core/abstractsqlstorage.h +++ b/src/core/abstractsqlstorage.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2012 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,11 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef ABSTRACTSQLSTORAGE_H -#define ABSTRACTSQLSTORAGE_H +#pragma once #include "storage.h" +#include + #include #include #include @@ -35,23 +36,43 @@ class AbstractSqlStorage : public Storage Q_OBJECT public: - AbstractSqlStorage(QObject *parent = 0); - virtual ~AbstractSqlStorage(); + AbstractSqlStorage(QObject *parent = nullptr); + ~AbstractSqlStorage() override; - virtual inline AbstractSqlMigrationReader *createMigrationReader() { return 0; } - virtual inline AbstractSqlMigrationWriter *createMigrationWriter() { return 0; } + virtual std::unique_ptr createMigrationReader() { return {}; } + virtual std::unique_ptr createMigrationWriter() { return {}; } public slots: - virtual State init(const QVariantMap &settings = QVariantMap()); - virtual bool setup(const QVariantMap &settings = QVariantMap()); + State init(const QVariantMap &settings = QVariantMap(), + const QProcessEnvironment &environment = {}, + bool loadFromEnvironment = false) override; + bool setup(const QVariantMap &settings = QVariantMap(), + const QProcessEnvironment &environment = {}, + bool loadFromEnvironment = false) override; protected: - inline virtual void sync() {}; + inline void sync() override {}; QSqlDatabase logDb(); - QString queryString(const QString &queryName, int version); - inline QString queryString(const QString &queryName) { return queryString(queryName, 0); } + /** + * Fetch an SQL query string by name and optional schema version + * + * Loads the named SQL query from the built-in SQL resource collection, returning it as a + * string. If a version is specified, it'll be loaded from the schema version-specific folder + * instead. + * + * @see schemaVersion() + * + * @param[in] queryName File name of the SQL query, minus the .sql extension + * @param[in] version + * @parblock + * SQL schema version; if 0, fetches from current version, otherwise loads from the specified + * schema version instead of the current schema files. + * @endparblock + * @return String with the requested SQL query, ready for parameter substitution + */ + QString queryString(const QString &queryName, int version = 0); QStringList setupQueries(); @@ -65,7 +86,9 @@ protected: virtual bool updateSchemaVersion(int newVersion) = 0; virtual bool setupSchemaVersion(int version) = 0; - virtual void setConnectionProperties(const QVariantMap &properties) = 0; + virtual void setConnectionProperties(const QVariantMap &properties, + const QProcessEnvironment &environment, + bool loadFromEnvironment) = 0; virtual QString driverName() = 0; inline virtual QString hostName() { return QString(); } inline virtual int port() { return -1; } @@ -80,15 +103,16 @@ protected: * When reimplementing this method, don't use logDB() inside this function as * this would cause as we're just about to initialize that DB connection. */ - inline virtual void initDbSession(QSqlDatabase & /* db */) {} + inline virtual bool initDbSession(QSqlDatabase & /* db */) { return true; } private slots: void connectionDestroyed(); private: void addConnectionToPool(); + void dbConnect(QSqlDatabase &db); - int _schemaVersion; + int _schemaVersion{0}; bool _debug; static int _nextConnectionId; @@ -100,6 +124,14 @@ private: QHash _connectionPool; }; +struct SenderData { + QString sender; + QString realname; + QString avatarurl; + + friend uint qHash(const SenderData &key); + friend bool operator==(const SenderData &a, const SenderData &b); +}; // ======================================== // AbstractSqlStorage::Connection @@ -109,8 +141,8 @@ class AbstractSqlStorage::Connection : public QObject Q_OBJECT public: - Connection(const QString &name, QObject *parent = 0); - ~Connection(); + Connection(const QString &name, QObject *parent = nullptr); + ~Connection() override; inline QLatin1String name() const { return QLatin1String(_name); } @@ -130,12 +162,15 @@ public: UserId id; QString username; QString password; + int hashversion; + QString authenticator; }; struct SenderMO { - int senderId; + qint64 senderId{0}; QString sender; - SenderMO() : senderId(0) {} + QString realname; + QString avatarurl; }; struct IdentityMO { @@ -153,7 +188,7 @@ public: bool autoAwayReasonEnabled; bool detachAwayEnabled; QString detachAwayReason; - bool detchAwayReasonEnabled; + bool detachAwayReasonEnabled; QString ident; QString kickReason; QString partReason; @@ -169,31 +204,35 @@ public: }; struct NetworkMO { - NetworkId networkid; UserId userid; QString networkname; - IdentityId identityid; - QString encodingcodec; - QString decodingcodec; - QString servercodec; - bool userandomserver; QString perform; - bool useautoidentify; QString autoidentifyservice; QString autoidentifypassword; - bool useautoreconnect; - int autoreconnectinterval; - int autoreconnectretries; - bool unlimitedconnectretries; - bool rejoinchannels; - bool connected; + QString saslaccount; + QString saslpassword; + QString servercodec; + QString encodingcodec; + QString decodingcodec; QString usermode; QString awaymessage; QString attachperform; QString detachperform; + NetworkId networkid; + IdentityId identityid; + int messagerateburstsize; + int messageratedelay; + int autoreconnectinterval; + int autoreconnectretries; + bool rejoinchannels; + bool userandomserver; + bool useautoidentify; bool usesasl; - QString saslaccount; - QString saslpassword; + bool useautoreconnect; + bool unlimitedconnectretries; + bool usecustommessagerate; + bool unlimitedmessagerate; + bool connected; }; struct BufferMO { @@ -204,10 +243,14 @@ public: QString buffername; QString buffercname; int buffertype; - int lastseenmsgid; - int markerlinemsgid; + qint64 lastmsgid; + qint64 lastseenmsgid; + qint64 markerlinemsgid; + int bufferactivity; + int highlightcount; QString key; bool joined; + QString cipher; }; struct BacklogMO { @@ -216,7 +259,8 @@ public: BufferId bufferid; int type; int flags; - int senderid; + qint64 senderid; + QString senderprefixes; QString message; }; @@ -228,6 +272,7 @@ public: int port; QString password; bool ssl; + bool sslverify; /// If true, validate SSL certificates int sslversion; bool useproxy; int proxytype; @@ -243,6 +288,11 @@ public: QByteArray settingvalue; }; + struct CoreStateMO { + QString key; + QByteArray value; + }; + enum MigrationObject { QuasselUser, Sender, @@ -252,11 +302,11 @@ public: Buffer, Backlog, IrcServer, - UserSetting + UserSetting, + CoreState }; - AbstractSqlMigrator(); - virtual ~AbstractSqlMigrator() {} + virtual ~AbstractSqlMigrator() = default; static QString migrationObject(MigrationObject moType); @@ -280,7 +330,7 @@ protected: virtual bool commit() = 0; private: - QSqlQuery *_query; + QSqlQuery *_query{nullptr}; }; @@ -298,6 +348,7 @@ public: virtual bool readMo(BacklogMO &backlog) = 0; virtual bool readMo(IrcServerMO &ircserver) = 0; virtual bool readMo(UserSettingMO &userSetting) = 0; + virtual bool readMo(CoreStateMO &coreState) = 0; bool migrateTo(AbstractSqlMigrationWriter *writer); @@ -307,7 +358,7 @@ private: template bool transferMo(MigrationObject moType, T &mo); - AbstractSqlMigrationWriter *_writer; + AbstractSqlMigrationWriter *_writer{nullptr}; }; @@ -323,6 +374,7 @@ public: virtual bool writeMo(const BacklogMO &backlog) = 0; virtual bool writeMo(const IrcServerMO &ircserver) = 0; virtual bool writeMo(const UserSettingMO &userSetting) = 0; + virtual bool writeMo(const CoreStateMO &coreState) = 0; inline bool migrateFrom(AbstractSqlMigrationReader *reader) { return reader->migrateTo(this); } @@ -330,6 +382,3 @@ public: virtual inline bool postProcess() { return true; } friend class AbstractSqlMigrationReader; }; - - -#endif