- checked filename's validation before sending drag info
- refactored duplicated write to drop dir code - removed legacy member variables - fixed code style - fixed typo
This commit is contained in:
parent
935ca0b2f2
commit
f87bd9e860
|
@ -21,6 +21,7 @@
|
||||||
#include "client/ServerProxy.h"
|
#include "client/ServerProxy.h"
|
||||||
#include "synergy/Screen.h"
|
#include "synergy/Screen.h"
|
||||||
#include "synergy/Clipboard.h"
|
#include "synergy/Clipboard.h"
|
||||||
|
#include "synergy/DropHelper.h"
|
||||||
#include "synergy/PacketStreamFilter.h"
|
#include "synergy/PacketStreamFilter.h"
|
||||||
#include "synergy/ProtocolUtil.h"
|
#include "synergy/ProtocolUtil.h"
|
||||||
#include "synergy/protocol_types.h"
|
#include "synergy/protocol_types.h"
|
||||||
|
@ -746,29 +747,8 @@ CClient::writeToDropDirThread(void*)
|
||||||
ARCH->sleep(.1f);
|
ARCH->sleep(.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fileTransferDes = m_screen->getDropTarget();
|
CDropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList,
|
||||||
LOG((CLOG_DEBUG "dropping file, files=%i target=%s", m_dragFileList.size(), m_fileTransferDes.c_str()));
|
m_receivedFileData);
|
||||||
|
|
||||||
if (!m_fileTransferDes.empty() && m_dragFileList.size() > 0) {
|
|
||||||
std::fstream file;
|
|
||||||
CString dropTarget = m_fileTransferDes;
|
|
||||||
#ifdef SYSAPI_WIN32
|
|
||||||
dropTarget.append("\\");
|
|
||||||
#else
|
|
||||||
dropTarget.append("/");
|
|
||||||
#endif
|
|
||||||
dropTarget.append(m_dragFileList.at(0).getFilename());
|
|
||||||
file.open(dropTarget.c_str(), std::ios::out | std::ios::binary);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
// TODO: file open failed
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -110,9 +110,6 @@ public:
|
||||||
//! Create a new thread and use it to send file to Server
|
//! Create a new thread and use it to send file to Server
|
||||||
void sendFileToServer(const char* filename);
|
void sendFileToServer(const char* filename);
|
||||||
|
|
||||||
//! Set file transder destination
|
|
||||||
void setFileTransferDes(CString& des) { m_fileTransferDes = des; }
|
|
||||||
|
|
||||||
//! Send dragging file information back to server
|
//! Send dragging file information back to server
|
||||||
void sendDragInfo(UInt32 fileCount, CString& info, size_t size);
|
void sendDragInfo(UInt32 fileCount, CString& info, size_t size);
|
||||||
|
|
||||||
|
@ -231,8 +228,6 @@ private:
|
||||||
CCryptoOptions m_crypto;
|
CCryptoOptions m_crypto;
|
||||||
std::size_t m_expectedFileSize;
|
std::size_t m_expectedFileSize;
|
||||||
CString m_receivedFileData;
|
CString m_receivedFileData;
|
||||||
CString m_fileTransferSrc;
|
|
||||||
CString m_fileTransferDes;
|
|
||||||
CDragFileList m_dragFileList;
|
CDragFileList m_dragFileList;
|
||||||
CString m_dragFileExt;
|
CString m_dragFileExt;
|
||||||
CThread* m_sendFileThread;
|
CThread* m_sendFileThread;
|
||||||
|
|
|
@ -1873,7 +1873,12 @@ CMSWindowsScreen::getDraggingFilename()
|
||||||
ShowWindow(m_dropWindow, SW_HIDE);
|
ShowWindow(m_dropWindow, SW_HIDE);
|
||||||
|
|
||||||
if (!filename.empty()) {
|
if (!filename.empty()) {
|
||||||
m_draggingFilename = filename;
|
if (CDragInformation::isFileValid(filename)) {
|
||||||
|
m_draggingFilename = filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG((CLOG_DEBUG "drag file name is invalid: %s", filename.c_str()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_draggingFilename.empty()) {
|
if (m_draggingFilename.empty()) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ fakeDragging(const char* str, int cursorX, int cursorY)
|
||||||
|
|
||||||
[g_dragWindow setFrame:rect display:NO];
|
[g_dragWindow setFrame:rect display:NO];
|
||||||
[g_dragWindow makeKeyAndOrderFront:nil];
|
[g_dragWindow makeKeyAndOrderFront:nil];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
|
||||||
[g_dragView setFileExt:g_ext];
|
[g_dragView setFileExt:g_ext];
|
||||||
|
|
||||||
|
|
|
@ -911,12 +911,6 @@ COSXScreen::leave()
|
||||||
CString& fileList = getDraggingFilename();
|
CString& fileList = getDraggingFilename();
|
||||||
|
|
||||||
if (!m_isPrimary) {
|
if (!m_isPrimary) {
|
||||||
// TODO: is this duplicated?
|
|
||||||
// fake esc key down and up
|
|
||||||
fakeKeyDown(kKeyEscape, 8192, 1);
|
|
||||||
fakeKeyUp(1);
|
|
||||||
fakeMouseButton(kButtonLeft, false);
|
|
||||||
|
|
||||||
if (fileList.empty() == false) {
|
if (fileList.empty() == false) {
|
||||||
CClientApp& app = CClientApp::instance();
|
CClientApp& app = CClientApp::instance();
|
||||||
CClient* client = app.getClientPtr();
|
CClient* client = app.getClientPtr();
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "server/ClientProxyUnknown.h"
|
#include "server/ClientProxyUnknown.h"
|
||||||
#include "server/PrimaryClient.h"
|
#include "server/PrimaryClient.h"
|
||||||
#include "synergy/IPlatformScreen.h"
|
#include "synergy/IPlatformScreen.h"
|
||||||
|
#include "synergy/DropHelper.h"
|
||||||
#include "synergy/option_types.h"
|
#include "synergy/option_types.h"
|
||||||
#include "synergy/protocol_types.h"
|
#include "synergy/protocol_types.h"
|
||||||
#include "synergy/XScreen.h"
|
#include "synergy/XScreen.h"
|
||||||
|
@ -2040,31 +2041,8 @@ CServer::writeToDropDirThread(void*)
|
||||||
ARCH->sleep(.1f);
|
ARCH->sleep(.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fileTransferDes = m_screen->getDropTarget();
|
CDropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList,
|
||||||
LOG((CLOG_DEBUG "dropping file, files=%i target=%s", m_dragFileList.size(), m_fileTransferDes.c_str()));
|
m_receivedFileData);
|
||||||
|
|
||||||
if (!m_fileTransferDes.empty() && m_dragFileList.size() > 0) {
|
|
||||||
std::fstream file;
|
|
||||||
CString dropTarget = m_fileTransferDes;
|
|
||||||
#ifdef SYSAPI_WIN32
|
|
||||||
dropTarget.append("\\");
|
|
||||||
#else
|
|
||||||
dropTarget.append("/");
|
|
||||||
#endif
|
|
||||||
dropTarget.append(m_dragFileList.at(0).getFilename());
|
|
||||||
file.open(dropTarget.c_str(), std::ios::out | std::ios::binary);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
// TODO: file open failed
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
m_dragFileList.clear();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -145,9 +145,6 @@ public:
|
||||||
//! Set the expected size of receiving file
|
//! Set the expected size of receiving file
|
||||||
void setExpectedFileSize(CString data);
|
void setExpectedFileSize(CString data);
|
||||||
|
|
||||||
//! Set file transder destination
|
|
||||||
void setFileTransferDes(CString& des) { m_fileTransferDes = des; }
|
|
||||||
|
|
||||||
//! Received a chunk of file data
|
//! Received a chunk of file data
|
||||||
void fileChunkReceived(CString data);
|
void fileChunkReceived(CString data);
|
||||||
|
|
||||||
|
@ -467,8 +464,6 @@ private:
|
||||||
// file transfer
|
// file transfer
|
||||||
size_t m_expectedFileSize;
|
size_t m_expectedFileSize;
|
||||||
CString m_receivedFileData;
|
CString m_receivedFileData;
|
||||||
CString m_fileTransferSrc;
|
|
||||||
CString m_fileTransferDes;
|
|
||||||
CDragFileList m_dragFileList;
|
CDragFileList m_dragFileList;
|
||||||
CThread* m_sendFileThread;
|
CThread* m_sendFileThread;
|
||||||
CThread* m_writeToDropDirThread;
|
CThread* m_writeToDropDirThread;
|
||||||
|
|
|
@ -86,12 +86,12 @@ CDragInformation::parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CSt
|
||||||
}
|
}
|
||||||
|
|
||||||
CString
|
CString
|
||||||
CDragInformation::getDragFileExtension(CString fileName)
|
CDragInformation::getDragFileExtension(CString filename)
|
||||||
{
|
{
|
||||||
size_t findResult = string::npos;
|
size_t findResult = string::npos;
|
||||||
findResult = fileName.find_last_of(".", fileName.size());
|
findResult = filename.find_last_of(".", filename.size());
|
||||||
if (findResult != string::npos) {
|
if (findResult != string::npos) {
|
||||||
return fileName.substr(findResult + 1, fileName.size() - findResult - 1);
|
return filename.substr(findResult + 1, filename.size() - findResult - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "";
|
return "";
|
||||||
|
@ -112,6 +112,21 @@ CDragInformation::setupDragInfo(CDragFileList& fileList, CString& output)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CDragInformation::isFileValid(CString filename)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
std::fstream file(filename.c_str(), ios::in|ios::binary);
|
||||||
|
|
||||||
|
if (file.is_open()) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
file. close();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
CDragInformation::stringToNum(CString& str)
|
CDragInformation::stringToNum(CString& str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,12 +35,14 @@ public:
|
||||||
void setFilesize(size_t size) { m_filesize = size; }
|
void setFilesize(size_t size) { m_filesize = size; }
|
||||||
|
|
||||||
static void parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data);
|
static void parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data);
|
||||||
static CString getDragFileExtension(CString fileName);
|
static CString getDragFileExtension(CString filename);
|
||||||
// helper function to setuo drag info
|
// helper function to setup drag info
|
||||||
// example: filename1,filesize1,filename2,filesize2,
|
// example: filename1,filesize1,filename2,filesize2,
|
||||||
// return file count
|
// return file count
|
||||||
static int setupDragInfo(CDragFileList& fileList, CString& output);
|
static int setupDragInfo(CDragFileList& fileList, CString& output);
|
||||||
|
|
||||||
|
static bool isFileValid(CString filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static size_t stringToNum(CString& str);
|
static size_t stringToNum(CString& str);
|
||||||
static CString getFileSize(CString& filename);
|
static CString getFileSize(CString& filename);
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2014 Bolton Software 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 COPYING that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "synergy/DropHelper.h"
|
||||||
|
|
||||||
|
#include "base/Log.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
void
|
||||||
|
CDropHelper::writeToDir(const CString& destination, CDragFileList& fileList, CString& data)
|
||||||
|
{
|
||||||
|
LOG((CLOG_DEBUG "dropping file, files=%i target=%s", fileList.size(), destination.c_str()));
|
||||||
|
|
||||||
|
if (!destination.empty() && fileList.size() > 0) {
|
||||||
|
std::fstream file;
|
||||||
|
CString dropTarget = destination;
|
||||||
|
#ifdef SYSAPI_WIN32
|
||||||
|
dropTarget.append("\\");
|
||||||
|
#else
|
||||||
|
dropTarget.append("/");
|
||||||
|
#endif
|
||||||
|
dropTarget.append(fileList.at(0).getFilename());
|
||||||
|
file.open(dropTarget.c_str(), std::ios::out | std::ios::binary);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
LOG((CLOG_DEBUG "drop file failed: can not open %s", dropTarget.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(data.c_str(), data.size());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
fileList.clear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2014 Bolton Software 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 COPYING that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "synergy/DragInformation.h"
|
||||||
|
#include "base/String.h"
|
||||||
|
|
||||||
|
class CDropHelper {
|
||||||
|
public:
|
||||||
|
static void writeToDir(const CString& destination,
|
||||||
|
CDragFileList& fileList, CString& data);
|
||||||
|
};
|
Loading…
Reference in New Issue