mirror of
https://github.com/kingk85/uFTP.git
synced 2025-07-25 13:16:12 +03:00
thread open ssl working
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/uFTP
BIN
build/uFTP
Binary file not shown.
@ -459,22 +459,21 @@ int parseCommandPasv(ftpDataType * data, int socketId)
|
||||
/* Create worker thread */
|
||||
void *pReturn;
|
||||
int returnCode;
|
||||
printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
|
||||
//printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
|
||||
|
||||
//if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
// {
|
||||
printf("\n data->clients[%d].workerData.threadHasBeenCreated = %d", socketId, data->clients[socketId].workerData.threadHasBeenCreated);
|
||||
if (data->clients[socketId].workerData.threadIsAlive == 1)
|
||||
{
|
||||
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
printf("\npasv pthread_cancel = %d", returnCode);
|
||||
}
|
||||
printf("\npasv pthread_cancel = %d", returnCode);
|
||||
//}
|
||||
printf("\npasv join ");
|
||||
|
||||
if (data->clients[socketId].workerData.threadHasBeenCreated == 1)
|
||||
{
|
||||
returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
printf("\nPasv join ok %d", returnCode);
|
||||
}
|
||||
|
||||
printf("\npasv join ok");
|
||||
data->clients[socketId].workerData.passiveModeOn = 1;
|
||||
data->clients[socketId].workerData.activeModeOn = 0;
|
||||
returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber);
|
||||
@ -505,7 +504,9 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
||||
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
|
||||
}
|
||||
if (data->clients[socketId].workerData.threadHasBeenCreated == 1)
|
||||
{
|
||||
returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
|
||||
}
|
||||
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);
|
||||
|
@ -603,7 +603,6 @@ 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.threadHasBeenCreated = 0;
|
||||
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&data->clients[clientId].workerData.conditionMutex, NULL) != 0)
|
||||
|
@ -119,6 +119,7 @@ void *connectionWorkerHandle(void * socketId)
|
||||
int theSocketId = *(int *)socketId;
|
||||
pthread_cleanup_push(workerCleanup, (void *) &theSocketId);
|
||||
ftpData.clients[theSocketId].workerData.threadIsAlive = 1;
|
||||
ftpData.clients[theSocketId].workerData.threadHasBeenCreated = 1;
|
||||
int returnCode;
|
||||
|
||||
printf("\nWORKER CREATED!");
|
||||
@ -505,7 +506,7 @@ void runFtpServer(void)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* no data to check client is not connected, continue to check other clients */
|
||||
if (isClientConnected(&ftpData, processingSock) == 0)
|
||||
{
|
||||
|
@ -630,7 +630,7 @@ int evaluateClientSocketConnection(ftpDataType * ftpData)
|
||||
//Errors while accepting, socket will be closed
|
||||
ftpData->clients[availableSocketIndex].closeTheClient = 1;
|
||||
printf("\n2 Errno = %d", errno);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -644,14 +644,9 @@ int evaluateClientSocketConnection(ftpDataType * ftpData)
|
||||
write(socketRefuseFd, messageToWrite, strlen(messageToWrite));
|
||||
shutdown(socketRefuseFd, SHUT_RDWR);
|
||||
close(socketRefuseFd);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftpData->clients[availableSocketIndex].closeTheClient = 1;
|
||||
printf("\n3 Errno = %d", errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -33,6 +33,19 @@
|
||||
#include "openSsl.h"
|
||||
#include "fileManagement.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define MUTEX_TYPE pthread_mutex_t
|
||||
#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL)
|
||||
#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x))
|
||||
#define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#define THREAD_ID pthread_self()
|
||||
|
||||
/* This array will store all of the mutexes available to OpenSSL. */
|
||||
static MUTEX_TYPE *mutex_buf = NULL;
|
||||
|
||||
void initOpenssl()
|
||||
{
|
||||
OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */
|
||||
@ -40,11 +53,14 @@ void initOpenssl()
|
||||
ERR_load_BIO_strings();
|
||||
ERR_load_crypto_strings();
|
||||
SSL_library_init();
|
||||
thread_setup();
|
||||
}
|
||||
|
||||
void cleanupOpenssl()
|
||||
{
|
||||
thread_cleanup();
|
||||
EVP_cleanup();
|
||||
|
||||
}
|
||||
|
||||
SSL_CTX *createServerContext()
|
||||
@ -162,4 +178,54 @@ void ShowCerts(SSL* ssl)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void handle_error(const char *file, int lineno, const char *msg)
|
||||
{
|
||||
fprintf(stderr, "** %s:%d %s\n", file, lineno, msg);
|
||||
ERR_print_errors_fp(stderr);
|
||||
/* exit(-1); */
|
||||
}
|
||||
|
||||
static void locking_function(int mode, int n, const char *file, int line)
|
||||
{
|
||||
if(mode & CRYPTO_LOCK)
|
||||
MUTEX_LOCK(mutex_buf[n]);
|
||||
else
|
||||
MUTEX_UNLOCK(mutex_buf[n]);
|
||||
}
|
||||
|
||||
static unsigned long id_function(void)
|
||||
{
|
||||
return ((unsigned long)THREAD_ID);
|
||||
}
|
||||
|
||||
int thread_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE));
|
||||
if(!mutex_buf)
|
||||
return 0;
|
||||
for(i = 0; i < CRYPTO_num_locks(); i++)
|
||||
MUTEX_SETUP(mutex_buf[i]);
|
||||
CRYPTO_set_id_callback(id_function);
|
||||
CRYPTO_set_locking_callback(locking_function);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int thread_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(!mutex_buf)
|
||||
return 0;
|
||||
CRYPTO_set_id_callback(NULL);
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
for(i = 0; i < CRYPTO_num_locks(); i++)
|
||||
MUTEX_CLEANUP(mutex_buf[i]);
|
||||
free(mutex_buf);
|
||||
mutex_buf = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user