Some cleanups
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 7 May 2018 20:20:10 +0000 (22:20 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 7 May 2018 20:38:41 +0000 (22:38 +0200)
* Use properly camel-cased method names
* Use override instead of virtual to avoid warnings
* Simplify some code

Closes GH-348.

src/core/core.cpp
src/core/core.h
src/core/coreapplication.cpp
src/core/coresession.cpp
src/core/oidentdconfiggenerator.cpp
src/core/oidentdconfiggenerator.h
src/core/postgresqlstorage.cpp
src/core/postgresqlstorage.h
src/core/sqlitestorage.cpp
src/core/sqlitestorage.h
src/core/storage.h

index aa52063..aecb06e 100644 (file)
@@ -239,7 +239,7 @@ void Core::init()
     if (Quassel::isOptionSet("oidentd")) {
         _oidentdConfigGenerator = new OidentdConfigGenerator(Quassel::isOptionSet("oidentd-strict"), this);
         if (Quassel::isOptionSet("oidentd-strict")) {
-            cacheSysident();
+            cacheSysIdent();
         }
     }
 }
@@ -333,7 +333,7 @@ QString Core::setupCore(const QString &adminUser, const QString &adminPassword,
 
     quInfo() << qPrintable(tr("Creating admin user..."));
     _storage->addUser(adminUser, adminPassword);
-    cacheSysident();
+    cacheSysIdent();
     startListening(); // TODO check when we need this
     return QString();
 }
@@ -553,32 +553,35 @@ bool Core::reloadCerts()
 #endif
 }
 
