Chromeclip (#69)
* Initial binary clipboard support * Rename -DLP_Clip_Types to -DLP_ClipTypes * Better handling of websocket frames * Copy-paste bug in SSE2 scaling to under 0.5x * Remove old text clipboard * Bind text to binary clipboard * Move binclip clear to probing phase * Off-by-one in sse2 scaling * Add a clarifying log message for INCR clipboard transfers * WIP: Update novnc commit * Fix CentOS pipeline * webpack fix * Update novnc commit * Change some DLP defaults * update novnc commit Co-authored-by: Lauri Kasanen <cand@gmx.com> Co-authored-by: matt <matt@kasmweb.com>
This commit is contained in:
@@ -284,74 +284,26 @@ void SConnection::setEncodings(int nEncodings, const rdr::S32* encodings)
|
||||
}
|
||||
|
||||
SMsgHandler::setEncodings(nEncodings, encodings);
|
||||
|
||||
if (cp.supportsExtendedClipboard) {
|
||||
rdr::U32 sizes[] = { 0 };
|
||||
writer()->writeClipboardCaps(rfb::clipboardUTF8 |
|
||||
rfb::clipboardRequest |
|
||||
rfb::clipboardPeek |
|
||||
rfb::clipboardNotify |
|
||||
rfb::clipboardProvide,
|
||||
sizes);
|
||||
}
|
||||
}
|
||||
|
||||
void SConnection::clientCutText(const char* str, int len)
|
||||
void SConnection::clearBinaryClipboard()
|
||||
{
|
||||
hasLocalClipboard = false;
|
||||
|
||||
strFree(clientClipboard);
|
||||
clientClipboard = NULL;
|
||||
|
||||
clientClipboard = latin1ToUTF8(str);
|
||||
|
||||
handleClipboardAnnounce(true);
|
||||
binaryClipboard.clear();
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardRequest(rdr::U32 flags)
|
||||
void SConnection::addBinaryClipboard(const char mime[], const rdr::U8 *data,
|
||||
const rdr::U32 len)
|
||||
{
|
||||
if (!(flags & rfb::clipboardUTF8))
|
||||
return;
|
||||
if (!hasLocalClipboard)
|
||||
return;
|
||||
handleClipboardRequest();
|
||||
binaryClipboard_t bin;
|
||||
strncpy(bin.mime, mime, sizeof(bin.mime));
|
||||
bin.mime[sizeof(bin.mime) - 1] = '\0';
|
||||
|
||||
bin.data.resize(len);
|
||||
memcpy(&bin.data[0], data, len);
|
||||
|
||||
binaryClipboard.push_back(bin);
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardPeek(rdr::U32 flags)
|
||||
{
|
||||
if (!hasLocalClipboard)
|
||||
return;
|
||||
if (cp.clipboardFlags() & rfb::clipboardNotify)
|
||||
writer()->writeClipboardNotify(rfb::clipboardUTF8);
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardNotify(rdr::U32 flags)
|
||||
{
|
||||
strFree(clientClipboard);
|
||||
clientClipboard = NULL;
|
||||
|
||||
if (flags & rfb::clipboardUTF8) {
|
||||
handleClipboardAnnounce(true);
|
||||
hasLocalClipboard = false;
|
||||
} else {
|
||||
handleClipboardAnnounce(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardProvide(rdr::U32 flags,
|
||||
const size_t* lengths,
|
||||
const rdr::U8* const* data)
|
||||
{
|
||||
if (!(flags & rfb::clipboardUTF8))
|
||||
return;
|
||||
|
||||
strFree(clientClipboard);
|
||||
clientClipboard = NULL;
|
||||
|
||||
clientClipboard = convertLF((const char*)data[0], lengths[0]);
|
||||
|
||||
handleClipboardData(clientClipboard, strlen(clientClipboard));
|
||||
}
|
||||
|
||||
void SConnection::supportsQEMUKeyEvent()
|
||||
{
|
||||
@@ -445,56 +397,13 @@ void SConnection::enableContinuousUpdates(bool enable,
|
||||
{
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardRequest()
|
||||
{
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardAnnounce(bool available)
|
||||
{
|
||||
}
|
||||
|
||||
void SConnection::handleClipboardData(const char* data, int len)
|
||||
{
|
||||
}
|
||||
|
||||
void SConnection::requestClipboard()
|
||||
{
|
||||
if (clientClipboard != NULL) {
|
||||
handleClipboardData(clientClipboard, strlen(clientClipboard));
|
||||
return;
|
||||
}
|
||||
|
||||
if (cp.supportsExtendedClipboard &&
|
||||
(cp.clipboardFlags() & rfb::clipboardRequest))
|
||||
writer()->writeClipboardRequest(rfb::clipboardUTF8);
|
||||
}
|
||||
|
||||
void SConnection::announceClipboard(bool available)
|
||||
{
|
||||
hasLocalClipboard = available;
|
||||
|
||||
if (cp.supportsExtendedClipboard &&
|
||||
(cp.clipboardFlags() & rfb::clipboardNotify))
|
||||
writer()->writeClipboardNotify(available ? rfb::clipboardUTF8 : 0);
|
||||
else {
|
||||
if (available)
|
||||
handleClipboardRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void SConnection::sendClipboardData(const char* data, int len)
|
||||
{
|
||||
if (cp.supportsExtendedClipboard &&
|
||||
(cp.clipboardFlags() & rfb::clipboardProvide)) {
|
||||
CharArray filtered(convertCRLF(data));
|
||||
size_t sizes[1] = { strlen(filtered.buf) + 1 };
|
||||
const rdr::U8* data[1] = { (const rdr::U8*)filtered.buf };
|
||||
writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data);
|
||||
} else {
|
||||
CharArray latin1(utf8ToLatin1(data));
|
||||
|
||||
writer()->writeServerCutText(latin1.buf, strlen(latin1.buf));
|
||||
}
|
||||
}
|
||||
|
||||
void SConnection::writeFakeColourMap(void)
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <rdr/OutStream.h>
|
||||
#include <rfb/SMsgHandler.h>
|
||||
#include <rfb/SecurityServer.h>
|
||||
#include <vector>
|
||||
|
||||
namespace rfb {
|
||||
|
||||
@@ -73,14 +74,9 @@ namespace rfb {
|
||||
|
||||
virtual void setEncodings(int nEncodings, const rdr::S32* encodings);
|
||||
|
||||
virtual void clientCutText(const char* str, int len);
|
||||
|
||||
virtual void handleClipboardRequest(rdr::U32 flags);
|
||||
virtual void handleClipboardPeek(rdr::U32 flags);
|
||||
virtual void handleClipboardNotify(rdr::U32 flags);
|
||||
virtual void handleClipboardProvide(rdr::U32 flags,
|
||||
const size_t* lengths,
|
||||
const rdr::U8* const* data);
|
||||
virtual void clearBinaryClipboard();
|
||||
virtual void addBinaryClipboard(const char mime[], const rdr::U8 *data,
|
||||
const rdr::U32 len);
|
||||
|
||||
virtual void supportsQEMUKeyEvent();
|
||||
|
||||
@@ -127,25 +123,11 @@ namespace rfb {
|
||||
virtual void enableContinuousUpdates(bool enable,
|
||||
int x, int y, int w, int h);
|
||||
|
||||
// handleClipboardRequest() is called whenever the client requests
|
||||
// the server to send over its clipboard data. It will only be
|
||||
// called after the server has first announced a clipboard change
|
||||
// via announceClipboard().
|
||||
virtual void handleClipboardRequest();
|
||||
|
||||
// handleClipboardAnnounce() is called to indicate a change in the
|
||||
// clipboard on the client. Call requestClipboard() to access the
|
||||
// actual data.
|
||||
virtual void handleClipboardAnnounce(bool available);
|
||||
|
||||
// handleClipboardData() is called when the client has sent over
|
||||
// the clipboard data as a result of a previous call to
|
||||
// requestClipboard(). Note that this function might never be
|
||||
// called if the clipboard data was no longer available when the
|
||||
// client received the request.
|
||||
virtual void handleClipboardData(const char* data, int len);
|
||||
|
||||
|
||||
virtual void add_changed_all() {}
|
||||
|
||||
// setAccessRights() allows a security package to limit the access rights
|
||||
@@ -166,22 +148,11 @@ namespace rfb {
|
||||
|
||||
// Other methods
|
||||
|
||||
// requestClipboard() will result in a request to the client to
|
||||
// transfer its clipboard data. A call to handleClipboardData()
|
||||
// will be made once the data is available.
|
||||
virtual void requestClipboard();
|
||||
|
||||
// announceClipboard() informs the client of changes to the
|
||||
// clipboard on the server. The client may later request the
|
||||
// clipboard data via handleClipboardRequest().
|
||||
virtual void announceClipboard(bool available);
|
||||
|
||||
// sendClipboardData() transfers the clipboard data to the client
|
||||
// and should be called whenever the client has requested the
|
||||
// clipboard via handleClipboardRequest().
|
||||
virtual void sendClipboardData(const char* data, int len);
|
||||
|
||||
|
||||
// authenticated() returns true if the client has authenticated
|
||||
// successfully.
|
||||
bool authenticated() { return (state_ == RFBSTATE_INITIALISATION ||
|
||||
@@ -221,12 +192,19 @@ namespace rfb {
|
||||
|
||||
rdr::S32 getPreferredEncoding() { return preferredEncoding; }
|
||||
|
||||
struct binaryClipboard_t {
|
||||
char mime[32];
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
protected:
|
||||
void setState(stateEnum s) { state_ = s; }
|
||||
|
||||
void setReader(SMsgReader *r) { reader_ = r; }
|
||||
void setWriter(SMsgWriter *w) { writer_ = w; }
|
||||
|
||||
std::vector<binaryClipboard_t> binaryClipboard;
|
||||
|
||||
private:
|
||||
void writeFakeColourMap(void);
|
||||
|
||||
|
||||
@@ -78,23 +78,13 @@ namespace rfb {
|
||||
// the relevant RFB protocol messages from clients.
|
||||
// See InputHandler for method signatures.
|
||||
|
||||
// handleClipboardRequest() is called whenever a client requests
|
||||
// the server to send over its clipboard data. It will only be
|
||||
// called after the server has first announced a clipboard change
|
||||
// via VNCServer::announceClipboard().
|
||||
virtual void handleClipboardRequest() {}
|
||||
|
||||
// handleClipboardAnnounce() is called to indicate a change in the
|
||||
// clipboard on a client. Call VNCServer::requestClipboard() to
|
||||
// access the actual data.
|
||||
virtual void handleClipboardAnnounce(bool __unused_attr available) {}
|
||||
|
||||
// handleClipboardData() is called when a client has sent over
|
||||
// the clipboard data as a result of a previous call to
|
||||
// VNCServer::requestClipboard(). Note that this function might
|
||||
// never be called if the clipboard data was no longer available
|
||||
// when the client received the request.
|
||||
virtual void handleClipboardData(const char* __unused_attr data, int len __unused_attr) {}
|
||||
virtual void handleClipboardAnnounceBinary(const unsigned __unused_attr num,
|
||||
const char __unused_attr mimes[][32]) {}
|
||||
|
||||
protected:
|
||||
virtual ~SDesktop() {}
|
||||
|
||||
@@ -64,26 +64,16 @@ void SMsgHandler::setEncodings(int nEncodings, const rdr::S32* encodings)
|
||||
supportsQEMUKeyEvent();
|
||||
}
|
||||
|
||||
void SMsgHandler::handleClipboardCaps(rdr::U32 flags, const rdr::U32* lengths)
|
||||
{
|
||||
cp.setClipboardCaps(flags, lengths);
|
||||
}
|
||||
|
||||
void SMsgHandler::handleClipboardRequest(rdr::U32 flags)
|
||||
void SMsgHandler::handleClipboardAnnounceBinary(const unsigned, const char mimes[][32])
|
||||
{
|
||||
}
|
||||
|
||||
void SMsgHandler::handleClipboardPeek(rdr::U32 flags)
|
||||
void SMsgHandler::clearBinaryClipboard()
|
||||
{
|
||||
}
|
||||
|
||||
void SMsgHandler::handleClipboardNotify(rdr::U32 flags)
|
||||
{
|
||||
}
|
||||
|
||||
void SMsgHandler::handleClipboardProvide(rdr::U32 flags,
|
||||
const size_t* lengths,
|
||||
const rdr::U8* const* data)
|
||||
void SMsgHandler::addBinaryClipboard(const char mime[], const rdr::U8 *data,
|
||||
const rdr::U32 len)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -54,14 +54,10 @@ namespace rfb {
|
||||
virtual void enableContinuousUpdates(bool enable,
|
||||
int x, int y, int w, int h) = 0;
|
||||
|
||||
virtual void handleClipboardCaps(rdr::U32 flags,
|
||||
const rdr::U32* lengths);
|
||||
virtual void handleClipboardRequest(rdr::U32 flags);
|
||||
virtual void handleClipboardPeek(rdr::U32 flags);
|
||||
virtual void handleClipboardNotify(rdr::U32 flags);
|
||||
virtual void handleClipboardProvide(rdr::U32 flags,
|
||||
const size_t* lengths,
|
||||
const rdr::U8* const* data);
|
||||
virtual void handleClipboardAnnounceBinary(const unsigned num, const char mimes[][32]);
|
||||
virtual void clearBinaryClipboard();
|
||||
virtual void addBinaryClipboard(const char mime[], const rdr::U8 *data,
|
||||
const rdr::U32 len);
|
||||
|
||||
virtual void sendStats(const bool toClient = true) = 0;
|
||||
virtual void handleFrameStats(rdr::U32 all, rdr::U32 render) = 0;
|
||||
|
||||
@@ -35,8 +35,6 @@ using namespace rfb;
|
||||
|
||||
static LogWriter vlog("SMsgReader");
|
||||
|
||||
static IntParameter maxCutText("MaxCutText", "Maximum permitted length of an incoming clipboard update", 256*1024);
|
||||
|
||||
SMsgReader::SMsgReader(SMsgHandler* handler_, rdr::InStream* is_)
|
||||
: handler(handler_), is(is_)
|
||||
{
|
||||
@@ -83,6 +81,9 @@ void SMsgReader::readMsg()
|
||||
case msgTypeFrameStats:
|
||||
readFrameStats();
|
||||
break;
|
||||
case msgTypeBinaryClipboard:
|
||||
readBinaryClipboard();
|
||||
break;
|
||||
case msgTypeKeyEvent:
|
||||
readKeyEvent();
|
||||
break;
|
||||
@@ -240,109 +241,54 @@ void SMsgReader::readClientCutText()
|
||||
readExtendedClipboard(slen);
|
||||
return;
|
||||
}
|
||||
if (len > (size_t)maxCutText) {
|
||||
is->skip(len);
|
||||
vlog.error("Cut text too long (%d bytes) - ignoring", len);
|
||||
return;
|
||||
is->skip(len);
|
||||
vlog.error("Client sent old cuttext msg, ignoring");
|
||||
}
|
||||
|
||||
void SMsgReader::readBinaryClipboard()
|
||||
{
|
||||
const rdr::U8 num = is->readU8();
|
||||
rdr::U8 i, valid = 0;
|
||||
char tmpmimes[num][32];
|
||||
|
||||
handler->clearBinaryClipboard();
|
||||
for (i = 0; i < num; i++) {
|
||||
const rdr::U8 mimelen = is->readU8();
|
||||
if (mimelen > 32 - 1) {
|
||||
vlog.error("Mime too long (%u)", mimelen);
|
||||
}
|
||||
|
||||
char mime[mimelen + 1];
|
||||
mime[mimelen] = '\0';
|
||||
is->readBytes(mime, mimelen);
|
||||
|
||||
strncpy(tmpmimes[valid], mime, 32);
|
||||
tmpmimes[valid][31] = '\0';
|
||||
|
||||
const rdr::U32 len = is->readU32();
|
||||
CharArray ca(len);
|
||||
is->readBytes(ca.buf, len);
|
||||
|
||||
if (rfb::Server::DLP_ClipAcceptMax && len > (unsigned) rfb::Server::DLP_ClipAcceptMax) {
|
||||
vlog.info("DLP: refused to receive binary clipboard, too large");
|
||||
continue;
|
||||
}
|
||||
|
||||
vlog.debug("Received binary clipboard, type %s, %u bytes", mime, len);
|
||||
|
||||
handler->addBinaryClipboard(mime, (rdr::U8 *) ca.buf, len);
|
||||
valid++;
|
||||
}
|
||||
CharArray ca(len+1);
|
||||
ca.buf[len] = 0;
|
||||
is->readBytes(ca.buf, len);
|
||||
handler->clientCutText(ca.buf, len);
|
||||
|
||||
handler->handleClipboardAnnounceBinary(valid, tmpmimes);
|
||||
}
|
||||
|
||||
void SMsgReader::readExtendedClipboard(rdr::S32 len)
|
||||
{
|
||||
rdr::U32 flags;
|
||||
rdr::U32 action;
|
||||
|
||||
if (len < 4)
|
||||
throw Exception("Invalid extended clipboard message");
|
||||
if (len > maxCutText) {
|
||||
vlog.error("Extended clipboard message too long (%d bytes) - ignoring", len);
|
||||
is->skip(len);
|
||||
return;
|
||||
}
|
||||
|
||||
flags = is->readU32();
|
||||
action = flags & clipboardActionMask;
|
||||
|
||||
if (action & clipboardCaps) {
|
||||
int i;
|
||||
size_t num;
|
||||
rdr::U32 lengths[16];
|
||||
|
||||
num = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (flags & (1 << i))
|
||||
num++;
|
||||
}
|
||||
|
||||
if (len < (rdr::S32)(4 + 4*num))
|
||||
throw Exception("Invalid extended clipboard message");
|
||||
|
||||
num = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (flags & (1 << i))
|
||||
lengths[num++] = is->readU32();
|
||||
}
|
||||
|
||||
handler->handleClipboardCaps(flags, lengths);
|
||||
} else if (action == clipboardProvide) {
|
||||
rdr::ZlibInStream zis;
|
||||
|
||||
int i;
|
||||
size_t num;
|
||||
size_t lengths[16];
|
||||
rdr::U8* buffers[16];
|
||||
|
||||
zis.setUnderlying(is, len - 4);
|
||||
|
||||
num = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (!(flags & 1 << i))
|
||||
continue;
|
||||
|
||||
lengths[num] = zis.readU32();
|
||||
if (lengths[num] > (size_t)maxCutText) {
|
||||
vlog.error("Extended clipboard data too long (%d bytes) - ignoring",
|
||||
(unsigned)lengths[num]);
|
||||
zis.skip(lengths[num]);
|
||||
flags &= ~(1 << i);
|
||||
continue;
|
||||
}
|
||||
|
||||
buffers[num] = new rdr::U8[lengths[num]];
|
||||
zis.readBytes(buffers[num], lengths[num]);
|
||||
num++;
|
||||
}
|
||||
|
||||
zis.flushUnderlying();
|
||||
zis.setUnderlying(NULL, 0);
|
||||
|
||||
handler->handleClipboardProvide(flags, lengths, buffers);
|
||||
|
||||
num = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (!(flags & 1 << i))
|
||||
continue;
|
||||
delete [] buffers[num++];
|
||||
}
|
||||
} else {
|
||||
switch (action) {
|
||||
case clipboardRequest:
|
||||
handler->handleClipboardRequest(flags);
|
||||
break;
|
||||
case clipboardPeek:
|
||||
handler->handleClipboardPeek(flags);
|
||||
break;
|
||||
case clipboardNotify:
|
||||
handler->handleClipboardNotify(flags);
|
||||
break;
|
||||
default:
|
||||
throw Exception("Invalid extended clipboard action");
|
||||
}
|
||||
}
|
||||
vlog.error("Client sent old cuttext msg, ignoring");
|
||||
is->skip(len);
|
||||
}
|
||||
|
||||
void SMsgReader::readRequestStats()
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace rfb {
|
||||
void readExtendedClipboard(rdr::S32 len);
|
||||
void readRequestStats();
|
||||
void readFrameStats();
|
||||
void readBinaryClipboard();
|
||||
|
||||
void readQEMUMessage();
|
||||
void readQEMUKeyEvent();
|
||||
|
||||
@@ -85,118 +85,21 @@ void SMsgWriter::writeBell()
|
||||
endMsg();
|
||||
}
|
||||
|
||||
void SMsgWriter::writeServerCutText(const char* str, int len)
|
||||
void SMsgWriter::writeBinaryClipboard(const std::vector<SConnection::binaryClipboard_t> &b)
|
||||
{
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeU32(len);
|
||||
os->writeBytes(str, len);
|
||||
endMsg();
|
||||
}
|
||||
startMsg(msgTypeBinaryClipboard);
|
||||
|
||||
void SMsgWriter::writeClipboardCaps(rdr::U32 caps,
|
||||
const rdr::U32* lengths)
|
||||
{
|
||||
size_t i, count;
|
||||
os->writeU8(b.size());
|
||||
rdr::U8 i;
|
||||
for (i = 0; i < b.size(); i++) {
|
||||
const rdr::U8 mimelen = strlen(b[i].mime);
|
||||
os->writeU8(mimelen);
|
||||
os->writeBytes(b[i].mime, mimelen);
|
||||
|
||||
if (!cp->supportsExtendedClipboard)
|
||||
throw Exception("Client does not support extended clipboard");
|
||||
|
||||
count = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (caps & (1 << i))
|
||||
count++;
|
||||
os->writeU32(b[i].data.size());
|
||||
os->writeBytes(&b[i].data[0], b[i].data.size());
|
||||
}
|
||||
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeS32(-(4 + 4 * count));
|
||||
|
||||
os->writeU32(caps | clipboardCaps);
|
||||
|
||||
count = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (caps & (1 << i))
|
||||
os->writeU32(lengths[count++]);
|
||||
}
|
||||
|
||||
endMsg();
|
||||
}
|
||||
|
||||
void SMsgWriter::writeClipboardRequest(rdr::U32 flags)
|
||||
{
|
||||
if (!cp->supportsExtendedClipboard)
|
||||
throw Exception("Client does not support extended clipboard");
|
||||
if (!(cp->clipboardFlags() & clipboardRequest))
|
||||
throw Exception("Client does not support clipboard \"request\" action");
|
||||
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeS32(-4);
|
||||
os->writeU32(flags | clipboardRequest);
|
||||
endMsg();
|
||||
}
|
||||
|
||||
void SMsgWriter::writeClipboardPeek(rdr::U32 flags)
|
||||
{
|
||||
if (!cp->supportsExtendedClipboard)
|
||||
throw Exception("Client does not support extended clipboard");
|
||||
if (!(cp->clipboardFlags() & clipboardPeek))
|
||||
throw Exception("Client does not support clipboard \"peek\" action");
|
||||
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeS32(-4);
|
||||
os->writeU32(flags | clipboardPeek);
|
||||
endMsg();
|
||||
}
|
||||
|
||||
void SMsgWriter::writeClipboardNotify(rdr::U32 flags)
|
||||
{
|
||||
if (!cp->supportsExtendedClipboard)
|
||||
throw Exception("Client does not support extended clipboard");
|
||||
if (!(cp->clipboardFlags() & clipboardNotify))
|
||||
throw Exception("Client does not support clipboard \"notify\" action");
|
||||
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeS32(-4);
|
||||
os->writeU32(flags | clipboardNotify);
|
||||
endMsg();
|
||||
}
|
||||
|
||||
void SMsgWriter::writeClipboardProvide(rdr::U32 flags,
|
||||
const size_t* lengths,
|
||||
const rdr::U8* const* data)
|
||||
{
|
||||
rdr::MemOutStream mos;
|
||||
rdr::ZlibOutStream zos;
|
||||
|
||||
int i, count;
|
||||
|
||||
if (!cp->supportsExtendedClipboard)
|
||||
throw Exception("Client does not support extended clipboard");
|
||||
if (!(cp->clipboardFlags() & clipboardProvide))
|
||||
throw Exception("Client does not support clipboard \"provide\" action");
|
||||
|
||||
zos.setUnderlying(&mos);
|
||||
|
||||
count = 0;
|
||||
for (i = 0;i < 16;i++) {
|
||||
if (!(flags & (1 << i)))
|
||||
continue;
|
||||
zos.writeU32(lengths[count]);
|
||||
zos.writeBytes(data[count], lengths[count]);
|
||||
count++;
|
||||
}
|
||||
|
||||
zos.flush();
|
||||
|
||||
startMsg(msgTypeServerCutText);
|
||||
os->pad(3);
|
||||
os->writeS32(-(4 + mos.length()));
|
||||
os->writeU32(flags | clipboardProvide);
|
||||
os->writeBytes(mos.data(), mos.length());
|
||||
endMsg();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <rdr/types.h>
|
||||
#include <rfb/encodings.h>
|
||||
#include <rfb/ScreenSet.h>
|
||||
#include <rfb/SConnection.h>
|
||||
#include <vector>
|
||||
|
||||
namespace rdr { class OutStream; }
|
||||
|
||||
@@ -54,14 +56,8 @@ namespace rfb {
|
||||
|
||||
// writeBell() and writeServerCutText() do the obvious thing.
|
||||
void writeBell();
|
||||
void writeServerCutText(const char* str, int len);
|
||||
|
||||
void writeClipboardCaps(rdr::U32 caps, const rdr::U32* lengths);
|
||||
void writeClipboardRequest(rdr::U32 flags);
|
||||
void writeClipboardPeek(rdr::U32 flags);
|
||||
void writeClipboardNotify(rdr::U32 flags);
|
||||
void writeClipboardProvide(rdr::U32 flags, const size_t* lengths,
|
||||
const rdr::U8* const* data);
|
||||
void writeBinaryClipboard(const std::vector<SConnection::binaryClipboard_t> &b);
|
||||
|
||||
void writeStats(const char* str, int len);
|
||||
|
||||
|
||||
@@ -149,15 +149,15 @@ rfb::IntParameter rfb::Server::webpVideoQuality
|
||||
rfb::IntParameter rfb::Server::DLP_ClipSendMax
|
||||
("DLP_ClipSendMax",
|
||||
"Limit clipboard bytes to send to clients in one transaction",
|
||||
10000, 0, INT_MAX);
|
||||
0, 0, INT_MAX);
|
||||
rfb::IntParameter rfb::Server::DLP_ClipAcceptMax
|
||||
("DLP_ClipAcceptMax",
|
||||
"Limit clipboard bytes to receive from clients in one transaction",
|
||||
10000, 0, INT_MAX);
|
||||
0, 0, INT_MAX);
|
||||
rfb::IntParameter rfb::Server::DLP_ClipDelay
|
||||
("DLP_ClipDelay",
|
||||
"This many milliseconds must pass between clipboard actions",
|
||||
1000, 0, INT_MAX);
|
||||
0, 0, INT_MAX);
|
||||
rfb::IntParameter rfb::Server::DLP_KeyRateLimit
|
||||
("DLP_KeyRateLimit",
|
||||
"Reject keyboard presses over this many per second",
|
||||
@@ -171,6 +171,10 @@ rfb::StringParameter rfb::Server::DLP_Region
|
||||
("DLP_Region",
|
||||
"Black out anything outside this region",
|
||||
"");
|
||||
rfb::StringParameter rfb::Server::DLP_Clip_Types
|
||||
("DLP_ClipTypes",
|
||||
"Allowed binary clipboard mimetypes",
|
||||
"text/html,image/png");
|
||||
|
||||
rfb::BoolParameter rfb::Server::DLP_RegionAllowClick
|
||||
("DLP_RegionAllowClick",
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace rfb {
|
||||
static IntParameter DLP_KeyRateLimit;
|
||||
static StringParameter DLP_ClipLog;
|
||||
static StringParameter DLP_Region;
|
||||
static StringParameter DLP_Clip_Types;
|
||||
static BoolParameter DLP_RegionAllowClick;
|
||||
static BoolParameter DLP_RegionAllowRelease;
|
||||
static IntParameter jpegVideoQuality;
|
||||
|
||||
@@ -57,7 +57,8 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,
|
||||
inProcessMessages(false),
|
||||
pendingSyncFence(false), syncFence(false), fenceFlags(0),
|
||||
fenceDataLen(0), fenceData(NULL), congestionTimer(this),
|
||||
losslessTimer(this), kbdLogTimer(this), server(server_), updates(false),
|
||||
losslessTimer(this), kbdLogTimer(this), binclipTimer(this),
|
||||
server(server_), updates(false),
|
||||
updateRenderedCursor(false), removeRenderedCursor(false),
|
||||
continuousUpdates(false), encodeManager(this, &server_->encCache),
|
||||
needsPermCheck(false), pointerEventTime(0),
|
||||
@@ -413,18 +414,6 @@ static void keylog(unsigned keysym, const char *client) {
|
||||
flushKeylog(client);
|
||||
}
|
||||
|
||||
void VNCSConnectionST::requestClipboardOrClose()
|
||||
{
|
||||
try {
|
||||
if (!(accessRights & AccessCutText)) return;
|
||||
if (!rfb::Server::acceptCutText) return;
|
||||
if (state() != RFBSTATE_NORMAL) return;
|
||||
requestClipboard();
|
||||
} catch(rdr::Exception& e) {
|
||||
close(e.str());
|
||||
}
|
||||
}
|
||||
|
||||
void VNCSConnectionST::announceClipboardOrClose(bool available)
|
||||
{
|
||||
try {
|
||||
@@ -437,29 +426,51 @@ void VNCSConnectionST::announceClipboardOrClose(bool available)
|
||||
}
|
||||
}
|
||||
|
||||
void VNCSConnectionST::sendClipboardDataOrClose(const char* data)
|
||||
void VNCSConnectionST::clearBinaryClipboardData()
|
||||
{
|
||||
clearBinaryClipboard();
|
||||
}
|
||||
|
||||
void VNCSConnectionST::sendBinaryClipboardDataOrClose(const char* mime,
|
||||
const unsigned char *data,
|
||||
const unsigned len)
|
||||
{
|
||||
try {
|
||||
if (!(accessRights & AccessCutText)) return;
|
||||
if (!rfb::Server::sendCutText) return;
|
||||
if (msSince(&lastClipboardOp) < (unsigned) rfb::Server::DLP_ClipDelay) {
|
||||
vlog.info("DLP: client %s: refused to send clipboard, too soon",
|
||||
if (rfb::Server::DLP_ClipSendMax && len > (unsigned) rfb::Server::DLP_ClipSendMax) {
|
||||
vlog.info("DLP: client %s: refused to send binary clipboard, too large",
|
||||
sock->getPeerAddress());
|
||||
return;
|
||||
}
|
||||
int len = strlen(data);
|
||||
const int origlen = len;
|
||||
if (rfb::Server::DLP_ClipSendMax && len > rfb::Server::DLP_ClipSendMax)
|
||||
len = rfb::Server::DLP_ClipSendMax;
|
||||
cliplog(data, len, origlen, "sent", sock->getPeerAddress());
|
||||
|
||||
cliplog((const char *) data, len, len, "sent", sock->getPeerAddress());
|
||||
if (state() != RFBSTATE_NORMAL) return;
|
||||
sendClipboardData(data, len);
|
||||
gettimeofday(&lastClipboardOp, NULL);
|
||||
|
||||
addBinaryClipboard(mime, data, len);
|
||||
binclipTimer.start(100);
|
||||
} catch(rdr::Exception& e) {
|
||||
close(e.str());
|
||||
}
|
||||
}
|
||||
|
||||
void VNCSConnectionST::getBinaryClipboardData(const char* mime, const unsigned char **data,
|
||||
unsigned *len)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < binaryClipboard.size(); i++) {
|
||||
if (!strcmp(binaryClipboard[i].mime, mime)) {
|
||||
*data = &binaryClipboard[i].data[0];
|
||||
*len = binaryClipboard[i].data.size();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vlog.error("Binary clipboard data for mime %s not found", mime);
|
||||
*data = (const unsigned char *) "";
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
void VNCSConnectionST::setDesktopNameOrClose(const char *name)
|
||||
{
|
||||
try {
|
||||
@@ -1014,12 +1025,6 @@ void VNCSConnectionST::enableContinuousUpdates(bool enable,
|
||||
}
|
||||
}
|
||||
|
||||
void VNCSConnectionST::handleClipboardRequest()
|
||||
{
|
||||
if (!(accessRights & AccessCutText)) return;
|
||||
server->handleClipboardRequest(this);
|
||||
}
|
||||
|
||||
void VNCSConnectionST::handleClipboardAnnounce(bool available)
|
||||
{
|
||||
if (!(accessRights & AccessCutText)) return;
|
||||
@@ -1027,25 +1032,13 @@ void VNCSConnectionST::handleClipboardAnnounce(bool available)
|
||||
server->handleClipboardAnnounce(this, available);
|
||||
}
|
||||
|
||||
void VNCSConnectionST::handleClipboardData(const char* data, int len)
|
||||
void VNCSConnectionST::handleClipboardAnnounceBinary(const unsigned num, const char mimes[][32])
|
||||
{
|
||||
if (!(accessRights & AccessCutText)) return;
|
||||
if (!rfb::Server::acceptCutText) return;
|
||||
if (msSince(&lastClipboardOp) < (unsigned) rfb::Server::DLP_ClipDelay) {
|
||||
vlog.info("DLP: client %s: refused to receive clipboard, too soon",
|
||||
sock->getPeerAddress());
|
||||
return;
|
||||
}
|
||||
const int origlen = len;
|
||||
if (rfb::Server::DLP_ClipAcceptMax && len > rfb::Server::DLP_ClipAcceptMax)
|
||||
len = rfb::Server::DLP_ClipAcceptMax;
|
||||
cliplog(data, len, origlen, "received", sock->getPeerAddress());
|
||||
|
||||
gettimeofday(&lastClipboardOp, NULL);
|
||||
server->handleClipboardData(this, data, len);
|
||||
server->handleClipboardAnnounceBinary(this, num, mimes);
|
||||
}
|
||||
|
||||
|
||||
// supportsLocalCursor() is called whenever the status of
|
||||
// cp.supportsLocalCursor has changed. If the client does now support local
|
||||
// cursor, we make sure that the old server-side rendered cursor is cleaned up
|
||||
@@ -1089,6 +1082,8 @@ bool VNCSConnectionST::handleTimeout(Timer* t)
|
||||
writeFramebufferUpdate();
|
||||
else if (t == &kbdLogTimer)
|
||||
flushKeylog(sock->getPeerAddress());
|
||||
else if (t == &binclipTimer)
|
||||
writeBinaryClipboard();
|
||||
} catch (rdr::Exception& e) {
|
||||
close(e.str());
|
||||
}
|
||||
@@ -1446,6 +1441,18 @@ void VNCSConnectionST::writeDataUpdate()
|
||||
requested.clear();
|
||||
}
|
||||
|
||||
void VNCSConnectionST::writeBinaryClipboard()
|
||||
{
|
||||
if (msSince(&lastClipboardOp) < (unsigned) rfb::Server::DLP_ClipDelay) {
|
||||
vlog.info("DLP: client %s: refused to send binary clipboard, too soon",
|
||||
sock->getPeerAddress());
|
||||
return;
|
||||
}
|
||||
|
||||
writer()->writeBinaryClipboard(binaryClipboard);
|
||||
|
||||
gettimeofday(&lastClipboardOp, NULL);
|
||||
}
|
||||
|
||||
void VNCSConnectionST::screenLayoutChange(rdr::U16 reason)
|
||||
{
|
||||
|
||||
@@ -77,9 +77,12 @@ namespace rfb {
|
||||
void bellOrClose();
|
||||
void setDesktopNameOrClose(const char *name);
|
||||
void setLEDStateOrClose(unsigned int state);
|
||||
void requestClipboardOrClose();
|
||||
void announceClipboardOrClose(bool available);
|
||||
void sendClipboardDataOrClose(const char* data);
|
||||
void clearBinaryClipboardData();
|
||||
void sendBinaryClipboardDataOrClose(const char* mime, const unsigned char *data,
|
||||
const unsigned len);
|
||||
void getBinaryClipboardData(const char* mime, const unsigned char **data,
|
||||
unsigned *len);
|
||||
|
||||
// checkIdleTimeout() returns the number of milliseconds left until the
|
||||
// idle timeout expires. If it has expired, the connection is closed and
|
||||
@@ -212,9 +215,8 @@ namespace rfb {
|
||||
virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
|
||||
virtual void enableContinuousUpdates(bool enable,
|
||||
int x, int y, int w, int h);
|
||||
virtual void handleClipboardRequest();
|
||||
virtual void handleClipboardAnnounce(bool available);
|
||||
virtual void handleClipboardData(const char* data, int len);
|
||||
virtual void handleClipboardAnnounceBinary(const unsigned num, const char mimes[][32]);
|
||||
virtual void supportsLocalCursor();
|
||||
virtual void supportsFence();
|
||||
virtual void supportsContinuousUpdates();
|
||||
@@ -260,6 +262,8 @@ namespace rfb {
|
||||
void writeNoDataUpdate();
|
||||
void writeDataUpdate();
|
||||
|
||||
void writeBinaryClipboard();
|
||||
|
||||
void screenLayoutChange(rdr::U16 reason);
|
||||
void setCursor();
|
||||
void setCursorPos();
|
||||
@@ -282,6 +286,7 @@ namespace rfb {
|
||||
Timer congestionTimer;
|
||||
Timer losslessTimer;
|
||||
Timer kbdLogTimer;
|
||||
Timer binclipTimer;
|
||||
|
||||
VNCServerST* server;
|
||||
SimpleUpdateTracker updates;
|
||||
|
||||
@@ -52,22 +52,11 @@ namespace rfb {
|
||||
// getPixelBuffer() returns a pointer to the PixelBuffer object.
|
||||
virtual PixelBuffer* getPixelBuffer() const = 0;
|
||||
|
||||
// requestClipboard() will result in a request to a client to
|
||||
// transfer its clipboard data. A call to
|
||||
// SDesktop::handleClipboardData() will be made once the data is
|
||||
// available.
|
||||
virtual void requestClipboard() = 0;
|
||||
|
||||
// announceClipboard() informs all clients of changes to the
|
||||
// clipboard on the server. A client may later request the
|
||||
// clipboard data via SDesktop::handleClipboardRequest().
|
||||
virtual void announceClipboard(bool available) = 0;
|
||||
|
||||
// sendClipboardData() transfers the clipboard data to a client
|
||||
// and should be called whenever a client has requested the
|
||||
// clipboard via SDesktop::handleClipboardRequest().
|
||||
virtual void sendClipboardData(const char* data) = 0;
|
||||
|
||||
// bell() tells the server that it should make all clients make a bell sound.
|
||||
virtual void bell() = 0;
|
||||
|
||||
|
||||
@@ -518,14 +518,6 @@ void VNCServerST::setScreenLayout(const ScreenSet& layout)
|
||||
}
|
||||
}
|
||||
|
||||
void VNCServerST::requestClipboard()
|
||||
{
|
||||
if (clipboardClient == NULL)
|
||||
return;
|
||||
|
||||
clipboardClient->requestClipboard();
|
||||
}
|
||||
|
||||
void VNCServerST::announceClipboard(bool available)
|
||||
{
|
||||
std::list<VNCSConnectionST*>::iterator ci, ci_next;
|
||||
@@ -541,20 +533,31 @@ void VNCServerST::announceClipboard(bool available)
|
||||
}
|
||||
}
|
||||
|
||||
void VNCServerST::sendClipboardData(const char* data)
|
||||
void VNCServerST::sendBinaryClipboardData(const char* mime, const unsigned char *data,
|
||||
const unsigned len)
|
||||
{
|
||||
std::list<VNCSConnectionST*>::iterator ci, ci_next;
|
||||
|
||||
if (strchr(data, '\r') != NULL)
|
||||
throw Exception("Invalid carriage return in clipboard data");
|
||||
|
||||
for (ci = clipboardRequestors.begin();
|
||||
ci != clipboardRequestors.end(); ci = ci_next) {
|
||||
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
|
||||
ci_next = ci; ci_next++;
|
||||
(*ci)->sendClipboardDataOrClose(data);
|
||||
(*ci)->sendBinaryClipboardDataOrClose(mime, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
clipboardRequestors.clear();
|
||||
void VNCServerST::getBinaryClipboardData(const char* mime, const unsigned char **data,
|
||||
unsigned *len)
|
||||
{
|
||||
if (!clipboardClient)
|
||||
return;
|
||||
clipboardClient->getBinaryClipboardData(mime, data, len);
|
||||
}
|
||||
|
||||
void VNCServerST::clearBinaryClipboardData()
|
||||
{
|
||||
std::list<VNCSConnectionST*>::iterator ci, ci_next;
|
||||
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
|
||||
ci_next = ci; ci_next++;
|
||||
(*ci)->clearBinaryClipboardData();
|
||||
}
|
||||
}
|
||||
|
||||
void VNCServerST::bell()
|
||||
@@ -1198,13 +1201,6 @@ bool VNCServerST::getComparerState()
|
||||
return false;
|
||||
}
|
||||
|
||||
void VNCServerST::handleClipboardRequest(VNCSConnectionST* client)
|
||||
{
|
||||
clipboardRequestors.push_back(client);
|
||||
if (clipboardRequestors.size() == 1)
|
||||
desktop->handleClipboardRequest();
|
||||
}
|
||||
|
||||
void VNCServerST::handleClipboardAnnounce(VNCSConnectionST* client,
|
||||
bool available)
|
||||
{
|
||||
@@ -1218,11 +1214,10 @@ void VNCServerST::handleClipboardAnnounce(VNCSConnectionST* client,
|
||||
desktop->handleClipboardAnnounce(available);
|
||||
}
|
||||
|
||||
void VNCServerST::handleClipboardData(VNCSConnectionST* client,
|
||||
const char* data, int len)
|
||||
void VNCServerST::handleClipboardAnnounceBinary(VNCSConnectionST* client,
|
||||
const unsigned num,
|
||||
const char mimes[][32])
|
||||
{
|
||||
if (client != clipboardClient)
|
||||
return;
|
||||
desktop->handleClipboardData(data, len);
|
||||
clipboardClient = client;
|
||||
desktop->handleClipboardAnnounceBinary(num, mimes);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +96,12 @@ namespace rfb {
|
||||
virtual void setPixelBuffer(PixelBuffer* pb);
|
||||
virtual void setScreenLayout(const ScreenSet& layout);
|
||||
virtual PixelBuffer* getPixelBuffer() const { if (DLPRegion.enabled && blackedpb) return blackedpb; else return pb; }
|
||||
virtual void requestClipboard();
|
||||
virtual void announceClipboard(bool available);
|
||||
virtual void sendClipboardData(const char* data);
|
||||
virtual void clearBinaryClipboardData();
|
||||
virtual void sendBinaryClipboardData(const char* mime, const unsigned char *data,
|
||||
const unsigned len);
|
||||
virtual void getBinaryClipboardData(const char *mime, const unsigned char **ptr,
|
||||
unsigned *len);
|
||||
virtual void add_changed(const Region ®ion);
|
||||
virtual void add_copied(const Region &dest, const Point &delta);
|
||||
virtual void setCursor(int width, int height, const Point& hotspot,
|
||||
@@ -191,9 +194,9 @@ namespace rfb {
|
||||
|
||||
void setAPIMessager(network::GetAPIMessager *msgr) { apimessager = msgr; }
|
||||
|
||||
void handleClipboardRequest(VNCSConnectionST* client);
|
||||
void handleClipboardAnnounce(VNCSConnectionST* client, bool available);
|
||||
void handleClipboardData(VNCSConnectionST* client, const char* data, int len);
|
||||
void handleClipboardAnnounceBinary(VNCSConnectionST* client, const unsigned num,
|
||||
const char mimes[][32]);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace rfb {
|
||||
// kasm
|
||||
const int msgTypeStats = 178;
|
||||
const int msgTypeRequestFrameStats = 179;
|
||||
const int msgTypeBinaryClipboard = 180;
|
||||
|
||||
const int msgTypeServerFence = 248;
|
||||
|
||||
@@ -49,6 +50,7 @@ namespace rfb {
|
||||
// kasm
|
||||
const int msgTypeRequestStats = 178;
|
||||
const int msgTypeFrameStats = 179;
|
||||
//const int msgTypeBinaryClipboard = 180;
|
||||
|
||||
const int msgTypeClientFence = 248;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ void SSE2_halve(const uint8_t *oldpx,
|
||||
|
||||
uint8_t * const dst = newpx + newstride * (y / 2) * 4;
|
||||
|
||||
for (x = 0; x < srcw; x += 4) {
|
||||
for (x = 0; x < srcw - 3; x += 4) {
|
||||
__m128i lo, hi, a, b, c, d;
|
||||
lo = _mm_loadu_si128((__m128i *) &row0[x * 4]);
|
||||
hi = _mm_loadu_si128((__m128i *) &row1[x * 4]);
|
||||
@@ -141,7 +141,7 @@ void SSE2_scale(const uint8_t *oldpx,
|
||||
const __m128i vertmul = _mm_set1_epi16(top);
|
||||
const __m128i vertmul2 = _mm_set1_epi16(bot);
|
||||
|
||||
for (x = 0; x < tgtw; x += 2) {
|
||||
for (x = 0; x < tgtw - 1; x += 2) {
|
||||
const float nx[2] = {
|
||||
x * invdiff,
|
||||
(x + 1) * invdiff,
|
||||
|
||||
Reference in New Issue
Block a user