Skip to content

Commit

Permalink
Synergy 1298 client can't connect to previous server version (deskflo…
Browse files Browse the repository at this point in the history
…w#7112)

* SYNERGY-1298 Remove language from hello message

* SYNERGY-1298 Client compatibility

* SYNERGY-1298 Compatibility for keydown

* SYNERGY-1298 Client part for keydown campatibility

* SYNERGY-1298 Move lang checking to handshake stage

* Update ChangeLog

* SYNERGY-1298 Fix code smell
  • Loading branch information
SerhiiGadzhilov authored Oct 25, 2021
1 parent 940e2ec commit d92f01f
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 101 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ v1.14.2-snapshot
===========
Bug fixes:
- #7070 Fix radio button shifted focus on macOS
- #7038 | #7104 | #7111 Fix client and server different keyboard layout errors
- #7038 | #7104 | #7111 | #7112 Fix client and server different keyboard layout errors
- #7078 Fix clipboard re-enables automatically
- #7077 Fix Ubuntu, CentOS and Debian build after SYNERGY-1161
- #7080 Add trace if the system can't open file with trusted fingerprints
Expand Down
42 changes: 25 additions & 17 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ Client::handshakeComplete()
{
m_ready = true;
m_screen->enable();
checkMissedLanguages();
sendEvent(m_events->forClient().connected(), NULL);
}

Expand Down Expand Up @@ -720,25 +719,45 @@ Client::handleClipboardGrabbed(const Event& event, void*)
}
}

bool
Client::isCompatible(int major, int minor) const
{
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
};

bool isCompatible = false;

if (major == kProtocolMajorVersion) {
auto versions = compatibleTable.find(minor);
if (versions != compatibleTable.end()) {
auto compatibleVersions = versions->second;
isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end();
}
}

return isCompatible;
}

