mirror of
https://github.com/kingk85/uFTP.git
synced 2025-08-02 14:57:31 +03:00
working on threads
This commit is contained in:
@ -495,10 +495,10 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
||||
returnCode = snprintf(data->clients[socketId].workerData.activeIpAddress, CLIENT_BUFFER_STRING_SIZE, "%d.%d.%d.%d", ipAddressBytes[0],ipAddressBytes[1],ipAddressBytes[2],ipAddressBytes[3]);
|
||||
|
||||
void *pReturn;
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
//if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
//{
|
||||
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
}
|
||||
//}
|
||||
returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
data->clients[socketId].workerData.passiveModeOn = 0;
|
||||
data->clients[socketId].workerData.activeModeOn = 1;
|
||||
@ -526,10 +526,10 @@ int parseCommandAbor(ftpDataType * data, int socketId)
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
void *pReturn;
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
//if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
//{
|
||||
pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
}
|
||||
//}
|
||||
pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
|
||||
returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n");
|
||||
@ -596,7 +596,7 @@ int parseCommandList(ftpDataType * data, int socketId)
|
||||
setDynamicStringDataType(&data->clients[socketId].listPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex);
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
@ -627,7 +627,7 @@ int parseCommandNlst(ftpDataType * data, int socketId)
|
||||
setDynamicStringDataType(&data->clients[socketId].nlistPath, data->clients[socketId].login.absolutePath.text, data->clients[socketId].login.absolutePath.textLen);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex);
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
@ -652,7 +652,7 @@ int parseCommandRetr(ftpDataType * data, int socketId)
|
||||
if (isSafePath == 1 &&
|
||||
FILE_IsFile(data->clients[socketId].fileToRetr.text) == 1)
|
||||
{
|
||||
pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex);
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
@ -682,7 +682,7 @@ int parseCommandStor(ftpDataType * data, int socketId)
|
||||
|
||||
if (isSafePath == 1)
|
||||
{
|
||||
pthread_mutex_lock(&data->clients[socketId].workerData.conditionMutex);
|
||||
pthread_mutex_trylock(&data->clients[socketId].workerData.conditionMutex);
|
||||
memset(data->clients[socketId].workerData.theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||
strcpy(data->clients[socketId].workerData.theCommandReceived, data->clients[socketId].theCommandReceived);
|
||||
data->clients[socketId].workerData.commandReceived = 1;
|
||||
|
@ -627,6 +627,7 @@ void resetWorkerData(ftpDataType *data, int clientId, int isInitialization)
|
||||
data->clients[clientId].workerData.directoryInfo.Destroy(&data->clients[clientId].workerData.directoryInfo, deleteListDataInfoVector);
|
||||
free(lastToDestroy);
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
data->clients[clientId].workerData.serverSsl = SSL_new(data->serverCtx);
|
||||
data->clients[clientId].workerData.clientSsl = SSL_new(data->clientCtx);
|
||||
@ -647,6 +648,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
|
||||
else
|
||||
{
|
||||
void *pReturn = NULL;
|
||||
pthread_cancel(data->clients[clientId].workerData.workerThread);
|
||||
pthread_join(data->clients[clientId].workerData.workerThread, &pReturn);
|
||||
}
|
||||
|
||||
@ -654,7 +656,7 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
|
||||
|
||||
#ifdef OPENSSL_ENABLED
|
||||
SSL_free(data->clients[clientId].ssl);
|
||||
//SSL_free(data->clients[clientId].workerData.ssl);
|
||||
SSL_free(data->clients[clientId].workerData.ssl);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ void runFtpServer(void)
|
||||
//Debug print errors
|
||||
if (ftpData.clients[processingSock].bufferIndex < 0)
|
||||
{
|
||||
ftpData.clients[processingSock].closeTheClient = 1;
|
||||
//ftpData.clients[processingSock].closeTheClient = 1;
|
||||
printf("\n1 Errno = %d", errno);
|
||||
perror("1 Error: ");
|
||||
continue;
|
||||
|
@ -460,13 +460,13 @@ void closeClient(ftpDataType * ftpData, int processingSocket)
|
||||
{
|
||||
printf("\nQUIT FLAG SET!\n");
|
||||
|
||||
if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1)
|
||||
{
|
||||
// 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.");
|
||||
}
|
||||
// }
|
||||
|
||||
FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll);
|
||||
FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.wsetAll);
|
||||
|
@ -8,6 +8,7 @@ sudo apt-get install libssl-dev
|
||||
#Remove password from a certificate
|
||||
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
|
||||
openssl rsa -in key.pem -out newkey.pem
|
||||
handle SIGPIPE nostop noprint pass
|
||||
|
||||
|
||||
#Testing ssl
|
||||
|
Reference in New Issue
Block a user