summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--README2
l---------README.md1
-rw-r--r--examples/camera.c2
-rw-r--r--libvncclient/listen.c9
-rw-r--r--libvncclient/rfbproto.c6
-rw-r--r--libvncclient/tls_gnutls.c21
-rw-r--r--libvncclient/vncviewer.c2
-rw-r--r--libvncserver/httpd.c2
-rw-r--r--libvncserver/rfbserver.c6
-rw-r--r--libvncserver/sockets.c21
-rw-r--r--rfb/rfbclient.h6
-rw-r--r--rfb/rfbproto.h4
13 files changed, 57 insertions, 29 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..13db7db
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: c
+
+# before build script, run autoreconf
+before_script: autoreconf -fiv \ No newline at end of file
diff --git a/README b/README
index 1b4e6f4..fc15824 100644
--- a/README
+++ b/README
@@ -1,3 +1,5 @@
+[![Build Status](https://travis-ci.org/LibVNC/libvncserver.svg?branch=master)](https://travis-ci.org/LibVNC/libvncserver)
+
LibVNCServer: A library for easy implementation of a VNC server.
Copyright (C) 2001-2003 Johannes E. Schindelin
diff --git a/README.md b/README.md
new file mode 120000
index 0000000..100b938
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+README \ No newline at end of file
diff --git a/examples/camera.c b/examples/camera.c
index 2e54da7..51b122d 100644
--- a/examples/camera.c
+++ b/examples/camera.c
@@ -104,7 +104,7 @@ int TakePicture(unsigned char *buffer)
*/
gettimeofday(&now,NULL);
line = now.tv_usec / (1000000/HEIGHT);
- if (line>HEIGHT) line=HEIGHT-1;
+ if (line>=HEIGHT) line=HEIGHT-1;
memset(&buffer[(WIDTH * BPP) * line], 0, (WIDTH * BPP));
/* frames per second (informational only) */
diff --git a/libvncclient/listen.c b/libvncclient/listen.c
index 739cd9f..e989d6a 100644
--- a/libvncclient/listen.c
+++ b/libvncclient/listen.c
@@ -30,9 +30,6 @@
#ifdef WIN32
#define close closesocket
#include <winsock2.h>
-#ifdef _MINGW32
-#undef max
-#endif // #ifdef _MINGW32
#else // #ifdef WIN32
#include <sys/wait.h>
#include <sys/utsname.h>
@@ -99,7 +96,7 @@ listenForIncomingConnections(rfbClient* client)
if(listen6Socket >= 0)
FD_SET(listen6Socket, &fds);
- r = select(max(listenSocket, listen6Socket)+1, &fds, NULL, NULL, NULL);
+ r = select(rfbMax(listenSocket, listen6Socket)+1, &fds, NULL, NULL, NULL);
if (r > 0) {
if (FD_ISSET(listenSocket, &fds))
@@ -195,9 +192,9 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)
FD_SET(client->listen6Sock, &fds);
if (timeout < 0)
- r = select(max(client->listenSock, client->listen6Sock) +1, &fds, NULL, NULL, NULL);
+ r = select(rfbMax(client->listenSock, client->listen6Sock) +1, &fds, NULL, NULL, NULL);
else
- r = select(max(client->listenSock, client->listen6Sock) +1, &fds, NULL, NULL, &to);
+ r = select(rfbMax(client->listenSock, client->listen6Sock) +1, &fds, NULL, NULL, &to);
if (r > 0)
{
diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c
index 187a56a..94b9bdb 100644
--- a/libvncclient/rfbproto.c
+++ b/libvncclient/rfbproto.c
@@ -1492,7 +1492,8 @@ SetFormatAndEncodings(rfbClient* client)
if(e->encodings) {
int* enc;
for(enc = e->encodings; *enc; enc++)
- encs[se->nEncodings++] = rfbClientSwap32IfLE(*enc);
+ if(se->nEncodings < MAX_ENCODINGS)
+ encs[se->nEncodings++] = rfbClientSwap32IfLE(*enc);
}
len = sz_rfbSetEncodingsMsg + se->nEncodings * 4;
@@ -1962,7 +1963,8 @@ HandleRFBServerMessage(rfbClient* client)
y += linesToRead;
}
- } break;
+ break;
+ }
case rfbEncodingCopyRect:
{
diff --git a/libvncclient/tls_gnutls.c b/libvncclient/tls_gnutls.c
index a5a5610..b9ffe89 100644
--- a/libvncclient/tls_gnutls.c
+++ b/libvncclient/tls_gnutls.c
@@ -491,6 +491,14 @@ WriteToTLS(rfbClient* client, char *buf, unsigned int n)
unsigned int offset = 0;
ssize_t ret;
+ if (client->LockWriteToTLS)
+ {
+ if (!client->LockWriteToTLS(client))
+ {
+ rfbClientLog("Callback to get lock in WriteToTLS() failed\n");
+ return -1;
+ }
+ }
while (offset < n)
{
ret = gnutls_record_send((gnutls_session_t)client->tlsSession, buf+offset, (size_t)(n-offset));
@@ -499,10 +507,23 @@ WriteToTLS(rfbClient* client, char *buf, unsigned int n)
{
if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) continue;
rfbClientLog("Error writing to TLS: %s.\n", gnutls_strerror(ret));
+ if (client->UnlockWriteToTLS)
+ {
+ if (!client->UnlockWriteToTLS(client))
+ rfbClientLog("Callback to unlock WriteToTLS() failed\n");
+ }
return -1;
}
offset += (unsigned int)ret;
}
+ if (client->UnlockWriteToTLS)
+ {
+ if (!client->UnlockWriteToTLS(client))
+ {
+ rfbClientLog("Callback to unlock WriteToTLS() failed\n");
+ return -1;
+ }
+ }
return offset;
}
diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c
index af0a50b..d81e298 100644
--- a/libvncclient/vncviewer.c
+++ b/libvncclient/vncviewer.c
@@ -220,6 +220,8 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
client->subAuthScheme = 0;
client->GetCredential = NULL;
client->tlsSession = NULL;
+ client->LockWriteToTLS = NULL;
+ client->UnlockWriteToTLS = NULL;
client->sock = -1;
client->listenSock = -1;
client->listenAddress = NULL;
diff --git a/libvncserver/httpd.c b/libvncserver/httpd.c
index 2a778e7..236ab3e 100644
--- a/libvncserver/httpd.c
+++ b/libvncserver/httpd.c
@@ -192,7 +192,7 @@ rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen)
}
tv.tv_sec = 0;
tv.tv_usec = 0;
- nfds = select(max(rfbScreen->httpListen6Sock, max(rfbScreen->httpSock,rfbScreen->httpListenSock)) + 1, &fds, NULL, NULL, &tv);
+ nfds = select(rfbMax(rfbScreen->httpListen6Sock, rfbMax(rfbScreen->httpSock,rfbScreen->httpListenSock)) + 1, &fds, NULL, NULL, &tv);
if (nfds == 0) {
return;
}
diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c
index 34e1c06..bc9cc11 100644
--- a/libvncserver/rfbserver.c
+++ b/libvncserver/rfbserver.c
@@ -363,13 +363,11 @@ rfbNewTCPOrUDPClient(rfbScreenInfoPtr rfbScreen,
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("setsockopt failed");
- close(sock);
- return NULL;
+ rfbLogPerror("setsockopt failed: can't set TCP_NODELAY flag, non TCP socket?");
}
FD_SET(sock,&(rfbScreen->allFds));
- rfbScreen->maxFd = max(sock,rfbScreen->maxFd);
+ rfbScreen->maxFd = rfbMax(sock,rfbScreen->maxFd);
INIT_MUTEX(cl->outputMutex);
INIT_MUTEX(cl->refCountMutex);
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c
index f21f162..51e86eb 100644
--- a/libvncserver/sockets.c
+++ b/libvncserver/sockets.c
@@ -146,8 +146,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
if (setsockopt(rfbScreen->inetdSock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("setsockopt");
- return;
+ rfbLogPerror("setsockopt failed: can't set TCP_NODELAY flag, non TCP socket?");
}
FD_ZERO(&(rfbScreen->allFds));
@@ -193,7 +192,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
rfbLog("Autoprobing selected TCP6 port %d\n", rfbScreen->ipv6port);
FD_SET(rfbScreen->listen6Sock, &(rfbScreen->allFds));
- rfbScreen->maxFd = max((int)rfbScreen->listen6Sock,rfbScreen->maxFd);
+ rfbScreen->maxFd = rfbMax((int)rfbScreen->listen6Sock,rfbScreen->maxFd);
#endif
}
else
@@ -220,7 +219,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
rfbLog("Listening for VNC connections on TCP6 port %d\n", rfbScreen->ipv6port);
FD_SET(rfbScreen->listen6Sock, &(rfbScreen->allFds));
- rfbScreen->maxFd = max((int)rfbScreen->listen6Sock,rfbScreen->maxFd);
+ rfbScreen->maxFd = rfbMax((int)rfbScreen->listen6Sock,rfbScreen->maxFd);
}
#endif
@@ -236,7 +235,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
rfbLog("Listening for VNC connections on TCP port %d\n", rfbScreen->port);
FD_SET(rfbScreen->udpSock, &(rfbScreen->allFds));
- rfbScreen->maxFd = max((int)rfbScreen->udpSock,rfbScreen->maxFd);
+ rfbScreen->maxFd = rfbMax((int)rfbScreen->udpSock,rfbScreen->maxFd);
}
}
@@ -395,7 +394,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
do {
rfbProcessClientMessage(cl);
- } while (webSocketsHasDataInBuffer(cl));
+ } while (cl->sock > 0 && webSocketsHasDataInBuffer(cl));
#else
rfbProcessClientMessage(cl);
#endif
@@ -453,9 +452,7 @@ rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("rfbCheckFds: setsockopt");
- closesocket(sock);
- return FALSE;
+ rfbLogPerror("rfbCheckFds: setsockopt failed: can't set TCP_NODELAY flag, non TCP socket?");
}
#ifdef USE_LIBWRAP
@@ -556,14 +553,12 @@ rfbConnect(rfbScreenInfoPtr rfbScreen,
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("setsockopt failed");
- closesocket(sock);
- return -1;
+ rfbLogPerror("setsockopt failed: can't set TCP_NODELAY flag, non TCP socket?");
}
/* AddEnabledDevice(sock); */
FD_SET(sock, &rfbScreen->allFds);
- rfbScreen->maxFd = max(sock,rfbScreen->maxFd);
+ rfbScreen->maxFd = rfbMax(sock,rfbScreen->maxFd);
return sock;
}
diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h
index 157461e..c18eaf9 100644
--- a/rfb/rfbclient.h
+++ b/rfb/rfbclient.h
@@ -182,6 +182,8 @@ typedef void (*BellProc)(struct _rfbClient* client);
*/
typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
+typedef rfbBool (*LockWriteToTLSProc)(struct _rfbClient* client);
+typedef rfbBool (*UnlockWriteToTLSProc)(struct _rfbClient* client);
typedef struct _rfbClient {
uint8_t* frameBuffer;
@@ -361,6 +363,10 @@ typedef struct _rfbClient {
/* Output Window ID. When set, client application enables libvncclient to perform direct rendering in its window */
unsigned long outputWindow;
+ /** Hooks for optional protection WriteToTLS() by mutex */
+ LockWriteToTLSProc LockWriteToTLS;
+ UnlockWriteToTLSProc UnlockWriteToTLS;
+
} rfbClient;
/* cursor.c */
diff --git a/rfb/rfbproto.h b/rfb/rfbproto.h
index 8e607e5..9eca868 100644
--- a/rfb/rfbproto.h
+++ b/rfb/rfbproto.h
@@ -93,8 +93,8 @@
#define strncasecmp _strnicmp
#endif
+#define rfbMax(a,b) (((a)>(b))?(a):(b))
#if !defined(WIN32) || defined(__MINGW32__)
-#define max(a,b) (((a)>(b))?(a):(b))
#ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -120,7 +120,7 @@ typedef uint32_t in_addr_t;
#define INADDR_NONE ((in_addr_t) 0xffffffff)
#endif
-#define MAX_ENCODINGS 21
+#define MAX_ENCODINGS 64
/*****************************************************************************
*