From 4b3b9d918e37972338bf1f012542504b8427c30a Mon Sep 17 00:00:00 2001 From: Gaurav Ujjwal Date: Tue, 19 Nov 2024 21:39:49 +0530 Subject: [PATCH] Libvncserver: Enable ExtendedClipboard encoding only when app signals support for UTF-8 cut-text A UTF-8 capable client will usually prefer to send cut-text via ExtendedClipboard encoding once libvncserver declares support for it. If app doesn't assign a setXCutTextUTF8() callback, the default handler is used which is no-op. So client-to-server clipboard transfer will not work. Re: #638 --- include/rfb/rfb.h | 2 ++ src/libvncserver/main.c | 2 +- src/libvncserver/rfbserver.c | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/rfb/rfb.h b/include/rfb/rfb.h index f639e27a..50acf244 100644 --- a/include/rfb/rfb.h +++ b/include/rfb/rfb.h @@ -370,6 +370,8 @@ typedef struct _rfbScreenInfo uintptr_t listener_thread; #endif #ifdef LIBVNCSERVER_HAVE_LIBZ + /** This is called when UTF-8 cut-text is received from a client. + * Set this callback to enable ExtendedClipboard support. */ rfbSetXCutTextUTF8ProcPtr setXCutTextUTF8; #endif /* Timeout value for select() calls, mainly used for multithreaded servers. */ diff --git a/src/libvncserver/main.c b/src/libvncserver/main.c index d6ba4b93..9e4bd3c8 100644 --- a/src/libvncserver/main.c +++ b/src/libvncserver/main.c @@ -1041,7 +1041,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv, screen->ptrAddEvent = rfbDefaultPtrAddEvent; screen->setXCutText = rfbDefaultSetXCutText; #ifdef LIBVNCSERVER_HAVE_LIBZ - screen->setXCutTextUTF8 = rfbDefaultSetXCutText; + screen->setXCutTextUTF8 = NULL; #endif screen->getCursorPtr = rfbDefaultGetCursorPtr; screen->setTranslateFunction = rfbSetTranslateFunction; diff --git a/src/libvncserver/rfbserver.c b/src/libvncserver/rfbserver.c index a80fd1ae..da7ae248 100644 --- a/src/libvncserver/rfbserver.c +++ b/src/libvncserver/rfbserver.c @@ -2193,7 +2193,7 @@ rfbProcessExtendedServerCutTextData(rfbClientPtr cl, uint32_t flags, const char } if (i == 0) { /* text */ - if (!cl->viewOnly) { + if (!cl->viewOnly && cl->screen->setXCutTextUTF8) { cl->screen->setXCutTextUTF8(buf, size, cl); } } @@ -2465,14 +2465,16 @@ rfbProcessClientNormalMessage(rfbClientPtr cl) break; #ifdef LIBVNCSERVER_HAVE_LIBZ case rfbEncodingExtendedClipboard: - if (!cl->enableExtendedClipboard) { - rfbLog("Enabling ExtendedClipboard extension for client " - "%s\n", cl->host); - cl->enableExtendedClipboard = TRUE; - } - /* send the capabilities we support, currently only text */ - if (!rfbSendExtendedClipboardCapability(cl)) { - return; + if (cl->screen->setXCutTextUTF8) { + if (!cl->enableExtendedClipboard) { + rfbLog("Enabling ExtendedClipboard extension for client " + "%s\n", cl->host); + cl->enableExtendedClipboard = TRUE; + } + /* send the capabilities we support, currently only text */ + if (!rfbSendExtendedClipboardCapability(cl)) { + return; + } } break; #endif