Handle the readyRead() signal in RemotePeer instead of LegacyPeer
[quassel.git] / src / common / protocols / legacy / legacypeer.cpp
index 08f5b15..e2890cc 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 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  *
@@ -25,9 +25,9 @@
 #include "quassel.h"
 
 /* version.inc is no longer used for this */
-const int protocolVersion = 10;
-const int coreNeedsProtocol = protocolVersion;
-const int clientNeedsProtocol = protocolVersion;
+const uint protocolVersion = 10;
+const uint coreNeedsProtocol = protocolVersion;
+const uint clientNeedsProtocol = protocolVersion;
 
 using namespace Protocol;
 
@@ -38,8 +38,6 @@ LegacyPeer::LegacyPeer(::AuthHandler *authHandler, QTcpSocket *socket, QObject *
 {
     _stream.setDevice(socket);
     _stream.setVersion(QDataStream::Qt_4_2);
-
-    connect(socket, SIGNAL(readyRead()), SLOT(socketDataAvailable()));
 }
 
 
@@ -48,7 +46,6 @@ void LegacyPeer::setSignalProxy(::SignalProxy *proxy)
     RemotePeer::setSignalProxy(proxy);
 
     // FIXME only in compat mode
-    socket()->flush();
     if (proxy) {
         // enable compression now if requested - the initial handshake is uncompressed in the legacy protocol!
         _useCompression = socket()->property("UseCompression").toBool();
@@ -59,7 +56,7 @@ void LegacyPeer::setSignalProxy(::SignalProxy *proxy)
 }
 
 
-void LegacyPeer::socketDataAvailable()
+void LegacyPeer::onSocketDataAvailable()
 {
     QVariant item;
     while (readSocketData(item)) {
@@ -179,9 +176,9 @@ void LegacyPeer::handleHandshakeMessage(const QVariant &msg)
 
     if (msgType == "ClientInit") {
         // FIXME only in compat mode
-        int ver = m["ProtocolVersion"].toInt();
+        uint ver = m["ProtocolVersion"].toUInt();
         if (ver < coreNeedsProtocol) {
-            emit protocolVersionMismatch(ver, coreNeedsProtocol);
+            emit protocolVersionMismatch((int)ver, (int)coreNeedsProtocol);
             return;
         }
 
@@ -200,9 +197,9 @@ void LegacyPeer::handleHandshakeMessage(const QVariant &msg)
 
     else if (msgType == "ClientInitAck") {
         // FIXME only in compat mode
-        int ver = m["ProtocolVersion"].toInt();
+        uint ver = m["ProtocolVersion"].toUInt(); // actually an UInt
         if (ver < clientNeedsProtocol) {
-            emit protocolVersionMismatch(ver, clientNeedsProtocol);
+            emit protocolVersionMismatch((int)ver, (int)clientNeedsProtocol);
             return;
         }
 #ifndef QT_NO_COMPRESS
@@ -286,7 +283,7 @@ void LegacyPeer::dispatch(const ClientRegistered &msg) {
     // FIXME only in compat mode
     m["ProtocolVersion"] = protocolVersion;
     m["SupportSsl"] = msg.sslSupported;
-    m["SupportsCompression"] = socket()->property("UseCompression"); // this property gets already set in the ClientInit handler
+    m["SupportsCompression"] = socket()->property("UseCompression").toBool(); // this property gets already set in the ClientInit handler
 
     // This is only used for old v10 clients (pre-0.5)
     int uptime = msg.coreStartTime.secsTo(QDateTime::currentDateTime().toUTC());
@@ -302,7 +299,6 @@ void LegacyPeer::dispatch(const ClientRegistered &msg) {
     m["LoginEnabled"] = m["Configured"] = msg.coreConfigured;
 
     writeSocketData(m);
-    socket()->flush(); // ensure that the write cache is flushed before we switch to ssl
 }