Handle invalid handshake data properly in the core
[quassel.git] / src / common / peerfactory.cpp
index 9d55fcc..cd0987b 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005-2014 by the Quassel Project                        *
+ *   Copyright (C) 2005-2015 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include "peerfactory.h"
 
 
 #include "peerfactory.h"
 
+#include "protocols/datastream/datastreampeer.h"
 #include "protocols/legacy/legacypeer.h"
 
 #include "protocols/legacy/legacypeer.h"
 
-RemotePeer *PeerFactory::createPeer(const ProtoDescriptor &protocol, AuthHandler *authHandler, QTcpSocket *socket, QObject *parent)
+
+PeerFactory::ProtoList PeerFactory::supportedProtocols()
+{
+    ProtoList result;
+    result.append(ProtoDescriptor(Protocol::DataStreamProtocol, DataStreamPeer::supportedFeatures()));
+    result.append(ProtoDescriptor(Protocol::LegacyProtocol, 0));
+    return result;
+}
+
+
+RemotePeer *PeerFactory::createPeer(const ProtoDescriptor &protocol, AuthHandler *authHandler, QTcpSocket *socket, Compressor::CompressionLevel level, QObject *parent)
 {
 {
-    return createPeer(ProtoList() << protocol, authHandler, socket, parent);
+    return createPeer(ProtoList() << protocol, authHandler, socket, level, parent);
 }
 
 
 }
 
 
-RemotePeer *PeerFactory::createPeer(const ProtoList &protocols, AuthHandler *authHandler, QTcpSocket *socket, QObject *parent)
+RemotePeer *PeerFactory::createPeer(const ProtoList &protocols, AuthHandler *authHandler, QTcpSocket *socket, Compressor::CompressionLevel level, QObject *parent)
 {
     foreach(const ProtoDescriptor &protodesc, protocols) {
         Protocol::Type proto = protodesc.first;
         quint16 features = protodesc.second;
         switch(proto) {
             case Protocol::LegacyProtocol:
 {
     foreach(const ProtoDescriptor &protodesc, protocols) {
         Protocol::Type proto = protodesc.first;
         quint16 features = protodesc.second;
         switch(proto) {
             case Protocol::LegacyProtocol:
-                return new LegacyPeer(authHandler, socket, parent);
+                return new LegacyPeer(authHandler, socket, level, parent);
+            case Protocol::DataStreamProtocol:
+                if (DataStreamPeer::acceptsFeatures(features))
+                    return new DataStreamPeer(authHandler, socket, features, level, parent);
+                break;
             default:
                 break;
         }
     }
 
             default:
                 break;
         }
     }
 
-    return 0;
+    return nullptr;
 }
 }