diff options
author | Joel Martin <github@martintribe.org> | 2011-08-16 14:02:31 +0200 |
---|---|---|
committer | Johannes Schindelin <johannes.schindelin@gmx.de> | 2011-08-17 12:41:23 +0200 |
commit | 6fac22a74b5020387a6961e4cc197b5fa4743f96 (patch) | |
tree | 9eb15702fbeed2f15fe2de17b54ac92544582509 /libvncserver/rfbserver.c | |
parent | 353b35e86aa7d51d767f4ff66e1179105bbee205 (diff) | |
download | libtdevnc-6fac22a74b5020387a6961e4cc197b5fa4743f96.tar.gz libtdevnc-6fac22a74b5020387a6961e4cc197b5fa4743f96.zip |
websockets: Initial WebSockets support.
Has a bug: WebSocket client disconnects are not detected.
rfbSendFramebufferUpdate is doing a MSG_PEEK recv to determine if
enough data is available which prevents a disconnect from being
detected.
Otherwise it's working pretty well.
[jes: moved added struct members to the end for binary compatibility with
previous LibVNCServer versions, removed an unused variable]
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'libvncserver/rfbserver.c')
-rw-r--r-- | libvncserver/rfbserver.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c index 587a2f0..1df4fee 100644 --- a/libvncserver/rfbserver.c +++ b/libvncserver/rfbserver.c @@ -358,6 +358,14 @@ rfbNewTCPOrUDPClient(rfbScreenInfoPtr rfbScreen, rfbScreen->clientHead = cl; UNLOCK(rfbClientListMutex); +#ifdef LIBVNCSERVER_WITH_WEBSOCKETS + cl->webSockets = FALSE; + cl->webSocketsSSL = FALSE; + cl->webSocketsBase64 = FALSE; + cl->dblen= 0; + cl->carrylen = 0; +#endif + #if defined(LIBVNCSERVER_HAVE_LIBZ) || defined(LIBVNCSERVER_HAVE_LIBPNG) cl->tightQualityLevel = -1; #if defined(LIBVNCSERVER_HAVE_LIBJPEG) || defined(LIBVNCSERVER_HAVE_LIBPNG) @@ -404,6 +412,20 @@ rfbNewTCPOrUDPClient(rfbScreenInfoPtr rfbScreen, cl->lastPtrX = -1; +#ifdef LIBVNCSERVER_WITH_WEBSOCKETS + /* + * Wait a few ms for the client to send one of: + * - Flash policy request + * - WebSockets connection (TLS/SSL or plain) + */ + if (!webSocketsCheck(cl)) { + /* Error reporting handled in webSocketsHandshake */ + rfbCloseClient(cl); + rfbClientConnectionGone(cl); + return NULL; + } +#endif + sprintf(pv,rfbProtocolVersionFormat,rfbScreen->protocolMajorVersion, rfbScreen->protocolMinorVersion); @@ -1817,6 +1839,16 @@ rfbProcessClientNormalMessage(rfbClientPtr cl) char encBuf[64]; char encBuf2[64]; +#ifdef LIBVNCSERVER_WITH_WEBSOCKETS + if (cl->webSockets && cl->webSocketsBase64) { + /* With Base64 encoding we need at least 4 bytes */ + n = recv(cl->sock, encBuf, 4, MSG_PEEK); + if ((n > 0) && (n < 4)) { + return; + } + } +#endif + if ((n = rfbReadExact(cl, (char *)&msg, 1)) <= 0) { if (n != 0) rfbLogPerror("rfbProcessClientNormalMessage: read"); @@ -2904,7 +2936,6 @@ rfbSendFramebufferUpdate(rfbClientPtr cl, #endif #ifdef LIBVNCSERVER_HAVE_LIBPNG case rfbEncodingTightPng: - /* TODO */ if (!rfbSendRectEncodingTightPng(cl, x, y, w, h)) goto updateFailed; break; |