diff --git a/ftpCommandElaborate.c b/ftpCommandElaborate.c index 515fed9..0f88986 100644 --- a/ftpCommandElaborate.c +++ b/ftpCommandElaborate.c @@ -463,12 +463,17 @@ int parseCommandPasv(ftpDataType * data, int socketId) //if (data->clients[socketId].workerData.threadIsAlive == 1) // { - - returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + if (data->clients[socketId].workerData.threadIsAlive == 1) + { + returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); + } printf("\npasv pthread_cancel = %d", returnCode); //} printf("\npasv join "); - returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + + if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); + printf("\npasv join ok"); data->clients[socketId].workerData.passiveModeOn = 1; data->clients[socketId].workerData.activeModeOn = 0; @@ -498,8 +503,14 @@ int parseCommandPort(ftpDataType * data, int socketId) //if (data->clients[socketId].workerData.threadIsAlive == 1) //{ returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); +<<<<<<< HEAD //} returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); +======= + } + if (data->clients[socketId].workerData.threadHasBeenCreated == 1) + returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); +>>>>>>> cd589876b02918418d1253f35b68349522f82294 data->clients[socketId].workerData.passiveModeOn = 0; data->clients[socketId].workerData.activeModeOn = 1; returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber); @@ -529,8 +540,12 @@ int parseCommandAbor(ftpDataType * data, int socketId) //if (data->clients[socketId].workerData.threadIsAlive == 1) //{ pthread_cancel(data->clients[socketId].workerData.workerThread); +<<<<<<< HEAD //} pthread_join(data->clients[socketId].workerData.workerThread, &pReturn); +======= + } +>>>>>>> cd589876b02918418d1253f35b68349522f82294 returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n"); if (returnCode <= 0) diff --git a/ftpData.c b/ftpData.c index 9a2775b..48b982d 100644 --- a/ftpData.c +++ b/ftpData.c @@ -602,7 +602,8 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization) { DYNV_VectorGeneric_Init(&data->clients[clientId].workerData.directoryInfo); data->clients[clientId].workerData.theStorFile = NULL; - data->clients[clientId].workerData.workerThread = 0; + data->clients[clientId].workerData.threadHasBeenCreated = 0; + } if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0) @@ -639,6 +640,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) if (isInitialization != 1) { +<<<<<<< HEAD if (data->clients[clientId].workerData.threadIsAlive == 1) { void *pReturn; @@ -651,13 +653,25 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) pthread_cancel(data->clients[clientId].workerData.workerThread); pthread_join(data->clients[clientId].workerData.workerThread, &pReturn); } +======= + void *pReturn; + if (data->clients[clientId].workerData.threadIsAlive == 1) + pthread_cancel(data->clients[clientId].workerData.workerThread); +>>>>>>> cd589876b02918418d1253f35b68349522f82294 - pthread_mutex_destroy(&data->clients[clientId].writeMutex); + pthread_mutex_destroy(&data->clients[clientId].writeMutex); +<<<<<<< HEAD #ifdef OPENSSL_ENABLED SSL_free(data->clients[clientId].ssl); SSL_free(data->clients[clientId].workerData.ssl); #endif +======= + #ifdef OPENSSL_ENABLED + SSL_free(data->clients[clientId].ssl); + //SSL_free(data->clients[clientId].workerData.ssl); + #endif +>>>>>>> cd589876b02918418d1253f35b68349522f82294 } if (pthread_mutex_init(&data->clients[clientId].writeMutex, NULL) != 0) @@ -665,6 +679,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization) printf("\nclientData->writeMutex init failed\n"); exit(0); } + data->clients[clientId].tlsIsNegotiating = 0; data->clients[clientId].tlsIsEnabled = 0; data->clients[clientId].dataChannelIsTls = 0; diff --git a/ftpData.h b/ftpData.h index d637850..035b6fc 100644 --- a/ftpData.h +++ b/ftpData.h @@ -125,6 +125,7 @@ struct workerData #endif int threadIsAlive; + int threadHasBeenCreated; int connectionPort; int passiveModeOn; int activeModeOn; diff --git a/ftpServer.c b/ftpServer.c index 9251396..5376d4d 100644 --- a/ftpServer.c +++ b/ftpServer.c @@ -602,7 +602,7 @@ void runFtpServer(void) returnCode = socketPrintf(&ftpData, processingSock, "s", "500 Unknown command\r\n"); if (returnCode < 0) { - ftpData.clients[processingSock].closeTheClient = 1; + ftpData.clients[processingSock].closeTheClient = 1; } printf("\n COMMAND NOT SUPPORTED ********* %s", ftpData.clients[processingSock].buffer); } diff --git a/library/connection.c b/library/connection.c index dbc3984..4b3b2d9 100644 --- a/library/connection.c +++ b/library/connection.c @@ -460,6 +460,7 @@ void closeClient(ftpDataType * ftpData, int processingSocket) { printf("\nQUIT FLAG SET!\n"); +<<<<<<< HEAD // if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) // { void *pReturn; @@ -467,6 +468,15 @@ void closeClient(ftpDataType * ftpData, int processingSocket) pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); printf("\nQuit command received the Pasv Thread has been cancelled."); // } +======= + if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) + { + void *pReturn; + pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); + //pthread_join(ftpData->clients[processingSocket].workerData.workerThread, &pReturn); + printf("\nQuit command received the Pasv Thread has been cancelled."); + } +>>>>>>> cd589876b02918418d1253f35b68349522f82294 FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll); FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.wsetAll); @@ -630,7 +640,7 @@ int evaluateClientSocketConnection(ftpDataType * ftpData) //Errors while accepting, socket will be closed ftpData->clients[availableSocketIndex].closeTheClient = 1; printf("\n2 Errno = %d", errno); - return 1; + return 0; } } else