cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / core / core.h
index b5ca2c1..acbac95 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2018 by the Quassel Project                        *
+ *   Copyright (C) 2005-2022 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include <QDateTime>
 #include <QPointer>
+#include <QSslSocket>
 #include <QString>
 #include <QTimer>
 #include <QVariant>
 
-#ifdef HAVE_SSL
-#    include <QSslSocket>
-
-#    include "sslserver.h"
-#else
-#    include <QTcpServer>
-#    include <QTcpSocket>
-#endif
-
 #include "authenticator.h"
 #include "bufferinfo.h"
 #include "deferredptr.h"
 #include "identserver.h"
 #include "message.h"
+#include "metricsserver.h"
 #include "oidentdconfiggenerator.h"
 #include "sessionthread.h"
 #include "singleton.h"
+#include "sslserver.h"
 #include "storage.h"
 #include "types.h"
 
@@ -125,6 +119,26 @@ public:
         return instance()->_storage->getUserAuthenticator(userid) == authenticator;
     }
 
+    //! Gets the authenticator configured for a user.
+    /**
+     * \param userName The user's name as a QString.
+     * \return String value corresponding to the user's configure dauthenticator.
+     */
+    static inline QString getUserAuthenticator(const QString& userName)
+    {
+        return instance()->_storage->getUserAuthenticator(instance()->_storage->getUserId(userName));
+    }
+
+    //! Gets the user ID mapped to a username. This is necessary so that non-database auth methods can log in users properly.
+    /**
+     * \param userName The user's name as a QString.
+     * \return userId  The user's ID.
+     */
+    static inline UserId getUserId(const QString& userName)
+    {
+        return instance()->_storage->getUserId(userName);
+    }
+
     //! Change a user's password
     /**
      * \param userId     The user's ID
@@ -173,14 +187,14 @@ public:
 
     static void removeIdentity(UserId user, IdentityId identityId) { instance()->_storage->removeIdentity(user, identityId); }
 
-    static QList<CoreIdentity> identities(UserId user) { return instance()->_storage->identities(user); }
+    static std::vector<CoreIdentity> identities(UserId user) { return instance()->_storage->identities(user); }
 
     //! Create a Network in the Storage and store it's Id in the given NetworkInfo
     /** \note This method is thredsafe.
      *
      *  \param user        The core user
      *  \param networkInfo a NetworkInfo definition to store the newly created ID in
-     *  \return true if successfull.
+     *  \return true if successful.
      */
     static bool createNetwork(UserId user, NetworkInfo& info);
 
@@ -189,7 +203,7 @@ public:
      *
      *  \param user        The core user
      *  \param networkInfo The Updated NetworkInfo
-     *  \return true if successfull.
+     *  \return true if successful.
      */
     static inline bool updateNetwork(UserId user, const NetworkInfo& info) { return instance()->_storage->updateNetwork(user, info); }
 
@@ -198,7 +212,7 @@ public:
      *
      *  \param user        The core user
      *  \param networkId   The network to delete
