Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/rfb/rfbclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ typedef void (*GotBitmapProc)(struct _rfbClient* client, const uint8_t* buffer,
typedef rfbBool (*GotJpegProc)(struct _rfbClient* client, const uint8_t* buffer, int length, int x, int y, int w, int h);
typedef rfbBool (*LockWriteToTLSProc)(struct _rfbClient* client); /** @deprecated */
typedef rfbBool (*UnlockWriteToTLSProc)(struct _rfbClient* client); /** @deprecated */
typedef rfbSocket (*ConnectToRFBServerProc)(struct _rfbClient* client, const char* hostname, int port);
typedef int (*ReadFromSocketProc)(struct _rfbClient* client, char* buf, unsigned int len);
typedef int (*WriteToSocketProc)(struct _rfbClient* client, const char* buf, unsigned int len);
typedef void (*CloseSocketProc)(struct _rfbClient* client);

#ifdef LIBVNCSERVER_HAVE_SASL
typedef char* (*GetUserProc)(struct _rfbClient* client);
Expand Down Expand Up @@ -467,6 +471,12 @@ typedef struct _rfbClient {
* ReadFromRFBServer() - keep at 0 to disable timeout detection and handling */
unsigned int readTimeout;

/** hooks for custom socket I/O */
ConnectToRFBServerProc ConnectToRFBServer;
ReadFromSocketProc ReadFromSocket;
WriteToSocketProc WriteToSocket;
CloseSocketProc CloseSocket;

/**
* Mutex to protect concurrent TLS read/write.
* For internal use only.
Expand Down
5 changes: 5 additions & 0 deletions src/libvncclient/rfbclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
return TRUE;
}

if(client->ConnectToRFBServer)
{
client->sock = client->ConnectToRFBServer(client, hostname, port);
}
else
#ifndef WIN32
if(IsUnixSocket(hostname))
/* serverHost is a UNIX socket. */
Expand Down
14 changes: 12 additions & 2 deletions src/libvncclient/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)

while (client->buffered < n) {
int i;
if (client->tlsSession)
if (client->ReadFromSocket)
i = client->ReadFromSocket(client, client->buf + client->buffered, RFB_BUF_SIZE - client->buffered);
else if (client->tlsSession)
i = ReadFromTLS(client, client->buf + client->buffered, RFB_BUF_SIZE - client->buffered);
else
#ifdef LIBVNCSERVER_HAVE_SASL
Expand Down Expand Up @@ -186,7 +188,9 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)

while (n > 0) {
int i;
if (client->tlsSession)
if (client->ReadFromSocket)
i = client->ReadFromSocket(client, out, n);
else if (client->tlsSession)
i = ReadFromTLS(client, out, n);
else
#ifdef LIBVNCSERVER_HAVE_SASL
Expand Down Expand Up @@ -262,6 +266,12 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
if (client->serverPort==-1)
return TRUE; /* vncrec playing */

if (client->WriteToSocket) {
i = client->WriteToSocket(client, buf, n);
if (i <= 0) return FALSE;

return TRUE;
}
if (client->tlsSession) {
/* WriteToTLS() will guarantee either everything is written, or error/eof returns */
i = WriteToTLS(client, buf, n);
Expand Down
4 changes: 4 additions & 0 deletions src/libvncclient/vncviewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ void rfbClientCleanup(rfbClient* client) {
free(client->vncRec);

if (client->sock != RFB_INVALID_SOCKET)
{
if (client->CloseSocket)
client->CloseSocket(client);
rfbCloseSocket(client->sock);
}
if (client->listenSock != RFB_INVALID_SOCKET)
rfbCloseSocket(client->listenSock);
if (client->listen6Sock != RFB_INVALID_SOCKET)
Expand Down
Loading