void
Client::handleHello(const Event&, void*)
{
SInt16 major, minor;
String remoteLanguages;
if (!ProtocolUtil::readf(m_stream, kMsgHello, &major, &minor, &remoteLanguages)) {
if (!ProtocolUtil::readf(m_stream, kMsgHello, &major, &minor)) {
sendConnectionFailedEvent("Protocol error from server, check encryption settings");
cleanupTimer();
cleanupConnection();
return;
}
m_languageManager.setRemoteLanguages(remoteLanguages);

// check versions
LOG((CLOG_DEBUG1 "got hello version %d.%d", major, minor));
SInt16 helloBackMajor = kProtocolMajorVersion;
SInt16 helloBackMinor = kProtocolMinorVersion;
if (major == kProtocolMajorVersion && minor == 6 && kProtocolMinorVersion == 7) {
//because 1.6 and 1.7 is comptable - downgrading protocol for server

if (isCompatible(major, minor)) {
//because 1.6 is comptable with 1.7 and 1.8 - downgrading protocol for server
LOG((CLOG_NOTE "Downgrading protocol version for server"));
helloBackMinor = minor;
}
Expand Down Expand Up @@ -814,17 +833,6 @@ Client::onFileRecieveCompleted()
}
}

void
Client::checkMissedLanguages() const
{
auto missedLanguages = m_languageManager.getMissedLanguages();
if (!missedLanguages.empty()) {
AppUtil::instance().showNotification("Language synchronization error",
"You need to install these languages on this computer to enable support for multiple languages: "
+ missedLanguages);
}
}

void
Client::handleStopRetry(const Event&, void*)
{
Expand Down
4 changes: 1 addition & 3 deletions src/lib/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "synergy/DragInformation.h"
#include "synergy/INode.h"
#include "synergy/ClientArgs.h"
#include "synergy/languages/LanguageManager.h"
#include "net/NetworkAddress.h"
#include "base/EventTypes.h"
#include "mt/CondVar.h"
Expand Down Expand Up @@ -201,6 +200,7 @@ class Client : public IClient, public INode {
void handleDisconnected(const Event&, void*);
void handleShapeChanged(const Event&, void*);
void handleClipboardGrabbed(const Event&, void*);
bool isCompatible(int major, int minor) const;
void handleHello(const Event&, void*);
void handleSuspend(const Event& event, void*);
void handleResume(const Event& event, void*);
Expand All @@ -209,7 +209,6 @@ class Client : public IClient, public INode {
void handleStopRetry(const Event&, void*);
void onFileRecieveCompleted();
void sendClipboardThread(void*);
void checkMissedLanguages() const;

public:
bool m_mock;
Expand Down Expand Up @@ -243,5 +242,4 @@ class Client : public IClient, public INode {
size_t m_maximumClipboardSize;
lib::synergy::ClientArgs m_args;
size_t m_resolvedAddressesCount = 0;
synergy::languages::LanguageManager m_languageManager;
};
87 changes: 63 additions & 24 deletions src/lib/client/ServerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ ServerProxy::parseHandshakeMessage(const UInt8* code)
m_client->refuseConnection("server reported a protocol error");
return kDisconnect;
}
else if (memcmp(code, kMsgDLanguageSynchronisation, 4) == 0) {
setServerLanguages();
}
else {
return kUnknown;
}
Expand All @@ -236,7 +239,25 @@ ServerProxy::parseMessage(const UInt8* code)
}

else if (memcmp(code, kMsgDKeyDown, 4) == 0) {
keyDown();
UInt16 id = 0;
UInt16 mask = 0;
UInt16 button = 0;
ProtocolUtil::readf(m_stream, kMsgDKeyDown + 4, &id, &mask, &button);
LOG((CLOG_DEBUG1 "recv key down id=0x%08x, mask=0x%04x, button=0x%04x", id, mask, button));

keyDown(id, mask, button, "");
}

else if (memcmp(code, kMsgDKeyDownLang, 4) == 0) {
String lang;
UInt16 id = 0;
UInt16 mask = 0;
UInt16 button = 0;

ProtocolUtil::readf(m_stream, kMsgDKeyDownLang + 4, &id, &mask, &button, &lang);
LOG((CLOG_DEBUG1 "recv key down id=0x%08x, mask=0x%04x, button=0x%04x, lang=\"%s\"", id, mask, button, lang.c_str()));

keyDown(id, mask, button, lang);
}

else if (memcmp(code, kMsgDKeyUp, 4) == 0) {
Expand Down Expand Up @@ -599,32 +620,11 @@ ServerProxy::grabClipboard()
}

void
ServerProxy::keyDown()
ServerProxy::keyDown(UInt16 id, UInt16 mask, UInt16 button, const String& lang)
{
// get mouse up to date
flushCompressedMouse();

// parse
UInt16 id, mask, button;
String lang;
ProtocolUtil::readf(m_stream, kMsgDKeyDown + 4, &id, &mask, &button, &lang);
LOG((CLOG_DEBUG1 "recv key down id=0x%08x, mask=0x%04x, button=0x%04x, lang=\"%s\"", id, mask, button, lang.c_str()));

if(m_serverLanguage != lang) {
m_isUserNotifiedAboutLanguageSyncError = false;
m_serverLanguage = lang;
}

auto localList = AppUtil::instance().getKeyboardLayoutList();
if(std::find(localList.begin(), localList.end(), lang) == localList.end()) {
if(!m_isUserNotifiedAboutLanguageSyncError) {
AppUtil::instance().showNotification("Language error", "Current server language is not installed on client!");
m_isUserNotifiedAboutLanguageSyncError = true;
}
}
else {
m_isUserNotifiedAboutLanguageSyncError = false;
}
setActiveServerLanguage(lang);

// translate
KeyID id2 = translateKey(static_cast<KeyID>(id));
Expand Down Expand Up @@ -954,3 +954,42 @@ ServerProxy::secureInputNotification()
"To fix the keyboard, the application must be closed.");
}
}

void
ServerProxy::setServerLanguages()
{
String serverLanguages;
ProtocolUtil::readf(m_stream, kMsgDLanguageSynchronisation + 4, &serverLanguages);
m_languageManager.setRemoteLanguages(serverLanguages);

auto missedLanguages = m_languageManager.getMissedLanguages();
if (!missedLanguages.empty()) {
AppUtil::instance().showNotification("Language synchronization error",
"You need to install these languages on this computer to enable support for multiple languages: "
+ missedLanguages);
}
}

