diff options
Diffstat (limited to 'src/gnutls/init.c')
-rw-r--r-- | src/gnutls/init.c | 73 |
1 files changed, 8 insertions, 65 deletions
diff --git a/src/gnutls/init.c b/src/gnutls/init.c index 8ca5cd28..3dd656b1 100644 --- a/src/gnutls/init.c +++ b/src/gnutls/init.c | |||
@@ -18,12 +18,9 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @file lib/init.c | 21 | * @file gnutls/init.c |
22 | * @brief initialization routines | 22 | * @brief gnutls-specific 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" |
@@ -35,6 +32,7 @@ | |||
35 | GCRY_THREAD_OPTION_PTHREAD_IMPL; | 32 | GCRY_THREAD_OPTION_PTHREAD_IMPL; |
36 | #elif defined(MHD_W32_MUTEX_) | 33 | #elif defined(MHD_W32_MUTEX_) |
37 | 34 | ||
35 | |||
38 | static int | 36 | static int |
39 | gcry_w32_mutex_init (void **ppmtx) | 37 | gcry_w32_mutex_init (void **ppmtx) |
40 | { | 38 | { |
@@ -42,13 +40,12 @@ gcry_w32_mutex_init (void **ppmtx) | |||
42 | 40 | ||
43 | if (NULL == *ppmtx) | 41 | if (NULL == *ppmtx) |
44 | return ENOMEM; | 42 | return ENOMEM; |
45 | if (!MHD_mutex_init_ ((MHD_mutex_*)*ppmtx)) | 43 | if (! MHD_mutex_init_ ((MHD_mutex_*)*ppmtx)) |
46 | { | 44 | { |
47 | free (*ppmtx); | 45 | free (*ppmtx); |
48 | *ppmtx = NULL; | 46 | *ppmtx = NULL; |
49 | return EPERM; | 47 | return EPERM; |
50 | } | 48 | } |
51 | |||
52 | return 0; | 49 | return 0; |
53 | } | 50 | } |
54 | 51 | ||
@@ -108,7 +105,7 @@ MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); | |||
108 | * and call initialiser if necessary. | 105 | * and call initialiser if necessary. |
109 | */ | 106 | */ |
110 | void | 107 | void |
111 | MHD_check_global_init_ (void) | 108 | MHD_TLS_check_global_init_ (void) |
112 | { | 109 | { |
113 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ | 110 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ |
114 | MHD_mutex_lock_chk_(&global_init_mutex_); | 111 | MHD_mutex_lock_chk_(&global_init_mutex_); |
@@ -122,57 +119,15 @@ MHD_check_global_init_ (void) | |||
122 | 119 | ||
123 | 120 | ||
124 | /** | 121 | /** |
125 | * Default implementation of the panic function, | ||
126 | * prints an error message and aborts. | ||
127 | * | ||
128 | * @param cls unused | ||
129 | * @param file name of the file with the problem | ||
130 | * @param line line number with the problem | ||
131 | * @param reason error message with details | ||
132 | */ | ||
133 | static void | ||
134 | mhd_panic_std (void *cls, | ||
135 | const char *file, | ||
136 | unsigned int line, | ||
137 | const char *reason) | ||
138 | { | ||
139 | (void)cls; /* Mute compiler warning. */ | ||
140 | #ifdef HAVE_MESSAGES | ||
141 | fprintf (stderr, | ||
142 | _("Fatal error in GNU libmicrohttpd %s:%u: %s\n"), | ||
143 | file, | ||
144 | line, | ||
145 | reason); | ||
146 | #else /* ! HAVE_MESSAGES */ | ||
147 | (void)file; /* Mute compiler warning. */ | ||
148 | (void)line; /* Mute compiler warning. */ | ||
149 | (void)reason; /* Mute compiler warning. */ | ||
150 | #endif | ||
151 | abort (); | ||
152 | } | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Initialize do setup work. | 122 | * Initialize do setup work. |
157 | */ | 123 | */ |
158 | void | 124 | void |
159 | MHD_init(void) | 125 | MHD_TLS_init (void) |
160 | { | 126 | { |
161 | #if defined(_WIN32) && ! defined(__CYGWIN__) | 127 | #if defined(_WIN32) && ! defined(__CYGWIN__) |
162 | WSADATA wsd; | 128 | WSADATA wsd; |
163 | #endif /* _WIN32 && ! __CYGWIN__ */ | 129 | #endif /* _WIN32 && ! __CYGWIN__ */ |
164 | 130 | ||
165 | if (NULL == mhd_panic) | ||
166 | mhd_panic = &mhd_panic_std; | ||
167 | |||
168 | #if defined(_WIN32) && ! defined(__CYGWIN__) | ||
169 | if (0 != WSAStartup(MAKEWORD(2, 2), &wsd)) | ||
170 | MHD_PANIC (_("Failed to initialize winsock\n")); | ||
171 | mhd_winsock_inited_ = 1; | ||
172 | if (2 != LOBYTE(wsd.wVersion) && 2 != HIBYTE(wsd.wVersion)) | ||
173 | MHD_PANIC (_("Winsock version 2.2 is not available\n")); | ||
174 | #endif | ||
175 | #ifdef HTTPS_SUPPORT | ||
176 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 131 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
177 | #if GCRYPT_VERSION_NUMBER < 0x010600 | 132 | #if GCRYPT_VERSION_NUMBER < 0x010600 |
178 | #if defined(MHD_USE_POSIX_THREADS) | 133 | #if defined(MHD_USE_POSIX_THREADS) |
@@ -191,27 +146,15 @@ MHD_init(void) | |||
191 | #endif | 146 | #endif |
192 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 147 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
193 | gnutls_global_init (); | 148 | gnutls_global_init (); |
194 | #endif /* HTTPS_SUPPORT */ | ||
195 | MHD_monotonic_sec_counter_init(); | ||
196 | #ifdef HAVE_FREEBSD_SENDFILE | ||
197 | MHD_conn_init_static_ (); | ||
198 | #endif /* HAVE_FREEBSD_SENDFILE */ | ||
199 | } | 149 | } |
200 | 150 | ||
201 | 151 | ||
202 | void | 152 | void |
203 | MHD_fini(void) | 153 | MHD_TLS_fini(void) |
204 | { | 154 | { |
205 | #ifdef HTTPS_SUPPORT | ||
206 | gnutls_global_deinit (); | 155 | gnutls_global_deinit (); |
207 | #endif /* HTTPS_SUPPORT */ | ||
208 | #if defined(_WIN32) && ! defined(__CYGWIN__) | ||
209 | if (mhd_winsock_inited_) | ||
210 | WSACleanup(); | ||
211 | #endif | ||
212 | MHD_monotonic_sec_counter_finish(); | ||
213 | } | 156 | } |
214 | 157 | ||
215 | #ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED | 158 | #ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED |
216 | _SET_INIT_AND_DEINIT_FUNCS(MHD_init, MHD_fini); | 159 | _SET_INIT_AND_DEINIT_FUNCS(MHD_TLS_init, MHD_TLS_fini); |
217 | #endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */ | 160 | #endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */ |