diff --git a/common/network/GetAPI.h b/common/network/GetAPI.h index f02c75e..5b6c7ed 100644 --- a/common/network/GetAPI.h +++ b/common/network/GetAPI.h @@ -66,6 +66,7 @@ namespace network { void netResetFrameStatsCall(); uint8_t netServerFrameStatsReady(); void netUdpUpgrade(void *client, uint32_t ip); + void netClearClipboard(); enum USER_ACTION { NONE, @@ -73,7 +74,8 @@ namespace network { WANT_FRAME_STATS_ALL, WANT_FRAME_STATS_OWNER, WANT_FRAME_STATS_SPECIFIC, - UDP_UPGRADE + UDP_UPGRADE, + CLEAR_CLIPBOARD, }; uint8_t netRequestFrameStats(USER_ACTION what, const char *client); diff --git a/common/network/GetAPIMessager.cxx b/common/network/GetAPIMessager.cxx index 0fb2ee0..17e53cd 100644 --- a/common/network/GetAPIMessager.cxx +++ b/common/network/GetAPIMessager.cxx @@ -806,3 +806,16 @@ void GetAPIMessager::netUdpUpgrade(void *client, uint32_t ip) { pthread_mutex_unlock(&userMutex); } + +void GetAPIMessager::netClearClipboard() { + action_data act; + act.action = CLEAR_CLIPBOARD; + + // Send it in + if (pthread_mutex_lock(&userMutex)) + return; + + actionQueue.push_back(act); + + pthread_mutex_unlock(&userMutex); +} diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index faa80f1..db13ec7 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -545,6 +545,12 @@ static uint8_t serverFrameStatsReadyCb(void *messager) return msgr->netServerFrameStatsReady(); } +static void clearClipboardCb(void *messager) +{ + GetAPIMessager *msgr = (GetAPIMessager *) messager; + msgr->netClearClipboard(); +} + #if OPENSSL_VERSION_NUMBER < 0x1010000f static pthread_mutex_t *sslmutex; @@ -693,6 +699,8 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr, settings.getClientFrameStatsNumCb = getClientFrameStatsNumCb; settings.serverFrameStatsReadyCb = serverFrameStatsReadyCb; + settings.clearClipboardCb = clearClipboardCb; + openssl_threads(); pthread_t tid; diff --git a/common/network/websocket.c b/common/network/websocket.c index 52c5183..816eb2e 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -1596,6 +1596,22 @@ static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in, const char * const use ws_send(ws_ctx, buf, strlen(buf)); weblog(200, wsthread_handler_id, 0, origip, ip, user, 1, origpath, strlen(buf)); + ret = 1; + } else entry("/api/clear_clipboard") { + settings.clearClipboardCb(settings.messager); + write(wakeuppipe[1], "", 1); + + sprintf(buf, "HTTP/1.1 200 OK\r\n" + "Server: KasmVNC/4.0\r\n" + "Connection: close\r\n" + "Content-type: text/plain\r\n" + "Content-length: 6\r\n" + "%s" + "\r\n" + "200 OK", extra_headers ? extra_headers : ""); + ws_send(ws_ctx, buf, strlen(buf)); + weblog(200, wsthread_handler_id, 0, origip, ip, user, 1, origpath, strlen(buf)); + ret = 1; } diff --git a/common/network/websocket.h b/common/network/websocket.h index 00d72e2..b5fc674 100644 --- a/common/network/websocket.h +++ b/common/network/websocket.h @@ -105,6 +105,8 @@ typedef struct { void (*getUsersCb)(void *messager, const char **buf); uint8_t (*getClientFrameStatsNumCb)(void *messager); uint8_t (*serverFrameStatsReadyCb)(void *messager); + + void (*clearClipboardCb)(void *messager); } settings_t; #ifdef __cplusplus diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 419e543..9b4dc2b 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -832,9 +832,8 @@ static void upgradeClientToUdp(const network::GetAPIMessager::action_data &act, } } -static void checkAPIMessages(network::GetAPIMessager *apimessager, - rdr::U8 &trackingFrameStats, char trackingClient[], - std::list &clients) +void VNCServerST::checkAPIMessages(network::GetAPIMessager *apimessager, + rdr::U8 &trackingFrameStats, char trackingClient[]) { if (pthread_mutex_lock(&apimessager->userMutex)) return; @@ -866,6 +865,13 @@ static void checkAPIMessages(network::GetAPIMessager *apimessager, case network::GetAPIMessager::UDP_UPGRADE: upgradeClientToUdp(act, clients); break; + case network::GetAPIMessager::CLEAR_CLIPBOARD: + clearBinaryClipboardData(); + clipboardClient = NULL; + desktop->handleClipboardAnnounceBinary(0, NULL); + + sendBinaryClipboardData("text/plain", NULL, 0); + break; } } @@ -1031,7 +1037,7 @@ void VNCServerST::writeUpdate() shottime = msSince(&shotstart); trackingFrameStats = 0; - checkAPIMessages(apimessager, trackingFrameStats, trackingClient, clients); + checkAPIMessages(apimessager, trackingFrameStats, trackingClient); } const rdr::U8 origtrackingFrameStats = trackingFrameStats; diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index e36412a..bdd43b0 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -284,6 +284,9 @@ namespace rfb { void translateDLPRegion(rdr::U16 &x1, rdr::U16 &y1, rdr::U16 &x2, rdr::U16 &y2) const; rdr::U32 clipboardId; + + void checkAPIMessages(network::GetAPIMessager *apimessager, + rdr::U8 &trackingFrameStats, char trackingClient[]); }; };