From c17aef31ac3540a04707a7f14f04524cc76c93d0 Mon Sep 17 00:00:00 2001 From: dscho Date: Thu, 31 Jan 2008 17:49:13 +0000 Subject: Fix rfbSendSupportedEncodings There was a long standing TODO to make the counting of the supported encodings dynamic. It never triggered, until ZYWRLE was added. Noticed by Christian Ehrlicher. Signed-off-by: Johannes Schindelin --- libvncserver/rfbserver.c | 75 +++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 43 deletions(-) (limited to 'libvncserver/rfbserver.c') diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c index 3dd2f29..2567f23 100644 --- a/libvncserver/rfbserver.c +++ b/libvncserver/rfbserver.c @@ -907,15 +907,6 @@ rfbSendSupportedMessages(rfbClientPtr cl) -static void rfbSendSupporteddEncodings_SendEncoding(rfbClientPtr cl, uint32_t enc) -{ - uint32_t nSwapped=0; - nSwapped = Swap32IfLE(enc); - memcpy(&cl->updateBuf[cl->ublen], (char *)&nSwapped, sizeof(nSwapped)); - cl->ublen+=sizeof(nSwapped); -} - - /* * Send rfbEncodingSupportedEncodings. */ @@ -924,21 +915,38 @@ rfbBool rfbSendSupportedEncodings(rfbClientPtr cl) { rfbFramebufferUpdateRectHeader rect; - uint16_t nEncodings=0; - - /* think rfbSetEncodingsMsg */ - - /* TODO: dynamic way of doing this */ - nEncodings=16; + static uint32_t supported[] = { + rfbEncodingRaw, + rfbEncodingCopyRect, + rfbEncodingRRE, + rfbEncodingCoRRE, + rfbEncodingHextile, #ifdef LIBVNCSERVER_HAVE_LIBZ - nEncodings += 2; + rfbEncodingZlib, + rfbEncodingZRLE, + rfbEncodingZYWRLE, #endif -#ifdef LIBVNCSERVER_HAVE_LIBZ - nEncodings++; +#ifdef LIBVNCSERVER_HAVE_LIBJPEG + rfbEncodingTight, #endif + rfbEncodingUltra, + rfbEncodingUltraZip, + rfbEncodingXCursor, + rfbEncodingRichCursor, + rfbEncodingPointerPos, + rfbEncodingLastRect, + rfbEncodingNewFBSize, + rfbEncodingKeyboardLedState, + rfbEncodingSupportedMessages, + rfbEncodingSupportedEncodings, + rfbEncodingServerIdentity, + }; + uint32_t nEncodings = sizeof(supported) / sizeof(supported[0]), i; + + /* think rfbSetEncodingsMsg */ if (cl->ublen + sz_rfbFramebufferUpdateRectHeader - + (nEncodings*sizeof(uint32_t)) > UPDATE_BUF_SIZE) { + + (nEncodings * sizeof(uint32_t)) > UPDATE_BUF_SIZE) { if (!rfbSendUpdateBuf(cl)) return FALSE; } @@ -953,30 +961,11 @@ rfbSendSupportedEncodings(rfbClientPtr cl) sz_rfbFramebufferUpdateRectHeader); cl->ublen += sz_rfbFramebufferUpdateRectHeader; - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingRaw); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingCopyRect); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingRRE); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingCoRRE); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingHextile); -#ifdef LIBVNCSERVER_HAVE_LIBZ - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingZlib); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingTight); -#endif -#ifdef LIBVNCSERVER_HAVE_LIBZ - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingZRLE); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingZYWRLE); -#endif - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingUltra); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingUltraZip); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingXCursor); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingRichCursor); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingPointerPos); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingLastRect); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingNewFBSize); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingKeyboardLedState); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingSupportedMessages); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingSupportedEncodings); - rfbSendSupporteddEncodings_SendEncoding(cl, rfbEncodingServerIdentity); + for (i = 0; i < nEncodings; i++) { + uint32_t encoding = Swap32IfLE(supported[i]); + memcpy(&cl->updateBuf[cl->ublen], (char *)&encoding, sizeof(encoding)); + cl->ublen += sizeof(encoding); + } rfbStatRecordEncodingSent(cl, rfbEncodingSupportedEncodings, sz_rfbFramebufferUpdateRectHeader+(nEncodings * sizeof(uint32_t)), -- cgit v1.2.1