+ //! Request a certain number of messages across all buffers
+ /** \param first if != -1 return only messages with a MsgId >= first
+ * \param last if != -1 return only messages with a MsgId < last
+ * \param limit Max amount of messages
+ * \return The requested list of messages
+ */
+ static inline QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1)
+ {
+ return instance()->_storage->requestAllMsgs(user, first, last, limit);
+ }
+
+
+ //! Request a list of all buffers known to a user.
+ /** This method is used to get a list of all buffers we have stored a backlog from.
+ * \note This method is threadsafe.
+ *
+ * \param user The user whose buffers we request
+ * \return A list of the BufferInfos for all buffers as requested
+ */
+ static inline QList<BufferInfo> requestBuffers(UserId user)
+ {
+ return instance()->_storage->requestBuffers(user);
+ }
+
+
+ //! Request a list of BufferIds for a given NetworkId
+ /** \note This method is threadsafe.
+ *
+ * \param user The user whose buffers we request
+ * \param networkId The NetworkId of the network in question
+ * \return List of BufferIds belonging to the Network
+ */
+ static inline QList<BufferId> requestBufferIdsForNetwork(UserId user, NetworkId networkId)
+ {
+ return instance()->_storage->requestBufferIdsForNetwork(user, networkId);
+ }
+
+
+ //! Remove permanently a buffer and it's content from the storage backend
+ /** This call cannot be reverted!
+ * \note This method is threadsafe.
+ *
+ * \param user The user who is the owner of the buffer
+ * \param bufferId The bufferId
+ * \return true if successfull
+ */
+ static inline bool removeBuffer(const UserId &user, const BufferId &bufferId)
+ {
+ return instance()->_storage->removeBuffer(user, bufferId);
+ }
+
+
+ //! Rename a Buffer
+ /** \note This method is threadsafe.
+ * \param user The id of the buffer owner
+ * \param bufferId The bufferId
+ * \param newName The new name of the buffer
+ * \return true if successfull
+ */
+ static inline bool renameBuffer(const UserId &user, const BufferId &bufferId, const QString &newName)
+ {
+ return instance()->_storage->renameBuffer(user, bufferId, newName);
+ }
+
+
+ //! Merge the content of two Buffers permanently. This cannot be reversed!
+ /** \note This method is threadsafe.
+ * \param user The id of the buffer owner
+ * \param bufferId1 The bufferId of the remaining buffer
+ * \param bufferId2 The buffer that is about to be removed
+ * \return true if successfulln
+ */
+ static inline bool mergeBuffersPermanently(const UserId &user, const BufferId &bufferId1, const BufferId &bufferId2)
+ {
+ return instance()->_storage->mergeBuffersPermanently(user, bufferId1, bufferId2);
+ }
+
+
+ //! Update the LastSeenDate for a Buffer
+ /** This Method is used to make the LastSeenDate of a Buffer persistent
+ * \note This method is threadsafe.
+ *
+ * \param user The Owner of that Buffer
+ * \param bufferId The buffer id
+ * \param MsgId The Message id of the message that has been just seen
+ */
+ static inline void setBufferLastSeenMsg(UserId user, const BufferId &bufferId, const MsgId &msgId)
+ {
+ return instance()->_storage->setBufferLastSeenMsg(user, bufferId, msgId);
+ }
+
+
+ //! Get a Hash of all last seen message ids
+ /** This Method is called when the Quassel Core is started to restore the lastSeenMsgIds
+ * \note This method is threadsafe.
+ *
+ * \param user The Owner of the buffers
+ */
+ static inline QHash<BufferId, MsgId> bufferLastSeenMsgIds(UserId user)
+ {
+ return instance()->_storage->bufferLastSeenMsgIds(user);
+ }
+
+
+ //! Update the MarkerLineMsgId for a Buffer
+ /** This Method is used to make the marker line position of a Buffer persistent
+ * \note This method is threadsafe.
+ *
+ * \param user The Owner of that Buffer
+ * \param bufferId The buffer id
+ * \param MsgId The Message id where the marker line should be placed
+ */
+ static inline void setBufferMarkerLineMsg(UserId user, const BufferId &bufferId, const MsgId &msgId)
+ {
+ return instance()->_storage->setBufferMarkerLineMsg(user, bufferId, msgId);
+ }
+
+
+ //! Get a Hash of all marker line message ids
+ /** This Method is called when the Quassel Core is started to restore the MarkerLineMsgIds
+ * \note This method is threadsafe.
+ *
+ * \param user The Owner of the buffers
+ */
+ static inline QHash<BufferId, MsgId> bufferMarkerLineMsgIds(UserId user)
+ {
+ return instance()->_storage->bufferMarkerLineMsgIds(user);
+ }
+
+
+ static inline QDateTime startTime() { return instance()->_startTime; }
+ static inline bool isConfigured() { return instance()->_configured; }
+ static bool sslSupported();
+
+ /**
+ * Reloads SSL certificates used for connection with clients
+ *
+ * @return True if certificates reloaded successfully, otherwise false.
+ */
+ static bool reloadCerts();
+
+ static QVariantList backendInfo();
+
+ /**
+ * Checks if a storage backend is the default storage backend. This
+ * hardcodes this information into the core (not the client).
+ *
+ * \param backend The backend to check.
+ *
+ * @return True if storage backend is default, false otherwise.
+ */
+ static inline bool isStorageBackendDefault(const Storage *backend)
+ {
+ return (backend->displayName() == "SQLite") ? true : false;
+ }
+
+ static QString setup(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData);
+
+ static inline QTimer &syncTimer() { return instance()->_storageSyncTimer; }
+
+ inline OidentdConfigGenerator *oidentdConfigGenerator() const { return _oidentdConfigGenerator; }
+
+ static const int AddClientEventId;
+
+public slots:
+ //! Make storage data persistent
+ /** \note This method is threadsafe.
+ */
+ void syncStorage();
+ void setupInternalClientSession(InternalPeer *clientConnection);
+ QString setupCore(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData);
+
+signals:
+ //! Sent when a BufferInfo is updated in storage.
+ void bufferInfoUpdated(UserId user, const BufferInfo &info);
+
+ //! Relay from CoreSession::sessionState(). Used for internal connection only
+ void sessionState(const Protocol::SessionState &sessionState);
+
+protected:
+ virtual void customEvent(QEvent *event);
+
+private slots:
+ bool startListening();
+ void stopListening(const QString &msg = QString());
+ void incomingConnection();
+ void clientDisconnected();
+
+ bool initStorage(const QString &backend, const QVariantMap &settings, bool setup = false);
+
+ void socketError(QAbstractSocket::SocketError err, const QString &errorString);
+ void setupClientSession(RemotePeer *, UserId);
+
+ bool changeUserPass(const QString &username);
+
+private:
+ Core();
+ ~Core();
+ void init();
+ static Core *instanceptr;
+
+ SessionThread *sessionForUser(UserId userId, bool restoreState = false);
+ void addClientHelper(RemotePeer *peer, UserId uid);
+ //void processCoreSetup(QTcpSocket *socket, QVariantMap &msg);
+ QString setupCoreForInternalUsage();
+
+ void registerStorageBackends();
+ bool registerStorageBackend(Storage *);
+ void unregisterStorageBackends();
+ void unregisterStorageBackend(Storage *);
+ bool selectBackend(const QString &backend);
+ bool createUser();
+ void saveBackendSettings(const QString &backend, const QVariantMap &settings);
+ QVariantMap promptForSettings(const Storage *storage);
+
+private:
+ QSet<CoreAuthHandler *> _connectingClients;
+ QHash<UserId, SessionThread *> _sessions;
+ Storage *_storage;
+ QTimer _storageSyncTimer;
+
+#ifdef HAVE_SSL
+ SslServer _server, _v6server;
+#else
+ QTcpServer _server, _v6server;
+#endif
+
+ OidentdConfigGenerator *_oidentdConfigGenerator;
+
+ QHash<QString, Storage *> _storageBackends;
+
+ QDateTime _startTime;
+
+ bool _configured;
+
+ static AbstractSqlMigrationReader *getMigrationReader(Storage *storage);
+ static AbstractSqlMigrationWriter *getMigrationWriter(Storage *storage);
+ static void stdInEcho(bool on);
+ static inline void enableStdInEcho() { stdInEcho(true); }
+ static inline void disableStdInEcho() { stdInEcho(false); }
+};