-     *  \return true if successfull.
+     *  \return true if successful.
      */
     static inline bool removeNetwork(UserId user, const NetworkId& networkId)
     {
@@ -209,9 +223,9 @@ public:
     /** \note This method is thredsafe.
      *
      *  \param user        The core user
-     *  \return QList<NetworkInfo>.
+     *  \return std::vector<NetworkInfo>.
      */
-    static inline QList<NetworkInfo> networks(UserId user) { return instance()->_storage->networks(user); }
+    static inline std::vector<NetworkInfo> networks(UserId user) { return instance()->_storage->networks(user); }
 
     //! Get a list of Networks to restore
     /** Return a list of networks the user was connected at the time of core shutdown
@@ -219,7 +233,7 @@ public:
      *
      *  \param user  The User Id in question
      */
-    static inline QList<NetworkId> connectedNetworks(UserId user) { return instance()->_storage->connectedNetworks(user); }
+    static inline std::vector<NetworkId> connectedNetworks(UserId user) { return instance()->_storage->connectedNetworks(user); }
 
     //! Update the connected state of a network
     /** \note This method is threadsafe
@@ -343,7 +357,7 @@ public:
      *  \param networkId The network id
      *  \param type      The type of the buffer (StatusBuffer, Channel, etc.)
      *  \param buffer    The buffer name (if empty, the net's status buffer is returned)
-     *  \param create    Whether or not the buffer should be created if it doesnt exist
+     *  \param create    Whether or not the buffer should be created if it doesn't exist
      *  \return The BufferInfo corresponding to the given network and buffer name, or 0 if not found
      */
     static inline BufferInfo bufferInfo(
@@ -386,7 +400,7 @@ public:
      *  \param limit    if != -1 limit the returned list to a max of \limit entries
      *  \return The requested list of messages
      */
-    static inline QList<Message> requestMsgs(UserId user, BufferId bufferId, MsgId first = -1, MsgId last = -1, int limit = -1)
+    static inline std::vector<Message> requestMsgs(UserId user, BufferId bufferId, MsgId first = -1, MsgId last = -1, int limit = -1)
     {
         return instance()->_storage->requestMsgs(user, bufferId, first, last, limit);
     }
@@ -399,7 +413,7 @@ public:
      *  \param type     The Message::Types that should be returned
      *  \return The requested list of messages
      */
-    static inline QList<Message> requestMsgsFiltered(UserId user,
+    static inline std::vector<Message> requestMsgsFiltered(UserId user,
                                                      BufferId bufferId,
                                                      MsgId first = -1,
                                                      MsgId last = -1,
@@ -410,13 +424,33 @@ public:
         return instance()->_storage->requestMsgsFiltered(user, bufferId, first, last, limit, type, flags);
     }
 
+    //! Request a certain number messages stored in a given buffer, matching certain filters, ascending
+    /** \param buffer   The buffer we request messages from
+     *  \param first    if != -1 return only messages with a MsgId >= first
+     *  \param last     if != -1 return only messages with a MsgId < last
+     *  \param limit    if != -1 limit the returned list to a max of \limit entries
+     *  \param type     The Message::Types that should be returned
+     *  \param flags     The Message::Flags that should be returned
+     *  \return The requested list of messages
+     */
+    static inline std::vector<Message> requestMsgsForward(UserId user,
+                                                           BufferId bufferId,
+                                                           MsgId first = -1,
+                                                           MsgId last = -1,
+                                                           int limit = -1,
+                                                           Message::Types type = Message::Types{-1},
+                                                           Message::Flags flags = Message::Flags{-1})
+    {
+        return instance()->_storage->requestMsgsForward(user, bufferId, first, last, limit, type, flags);
+    }
+
     //! 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)
+    static inline std::vector<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1)
     {
         return instance()->_storage->requestAllMsgs(user, first, last, limit);
     }
@@ -428,7 +462,7 @@ public:
      *  \param type     The Message::Types that should be returned
      *  \return The requested list of messages
      */
-    static inline QList<Message> requestAllMsgsFiltered(UserId user,
+    static inline std::vector<Message> requestAllMsgsFiltered(UserId user,
                                                         MsgId first = -1,
                                                         MsgId last = -1,
                                                         int limit = -1,
@@ -445,7 +479,7 @@ public:
      *  \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); }
+    static inline std::vector<BufferInfo> requestBuffers(UserId user) { return instance()->_storage->requestBuffers(user); }
 
     //! Request a list of BufferIds for a given NetworkId
     /** \note This method is threadsafe.
@@ -454,7 +488,7 @@ public:
      *  \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)
+    static inline std::vector<BufferId> requestBufferIdsForNetwork(UserId user, NetworkId networkId)
     {
         return instance()->_storage->requestBufferIdsForNetwork(user, networkId);
     }
@@ -465,7 +499,7 @@ public:
      *
      *  \param user      The user who is the owner of the buffer
      *  \param bufferId  The bufferId
-     *  \return true if successfull
+     *  \return true if successful
      */
     static inline bool removeBuffer(const UserId& user, const BufferId& bufferId)
     {
@@ -477,7 +511,7 @@ public:
      *  \param user      The id of the buffer owner
      *  \param bufferId  The bufferId
      *  \param newName   The new name of the buffer
-     *  \return true if successfull
+     *  \return true if successful
      */
     static inline bool renameBuffer(const UserId& user, const BufferId& bufferId, const QString& newName)
     {
@@ -489,7 +523,7 @@ public:
      *  \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
+     *  \return true if successful
      */
     static inline bool mergeBuffersPermanently(const UserId& user, const BufferId& bufferId1, const BufferId& bufferId2)
     {
@@ -515,6 +549,14 @@ public:
      */
     QString strictSysIdent(UserId user) const;
 
+    //! Get a Hash of all last message ids
+    /** This Method is called when the Quassel Core is started to restore the lastMsgIds
+     *  \note This method is threadsafe.
+     *
+     * \param user      The Owner of the buffers
+     */
+    static inline QHash<BufferId, MsgId> bufferLastMsgIds(UserId user) { return instance()->_storage->bufferLastMsgIds(user); }
+
     //! 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.
@@ -635,6 +677,7 @@ public:
 
     inline OidentdConfigGenerator* oidentdConfigGenerator() const { return _oidentdConfigGenerator; }
     inline IdentServer* identServer() const { return _identServer; }
+    inline MetricsServer* metricsServer() const { return _metricsServer; }
 
     static const int AddClientEventId;
 
@@ -751,11 +794,7 @@ private:
 
     QTimer _storageSyncTimer;
 
-#ifdef HAVE_SSL
     SslServer _server, _v6server;
-#else
-    QTcpServer _server, _v6server;
-#endif
 
     OidentdConfigGenerator* _oidentdConfigGenerator{nullptr};
 
@@ -765,6 +804,7 @@ private:
     QDateTime _startTime;
 
     IdentServer* _identServer{nullptr};
+    MetricsServer* _metricsServer{nullptr};
 
     bool _initialized{false};
     bool _configured{false};