diff options
-rw-r--r-- | doc/examples/largepost.c | 4 | ||||
-rw-r--r-- | src/examples/chunked_example.c | 35 | ||||
-rw-r--r-- | src/examples/demo.c | 6 | ||||
-rw-r--r-- | src/examples/https_fileserver_example.c | 42 | ||||
-rw-r--r-- | src/examples/post_example.c | 22 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 7 | ||||
-rw-r--r-- | src/microhttpd/response.c | 8 | ||||
-rw-r--r-- | src/microhttpd/test_shutdown_select.c | 7 | ||||
-rw-r--r-- | src/testcurl/https/test_https_session_info.c | 4 | ||||
-rw-r--r-- | src/testcurl/https/test_tls_extensions.c | 4 | ||||
-rw-r--r-- | src/testcurl/https/test_tls_options.c | 7 | ||||
-rw-r--r-- | src/testcurl/https/tls_test_common.c | 82 | ||||
-rw-r--r-- | src/testcurl/https/tls_test_common.h | 27 | ||||
-rw-r--r-- | src/testcurl/test_callback.c | 14 | ||||
-rw-r--r-- | src/testcurl/test_get_chunked.c | 45 |
15 files changed, 208 insertions, 106 deletions
diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c index af6a48dd..8ef7c9fe 100644 --- a/doc/examples/largepost.c +++ b/doc/examples/largepost.c | |||
@@ -151,7 +151,9 @@ iterate_post (void *coninfo_cls, | |||
151 | con_info->answercode = MHD_HTTP_FORBIDDEN; | 151 | con_info->answercode = MHD_HTTP_FORBIDDEN; |
152 | return MHD_YES; | 152 | return MHD_YES; |
153 | } | 153 | } |
154 | 154 | /* NOTE: This is technically a race with the 'fopen()' above, | |
155 | but there is no easy fix, short of moving to open(O_EXCL) | ||
156 | instead of using fopen(). For the example, we do not care. */ | ||
155 | con_info->fp = fopen (filename, "ab"); | 157 | con_info->fp = fopen (filename, "ab"); |
156 | if (!con_info->fp) | 158 | if (!con_info->fp) |
157 | { | 159 | { |
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c index a661216c..9bf73e34 100644 --- a/src/examples/chunked_example.c +++ b/src/examples/chunked_example.c | |||
@@ -32,6 +32,7 @@ struct ResponseContentCallbackParam | |||
32 | size_t response_size; | 32 | size_t response_size; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | |||
35 | static ssize_t | 36 | static ssize_t |
36 | callback (void *cls, | 37 | callback (void *cls, |
37 | uint64_t pos, | 38 | uint64_t pos, |
@@ -77,12 +78,14 @@ callback (void *cls, | |||
77 | return size_to_copy; | 78 | return size_to_copy; |
78 | } | 79 | } |
79 | 80 | ||
80 | void | 81 | |
81 | free_callback_param(void *cls) | 82 | static void |
83 | free_callback_param (void *cls) | ||
82 | { | 84 | { |
83 | free(cls); | 85 | free(cls); |
84 | } | 86 | } |
85 | 87 | ||
88 | |||
86 | static const char simple_response_text[] = "<html><head><title>Simple response</title></head>" | 89 | static const char simple_response_text[] = "<html><head><title>Simple response</title></head>" |
87 | "<body>Simple response text</body></html>"; | 90 | "<body>Simple response text</body></html>"; |
88 | 91 | ||
@@ -93,10 +96,12 @@ ahc_echo (void *cls, | |||
93 | const char *url, | 96 | const char *url, |
94 | const char *method, | 97 | const char *method, |
95 | const char *version, | 98 | const char *version, |
96 | const char *upload_data, size_t *upload_data_size, void **ptr) | 99 | const char *upload_data, |
100 | size_t *upload_data_size, | ||
101 | void **ptr) | ||
97 | { | 102 | { |
98 | static int aptr; | 103 | static int aptr; |
99 | struct ResponseContentCallbackParam * callback_param; | 104 | struct ResponseContentCallbackParam *callback_param; |
100 | struct MHD_Response *response; | 105 | struct MHD_Response *response; |
101 | int ret; | 106 | int ret; |
102 | (void)cls; /* Unused. Silent compiler warning. */ | 107 | (void)cls; /* Unused. Silent compiler warning. */ |
@@ -127,31 +132,47 @@ ahc_echo (void *cls, | |||
127 | &callback, | 132 | &callback, |
128 | callback_param, | 133 | callback_param, |
129 | &free_callback_param); | 134 | &free_callback_param); |
135 | if (NULL == response) | ||
136 | { | ||
137 | free (callback_param); | ||
138 | return MHD_NO; | ||
139 | } | ||
130 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 140 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
131 | MHD_destroy_response (response); | 141 | MHD_destroy_response (response); |
132 | return ret; | 142 | return ret; |
133 | } | 143 | } |
134 | 144 | ||
145 | |||
135 | int | 146 | int |
136 | main (int argc, char *const *argv) | 147 | main (int argc, char *const *argv) |
137 | { | 148 | { |
138 | struct MHD_Daemon *d; | 149 | struct MHD_Daemon *d; |
150 | int port; | ||
139 | 151 | ||
140 | if (argc != 2) | 152 | if (argc != 2) |
141 | { | 153 | { |
142 | printf ("%s PORT\n", argv[0]); | 154 | printf ("%s PORT\n", argv[0]); |
143 | return 1; | 155 | return 1; |
144 | } | 156 | } |
157 | port = atoi (argv[1]); | ||
158 | if ( (1 > port) || | ||
159 | (port > UINT16_MAX) ) | ||
160 | { | ||
161 | fprintf (stderr, | ||
162 | "Port must be a number between 1 and 65535\n"); | ||
163 | return 1; | ||
164 | } | ||
145 | d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 165 | d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
146 | MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 166 | MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
147 | // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, | 167 | // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, |
148 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, | 168 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, |
149 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 169 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
150 | atoi (argv[1]), | 170 | (uint16_t) port, |
151 | NULL, NULL, &ahc_echo, NULL, | 171 | NULL, NULL, |
172 | &ahc_echo, NULL, | ||
152 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, | 173 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, |
153 | MHD_OPTION_END); | 174 | MHD_OPTION_END); |
154 | if (d == NULL) | 175 | if (NULL == d) |
155 | return 1; | 176 | return 1; |
156 | (void) getc (stdin); | 177 | (void) getc (stdin); |
157 | MHD_stop_daemon (d); | 178 | MHD_stop_daemon (d); |
diff --git a/src/examples/demo.c b/src/examples/demo.c index edf38e98..0b177357 100644 --- a/src/examples/demo.c +++ b/src/examples/demo.c | |||
@@ -254,7 +254,7 @@ struct ResponseDataContext | |||
254 | * | 254 | * |
255 | * @param rdc where to store the list of files | 255 | * @param rdc where to store the list of files |
256 | * @param dirname name of the directory to list | 256 | * @param dirname name of the directory to list |
257 | * @return MHD_YES on success, MHD_NO on error | 257 | * @return #MHD_YES on success, #MHD_NO on error |
258 | */ | 258 | */ |
259 | static int | 259 | static int |
260 | list_directory (struct ResponseDataContext *rdc, | 260 | list_directory (struct ResponseDataContext *rdc, |
@@ -271,7 +271,7 @@ list_directory (struct ResponseDataContext *rdc, | |||
271 | { | 271 | { |
272 | if ('.' == de->d_name[0]) | 272 | if ('.' == de->d_name[0]) |
273 | continue; | 273 | continue; |
274 | if (sizeof (fullname) <= (size_t) | 274 | if (sizeof (fullname) <= (unsigned int) |
275 | snprintf (fullname, sizeof (fullname), | 275 | snprintf (fullname, sizeof (fullname), |
276 | "%s/%s", | 276 | "%s/%s", |
277 | dirname, de->d_name)) | 277 | dirname, de->d_name)) |
@@ -555,7 +555,7 @@ process_upload_data (void *cls, | |||
555 | uc->category, | 555 | uc->category, |
556 | filename); | 556 | filename); |
557 | for (i=strlen (fn)-1;i>=0;i--) | 557 | for (i=strlen (fn)-1;i>=0;i--) |
558 | if (! isprint ((int) fn[i])) | 558 | if (! isprint ((unsigned char) fn[i])) |
559 | fn[i] = '_'; | 559 | fn[i] = '_'; |
560 | uc->fd = open (fn, | 560 | uc->fd = open (fn, |
561 | O_CREAT | O_EXCL | 561 | O_CREAT | O_EXCL |
diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c index 453ca2ff..818c8d55 100644 --- a/src/examples/https_fileserver_example.c +++ b/src/examples/https_fileserver_example.c | |||
@@ -191,38 +191,44 @@ int | |||
191 | main (int argc, char *const *argv) | 191 | main (int argc, char *const *argv) |
192 | { | 192 | { |
193 | struct MHD_Daemon *TLS_daemon; | 193 | struct MHD_Daemon *TLS_daemon; |
194 | int port; | ||
194 | 195 | ||
195 | if (argc == 2) | 196 | if (argc != 2) |
196 | { | 197 | { |
197 | /* TODO check if this is truly necessary - disallow usage of the blocking /dev/random */ | 198 | printf ("%s PORT\n", argv[0]); |
198 | /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */ | 199 | return 1; |
199 | TLS_daemon = | ||
200 | MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | | ||
201 | MHD_USE_TLS, atoi (argv[1]), NULL, NULL, &http_ahc, | ||
202 | NULL, MHD_OPTION_CONNECTION_TIMEOUT, 256, | ||
203 | MHD_OPTION_HTTPS_MEM_KEY, key_pem, | ||
204 | MHD_OPTION_HTTPS_MEM_CERT, cert_pem, | ||
205 | MHD_OPTION_END); | ||
206 | } | 200 | } |
207 | else | 201 | port = atoi (argv[1]); |
202 | if ( (1 > port) || | ||
203 | (port > UINT16_MAX) ) | ||
208 | { | 204 | { |
209 | printf ("Usage: %s HTTP-PORT\n", argv[0]); | 205 | fprintf (stderr, |
206 | "Port must be a number between 1 and 65535\n"); | ||
210 | return 1; | 207 | return 1; |
211 | } | 208 | } |
212 | 209 | ||
213 | if (TLS_daemon == NULL) | 210 | /* TODO check if this is truly necessary - disallow usage of the blocking /dev/random */ |
211 | /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */ | ||
212 | TLS_daemon = | ||
213 | MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | | ||
214 | MHD_USE_TLS, | ||
215 | (uint16_t) port, | ||
216 | NULL, NULL, | ||
217 | &http_ahc, NULL, | ||
218 | MHD_OPTION_CONNECTION_TIMEOUT, 256, | ||
219 | MHD_OPTION_HTTPS_MEM_KEY, key_pem, | ||
220 | MHD_OPTION_HTTPS_MEM_CERT, cert_pem, | ||
221 | MHD_OPTION_END); | ||
222 | if (NULL == TLS_daemon) | ||
214 | { | 223 | { |
215 | fprintf (stderr, "Error: failed to start TLS_daemon\n"); | 224 | fprintf (stderr, "Error: failed to start TLS_daemon\n"); |
216 | return 1; | 225 | return 1; |
217 | } | 226 | } |
218 | else | 227 | printf ("MHD daemon listening on port %u\n", |
219 | { | 228 | (unsigned int) port); |
220 | printf ("MHD daemon listening on port %d\n", atoi (argv[1])); | ||
221 | } | ||
222 | 229 | ||
223 | (void) getc (stdin); | 230 | (void) getc (stdin); |
224 | 231 | ||
225 | MHD_stop_daemon (TLS_daemon); | 232 | MHD_stop_daemon (TLS_daemon); |
226 | |||
227 | return 0; | 233 | return 0; |
228 | } | 234 | } |
diff --git a/src/examples/post_example.c b/src/examples/post_example.c index 8b92956d..6c9a3f4b 100644 --- a/src/examples/post_example.c +++ b/src/examples/post_example.c | |||
@@ -313,23 +313,28 @@ fill_v1_form (const void *cls, | |||
313 | struct MHD_Connection *connection) | 313 | struct MHD_Connection *connection) |
314 | { | 314 | { |
315 | int ret; | 315 | int ret; |
316 | size_t slen; | ||
316 | char *reply; | 317 | char *reply; |
317 | struct MHD_Response *response; | 318 | struct MHD_Response *response; |
318 | (void)cls; /* Unused. Silent compiler warning. */ | 319 | (void)cls; /* Unused. Silent compiler warning. */ |
319 | 320 | ||
320 | reply = malloc (strlen (MAIN_PAGE) + strlen (session->value_1) + 1); | 321 | slen = strlen (MAIN_PAGE) + strlen (session->value_1); |
322 | reply = malloc (slen + 1); | ||
321 | if (NULL == reply) | 323 | if (NULL == reply) |
322 | return MHD_NO; | 324 | return MHD_NO; |
323 | snprintf (reply, | 325 | snprintf (reply, |
324 | strlen (MAIN_PAGE) + strlen (session->value_1) + 1, | 326 | slen + 1, |
325 | MAIN_PAGE, | 327 | MAIN_PAGE, |
326 | session->value_1); | 328 | session->value_1); |
327 | /* return static form */ | 329 | /* return static form */ |
328 | response = MHD_create_response_from_buffer (strlen (reply), | 330 | response = MHD_create_response_from_buffer (slen, |
329 | (void *) reply, | 331 | (void *) reply, |
330 | MHD_RESPMEM_MUST_FREE); | 332 | MHD_RESPMEM_MUST_FREE); |
331 | if (NULL == response) | 333 | if (NULL == response) |
334 | { | ||
335 | free (reply); | ||
332 | return MHD_NO; | 336 | return MHD_NO; |
337 | } | ||
333 | add_session_cookie (session, response); | 338 | add_session_cookie (session, response); |
334 | MHD_add_response_header (response, | 339 | MHD_add_response_header (response, |
335 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 340 | MHD_HTTP_HEADER_CONTENT_ENCODING, |
@@ -359,22 +364,27 @@ fill_v1_v2_form (const void *cls, | |||
359 | int ret; | 364 | int ret; |
360 | char *reply; | 365 | char *reply; |
361 | struct MHD_Response *response; | 366 | struct MHD_Response *response; |
367 | size_t slen; | ||
362 | (void)cls; /* Unused. Silent compiler warning. */ | 368 | (void)cls; /* Unused. Silent compiler warning. */ |
363 | 369 | ||
364 | reply = malloc (strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2) + 1); | 370 | slen = strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2); |
371 | reply = malloc (slen + 1); | ||
365 | if (NULL == reply) | 372 | if (NULL == reply) |
366 | return MHD_NO; | 373 | return MHD_NO; |
367 | snprintf (reply, | 374 | snprintf (reply, |
368 | strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2) + 1, | 375 | slen + 1, |
369 | SECOND_PAGE, | 376 | SECOND_PAGE, |
370 | session->value_1, | 377 | session->value_1, |
371 | session->value_2); | 378 | session->value_2); |
372 | /* return static form */ | 379 | /* return static form */ |
373 | response = MHD_create_response_from_buffer (strlen (reply), | 380 | response = MHD_create_response_from_buffer (slen, |
374 | (void *) reply, | 381 | (void *) reply, |
375 | MHD_RESPMEM_MUST_FREE); | 382 | MHD_RESPMEM_MUST_FREE); |
376 | if (NULL == response) | 383 | if (NULL == response) |
384 | { | ||
385 | free (reply); | ||
377 | return MHD_NO; | 386 | return MHD_NO; |
387 | } | ||
378 | add_session_cookie (session, response); | 388 | add_session_cookie (session, response); |
379 | MHD_add_response_header (response, | 389 | MHD_add_response_header (response, |
380 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 390 | MHD_HTTP_HEADER_CONTENT_ENCODING, |
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index c33d484a..9b040418 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -1070,7 +1070,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1070 | * Prepare the response buffer of this connection for sending. | 1070 | * Prepare the response buffer of this connection for sending. |
1071 | * Assumes that the response mutex is already held. If the | 1071 | * Assumes that the response mutex is already held. If the |
1072 | * transmission is complete, this function may close the socket (and | 1072 | * transmission is complete, this function may close the socket (and |
1073 | * return MHD_NO). | 1073 | * return #MHD_NO). |
1074 | * | 1074 | * |
1075 | * @param connection the connection | 1075 | * @param connection the connection |
1076 | * @return #MHD_NO if readying the response failed | 1076 | * @return #MHD_NO if readying the response failed |
@@ -1086,6 +1086,8 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
1086 | int cblen; | 1086 | int cblen; |
1087 | 1087 | ||
1088 | response = connection->response; | 1088 | response = connection->response; |
1089 | if (NULL == response->crc) | ||
1090 | return MHD_YES; | ||
1089 | if (0 == connection->write_buffer_size) | 1091 | if (0 == connection->write_buffer_size) |
1090 | { | 1092 | { |
1091 | size = MHD_MIN (connection->daemon->pool_size, | 1093 | size = MHD_MIN (connection->daemon->pool_size, |
@@ -3533,8 +3535,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3533 | socket_start_no_buffering (connection); | 3535 | socket_start_no_buffering (connection); |
3534 | continue; | 3536 | continue; |
3535 | } | 3537 | } |
3536 | if (NULL != connection->response->crc) | 3538 | MHD_mutex_unlock_chk_ (&connection->response->mutex); |
3537 | MHD_mutex_unlock_chk_ (&connection->response->mutex); | ||
3538 | break; | 3539 | break; |
3539 | case MHD_CONNECTION_BODY_SENT: | 3540 | case MHD_CONNECTION_BODY_SENT: |
3540 | if (MHD_NO == build_header_response (connection)) | 3541 | if (MHD_NO == build_header_response (connection)) |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index a0ecf3ea..fa1cedf4 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -316,10 +316,10 @@ MHD_create_response_from_callback (uint64_t size, | |||
316 | response->data = (void *) &response[1]; | 316 | response->data = (void *) &response[1]; |
317 | response->data_buffer_size = block_size; | 317 | response->data_buffer_size = block_size; |
318 | if (! MHD_mutex_init_ (&response->mutex)) | 318 | if (! MHD_mutex_init_ (&response->mutex)) |
319 | { | 319 | { |
320 | free (response); | 320 | free (response); |
321 | return NULL; | 321 | return NULL; |
322 | } | 322 | } |
323 | response->crc = crc; | 323 | response->crc = crc; |
324 | response->crfc = crfc; | 324 | response->crfc = crfc; |
325 | response->crc_cls = crc_cls; | 325 | response->crc_cls = crc_cls; |
diff --git a/src/microhttpd/test_shutdown_select.c b/src/microhttpd/test_shutdown_select.c index e8942c0b..1e4e3d82 100644 --- a/src/microhttpd/test_shutdown_select.c +++ b/src/microhttpd/test_shutdown_select.c | |||
@@ -112,10 +112,11 @@ has_in_name(const char *prog_name, const char *marker) | |||
112 | pos++; | 112 | pos++; |
113 | } | 113 | } |
114 | if (name_pos == pos) | 114 | if (name_pos == pos) |
115 | return !0; | 115 | return true; |
116 | return strstr(prog_name + name_pos, marker) != NULL; | 116 | return strstr(prog_name + name_pos, marker) != NULL; |
117 | } | 117 | } |
118 | 118 | ||
119 | |||
119 | static MHD_socket | 120 | static MHD_socket |
120 | start_socket_listen(int domain) | 121 | start_socket_listen(int domain) |
121 | { | 122 | { |
@@ -290,7 +291,7 @@ main (int argc, char *const *argv) | |||
290 | 291 | ||
291 | test_poll = has_in_name(argv[0], "_poll"); | 292 | test_poll = has_in_name(argv[0], "_poll"); |
292 | must_ignore = has_in_name(argv[0], "_ignore"); | 293 | must_ignore = has_in_name(argv[0], "_ignore"); |
293 | if (!test_poll) | 294 | if (! test_poll) |
294 | test_func = &select_thread; | 295 | test_func = &select_thread; |
295 | else | 296 | else |
296 | { | 297 | { |
@@ -324,7 +325,7 @@ main (int argc, char *const *argv) | |||
324 | if (MHD_INVALID_SOCKET == listen_socket) | 325 | if (MHD_INVALID_SOCKET == listen_socket) |
325 | return 99; | 326 | return 99; |
326 | 327 | ||
327 | check_err = !0; | 328 | check_err = true; |
328 | /* fprintf (stdout, "Starting select() thread...\n"); */ | 329 | /* fprintf (stdout, "Starting select() thread...\n"); */ |
329 | #if defined(MHD_USE_POSIX_THREADS) | 330 | #if defined(MHD_USE_POSIX_THREADS) |
330 | if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket)) | 331 | if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket)) |
diff --git a/src/testcurl/https/test_https_session_info.c b/src/testcurl/https/test_https_session_info.c index eb821240..f21e03b0 100644 --- a/src/testcurl/https/test_https_session_info.c +++ b/src/testcurl/https/test_https_session_info.c | |||
@@ -141,7 +141,9 @@ test_query_session () | |||
141 | aes256_sha = "rsa_aes_256_sha"; | 141 | aes256_sha = "rsa_aes_256_sha"; |
142 | } | 142 | } |
143 | 143 | ||
144 | gen_test_file_url (url, port); | 144 | gen_test_file_url (url, |
145 | sizeof (url), | ||
146 | port); | ||
145 | c = curl_easy_init (); | 147 | c = curl_easy_init (); |
146 | #if DEBUG_HTTPS_TEST | 148 | #if DEBUG_HTTPS_TEST |
147 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1); | 149 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1); |
diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c index a7bb6d4e..98725ee3 100644 --- a/src/testcurl/https/test_tls_extensions.c +++ b/src/testcurl/https/test_tls_extensions.c | |||
@@ -168,7 +168,9 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
168 | 168 | ||
169 | gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd); | 169 | gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd); |
170 | 170 | ||
171 | if (gen_test_file_url (url, port)) | 171 | if (gen_test_file_url (url, |
172 | sizeof (url), | ||
173 | port)) | ||
172 | { | 174 | { |
173 | ret = -1; | 175 | ret = -1; |
174 | goto cleanup; | 176 | goto cleanup; |
diff --git a/src/testcurl/https/test_tls_options.c b/src/testcurl/https/test_tls_options.c index a0f053a0..6eed7932 100644 --- a/src/testcurl/https/test_tls_options.c +++ b/src/testcurl/https/test_tls_options.c | |||
@@ -57,10 +57,13 @@ test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite, | |||
57 | cbc.pos = 0; | 57 | cbc.pos = 0; |
58 | 58 | ||
59 | char url[255]; | 59 | char url[255]; |
60 | if (gen_test_file_url (url, port)) | 60 | if (gen_test_file_url (url, |
61 | sizeof (url), | ||
62 | port)) | ||
61 | { | 63 | { |
62 | free (cbc.buf); | 64 | free (cbc.buf); |
63 | fprintf (stderr, "Internal error in gen_test_file_url\n"); | 65 | fprintf (stderr, |
66 | "Internal error in gen_test_file_url\n"); | ||
64 | return -1; | 67 | return -1; |
65 | } | 68 | } |
66 | 69 | ||
diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c index 63cb1013..e929334b 100644 --- a/src/testcurl/https/tls_test_common.c +++ b/src/testcurl/https/tls_test_common.c | |||
@@ -84,7 +84,9 @@ test_daemon_get (void *cls, | |||
84 | cbc.pos = 0; | 84 | cbc.pos = 0; |
85 | 85 | ||
86 | /* construct url - this might use doc_path */ | 86 | /* construct url - this might use doc_path */ |
87 | gen_test_file_url (url, port); | 87 | gen_test_file_url (url, |
88 | sizeof (url), | ||
89 | port); | ||
88 | 90 | ||
89 | c = curl_easy_init (); | 91 | c = curl_easy_init (); |
90 | #if DEBUG_HTTPS_TEST | 92 | #if DEBUG_HTTPS_TEST |
@@ -108,7 +110,7 @@ test_daemon_get (void *cls, | |||
108 | curl_easy_setopt (c, CURLOPT_CAINFO, ca_cert_file_name); | 110 | curl_easy_setopt (c, CURLOPT_CAINFO, ca_cert_file_name); |
109 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0); | 111 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0); |
110 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 112 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
111 | 113 | ||
112 | /* NOTE: use of CONNECTTIMEOUT without also | 114 | /* NOTE: use of CONNECTTIMEOUT without also |
113 | setting NOSIGNAL results in really weird | 115 | setting NOSIGNAL results in really weird |
114 | crashes on my system! */ | 116 | crashes on my system! */ |
@@ -258,12 +260,15 @@ send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite, | |||
258 | /** | 260 | /** |
259 | * compile test file url pointing to the current running directory path | 261 | * compile test file url pointing to the current running directory path |
260 | * | 262 | * |
261 | * @param url - char buffer into which the url is compiled | 263 | * @param[out] url - char buffer into which the url is compiled |
264 | * @param url_len number of bytes available in url | ||
262 | * @param port port to use for the test | 265 | * @param port port to use for the test |
263 | * @return -1 on error | 266 | * @return -1 on error |
264 | */ | 267 | */ |
265 | int | 268 | int |
266 | gen_test_file_url (char *url, int port) | 269 | gen_test_file_url (char *url, |
270 | size_t url_len, | ||
271 | int port) | ||
267 | { | 272 | { |
268 | int ret = 0; | 273 | int ret = 0; |
269 | char *doc_path; | 274 | char *doc_path; |
@@ -279,46 +284,54 @@ gen_test_file_url (char *url, int port) | |||
279 | fprintf (stderr, MHD_E_MEM); | 284 | fprintf (stderr, MHD_E_MEM); |
280 | return -1; | 285 | return -1; |
281 | } | 286 | } |
282 | if (getcwd (doc_path, doc_path_len) == NULL) | 287 | if (NULL == getcwd (doc_path, doc_path_len)) |
283 | { | 288 | { |
284 | fprintf (stderr, "Error: failed to get working directory. %s\n", | 289 | fprintf (stderr, |
290 | "Error: failed to get working directory. %s\n", | ||
285 | strerror (errno)); | 291 | strerror (errno)); |
286 | ret = -1; | 292 | free (doc_path); |
293 | return -1; | ||
287 | } | 294 | } |
288 | #ifdef WINDOWS | 295 | #ifdef WINDOWS |
296 | for (int i = 0; i < doc_path_len; i++) | ||
289 | { | 297 | { |
290 | int i; | 298 | if (doc_path[i] == 0) |
291 | for (i = 0; i < doc_path_len; i++) | 299 | break; |
292 | { | 300 | if (doc_path[i] == '\\') |
293 | if (doc_path[i] == 0) | ||
294 | break; | ||
295 | if (doc_path[i] == '\\') | ||
296 | { | 301 | { |
297 | doc_path[i] = '/'; | 302 | doc_path[i] = '/'; |
298 | } | 303 | } |
299 | if (doc_path[i] != ':') | 304 | if (doc_path[i] != ':') |
300 | continue; | 305 | continue; |
301 | if (i == 0) | 306 | if (i == 0) |
302 | break; | 307 | break; |
303 | doc_path[i] = doc_path[i - 1]; | 308 | doc_path[i] = doc_path[i - 1]; |
304 | doc_path[i - 1] = '/'; | 309 | doc_path[i - 1] = '/'; |
305 | } | ||
306 | } | 310 | } |
307 | #endif | 311 | #endif |
308 | /* construct url - this might use doc_path */ | 312 | /* construct url */ |
309 | if (sprintf (url, "%s:%d%s/%s", "https://127.0.0.1", port, | 313 | if (snprintf (url, |
310 | doc_path, "urlpath") < 0) | 314 | url_len, |
315 | "%s:%d%s/%s", | ||
316 | "https://127.0.0.1", | ||
317 | port, | ||
318 | doc_path, | ||
319 | "urlpath") >= url_len) | ||
311 | ret = -1; | 320 | ret = -1; |
312 | 321 | ||
313 | free (doc_path); | 322 | free (doc_path); |
314 | return ret; | 323 | return ret; |
315 | } | 324 | } |
316 | 325 | ||
326 | |||
317 | /** | 327 | /** |
318 | * test HTTPS file transfer | 328 | * test HTTPS file transfer |
319 | */ | 329 | */ |
320 | int | 330 | int |
321 | test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_version) | 331 | test_https_transfer (void *cls, |
332 | int port, | ||
333 | const char *cipher_suite, | ||
334 | int proto_version) | ||
322 | { | 335 | { |
323 | int len; | 336 | int len; |
324 | int ret = 0; | 337 | int ret = 0; |
@@ -334,13 +347,16 @@ test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_ve | |||
334 | cbc.size = len; | 347 | cbc.size = len; |
335 | cbc.pos = 0; | 348 | cbc.pos = 0; |
336 | 349 | ||
337 | if (gen_test_file_url (url, port)) | 350 | if (gen_test_file_url (url, |
351 | sizeof (url), | ||
352 | port)) | ||
338 | { | 353 | { |
339 | ret = -1; | 354 | ret = -1; |
340 | goto cleanup; | 355 | goto cleanup; |
341 | } | 356 | } |
342 | 357 | ||
343 | if (CURLE_OK != send_curl_req (url, &cbc, cipher_suite, proto_version)) | 358 | if (CURLE_OK != |
359 | send_curl_req (url, &cbc, cipher_suite, proto_version)) | ||
344 | { | 360 | { |
345 | ret = -1; | 361 | ret = -1; |
346 | goto cleanup; | 362 | goto cleanup; |
@@ -348,8 +364,8 @@ test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_ve | |||
348 | 364 | ||
349 | /* compare test file & daemon responce */ | 365 | /* compare test file & daemon responce */ |
350 | if ( (len != strlen (test_data)) || | 366 | if ( (len != strlen (test_data)) || |
351 | (memcmp (cbc.buf, | 367 | (memcmp (cbc.buf, |
352 | test_data, | 368 | test_data, |
353 | len) != 0) ) | 369 | len) != 0) ) |
354 | { | 370 | { |
355 | fprintf (stderr, "Error: local file & received file differ.\n"); | 371 | fprintf (stderr, "Error: local file & received file differ.\n"); |
@@ -404,7 +420,7 @@ teardown_testcase (struct MHD_Daemon *d) | |||
404 | int | 420 | int |
405 | setup_session (gnutls_session_t * session, | 421 | setup_session (gnutls_session_t * session, |
406 | gnutls_datum_t * key, | 422 | gnutls_datum_t * key, |
407 | gnutls_datum_t * cert, | 423 | gnutls_datum_t * cert, |
408 | gnutls_certificate_credentials_t * xcred) | 424 | gnutls_certificate_credentials_t * xcred) |
409 | { | 425 | { |
410 | int ret; | 426 | int ret; |
@@ -413,7 +429,7 @@ setup_session (gnutls_session_t * session, | |||
413 | gnutls_certificate_allocate_credentials (xcred); | 429 | gnutls_certificate_allocate_credentials (xcred); |
414 | key->size = strlen (srv_key_pem) + 1; | 430 | key->size = strlen (srv_key_pem) + 1; |
415 | key->data = malloc (key->size); | 431 | key->data = malloc (key->size); |
416 | if (NULL == key->data) | 432 | if (NULL == key->data) |
417 | { | 433 | { |
418 | gnutls_certificate_free_credentials (*xcred); | 434 | gnutls_certificate_free_credentials (*xcred); |
419 | return -1; | 435 | return -1; |
@@ -424,7 +440,7 @@ setup_session (gnutls_session_t * session, | |||
424 | if (NULL == cert->data) | 440 | if (NULL == cert->data) |
425 | { | 441 | { |
426 | gnutls_certificate_free_credentials (*xcred); | 442 | gnutls_certificate_free_credentials (*xcred); |
427 | free (key->data); | 443 | free (key->data); |
428 | return -1; | 444 | return -1; |
429 | } | 445 | } |
430 | memcpy (cert->data, srv_self_signed_cert_pem, cert->size); | 446 | memcpy (cert->data, srv_self_signed_cert_pem, cert->size); |
@@ -440,8 +456,8 @@ setup_session (gnutls_session_t * session, | |||
440 | free (key->data); | 456 | free (key->data); |
441 | return -1; | 457 | return -1; |
442 | } | 458 | } |
443 | gnutls_credentials_set (*session, | 459 | gnutls_credentials_set (*session, |
444 | GNUTLS_CRD_CERTIFICATE, | 460 | GNUTLS_CRD_CERTIFICATE, |
445 | *xcred); | 461 | *xcred); |
446 | return 0; | 462 | return 0; |
447 | } | 463 | } |
diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h index a59c43f4..07849e44 100644 --- a/src/testcurl/https/tls_test_common.h +++ b/src/testcurl/https/tls_test_common.h | |||
@@ -68,12 +68,15 @@ struct CipherDef | |||
68 | }; | 68 | }; |
69 | 69 | ||
70 | 70 | ||
71 | int curl_check_version (const char *req_version, ...); | 71 | int |
72 | int curl_uses_nss_ssl (); | 72 | curl_check_version (const char *req_version, ...); |
73 | |||
74 | int | ||
75 | curl_uses_nss_ssl (void); | ||
73 | 76 | ||
74 | 77 | ||
75 | FILE * | 78 | FILE * |
76 | setup_ca_cert (); | 79 | setup_ca_cert (void); |
77 | 80 | ||
78 | /** | 81 | /** |
79 | * perform cURL request for file | 82 | * perform cURL request for file |
@@ -83,9 +86,11 @@ test_daemon_get (void * cls, | |||
83 | const char *cipher_suite, int proto_version, | 86 | const char *cipher_suite, int proto_version, |
84 | int port, int ver_peer); | 87 | int port, int ver_peer); |
85 | 88 | ||
86 | void print_test_result (int test_outcome, char *test_name); | 89 | void |
90 | print_test_result (int test_outcome, char *test_name); | ||
87 | 91 | ||
88 | size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx); | 92 | size_t |
93 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx); | ||
89 | 94 | ||
90 | int | 95 | int |
91 | http_ahc (void *cls, struct MHD_Connection *connection, | 96 | http_ahc (void *cls, struct MHD_Connection *connection, |
@@ -102,11 +107,15 @@ http_dummy_ahc (void *cls, struct MHD_Connection *connection, | |||
102 | /** | 107 | /** |
103 | * compile test file url pointing to the current running directory path | 108 | * compile test file url pointing to the current running directory path |
104 | * | 109 | * |
105 | * @param url - char buffer into which the url is compiled | 110 | * @param[out] url - char buffer into which the url is compiled |
111 | * @param url_len number of bytes available in @a url | ||
106 | * @param port port to use for the test | 112 | * @param port port to use for the test |
107 | * @return -1 on error | 113 | * @return -1 on error |
108 | */ | 114 | */ |
109 | int gen_test_file_url (char *url, int port); | 115 | int |
116 | gen_test_file_url (char *url, | ||
117 | size_t url_len, | ||
118 | int port); | ||
110 | 119 | ||
111 | int | 120 | int |
112 | send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite, | 121 | send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite, |
@@ -118,7 +127,9 @@ test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_ve | |||
118 | int | 127 | int |
119 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list); | 128 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list); |
120 | 129 | ||
121 | void teardown_testcase (struct MHD_Daemon *d); | 130 | void |
131 | teardown_testcase (struct MHD_Daemon *d); | ||
132 | |||
122 | 133 | ||
123 | int | 134 | int |
124 | setup_session (gnutls_session_t * session, | 135 | setup_session (gnutls_session_t * session, |
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c index 6901be0f..9c9e125f 100644 --- a/src/testcurl/test_callback.c +++ b/src/testcurl/test_callback.c | |||
@@ -69,15 +69,21 @@ callback(void *cls, | |||
69 | { | 69 | { |
70 | struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure)); | 70 | struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure)); |
71 | struct MHD_Response *r; | 71 | struct MHD_Response *r; |
72 | int ret; | ||
72 | 73 | ||
73 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, | 74 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, |
74 | &called_twice, cbc, | 75 | &called_twice, cbc, |
75 | &free); | 76 | &free); |
76 | MHD_queue_response (connection, | 77 | if (NULL == r) |
77 | MHD_HTTP_OK, | 78 | { |
78 | r); | 79 | free (cbc); |
80 | return MHD_NO; | ||
81 | } | ||
82 | ret = MHD_queue_response (connection, | ||
83 | MHD_HTTP_OK, | ||
84 | r); | ||
79 | MHD_destroy_response (r); | 85 | MHD_destroy_response (r); |
80 | return MHD_YES; | 86 | return ret; |
81 | } | 87 | } |
82 | 88 | ||
83 | 89 | ||
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c index 425776af..2c6ec2d4 100644 --- a/src/testcurl/test_get_chunked.c +++ b/src/testcurl/test_get_chunked.c | |||
@@ -54,8 +54,12 @@ struct CBC | |||
54 | size_t size; | 54 | size_t size; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | |||
57 | static size_t | 58 | static size_t |
58 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 59 | copyBuffer (void *ptr, |
60 | size_t size, | ||
61 | size_t nmemb, | ||
62 | void *ctx) | ||
59 | { | 63 | { |
60 | struct CBC *cbc = ctx; | 64 | struct CBC *cbc = ctx; |
61 | 65 | ||
@@ -66,28 +70,34 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
66 | return size * nmemb; | 70 | return size * nmemb; |
67 | } | 71 | } |
68 | 72 | ||
73 | |||
69 | /** | 74 | /** |
70 | * MHD content reader callback that returns | 75 | * MHD content reader callback that returns data in chunks. |
71 | * data in chunks. | ||
72 | */ | 76 | */ |
73 | static ssize_t | 77 | static ssize_t |
74 | crc (void *cls, uint64_t pos, char *buf, size_t max) | 78 | crc (void *cls, |
79 | uint64_t pos, | ||
80 | char *buf, | ||
81 | size_t max) | ||
75 | { | 82 | { |
76 | struct MHD_Response **responseptr = cls; | 83 | struct MHD_Response **responseptr = cls; |
77 | 84 | ||
78 | if (pos == 128 * 10) | 85 | if (pos == 128 * 10) |
79 | { | 86 | { |
80 | MHD_add_response_header (*responseptr, "Footer", "working"); | 87 | MHD_add_response_footer (*responseptr, |
81 | return MHD_CONTENT_READER_END_OF_STREAM; | 88 | "Footer", |
82 | } | 89 | "working"); |
90 | return MHD_CONTENT_READER_END_OF_STREAM; | ||
91 | } | ||
83 | if (max < 128) | 92 | if (max < 128) |
84 | abort (); /* should not happen in this testcase... */ | 93 | abort (); /* should not happen in this testcase... */ |
85 | memset (buf, 'A' + (pos / 128), 128); | 94 | memset (buf, 'A' + (pos / 128), 128); |
86 | return 128; | 95 | return 128; |
87 | } | 96 | } |
88 | 97 | ||
98 | |||
89 | /** | 99 | /** |
90 | * Dummy function that does nothing. | 100 | * Dummy function that frees the "responseptr". |
91 | */ | 101 | */ |
92 | static void | 102 | static void |
93 | crcf (void *ptr) | 103 | crcf (void *ptr) |
@@ -95,6 +105,7 @@ crcf (void *ptr) | |||
95 | free (ptr); | 105 | free (ptr); |
96 | } | 106 | } |
97 | 107 | ||
108 | |||
98 | static int | 109 | static int |
99 | ahc_echo (void *cls, | 110 | ahc_echo (void *cls, |
100 | struct MHD_Connection *connection, | 111 | struct MHD_Connection *connection, |
@@ -118,17 +129,27 @@ ahc_echo (void *cls, | |||
118 | return MHD_YES; | 129 | return MHD_YES; |
119 | } | 130 | } |
120 | responseptr = malloc (sizeof (struct MHD_Response *)); | 131 | responseptr = malloc (sizeof (struct MHD_Response *)); |
121 | if (responseptr == NULL) | 132 | if (NULL == responseptr) |
122 | return MHD_NO; | 133 | return MHD_NO; |
123 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | 134 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, |
124 | 1024, | 135 | 1024, |
125 | &crc, responseptr, &crcf); | 136 | &crc, |
137 | responseptr, | ||
138 | &crcf); | ||
139 | if (NULL == response) | ||
140 | { | ||
141 | free (responseptr); | ||
142 | return MHD_NO; | ||
143 | } | ||
126 | *responseptr = response; | 144 | *responseptr = response; |
127 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 145 | ret = MHD_queue_response (connection, |
146 | MHD_HTTP_OK, | ||
147 | response); | ||
128 | MHD_destroy_response (response); | 148 | MHD_destroy_response (response); |
129 | return ret; | 149 | return ret; |
130 | } | 150 | } |
131 | 151 | ||
152 | |||
132 | static int | 153 | static int |
133 | validate (struct CBC cbc, int ebase) | 154 | validate (struct CBC cbc, int ebase) |
134 | { | 155 | { |