diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c index c53ed0916..4cfd0194e 100644 --- a/libvncclient/rfbproto.c +++ b/libvncclient/rfbproto.c @@ -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. */ diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 7ce6c990d..868678854 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -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 @@ -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 @@ -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); diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c index 34306c0fe..8e94dd98c 100644 --- a/libvncclient/vncviewer.c +++ b/libvncclient/vncviewer.c @@ -539,7 +539,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); free(client->desktopName); diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h index 9d33dc040..7b9810e63 100644 --- a/rfb/rfbclient.h +++ b/rfb/rfbclient.h @@ -232,6 +232,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); @@ -466,6 +470,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.