2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* 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
|
|
|
#include "client/Client.h"
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "arch/Arch.h"
|
|
|
|
|
#include "base/IEventQueue.h"
|
|
|
|
|
#include "base/Log.h"
|
|
|
|
|
#include "base/TMethodEventJob.h"
|
|
|
|
|
#include "base/TMethodJob.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "client/ServerProxy.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "common/stdexcept.h"
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/AppUtil.h"
|
|
|
|
|
#include "deskflow/DropHelper.h"
|
|
|
|
|
#include "deskflow/FileChunk.h"
|
|
|
|
|
#include "deskflow/IPlatformScreen.h"
|
|
|
|
|
#include "deskflow/PacketStreamFilter.h"
|
|
|
|
|
#include "deskflow/ProtocolUtil.h"
|
|
|
|
|
#include "deskflow/Screen.h"
|
|
|
|
|
#include "deskflow/StreamChunker.h"
|
|
|
|
|
#include "deskflow/XDeskflow.h"
|
|
|
|
|
#include "deskflow/protocol_types.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "mt/Thread.h"
|
|
|
|
|
#include "net/IDataSocket.h"
|
|
|
|
|
#include "net/ISocketFactory.h"
|
|
|
|
|
#include "net/SecureSocket.h"
|
|
|
|
|
#include "net/TCPSocket.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2017-01-24 16:20:50 +00:00
|
|
|
#include <algorithm>
|
2017-01-24 16:21:06 +00:00
|
|
|
#include <climits>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <fstream>
|
2021-10-04 15:51:12 +00:00
|
|
|
#include <iterator>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <sstream>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// Client
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2024-07-16 13:36:44 +00:00
|
|
|
Client::Client(
|
2024-10-17 18:04:35 +00:00
|
|
|
IEventQueue *events, const String &name, const NetworkAddress &address, ISocketFactory *socketFactory,
|
|
|
|
|
deskflow::Screen *screen, deskflow::ClientArgs const &args
|
|
|
|
|
)
|
2024-07-16 13:36:44 +00:00
|
|
|
: m_mock(false),
|
|
|
|
|
m_name(name),
|
|
|
|
|
m_serverAddress(address),
|
|
|
|
|
m_socketFactory(socketFactory),
|
|
|
|
|
m_screen(screen),
|
|
|
|
|
m_stream(NULL),
|
|
|
|
|
m_timer(NULL),
|
|
|
|
|
m_server(NULL),
|
|
|
|
|
m_ready(false),
|
|
|
|
|
m_active(false),
|
|
|
|
|
m_suspended(false),
|
|
|
|
|
m_connectOnResume(false),
|
|
|
|
|
m_events(events),
|
|
|
|
|
m_sendFileThread(nullptr),
|
|
|
|
|
m_writeToDropDirThread(nullptr),
|
|
|
|
|
m_useSecureNetwork(args.m_enableCrypto),
|
|
|
|
|
m_args(args),
|
|
|
|
|
m_enableClipboard(true),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_maximumClipboardSize(INT_MAX)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(m_socketFactory != NULL);
|
|
|
|
|
assert(m_screen != NULL);
|
|
|
|
|
|
|
|
|
|
// register suspend/resume event handlers
|
|
|
|
|
m_events->adoptHandler(
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->forIScreen().suspend(), getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleSuspend)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->forIScreen().resume(), getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleResume)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
if (m_args.m_enableDragDrop) {
|
|
|
|
|
m_events->adoptHandler(
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->forFile().fileChunkSending(), this, new TMethodEventJob<Client>(this, &Client::handleFileChunkSending)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forFile().fileRecieveCompleted(), this,
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleFileRecieveCompleted)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Client::~Client()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_mock) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_events->removeHandler(m_events->forIScreen().suspend(), getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forIScreen().resume(), getEventTarget());
|
|
|
|
|
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
delete m_socketFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::connect(size_t addressIndex)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_stream != NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_suspended) {
|
|
|
|
|
m_connectOnResume = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (m_args.m_hostMode) {
|
2024-10-17 18:04:35 +00:00
|
|
|
LOG((CLOG_NOTE "waiting for server connection on %i port", m_serverAddress.getPort()));
|
2024-07-02 19:07:06 +00:00
|
|
|
} else {
|
|
|
|
|
// resolve the server hostname. do this every time we connect
|
|
|
|
|
// in case we couldn't resolve the address earlier or the address
|
|
|
|
|
// has changed (which can happen frequently if this is a laptop
|
|
|
|
|
// being shuttled between various networks). patch by Brent
|
|
|
|
|
// Priddy.
|
|
|
|
|
m_resolvedAddressesCount = m_serverAddress.resolve(addressIndex);
|
|
|
|
|
|
|
|
|
|
// m_serverAddress will be null if the hostname address is not reolved
|
|
|
|
|
if (m_serverAddress.getAddress() != nullptr) {
|
|
|
|
|
// to help users troubleshoot, show server host name (issue: 60)
|
2024-07-16 13:36:44 +00:00
|
|
|
LOG(
|
2024-10-17 18:04:35 +00:00
|
|
|
(CLOG_NOTE "connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(),
|
|
|
|
|
ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort())
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create the socket
|
2024-10-17 18:04:35 +00:00
|
|
|
IDataSocket *socket =
|
|
|
|
|
m_socketFactory->create(m_useSecureNetwork, ARCH->getAddrFamily(m_serverAddress.getAddress()));
|
2024-07-02 19:07:06 +00:00
|
|
|
bindNetworkInterface(socket);
|
|
|
|
|
|
|
|
|
|
// filter socket messages, including a packetizing filter
|
|
|
|
|
m_stream = new PacketStreamFilter(m_events, socket, true);
|
|
|
|
|
|
|
|
|
|
// connect
|
|
|
|
|
LOG((CLOG_DEBUG1 "connecting to server"));
|
|
|
|
|
setupConnecting();
|
|
|
|
|
setupTimer();
|
|
|
|
|
socket->connect(m_serverAddress);
|
|
|
|
|
} catch (XBase &e) {
|
2016-12-28 11:50:32 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnecting();
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupStream();
|
|
|
|
|
LOG((CLOG_DEBUG1 "connection failed"));
|
|
|
|
|
sendConnectionFailedEvent(e.what());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::disconnect(const char *msg)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanup();
|
2021-05-24 08:21:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (msg) {
|
|
|
|
|
sendConnectionFailedEvent(msg);
|
|
|
|
|
} else {
|
|
|
|
|
sendEvent(m_events->forClient().disconnected(), NULL);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::refuseConnection(const char *msg)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanup();
|
2021-05-24 08:21:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (msg) {
|
|
|
|
|
auto info = new FailInfo(msg);
|
|
|
|
|
info->m_retry = true;
|
2024-10-17 18:04:35 +00:00
|
|
|
Event event(m_events->forClient().connectionRefused(), getEventTarget(), info, Event::kDontFreeData);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->addEvent(event);
|
|
|
|
|
}
|
2021-05-24 08:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handshakeComplete()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_ready = true;
|
|
|
|
|
m_screen->enable();
|
|
|
|
|
sendEvent(m_events->forClient().connected(), NULL);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isConnected() const
|
|
|
|
|
{
|
|
|
|
|
return (m_server != NULL);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isConnecting() const
|
|
|
|
|
{
|
|
|
|
|
return (m_timer != NULL);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
NetworkAddress Client::getServerAddress() const
|
|
|
|
|
{
|
|
|
|
|
return m_serverAddress;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void *Client::getEventTarget() const
|
|
|
|
|
{
|
|
|
|
|
return m_screen->getEventTarget();
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::getClipboard(ClipboardID id, IClipboard *clipboard) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return m_screen->getClipboard(id, clipboard);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::getShape(SInt32 &x, SInt32 &y, SInt32 &w, SInt32 &h) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->getShape(x, y, w, h);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::getCursorPos(SInt32 &x, SInt32 &y) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->getCursorPos(x, y);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_active = true;
|
|
|
|
|
m_screen->mouseMove(xAbs, yAbs);
|
|
|
|
|
m_screen->enter(mask);
|
2015-06-04 20:09:48 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_sendFileThread) {
|
|
|
|
|
StreamChunker::interruptFile();
|
|
|
|
|
m_sendFileThread.reset(nullptr);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::leave()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_active = false;
|
2015-06-04 20:09:48 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->leave();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_enableClipboard) {
|
|
|
|
|
// send clipboards that we own and that have changed
|
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
|
|
|
|
if (m_ownClipboard[id]) {
|
|
|
|
|
sendClipboard(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return true;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setClipboard(ClipboardID id, const IClipboard *clipboard)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->setClipboard(id, clipboard);
|
|
|
|
|
m_ownClipboard[id] = false;
|
|
|
|
|
m_sentClipboard[id] = false;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::grabClipboard(ClipboardID id)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->grabClipboard(id);
|
|
|
|
|
m_ownClipboard[id] = false;
|
|
|
|
|
m_sentClipboard[id] = false;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setClipboardDirty(ClipboardID, bool)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(0 && "shouldn't be called");
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::keyDown(KeyID id, KeyModifierMask mask, KeyButton button, const String &lang)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->keyDown(id, mask, button, lang);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::keyRepeat(KeyID id, KeyModifierMask mask, SInt32 count, KeyButton button, const String &lang)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->keyRepeat(id, mask, count, button, lang);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::keyUp(KeyID id, KeyModifierMask mask, KeyButton button)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->keyUp(id, mask, button);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::mouseDown(ButtonID id)
|
|
|
|
|
{
|
|
|
|
|
m_screen->mouseDown(id);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::mouseUp(ButtonID id)
|
|
|
|
|
{
|
|
|
|
|
m_screen->mouseUp(id);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::mouseMove(SInt32 x, SInt32 y)
|
|
|
|
|
{
|
|
|
|
|
m_screen->mouseMove(x, y);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::mouseRelativeMove(SInt32 dx, SInt32 dy)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->mouseRelativeMove(dx, dy);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::mouseWheel(SInt32 xDelta, SInt32 yDelta)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->mouseWheel(xDelta, yDelta);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::screensaver(bool activate)
|
|
|
|
|
{
|
|
|
|
|
m_screen->screensaver(activate);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::resetOptions()
|
|
|
|
|
{
|
|
|
|
|
m_screen->resetOptions();
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setOptions(const OptionsList &options)
|
|
|
|
|
{
|
|
|
|
|
for (OptionsList::const_iterator index = options.begin(); index != options.end(); ++index) {
|
2024-07-02 19:07:06 +00:00
|
|
|
const OptionID id = *index;
|
|
|
|
|
if (id == kOptionClipboardSharing) {
|
|
|
|
|
index++;
|
|
|
|
|
if (index != options.end()) {
|
|
|
|
|
if (!*index) {
|
|
|
|
|
LOG((CLOG_NOTE "clipboard sharing disabled by server"));
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
m_enableClipboard = *index;
|
|
|
|
|
}
|
|
|
|
|
} else if (id == kOptionClipboardSharingSize) {
|
|
|
|
|
index++;
|
|
|
|
|
if (index != options.end()) {
|
|
|
|
|
m_maximumClipboardSize = *index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_enableClipboard && !m_maximumClipboardSize) {
|
|
|
|
|
m_enableClipboard = false;
|
|
|
|
|
LOG((CLOG_NOTE "clipboard sharing is disabled because the server "
|
|
|
|
|
"set the maximum clipboard size to 0"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_screen->setOptions(options);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
String Client::getName() const
|
|
|
|
|
{
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendClipboard(ClipboardID id)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// note -- m_mutex must be locked on entry
|
|
|
|
|
assert(m_screen != NULL);
|
|
|
|
|
assert(m_server != NULL);
|
|
|
|
|
|
|
|
|
|
// get clipboard data. set the clipboard time to the last
|
|
|
|
|
// clipboard time before getting the data from the screen
|
|
|
|
|
// as the screen may detect an unchanged clipboard and
|
|
|
|
|
// avoid copying the data.
|
|
|
|
|
Clipboard clipboard;
|
|
|
|
|
if (clipboard.open(m_timeClipboard[id])) {
|
|
|
|
|
clipboard.close();
|
|
|
|
|
}
|
|
|
|
|
m_screen->getClipboard(id, &clipboard);
|
|
|
|
|
|
|
|
|
|
// check time
|
|
|
|
|
if (m_timeClipboard[id] == 0 || clipboard.getTime() != m_timeClipboard[id]) {
|
|
|
|
|
// marshall the data
|
|
|
|
|
String data = clipboard.marshall();
|
|
|
|
|
if (data.size() >= m_maximumClipboardSize * 1024) {
|
2024-07-16 13:36:44 +00:00
|
|
|
LOG(
|
|
|
|
|
(CLOG_NOTE "skipping clipboard transfer because the clipboard"
|
2024-07-02 19:07:06 +00:00
|
|
|
" contents exceeds the %i MB size limit set by the server",
|
2024-10-17 18:04:35 +00:00
|
|
|
m_maximumClipboardSize / 1024)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// save new time
|
|
|
|
|
m_timeClipboard[id] = clipboard.getTime();
|
|
|
|
|
// save and send data if different or not yet sent
|
|
|
|
|
if (!m_sentClipboard[id] || data != m_dataClipboard[id]) {
|
|
|
|
|
m_sentClipboard[id] = true;
|
|
|
|
|
m_dataClipboard[id] = data;
|
|
|
|
|
m_server->onClipboardChanged(id, &clipboard);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendEvent(Event::Type type, void *data)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->addEvent(Event(type, getEventTarget(), data));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendConnectionFailedEvent(const char *msg)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
FailInfo *info = new FailInfo(msg);
|
|
|
|
|
info->m_retry = true;
|
2024-10-17 18:04:35 +00:00
|
|
|
Event event(m_events->forClient().connectionFailed(), getEventTarget(), info, Event::kDontFreeData);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->addEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendFileChunk(const void *data)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
FileChunk *chunk = static_cast<FileChunk *>(const_cast<void *>(data));
|
|
|
|
|
LOG((CLOG_DEBUG1 "send file chunk"));
|
|
|
|
|
assert(m_server != NULL);
|
|
|
|
|
|
|
|
|
|
// relay
|
2024-10-17 18:04:35 +00:00
|
|
|
m_server->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupConnecting()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(m_stream != NULL);
|
|
|
|
|
|
|
|
|
|
if (m_args.m_enableCrypto) {
|
|
|
|
|
m_events->adoptHandler(
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->forIDataSocket().secureConnected(), m_stream->getEventTarget(),
|
|
|
|
|
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
} else {
|
|
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIDataSocket().connected(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleConnectionFailed)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupConnection()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(m_stream != NULL);
|
|
|
|
|
|
|
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forISocket().disconnected(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIStream().inputReady(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleHello)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIStream().outputError(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleOutputError)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIStream().inputShutdown(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIStream().outputShutdown(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forISocket().stopRetry(), m_stream->getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleStopRetry)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupScreen()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(m_server == NULL);
|
|
|
|
|
|
|
|
|
|
m_ready = false;
|
|
|
|
|
m_server = new ServerProxy(this, m_stream, m_events);
|
|
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forIScreen().shapeChanged(), getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleShapeChanged)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(
|
|
|
|
|
m_events->forClipboard().clipboardGrabbed(), getEventTarget(),
|
2024-10-17 18:04:35 +00:00
|
|
|
new TMethodEventJob<Client>(this, &Client::handleClipboardGrabbed)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupTimer()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
assert(m_timer == NULL);
|
|
|
|
|
|
|
|
|
|
if (!m_args.m_hostMode) {
|
|
|
|
|
m_timer = m_events->newOneShotTimer(2.0, NULL);
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->adoptHandler(Event::kTimer, m_timer, new TMethodEventJob<Client>(this, &Client::handleConnectTimeout));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanup()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_connectOnResume = false;
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupConnection();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanupConnecting()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_stream != NULL) {
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->removeHandler(m_events->forIDataSocket().connected(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget());
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanupConnection()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_stream != NULL) {
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->removeHandler(m_events->forIStream().inputReady(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forIStream().outputError(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forIStream().outputShutdown(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forISocket().disconnected(), m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forISocket().stopRetry(), m_stream->getEventTarget());
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupStream();
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanupScreen()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_server != NULL) {
|
|
|
|
|
if (m_ready) {
|
|
|
|
|
m_screen->disable();
|
|
|
|
|
m_ready = false;
|
|
|
|
|
}
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->removeHandler(m_events->forIScreen().shapeChanged(), getEventTarget());
|
|
|
|
|
m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(), getEventTarget());
|
2024-07-02 19:07:06 +00:00
|
|
|
delete m_server;
|
|
|
|
|
m_server = NULL;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanupTimer()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_timer != NULL) {
|
|
|
|
|
m_events->removeHandler(Event::kTimer, m_timer);
|
|
|
|
|
m_events->deleteTimer(m_timer);
|
|
|
|
|
m_timer = NULL;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::cleanupStream()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
delete m_stream;
|
|
|
|
|
m_stream = NULL;
|
2015-01-14 17:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleConnected(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
LOG((CLOG_DEBUG1 "connected; wait for hello"));
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
setupConnection();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// reset clipboard state
|
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
|
|
|
|
m_ownClipboard[id] = false;
|
|
|
|
|
m_sentClipboard[id] = false;
|
|
|
|
|
m_timeClipboard[id] = 0;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleConnectionFailed(const Event &event, void *)
|
|
|
|
|
{
|
|
|
|
|
IDataSocket::ConnectionFailedInfo *info = static_cast<IDataSocket::ConnectionFailedInfo *>(event.getData());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupStream();
|
|
|
|
|
LOG((CLOG_DEBUG1 "connection failed"));
|
|
|
|
|
sendConnectionFailedEvent(info->m_what.c_str());
|
|
|
|
|
delete info;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleConnectTimeout(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
cleanupStream();
|
|
|
|
|
LOG((CLOG_DEBUG1 "connection timed out"));
|
|
|
|
|
sendConnectionFailedEvent("Timed out");
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleOutputError(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
LOG((CLOG_WARN "error sending to server"));
|
|
|
|
|
sendEvent(m_events->forClient().disconnected(), NULL);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleDisconnected(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
LOG((CLOG_DEBUG1 "disconnected"));
|
|
|
|
|
sendEvent(m_events->forClient().disconnected(), NULL);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleShapeChanged(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
LOG((CLOG_DEBUG "resolution changed"));
|
|
|
|
|
m_server->onInfoChanged();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleClipboardGrabbed(const Event &event, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-16 13:24:46 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
const IScreen::ClipboardInfo *info = static_cast<const IScreen::ClipboardInfo *>(event.getData());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// grab ownership
|
|
|
|
|
m_server->onGrabClipboard(info->m_id);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// we now own the clipboard and it has not been sent to the server
|
|
|
|
|
m_ownClipboard[info->m_id] = true;
|
|
|
|
|
m_sentClipboard[info->m_id] = false;
|
|
|
|
|
m_timeClipboard[info->m_id] = 0;
|
2016-09-01 10:15:58 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// if we're not the active screen then send the clipboard now,
|
|
|
|
|
// otherwise we'll wait until we leave.
|
|
|
|
|
if (!m_active) {
|
|
|
|
|
sendClipboard(info->m_id);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isCompatible(int major, int minor) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
const std::map<int, std::set<int>> compatibleTable{
|
|
|
|
|
{6, {7, 8}}, // 1.6 is compatible with 1.7 and 1.8
|
|
|
|
|
{7, {8}} // 1.7 is compatible with 1.8
|
|
|
|
|
};
|
2021-10-25 15:55:09 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
bool isCompatible = false;
|
2021-10-25 15:55:09 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (major == kProtocolMajorVersion) {
|
|
|
|
|
auto versions = compatibleTable.find(minor);
|
|
|
|
|
if (versions != compatibleTable.end()) {
|
|
|
|
|
auto compatibleVersions = versions->second;
|
2024-10-17 18:04:35 +00:00
|
|
|
isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end();
|
2021-10-25 15:55:09 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2021-10-25 15:55:09 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return isCompatible;
|
2021-10-25 15:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleHello(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
SInt16 major, minor;
|
2024-10-14 17:13:49 +00:00
|
|
|
|
|
|
|
|
// as luck would have it, both "Synergy" and "Barrier" are 7 chars,
|
|
|
|
|
// so we eat 7 chars and then test for either protocol name.
|
|
|
|
|
// we cannot re-use `readf` to check for various hello messages,
|
|
|
|
|
// as `readf` eats bytes (advances the stream position reference).
|
|
|
|
|
std::string protocolName;
|
|
|
|
|
ProtocolUtil::readf(m_stream, kMsgHello, &protocolName, &major, &minor);
|
|
|
|
|
|
|
|
|
|
if (protocolName != kSynergyProtocolName && protocolName != kBarrierProtocolName) {
|
|
|
|
|
sendConnectionFailedEvent("got invalid hello message from server");
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check versions
|
2024-10-14 17:13:49 +00:00
|
|
|
LOG_DEBUG("got hello version %s, %d.%d", protocolName.c_str(), major, minor);
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
SInt16 helloBackMajor = kProtocolMajorVersion;
|
|
|
|
|
SInt16 helloBackMinor = kProtocolMinorVersion;
|
|
|
|
|
|
|
|
|
|
if (isCompatible(major, minor)) {
|
2024-10-14 17:13:49 +00:00
|
|
|
// because 1.6 is compatable with 1.7 and 1.8 - downgrading protocol for
|
2024-07-02 19:07:06 +00:00
|
|
|
// server
|
2024-10-14 17:13:49 +00:00
|
|
|
LOG_NOTE("downgrading protocol version for server");
|
2024-07-02 19:07:06 +00:00
|
|
|
helloBackMinor = minor;
|
2024-10-17 18:04:35 +00:00
|
|
|
} else if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
|
2024-07-02 19:07:06 +00:00
|
|
|
sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// say hello back
|
2024-10-14 17:13:49 +00:00
|
|
|
LOG_DEBUG("say hello version %s %d.%d", protocolName.c_str(), helloBackMajor, helloBackMinor);
|
|
|
|
|
|
|
|
|
|
// dynamically build write format for hello back since `writef` doesn't
|
|
|
|
|
// support fixed length strings yet.
|
|
|
|
|
std::string helloBackMessage = protocolName + "%2i%2i%s";
|
|
|
|
|
ProtocolUtil::writef(m_stream, helloBackMessage.c_str(), helloBackMajor, helloBackMinor, &m_name);
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// now connected but waiting to complete handshake
|
|
|
|
|
setupScreen();
|
|
|
|
|
cleanupTimer();
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// make sure we process any remaining messages later. we won't
|
|
|
|
|
// receive another event for already pending messages so we fake
|
|
|
|
|
// one.
|
|
|
|
|
if (m_stream->isReady()) {
|
2024-10-17 18:04:35 +00:00
|
|
|
m_events->addEvent(Event(m_events->forIStream().inputReady(), m_stream->getEventTarget()));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleSuspend(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!m_suspended) {
|
|
|
|
|
LOG((CLOG_INFO "suspend"));
|
|
|
|
|
m_suspended = true;
|
|
|
|
|
bool wasConnected = isConnected();
|
|
|
|
|
disconnect(NULL);
|
|
|
|
|
m_connectOnResume = wasConnected;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleResume(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_suspended) {
|
|
|
|
|
LOG((CLOG_INFO "resume"));
|
|
|
|
|
m_suspended = false;
|
|
|
|
|
if (m_connectOnResume) {
|
|
|
|
|
m_connectOnResume = false;
|
|
|
|
|
connect();
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleFileChunkSending(const Event &event, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
sendFileChunk(event.getDataObject());
|
2013-07-16 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleFileRecieveCompleted(const Event &event, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
onFileRecieveCompleted();
|
2013-08-23 15:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::onFileRecieveCompleted()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (isReceivedFileSizeValid()) {
|
|
|
|
|
auto method = new TMethodJob<Client>(this, &Client::writeToDropDirThread);
|
|
|
|
|
m_writeToDropDirThread.reset(new Thread(method));
|
|
|
|
|
}
|
2013-09-25 14:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::bindNetworkInterface(IDataSocket *socket) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
try {
|
2024-09-17 19:00:25 +00:00
|
|
|
if (!m_args.m_deskflowAddress.empty()) {
|
2024-10-17 18:04:35 +00:00
|
|
|
LOG((CLOG_DEBUG1 "bind to network interface: %s", m_args.m_deskflowAddress.c_str()));
|
2023-03-29 08:39:49 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
NetworkAddress bindAddress(m_args.m_deskflowAddress);
|
2024-07-02 19:07:06 +00:00
|
|
|
bindAddress.resolve();
|
2023-03-29 08:39:49 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
socket->bind(bindAddress);
|
2023-03-29 08:39:49 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
} catch (XBase &e) {
|
|
|
|
|
LOG((CLOG_WARN "%s", e.what()));
|
2024-10-17 18:04:35 +00:00
|
|
|
LOG((CLOG_WARN "operating system will select network interface automatically"));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2023-03-29 08:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::handleStopRetry(const Event &, void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_args.m_restartable = false;
|
2015-04-20 13:43:39 +00:00
|
|
|
}
|
2013-09-25 14:49:04 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::writeToDropDirThread(void *)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
LOG((CLOG_DEBUG "starting write to drop dir thread"));
|
2014-02-07 17:06:26 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
while (m_screen->isFakeDraggingStarted()) {
|
|
|
|
|
ARCH->sleep(.1f);
|
|
|
|
|
}
|
2014-02-06 18:39:12 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
DropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList, m_receivedFileData);
|
2013-08-30 14:38:43 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::dragInfoReceived(UInt32 fileNum, String data)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// TODO: fix duplicate function from CServer
|
|
|
|
|
if (!m_args.m_enableDragDrop) {
|
|
|
|
|
LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DragInformation::parseDragInfo(m_dragFileList, fileNum, data);
|
|
|
|
|
|
|
|
|
|
m_screen->startDraggingFiles(m_dragFileList);
|
2013-07-16 19:02:30 +00:00
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isReceivedFileSizeValid()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return m_expectedFileSize == m_receivedFileData.size();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendFileToServer(const char *filename)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_sendFileThread) {
|
|
|
|
|
StreamChunker::interruptFile();
|
|
|
|
|
}
|
2022-05-19 15:29:11 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
auto data = static_cast<void *>(const_cast<char *>(filename));
|
|
|
|
|
auto method = new TMethodJob<Client>(this, &Client::sendFileThread, data);
|
|
|
|
|
m_sendFileThread.reset(new Thread(method));
|
2013-07-24 16:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendFileThread(void *filename)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
try {
|
|
|
|
|
char *name = static_cast<char *>(filename);
|
|
|
|
|
StreamChunker::sendFile(name, m_events, this);
|
|
|
|
|
} catch (std::runtime_error &error) {
|
|
|
|
|
LOG((CLOG_ERR "failed sending file chunks: %s", error.what()));
|
|
|
|
|
}
|
2013-08-30 19:49:38 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
m_sendFileThread.reset(nullptr);
|
2013-08-30 19:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendDragInfo(UInt32 fileCount, String &info, size_t size)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_server->sendDragInfo(fileCount, info.c_str(), size);
|
2013-07-24 16:41:12 +00:00
|
|
|
}
|