registerStorageBackend(new SqliteStorage(this));
if(!_storageBackends.count()) {
- quWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
- quWarning() << qPrintable(tr("Currently, Quassel only supports SQLite3. You need to build your\n"
+ qWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
+ qWarning() << qPrintable(tr("Currently, Quassel only supports SQLite3. You need to build your\n"
"Qt library with the sqlite plugin enabled in order for quasselcore\n"
"to work."));
exit(1); // TODO make this less brutal (especially for mono client -> popup)
CoreSettings cs;
if(!(configured = initStorage(cs.storageSettings().toMap()))) {
- quWarning() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
+ qWarning() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
// try to migrate old settings
QVariantMap old = cs.oldDbSettings().toMap();
QVariantMap newSettings;
newSettings["Backend"] = "SQLite";
if((configured = initStorage(newSettings))) {
- quWarning() << "...but thankfully I found some old settings to migrate!";
+ qWarning() << "...but thankfully I found some old settings to migrate!";
cs.setStorageSettings(newSettings);
}
}
return;
}
if(instance()->sessions.count()) {
- quWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
+ qWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
return;
}
CoreSettings s;
}
/*** Core Setup ***/
+QString Core::setupCoreForInternalUsage() {
+ Q_ASSERT(!_storageBackends.isEmpty());
+ QVariantMap setupData;
+ qsrand(QDateTime::currentDateTime().toTime_t());
+ int pass = 0;
+ for(int i = 0; i < 10; i++) {
+ pass *= 10;
+ pass += qrand() % 10;
+ }
+ setupData["AdminUser"] = "AdminUser";
+ setupData["AdminPasswd"] = QString::number(pass);
+ setupData["Backend"] = _storageBackends[_storageBackends.keys().first()]->displayName();
+ return setupCore(setupData);
+}
-QString Core::setupCore(const QVariant &setupData_) {
- QVariantMap setupData = setupData_.toMap();
+QString Core::setupCore(QVariantMap setupData) {
QString user = setupData.take("AdminUser").toString();
QString password = setupData.take("AdminPasswd").toString();
if(user.isEmpty() || password.isEmpty()) {
if(_storageBackends.contains(backend)) {
storage = _storageBackends[backend];
} else {
- quError() << "Selected storage backend is not available:" << backend;
+ qCritical() << "Selected storage backend is not available:" << backend;
return configured = false;
}
if(!storage->init(dbSettings)) {
if(!setup || !(storage->setup(dbSettings) && storage->init(dbSettings))) {
- quError() << "Could not init storage!";
+ qCritical() << "Could not init storage!";
storage = 0;
return configured = false;
}
/*** Network Management ***/
bool Core::startListening() {
+ // in mono mode we only start a local port if a port is specified in the cli call
+ if(Quassel::runMode() == Quassel::Monolithic && !Quassel::isOptionSet("port"))
+ return true;
+
bool success = false;
uint port = Quassel::optionValue("port").toUInt();
}
if(!success) {
- quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(_server.errorString()));
+ qCritical() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(_server.errorString()));
}
return success;
}
-void Core::stopListening() {
- _server.close();
- _v6server.close();
- quInfo() << "No longer listening for GUI clients.";
+void Core::stopListening(const QString &reason) {
+ bool wasListening = false;
+ if(_server.isListening()) {
+ wasListening = true;
+ _server.close();
+ }
+ if(_v6server.isListening()) {
+ wasListening = true;
+ _v6server.close();
+ }
+ if(wasListening) {
+ if(reason.isEmpty())
+ quInfo() << "No longer listening for GUI clients.";
+ else
+ quInfo() << qPrintable(reason);
+ }
}
void Core::incomingConnection() {
quInfo() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString());
if(!configured) {
- _server.close();
- _v6server.close();
- quDebug() << "Closing server for basic setup.";
+ stopListening(tr("Closing server for basic setup."));
}
}
}
void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) {
if(!msg.contains("MsgType")) {
// Client is way too old, does not even use the current init format
- quWarning() << qPrintable(tr("Antique client trying to connect... refusing."));
+ qWarning() << qPrintable(tr("Antique client trying to connect... refusing."));
socket->close();
return;
}
"This core needs at least client/core protocol version %1.<br>"
"Please consider upgrading your client.").arg(Quassel::buildInfo().coreNeedsProtocol);
SignalProxy::writeDataToDevice(socket, reply);
- quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting."));
+ qWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting."));
socket->close(); return;
}
#ifdef HAVE_SSL
// after we told the client that we are ssl capable we switch to ssl mode
if(supportSsl && msg["UseSsl"].toBool()) {
- quDebug() << qPrintable(tr("Starting TLS for Client:")) << qPrintable(socket->peerAddress().toString());
+ qDebug() << qPrintable(tr("Starting TLS for Client:")) << qPrintable(socket->peerAddress().toString());
connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
sslSocket->startServerEncryption();
}
#ifndef QT_NO_COMPRESS
if(supportsCompression && msg["UseCompression"].toBool()) {
socket->setProperty("UseCompression", true);
- quDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString());
+ qDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString());
}
#endif
reply["MsgType"] = "ClientLoginReject";
reply["Error"] = tr("<b>Client not initialized!</b><br>You need to send an init message before trying to login.");
SignalProxy::writeDataToDevice(socket, reply);
- quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting."));
+ qWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting."));
socket->close(); return;
}
if(msg["MsgType"] == "CoreSetupData") {
QVariantMap reply;
- QString result = setupCore(msg["SetupData"]);
+ QString result = setupCore(msg["SetupData"].toMap());
if(!result.isEmpty()) {
reply["MsgType"] = "CoreSetupReject";
reply["Error"] = result;
socket->deleteLater();
} else {
// we have to crawl through the hashes and see if we find a victim to remove
- quDebug() << qPrintable(tr("Non-authed client disconnected. (socket allready destroyed)"));
+ qDebug() << qPrintable(tr("Non-authed client disconnected. (socket allready destroyed)"));
// DO NOT CALL ANY METHODS ON socket!!
socket = static_cast<QTcpSocket *>(sender());
blocksizes.remove(socket);
clientInfo.remove(socket);
if(!sess) {
- quWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(socket->peerAddress().toString());
+ qWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(socket->peerAddress().toString());
socket->close();
}
sess->addClient(socket);
}
+void Core::setupInternalClientSession(SignalProxy *proxy) {
+ if(!configured) {
+ stopListening();
+ setupCoreForInternalUsage();
+ }
+
+ mutex.lock();
+ UserId uid = storage->internalUser();
+ mutex.unlock();
+
+ // Find or create session for validated user
+ SessionThread *sess;
+ if(sessions.contains(uid))
+ sess = sessions[uid];
+ else
+ sess = createSession(uid);
+ sess->addClient(proxy);
+}
+
SessionThread *Core::createSession(UserId uid, bool restore) {
if(sessions.contains(uid)) {
- quWarning() << "Calling createSession() when a session for the user already exists!";
+ qWarning() << "Calling createSession() when a session for the user already exists!";
return 0;
}
SessionThread *sess = new SessionThread(uid, restore, this);
void Core::socketError(QAbstractSocket::SocketError err) {
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(sender());
if(socket && err != QAbstractSocket::RemoteHostClosedError)
- quWarning() << "Core::socketError()" << socket << err << socket->errorString();
+ qWarning() << "Core::socketError()" << socket << err << socket->errorString();
}