4d555cfc4720b59808e2357afc11d22a104ca99c
[quassel.git] / src / core / core.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include <QMetaObject>
22 #include <QMetaMethod>
23 #include <QMutexLocker>
24 #include <QCoreApplication>
25
26 #include "core.h"
27 #include "coresession.h"
28 #include "coresettings.h"
29 #include "quassel.h"
30 #include "signalproxy.h"
31 #include "sqlitestorage.h"
32 #include "network.h"
33 #include "logger.h"
34
35 #include "util.h"
36
37 Core *Core::instanceptr = 0;
38 QMutex Core::mutex;
39
40 Core *Core::instance() {
41   if(instanceptr) return instanceptr;
42   instanceptr = new Core();
43   instanceptr->init();
44   return instanceptr;
45 }
46
47 void Core::destroy() {
48   delete instanceptr;
49   instanceptr = 0;
50 }
51
52 Core::Core() : storage(0) {
53   _startTime = QDateTime::currentDateTime().toUTC();  // for uptime :)
54
55   // Register storage backends here!
56   registerStorageBackend(new SqliteStorage(this));
57
58   if(!_storageBackends.count()) {
59     quWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
60     quWarning() << qPrintable(tr("Currently, Quassel only supports SQLite3. You need to build your\n"
61                                 "Qt library with the sqlite plugin enabled in order for quasselcore\n"
62                                 "to work."));
63     exit(1); // TODO make this less brutal (especially for mono client -> popup)
64   }
65   connect(&_storageSyncTimer, SIGNAL(timeout()), this, SLOT(syncStorage()));
66   _storageSyncTimer.start(10 * 60 * 1000); // in msecs
67 }
68
69 void Core::init() {
70   configured = false;
71
72   CoreSettings cs;
73
74   if(!(configured = initStorage(cs.storageSettings().toMap()))) {
75     quWarning() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
76
77     // try to migrate old settings
78     QVariantMap old = cs.oldDbSettings().toMap();
79     if(old.count() && old["Type"].toString().toUpper() == "SQLITE") {
80       QVariantMap newSettings;
81       newSettings["Backend"] = "SQLite";
82       if((configured = initStorage(newSettings))) {
83         quWarning() << "...but thankfully I found some old settings to migrate!";
84         cs.setStorageSettings(newSettings);
85       }
86     }
87   }
88
89   connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
90   connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
91   if(!startListening()) exit(1); // TODO make this less brutal
92 }
93
94 Core::~Core() {
95   foreach(QTcpSocket *socket, blocksizes.keys()) {
96     socket->disconnectFromHost();  // disconnect non authed clients
97   }
98   qDeleteAll(sessions);
99   qDeleteAll(_storageBackends);
100 }
101
102 /*** Session Restore ***/
103
104 void Core::saveState() {
105   CoreSettings s;
106   QVariantMap state;
107   QVariantList activeSessions;
108   foreach(UserId user, instance()->sessions.keys()) activeSessions << QVariant::fromValue<UserId>(user);
109   state["CoreStateVersion"] = 1;
110   state["ActiveSessions"] = activeSessions;
111   s.setCoreState(state);
112 }
113
114 void Core::restoreState() {
115   if(!instance()->configured) {
116     // qWarning() << qPrintable(tr("Cannot restore a state for an unconfigured core!"));
117     return;
118   }
119   if(instance()->sessions.count()) {
120     quWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!"));
121     return;
122   }
123   CoreSettings s;
124   /* We don't check, since we are at the first version since switching to Git
125   uint statever = s.coreState().toMap()["CoreStateVersion"].toUInt();
126   if(statever < 1) {
127     qWarning() << qPrintable(tr("Core state too old, ignoring..."));
128     return;
129   }
130   */
131   QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList();
132   if(activeSessions.count() > 0) {
133     quInfo() << "Restoring previous core state...";
134     foreach(QVariant v, activeSessions) {
135       UserId user = v.value<UserId>();
136       instance()->createSession(user, true);
137     }
138   }
139 }
140
141 /*** Core Setup ***/
142
143 QString Core::setupCore(const QVariant &setupData_) {
144   QVariantMap setupData = setupData_.toMap();
145   QString user = setupData.take("AdminUser").toString();
146   QString password = setupData.take("AdminPasswd").toString();
147   if(user.isEmpty() || password.isEmpty()) {
148     return tr("Admin user or password not set.");
149   }
150   if(!initStorage(setupData, true)) {
151     return tr("Could not setup storage!");
152   }
153   CoreSettings s;
154   s.setStorageSettings(setupData);
155   quInfo() << qPrintable(tr("Creating admin user..."));
156   mutex.lock();
157   storage->addUser(user, password);
158   mutex.unlock();
159   startListening();  // TODO check when we need this
160   return QString();
161 }
162
163 /*** Storage Handling ***/
164
165 bool Core::registerStorageBackend(Storage *backend) {
166   if(backend->isAvailable()) {
167     _storageBackends[backend->displayName()] = backend;
168     return true;
169   } else {
170     backend->deleteLater();
171     return false;
172   }
173 }
174
175 void Core::unregisterStorageBackend(Storage *backend) {
176   _storageBackends.remove(backend->displayName());
177   backend->deleteLater();
178 }
179
180 // old db settings:
181 // "Type" => "sqlite"
182 bool Core::initStorage(QVariantMap dbSettings, bool setup) {
183   QString backend = dbSettings["Backend"].toString();
184   if(backend.isEmpty()) {
185     //qWarning() << "No storage backend selected!";
186     return configured = false;
187   }
188
189   if(_storageBackends.contains(backend)) {
190     storage = _storageBackends[backend];
191   } else {
192     quError() << "Selected storage backend is not available:" << backend;
193     return configured = false;
194   }
195   if(!storage->init(dbSettings)) {
196     if(!setup || !(storage->setup(dbSettings) && storage->init(dbSettings))) {
197       quError() << "Could not init storage!";
198       storage = 0;
199       return configured = false;
200     }
201   }
202   // delete all other backends
203   foreach(Storage *s, _storageBackends.values()) {
204     if(s != storage) s->deleteLater();
205   }
206   _storageBackends.clear();
207
208   connect(storage, SIGNAL(bufferInfoUpdated(UserId, const BufferInfo &)), this, SIGNAL(bufferInfoUpdated(UserId, const BufferInfo &)));
209   return configured = true;
210 }
211
212 void Core::syncStorage() {
213   QMutexLocker locker(&mutex);
214   if(storage) storage->sync();
215 }
216
217 /*** Storage Access ***/
218 void Core::setUserSetting(UserId userId, const QString &settingName, const QVariant &data) {
219   QMutexLocker locker(&mutex);
220   instance()->storage->setUserSetting(userId, settingName, data);
221 }
222
223 QVariant Core::getUserSetting(UserId userId, const QString &settingName, const QVariant &data) {
224   QMutexLocker locker(&mutex);
225   return instance()->storage->getUserSetting(userId, settingName, data);
226 }
227
228 bool Core::createNetwork(UserId user, NetworkInfo &info) {
229   QMutexLocker locker(&mutex);
230   NetworkId networkId = instance()->storage->createNetwork(user, info);
231   if(!networkId.isValid())
232     return false;
233
234   info.networkId = networkId;
235   return true;
236 }
237
238 bool Core::updateNetwork(UserId user, const NetworkInfo &info) {
239   QMutexLocker locker(&mutex);
240   return instance()->storage->updateNetwork(user, info);
241 }
242
243 bool Core::removeNetwork(UserId user, const NetworkId &networkId) {
244   QMutexLocker locker(&mutex);
245   return instance()->storage->removeNetwork(user, networkId);
246 }
247
248 QList<NetworkInfo> Core::networks(UserId user) {
249   QMutexLocker locker(&mutex);
250   return instance()->storage->networks(user);
251 }
252
253 NetworkId Core::networkId(UserId user, const QString &network) {
254   QMutexLocker locker(&mutex);
255   return instance()->storage->getNetworkId(user, network);
256 }
257
258 QList<NetworkId> Core::connectedNetworks(UserId user) {
259   QMutexLocker locker(&mutex);
260   return instance()->storage->connectedNetworks(user);
261 }
262
263 void Core::setNetworkConnected(UserId user, const NetworkId &networkId, bool isConnected) {
264   QMutexLocker locker(&mutex);
265   return instance()->storage->setNetworkConnected(user, networkId, isConnected);
266 }
267
268 QHash<QString, QString> Core::persistentChannels(UserId user, const NetworkId &networkId) {
269   QMutexLocker locker(&mutex);
270   return instance()->storage->persistentChannels(user, networkId);
271 }
272
273 void Core::setChannelPersistent(UserId user, const NetworkId &networkId, const QString &channel, bool isJoined) {
274   QMutexLocker locker(&mutex);
275   return instance()->storage->setChannelPersistent(user, networkId, channel, isJoined);
276 }
277
278 void Core::setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key) {
279   QMutexLocker locker(&mutex);
280   return instance()->storage->setPersistentChannelKey(user, networkId, channel, key);
281 }
282
283 BufferInfo Core::bufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer) {
284   QMutexLocker locker(&mutex);
285   return instance()->storage->getBufferInfo(user, networkId, type, buffer);
286 }
287
288 BufferInfo Core::getBufferInfo(UserId user, const BufferId &bufferId) {
289   QMutexLocker locker(&mutex);
290   return instance()->storage->getBufferInfo(user, bufferId);
291 }
292
293 MsgId Core::storeMessage(const Message &message) {
294   QMutexLocker locker(&mutex);
295   return instance()->storage->logMessage(message);
296 }
297
298 QList<Message> Core::requestMsgs(UserId user, BufferId buffer, int lastmsgs, int offset) {
299   QMutexLocker locker(&mutex);
300   return instance()->storage->requestMsgs(user, buffer, lastmsgs, offset);
301 }
302
303 QList<Message> Core::requestMsgs(UserId user, BufferId buffer, QDateTime since, int offset) {
304   QMutexLocker locker(&mutex);
305   return instance()->storage->requestMsgs(user, buffer, since, offset);
306 }
307
308 QList<Message> Core::requestMsgRange(UserId user, BufferId buffer, int first, int last) {
309   QMutexLocker locker(&mutex);
310   return instance()->storage->requestMsgRange(user, buffer, first, last);
311 }
312
313 QList<BufferInfo> Core::requestBuffers(UserId user) {
314   QMutexLocker locker(&mutex);
315   return instance()->storage->requestBuffers(user);
316 }
317
318 QList<BufferId> Core::requestBufferIdsForNetwork(UserId user, NetworkId networkId) {
319   QMutexLocker locker(&mutex);
320   return instance()->storage->requestBufferIdsForNetwork(user, networkId);
321 }
322
323 bool Core::removeBuffer(const UserId &user, const BufferId &bufferId) {
324   QMutexLocker locker(&mutex);
325   return instance()->storage->removeBuffer(user, bufferId);
326 }
327
328 BufferId Core::renameBuffer(const UserId &user, const NetworkId &networkId, const QString &newName, const QString &oldName) {
329   QMutexLocker locker(&mutex);
330   return instance()->storage->renameBuffer(user, networkId, newName, oldName);
331 }
332
333 void Core::setBufferLastSeenMsg(UserId user, const BufferId &bufferId, const MsgId &msgId) {
334   QMutexLocker locker(&mutex);
335   return instance()->storage->setBufferLastSeenMsg(user, bufferId, msgId);
336 }
337
338 QHash<BufferId, MsgId> Core::bufferLastSeenMsgIds(UserId user) {
339   QMutexLocker locker(&mutex);
340   return instance()->storage->bufferLastSeenMsgIds(user);
341 }
342
343 /*** Network Management ***/
344
345 bool Core::startListening() {
346   bool success = false;
347   uint port = Quassel::optionValue("port").toUInt();
348
349   if(_server.listen(QHostAddress::Any, port)) {
350     quInfo() << "Listening for GUI clients on IPv6 port" << _server.serverPort() << "using protocol version" << Global::protocolVersion;
351     success = true;
352   }
353   if(_v6server.listen(QHostAddress::AnyIPv6, port)) {
354     quInfo() << "Listening for GUI clients on IPv4 port" << _v6server.serverPort() << "using protocol version" << Global::protocolVersion;
355     success = true;
356   }
357
358   if(!success) {
359     quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(_server.errorString()));
360   }
361
362   return success;
363 }
364
365 void Core::stopListening() {
366   _server.close();
367   _v6server.close();
368   quInfo() << "No longer listening for GUI clients.";
369 }
370
371 void Core::incomingConnection() {
372   QTcpServer *server = qobject_cast<QTcpServer *>(sender());
373   Q_ASSERT(server);
374   while(server->hasPendingConnections()) {
375     QTcpSocket *socket = server->nextPendingConnection();
376     connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
377     connect(socket, SIGNAL(readyRead()), this, SLOT(clientHasData()));
378     connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
379
380     QVariantMap clientInfo;
381     blocksizes.insert(socket, (quint32)0);
382     quInfo() << qPrintable(tr("Client connected from"))  << qPrintable(socket->peerAddress().toString());
383
384     if(!configured) {
385       _server.close();
386       _v6server.close();
387       quDebug() << "Closing server for basic setup.";
388     }
389   }
390 }
391
392 void Core::clientHasData() {
393   QTcpSocket *socket = dynamic_cast<QTcpSocket*>(sender());
394   Q_ASSERT(socket && blocksizes.contains(socket));
395   QVariant item;
396   while(SignalProxy::readDataFromDevice(socket, blocksizes[socket], item)) {
397     QVariantMap msg = item.toMap();
398     processClientMessage(socket, msg);
399     if(!blocksizes.contains(socket)) break;  // this socket is no longer ours to handle!
400   }
401 }
402
403 void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) {
404   if(!msg.contains("MsgType")) {
405     // Client is way too old, does not even use the current init format
406     quWarning() << qPrintable(tr("Antique client trying to connect... refusing."));
407     socket->close();
408     return;
409   }
410   // OK, so we have at least an init message format we can understand
411   if(msg["MsgType"] == "ClientInit") {
412     QVariantMap reply;
413
414     // Just version information -- check it!
415     uint ver = 0;
416     if(!msg.contains("ProtocolVersion") && msg["ClientBuild"].toUInt() >= 732) ver = 1; // FIXME legacy
417     if(msg.contains("ProtocolVersion")) ver = msg["ProtocolVersion"].toUInt();
418     if(ver < Global::coreNeedsProtocol) {
419       reply["MsgType"] = "ClientInitReject";
420       reply["Error"] = tr("<b>Your Quassel Client is too old!</b><br>"
421       "This core needs at least client/core protocol version %1.<br>"
422       "Please consider upgrading your client.").arg(Global::coreNeedsProtocol);
423       SignalProxy::writeDataToDevice(socket, reply);
424       quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting."));
425       socket->close(); return;
426     }
427
428     reply["CoreVersion"] = Global::quasselVersion;
429     reply["CoreDate"] = Global::quasselBuildDate;
430     reply["CoreBuild"] = 860; // FIXME legacy
431     reply["ProtocolVersion"] = Global::protocolVersion;
432     // TODO: Make the core info configurable
433     int uptime = startTime().secsTo(QDateTime::currentDateTime().toUTC());
434     int updays = uptime / 86400; uptime %= 86400;
435     int uphours = uptime / 3600; uptime %= 3600;
436     int upmins = uptime / 60;
437     reply["CoreInfo"] = tr("<b>Quassel Core Version %1</b><br>"
438                            "Built: %2<br>"
439                            "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuildDate)
440       .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime().toString(Qt::TextDate));
441
442 #ifdef HAVE_SSL
443     SslServer *sslServer = qobject_cast<SslServer *>(&_server);
444     QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
445     bool supportSsl = (bool)sslServer && (bool)sslSocket && sslServer->certIsValid();
446 #else
447     bool supportSsl = false;
448 #endif
449
450 #ifndef QT_NO_COMPRESS
451     bool supportsCompression = true;
452 #else
453     bool supportsCompression = false;
454 #endif
455
456     reply["SupportSsl"] = supportSsl;
457     reply["SupportsCompression"] = supportsCompression;
458     // switch to ssl/compression after client has been informed about our capabilities (see below)
459
460     reply["LoginEnabled"] = true;
461
462     // check if we are configured, start wizard otherwise
463     if(!configured) {
464       reply["Configured"] = false;
465       QList<QVariant> backends;
466       foreach(Storage *backend, _storageBackends.values()) {
467         QVariantMap v;
468         v["DisplayName"] = backend->displayName();
469         v["Description"] = backend->description();
470         backends.append(v);
471       }
472       reply["StorageBackends"] = backends;
473       reply["LoginEnabled"] = false;
474     } else {
475       reply["Configured"] = true;
476     }
477     clientInfo[socket] = msg; // store for future reference
478     reply["MsgType"] = "ClientInitAck";
479     SignalProxy::writeDataToDevice(socket, reply);
480
481 #ifdef HAVE_SSL
482     // after we told the client that we are ssl capable we switch to ssl mode
483     if(supportSsl && msg["UseSsl"].toBool()) {
484       quDebug() << qPrintable(tr("Starting TLS for Client:"))  << qPrintable(socket->peerAddress().toString());
485       connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
486       sslSocket->startServerEncryption();
487     }
488 #endif
489
490 #ifndef QT_NO_COMPRESS
491     if(supportsCompression && msg["UseCompression"].toBool()) {
492       socket->setProperty("UseCompression", true);
493       quDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString());
494     }
495 #endif
496
497   } else {
498     // for the rest, we need an initialized connection
499     if(!clientInfo.contains(socket)) {
500       QVariantMap reply;
501       reply["MsgType"] = "ClientLoginReject";
502       reply["Error"] = tr("<b>Client not initialized!</b><br>You need to send an init message before trying to login.");
503       SignalProxy::writeDataToDevice(socket, reply);
504       quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting."));
505       socket->close(); return;
506     }
507     if(msg["MsgType"] == "CoreSetupData") {
508       QVariantMap reply;
509       QString result = setupCore(msg["SetupData"]);
510       if(!result.isEmpty()) {
511         reply["MsgType"] = "CoreSetupReject";
512         reply["Error"] = result;
513       } else {
514         reply["MsgType"] = "CoreSetupAck";
515       }
516       SignalProxy::writeDataToDevice(socket, reply);
517     } else if(msg["MsgType"] == "ClientLogin") {
518       QVariantMap reply;
519       mutex.lock();
520       UserId uid = storage->validateUser(msg["User"].toString(), msg["Password"].toString());
521       mutex.unlock();
522       if(uid == 0) {
523         reply["MsgType"] = "ClientLoginReject";
524         reply["Error"] = tr("<b>Invalid username or password!</b><br>The username/password combination you supplied could not be found in the database.");
525         SignalProxy::writeDataToDevice(socket, reply);
526         return;
527       }
528       reply["MsgType"] = "ClientLoginAck";
529       SignalProxy::writeDataToDevice(socket, reply);
530       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()));
531       setupClientSession(socket, uid);
532     }
533   }
534 }
535
536 // Potentially called during the initialization phase (before handing the connection off to the session)
537 void Core::clientDisconnected() {
538   QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
539   if(socket) {
540     // here it's safe to call methods on socket!
541     quInfo() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(socket->peerAddress().toString());
542     blocksizes.remove(socket);
543     clientInfo.remove(socket);
544     socket->deleteLater();
545   } else {
546     // we have to crawl through the hashes and see if we find a victim to remove
547     quDebug() << qPrintable(tr("Non-authed client disconnected. (socket allready destroyed)"));
548
549     // DO NOT CALL ANY METHODS ON socket!!
550     socket = static_cast<QTcpSocket *>(sender());
551
552     QHash<QTcpSocket *, quint32>::iterator blockSizeIter = blocksizes.begin();
553     while(blockSizeIter != blocksizes.end()) {
554       if(blockSizeIter.key() == socket) {
555         blocksizes.erase(blockSizeIter);
556       }
557       blockSizeIter++;
558     }
559
560     QHash<QTcpSocket *, QVariantMap>::iterator clientInfoIter = clientInfo.begin();
561     while(clientInfoIter != clientInfo.end()) {
562       if(clientInfoIter.key() == socket) {
563         clientInfo.erase(clientInfoIter);
564       }
565       clientInfoIter++;
566     }
567   }
568
569
570   // make server listen again if still not configured
571   if (!configured) {
572     startListening();
573   }
574
575   // TODO remove unneeded sessions - if necessary/possible...
576   // Suggestion: kill sessions if they are not connected to any network and client.
577 }
578
579 void Core::setupClientSession(QTcpSocket *socket, UserId uid) {
580   // Find or create session for validated user
581   SessionThread *sess;
582   if(sessions.contains(uid)) sess = sessions[uid];
583   else sess = createSession(uid);
584   // Hand over socket, session then sends state itself
585   disconnect(socket, 0, this, 0);
586   blocksizes.remove(socket);
587   clientInfo.remove(socket);
588   if(!sess) {
589     quWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(socket->peerAddress().toString());
590     socket->close();
591   }
592   sess->addClient(socket);
593 }
594
595 SessionThread *Core::createSession(UserId uid, bool restore) {
596   if(sessions.contains(uid)) {
597     quWarning() << "Calling createSession() when a session for the user already exists!";
598     return 0;
599   }
600   SessionThread *sess = new SessionThread(uid, restore, this);
601   sessions[uid] = sess;
602   sess->start();
603   return sess;
604 }
605
606 #ifdef HAVE_SSL
607 void Core::sslErrors(const QList<QSslError> &errors) {
608   Q_UNUSED(errors);
609   QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
610   if(socket)
611     socket->ignoreSslErrors();
612 }
613 #endif
614
615 void Core::socketError(QAbstractSocket::SocketError err) {
616   QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(sender());
617   if(socket && err != QAbstractSocket::RemoteHostClosedError)
618     quWarning() << "Core::socketError()" << socket << err << socket->errorString();
619 }