Move SetFormatAndEncodings back into rfbproto.c
parent
760db16923
commit
9a2a318991
|
@ -68,7 +68,6 @@ sources = [
|
|||
'src/pointer.c',
|
||||
'src/keyboard.c',
|
||||
'src/vnc.c',
|
||||
'src/vnc_encodings.c',
|
||||
'src/strlcpy.c',
|
||||
'src/evdev-to-qnum.c',
|
||||
'src/pixels.c',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Andri Yngvason. All Rights Reserved.
|
||||
* Copyright (C) 2000-2002 Constantin Kaplinsky. All Rights Reserved.
|
||||
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
|
||||
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||
|
@ -33,7 +34,9 @@
|
|||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
#include <errno.h>
|
||||
#include <rfb/rfbclient.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "rfb/rfbclient.h"
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBZ
|
||||
#include <zlib.h>
|
||||
#ifdef __CHECKER__
|
||||
|
@ -1220,6 +1223,8 @@ InitialiseRFBConnection(rfbClient* client)
|
|||
rfbBool
|
||||
SetFormatAndEncodings(rfbClient* client)
|
||||
{
|
||||
assert(client->appData.encodingsString);
|
||||
|
||||
rfbSetPixelFormatMsg spf;
|
||||
union {
|
||||
char bytes[sz_rfbSetEncodingsMsg + MAX_ENCODINGS*4];
|
||||
|
@ -1232,9 +1237,9 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
rfbBool requestCompressLevel = FALSE;
|
||||
rfbBool requestQualityLevel = FALSE;
|
||||
rfbBool requestLastRectEncoding = FALSE;
|
||||
rfbClientProtocolExtension* e;
|
||||
|
||||
if (!SupportsClient2Server(client, rfbSetPixelFormat)) return TRUE;
|
||||
if (!SupportsClient2Server(client, rfbSetPixelFormat))
|
||||
return TRUE;
|
||||
|
||||
spf.type = rfbSetPixelFormat;
|
||||
spf.pad1 = 0;
|
||||
|
@ -1248,17 +1253,17 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
return FALSE;
|
||||
|
||||
|
||||
if (!SupportsClient2Server(client, rfbSetEncodings)) return TRUE;
|
||||
if (!SupportsClient2Server(client, rfbSetEncodings))
|
||||
return TRUE;
|
||||
|
||||
se->type = rfbSetEncodings;
|
||||
se->pad = 0;
|
||||
se->nEncodings = 0;
|
||||
|
||||
if (client->appData.encodingsString) {
|
||||
const char *encStr = client->appData.encodingsString;
|
||||
int encStrLen;
|
||||
do {
|
||||
const char *nextEncStr = strchr(encStr, ' ');
|
||||
const char *nextEncStr = strchr(encStr, ',');
|
||||
if (nextEncStr) {
|
||||
encStrLen = nextEncStr - encStr;
|
||||
nextEncStr++;
|
||||
|
@ -1308,6 +1313,8 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCoRRE);
|
||||
} else if (strncasecmp(encStr,"rre",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRRE);
|
||||
} else if (strncasecmp(encStr,"open-h264",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(50);
|
||||
} else {
|
||||
rfbClientLog("Unknown encoding '%.*s'\n",encStrLen,encStr);
|
||||
}
|
||||
|
@ -1326,59 +1333,6 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
encs[se->nEncodings++] = rfbClientSwap32IfLE(client->appData.qualityLevel +
|
||||
rfbEncodingQualityLevel0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (SameMachine(client->sock)) {
|
||||
/* TODO:
|
||||
if (!tunnelSpecified) {
|
||||
*/
|
||||
rfbClientLog("Same machine: preferring raw encoding\n");
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRaw);
|
||||
/*
|
||||
} else {
|
||||
rfbClientLog("Tunneling active: preferring tight encoding\n");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCopyRect);
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBZ
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingTight);
|
||||
requestLastRectEncoding = TRUE;
|
||||
#endif
|
||||
#endif
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingHextile);
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBZ
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZlib);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZRLE);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZYWRLE);
|
||||
#endif
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingUltra);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingUltraZip);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCoRRE);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRRE);
|
||||
|
||||
if (client->appData.compressLevel >= 0 && client->appData.compressLevel <= 9) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(client->appData.compressLevel +
|
||||
rfbEncodingCompressLevel0);
|
||||
} else /* if (!tunnelSpecified) */ {
|
||||
/* If -tunnel option was provided, we assume that server machine is
|
||||
not in the local network so we use default compression level for
|
||||
tight encoding instead of fast compression. Thus we are
|
||||
requesting level 1 compression only if tunneling is not used. */
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCompressLevel1);
|
||||
}
|
||||
|
||||
if (client->appData.enableJPEG) {
|
||||
if (client->appData.qualityLevel < 0 || client->appData.qualityLevel > 9)
|
||||
client->appData.qualityLevel = 5;
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(client->appData.qualityLevel +
|
||||
rfbEncodingQualityLevel0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Remote Cursor Support (local to viewer) */
|
||||
if (client->appData.useRemoteCursor) {
|
||||
|
@ -1397,8 +1351,6 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
/* New Frame Buffer Size */
|
||||
if (se->nEncodings < MAX_ENCODINGS && client->canHandleNewFBSize)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingNewFBSize);
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingExtDesktopSize);
|
||||
|
||||
/* Last Rect */
|
||||
if (se->nEncodings < MAX_ENCODINGS && requestLastRectEncoding)
|
||||
|
@ -1419,22 +1371,15 @@ SetFormatAndEncodings(rfbClient* client)
|
|||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingQemuExtendedKeyEvent);
|
||||
|
||||
/* client extensions */
|
||||
for(e = rfbClientExtensions; e; e = e->next)
|
||||
if(e->encodings) {
|
||||
int* enc;
|
||||
for(enc = e->encodings; *enc; enc++)
|
||||
if(se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(*enc);
|
||||
}
|
||||
/* pts */
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(-1000);
|
||||
|
||||
len = sz_rfbSetEncodingsMsg + se->nEncodings * 4;
|
||||
|
||||
se->nEncodings = rfbClientSwap16IfLE(se->nEncodings);
|
||||
|
||||
if (!WriteToRFBServer(client, buf.bytes, len)) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
return WriteToRFBServer(client, buf.bytes, len);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
extern const unsigned short code_map_linux_to_qnum[];
|
||||
extern const unsigned int code_map_linux_to_qnum_len;
|
||||
|
||||
rfbBool vnc_client_set_format_and_encodings(rfbClient* client);
|
||||
|
||||
static uint64_t vnc_client_htonll(uint64_t x)
|
||||
{
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
|
@ -262,7 +260,7 @@ int vnc_client_init(struct vnc_client* self)
|
|||
if (!client->MallocFrameBuffer(client))
|
||||
goto failure;
|
||||
|
||||
if (!vnc_client_set_format_and_encodings(client))
|
||||
if (!SetFormatAndEncodings(client))
|
||||
goto failure;
|
||||
|
||||
if (client->updateRect.x < 0) {
|
||||
|
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Andri Yngvason. All Rights Reserved.
|
||||
* Copyright (C) 2000-2002 Constantin Kaplinsky. All Rights Reserved.
|
||||
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
|
||||
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#include <rfb/rfbclient.h>
|
||||
#include <assert.h>
|
||||
|
||||
rfbBool vnc_client_set_format_and_encodings(rfbClient* client)
|
||||
{
|
||||
assert(client->appData.encodingsString);
|
||||
|
||||
rfbSetPixelFormatMsg spf;
|
||||
union {
|
||||
char bytes[sz_rfbSetEncodingsMsg + MAX_ENCODINGS*4];
|
||||
rfbSetEncodingsMsg msg;
|
||||
} buf;
|
||||
|
||||
rfbSetEncodingsMsg *se = &buf.msg;
|
||||
uint32_t *encs = (uint32_t *)(&buf.bytes[sz_rfbSetEncodingsMsg]);
|
||||
int len = 0;
|
||||
rfbBool requestCompressLevel = FALSE;
|
||||
rfbBool requestQualityLevel = FALSE;
|
||||
rfbBool requestLastRectEncoding = FALSE;
|
||||
|
||||
if (!SupportsClient2Server(client, rfbSetPixelFormat))
|
||||
return TRUE;
|
||||
|
||||
spf.type = rfbSetPixelFormat;
|
||||
spf.pad1 = 0;
|
||||
spf.pad2 = 0;
|
||||
spf.format = client->format;
|
||||
spf.format.redMax = rfbClientSwap16IfLE(spf.format.redMax);
|
||||
spf.format.greenMax = rfbClientSwap16IfLE(spf.format.greenMax);
|
||||
spf.format.blueMax = rfbClientSwap16IfLE(spf.format.blueMax);
|
||||
|
||||
if (!WriteToRFBServer(client, (char *)&spf, sz_rfbSetPixelFormatMsg))
|
||||
return FALSE;
|
||||
|
||||
|
||||
if (!SupportsClient2Server(client, rfbSetEncodings))
|
||||
return TRUE;
|
||||
|
||||
se->type = rfbSetEncodings;
|
||||
se->pad = 0;
|
||||
se->nEncodings = 0;
|
||||
|
||||
const char *encStr = client->appData.encodingsString;
|
||||
int encStrLen;
|
||||
do {
|
||||
const char *nextEncStr = strchr(encStr, ',');
|
||||
if (nextEncStr) {
|
||||
encStrLen = nextEncStr - encStr;
|
||||
nextEncStr++;
|
||||
} else {
|
||||
encStrLen = strlen(encStr);
|
||||
}
|
||||
|
||||
if (strncasecmp(encStr,"raw",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRaw);
|
||||
} else if (strncasecmp(encStr,"copyrect",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCopyRect);
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBZ
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
|
||||
} else if (strncasecmp(encStr,"tight",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingTight);
|
||||
requestLastRectEncoding = TRUE;
|
||||
if (client->appData.compressLevel >= 0 && client->appData.compressLevel <= 9)
|
||||
requestCompressLevel = TRUE;
|
||||
if (client->appData.enableJPEG)
|
||||
requestQualityLevel = TRUE;
|
||||
#endif
|
||||
#endif
|
||||
} else if (strncasecmp(encStr,"hextile",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingHextile);
|
||||
#ifdef LIBVNCSERVER_HAVE_LIBZ
|
||||
} else if (strncasecmp(encStr,"zlib",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZlib);
|
||||
if (client->appData.compressLevel >= 0 && client->appData.compressLevel <= 9)
|
||||
requestCompressLevel = TRUE;
|
||||
} else if (strncasecmp(encStr,"zlibhex",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZlibHex);
|
||||
if (client->appData.compressLevel >= 0 && client->appData.compressLevel <= 9)
|
||||
requestCompressLevel = TRUE;
|
||||
} else if (strncasecmp(encStr,"trle",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingTRLE);
|
||||
} else if (strncasecmp(encStr,"zrle",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZRLE);
|
||||
} else if (strncasecmp(encStr,"zywrle",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingZYWRLE);
|
||||
requestQualityLevel = TRUE;
|
||||
#endif
|
||||
} else if ((strncasecmp(encStr,"ultra",encStrLen) == 0) || (strncasecmp(encStr,"ultrazip",encStrLen) == 0)) {
|
||||
/* There are 2 encodings used in 'ultra' */
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingUltra);
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingUltraZip);
|
||||
} else if (strncasecmp(encStr,"corre",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingCoRRE);
|
||||
} else if (strncasecmp(encStr,"rre",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRRE);
|
||||
} else if (strncasecmp(encStr,"open-h264",encStrLen) == 0) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(50);
|
||||
} else {
|
||||
rfbClientLog("Unknown encoding '%.*s'\n",encStrLen,encStr);
|
||||
}
|
||||
|
||||
encStr = nextEncStr;
|
||||
} while (encStr && se->nEncodings < MAX_ENCODINGS);
|
||||
|
||||
if (se->nEncodings < MAX_ENCODINGS && requestCompressLevel) {
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(client->appData.compressLevel +
|
||||
rfbEncodingCompressLevel0);
|
||||
}
|
||||
|
||||
if (se->nEncodings < MAX_ENCODINGS && requestQualityLevel) {
|
||||
if (client->appData.qualityLevel < 0 || client->appData.qualityLevel > 9)
|
||||
client->appData.qualityLevel = 5;
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(client->appData.qualityLevel +
|
||||
rfbEncodingQualityLevel0);
|
||||
}
|
||||
|
||||
/* Remote Cursor Support (local to viewer) */
|
||||
if (client->appData.useRemoteCursor) {
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingXCursor);
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRichCursor);
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingPointerPos);
|
||||
}
|
||||
|
||||
/* Keyboard State Encodings */
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingKeyboardLedState);
|
||||
|
||||
/* New Frame Buffer Size */
|
||||
if (se->nEncodings < MAX_ENCODINGS && client->canHandleNewFBSize)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingNewFBSize);
|
||||
|
||||
/* Last Rect */
|
||||
if (se->nEncodings < MAX_ENCODINGS && requestLastRectEncoding)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingLastRect);
|
||||
|
||||
/* Server Capabilities */
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingSupportedMessages);
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingSupportedEncodings);
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingServerIdentity);
|
||||
|
||||
/* xvp */
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingXvp);
|
||||
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingQemuExtendedKeyEvent);
|
||||
|
||||
/* pts */
|
||||
if (se->nEncodings < MAX_ENCODINGS)
|
||||
encs[se->nEncodings++] = rfbClientSwap32IfLE(-1000);
|
||||
|
||||
len = sz_rfbSetEncodingsMsg + se->nEncodings * 4;
|
||||
|
||||
se->nEncodings = rfbClientSwap16IfLE(se->nEncodings);
|
||||
|
||||
return WriteToRFBServer(client, buf.bytes, len);
|
||||
}
|
Loading…
Reference in New Issue