summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2013-07-26 16:15:19 +0000
committerjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2013-07-26 16:15:19 +0000
commit817a72f57f1fccf15580cac6530dd2d9c37c4510 (patch)
tree1b5b52ca2d450264ac8c592c8994e728e6faa2a8
parent7d94e4addd2cc8929407a94c319e3dd62a0ad493 (diff)
downloadneon-817a72f57f1fccf15580cac6530dd2d9c37c4510.tar.gz
* config.hw.in, src/ne_openssl.c: Add thread-safety support for SSL on Windows.
git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@1901 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
-rw-r--r--config.hw.in2
-rw-r--r--src/ne_openssl.c26
2 files changed, 28 insertions, 0 deletions
diff --git a/config.hw.in b/config.hw.in
index c2d7204..56e5cee 100644
--- a/config.hw.in
+++ b/config.hw.in
@@ -39,6 +39,8 @@
#define HAVE_SSPI
+#define NE_HAVE_TS_SSL 1
+
/* Define to enable debugging */
#define NE_DEBUGGING 1
diff --git a/src/ne_openssl.c b/src/ne_openssl.c
index 2eac8fc..f8350fa 100644
--- a/src/ne_openssl.c
+++ b/src/ne_openssl.c
@@ -38,8 +38,10 @@
#ifdef NE_HAVE_TS_SSL
#include <stdlib.h> /* for abort() */
+#ifndef _WIN32
#include <pthread.h>
#endif
+#endif
#include "ne_ssl.h"
#include "ne_string.h"
@@ -1131,17 +1133,25 @@ int ne_ssl_cert_digest(const ne_ssl_certificate *cert, char *digest)
* it's necessary to cast from a pthread_t to an unsigned long at some
* point. */
+#ifndef _WIN32
static pthread_mutex_t *locks;
+#else
+static HANDLE *locks;
+#endif
static size_t num_locks;
#ifndef HAVE_CRYPTO_SET_IDPTR_CALLBACK
/* Named to be obvious when it shows up in a backtrace. */
static unsigned long thread_id_neon(void)
{
+#ifndef _WIN32
/* This will break if pthread_t is a structure; upgrading OpenSSL
* >= 0.9.9 (which does not require this callback) is the only
* solution. */
return (unsigned long) pthread_self();
+#else
+ return (unsigned long) GetCurrentThreadId();
+#endif
}
#endif
@@ -1150,12 +1160,20 @@ static unsigned long thread_id_neon(void)
static void thread_lock_neon(int mode, int n, const char *file, int line)
{
if (mode & CRYPTO_LOCK) {
+#ifndef _WIN32
if (pthread_mutex_lock(&locks[n])) {
+#else
+ if (WaitForSingleObject(locks[n], INFINITE)) {
+#endif
abort();
}
}
else {
+#ifndef _WIN32
if (pthread_mutex_unlock(&locks[n])) {
+#else
+ if (!ReleaseMutex(locks[n])) {
+#endif
abort();
}
}
@@ -1204,7 +1222,11 @@ int ne__ssl_init(void)
locks = malloc(num_locks * sizeof *locks);
for (n = 0; n < num_locks; n++) {
+#ifndef _WIN32
if (pthread_mutex_init(&locks[n], NULL)) {
+#else
+ if ((locks[n] = CreateMutex(NULL, FALSE, NULL)) == NULL) {
+#endif
NE_DEBUG(NE_DBG_SOCKET, "ssl: Failed to initialize pthread mutex.\n");
return -1;
}
@@ -1237,7 +1259,11 @@ void ne__ssl_exit(void)
CRYPTO_set_locking_callback(NULL);
for (n = 0; n < num_locks; n++) {
+#ifndef _WIN32
pthread_mutex_destroy(&locks[n]);
+#else
+ CloseHandle(locks[n]);
+#endif
}
free(locks);