void
ServerProxy::setActiveServerLanguage(const String& language)
{
if (!language.empty()) {
if(m_serverLanguage != language) {
m_isUserNotifiedAboutLanguageSyncError = false;
m_serverLanguage = language;
}

if (!m_languageManager.isLanguageInstalled(m_serverLanguage)) {
if(!m_isUserNotifiedAboutLanguageSyncError) {
AppUtil::instance().showNotification("Language error", "Current server language is not installed on client!");
m_isUserNotifiedAboutLanguageSyncError = true;
}
}
else {
m_isUserNotifiedAboutLanguageSyncError = false;
}
}
else {
LOG((CLOG_DEBUG1 "Active server langauge is empty!"));
}
}
6 changes: 5 additions & 1 deletion src/lib/client/ServerProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include "synergy/languages/LanguageManager.h"
#include "synergy/clipboard_types.h"
#include "synergy/key_types.h"
#include "base/Event.h"
Expand Down Expand Up @@ -96,7 +97,7 @@ class ServerProxy {
void leave();
void setClipboard();
void grabClipboard();
void keyDown();
void keyDown(UInt16 id, UInt16 mask, UInt16 button, const String& lang);
void keyRepeat();
void keyUp();
void mouseDown();
Expand All @@ -113,6 +114,8 @@ class ServerProxy {
void dragInfoReceived();
void handleClipboardSendingEvent(const Event&, void*);
void secureInputNotification();
void setServerLanguages();
void setActiveServerLanguage(const String& language);

private:
typedef EResult (ServerProxy::*MessageParser)(const UInt8*);
Expand All @@ -138,4 +141,5 @@ class ServerProxy {
IEventQueue* m_events;
String m_serverLanguage = "";
bool m_isUserNotifiedAboutLanguageSyncError = false;
synergy::languages::LanguageManager m_languageManager;
};
6 changes: 3 additions & 3 deletions src/lib/server/ClientProxy1_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ ClientProxy1_1::~ClientProxy1_1()
}

void
ClientProxy1_1::keyDown(KeyID key, KeyModifierMask mask, KeyButton button, const String& lang)
ClientProxy1_1::keyDown(KeyID key, KeyModifierMask mask, KeyButton button, const String&)
{
LOG((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x, button=0x%04x, lang=\"%s\"", getName().c_str(), key, mask, button, lang.c_str()));
ProtocolUtil::writef(getStream(), kMsgDKeyDown, key, mask, button, &lang);
LOG((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x, button=0x%04x", getName().c_str(), key, mask, button));
ProtocolUtil::writef(getStream(), kMsgDKeyDown, key, mask, button);
}

void
Expand Down
49 changes: 49 additions & 0 deletions src/lib/server/ClientProxy1_8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015-2021 Symless Ltd.
*
* 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 LICENSE 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/>.
*/
#include "base/Log.h"
#include "synergy/ProtocolUtil.h"
#include "synergy/languages/LanguageManager.h"

#include "ClientProxy1_8.h"


ClientProxy1_8::ClientProxy1_8(const String& name, synergy::IStream* adoptedStream, Server* server, IEventQueue* events) :
ClientProxy1_7(name, adoptedStream, server, events)
{
synchronizeLanguages();
}

void ClientProxy1_8::synchronizeLanguages() const
{
synergy::languages::LanguageManager languageManager;
auto localLanguages = languageManager.getSerializedLocalLanguages();
if (!localLanguages.empty()) {
LOG((CLOG_DEBUG1 "send server languages to the client: %s", localLanguages.c_str()));
ProtocolUtil::writef(getStream(), kMsgDLanguageSynchronisation, &localLanguages);
}
else {
LOG((CLOG_ERR "Fail to read server languages"));
}
}

void
ClientProxy1_8::keyDown(KeyID key, KeyModifierMask mask, KeyButton button, const String& language)
{
LOG((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x, button=0x%04x, language=%s", getName().c_str(), key, mask, button, language.c_str()));
ProtocolUtil::writef(getStream(), kMsgDKeyDownLang, key, mask, button, &language);
}

35 changes: 35 additions & 0 deletions src/lib/server/ClientProxy1_8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015-2021 Symless Ltd.
*
* 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 LICENSE 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/>.
*/
#ifndef SERVER_CLIENTPROXY1_8_H
#define SERVER_CLIENTPROXY1_8_H

#include "server/ClientProxy1_7.h"

class ClientProxy1_8 : public ClientProxy1_7
{
public:
ClientProxy1_8(const String& name, synergy::IStream* adoptedStream, Server* server, IEventQueue* events);
~ClientProxy1_8() override = default;

void keyDown(KeyID, KeyModifierMask, KeyButton, const String&) override;

private:
void synchronizeLanguages() const;

};

#endif // SERVER_CLIENTPROXY1_8_H
Loading

0 comments on commit d92f01f

Please sign in to comment.