identd: Remove unneeded strict attribute
[quassel.git] / src / core / abstractsqlstorage.h
index c39e826..5d77cf3 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2015 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  *
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef ABSTRACTSQLSTORAGE_H
-#define ABSTRACTSQLSTORAGE_H
+#pragma once
 
 #include "storage.h"
 
+#include <memory>
+
 #include <QSqlDatabase>
 #include <QSqlQuery>
 #include <QSqlError>
@@ -38,20 +39,40 @@ public:
     AbstractSqlStorage(QObject *parent = 0);
     virtual ~AbstractSqlStorage();
 
-    virtual inline AbstractSqlMigrationReader *createMigrationReader() { return 0; }
-    virtual inline AbstractSqlMigrationWriter *createMigrationWriter() { return 0; }
+    virtual std::unique_ptr<AbstractSqlMigrationReader> createMigrationReader() { return {}; }
+    virtual std::unique_ptr<AbstractSqlMigrationWriter> createMigrationWriter() { return {}; }
 
 public slots:
-    virtual State init(const QVariantMap &settings = QVariantMap());
-    virtual bool setup(const QVariantMap &settings = QVariantMap());
+    virtual State init(const QVariantMap &settings = QVariantMap(),
+                       const QProcessEnvironment &environment = {},
+                       bool loadFromEnvironment = false);
+    virtual bool setup(const QVariantMap &settings = QVariantMap(),
+                       const QProcessEnvironment &environment = {},
+                       bool loadFromEnvironment = false);
 
 protected:
     inline virtual void sync() {};
 
     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; }
@@ -101,6 +124,14 @@ private:
     QHash<QThread *, Connection *> _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
@@ -131,11 +162,15 @@ public:
         UserId id;
         QString username;
         QString password;
+        int hashversion;
+        QString authenticator;
     };
 
     struct SenderMO {
-        int senderId;
+        qint64 senderId;
         QString sender;
+        QString realname;
+        QString avatarurl;
         SenderMO() : senderId(0) {}
     };
 
@@ -154,7 +189,7 @@ public:
         bool autoAwayReasonEnabled;
         bool detachAwayEnabled;
         QString detachAwayReason;
-        bool detchAwayReasonEnabled;
+        bool detachAwayReasonEnabled;
         QString ident;
         QString kickReason;
         QString partReason;
@@ -187,6 +222,12 @@ public:
         int autoreconnectretries;
         bool unlimitedconnectretries;
         bool rejoinchannels;
+        // Custom rate limiting
+        bool usecustommessagerate;
+        int messagerateburstsize;
+        int messageratedelay;
+        bool unlimitedmessagerate;
+        // ...
         bool connected;
         QString usermode;
         QString awaymessage;
@@ -205,10 +246,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 {
@@ -217,7 +262,8 @@ public:
         BufferId bufferid;
         int type;
         int flags;
-        int senderid;
+        qint64 senderid;
+        QString senderprefixes;
         QString message;
     };
 
@@ -229,6 +275,7 @@ public:
         int port;
         QString password;
         bool ssl;
+        bool sslverify;     /// If true, validate SSL certificates
         int sslversion;
         bool useproxy;
         int proxytype;
@@ -244,6 +291,11 @@ public:
         QByteArray settingvalue;
     };
 
+    struct CoreStateMO {
+        QString key;
+        QByteArray value;
+    };
+
     enum MigrationObject {
         QuasselUser,
         Sender,
@@ -253,7 +305,8 @@ public:
         Buffer,
         Backlog,
         IrcServer,
-        UserSetting
+        UserSetting,
+        CoreState
     };
 
     AbstractSqlMigrator();
@@ -299,6 +352,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);
 
@@ -324,6 +378,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); }
 
@@ -331,6 +386,3 @@ public:
     virtual inline bool postProcess() { return true; }
     friend class AbstractSqlMigrationReader;
 };
-
-
-#endif