-void Core::cacheSysident() {
-    if(isConfigured()) {
-        instance()->_authusernames = instance()->_storage->getAllAuthusernames();
+
+void Core::cacheSysIdent()
+{
+    if (isConfigured()) {
+        instance()->_authUserNames = instance()->_storage->getAllAuthUserNames();
     }
 }
 
-QString Core::strictSysident(UserId user) {
-    QMap<UserId, QString> *allAuthusernames = &instance()->_authusernames;
-    auto authusername = allAuthusernames->find(user);
-    if (authusername == allAuthusernames->end()) {
-        // A new user got added since we last pulled our cache from the database.
-        // There's no way to avoid a database hit - we don't even know the authname!
-        cacheSysident();
-        authusername = allAuthusernames->find(user);
-        if (authusername == allAuthusernames->end()) {
-            // ...something very weird is going on if we ended up here (an active CoreSession without a corresponding database entry?)
-            QDebug d = qWarning();
-            d << "Unable to find authusername for UserId" << user;
-            d.nospace();
-            d << ", this should never happen!";
-            return "unknown"; // Should we just terminate the program instead?
-        }
+
+QString Core::strictSysIdent(UserId user) const
+{
+    if (_authUserNames.contains(user)) {
+        return _authUserNames[user];
     }
-    return *authusername;
+
+    // A new user got added since we last pulled our cache from the database.
+    // There's no way to avoid a database hit - we don't even know the authname!
+    cacheSysIdent();
+
+    if (_authUserNames.contains(user)) {
+        return _authUserNames[user];
+    }
+
+    // ...something very weird is going on if we ended up here (an active CoreSession without a corresponding database entry?)
+    qWarning().nospace() << "Unable to find authusername for UserId " << user << ", this should never happen!";
+    return "unknown"; // Should we just terminate the program instead?
 }
 
+
 bool Core::startListening()
 {
     // in mono mode we only start a local port if a port is specified in the cli call
index 91aafd2..5f90917 100644 (file)
@@ -497,15 +497,15 @@ public:
     /** \param user  The user to retrieve the username for
      *  \return      The username for the user
      */
-    static inline const QString getAuthusername(UserId user) {
-        return instance()->_storage->getAuthusername(user);
+    static inline QString getAuthUserName(UserId user) {
+        return instance()->_storage->getAuthUserName(user);
     }
 
     //! Get a usable sysident for the given user in oidentd-strict mode
     /** \param user    The user to retrieve the sysident for
      *  \return The authusername
      */
-    QString strictSysident(UserId user);
+    QString strictSysIdent(UserId user) const;
 
 
     //! Get a Hash of all last seen message ids
@@ -590,7 +590,7 @@ public:
      */
     static bool reloadCerts();
 
-    static void cacheSysident();
+    static void cacheSysIdent();
 
     static QVariantList backendInfo();
     static QVariantList authenticatorInfo();
@@ -675,7 +675,7 @@ private:
     DeferredSharedPtr<Storage>       _storage;        ///< Active storage backend
     DeferredSharedPtr<Authenticator> _authenticator;  ///< Active authenticator
     QTimer _storageSyncTimer;
-    QMap<UserId, QString> _authusernames;
+    QMap<UserId, QString> _authUserNames;
 
 #ifdef HAVE_SSL
     SslServer _server, _v6server;
index 7f4388b..25dd685 100644 (file)
@@ -57,7 +57,7 @@ bool CoreApplicationInternal::init()
 
     Quassel::registerReloadHandler([]() {
         // Currently, only reloading SSL certificates and the sysident cache is supported
-        Core::cacheSysident();
+        Core::cacheSysIdent();
         return Core::reloadCerts();
     });
 
index 41bf2d6..3cc3d07 100644 (file)
@@ -509,7 +509,7 @@ void CoreSession::createIdentity(const Identity &identity, const QVariantMap &ad
 }
 
 const QString CoreSession::strictSysident() {
-    return Core::instance()->strictSysident(_user);
+    return Core::instance()->strictSysIdent(_user);
 }
 
 void CoreSession::createIdentity(const CoreIdentity &identity)
index ba54f00..bd4350d 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#include "oidentdconfiggenerator.h"
-#include "corenetwork.h"
-
 #include <QString>
 
+#include "corenetwork.h"
+#include "oidentdconfiggenerator.h"
+
 OidentdConfigGenerator::OidentdConfigGenerator(bool strict, QObject *parent) :
     QObject(parent),
     _initialized(false),
@@ -69,7 +69,8 @@ bool OidentdConfigGenerator::init()
     return _initialized;
 }
 
-const QString OidentdConfigGenerator::sysidentForIdentity(const CoreIdentity *identity) {
+
+QString OidentdConfigGenerator::sysIdentForIdentity(const CoreIdentity *identity) const {
     if (!_strict) {
         return identity->ident();
     }
@@ -77,10 +78,11 @@ const QString OidentdConfigGenerator::sysidentForIdentity(const CoreIdentity *id
     return network->coreSession()->strictSysident();
 }
 
+
 bool OidentdConfigGenerator::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort)
 {
     Q_UNUSED(localAddress) Q_UNUSED(peerAddress) Q_UNUSED(peerPort)
-    const QString ident = sysidentForIdentity(identity);
+    const QString ident = sysIdentForIdentity(identity);
 
     _quasselConfig.append(_quasselStanzaTemplate.arg(localPort).arg(ident).arg(_configTag).toLatin1());
 
index f4128d6..375636c 100644 (file)
@@ -71,7 +71,7 @@ public slots:
     bool removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort);
 
 private:
-    const QString sysidentForIdentity(const CoreIdentity *identity);
+    QString sysIdentForIdentity(const CoreIdentity *identity) const;
     bool init();
     bool writeConfig();
     bool parseConfig(bool readQuasselStanzas = false);
index f976f09..af04a59 100644 (file)
@@ -1702,7 +1702,9 @@ QList<Message> PostgreSqlStorage::requestAllMsgs(UserId user, MsgId first, MsgId
     return messagelist;
 }
 
-QMap<UserId, QString> PostgreSqlStorage::getAllAuthusernames() {
+
+QMap<UserId, QString> PostgreSqlStorage::getAllAuthUserNames()
+{
     QMap<UserId, QString> authusernames;
     QSqlQuery query(logDb());
     query.prepare(queryString("select_all_authusernames"));
@@ -1715,7 +1717,9 @@ QMap<UserId, QString> PostgreSqlStorage::getAllAuthusernames() {
     return authusernames;
 }
 
-const QString PostgreSqlStorage::getAuthusername(UserId user) {
+
+QString PostgreSqlStorage::getAuthUserName(UserId user)
+{
     QString authusername;
     QSqlQuery query(logDb());
     query.prepare(queryString("select_authusername"));
index 2445c61..81439bb 100644 (file)
@@ -106,8 +106,8 @@ public slots:
     QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override;
 
     /* Sysident handling */
-    virtual QMap<UserId, QString> getAllAuthusernames();
-    virtual const QString getAuthusername(UserId user);
+    QMap<UserId, QString> getAllAuthUserNames() override;
+    QString getAuthUserName(UserId user) override;
 
 protected:
     bool initDbSession(QSqlDatabase &db) override;
index 69c41b8..a6d7671 100644 (file)
@@ -1820,7 +1820,8 @@ QList<Message> SqliteStorage::requestAllMsgs(UserId user, MsgId first, MsgId las
     return messagelist;
 }
 
-QMap<UserId, QString> SqliteStorage::getAllAuthusernames()
+
+QMap<UserId, QString> SqliteStorage::getAllAuthUserNames()
 {
     QMap<UserId, QString> authusernames;
 
@@ -1842,7 +1843,8 @@ QMap<UserId, QString> SqliteStorage::getAllAuthusernames()
     return authusernames;
 }
 
-const QString SqliteStorage::getAuthusername(UserId user) {
+
+QString SqliteStorage::getAuthUserName(UserId user) {
     QString authusername;
     QSqlQuery query(logDb());
     query.prepare(queryString("select_authusername"));
@@ -1860,6 +1862,7 @@ const QString SqliteStorage::getAuthusername(UserId user) {
     return authusername;
 }
 
+
 QString SqliteStorage::backlogFile()
 {
     return Quassel::configDirPath() + "quassel-storage.sqlite";
index fcc85ff..aaf2d69 100644 (file)
@@ -107,8 +107,8 @@ public slots:
     QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override;
 
     /* Sysident handling */
-    virtual QMap<UserId, QString> getAllAuthusernames();
-    virtual const QString getAuthusername(UserId user);
+    QMap<UserId, QString> getAllAuthUserNames() override;
+    QString getAuthUserName(UserId user) override;
 
 protected:
     void setConnectionProperties(const QVariantMap & /* properties */)  override {}
index c809a7f..b915d04 100644 (file)
@@ -445,13 +445,13 @@ public slots:
     //! Fetch all authusernames
     /** \return      Map of all current UserIds to permitted idents
      */
-    virtual QMap<UserId, QString> getAllAuthusernames() = 0;
+    virtual QMap<UserId, QString> getAllAuthUserNames() = 0;
 
     //! Get the auth username associated with a userId
     /** \param user  The user to retrieve the username for
      *  \return      The username for the user
      */
-    virtual const QString getAuthusername(UserId user) = 0;
+    virtual QString getAuthUserName(UserId user) = 0;
 
 signals:
     //! Sent when a new BufferInfo is created, or an existing one changed somehow.