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