diff options
author | Christian Beier <[email protected]> | 2016-04-24 17:00:08 +0200 |
---|---|---|
committer | Christian Beier <[email protected]> | 2016-04-24 17:00:08 +0200 |
commit | fc3dfdd9c59a6a36f7add3255aaad50d56228c59 (patch) | |
tree | 1f67155bd18492eb8dbbf0b059a66b0c62fdee68 | |
parent | 2893c2b057dfddd25efdbda21ff9d2522763489a (diff) | |
parent | 1da7872784a78446284b4e8ef71691458296026c (diff) | |
download | libtdevnc-fc3dfdd9c59a6a36f7add3255aaad50d56228c59.tar.gz libtdevnc-fc3dfdd9c59a6a36f7add3255aaad50d56228c59.zip |
Merge pull request #118 from gbdj/threadsafe-100-squash
libvncclient/tls_gnutls.c: Add hooks to WriteToTLS() for optional protection by mutex. (Squashed)
-rw-r--r-- | libvncclient/tls_gnutls.c | 21 | ||||
-rw-r--r-- | libvncclient/vncviewer.c | 2 | ||||
-rw-r--r-- | rfb/rfbclient.h | 6 |
3 files changed, 29 insertions, 0 deletions
diff --git a/libvncclient/tls_gnutls.c b/libvncclient/tls_gnutls.c index 3daa416..91cea67 100644 --- a/libvncclient/tls_gnutls.c +++ b/libvncclient/tls_gnutls.c @@ -480,6 +480,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)); @@ -488,10 +496,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/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 */ |