2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2012 Bolton Software Ltd.
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "synergy/IClient.h"
|
|
|
|
|
|
|
|
#include "synergy/IClipboard.h"
|
|
|
|
#include "synergy/DragInformation.h"
|
|
|
|
#include "synergy/INode.h"
|
|
|
|
#include "net/NetworkAddress.h"
|
|
|
|
#include "io/CryptoOptions.h"
|
|
|
|
#include "base/EventTypes.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
class CEventQueueTimer;
|
|
|
|
class CScreen;
|
|
|
|
class CServerProxy;
|
|
|
|
class IDataSocket;
|
|
|
|
class ISocketFactory;
|
2012-07-05 18:05:35 +00:00
|
|
|
namespace synergy { class IStream; }
|
2012-06-10 16:50:54 +00:00
|
|
|
class IStreamFilterFactory;
|
|
|
|
class IEventQueue;
|
2013-04-09 18:56:19 +00:00
|
|
|
class CCryptoStream;
|
2013-08-30 19:49:38 +00:00
|
|
|
class CThread;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
//! Synergy client
|
|
|
|
/*!
|
|
|
|
This class implements the top-level client algorithms for synergy.
|
|
|
|
*/
|
|
|
|
class CClient : public IClient, public INode {
|
|
|
|
public:
|
|
|
|
class CFailInfo {
|
|
|
|
public:
|
|
|
|
CFailInfo(const char* what) : m_retry(false), m_what(what) { }
|
|
|
|
bool m_retry;
|
|
|
|
CString m_what;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
This client will attempt to connect to the server using \p name
|
|
|
|
as its name and \p address as the server's address and \p factory
|
|
|
|
to create the socket. \p screen is the local screen.
|
|
|
|
*/
|
2013-06-29 14:17:49 +00:00
|
|
|
CClient(IEventQueue* events,
|
2012-06-10 16:50:54 +00:00
|
|
|
const CString& name, const CNetworkAddress& address,
|
|
|
|
ISocketFactory* socketFactory,
|
|
|
|
IStreamFilterFactory* streamFilterFactory,
|
2013-04-09 21:57:07 +00:00
|
|
|
CScreen* screen,
|
2014-02-06 18:39:12 +00:00
|
|
|
const CCryptoOptions& crypto,
|
|
|
|
bool enableDragDrop);
|
2012-06-10 16:50:54 +00:00
|
|
|
~CClient();
|
2013-04-09 18:56:19 +00:00
|
|
|
|
|
|
|
#ifdef TEST_ENV
|
2013-07-16 19:02:30 +00:00
|
|
|
CClient() : m_mock(true) { }
|
2013-04-09 18:56:19 +00:00
|
|
|
#endif
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
|
|
|
|
|
|
|
//! Connect to server
|
|
|
|
/*!
|
|
|
|
Starts an attempt to connect to the server. This is ignored if
|
|
|
|
the client is trying to connect or is already connected.
|
|
|
|
*/
|
|
|
|
void connect();
|
|
|
|
|
|
|
|
//! Disconnect
|
|
|
|
/*!
|
|
|
|
Disconnects from the server with an optional error message.
|
|
|
|
*/
|
|
|
|
void disconnect(const char* msg);
|
|
|
|
|
|
|
|
//! Notify of handshake complete
|
|
|
|
/*!
|
|
|
|
Notifies the client that the connection handshake has completed.
|
|
|
|
*/
|
2013-04-09 18:56:19 +00:00
|
|
|
virtual void handshakeComplete();
|
|
|
|
|
2013-05-01 15:53:22 +00:00
|
|
|
//! Set crypto IV for decryption
|
|
|
|
virtual void setDecryptIv(const UInt8* iv);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2013-07-16 19:02:30 +00:00
|
|
|
//! Clears the file buffer
|
|
|
|
void clearReceivedFileData();
|
|
|
|
|
|
|
|
//! Set the expected size of receiving file
|
|
|
|
void setExpectedFileSize(CString data);
|
|
|
|
|
|
|
|
//! Received a chunk of file data
|
|
|
|
void fileChunkReceived(CString data);
|
2013-08-30 14:38:43 +00:00
|
|
|
|
|
|
|
//! Received drag information
|
|
|
|
void dragInfoReceived(UInt32 fileNum, CString data);
|
|
|
|
|
2013-07-24 16:41:12 +00:00
|
|
|
//! Create a new thread and use it to send file to Server
|
|
|
|
void sendFileToServer(const char* filename);
|
2013-07-16 19:02:30 +00:00
|
|
|
|
2013-08-23 15:36:23 +00:00
|
|
|
//! Set file transder destination
|
|
|
|
void setFileTransferDes(CString& des) { m_fileTransferDes = des; }
|
2013-08-30 19:49:38 +00:00
|
|
|
|
|
|
|
//! Send dragging file information back to server
|
2014-05-01 13:56:07 +00:00
|
|
|
void sendDragInfo(UInt32 fileCount, CString& fileList, size_t size);
|
2013-08-30 19:49:38 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
|
|
|
|
|
|
|
//! Test if connected
|
|
|
|
/*!
|
|
|
|
Returns true iff the client is successfully connected to the server.
|
|
|
|
*/
|
|
|
|
bool isConnected() const;
|
|
|
|
|
|
|
|
//! Test if connecting
|
|
|
|
/*!
|
|
|
|
Returns true iff the client is currently attempting to connect to
|
|
|
|
the server.
|
|
|
|
*/
|
|
|
|
bool isConnecting() const;
|
|
|
|
|
|
|
|
//! Get address of server
|
|
|
|
/*!
|
|
|
|
Returns the address of the server the client is connected (or wants
|
|
|
|
to connect) to.
|
|
|
|
*/
|
|
|
|
CNetworkAddress getServerAddress() const;
|
2013-06-29 14:17:49 +00:00
|
|
|
|
2013-07-24 16:41:12 +00:00
|
|
|
//! Return true if recieved file size is valid
|
|
|
|
bool isReceivedFileSizeValid();
|
|
|
|
|
2013-07-26 12:44:14 +00:00
|
|
|
//! Return expected file size
|
|
|
|
size_t getExpectedFileSize() { return m_expectedFileSize; }
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
// IScreen overrides
|
|
|
|
virtual void* getEventTarget() const;
|
|
|
|
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
|
|
|
|
virtual void getShape(SInt32& x, SInt32& y,
|
|
|
|
SInt32& width, SInt32& height) const;
|
|
|
|
virtual void getCursorPos(SInt32& x, SInt32& y) const;
|
|
|
|
|
|
|
|
// IClient overrides
|
|
|
|
virtual void enter(SInt32 xAbs, SInt32 yAbs,
|
|
|
|
UInt32 seqNum, KeyModifierMask mask,
|
|
|
|
bool forScreensaver);
|
|
|
|
virtual bool leave();
|
|
|
|
virtual void setClipboard(ClipboardID, const IClipboard*);
|
|
|
|
virtual void grabClipboard(ClipboardID);
|
|
|
|
virtual void setClipboardDirty(ClipboardID, bool);
|
|
|
|
virtual void keyDown(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
virtual void keyRepeat(KeyID, KeyModifierMask,
|
|
|
|
SInt32 count, KeyButton);
|
|
|
|
virtual void keyUp(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
virtual void mouseDown(ButtonID);
|
|
|
|
virtual void mouseUp(ButtonID);
|
|
|
|
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
|
|
|
|
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
|
|
|
|
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
|
|
|
|
virtual void screensaver(bool activate);
|
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
|
|
|
virtual CString getName() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void sendClipboard(ClipboardID);
|
|
|
|
void sendEvent(CEvent::Type, void*);
|
|
|
|
void sendConnectionFailedEvent(const char* msg);
|
2013-07-24 16:41:12 +00:00
|
|
|
void sendFileChunk(const void* data);
|
|
|
|
void sendFileThread(void*);
|
2013-09-25 14:49:04 +00:00
|
|
|
void writeToDropDirThread(void*);
|
2012-06-10 16:50:54 +00:00
|
|
|
void setupConnecting();
|
|
|
|
void setupConnection();
|
|
|
|
void setupScreen();
|
|
|
|
void setupTimer();
|
|
|
|
void cleanupConnecting();
|
|
|
|
void cleanupConnection();
|
|
|
|
void cleanupScreen();
|
|
|
|
void cleanupTimer();
|
|
|
|
void handleConnected(const CEvent&, void*);
|
|
|
|
void handleConnectionFailed(const CEvent&, void*);
|
|
|
|
void handleConnectTimeout(const CEvent&, void*);
|
|
|
|
void handleOutputError(const CEvent&, void*);
|
|
|
|
void handleDisconnected(const CEvent&, void*);
|
|
|
|
void handleShapeChanged(const CEvent&, void*);
|
|
|
|
void handleClipboardGrabbed(const CEvent&, void*);
|
|
|
|
void handleHello(const CEvent&, void*);
|
|
|
|
void handleSuspend(const CEvent& event, void*);
|
|
|
|
void handleResume(const CEvent& event, void*);
|
2013-07-16 19:02:30 +00:00
|
|
|
void handleFileChunkSending(const CEvent&, void*);
|
2013-08-30 14:38:43 +00:00
|
|
|
void handleFileRecieveCompleted(const CEvent&, void*);
|
|
|
|
void onFileRecieveCompleted();
|
2013-07-24 16:41:12 +00:00
|
|
|
|
2013-04-09 18:56:19 +00:00
|
|
|
public:
|
|
|
|
bool m_mock;
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
private:
|
|
|
|
CString m_name;
|
|
|
|
CNetworkAddress m_serverAddress;
|
|
|
|
ISocketFactory* m_socketFactory;
|
|
|
|
IStreamFilterFactory* m_streamFilterFactory;
|
|
|
|
CScreen* m_screen;
|
2012-07-05 18:05:35 +00:00
|
|
|
synergy::IStream* m_stream;
|
2012-06-10 16:50:54 +00:00
|
|
|
CEventQueueTimer* m_timer;
|
|
|
|
CServerProxy* m_server;
|
|
|
|
bool m_ready;
|
|
|
|
bool m_active;
|
|
|
|
bool m_suspended;
|
|
|
|
bool m_connectOnResume;
|
|
|
|
bool m_ownClipboard[kClipboardEnd];
|
|
|
|
bool m_sentClipboard[kClipboardEnd];
|
|
|
|
IClipboard::Time m_timeClipboard[kClipboardEnd];
|
|
|
|
CString m_dataClipboard[kClipboardEnd];
|
2013-06-29 14:17:49 +00:00
|
|
|
IEventQueue* m_events;
|
2013-04-09 18:56:19 +00:00
|
|
|
CCryptoStream* m_cryptoStream;
|
2013-04-09 21:57:07 +00:00
|
|
|
CCryptoOptions m_crypto;
|
2013-07-16 19:02:30 +00:00
|
|
|
std::size_t m_expectedFileSize;
|
|
|
|
CString m_receivedFileData;
|
2013-08-23 15:36:23 +00:00
|
|
|
CString m_fileTransferSrc;
|
|
|
|
CString m_fileTransferDes;
|
2013-08-30 14:38:43 +00:00
|
|
|
CDragFileList m_dragFileList;
|
|
|
|
CString m_dragFileExt;
|
2013-08-30 19:49:38 +00:00
|
|
|
CThread* m_sendFileThread;
|
2013-09-25 14:49:04 +00:00
|
|
|
CThread* m_writeToDropDirThread;
|
2014-02-06 18:39:12 +00:00
|
|
|
bool m_enableDragDrop;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|