aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/client
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:13 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:13 -0500
commitbeb08eb751fa8e1f72042f263316ab5e5ddb596d (patch)
tree3b00df983527648bdae610ac7b88cb639b1f1828 /src/lib/client
parentfbc30002ab3438356c0476e70c4577a0310d52c0 (diff)
New upstream version 2.4.0+dfsg.upstream/2.4.0+dfsgupstream
Diffstat (limited to 'src/lib/client')
-rw-r--r--src/lib/client/CMakeLists.txt4
-rw-r--r--src/lib/client/Client.cpp46
-rw-r--r--src/lib/client/Client.h16
-rw-r--r--src/lib/client/ServerProxy.cpp37
-rw-r--r--src/lib/client/ServerProxy.h8
5 files changed, 59 insertions, 52 deletions
diff --git a/src/lib/client/CMakeLists.txt b/src/lib/client/CMakeLists.txt
index 97dc9db..033876f 100644
--- a/src/lib/client/CMakeLists.txt
+++ b/src/lib/client/CMakeLists.txt
@@ -1,11 +1,11 @@
# barrier -- mouse and keyboard sharing utility
# Copyright (C) 2012-2016 Symless Ltd.
# Copyright (C) 2009 Nick Bolton
-#
+#
# 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
diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp
index 96d2c67..a7b15cf 100644
--- a/src/lib/client/Client.cpp
+++ b/src/lib/client/Client.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
- *
+ *
* 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
@@ -37,7 +37,6 @@
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
-#include "base/TMethodJob.h"
#include <cstring>
#include <cstdlib>
@@ -127,6 +126,12 @@ Client::connect()
return;
}
+ auto security_level = ConnectionSecurityLevel::PLAINTEXT;
+ if (m_useSecureNetwork) {
+ // client always authenticates server
+ security_level = ConnectionSecurityLevel::ENCRYPTED_AUTHENTICATED;
+ }
+
try {
// resolve the server hostname. do this every time we connect
// in case we couldn't resolve the address earlier or the address
@@ -134,20 +139,19 @@ Client::connect()
// being shuttled between various networks). patch by Brent
// Priddy.
m_serverAddress.resolve();
-
+
// m_serverAddress will be null if the hostname address is not reolved
if (m_serverAddress.getAddress() != NULL) {
// to help users troubleshoot, show server host name (issue: 60)
- LOG((CLOG_NOTE "connecting to '%s': %s:%i",
+ LOG((CLOG_NOTE "connecting to '%s': %s:%i",
m_serverAddress.getHostname().c_str(),
ARCH->addrToString(m_serverAddress.getAddress()).c_str(),
m_serverAddress.getPort()));
}
// create the socket
- IDataSocket* socket = m_socketFactory->create(
- ARCH->getAddrFamily(m_serverAddress.getAddress()),
- m_useSecureNetwork);
+ IDataSocket* socket = m_socketFactory->create(ARCH->getAddrFamily(m_serverAddress.getAddress()),
+ security_level);
m_socket = dynamic_cast<TCPSocket*>(socket);
// filter socket messages, including a packetizing filter
@@ -255,7 +259,7 @@ Client::leave()
m_active = false;
m_screen->leave();
-
+
if (m_enableClipboard) {
// send clipboards that we own and that have changed
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
@@ -755,9 +759,7 @@ void
Client::onFileRecieveCompleted()
{
if (isReceivedFileSizeValid()) {
- m_writeToDropDirThread = new Thread(
- new TMethodJob<Client>(
- this, &Client::writeToDropDirThread));
+ m_writeToDropDirThread = new Thread([this](){ write_to_drop_dir_thread(); });
}
}
@@ -767,15 +769,14 @@ Client::handleStopRetry(const Event&, void*)
m_args.m_restartable = false;
}
-void
-Client::writeToDropDirThread(void*)
+void Client::write_to_drop_dir_thread()
{
LOG((CLOG_DEBUG "starting write to drop dir thread"));
while (m_screen->isFakeDraggingStarted()) {
ARCH->sleep(.1f);
}
-
+
DropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList,
m_receivedFileData);
}
@@ -790,7 +791,7 @@ Client::dragInfoReceived(UInt32 fileNum, std::string data)
}
DragInformation::parseDragInfo(m_dragFileList, fileNum, data);
-
+
m_screen->startDraggingFiles(m_dragFileList);
}
@@ -806,19 +807,14 @@ Client::sendFileToServer(const char* filename)
if (m_sendFileThread != NULL) {
StreamChunker::interruptFile();
}
-
- m_sendFileThread = new Thread(
- new TMethodJob<Client>(
- this, &Client::sendFileThread,
- static_cast<void*>(const_cast<char*>(filename))));
+
+ m_sendFileThread = new Thread([this, filename]() { send_file_thread(filename); });
}
-void
-Client::sendFileThread(void* filename)
+void Client::send_file_thread(const char* filename)
{
try {
- char* name = static_cast<char*>(filename);
- StreamChunker::sendFile(name, m_events, this);
+ StreamChunker::sendFile(filename, m_events, this);
}
catch (std::runtime_error& error) {
LOG((CLOG_ERR "failed sending file chunks: %s", error.what()));
diff --git a/src/lib/client/Client.h b/src/lib/client/Client.h
index 7e566be..c172af2 100644
--- a/src/lib/client/Client.h
+++ b/src/lib/client/Client.h
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
- *
+ *
* 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
@@ -90,11 +90,11 @@ public:
//! Create a new thread and use it to send file to Server
void sendFileToServer(const char* filename);
-
+
//! Send dragging file information back to server
void sendDragInfo(UInt32 fileCount, std::string& info, size_t size);
-
+
//@}
//! @name accessors
//@{
@@ -118,8 +118,8 @@ public:
to connect) to.
*/
NetworkAddress getServerAddress() const;
-
- //! Return true if recieved file size is valid
+
+ //! Return true if received file size is valid
bool isReceivedFileSizeValid();
//! Return expected file size
@@ -167,8 +167,8 @@ private:
void sendEvent(Event::Type, void*);
void sendConnectionFailedEvent(const char* msg);
void sendFileChunk(const void* data);
- void sendFileThread(void*);
- void writeToDropDirThread(void*);
+ void send_file_thread(const char* filename);
+ void write_to_drop_dir_thread();
void setupConnecting();
void setupConnection();
void setupScreen();
diff --git a/src/lib/client/ServerProxy.cpp b/src/lib/client/ServerProxy.cpp
index c067f13..c6e3576 100644
--- a/src/lib/client/ServerProxy.cpp
+++ b/src/lib/client/ServerProxy.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
- *
+ *
* 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
@@ -26,6 +26,7 @@
#include "barrier/ProtocolUtil.h"
#include "barrier/option_types.h"
#include "barrier/protocol_types.h"
+#include "barrier/XBarrier.h"
#include "io/IStream.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
@@ -124,17 +125,27 @@ ServerProxy::handleData(const Event&, void*)
// parse message
LOG((CLOG_DEBUG2 "msg from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
- switch ((this->*m_parser)(code)) {
- case kOkay:
- break;
-
- case kUnknown:
- LOG((CLOG_ERR "invalid message from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
+ try {
+ switch ((this->*m_parser)(code)) {
+ case kOkay:
+ break;
+
+ case kUnknown:
+ LOG((CLOG_ERR "invalid message from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
+ m_client->disconnect("invalid message from server");
+ return;
+
+ case kDisconnect:
+ return;
+ }
+ } catch (const XBadClient& e) {
+ // TODO: disconnect handling is currently dispersed across both parseMessage() and
+ // handleData() functions, we should collect that to a single place
+
+ LOG((CLOG_ERR "protocol error from server: %s", e.what()));
+ ProtocolUtil::writef(m_stream, kMsgEBad);
m_client->disconnect("invalid message from server");
return;
-
- case kDisconnect:
- return;
}
// next message
@@ -553,7 +564,7 @@ ServerProxy::setClipboard()
static std::string dataCached;
ClipboardID id;
UInt32 seq;
-
+
int r = ClipboardChunk::assemble(m_stream, dataCached, id, seq);
if (r == kStart) {
@@ -562,7 +573,7 @@ ServerProxy::setClipboard()
}
else if (r == kFinish) {
LOG((CLOG_DEBUG "received clipboard %d size=%d", id, dataCached.size()));
-
+
// forward
Clipboard clipboard;
clipboard.unmarshall(dataCached, 0);
diff --git a/src/lib/client/ServerProxy.h b/src/lib/client/ServerProxy.h
index abca4c3..12a3226 100644
--- a/src/lib/client/ServerProxy.h
+++ b/src/lib/client/ServerProxy.h
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
- *
+ *
* 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
@@ -58,8 +58,8 @@ public:
// sending dragging information to server
void sendDragInfo(UInt32 fileCount, const char* info, size_t size);
-
-#ifdef TEST_ENV
+
+#ifdef BARRIER_TEST_ENV
void handleDataForTest() { handleData(Event(), NULL); }
#endif