From 3e9fc89d96a2758f8a9b0dbb15237ea0923744f9 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 20 May 2015 19:54:56 +0100 Subject: [PATCH] Modified server to use correct clipboard format #4601 --- src/lib/server/ClientProxy1_0.cpp | 54 ++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp index cb2f6307..a95fe2d9 100644 --- a/src/lib/server/ClientProxy1_0.cpp +++ b/src/lib/server/ClientProxy1_0.cpp @@ -452,31 +452,49 @@ bool ClientProxy1_0::recvClipboard() { // parse message + static String dataCached; + static size_t expectedSize; ClipboardID id; + UInt8 mark; UInt32 seqNum; String data; if (!ProtocolUtil::readf(getStream(), - kMsgDClipboard + 4, &id, &seqNum, &data)) { + kMsgDClipboard + 4, &id, &seqNum, &mark, &data)) { return false; } - LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, data.size())); - - // validate - if (id >= kClipboardEnd) { - return false; + + if (mark == kDataStart) { + expectedSize = synergy::string::stringToSizeType(data); + LOG((CLOG_DEBUG "start receiving clipboard data")); + dataCached.clear(); } - - // save clipboard - m_clipboard[id].m_clipboard.unmarshall(data, 0); - m_clipboard[id].m_sequenceNumber = seqNum; - - // notify - ClipboardInfo* info = new ClipboardInfo; - info->m_id = id; - info->m_sequenceNumber = seqNum; - m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(), - getEventTarget(), info)); - + else if (mark == kDataChunk) { + dataCached.append(data); + } + else if (mark == kDataEnd) { + LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, dataCached.size())); + + // validate + if (id >= kClipboardEnd) { + return false; + } + else if (expectedSize != dataCached.size()) { + LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", expectedSize, dataCached.size())); + return false; + } + + // save clipboard + m_clipboard[id].m_clipboard.unmarshall(dataCached, 0); + m_clipboard[id].m_sequenceNumber = seqNum; + + // notify + ClipboardInfo* info = new ClipboardInfo; + info->m_id = id; + info->m_sequenceNumber = seqNum; + m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(), + getEventTarget(), info)); + } + return true; }