From ceeaeb7767011ff956d273b85bcfe49b9bc79a45 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 15 Sep 2016 21:40:39 -0500 Subject: [PATCH] Access data in read buffer using pointer instead of handle. This is a prelude to revamping the read routines. --- clipboard.cc | 8 +++---- copyrect.cc | 2 +- hextile.cc | 6 ++--- mouse.cc | 4 ++-- raw.cc | 2 +- vncdisplay.cc | 8 +++---- vncsession.cc | 63 +++++++++++++++++++++++++-------------------------- vncsession.h | 3 ++- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/clipboard.cc b/clipboard.cc index 99f7a9a..b1d37eb 100644 --- a/clipboard.cc +++ b/clipboard.cc @@ -48,7 +48,7 @@ void DoServerCutText (void) { DoClose(vncWindow); return; } - textLen = SwapBytes4((unsigned long) **readBufferHndl); + textLen = SwapBytes4(*(unsigned long *)readBufferPtr); if (! DoWaitingReadTCP(textLen)) { DoClose(vncWindow); @@ -59,11 +59,11 @@ void DoServerCutText (void) { /* Convert lf->cr; Use pointer arithmetic so we can go over 64k */ for (i = 0; i < textLen; i++) - if (*((*(char **)readBufferHndl)+i) == '\n') - *((*(char **)readBufferHndl)+i) = '\r'; + if (*(readBufferPtr+i) == '\n') + *(readBufferPtr+i) = '\r'; /* Below function call requires to be fixed */ - PutScrap(textLen, textScrap, (Pointer) *readBufferHndl); + PutScrap(textLen, textScrap, (Pointer) readBufferPtr); /* Potential errors (e.g. out of memory) ignored */ DoneWithReadBuffer(); } diff --git a/copyrect.cc b/copyrect.cc index c32a4e0..f2e91b2 100644 --- a/copyrect.cc +++ b/copyrect.cc @@ -47,7 +47,7 @@ void DoCopyRect (void) { contentOrigin.l = GetContentOrigin(vncWindow); - dataPtr = (unsigned int *) ((char *) (*readBufferHndl)); + dataPtr = (unsigned int *) readBufferPtr; srcRect.h1 = SwapBytes2(dataPtr[0]) - contentOrigin.pt.h; srcRect.v1 = SwapBytes2(dataPtr[1]) - contentOrigin.pt.v; diff --git a/hextile.cc b/hextile.cc index 5ea76ad..cf67821 100644 --- a/hextile.cc +++ b/hextile.cc @@ -78,7 +78,7 @@ static void HexRawDraw (Origin contentOrigin, int rectWidth, int rectHeight) { static Rect srcRect = {0,0,0,0}; - dataPtr = (unsigned char *) *readBufferHndl; + dataPtr = readBufferPtr; if ((hRez==640 && (rectWidth & 0x03)) || (hRez==320 && (rectWidth & 0x01))) extraByteAdvance = TRUE; @@ -209,8 +209,8 @@ void HexDispatch (void) { /* If we don't have the next bit of needed data yet, return. */ while (DoReadTCP(bytesNeeded)) { - dataPtr = *(unsigned char **) readBufferHndl; - /* If we're here, readBufferHndl contains bytesNeeded bytes of data. */ + dataPtr = readBufferPtr; + /* If we're here, readBufferPtr contains bytesNeeded bytes of data. */ switch (status) { case hexWaitingForSubencoding: subencoding = *dataPtr; diff --git a/mouse.cc b/mouse.cc index 2abd22c..4ffc8bf 100644 --- a/mouse.cc +++ b/mouse.cc @@ -161,8 +161,8 @@ void DoCursor (void) { if (!DoReadTCP((unsigned long)rectWidth * rectHeight + bitmaskLineBytes * rectHeight)) return; /* Try again later */ - cursorPixels = (unsigned char *)(*readBufferHndl); - bitmask = (unsigned char *)(*readBufferHndl) + (unsigned long)rectWidth * rectHeight; + cursorPixels = readBufferPtr; + bitmask = readBufferPtr + (unsigned long)rectWidth * rectHeight; if (hRez == 640) lineWords = ((unsigned long)rectWidth + 7) / 8 + 1; diff --git a/raw.cc b/raw.cc index eeb14da..a74fd55 100644 --- a/raw.cc +++ b/raw.cc @@ -122,7 +122,7 @@ void RawDraw (void) { if (linesAvailable == 0) { linesAvailable = DoReadMultipleTCP(rectWidth, rectHeight - drawingLine); if (linesAvailable) { - lineDataPtr = (unsigned char *) *readBufferHndl; + lineDataPtr = readBufferPtr; } else { return; } diff --git a/vncdisplay.cc b/vncdisplay.cc index 626db1e..82a7bd7 100644 --- a/vncdisplay.cc +++ b/vncdisplay.cc @@ -228,7 +228,7 @@ static void DoFBUpdate (void) { //printf("Closing in DoFBUpdate\n"); return; } - dataPtr = (unsigned int *) (((char *) (*readBufferHndl)) + 1); + dataPtr = (unsigned int *) (readBufferPtr + 1); numRects = SwapBytes2(dataPtr[0]); /* Get data */ rectX = SwapBytes2(dataPtr[1]); rectY = SwapBytes2(dataPtr[2]); @@ -246,7 +246,7 @@ static void DoSetColourMapEntries (void) { DoWaitingReadTCP(3); DoWaitingReadTCP(2); - numColors = SwapBytes2((unsigned int) **readBufferHndl); + numColors = SwapBytes2(*(unsigned int *)readBufferPtr); skipBytes = 6UL * numColors; } @@ -275,7 +275,7 @@ void NextRect (void) { DoClose(vncWindow); return; } - dataPtr = (unsigned int *) ((char *) (*readBufferHndl)); + dataPtr = (unsigned int *)readBufferPtr; rectX = SwapBytes2(dataPtr[0]); rectY = SwapBytes2(dataPtr[1]); rectWidth = SwapBytes2(dataPtr[2]); @@ -344,7 +344,7 @@ void ConnectedEventLoop (void) { } } else if (DoReadTCP(1)) { /* Read message type byte */ - messageType = ((unsigned char) **readBufferHndl); + messageType = *readBufferPtr; switch (messageType) { case FBUpdate: DoFBUpdate(); break; diff --git a/vncsession.cc b/vncsession.cc index 0f9c000..0c0dee4 100644 --- a/vncsession.cc +++ b/vncsession.cc @@ -54,10 +54,8 @@ segment "VNCview GS"; GrafPortPtr connectStatusWindowPtr = NULL; unsigned int hostIpid; -void ** readBufferHndl; /* Handle to the data read by the last - * DoReadTCP call. Copy this elsewhere if more - * data may be read while it is still in use. - */ +void ** readBufferHndl; /* User internally by TCP read routines. */ +unsigned char *readBufferPtr; /* Ptr to data read by last DoReadTCP call. */ static BOOLEAN alerted = FALSE; static void CloseConnectStatusWindow (void); @@ -340,6 +338,7 @@ static BOOLEAN ReadFixup (unsigned long requested, unsigned long returned) { DisposeHandle(theRRBuff.rrBuffHandle); } while (returned < requested); + readBufferPtr = *readBufferHndl; return TRUE; } @@ -378,6 +377,7 @@ BOOLEAN DoReadTCP (unsigned long dataLength) { return ReadFixup(dataLength, theRRBuff.rrBuffCount); HLock(readBufferHndl); + readBufferPtr = *readBufferHndl; return TRUE; } @@ -417,6 +417,7 @@ static BOOLEAN DoVNCHandshaking (void) { static char versionString[12]; unsigned long reasonLength; char *errorString; + char **errorStringPtr = &errorString; WaitCursor(); DisplayConnectStatus("\pConnecting to VNC server...", FALSE); @@ -425,10 +426,10 @@ static BOOLEAN DoVNCHandshaking (void) { strcpy(versionString, ""); if (! DoWaitingReadTCP(12)) return FALSE; - if ( ! ((strncmp((char *)*readBufferHndl, "RFB ", 4) == 0) && - (strncmp((char *)*readBufferHndl+4, RFBMAJORVERSIONSTR, 3) >= 0) && - (strncmp((char *)*readBufferHndl+7, ".", 1) == 0) && - (strncmp((char *)*readBufferHndl+11, "\n", 1) == 0))) { + if ( ! ((strncmp((char *)readBufferPtr, "RFB ", 4) == 0) && + (strncmp((char *)readBufferPtr+4, RFBMAJORVERSIONSTR, 3) >= 0) && + (strncmp((char *)readBufferPtr+7, ".", 1) == 0) && + (strncmp((char *)readBufferPtr+11, "\n", 1) == 0))) { InitCursor(); AlertWindow(awResource, NULL, badRFBVersionAlert); alerted = TRUE; @@ -446,30 +447,28 @@ static BOOLEAN DoVNCHandshaking (void) { if (! DoWaitingReadTCP(4)) { /* Read authentication type */ return FALSE; } - switch ((unsigned long) (**readBufferHndl)) { + switch (*(unsigned long *) readBufferPtr) { case vncConnectionFailed: if (! DoWaitingReadTCP(4)) return FALSE; if (toolerror()) return FALSE; - reasonLength = SwapBytes4(**readBufferHndl); + reasonLength = SwapBytes4( + *(unsigned long *)readBufferPtr); if (! DoWaitingReadTCP(reasonLength)) return FALSE; if (toolerror()) return FALSE; - HUnlock(readBufferHndl); - SetHandleSize( - GetHandleSize(readBufferHndl)+1, - readBufferHndl); - if (! toolerror()) { - HLock(readBufferHndl); - *((char *) *readBufferHndl+reasonLength) - = 0; - InitCursor(); - AlertWindow(awResource, - (Pointer) readBufferHndl, - connectionFailedAlert); - alerted = TRUE; - } + errorString = calloc(reasonLength + 1, 1); + if (errorString == NULL) + return FALSE; + memcpy(errorString, readBufferPtr, + reasonLength); + InitCursor(); + AlertWindow(awResource, + (Pointer) errorStringPtr, + connectionFailedAlert); + free(errorString); + alerted = TRUE; return FALSE; case vncNoAuthentication: break; case vncVNCAuthentication: if (DoDES()) @@ -569,8 +568,8 @@ static BOOLEAN DoDES (void) { DESAddParity(theKey, &vncPassword[1]); - DESCipher(theResponse, theKey, *(char **)readBufferHndl, modeEncrypt); - DESCipher(&theResponse[8], theKey, *(char **)readBufferHndl+8, modeEncrypt); + DESCipher(theResponse, theKey, (char *)readBufferPtr, modeEncrypt); + DESCipher(&theResponse[8], theKey, (char *)readBufferPtr+8, modeEncrypt); if (TCPIPWriteTCP(hostIpid, theResponse, sizeof(theResponse), TRUE, FALSE)) { @@ -586,18 +585,18 @@ static BOOLEAN DoDES (void) { goto UnloadCrypto; } - if ((**readBufferHndl) == statusOK) { + if (*readBufferPtr == statusOK) { success = TRUE; goto UnloadCrypto; } - else if ((**readBufferHndl) == statusFailed) { + else if (*readBufferPtr == statusFailed) { InitCursor(); AlertWindow(awResource, NULL, authFailedError); alerted = TRUE; success = FALSE; goto UnloadCrypto; } - else if ((**readBufferHndl) == statusTooMany) { + else if (*readBufferPtr == statusTooMany) { InitCursor(); AlertWindow(awResource, NULL, authTooManyError); alerted = TRUE; @@ -695,10 +694,10 @@ static BOOLEAN FinishVNCHandshaking (void) { /* ServerInitialisation */ if (! DoWaitingReadTCP(2)) return FALSE; - fbWidth = SwapBytes2(**(unsigned **)readBufferHndl); + fbWidth = SwapBytes2(*(unsigned *)readBufferPtr); if (! DoWaitingReadTCP(2)) return FALSE; - fbHeight = SwapBytes2(**(unsigned **)readBufferHndl); + fbHeight = SwapBytes2(*(unsigned *)readBufferPtr); if ((fbWidth > 16384) || (fbHeight > 16384)) { AlertWindow(awResource, NULL, screenTooBigError); @@ -710,7 +709,7 @@ static BOOLEAN FinishVNCHandshaking (void) { return FALSE; if (! DoWaitingReadTCP(4)) return FALSE; - serverNameLen = SwapBytes4(**(unsigned long **)readBufferHndl); + serverNameLen = SwapBytes4(*(unsigned long *)readBufferPtr); if (! DoWaitingReadTCP(serverNameLen)) return FALSE; diff --git a/vncsession.h b/vncsession.h index fed9008..4ce3b6e 100644 --- a/vncsession.h +++ b/vncsession.h @@ -16,7 +16,8 @@ extern GrafPortPtr connectStatusWindowPtr; -extern void ** readBufferHndl; +extern void ** readBufferHndl; /* User internally by TCP read routines. */ +extern unsigned char *readBufferPtr; /* Ptr to data read by last DoReadTCP call. */ extern unsigned int hostIpid;