Passed args into client and socket

Conflicts:
	src/lib/client/Client.cpp
	src/lib/client/Client.h
	src/lib/synergy/ClientApp.cpp
	src/test/integtests/net/NetworkTests.cpp
This commit is contained in:
XinyuHou 2015-04-02 14:43:23 +01:00
parent 39e183da3e
commit b4665b9cd5
10 changed files with 41 additions and 20 deletions

View File

@ -60,8 +60,7 @@ Client::Client(
const String& name, const NetworkAddress& address, const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory, ISocketFactory* socketFactory,
synergy::Screen* screen, synergy::Screen* screen,
bool enableDragDrop, ClientArgs args) :
bool enableCrypto) :
m_mock(false), m_mock(false),
m_name(name), m_name(name),
m_serverAddress(address), m_serverAddress(address),
@ -77,9 +76,9 @@ Client::Client(
m_events(events), m_events(events),
m_sendFileThread(NULL), m_sendFileThread(NULL),
m_writeToDropDirThread(NULL), m_writeToDropDirThread(NULL),
m_enableDragDrop(enableDragDrop),
m_socket(NULL), m_socket(NULL),
m_useSecureNetwork(false) m_useSecureNetwork(false)
m_args(args)
{ {
assert(m_socketFactory != NULL); assert(m_socketFactory != NULL);
assert(m_screen != NULL); assert(m_screen != NULL);
@ -94,7 +93,7 @@ Client::Client(
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
&Client::handleResume)); &Client::handleResume));
if (m_enableDragDrop) { if (m_args.m_enableDragDrop) {
m_events->adoptHandler(m_events->forIScreen().fileChunkSending(), m_events->adoptHandler(m_events->forIScreen().fileChunkSending(),
this, this,
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
@ -162,6 +161,7 @@ Client::connect()
// create the socket // create the socket
IDataSocket* socket = m_socketFactory->create(m_useSecureNetwork); IDataSocket* socket = m_socketFactory->create(m_useSecureNetwork);
m_socket = dynamic_cast<TCPSocket*>(socket); m_socket = dynamic_cast<TCPSocket*>(socket);
m_socket->setFingerprintFilename(m_args.m_certFingerprintFilename);
// filter socket messages, including a packetizing filter // filter socket messages, including a packetizing filter
m_stream = socket; m_stream = socket;
@ -780,7 +780,8 @@ Client::fileChunkReceived(String data)
void void
Client::dragInfoReceived(UInt32 fileNum, String data) Client::dragInfoReceived(UInt32 fileNum, String data)
{ {
if (!m_enableDragDrop) { // TODO: fix duplicate function from CServer
if (!m_args.m_enableDragDrop) {
LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info.")); LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info."));
return; return;
} }

View File

@ -23,6 +23,7 @@
#include "synergy/IClipboard.h" #include "synergy/IClipboard.h"
#include "synergy/DragInformation.h" #include "synergy/DragInformation.h"
#include "synergy/INode.h" #include "synergy/INode.h"
#include "synergy/ClientArgs.h"
#include "net/NetworkAddress.h" #include "net/NetworkAddress.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
@ -59,8 +60,7 @@ public:
const String& name, const NetworkAddress& address, const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory, ISocketFactory* socketFactory,
synergy::Screen* screen, synergy::Screen* screen,
bool enableDragDrop, ClientArgs args);
bool enableCrypto);
~Client(); ~Client();
#ifdef TEST_ENV #ifdef TEST_ENV
@ -227,4 +227,5 @@ private:
bool m_enableDragDrop; bool m_enableDragDrop;
TCPSocket* m_socket; TCPSocket* m_socket;
bool m_useSecureNetwork; bool m_useSecureNetwork;
ClientArgs m_args;
}; };

View File

@ -59,6 +59,7 @@ public:
virtual void secureConnect() {} virtual void secureConnect() {}
virtual void secureAccept() {} virtual void secureAccept() {}
virtual void setFingerprintFilename(CString& f) {}
protected: protected:
ArchSocket getSocket() { return m_socket; } ArchSocket getSocket() { return m_socket; }

View File

