diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-05-02 12:32:03 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-07-01 10:48:21 +0200 |
commit | 66f1db543b425f6fe64d437477e6f78924ec57be (patch) | |
tree | 196c5e5fd095f6690da363d05be306ec877c13b0 /unix/xserver | |
parent | 546b2ad80a68e80a737aade06f0685cccb5e9716 (diff) | |
download | tigervnc-66f1db543b425f6fe64d437477e6f78924ec57be.tar.gz tigervnc-66f1db543b425f6fe64d437477e6f78924ec57be.zip |
Clean up internal clipboard handling
We now filter incoming data, which means we can start assuming the
clipboard data is always null terminated. This allows us to clean
up a lot of the internal handling.
Diffstat (limited to 'unix/xserver')
-rw-r--r-- | unix/xserver/hw/vnc/XserverDesktop.cc | 8 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/XserverDesktop.h | 4 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncExtInit.cc | 4 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncExtInit.h | 2 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncSelection.c | 21 | ||||
-rw-r--r-- | unix/xserver/hw/vnc/vncSelection.h | 4 |
6 files changed, 18 insertions, 25 deletions
diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index d8b3a4d4..cd9b1f9b 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -192,10 +192,10 @@ void XserverDesktop::setLEDState(unsigned int state) server->setLEDState(state); } -void XserverDesktop::serverCutText(const char* str, int len) +void XserverDesktop::serverCutText(const char* str) { try { - server->serverCutText(str, len); + server->serverCutText(str); } catch (rdr::Exception& e) { vlog.error("XserverDesktop::serverCutText: %s",e.str()); } @@ -436,9 +436,9 @@ void XserverDesktop::pointerEvent(const Point& pos, int buttonMask) vncPointerButtonAction(buttonMask); } -void XserverDesktop::clientCutText(const char* str, int len) +void XserverDesktop::clientCutText(const char* str) { - vncClientCutText(str, len); + vncClientCutText(str); } unsigned int XserverDesktop::setScreenLayout(int fb_width, int fb_height, diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index 1253935f..c6c4eb10 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -61,7 +61,7 @@ public: void refreshScreenLayout(); void bell(); void setLEDState(unsigned int state); - void serverCutText(const char* str, int len); + void serverCutText(const char* str); void setDesktopName(const char* name); void setCursor(int width, int height, int hotX, int hotY, const unsigned char *rgbaData); @@ -92,7 +92,7 @@ public: const char* userName); virtual void pointerEvent(const rfb::Point& pos, int buttonMask); virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down); - virtual void clientCutText(const char* str, int len); + virtual void clientCutText(const char* str); virtual unsigned int setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout); diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 20072f48..10143f6f 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -285,10 +285,10 @@ void vncUpdateDesktopName(void) desktop[scr]->setDesktopName(desktopName); } -void vncServerCutText(const char *text, size_t len) +void vncServerCutText(const char *text) { for (int scr = 0; scr < vncGetScreenCount(); scr++) - desktop[scr]->serverCutText(text, len); + desktop[scr]->serverCutText(text); } int vncConnectClient(const char *addr) diff --git a/unix/xserver/hw/vnc/vncExtInit.h b/unix/xserver/hw/vnc/vncExtInit.h index 5f97f96d..bdcce83a 100644 --- a/unix/xserver/hw/vnc/vncExtInit.h +++ b/unix/xserver/hw/vnc/vncExtInit.h @@ -53,7 +53,7 @@ int vncGetSendPrimary(void); void vncUpdateDesktopName(void); -void vncServerCutText(const char *text, size_t len); +void vncServerCutText(const char *text); int vncConnectClient(const char *addr); diff --git a/unix/xserver/hw/vnc/vncSelection.c b/unix/xserver/hw/vnc/vncSelection.c index 5ddcaf00..8f4146d9 100644 --- a/unix/xserver/hw/vnc/vncSelection.c +++ b/unix/xserver/hw/vnc/vncSelection.c @@ -48,7 +48,6 @@ static WindowPtr pWindow; static Window wid; static char* clientCutText; -static int clientCutTextLen; static int vncCreateSelectionWindow(void); static int vncOwnSelection(Atom selection); @@ -82,23 +81,20 @@ void vncSelectionInit(void) FatalError("Add VNC SelectionCallback failed\n"); } -void vncClientCutText(const char* str, int len) +void vncClientCutText(const char* str) { int rc; if (clientCutText != NULL) free(clientCutText); - clientCutText = malloc(len); + clientCutText = strdup(str); if (clientCutText == NULL) { LOG_ERROR("Could not allocate clipboard buffer"); DeleteWindowFromAnySelections(pWindow); return; } - memcpy(clientCutText, str, len); - clientCutTextLen = len; - if (vncGetSetPrimary()) { rc = vncOwnSelection(xaPRIMARY); if (rc != Success) @@ -246,7 +242,7 @@ static int vncConvertSelection(ClientPtr client, Atom selection, } else if ((target == xaSTRING) || (target == xaTEXT)) { rc = dixChangeWindowProperty(serverClient, pWin, realProperty, XA_STRING, 8, PropModeReplace, - clientCutTextLen, clientCutText, + strlen(clientCutText), clientCutText, TRUE); if (rc != Success) return rc; @@ -258,25 +254,22 @@ static int vncConvertSelection(ClientPtr client, Atom selection, const unsigned char* in; size_t in_len; - buffer = malloc(clientCutTextLen*2); + buffer = malloc(strlen(clientCutText)*2); if (buffer == NULL) return BadAlloc; out = buffer; len = 0; in = clientCutText; - in_len = clientCutTextLen; - while (in_len > 0) { + while (*in != '\0') { if (*in & 0x80) { *out++ = 0xc0 | (*in >> 6); *out++ = 0x80 | (*in & 0x3f); len += 2; in++; - in_len--; } else { *out++ = *in++; len++; - in_len--; } } @@ -426,7 +419,7 @@ static void vncHandleSelection(Atom selection, Atom target, if (filtered == NULL) return; - vncServerCutText(filtered, strlen(filtered)); + vncServerCutText(filtered); vncStrFree(filtered); } else if (target == xaUTF8_STRING) { @@ -484,7 +477,7 @@ static void vncHandleSelection(Atom selection, Atom target, if (filtered == NULL) return; - vncServerCutText(filtered, strlen(filtered)); + vncServerCutText(filtered); vncStrFree(filtered); } diff --git a/unix/xserver/hw/vnc/vncSelection.h b/unix/xserver/hw/vnc/vncSelection.h index 969f8958..e11d4a49 100644 --- a/unix/xserver/hw/vnc/vncSelection.h +++ b/unix/xserver/hw/vnc/vncSelection.h @@ -1,4 +1,4 @@ -/* Copyright 2016 Pierre Ossman for Cendio AB +/* Copyright 2016-2019 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ extern "C" { void vncSelectionInit(void); -void vncClientCutText(const char* str, int len); +void vncClientCutText(const char* str); #ifdef __cplusplus } |