2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2026-05-26 14:20:19 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
|
2026-06-08 20:37:23 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016, 2026 Synergy App Ltd
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
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"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "client/ServerProxy.h"
|
2026-09-18 15:27:24 +00:00
|
|
|
#include "client/ServerProxy1_7.h"
|
|
|
|
|
#include "client/ServerProxy1_8.h"
|
2026-03-02 04:06:06 +00:00
|
|
|
#include "common/NetworkProtocol.h"
|
2025-08-22 23:35:18 +00:00
|
|
|
#include "common/Settings.h"
|
2025-11-06 20:24:45 +00:00
|
|
|
#include "deskflow/Clipboard.h"
|
2026-07-04 14:19:47 +00:00
|
|
|
#include "deskflow/DeskflowException.h"
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/IPlatformScreen.h"
|
|
|
|
|
#include "deskflow/PacketStreamFilter.h"
|
2026-01-26 10:41:21 +00:00
|
|
|
#include "deskflow/ProtocolTypes.h"
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/ProtocolUtil.h"
|
|
|
|
|
#include "deskflow/Screen.h"
|
|
|
|
|
#include "deskflow/StreamChunker.h"
|
2026-03-26 14:17:56 +00:00
|
|
|
#include "deskflow/ipc/CoreIpc.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "net/IDataSocket.h"
|
|
|
|
|
#include "net/ISocketFactory.h"
|
|
|
|
|
#include "net/SecureSocket.h"
|
|
|
|
|
#include "net/TCPSocket.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2026-03-26 14:17:56 +00:00
|
|
|
#include <QMetaEnum>
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2024-10-16 15:12:17 +00:00
|
|
|
|
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
|
|
|
//
|
|
|
|
|
|
2026-07-10 14:40:20 +00:00
|
|
|
Client::DisconnectRequest::DisconnectRequest(Kind kind, const char *message)
|
|
|
|
|
: m_kind(kind),
|
|
|
|
|
m_message(message != nullptr ? message : "")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client::DisconnectRequest::DisconnectRequest(deskflow::core::ConnectionRefusal reason, const char *message)
|
|
|
|
|
: m_kind(Kind::Refuse),
|
|
|
|
|
m_refusalReason(reason),
|
|
|
|
|
m_message(message != nullptr ? message : "")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 13:36:44 +00:00
|
|
|
Client::Client(
|
2025-01-06 00:55:07 +00:00
|
|
|
IEventQueue *events, const std::string &name, const NetworkAddress &address, ISocketFactory *socketFactory,
|
2025-09-18 01:39:24 +00:00
|
|
|
deskflow::Screen *screen
|
2024-10-17 18:04:35 +00:00
|
|
|
)
|
2025-05-22 22:22:20 +00:00
|
|
|
: m_name(name),
|
2024-07-16 13:36:44 +00:00
|
|
|
m_serverAddress(address),
|
|
|
|
|
m_socketFactory(socketFactory),
|
|
|
|
|
m_screen(screen),
|
|
|
|
|
m_events(events),
|
2026-07-03 13:17:07 +00:00
|
|
|
m_useSecureNetwork(Settings::value(Settings::Security::TlsEnabled).toBool()),
|
|
|
|
|
m_maximumClipboardReceiveSize(
|
|
|
|
|
static_cast<size_t>(Settings::value(Settings::Server::ClipboardSize).toUInt()) * 1024 * 1024
|
|
|
|
|
)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_socketFactory != nullptr);
|
|
|
|
|
assert(m_screen != nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// register suspend/resume event handlers
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::ScreenSuspend, getEventTarget(), [this](const auto &) { handleSuspend(); });
|
|
|
|
|
m_events->addHandler(EventTypes::ScreenResume, getEventTarget(), [this](const auto &) { handleResume(); });
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Client::~Client()
|
|
|
|
|
{
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->removeHandler(EventTypes::ScreenSuspend, getEventTarget());
|
|
|
|
|
m_events->removeHandler(EventTypes::ScreenResume, getEventTarget());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
delete m_socketFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 08:05:32 +00:00
|
|
|
void Client::setServerAddress(const NetworkAddress &address)
|
|
|
|
|
{
|
|
|
|
|
m_serverAddress = address;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::connect(size_t addressIndex)
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_stream != nullptr) {
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_suspended) {
|
|
|
|
|
m_connectOnResume = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 13:19:41 +00:00
|
|
|
auto securityLevel = m_useSecureNetwork ? SecurityLevel::PeerAuth : SecurityLevel::PlainText;
|
2024-11-28 12:28:55 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
try {
|
2025-04-04 17:41:44 +00:00
|
|
|
// 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)
|
2026-03-26 12:34:18 +00:00
|
|
|
LOG_DEBUG(
|
2025-08-23 17:38:30 +00:00
|
|
|
"connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(),
|
|
|
|
|
ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort()
|
2025-04-04 17:41:44 +00:00
|
|
|
);
|
2026-03-26 12:34:18 +00:00
|
|
|
ipcSendConnectionState(deskflow::core::ConnectionState::Connecting);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create the socket
|
2024-11-28 12:28:55 +00:00
|
|
|
IDataSocket *socket = m_socketFactory->create(ARCH->getAddrFamily(m_serverAddress.getAddress()), securityLevel);
|
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
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("connecting to server");
|
2024-07-02 19:07:06 +00:00
|
|
|
setupConnecting();
|
|
|
|
|
setupTimer();
|
|
|
|
|
socket->connect(m_serverAddress);
|
2025-08-07 21:26:44 +00:00
|
|
|
} catch (BaseException &e) {
|
2016-12-28 11:50:32 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnecting();
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupStream();
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("connection failed");
|
2024-07-02 19:07:06 +00:00
|
|
|
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 {
|
2025-11-13 00:29:22 +00:00
|
|
|
sendEvent(EventTypes::ClientDisconnected);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 14:17:56 +00:00
|
|
|
void Client::refuseConnection(deskflow::core::ConnectionRefusal reason, const char *msg)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2026-03-26 14:17:56 +00:00
|
|
|
const auto metaEnum = QMetaEnum::fromType<deskflow::core::ConnectionRefusal>();
|
|
|
|
|
ipcSendToClient("connectionRefused", metaEnum.valueToKey(static_cast<int>(reason)));
|
|
|
|
|
|
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;
|
2025-07-08 12:12:53 +00:00
|
|
|
Event event(EventTypes::ClientConnectionRefused, getEventTarget(), info, Event::EventFlags::DontFreeData);
|
2025-11-13 01:29:03 +00:00
|
|
|
m_events->addEvent(std::move(event));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
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();
|
2026-05-26 14:20:19 +00:00
|
|
|
if (m_relativeMouseMoves && !m_hasRelativeRestorePosition) {
|
|
|
|
|
saveRelativeRestorePosition();
|
|
|
|
|
}
|
2025-11-13 00:29:22 +00:00
|
|
|
sendEvent(EventTypes::ClientConnected);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isConnected() const
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
return (m_server != nullptr);
|
2024-10-17 18:04:35 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::isConnecting() const
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
return (m_timer != nullptr);
|
2024-10-17 18:04:35 +00:00
|
|
|
}
|
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
|
|
|
|
2026-07-03 13:17:07 +00:00
|
|
|
size_t Client::getMaximumClipboardReceiveSizeBytes() const
|
2026-07-03 13:12:49 +00:00
|
|
|
{
|
2026-07-03 13:17:07 +00:00
|
|
|
return m_maximumClipboardReceiveSize;
|
2026-07-03 13:12:49 +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
|
|
|
}
|
|
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::getShape(int32_t &x, int32_t &y, int32_t &w, int32_t &h) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->getShape(x, y, w, h);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::getCursorPos(int32_t &x, int32_t &y) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->getCursorPos(x, y);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-11 02:13:19 +00:00
|
|
|
void Client::enter(int32_t xAbs, int32_t yAbs, uint32_t, KeyModifierMask mask, bool)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_active = true;
|
2026-05-26 14:20:19 +00:00
|
|
|
if (m_relativeMouseMoves && m_hasRelativeRestorePosition) {
|
|
|
|
|
xAbs = m_relativeRestoreX;
|
|
|
|
|
yAbs = m_relativeRestoreY;
|
|
|
|
|
LOG_VERBOSE("using relative restore position: %d,%d", xAbs, yAbs);
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->mouseMove(xAbs, yAbs);
|
|
|
|
|
m_screen->enter(mask);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Client::leave()
|
|
|
|
|
{
|
2026-05-26 14:20:19 +00:00
|
|
|
if (m_relativeMouseMoves) {
|
|
|
|
|
saveRelativeRestorePosition();
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
void Client::keyDown(KeyID id, KeyModifierMask mask, KeyButton button, const std::string &lang)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->keyDown(id, mask, button, lang);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::keyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButton button, const std::string &lang)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
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
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::mouseMove(int32_t x, int32_t y)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
m_screen->mouseMove(x, y);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::mouseRelativeMove(int32_t dx, int32_t dy)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
m_screen->mouseRelativeMove(dx, dy);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-11 01:11:56 +00:00
|
|
|
void Client::mouseWheel(int32_t xDelta, int32_t yDelta)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
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()
|
|
|
|
|
{
|
2026-05-26 14:20:19 +00:00
|
|
|
m_relativeMouseMoves = false;
|
|
|
|
|
m_hasRelativeRestorePosition = false;
|
2024-10-17 18:04:35 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2026-06-30 12:29:58 +00:00
|
|
|
if (options.size() % 2 != 0) {
|
|
|
|
|
LOG_ERR("options are the incorrect size, can not process them");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-27 16:29:43 +00:00
|
|
|
for (auto 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) {
|
2026-05-09 00:27:37 +00:00
|
|
|
LOG_INFO("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;
|
|
|
|
|
}
|
2026-05-26 14:20:19 +00:00
|
|
|
} else if (id == kOptionRelativeMouseMoves) {
|
|
|
|
|
index++;
|
|
|
|
|
if (index != options.end()) {
|
|
|
|
|
m_relativeMouseMoves = (*index != 0);
|
|
|
|
|
if (m_relativeMouseMoves && m_ready && !m_hasRelativeRestorePosition) {
|
|
|
|
|
saveRelativeRestorePosition();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_enableClipboard && !m_maximumClipboardSize) {
|
|
|
|
|
m_enableClipboard = false;
|
2026-05-09 00:27:37 +00:00
|
|
|
LOG_INFO("clipboard sharing is disabled because the server set the maximum clipboard size to 0");
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_screen->setOptions(options);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 14:20:19 +00:00
|
|
|
void Client::saveRelativeRestorePosition()
|
|
|
|
|
{
|
|
|
|
|
m_screen->getCursorPos(m_relativeRestoreX, m_relativeRestoreY);
|
|
|
|
|
m_hasRelativeRestorePosition = true;
|
|
|
|
|
LOG_VERBOSE("saved relative restore position: %d,%d", m_relativeRestoreX, m_relativeRestoreY);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string Client::getName() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
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
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_screen != nullptr);
|
|
|
|
|
assert(m_server != nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// 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
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string data = clipboard.marshall();
|
2024-07-02 19:07:06 +00:00
|
|
|
if (data.size() >= m_maximumClipboardSize * 1024) {
|
2026-05-10 05:18:20 +00:00
|
|
|
LOG_WARN("not sending clipboard data, exceeds limit: %zu KB", m_maximumClipboardSize);
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-13 00:29:22 +00:00
|
|
|
void Client::sendEvent(EventTypes type)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-11-13 00:29:22 +00:00
|
|
|
m_events->addEvent(Event(type, getEventTarget()));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::sendConnectionFailedEvent(const char *msg)
|
|
|
|
|
{
|
2025-04-27 16:29:43 +00:00
|
|
|
auto *info = new FailInfo(msg);
|
2024-07-02 19:07:06 +00:00
|
|
|
info->m_retry = true;
|
2025-07-08 12:12:53 +00:00
|
|
|
Event event(EventTypes::ClientConnectionFailed, getEventTarget(), info, Event::EventFlags::DontFreeData);
|
2025-11-13 01:29:03 +00:00
|
|
|
m_events->addEvent(std::move(event));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupConnecting()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_stream != nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-08-23 19:27:50 +00:00
|
|
|
if (Settings::value(Settings::Security::TlsEnabled).toBool()) {
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleConnected();
|
|
|
|
|
});
|
2024-07-02 19:07:06 +00:00
|
|
|
} else {
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::DataSocketConnected, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleConnected();
|
|
|
|
|
});
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), [this](const auto &e) {
|
|
|
|
|
handleConnectionFailed(e);
|
|
|
|
|
});
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupConnection()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_stream != nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2026-07-10 14:40:20 +00:00
|
|
|
m_events->addHandler(EventTypes::ClientDisconnectRequested, m_stream->getEventTarget(), [this](const auto &e) {
|
|
|
|
|
handleDisconnectRequested(e);
|
|
|
|
|
});
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::SocketDisconnected, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleDisconnected();
|
|
|
|
|
});
|
|
|
|
|
m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleHello();
|
|
|
|
|
});
|
|
|
|
|
m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleOutputError();
|
|
|
|
|
});
|
|
|
|
|
m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleDisconnected();
|
|
|
|
|
});
|
|
|
|
|
m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleDisconnected();
|
|
|
|
|
});
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-18 15:27:24 +00:00
|
|
|
bool Client::setupScreen(int16_t protocolMinor)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_server == nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
m_ready = false;
|
2026-09-18 15:27:24 +00:00
|
|
|
|
|
|
|
|
// only 1.6 and later have a proxy: the clipboard, mouse wheel and key message formats
|
|
|
|
|
// differ below that, and nothing older (synergy 1.4 and earlier) still needs supporting.
|
|
|
|
|
// a version with no case is refused by the hello handler.
|
|
|
|
|
switch (protocolMinor) {
|
|
|
|
|
case 6:
|
|
|
|
|
m_server = new ServerProxy(this, m_stream, m_events);
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
m_server = new ServerProxy1_7(this, m_stream, m_events);
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
m_server = new ServerProxy1_8(this, m_stream, m_events);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_server != nullptr) {
|
|
|
|
|
m_events->addHandler(EventTypes::ScreenShapeChanged, getEventTarget(), [this](const auto &) {
|
|
|
|
|
handleShapeChanged();
|
|
|
|
|
});
|
|
|
|
|
m_events->addHandler(EventTypes::ClipboardGrabbed, getEventTarget(), [this](const auto &e) {
|
|
|
|
|
handleClipboardGrabbed(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return m_server != nullptr;
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Client::setupTimer()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
assert(m_timer == nullptr);
|
|
|
|
|
m_timer = m_events->newOneShotTimer(2.0, nullptr);
|
2025-06-18 04:17:54 +00:00
|
|
|
m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleConnectTimeout(); });
|
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()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_stream != nullptr) {
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->removeHandler(EventTypes::DataSocketConnected, m_stream->getEventTarget());
|
2026-07-10 14:40:20 +00:00
|
|
|
m_events->removeHandler(EventTypes::DataSocketSecureConnected, m_stream->getEventTarget());
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->removeHandler(EventTypes::DataSocketConnectionFailed, 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()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_stream != nullptr) {
|
2025-07-01 03:23:18 +00:00
|
|
|
using enum EventTypes;
|
|
|
|
|
m_events->removeHandler(StreamInputReady, m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(StreamOutputError, m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(StreamInputShutdown, m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(StreamOutputShutdown, m_stream->getEventTarget());
|
|
|
|
|
m_events->removeHandler(SocketDisconnected, m_stream->getEventTarget());
|
2026-07-10 14:40:20 +00:00
|
|
|
m_events->removeHandler(ClientDisconnectRequested, 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()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_server != nullptr) {
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_ready) {
|
|
|
|
|
m_screen->disable();
|
|
|
|
|
m_ready = false;
|
|
|
|
|
}
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->removeHandler(EventTypes::ScreenShapeChanged, getEventTarget());
|
|
|
|
|
m_events->removeHandler(EventTypes::ClipboardGrabbed, getEventTarget());
|
2024-07-02 19:07:06 +00:00
|
|
|
delete m_server;
|
2025-04-27 19:39:23 +00:00
|
|
|
m_server = nullptr;
|
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::cleanupTimer()
|
|
|
|
|
{
|
2025-04-27 19:39:23 +00:00
|
|
|
if (m_timer != nullptr) {
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->removeHandler(EventTypes::Timer, m_timer);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->deleteTimer(m_timer);
|
2025-04-27 19:39:23 +00:00
|
|
|
m_timer = nullptr;
|
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::cleanupStream()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
delete m_stream;
|
2025-04-27 19:39:23 +00:00
|
|
|
m_stream = nullptr;
|
2015-01-14 17:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleConnected()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("connected, waiting for hello");
|
2024-07-02 19:07:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleConnectionFailed(const Event &event)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-04-27 16:29:43 +00:00
|
|
|
auto *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();
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("connection failed");
|
2024-07-02 19:07:06 +00:00
|
|
|
sendConnectionFailedEvent(info->m_what.c_str());
|
|
|
|
|
delete info;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleConnectTimeout()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnecting();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
cleanupStream();
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("connection timed out");
|
2024-07-02 19:07:06 +00:00
|
|
|
sendConnectionFailedEvent("Timed out");
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleOutputError()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnection();
|
2025-08-06 11:54:59 +00:00
|
|
|
LOG_WARN("error sending to server");
|
2025-11-13 00:29:22 +00:00
|
|
|
sendEvent(EventTypes::ClientDisconnected);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleDisconnected()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupScreen();
|
|
|
|
|
cleanupConnection();
|
2026-05-09 01:10:59 +00:00
|
|
|
LOG_VERBOSE("disconnected");
|
2025-11-13 00:29:22 +00:00
|
|
|
sendEvent(EventTypes::ClientDisconnected);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 14:40:20 +00:00
|
|
|
void Client::handleDisconnectRequested(const Event &event)
|
|
|
|
|
{
|
|
|
|
|
const auto *request = static_cast<const DisconnectRequest *>(event.getDataObject());
|
|
|
|
|
if (request == nullptr) {
|
|
|
|
|
disconnect(nullptr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request->kind() == DisconnectRequest::Kind::Refuse) {
|
|
|
|
|
refuseConnection(request->refusalReason(), request->message());
|
|
|
|
|
} else {
|
|
|
|
|
disconnect(request->message());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleShapeChanged()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-08-06 11:54:59 +00:00
|
|
|
LOG_DEBUG("resolution changed");
|
2024-07-02 19:07:06 +00:00
|
|
|
m_server->onInfoChanged();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleClipboardGrabbed(const Event &event)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-16 13:24:46 +00:00
|
|
|
|
2025-04-27 16:29:43 +00:00
|
|
|
const auto *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
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleHello()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2026-01-26 10:41:21 +00:00
|
|
|
int16_t serverMajor;
|
|
|
|
|
int16_t serverMinor;
|
|
|
|
|
|
|
|
|
|
// 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, &serverMajor, &serverMinor);
|
|
|
|
|
|
2026-01-26 15:46:07 +00:00
|
|
|
if (const auto proto = networkProtocolFromString(QString::fromStdString(protocolName));
|
|
|
|
|
proto == NetworkProtocol::Unknown) {
|
2026-01-26 10:41:21 +00:00
|
|
|
LOG_WARN("hello back received with protocol: '%s'", protocolName.c_str());
|
|
|
|
|
sendConnectionFailedEvent("got invalid hello message from server");
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-04 14:19:47 +00:00
|
|
|
if (serverMajor != kProtocolMajorVersion) {
|
|
|
|
|
LOG_WARN("server protocol version not compatible: %d.%d", serverMajor, serverMinor);
|
|
|
|
|
sendConnectionFailedEvent(IncompatibleClientException(serverMajor, serverMinor).what());
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t helloBackMinor = kProtocolMinorVersion;
|
|
|
|
|
if (serverMinor < kProtocolMinorVersion) {
|
|
|
|
|
helloBackMinor = serverMinor;
|
|
|
|
|
LOG_INFO(
|
|
|
|
|
"downgrading client protocol version from %d.%d to %d.%d", //
|
|
|
|
|
kProtocolMajorVersion, kProtocolMinorVersion, kProtocolMajorVersion, helloBackMinor
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-18 15:27:24 +00:00
|
|
|
// no proxy speaks the negotiated version, so hang up as incompatible rather than
|
|
|
|
|
// talk a version the client does not implement, the same rule the server applies
|
|
|
|
|
// when it picks a client proxy
|
|
|
|
|
if (!setupScreen(helloBackMinor)) {
|
|
|
|
|
LOG_WARN("server protocol version not supported: %d.%d", serverMajor, serverMinor);
|
|
|
|
|
sendConnectionFailedEvent(IncompatibleClientException(serverMajor, serverMinor).what());
|
|
|
|
|
cleanupTimer();
|
|
|
|
|
cleanupConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-04 14:19:47 +00:00
|
|
|
LOG_DEBUG("saying hello back with version %s %d.%d", protocolName.c_str(), kProtocolMajorVersion, helloBackMinor);
|
2026-01-26 10:41:21 +00:00
|
|
|
|
|
|
|
|
// dynamically build write format for hello back since `ProtocolUtil::writef`
|
|
|
|
|
// doesn't support formatting fixed length strings yet.
|
|
|
|
|
std::string helloBackMessage = protocolName + kMsgHelloBackArgs;
|
2026-07-04 14:19:47 +00:00
|
|
|
ProtocolUtil::writef(m_stream, helloBackMessage.c_str(), kProtocolMajorVersion, 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
|
|
|
|
|
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()) {
|
2025-05-02 01:50:53 +00:00
|
|
|
m_events->addEvent(Event(EventTypes::StreamInputReady, m_stream->getEventTarget()));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleSuspend()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!m_suspended) {
|
2025-08-06 11:54:59 +00:00
|
|
|
LOG_INFO("suspend");
|
2024-07-02 19:07:06 +00:00
|
|
|
m_suspended = true;
|
|
|
|
|
bool wasConnected = isConnected();
|
2025-04-27 19:39:23 +00:00
|
|
|
disconnect(nullptr);
|
2024-07-02 19:07:06 +00:00
|
|
|
m_connectOnResume = wasConnected;
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void Client::handleResume()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_suspended) {
|
2025-08-06 11:54:59 +00:00
|
|
|
LOG_INFO("resume");
|
2024-07-02 19:07:06 +00:00
|
|
|
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::bindNetworkInterface(IDataSocket *socket) const
|
|
|
|
|
{
|
2026-04-20 13:04:24 +00:00
|
|
|
const auto address = Settings::value(Settings::Core::Interface).toString();
|
|
|
|
|
if (address.isEmpty())
|
|
|
|
|
return;
|
2023-03-29 08:39:49 +00:00
|
|
|
|
2026-04-20 13:04:24 +00:00
|
|
|
LOG_DEBUG("bind to network interface: %s", qPrintable(address));
|
2023-03-29 08:39:49 +00:00
|
|
|
|
2026-04-20 13:04:24 +00:00
|
|
|
NetworkAddress bindAddress(address.toStdString());
|
|
|
|
|
bindAddress.resolve();
|
|
|
|
|
|
|
|
|
|
socket->bind(bindAddress);
|
2023-03-29 08:39:49 +00:00
|
|
|
}
|