From: Manuel Nickschas Date: Mon, 7 May 2018 20:20:10 +0000 (+0200) Subject: Some cleanups X-Git-Tag: travis-deploy-test~123 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=6422c61b11d97f905b6a27f2d280e9ec0d8bb3e2 Some cleanups * Use properly camel-cased method names * Use override instead of virtual to avoid warnings * Simplify some code Closes GH-348. --- diff --git a/src/core/core.cpp b/src/core/core.cpp index aa520633..aecb06e3 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -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 *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 diff --git a/src/core/core.h b/src/core/core.h index 91aafd27..5f909175 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -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; ///< Active storage backend DeferredSharedPtr _authenticator; ///< Active authenticator QTimer _storageSyncTimer; - QMap _authusernames; + QMap _authUserNames; #ifdef HAVE_SSL SslServer _server, _v6server; diff --git a/src/core/coreapplication.cpp b/src/core/coreapplication.cpp index 7f4388b2..25dd6851 100644 --- a/src/core/coreapplication.cpp +++ b/src/core/coreapplication.cpp @@ -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(); }); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 41bf2d6f..3cc3d07a 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -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) diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index ba54f00c..bd4350da 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -18,11 +18,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "oidentdconfiggenerator.h" -#include "corenetwork.h" - #include +#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()); diff --git a/src/core/oidentdconfiggenerator.h b/src/core/oidentdconfiggenerator.h index f4128d67..375636ce 100644 --- a/src/core/oidentdconfiggenerator.h +++ b/src/core/oidentdconfiggenerator.h @@ -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); diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index f976f095..af04a595 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -1702,7 +1702,9 @@ QList PostgreSqlStorage::requestAllMsgs(UserId user, MsgId first, MsgId return messagelist; } -QMap PostgreSqlStorage::getAllAuthusernames() { + +QMap PostgreSqlStorage::getAllAuthUserNames() +{ QMap authusernames; QSqlQuery query(logDb()); query.prepare(queryString("select_all_authusernames")); @@ -1715,7 +1717,9 @@ QMap 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")); diff --git a/src/core/postgresqlstorage.h b/src/core/postgresqlstorage.h index 2445c615..81439bbb 100644 --- a/src/core/postgresqlstorage.h +++ b/src/core/postgresqlstorage.h @@ -106,8 +106,8 @@ public slots: QList requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override; /* Sysident handling */ - virtual QMap getAllAuthusernames(); - virtual const QString getAuthusername(UserId user); + QMap getAllAuthUserNames() override; + QString getAuthUserName(UserId user) override; protected: bool initDbSession(QSqlDatabase &db) override; diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index 69c41b8f..a6d7671f 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -1820,7 +1820,8 @@ QList SqliteStorage::requestAllMsgs(UserId user, MsgId first, MsgId las return messagelist; } -QMap SqliteStorage::getAllAuthusernames() + +QMap SqliteStorage::getAllAuthUserNames() { QMap authusernames; @@ -1842,7 +1843,8 @@ QMap 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"; diff --git a/src/core/sqlitestorage.h b/src/core/sqlitestorage.h index fcc85ff4..aaf2d69a 100644 --- a/src/core/sqlitestorage.h +++ b/src/core/sqlitestorage.h @@ -107,8 +107,8 @@ public slots: QList requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) override; /* Sysident handling */ - virtual QMap getAllAuthusernames(); - virtual const QString getAuthusername(UserId user); + QMap getAllAuthUserNames() override; + QString getAuthUserName(UserId user) override; protected: void setConnectionProperties(const QVariantMap & /* properties */) override {} diff --git a/src/core/storage.h b/src/core/storage.h index c809a7f4..b915d047 100644 --- a/src/core/storage.h +++ b/src/core/storage.h @@ -445,13 +445,13 @@ public slots: //! Fetch all authusernames /** \return Map of all current UserIds to permitted idents */ - virtual QMap getAllAuthusernames() = 0; + virtual QMap 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.