2013-07-16 19:02:30 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2013-2016 Symless Ltd.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
2013-07-16 19:02:30 +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
|
|
|
*
|
2013-07-16 19:02:30 +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 "server/ClientProxy1_5.h"
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "base/Log.h"
|
|
|
|
|
#include "base/TMethodEventJob.h"
|
|
|
|
|
#include "io/IStream.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "server/Server.h"
|
2015-05-22 18:27:57 +00:00
|
|
|
#include "synergy/FileChunk.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "synergy/ProtocolUtil.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "synergy/StreamChunker.h"
|
2013-07-16 19:02:30 +00:00
|
|
|
|
2015-05-15 21:26:57 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2013-07-16 19:02:30 +00:00
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// ClientProxy1_5
|
2013-07-16 19:02:30 +00:00
|
|
|
//
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
ClientProxy1_5::ClientProxy1_5(const String &name, synergy::IStream *stream,
|
|
|
|
|
Server *server, IEventQueue *events)
|
|
|
|
|
: ClientProxy1_4(name, stream, server, events), m_events(events) {
|
2015-12-08 20:27:55 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
m_events->adoptHandler(m_events->forFile().keepAlive(), this,
|
|
|
|
|
new TMethodEventJob<ClientProxy1_3>(
|
|
|
|
|
this, &ClientProxy1_3::handleKeepAlive, NULL));
|
2013-07-16 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
ClientProxy1_5::~ClientProxy1_5() {
|
|
|
|
|
m_events->removeHandler(m_events->forFile().keepAlive(), this);
|
2013-07-16 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void ClientProxy1_5::sendDragInfo(UInt32 fileCount, const char *info,
|
|
|
|
|
size_t size) {
|
|
|
|
|
String data(info, size);
|
2013-08-30 14:38:43 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
ProtocolUtil::writef(getStream(), kMsgDDragInfo, fileCount, &data);
|
2013-08-30 14:38:43 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void ClientProxy1_5::fileChunkSending(UInt8 mark, char *data, size_t dataSize) {
|
|
|
|
|
FileChunk::send(getStream(), mark, data, dataSize);
|
2013-07-16 19:02:30 +00:00
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
bool ClientProxy1_5::parseMessage(const UInt8 *code) {
|
|
|
|
|
if (memcmp(code, kMsgDFileTransfer, 4) == 0) {
|
|
|
|
|
fileChunkReceived();
|
|
|
|
|
} else if (memcmp(code, kMsgDDragInfo, 4) == 0) {
|
|
|
|
|
dragInfoReceived();
|
|
|
|
|
} else {
|
|
|
|
|
return ClientProxy1_4::parseMessage(code);
|
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return true;
|
2013-07-24 16:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void ClientProxy1_5::fileChunkReceived() {
|
|
|
|
|
Server *server = getServer();
|
|
|
|
|
int result = FileChunk::assemble(getStream(), server->getReceivedFileData(),
|
|
|
|
|
server->getExpectedFileSize());
|
|
|
|
|
|
|
|
|
|
if (result == kFinish) {
|
|
|
|
|
m_events->addEvent(
|
|
|
|
|
Event(m_events->forFile().fileRecieveCompleted(), server));
|
|
|
|
|
} else if (result == kStart) {
|
|
|
|
|
if (server->getFakeDragFileList().size() > 0) {
|
|
|
|
|
String filename = server->getFakeDragFileList().at(0).getFilename();
|
|
|
|
|
LOG((CLOG_DEBUG "start receiving %s", filename.c_str()));
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
}
|
2013-08-30 19:49:38 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void ClientProxy1_5::dragInfoReceived() {
|
|
|
|
|
// parse
|
|
|
|
|
UInt32 fileNum = 0;
|
|
|
|
|
String content;
|
|
|
|
|
ProtocolUtil::readf(getStream(), kMsgDDragInfo + 4, &fileNum, &content);
|
|
|
|
|
|
|
|
|
|
m_server->dragInfoReceived(fileNum, content);
|
2013-08-30 19:49:38 +00:00
|
|
|
}
|