identd: Remove unneeded strict attribute
[quassel.git] / src / core / core.cpp
index 7d20fa7..d596344 100644 (file)
@@ -81,6 +81,12 @@ Core::Core()
         delete _instance;
     }
     _instance = this;
         delete _instance;
     }
     _instance = this;
+
+    // Parent all QObject-derived attributes, so when the Core instance gets moved into another
+    // thread, they get moved with it
+    _server.setParent(this);
+    _v6server.setParent(this);
+    _storageSyncTimer.setParent(this);
 }
 
 
 }
 
 
@@ -98,14 +104,17 @@ bool Core::init()
 {
     _startTime = QDateTime::currentDateTime().toUTC(); // for uptime :)
 
 {
     _startTime = QDateTime::currentDateTime().toUTC(); // for uptime :)
 
-    Quassel::loadTranslation(QLocale::system());
+    if (Quassel::runMode() == Quassel::RunMode::CoreOnly) {
+        Quassel::loadTranslation(QLocale::system());
+    }
 
     // check settings version
     // so far, we only have 1
     CoreSettings s;
     if (s.version() != 1) {
         qCritical() << "Invalid core settings version, terminating!";
 
     // check settings version
     // so far, we only have 1
     CoreSettings s;
     if (s.version() != 1) {
         qCritical() << "Invalid core settings version, terminating!";
-        exit(EXIT_FAILURE);
+        QCoreApplication::exit(EXIT_FAILURE);
+        return false;
     }
 
     // Set up storage and authentication backends
     }
 
     // Set up storage and authentication backends
@@ -149,13 +158,15 @@ bool Core::init()
     }
 
     if (Quassel::isOptionSet("select-backend") || Quassel::isOptionSet("select-authenticator")) {
     }
 
     if (Quassel::isOptionSet("select-backend") || Quassel::isOptionSet("select-authenticator")) {
+        bool success{true};
         if (Quassel::isOptionSet("select-backend")) {
         if (Quassel::isOptionSet("select-backend")) {
-            selectBackend(Quassel::optionValue("select-backend"));
+            success &= selectBackend(Quassel::optionValue("select-backend"));
         }
         if (Quassel::isOptionSet("select-authenticator")) {
         }
         if (Quassel::isOptionSet("select-authenticator")) {
-            selectAuthenticator(Quassel::optionValue("select-authenticator"));
+            success &= selectAuthenticator(Quassel::optionValue("select-authenticator"));
         }
         }
-        exit(EXIT_SUCCESS);
+        QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+        return success;
     }
 
     if (!_configured) {
     }
 
     if (!_configured) {
@@ -165,7 +176,8 @@ bool Core::init()
 
             if (!_configured) {
                 qWarning() << "Cannot configure from environment";
 
             if (!_configured) {
                 qWarning() << "Cannot configure from environment";
-                exit(EXIT_FAILURE);
+                QCoreApplication::exit(EXIT_FAILURE);
+                return false;
             }
         }
         else {
             }
         }
         else {
@@ -175,12 +187,14 @@ bool Core::init()
                         << qPrintable(tr("Currently, Quassel supports SQLite3 and PostgreSQL. You need to build your\n"
                                          "Qt library with the sqlite or postgres plugin enabled in order for quasselcore\n"
                                          "to work."));
                         << qPrintable(tr("Currently, Quassel supports SQLite3 and PostgreSQL. You need to build your\n"
                                          "Qt library with the sqlite or postgres plugin enabled in order for quasselcore\n"
                                          "to work."));
-                exit(EXIT_FAILURE); // TODO make this less brutal (especially for mono client -> popup)
+                QCoreApplication::exit(EXIT_FAILURE); // TODO make this less brutal (especially for mono client -> popup)
+                return false;
             }
 
             if (writeError) {
                 qWarning() << "Cannot write quasselcore configuration; probably a permission problem.";
             }
 
             if (writeError) {
                 qWarning() << "Cannot write quasselcore configuration; probably a permission problem.";
-                exit(EXIT_FAILURE);
+                QCoreApplication::exit(EXIT_FAILURE);
+                return false;
             }
 
             quInfo() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
             }
 
             quInfo() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
@@ -188,11 +202,15 @@ bool Core::init()
     }
     else {
         if (Quassel::isOptionSet("add-user")) {
     }
     else {
         if (Quassel::isOptionSet("add-user")) {
-            exit(createUser() ? EXIT_SUCCESS : EXIT_FAILURE);
+            bool success = createUser();
+            QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+            return success;
         }
 
         if (Quassel::isOptionSet("change-userpass")) {
         }
 
         if (Quassel::isOptionSet("change-userpass")) {
-            exit(changeUserPass(Quassel::optionValue("change-userpass")) ? EXIT_SUCCESS : EXIT_FAILURE);
+            bool success = changeUserPass(Quassel::optionValue("change-userpass"));
+            QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+            return success;
         }
 
         _strictIdentEnabled = Quassel::isOptionSet("strict-ident");
         }
 
         _strictIdentEnabled = Quassel::isOptionSet("strict-ident");
@@ -204,6 +222,11 @@ bool Core::init()
             _oidentdConfigGenerator = new OidentdConfigGenerator(this);
         }
 
             _oidentdConfigGenerator = new OidentdConfigGenerator(this);
         }
 
