Skip to content

Commit

Permalink
Merge branch 'fix-#242'
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Nov 10, 2018
2 parents af24482 + 495ffa3 commit 162d716
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
14 changes: 12 additions & 2 deletions libvncserver/tightvnc-filetransfer/filetransfermsg.c
Expand Up @@ -672,7 +672,7 @@ ChkFileUploadWriteErr(rfbClientPtr cl, rfbTightClientPtr rtcp, char* pBuf)
char reason[] = "Error writing file data";
int reasonLen = strlen(reason);
ftm = CreateFileUploadErrMsg(reason, reasonLen);
CloseUndoneFileTransfer(cl, rtcp);
CloseUndoneFileUpload(cl, rtcp);
}
return ftm;
}
Expand Down Expand Up @@ -735,7 +735,7 @@ CreateFileUploadErrMsg(char* reason, unsigned int reasonLen)
******************************************************************************/

void
CloseUndoneFileTransfer(rfbClientPtr cl, rfbTightClientPtr rtcp)
CloseUndoneFileUpload(rfbClientPtr cl, rfbTightClientPtr rtcp)
{
/* TODO :: File Upload case is not handled currently */
/* TODO :: In case of concurrency we need to use Critical Section */
Expand All @@ -759,9 +759,19 @@ CloseUndoneFileTransfer(rfbClientPtr cl, rfbTightClientPtr rtcp)

memset(rtcp->rcft.rcfu.fName, 0 , PATH_MAX);
}
}


void
CloseUndoneFileDownload(rfbClientPtr cl, rfbTightClientPtr rtcp)
{
if(cl == NULL)
return;

if(rtcp->rcft.rcfd.downloadInProgress == TRUE) {
rtcp->rcft.rcfd.downloadInProgress = FALSE;
/* the thread will return if downloadInProgress is FALSE */
pthread_join(rtcp->rcft.rcfd.downloadThread, NULL);

if(rtcp->rcft.rcfd.downloadFD != -1) {
close(rtcp->rcft.rcfd.downloadFD);
Expand Down
3 changes: 2 additions & 1 deletion libvncserver/tightvnc-filetransfer/filetransfermsg.h
Expand Up @@ -51,7 +51,8 @@ FileTransferMsg ChkFileUploadWriteErr(rfbClientPtr cl, rfbTightClientPtr data, c

void CreateDirectory(char* dirName);
void FileUpdateComplete(rfbClientPtr cl, rfbTightClientPtr data);
void CloseUndoneFileTransfer(rfbClientPtr cl, rfbTightClientPtr data);
void CloseUndoneFileUpload(rfbClientPtr cl, rfbTightClientPtr data);
void CloseUndoneFileDownload(rfbClientPtr cl, rfbTightClientPtr data);

void FreeFileTransferMsg(FileTransferMsg ftm);

Expand Down
18 changes: 5 additions & 13 deletions libvncserver/tightvnc-filetransfer/handlefiletransferrequest.c
Expand Up @@ -489,12 +489,6 @@ RunFileDownloadThread(void* client)
if(rfbWriteExact(cl, fileDownloadMsg.data, fileDownloadMsg.length) < 0) {
rfbLog("File [%s]: Method [%s]: Error while writing to socket \n"
, __FILE__, __FUNCTION__);

if(cl != NULL) {
rfbCloseClient(cl);
CloseUndoneFileTransfer(cl, rtcp);
}

FreeFileTransferMsg(fileDownloadMsg);
return NULL;
}
Expand All @@ -508,7 +502,6 @@ RunFileDownloadThread(void* client)
void
HandleFileDownload(rfbClientPtr cl, rfbTightClientPtr rtcp)
{
pthread_t fileDownloadThread;
FileTransferMsg fileDownloadMsg;

memset(&fileDownloadMsg, 0, sizeof(FileTransferMsg));
Expand All @@ -518,10 +511,9 @@ HandleFileDownload(rfbClientPtr cl, rfbTightClientPtr rtcp)
FreeFileTransferMsg(fileDownloadMsg);
return;
}
rtcp->rcft.rcfd.downloadInProgress = FALSE;
rtcp->rcft.rcfd.downloadFD = -1;
CloseUndoneFileDownload(cl, rtcp);

if(pthread_create(&fileDownloadThread, NULL, RunFileDownloadThread, (void*)
if(pthread_create(&rtcp->rcft.rcfd.downloadThread, NULL, RunFileDownloadThread, (void*)
cl) != 0) {
FileTransferMsg ftm = GetFileDownLoadErrMsg();

Expand Down Expand Up @@ -593,7 +585,7 @@ HandleFileDownloadCancelRequest(rfbClientPtr cl, rfbTightClientPtr rtcp)
" reason <%s>\n", __FILE__, __FUNCTION__, reason);

pthread_mutex_lock(&fileDownloadMutex);
CloseUndoneFileTransfer(cl, rtcp);
CloseUndoneFileDownload(cl, rtcp);
pthread_mutex_unlock(&fileDownloadMutex);

if(reason != NULL) {
Expand Down Expand Up @@ -836,7 +828,7 @@ HandleFileUploadDataRequest(rfbClientPtr cl, rfbTightClientPtr rtcp)
FreeFileTransferMsg(ftm);
}

CloseUndoneFileTransfer(cl, rtcp);
CloseUndoneFileUpload(cl, rtcp);

if(pBuf != NULL) {
free(pBuf);
Expand Down Expand Up @@ -936,7 +928,7 @@ HandleFileUploadFailedRequest(rfbClientPtr cl, rfbTightClientPtr rtcp)
rfbLog("File [%s]: Method [%s]: File Upload Failed Request received:"
" reason <%s>\n", __FILE__, __FUNCTION__, reason);

CloseUndoneFileTransfer(cl, rtcp);
CloseUndoneFileUpload(cl, rtcp);

if(reason != NULL) {
free(reason);
Expand Down
1 change: 1 addition & 0 deletions libvncserver/tightvnc-filetransfer/rfbtightproto.h
Expand Up @@ -148,6 +148,7 @@ typedef struct _rfbClientFileDownload {
int downloadInProgress;
unsigned long mTime;
int downloadFD;
pthread_t downloadThread;
} rfbClientFileDownload ;

typedef struct _rfbClientFileUpload {
Expand Down
7 changes: 5 additions & 2 deletions libvncserver/tightvnc-filetransfer/rfbtightserver.c
Expand Up @@ -26,6 +26,7 @@
#include <rfb/rfb.h>
#include "rfbtightproto.h"
#include "handlefiletransferrequest.h"
#include "filetransfermsg.h"

/*
* Get my data!
Expand Down Expand Up @@ -448,9 +449,11 @@ rfbTightExtensionMsgHandler(struct _rfbClientRec* cl, void* data,
void
rfbTightExtensionClientClose(rfbClientPtr cl, void* data) {

if(data != NULL)
if(data != NULL) {
CloseUndoneFileUpload(cl, data);
CloseUndoneFileDownload(cl, data);
free(data);

}
}

void
Expand Down

0 comments on commit 162d716

Please sign in to comment.