diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/polarssl.c | 42 | ||||
-rwxr-xr-x | lib/polarsslthreadlock.c | 91 |
2 files changed, 64 insertions, 69 deletions
diff --git a/lib/polarssl.c b/lib/polarssl.c index 5ebccc080..dd78bc690 100644 --- a/lib/polarssl.c +++ b/lib/polarssl.c @@ -87,14 +87,13 @@ static int entropy_init_initialized = 0; /* start of entropy_init_mutex() */ static void entropy_init_mutex(entropy_context *ctx) { - /* lock 0 = entropy_init_mutex() */ - polarsslthreadlock_lock_function(0); - if(entropy_init_initialized == 0) - { - entropy_init(ctx); - entropy_init_initialized = 1; - } - polarsslthreadlock_unlock_function(0); + /* lock 0 = entropy_init_mutex() */ + polarsslthreadlock_lock_function(0); + if(entropy_init_initialized == 0) { + entropy_init(ctx); + entropy_init_initialized = 1; + } + polarsslthreadlock_unlock_function(0); } /* end of entropy_init_mutex() */ @@ -102,12 +101,12 @@ static void entropy_init_mutex(entropy_context *ctx) static int entropy_func_mutex(void *data, unsigned char *output, size_t len) { int ret; - /* lock 1 = entropy_func_mutex() */ + /* lock 1 = entropy_func_mutex() */ polarsslthreadlock_lock_function(1); ret = entropy_func(data, output, len); polarsslthreadlock_unlock_function(1); - - return ret; + + return ret; } /* end of entropy_func_mutex() */ @@ -171,23 +170,23 @@ polarssl_connect_step1(struct connectdata *conn, entropy_init_mutex(&entropy); if((ret = ctr_drbg_init(&connssl->ctr_drbg, entropy_func_mutex, &entropy, - connssl->ssn.id, connssl->ssn.length)) != 0) - { + connssl->ssn.id, connssl->ssn.length)) != 0) { #ifdef POLARSSL_ERROR_C error_strerror(ret, errorbuf, sizeof(errorbuf)); #endif /* POLARSSL_ERROR_C */ - failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n", -ret, errorbuf); + failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n", + -ret, errorbuf); } #else entropy_init(&connssl->entropy); if((ret = ctr_drbg_init(&connssl->ctr_drbg, entropy_func, &connssl->entropy, - connssl->ssn.id, connssl->ssn.length)) != 0) - { + connssl->ssn.id, connssl->ssn.length)) != 0) { #ifdef POLARSSL_ERROR_C error_strerror(ret, errorbuf, sizeof(errorbuf)); #endif /* POLARSSL_ERROR_C */ - failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n", -ret, errorbuf); + failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n", + -ret, errorbuf); } #endif /* THREADING_SUPPORT */ #endif /* POLARSSL_VERSION_NUMBER<0x01010000 */ @@ -354,11 +353,12 @@ polarssl_connect_step2(struct connectdata *conn, else if(ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) { #ifdef POLARSSL_ERROR_C - error_strerror(ret, errorbuf, sizeof(errorbuf)); + error_strerror(ret, errorbuf, sizeof(errorbuf)); #endif /* POLARSSL_ERROR_C */ - failf(data, "ssl_handshake returned - PolarSSL: (-0x%04X) %s", -ret, errorbuf); + failf(data, "ssl_handshake returned - PolarSSL: (-0x%04X) %s", + -ret, errorbuf); - return CURLE_SSL_CONNECT_ERROR; + return CURLE_SSL_CONNECT_ERROR; } else { if(ret == POLARSSL_ERR_NET_WANT_READ) { @@ -699,7 +699,7 @@ int polarssl_init(void) return polarsslthreadlock_thread_setup(); #else /* THREADING_SUPPORT */ return 1; -#endif /* THREADING_SUPPORT */ +#endif /* THREADING_SUPPORT */ } void polarssl_cleanup(void) diff --git a/lib/polarsslthreadlock.c b/lib/polarsslthreadlock.c index c8a3832e3..acef2fea0 100755 --- a/lib/polarsslthreadlock.c +++ b/lib/polarsslthreadlock.c @@ -24,7 +24,8 @@ #include <stdio.h> #include "curl_setup.h" -#if defined(USE_POLARSSL) && (defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)) +#if defined(USE_POLARSSL) && \ + (defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)) #if defined(USE_THREADS_POSIX) #ifdef HAVE_PTHREAD_H @@ -52,23 +53,21 @@ int polarsslthreadlock_thread_setup(void) int ret; mutex_buf = malloc(NUMT * sizeof(MUTEX_TYPE)); - if (!mutex_buf) + if(!mutex_buf) return 0; /* error, no number of threads defined */ #ifdef HAVE_PTHREAD_H - for (i = 0; i < NUMT; i++) - { + for(i = 0; i < NUMT; i++) { ret = pthread_mutex_init(&mutex_buf[i], NULL); - if(ret) - return 0; /* pthread_mutex_init failed */ + if(ret) + return 0; /* pthread_mutex_init failed */ } #elif defined(HAVE_PROCESS_H) - for (i = 0; i < NUMT; i++) - { + for(i = 0; i < NUMT; i++) { mutex_buf[i] = CreateMutex(0, FALSE, 0); - if(mutex_buf[i] == 0) - return 0; /* CreateMutex failed */ - } + if(mutex_buf[i] == 0) + return 0; /* CreateMutex failed */ + } #endif /* HAVE_PTHREAD_H */ return 1; /* OK */ @@ -78,22 +77,22 @@ int polarsslthreadlock_thread_cleanup(void) { int i; int ret; - - if (!mutex_buf) + + if(!mutex_buf) return 0; /* error, no threads locks defined */ #ifdef HAVE_PTHREAD_H - for (i = 0; i < NUMT; i++) - { + for(i = 0; i < NUMT; i++) { ret = pthread_mutex_destroy(&mutex_buf[i]); - if(ret) - return 0; /* pthread_mutex_destroy failed */ + if(ret) + return 0; /* pthread_mutex_destroy failed */ } #elif defined(HAVE_PROCESS_H) - for (i = 0; i < NUMT; i++) + for(i = 0; i < NUMT; i++) { ret = CloseHandle(mutex_buf[i]); if(!ret) - return 0; /* CloseHandle failed */ + return 0; /* CloseHandle failed */ + } #endif /* HAVE_PTHREAD_H */ free(mutex_buf); mutex_buf = NULL; @@ -105,25 +104,23 @@ int polarsslthreadlock_lock_function(int n) { int ret; #ifdef HAVE_PTHREAD_H - if(n < NUMT) - { + if(n < NUMT) { ret = pthread_mutex_lock(&mutex_buf[n]); - if(ret) - { - DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_lock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } + if(ret) { + DEBUGF(fprintf(stderr, + "Error: polarsslthreadlock_lock_function failed\n")); + return 0; /* pthread_mutex_lock failed */ + } } #elif defined(HAVE_PROCESS_H) - if(n < NUMT) - { + if(n < NUMT) { ret = (WaitForSingleObject(mutex_buf[n], INFINITE)==WAIT_FAILED?1:0); - if(ret) - { - DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_lock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } - } + if(ret) { + DEBUGF(fprintf(stderr, + "Error: polarsslthreadlock_lock_function failed\n")); + return 0; /* pthread_mutex_lock failed */ + } + } #endif /* HAVE_PTHREAD_H */ return 1; /* OK */ } @@ -132,24 +129,22 @@ int polarsslthreadlock_unlock_function(int n) { int ret; #ifdef HAVE_PTHREAD_H - if(n < NUMT) - { + if(n < NUMT) { ret = pthread_mutex_unlock(&mutex_buf[n]); - if(ret) - { - DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_unlock_function failed\n")); - return 0; /* pthread_mutex_unlock failed */ - } + if(ret) { + DEBUGF(fprintf(stderr, + "Error: polarsslthreadlock_unlock_function failed\n")); + return 0; /* pthread_mutex_unlock failed */ + } } #elif defined(HAVE_PROCESS_H) - if(n < NUMT) - { + if(n < NUMT) { ret = ReleaseMutex(mutex_buf[n]); - if(!ret) - { - DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_unlock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } + if(!ret) { + DEBUGF(fprintf(stderr, + "Error: polarsslthreadlock_unlock_function failed\n")); + return 0; /* pthread_mutex_lock failed */ + } } #endif /* HAVE_PTHREAD_H */ return 1; /* OK */ |