X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorenetwork.cpp;h=87f1484a7b9beb2ab6cb9c650bda9acaa2ff33ee;hp=ed3b39e7159261e2c434339f61858a5966532d8a;hb=2cf99193317f0c970422f6be61ac6efa658b0006;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222 diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index ed3b39e7..87f1484a 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2012 by the Quassel Project * + * Copyright (C) 2005-2014 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -40,10 +40,10 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session) _lastPingTime(0), _pingCount(0), + _sendPings(false), _requestedUserModes('-') { _autoReconnectTimer.setSingleShot(true); - _socketCloseTimer.setSingleShot(true); connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout())); setPingInterval(networkConfig()->pingInterval()); @@ -182,6 +182,8 @@ void CoreNetwork::connectToIrc(bool reconnecting) socket.setProxy(QNetworkProxy::NoProxy); } + enablePingTimeout(); + #ifdef HAVE_SSL socket.setProtocol((QSsl::SslProtocol)server.sslVersion); if (server.useSsl) { @@ -310,7 +312,7 @@ void CoreNetwork::removeChannelKey(const QString &channel) #ifdef HAVE_QCA2 -Cipher *CoreNetwork::cipher(const QString &target) const +Cipher *CoreNetwork::cipher(const QString &target) { if (target.isEmpty()) return 0; @@ -318,39 +320,64 @@ Cipher *CoreNetwork::cipher(const QString &target) const if (!Cipher::neededFeaturesAvailable()) return 0; - QByteArray key = cipherKey(target); - if (key.isEmpty()) - return 0; - CoreIrcChannel *channel = qobject_cast(ircChannel(target)); if (channel) { - if (channel->cipher()->setKey(key)) - return channel->cipher(); + return channel->cipher(); } - else { - CoreIrcUser *user = qobject_cast(ircUser(target)); - if (user && user->cipher()->setKey(key)) - return user->cipher(); + CoreIrcUser *user = qobject_cast(ircUser(target)); + if (user) { + return user->cipher(); + } else if (!isChannelName(target)) { + return qobject_cast(newIrcUser(target))->cipher(); } return 0; } -QByteArray CoreNetwork::cipherKey(const QString &recipient) const +QByteArray CoreNetwork::cipherKey(const QString &target) const { - return _cipherKeys.value(recipient.toLower(), QByteArray()); + CoreIrcChannel *c = qobject_cast(ircChannel(target)); + if (c) + return c->cipher()->key(); + + CoreIrcUser *u = qobject_cast(ircUser(target)); + if (u) + return u->cipher()->key(); + + return QByteArray(); } -void CoreNetwork::setCipherKey(const QString &recipient, const QByteArray &key) +void CoreNetwork::setCipherKey(const QString &target, const QByteArray &key) { - if (!key.isEmpty()) - _cipherKeys[recipient.toLower()] = key; - else - _cipherKeys.remove(recipient.toLower()); + CoreIrcChannel *c = qobject_cast(ircChannel(target)); + if (c) { + c->setEncrypted(c->cipher()->setKey(key)); + return; + } + + CoreIrcUser *u = qobject_cast(ircUser(target)); + if (!u && !isChannelName(target)) + u = qobject_cast(newIrcUser(target)); + + if (u) { + u->setEncrypted(u->cipher()->setKey(key)); + return; + } } +bool CoreNetwork::cipherUsesCBC(const QString &target) +{ + CoreIrcChannel *c = qobject_cast(ircChannel(target)); + if (c) + return c->cipher()->usesCBC(); + CoreIrcUser *u = qobject_cast(ircUser(target)); + if (u) + return u->cipher()->usesCBC(); + + return false; +} #endif /* HAVE_QCA2 */ bool CoreNetwork::setAutoWhoDone(const QString &channel) @@ -375,7 +402,8 @@ void CoreNetwork::setMyNick(const QString &mynick) void CoreNetwork::socketHasData() { while (socket.canReadLine()) { - QByteArray s = socket.readLine().trimmed(); + QByteArray s = socket.readLine(); + s.chop(2); NetworkDataEvent *event = new NetworkDataEvent(EventManager::NetworkIncoming, this, s); #if QT_VERSION >= 0x040700 event->setTimestamp(QDateTime::currentDateTimeUtc()); @@ -525,7 +553,7 @@ void CoreNetwork::networkInitialized() sendPerform(); - enablePingTimeout(); + _sendPings = true; if (networkConfig()->autoWhoEnabled()) { _autoWhoCycleTimer.start(); @@ -769,7 +797,9 @@ void CoreNetwork::sendPing() else { _lastPingTime = now; _pingCount++; - userInputHandler()->handlePing(BufferInfo(), QString()); + // Don't send pings until the network is initialized + if(_sendPings) + userInputHandler()->handlePing(BufferInfo(), QString()); } } @@ -789,6 +819,7 @@ void CoreNetwork::enablePingTimeout(bool enable) void CoreNetwork::disablePingTimeout() { _pingTimer.stop(); + _sendPings = false; resetPingTimeout(); }