@ -46,7 +46,7 @@ CSecureSocket::CSecureSocket(
CSocketMultiplexer* socketMultiplexer) : CSocketMultiplexer* socketMultiplexer) :
CTCPSocket(events, socketMultiplexer), CTCPSocket(events, socketMultiplexer),
m_secureReady(false), m_secureReady(false),
m_certFingerprint() m_certFingerprintFilename()
{ {
} }
@ -405,6 +405,10 @@ CSecureSocket::disconnect()
bool bool
CSecureSocket::verifyCertFingerprint() CSecureSocket::verifyCertFingerprint()
{ {
if (m_certFingerprintFilename.empty()) {
return false;
}
// calculate received certificate fingerprint // calculate received certificate fingerprint
X509 *cert = cert = SSL_get_peer_certificate(m_ssl->m_ssl); X509 *cert = cert = SSL_get_peer_certificate(m_ssl->m_ssl);
EVP_MD* tempDigest; EVP_MD* tempDigest;
@ -426,7 +430,7 @@ CSecureSocket::verifyCertFingerprint()
CString fileLine; CString fileLine;
CString certificateFingerprint; CString certificateFingerprint;
std::ifstream file; std::ifstream file;
file.open(m_certFingerprint.c_str()); file.open(m_certFingerprintFilename.c_str());
while (!file.eof()) { while (!file.eof()) {
getline(file,fileLine); getline(file,fileLine);

View File

@ -43,6 +43,7 @@ public:
void secureConnect(); void secureConnect();
void secureAccept(); void secureAccept();
void setFingerprintFilename(CString& f) { m_certFingerprintFilename = f; }
bool isReady() const { return m_secureReady; } bool isReady() const { return m_secureReady; }
bool isSecureReady(); bool isSecureReady();
bool isSecure() { return true; } bool isSecure() { return true; }
@ -76,5 +77,5 @@ private:
private: private:
Ssl* m_ssl; Ssl* m_ssl;
bool m_secureReady; bool m_secureReady;
CString m_certFingerprint; CString m_certFingerprintFilename;
}; };

View File

@ -91,7 +91,7 @@ ArgParser::parseClientArgs(ClientArgs& args, int argc, const char* const* argv)
} }
else if (isArg(i, argc, argv, NULL, "--certificate-fingerprint", 1)) { else if (isArg(i, argc, argv, NULL, "--certificate-fingerprint", 1)) {
// define scroll // define scroll
args.m_certFingerprint = argv[++i]; args.m_certFingerprintFilename = argv[++i];
} }
else { else {
if (i + 1 == argc) { if (i + 1 == argc) {

View File

@ -342,8 +342,7 @@ ClientApp::openClient(const String& name, const NetworkAddress& address,
address, address,
new TCPSocketFactory(m_events, getSocketMultiplexer()), new TCPSocketFactory(m_events, getSocketMultiplexer()),
screen, screen,
args().m_enableDragDrop, args());
args().m_enableCrypto);
try { try {
m_events->adoptHandler( m_events->adoptHandler(

View File

@ -19,6 +19,6 @@
CClientArgs::CClientArgs() : CClientArgs::CClientArgs() :
m_yscroll(0), m_yscroll(0),
m_certFingerprint() m_certFingerprintFilename()
{ {
} }

View File

@ -27,5 +27,5 @@ public:
public: public:
int m_yscroll; int m_yscroll;
CString m_certFingerprint; CString m_certFingerprintFilename;
}; };

View File

@ -140,7 +140,11 @@ TEST_F(NetworkTests, sendToClient_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
ClientArgs args;
args.m_enableDragDrop = true;
args.m_enableCrypto = false;
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client, m_events.forIScreen().fileRecieveCompleted(), &client,
@ -192,7 +196,11 @@ TEST_F(NetworkTests, sendToClient_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
ClientArgs args;
args.m_enableDragDrop = true;
args.m_enableCrypto = false;
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client, m_events.forIScreen().fileRecieveCompleted(), &client,
@ -238,7 +246,10 @@ TEST_F(NetworkTests, sendToServer_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); ClientArgs args;
args.m_enableDragDrop = true;
args.m_enableCrypto = false;
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forClientListener().connected(), &listener, m_events.forClientListener().connected(), &listener,
@ -290,8 +301,11 @@ TEST_F(NetworkTests, sendToServer_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); ClientArgs args;
args.m_enableDragDrop = true;
args.m_enableCrypto = false;
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forClientListener().connected(), &listener, m_events.forClientListener().connected(), &listener,
new TMethodEventJob<NetworkTests>( new TMethodEventJob<NetworkTests>(