aboutsummaryrefslogtreecommitdiff
path: root/src/lib/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/init.c')
-rw-r--r--src/lib/init.c107
1 files changed, 14 insertions, 93 deletions
diff --git a/src/lib/init.c b/src/lib/init.c
index 8ca5cd28..d3965763 100644
--- a/src/lib/init.c
+++ b/src/lib/init.c
@@ -21,78 +21,17 @@
21 * @file lib/init.c 21 * @file lib/init.c
22 * @brief initialization routines 22 * @brief initialization routines
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 * TODO: most of this is only required for gcrypt/GNUtls,
26 * should probably be moved to TLS plugin!
27 */ 24 */
28#include "internal.h" 25#include "internal.h"
29#include "init.h" 26#include "init.h"
30 27
31 28
32#ifdef MHD_HTTPS_REQUIRE_GRYPT
33#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
34#if defined(MHD_USE_POSIX_THREADS)
35GCRY_THREAD_OPTION_PTHREAD_IMPL;
36#elif defined(MHD_W32_MUTEX_)
37
38static int
39gcry_w32_mutex_init (void **ppmtx)
40{
41 *ppmtx = malloc (sizeof (MHD_mutex_));
42
43 if (NULL == *ppmtx)
44 return ENOMEM;
45 if (!MHD_mutex_init_ ((MHD_mutex_*)*ppmtx))
46 {
47 free (*ppmtx);
48 *ppmtx = NULL;
49 return EPERM;
50 }
51
52 return 0;
53}
54
55
56static int
57gcry_w32_mutex_destroy (void **ppmtx)
58{
59 int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : EINVAL;
60 free (*ppmtx);
61 return res;
62}
63
64
65static int
66gcry_w32_mutex_lock (void **ppmtx)
67{
68 return MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL;
69}
70
71
72static int
73gcry_w32_mutex_unlock (void **ppmtx)
74{
75 return MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL;
76}
77
78
79static struct gcry_thread_cbs gcry_threads_w32 = {
80 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
81 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
82 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
83 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
84
85#endif /* defined(MHD_W32_MUTEX_) */
86#endif /* HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 */
87#endif /* MHD_HTTPS_REQUIRE_GRYPT */
88
89
90#ifndef _AUTOINIT_FUNCS_ARE_SUPPORTED 29#ifndef _AUTOINIT_FUNCS_ARE_SUPPORTED
91
92/** 30/**
93 * Track global initialisation 31 * Track global initialisation
94 */ 32 */
95volatile int global_init_count = 0; 33volatile unsigned int global_init_count = 0;
34
96#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 35#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
97/** 36/**
98 * Global initialisation mutex 37 * Global initialisation mutex
@@ -153,10 +92,10 @@ mhd_panic_std (void *cls,
153 92
154 93
155/** 94/**
156 * Initialize do setup work. 95 * Globally initialize library.
157 */ 96 */
158void 97void
159MHD_init(void) 98MHD_init (void)
160{ 99{
161#if defined(_WIN32) && ! defined(__CYGWIN__) 100#if defined(_WIN32) && ! defined(__CYGWIN__)
162 WSADATA wsd; 101 WSADATA wsd;
@@ -166,50 +105,32 @@ MHD_init(void)
166 mhd_panic = &mhd_panic_std; 105 mhd_panic = &mhd_panic_std;
167 106
168#if defined(_WIN32) && ! defined(__CYGWIN__) 107#if defined(_WIN32) && ! defined(__CYGWIN__)
169 if (0 != WSAStartup(MAKEWORD(2, 2), &wsd)) 108 if (0 != WSAStartup (MAKEWORD(2, 2),
109 &wsd))
170 MHD_PANIC (_("Failed to initialize winsock\n")); 110 MHD_PANIC (_("Failed to initialize winsock\n"));
171 mhd_winsock_inited_ = 1; 111 mhd_winsock_inited_ = 1;
172 if (2 != LOBYTE(wsd.wVersion) && 2 != HIBYTE(wsd.wVersion)) 112 if ( (2 != LOBYTE(wsd.wVersion)) &&
113 (2 != HIBYTE(wsd.wVersion)) )
173 MHD_PANIC (_("Winsock version 2.2 is not available\n")); 114 MHD_PANIC (_("Winsock version 2.2 is not available\n"));
174#endif 115#endif
175#ifdef HTTPS_SUPPORT 116 MHD_monotonic_sec_counter_init ();
176#ifdef MHD_HTTPS_REQUIRE_GRYPT
177#if GCRYPT_VERSION_NUMBER < 0x010600
178#if defined(MHD_USE_POSIX_THREADS)
179 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
180 &gcry_threads_pthread))
181 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n"));
182#elif defined(MHD_W32_MUTEX_)
183 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
184 &gcry_threads_w32))
185 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n"));
186#endif /* defined(MHD_W32_MUTEX_) */
187 gcry_check_version (NULL);
188#else
189 if (NULL == gcry_check_version ("1.6.0"))
190 MHD_PANIC (_("libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n"));
191#endif
192#endif /* MHD_HTTPS_REQUIRE_GRYPT */
193 gnutls_global_init ();
194#endif /* HTTPS_SUPPORT */
195 MHD_monotonic_sec_counter_init();
196#ifdef HAVE_FREEBSD_SENDFILE 117#ifdef HAVE_FREEBSD_SENDFILE
197 MHD_conn_init_static_ (); 118 MHD_conn_init_static_ ();
198#endif /* HAVE_FREEBSD_SENDFILE */ 119#endif /* HAVE_FREEBSD_SENDFILE */
199} 120}
200 121
201 122
123/**
124 * Global teardown work.
125 */
202void 126void
203MHD_fini(void) 127MHD_fini (void)
204{ 128{
205#ifdef HTTPS_SUPPORT
206 gnutls_global_deinit ();
207#endif /* HTTPS_SUPPORT */
208#if defined(_WIN32) && ! defined(__CYGWIN__) 129#if defined(_WIN32) && ! defined(__CYGWIN__)
209 if (mhd_winsock_inited_) 130 if (mhd_winsock_inited_)
210 WSACleanup(); 131 WSACleanup();
211#endif 132#endif
212 MHD_monotonic_sec_counter_finish(); 133 MHD_monotonic_sec_counter_finish ();
213} 134}
214 135
215#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED 136#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED