#include "signalproxy.h"
#include "sqlitestorage.h"
#include "network.h"
+#include "logger.h"
#include "util.h"
}
Core::Core() : storage(0) {
- startTime = QDateTime::currentDateTime(); // for uptime :)
+ _startTime = QDateTime::currentDateTime(); // for uptime :)
// Register storage backends here!
registerStorageBackend(new SqliteStorage(this));
if(!_storageBackends.count()) {
- qWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
- qWarning() << qPrintable(tr("Currently, Quassel only supports SQLite3. You need to build your\n"
+ quWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
+ quWarning() << 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()))) {
- qWarning("Core is currently not configured! Please connect with a Quassel Client for basic setup.");
+ quWarning() << "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))) {
- qWarning("...but thankfully I found some old settings to migrate!");
+ quWarning() << "...but thankfully I found some old settings to migrate!";
cs.setStorageSettings(newSettings);
}
}
return;
}
if(instance()->sessions.count()) {
- qWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
+ quWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
return;
}
CoreSettings s;
*/
QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList();
if(activeSessions.count() > 0) {
- qDebug() << "Restoring previous core state...";
+ quInfo() << "Restoring previous core state...";
foreach(QVariant v, activeSessions) {
UserId user = v.value<UserId>();
instance()->createSession(user, true);
}
CoreSettings s;
s.setStorageSettings(setupData);
- qDebug() << qPrintable(tr("Creating admin user..."));
+ quInfo() << qPrintable(tr("Creating admin user..."));
mutex.lock();
storage->addUser(user, password);
mutex.unlock();
if(_storageBackends.contains(backend)) {
storage = _storageBackends[backend];
} else {
- qWarning() << "Selected storage backend is not available:" << backend;
+ quError() << "Selected storage backend is not available:" << backend;
return configured = false;
}
if(!storage->init(dbSettings)) {
if(!setup || !(storage->setup(dbSettings) && storage->init(dbSettings))) {
- qWarning() << "Could not init storage!";
+ quError() << "Could not init storage!";
storage = 0;
return configured = false;
}
}
if(!success) {
- qWarning("%s", qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(server.errorString())));
+ quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(server.errorString()));
} else {
- qDebug() << "Listening for GUI clients on port" << server.serverPort();
+ quInfo() << "Listening for GUI clients on port" << server.serverPort() << "using protocol version" << Global::protocolVersion;
}
return success;
void Core::stopListening() {
server.close();
- qDebug() << "No longer listening for GUI clients.";
+ quInfo() << "No longer listening for GUI clients.";
}
void Core::incomingConnection() {
QVariantMap clientInfo;
blocksizes.insert(socket, (quint32)0);
- qDebug() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString());
+ quInfo() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString());
if (!configured) {
server.close();
- qDebug() << "Closing server for basic setup.";
+ quDebug() << "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
- qWarning() << qPrintable(tr("Antique client trying to connect... refusing."));
+ quWarning() << 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(Global::coreNeedsProtocol);
SignalProxy::writeDataToDevice(socket, reply);
- qWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting."));
+ quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting."));
socket->close(); return;
}
reply["CoreBuild"] = 860; // FIXME legacy
reply["ProtocolVersion"] = Global::protocolVersion;
// TODO: Make the core info configurable
- int uptime = startTime.secsTo(QDateTime::currentDateTime());
+ int uptime = startTime().secsTo(QDateTime::currentDateTime());
int updays = uptime / 86400; uptime %= 86400;
int uphours = uptime / 3600; uptime %= 3600;
int upmins = uptime / 60;
reply["CoreInfo"] = tr("<b>Quassel Core Version %1</b><br>"
- "Built: %2<br>"
- "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuildDate)
- .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime.toString(Qt::TextDate));
+ "Built: %2<br>"
+ "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuildDate)
+ .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime().toString(Qt::TextDate));
#ifndef QT_NO_OPENSSL
SslServer *sslServer = qobject_cast<SslServer *>(&server);
#ifndef QT_NO_OPENSSL
// after we told the client that we are ssl capable we switch to ssl mode
if(supportSsl && msg["UseSsl"].toBool()) {
- qDebug() << qPrintable(tr("Starting TLS for Client:")) << qPrintable(socket->peerAddress().toString());
+ quDebug() << 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);
- qDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString());
+ quDebug() << "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);
- qWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting."));
+ quWarning() << 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") {
}
reply["MsgType"] = "ClientLoginAck";
SignalProxy::writeDataToDevice(socket, reply);
- qDebug() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("initialized and authenticated successfully as \"%1\" (UserId: %2).").arg(msg["User"].toString()).arg(uid.toInt()));
+ quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("initialized and authenticated successfully as \"%1\" (UserId: %2).").arg(msg["User"].toString()).arg(uid.toInt()));
setupClientSession(socket, uid);
}
}
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
if(socket) {
// here it's safe to call methods on socket!
- qDebug() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(socket->peerAddress().toString());
+ quInfo() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(socket->peerAddress().toString());
+ blocksizes.remove(socket);
+ clientInfo.remove(socket);
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)"));
// DO NOT CALL ANY METHODS ON socket!!
socket = static_cast<QTcpSocket *>(sender());
blocksizes.remove(socket);
clientInfo.remove(socket);
if(!sess) {
- qWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(socket->peerAddress().toString());
+ quWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(socket->peerAddress().toString());
socket->close();
}
sess->addClient(socket);
SessionThread *Core::createSession(UserId uid, bool restore) {
if(sessions.contains(uid)) {
- qWarning() << "Calling createSession() when a session for the user already exists!";
+ quWarning() << "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)
- qDebug() << "Core::socketError()" << socket << err << socket->errorString();
+ quWarning() << "Core::socketError()" << socket << err << socket->errorString();
}