+
+        if (Quassel::isOptionSet("ident-daemon")) {
+            _identServer = new IdentServer(this);
+        }
+
         Quassel::registerReloadHandler([]() {
             // Currently, only reloading SSL certificates and the sysident cache is supported
             if (Core::instance()) {
         Quassel::registerReloadHandler([]() {
             // Currently, only reloading SSL certificates and the sysident cache is supported
             if (Core::instance()) {
@@ -222,13 +245,21 @@ bool Core::init()
     connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
 
     if (!startListening()) {
     connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
 
     if (!startListening()) {
-        exit(EXIT_FAILURE);  // TODO make this less brutal
+        QCoreApplication::exit(EXIT_FAILURE);  // TODO make this less brutal
+        return false;
     }
 
     if (_configured && !Quassel::isOptionSet("norestore")) {
         Core::restoreState();
     }
 
     }
 
     if (_configured && !Quassel::isOptionSet("norestore")) {
         Core::restoreState();
     }
 
+    _initialized = true;
+
+    if (_pendingInternalConnection) {
+        connectInternalPeer(_pendingInternalConnection);
+        _pendingInternalConnection = {};
+    }
+
     return true;
 }
 
     return true;
 }
 
@@ -380,6 +411,8 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings,
         return false;
     }
 
         return false;
     }
 
+    connect(storage.get(), SIGNAL(dbUpgradeInProgress(bool)), this, SIGNAL(dbUpgradeInProgress(bool)));
+
     Storage::State storageState = storage->init(settings, environment, loadFromEnvironment);
     switch (storageState) {
     case Storage::NeedsSetup:
     Storage::State storageState = storage->init(settings, environment, loadFromEnvironment);
     switch (storageState) {
     case Storage::NeedsSetup:
@@ -392,8 +425,9 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings,
     // if initialization wasn't successful, we quit to keep from coming up unconfigured
     case Storage::NotAvailable:
         qCritical() << "FATAL: Selected storage backend is not available:" << backend;
     // if initialization wasn't successful, we quit to keep from coming up unconfigured
     case Storage::NotAvailable:
         qCritical() << "FATAL: Selected storage backend is not available:" << backend;
-        if (!setup)
-            exit(EXIT_FAILURE);
+        if (!setup) {
+            QCoreApplication::exit(EXIT_FAILURE);
+        }
         return false;
 
     case Storage::IsReady:
         return false;
 
     case Storage::IsReady:
@@ -491,8 +525,9 @@ bool Core::initAuthenticator(const QString &backend, const QVariantMap &settings
     // if initialization wasn't successful, we quit to keep from coming up unconfigured
     case Authenticator::NotAvailable:
         qCritical() << "FATAL: Selected auth backend is not available:" << backend;
     // if initialization wasn't successful, we quit to keep from coming up unconfigured
     case Authenticator::NotAvailable:
         qCritical() << "FATAL: Selected auth backend is not available:" << backend;
-        if (!setup)
-            exit(EXIT_FAILURE);
+        if (!setup) {
+            QCoreApplication::exit(EXIT_FAILURE);
+        }
         return false;
 
     case Authenticator::IsReady:
         return false;
 
     case Authenticator::IsReady:
@@ -635,12 +670,20 @@ bool Core::startListening()
     if (!success)
         quError() << qPrintable(tr("Could not open any network interfaces to listen on!"));
 
     if (!success)
         quError() << qPrintable(tr("Could not open any network interfaces to listen on!"));
 
+    if (_identServer) {
+        _identServer->startListening();
+    }
+
     return success;
 }
 
 
 void Core::stopListening(const QString &reason)
 {
     return success;
 }
 
 
 void Core::stopListening(const QString &reason)
 {
+    if (_identServer) {
+        _identServer->stopListening(reason);
+    }
+
     bool wasListening = false;
     if (_server.isListening()) {
         wasListening = true;
     bool wasListening = false;
     if (_server.isListening()) {
         wasListening = true;
@@ -739,7 +782,18 @@ void Core::addClientHelper(RemotePeer *peer, UserId uid)
 }
 
 
 }
 
 
-void Core::setupInternalClientSession(InternalPeer *clientPeer)
+void Core::connectInternalPeer(QPointer<InternalPeer> peer)
+{
+    if (_initialized && peer) {
+        setupInternalClientSession(peer);
+    }
+    else {
+        _pendingInternalConnection = peer;
+    }
+}
+
+
+void Core::setupInternalClientSession(QPointer<InternalPeer> clientPeer)
 {
     if (!_configured) {
         stopListening();
 {
     if (!_configured) {
         stopListening();
@@ -752,6 +806,12 @@ void Core::setupInternalClientSession(InternalPeer *clientPeer)
     }
     else {
         quWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!";
     }
     else {
         quWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!";
+        QCoreApplication::exit(EXIT_FAILURE);
+        return;
+    }
+
+    if (!clientPeer) {
+        quWarning() << "Client peer went away, not starting a session";
         return;
     }
 
         return;
     }