aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/examples/authorization_example.c59
-rw-r--r--src/examples/benchmark.c79
-rw-r--r--src/examples/benchmark_https.c168
-rw-r--r--src/examples/chunked_example.c76
-rw-r--r--src/examples/connection_close.c76
-rw-r--r--src/examples/demo.c748
-rw-r--r--src/examples/demo_https.c846
-rw-r--r--src/examples/digest_auth_example.c142
-rw-r--r--src/examples/dual_stack_example.c44
-rw-r--r--src/examples/fileserver_example_dirs.c162
-rw-r--r--src/examples/fileserver_example_external_select.c137
-rw-r--r--src/examples/http_chunked_compression.c139
-rw-r--r--src/examples/http_compression.c63
-rw-r--r--src/examples/https_fileserver_example.c114
-rw-r--r--src/examples/minimal_example_comet.c35
-rw-r--r--src/examples/msgs_i18n.c47
-rw-r--r--src/examples/post_example.c509
-rw-r--r--src/examples/querystring_example.c50
-rw-r--r--src/examples/refuse_post_example.c59
-rw-r--r--src/examples/suspend_resume_epoll.c64
-rw-r--r--src/examples/timeout.c39
-rw-r--r--src/examples/upgrade_example.c118
-rw-r--r--src/gnutls/check_record_pending.c8
-rw-r--r--src/gnutls/handshake.c24
-rw-r--r--src/gnutls/idle_ready.c18
-rw-r--r--src/gnutls/init.c38
-rw-r--r--src/gnutls/init.h2
-rw-r--r--src/gnutls/recv.c6
-rw-r--r--src/gnutls/send.c16
-rw-r--r--src/gnutls/setup_connection.c83
-rw-r--r--src/gnutls/shutdown_connection.c8
-rw-r--r--src/gnutls/strerror.c6
-rw-r--r--src/gnutls/update_event_loop_info.c36
-rw-r--r--src/include/autoinit_funcs.h105
-rw-r--r--src/include/mhd_options.h14
-rw-r--r--src/include/microhttpd.h390
-rw-r--r--src/include/microhttpd2.h488
-rw-r--r--src/include/microhttpd_tls.h56
-rw-r--r--src/include/platform.h16
-rw-r--r--src/lib/action_continue.c4
-rw-r--r--src/lib/action_from_response.c53
-rw-r--r--src/lib/action_parse_post.c4
-rw-r--r--src/lib/action_process_upload.c8
-rw-r--r--src/lib/action_suspend.c70
-rw-r--r--src/lib/base64.c55
-rw-r--r--src/lib/base64.h2
-rw-r--r--src/lib/connection_add.c1204
-rw-r--r--src/lib/connection_add.h4
-rw-r--r--src/lib/connection_call_handlers.c4026
-rw-r--r--src/lib/connection_call_handlers.h12
-rw-r--r--src/lib/connection_cleanup.c132
-rw-r--r--src/lib/connection_cleanup.h6
-rw-r--r--src/lib/connection_close.c58
-rw-r--r--src/lib/connection_close.h4
-rw-r--r--src/lib/connection_finish_forward.c46
-rw-r--r--src/lib/connection_finish_forward.h2
-rw-r--r--src/lib/connection_info.c12
-rw-r--r--src/lib/connection_options.c70
-rw-r--r--src/lib/connection_update_last_activity.c11
-rw-r--r--src/lib/connection_update_last_activity.h2
-rw-r--r--src/lib/daemon_close_all_connections.c179
-rw-r--r--src/lib/daemon_close_all_connections.h2
-rw-r--r--src/lib/daemon_create.c50
-rw-r--r--src/lib/daemon_destroy.c158
-rw-r--r--src/lib/daemon_epoll.c533
-rw-r--r--src/lib/daemon_epoll.h4
-rw-r--r--src/lib/daemon_get_timeout.c78
-rw-r--r--src/lib/daemon_info.c98
-rw-r--r--src/lib/daemon_ip_limit.c120
-rw-r--r--src/lib/daemon_ip_limit.h12
-rw-r--r--src/lib/daemon_options.c140
-rw-r--r--src/lib/daemon_poll.c368
-rw-r--r--src/lib/daemon_poll.h14
-rw-r--r--src/lib/daemon_quiesce.c103
-rw-r--r--src/lib/daemon_run.c36
-rw-r--r--src/lib/daemon_select.c699
-rw-r--r--src/lib/daemon_select.h6
-rw-r--r--src/lib/daemon_start.c1013
-rw-r--r--src/lib/init.c40
-rw-r--r--src/lib/init.h2
-rw-r--r--src/lib/internal.c288
-rw-r--r--src/lib/internal.h161
-rw-r--r--src/lib/md5.c226
-rw-r--r--src/lib/md5.h24
-rw-r--r--src/lib/memorypool.c118
-rw-r--r--src/lib/memorypool.h12
-rw-r--r--src/lib/mhd_assert.h16
-rw-r--r--src/lib/mhd_byteorder.h47
-rw-r--r--src/lib/mhd_compat.c24
-rw-r--r--src/lib/mhd_compat.h18
-rw-r--r--src/lib/mhd_itc.c6
-rw-r--r--src/lib/mhd_itc.h103
-rw-r--r--src/lib/mhd_itc_types.h2
-rw-r--r--src/lib/mhd_limits.h38
-rw-r--r--src/lib/mhd_locks.h47
-rw-r--r--src/lib/mhd_mono_clock.c178
-rw-r--r--src/lib/mhd_mono_clock.h6
-rw-r--r--src/lib/mhd_sockets.c239
-rw-r--r--src/lib/mhd_sockets.h239
-rw-r--r--src/lib/mhd_str.c347
-rw-r--r--src/lib/mhd_str.h103
-rw-r--r--src/lib/mhd_threads.c162
-rw-r--r--src/lib/mhd_threads.h78
-rw-r--r--src/lib/reason_phrase.c2
-rw-r--r--src/lib/request.c72
-rw-r--r--src/lib/request_info.c12
-rw-r--r--src/lib/request_resume.c185
-rw-r--r--src/lib/request_resume.h2
-rw-r--r--src/lib/response.c126
-rw-r--r--src/lib/response_for_upgrade.c20
-rw-r--r--src/lib/response_from_buffer.c46
-rw-r--r--src/lib/response_from_callback.c14
-rw-r--r--src/lib/response_from_fd.c85
-rw-r--r--src/lib/response_options.c5
-rw-r--r--src/lib/sysfdsetsize.c2
-rw-r--r--src/lib/tsearch.c122
-rw-r--r--src/lib/tsearch.h24
-rw-r--r--src/lib/upgrade_process.c491
-rw-r--r--src/lib/upgrade_process.h2
-rw-r--r--src/lib/version.c155
-rw-r--r--src/microhttpd/base64.c55
-rw-r--r--src/microhttpd/base64.h2
-rw-r--r--src/microhttpd/connection.h2
-rw-r--r--src/microhttpd/connection_https.c127
-rw-r--r--src/microhttpd/connection_https.h2
-rw-r--r--src/microhttpd/daemon.c7140
-rw-r--r--src/microhttpd/digestauth.c936
-rw-r--r--src/microhttpd/internal.c290
-rw-r--r--src/microhttpd/internal.h161
-rw-r--r--src/microhttpd/md5.c181
-rw-r--r--src/microhttpd/md5.h18
-rw-r--r--src/microhttpd/memorypool.h10
-rw-r--r--src/microhttpd/mhd_assert.h16
-rw-r--r--src/microhttpd/mhd_bithelpers.h152
-rw-r--r--src/microhttpd/mhd_byteorder.h47
-rw-r--r--src/microhttpd/mhd_compat.c24
-rw-r--r--src/microhttpd/mhd_compat.h18
-rw-r--r--src/microhttpd/mhd_itc.c6
-rw-r--r--src/microhttpd/mhd_itc.h103
-rw-r--r--src/microhttpd/mhd_itc_types.h2
-rw-r--r--src/microhttpd/mhd_limits.h38
-rw-r--r--src/microhttpd/mhd_locks.h47
-rw-r--r--src/microhttpd/mhd_mono_clock.c178
-rw-r--r--src/microhttpd/mhd_mono_clock.h6
-rw-r--r--src/microhttpd/mhd_send.c347
-rw-r--r--src/microhttpd/mhd_send.h6
-rw-r--r--src/microhttpd/mhd_sockets.h239
-rw-r--r--src/microhttpd/mhd_str.c369
-rw-r--r--src/microhttpd/mhd_str.h109
-rw-r--r--src/microhttpd/mhd_threads.h78
-rw-r--r--src/microhttpd/postprocessor.c1205
-rw-r--r--src/microhttpd/reason_phrase.c184
-rw-r--r--src/microhttpd/response.c611
-rw-r--r--src/microhttpd/sha256.c254
-rw-r--r--src/microhttpd/sha256.h4
-rw-r--r--src/microhttpd/sysfdsetsize.c2
-rw-r--r--src/microhttpd/test_daemon.c69
-rw-r--r--src/microhttpd/test_helpers.h34
-rw-r--r--src/microhttpd/test_http_reasons.c124
-rw-r--r--src/microhttpd/test_options.c32
-rw-r--r--src/microhttpd/test_postprocessor.c68
-rw-r--r--src/microhttpd/test_postprocessor_amp.c30
-rw-r--r--src/microhttpd/test_postprocessor_large.c16
-rw-r--r--src/microhttpd/test_shutdown_select.c285
-rw-r--r--src/microhttpd/test_start_stop.c50
-rw-r--r--src/microhttpd/test_str.c4627
-rw-r--r--src/microhttpd/test_str_token.c127
-rw-r--r--src/microhttpd/tsearch.c122
-rw-r--r--src/microhttpd/tsearch.h24
-rw-r--r--src/testcurl/curl_version_check.c108
-rw-r--r--src/testcurl/gauger.h114
-rw-r--r--src/testcurl/https/test_empty_response.c170
-rw-r--r--src/testcurl/https/test_https_get.c55
-rw-r--r--src/testcurl/https/test_https_get_parallel.c67
-rw-r--r--src/testcurl/https/test_https_get_parallel_threads.c72
-rw-r--r--src/testcurl/https/test_https_get_select.c185
-rw-r--r--src/testcurl/https/test_https_multi_daemon.c106
-rw-r--r--src/testcurl/https/test_https_session_info.c113
-rw-r--r--src/testcurl/https/test_https_sni.c156
-rw-r--r--src/testcurl/https/test_https_time_out.c75
-rw-r--r--src/testcurl/https/test_tls_authentication.c67
-rw-r--r--src/testcurl/https/test_tls_extensions.c144
-rw-r--r--src/testcurl/https/test_tls_options.c114
-rw-r--r--src/testcurl/https/tls_test_common.c317
-rw-r--r--src/testcurl/https/tls_test_common.h35
-rw-r--r--src/testcurl/https/tls_test_keys.h260
-rw-r--r--src/testcurl/mhd_has_in_name.h20
-rw-r--r--src/testcurl/perf_get.c526
-rw-r--r--src/testcurl/perf_get_concurrent.c368
-rw-r--r--src/testcurl/test_callback.c232
-rw-r--r--src/testcurl/test_concurrent_stop.c188
-rw-r--r--src/testcurl/test_delete.c287
-rw-r--r--src/testcurl/test_digestauth.c157
-rw-r--r--src/testcurl/test_digestauth_sha256.c159
-rw-r--r--src/testcurl/test_digestauth_with_arguments.c164
-rw-r--r--src/testcurl/test_get.c808
-rw-r--r--src/testcurl/test_get_chunked.c289
-rw-r--r--src/testcurl/test_get_response_cleanup.c259
-rw-r--r--src/testcurl/test_get_sendfile.c394
-rw-r--r--src/testcurl/test_iplimit.c338
-rw-r--r--src/testcurl/test_large_put.c522
-rw-r--r--src/testcurl/test_long_header.c168
-rw-r--r--src/testcurl/test_parse_cookies.c173
-rw-r--r--src/testcurl/test_post.c560
-rw-r--r--src/testcurl/test_post_loop.c692
-rw-r--r--src/testcurl/test_postform.c385
-rw-r--r--src/testcurl/test_process_arguments.c176
-rw-r--r--src/testcurl/test_process_headers.c325
-rw-r--r--src/testcurl/test_put.c335
-rw-r--r--src/testcurl/test_put_chunked.c305
-rw-r--r--src/testcurl/test_quiesce.c510
-rw-r--r--src/testcurl/test_quiesce_stream.c80
-rw-r--r--src/testcurl/test_termination.c62
-rw-r--r--src/testcurl/test_timeout.c178
-rw-r--r--src/testcurl/test_urlparse.c77
-rw-r--r--src/testzzuf/socat.c50
-rw-r--r--src/testzzuf/test_get.c262
-rw-r--r--src/testzzuf/test_get_chunked.c246
-rw-r--r--src/testzzuf/test_long_header.c164
-rw-r--r--src/testzzuf/test_post.c348
-rw-r--r--src/testzzuf/test_post_form.c342
-rw-r--r--src/testzzuf/test_put.c310
-rw-r--r--src/testzzuf/test_put_chunked.c275
-rw-r--r--src/testzzuf/test_put_large.c324
224 files changed, 25785 insertions, 24383 deletions
diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c
index d8a88203..c07d7827 100644
--- a/src/examples/authorization_example.c
+++ b/src/examples/authorization_example.c
@@ -32,9 +32,11 @@
32#include <windows.h> 32#include <windows.h>
33#endif 33#endif
34 34
35#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 35#define PAGE \
36 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
36 37
37#define DENIED "<html><head><title>Access denied</title></head><body>Access denied</body></html>" 38#define DENIED \
39 "<html><head><title>Access denied</title></head><body>Access denied</body></html>"
38 40
39 41
40 42
@@ -53,19 +55,19 @@ ahc_echo (void *cls,
53 char *user; 55 char *user;
54 char *pass; 56 char *pass;
55 int fail; 57 int fail;
56 (void)url; /* Unused. Silent compiler warning. */ 58 (void) url; /* Unused. Silent compiler warning. */
57 (void)version; /* Unused. Silent compiler warning. */ 59 (void) version; /* Unused. Silent compiler warning. */
58 (void)upload_data; /* Unused. Silent compiler warning. */ 60 (void) upload_data; /* Unused. Silent compiler warning. */
59 (void)upload_data_size; /* Unused. Silent compiler warning. */ 61 (void) upload_data_size; /* Unused. Silent compiler warning. */
60 62
61 if (0 != strcmp (method, "GET")) 63 if (0 != strcmp (method, "GET"))
62 return MHD_NO; /* unexpected method */ 64 return MHD_NO; /* unexpected method */
63 if (&aptr != *ptr) 65 if (&aptr != *ptr)
64 { 66 {
65 /* do never respond on first call */ 67 /* do never respond on first call */
66 *ptr = &aptr; 68 *ptr = &aptr;
67 return MHD_YES; 69 return MHD_YES;
68 } 70 }
69 *ptr = NULL; /* reset when done */ 71 *ptr = NULL; /* reset when done */
70 72
71 /* require: "Aladdin" with password "open sesame" */ 73 /* require: "Aladdin" with password "open sesame" */
@@ -77,18 +79,18 @@ ahc_echo (void *cls,
77 (0 != strcmp (pass, "open sesame") ) ); 79 (0 != strcmp (pass, "open sesame") ) );
78 if (fail) 80 if (fail)
79 { 81 {
80 response = MHD_create_response_from_buffer (strlen (DENIED), 82 response = MHD_create_response_from_buffer (strlen (DENIED),
81 (void *) DENIED, 83 (void *) DENIED,
82 MHD_RESPMEM_PERSISTENT); 84 MHD_RESPMEM_PERSISTENT);
83 ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response); 85 ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response);
84 } 86 }
85 else 87 else
86 { 88 {
87 response = MHD_create_response_from_buffer (strlen (me), 89 response = MHD_create_response_from_buffer (strlen (me),
88 (void *) me, 90 (void *) me,
89 MHD_RESPMEM_PERSISTENT); 91 MHD_RESPMEM_PERSISTENT);
90 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 92 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
91 } 93 }
92 if (NULL != user) 94 if (NULL != user)
93 MHD_free (user); 95 MHD_free (user);
94 if (NULL != pass) 96 if (NULL != pass)
@@ -107,13 +109,14 @@ main (int argc, char *const *argv)
107 if ( (argc != 2) || 109 if ( (argc != 2) ||
108 (1 != sscanf (argv[1], "%u", &port)) || 110 (1 != sscanf (argv[1], "%u", &port)) ||
109 (UINT16_MAX < port) ) 111 (UINT16_MAX < port) )
110 { 112 {
111 fprintf (stderr, 113 fprintf (stderr,
112 "%s PORT\n", argv[0]); 114 "%s PORT\n", argv[0]);
113 return 1; 115 return 1;
114 } 116 }
115 117
116 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 118 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
119 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
117 atoi (argv[1]), 120 atoi (argv[1]),
118 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); 121 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
119 if (d == NULL) 122 if (d == NULL)
diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c
index 9512b9bf..2a8fb179 100644
--- a/src/examples/benchmark.c
+++ b/src/examples/benchmark.c
@@ -25,14 +25,15 @@
25#include "platform.h" 25#include "platform.h"
26#include <microhttpd.h> 26#include <microhttpd.h>
27 27
28#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 28#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
29#undef CPU_COUNT 29#undef CPU_COUNT
30#endif 30#endif
31#if !defined(CPU_COUNT) 31#if ! defined(CPU_COUNT)
32#define CPU_COUNT 2 32#define CPU_COUNT 2
33#endif 33#endif
34 34
35#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 35#define PAGE \
36 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
36 37
37 38
38#define SMALL (1024 * 128) 39#define SMALL (1024 * 128)
@@ -62,16 +63,16 @@ static struct MHD_Response *response;
62 */ 63 */
63static void 64static void
64completed_callback (void *cls, 65completed_callback (void *cls,
65 struct MHD_Connection *connection, 66 struct MHD_Connection *connection,
66 void **con_cls, 67 void **con_cls,
67 enum MHD_RequestTerminationCode toe) 68 enum MHD_RequestTerminationCode toe)
68{ 69{
69 struct timeval *tv = *con_cls; 70 struct timeval *tv = *con_cls;
70 struct timeval tve; 71 struct timeval tve;
71 uint64_t delta; 72 uint64_t delta;
72 (void)cls; /* Unused. Silent compiler warning. */ 73 (void) cls; /* Unused. Silent compiler warning. */
73 (void)connection; /* Unused. Silent compiler warning. */ 74 (void) connection; /* Unused. Silent compiler warning. */
74 (void)toe; /* Unused. Silent compiler warning. */ 75 (void) toe; /* Unused. Silent compiler warning. */
75 76
76 if (NULL == tv) 77 if (NULL == tv)
77 return; 78 return;
@@ -80,10 +81,10 @@ completed_callback (void *cls,
80 delta = 0; 81 delta = 0;
81 if (tve.tv_usec >= tv->tv_usec) 82 if (tve.tv_usec >= tv->tv_usec)
82 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 83 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
83 + (tve.tv_usec - tv->tv_usec); 84 + (tve.tv_usec - tv->tv_usec);
84 else 85 else
85 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 86 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
86 - tv->tv_usec + tve.tv_usec; 87 - tv->tv_usec + tve.tv_usec;
87 if (delta < SMALL) 88 if (delta < SMALL)
88 small_deltas[delta]++; 89 small_deltas[delta]++;
89 else 90 else
@@ -94,11 +95,11 @@ completed_callback (void *cls,
94 95
95static void * 96static void *
96uri_logger_cb (void *cls, 97uri_logger_cb (void *cls,
97 const char *uri) 98 const char *uri)
98{ 99{
99 struct timeval *tv = malloc (sizeof (struct timeval)); 100 struct timeval *tv = malloc (sizeof (struct timeval));
100 (void)cls; /* Unused. Silent compiler warning. */ 101 (void) cls; /* Unused. Silent compiler warning. */
101 (void)uri; /* Unused. Silent compiler warning. */ 102 (void) uri; /* Unused. Silent compiler warning. */
102 103
103 if (NULL != tv) 104 if (NULL != tv)
104 gettimeofday (tv, NULL); 105 gettimeofday (tv, NULL);
@@ -114,12 +115,12 @@ ahc_echo (void *cls,
114 const char *version, 115 const char *version,
115 const char *upload_data, size_t *upload_data_size, void **ptr) 116 const char *upload_data, size_t *upload_data_size, void **ptr)
116{ 117{
117 (void)cls; /* Unused. Silent compiler warning. */ 118 (void) cls; /* Unused. Silent compiler warning. */
118 (void)url; /* Unused. Silent compiler warning. */ 119 (void) url; /* Unused. Silent compiler warning. */
119 (void)version; /* Unused. Silent compiler warning. */ 120 (void) version; /* Unused. Silent compiler warning. */
120 (void)upload_data; /* Unused. Silent compiler warning. */ 121 (void) upload_data; /* Unused. Silent compiler warning. */
121 (void)upload_data_size; /* Unused. Silent compiler warning. */ 122 (void) upload_data_size; /* Unused. Silent compiler warning. */
122 (void)ptr; /* Unused. Silent compiler warning. */ 123 (void) ptr; /* Unused. Silent compiler warning. */
123 124
124 if (0 != strcmp (method, "GET")) 125 if (0 != strcmp (method, "GET"))
125 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
@@ -134,37 +135,39 @@ main (int argc, char *const *argv)
134 unsigned int i; 135 unsigned int i;
135 136
136 if (argc != 2) 137 if (argc != 2)
137 { 138 {
138 printf ("%s PORT\n", argv[0]); 139 printf ("%s PORT\n", argv[0]);
139 return 1; 140 return 1;
140 } 141 }
141 response = MHD_create_response_from_buffer (strlen (PAGE), 142 response = MHD_create_response_from_buffer (strlen (PAGE),
142 (void *) PAGE, 143 (void *) PAGE,
143 MHD_RESPMEM_PERSISTENT); 144 MHD_RESPMEM_PERSISTENT);
144#if 0 145#if 0
145 (void) MHD_add_response_header (response, 146 (void) MHD_add_response_header (response,
146 MHD_HTTP_HEADER_CONNECTION, 147 MHD_HTTP_HEADER_CONNECTION,
147 "close"); 148 "close");
148#endif 149#endif
149 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_SUPPRESS_DATE_NO_CLOCK 150 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD
151 | MHD_USE_SUPPRESS_DATE_NO_CLOCK
150#ifdef EPOLL_SUPPORT 152#ifdef EPOLL_SUPPORT
151 | MHD_USE_EPOLL | MHD_USE_TURBO 153 | MHD_USE_EPOLL | MHD_USE_TURBO
152#endif 154#endif
153 , 155 ,
154 atoi (argv[1]), 156 atoi (argv[1]),
155 NULL, NULL, &ahc_echo, NULL, 157 NULL, NULL, &ahc_echo, NULL,
156 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 158 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
157 MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, 159 MHD_OPTION_THREAD_POOL_SIZE, (unsigned
158 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL, 160 int) NUMBER_OF_THREADS,
159 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL, 161 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL,
160 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000, 162 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL,
161 MHD_OPTION_END); 163 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000,
164 MHD_OPTION_END);
162 if (d == NULL) 165 if (d == NULL)
163 return 1; 166 return 1;
164 (void) getc (stdin); 167 (void) getc (stdin);
165 MHD_stop_daemon (d); 168 MHD_stop_daemon (d);
166 MHD_destroy_response (response); 169 MHD_destroy_response (response);
167 for (i=0;i<SMALL;i++) 170 for (i = 0; i<SMALL; i++)
168 if (0 != small_deltas[i]) 171 if (0 != small_deltas[i])
169 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]); 172 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]);
170 return 0; 173 return 0;
diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c
index 64eb11b7..9506e562 100644
--- a/src/examples/benchmark_https.c
+++ b/src/examples/benchmark_https.c
@@ -25,14 +25,15 @@
25#include "platform.h" 25#include "platform.h"
26#include <microhttpd.h> 26#include <microhttpd.h>
27 27
28#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 28#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
29#undef CPU_COUNT 29#undef CPU_COUNT
30#endif 30#endif
31#if !defined(CPU_COUNT) 31#if ! defined(CPU_COUNT)
32#define CPU_COUNT 2 32#define CPU_COUNT 2
33#endif 33#endif
34 34
35#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 35#define PAGE \
36 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
36 37
37 38
38#define SMALL (1024 * 128) 39#define SMALL (1024 * 128)
@@ -62,16 +63,16 @@ static struct MHD_Response *response;
62 */ 63 */
63static void 64static void
64completed_callback (void *cls, 65completed_callback (void *cls,
65 struct MHD_Connection *connection, 66 struct MHD_Connection *connection,
66 void **con_cls, 67 void **con_cls,
67 enum MHD_RequestTerminationCode toe) 68 enum MHD_RequestTerminationCode toe)
68{ 69{
69 struct timeval *tv = *con_cls; 70 struct timeval *tv = *con_cls;
70 struct timeval tve; 71 struct timeval tve;
71 uint64_t delta; 72 uint64_t delta;
72 (void)cls; /* Unused. Silent compiler warning. */ 73 (void) cls; /* Unused. Silent compiler warning. */
73 (void)connection; /* Unused. Silent compiler warning. */ 74 (void) connection; /* Unused. Silent compiler warning. */
74 (void)toe; /* Unused. Silent compiler warning. */ 75 (void) toe; /* Unused. Silent compiler warning. */
75 76
76 if (NULL == tv) 77 if (NULL == tv)
77 return; 78 return;
@@ -80,10 +81,10 @@ completed_callback (void *cls,
80 delta = 0; 81 delta = 0;
81 if (tve.tv_usec >= tv->tv_usec) 82 if (tve.tv_usec >= tv->tv_usec)
82 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 83 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
83 + (tve.tv_usec - tv->tv_usec); 84 + (tve.tv_usec - tv->tv_usec);
84 else 85 else
85 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 86 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
86 - tv->tv_usec + tve.tv_usec; 87 - tv->tv_usec + tve.tv_usec;
87 if (delta < SMALL) 88 if (delta < SMALL)
88 small_deltas[delta]++; 89 small_deltas[delta]++;
89 else 90 else
@@ -94,11 +95,11 @@ completed_callback (void *cls,
94 95
95static void * 96static void *
96uri_logger_cb (void *cls, 97uri_logger_cb (void *cls,
97 const char *uri) 98 const char *uri)
98{ 99{
99 struct timeval *tv = malloc (sizeof (struct timeval)); 100 struct timeval *tv = malloc (sizeof (struct timeval));
100 (void)cls; /* Unused. Silent compiler warning. */ 101 (void) cls; /* Unused. Silent compiler warning. */
101 (void)uri; /* Unused. Silent compiler warning. */ 102 (void) uri; /* Unused. Silent compiler warning. */
102 103
103 if (NULL != tv) 104 if (NULL != tv)
104 gettimeofday (tv, NULL); 105 gettimeofday (tv, NULL);
@@ -114,12 +115,12 @@ ahc_echo (void *cls,
114 const char *version, 115 const char *version,
115 const char *upload_data, size_t *upload_data_size, void **ptr) 116 const char *upload_data, size_t *upload_data_size, void **ptr)
116{ 117{
117 (void)cls; /* Unused. Silent compiler warning. */ 118 (void) cls; /* Unused. Silent compiler warning. */
118 (void)url; /* Unused. Silent compiler warning. */ 119 (void) url; /* Unused. Silent compiler warning. */
119 (void)version; /* Unused. Silent compiler warning. */ 120 (void) version; /* Unused. Silent compiler warning. */
120 (void)upload_data; /* Unused. Silent compiler warning. */ 121 (void) upload_data; /* Unused. Silent compiler warning. */
121 (void)upload_data_size; /* Unused. Silent compiler warning. */ 122 (void) upload_data_size; /* Unused. Silent compiler warning. */
122 (void)ptr; /* Unused. Silent compiler warning. */ 123 (void) ptr; /* Unused. Silent compiler warning. */
123 124
124 if (0 != strcmp (method, "GET")) 125 if (0 != strcmp (method, "GET"))
125 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
@@ -129,53 +130,53 @@ ahc_echo (void *cls,
129 130
130/* test server key */ 131/* test server key */
131const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 132const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
132 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" 133 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n"
133 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" 134 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n"
134 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" 135 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n"
135 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" 136 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n"
136 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" 137 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n"
137 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n" 138 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n"
138 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n" 139 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n"
139 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n" 140 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n"
140 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n" 141 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n"
141 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n" 142 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n"
142 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n" 143 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n"
143 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n" 144 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n"
144 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n" 145 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n"
145 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n" 146 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n"
146 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n" 147 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n"
147 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n" 148 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n"
148 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n" 149 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n"
149 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n" 150 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n"
150 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n" 151 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n"
151 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n" 152 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n"
152 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n" 153 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n"
153 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" 154 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n"
154 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" 155 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n"
155 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" 156 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n"
156 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" 157 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n"
157 "-----END RSA PRIVATE KEY-----\n"; 158 "-----END RSA PRIVATE KEY-----\n";
158 159
159/* test server CA signed certificates */ 160/* test server CA signed certificates */
160const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 161const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
161 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 162 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
162 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 163 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n"
163 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" 164 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n"
164 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n" 165 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n"
165 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n" 166 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n"
166 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n" 167 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n"
167 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n" 168 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n"
168 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n" 169 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n"
169 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" 170 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n"
170 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n" 171 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n"
171 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n" 172 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n"
172 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n" 173 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n"
173 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n" 174 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n"
174 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n" 175 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n"
175 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n" 176 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n"
176 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n" 177 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n"
177 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n" 178 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n"
178 "-----END CERTIFICATE-----\n"; 179 "-----END CERTIFICATE-----\n";
179 180
180 181
181int 182int
@@ -185,36 +186,37 @@ main (int argc, char *const *argv)
185 unsigned int i; 186 unsigned int i;
186 187
187 if (argc != 2) 188 if (argc != 2)
188 { 189 {
189 printf ("%s PORT\n", argv[0]); 190 printf ("%s PORT\n", argv[0]);
190 return 1; 191 return 1;
191 } 192 }
192 response = MHD_create_response_from_buffer (strlen (PAGE), 193 response = MHD_create_response_from_buffer (strlen (PAGE),
193 (void *) PAGE, 194 (void *) PAGE,
194 MHD_RESPMEM_PERSISTENT); 195 MHD_RESPMEM_PERSISTENT);
195 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS 196 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
196#ifdef EPOLL_SUPPORT 197#ifdef EPOLL_SUPPORT
197 | MHD_USE_EPOLL | MHD_USE_TURBO 198 | MHD_USE_EPOLL | MHD_USE_TURBO
198#endif 199#endif
199 , 200 ,
200 atoi (argv[1]), 201 atoi (argv[1]),
201 NULL, NULL, &ahc_echo, NULL, 202 NULL, NULL, &ahc_echo, NULL,
202 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 203 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
203 MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, 204 MHD_OPTION_THREAD_POOL_SIZE, (unsigned
204 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL, 205 int) NUMBER_OF_THREADS,
205 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL, 206 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL,
206 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000, 207 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL,
207 /* Optionally, the gnutls_load_file() can be used to 208 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000,
208 load the key and the certificate from file. */ 209 /* Optionally, the gnutls_load_file() can be used to
209 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 210 load the key and the certificate from file. */
210 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 211 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
211 MHD_OPTION_END); 212 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
213 MHD_OPTION_END);
212 if (d == NULL) 214 if (d == NULL)
213 return 1; 215 return 1;
214 (void) getc (stdin); 216 (void) getc (stdin);
215 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
216 MHD_destroy_response (response); 218 MHD_destroy_response (response);
217 for (i=0;i<SMALL;i++) 219 for (i = 0; i<SMALL; i++)
218 if (0 != small_deltas[i]) 220 if (0 != small_deltas[i])
219 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]); 221 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]);
220 return 0; 222 return 0;
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index 26dacd3b..cd6539ef 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -40,15 +40,15 @@ callback (void *cls,
40 size_t buf_size) 40 size_t buf_size)
41{ 41{
42 size_t size_to_copy; 42 size_t size_to_copy;
43 struct ResponseContentCallbackParam * const param = 43 struct ResponseContentCallbackParam *const param =
44 (struct ResponseContentCallbackParam *)cls; 44 (struct ResponseContentCallbackParam *) cls;
45 45
46 /* Note: 'pos' will never exceed size of transmitted data. */ 46 /* Note: 'pos' will never exceed size of transmitted data. */
47 /* You can use 'pos == param->response_size' in next check. */ 47 /* You can use 'pos == param->response_size' in next check. */
48 if (pos >= param->response_size) 48 if (pos >= param->response_size)
49 { /* Whole response was sent. Signal end of response. */ 49 { /* Whole response was sent. Signal end of response. */
50 return MHD_CONTENT_READER_END_OF_STREAM; 50 return MHD_CONTENT_READER_END_OF_STREAM;
51 } 51 }
52 52
53 /* Pseudo code. * 53 /* Pseudo code. *
54 if (data_not_ready) 54 if (data_not_ready)
@@ -82,12 +82,13 @@ callback (void *cls,
82static void 82static void
83free_callback_param (void *cls) 83free_callback_param (void *cls)
84{ 84{
85 free(cls); 85 free (cls);
86} 86}
87 87
88 88
89static const char simple_response_text[] = "<html><head><title>Simple response</title></head>" 89static const char simple_response_text[] =
90 "<body>Simple response text</body></html>"; 90 "<html><head><title>Simple response</title></head>"
91 "<body>Simple response text</body></html>";
91 92
92 93
93static int 94static int
@@ -104,27 +105,28 @@ ahc_echo (void *cls,
104 struct ResponseContentCallbackParam *callback_param; 105 struct ResponseContentCallbackParam *callback_param;
105 struct MHD_Response *response; 106 struct MHD_Response *response;
106 int ret; 107 int ret;
107 (void)cls; /* Unused. Silent compiler warning. */ 108 (void) cls; /* Unused. Silent compiler warning. */
108 (void)url; /* Unused. Silent compiler warning. */ 109 (void) url; /* Unused. Silent compiler warning. */
109 (void)version; /* Unused. Silent compiler warning. */ 110 (void) version; /* Unused. Silent compiler warning. */
110 (void)upload_data; /* Unused. Silent compiler warning. */ 111 (void) upload_data; /* Unused. Silent compiler warning. */
111 (void)upload_data_size; /* Unused. Silent compiler warning. */ 112 (void) upload_data_size; /* Unused. Silent compiler warning. */
112 113
113 if (0 != strcmp (method, "GET")) 114 if (0 != strcmp (method, "GET"))
114 return MHD_NO; /* unexpected method */ 115 return MHD_NO; /* unexpected method */
115 if (&aptr != *ptr) 116 if (&aptr != *ptr)
116 { 117 {
117 /* do never respond on first call */ 118 /* do never respond on first call */
118 *ptr = &aptr; 119 *ptr = &aptr;
119 return MHD_YES; 120 return MHD_YES;
120 } 121 }
121 122
122 callback_param = malloc (sizeof(struct ResponseContentCallbackParam)); 123 callback_param = malloc (sizeof(struct ResponseContentCallbackParam));
123 if (NULL == callback_param) 124 if (NULL == callback_param)
124 return MHD_NO; /* Not enough memory. */ 125 return MHD_NO; /* Not enough memory. */
125 126
126 callback_param->response_data = simple_response_text; 127 callback_param->response_data = simple_response_text;
127 callback_param->response_size = (sizeof(simple_response_text)/sizeof(char)) - 1; 128 callback_param->response_size = (sizeof(simple_response_text)
129 / sizeof(char)) - 1;
128 130
129 *ptr = NULL; /* reset when done */ 131 *ptr = NULL; /* reset when done */
130 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 132 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
@@ -150,28 +152,28 @@ main (int argc, char *const *argv)
150 int port; 152 int port;
151 153
152 if (argc != 2) 154 if (argc != 2)
153 { 155 {
154 printf ("%s PORT\n", argv[0]); 156 printf ("%s PORT\n", argv[0]);
155 return 1; 157 return 1;
156 } 158 }
157 port = atoi (argv[1]); 159 port = atoi (argv[1]);
158 if ( (1 > port) || 160 if ( (1 > port) ||
159 (port > UINT16_MAX) ) 161 (port > UINT16_MAX) )
160 { 162 {
161 fprintf (stderr, 163 fprintf (stderr,
162 "Port must be a number between 1 and 65535\n"); 164 "Port must be a number between 1 and 65535\n");
163 return 1; 165 return 1;
164 } 166 }
165 d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ 167 d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
166 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 168 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
167 /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ 169 /* 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, */ 170 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
169 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ 171 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
170 (uint16_t) port, 172 (uint16_t) port,
171 NULL, NULL, 173 NULL, NULL,
172 &ahc_echo, NULL, 174 &ahc_echo, NULL,
173 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 175 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
174 MHD_OPTION_END); 176 MHD_OPTION_END);
175 if (NULL == d) 177 if (NULL == d)
176 return 1; 178 return 1;
177 (void) getc (stdin); 179 (void) getc (stdin);
diff --git a/src/examples/connection_close.c b/src/examples/connection_close.c
index 88222cbf..43ee379f 100644
--- a/src/examples/connection_close.c
+++ b/src/examples/connection_close.c
@@ -25,7 +25,8 @@
25#include "platform.h" 25#include "platform.h"
26#include <microhttpd.h> 26#include <microhttpd.h>
27 27
28#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 28#define PAGE \
29 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
29 30
30static int 31static int
31ahc_echo (void *cls, 32ahc_echo (void *cls,
@@ -39,23 +40,23 @@ ahc_echo (void *cls,
39 const char *me = cls; 40 const char *me = cls;
40 struct MHD_Response *response; 41 struct MHD_Response *response;
41 int ret; 42 int ret;
42 (void)url; /* Unused. Silent compiler warning. */ 43 (void) url; /* Unused. Silent compiler warning. */
43 (void)version; /* Unused. Silent compiler warning. */ 44 (void) version; /* Unused. Silent compiler warning. */
44 (void)upload_data; /* Unused. Silent compiler warning. */ 45 (void) upload_data; /* Unused. Silent compiler warning. */
45 (void)upload_data_size; /* Unused. Silent compiler warning. */ 46 (void) upload_data_size; /* Unused. Silent compiler warning. */
46 47
47 if (0 != strcmp (method, "GET")) 48 if (0 != strcmp (method, "GET"))
48 return MHD_NO; /* unexpected method */ 49 return MHD_NO; /* unexpected method */
49 if (&aptr != *ptr) 50 if (&aptr != *ptr)
50 { 51 {
51 /* do never respond on first call */ 52 /* do never respond on first call */
52 *ptr = &aptr; 53 *ptr = &aptr;
53 return MHD_YES; 54 return MHD_YES;
54 } 55 }
55 *ptr = NULL; /* reset when done */ 56 *ptr = NULL; /* reset when done */
56 response = MHD_create_response_from_buffer (strlen (me), 57 response = MHD_create_response_from_buffer (strlen (me),
57 (void *) me, 58 (void *) me,
58 MHD_RESPMEM_PERSISTENT); 59 MHD_RESPMEM_PERSISTENT);
59 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 60 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
60 MHD_destroy_response (response); 61 MHD_destroy_response (response);
61 return ret; 62 return ret;
@@ -65,27 +66,27 @@ ahc_echo (void *cls,
65 66
66static void 67static void
67request_completed (void *cls, 68request_completed (void *cls,
68 struct MHD_Connection *connection, 69 struct MHD_Connection *connection,
69 void **con_cls, 70 void **con_cls,
70 enum MHD_RequestTerminationCode toe) 71 enum MHD_RequestTerminationCode toe)
71{ 72{
72 fprintf (stderr, 73 fprintf (stderr,
73 "%llu - RC: %d\n", 74 "%llu - RC: %d\n",
74 (unsigned long long) __rdtsc(), 75 (unsigned long long) __rdtsc (),
75 toe); 76 toe);
76} 77}
77 78
78 79
79static void 80static void
80connection_completed (void *cls, 81connection_completed (void *cls,
81 struct MHD_Connection *connection, 82 struct MHD_Connection *connection,
82 void **socket_context, 83 void **socket_context,
83 enum MHD_ConnectionNotificationCode toe) 84 enum MHD_ConnectionNotificationCode toe)
84{ 85{
85 fprintf (stderr, 86 fprintf (stderr,
86 "%llu - CC: %d\n", 87 "%llu - CC: %d\n",
87 (unsigned long long) __rdtsc(), 88 (unsigned long long) __rdtsc (),
88 toe); 89 toe);
89} 90}
90 91
91 92
@@ -95,22 +96,23 @@ main (int argc, char *const *argv)
95 struct MHD_Daemon *d; 96 struct MHD_Daemon *d;
96 97
97 if (argc != 2) 98 if (argc != 2)
98 { 99 {
99 printf ("%s PORT\n", argv[0]); 100 printf ("%s PORT\n", argv[0]);
100 return 1; 101 return 1;
101 } 102 }
102 d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ 103 d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
103 /* MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ 104 /* MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
104 /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ 105 /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
105 MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, // | MHD_USE_ITC, 106 MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD
106 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ 107 | MHD_USE_ERROR_LOG | MHD_USE_POLL, // | MHD_USE_ITC,
107 atoi (argv[1]), 108 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
108 NULL, NULL, &ahc_echo, PAGE, 109 atoi (argv[1]),
109 MHD_OPTION_NOTIFY_COMPLETED, &request_completed, NULL, 110 NULL, NULL, &ahc_echo, PAGE,
110 MHD_OPTION_NOTIFY_CONNECTION, &connection_completed, NULL, 111 MHD_OPTION_NOTIFY_COMPLETED, &request_completed, NULL,
111 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 112 MHD_OPTION_NOTIFY_CONNECTION, &connection_completed, NULL,
112 MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, 113 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
113 MHD_OPTION_END); 114 MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
115 MHD_OPTION_END);
114 if (d == NULL) 116 if (d == NULL)
115 return 1; 117 return 1;
116 (void) getc (stdin); 118 (void) getc (stdin);
diff --git a/src/examples/demo.c b/src/examples/demo.c
index e93fb34b..375f2a63 100644
--- a/src/examples/demo.c
+++ b/src/examples/demo.c
@@ -41,10 +41,10 @@
41#include <limits.h> 41#include <limits.h>
42#include <ctype.h> 42#include <ctype.h>
43 43
44#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 44#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
45#undef CPU_COUNT 45#undef CPU_COUNT
46#endif 46#endif
47#if !defined(CPU_COUNT) 47#if ! defined(CPU_COUNT)
48#define CPU_COUNT 2 48#define CPU_COUNT 2
49#endif 49#endif
50 50
@@ -73,46 +73,50 @@
73/** 73/**
74 * Page returned for file-not-found. 74 * Page returned for file-not-found.
75 */ 75 */
76#define FILE_NOT_FOUND_PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 76#define FILE_NOT_FOUND_PAGE \
77 "<html><head><title>File not found</title></head><body>File not found</body></html>"
77 78
78 79
79/** 80/**
80 * Page returned for internal errors. 81 * Page returned for internal errors.
81 */ 82 */
82#define INTERNAL_ERROR_PAGE "<html><head><title>Internal error</title></head><body>Internal error</body></html>" 83#define INTERNAL_ERROR_PAGE \
84 "<html><head><title>Internal error</title></head><body>Internal error</body></html>"
83 85
84 86
85/** 87/**
86 * Page returned for refused requests. 88 * Page returned for refused requests.
87 */ 89 */
88#define REQUEST_REFUSED_PAGE "<html><head><title>Request refused</title></head><body>Request refused (file exists?)</body></html>" 90#define REQUEST_REFUSED_PAGE \
91 "<html><head><title>Request refused</title></head><body>Request refused (file exists?)</body></html>"
89 92
90 93
91/** 94/**
92 * Head of index page. 95 * Head of index page.
93 */ 96 */
94#define INDEX_PAGE_HEADER "<html>\n<head><title>Welcome</title></head>\n<body>\n"\ 97#define INDEX_PAGE_HEADER \
95 "<h1>Upload</h1>\n"\ 98 "<html>\n<head><title>Welcome</title></head>\n<body>\n" \
96 "<form method=\"POST\" enctype=\"multipart/form-data\" action=\"/\">\n"\ 99 "<h1>Upload</h1>\n" \
97 "<dl><dt>Content type:</dt><dd>"\ 100 "<form method=\"POST\" enctype=\"multipart/form-data\" action=\"/\">\n" \
98 "<input type=\"radio\" name=\"category\" value=\"books\">Book</input>"\ 101 "<dl><dt>Content type:</dt><dd>" \
99 "<input type=\"radio\" name=\"category\" value=\"images\">Image</input>"\ 102 "<input type=\"radio\" name=\"category\" value=\"books\">Book</input>" \
100 "<input type=\"radio\" name=\"category\" value=\"music\">Music</input>"\ 103 "<input type=\"radio\" name=\"category\" value=\"images\">Image</input>" \
101 "<input type=\"radio\" name=\"category\" value=\"software\">Software</input>"\ 104 "<input type=\"radio\" name=\"category\" value=\"music\">Music</input>" \
102 "<input type=\"radio\" name=\"category\" value=\"videos\">Videos</input>\n"\ 105 "<input type=\"radio\" name=\"category\" value=\"software\">Software</input>" \
103 "<input type=\"radio\" name=\"category\" value=\"other\" checked>Other</input></dd>"\ 106 "<input type=\"radio\" name=\"category\" value=\"videos\">Videos</input>\n" \
104 "<dt>Language:</dt><dd>"\ 107 "<input type=\"radio\" name=\"category\" value=\"other\" checked>Other</input></dd>" \
105 "<input type=\"radio\" name=\"language\" value=\"no-lang\" checked>none</input>"\ 108 "<dt>Language:</dt><dd>" \
106 "<input type=\"radio\" name=\"language\" value=\"en\">English</input>"\ 109 "<input type=\"radio\" name=\"language\" value=\"no-lang\" checked>none</input>" \
107 "<input type=\"radio\" name=\"language\" value=\"de\">German</input>"\ 110 "<input type=\"radio\" name=\"language\" value=\"en\">English</input>" \
108 "<input type=\"radio\" name=\"language\" value=\"fr\">French</input>"\ 111 "<input type=\"radio\" name=\"language\" value=\"de\">German</input>" \
109 "<input type=\"radio\" name=\"language\" value=\"es\">Spanish</input></dd>\n"\ 112 "<input type=\"radio\" name=\"language\" value=\"fr\">French</input>" \
110 "<dt>File:</dt><dd>"\ 113 "<input type=\"radio\" name=\"language\" value=\"es\">Spanish</input></dd>\n" \
111 "<input type=\"file\" name=\"upload\"/></dd></dl>"\ 114 "<dt>File:</dt><dd>" \
112 "<input type=\"submit\" value=\"Send!\"/>\n"\ 115 "<input type=\"file\" name=\"upload\"/></dd></dl>" \
113 "</form>\n"\ 116 "<input type=\"submit\" value=\"Send!\"/>\n" \
114 "<h1>Download</h1>\n"\ 117 "</form>\n" \
115 "<ol>\n" 118 "<h1>Download</h1>\n" \
119 "<ol>\n"
116 120
117/** 121/**
118 * Footer of index page. 122 * Footer of index page.
@@ -124,16 +128,15 @@
124 * NULL-terminated array of supported upload categories. Should match HTML 128 * NULL-terminated array of supported upload categories. Should match HTML
125 * in the form. 129 * in the form.
126 */ 130 */
127static const char * const categories[] = 131static const char *const categories[] = {
128 { 132 "books",
129 "books", 133 "images",
130 "images", 134 "music",
131 "music", 135 "software",
132 "software", 136 "videos",
133 "videos", 137 "other",
134 "other", 138 NULL,
135 NULL, 139};
136 };
137 140
138 141
139/** 142/**
@@ -157,15 +160,14 @@ struct Language
157 * NULL-terminated array of supported upload categories. Should match HTML 160 * NULL-terminated array of supported upload categories. Should match HTML
158 * in the form. 161 * in the form.
159 */ 162 */
160static const struct Language languages[] = 163static const struct Language languages[] = {
161 { 164 { "no-lang", "No language specified" },
162 { "no-lang", "No language specified" }, 165 { "en", "English" },
163 { "en", "English" }, 166 { "de", "German" },
164 { "de", "German" }, 167 { "fr", "French" },
165 { "fr", "French" }, 168 { "es", "Spanish" },
166 { "es", "Spanish" }, 169 { NULL, NULL },
167 { NULL, NULL }, 170};
168 };
169 171
170 172
171/** 173/**
@@ -210,8 +212,8 @@ static void
210mark_as_html (struct MHD_Response *response) 212mark_as_html (struct MHD_Response *response)
211{ 213{
212 (void) MHD_add_response_header (response, 214 (void) MHD_add_response_header (response,
213 MHD_HTTP_HEADER_CONTENT_TYPE, 215 MHD_HTTP_HEADER_CONTENT_TYPE,
214 "text/html"); 216 "text/html");
215} 217}
216 218
217 219
@@ -264,7 +266,7 @@ struct ResponseDataContext
264 */ 266 */
265static int 267static int
266list_directory (struct ResponseDataContext *rdc, 268list_directory (struct ResponseDataContext *rdc,
267 const char *dirname) 269 const char *dirname)
268{ 270{
269 char fullname[PATH_MAX]; 271 char fullname[PATH_MAX];
270 struct stat sbuf; 272 struct stat sbuf;
@@ -274,35 +276,35 @@ list_directory (struct ResponseDataContext *rdc,
274 if (NULL == (dir = opendir (dirname))) 276 if (NULL == (dir = opendir (dirname)))
275 return MHD_NO; 277 return MHD_NO;
276 while (NULL != (de = readdir (dir))) 278 while (NULL != (de = readdir (dir)))
279 {
280 if ('.' == de->d_name[0])
281 continue;
282 if (sizeof (fullname) <= (unsigned int)
283 snprintf (fullname, sizeof (fullname),
284 "%s/%s",
285 dirname, de->d_name))
286 continue; /* ugh, file too long? how can this be!? */
287 if (0 != stat (fullname, &sbuf))
288 continue; /* ugh, failed to 'stat' */
289 if (! S_ISREG (sbuf.st_mode))
290 continue; /* not a regular file, skip */
291 if (rdc->off + 1024 > rdc->buf_len)
277 { 292 {
278 if ('.' == de->d_name[0]) 293 void *r;
279 continue; 294
280 if (sizeof (fullname) <= (unsigned int) 295 if ( (2 * rdc->buf_len + 1024) < rdc->buf_len)
281 snprintf (fullname, sizeof (fullname), 296 break; /* more than SIZE_T _index_ size? Too big for us */
282 "%s/%s", 297 rdc->buf_len = 2 * rdc->buf_len + 1024;
283 dirname, de->d_name)) 298 if (NULL == (r = realloc (rdc->buf, rdc->buf_len)))
284 continue; /* ugh, file too long? how can this be!? */ 299 break; /* out of memory */
285 if (0 != stat (fullname, &sbuf)) 300 rdc->buf = r;
286 continue; /* ugh, failed to 'stat' */
287 if (! S_ISREG (sbuf.st_mode))
288 continue; /* not a regular file, skip */
289 if (rdc->off + 1024 > rdc->buf_len)
290 {
291 void *r;
292
293 if ( (2 * rdc->buf_len + 1024) < rdc->buf_len)
294 break; /* more than SIZE_T _index_ size? Too big for us */
295 rdc->buf_len = 2 * rdc->buf_len + 1024;
296 if (NULL == (r = realloc (rdc->buf, rdc->buf_len)))
297 break; /* out of memory */
298 rdc->buf = r;
299 }
300 rdc->off += snprintf (&rdc->buf[rdc->off],
301 rdc->buf_len - rdc->off,
302 "<li><a href=\"/%s\">%s</a></li>\n",
303 fullname,
304 de->d_name);
305 } 301 }
302 rdc->off += snprintf (&rdc->buf[rdc->off],
303 rdc->buf_len - rdc->off,
304 "<li><a href=\"/%s\">%s</a></li>\n",
305 fullname,
306 de->d_name);
307 }
306 (void) closedir (dir); 308 (void) closedir (dir);
307 return MHD_YES; 309 return MHD_YES;
308} 310}
@@ -326,65 +328,66 @@ update_directory ()
326 328
327 rdc.buf_len = initial_allocation; 329 rdc.buf_len = initial_allocation;
328 if (NULL == (rdc.buf = malloc (rdc.buf_len))) 330 if (NULL == (rdc.buf = malloc (rdc.buf_len)))
329 { 331 {
330 update_cached_response (NULL); 332 update_cached_response (NULL);
331 return; 333 return;
332 } 334 }
333 rdc.off = snprintf (rdc.buf, rdc.buf_len, 335 rdc.off = snprintf (rdc.buf, rdc.buf_len,
334 "%s", 336 "%s",
335 INDEX_PAGE_HEADER); 337 INDEX_PAGE_HEADER);
336 for (language_idx = 0; NULL != languages[language_idx].dirname; language_idx++) 338 for (language_idx = 0; NULL != languages[language_idx].dirname;
339 language_idx++)
340 {
341 language = &languages[language_idx];
342
343 if (0 != stat (language->dirname, &sbuf))
344 continue; /* empty */
345 /* we ensured always +1k room, filenames are ~256 bytes,
346 so there is always still enough space for the header
347 without need for an additional reallocation check. */
348 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
349 "<h2>%s</h2>\n",
350 language->longname);
351 for (category_idx = 0; NULL != categories[category_idx]; category_idx++)
337 { 352 {
338 language = &languages[language_idx]; 353 category = categories[category_idx];
354 snprintf (dir_name, sizeof (dir_name),
355 "%s/%s",
356 language->dirname,
357 category);
358 if (0 != stat (dir_name, &sbuf))
359 continue; /* empty */
339 360
340 if (0 != stat (language->dirname, &sbuf))
341 continue; /* empty */
342 /* we ensured always +1k room, filenames are ~256 bytes, 361 /* we ensured always +1k room, filenames are ~256 bytes,
343 so there is always still enough space for the header 362 so there is always still enough space for the header
344 without need for an additional reallocation check. */ 363 without need for an additional reallocation check. */
345 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off, 364 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
346 "<h2>%s</h2>\n", 365 "<h3>%s</h3>\n",
347 language->longname); 366 category);
348 for (category_idx = 0; NULL != categories[category_idx]; category_idx++) 367
349 { 368 if (MHD_NO == list_directory (&rdc, dir_name))
350 category = categories[category_idx]; 369 {
351 snprintf (dir_name, sizeof (dir_name), 370 free (rdc.buf);
352 "%s/%s", 371 update_cached_response (NULL);
353 language->dirname, 372 return;
354 category); 373 }
355 if (0 != stat (dir_name, &sbuf))
356 continue; /* empty */
357
358 /* we ensured always +1k room, filenames are ~256 bytes,
359 so there is always still enough space for the header
360 without need for an additional reallocation check. */
361 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
362 "<h3>%s</h3>\n",
363 category);
364
365 if (MHD_NO == list_directory (&rdc, dir_name))
366 {
367 free (rdc.buf);
368 update_cached_response (NULL);
369 return;
370 }
371 }
372 } 374 }
375 }
373 /* we ensured always +1k room, filenames are ~256 bytes, 376 /* we ensured always +1k room, filenames are ~256 bytes,
374 so there is always still enough space for the footer 377 so there is always still enough space for the footer
375 without need for a final reallocation check. */ 378 without need for a final reallocation check. */
376 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off, 379 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
377 "%s", 380 "%s",
378 INDEX_PAGE_FOOTER); 381 INDEX_PAGE_FOOTER);
379 initial_allocation = rdc.buf_len; /* remember for next time */ 382 initial_allocation = rdc.buf_len; /* remember for next time */
380 response = MHD_create_response_from_buffer (rdc.off, 383 response = MHD_create_response_from_buffer (rdc.off,
381 rdc.buf, 384 rdc.buf,
382 MHD_RESPMEM_MUST_FREE); 385 MHD_RESPMEM_MUST_FREE);
383 mark_as_html (response); 386 mark_as_html (response);
384#if FORCE_CLOSE 387#if FORCE_CLOSE
385 (void) MHD_add_response_header (response, 388 (void) MHD_add_response_header (response,
386 MHD_HTTP_HEADER_CONNECTION, 389 MHD_HTTP_HEADER_CONNECTION,
387 "close"); 390 "close");
388#endif 391#endif
389 update_cached_response (response); 392 update_cached_response (response);
390} 393}
@@ -443,8 +446,8 @@ struct UploadContext
443 */ 446 */
444static int 447static int
445do_append (char **ret, 448do_append (char **ret,
446 const char *data, 449 const char *data,
447 size_t size) 450 size_t size)
448{ 451{
449 char *buf; 452 char *buf;
450 size_t old_len; 453 size_t old_len;
@@ -456,15 +459,15 @@ do_append (char **ret,
456 if (NULL == (buf = malloc (old_len + size + 1))) 459 if (NULL == (buf = malloc (old_len + size + 1)))
457 return MHD_NO; 460 return MHD_NO;
458 if (NULL != *ret) 461 if (NULL != *ret)
459 { 462 {
460 memcpy (buf, 463 memcpy (buf,
461 *ret, 464 *ret,
462 old_len); 465 old_len);
463 free (*ret); 466 free (*ret);
464 } 467 }
465 memcpy (&buf[old_len], 468 memcpy (&buf[old_len],
466 data, 469 data,
467 size); 470 size);
468 buf[old_len + size] = '\0'; 471 buf[old_len + size] = '\0';
469 *ret = buf; 472 *ret = buf;
470 return MHD_YES; 473 return MHD_YES;
@@ -492,119 +495,119 @@ do_append (char **ret,
492 */ 495 */
493static int 496static int
494process_upload_data (void *cls, 497process_upload_data (void *cls,
495 enum MHD_ValueKind kind, 498 enum MHD_ValueKind kind,
496 const char *key, 499 const char *key,
497 const char *filename, 500 const char *filename,
498 const char *content_type, 501 const char *content_type,
499 const char *transfer_encoding, 502 const char *transfer_encoding,
500 const char *data, 503 const char *data,
501 uint64_t off, 504 uint64_t off,
502 size_t size) 505 size_t size)
503{ 506{
504 struct UploadContext *uc = cls; 507 struct UploadContext *uc = cls;
505 int i; 508 int i;
506 (void)kind; /* Unused. Silent compiler warning. */ 509 (void) kind; /* Unused. Silent compiler warning. */
507 (void)content_type; /* Unused. Silent compiler warning. */ 510 (void) content_type; /* Unused. Silent compiler warning. */
508 (void)transfer_encoding; /* Unused. Silent compiler warning. */ 511 (void) transfer_encoding; /* Unused. Silent compiler warning. */
509 (void)off; /* Unused. Silent compiler warning. */ 512 (void) off; /* Unused. Silent compiler warning. */
510 513
511 if (0 == strcmp (key, "category")) 514 if (0 == strcmp (key, "category"))
512 return do_append (&uc->category, data, size); 515 return do_append (&uc->category, data, size);
513 if (0 == strcmp (key, "language")) 516 if (0 == strcmp (key, "language"))
514 return do_append (&uc->language, data, size); 517 return do_append (&uc->language, data, size);
515 if (0 != strcmp (key, "upload")) 518 if (0 != strcmp (key, "upload"))
516 { 519 {
517 fprintf (stderr, 520 fprintf (stderr,
518 "Ignoring unexpected form value `%s'\n", 521 "Ignoring unexpected form value `%s'\n",
519 key); 522 key);
520 return MHD_YES; /* ignore */ 523 return MHD_YES; /* ignore */
521 } 524 }
522 if (NULL == filename) 525 if (NULL == filename)
523 { 526 {
524 fprintf (stderr, "No filename, aborting upload\n"); 527 fprintf (stderr, "No filename, aborting upload\n");
525 return MHD_NO; /* no filename, error */ 528 return MHD_NO; /* no filename, error */
526 } 529 }
527 if ( (NULL == uc->category) || 530 if ( (NULL == uc->category) ||
528 (NULL == uc->language) ) 531 (NULL == uc->language) )
532 {
533 fprintf (stderr,
534 "Missing form data for upload `%s'\n",
535 filename);
536 uc->response = request_refused_response;
537 return MHD_NO;
538 }
539 if (-1 == uc->fd)
540 {
541 char fn[PATH_MAX];
542
543 if ( (NULL != strstr (filename, "..")) ||
544 (NULL != strchr (filename, '/')) ||
545 (NULL != strchr (filename, '\\')) )
529 { 546 {
530 fprintf (stderr,
531 "Missing form data for upload `%s'\n",
532 filename);
533 uc->response = request_refused_response; 547 uc->response = request_refused_response;
534 return MHD_NO; 548 return MHD_NO;
535 } 549 }
536 if (-1 == uc->fd) 550 /* create directories -- if they don't exist already */
537 {
538 char fn[PATH_MAX];
539
540 if ( (NULL != strstr (filename, "..")) ||
541 (NULL != strchr (filename, '/')) ||
542 (NULL != strchr (filename, '\\')) )
543 {
544 uc->response = request_refused_response;
545 return MHD_NO;
546 }
547 /* create directories -- if they don't exist already */
548#ifdef WINDOWS 551#ifdef WINDOWS
549 (void) mkdir (uc->language); 552 (void) mkdir (uc->language);
550#else 553#else
551 (void) mkdir (uc->language, S_IRWXU); 554 (void) mkdir (uc->language, S_IRWXU);
552#endif 555#endif
553 snprintf (fn, sizeof (fn), 556 snprintf (fn, sizeof (fn),
554 "%s/%s", 557 "%s/%s",
555 uc->language, 558 uc->language,
556 uc->category); 559 uc->category);
557#ifdef WINDOWS 560#ifdef WINDOWS
558 (void) mkdir (fn); 561 (void) mkdir (fn);
559#else 562#else
560 (void) mkdir (fn, S_IRWXU); 563 (void) mkdir (fn, S_IRWXU);
561#endif 564#endif
562 /* open file */ 565 /* open file */
563 snprintf (fn, sizeof (fn), 566 snprintf (fn, sizeof (fn),
564 "%s/%s/%s", 567 "%s/%s/%s",
565 uc->language, 568 uc->language,
566 uc->category, 569 uc->category,
567 filename); 570 filename);
568 for (i=strlen (fn)-1;i>=0;i--) 571 for (i = strlen (fn) - 1; i>=0; i--)
569 if (! isprint ((unsigned char) fn[i])) 572 if (! isprint ((unsigned char) fn[i]))
570 fn[i] = '_'; 573 fn[i] = '_';
571 uc->fd = open (fn, 574 uc->fd = open (fn,
572 O_CREAT | O_EXCL 575 O_CREAT | O_EXCL
573#if O_LARGEFILE 576#if O_LARGEFILE
574 | O_LARGEFILE 577 | O_LARGEFILE
575#endif 578#endif
576 | O_WRONLY, 579 | O_WRONLY,
577 S_IRUSR | S_IWUSR); 580 S_IRUSR | S_IWUSR);
578 if (-1 == uc->fd) 581 if (-1 == uc->fd)
579 { 582 {
580 fprintf (stderr, 583 fprintf (stderr,
581 "Error opening file `%s' for upload: %s\n", 584 "Error opening file `%s' for upload: %s\n",
582 fn, 585 fn,
583 strerror (errno)); 586 strerror (errno));
584 uc->response = request_refused_response; 587 uc->response = request_refused_response;
585 return MHD_NO; 588 return MHD_NO;
586 }
587 uc->filename = strdup (fn);
588 } 589 }
590 uc->filename = strdup (fn);
591 }
589 if ( (0 != size) && 592 if ( (0 != size) &&
590 (size != (size_t) write (uc->fd, data, size)) ) 593 (size != (size_t) write (uc->fd, data, size)) )
594 {
595 /* write failed; likely: disk full */
596 fprintf (stderr,
597 "Error writing to file `%s': %s\n",
598 uc->filename,
599 strerror (errno));
600 uc->response = internal_error_response;
601 (void) close (uc->fd);
602 uc->fd = -1;
603 if (NULL != uc->filename)
591 { 604 {
592 /* write failed; likely: disk full */ 605 unlink (uc->filename);
593 fprintf (stderr, 606 free (uc->filename);
594 "Error writing to file `%s': %s\n", 607 uc->filename = NULL;
595 uc->filename,
596 strerror (errno));
597 uc->response = internal_error_response;
598 (void) close (uc->fd);
599 uc->fd = -1;
600 if (NULL != uc->filename)
601 {
602 unlink (uc->filename);
603 free (uc->filename);
604 uc->filename = NULL;
605 }
606 return MHD_NO;
607 } 608 }
609 return MHD_NO;
610 }
608 return MHD_YES; 611 return MHD_YES;
609} 612}
610 613
@@ -622,32 +625,32 @@ process_upload_data (void *cls,
622 */ 625 */
623static void 626static void
624response_completed_callback (void *cls, 627response_completed_callback (void *cls,
625 struct MHD_Connection *connection, 628 struct MHD_Connection *connection,
626 void **con_cls, 629 void **con_cls,
627 enum MHD_RequestTerminationCode toe) 630 enum MHD_RequestTerminationCode toe)
628{ 631{
629 struct UploadContext *uc = *con_cls; 632 struct UploadContext *uc = *con_cls;
630 (void)cls; /* Unused. Silent compiler warning. */ 633 (void) cls; /* Unused. Silent compiler warning. */
631 (void)connection; /* Unused. Silent compiler warning. */ 634 (void) connection; /* Unused. Silent compiler warning. */
632 (void)toe; /* Unused. Silent compiler warning. */ 635 (void) toe; /* Unused. Silent compiler warning. */
633 636
634 if (NULL == uc) 637 if (NULL == uc)
635 return; /* this request wasn't an upload request */ 638 return; /* this request wasn't an upload request */
636 if (NULL != uc->pp) 639 if (NULL != uc->pp)
637 { 640 {
638 MHD_destroy_post_processor (uc->pp); 641 MHD_destroy_post_processor (uc->pp);
639 uc->pp = NULL; 642 uc->pp = NULL;
640 } 643 }
641 if (-1 != uc->fd) 644 if (-1 != uc->fd)
642 { 645 {
643 (void) close (uc->fd); 646 (void) close (uc->fd);
644 if (NULL != uc->filename) 647 if (NULL != uc->filename)
645 { 648 {
646 fprintf (stderr, 649 fprintf (stderr,
647 "Upload of file `%s' failed (incomplete or aborted), removing file.\n", 650 "Upload of file `%s' failed (incomplete or aborted), removing file.\n",
648 uc->filename); 651 uc->filename);
649 (void) unlink (uc->filename); 652 (void) unlink (uc->filename);
650 } 653 }
651 } 654 }
652 if (NULL != uc->filename) 655 if (NULL != uc->filename)
653 free (uc->filename); 656 free (uc->filename);
@@ -669,12 +672,12 @@ return_directory_response (struct MHD_Connection *connection)
669 (void) pthread_mutex_lock (&mutex); 672 (void) pthread_mutex_lock (&mutex);
670 if (NULL == cached_directory_response) 673 if (NULL == cached_directory_response)
671 ret = MHD_queue_response (connection, 674 ret = MHD_queue_response (connection,
672 MHD_HTTP_INTERNAL_SERVER_ERROR, 675 MHD_HTTP_INTERNAL_SERVER_ERROR,
673 internal_error_response); 676 internal_error_response);
674 else 677 else
675 ret = MHD_queue_response (connection, 678 ret = MHD_queue_response (connection,
676 MHD_HTTP_OK, 679 MHD_HTTP_OK,
677 cached_directory_response); 680 cached_directory_response);
678 (void) pthread_mutex_unlock (&mutex); 681 (void) pthread_mutex_unlock (&mutex);
679 return ret; 682 return ret;
680} 683}
@@ -695,12 +698,12 @@ return_directory_response (struct MHD_Connection *connection)
695 */ 698 */
696static int 699static int
697generate_page (void *cls, 700generate_page (void *cls,
698 struct MHD_Connection *connection, 701 struct MHD_Connection *connection,
699 const char *url, 702 const char *url,
700 const char *method, 703 const char *method,
701 const char *version, 704 const char *version,
702 const char *upload_data, 705 const char *upload_data,
703 size_t *upload_data_size, void **ptr) 706 size_t *upload_data_size, void **ptr)
704{ 707{
705 struct MHD_Response *response; 708 struct MHD_Response *response;
706 int ret; 709 int ret;
@@ -710,117 +713,117 @@ generate_page (void *cls,
710 (void) version; /* Unused. Silent compiler warning. */ 713 (void) version; /* Unused. Silent compiler warning. */
711 714
712 if (0 != strcmp (url, "/")) 715 if (0 != strcmp (url, "/"))
713 { 716 {
714 /* should be file download */ 717 /* should be file download */
715#ifdef MHD_HAVE_LIBMAGIC 718#ifdef MHD_HAVE_LIBMAGIC
716 char file_data[MAGIC_HEADER_SIZE]; 719 char file_data[MAGIC_HEADER_SIZE];
717 ssize_t got; 720 ssize_t got;
718#endif /* MHD_HAVE_LIBMAGIC */ 721#endif /* MHD_HAVE_LIBMAGIC */
719 const char *mime; 722 const char *mime;
720 723
721 if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) && 724 if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) &&
722 (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 725 (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) )
723 return MHD_NO; /* unexpected method (we're not polite...) */ 726 return MHD_NO; /* unexpected method (we're not polite...) */
724 fd = -1; 727 fd = -1;
725 if ( (NULL == strstr (&url[1], "..")) && 728 if ( (NULL == strstr (&url[1], "..")) &&
726 ('/' != url[1]) ) 729 ('/' != url[1]) )
727 { 730 {
728 fd = open (&url[1], O_RDONLY); 731 fd = open (&url[1], O_RDONLY);
729 if ( (-1 != fd) && 732 if ( (-1 != fd) &&
730 ( (0 != fstat (fd, &buf)) || 733 ( (0 != fstat (fd, &buf)) ||
731 (! S_ISREG (buf.st_mode)) ) ) 734 (! S_ISREG (buf.st_mode)) ) )
732 { 735 {
733 (void) close (fd); 736 (void) close (fd);
734 fd = -1; 737 fd = -1;
735 } 738 }
736 } 739 }
737 if (-1 == fd) 740 if (-1 == fd)
738 return MHD_queue_response (connection, 741 return MHD_queue_response (connection,
739 MHD_HTTP_NOT_FOUND, 742 MHD_HTTP_NOT_FOUND,
740 file_not_found_response); 743 file_not_found_response);
741#ifdef MHD_HAVE_LIBMAGIC 744#ifdef MHD_HAVE_LIBMAGIC
742 /* read beginning of the file to determine mime type */ 745 /* read beginning of the file to determine mime type */
743 got = read (fd, file_data, sizeof (file_data)); 746 got = read (fd, file_data, sizeof (file_data));
744 (void) lseek (fd, 0, SEEK_SET); 747 (void) lseek (fd, 0, SEEK_SET);
745 if (-1 != got) 748 if (-1 != got)
746 mime = magic_buffer (magic, file_data, got); 749 mime = magic_buffer (magic, file_data, got);
747 else 750 else
748#endif /* MHD_HAVE_LIBMAGIC */ 751#endif /* MHD_HAVE_LIBMAGIC */
749 mime = NULL; 752 mime = NULL;
750 753
751 if (NULL == (response = MHD_create_response_from_fd (buf.st_size, 754 if (NULL == (response = MHD_create_response_from_fd (buf.st_size,
752 fd))) 755 fd)))
753 { 756 {
754 /* internal error (i.e. out of memory) */ 757 /* internal error (i.e. out of memory) */
755 (void) close (fd); 758 (void) close (fd);
756 return MHD_NO; 759 return MHD_NO;
757 }
758
759 /* add mime type if we had one */
760 if (NULL != mime)
761 (void) MHD_add_response_header (response,
762 MHD_HTTP_HEADER_CONTENT_TYPE,
763 mime);
764 ret = MHD_queue_response (connection,
765 MHD_HTTP_OK,
766 response);
767 MHD_destroy_response (response);
768 return ret;
769 } 760 }
770 761
762 /* add mime type if we had one */
763 if (NULL != mime)
764 (void) MHD_add_response_header (response,
765 MHD_HTTP_HEADER_CONTENT_TYPE,
766 mime);
767 ret = MHD_queue_response (connection,
768 MHD_HTTP_OK,
769 response);
770 MHD_destroy_response (response);
771 return ret;
772 }
773
771 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 774 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
775 {
776 /* upload! */
777 struct UploadContext *uc = *ptr;
778
779 if (NULL == uc)
780 {
781 if (NULL == (uc = malloc (sizeof (struct UploadContext))))
782 return MHD_NO; /* out of memory, close connection */
783 memset (uc, 0, sizeof (struct UploadContext));
784 uc->fd = -1;
785 uc->connection = connection;
786 uc->pp = MHD_create_post_processor (connection,
787 64 * 1024 /* buffer size */,
788 &process_upload_data, uc);
789 if (NULL == uc->pp)
790 {
791 /* out of memory, close connection */
792 free (uc);
793 return MHD_NO;
794 }
795 *ptr = uc;
796 return MHD_YES;
797 }
798 if (0 != *upload_data_size)
799 {
800 if (NULL == uc->response)
801 (void) MHD_post_process (uc->pp,
802 upload_data,
803 *upload_data_size);
804 *upload_data_size = 0;
805 return MHD_YES;
806 }
807 /* end of upload, finish it! */
808 MHD_destroy_post_processor (uc->pp);
809 uc->pp = NULL;
810 if (-1 != uc->fd)
811 {
812 close (uc->fd);
813 uc->fd = -1;
814 }
815 if (NULL != uc->response)
816 {
817 return MHD_queue_response (connection,
818 MHD_HTTP_FORBIDDEN,
819 uc->response);
820 }
821 else
772 { 822 {
773 /* upload! */ 823 update_directory ();
774 struct UploadContext *uc = *ptr; 824 return return_directory_response (connection);
775
776 if (NULL == uc)
777 {
778 if (NULL == (uc = malloc (sizeof (struct UploadContext))))
779 return MHD_NO; /* out of memory, close connection */
780 memset (uc, 0, sizeof (struct UploadContext));
781 uc->fd = -1;
782 uc->connection = connection;
783 uc->pp = MHD_create_post_processor (connection,
784 64 * 1024 /* buffer size */,
785 &process_upload_data, uc);
786 if (NULL == uc->pp)
787 {
788 /* out of memory, close connection */
789 free (uc);
790 return MHD_NO;
791 }
792 *ptr = uc;
793 return MHD_YES;
794 }
795 if (0 != *upload_data_size)
796 {
797 if (NULL == uc->response)
798 (void) MHD_post_process (uc->pp,
799 upload_data,
800 *upload_data_size);
801 *upload_data_size = 0;
802 return MHD_YES;
803 }
804 /* end of upload, finish it! */
805 MHD_destroy_post_processor (uc->pp);
806 uc->pp = NULL;
807 if (-1 != uc->fd)
808 {
809 close (uc->fd);
810 uc->fd = -1;
811 }
812 if (NULL != uc->response)
813 {
814 return MHD_queue_response (connection,
815 MHD_HTTP_FORBIDDEN,
816 uc->response);
817 }
818 else
819 {
820 update_directory ();
821 return return_directory_response (connection);
822 }
823 } 825 }
826 }
824 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || 827 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
825 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 828 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) )
826 { 829 {
@@ -829,8 +832,8 @@ generate_page (void *cls,
829 832
830 /* unexpected request, refuse */ 833 /* unexpected request, refuse */
831 return MHD_queue_response (connection, 834 return MHD_queue_response (connection,
832 MHD_HTTP_FORBIDDEN, 835 MHD_HTTP_FORBIDDEN,
833 request_refused_response); 836 request_refused_response);
834} 837}
835 838
836 839
@@ -843,7 +846,7 @@ generate_page (void *cls,
843static void 846static void
844catcher (int sig) 847catcher (int sig)
845{ 848{
846 (void)sig; /* Unused. Silent compiler warning. */ 849 (void) sig; /* Unused. Silent compiler warning. */
847 /* do nothing */ 850 /* do nothing */
848} 851}
849 852
@@ -889,11 +892,11 @@ main (int argc, char *const *argv)
889 if ( (argc != 2) || 892 if ( (argc != 2) ||
890 (1 != sscanf (argv[1], "%u", &port)) || 893 (1 != sscanf (argv[1], "%u", &port)) ||
891 (UINT16_MAX < port) ) 894 (UINT16_MAX < port) )
892 { 895 {
893 fprintf (stderr, 896 fprintf (stderr,
894 "%s PORT\n", argv[0]); 897 "%s PORT\n", argv[0]);
895 return 1; 898 return 1;
896 } 899 }
897#ifndef MINGW 900#ifndef MINGW
898 ignore_sigpipe (); 901 ignore_sigpipe ();
899#endif 902#endif
@@ -903,31 +906,42 @@ main (int argc, char *const *argv)
903#endif /* MHD_HAVE_LIBMAGIC */ 906#endif /* MHD_HAVE_LIBMAGIC */
904 907
905 (void) pthread_mutex_init (&mutex, NULL); 908 (void) pthread_mutex_init (&mutex, NULL);
906 file_not_found_response = MHD_create_response_from_buffer (strlen (FILE_NOT_FOUND_PAGE), 909 file_not_found_response = MHD_create_response_from_buffer (strlen (
907 (void *) FILE_NOT_FOUND_PAGE, 910 FILE_NOT_FOUND_PAGE),
908 MHD_RESPMEM_PERSISTENT); 911 (void *)
912 FILE_NOT_FOUND_PAGE,
913 MHD_RESPMEM_PERSISTENT);
909 mark_as_html (file_not_found_response); 914 mark_as_html (file_not_found_response);
910 request_refused_response = MHD_create_response_from_buffer (strlen (REQUEST_REFUSED_PAGE), 915 request_refused_response = MHD_create_response_from_buffer (strlen (
911 (void *) REQUEST_REFUSED_PAGE, 916 REQUEST_REFUSED_PAGE),
912 MHD_RESPMEM_PERSISTENT); 917 (void *)
918 REQUEST_REFUSED_PAGE,
919 MHD_RESPMEM_PERSISTENT);
913 mark_as_html (request_refused_response); 920 mark_as_html (request_refused_response);
914 internal_error_response = MHD_create_response_from_buffer (strlen (INTERNAL_ERROR_PAGE), 921 internal_error_response = MHD_create_response_from_buffer (strlen (
915 (void *) INTERNAL_ERROR_PAGE, 922 INTERNAL_ERROR_PAGE),
916 MHD_RESPMEM_PERSISTENT); 923 (void *)
924 INTERNAL_ERROR_PAGE,
925 MHD_RESPMEM_PERSISTENT);
917 mark_as_html (internal_error_response); 926 mark_as_html (internal_error_response);
918 update_directory (); 927 update_directory ();
919 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 928 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
929 | MHD_USE_ERROR_LOG,
920 port, 930 port,
921 NULL, NULL, 931 NULL, NULL,
922 &generate_page, NULL, 932 &generate_page, NULL,
923 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (256 * 1024), 933 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (256
934 * 1024),
924#if PRODUCTION 935#if PRODUCTION
925 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) (64), 936 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) (64),
926#endif 937#endif
927 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) (120 /* seconds */), 938 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
928 MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, 939 int) (120 /* seconds */),
929 MHD_OPTION_NOTIFY_COMPLETED, &response_completed_callback, NULL, 940 MHD_OPTION_THREAD_POOL_SIZE, (unsigned
930 MHD_OPTION_END); 941 int) NUMBER_OF_THREADS,
942 MHD_OPTION_NOTIFY_COMPLETED,
943 &response_completed_callback, NULL,
944 MHD_OPTION_END);
931 if (NULL == d) 945 if (NULL == d)
932 return 1; 946 return 1;
933 fprintf (stderr, "HTTP server running. Press ENTER to stop the server\n"); 947 fprintf (stderr, "HTTP server running. Press ENTER to stop the server\n");
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
index f2230b16..7f7eb3a5 100644
--- a/src/examples/demo_https.c
+++ b/src/examples/demo_https.c
@@ -44,10 +44,10 @@
44#include <limits.h> 44#include <limits.h>
45#include <ctype.h> 45#include <ctype.h>
46 46
47#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 47#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
48#undef CPU_COUNT 48#undef CPU_COUNT
49#endif 49#endif
50#if !defined(CPU_COUNT) 50#if ! defined(CPU_COUNT)
51#define CPU_COUNT 2 51#define CPU_COUNT 2
52#endif 52#endif
53 53
@@ -76,46 +76,50 @@
76/** 76/**
77 * Page returned for file-not-found. 77 * Page returned for file-not-found.
78 */ 78 */
79#define FILE_NOT_FOUND_PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 79#define FILE_NOT_FOUND_PAGE \
80 "<html><head><title>File not found</title></head><body>File not found</body></html>"
80 81
81 82
82/** 83/**
83 * Page returned for internal errors. 84 * Page returned for internal errors.
84 */ 85 */
85#define INTERNAL_ERROR_PAGE "<html><head><title>Internal error</title></head><body>Internal error</body></html>" 86#define INTERNAL_ERROR_PAGE \
87 "<html><head><title>Internal error</title></head><body>Internal error</body></html>"
86 88
87 89
88/** 90/**
89 * Page returned for refused requests. 91 * Page returned for refused requests.
90 */ 92 */
91#define REQUEST_REFUSED_PAGE "<html><head><title>Request refused</title></head><body>Request refused (file exists?)</body></html>" 93#define REQUEST_REFUSED_PAGE \
94 "<html><head><title>Request refused</title></head><body>Request refused (file exists?)</body></html>"
92 95
93 96
94/** 97/**
95 * Head of index page. 98 * Head of index page.
96 */ 99 */
97#define INDEX_PAGE_HEADER "<html>\n<head><title>Welcome</title></head>\n<body>\n"\ 100#define INDEX_PAGE_HEADER \
98 "<h1>Upload</h1>\n"\ 101 "<html>\n<head><title>Welcome</title></head>\n<body>\n" \
99 "<form method=\"POST\" enctype=\"multipart/form-data\" action=\"/\">\n"\ 102 "<h1>Upload</h1>\n" \
100 "<dl><dt>Content type:</dt><dd>"\ 103 "<form method=\"POST\" enctype=\"multipart/form-data\" action=\"/\">\n" \
101 "<input type=\"radio\" name=\"category\" value=\"books\">Book</input>"\ 104 "<dl><dt>Content type:</dt><dd>" \
102 "<input type=\"radio\" name=\"category\" value=\"images\">Image</input>"\ 105 "<input type=\"radio\" name=\"category\" value=\"books\">Book</input>" \
103 "<input type=\"radio\" name=\"category\" value=\"music\">Music</input>"\ 106 "<input type=\"radio\" name=\"category\" value=\"images\">Image</input>" \
104 "<input type=\"radio\" name=\"category\" value=\"software\">Software</input>"\ 107 "<input type=\"radio\" name=\"category\" value=\"music\">Music</input>" \
105 "<input type=\"radio\" name=\"category\" value=\"videos\">Videos</input>\n"\ 108 "<input type=\"radio\" name=\"category\" value=\"software\">Software</input>" \
106 "<input type=\"radio\" name=\"category\" value=\"other\" checked>Other</input></dd>"\ 109 "<input type=\"radio\" name=\"category\" value=\"videos\">Videos</input>\n" \
107 "<dt>Language:</dt><dd>"\ 110 "<input type=\"radio\" name=\"category\" value=\"other\" checked>Other</input></dd>" \
108 "<input type=\"radio\" name=\"language\" value=\"no-lang\" checked>none</input>"\ 111 "<dt>Language:</dt><dd>" \
109 "<input type=\"radio\" name=\"language\" value=\"en\">English</input>"\ 112 "<input type=\"radio\" name=\"language\" value=\"no-lang\" checked>none</input>" \
110 "<input type=\"radio\" name=\"language\" value=\"de\">German</input>"\ 113 "<input type=\"radio\" name=\"language\" value=\"en\">English</input>" \
111 "<input type=\"radio\" name=\"language\" value=\"fr\">French</input>"\ 114 "<input type=\"radio\" name=\"language\" value=\"de\">German</input>" \
112 "<input type=\"radio\" name=\"language\" value=\"es\">Spanish</input></dd>\n"\ 115 "<input type=\"radio\" name=\"language\" value=\"fr\">French</input>" \
113 "<dt>File:</dt><dd>"\ 116 "<input type=\"radio\" name=\"language\" value=\"es\">Spanish</input></dd>\n" \
114 "<input type=\"file\" name=\"upload\"/></dd></dl>"\ 117 "<dt>File:</dt><dd>" \
115 "<input type=\"submit\" value=\"Send!\"/>\n"\ 118 "<input type=\"file\" name=\"upload\"/></dd></dl>" \
116 "</form>\n"\ 119 "<input type=\"submit\" value=\"Send!\"/>\n" \
117 "<h1>Download</h1>\n"\ 120 "</form>\n" \
118 "<ol>\n" 121 "<h1>Download</h1>\n" \
122 "<ol>\n"
119 123
120/** 124/**
121 * Footer of index page. 125 * Footer of index page.
@@ -127,16 +131,15 @@
127 * NULL-terminated array of supported upload categories. Should match HTML 131 * NULL-terminated array of supported upload categories. Should match HTML
128 * in the form. 132 * in the form.
129 */ 133 */
130static const char * const categories[] = 134static const char *const categories[] = {
131 { 135 "books",
132 "books", 136 "images",
133 "images", 137 "music",
134 "music", 138 "software",
135 "software", 139 "videos",
136 "videos", 140 "other",
137 "other", 141 NULL,
138 NULL, 142};
139 };
140 143
141 144
142/** 145/**
@@ -160,15 +163,14 @@ struct Language
160 * NULL-terminated array of supported upload categories. Should match HTML 163 * NULL-terminated array of supported upload categories. Should match HTML
161 * in the form. 164 * in the form.
162 */ 165 */
163static const struct Language languages[] = 166static const struct Language languages[] = {
164 { 167 { "no-lang", "No language specified" },
165 { "no-lang", "No language specified" }, 168 { "en", "English" },
166 { "en", "English" }, 169 { "de", "German" },
167 { "de", "German" }, 170 { "fr", "French" },
168 { "fr", "French" }, 171 { "es", "Spanish" },
169 { "es", "Spanish" }, 172 { NULL, NULL },
170 { NULL, NULL }, 173};
171 };
172 174
173 175
174/** 176/**
@@ -213,8 +215,8 @@ static void
213mark_as_html (struct MHD_Response *response) 215mark_as_html (struct MHD_Response *response)
214{ 216{
215 (void) MHD_add_response_header (response, 217 (void) MHD_add_response_header (response,
216 MHD_HTTP_HEADER_CONTENT_TYPE, 218 MHD_HTTP_HEADER_CONTENT_TYPE,
217 "text/html"); 219 "text/html");
218} 220}
219 221
220 222
@@ -267,7 +269,7 @@ struct ResponseDataContext
267 */ 269 */
268static int 270static int
269list_directory (struct ResponseDataContext *rdc, 271list_directory (struct ResponseDataContext *rdc,
270 const char *dirname) 272 const char *dirname)
271{ 273{
272 char fullname[PATH_MAX]; 274 char fullname[PATH_MAX];
273 struct stat sbuf; 275 struct stat sbuf;
@@ -277,35 +279,35 @@ list_directory (struct ResponseDataContext *rdc,
277 if (NULL == (dir = opendir (dirname))) 279 if (NULL == (dir = opendir (dirname)))
278 return MHD_NO; 280 return MHD_NO;
279 while (NULL != (de = readdir (dir))) 281 while (NULL != (de = readdir (dir)))
282 {
283 if ('.' == de->d_name[0])
284 continue;
285 if (sizeof (fullname) <= (size_t)
286 snprintf (fullname, sizeof (fullname),
287 "%s/%s",
288 dirname, de->d_name))
289 continue; /* ugh, file too long? how can this be!? */
290 if (0 != stat (fullname, &sbuf))
291 continue; /* ugh, failed to 'stat' */
292 if (! S_ISREG (sbuf.st_mode))
293 continue; /* not a regular file, skip */
294 if (rdc->off + 1024 > rdc->buf_len)
280 { 295 {
281 if ('.' == de->d_name[0]) 296 void *r;
282 continue; 297
283 if (sizeof (fullname) <= (size_t) 298 if ( (2 * rdc->buf_len + 1024) < rdc->buf_len)
284 snprintf (fullname, sizeof (fullname), 299 break; /* more than SIZE_T _index_ size? Too big for us */
285 "%s/%s", 300 rdc->buf_len = 2 * rdc->buf_len + 1024;
286 dirname, de->d_name)) 301 if (NULL == (r = realloc (rdc->buf, rdc->buf_len)))
287 continue; /* ugh, file too long? how can this be!? */ 302 break; /* out of memory */
288 if (0 != stat (fullname, &sbuf)) 303 rdc->buf = r;
289 continue; /* ugh, failed to 'stat' */
290 if (! S_ISREG (sbuf.st_mode))
291 continue; /* not a regular file, skip */
292 if (rdc->off + 1024 > rdc->buf_len)
293 {
294 void *r;
295
296 if ( (2 * rdc->buf_len + 1024) < rdc->buf_len)
297 break; /* more than SIZE_T _index_ size? Too big for us */
298 rdc->buf_len = 2 * rdc->buf_len + 1024;
299 if (NULL == (r = realloc (rdc->buf, rdc->buf_len)))
300 break; /* out of memory */
301 rdc->buf = r;
302 }
303 rdc->off += snprintf (&rdc->buf[rdc->off],
304 rdc->buf_len - rdc->off,
305 "<li><a href=\"/%s\">%s</a></li>\n",
306 fullname,
307 de->d_name);
308 } 304 }
305 rdc->off += snprintf (&rdc->buf[rdc->off],
306 rdc->buf_len - rdc->off,
307 "<li><a href=\"/%s\">%s</a></li>\n",
308 fullname,
309 de->d_name);
310 }
309 (void) closedir (dir); 311 (void) closedir (dir);
310 return MHD_YES; 312 return MHD_YES;
311} 313}
@@ -329,65 +331,66 @@ update_directory ()
329 331
330 rdc.buf_len = initial_allocation; 332 rdc.buf_len = initial_allocation;
331 if (NULL == (rdc.buf = malloc (rdc.buf_len))) 333 if (NULL == (rdc.buf = malloc (rdc.buf_len)))
332 { 334 {
333 update_cached_response (NULL); 335 update_cached_response (NULL);
334 return; 336 return;
335 } 337 }
336 rdc.off = snprintf (rdc.buf, rdc.buf_len, 338 rdc.off = snprintf (rdc.buf, rdc.buf_len,
337 "%s", 339 "%s",
338 INDEX_PAGE_HEADER); 340 INDEX_PAGE_HEADER);
339 for (language_idx = 0; NULL != languages[language_idx].dirname; language_idx++) 341 for (language_idx = 0; NULL != languages[language_idx].dirname;
342 language_idx++)
343 {
344 language = &languages[language_idx];
345
346 if (0 != stat (language->dirname, &sbuf))
347 continue; /* empty */
348 /* we ensured always +1k room, filenames are ~256 bytes,
349 so there is always still enough space for the header
350 without need for an additional reallocation check. */
351 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
352 "<h2>%s</h2>\n",
353 language->longname);
354 for (category_idx = 0; NULL != categories[category_idx]; category_idx++)
340 { 355 {
341 language = &languages[language_idx]; 356 category = categories[category_idx];
357 snprintf (dir_name, sizeof (dir_name),
358 "%s/%s",
359 language->dirname,
360 category);
361 if (0 != stat (dir_name, &sbuf))
362 continue; /* empty */
342 363
343 if (0 != stat (language->dirname, &sbuf))
344 continue; /* empty */
345 /* we ensured always +1k room, filenames are ~256 bytes, 364 /* we ensured always +1k room, filenames are ~256 bytes,
346 so there is always still enough space for the header 365 so there is always still enough space for the header
347 without need for an additional reallocation check. */ 366 without need for an additional reallocation check. */
348 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off, 367 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
349 "<h2>%s</h2>\n", 368 "<h3>%s</h3>\n",
350 language->longname); 369 category);
351 for (category_idx = 0; NULL != categories[category_idx]; category_idx++) 370
352 { 371 if (MHD_NO == list_directory (&rdc, dir_name))
353 category = categories[category_idx]; 372 {
354 snprintf (dir_name, sizeof (dir_name), 373 free (rdc.buf);
355 "%s/%s", 374 update_cached_response (NULL);
356 language->dirname, 375 return;
357 category); 376 }
358 if (0 != stat (dir_name, &sbuf))
359 continue; /* empty */
360
361 /* we ensured always +1k room, filenames are ~256 bytes,
362 so there is always still enough space for the header
363 without need for an additional reallocation check. */
364 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
365 "<h3>%s</h3>\n",
366 category);
367
368 if (MHD_NO == list_directory (&rdc, dir_name))
369 {
370 free (rdc.buf);
371 update_cached_response (NULL);
372 return;
373 }
374 }
375 } 377 }
378 }
376 /* we ensured always +1k room, filenames are ~256 bytes, 379 /* we ensured always +1k room, filenames are ~256 bytes,
377 so there is always still enough space for the footer 380 so there is always still enough space for the footer
378 without need for a final reallocation check. */ 381 without need for a final reallocation check. */
379 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off, 382 rdc.off += snprintf (&rdc.buf[rdc.off], rdc.buf_len - rdc.off,
380 "%s", 383 "%s",
381 INDEX_PAGE_FOOTER); 384 INDEX_PAGE_FOOTER);
382 initial_allocation = rdc.buf_len; /* remember for next time */ 385 initial_allocation = rdc.buf_len; /* remember for next time */
383 response = MHD_create_response_from_buffer (rdc.off, 386 response = MHD_create_response_from_buffer (rdc.off,
384 rdc.buf, 387 rdc.buf,
385 MHD_RESPMEM_MUST_FREE); 388 MHD_RESPMEM_MUST_FREE);
386 mark_as_html (response); 389 mark_as_html (response);
387#if FORCE_CLOSE 390#if FORCE_CLOSE
388 (void) MHD_add_response_header (response, 391 (void) MHD_add_response_header (response,
389 MHD_HTTP_HEADER_CONNECTION, 392 MHD_HTTP_HEADER_CONNECTION,
390 "close"); 393 "close");
391#endif 394#endif
392 update_cached_response (response); 395 update_cached_response (response);
393} 396}
@@ -446,8 +449,8 @@ struct UploadContext
446 */ 449 */
447static int 450static int
448do_append (char **ret, 451do_append (char **ret,
449 const char *data, 452 const char *data,
450 size_t size) 453 size_t size)
451{ 454{
452 char *buf; 455 char *buf;
453 size_t old_len; 456 size_t old_len;
@@ -459,15 +462,15 @@ do_append (char **ret,
459 if (NULL == (buf = malloc (old_len + size + 1))) 462 if (NULL == (buf = malloc (old_len + size + 1)))
460 return MHD_NO; 463 return MHD_NO;
461 if (NULL != *ret) 464 if (NULL != *ret)
462 { 465 {
463 memcpy (buf, 466 memcpy (buf,
464 *ret, 467 *ret,
465 old_len); 468 old_len);
466 free (*ret); 469 free (*ret);
467 } 470 }
468 memcpy (&buf[old_len], 471 memcpy (&buf[old_len],
469 data, 472 data,
470 size); 473 size);
471 buf[old_len + size] = '\0'; 474 buf[old_len + size] = '\0';
472 *ret = buf; 475 *ret = buf;
473 return MHD_YES; 476 return MHD_YES;
@@ -495,119 +498,119 @@ do_append (char **ret,
495 */ 498 */
496static int 499static int
497process_upload_data (void *cls, 500process_upload_data (void *cls,
498 enum MHD_ValueKind kind, 501 enum MHD_ValueKind kind,
499 const char *key, 502 const char *key,
500 const char *filename, 503 const char *filename,
501 const char *content_type, 504 const char *content_type,
502 const char *transfer_encoding, 505 const char *transfer_encoding,
503 const char *data, 506 const char *data,
504 uint64_t off, 507 uint64_t off,
505 size_t size) 508 size_t size)
506{ 509{
507 struct UploadContext *uc = cls; 510 struct UploadContext *uc = cls;
508 int i; 511 int i;
509 (void)kind; /* Unused. Silent compiler warning. */ 512 (void) kind; /* Unused. Silent compiler warning. */
510 (void)content_type; /* Unused. Silent compiler warning. */ 513 (void) content_type; /* Unused. Silent compiler warning. */
511 (void)transfer_encoding; /* Unused. Silent compiler warning. */ 514 (void) transfer_encoding; /* Unused. Silent compiler warning. */
512 (void)off; /* Unused. Silent compiler warning. */ 515 (void) off; /* Unused. Silent compiler warning. */
513 516
514 if (0 == strcmp (key, "category")) 517 if (0 == strcmp (key, "category"))
515 return do_append (&uc->category, data, size); 518 return do_append (&uc->category, data, size);
516 if (0 == strcmp (key, "language")) 519 if (0 == strcmp (key, "language"))
517 return do_append (&uc->language, data, size); 520 return do_append (&uc->language, data, size);
518 if (0 != strcmp (key, "upload")) 521 if (0 != strcmp (key, "upload"))
519 { 522 {
520 fprintf (stderr, 523 fprintf (stderr,
521 "Ignoring unexpected form value `%s'\n", 524 "Ignoring unexpected form value `%s'\n",
522 key); 525 key);
523 return MHD_YES; /* ignore */ 526 return MHD_YES; /* ignore */
524 } 527 }
525 if (NULL == filename) 528 if (NULL == filename)
526 { 529 {
527 fprintf (stderr, "No filename, aborting upload\n"); 530 fprintf (stderr, "No filename, aborting upload\n");
528 return MHD_NO; /* no filename, error */ 531 return MHD_NO; /* no filename, error */
529 } 532 }
530 if ( (NULL == uc->category) || 533 if ( (NULL == uc->category) ||
531 (NULL == uc->language) ) 534 (NULL == uc->language) )
535 {
536 fprintf (stderr,
537 "Missing form data for upload `%s'\n",
538 filename);
539 uc->response = request_refused_response;
540 return MHD_NO;
541 }
542 if (-1 == uc->fd)
543 {
544 char fn[PATH_MAX];
545
546 if ( (NULL != strstr (filename, "..")) ||
547 (NULL != strchr (filename, '/')) ||
548 (NULL != strchr (filename, '\\')) )
532 { 549 {
533 fprintf (stderr,
534 "Missing form data for upload `%s'\n",
535 filename);
536 uc->response = request_refused_response; 550 uc->response = request_refused_response;
537 return MHD_NO; 551 return MHD_NO;
538 } 552 }
539 if (-1 == uc->fd) 553 /* create directories -- if they don't exist already */
540 {
541 char fn[PATH_MAX];
542
543 if ( (NULL != strstr (filename, "..")) ||
544 (NULL != strchr (filename, '/')) ||
545 (NULL != strchr (filename, '\\')) )
546 {
547 uc->response = request_refused_response;
548 return MHD_NO;
549 }
550 /* create directories -- if they don't exist already */
551#ifdef WINDOWS 554#ifdef WINDOWS
552 (void) mkdir (uc->language); 555 (void) mkdir (uc->language);
553#else 556#else
554 (void) mkdir (uc->language, S_IRWXU); 557 (void) mkdir (uc->language, S_IRWXU);
555#endif 558#endif
556 snprintf (fn, sizeof (fn), 559 snprintf (fn, sizeof (fn),
557 "%s/%s", 560 "%s/%s",
558 uc->language, 561 uc->language,
559 uc->category); 562 uc->category);
560#ifdef WINDOWS 563#ifdef WINDOWS
561 (void) mkdir (fn); 564 (void) mkdir (fn);
562#else 565#else
563 (void) mkdir (fn, S_IRWXU); 566 (void) mkdir (fn, S_IRWXU);
564#endif 567#endif
565 /* open file */ 568 /* open file */
566 snprintf (fn, sizeof (fn), 569 snprintf (fn, sizeof (fn),
567 "%s/%s/%s", 570 "%s/%s/%s",
568 uc->language, 571 uc->language,
569 uc->category, 572 uc->category,
570 filename); 573 filename);
571 for (i=strlen (fn)-1;i>=0;i--) 574 for (i = strlen (fn) - 1; i>=0; i--)
572 if (! isprint ((unsigned char) fn[i])) 575 if (! isprint ((unsigned char) fn[i]))
573 fn[i] = '_'; 576 fn[i] = '_';
574 uc->fd = open (fn, 577 uc->fd = open (fn,
575 O_CREAT | O_EXCL 578 O_CREAT | O_EXCL
576#if O_LARGEFILE 579#if O_LARGEFILE
577 | O_LARGEFILE 580 | O_LARGEFILE
578#endif 581#endif
579 | O_WRONLY, 582 | O_WRONLY,
580 S_IRUSR | S_IWUSR); 583 S_IRUSR | S_IWUSR);
581 if (-1 == uc->fd) 584 if (-1 == uc->fd)
582 { 585 {
583 fprintf (stderr, 586 fprintf (stderr,
584 "Error opening file `%s' for upload: %s\n", 587 "Error opening file `%s' for upload: %s\n",
585 fn, 588 fn,
586 strerror (errno)); 589 strerror (errno));
587 uc->response = request_refused_response; 590 uc->response = request_refused_response;
588 return MHD_NO; 591 return MHD_NO;
589 }
590 uc->filename = strdup (fn);
591 } 592 }
593 uc->filename = strdup (fn);
594 }
592 if ( (0 != size) && 595 if ( (0 != size) &&
593 (size != (size_t) write (uc->fd, data, size)) ) 596 (size != (size_t) write (uc->fd, data, size)) )
597 {
598 /* write failed; likely: disk full */
599 fprintf (stderr,
600 "Error writing to file `%s': %s\n",
601 uc->filename,
602 strerror (errno));
603 uc->response = internal_error_response;
604 close (uc->fd);
605 uc->fd = -1;
606 if (NULL != uc->filename)
594 { 607 {
595 /* write failed; likely: disk full */ 608 unlink (uc->filename);
596 fprintf (stderr, 609 free (uc->filename);
597 "Error writing to file `%s': %s\n", 610 uc->filename = NULL;
598 uc->filename,
599 strerror (errno));
600 uc->response = internal_error_response;
601 close (uc->fd);
602 uc->fd = -1;
603 if (NULL != uc->filename)
604 {
605 unlink (uc->filename);
606 free (uc->filename);
607 uc->filename = NULL;
608 }
609 return MHD_NO;
610 } 611 }
612 return MHD_NO;
613 }
611 return MHD_YES; 614 return MHD_YES;
612} 615}
613 616
@@ -625,32 +628,32 @@ process_upload_data (void *cls,
625 */ 628 */
626static void 629static void
627response_completed_callback (void *cls, 630response_completed_callback (void *cls,
628 struct MHD_Connection *connection, 631 struct MHD_Connection *connection,
629 void **con_cls, 632 void **con_cls,
630 enum MHD_RequestTerminationCode toe) 633 enum MHD_RequestTerminationCode toe)
631{ 634{
632 struct UploadContext *uc = *con_cls; 635 struct UploadContext *uc = *con_cls;
633 (void)cls; /* Unused. Silent compiler warning. */ 636 (void) cls; /* Unused. Silent compiler warning. */
634 (void)connection; /* Unused. Silent compiler warning. */ 637 (void) connection; /* Unused. Silent compiler warning. */
635 (void)toe; /* Unused. Silent compiler warning. */ 638 (void) toe; /* Unused. Silent compiler warning. */
636 639
637 if (NULL == uc) 640 if (NULL == uc)
638 return; /* this request wasn't an upload request */ 641 return; /* this request wasn't an upload request */
639 if (NULL != uc->pp) 642 if (NULL != uc->pp)
640 { 643 {
641 MHD_destroy_post_processor (uc->pp); 644 MHD_destroy_post_processor (uc->pp);
642 uc->pp = NULL; 645 uc->pp = NULL;
643 } 646 }
644 if (-1 != uc->fd) 647 if (-1 != uc->fd)
645 { 648 {
646 (void) close (uc->fd); 649 (void) close (uc->fd);
647 if (NULL != uc->filename) 650 if (NULL != uc->filename)
648 { 651 {
649 fprintf (stderr, 652 fprintf (stderr,
650 "Upload of file `%s' failed (incomplete or aborted), removing file.\n", 653 "Upload of file `%s' failed (incomplete or aborted), removing file.\n",
651 uc->filename); 654 uc->filename);
652 (void) unlink (uc->filename); 655 (void) unlink (uc->filename);
653 } 656 }
654 } 657 }
655 if (NULL != uc->filename) 658 if (NULL != uc->filename)
656 free (uc->filename); 659 free (uc->filename);
@@ -672,12 +675,12 @@ return_directory_response (struct MHD_Connection *connection)
672 (void) pthread_mutex_lock (&mutex); 675 (void) pthread_mutex_lock (&mutex);
673 if (NULL == cached_directory_response) 676 if (NULL == cached_directory_response)
674 ret = MHD_queue_response (connection, 677 ret = MHD_queue_response (connection,
675 MHD_HTTP_INTERNAL_SERVER_ERROR, 678 MHD_HTTP_INTERNAL_SERVER_ERROR,
676 internal_error_response); 679 internal_error_response);
677 else 680 else
678 ret = MHD_queue_response (connection, 681 ret = MHD_queue_response (connection,
679 MHD_HTTP_OK, 682 MHD_HTTP_OK,
680 cached_directory_response); 683 cached_directory_response);
681 (void) pthread_mutex_unlock (&mutex); 684 (void) pthread_mutex_unlock (&mutex);
682 return ret; 685 return ret;
683} 686}
@@ -698,131 +701,131 @@ return_directory_response (struct MHD_Connection *connection)
698 */ 701 */
699static int 702static int
700generate_page (void *cls, 703generate_page (void *cls,
701 struct MHD_Connection *connection, 704 struct MHD_Connection *connection,
702 const char *url, 705 const char *url,
703 const char *method, 706 const char *method,
704 const char *version, 707 const char *version,
705 const char *upload_data, 708 const char *upload_data,
706 size_t *upload_data_size, void **ptr) 709 size_t *upload_data_size, void **ptr)
707{ 710{
708 struct MHD_Response *response; 711 struct MHD_Response *response;
709 int ret; 712 int ret;
710 int fd; 713 int fd;
711 struct stat buf; 714 struct stat buf;
712 (void)cls; /* Unused. Silent compiler warning. */ 715 (void) cls; /* Unused. Silent compiler warning. */
713 (void)version; /* Unused. Silent compiler warning. */ 716 (void) version; /* Unused. Silent compiler warning. */
714 717
715 if (0 != strcmp (url, "/")) 718 if (0 != strcmp (url, "/"))
716 { 719 {
717 /* should be file download */ 720 /* should be file download */
718#ifdef MHD_HAVE_LIBMAGIC 721#ifdef MHD_HAVE_LIBMAGIC
719 char file_data[MAGIC_HEADER_SIZE]; 722 char file_data[MAGIC_HEADER_SIZE];
720 ssize_t got; 723 ssize_t got;
721#endif /* MHD_HAVE_LIBMAGIC */ 724#endif /* MHD_HAVE_LIBMAGIC */
722 const char *mime; 725 const char *mime;
723 726
724 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 727 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
725 return MHD_NO; /* unexpected method (we're not polite...) */ 728 return MHD_NO; /* unexpected method (we're not polite...) */
726 fd = -1; 729 fd = -1;
727 if ( (NULL == strstr (&url[1], "..")) && 730 if ( (NULL == strstr (&url[1], "..")) &&
728 ('/' != url[1]) ) 731 ('/' != url[1]) )
729 { 732 {
730 fd = open (&url[1], O_RDONLY); 733 fd = open (&url[1], O_RDONLY);
731 if ( (-1 != fd) && 734 if ( (-1 != fd) &&
732 ( (0 != fstat (fd, &buf)) || 735 ( (0 != fstat (fd, &buf)) ||
733 (! S_ISREG (buf.st_mode)) ) ) 736 (! S_ISREG (buf.st_mode)) ) )
734 { 737 {
735 (void) close (fd); 738 (void) close (fd);
736 fd = -1; 739 fd = -1;
737 } 740 }
738 } 741 }
739 if (-1 == fd) 742 if (-1 == fd)
740 return MHD_queue_response (connection, 743 return MHD_queue_response (connection,
741 MHD_HTTP_NOT_FOUND, 744 MHD_HTTP_NOT_FOUND,
742 file_not_found_response); 745 file_not_found_response);
743#ifdef MHD_HAVE_LIBMAGIC 746#ifdef MHD_HAVE_LIBMAGIC
744 /* read beginning of the file to determine mime type */ 747 /* read beginning of the file to determine mime type */
745 got = read (fd, file_data, sizeof (file_data)); 748 got = read (fd, file_data, sizeof (file_data));
746 (void) lseek (fd, 0, SEEK_SET); 749 (void) lseek (fd, 0, SEEK_SET);
747 if (-1 != got) 750 if (-1 != got)
748 mime = magic_buffer (magic, file_data, got); 751 mime = magic_buffer (magic, file_data, got);
749 else 752 else
750#endif /* MHD_HAVE_LIBMAGIC */ 753#endif /* MHD_HAVE_LIBMAGIC */
751 mime = NULL; 754 mime = NULL;
752 755
753 if (NULL == (response = MHD_create_response_from_fd (buf.st_size, 756 if (NULL == (response = MHD_create_response_from_fd (buf.st_size,
754 fd))) 757 fd)))
755 { 758 {
756 /* internal error (i.e. out of memory) */ 759 /* internal error (i.e. out of memory) */
757 (void) close (fd); 760 (void) close (fd);
758 return MHD_NO; 761 return MHD_NO;
759 }
760
761 /* add mime type if we had one */
762 if (NULL != mime)
763 (void) MHD_add_response_header (response,
764 MHD_HTTP_HEADER_CONTENT_TYPE,
765 mime);
766 ret = MHD_queue_response (connection,
767 MHD_HTTP_OK,
768 response);
769 MHD_destroy_response (response);
770 return ret;
771 } 762 }
772 763
764 /* add mime type if we had one */
765 if (NULL != mime)
766 (void) MHD_add_response_header (response,
767 MHD_HTTP_HEADER_CONTENT_TYPE,
768 mime);
769 ret = MHD_queue_response (connection,
770 MHD_HTTP_OK,
771 response);
772 MHD_destroy_response (response);
773 return ret;
774 }
775
773 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 776 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
777 {
778 /* upload! */
779 struct UploadContext *uc = *ptr;
780
781 if (NULL == uc)
782 {
783 if (NULL == (uc = malloc (sizeof (struct UploadContext))))
784 return MHD_NO; /* out of memory, close connection */
785 memset (uc, 0, sizeof (struct UploadContext));
786 uc->fd = -1;
787 uc->connection = connection;
788 uc->pp = MHD_create_post_processor (connection,
789 64 * 1024 /* buffer size */,
790 &process_upload_data, uc);
791 if (NULL == uc->pp)
792 {
793 /* out of memory, close connection */
794 free (uc);
795 return MHD_NO;
796 }
797 *ptr = uc;
798 return MHD_YES;
799 }
800 if (0 != *upload_data_size)
801 {
802 if (NULL == uc->response)
803 (void) MHD_post_process (uc->pp,
804 upload_data,
805 *upload_data_size);
806 *upload_data_size = 0;
807 return MHD_YES;
808 }
809 /* end of upload, finish it! */
810 MHD_destroy_post_processor (uc->pp);
811 uc->pp = NULL;
812 if (-1 != uc->fd)
813 {
814 close (uc->fd);
815 uc->fd = -1;
816 }
817 if (NULL != uc->response)
818 {
819 return MHD_queue_response (connection,
820 MHD_HTTP_FORBIDDEN,
821 uc->response);
822 }
823 else
774 { 824 {
775 /* upload! */ 825 update_directory ();
776 struct UploadContext *uc = *ptr; 826 return return_directory_response (connection);
777
778 if (NULL == uc)
779 {
780 if (NULL == (uc = malloc (sizeof (struct UploadContext))))
781 return MHD_NO; /* out of memory, close connection */
782 memset (uc, 0, sizeof (struct UploadContext));
783 uc->fd = -1;
784 uc->connection = connection;
785 uc->pp = MHD_create_post_processor (connection,
786 64 * 1024 /* buffer size */,
787 &process_upload_data, uc);
788 if (NULL == uc->pp)
789 {
790 /* out of memory, close connection */
791 free (uc);
792 return MHD_NO;
793 }
794 *ptr = uc;
795 return MHD_YES;
796 }
797 if (0 != *upload_data_size)
798 {
799 if (NULL == uc->response)
800 (void) MHD_post_process (uc->pp,
801 upload_data,
802 *upload_data_size);
803 *upload_data_size = 0;
804 return MHD_YES;
805 }
806 /* end of upload, finish it! */
807 MHD_destroy_post_processor (uc->pp);
808 uc->pp = NULL;
809 if (-1 != uc->fd)
810 {
811 close (uc->fd);
812 uc->fd = -1;
813 }
814 if (NULL != uc->response)
815 {
816 return MHD_queue_response (connection,
817 MHD_HTTP_FORBIDDEN,
818 uc->response);
819 }
820 else
821 {
822 update_directory ();
823 return return_directory_response (connection);
824 }
825 } 827 }
828 }
826 if (0 == strcmp (method, MHD_HTTP_METHOD_GET)) 829 if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
827 { 830 {
828 return return_directory_response (connection); 831 return return_directory_response (connection);
@@ -830,8 +833,8 @@ generate_page (void *cls,
830 833
831 /* unexpected request, refuse */ 834 /* unexpected request, refuse */
832 return MHD_queue_response (connection, 835 return MHD_queue_response (connection,
833 MHD_HTTP_FORBIDDEN, 836 MHD_HTTP_FORBIDDEN,
834 request_refused_response); 837 request_refused_response);
835} 838}
836 839
837 840
@@ -844,7 +847,7 @@ generate_page (void *cls,
844static void 847static void
845catcher (int sig) 848catcher (int sig)
846{ 849{
847 (void)sig; /* Unused. Silent compiler warning. */ 850 (void) sig; /* Unused. Silent compiler warning. */
848 /* do nothing */ 851 /* do nothing */
849} 852}
850 853
@@ -873,53 +876,53 @@ ignore_sigpipe (void)
873 876
874/* test server key */ 877/* test server key */
875const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 878const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
876 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" 879 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n"
877 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" 880 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n"
878 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" 881 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n"
879 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" 882 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n"
880 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" 883 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n"
881 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n" 884 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n"
882 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n" 885 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n"
883 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n" 886 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n"
884 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n" 887 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n"
885 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n" 888 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n"
886 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n" 889 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n"
887 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n" 890 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n"
888 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n" 891 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n"
889 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n" 892 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n"
890 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n" 893 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n"
891 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n" 894 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n"
892 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n" 895 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n"
893 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n" 896 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n"
894 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n" 897 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n"
895 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n" 898 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n"
896 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n" 899 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n"
897 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" 900 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n"
898 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" 901 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n"
899 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" 902 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n"
900 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" 903 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n"
901 "-----END RSA PRIVATE KEY-----\n"; 904 "-----END RSA PRIVATE KEY-----\n";
902 905
903/* test server CA signed certificates */ 906/* test server CA signed certificates */
904const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 907const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
905 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 908 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
906 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 909 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n"
907 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" 910 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n"
908 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n" 911 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n"
909 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n" 912 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n"
910 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n" 913 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n"
911 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n" 914 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n"
912 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n" 915 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n"
913 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" 916 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n"
914 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n" 917 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n"
915 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n" 918 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n"
916 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n" 919 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n"
917 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n" 920 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n"
918 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n" 921 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n"
919 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n" 922 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n"
920 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n" 923 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n"
921 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n" 924 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n"
922 "-----END CERTIFICATE-----\n"; 925 "-----END CERTIFICATE-----\n";
923 926
924 927
925/** 928/**
@@ -940,11 +943,11 @@ main (int argc, char *const *argv)
940 if ( (argc != 2) || 943 if ( (argc != 2) ||
941 (1 != sscanf (argv[1], "%u", &port)) || 944 (1 != sscanf (argv[1], "%u", &port)) ||
942 (UINT16_MAX < port) ) 945 (UINT16_MAX < port) )
943 { 946 {
944 fprintf (stderr, 947 fprintf (stderr,
945 "%s PORT\n", argv[0]); 948 "%s PORT\n", argv[0]);
946 return 1; 949 return 1;
947 } 950 }
948 #ifndef MINGW 951 #ifndef MINGW
949 ignore_sigpipe (); 952 ignore_sigpipe ();
950 #endif 953 #endif
@@ -954,35 +957,46 @@ main (int argc, char *const *argv)
954#endif /* MHD_HAVE_LIBMAGIC */ 957#endif /* MHD_HAVE_LIBMAGIC */
955 958
956 (void) pthread_mutex_init (&mutex, NULL); 959 (void) pthread_mutex_init (&mutex, NULL);
957 file_not_found_response = MHD_create_response_from_buffer (strlen (FILE_NOT_FOUND_PAGE), 960 file_not_found_response = MHD_create_response_from_buffer (strlen (
958 (void *) FILE_NOT_FOUND_PAGE, 961 FILE_NOT_FOUND_PAGE),
959 MHD_RESPMEM_PERSISTENT); 962 (void *)
963 FILE_NOT_FOUND_PAGE,
964 MHD_RESPMEM_PERSISTENT);
960 mark_as_html (file_not_found_response); 965 mark_as_html (file_not_found_response);
961 request_refused_response = MHD_create_response_from_buffer (strlen (REQUEST_REFUSED_PAGE), 966 request_refused_response = MHD_create_response_from_buffer (strlen (
962 (void *) REQUEST_REFUSED_PAGE, 967 REQUEST_REFUSED_PAGE),
963 MHD_RESPMEM_PERSISTENT); 968 (void *)
969 REQUEST_REFUSED_PAGE,
970 MHD_RESPMEM_PERSISTENT);
964 mark_as_html (request_refused_response); 971 mark_as_html (request_refused_response);
965 internal_error_response = MHD_create_response_from_buffer (strlen (INTERNAL_ERROR_PAGE), 972 internal_error_response = MHD_create_response_from_buffer (strlen (
966 (void *) INTERNAL_ERROR_PAGE, 973 INTERNAL_ERROR_PAGE),
967 MHD_RESPMEM_PERSISTENT); 974 (void *)
975 INTERNAL_ERROR_PAGE,
976 MHD_RESPMEM_PERSISTENT);
968 mark_as_html (internal_error_response); 977 mark_as_html (internal_error_response);
969 update_directory (); 978 update_directory ();
970 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_TLS, 979 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
980 | MHD_USE_ERROR_LOG | MHD_USE_TLS,
971 port, 981 port,
972 NULL, NULL, 982 NULL, NULL,
973 &generate_page, NULL, 983 &generate_page, NULL,
974 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (256 * 1024), 984 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (256
985 * 1024),
975#if PRODUCTION 986#if PRODUCTION
976 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) (64), 987 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) (64),
977#endif 988#endif
978 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) (120 /* seconds */), 989 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
979 MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, 990 int) (120 /* seconds */),
980 MHD_OPTION_NOTIFY_COMPLETED, &response_completed_callback, NULL, 991 MHD_OPTION_THREAD_POOL_SIZE, (unsigned
981 /* Optionally, the gnutls_load_file() can be used to 992 int) NUMBER_OF_THREADS,
982 load the key and the certificate from file. */ 993 MHD_OPTION_NOTIFY_COMPLETED,
983 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 994 &response_completed_callback, NULL,
984 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 995 /* Optionally, the gnutls_load_file() can be used to
985 MHD_OPTION_END); 996 load the key and the certificate from file. */
997 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
998 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
999 MHD_OPTION_END);
986 if (NULL == d) 1000 if (NULL == d)
987 return 1; 1001 return 1;
988 fprintf (stderr, "HTTP server running. Press ENTER to stop the server\n"); 1002 fprintf (stderr, "HTTP server running. Press ENTER to stop the server\n");
diff --git a/src/examples/digest_auth_example.c b/src/examples/digest_auth_example.c
index 889967fb..720576cd 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -26,9 +26,11 @@
26#include <microhttpd.h> 26#include <microhttpd.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" 29#define PAGE \
30 "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
30 31
31#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" 32#define DENIED \
33 "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
32 34
33#define MY_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4" 35#define MY_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
34 36
@@ -45,51 +47,52 @@ ahc_echo (void *cls,
45 const char *password = "testpass"; 47 const char *password = "testpass";
46 const char *realm = "test@example.com"; 48 const char *realm = "test@example.com";
47 int ret; 49 int ret;
48 (void)cls; /* Unused. Silent compiler warning. */ 50 (void) cls; /* Unused. Silent compiler warning. */
49 (void)url; /* Unused. Silent compiler warning. */ 51 (void) url; /* Unused. Silent compiler warning. */
50 (void)method; /* Unused. Silent compiler warning. */ 52 (void) method; /* Unused. Silent compiler warning. */
51 (void)version; /* Unused. Silent compiler warning. */ 53 (void) version; /* Unused. Silent compiler warning. */
52 (void)upload_data; /* Unused. Silent compiler warning. */ 54 (void) upload_data; /* Unused. Silent compiler warning. */
53 (void)upload_data_size; /* Unused. Silent compiler warning. */ 55 (void) upload_data_size; /* Unused. Silent compiler warning. */
54 (void)ptr; /* Unused. Silent compiler warning. */ 56 (void) ptr; /* Unused. Silent compiler warning. */
55 57
56 username = MHD_digest_auth_get_username(connection); 58 username = MHD_digest_auth_get_username (connection);
57 if (NULL == username) 59 if (NULL == username)
58 { 60 {
59 response = MHD_create_response_from_buffer(strlen (DENIED), 61 response = MHD_create_response_from_buffer (strlen (DENIED),
60 DENIED, 62 DENIED,
61 MHD_RESPMEM_PERSISTENT); 63 MHD_RESPMEM_PERSISTENT);
62 ret = MHD_queue_auth_fail_response(connection, realm, 64 ret = MHD_queue_auth_fail_response (connection, realm,
63 MY_OPAQUE_STR, 65 MY_OPAQUE_STR,
64 response, 66 response,
65 MHD_NO); 67 MHD_NO);
66 MHD_destroy_response(response); 68 MHD_destroy_response (response);
67 return ret; 69 return ret;
68 } 70 }
69 ret = MHD_digest_auth_check(connection, realm, 71 ret = MHD_digest_auth_check (connection, realm,
70 username, 72 username,
71 password, 73 password,
72 300); 74 300);
73 MHD_free (username); 75 MHD_free (username);
74 if ( (ret == MHD_INVALID_NONCE) || 76 if ( (ret == MHD_INVALID_NONCE) ||
75 (ret == MHD_NO) ) 77 (ret == MHD_NO) )
76 { 78 {
77 response = MHD_create_response_from_buffer(strlen (DENIED), 79 response = MHD_create_response_from_buffer (strlen (DENIED),
78 DENIED, 80 DENIED,
79 MHD_RESPMEM_PERSISTENT); 81 MHD_RESPMEM_PERSISTENT);
80 if (NULL == response) 82 if (NULL == response)
81 return MHD_NO; 83 return MHD_NO;
82 ret = MHD_queue_auth_fail_response(connection, realm, 84 ret = MHD_queue_auth_fail_response (connection, realm,
83 MY_OPAQUE_STR, 85 MY_OPAQUE_STR,
84 response, 86 response,
85 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); 87 (ret == MHD_INVALID_NONCE) ? MHD_YES :
86 MHD_destroy_response(response); 88 MHD_NO);
87 return ret; 89 MHD_destroy_response (response);
88 } 90 return ret;
89 response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, 91 }
90 MHD_RESPMEM_PERSISTENT); 92 response = MHD_create_response_from_buffer (strlen (PAGE), PAGE,
91 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 93 MHD_RESPMEM_PERSISTENT);
92 MHD_destroy_response(response); 94 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
95 MHD_destroy_response (response);
93 return ret; 96 return ret;
94} 97}
95 98
@@ -104,40 +107,41 @@ main (int argc, char *const *argv)
104 struct MHD_Daemon *d; 107 struct MHD_Daemon *d;
105 108
106 if (argc != 2) 109 if (argc != 2)
107 { 110 {
108 printf ("%s PORT\n", argv[0]); 111 printf ("%s PORT\n", argv[0]);
109 return 1; 112 return 1;
110 } 113 }
111 fd = open("/dev/urandom", O_RDONLY); 114 fd = open ("/dev/urandom", O_RDONLY);
112 if (-1 == fd) 115 if (-1 == fd)
113 { 116 {
114 fprintf (stderr, "Failed to open `%s': %s\n", 117 fprintf (stderr, "Failed to open `%s': %s\n",
115 "/dev/urandom", 118 "/dev/urandom",
116 strerror (errno)); 119 strerror (errno));
117 return 1; 120 return 1;
118 } 121 }
119 off = 0; 122 off = 0;
120 while (off < 8) 123 while (off < 8)
124 {
125 len = read (fd, rnd, 8);
126 if (len == -1)
121 { 127 {
122 len = read(fd, rnd, 8); 128 fprintf (stderr, "Failed to read `%s': %s\n",
123 if (len == -1) 129 "/dev/urandom",
124 { 130 strerror (errno));
125 fprintf (stderr, "Failed to read `%s': %s\n", 131 (void) close (fd);
126 "/dev/urandom", 132 return 1;
127 strerror (errno));
128 (void) close (fd);
129 return 1;
130 }
131 off += len;
132 } 133 }
133 (void) close(fd); 134 off += len;
134 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 135 }
136 (void) close (fd);
137 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
138 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
135 atoi (argv[1]), 139 atoi (argv[1]),
136 NULL, NULL, &ahc_echo, PAGE, 140 NULL, NULL, &ahc_echo, PAGE,
137 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd, 141 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd,
138 MHD_OPTION_NONCE_NC_SIZE, 300, 142 MHD_OPTION_NONCE_NC_SIZE, 300,
139 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 143 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
140 MHD_OPTION_END); 144 MHD_OPTION_END);
141 if (d == NULL) 145 if (d == NULL)
142 return 1; 146 return 1;
143 (void) getc (stdin); 147 (void) getc (stdin);
diff --git a/src/examples/dual_stack_example.c b/src/examples/dual_stack_example.c
index 31b25438..ffacec4a 100644
--- a/src/examples/dual_stack_example.c
+++ b/src/examples/dual_stack_example.c
@@ -25,7 +25,8 @@
25#include "platform.h" 25#include "platform.h"
26#include <microhttpd.h> 26#include <microhttpd.h>
27 27
28#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 28#define PAGE \
29 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
29 30
30static int 31static int
31ahc_echo (void *cls, 32ahc_echo (void *cls,
@@ -39,23 +40,23 @@ ahc_echo (void *cls,
39 const char *me = cls; 40 const char *me = cls;
40 struct MHD_Response *response; 41 struct MHD_Response *response;
41 int ret; 42 int ret;
42 (void)url; /* Unused. Silent compiler warning. */ 43 (void) url; /* Unused. Silent compiler warning. */
43 (void)version; /* Unused. Silent compiler warning. */ 44 (void) version; /* Unused. Silent compiler warning. */
44 (void)upload_data; /* Unused. Silent compiler warning. */ 45 (void) upload_data; /* Unused. Silent compiler warning. */
45 (void)upload_data_size; /* Unused. Silent compiler warning. */ 46 (void) upload_data_size; /* Unused. Silent compiler warning. */
46 47
47 if (0 != strcmp (method, "GET")) 48 if (0 != strcmp (method, "GET"))
48 return MHD_NO; /* unexpected method */ 49 return MHD_NO; /* unexpected method */
49 if (&aptr != *ptr) 50 if (&aptr != *ptr)
50 { 51 {
51 /* do never respond on first call */ 52 /* do never respond on first call */
52 *ptr = &aptr; 53 *ptr = &aptr;
53 return MHD_YES; 54 return MHD_YES;
54 } 55 }
55 *ptr = NULL; /* reset when done */ 56 *ptr = NULL; /* reset when done */
56 response = MHD_create_response_from_buffer (strlen (me), 57 response = MHD_create_response_from_buffer (strlen (me),
57 (void *) me, 58 (void *) me,
58 MHD_RESPMEM_PERSISTENT); 59 MHD_RESPMEM_PERSISTENT);
59 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 60 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
60 MHD_destroy_response (response); 61 MHD_destroy_response (response);
61 return ret; 62 return ret;
@@ -68,15 +69,16 @@ main (int argc, char *const *argv)
68 struct MHD_Daemon *d; 69 struct MHD_Daemon *d;
69 70
70 if (argc != 2) 71 if (argc != 2)
71 { 72 {
72 printf ("%s PORT\n", argv[0]); 73 printf ("%s PORT\n", argv[0]);
73 return 1; 74 return 1;
74 } 75 }
75 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_DUAL_STACK, 76 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
76 atoi (argv[1]), 77 | MHD_USE_DUAL_STACK,
77 NULL, NULL, &ahc_echo, PAGE, 78 atoi (argv[1]),
78 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 79 NULL, NULL, &ahc_echo, PAGE,
79 MHD_OPTION_END); 80 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
81 MHD_OPTION_END);
80 (void) getc (stdin); 82 (void) getc (stdin);
81 MHD_stop_daemon (d); 83 MHD_stop_daemon (d);
82 return 0; 84 return 0;
diff --git a/src/examples/fileserver_example_dirs.c b/src/examples/fileserver_example_dirs.c
index 8c37f219..2b544b69 100644
--- a/src/examples/fileserver_example_dirs.c
+++ b/src/examples/fileserver_example_dirs.c
@@ -28,7 +28,8 @@
28#include <microhttpd.h> 28#include <microhttpd.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 31#define PAGE \
32 "<html><head><title>File not found</title></head><body>File not found</body></html>"
32 33
33 34
34static ssize_t 35static ssize_t
@@ -66,17 +67,17 @@ dir_reader (void *cls, uint64_t pos, char *buf, size_t max)
66 67
67 if (max < 512) 68 if (max < 512)
68 return 0; 69 return 0;
69 (void)pos; /* 'pos' is ignored as function return next one single entry per call. */ 70 (void) pos; /* 'pos' is ignored as function return next one single entry per call. */
70 do 71 do
71 { 72 {
72 e = readdir (dir); 73 e = readdir (dir);
73 if (e == NULL) 74 if (e == NULL)
74 return MHD_CONTENT_READER_END_OF_STREAM; 75 return MHD_CONTENT_READER_END_OF_STREAM;
75 } while (e->d_name[0] == '.'); 76 } while (e->d_name[0] == '.');
76 return snprintf (buf, max, 77 return snprintf (buf, max,
77 "<a href=\"/%s\">%s</a><br>", 78 "<a href=\"/%s\">%s</a><br>",
78 e->d_name, 79 e->d_name,
79 e->d_name); 80 e->d_name);
80} 81}
81 82
82 83
@@ -87,7 +88,7 @@ ahc_echo (void *cls,
87 const char *method, 88 const char *method,
88 const char *version, 89 const char *version,
89 const char *upload_data, 90 const char *upload_data,
90 size_t *upload_data_size, void **ptr) 91 size_t *upload_data_size, void **ptr)
91{ 92{
92 static int aptr; 93 static int aptr;
93 struct MHD_Response *response; 94 struct MHD_Response *response;
@@ -97,90 +98,90 @@ ahc_echo (void *cls,
97 DIR *dir; 98 DIR *dir;
98 struct stat buf; 99 struct stat buf;
99 char emsg[1024]; 100 char emsg[1024];
100 (void)cls; /* Unused. Silent compiler warning. */ 101 (void) cls; /* Unused. Silent compiler warning. */
101 (void)version; /* Unused. Silent compiler warning. */ 102 (void) version; /* Unused. Silent compiler warning. */
102 (void)upload_data; /* Unused. Silent compiler warning. */ 103 (void) upload_data; /* Unused. Silent compiler warning. */
103 (void)upload_data_size; /* Unused. Silent compiler warning. */ 104 (void) upload_data_size; /* Unused. Silent compiler warning. */
104 105
105 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 106 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
106 return MHD_NO; /* unexpected method */ 107 return MHD_NO; /* unexpected method */
107 if (&aptr != *ptr) 108 if (&aptr != *ptr)
108 { 109 {
109 /* do never respond on first call */ 110 /* do never respond on first call */
110 *ptr = &aptr; 111 *ptr = &aptr;
111 return MHD_YES; 112 return MHD_YES;
112 } 113 }
113 *ptr = NULL; /* reset when done */ 114 *ptr = NULL; /* reset when done */
114 115
115 file = fopen (&url[1], "rb"); 116 file = fopen (&url[1], "rb");
116 if (NULL != file) 117 if (NULL != file)
118 {
119 fd = fileno (file);
120 if (-1 == fd)
117 { 121 {
118 fd = fileno (file); 122 (void) fclose (file);
119 if (-1 == fd) 123 return MHD_NO; /* internal error */
120 {
121 (void) fclose (file);
122 return MHD_NO; /* internal error */
123 }
124 if ( (0 != fstat (fd, &buf)) ||
125 (! S_ISREG (buf.st_mode)) )
126 {
127 /* not a regular file, refuse to serve */
128 fclose (file);
129 file = NULL;
130 }
131 } 124 }
125 if ( (0 != fstat (fd, &buf)) ||
126 (! S_ISREG (buf.st_mode)) )
127 {
128 /* not a regular file, refuse to serve */
129 fclose (file);
130 file = NULL;
131 }
132 }
132 133
133 if (NULL == file) 134 if (NULL == file)
135 {
136 dir = opendir (".");
137 if (NULL == dir)
134 { 138 {
135 dir = opendir ("."); 139 /* most likely cause: more concurrent requests than
136 if (NULL == dir) 140 available file descriptors / 2 */
137 { 141 snprintf (emsg,
138 /* most likely cause: more concurrent requests than 142 sizeof (emsg),
139 available file descriptors / 2 */ 143 "Failed to open directory `.': %s\n",
140 snprintf (emsg, 144 strerror (errno));
141 sizeof (emsg), 145 response = MHD_create_response_from_buffer (strlen (emsg),
142 "Failed to open directory `.': %s\n", 146 emsg,
143 strerror (errno)); 147 MHD_RESPMEM_MUST_COPY);
144 response = MHD_create_response_from_buffer (strlen (emsg), 148 if (NULL == response)
145 emsg, 149 return MHD_NO;
146 MHD_RESPMEM_MUST_COPY); 150 ret = MHD_queue_response (connection,
147 if (NULL == response) 151 MHD_HTTP_SERVICE_UNAVAILABLE,
148 return MHD_NO; 152 response);
149 ret = MHD_queue_response (connection, 153 MHD_destroy_response (response);
150 MHD_HTTP_SERVICE_UNAVAILABLE,
151 response);
152 MHD_destroy_response (response);
153 }
154 else
155 {
156 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
157 32 * 1024,
158 &dir_reader,
159 dir,
160 &dir_free_callback);
161 if (NULL == response)
162 {
163 closedir (dir);
164 return MHD_NO;
165 }
166 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
167 MHD_destroy_response (response);
168 }
169 } 154 }
170 else 155 else
171 { 156 {
172 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */ 157 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
173 &file_reader, 158 32 * 1024,
174 file, 159 &dir_reader,
175 &file_free_callback); 160 dir,
161 &dir_free_callback);
176 if (NULL == response) 162 if (NULL == response)
177 { 163 {
178 fclose (file); 164 closedir (dir);
179 return MHD_NO; 165 return MHD_NO;
180 } 166 }
181 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 167 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
182 MHD_destroy_response (response); 168 MHD_destroy_response (response);
183 } 169 }
170 }
171 else
172 {
173 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */
174 &file_reader,
175 file,
176 &file_free_callback);
177 if (NULL == response)
178 {
179 fclose (file);
180 return MHD_NO;
181 }
182 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
183 MHD_destroy_response (response);
184 }
184 return ret; 185 return ret;
185} 186}
186 187
@@ -191,11 +192,12 @@ main (int argc, char *const *argv)
191 struct MHD_Daemon *d; 192 struct MHD_Daemon *d;
192 193
193 if (argc != 2) 194 if (argc != 2)
194 { 195 {
195 printf ("%s PORT\n", argv[0]); 196 printf ("%s PORT\n", argv[0]);
196 return 1; 197 return 1;
197 } 198 }
198 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 199 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
200 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
199 atoi (argv[1]), 201 atoi (argv[1]),
200 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); 202 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
201 if (NULL == d) 203 if (NULL == d)
diff --git a/src/examples/fileserver_example_external_select.c b/src/examples/fileserver_example_external_select.c
index 6aea6dbf..187cdf7e 100644
--- a/src/examples/fileserver_example_external_select.c
+++ b/src/examples/fileserver_example_external_select.c
@@ -27,7 +27,8 @@
27#include <sys/stat.h> 27#include <sys/stat.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 30#define PAGE \
31 "<html><head><title>File not found</title></head><body>File not found</body></html>"
31 32
32static ssize_t 33static ssize_t
33file_reader (void *cls, uint64_t pos, char *buf, size_t max) 34file_reader (void *cls, uint64_t pos, char *buf, size_t max)
@@ -54,7 +55,7 @@ ahc_echo (void *cls,
54 const char *method, 55 const char *method,
55 const char *version, 56 const char *version,
56 const char *upload_data, 57 const char *upload_data,
57 size_t *upload_data_size, void **ptr) 58 size_t *upload_data_size, void **ptr)
58{ 59{
59 static int aptr; 60 static int aptr;
60 struct MHD_Response *response; 61 struct MHD_Response *response;
@@ -62,61 +63,61 @@ ahc_echo (void *cls,
62 FILE *file; 63 FILE *file;
63 int fd; 64 int fd;
64 struct stat buf; 65 struct stat buf;
65 (void)cls; /* Unused. Silent compiler warning. */ 66 (void) cls; /* Unused. Silent compiler warning. */
66 (void)version; /* Unused. Silent compiler warning. */ 67 (void) version; /* Unused. Silent compiler warning. */
67 (void)upload_data; /* Unused. Silent compiler warning. */ 68 (void) upload_data; /* Unused. Silent compiler warning. */
68 (void)upload_data_size; /* Unused. Silent compiler warning. */ 69 (void) upload_data_size; /* Unused. Silent compiler warning. */
69 70
70 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 71 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
71 return MHD_NO; /* unexpected method */ 72 return MHD_NO; /* unexpected method */
72 if (&aptr != *ptr) 73 if (&aptr != *ptr)
73 { 74 {
74 /* do never respond on first call */ 75 /* do never respond on first call */
75 *ptr = &aptr; 76 *ptr = &aptr;
76 return MHD_YES; 77 return MHD_YES;
77 } 78 }
78 *ptr = NULL; /* reset when done */ 79 *ptr = NULL; /* reset when done */
79 80
80 file = fopen (&url[1], "rb"); 81 file = fopen (&url[1], "rb");
81 if (NULL != file) 82 if (NULL != file)
83 {
84 fd = fileno (file);
85 if (-1 == fd)
82 { 86 {
83 fd = fileno (file); 87 (void) fclose (file);
84 if (-1 == fd) 88 return MHD_NO; /* internal error */
85 {
86 (void) fclose (file);
87 return MHD_NO; /* internal error */
88 }
89 if ( (0 != fstat (fd, &buf)) ||
90 (! S_ISREG (buf.st_mode)) )
91 {
92 /* not a regular file, refuse to serve */
93 fclose (file);
94 file = NULL;
95 }
96 } 89 }
97 90 if ( (0 != fstat (fd, &buf)) ||
98 if (NULL == file) 91 (! S_ISREG (buf.st_mode)) )
99 { 92 {
100 response = MHD_create_response_from_buffer (strlen (PAGE), 93 /* not a regular file, refuse to serve */
101 (void *) PAGE, 94 fclose (file);
102 MHD_RESPMEM_PERSISTENT); 95 file = NULL;
103 ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
104 MHD_destroy_response (response);
105 } 96 }
97 }
98
99 if (NULL == file)
100 {
101 response = MHD_create_response_from_buffer (strlen (PAGE),
102 (void *) PAGE,
103 MHD_RESPMEM_PERSISTENT);
104 ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
105 MHD_destroy_response (response);
106 }
106 else 107 else
108 {
109 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */
110 &file_reader,
111 file,
112 &free_callback);
113 if (NULL == response)
107 { 114 {
108 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */ 115 fclose (file);
109 &file_reader, 116 return MHD_NO;
110 file,
111 &free_callback);
112 if (NULL == response)
113 {
114 fclose (file);
115 return MHD_NO;
116 }
117 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
118 MHD_destroy_response (response);
119 } 117 }
118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
119 MHD_destroy_response (response);
120 }
120 return ret; 121 return ret;
121} 122}
122 123
@@ -135,10 +136,10 @@ main (int argc, char *const *argv)
135 MHD_UNSIGNED_LONG_LONG mhd_timeout; 136 MHD_UNSIGNED_LONG_LONG mhd_timeout;
136 137
137 if (argc != 3) 138 if (argc != 3)
138 { 139 {
139 printf ("%s PORT SECONDS-TO-RUN\n", argv[0]); 140 printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
140 return 1; 141 return 1;
141 } 142 }
142 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 143 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
143 atoi (argv[1]), 144 atoi (argv[1]),
144 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); 145 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
@@ -146,30 +147,30 @@ main (int argc, char *const *argv)
146 return 1; 147 return 1;
147 end = time (NULL) + atoi (argv[2]); 148 end = time (NULL) + atoi (argv[2]);
148 while ((t = time (NULL)) < end) 149 while ((t = time (NULL)) < end)
150 {
151 tv.tv_sec = end - t;
152 tv.tv_usec = 0;
153 max = 0;
154 FD_ZERO (&rs);
155 FD_ZERO (&ws);
156 FD_ZERO (&es);
157 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
158 break; /* fatal internal error */
159 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
160 {
161 if (((MHD_UNSIGNED_LONG_LONG) tv.tv_sec) < mhd_timeout / 1000LL)
162 {
163 tv.tv_sec = mhd_timeout / 1000LL;
164 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000LL)) * 1000LL;
165 }
166 }
167 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
149 { 168 {
150 tv.tv_sec = end - t; 169 if (EINTR != errno)
151 tv.tv_usec = 0; 170 abort ();
152 max = 0;
153 FD_ZERO (&rs);
154 FD_ZERO (&ws);
155 FD_ZERO (&es);
156 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
157 break; /* fatal internal error */
158 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
159 {
160 if (((MHD_UNSIGNED_LONG_LONG)tv.tv_sec) < mhd_timeout / 1000LL)
161 {
162 tv.tv_sec = mhd_timeout / 1000LL;
163 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000LL)) * 1000LL;
164 }
165 }
166 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
167 {
168 if (EINTR != errno)
169 abort ();
170 }
171 MHD_run (d);
172 } 171 }
172 MHD_run (d);
173 }
173 MHD_stop_daemon (d); 174 MHD_stop_daemon (d);
174 return 0; 175 return 0;
175} 176}
diff --git a/src/examples/http_chunked_compression.c b/src/examples/http_chunked_compression.c
index 9c3f629f..461f4d3a 100644
--- a/src/examples/http_chunked_compression.c
+++ b/src/examples/http_chunked_compression.c
@@ -38,20 +38,22 @@
38#elif defined(INTPTR_MAX) 38#elif defined(INTPTR_MAX)
39#define SSIZE_MAX INTPTR_MAX 39#define SSIZE_MAX INTPTR_MAX
40#else 40#else
41#define SSIZE_MAX ((ssize_t)(((size_t)-1)>>1)) 41#define SSIZE_MAX ((ssize_t) (((size_t) -1) >> 1))
42#endif 42#endif
43#endif /* ! SSIZE_MAX */ 43#endif /* ! SSIZE_MAX */
44 44
45#define CHUNK 16384 45#define CHUNK 16384
46 46
47struct Holder { 47struct Holder
48 FILE *file; 48{
49 z_stream stream; 49 FILE *file;
50 void *buf; 50 z_stream stream;
51 void *buf;
51}; 52};
52 53
53static int 54static int
54compress_buf (z_stream *strm, const void *src, size_t src_size, size_t *offset, void **dest, size_t *dest_size, 55compress_buf (z_stream *strm, const void *src, size_t src_size, size_t *offset,
56 void **dest, size_t *dest_size,
55 void *tmp) 57 void *tmp)
56{ 58{
57 unsigned int have; 59 unsigned int have;
@@ -61,39 +63,39 @@ compress_buf (z_stream *strm, const void *src, size_t src_size, size_t *offset,
61 *dest = NULL; 63 *dest = NULL;
62 *dest_size = 0; 64 *dest_size = 0;
63 do 65 do
66 {
67 if (src_size > CHUNK)
64 { 68 {
65 if (src_size > CHUNK) 69 strm->avail_in = CHUNK;
66 { 70 src_size -= CHUNK;
67 strm->avail_in = CHUNK; 71 flush = Z_NO_FLUSH;
68 src_size -= CHUNK;
69 flush = Z_NO_FLUSH;
70 }
71 else
72 {
73 strm->avail_in = (uInt) src_size;
74 flush = Z_SYNC_FLUSH;
75 }
76 *offset += strm->avail_in;
77 strm->next_in = (Bytef *) src;
78 do
79 {
80 strm->avail_out = CHUNK;
81 strm->next_out = tmp;
82 ret = deflate (strm, flush);
83 have = CHUNK - strm->avail_out;
84 *dest_size += have;
85 tmp_dest = realloc (*dest, *dest_size);
86 if (NULL == tmp_dest)
87 {
88 free (*dest);
89 *dest = NULL;
90 return MHD_NO;
91 }
92 *dest = tmp_dest;
93 memcpy ((*dest) + ((*dest_size) - have), tmp, have);
94 }
95 while (0 == strm->avail_out);
96 } 72 }
73 else
74 {
75 strm->avail_in = (uInt) src_size;
76 flush = Z_SYNC_FLUSH;
77 }
78 *offset += strm->avail_in;
79 strm->next_in = (Bytef *) src;
80 do
81 {
82 strm->avail_out = CHUNK;
83 strm->next_out = tmp;
84 ret = deflate (strm, flush);
85 have = CHUNK - strm->avail_out;
86 *dest_size += have;
87 tmp_dest = realloc (*dest, *dest_size);
88 if (NULL == tmp_dest)
89 {
90 free (*dest);
91 *dest = NULL;
92 return MHD_NO;
93 }
94 *dest = tmp_dest;
95 memcpy ((*dest) + ((*dest_size) - have), tmp, have);
96 }
97 while (0 == strm->avail_out);
98 }
97 while (flush != Z_SYNC_FLUSH); 99 while (flush != Z_SYNC_FLUSH);
98 return (Z_OK == ret) ? MHD_YES : MHD_NO; 100 return (Z_OK == ret) ? MHD_YES : MHD_NO;
99} 101}
@@ -114,22 +116,23 @@ read_cb (void *cls, uint64_t pos, char *mem, size_t size)
114 return MHD_CONTENT_READER_END_WITH_ERROR; 116 return MHD_CONTENT_READER_END_WITH_ERROR;
115 ret = fread (src, 1, size, holder->file); 117 ret = fread (src, 1, size, holder->file);
116 if (ret < 0) 118 if (ret < 0)
117 { 119 {
118 ret = MHD_CONTENT_READER_END_WITH_ERROR; 120 ret = MHD_CONTENT_READER_END_WITH_ERROR;
119 goto done; 121 goto done;
120 } 122 }
121 if (0 == size) 123 if (0 == size)
122 { 124 {
123 ret = MHD_CONTENT_READER_END_OF_STREAM; 125 ret = MHD_CONTENT_READER_END_OF_STREAM;
124 goto done; 126 goto done;
125 } 127 }
126 if (MHD_YES != compress_buf (&holder->stream, src, ret, &offset, &buf, &size, holder->buf)) 128 if (MHD_YES != compress_buf (&holder->stream, src, ret, &offset, &buf, &size,
129 holder->buf))
127 ret = MHD_CONTENT_READER_END_WITH_ERROR; 130 ret = MHD_CONTENT_READER_END_WITH_ERROR;
128 else 131 else
129 { 132 {
130 memcpy (mem, buf, size); 133 memcpy (mem, buf, size);
131 ret = size; 134 ret = size;
132 } 135 }
133 free (buf); /* Buf may be set even on error return. */ 136 free (buf); /* Buf may be set even on error return. */
134done: 137done:
135 free (src); 138 free (src);
@@ -147,7 +150,8 @@ free_cb (void *cls)
147} 150}
148 151
149static int 152static int
150ahc_echo (void *cls, struct MHD_Connection *con, const char *url, const char *method, const char *version, 153ahc_echo (void *cls, struct MHD_Connection *con, const char *url, const
154 char *method, const char *version,
151 const char *upload_data, size_t *upload_size, void **ptr) 155 const char *upload_data, size_t *upload_size, void **ptr)
152{ 156{
153 struct Holder *holder; 157 struct Holder *holder;
@@ -160,27 +164,29 @@ ahc_echo (void *cls, struct MHD_Connection *con, const char *url, const char *me
160 (void) upload_data; 164 (void) upload_data;
161 (void) upload_size; 165 (void) upload_size;
162 if (NULL == *ptr) 166 if (NULL == *ptr)
163 { 167 {
164 *ptr = (void *) 1; 168 *ptr = (void *) 1;
165 return MHD_YES; 169 return MHD_YES;
166 } 170 }
167 *ptr = NULL; 171 *ptr = NULL;
168 holder = calloc (1, sizeof (struct Holder)); 172 holder = calloc (1, sizeof (struct Holder));
169 if (!holder) 173 if (! holder)
170 return MHD_NO; 174 return MHD_NO;
171 holder->file = fopen (__FILE__, "rb"); 175 holder->file = fopen (__FILE__, "rb");
172 if (NULL == holder->file) 176 if (NULL == holder->file)
173 goto file_error; 177 goto file_error;
174 ret = deflateInit(&holder->stream, Z_BEST_COMPRESSION); 178 ret = deflateInit (&holder->stream, Z_BEST_COMPRESSION);
175 if (ret != Z_OK) 179 if (ret != Z_OK)
176 goto stream_error; 180 goto stream_error;
177 holder->buf = malloc (CHUNK); 181 holder->buf = malloc (CHUNK);
178 if (NULL == holder->buf) 182 if (NULL == holder->buf)
179 goto buf_error; 183 goto buf_error;
180 res = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, &read_cb, holder, &free_cb); 184 res = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, &read_cb,
185 holder, &free_cb);
181 if (NULL == res) 186 if (NULL == res)
182 goto error; 187 goto error;
183 ret = MHD_add_response_header (res, MHD_HTTP_HEADER_CONTENT_ENCODING, "deflate"); 188 ret = MHD_add_response_header (res, MHD_HTTP_HEADER_CONTENT_ENCODING,
189 "deflate");
184 if (MHD_YES != ret) 190 if (MHD_YES != ret)
185 goto res_error; 191 goto res_error;
186 ret = MHD_add_response_header (res, MHD_HTTP_HEADER_CONTENT_TYPE, "text/x-c"); 192 ret = MHD_add_response_header (res, MHD_HTTP_HEADER_CONTENT_TYPE, "text/x-c");
@@ -209,18 +215,21 @@ main (int argc, char *const *argv)
209 if ((argc != 2) || 215 if ((argc != 2) ||
210 (1 != sscanf (argv[1], "%u", &port)) || 216 (1 != sscanf (argv[1], "%u", &port)) ||
211 (UINT16_MAX < port)) 217 (UINT16_MAX < port))
212 { 218 {
213 fprintf (stderr, "%s PORT\n", argv[0]); 219 fprintf (stderr, "%s PORT\n", argv[0]);
214 return 1; 220 return 1;
215 } 221 }
216 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, (uint16_t) port, NULL, NULL, 222 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
223 (uint16_t) port, NULL, NULL,
217 &ahc_echo, NULL, 224 &ahc_echo, NULL,
218 MHD_OPTION_END); 225 MHD_OPTION_END);
219 if (NULL == d) 226 if (NULL == d)
220 return 1; 227 return 1;
221 if (0 == port) 228 if (0 == port)
222 MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT, &port); 229 MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT, &port);
223 fprintf (stdout, "HTTP server running at http://localhost:%u\n\nPress ENTER to stop the server ...\n", port); 230 fprintf (stdout,
231 "HTTP server running at http://localhost:%u\n\nPress ENTER to stop the server ...\n",
232 port);
224 (void) getc (stdin); 233 (void) getc (stdin);
225 MHD_stop_daemon (d); 234 MHD_stop_daemon (d);
226 return 0; 235 return 0;
diff --git a/src/examples/http_compression.c b/src/examples/http_compression.c
index 1324fa4d..af153f6e 100644
--- a/src/examples/http_compression.c
+++ b/src/examples/http_compression.c
@@ -77,11 +77,11 @@ body_compress (void **buf,
77 *buf_size); 77 *buf_size);
78 if ((Z_OK != ret) || 78 if ((Z_OK != ret) ||
79 (cbuf_size >= *buf_size)) 79 (cbuf_size >= *buf_size))
80 { 80 {
81 /* compression failed */ 81 /* compression failed */
82 free (cbuf); 82 free (cbuf);
83 return MHD_NO; 83 return MHD_NO;
84 } 84 }
85 free (*buf); 85 free (*buf);
86 *buf = (void *) cbuf; 86 *buf = (void *) cbuf;
87 *buf_size = (size_t) cbuf_size; 87 *buf_size = (size_t) cbuf_size;
@@ -109,18 +109,18 @@ ahc_echo (void *cls,
109 109
110 if (0 != strcmp (method, "GET")) 110 if (0 != strcmp (method, "GET"))
111 return MHD_NO; /* unexpected method */ 111 return MHD_NO; /* unexpected method */
112 if (!*ptr) 112 if (! *ptr)
113 { 113 {
114 *ptr = (void *) 1; 114 *ptr = (void *) 1;
115 return MHD_YES; 115 return MHD_YES;
116 } 116 }
117 *ptr = NULL; 117 *ptr = NULL;
118 118
119 body_str = strdup (PAGE); 119 body_str = strdup (PAGE);
120 if (NULL == body_str) 120 if (NULL == body_str)
121 { 121 {
122 return MHD_NO; 122 return MHD_NO;
123 } 123 }
124 body_len = strlen (body_str); 124 body_len = strlen (body_str);
125 /* try to compress the body */ 125 /* try to compress the body */
126 comp = MHD_NO; 126 comp = MHD_NO;
@@ -132,23 +132,23 @@ ahc_echo (void *cls,
132 body_str, 132 body_str,
133 MHD_RESPMEM_MUST_FREE); 133 MHD_RESPMEM_MUST_FREE);
134 if (NULL == response) 134 if (NULL == response)
135 { 135 {
136 free (body_str); 136 free (body_str);
137 return MHD_NO; 137 return MHD_NO;
138 } 138 }
139 139
140 if (MHD_YES == comp) 140 if (MHD_YES == comp)
141 {
142 /* Need to indicate to client that body is compressed */
143 if (MHD_NO ==
144 MHD_add_response_header (response,
145 MHD_HTTP_HEADER_CONTENT_ENCODING,
146 "deflate"))
141 { 147 {
142 /* Need to indicate to client that body is compressed */ 148 MHD_destroy_response (response);
143 if (MHD_NO == 149 return MHD_NO;
144 MHD_add_response_header (response,
145 MHD_HTTP_HEADER_CONTENT_ENCODING,
146 "deflate"))
147 {
148 MHD_destroy_response (response);
149 return MHD_NO;
150 }
151 } 150 }
151 }
152 ret = MHD_queue_response (connection, 152 ret = MHD_queue_response (connection,
153 200, 153 200,
154 response); 154 response);
@@ -162,11 +162,12 @@ main (int argc, char *const *argv)
162 struct MHD_Daemon *d; 162 struct MHD_Daemon *d;
163 163
164 if (argc != 2) 164 if (argc != 2)
165 { 165 {
166 printf ("%s PORT\n", argv[0]); 166 printf ("%s PORT\n", argv[0]);
167 return 1; 167 return 1;
168 } 168 }
169 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 169 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
170 | MHD_USE_ERROR_LOG,
170 atoi (argv[1]), NULL, NULL, 171 atoi (argv[1]), NULL, NULL,
171 &ahc_echo, NULL, 172 &ahc_echo, NULL,
172 MHD_OPTION_END); 173 MHD_OPTION_END);
diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c
index 7e3e6d43..cd7aa355 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -43,7 +43,8 @@
43#define CAFILE "ca.pem" 43#define CAFILE "ca.pem"
44#define CRLFILE "crl.pem" 44#define CRLFILE "crl.pem"
45 45
46#define EMPTY_PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 46#define EMPTY_PAGE \
47 "<html><head><title>File not found</title></head><body>File not found</body></html>"
47 48
48/* Test Certificate */ 49/* Test Certificate */
49const char cert_pem[] = 50const char cert_pem[] =
@@ -117,7 +118,7 @@ http_ahc (void *cls,
117 const char *method, 118 const char *method,
118 const char *version, 119 const char *version,
119 const char *upload_data, 120 const char *upload_data,
120 size_t *upload_data_size, void **ptr) 121 size_t *upload_data_size, void **ptr)
121{ 122{
122 static int aptr; 123 static int aptr;
123 struct MHD_Response *response; 124 struct MHD_Response *response;
@@ -125,60 +126,60 @@ http_ahc (void *cls,
125 FILE *file; 126 FILE *file;
126 int fd; 127 int fd;
127 struct stat buf; 128 struct stat buf;
128 (void)cls; /* Unused. Silent compiler warning. */ 129 (void) cls; /* Unused. Silent compiler warning. */
129 (void)version; /* Unused. Silent compiler warning. */ 130 (void) version; /* Unused. Silent compiler warning. */
130 (void)upload_data; /* Unused. Silent compiler warning. */ 131 (void) upload_data; /* Unused. Silent compiler warning. */
131 (void)upload_data_size; /* Unused. Silent compiler warning. */ 132 (void) upload_data_size; /* Unused. Silent compiler warning. */
132 133
133 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 134 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
134 return MHD_NO; /* unexpected method */ 135 return MHD_NO; /* unexpected method */
135 if (&aptr != *ptr) 136 if (&aptr != *ptr)
136 { 137 {
137 /* do never respond on first call */ 138 /* do never respond on first call */
138 *ptr = &aptr; 139 *ptr = &aptr;
139 return MHD_YES; 140 return MHD_YES;
140 } 141 }
141 *ptr = NULL; /* reset when done */ 142 *ptr = NULL; /* reset when done */
142 143
143 file = fopen (&url[1], "rb"); 144 file = fopen (&url[1], "rb");
144 if (NULL != file) 145 if (NULL != file)
146 {
147 fd = fileno (file);
148 if (-1 == fd)
145 { 149 {
146 fd = fileno (file); 150 (void) fclose (file);
147 if (-1 == fd) 151 return MHD_NO; /* internal error */
148 {
149 (void) fclose (file);
150 return MHD_NO; /* internal error */
151 }
152 if ( (0 != fstat (fd, &buf)) ||
153 (! S_ISREG (buf.st_mode)) )
154 {
155 /* not a regular file, refuse to serve */
156 fclose (file);
157 file = NULL;
158 }
159 } 152 }
160 153 if ( (0 != fstat (fd, &buf)) ||
161 if (NULL == file) 154 (! S_ISREG (buf.st_mode)) )
162 { 155 {
163 response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), 156 /* not a regular file, refuse to serve */
164 (void *) EMPTY_PAGE, 157 fclose (file);
165 MHD_RESPMEM_PERSISTENT); 158 file = NULL;
166 ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
167 MHD_destroy_response (response);
168 } 159 }
160 }
161
162 if (NULL == file)
163 {
164 response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE),
165 (void *) EMPTY_PAGE,
166 MHD_RESPMEM_PERSISTENT);
167 ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
168 MHD_destroy_response (response);
169 }
169 else 170 else
171 {
172 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k PAGE_NOT_FOUND size */
173 &file_reader, file,
174 &file_free_callback);
175 if (NULL == response)
170 { 176 {
171 response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k PAGE_NOT_FOUND size */ 177 fclose (file);
172 &file_reader, file, 178 return MHD_NO;
173 &file_free_callback);
174 if (NULL == response)
175 {
176 fclose (file);
177 return MHD_NO;
178 }
179 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
180 MHD_destroy_response (response);
181 } 179 }
180 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
181 MHD_destroy_response (response);
182 }
182 return ret; 183 return ret;
183} 184}
184 185
@@ -190,22 +191,23 @@ main (int argc, char *const *argv)
190 int port; 191 int port;
191 192
192 if (argc != 2) 193 if (argc != 2)
193 { 194 {
194 printf ("%s PORT\n", argv[0]); 195 printf ("%s PORT\n", argv[0]);
195 return 1; 196 return 1;
196 } 197 }
197 port = atoi (argv[1]); 198 port = atoi (argv[1]);
198 if ( (1 > port) || 199 if ( (1 > port) ||
199 (port > UINT16_MAX) ) 200 (port > UINT16_MAX) )
200 { 201 {
201 fprintf (stderr, 202 fprintf (stderr,
202 "Port must be a number between 1 and 65535\n"); 203 "Port must be a number between 1 and 65535\n");
203 return 1; 204 return 1;
204 } 205 }
205 206
206 TLS_daemon = 207 TLS_daemon =
207 MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | 208 MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
208 MHD_USE_TLS, 209 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
210 | MHD_USE_TLS,
209 (uint16_t) port, 211 (uint16_t) port,
210 NULL, NULL, 212 NULL, NULL,
211 &http_ahc, NULL, 213 &http_ahc, NULL,
@@ -214,10 +216,10 @@ main (int argc, char *const *argv)
214 MHD_OPTION_HTTPS_MEM_CERT, cert_pem, 216 MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
215 MHD_OPTION_END); 217 MHD_OPTION_END);
216 if (NULL == TLS_daemon) 218 if (NULL == TLS_daemon)
217 { 219 {
218 fprintf (stderr, "Error: failed to start TLS_daemon\n"); 220 fprintf (stderr, "Error: failed to start TLS_daemon\n");
219 return 1; 221 return 1;
220 } 222 }
221 printf ("MHD daemon listening on port %u\n", 223 printf ("MHD daemon listening on port %u\n",
222 (unsigned int) port); 224 (unsigned int) port);
223 225
diff --git a/src/examples/minimal_example_comet.c b/src/examples/minimal_example_comet.c
index c4a3395d..53f8f666 100644
--- a/src/examples/minimal_example_comet.c
+++ b/src/examples/minimal_example_comet.c
@@ -28,8 +28,8 @@
28static ssize_t 28static ssize_t
29data_generator (void *cls, uint64_t pos, char *buf, size_t max) 29data_generator (void *cls, uint64_t pos, char *buf, size_t max)
30{ 30{
31 (void)cls; /* Unused. Silent compiler warning. */ 31 (void) cls; /* Unused. Silent compiler warning. */
32 (void)pos; /* Unused. Silent compiler warning. */ 32 (void) pos; /* Unused. Silent compiler warning. */
33 if (max < 80) 33 if (max < 80)
34 return 0; 34 return 0;
35 memset (buf, 'A', max - 1); 35 memset (buf, 'A', max - 1);
@@ -48,20 +48,20 @@ ahc_echo (void *cls,
48 static int aptr; 48 static int aptr;
49 struct MHD_Response *response; 49 struct MHD_Response *response;
50 int ret; 50 int ret;
51 (void)cls; /* Unused. Silent compiler warning. */ 51 (void) cls; /* Unused. Silent compiler warning. */
52 (void)url; /* Unused. Silent compiler warning. */ 52 (void) url; /* Unused. Silent compiler warning. */
53 (void)version; /* Unused. Silent compiler warning. */ 53 (void) version; /* Unused. Silent compiler warning. */
54 (void)upload_data; /* Unused. Silent compiler warning. */ 54 (void) upload_data; /* Unused. Silent compiler warning. */
55 (void)upload_data_size; /* Unused. Silent compiler warning. */ 55 (void) upload_data_size; /* Unused. Silent compiler warning. */
56 56
57 if (0 != strcmp (method, "GET")) 57 if (0 != strcmp (method, "GET"))
58 return MHD_NO; /* unexpected method */ 58 return MHD_NO; /* unexpected method */
59 if (&aptr != *ptr) 59 if (&aptr != *ptr)
60 { 60 {
61 /* do never respond on first call */ 61 /* do never respond on first call */
62 *ptr = &aptr; 62 *ptr = &aptr;
63 return MHD_YES; 63 return MHD_YES;
64 } 64 }
65 *ptr = NULL; /* reset when done */ 65 *ptr = NULL; /* reset when done */
66 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 66 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
67 80, 67 80,
@@ -77,11 +77,12 @@ main (int argc, char *const *argv)
77 struct MHD_Daemon *d; 77 struct MHD_Daemon *d;
78 78
79 if (argc != 2) 79 if (argc != 2)
80 { 80 {
81 printf ("%s PORT\n", argv[0]); 81 printf ("%s PORT\n", argv[0]);
82 return 1; 82 return 1;
83 } 83 }
84 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 84 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION
85 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
85 atoi (argv[1]), 86 atoi (argv[1]),
86 NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 87 NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
87 if (d == NULL) 88 if (d == NULL)
diff --git a/src/examples/msgs_i18n.c b/src/examples/msgs_i18n.c
index 2d8eb566..e5f92bb5 100644
--- a/src/examples/msgs_i18n.c
+++ b/src/examples/msgs_i18n.c
@@ -45,29 +45,29 @@
45 45
46static int 46static int
47ahc_echo (void *cls, 47ahc_echo (void *cls,
48 struct MHD_Connection *cnc, 48 struct MHD_Connection *cnc,
49 const char *url, 49 const char *url,
50 const char *mt, 50 const char *mt,
51 const char *ver, 51 const char *ver,
52 const char *upd, 52 const char *upd,
53 size_t *upsz, 53 size_t *upsz,
54 void **ptr) 54 void **ptr)
55{ 55{
56 return MHD_NO; 56 return MHD_NO;
57} 57}
58 58
59 59
60static void 60static void
61error_handler (void *cls, 61error_handler (void *cls,
62 const char *fm, 62 const char *fm,
63 va_list ap) 63 va_list ap)
64{ 64{
65 /* Here we do the translation using GNU gettext. 65 /* Here we do the translation using GNU gettext.
66 As the error message is from libmicrohttpd, we specify 66 As the error message is from libmicrohttpd, we specify
67 "libmicrohttpd" as the translation domain here. */ 67 "libmicrohttpd" as the translation domain here. */
68 vprintf (dgettext ("libmicrohttpd", 68 vprintf (dgettext ("libmicrohttpd",
69 fm), 69 fm),
70 ap); 70 ap);
71} 71}
72 72
73 73
@@ -75,21 +75,22 @@ int
75main (int argc, 75main (int argc,
76 char **argv) 76 char **argv)
77{ 77{
78 setlocale(LC_ALL, ""); 78 setlocale (LC_ALL, "");
79 79
80 /* The example uses PO files in the directory 80 /* The example uses PO files in the directory
81 "libmicrohttpd/src/examples/locale". This 81 "libmicrohttpd/src/examples/locale". This
82 needs to be adapted to match 82 needs to be adapted to match
83 where the MHD PO files are installed. */ 83 where the MHD PO files are installed. */
84 bindtextdomain ("libmicrohttpd", 84 bindtextdomain ("libmicrohttpd",
85 "locale"); 85 "locale");
86 MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | MHD_USE_ERROR_LOG, 86 MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES
87 8080, 87 | MHD_USE_ERROR_LOG,
88 NULL, NULL, 88 8080,
89 &ahc_echo, NULL, 89 NULL, NULL,
90 MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL, 90 &ahc_echo, NULL,
91 99999 /* invalid option, to raise the error 91 MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL,
92 "Invalid option ..." which we are going 92 99999 /* invalid option, to raise the error
93 to translate */); 93 "Invalid option ..." which we are going
94 to translate */);
94 return 1; /* This program won't "succeed"... */ 95 return 1; /* This program won't "succeed"... */
95} 96}
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 6c9a3f4b..311bf6c2 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -32,32 +32,38 @@
32/** 32/**
33 * Invalid method page. 33 * Invalid method page.
34 */ 34 */
35#define METHOD_ERROR "<html><head><title>Illegal request</title></head><body>Go away.</body></html>" 35#define METHOD_ERROR \
36 "<html><head><title>Illegal request</title></head><body>Go away.</body></html>"
36 37
37/** 38/**
38 * Invalid URL page. 39 * Invalid URL page.
39 */ 40 */
40#define NOT_FOUND_ERROR "<html><head><title>Not found</title></head><body>Go away.</body></html>" 41#define NOT_FOUND_ERROR \
42 "<html><head><title>Not found</title></head><body>Go away.</body></html>"
41 43
42/** 44/**
43 * Front page. (/) 45 * Front page. (/)
44 */ 46 */
45#define MAIN_PAGE "<html><head><title>Welcome</title></head><body><form action=\"/2\" method=\"post\">What is your name? <input type=\"text\" name=\"v1\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" 47#define MAIN_PAGE \
48 "<html><head><title>Welcome</title></head><body><form action=\"/2\" method=\"post\">What is your name? <input type=\"text\" name=\"v1\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>"
46 49
47/** 50/**
48 * Second page. (/2) 51 * Second page. (/2)
49 */ 52 */
50#define SECOND_PAGE "<html><head><title>Tell me more</title></head><body><a href=\"/\">previous</a> <form action=\"/S\" method=\"post\">%s, what is your job? <input type=\"text\" name=\"v2\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" 53#define SECOND_PAGE \
54 "<html><head><title>Tell me more</title></head><body><a href=\"/\">previous</a> <form action=\"/S\" method=\"post\">%s, what is your job? <input type=\"text\" name=\"v2\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>"
51 55
52/** 56/**
53 * Second page (/S) 57 * Second page (/S)
54 */ 58 */
55#define SUBMIT_PAGE "<html><head><title>Ready to submit?</title></head><body><form action=\"/F\" method=\"post\"><a href=\"/2\">previous </a> <input type=\"hidden\" name=\"DONE\" value=\"yes\" /><input type=\"submit\" value=\"Submit\" /></body></html>" 59#define SUBMIT_PAGE \
60 "<html><head><title>Ready to submit?</title></head><body><form action=\"/F\" method=\"post\"><a href=\"/2\">previous </a> <input type=\"hidden\" name=\"DONE\" value=\"yes\" /><input type=\"submit\" value=\"Submit\" /></body></html>"
56 61
57/** 62/**
58 * Last page. 63 * Last page.
59 */ 64 */
60#define LAST_PAGE "<html><head><title>Thank you</title></head><body>Thank you.</body></html>" 65#define LAST_PAGE \
66 "<html><head><title>Thank you</title></head><body>Thank you.</body></html>"
61 67
62/** 68/**
63 * Name of our cookie. 69 * Name of our cookie.
@@ -150,40 +156,40 @@ get_session (struct MHD_Connection *connection)
150 const char *cookie; 156 const char *cookie;
151 157
152 cookie = MHD_lookup_connection_value (connection, 158 cookie = MHD_lookup_connection_value (connection,
153 MHD_COOKIE_KIND, 159 MHD_COOKIE_KIND,
154 COOKIE_NAME); 160 COOKIE_NAME);
155 if (cookie != NULL) 161 if (cookie != NULL)
162 {
163 /* find existing session */
164 ret = sessions;
165 while (NULL != ret)
166 {
167 if (0 == strcmp (cookie, ret->sid))
168 break;
169 ret = ret->next;
170 }
171 if (NULL != ret)
156 { 172 {
157 /* find existing session */ 173 ret->rc++;
158 ret = sessions; 174 return ret;
159 while (NULL != ret)
160 {
161 if (0 == strcmp (cookie, ret->sid))
162 break;
163 ret = ret->next;
164 }
165 if (NULL != ret)
166 {
167 ret->rc++;
168 return ret;
169 }
170 } 175 }
176 }
171 /* create fresh session */ 177 /* create fresh session */
172 ret = calloc (1, sizeof (struct Session)); 178 ret = calloc (1, sizeof (struct Session));
173 if (NULL == ret) 179 if (NULL == ret)
174 { 180 {
175 fprintf (stderr, "calloc error: %s\n", strerror (errno)); 181 fprintf (stderr, "calloc error: %s\n", strerror (errno));
176 return NULL; 182 return NULL;
177 } 183 }
178 /* not a super-secure way to generate a random session ID, 184 /* not a super-secure way to generate a random session ID,
179 but should do for a simple example... */ 185 but should do for a simple example... */
180 snprintf (ret->sid, 186 snprintf (ret->sid,
181 sizeof (ret->sid), 187 sizeof (ret->sid),
182 "%X%X%X%X", 188 "%X%X%X%X",
183 (unsigned int) rand (), 189 (unsigned int) rand (),
184 (unsigned int) rand (), 190 (unsigned int) rand (),
185 (unsigned int) rand (), 191 (unsigned int) rand (),
186 (unsigned int) rand ()); 192 (unsigned int) rand ());
187 ret->rc++; 193 ret->rc++;
188 ret->start = time (NULL); 194 ret->start = time (NULL);
189 ret->next = sessions; 195 ret->next = sessions;
@@ -202,9 +208,9 @@ get_session (struct MHD_Connection *connection)
202 * @param MHD_YES on success, MHD_NO on failure 208 * @param MHD_YES on success, MHD_NO on failure
203 */ 209 */
204typedef int (*PageHandler)(const void *cls, 210typedef int (*PageHandler)(const void *cls,
205 const char *mime, 211 const char *mime,
206 struct Session *session, 212 struct Session *session,
207 struct MHD_Connection *connection); 213 struct MHD_Connection *connection);
208 214
209 215
210/** 216/**
@@ -242,22 +248,22 @@ struct Page
242 */ 248 */
243static void 249static void
244add_session_cookie (struct Session *session, 250add_session_cookie (struct Session *session,
245 struct MHD_Response *response) 251 struct MHD_Response *response)
246{ 252{
247 char cstr[256]; 253 char cstr[256];
248 snprintf (cstr, 254 snprintf (cstr,
249 sizeof (cstr), 255 sizeof (cstr),
250 "%s=%s", 256 "%s=%s",
251 COOKIE_NAME, 257 COOKIE_NAME,
252 session->sid); 258 session->sid);
253 if (MHD_NO == 259 if (MHD_NO ==
254 MHD_add_response_header (response, 260 MHD_add_response_header (response,
255 MHD_HTTP_HEADER_SET_COOKIE, 261 MHD_HTTP_HEADER_SET_COOKIE,
256 cstr)) 262 cstr))
257 { 263 {
258 fprintf (stderr, 264 fprintf (stderr,
259 "Failed to set session cookie header!\n"); 265 "Failed to set session cookie header!\n");
260 } 266 }
261} 267}
262 268
263 269
@@ -272,9 +278,9 @@ add_session_cookie (struct Session *session,
272 */ 278 */
273static int 279static int
274serve_simple_form (const void *cls, 280serve_simple_form (const void *cls,
275 const char *mime, 281 const char *mime,
276 struct Session *session, 282 struct Session *session,
277 struct MHD_Connection *connection) 283 struct MHD_Connection *connection)
278{ 284{
279 int ret; 285 int ret;
280 const char *form = cls; 286 const char *form = cls;
@@ -282,17 +288,17 @@ serve_simple_form (const void *cls,
282 288
283 /* return static form */ 289 /* return static form */
284 response = MHD_create_response_from_buffer (strlen (form), 290 response = MHD_create_response_from_buffer (strlen (form),
285 (void *) form, 291 (void *) form,
286 MHD_RESPMEM_PERSISTENT); 292 MHD_RESPMEM_PERSISTENT);
287 if (NULL == response) 293 if (NULL == response)
288 return MHD_NO; 294 return MHD_NO;
289 add_session_cookie (session, response); 295 add_session_cookie (session, response);
290 MHD_add_response_header (response, 296 MHD_add_response_header (response,
291 MHD_HTTP_HEADER_CONTENT_ENCODING, 297 MHD_HTTP_HEADER_CONTENT_ENCODING,
292 mime); 298 mime);
293 ret = MHD_queue_response (connection, 299 ret = MHD_queue_response (connection,
294 MHD_HTTP_OK, 300 MHD_HTTP_OK,
295 response); 301 response);
296 MHD_destroy_response (response); 302 MHD_destroy_response (response);
297 return ret; 303 return ret;
298} 304}
@@ -308,28 +314,28 @@ serve_simple_form (const void *cls,
308 */ 314 */
309static int 315static int
310fill_v1_form (const void *cls, 316fill_v1_form (const void *cls,
311 const char *mime, 317 const char *mime,
312 struct Session *session, 318 struct Session *session,
313 struct MHD_Connection *connection) 319 struct MHD_Connection *connection)
314{ 320{
315 int ret; 321 int ret;
316 size_t slen; 322 size_t slen;
317 char *reply; 323 char *reply;
318 struct MHD_Response *response; 324 struct MHD_Response *response;
319 (void)cls; /* Unused. Silent compiler warning. */ 325 (void) cls; /* Unused. Silent compiler warning. */
320 326
321 slen = strlen (MAIN_PAGE) + strlen (session->value_1); 327 slen = strlen (MAIN_PAGE) + strlen (session->value_1);
322 reply = malloc (slen + 1); 328 reply = malloc (slen + 1);
323 if (NULL == reply) 329 if (NULL == reply)
324 return MHD_NO; 330 return MHD_NO;
325 snprintf (reply, 331 snprintf (reply,
326 slen + 1, 332 slen + 1,
327 MAIN_PAGE, 333 MAIN_PAGE,
328 session->value_1); 334 session->value_1);
329 /* return static form */ 335 /* return static form */
330 response = MHD_create_response_from_buffer (slen, 336 response = MHD_create_response_from_buffer (slen,
331 (void *) reply, 337 (void *) reply,
332 MHD_RESPMEM_MUST_FREE); 338 MHD_RESPMEM_MUST_FREE);
333 if (NULL == response) 339 if (NULL == response)
334 { 340 {
335 free (reply); 341 free (reply);
@@ -337,11 +343,11 @@ fill_v1_form (const void *cls,
337 } 343 }
338 add_session_cookie (session, response); 344 add_session_cookie (session, response);
339 MHD_add_response_header (response, 345 MHD_add_response_header (response,
340 MHD_HTTP_HEADER_CONTENT_ENCODING, 346 MHD_HTTP_HEADER_CONTENT_ENCODING,
341 mime); 347 mime);
342 ret = MHD_queue_response (connection, 348 ret = MHD_queue_response (connection,
343 MHD_HTTP_OK, 349 MHD_HTTP_OK,
344 response); 350 response);
345 MHD_destroy_response (response); 351 MHD_destroy_response (response);
346 return ret; 352 return ret;
347} 353}
@@ -357,29 +363,30 @@ fill_v1_form (const void *cls,
357 */ 363 */
358static int 364static int
359fill_v1_v2_form (const void *cls, 365fill_v1_v2_form (const void *cls,
360 const char *mime, 366 const char *mime,
361 struct Session *session, 367 struct Session *session,
362 struct MHD_Connection *connection) 368 struct MHD_Connection *connection)
363{ 369{
364 int ret; 370 int ret;
365 char *reply; 371 char *reply;
366 struct MHD_Response *response; 372 struct MHD_Response *response;
367 size_t slen; 373 size_t slen;
368 (void)cls; /* Unused. Silent compiler warning. */ 374 (void) cls; /* Unused. Silent compiler warning. */
369 375
370 slen = strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2); 376 slen = strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (
377 session->value_2);
371 reply = malloc (slen + 1); 378 reply = malloc (slen + 1);
372 if (NULL == reply) 379 if (NULL == reply)
373 return MHD_NO; 380 return MHD_NO;
374 snprintf (reply, 381 snprintf (reply,
375 slen + 1, 382 slen + 1,
376 SECOND_PAGE, 383 SECOND_PAGE,
377 session->value_1, 384 session->value_1,
378 session->value_2); 385 session->value_2);
379 /* return static form */ 386 /* return static form */
380 response = MHD_create_response_from_buffer (slen, 387 response = MHD_create_response_from_buffer (slen,
381 (void *) reply, 388 (void *) reply,
382 MHD_RESPMEM_MUST_FREE); 389 MHD_RESPMEM_MUST_FREE);
383 if (NULL == response) 390 if (NULL == response)
384 { 391 {
385 free (reply); 392 free (reply);
@@ -387,11 +394,11 @@ fill_v1_v2_form (const void *cls,
387 } 394 }
388 add_session_cookie (session, response); 395 add_session_cookie (session, response);
389 MHD_add_response_header (response, 396 MHD_add_response_header (response,
390 MHD_HTTP_HEADER_CONTENT_ENCODING, 397 MHD_HTTP_HEADER_CONTENT_ENCODING,
391 mime); 398 mime);
392 ret = MHD_queue_response (connection, 399 ret = MHD_queue_response (connection,
393 MHD_HTTP_OK, 400 MHD_HTTP_OK,
394 response); 401 response);
395 MHD_destroy_response (response); 402 MHD_destroy_response (response);
396 return ret; 403 return ret;
397} 404}
@@ -407,27 +414,27 @@ fill_v1_v2_form (const void *cls,
407 */ 414 */
408static int 415static int
409not_found_page (const void *cls, 416not_found_page (const void *cls,
410 const char *mime, 417 const char *mime,
411 struct Session *session, 418 struct Session *session,
412 struct MHD_Connection *connection) 419 struct MHD_Connection *connection)
413{ 420{
414 int ret; 421 int ret;
415 struct MHD_Response *response; 422 struct MHD_Response *response;
416 (void)cls; /* Unused. Silent compiler warning. */ 423 (void) cls; /* Unused. Silent compiler warning. */
417 (void)session; /* Unused. Silent compiler warning. */ 424 (void) session; /* Unused. Silent compiler warning. */
418 425
419 /* unsupported HTTP method */ 426 /* unsupported HTTP method */
420 response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR), 427 response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR),
421 (void *) NOT_FOUND_ERROR, 428 (void *) NOT_FOUND_ERROR,
422 MHD_RESPMEM_PERSISTENT); 429 MHD_RESPMEM_PERSISTENT);
423 if (NULL == response) 430 if (NULL == response)
424 return MHD_NO; 431 return MHD_NO;
425 ret = MHD_queue_response (connection, 432 ret = MHD_queue_response (connection,
426 MHD_HTTP_NOT_FOUND, 433 MHD_HTTP_NOT_FOUND,
427 response); 434 response);
428 MHD_add_response_header (response, 435 MHD_add_response_header (response,
429 MHD_HTTP_HEADER_CONTENT_ENCODING, 436 MHD_HTTP_HEADER_CONTENT_ENCODING,
430 mime); 437 mime);
431 MHD_destroy_response (response); 438 MHD_destroy_response (response);
432 return ret; 439 return ret;
433} 440}
@@ -436,14 +443,13 @@ not_found_page (const void *cls,
436/** 443/**
437 * List of all pages served by this HTTP server. 444 * List of all pages served by this HTTP server.
438 */ 445 */
439static struct Page pages[] = 446static struct Page pages[] = {
440 { 447 { "/", "text/html", &fill_v1_form, NULL },
441 { "/", "text/html", &fill_v1_form, NULL }, 448 { "/2", "text/html", &fill_v1_v2_form, NULL },
442 { "/2", "text/html", &fill_v1_v2_form, NULL }, 449 { "/S", "text/html", &serve_simple_form, SUBMIT_PAGE },
443 { "/S", "text/html", &serve_simple_form, SUBMIT_PAGE }, 450 { "/F", "text/html", &serve_simple_form, LAST_PAGE },
444 { "/F", "text/html", &serve_simple_form, LAST_PAGE }, 451 { NULL, NULL, &not_found_page, NULL } /* 404 */
445 { NULL, NULL, &not_found_page, NULL } /* 404 */ 452};
446 };
447 453
448 454
449 455
@@ -468,49 +474,49 @@ static struct Page pages[] =
468 */ 474 */
469static int 475static int
470post_iterator (void *cls, 476post_iterator (void *cls,
471 enum MHD_ValueKind kind, 477 enum MHD_ValueKind kind,
472 const char *key, 478 const char *key,
473 const char *filename, 479 const char *filename,
474 const char *content_type, 480 const char *content_type,
475 const char *transfer_encoding, 481 const char *transfer_encoding,
476 const char *data, uint64_t off, size_t size) 482 const char *data, uint64_t off, size_t size)
477{ 483{
478 struct Request *request = cls; 484 struct Request *request = cls;
479 struct Session *session = request->session; 485 struct Session *session = request->session;
480 (void)kind; /* Unused. Silent compiler warning. */ 486 (void) kind; /* Unused. Silent compiler warning. */
481 (void)filename; /* Unused. Silent compiler warning. */ 487 (void) filename; /* Unused. Silent compiler warning. */
482 (void)content_type; /* Unused. Silent compiler warning. */ 488 (void) content_type; /* Unused. Silent compiler warning. */
483 (void)transfer_encoding; /* Unused. Silent compiler warning. */ 489 (void) transfer_encoding; /* Unused. Silent compiler warning. */
484 490
485 if (0 == strcmp ("DONE", key)) 491 if (0 == strcmp ("DONE", key))
486 { 492 {
487 fprintf (stdout, 493 fprintf (stdout,
488 "Session `%s' submitted `%s', `%s'\n", 494 "Session `%s' submitted `%s', `%s'\n",
489 session->sid, 495 session->sid,
490 session->value_1, 496 session->value_1,
491 session->value_2); 497 session->value_2);
492 return MHD_YES; 498 return MHD_YES;
493 } 499 }
494 if (0 == strcmp ("v1", key)) 500 if (0 == strcmp ("v1", key))
495 { 501 {
496 if (size + off >= sizeof(session->value_1)) 502 if (size + off >= sizeof(session->value_1))
497 size = sizeof (session->value_1) - off - 1; 503 size = sizeof (session->value_1) - off - 1;
498 memcpy (&session->value_1[off], 504 memcpy (&session->value_1[off],
499 data, 505 data,
500 size); 506 size);
501 session->value_1[size+off] = '\0'; 507 session->value_1[size + off] = '\0';
502 return MHD_YES; 508 return MHD_YES;
503 } 509 }
504 if (0 == strcmp ("v2", key)) 510 if (0 == strcmp ("v2", key))
505 { 511 {
506 if (size + off >= sizeof(session->value_2)) 512 if (size + off >= sizeof(session->value_2))
507 size = sizeof (session->value_2) - off - 1; 513 size = sizeof (session->value_2) - off - 1;
508 memcpy (&session->value_2[off], 514 memcpy (&session->value_2[off],
509 data, 515 data,
510 size); 516 size);
511 session->value_2[size+off] = '\0'; 517 session->value_2[size + off] = '\0';
512 return MHD_YES; 518 return MHD_YES;
513 } 519 }
514 fprintf (stderr, 520 fprintf (stderr,
515 "Unsupported form value `%s'\n", 521 "Unsupported form value `%s'\n",
516 key); 522 key);
@@ -553,99 +559,99 @@ post_iterator (void *cls,
553 */ 559 */
554static int 560static int
555create_response (void *cls, 561create_response (void *cls,
556 struct MHD_Connection *connection, 562 struct MHD_Connection *connection,
557 const char *url, 563 const char *url,
558 const char *method, 564 const char *method,
559 const char *version, 565 const char *version,
560 const char *upload_data, 566 const char *upload_data,
561 size_t *upload_data_size, 567 size_t *upload_data_size,
562 void **ptr) 568 void **ptr)
563{ 569{
564 struct MHD_Response *response; 570 struct MHD_Response *response;
565 struct Request *request; 571 struct Request *request;
566 struct Session *session; 572 struct Session *session;
567 int ret; 573 int ret;
568 unsigned int i; 574 unsigned int i;
569 (void)cls; /* Unused. Silent compiler warning. */ 575 (void) cls; /* Unused. Silent compiler warning. */
570 (void)version; /* Unused. Silent compiler warning. */ 576 (void) version; /* Unused. Silent compiler warning. */
571 577
572 request = *ptr; 578 request = *ptr;
573 if (NULL == request) 579 if (NULL == request)
580 {
581 request = calloc (1, sizeof (struct Request));
582 if (NULL == request)
574 { 583 {
575 request = calloc (1, sizeof (struct Request)); 584 fprintf (stderr, "calloc error: %s\n", strerror (errno));
576 if (NULL == request) 585 return MHD_NO;
577 {
578 fprintf (stderr, "calloc error: %s\n", strerror (errno));
579 return MHD_NO;
580 }
581 *ptr = request;
582 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
583 {
584 request->pp = MHD_create_post_processor (connection, 1024,
585 &post_iterator, request);
586 if (NULL == request->pp)
587 {
588 fprintf (stderr, "Failed to setup post processor for `%s'\n",
589 url);
590 return MHD_NO; /* internal error */
591 }
592 }
593 return MHD_YES;
594 } 586 }
587 *ptr = request;
588 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
589 {
590 request->pp = MHD_create_post_processor (connection, 1024,
591 &post_iterator, request);
592 if (NULL == request->pp)
593 {
594 fprintf (stderr, "Failed to setup post processor for `%s'\n",
595 url);
596 return MHD_NO; /* internal error */
597 }
598 }
599 return MHD_YES;
600 }
595 if (NULL == request->session) 601 if (NULL == request->session)
602 {
603 request->session = get_session (connection);
604 if (NULL == request->session)
596 { 605 {
597 request->session = get_session (connection); 606 fprintf (stderr, "Failed to setup session for `%s'\n",
598 if (NULL == request->session) 607 url);
599 { 608 return MHD_NO; /* internal error */
600 fprintf (stderr, "Failed to setup session for `%s'\n",
601 url);
602 return MHD_NO; /* internal error */
603 }
604 } 609 }
610 }
605 session = request->session; 611 session = request->session;
606 session->start = time (NULL); 612 session->start = time (NULL);
607 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 613 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
614 {
615 /* evaluate POST data */
616 MHD_post_process (request->pp,
617 upload_data,
618 *upload_data_size);
619 if (0 != *upload_data_size)
608 { 620 {
609 /* evaluate POST data */ 621 *upload_data_size = 0;
610 MHD_post_process (request->pp, 622 return MHD_YES;
611 upload_data,
612 *upload_data_size);
613 if (0 != *upload_data_size)
614 {
615 *upload_data_size = 0;
616 return MHD_YES;
617 }
618 /* done with POST data, serve response */
619 MHD_destroy_post_processor (request->pp);
620 request->pp = NULL;
621 method = MHD_HTTP_METHOD_GET; /* fake 'GET' */
622 if (NULL != request->post_url)
623 url = request->post_url;
624 } 623 }
624 /* done with POST data, serve response */
625 MHD_destroy_post_processor (request->pp);
626 request->pp = NULL;
627 method = MHD_HTTP_METHOD_GET; /* fake 'GET' */
628 if (NULL != request->post_url)
629 url = request->post_url;
630 }
625 631
626 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || 632 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
627 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 633 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) )
628 { 634 {
629 /* find out which page to serve */ 635 /* find out which page to serve */
630 i=0; 636 i = 0;
631 while ( (pages[i].url != NULL) && 637 while ( (pages[i].url != NULL) &&
632 (0 != strcmp (pages[i].url, url)) ) 638 (0 != strcmp (pages[i].url, url)) )
633 i++; 639 i++;
634 ret = pages[i].handler (pages[i].handler_cls, 640 ret = pages[i].handler (pages[i].handler_cls,
635 pages[i].mime, 641 pages[i].mime,
636 session, connection); 642 session, connection);
637 if (ret != MHD_YES) 643 if (ret != MHD_YES)
638 fprintf (stderr, "Failed to create page for `%s'\n", 644 fprintf (stderr, "Failed to create page for `%s'\n",
639 url); 645 url);
640 return ret; 646 return ret;
641 } 647 }
642 /* unsupported HTTP method */ 648 /* unsupported HTTP method */
643 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), 649 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
644 (void *) METHOD_ERROR, 650 (void *) METHOD_ERROR,
645 MHD_RESPMEM_PERSISTENT); 651 MHD_RESPMEM_PERSISTENT);
646 ret = MHD_queue_response (connection, 652 ret = MHD_queue_response (connection,
647 MHD_HTTP_NOT_ACCEPTABLE, 653 MHD_HTTP_NOT_ACCEPTABLE,
648 response); 654 response);
649 MHD_destroy_response (response); 655 MHD_destroy_response (response);
650 return ret; 656 return ret;
651} 657}
@@ -662,14 +668,14 @@ create_response (void *cls,
662 */ 668 */
663static void 669static void
664request_completed_callback (void *cls, 670request_completed_callback (void *cls,
665 struct MHD_Connection *connection, 671 struct MHD_Connection *connection,
666 void **con_cls, 672 void **con_cls,
667 enum MHD_RequestTerminationCode toe) 673 enum MHD_RequestTerminationCode toe)
668{ 674{
669 struct Request *request = *con_cls; 675 struct Request *request = *con_cls;
670 (void)cls; /* Unused. Silent compiler warning. */ 676 (void) cls; /* Unused. Silent compiler warning. */
671 (void)connection; /* Unused. Silent compiler warning. */ 677 (void) connection; /* Unused. Silent compiler warning. */
672 (void)toe; /* Unused. Silent compiler warning. */ 678 (void) toe; /* Unused. Silent compiler warning. */
673 679
674 if (NULL == request) 680 if (NULL == request)
675 return; 681 return;
@@ -697,21 +703,21 @@ expire_sessions ()
697 prev = NULL; 703 prev = NULL;
698 pos = sessions; 704 pos = sessions;
699 while (NULL != pos) 705 while (NULL != pos)
706 {
707 next = pos->next;
708 if (now - pos->start > 60 * 60)
700 { 709 {
701 next = pos->next; 710 /* expire sessions after 1h */
702 if (now - pos->start > 60 * 60) 711 if (NULL == prev)
703 { 712 sessions = pos->next;
704 /* expire sessions after 1h */
705 if (NULL == prev)
706 sessions = pos->next;
707 else
708 prev->next = next;
709 free (pos);
710 }
711 else 713 else
712 prev = pos; 714 prev->next = next;
713 pos = next; 715 free (pos);
714 } 716 }
717 else
718 prev = pos;
719 pos = next;
720 }
715} 721}
716 722
717 723
@@ -732,45 +738,46 @@ main (int argc, char *const *argv)
732 MHD_UNSIGNED_LONG_LONG mhd_timeout; 738 MHD_UNSIGNED_LONG_LONG mhd_timeout;
733 739
734 if (argc != 2) 740 if (argc != 2)
735 { 741 {
736 printf ("%s PORT\n", argv[0]); 742 printf ("%s PORT\n", argv[0]);
737 return 1; 743 return 1;
738 } 744 }
739 /* initialize PRNG */ 745 /* initialize PRNG */
740 srand ((unsigned int) time (NULL)); 746 srand ((unsigned int) time (NULL));
741 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 747 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
742 atoi (argv[1]), 748 atoi (argv[1]),
743 NULL, NULL, 749 NULL, NULL,
744 &create_response, NULL, 750 &create_response, NULL,
745 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, 751 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
746 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, 752 MHD_OPTION_NOTIFY_COMPLETED,
747 MHD_OPTION_END); 753 &request_completed_callback, NULL,
754 MHD_OPTION_END);
748 if (NULL == d) 755 if (NULL == d)
749 return 1; 756 return 1;
750 while (1) 757 while (1)
758 {
759 expire_sessions ();
760 max = 0;
761 FD_ZERO (&rs);
762 FD_ZERO (&ws);
763 FD_ZERO (&es);
764 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
765 break; /* fatal internal error */
766 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
751 { 767 {
752 expire_sessions (); 768 tv.tv_sec = mhd_timeout / 1000;
753 max = 0; 769 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
754 FD_ZERO (&rs); 770 tvp = &tv;
755 FD_ZERO (&ws);
756 FD_ZERO (&es);
757 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
758 break; /* fatal internal error */
759 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
760 {
761 tv.tv_sec = mhd_timeout / 1000;
762 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
763 tvp = &tv;
764 }
765 else
766 tvp = NULL;
767 if (-1 == select (max + 1, &rs, &ws, &es, tvp))
768 {
769 if (EINTR != errno)
770 abort ();
771 }
772 MHD_run (d);
773 } 771 }
772 else
773 tvp = NULL;
774 if (-1 == select (max + 1, &rs, &ws, &es, tvp))
775 {
776 if (EINTR != errno)
777 abort ();
778 }
779 MHD_run (d);
780 }
774 MHD_stop_daemon (d); 781 MHD_stop_daemon (d);
775 return 0; 782 return 0;
776} 783}
diff --git a/src/examples/querystring_example.c b/src/examples/querystring_example.c
index db0d6f1a..a8f0f572 100644
--- a/src/examples/querystring_example.c
+++ b/src/examples/querystring_example.c
@@ -26,7 +26,8 @@
26#include "platform.h" 26#include "platform.h"
27#include <microhttpd.h> 27#include <microhttpd.h>
28 28
29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Query string for &quot;%s&quot; was &quot;%s&quot;</body></html>" 29#define PAGE \
30 "<html><head><title>libmicrohttpd demo</title></head><body>Query string for &quot;%s&quot; was &quot;%s&quot;</body></html>"
30 31
31static int 32static int
32ahc_echo (void *cls, 33ahc_echo (void *cls,
@@ -42,19 +43,19 @@ ahc_echo (void *cls,
42 char *me; 43 char *me;
43 struct MHD_Response *response; 44 struct MHD_Response *response;
44 int ret; 45 int ret;
45 (void)url; /* Unused. Silent compiler warning. */ 46 (void) url; /* Unused. Silent compiler warning. */
46 (void)version; /* Unused. Silent compiler warning. */ 47 (void) version; /* Unused. Silent compiler warning. */
47 (void)upload_data; /* Unused. Silent compiler warning. */ 48 (void) upload_data; /* Unused. Silent compiler warning. */
48 (void)upload_data_size; /* Unused. Silent compiler warning. */ 49 (void) upload_data_size; /* Unused. Silent compiler warning. */
49 50
50 if (0 != strcmp (method, "GET")) 51 if (0 != strcmp (method, "GET"))
51 return MHD_NO; /* unexpected method */ 52 return MHD_NO; /* unexpected method */
52 if (&aptr != *ptr) 53 if (&aptr != *ptr)
53 { 54 {
54 /* do never respond on first call */ 55 /* do never respond on first call */
55 *ptr = &aptr; 56 *ptr = &aptr;
56 return MHD_YES; 57 return MHD_YES;
57 } 58 }
58 *ptr = NULL; /* reset when done */ 59 *ptr = NULL; /* reset when done */
59 val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "q"); 60 val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "q");
60 me = malloc (snprintf (NULL, 0, fmt, "q", val) + 1); 61 me = malloc (snprintf (NULL, 0, fmt, "q", val) + 1);
@@ -62,12 +63,12 @@ ahc_echo (void *cls,
62 return MHD_NO; 63 return MHD_NO;
63 sprintf (me, fmt, "q", val); 64 sprintf (me, fmt, "q", val);
64 response = MHD_create_response_from_buffer (strlen (me), me, 65 response = MHD_create_response_from_buffer (strlen (me), me,
65 MHD_RESPMEM_MUST_FREE); 66 MHD_RESPMEM_MUST_FREE);
66 if (response == NULL) 67 if (response == NULL)
67 { 68 {
68 free (me); 69 free (me);
69 return MHD_NO; 70 return MHD_NO;
70 } 71 }
71 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 72 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
72 MHD_destroy_response (response); 73 MHD_destroy_response (response);
73 return ret; 74 return ret;
@@ -80,18 +81,19 @@ main (int argc, char *const *argv)
80 int port; 81 int port;
81 82
82 if (argc != 2) 83 if (argc != 2)
83 { 84 {
84 printf ("%s PORT\n", argv[0]); 85 printf ("%s PORT\n", argv[0]);
85 return 1; 86 return 1;
86 } 87 }
87 port = atoi (argv[1]); 88 port = atoi (argv[1]);
88 if ( (port < 0) || 89 if ( (port < 0) ||
89 (port > UINT16_MAX) ) 90 (port > UINT16_MAX) )
90 { 91 {
91 printf ("%s PORT\n", argv[0]); 92 printf ("%s PORT\n", argv[0]);
92 return 1; 93 return 1;
93 } 94 }
94 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 95 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
96 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
95 (uint16_t) port, 97 (uint16_t) port,
96 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); 98 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
97 if (NULL == d) 99 if (NULL == d)
diff --git a/src/examples/refuse_post_example.c b/src/examples/refuse_post_example.c
index dad3beb1..9241ce43 100644
--- a/src/examples/refuse_post_example.c
+++ b/src/examples/refuse_post_example.c
@@ -24,14 +24,16 @@
24#include "platform.h" 24#include "platform.h"
25#include <microhttpd.h> 25#include <microhttpd.h>
26 26
27const char *askpage = "<html><body>\n\ 27const char *askpage =
28 "<html><body>\n\
28 Upload a file, please!<br>\n\ 29 Upload a file, please!<br>\n\
29 <form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\ 30 <form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\
30 <input name=\"file\" type=\"file\">\n\ 31 <input name=\"file\" type=\"file\">\n\
31 <input type=\"submit\" value=\" Send \"></form>\n\ 32 <input type=\"submit\" value=\" Send \"></form>\n\
32 </body></html>"; 33 </body></html>";
33 34
34#define BUSYPAGE "<html><head><title>Webserver busy</title></head><body>We are too busy to process POSTs right now.</body></html>" 35#define BUSYPAGE \
36 "<html><head><title>Webserver busy</title></head><body>We are too busy to process POSTs right now.</body></html>"
35 37
36static int 38static int
37ahc_echo (void *cls, 39ahc_echo (void *cls,
@@ -45,37 +47,37 @@ ahc_echo (void *cls,
45 const char *me = cls; 47 const char *me = cls;
46 struct MHD_Response *response; 48 struct MHD_Response *response;
47 int ret; 49 int ret;
48 (void)cls; /* Unused. Silent compiler warning. */ 50 (void) cls; /* Unused. Silent compiler warning. */
49 (void)url; /* Unused. Silent compiler warning. */ 51 (void) url; /* Unused. Silent compiler warning. */
50 (void)version; /* Unused. Silent compiler warning. */ 52 (void) version; /* Unused. Silent compiler warning. */
51 (void)upload_data; /* Unused. Silent compiler warning. */ 53 (void) upload_data; /* Unused. Silent compiler warning. */
52 (void)upload_data_size; /* Unused. Silent compiler warning. */ 54 (void) upload_data_size; /* Unused. Silent compiler warning. */
53 55
54 if ((0 != strcmp (method, "GET")) && (0 != strcmp (method, "POST"))) 56 if ((0 != strcmp (method, "GET")) && (0 != strcmp (method, "POST")))
55 return MHD_NO; /* unexpected method */ 57 return MHD_NO; /* unexpected method */
56 58
57 if (&aptr != *ptr) 59 if (&aptr != *ptr)
58 { 60 {
59 *ptr = &aptr; 61 *ptr = &aptr;
60 62
61 /* always to busy for POST requests */ 63 /* always to busy for POST requests */
62 if (0 == strcmp (method, "POST")) 64 if (0 == strcmp (method, "POST"))
63 { 65 {
64 response = MHD_create_response_from_buffer (strlen (BUSYPAGE), 66 response = MHD_create_response_from_buffer (strlen (BUSYPAGE),
65 (void *) BUSYPAGE, 67 (void *) BUSYPAGE,
66 MHD_RESPMEM_PERSISTENT); 68 MHD_RESPMEM_PERSISTENT);
67 ret = 69 ret =
68 MHD_queue_response (connection, MHD_HTTP_SERVICE_UNAVAILABLE, 70 MHD_queue_response (connection, MHD_HTTP_SERVICE_UNAVAILABLE,
69 response); 71 response);
70 MHD_destroy_response (response); 72 MHD_destroy_response (response);
71 return ret; 73 return ret;
72 }
73 } 74 }
75 }
74 76
75 *ptr = NULL; /* reset when done */ 77 *ptr = NULL; /* reset when done */
76 response = MHD_create_response_from_buffer (strlen (me), 78 response = MHD_create_response_from_buffer (strlen (me),
77 (void *) me, 79 (void *) me,
78 MHD_RESPMEM_PERSISTENT); 80 MHD_RESPMEM_PERSISTENT);
79 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 81 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
80 MHD_destroy_response (response); 82 MHD_destroy_response (response);
81 return ret; 83 return ret;
@@ -87,11 +89,12 @@ main (int argc, char *const *argv)
87 struct MHD_Daemon *d; 89 struct MHD_Daemon *d;
88 90
89 if (argc != 2) 91 if (argc != 2)
90 { 92 {
91 printf ("%s PORT\n", argv[0]); 93 printf ("%s PORT\n", argv[0]);
92 return 1; 94 return 1;
93 } 95 }
94 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 96 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
97 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
95 atoi (argv[1]), 98 atoi (argv[1]),
96 NULL, NULL, &ahc_echo, (void *) askpage, 99 NULL, NULL, &ahc_echo, (void *) askpage,
97 MHD_OPTION_END); 100 MHD_OPTION_END);
diff --git a/src/examples/suspend_resume_epoll.c b/src/examples/suspend_resume_epoll.c
index 3e0be24c..a69fdc4a 100644
--- a/src/examples/suspend_resume_epoll.c
+++ b/src/examples/suspend_resume_epoll.c
@@ -31,7 +31,8 @@
31 31
32#define TIMEOUT_INFINITE -1 32#define TIMEOUT_INFINITE -1
33 33
34struct Request { 34struct Request
35{
35 struct MHD_Connection *connection; 36 struct MHD_Connection *connection;
36 int timerfd; 37 int timerfd;
37}; 38};
@@ -52,7 +53,7 @@ ahc_echo (void *cls,
52{ 53{
53 struct MHD_Response *response; 54 struct MHD_Response *response;
54 int ret; 55 int ret;
55 struct Request* req; 56 struct Request*req;
56 struct itimerspec ts; 57 struct itimerspec ts;
57 58
58 (void) cls; 59 (void) cls;
@@ -89,29 +90,29 @@ ahc_echo (void *cls,
89 return ret; 90 return ret;
90 } 91 }
91 /* create timer and suspend connection */ 92 /* create timer and suspend connection */
92 req->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); 93 req->timerfd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK);
93 if (-1 == req->timerfd) 94 if (-1 == req->timerfd)
94 { 95 {
95 printf("timerfd_create: %s", strerror(errno)); 96 printf ("timerfd_create: %s", strerror (errno));
96 return MHD_NO; 97 return MHD_NO;
97 } 98 }
98 evt.events = EPOLLIN; 99 evt.events = EPOLLIN;
99 evt.data.ptr = req; 100 evt.data.ptr = req;
100 if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, req->timerfd, &evt)) 101 if (-1 == epoll_ctl (epfd, EPOLL_CTL_ADD, req->timerfd, &evt))
101 { 102 {
102 printf("epoll_ctl: %s", strerror(errno)); 103 printf ("epoll_ctl: %s", strerror (errno));
103 return MHD_NO; 104 return MHD_NO;
104 } 105 }
105 ts.it_value.tv_sec = 1; 106 ts.it_value.tv_sec = 1;
106 ts.it_value.tv_nsec = 0; 107 ts.it_value.tv_nsec = 0;
107 ts.it_interval.tv_sec = 0; 108 ts.it_interval.tv_sec = 0;
108 ts.it_interval.tv_nsec = 0; 109 ts.it_interval.tv_nsec = 0;
109 if (-1 == timerfd_settime(req->timerfd, 0, &ts, NULL)) 110 if (-1 == timerfd_settime (req->timerfd, 0, &ts, NULL))
110 { 111 {
111 printf("timerfd_settime: %s", strerror(errno)); 112 printf ("timerfd_settime: %s", strerror (errno));
112 return MHD_NO; 113 return MHD_NO;
113 } 114 }
114 MHD_suspend_connection(connection); 115 MHD_suspend_connection (connection);
115 return MHD_YES; 116 return MHD_YES;
116} 117}
117 118
@@ -130,7 +131,7 @@ connection_done (void *cls,
130 if (-1 != req->timerfd) 131 if (-1 != req->timerfd)
131 if (0 != close (req->timerfd)) 132 if (0 != close (req->timerfd))
132 abort (); 133 abort ();
133 free(req); 134 free (req);
134} 135}
135 136
136 137
@@ -139,17 +140,17 @@ main (int argc,
139 char *const *argv) 140 char *const *argv)
140{ 141{
141 struct MHD_Daemon *d; 142 struct MHD_Daemon *d;
142 const union MHD_DaemonInfo * info; 143 const union MHD_DaemonInfo *info;
143 int current_event_count; 144 int current_event_count;
144 struct epoll_event events_list[1]; 145 struct epoll_event events_list[1];
145 struct Request *req; 146 struct Request *req;
146 uint64_t timer_expirations; 147 uint64_t timer_expirations;
147 148
148 if (argc != 2) 149 if (argc != 2)
149 { 150 {
150 printf ("%s PORT\n", argv[0]); 151 printf ("%s PORT\n", argv[0]);
151 return 1; 152 return 1;
152 } 153 }
153 d = MHD_start_daemon (MHD_USE_EPOLL | MHD_ALLOW_SUSPEND_RESUME, 154 d = MHD_start_daemon (MHD_USE_EPOLL | MHD_ALLOW_SUSPEND_RESUME,
154 atoi (argv[1]), 155 atoi (argv[1]),
155 NULL, NULL, &ahc_echo, NULL, 156 NULL, NULL, &ahc_echo, NULL,
@@ -158,17 +159,17 @@ main (int argc,
158 if (d == NULL) 159 if (d == NULL)
159 return 1; 160 return 1;
160 161
161 info = MHD_get_daemon_info(d, MHD_DAEMON_INFO_EPOLL_FD); 162 info = MHD_get_daemon_info (d, MHD_DAEMON_INFO_EPOLL_FD);
162 if (info == NULL) 163 if (info == NULL)
163 return 1; 164 return 1;
164 165
165 epfd = epoll_create1(EPOLL_CLOEXEC); 166 epfd = epoll_create1 (EPOLL_CLOEXEC);
166 if (-1 == epfd) 167 if (-1 == epfd)
167 return 1; 168 return 1;
168 169
169 evt.events = EPOLLIN; 170 evt.events = EPOLLIN;
170 evt.data.ptr = NULL; 171 evt.data.ptr = NULL;
171 if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, info->epoll_fd, &evt)) 172 if (-1 == epoll_ctl (epfd, EPOLL_CTL_ADD, info->epoll_fd, &evt))
172 return 1; 173 return 1;
173 174
174 while (1) 175 while (1)
@@ -182,7 +183,7 @@ main (int argc,
182 timeout = TIMEOUT_INFINITE; 183 timeout = TIMEOUT_INFINITE;
183 else 184 else
184 timeout = (to < INT_MAX - 1) ? (int) to : (INT_MAX - 1); 185 timeout = (to < INT_MAX - 1) ? (int) to : (INT_MAX - 1);
185 current_event_count = epoll_wait(epfd, events_list, 1, timeout); 186 current_event_count = epoll_wait (epfd, events_list, 1, timeout);
186 187
187 if (1 == current_event_count) 188 if (1 == current_event_count)
188 { 189 {
@@ -191,12 +192,13 @@ main (int argc,
191 /* A timer has timed out */ 192 /* A timer has timed out */
192 req = events_list[0].data.ptr; 193 req = events_list[0].data.ptr;
193 /* read from the fd so the system knows we heard the notice */ 194 /* read from the fd so the system knows we heard the notice */
194 if (-1 == read(req->timerfd, &timer_expirations, sizeof(timer_expirations))) 195 if (-1 == read (req->timerfd, &timer_expirations,
196 sizeof(timer_expirations)))
195 { 197 {
196 return 1; 198 return 1;
197 } 199 }
198 /* Now resume the connection */ 200 /* Now resume the connection */
199 MHD_resume_connection(req->connection); 201 MHD_resume_connection (req->connection);
200 } 202 }
201 } 203 }
202 else if (0 == current_event_count) 204 else if (0 == current_event_count)
@@ -208,7 +210,7 @@ main (int argc,
208 /* error */ 210 /* error */
209 return 1; 211 return 1;
210 } 212 }
211 if (! MHD_run(d)) 213 if (! MHD_run (d))
212 return 1; 214 return 1;
213 } 215 }
214 216
diff --git a/src/examples/timeout.c b/src/examples/timeout.c
index 91de1599..cfb66950 100644
--- a/src/examples/timeout.c
+++ b/src/examples/timeout.c
@@ -30,27 +30,27 @@
30#define PORT 8080 30#define PORT 8080
31 31
32static int 32static int
33answer_to_connection(void *cls, 33answer_to_connection (void *cls,
34 struct MHD_Connection *connection, 34 struct MHD_Connection *connection,
35 const char *url, 35 const char *url,
36 const char *method, 36 const char *method,
37 const char *version, 37 const char *version,
38 const char *upload_data, 38 const char *upload_data,
39 size_t *upload_data_size, 39 size_t *upload_data_size,
40 void **con_cls) 40 void **con_cls)
41{ 41{
42 const char *page = "<html><body>Hello timeout!</body></html>"; 42 const char *page = "<html><body>Hello timeout!</body></html>";
43 struct MHD_Response *response; 43 struct MHD_Response *response;
44 int ret; 44 int ret;
45 (void)cls; /* Unused. Silent compiler warning. */ 45 (void) cls; /* Unused. Silent compiler warning. */
46 (void)url; /* Unused. Silent compiler warning. */ 46 (void) url; /* Unused. Silent compiler warning. */
47 (void)version; /* Unused. Silent compiler warning. */ 47 (void) version; /* Unused. Silent compiler warning. */
48 (void)method; /* Unused. Silent compiler warning. */ 48 (void) method; /* Unused. Silent compiler warning. */
49 (void)upload_data; /* Unused. Silent compiler warning. */ 49 (void) upload_data; /* Unused. Silent compiler warning. */
50 (void)upload_data_size; /* Unused. Silent compiler warning. */ 50 (void) upload_data_size; /* Unused. Silent compiler warning. */
51 (void)con_cls; /* Unused. Silent compiler warning. */ 51 (void) con_cls; /* Unused. Silent compiler warning. */
52 52
53 response = MHD_create_response_from_buffer (strlen(page), 53 response = MHD_create_response_from_buffer (strlen (page),
54 (void *) page, 54 (void *) page,
55 MHD_RESPMEM_PERSISTENT); 55 MHD_RESPMEM_PERSISTENT);
56 MHD_add_response_header (response, 56 MHD_add_response_header (response,
@@ -59,7 +59,7 @@ answer_to_connection(void *cls,
59 ret = MHD_queue_response (connection, 59 ret = MHD_queue_response (connection,
60 MHD_HTTP_OK, 60 MHD_HTTP_OK,
61 response); 61 response);
62 MHD_destroy_response(response); 62 MHD_destroy_response (response);
63 return ret; 63 return ret;
64} 64}
65 65
@@ -69,7 +69,8 @@ main (void)
69{ 69{
70 struct MHD_Daemon *daemon; 70 struct MHD_Daemon *daemon;
71 71
72 daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 72 daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
73 | MHD_USE_INTERNAL_POLLING_THREAD,
73 PORT, 74 PORT,
74 NULL, NULL, 75 NULL, NULL,
75 &answer_to_connection, NULL, 76 &answer_to_connection, NULL,
@@ -78,7 +79,7 @@ main (void)
78 MHD_OPTION_END); 79 MHD_OPTION_END);
79 if (NULL == daemon) 80 if (NULL == daemon)
80 return 1; 81 return 1;
81 (void) getchar(); 82 (void) getchar ();
82 MHD_stop_daemon (daemon); 83 MHD_stop_daemon (daemon);
83 return 0; 84 return 0;
84} 85}
diff --git a/src/examples/upgrade_example.c b/src/examples/upgrade_example.c
index 35761c97..98675e09 100644
--- a/src/examples/upgrade_example.c
+++ b/src/examples/upgrade_example.c
@@ -32,7 +32,8 @@
32#include <microhttpd.h> 32#include <microhttpd.h>
33#include <pthread.h> 33#include <pthread.h>
34 34
35#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 35#define PAGE \
36 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
36 37
37 38
38/** 39/**
@@ -72,23 +73,23 @@ send_all (MHD_socket sock,
72 73
73 make_blocking (sock); 74 make_blocking (sock);
74 for (off = 0; off < len; off += ret) 75 for (off = 0; off < len; off += ret)
76 {
77 ret = send (sock,
78 &buf[off],
79 len - off,
80 0);
81 if (0 > ret)
75 { 82 {
76 ret = send (sock, 83 if (EAGAIN == errno)
77 &buf[off], 84 {
78 len - off, 85 ret = 0;
79 0); 86 continue;
80 if (0 > ret) 87 }
81 { 88 break;
82 if (EAGAIN == errno)
83 {
84 ret = 0;
85 continue;
86 }
87 break;
88 }
89 if (0 == ret)
90 break;
91 } 89 }
90 if (0 == ret)
91 break;
92 }
92} 93}
93 94
94 95
@@ -118,25 +119,25 @@ run_usock (void *cls)
118 make_blocking (md->sock); 119 make_blocking (md->sock);
119 /* start by sending extra data MHD may have already read, if any */ 120 /* start by sending extra data MHD may have already read, if any */
120 if (0 != md->extra_in_size) 121 if (0 != md->extra_in_size)
121 { 122 {
122 send_all (md->sock, 123 send_all (md->sock,
123 md->extra_in, 124 md->extra_in,
124 md->extra_in_size); 125 md->extra_in_size);
125 free (md->extra_in); 126 free (md->extra_in);
126 } 127 }
127 /* now echo in a loop */ 128 /* now echo in a loop */
128 while (1) 129 while (1)
129 { 130 {
130 got = recv (md->sock, 131 got = recv (md->sock,
131 buf,
132 sizeof (buf),
133 0);
134 if (0 >= got)
135 break;
136 send_all (md->sock,
137 buf, 132 buf,
138 got); 133 sizeof (buf),
139 } 134 0);
135 if (0 >= got)
136 break;
137 send_all (md->sock,
138 buf,
139 got);
140 }
140 free (md); 141 free (md);
141 MHD_upgrade_action (urh, 142 MHD_upgrade_action (urh,
142 MHD_UPGRADE_ACTION_CLOSE); 143 MHD_UPGRADE_ACTION_CLOSE);
@@ -202,23 +203,23 @@ uh_cb (void *cls,
202{ 203{
203 struct MyData *md; 204 struct MyData *md;
204 pthread_t pt; 205 pthread_t pt;
205 (void)cls; /* Unused. Silent compiler warning. */ 206 (void) cls; /* Unused. Silent compiler warning. */
206 (void)connection; /* Unused. Silent compiler warning. */ 207 (void) connection; /* Unused. Silent compiler warning. */
207 (void)con_cls; /* Unused. Silent compiler warning. */ 208 (void) con_cls; /* Unused. Silent compiler warning. */
208 209
209 md = malloc (sizeof (struct MyData)); 210 md = malloc (sizeof (struct MyData));
210 if (NULL == md) 211 if (NULL == md)
211 abort (); 212 abort ();
212 memset (md, 0, sizeof (struct MyData)); 213 memset (md, 0, sizeof (struct MyData));
213 if (0 != extra_in_size) 214 if (0 != extra_in_size)
214 { 215 {
215 md->extra_in = malloc (extra_in_size); 216 md->extra_in = malloc (extra_in_size);
216 if (NULL == md->extra_in) 217 if (NULL == md->extra_in)
217 abort (); 218 abort ();
218 memcpy (md->extra_in, 219 memcpy (md->extra_in,
219 extra_in, 220 extra_in,
220 extra_in_size); 221 extra_in_size);
221 } 222 }
222 md->extra_in_size = extra_in_size; 223 md->extra_in_size = extra_in_size;
223 md->sock = sock; 224 md->sock = sock;
224 md->urh = urh; 225 md->urh = urh;
@@ -252,20 +253,20 @@ ahc_echo (void *cls,
252 static int aptr; 253 static int aptr;
253 struct MHD_Response *response; 254 struct MHD_Response *response;
254 int ret; 255 int ret;
255 (void)cls; /* Unused. Silent compiler warning. */ 256 (void) cls; /* Unused. Silent compiler warning. */
256 (void)url; /* Unused. Silent compiler warning. */ 257 (void) url; /* Unused. Silent compiler warning. */
257 (void)version; /* Unused. Silent compiler warning. */ 258 (void) version; /* Unused. Silent compiler warning. */
258 (void)upload_data; /* Unused. Silent compiler warning. */ 259 (void) upload_data; /* Unused. Silent compiler warning. */
259 (void)upload_data_size; /* Unused. Silent compiler warning. */ 260 (void) upload_data_size; /* Unused. Silent compiler warning. */
260 261
261 if (0 != strcmp (method, "GET")) 262 if (0 != strcmp (method, "GET"))
262 return MHD_NO; /* unexpected method */ 263 return MHD_NO; /* unexpected method */
263 if (&aptr != *ptr) 264 if (&aptr != *ptr)
264 { 265 {
265 /* do never respond on first call */ 266 /* do never respond on first call */
266 *ptr = &aptr; 267 *ptr = &aptr;
267 return MHD_YES; 268 return MHD_YES;
268 } 269 }
269 *ptr = NULL; /* reset when done */ 270 *ptr = NULL; /* reset when done */
270 response = MHD_create_response_for_upgrade (&uh_cb, 271 response = MHD_create_response_for_upgrade (&uh_cb,
271 NULL); 272 NULL);
@@ -288,11 +289,12 @@ main (int argc,
288 struct MHD_Daemon *d; 289 struct MHD_Daemon *d;
289 290
290 if (argc != 2) 291 if (argc != 2)
291 { 292 {
292 printf ("%s PORT\n", argv[0]); 293 printf ("%s PORT\n", argv[0]);
293 return 1; 294 return 1;
294 } 295 }
295 d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 296 d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO
297 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
296 atoi (argv[1]), 298 atoi (argv[1]),
297 NULL, NULL, 299 NULL, NULL,
298 &ahc_echo, NULL, 300 &ahc_echo, NULL,
diff --git a/src/gnutls/check_record_pending.c b/src/gnutls/check_record_pending.c
index e688f2b7..2069ca0a 100644
--- a/src/gnutls/check_record_pending.c
+++ b/src/gnutls/check_record_pending.c
@@ -1,6 +1,6 @@
1 enum MHD_Bool 1enum MHD_Bool
2 (*check_record_pending)(void *cls, 2(*check_record_pending)(void *cls,
3 struct MHD_TLS_ConnectionState *cs); 3 struct MHD_TLS_ConnectionState *cs);
4 4
5see: 5see:
6gnutls_record_check_pending (connection->tls_session) 6gnutls_record_check_pending (connection->tls_session)
diff --git a/src/gnutls/handshake.c b/src/gnutls/handshake.c
index 259056df..8970ad8a 100644
--- a/src/gnutls/handshake.c
+++ b/src/gnutls/handshake.c
@@ -1,15 +1,15 @@
1 enum MHD_Bool 1enum MHD_Bool
2 (*handshake)(void *cls, 2(*handshake)(void *cls,
3 struct MHD_TLS_ConnectionState *cs): 3 struct MHD_TLS_ConnectionState *cs) :
4 4
5 5
6 6
7 if (MHD_TLS_CONN_NO_TLS != connection->tls_state) 7 if (MHD_TLS_CONN_NO_TLS != connection->tls_state)
8 { /* HTTPS connection. */ 8{ /* HTTPS connection. */
9 if (MHD_TLS_CONN_CONNECTED > connection->tls_state) 9 if (MHD_TLS_CONN_CONNECTED > connection->tls_state)
10 { 10 {
11 if (! MHD_run_tls_handshake_ (connection)) 11 if (! MHD_run_tls_handshake_ (connection))
12 return MHD_FALSE; 12 return MHD_FALSE;
13 } 13 }
14 } 14}
15 return MHD_TRUE; 15return MHD_TRUE;
diff --git a/src/gnutls/idle_ready.c b/src/gnutls/idle_ready.c
index 0e315950..ddc471a9 100644
--- a/src/gnutls/idle_ready.c
+++ b/src/gnutls/idle_ready.c
@@ -1,12 +1,12 @@
1 enum MHD_Bool 1enum MHD_Bool
2 (*idle_ready)(void *cls, 2(*idle_ready)(void *cls,
3 struct MHD_TLS_ConnectionState *cs); 3 struct MHD_TLS_ConnectionState *cs);
4 4
5 5
6 if (MHD_TLS_CONN_NO_TLS != connection->tls_state) 6if (MHD_TLS_CONN_NO_TLS != connection->tls_state)
7 { /* HTTPS connection. */ 7{ /* HTTPS connection. */
8 if ((MHD_TLS_CONN_INIT <= connection->tls_state) && 8 if ((MHD_TLS_CONN_INIT <= connection->tls_state) &&
9 (MHD_TLS_CONN_CONNECTED > connection->tls_state)) 9 (MHD_TLS_CONN_CONNECTED > connection->tls_state))
10 return false; 10 return false;
11 } 11}
12return true; 12return true;
diff --git a/src/gnutls/init.c b/src/gnutls/init.c
index 3dd656b1..321e7e6a 100644
--- a/src/gnutls/init.c
+++ b/src/gnutls/init.c
@@ -40,12 +40,12 @@ gcry_w32_mutex_init (void **ppmtx)
40 40
41 if (NULL == *ppmtx) 41 if (NULL == *ppmtx)
42 return ENOMEM; 42 return ENOMEM;
43 if (! MHD_mutex_init_ ((MHD_mutex_*)*ppmtx)) 43 if (! MHD_mutex_init_ ((MHD_mutex_*) *ppmtx))
44 { 44 {
45 free (*ppmtx); 45 free (*ppmtx);
46 *ppmtx = NULL; 46 *ppmtx = NULL;
47 return EPERM; 47 return EPERM;
48 } 48 }
49 return 0; 49 return 0;
50} 50}
51 51
@@ -53,7 +53,7 @@ gcry_w32_mutex_init (void **ppmtx)
53static int 53static int
54gcry_w32_mutex_destroy (void **ppmtx) 54gcry_w32_mutex_destroy (void **ppmtx)
55{ 55{
56 int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : EINVAL; 56 int res = (MHD_mutex_destroy_ ((MHD_mutex_*) *ppmtx)) ? 0 : EINVAL;
57 free (*ppmtx); 57 free (*ppmtx);
58 return res; 58 return res;
59} 59}
@@ -62,14 +62,14 @@ gcry_w32_mutex_destroy (void **ppmtx)
62static int 62static int
63gcry_w32_mutex_lock (void **ppmtx) 63gcry_w32_mutex_lock (void **ppmtx)
64{ 64{
65 return MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL; 65 return MHD_mutex_lock_ ((MHD_mutex_*) *ppmtx) ? 0 : EINVAL;
66} 66}
67 67
68 68
69static int 69static int
70gcry_w32_mutex_unlock (void **ppmtx) 70gcry_w32_mutex_unlock (void **ppmtx)
71{ 71{
72 return MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL; 72 return MHD_mutex_unlock_ ((MHD_mutex_*) *ppmtx) ? 0 : EINVAL;
73} 73}
74 74
75 75
@@ -77,7 +77,8 @@ static struct gcry_thread_cbs gcry_threads_w32 = {
77 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)), 77 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
78 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy, 78 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
79 gcry_w32_mutex_lock, gcry_w32_mutex_unlock, 79 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
80 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; 80 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
81};
81 82
82#endif /* defined(MHD_W32_MUTEX_) */ 83#endif /* defined(MHD_W32_MUTEX_) */
83#endif /* HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 */ 84#endif /* HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 */
@@ -94,7 +95,7 @@ volatile int global_init_count = 0;
94/** 95/**
95 * Global initialisation mutex 96 * Global initialisation mutex
96 */ 97 */
97MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); 98MHD_MUTEX_STATIC_DEFN_INIT_ (global_init_mutex_);
98#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 99#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
99 100
100#endif 101#endif
@@ -108,12 +109,12 @@ void
108MHD_TLS_check_global_init_ (void) 109MHD_TLS_check_global_init_ (void)
109{ 110{
110#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 111#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
111 MHD_mutex_lock_chk_(&global_init_mutex_); 112 MHD_mutex_lock_chk_ (&global_init_mutex_);
112#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 113#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
113 if (0 == global_init_count++) 114 if (0 == global_init_count++)
114 MHD_init (); 115 MHD_init ();
115#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 116#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
116 MHD_mutex_unlock_chk_(&global_init_mutex_); 117 MHD_mutex_unlock_chk_ (&global_init_mutex_);
117#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 118#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
118} 119}
119 120
@@ -133,16 +134,17 @@ MHD_TLS_init (void)
133#if defined(MHD_USE_POSIX_THREADS) 134#if defined(MHD_USE_POSIX_THREADS)
134 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS, 135 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
135 &gcry_threads_pthread)) 136 &gcry_threads_pthread))
136 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n")); 137 MHD_PANIC (_ ("Failed to initialise multithreading in libgcrypt\n"));
137#elif defined(MHD_W32_MUTEX_) 138#elif defined(MHD_W32_MUTEX_)
138 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS, 139 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
139 &gcry_threads_w32)) 140 &gcry_threads_w32))
140 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n")); 141 MHD_PANIC (_ ("Failed to initialise multithreading in libgcrypt\n"));
141#endif /* defined(MHD_W32_MUTEX_) */ 142#endif /* defined(MHD_W32_MUTEX_) */
142 gcry_check_version (NULL); 143 gcry_check_version (NULL);
143#else 144#else
144 if (NULL == gcry_check_version ("1.6.0")) 145 if (NULL == gcry_check_version ("1.6.0"))
145 MHD_PANIC (_("libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n")); 146 MHD_PANIC (_ (
147 "libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n"));
146#endif 148#endif
147#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 149#endif /* MHD_HTTPS_REQUIRE_GRYPT */
148 gnutls_global_init (); 150 gnutls_global_init ();
@@ -150,11 +152,11 @@ MHD_TLS_init (void)
150 152
151 153
152void 154void
153MHD_TLS_fini(void) 155MHD_TLS_fini (void)
154{ 156{
155 gnutls_global_deinit (); 157 gnutls_global_deinit ();
156} 158}
157 159
158#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED 160#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
159_SET_INIT_AND_DEINIT_FUNCS(MHD_TLS_init, MHD_TLS_fini); 161_SET_INIT_AND_DEINIT_FUNCS (MHD_TLS_init, MHD_TLS_fini);
160#endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */ 162#endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */
diff --git a/src/gnutls/init.h b/src/gnutls/init.h
index 03d19412..ea5fc261 100644
--- a/src/gnutls/init.h
+++ b/src/gnutls/init.h
@@ -31,7 +31,7 @@
31 * Do nothing - global initialisation is 31 * Do nothing - global initialisation is
32 * performed by library constructor. 32 * performed by library constructor.
33 */ 33 */
34#define MHD_TLS_check_global_init_() (void)0 34#define MHD_TLS_check_global_init_() (void) 0
35#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */ 35#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */
36/** 36/**
37 * Check whether global initialisation was performed 37 * Check whether global initialisation was performed
diff --git a/src/gnutls/recv.c b/src/gnutls/recv.c
index cfa9dc4b..9c58cb62 100644
--- a/src/gnutls/recv.c
+++ b/src/gnutls/recv.c
@@ -1,5 +1,5 @@
1recv: 1recv :
2 2
3res = gnutls_record_recv (connection->tls_session, 3res = gnutls_record_recv (connection->tls_session,
4 &urh->in_buffer[urh->in_buffer_used], 4 &urh->in_buffer[urh->in_buffer_used],
5 buf_size); 5 buf_size);
diff --git a/src/gnutls/send.c b/src/gnutls/send.c
index 65cdba77..3fad99fb 100644
--- a/src/gnutls/send.c
+++ b/src/gnutls/send.c
@@ -1,11 +1,11 @@
1 ssize_t 1ssize_t
2 (*send)(void *cls, 2(*send)(void *cls,
3 struct MHD_TLS_ConnectionState *cs, 3 struct MHD_TLS_ConnectionState *cs,
4 const void *buf, 4 const void *buf,
5 size_t buf_size); 5 size_t buf_size);
6 6
7 7
8see: 8see:
9 res = gnutls_record_send (connection->tls_session, 9res = gnutls_record_send (connection->tls_session,
10 urh->out_buffer, 10 urh->out_buffer,
11 data_size); 11 data_size);
diff --git a/src/gnutls/setup_connection.c b/src/gnutls/setup_connection.c
index c789613d..64082952 100644
--- a/src/gnutls/setup_connection.c
+++ b/src/gnutls/setup_connection.c
@@ -1,57 +1,58 @@
1
2
3setup_connection () 1setup_connection ()
4{ 2{
5 connection->tls_state = MHD_TLS_CONN_INIT; 3 connection->tls_state = MHD_TLS_CONN_INIT;
6 MHD_set_https_callbacks (connection); 4 MHD_set_https_callbacks (connection);
7 gnutls_init (&connection->tls_session, 5 gnutls_init (&connection->tls_session,
8 GNUTLS_SERVER 6 GNUTLS_SERVER
9#if (GNUTLS_VERSION_NUMBER+0 >= 0x030402) 7#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
10 | GNUTLS_NO_SIGNAL 8 | GNUTLS_NO_SIGNAL
11#endif /* GNUTLS_VERSION_NUMBER >= 0x030402 */ 9#endif /* GNUTLS_VERSION_NUMBER >= 0x030402 */
12#if GNUTLS_VERSION_MAJOR >= 3 10#if GNUTLS_VERSION_MAJOR >= 3
13 | GNUTLS_NONBLOCK 11 | GNUTLS_NONBLOCK
14#endif /* GNUTLS_VERSION_MAJOR >= 3*/ 12#endif /* GNUTLS_VERSION_MAJOR >= 3*/
15 ); 13 );
16 gnutls_priority_set (connection->tls_session, 14 gnutls_priority_set (connection->tls_session,
17 daemon->priority_cache); 15 daemon->priority_cache);
18 switch (daemon->cred_type) 16 switch (daemon->cred_type)
19 { 17 {
20 /* set needed credentials for certificate authentication. */ 18 /* set needed credentials for certificate authentication. */
21 case GNUTLS_CRD_CERTIFICATE: 19 case GNUTLS_CRD_CERTIFICATE:
22 gnutls_credentials_set (connection->tls_session, 20 gnutls_credentials_set (connection->tls_session,
23 GNUTLS_CRD_CERTIFICATE, 21 GNUTLS_CRD_CERTIFICATE,
24 daemon->x509_cred); 22 daemon->x509_cred);
25 break; 23 break;
26 default: 24 default:
27#ifdef HAVE_MESSAGES 25#ifdef HAVE_MESSAGES
28 MHD_DLOG (connection->daemon, 26 MHD_DLOG (connection->daemon,
29 _("Failed to setup TLS credentials: unknown credential type %d\n"), 27 _ (
30 daemon->cred_type); 28 "Failed to setup TLS credentials: unknown credential type %d\n"),
29 daemon->cred_type);
31#endif 30#endif
32 MHD_socket_close_chk_ (client_socket); 31 MHD_socket_close_chk_ (client_socket);
33 MHD_ip_limit_del (daemon, 32 MHD_ip_limit_del (daemon,
34 addr, 33 addr,
35 addrlen); 34 addrlen);
36 free (connection); 35 free (connection);
37 MHD_PANIC (_("Unknown credential type")); 36 MHD_PANIC (_ ("Unknown credential type"));
38#if EINVAL 37#if EINVAL
39 errno = EINVAL; 38 errno = EINVAL;
40#endif 39#endif
41 return MHD_NO; 40 return MHD_NO;
42 } 41 }
43#if (GNUTLS_VERSION_NUMBER+0 >= 0x030109) && !defined(_WIN64) 42#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
44 gnutls_transport_set_int (connection->tls_session, (int)(client_socket)); 43 gnutls_transport_set_int (connection->tls_session, (int) (client_socket));
45#else /* GnuTLS before 3.1.9 or Win x64 */ 44#else /* GnuTLS before 3.1.9 or Win x64 */
46 gnutls_transport_set_ptr (connection->tls_session, (gnutls_transport_ptr_t)(intptr_t)(client_socket)); 45 gnutls_transport_set_ptr (connection->tls_session,
46 (gnutls_transport_ptr_t) (intptr_t) (client_socket));
47#endif /* GnuTLS before 3.1.9 */ 47#endif /* GnuTLS before 3.1.9 */
48#ifdef MHD_TLSLIB_NEED_PUSH_FUNC 48#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
49 gnutls_transport_set_push_function (connection->tls_session, MHD_tls_push_func_); 49 gnutls_transport_set_push_function (connection->tls_session,
50 MHD_tls_push_func_);
50#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */ 51#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */
51 if (daemon->https_mem_trust) 52 if (daemon->https_mem_trust)
52 gnutls_certificate_server_set_request (connection->tls_session, 53 gnutls_certificate_server_set_request (connection->tls_session,
53 GNUTLS_CERT_REQUEST); 54 GNUTLS_CERT_REQUEST);
54#else /* ! HTTPS_SUPPORT */ 55#else /* ! HTTPS_SUPPORT */
55 return NULL; 56 return NULL;
56 57
57} 58}
diff --git a/src/gnutls/shutdown_connection.c b/src/gnutls/shutdown_connection.c
index be1e0bde..48db358a 100644
--- a/src/gnutls/shutdown_connection.c
+++ b/src/gnutls/shutdown_connection.c
@@ -1,5 +1,5 @@
1 enum MHD_Bool 1enum MHD_Bool
2 (*shutdown_connection) (void *cls, 2(*shutdown_connection)(void *cls,
3 struct MHD_TLS_ConnectionState *cs); 3 struct MHD_TLS_ConnectionState *cs);
4 4
5see: MHD_tls_connection_shutdown() 5see: MHD_tls_connection_shutdown ()
diff --git a/src/gnutls/strerror.c b/src/gnutls/strerror.c
index b6606661..a2333651 100644
--- a/src/gnutls/strerror.c
+++ b/src/gnutls/strerror.c
@@ -1,6 +1,6 @@
1 const char * 1const char *
2 (*strerror)(void *cls, 2(*strerror)(void *cls,
3 int ec); 3 int ec);
4 4
5see: 5see:
6gnutls_strerror (ec)); 6gnutls_strerror (ec));
diff --git a/src/gnutls/update_event_loop_info.c b/src/gnutls/update_event_loop_info.c
index 327b20e4..3b7bc628 100644
--- a/src/gnutls/update_event_loop_info.c
+++ b/src/gnutls/update_event_loop_info.c
@@ -1,20 +1,20 @@
1 enum MHD_Bool 1enum MHD_Bool
2 (*update_event_loop_info)(void *cls, 2(*update_event_loop_info)(void *cls,
3 struct MHD_TLS_ConnectionState *cs, 3 struct MHD_TLS_ConnectionState *cs,
4 enum MHD_RequestEventLoopInfo *eli); 4 enum MHD_RequestEventLoopInfo *eli);
5 5
6 6
7 switch (connection->tls_state) 7switch (connection->tls_state)
8 { 8{
9 case MHD_TLS_CONN_INIT: 9case MHD_TLS_CONN_INIT:
10 *eli = MHD_EVENT_LOOP_INFO_READ; 10 *eli = MHD_EVENT_LOOP_INFO_READ;
11 return true; 11 return true;
12 case MHD_TLS_CONN_HANDSHAKING: 12case MHD_TLS_CONN_HANDSHAKING:
13 if (0 == gnutls_record_get_direction (connection->tls_session)) 13 if (0 == gnutls_record_get_direction (connection->tls_session))
14 *eli = MHD_EVENT_LOOP_INFO_READ; 14 *eli = MHD_EVENT_LOOP_INFO_READ;
15 else 15 else
16 *eli = MHD_EVENT_LOOP_INFO_WRITE; 16 *eli = MHD_EVENT_LOOP_INFO_WRITE;
17 return true; 17 return true;
18 default: 18default:
19 return false; 19 return false;
20 } 20}
diff --git a/src/include/autoinit_funcs.h b/src/include/autoinit_funcs.h
index d925c7be..c4f3d014 100644
--- a/src/include/autoinit_funcs.h
+++ b/src/include/autoinit_funcs.h
@@ -20,7 +20,7 @@
20/* 20/*
21 General usage is simple: include this header, declare or define two 21 General usage is simple: include this header, declare or define two
22 functions with zero parameters (void) and any return type: one for 22 functions with zero parameters (void) and any return type: one for
23 initialization and one for deinitialization, add 23 initialization and one for deinitialization, add
24 _SET_INIT_AND_DEINIT_FUNCS(FuncInitName, FuncDeInitName) to the code 24 _SET_INIT_AND_DEINIT_FUNCS(FuncInitName, FuncDeInitName) to the code
25 and functions will be automatically called during application startup 25 and functions will be automatically called during application startup
26 and shutdown. 26 and shutdown.
@@ -70,9 +70,9 @@
70#define AUTOINIT_FUNCS_VERSION 0x01000100 70#define AUTOINIT_FUNCS_VERSION 0x01000100
71 71
72#if defined(__GNUC__) 72#if defined(__GNUC__)
73 /* if possible - check for supported attribute */ 73/* if possible - check for supported attribute */
74#ifdef __has_attribute 74#ifdef __has_attribute
75#if !__has_attribute(constructor) || !__has_attribute(destructor) 75#if ! __has_attribute (constructor) || ! __has_attribute (destructor)
76#define _GNUC_ATTR_CONSTR_NOT_SUPPORTED 1 76#define _GNUC_ATTR_CONSTR_NOT_SUPPORTED 1
77#endif /* !__has_attribute(constructor) || !__has_attribute(destructor) */ 77#endif /* !__has_attribute(constructor) || !__has_attribute(destructor) */
78#endif /* __has_attribute */ 78#endif /* __has_attribute */
@@ -80,20 +80,20 @@
80 80
81/* "_attribute__ ((constructor))" is supported by GCC, clang and 81/* "_attribute__ ((constructor))" is supported by GCC, clang and
82 Sun/Oracle compiler starting from version 12.1. */ 82 Sun/Oracle compiler starting from version 12.1. */
83#if (defined(__GNUC__) && !defined(_GNUC_ATTR_CONSTR_NOT_SUPPORTED)) || \ 83#if (defined(__GNUC__) && ! defined(_GNUC_ATTR_CONSTR_NOT_SUPPORTED)) || \
84 (defined(__SUNPRO_C) && __SUNPRO_C+0 >= 0x5100) 84 (defined(__SUNPRO_C) && __SUNPRO_C + 0 >= 0x5100)
85 85
86#define GNUC_SET_INIT_AND_DEINIT(FI,FD) \ 86#define GNUC_SET_INIT_AND_DEINIT(FI,FD) \
87 void __attribute__ ((constructor)) _GNUC_init_helper_##FI(void) \ 87 void __attribute__ ((constructor)) _GNUC_init_helper_ ## FI (void) \
88 { (void)(FI)(); } \ 88 { (void) (FI) (); } \
89 void __attribute__ ((destructor)) _GNUC_deinit_helper_##FD(void) \ 89 void __attribute__ ((destructor)) _GNUC_deinit_helper_ ## FD (void) \
90 { (void)(FD)(); } \ 90 { (void) (FD) (); } \
91 struct _GNUC_dummy_str_##FI{int i;} 91 struct _GNUC_dummy_str_ ## FI {int i;}
92 92
93#define _SET_INIT_AND_DEINIT_FUNCS(FI,FD) GNUC_SET_INIT_AND_DEINIT(FI,FD) 93#define _SET_INIT_AND_DEINIT_FUNCS(FI,FD) GNUC_SET_INIT_AND_DEINIT (FI,FD)
94#define _AUTOINIT_FUNCS_ARE_SUPPORTED 1 94#define _AUTOINIT_FUNCS_ARE_SUPPORTED 1
95 95
96#elif defined (_MSC_FULL_VER) && _MSC_VER+0 >= 1600 96#elif defined (_MSC_FULL_VER) && _MSC_VER + 0 >= 1600
97 97
98/* Make sure that your project/sources define: 98/* Make sure that your project/sources define:
99 _LIB if building a static library (_LIB is ignored if _CONSOLE is defined); 99 _LIB if building a static library (_LIB is ignored if _CONSOLE is defined);
@@ -107,9 +107,9 @@
107 107
108/* Stringify macros */ 108/* Stringify macros */
109#define _INSTRMACRO(a) #a 109#define _INSTRMACRO(a) #a
110#define _STRMACRO(a) _INSTRMACRO(a) 110#define _STRMACRO(a) _INSTRMACRO (a)
111 111
112#if !defined(_USRDLL) || defined(AUTOINIT_FUNCS_DECLARE_STATIC_REG) 112#if ! defined(_USRDLL) || defined(AUTOINIT_FUNCS_DECLARE_STATIC_REG)
113 113
114/* required for atexit() */ 114/* required for atexit() */
115#include <stdlib.h> 115#include <stdlib.h>
@@ -128,15 +128,16 @@
128#define W32_VARDECORPEFIXSTR "" 128#define W32_VARDECORPEFIXSTR ""
129#elif defined(_M_IX86) || defined(_X86_) 129#elif defined(_M_IX86) || defined(_X86_)
130#define W32_VARDECORPREFIX _ 130#define W32_VARDECORPREFIX _
131#define W32_DECORVARNAME(v) _##v 131#define W32_DECORVARNAME(v) _ ## v
132#define W32_VARDECORPEFIXSTR "_" 132#define W32_VARDECORPEFIXSTR "_"
133#else 133#else
134#error Do not know how to decorate symbols for this architecture 134#error Do not know how to decorate symbols for this architecture
135#endif 135#endif
136 136
137/* Internal variable prefix (can be any) */ 137/* Internal variable prefix (can be any) */
138#define W32_INITHELPERVARNAME(f) _initHelperDummy_##f 138#define W32_INITHELPERVARNAME(f) _initHelperDummy_ ## f
139#define W32_INITHELPERVARNAMEDECORSTR(f) W32_VARDECORPEFIXSTR _STRMACRO(W32_INITHELPERVARNAME(f)) 139#define W32_INITHELPERVARNAMEDECORSTR(f) W32_VARDECORPEFIXSTR _STRMACRO ( \
140 W32_INITHELPERVARNAME (f))
140 141
141/* Declare section (segment), put variable pointing to init function to chosen segment, 142/* Declare section (segment), put variable pointing to init function to chosen segment,
142 force linker to include variable to avoid omitting by optimizer */ 143 force linker to include variable to avoid omitting by optimizer */
@@ -145,9 +146,10 @@
145/* Return value is ignored for C++ initializers */ 146/* Return value is ignored for C++ initializers */
146/* For C initializers: startup process is aborted if initializer return non-zero */ 147/* For C initializers: startup process is aborted if initializer return non-zero */
147#define W32_FPTR_IN_SEG(S,F) \ 148#define W32_FPTR_IN_SEG(S,F) \
148 __pragma(section(S,long,read)) \ 149 __pragma (section (S,long,read)) \
149 __pragma(comment(linker, "/INCLUDE:" W32_INITHELPERVARNAMEDECORSTR(F))) \ 150 __pragma (comment (linker, "/INCLUDE:" W32_INITHELPERVARNAMEDECORSTR (F))) \
150 W32_INITVARDECL __declspec(allocate(S)) int(__cdecl *W32_INITHELPERVARNAME(F))(void) = &F 151 W32_INITVARDECL __declspec(allocate (S))int (__cdecl * W32_INITHELPERVARNAME ( \
152 F))(void) = &F
151 153
152/* Section (segment) names for pointers to initializers */ 154/* Section (segment) names for pointers to initializers */
153#define W32_SEG_INIT_C_USER ".CRT$XCU" 155#define W32_SEG_INIT_C_USER ".CRT$XCU"
@@ -161,10 +163,10 @@
161 during application startup */ 163 during application startup */
162/* "lib" initializers are called before "user" initializers */ 164/* "lib" initializers are called before "user" initializers */
163/* "C" initializers are called before "C++" initializers */ 165/* "C" initializers are called before "C++" initializers */
164#define W32_REG_INIT_C_USER(F) W32_FPTR_IN_SEG(W32_SEG_INIT_C_USER,F) 166#define W32_REG_INIT_C_USER(F) W32_FPTR_IN_SEG (W32_SEG_INIT_C_USER,F)
165#define W32_REG_INIT_C_LIB(F) W32_FPTR_IN_SEG(W32_SEG_INIT_C_LIB,F) 167#define W32_REG_INIT_C_LIB(F) W32_FPTR_IN_SEG (W32_SEG_INIT_C_LIB,F)
166#define W32_REG_INIT_CXX_USER(F) W32_FPTR_IN_SEG(W32_SEG_INIT_CXX_USER,F) 168#define W32_REG_INIT_CXX_USER(F) W32_FPTR_IN_SEG (W32_SEG_INIT_CXX_USER,F)
167#define W32_REG_INIT_CXX_LIB(F) W32_FPTR_IN_SEG(W32_SEG_INIT_CXX_LIB,F) 169#define W32_REG_INIT_CXX_LIB(F) W32_FPTR_IN_SEG (W32_SEG_INIT_CXX_LIB,F)
168 170
169/* Choose main register macro based on language and program type */ 171/* Choose main register macro based on language and program type */
170/* Assuming that _LIB or _USRDLL is defined for static or DLL-library */ 172/* Assuming that _LIB or _USRDLL is defined for static or DLL-library */
@@ -174,16 +176,18 @@
174/* Define AUTOINIT_FUNCS_FORCE_USER_LVL_INIT to register initializers 176/* Define AUTOINIT_FUNCS_FORCE_USER_LVL_INIT to register initializers
175 at user level even if building library */ 177 at user level even if building library */
176#ifdef __cplusplus 178#ifdef __cplusplus
177#if ((defined(_LIB) && !defined(_CONSOLE)) || defined(_USRDLL)) && !defined(AUTOINIT_FUNCS_FORCE_USER_LVL_INIT) 179#if ((defined(_LIB) && ! defined(_CONSOLE)) || defined(_USRDLL)) && \
178#define W32_REGISTER_INIT(F) W32_REG_INIT_CXX_LIB(F) 180 ! defined(AUTOINIT_FUNCS_FORCE_USER_LVL_INIT)
181#define W32_REGISTER_INIT(F) W32_REG_INIT_CXX_LIB (F)
179#else /* ! _LIB && ! _DLL */ 182#else /* ! _LIB && ! _DLL */
180#define W32_REGISTER_INIT(F) W32_REG_INIT_CXX_USER(F) 183#define W32_REGISTER_INIT(F) W32_REG_INIT_CXX_USER (F)
181#endif /* ! _LIB && ! _DLL */ 184#endif /* ! _LIB && ! _DLL */
182#else /* !__cplusplus*/ 185#else /* !__cplusplus*/
183#if ((defined(_LIB) && !defined(_CONSOLE)) || defined(_USRDLL)) && !defined(AUTOINIT_FUNCS_FORCE_USER_LVL_INIT) 186#if ((defined(_LIB) && ! defined(_CONSOLE)) || defined(_USRDLL)) && \
184#define W32_REGISTER_INIT(F) W32_REG_INIT_C_LIB(F) 187 ! defined(AUTOINIT_FUNCS_FORCE_USER_LVL_INIT)
188#define W32_REGISTER_INIT(F) W32_REG_INIT_C_LIB (F)
185#else /* ! _LIB && ! _DLL */ 189#else /* ! _LIB && ! _DLL */
186#define W32_REGISTER_INIT(F) W32_REG_INIT_C_USER(F) 190#define W32_REGISTER_INIT(F) W32_REG_INIT_C_USER (F)
187#endif /* ! _LIB && ! _DLL */ 191#endif /* ! _LIB && ! _DLL */
188#endif /* !__cplusplus*/ 192#endif /* !__cplusplus*/
189 193
@@ -197,36 +201,36 @@
197#endif /* _USRDLL */ 201#endif /* _USRDLL */
198 202
199 203
200#if !defined(_USRDLL) || defined(AUTOINIT_FUNCS_FORCE_STATIC_REG) 204#if ! defined(_USRDLL) || defined(AUTOINIT_FUNCS_FORCE_STATIC_REG)
201#define W32_SET_INIT_AND_DEINIT(FI,FD) \ 205#define W32_SET_INIT_AND_DEINIT(FI,FD) \
202 void __cdecl _W32_deinit_helper_##FD(void) \ 206 void __cdecl _W32_deinit_helper_ ## FD (void) \
203 { (void)(FD)(); } \ 207 { (void) (FD) (); } \
204 int __cdecl _W32_init_helper_##FI(void) \ 208 int __cdecl _W32_init_helper_ ## FI (void) \
205 { (void)(FI)(); atexit(_W32_deinit_helper_##FD); return 0; } \ 209 { (void) (FI) (); atexit (_W32_deinit_helper_ ## FD); return 0; } \
206 W32_REGISTER_INIT(_W32_init_helper_##FI) 210 W32_REGISTER_INIT (_W32_init_helper_ ## FI)
207#else /* _USRDLL */ 211#else /* _USRDLL */
208 212
209/* If DllMain is already present in code, define AUTOINIT_FUNCS_CALL_USR_DLLMAIN 213/* If DllMain is already present in code, define AUTOINIT_FUNCS_CALL_USR_DLLMAIN
210 and rename DllMain to usr_DllMain */ 214 and rename DllMain to usr_DllMain */
211#ifndef AUTOINIT_FUNCS_CALL_USR_DLLMAIN 215#ifndef AUTOINIT_FUNCS_CALL_USR_DLLMAIN
212#define W32_SET_INIT_AND_DEINIT(FI,FD) \ 216#define W32_SET_INIT_AND_DEINIT(FI,FD) \
213 BOOL WINAPI DllMain(HINSTANCE hinst,DWORD reason,LPVOID unused) \ 217 BOOL WINAPI DllMain (HINSTANCE hinst,DWORD reason,LPVOID unused) \
214 { if(DLL_PROCESS_ATTACH==reason) {(void)(FI)();} \ 218 { if (DLL_PROCESS_ATTACH==reason) {(void) (FI) ();} \
215 else if(DLL_PROCESS_DETACH==reason) {(void)(FD)();} \ 219 else if (DLL_PROCESS_DETACH==reason) {(void) (FD) ();} \
216 return TRUE; \ 220 return TRUE; \
217 } struct _W32_dummy_strc_##FI{int i;} 221 } struct _W32_dummy_strc_ ## FI {int i;}
218#else /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */ 222#else /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */
219#define W32_SET_INIT_AND_DEINIT(FI,FD) \ 223#define W32_SET_INIT_AND_DEINIT(FI,FD) \
220 BOOL WINAPI usr_DllMain(HINSTANCE hinst,DWORD reason,LPVOID unused); \ 224 BOOL WINAPI usr_DllMain (HINSTANCE hinst,DWORD reason,LPVOID unused); \
221 BOOL WINAPI DllMain(HINSTANCE hinst,DWORD reason,LPVOID unused) \ 225 BOOL WINAPI DllMain (HINSTANCE hinst,DWORD reason,LPVOID unused) \
222 { if(DLL_PROCESS_ATTACH==reason) {(void)(FI)();} \ 226 { if (DLL_PROCESS_ATTACH==reason) {(void) (FI) ();} \
223 else if(DLL_PROCESS_DETACH==reason) {(void)(FD)();} \ 227 else if (DLL_PROCESS_DETACH==reason) {(void) (FD) ();} \
224 return usr_DllMain(hinst,reason,unused); \ 228 return usr_DllMain (hinst,reason,unused); \
225 } struct _W32_dummy_strc_##FI{int i;} 229 } struct _W32_dummy_strc_ ## FI {int i;}
226#endif /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */ 230#endif /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */
227#endif /* _USRDLL */ 231#endif /* _USRDLL */
228 232
229#define _SET_INIT_AND_DEINIT_FUNCS(FI,FD) W32_SET_INIT_AND_DEINIT(FI,FD) 233#define _SET_INIT_AND_DEINIT_FUNCS(FI,FD) W32_SET_INIT_AND_DEINIT (FI,FD)
230/* Indicate that automatic initializers/deinitializers are supported */ 234/* Indicate that automatic initializers/deinitializers are supported */
231#define _AUTOINIT_FUNCS_ARE_SUPPORTED 1 235#define _AUTOINIT_FUNCS_ARE_SUPPORTED 1
232 236
@@ -235,7 +239,8 @@
235/* Define EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED before inclusion of header to 239/* Define EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED before inclusion of header to
236 abort compilation if automatic initializers/deinitializers are not supported */ 240 abort compilation if automatic initializers/deinitializers are not supported */
237#ifdef EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED 241#ifdef EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED
238#error Compiler/platform don not support automatic calls of user-defined initializer and deinitializer 242#error \
243 Compiler/platform don not support automatic calls of user-defined initializer and deinitializer
239#endif /* EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED */ 244#endif /* EMIT_ERROR_IF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED */
240 245
241/* Do nothing */ 246/* Do nothing */
diff --git a/src/include/mhd_options.h b/src/include/mhd_options.h
index 47b7ce0e..26ab49e1 100644
--- a/src/include/mhd_options.h
+++ b/src/include/mhd_options.h
@@ -45,7 +45,7 @@
45 45
46#ifndef _MHD_EXTERN 46#ifndef _MHD_EXTERN
47#if defined(BUILDING_MHD_LIB) && defined(_WIN32) && \ 47#if defined(BUILDING_MHD_LIB) && defined(_WIN32) && \
48 (defined(DLL_EXPORT) || defined(MHD_W32DLL)) 48 (defined(DLL_EXPORT) || defined(MHD_W32DLL))
49#define _MHD_EXTERN __declspec(dllexport) extern 49#define _MHD_EXTERN __declspec(dllexport) extern
50#else /* !BUILDING_MHD_LIB || !_WIN32 || (!DLL_EXPORT && !MHD_W32DLL) */ 50#else /* !BUILDING_MHD_LIB || !_WIN32 || (!DLL_EXPORT && !MHD_W32DLL) */
51#define _MHD_EXTERN extern 51#define _MHD_EXTERN extern
@@ -66,7 +66,7 @@
66#endif /* !FD_SETSIZE && !W32 */ 66#endif /* !FD_SETSIZE && !W32 */
67 67
68#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) || \ 68#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) || \
69 defined(HAVE_DARWIN_SENDFILE) || defined(HAVE_SOLARIS_SENDFILE) 69 defined(HAVE_DARWIN_SENDFILE) || defined(HAVE_SOLARIS_SENDFILE)
70/* Have any supported sendfile() function. */ 70/* Have any supported sendfile() function. */
71#define _MHD_HAVE_SENDFILE 71#define _MHD_HAVE_SENDFILE
72#endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE || 72#endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE ||
@@ -104,7 +104,8 @@
104#define RESTRICT __restrict__ 104#define RESTRICT __restrict__
105#endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */ 105#endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */
106 106
107#if LINUX+0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && ! defined(_LARGEFILE64_SOURCE) 107#if LINUX + 0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && \
108 ! defined(_LARGEFILE64_SOURCE)
108/* On Linux, special macro is required to enable definitions of some xxx64 functions */ 109/* On Linux, special macro is required to enable definitions of some xxx64 functions */
109#define _LARGEFILE64_SOURCE 1 110#define _LARGEFILE64_SOURCE 1
110#endif 111#endif
@@ -115,12 +116,13 @@
115#endif /* HAVE_C11_GMTIME_S */ 116#endif /* HAVE_C11_GMTIME_S */
116 117
117#if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE) 118#if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE)
118#error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. Cannot favor speed and size at the same time. 119#error \
120 MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. Cannot favor speed and size at the same time.
119#endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */ 121#endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */
120 122
121/* Define MHD_FAVOR_FAST_CODE to force fast code path or 123/* Define MHD_FAVOR_FAST_CODE to force fast code path or
122 define MHD_FAVOR_SMALL_CODE to choose compact code path */ 124 define MHD_FAVOR_SMALL_CODE to choose compact code path */
123#if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) 125#if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE)
124/* Try to detect user preferences */ 126/* Try to detect user preferences */
125/* Defined by GCC and many compatible compilers */ 127/* Defined by GCC and many compatible compilers */
126#if defined(__OPTIMIZE_SIZE__) 128#if defined(__OPTIMIZE_SIZE__)
@@ -130,7 +132,7 @@
130#endif /* __OPTIMIZE__ */ 132#endif /* __OPTIMIZE__ */
131#endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */ 133#endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
132 134
133#if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) 135#if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE)
134/* Use faster code by default */ 136/* Use faster code by default */
135#define MHD_FAVOR_FAST_CODE 1 137#define MHD_FAVOR_FAST_CODE 1
136#endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */ 138#endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index a678f399..4f8f685a 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -108,7 +108,7 @@ extern "C"
108#include <stdarg.h> 108#include <stdarg.h>
109#include <stdint.h> 109#include <stdint.h>
110#include <sys/types.h> 110#include <sys/types.h>
111#if !defined(_WIN32) || defined(__CYGWIN__) 111#if ! defined(_WIN32) || defined(__CYGWIN__)
112#include <unistd.h> 112#include <unistd.h>
113#include <sys/time.h> 113#include <sys/time.h>
114#include <sys/socket.h> 114#include <sys/socket.h>
@@ -116,14 +116,14 @@ extern "C"
116/* Declare POSIX-compatible names */ 116/* Declare POSIX-compatible names */
117#define _CRT_DECLARE_NONSTDC_NAMES 1 117#define _CRT_DECLARE_NONSTDC_NAMES 1
118#include <ws2tcpip.h> 118#include <ws2tcpip.h>
119#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 119#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
120#define _SSIZE_T_DEFINED 120#define _SSIZE_T_DEFINED
121typedef intptr_t ssize_t; 121typedef intptr_t ssize_t;
122#endif /* !_SSIZE_T_DEFINED */ 122#endif /* !_SSIZE_T_DEFINED */
123#endif /* _WIN32 && ! __CYGWIN__ */ 123#endif /* _WIN32 && ! __CYGWIN__ */
124#endif 124#endif
125 125
126#if defined(__CYGWIN__) && !defined(_SYS_TYPES_FD_SET) 126#if defined(__CYGWIN__) && ! defined(_SYS_TYPES_FD_SET)
127/* Do not define __USE_W32_SOCKETS under Cygwin! */ 127/* Do not define __USE_W32_SOCKETS under Cygwin! */
128#error Cygwin with winsock fd_set is not supported 128#error Cygwin with winsock fd_set is not supported
129#endif 129#endif
@@ -182,7 +182,7 @@ typedef intptr_t ssize_t;
182/** 182/**
183 * MHD_socket is type for socket FDs 183 * MHD_socket is type for socket FDs
184 */ 184 */
185#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) 185#if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
186#define MHD_POSIX_SOCKETS 1 186#define MHD_POSIX_SOCKETS 1
187typedef int MHD_socket; 187typedef int MHD_socket;
188#define MHD_INVALID_SOCKET (-1) 188#define MHD_INVALID_SOCKET (-1)
@@ -207,30 +207,35 @@ typedef SOCKET MHD_socket;
207#endif /* MHD_NO_DEPRECATION */ 207#endif /* MHD_NO_DEPRECATION */
208 208
209#ifndef _MHD_DEPR_MACRO 209#ifndef _MHD_DEPR_MACRO
210#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1500 210#if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1500
211/* VS 2008 or later */ 211/* VS 2008 or later */
212/* Stringify macros */ 212/* Stringify macros */
213#define _MHD_INSTRMACRO(a) #a 213#define _MHD_INSTRMACRO(a) #a
214#define _MHD_STRMACRO(a) _MHD_INSTRMACRO(a) 214#define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
215/* deprecation message */ 215/* deprecation message */
216#define _MHD_DEPR_MACRO(msg) __pragma(message(__FILE__ "(" _MHD_STRMACRO(__LINE__)"): warning: " msg)) 216#define _MHD_DEPR_MACRO(msg) __pragma (message (__FILE__ "(" _MHD_STRMACRO ( \
217#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 217 __LINE__) "): warning: " msg))
218#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
218#elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__) 219#elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__)
219/* clang or GCC since 3.0 */ 220/* clang or GCC since 3.0 */
220#define _MHD_GCC_PRAG(x) _Pragma (#x) 221#define _MHD_GCC_PRAG(x) _Pragma (#x)
221#if (defined(__clang__) && (__clang_major__+0 >= 5 || \ 222#if (defined(__clang__) && (__clang_major__ + 0 >= 5 || \
222 (!defined(__apple_build_version__) && (__clang_major__+0 > 3 || (__clang_major__+0 == 3 && __clang_minor__ >= 3))))) || \ 223 (! defined(__apple_build_version__) && \
223 __GNUC__+0 > 4 || (__GNUC__+0 == 4 && __GNUC_MINOR__+0 >= 8) 224 (__clang_major__ + 0 > 3 || (__clang_major__ + 0 == 3 && __clang_minor__ >= \
225 3))))) || \
226 __GNUC__ + 0 > 4 || (__GNUC__ + 0 == 4 && __GNUC_MINOR__ + 0 >= 8)
224/* clang >= 3.3 (or XCode's clang >= 5.0) or 227/* clang >= 3.3 (or XCode's clang >= 5.0) or
225 GCC >= 4.8 */ 228 GCC >= 4.8 */
226#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(GCC warning msg) 229#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (GCC warning msg)
227#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 230#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
228#else /* older clang or GCC */ 231#else /* older clang or GCC */
229/* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */ 232/* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */
230#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(message msg) 233#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (message msg)
231#if (defined(__clang__) && (__clang_major__+0 > 2 || (__clang_major__+0 == 2 && __clang_minor__ >= 9))) /* FIXME: clang >= 2.9, earlier versions not tested */ 234#if (defined(__clang__) && (__clang_major__ + 0 > 2 || (__clang_major__ + 0 == \
235 2 && __clang_minor__ >= \
236 9))) /* FIXME: clang >= 2.9, earlier versions not tested */
232/* clang handles inline pragmas better than GCC */ 237/* clang handles inline pragmas better than GCC */
233#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 238#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
234#endif /* clang >= 2.9 */ 239#endif /* clang >= 2.9 */
235#endif /* older clang or GCC */ 240#endif /* older clang or GCC */
236/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */ 241/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
@@ -247,17 +252,19 @@ typedef SOCKET MHD_socket;
247#endif /* !_MHD_DEPR_IN_MACRO */ 252#endif /* !_MHD_DEPR_IN_MACRO */
248 253
249#ifndef _MHD_DEPR_FUNC 254#ifndef _MHD_DEPR_FUNC
250#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1400 255#if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1400
251/* VS 2005 or later */ 256/* VS 2005 or later */
252#define _MHD_DEPR_FUNC(msg) __declspec(deprecated(msg)) 257#define _MHD_DEPR_FUNC(msg) __declspec(deprecated (msg))
253#elif defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1310 258#elif defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1310
254/* VS .NET 2003 deprecation do not support custom messages */ 259/* VS .NET 2003 deprecation do not support custom messages */
255#define _MHD_DEPR_FUNC(msg) __declspec(deprecated) 260#define _MHD_DEPR_FUNC(msg) __declspec(deprecated)
256#elif (__GNUC__+0 >= 5) || (defined (__clang__) && \ 261#elif (__GNUC__ + 0 >= 5) || (defined (__clang__) && \
257 (__clang_major__+0 > 2 || (__clang_major__+0 == 2 && __clang_minor__ >= 9))) /* FIXME: earlier versions not tested */ 262 (__clang_major__ + 0 > 2 || (__clang_major__ + 0 == 2 && __clang_minor__ >= \
263 9))) /* FIXME: earlier versions not tested */
258/* GCC >= 5.0 or clang >= 2.9 */ 264/* GCC >= 5.0 or clang >= 2.9 */
259#define _MHD_DEPR_FUNC(msg) __attribute__((deprecated(msg))) 265#define _MHD_DEPR_FUNC(msg) __attribute__((deprecated (msg)))
260#elif defined (__clang__) || __GNUC__+0 > 3 || (__GNUC__+0 == 3 && __GNUC_MINOR__+0 >= 1) 266#elif defined (__clang__) || __GNUC__ + 0 > 3 || (__GNUC__ + 0 == 3 && \
267 __GNUC_MINOR__ + 0 >= 1)
261/* 3.1 <= GCC < 5.0 or clang < 2.9 */ 268/* 3.1 <= GCC < 5.0 or clang < 2.9 */
262/* old GCC-style deprecation do not support custom messages */ 269/* old GCC-style deprecation do not support custom messages */
263#define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__)) 270#define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__))
@@ -282,7 +289,8 @@ typedef SOCKET MHD_socket;
282#define MHD_LONG_LONG long long 289#define MHD_LONG_LONG long long
283#define MHD_UNSIGNED_LONG_LONG unsigned long long 290#define MHD_UNSIGNED_LONG_LONG unsigned long long
284#else /* MHD_LONG_LONG */ 291#else /* MHD_LONG_LONG */
285_MHD_DEPR_MACRO("Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG") 292_MHD_DEPR_MACRO (
293 "Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG")
286#endif 294#endif
287/** 295/**
288 * Format string for printing a variable of type #MHD_LONG_LONG. 296 * Format string for printing a variable of type #MHD_LONG_LONG.
@@ -295,14 +303,15 @@ _MHD_DEPR_MACRO("Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG")
295#define MHD_LONG_LONG_PRINTF "ll" 303#define MHD_LONG_LONG_PRINTF "ll"
296#define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu" 304#define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
297#else /* MHD_LONG_LONG_PRINTF */ 305#else /* MHD_LONG_LONG_PRINTF */
298_MHD_DEPR_MACRO("Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG_LONG_PRINTF") 306_MHD_DEPR_MACRO (
307 "Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG_LONG_PRINTF")
299#endif 308#endif
300 309
301 310
302/** 311/**
303 * Length of the binary output of the MD5 hash function. 312 * Length of the binary output of the MD5 hash function.
304 */ 313 */
305#define MHD_MD5_DIGEST_SIZE 16 314#define MHD_MD5_DIGEST_SIZE 16
306 315
307 316
308/** 317/**
@@ -463,27 +472,39 @@ _MHD_DEPR_MACRO("Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG
463/* Deprecated codes */ 472/* Deprecated codes */
464/** @deprecated */ 473/** @deprecated */
465#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \ 474#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \
466 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") 406 475 _MHD_DEPR_IN_MACRO ( \
476 "Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") \
477 406
467 478
468/** @deprecated */ 479/** @deprecated */
469#define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE \ 480#define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE \
470 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_PAYLOAD_TOO_LARGE") 413 481 _MHD_DEPR_IN_MACRO ( \
482 "Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_PAYLOAD_TOO_LARGE") \
483 413
471 484
472/** @deprecated */ 485/** @deprecated */
473#define MHD_HTTP_REQUEST_URI_TOO_LONG \ 486#define MHD_HTTP_REQUEST_URI_TOO_LONG \
474 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG") 414 487 _MHD_DEPR_IN_MACRO ( \
488 "Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG") \
489 414
475 490
476/** @deprecated */ 491/** @deprecated */
477#define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE \ 492#define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE \
478 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE") 416 493 _MHD_DEPR_IN_MACRO ( \
494 "Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE") \
495 416
479 496
480/** @deprecated */ 497/** @deprecated */
481#define MHD_HTTP_UNORDERED_COLLECTION \ 498#define MHD_HTTP_UNORDERED_COLLECTION \
482 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_UNORDERED_COLLECTION is deprecated as it was removed from RFC") 425 499 _MHD_DEPR_IN_MACRO ( \
500 "Value MHD_HTTP_UNORDERED_COLLECTION is deprecated as it was removed from RFC") \
501 425
483 502
484/** @deprecated */ 503/** @deprecated */
485#define MHD_HTTP_NO_RESPONSE \ 504#define MHD_HTTP_NO_RESPONSE \
486 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_NO_RESPONSE is deprecated as it is nginx internal code for logs only") 444 505 _MHD_DEPR_IN_MACRO ( \
506 "Value MHD_HTTP_NO_RESPONSE is deprecated as it is nginx internal code for logs only") \
507 444
487 508
488 509
489/** @} */ /* end of group httpcode */ 510/** @} */ /* end of group httpcode */
@@ -504,7 +525,7 @@ MHD_get_reason_phrase_for (unsigned int code);
504 * with the SHOUTcast "ICY" line instad of "HTTP". 525 * with the SHOUTcast "ICY" line instad of "HTTP".
505 * @ingroup specialized 526 * @ingroup specialized
506 */ 527 */
507#define MHD_ICY_FLAG ((uint32_t)(((uint32_t)1) << 31)) 528#define MHD_ICY_FLAG ((uint32_t) (((uint32_t) 1) << 31))
508 529
509/** 530/**
510 * @defgroup headers HTTP headers 531 * @defgroup headers HTTP headers
@@ -712,7 +733,8 @@ MHD_get_reason_phrase_for (unsigned int code);
712/* Standard. RFC6638 */ 733/* Standard. RFC6638 */
713#define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match" 734#define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match"
714/* Standard. RFC8473 */ 735/* Standard. RFC8473 */
715#define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID "Include-Referred-Token-Binding-ID" 736#define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \
737 "Include-Referred-Token-Binding-ID"
716/* No category. RFC4229 */ 738/* No category. RFC4229 */
717#define MHD_HTTP_HEADER_KEEP_ALIVE "Keep-Alive" 739#define MHD_HTTP_HEADER_KEEP_ALIVE "Keep-Alive"
718/* No category. RFC4229 */ 740/* No category. RFC4229 */
@@ -776,7 +798,8 @@ MHD_get_reason_phrase_for (unsigned int code);
776/* Standard. RFC7469 */ 798/* Standard. RFC7469 */
777#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins" 799#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
778/* Standard. RFC7469 */ 800/* Standard. RFC7469 */
779#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY "Public-Key-Pins-Report-Only" 801#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
802 "Public-Key-Pins-Report-Only"
780/* No category. RFC4437 */ 803/* No category. RFC4437 */
781#define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref" 804#define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
782/* Standard. RFC8555, Section 6.5.1 */ 805/* Standard. RFC8555, Section 6.5.1 */
@@ -843,7 +866,8 @@ MHD_get_reason_phrase_for (unsigned int code);
843#define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options" 866#define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
844 867
845/* Some provisional headers. */ 868/* Some provisional headers. */
846#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN "Access-Control-Allow-Origin" 869#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
870 "Access-Control-Allow-Origin"
847/** @} */ /* end of group headers */ 871/** @} */ /* end of group headers */
848 872
849/** 873/**
@@ -954,7 +978,8 @@ MHD_get_reason_phrase_for (unsigned int code);
954 * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4 978 * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
955 * @{ 979 * @{
956 */ 980 */
957#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded" 981#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED \
982 "application/x-www-form-urlencoded"
958#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data" 983#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
959 984
960/** @} */ /* end of group postenc */ 985/** @} */ /* end of group postenc */
@@ -1031,7 +1056,7 @@ enum MHD_FLAG
1031#if 0 1056#if 0
1032 /* let's do this later once versions that define MHD_USE_TLS a more widely deployed. */ 1057 /* let's do this later once versions that define MHD_USE_TLS a more widely deployed. */
1033#define MHD_USE_SSL \ 1058#define MHD_USE_SSL \
1034 _MHD_DEPR_IN_MACRO("Value MHD_USE_SSL is deprecated, use MHD_USE_TLS") \ 1059 _MHD_DEPR_IN_MACRO ("Value MHD_USE_SSL is deprecated, use MHD_USE_TLS") \
1035 MHD_USE_TLS 1060 MHD_USE_TLS
1036#endif 1061#endif
1037 1062
@@ -1056,7 +1081,8 @@ enum MHD_FLAG
1056 MHD_USE_SELECT_INTERNALLY = 8, 1081 MHD_USE_SELECT_INTERNALLY = 8,
1057#if 0 /* Will be marked for real deprecation later. */ 1082#if 0 /* Will be marked for real deprecation later. */
1058#define MHD_USE_SELECT_INTERNALLY \ 1083#define MHD_USE_SELECT_INTERNALLY \
1059 _MHD_DEPR_IN_MACRO("Value MHD_USE_SELECT_INTERNALLY is deprecated, use MHD_USE_INTERNAL_POLLING_THREAD instead") \ 1084 _MHD_DEPR_IN_MACRO ( \
1085 "Value MHD_USE_SELECT_INTERNALLY is deprecated, use MHD_USE_INTERNAL_POLLING_THREAD instead") \
1060 MHD_USE_INTERNAL_POLLING_THREAD 1086 MHD_USE_INTERNAL_POLLING_THREAD
1061#endif /* 0 */ 1087#endif /* 0 */
1062 1088
@@ -1081,7 +1107,8 @@ enum MHD_FLAG
1081 MHD_USE_PEDANTIC_CHECKS = 32, 1107 MHD_USE_PEDANTIC_CHECKS = 32,
1082#if 0 /* Will be marked for real deprecation later. */ 1108#if 0 /* Will be marked for real deprecation later. */
1083#define MHD_USE_PEDANTIC_CHECKS \ 1109#define MHD_USE_PEDANTIC_CHECKS \
1084 _MHD_DEPR_IN_MACRO("Flag MHD_USE_PEDANTIC_CHECKS is deprecated, use option MHD_OPTION_STRICT_FOR_CLIENT instead") \ 1110 _MHD_DEPR_IN_MACRO ( \
1111 "Flag MHD_USE_PEDANTIC_CHECKS is deprecated, use option MHD_OPTION_STRICT_FOR_CLIENT instead") \
1085 32 1112 32
1086#endif /* 0 */ 1113#endif /* 0 */
1087 1114
@@ -1105,7 +1132,8 @@ enum MHD_FLAG
1105 MHD_USE_POLL_INTERNALLY = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD, 1132 MHD_USE_POLL_INTERNALLY = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD,
1106#if 0 /* Will be marked for real deprecation later. */ 1133#if 0 /* Will be marked for real deprecation later. */
1107#define MHD_USE_POLL_INTERNALLY \ 1134#define MHD_USE_POLL_INTERNALLY \
1108 _MHD_DEPR_IN_MACRO("Value MHD_USE_POLL_INTERNALLY is deprecated, use MHD_USE_POLL_INTERNAL_THREAD instead") \ 1135 _MHD_DEPR_IN_MACRO ( \
1136 "Value MHD_USE_POLL_INTERNALLY is deprecated, use MHD_USE_POLL_INTERNAL_THREAD instead") \
1109 MHD_USE_POLL_INTERNAL_THREAD 1137 MHD_USE_POLL_INTERNAL_THREAD
1110#endif /* 0 */ 1138#endif /* 0 */
1111 1139
@@ -1121,7 +1149,8 @@ enum MHD_FLAG
1121 MHD_SUPPRESS_DATE_NO_CLOCK = 128, 1149 MHD_SUPPRESS_DATE_NO_CLOCK = 128,
1122#if 0 /* Will be marked for real deprecation later. */ 1150#if 0 /* Will be marked for real deprecation later. */
1123#define MHD_SUPPRESS_DATE_NO_CLOCK \ 1151#define MHD_SUPPRESS_DATE_NO_CLOCK \
1124 _MHD_DEPR_IN_MACRO("Value MHD_SUPPRESS_DATE_NO_CLOCK is deprecated, use MHD_USE_SUPPRESS_DATE_NO_CLOCK instead") \ 1152 _MHD_DEPR_IN_MACRO ( \
1153 "Value MHD_SUPPRESS_DATE_NO_CLOCK is deprecated, use MHD_USE_SUPPRESS_DATE_NO_CLOCK instead") \
1125 MHD_USE_SUPPRESS_DATE_NO_CLOCK 1154 MHD_USE_SUPPRESS_DATE_NO_CLOCK
1126#endif /* 0 */ 1155#endif /* 0 */
1127 1156
@@ -1147,7 +1176,8 @@ enum MHD_FLAG
1147 MHD_USE_EPOLL_LINUX_ONLY = 512, 1176 MHD_USE_EPOLL_LINUX_ONLY = 512,
1148#if 0 /* Will be marked for real deprecation later. */ 1177#if 0 /* Will be marked for real deprecation later. */
1149#define MHD_USE_EPOLL_LINUX_ONLY \ 1178#define MHD_USE_EPOLL_LINUX_ONLY \
1150 _MHD_DEPR_IN_MACRO("Value MHD_USE_EPOLL_LINUX_ONLY is deprecated, use MHD_USE_EPOLL") \ 1179 _MHD_DEPR_IN_MACRO ( \
1180 "Value MHD_USE_EPOLL_LINUX_ONLY is deprecated, use MHD_USE_EPOLL") \
1151 MHD_USE_EPOLL 1181 MHD_USE_EPOLL
1152#endif /* 0 */ 1182#endif /* 0 */
1153 1183
@@ -1157,19 +1187,23 @@ enum MHD_FLAG
1157 * platform without `epoll` support will cause #MHD_start_daemon to fail. 1187 * platform without `epoll` support will cause #MHD_start_daemon to fail.
1158 * @sa ::MHD_FEATURE_EPOLL, #MHD_USE_EPOLL, #MHD_USE_INTERNAL_POLLING_THREAD 1188 * @sa ::MHD_FEATURE_EPOLL, #MHD_USE_EPOLL, #MHD_USE_INTERNAL_POLLING_THREAD
1159 */ 1189 */
1160 MHD_USE_EPOLL_INTERNAL_THREAD = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD, 1190 MHD_USE_EPOLL_INTERNAL_THREAD = MHD_USE_EPOLL
1191 | MHD_USE_INTERNAL_POLLING_THREAD,
1161 1192
1162 /** @deprecated */ 1193 /** @deprecated */
1163 MHD_USE_EPOLL_INTERNALLY = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD, 1194 MHD_USE_EPOLL_INTERNALLY = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD,
1164 /** @deprecated */ 1195 /** @deprecated */
1165 MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD, 1196 MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY = MHD_USE_EPOLL
1197 | MHD_USE_INTERNAL_POLLING_THREAD,
1166#if 0 /* Will be marked for real deprecation later. */ 1198#if 0 /* Will be marked for real deprecation later. */
1167#define MHD_USE_EPOLL_INTERNALLY \ 1199#define MHD_USE_EPOLL_INTERNALLY \
1168 _MHD_DEPR_IN_MACRO("Value MHD_USE_EPOLL_INTERNALLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \ 1200 _MHD_DEPR_IN_MACRO ( \
1201 "Value MHD_USE_EPOLL_INTERNALLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
1169 MHD_USE_EPOLL_INTERNAL_THREAD 1202 MHD_USE_EPOLL_INTERNAL_THREAD
1170 /** @deprecated */ 1203 /** @deprecated */
1171#define MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY \ 1204#define MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY \
1172 _MHD_DEPR_IN_MACRO("Value MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \ 1205 _MHD_DEPR_IN_MACRO ( \
1206 "Value MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
1173 MHD_USE_EPOLL_INTERNAL_THREAD 1207 MHD_USE_EPOLL_INTERNAL_THREAD
1174#endif /* 0 */ 1208#endif /* 0 */
1175 1209
@@ -1191,7 +1225,8 @@ enum MHD_FLAG
1191 MHD_USE_PIPE_FOR_SHUTDOWN = 1024, 1225 MHD_USE_PIPE_FOR_SHUTDOWN = 1024,
1192#if 0 /* Will be marked for real deprecation later. */ 1226#if 0 /* Will be marked for real deprecation later. */
1193#define MHD_USE_PIPE_FOR_SHUTDOWN \ 1227#define MHD_USE_PIPE_FOR_SHUTDOWN \
1194 _MHD_DEPR_IN_MACRO("Value MHD_USE_PIPE_FOR_SHUTDOWN is deprecated, use MHD_USE_ITC") \ 1228 _MHD_DEPR_IN_MACRO ( \
1229 "Value MHD_USE_PIPE_FOR_SHUTDOWN is deprecated, use MHD_USE_ITC") \
1195 MHD_USE_ITC 1230 MHD_USE_ITC
1196#endif /* 0 */ 1231#endif /* 0 */
1197 1232
@@ -1212,7 +1247,8 @@ enum MHD_FLAG
1212 MHD_USE_EPOLL_TURBO = 4096, 1247 MHD_USE_EPOLL_TURBO = 4096,
1213#if 0 /* Will be marked for real deprecation later. */ 1248#if 0 /* Will be marked for real deprecation later. */
1214#define MHD_USE_EPOLL_TURBO \ 1249#define MHD_USE_EPOLL_TURBO \
1215 _MHD_DEPR_IN_MACRO("Value MHD_USE_EPOLL_TURBO is deprecated, use MHD_USE_TURBO") \ 1250 _MHD_DEPR_IN_MACRO ( \
1251 "Value MHD_USE_EPOLL_TURBO is deprecated, use MHD_USE_TURBO") \
1216 MHD_USE_TURBO 1252 MHD_USE_TURBO
1217#endif /* 0 */ 1253#endif /* 0 */
1218 1254
@@ -1226,7 +1262,8 @@ enum MHD_FLAG
1226 MHD_USE_SUSPEND_RESUME = 8192 | MHD_USE_ITC, 1262 MHD_USE_SUSPEND_RESUME = 8192 | MHD_USE_ITC,
1227#if 0 /* Will be marked for real deprecation later. */ 1263#if 0 /* Will be marked for real deprecation later. */
1228#define MHD_USE_SUSPEND_RESUME \ 1264#define MHD_USE_SUSPEND_RESUME \
1229 _MHD_DEPR_IN_MACRO("Value MHD_USE_SUSPEND_RESUME is deprecated, use MHD_ALLOW_SUSPEND_RESUME instead") \ 1265 _MHD_DEPR_IN_MACRO ( \
1266 "Value MHD_USE_SUSPEND_RESUME is deprecated, use MHD_ALLOW_SUSPEND_RESUME instead") \
1230 MHD_ALLOW_SUSPEND_RESUME 1267 MHD_ALLOW_SUSPEND_RESUME
1231#endif /* 0 */ 1268#endif /* 0 */
1232 1269
@@ -1269,13 +1306,13 @@ enum MHD_FLAG
1269 * Flag set to enable post-handshake client authentication 1306 * Flag set to enable post-handshake client authentication
1270 * (only useful in combination with #MHD_USE_TLS). 1307 * (only useful in combination with #MHD_USE_TLS).
1271 */ 1308 */
1272 MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT = 1U <<17, 1309 MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT = 1U << 17,
1273 1310
1274 /** 1311 /**
1275 * Flag set to enable TLS 1.3 early data. This has 1312 * Flag set to enable TLS 1.3 early data. This has
1276 * security implications, be VERY careful when using this. 1313 * security implications, be VERY careful when using this.
1277 */ 1314 */
1278 MHD_USE_INSECURE_TLS_EARLY_DATA = 1U <<18 1315 MHD_USE_INSECURE_TLS_EARLY_DATA = 1U << 18
1279 1316
1280}; 1317};
1281 1318
@@ -1308,10 +1345,10 @@ typedef void
1308 */ 1345 */
1309typedef int 1346typedef int
1310(*MHD_PskServerCredentialsCallback)(void *cls, 1347(*MHD_PskServerCredentialsCallback)(void *cls,
1311 const struct MHD_Connection *connection, 1348 const struct MHD_Connection *connection,
1312 const char *username, 1349 const char *username,
1313 void **psk, 1350 void **psk,
1314 size_t *psk_size); 1351 size_t *psk_size);
1315 1352
1316/** 1353/**
1317 * @brief MHD options. 1354 * @brief MHD options.
@@ -1654,7 +1691,7 @@ enum MHD_OPTION
1654 * followed by a argument of type `gnutls_certificate_retrieve_function3 *`. 1691 * followed by a argument of type `gnutls_certificate_retrieve_function3 *`.
1655 * This option provides an 1692 * This option provides an
1656 * alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK. 1693 * alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK.
1657 * You must use this version if you want to use OCSP stapling. 1694 * You must use this version if you want to use OCSP stapling.
1658 * Using this option requires GnuTLS 3.6.3 or higher. 1695 * Using this option requires GnuTLS 3.6.3 or higher.
1659 */ 1696 */
1660 MHD_OPTION_HTTPS_CERT_CALLBACK2 = 31 1697 MHD_OPTION_HTTPS_CERT_CALLBACK2 = 31
@@ -1701,7 +1738,8 @@ enum MHD_ValueKind
1701 */ 1738 */
1702 MHD_RESPONSE_HEADER_KIND = 0, 1739 MHD_RESPONSE_HEADER_KIND = 0,
1703#define MHD_RESPONSE_HEADER_KIND \ 1740#define MHD_RESPONSE_HEADER_KIND \
1704 _MHD_DEPR_IN_MACRO("Value MHD_RESPONSE_HEADER_KIND is deprecated and not used") \ 1741 _MHD_DEPR_IN_MACRO ( \
1742 "Value MHD_RESPONSE_HEADER_KIND is deprecated and not used") \
1705 MHD_RESPONSE_HEADER_KIND 1743 MHD_RESPONSE_HEADER_KIND
1706 1744
1707 /** 1745 /**
@@ -2197,11 +2235,11 @@ typedef int
2197 */ 2235 */
2198typedef int 2236typedef int
2199(*MHD_KeyValueIteratorN) (void *cls, 2237(*MHD_KeyValueIteratorN) (void *cls,
2200 enum MHD_ValueKind kind, 2238 enum MHD_ValueKind kind,
2201 const char *key, 2239 const char *key,
2202 size_t key_size, 2240 size_t key_size,
2203 const char *value, 2241 const char *value,
2204 size_t value_size); 2242 size_t value_size);
2205 2243
2206 2244
2207/** 2245/**
@@ -2323,10 +2361,10 @@ typedef int
2323 */ 2361 */
2324_MHD_EXTERN struct MHD_Daemon * 2362_MHD_EXTERN struct MHD_Daemon *
2325MHD_start_daemon_va (unsigned int flags, 2363MHD_start_daemon_va (unsigned int flags,
2326 uint16_t port, 2364 uint16_t port,
2327 MHD_AcceptPolicyCallback apc, void *apc_cls, 2365 MHD_AcceptPolicyCallback apc, void *apc_cls,
2328 MHD_AccessHandlerCallback dh, void *dh_cls, 2366 MHD_AccessHandlerCallback dh, void *dh_cls,
2329 va_list ap); 2367 va_list ap);
2330 2368
2331 2369
2332/** 2370/**
@@ -2351,10 +2389,10 @@ MHD_start_daemon_va (unsigned int flags,
2351 */ 2389 */
2352_MHD_EXTERN struct MHD_Daemon * 2390_MHD_EXTERN struct MHD_Daemon *
2353MHD_start_daemon (unsigned int flags, 2391MHD_start_daemon (unsigned int flags,
2354 uint16_t port, 2392 uint16_t port,
2355 MHD_AcceptPolicyCallback apc, void *apc_cls, 2393 MHD_AcceptPolicyCallback apc, void *apc_cls,
2356 MHD_AccessHandlerCallback dh, void *dh_cls, 2394 MHD_AccessHandlerCallback dh, void *dh_cls,
2357 ...); 2395 ...);
2358 2396
2359 2397
2360/** 2398/**
@@ -2419,9 +2457,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon);
2419 */ 2457 */
2420_MHD_EXTERN int 2458_MHD_EXTERN int
2421MHD_add_connection (struct MHD_Daemon *daemon, 2459MHD_add_connection (struct MHD_Daemon *daemon,
2422 MHD_socket client_socket, 2460 MHD_socket client_socket,
2423 const struct sockaddr *addr, 2461 const struct sockaddr *addr,
2424 socklen_t addrlen); 2462 socklen_t addrlen);
2425 2463
2426 2464
2427/** 2465/**
@@ -2457,8 +2495,8 @@ _MHD_EXTERN int
2457MHD_get_fdset (struct MHD_Daemon *daemon, 2495MHD_get_fdset (struct MHD_Daemon *daemon,
2458 fd_set *read_fd_set, 2496 fd_set *read_fd_set,
2459 fd_set *write_fd_set, 2497 fd_set *write_fd_set,
2460 fd_set *except_fd_set, 2498 fd_set *except_fd_set,
2461 MHD_socket *max_fd); 2499 MHD_socket *max_fd);
2462 2500
2463 2501
2464/** 2502/**
@@ -2495,11 +2533,11 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
2495 */ 2533 */
2496_MHD_EXTERN int 2534_MHD_EXTERN int
2497MHD_get_fdset2 (struct MHD_Daemon *daemon, 2535MHD_get_fdset2 (struct MHD_Daemon *daemon,
2498 fd_set *read_fd_set, 2536 fd_set *read_fd_set,
2499 fd_set *write_fd_set, 2537 fd_set *write_fd_set,
2500 fd_set *except_fd_set, 2538 fd_set *except_fd_set,
2501 MHD_socket *max_fd, 2539 MHD_socket *max_fd,
2502 unsigned int fd_setsize); 2540 unsigned int fd_setsize);
2503 2541
2504 2542
2505/** 2543/**
@@ -2527,7 +2565,8 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
2527 * @ingroup event 2565 * @ingroup event
2528 */ 2566 */
2529#define MHD_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \ 2567#define MHD_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \
2530 MHD_get_fdset2((daemon),(read_fd_set),(write_fd_set),(except_fd_set),(max_fd),FD_SETSIZE) 2568 MHD_get_fdset2 ((daemon),(read_fd_set),(write_fd_set),(except_fd_set), \
2569 (max_fd),FD_SETSIZE)
2531 2570
2532 2571
2533/** 2572/**
@@ -2550,7 +2589,7 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
2550 */ 2589 */
2551_MHD_EXTERN int 2590_MHD_EXTERN int
2552MHD_get_timeout (struct MHD_Daemon *daemon, 2591MHD_get_timeout (struct MHD_Daemon *daemon,
2553 MHD_UNSIGNED_LONG_LONG *timeout); 2592 MHD_UNSIGNED_LONG_LONG *timeout);
2554 2593
2555 2594
2556/** 2595/**
@@ -2601,9 +2640,9 @@ MHD_run (struct MHD_Daemon *daemon);
2601 */ 2640 */
2602_MHD_EXTERN int 2641_MHD_EXTERN int
2603MHD_run_from_select (struct MHD_Daemon *daemon, 2642MHD_run_from_select (struct MHD_Daemon *daemon,
2604 const fd_set *read_fd_set, 2643 const fd_set *read_fd_set,
2605 const fd_set *write_fd_set, 2644 const fd_set *write_fd_set,
2606 const fd_set *except_fd_set); 2645 const fd_set *except_fd_set);
2607 2646
2608 2647
2609 2648
@@ -2678,7 +2717,7 @@ _MHD_EXTERN int
2678MHD_set_connection_value (struct MHD_Connection *connection, 2717MHD_set_connection_value (struct MHD_Connection *connection,
2679 enum MHD_ValueKind kind, 2718 enum MHD_ValueKind kind,
2680 const char *key, 2719 const char *key,
2681 const char *value); 2720 const char *value);
2682 2721
2683 2722
2684/** 2723/**
@@ -2708,11 +2747,11 @@ MHD_set_connection_value (struct MHD_Connection *connection,
2708 */ 2747 */
2709int 2748int
2710MHD_set_connection_value_n (struct MHD_Connection *connection, 2749MHD_set_connection_value_n (struct MHD_Connection *connection,
2711 enum MHD_ValueKind kind, 2750 enum MHD_ValueKind kind,
2712 const char *key, 2751 const char *key,
2713 size_t key_size, 2752 size_t key_size,
2714 const char *value, 2753 const char *value,
2715 size_t value_size); 2754 size_t value_size);
2716 2755
2717 2756
2718/** 2757/**
@@ -2760,8 +2799,8 @@ MHD_http_unescape (char *val);
2760 */ 2799 */
2761_MHD_EXTERN const char * 2800_MHD_EXTERN const char *
2762MHD_lookup_connection_value (struct MHD_Connection *connection, 2801MHD_lookup_connection_value (struct MHD_Connection *connection,
2763 enum MHD_ValueKind kind, 2802 enum MHD_ValueKind kind,
2764 const char *key); 2803 const char *key);
2765 2804
2766 2805
2767/** 2806/**
@@ -2806,7 +2845,7 @@ MHD_lookup_connection_value_n (struct MHD_Connection *connection,
2806_MHD_EXTERN int 2845_MHD_EXTERN int
2807MHD_queue_response (struct MHD_Connection *connection, 2846MHD_queue_response (struct MHD_Connection *connection,
2808 unsigned int status_code, 2847 unsigned int status_code,
2809 struct MHD_Response *response); 2848 struct MHD_Response *response);
2810 2849
2811 2850
2812/** 2851/**
@@ -2934,9 +2973,9 @@ MHD_set_response_options (struct MHD_Response *response,
2934 */ 2973 */
2935_MHD_EXTERN struct MHD_Response * 2974_MHD_EXTERN struct MHD_Response *
2936MHD_create_response_from_callback (uint64_t size, 2975MHD_create_response_from_callback (uint64_t size,
2937 size_t block_size, 2976 size_t block_size,
2938 MHD_ContentReaderCallback crc, void *crc_cls, 2977 MHD_ContentReaderCallback crc, void *crc_cls,
2939 MHD_ContentReaderFreeCallback crfc); 2978 MHD_ContentReaderFreeCallback crfc);
2940 2979
2941 2980
2942/** 2981/**
@@ -2953,12 +2992,13 @@ MHD_create_response_from_callback (uint64_t size,
2953 * @deprecated use #MHD_create_response_from_buffer instead 2992 * @deprecated use #MHD_create_response_from_buffer instead
2954 * @ingroup response 2993 * @ingroup response
2955 */ 2994 */
2956_MHD_DEPR_FUNC("MHD_create_response_from_data() is deprecated, use MHD_create_response_from_buffer()") \ 2995_MHD_DEPR_FUNC (
2957_MHD_EXTERN struct MHD_Response * 2996 "MHD_create_response_from_data() is deprecated, use MHD_create_response_from_buffer()") \
2997 _MHD_EXTERN struct MHD_Response *
2958MHD_create_response_from_data (size_t size, 2998MHD_create_response_from_data (size_t size,
2959 void *data, 2999 void *data,
2960 int must_free, 3000 int must_free,
2961 int must_copy); 3001 int must_copy);
2962 3002
2963 3003
2964/** 3004/**
@@ -3009,8 +3049,8 @@ enum MHD_ResponseMemoryMode
3009 */ 3049 */
3010_MHD_EXTERN struct MHD_Response * 3050_MHD_EXTERN struct MHD_Response *
3011MHD_create_response_from_buffer (size_t size, 3051MHD_create_response_from_buffer (size_t size,
3012 void *buffer, 3052 void *buffer,
3013 enum MHD_ResponseMemoryMode mode); 3053 enum MHD_ResponseMemoryMode mode);
3014 3054
3015 3055
3016 3056
@@ -3027,8 +3067,9 @@ MHD_create_response_from_buffer (size_t size,
3027 */ 3067 */
3028_MHD_EXTERN struct MHD_Response * 3068_MHD_EXTERN struct MHD_Response *
3029MHD_create_response_from_buffer_with_free_callback (size_t size, 3069MHD_create_response_from_buffer_with_free_callback (size_t size,
3030 void *buffer, 3070 void *buffer,
3031 MHD_ContentReaderFreeCallback crfc); 3071 MHD_ContentReaderFreeCallback
3072 crfc);
3032 3073
3033 3074
3034/** 3075/**
@@ -3044,7 +3085,7 @@ MHD_create_response_from_buffer_with_free_callback (size_t size,
3044 */ 3085 */
3045_MHD_EXTERN struct MHD_Response * 3086_MHD_EXTERN struct MHD_Response *
3046MHD_create_response_from_fd (size_t size, 3087MHD_create_response_from_fd (size_t size,
3047 int fd); 3088 int fd);
3048 3089
3049 3090
3050/** 3091/**
@@ -3081,18 +3122,20 @@ MHD_create_response_from_fd64 (uint64_t size,
3081 * @return NULL on error (i.e. invalid arguments, out of memory) 3122 * @return NULL on error (i.e. invalid arguments, out of memory)
3082 * @ingroup response 3123 * @ingroup response
3083 */ 3124 */
3084_MHD_DEPR_FUNC("Function MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \ 3125_MHD_DEPR_FUNC (
3085_MHD_EXTERN struct MHD_Response * 3126 "Function MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \
3127 _MHD_EXTERN struct MHD_Response *
3086MHD_create_response_from_fd_at_offset (size_t size, 3128MHD_create_response_from_fd_at_offset (size_t size,
3087 int fd, 3129 int fd,
3088 off_t offset); 3130 off_t offset);
3089 3131
3090#if !defined(_MHD_NO_DEPR_IN_MACRO) || defined(_MHD_NO_DEPR_FUNC) 3132#if ! defined(_MHD_NO_DEPR_IN_MACRO) || defined(_MHD_NO_DEPR_FUNC)
3091/* Substitute MHD_create_response_from_fd_at_offset64() instead of MHD_create_response_from_fd_at_offset() 3133/* Substitute MHD_create_response_from_fd_at_offset64() instead of MHD_create_response_from_fd_at_offset()
3092 to minimize potential problems with different off_t sizes */ 3134 to minimize potential problems with different off_t sizes */
3093#define MHD_create_response_from_fd_at_offset(size,fd,offset) \ 3135#define MHD_create_response_from_fd_at_offset(size,fd,offset) \
3094 _MHD_DEPR_IN_MACRO("Usage of MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \ 3136 _MHD_DEPR_IN_MACRO ( \
3095 MHD_create_response_from_fd_at_offset64((size),(fd),(offset)) 3137 "Usage of MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \
3138 MHD_create_response_from_fd_at_offset64 ((size),(fd),(offset))
3096#endif /* !_MHD_NO_DEPR_IN_MACRO || _MHD_NO_DEPR_FUNC */ 3139#endif /* !_MHD_NO_DEPR_IN_MACRO || _MHD_NO_DEPR_FUNC */
3097 3140
3098 3141
@@ -3261,7 +3304,7 @@ typedef void
3261 */ 3304 */
3262_MHD_EXTERN struct MHD_Response * 3305_MHD_EXTERN struct MHD_Response *
3263MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, 3306MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
3264 void *upgrade_handler_cls); 3307 void *upgrade_handler_cls);
3265 3308
3266 3309
3267/** 3310/**
@@ -3290,7 +3333,7 @@ MHD_destroy_response (struct MHD_Response *response);
3290_MHD_EXTERN int 3333_MHD_EXTERN int
3291MHD_add_response_header (struct MHD_Response *response, 3334MHD_add_response_header (struct MHD_Response *response,
3292 const char *header, 3335 const char *header,
3293 const char *content); 3336 const char *content);
3294 3337
3295 3338
3296/** 3339/**
@@ -3305,7 +3348,7 @@ MHD_add_response_header (struct MHD_Response *response,
3305_MHD_EXTERN int 3348_MHD_EXTERN int
3306MHD_add_response_footer (struct MHD_Response *response, 3349MHD_add_response_footer (struct MHD_Response *response,
3307 const char *footer, 3350 const char *footer,
3308 const char *content); 3351 const char *content);
3309 3352
3310 3353
3311/** 3354/**
@@ -3320,7 +3363,7 @@ MHD_add_response_footer (struct MHD_Response *response,
3320_MHD_EXTERN int 3363_MHD_EXTERN int
3321MHD_del_response_header (struct MHD_Response *response, 3364MHD_del_response_header (struct MHD_Response *response,
3322 const char *header, 3365 const char *header,
3323 const char *content); 3366 const char *content);
3324 3367
3325 3368
3326/** 3369/**
@@ -3336,7 +3379,7 @@ MHD_del_response_header (struct MHD_Response *response,
3336_MHD_EXTERN int 3379_MHD_EXTERN int
3337MHD_get_response_headers (struct MHD_Response *response, 3380MHD_get_response_headers (struct MHD_Response *response,
3338 MHD_KeyValueIterator iterator, 3381 MHD_KeyValueIterator iterator,
3339 void *iterator_cls); 3382 void *iterator_cls);
3340 3383
3341 3384
3342/** 3385/**
@@ -3349,7 +3392,7 @@ MHD_get_response_headers (struct MHD_Response *response,
3349 */ 3392 */
3350_MHD_EXTERN const char * 3393_MHD_EXTERN const char *
3351MHD_get_response_header (struct MHD_Response *response, 3394MHD_get_response_header (struct MHD_Response *response,
3352 const char *key); 3395 const char *key);
3353 3396
3354 3397
3355/* ********************** PostProcessor functions ********************** */ 3398/* ********************** PostProcessor functions ********************** */
@@ -3381,8 +3424,8 @@ MHD_get_response_header (struct MHD_Response *response,
3381 */ 3424 */
3382_MHD_EXTERN struct MHD_PostProcessor * 3425_MHD_EXTERN struct MHD_PostProcessor *
3383MHD_create_post_processor (struct MHD_Connection *connection, 3426MHD_create_post_processor (struct MHD_Connection *connection,
3384 size_t buffer_size, 3427 size_t buffer_size,
3385 MHD_PostDataIterator iter, void *iter_cls); 3428 MHD_PostDataIterator iter, void *iter_cls);
3386 3429
3387 3430
3388/** 3431/**
@@ -3433,7 +3476,7 @@ MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
3433 * 3476 *
3434 * @param connection The MHD connection structure 3477 * @param connection The MHD connection structure
3435 * @return NULL if no username could be found, a pointer 3478 * @return NULL if no username could be found, a pointer
3436 * to the username if found, free using #MHD_free(). 3479 * to the username if found, free using #MHD_free().
3437 * @ingroup authentication 3480 * @ingroup authentication
3438 */ 3481 */
3439_MHD_EXTERN char * 3482_MHD_EXTERN char *
@@ -3455,7 +3498,8 @@ MHD_free (void *ptr);
3455/** 3498/**
3456 * Which digest algorithm should MHD use for HTTP digest authentication? 3499 * Which digest algorithm should MHD use for HTTP digest authentication?
3457 */ 3500 */
3458enum MHD_DigestAuthAlgorithm { 3501enum MHD_DigestAuthAlgorithm
3502{
3459 3503
3460 /** 3504 /**
3461 * MHD should pick (currently defaults to SHA-256). 3505 * MHD should pick (currently defaults to SHA-256).
@@ -3483,19 +3527,19 @@ enum MHD_DigestAuthAlgorithm {
3483 * @param username The username needs to be authenticated 3527 * @param username The username needs to be authenticated
3484 * @param password The password used in the authentication 3528 * @param password The password used in the authentication
3485 * @param nonce_timeout The amount of time for a nonce to be 3529 * @param nonce_timeout The amount of time for a nonce to be
3486 * invalid in seconds 3530 * invalid in seconds
3487 * @param algo digest algorithms allowed for verification 3531 * @param algo digest algorithms allowed for verification
3488 * @return #MHD_YES if authenticated, #MHD_NO if not, 3532 * @return #MHD_YES if authenticated, #MHD_NO if not,
3489 * #MHD_INVALID_NONCE if nonce is invalid 3533 * #MHD_INVALID_NONCE if nonce is invalid
3490 * @ingroup authentication 3534 * @ingroup authentication
3491 */ 3535 */
3492_MHD_EXTERN int 3536_MHD_EXTERN int
3493MHD_digest_auth_check2 (struct MHD_Connection *connection, 3537MHD_digest_auth_check2 (struct MHD_Connection *connection,
3494 const char *realm, 3538 const char *realm,
3495 const char *username, 3539 const char *username,
3496 const char *password, 3540 const char *password,
3497 unsigned int nonce_timeout, 3541 unsigned int nonce_timeout,
3498 enum MHD_DigestAuthAlgorithm algo); 3542 enum MHD_DigestAuthAlgorithm algo);
3499 3543
3500 3544
3501/** 3545/**
@@ -3510,18 +3554,18 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection,
3510 * @param username The username needs to be authenticated 3554 * @param username The username needs to be authenticated
3511 * @param password The password used in the authentication 3555 * @param password The password used in the authentication
3512 * @param nonce_timeout The amount of time for a nonce to be 3556 * @param nonce_timeout The amount of time for a nonce to be
3513 * invalid in seconds 3557 * invalid in seconds
3514 * @return #MHD_YES if authenticated, #MHD_NO if not, 3558 * @return #MHD_YES if authenticated, #MHD_NO if not,
3515 * #MHD_INVALID_NONCE if nonce is invalid 3559 * #MHD_INVALID_NONCE if nonce is invalid
3516 * @ingroup authentication 3560 * @ingroup authentication
3517 * @deprecated use MHD_digest_auth_check2() 3561 * @deprecated use MHD_digest_auth_check2()
3518 */ 3562 */
3519_MHD_EXTERN int 3563_MHD_EXTERN int
3520MHD_digest_auth_check (struct MHD_Connection *connection, 3564MHD_digest_auth_check (struct MHD_Connection *connection,
3521 const char *realm, 3565 const char *realm,
3522 const char *username, 3566 const char *username,
3523 const char *password, 3567 const char *password,
3524 unsigned int nonce_timeout); 3568 unsigned int nonce_timeout);
3525 3569
3526 3570
3527/** 3571/**
@@ -3531,24 +3575,24 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
3531 * @param realm The realm presented to the client 3575 * @param realm The realm presented to the client
3532 * @param username The username needs to be authenticated 3576 * @param username The username needs to be authenticated
3533 * @param digest An `unsigned char *' pointer to the binary MD5 sum 3577 * @param digest An `unsigned char *' pointer to the binary MD5 sum
3534 * for the precalculated hash value "username:realm:password" 3578 * for the precalculated hash value "username:realm:password"
3535 * of @a digest_size bytes 3579 * of @a digest_size bytes
3536 * @param digest_size number of bytes in @a digest (size must match @a algo!) 3580 * @param digest_size number of bytes in @a digest (size must match @a algo!)
3537 * @param nonce_timeout The amount of time for a nonce to be 3581 * @param nonce_timeout The amount of time for a nonce to be
3538 * invalid in seconds 3582 * invalid in seconds
3539 * @param algo digest algorithms allowed for verification 3583 * @param algo digest algorithms allowed for verification
3540 * @return #MHD_YES if authenticated, #MHD_NO if not, 3584 * @return #MHD_YES if authenticated, #MHD_NO if not,
3541 * #MHD_INVALID_NONCE if nonce is invalid 3585 * #MHD_INVALID_NONCE if nonce is invalid
3542 * @ingroup authentication 3586 * @ingroup authentication
3543 */ 3587 */
3544_MHD_EXTERN int 3588_MHD_EXTERN int
3545MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, 3589MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
3546 const char *realm, 3590 const char *realm,
3547 const char *username, 3591 const char *username,
3548 const uint8_t *digest, 3592 const uint8_t *digest,
3549 size_t digest_size, 3593 size_t digest_size,
3550 unsigned int nonce_timeout, 3594 unsigned int nonce_timeout,
3551 enum MHD_DigestAuthAlgorithm algo); 3595 enum MHD_DigestAuthAlgorithm algo);
3552 3596
3553 3597
3554/** 3598/**
@@ -3560,21 +3604,21 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
3560 * @param realm The realm presented to the client 3604 * @param realm The realm presented to the client
3561 * @param username The username needs to be authenticated 3605 * @param username The username needs to be authenticated
3562 * @param digest An `unsigned char *' pointer to the binary hash 3606 * @param digest An `unsigned char *' pointer to the binary hash
3563 * for the precalculated hash value "username:realm:password"; 3607 * for the precalculated hash value "username:realm:password";
3564 * length must be #MHD_MD5_DIGEST_SIZE bytes 3608 * length must be #MHD_MD5_DIGEST_SIZE bytes
3565 * @param nonce_timeout The amount of time for a nonce to be 3609 * @param nonce_timeout The amount of time for a nonce to be
3566 * invalid in seconds 3610 * invalid in seconds
3567 * @return #MHD_YES if authenticated, #MHD_NO if not, 3611 * @return #MHD_YES if authenticated, #MHD_NO if not,
3568 * #MHD_INVALID_NONCE if nonce is invalid 3612 * #MHD_INVALID_NONCE if nonce is invalid
3569 * @ingroup authentication 3613 * @ingroup authentication
3570 * @deprecated use #MHD_digest_auth_check_digest2() 3614 * @deprecated use #MHD_digest_auth_check_digest2()
3571 */ 3615 */
3572_MHD_EXTERN int 3616_MHD_EXTERN int
3573MHD_digest_auth_check_digest (struct MHD_Connection *connection, 3617MHD_digest_auth_check_digest (struct MHD_Connection *connection,
3574 const char *realm, 3618 const char *realm,
3575 const char *username, 3619 const char *username,
3576 const uint8_t digest[MHD_MD5_DIGEST_SIZE], 3620 const uint8_t digest[MHD_MD5_DIGEST_SIZE],
3577 unsigned int nonce_timeout); 3621 unsigned int nonce_timeout);
3578 3622
3579 3623
3580/** 3624/**
@@ -3587,18 +3631,18 @@ MHD_digest_auth_check_digest (struct MHD_Connection *connection,
3587 * body; note that this function will set the "WWW Authenticate" 3631 * body; note that this function will set the "WWW Authenticate"
3588 * header and that the caller should not do this 3632 * header and that the caller should not do this
3589 * @param signal_stale #MHD_YES if the nonce is invalid to add 3633 * @param signal_stale #MHD_YES if the nonce is invalid to add
3590 * 'stale=true' to the authentication header 3634 * 'stale=true' to the authentication header
3591 * @param algo digest algorithm to use 3635 * @param algo digest algorithm to use
3592 * @return #MHD_YES on success, #MHD_NO otherwise 3636 * @return #MHD_YES on success, #MHD_NO otherwise
3593 * @ingroup authentication 3637 * @ingroup authentication
3594 */ 3638 */
3595_MHD_EXTERN int 3639_MHD_EXTERN int
3596MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, 3640MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
3597 const char *realm, 3641 const char *realm,
3598 const char *opaque, 3642 const char *opaque,
3599 struct MHD_Response *response, 3643 struct MHD_Response *response,
3600 int signal_stale, 3644 int signal_stale,
3601 enum MHD_DigestAuthAlgorithm algo); 3645 enum MHD_DigestAuthAlgorithm algo);
3602 3646
3603 3647
3604/** 3648/**
@@ -3613,17 +3657,17 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
3613 * body; note that this function will set the "WWW Authenticate" 3657 * body; note that this function will set the "WWW Authenticate"
3614 * header and that the caller should not do this 3658 * header and that the caller should not do this
3615 * @param signal_stale #MHD_YES if the nonce is invalid to add 3659 * @param signal_stale #MHD_YES if the nonce is invalid to add
3616 * 'stale=true' to the authentication header 3660 * 'stale=true' to the authentication header
3617 * @return #MHD_YES on success, #MHD_NO otherwise 3661 * @return #MHD_YES on success, #MHD_NO otherwise
3618 * @ingroup authentication 3662 * @ingroup authentication
3619 * @deprecated use MHD_queue_auth_fail_response2() 3663 * @deprecated use MHD_queue_auth_fail_response2()
3620 */ 3664 */
3621_MHD_EXTERN int 3665_MHD_EXTERN int
3622MHD_queue_auth_fail_response (struct MHD_Connection *connection, 3666MHD_queue_auth_fail_response (struct MHD_Connection *connection,
3623 const char *realm, 3667 const char *realm,
3624 const char *opaque, 3668 const char *opaque,
3625 struct MHD_Response *response, 3669 struct MHD_Response *response,
3626 int signal_stale); 3670 int signal_stale);
3627 3671
3628 3672
3629/** 3673/**
@@ -3632,12 +3676,12 @@ MHD_queue_auth_fail_response (struct MHD_Connection *connection,
3632 * @param connection The MHD connection structure 3676 * @param connection The MHD connection structure
3633 * @param[out] password a pointer for the password, free using #MHD_free(). 3677 * @param[out] password a pointer for the password, free using #MHD_free().
3634 * @return NULL if no username could be found, a pointer 3678 * @return NULL if no username could be found, a pointer
3635 * to the username if found, free using #MHD_free(). 3679 * to the username if found, free using #MHD_free().
3636 * @ingroup authentication 3680 * @ingroup authentication
3637 */ 3681 */
3638_MHD_EXTERN char * 3682_MHD_EXTERN char *
3639MHD_basic_auth_get_username_password (struct MHD_Connection *connection, 3683MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
3640 char** password); 3684 char**password);
3641 3685
3642 3686
3643/** 3687/**
@@ -3654,8 +3698,8 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
3654 */ 3698 */
3655_MHD_EXTERN int 3699_MHD_EXTERN int
3656MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, 3700MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
3657 const char *realm, 3701 const char *realm,
3658 struct MHD_Response *response); 3702 struct MHD_Response *response);
3659 3703
3660/* ********************** generic query functions ********************** */ 3704/* ********************** generic query functions ********************** */
3661 3705
@@ -3672,8 +3716,8 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
3672 */ 3716 */
3673_MHD_EXTERN const union MHD_ConnectionInfo * 3717_MHD_EXTERN const union MHD_ConnectionInfo *
3674MHD_get_connection_info (struct MHD_Connection *connection, 3718MHD_get_connection_info (struct MHD_Connection *connection,
3675 enum MHD_ConnectionInfoType info_type, 3719 enum MHD_ConnectionInfoType info_type,
3676 ...); 3720 ...);
3677 3721
3678 3722
3679/** 3723/**
@@ -3706,8 +3750,8 @@ enum MHD_CONNECTION_OPTION
3706 */ 3750 */
3707_MHD_EXTERN int 3751_MHD_EXTERN int
3708MHD_set_connection_option (struct MHD_Connection *connection, 3752MHD_set_connection_option (struct MHD_Connection *connection,
3709 enum MHD_CONNECTION_OPTION option, 3753 enum MHD_CONNECTION_OPTION option,
3710 ...); 3754 ...);
3711 3755
3712 3756
3713/** 3757/**
@@ -3770,8 +3814,8 @@ union MHD_DaemonInfo
3770 */ 3814 */
3771_MHD_EXTERN const union MHD_DaemonInfo * 3815_MHD_EXTERN const union MHD_DaemonInfo *
3772MHD_get_daemon_info (struct MHD_Daemon *daemon, 3816MHD_get_daemon_info (struct MHD_Daemon *daemon,
3773 enum MHD_DaemonInfoType info_type, 3817 enum MHD_DaemonInfoType info_type,
3774 ...); 3818 ...);
3775 3819
3776 3820
3777/** 3821/**
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
index 710115d1..9716573c 100644
--- a/src/include/microhttpd2.h
+++ b/src/include/microhttpd2.h
@@ -99,9 +99,9 @@ extern "C"
99#include <stdarg.h> 99#include <stdarg.h>
100#include <stdint.h> 100#include <stdint.h>
101#include <sys/types.h> 101#include <sys/types.h>
102#if defined(_WIN32) && !defined(__CYGWIN__) 102#if defined(_WIN32) && ! defined(__CYGWIN__)
103#include <ws2tcpip.h> 103#include <ws2tcpip.h>
104#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 104#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
105#define _SSIZE_T_DEFINED 105#define _SSIZE_T_DEFINED
106typedef intptr_t ssize_t; 106typedef intptr_t ssize_t;
107#endif /* !_SSIZE_T_DEFINED */ 107#endif /* !_SSIZE_T_DEFINED */
@@ -112,7 +112,7 @@ typedef intptr_t ssize_t;
112#endif 112#endif
113#endif 113#endif
114 114
115#if defined(__CYGWIN__) && !defined(_SYS_TYPES_FD_SET) 115#if defined(__CYGWIN__) && ! defined(_SYS_TYPES_FD_SET)
116/* Do not define __USE_W32_SOCKETS under Cygwin! */ 116/* Do not define __USE_W32_SOCKETS under Cygwin! */
117#error Cygwin with winsock fd_set is not supported 117#error Cygwin with winsock fd_set is not supported
118#endif 118#endif
@@ -179,7 +179,7 @@ enum MHD_Bool
179/** 179/**
180 * MHD_socket is type for socket FDs 180 * MHD_socket is type for socket FDs
181 */ 181 */
182#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) 182#if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
183#define MHD_POSIX_SOCKETS 1 183#define MHD_POSIX_SOCKETS 1
184typedef int MHD_socket; 184typedef int MHD_socket;
185#define MHD_INVALID_SOCKET (-1) 185#define MHD_INVALID_SOCKET (-1)
@@ -204,30 +204,35 @@ typedef SOCKET MHD_socket;
204#endif /* MHD_NO_DEPRECATION */ 204#endif /* MHD_NO_DEPRECATION */
205 205
206#ifndef _MHD_DEPR_MACRO 206#ifndef _MHD_DEPR_MACRO
207#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1500 207#if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1500
208/* VS 2008 or later */ 208/* VS 2008 or later */
209/* Stringify macros */ 209/* Stringify macros */
210#define _MHD_INSTRMACRO(a) #a 210#define _MHD_INSTRMACRO(a) #a
211#define _MHD_STRMACRO(a) _MHD_INSTRMACRO(a) 211#define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
212/* deprecation message */ 212/* deprecation message */
213#define _MHD_DEPR_MACRO(msg) __pragma(message(__FILE__ "(" _MHD_STRMACRO(__LINE__)"): warning: " msg)) 213#define _MHD_DEPR_MACRO(msg) __pragma (message (__FILE__ "(" _MHD_STRMACRO ( \
214#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 214 __LINE__) "): warning: " msg))
215#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
215#elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__) 216#elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__)
216/* clang or GCC since 3.0 */ 217/* clang or GCC since 3.0 */
217#define _MHD_GCC_PRAG(x) _Pragma (#x) 218#define _MHD_GCC_PRAG(x) _Pragma (#x)
218#if (defined(__clang__) && (__clang_major__+0 >= 5 || \ 219#if (defined(__clang__) && (__clang_major__ + 0 >= 5 || \
219 (!defined(__apple_build_version__) && (__clang_major__+0 > 3 || (__clang_major__+0 == 3 && __clang_minor__ >= 3))))) || \ 220 (! defined(__apple_build_version__) && \
220 __GNUC__+0 > 4 || (__GNUC__+0 == 4 && __GNUC_MINOR__+0 >= 8) 221 (__clang_major__ + 0 > 3 || (__clang_major__ + 0 == 3 && __clang_minor__ >= \
222 3))))) || \
223 __GNUC__ + 0 > 4 || (__GNUC__ + 0 == 4 && __GNUC_MINOR__ + 0 >= 8)
221/* clang >= 3.3 (or XCode's clang >= 5.0) or 224/* clang >= 3.3 (or XCode's clang >= 5.0) or
222 GCC >= 4.8 */ 225 GCC >= 4.8 */
223#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(GCC warning msg) 226#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (GCC warning msg)
224#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 227#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
225#else /* older clang or GCC */ 228#else /* older clang or GCC */
226/* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */ 229/* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */
227#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(message msg) 230#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (message msg)
228#if (defined(__clang__) && (__clang_major__+0 > 2 || (__clang_major__+0 == 2 && __clang_minor__ >= 9))) /* FIXME: clang >= 2.9, earlier versions not tested */ 231#if (defined(__clang__) && (__clang_major__ + 0 > 2 || (__clang_major__ + 0 == \
232 2 && __clang_minor__ >= \
233 9))) /* FIXME: clang >= 2.9, earlier versions not tested */
229/* clang handles inline pragmas better than GCC */ 234/* clang handles inline pragmas better than GCC */
230#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) 235#define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
231#endif /* clang >= 2.9 */ 236#endif /* clang >= 2.9 */
232#endif /* older clang or GCC */ 237#endif /* older clang or GCC */
233/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */ 238/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
@@ -244,17 +249,19 @@ typedef SOCKET MHD_socket;
244#endif /* !_MHD_DEPR_IN_MACRO */ 249#endif /* !_MHD_DEPR_IN_MACRO */
245 250
246#ifndef _MHD_DEPR_FUNC 251#ifndef _MHD_DEPR_FUNC
247#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1400 252#if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1400
248/* VS 2005 or later */ 253/* VS 2005 or later */
249#define _MHD_DEPR_FUNC(msg) __declspec(deprecated(msg)) 254#define _MHD_DEPR_FUNC(msg) __declspec(deprecated (msg))
250#elif defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1310 255#elif defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1310
251/* VS .NET 2003 deprecation do not support custom messages */ 256/* VS .NET 2003 deprecation do not support custom messages */
252#define _MHD_DEPR_FUNC(msg) __declspec(deprecated) 257#define _MHD_DEPR_FUNC(msg) __declspec(deprecated)
253#elif (__GNUC__+0 >= 5) || (defined (__clang__) && \ 258#elif (__GNUC__ + 0 >= 5) || (defined (__clang__) && \
254 (__clang_major__+0 > 2 || (__clang_major__+0 == 2 && __clang_minor__ >= 9))) /* FIXME: earlier versions not tested */ 259 (__clang_major__ + 0 > 2 || (__clang_major__ + 0 == 2 && __clang_minor__ >= \
260 9))) /* FIXME: earlier versions not tested */
255/* GCC >= 5.0 or clang >= 2.9 */ 261/* GCC >= 5.0 or clang >= 2.9 */
256#define _MHD_DEPR_FUNC(msg) __attribute__((deprecated(msg))) 262#define _MHD_DEPR_FUNC(msg) __attribute__((deprecated (msg)))
257#elif defined (__clang__) || __GNUC__+0 > 3 || (__GNUC__+0 == 3 && __GNUC_MINOR__+0 >= 1) 263#elif defined (__clang__) || __GNUC__ + 0 > 3 || (__GNUC__ + 0 == 3 && \
264 __GNUC_MINOR__ + 0 >= 1)
258/* 3.1 <= GCC < 5.0 or clang < 2.9 */ 265/* 3.1 <= GCC < 5.0 or clang < 2.9 */
259/* old GCC-style deprecation do not support custom messages */ 266/* old GCC-style deprecation do not support custom messages */
260#define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__)) 267#define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__))
@@ -277,7 +284,7 @@ typedef SOCKET MHD_socket;
277#if defined(__CYGWIN__) || defined(_WIN32) || defined(MHD_W32LIB) 284#if defined(__CYGWIN__) || defined(_WIN32) || defined(MHD_W32LIB)
278#define MHD_NONNULL(...) /* empty */ 285#define MHD_NONNULL(...) /* empty */
279#else 286#else
280#define MHD_NONNULL(...) __THROW __nonnull((__VA_ARGS__)) 287#define MHD_NONNULL(...) __THROW __nonnull ((__VA_ARGS__))
281#endif 288#endif
282 289
283/** 290/**
@@ -1110,8 +1117,8 @@ enum MHD_Method
1110 */ 1117 */
1111 MHD_METHOD_VERSION_CONTROL = 38 1118 MHD_METHOD_VERSION_CONTROL = 38
1112 1119
1113 /* For more, check: 1120 /* For more, check:
1114 https://www.iana.org/assignments/http-methods/http-methods.xhtml */ 1121 https://www.iana.org/assignments/http-methods/http-methods.xhtml */
1115 1122
1116}; 1123};
1117 1124
@@ -1123,7 +1130,8 @@ enum MHD_Method
1123 * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4 1130 * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
1124 * @{ 1131 * @{
1125 */ 1132 */
1126#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded" 1133#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED \
1134 "application/x-www-form-urlencoded"
1127#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data" 1135#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
1128 1136
1129/** @} */ /* end of group postenc */ 1137/** @} */ /* end of group postenc */
@@ -1386,7 +1394,8 @@ enum MHD_Method
1386/* Standard. RFC7469 */ 1394/* Standard. RFC7469 */
1387#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins" 1395#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
1388/* Standard. RFC7469 */ 1396/* Standard. RFC7469 */
1389#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY "Public-Key-Pins-Report-Only" 1397#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
1398 "Public-Key-Pins-Report-Only"
1390/* No category. RFC4437 */ 1399/* No category. RFC4437 */
1391#define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref" 1400#define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
1392/* No category. RFC4229 */ 1401/* No category. RFC4229 */
@@ -1445,7 +1454,8 @@ enum MHD_Method
1445#define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options" 1454#define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
1446 1455
1447/* Some provisional headers. */ 1456/* Some provisional headers. */
1448#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN "Access-Control-Allow-Origin" 1457#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
1458 "Access-Control-Allow-Origin"
1449/** @} */ /* end of group headers */ 1459/** @} */ /* end of group headers */
1450 1460
1451 1461
@@ -1468,9 +1478,9 @@ enum MHD_Method
1468 */ 1478 */
1469typedef const struct MHD_Action * 1479typedef const struct MHD_Action *
1470(*MHD_RequestCallback) (void *cls, 1480(*MHD_RequestCallback) (void *cls,
1471 struct MHD_Request *request, 1481 struct MHD_Request *request,
1472 const char *url, 1482 const char *url,
1473 enum MHD_Method method); 1483 enum MHD_Method method);
1474 1484
1475 1485
1476/** 1486/**
@@ -1484,8 +1494,8 @@ typedef const struct MHD_Action *
1484 */ 1494 */
1485_MHD_EXTERN struct MHD_Daemon * 1495_MHD_EXTERN struct MHD_Daemon *
1486MHD_daemon_create (MHD_RequestCallback cb, 1496MHD_daemon_create (MHD_RequestCallback cb,
1487 void *cb_cls) 1497 void *cb_cls)
1488 MHD_NONNULL(1); 1498MHD_NONNULL (1);
1489 1499
1490 1500
1491/** 1501/**
@@ -1498,7 +1508,7 @@ MHD_daemon_create (MHD_RequestCallback cb,
1498 */ 1508 */
1499_MHD_EXTERN enum MHD_StatusCode 1509_MHD_EXTERN enum MHD_StatusCode
1500MHD_daemon_start (struct MHD_Daemon *daemon) 1510MHD_daemon_start (struct MHD_Daemon *daemon)
1501 MHD_NONNULL(1); 1511MHD_NONNULL (1);
1502 1512
1503 1513
1504/** 1514/**
@@ -1523,7 +1533,7 @@ MHD_daemon_start (struct MHD_Daemon *daemon)
1523 */ 1533 */
1524_MHD_EXTERN MHD_socket 1534_MHD_EXTERN MHD_socket
1525MHD_daemon_quiesce (struct MHD_Daemon *daemon) 1535MHD_daemon_quiesce (struct MHD_Daemon *daemon)
1526 MHD_NONNULL(1); 1536MHD_NONNULL (1);
1527 1537
1528 1538
1529/** 1539/**
@@ -1534,7 +1544,7 @@ MHD_daemon_quiesce (struct MHD_Daemon *daemon)
1534 */ 1544 */
1535_MHD_EXTERN void 1545_MHD_EXTERN void
1536MHD_daemon_destroy (struct MHD_Daemon *daemon) 1546MHD_daemon_destroy (struct MHD_Daemon *daemon)
1537 MHD_NONNULL(1); 1547MHD_NONNULL (1);
1538 1548
1539 1549
1540/** 1550/**
@@ -1564,10 +1574,10 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon)
1564 */ 1574 */
1565_MHD_EXTERN enum MHD_StatusCode 1575_MHD_EXTERN enum MHD_StatusCode
1566MHD_daemon_add_connection (struct MHD_Daemon *daemon, 1576MHD_daemon_add_connection (struct MHD_Daemon *daemon,
1567 MHD_socket client_socket, 1577 MHD_socket client_socket,
1568 const struct sockaddr *addr, 1578 const struct sockaddr *addr,
1569 socklen_t addrlen) 1579 socklen_t addrlen)
1570 MHD_NONNULL(1); 1580MHD_NONNULL (1);
1571 1581
1572 1582
1573/** 1583/**
@@ -1596,11 +1606,11 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
1596 */ 1606 */
1597_MHD_EXTERN enum MHD_StatusCode 1607_MHD_EXTERN enum MHD_StatusCode
1598MHD_daemon_get_fdset (struct MHD_Daemon *daemon, 1608MHD_daemon_get_fdset (struct MHD_Daemon *daemon,
1599 fd_set *read_fd_set, 1609 fd_set *read_fd_set,
1600 fd_set *write_fd_set, 1610 fd_set *write_fd_set,
1601 fd_set *except_fd_set, 1611 fd_set *except_fd_set,
1602 MHD_socket *max_fd) 1612 MHD_socket *max_fd)
1603 MHD_NONNULL(1,2,3,4); 1613MHD_NONNULL (1,2,3,4);
1604 1614
1605 1615
1606/** 1616/**
@@ -1632,12 +1642,12 @@ MHD_daemon_get_fdset (struct MHD_Daemon *daemon,
1632 */ 1642 */
1633_MHD_EXTERN enum MHD_StatusCode 1643_MHD_EXTERN enum MHD_StatusCode
1634MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon, 1644MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon,
1635 fd_set *read_fd_set, 1645 fd_set *read_fd_set,
1636 fd_set *write_fd_set, 1646 fd_set *write_fd_set,
1637 fd_set *except_fd_set, 1647 fd_set *except_fd_set,
1638 MHD_socket *max_fd, 1648 MHD_socket *max_fd,
1639 unsigned int fd_setsize) 1649 unsigned int fd_setsize)
1640 MHD_NONNULL(1,2,3,4); 1650MHD_NONNULL (1,2,3,4);
1641 1651
1642 1652
1643/** 1653/**
@@ -1662,8 +1672,10 @@ MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon,
1662 * fit fd_set. 1672 * fit fd_set.
1663 * @ingroup event 1673 * @ingroup event
1664 */ 1674 */
1665#define MHD_daemon_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \ 1675#define MHD_daemon_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set, \
1666 MHD_get_fdset2((daemon),(read_fd_set),(write_fd_set),(except_fd_set),(max_fd),FD_SETSIZE) 1676 max_fd) \
1677 MHD_get_fdset2 ((daemon),(read_fd_set),(write_fd_set),(except_fd_set), \
1678 (max_fd),FD_SETSIZE)
1667 1679
1668 1680
1669/** 1681/**
@@ -1687,8 +1699,8 @@ MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon,
1687 */ 1699 */
1688_MHD_EXTERN enum MHD_StatusCode 1700_MHD_EXTERN enum MHD_StatusCode
1689MHD_daemon_get_timeout (struct MHD_Daemon *daemon, 1701MHD_daemon_get_timeout (struct MHD_Daemon *daemon,
1690 MHD_UNSIGNED_LONG_LONG *timeout) 1702 MHD_UNSIGNED_LONG_LONG *timeout)
1691 MHD_NONNULL(1,2); 1703MHD_NONNULL (1,2);
1692 1704
1693 1705
1694/** 1706/**
@@ -1711,7 +1723,7 @@ MHD_daemon_get_timeout (struct MHD_Daemon *daemon,
1711 */ 1723 */
1712_MHD_EXTERN enum MHD_StatusCode 1724_MHD_EXTERN enum MHD_StatusCode
1713MHD_daemon_run (struct MHD_Daemon *daemon) 1725MHD_daemon_run (struct MHD_Daemon *daemon)
1714 MHD_NONNULL(1); 1726MHD_NONNULL (1);
1715 1727
1716 1728
1717/** 1729/**
@@ -1738,10 +1750,10 @@ MHD_daemon_run (struct MHD_Daemon *daemon)
1738 */ 1750 */
1739_MHD_EXTERN enum MHD_StatusCode 1751_MHD_EXTERN enum MHD_StatusCode
1740MHD_daemon_run_from_select (struct MHD_Daemon *daemon, 1752MHD_daemon_run_from_select (struct MHD_Daemon *daemon,
1741 const fd_set *read_fd_set, 1753 const fd_set *read_fd_set,
1742 const fd_set *write_fd_set, 1754 const fd_set *write_fd_set,
1743 const fd_set *except_fd_set) 1755 const fd_set *except_fd_set)
1744 MHD_NONNULL(1,2,3,4); 1756MHD_NONNULL (1,2,3,4);
1745 1757
1746 1758
1747/* ********************* daemon options ************** */ 1759/* ********************* daemon options ************** */
@@ -1758,9 +1770,9 @@ MHD_daemon_run_from_select (struct MHD_Daemon *daemon,
1758 */ 1770 */
1759typedef void 1771typedef void
1760(*MHD_LoggingCallback)(void *cls, 1772(*MHD_LoggingCallback)(void *cls,
1761 enum MHD_StatusCode sc, 1773 enum MHD_StatusCode sc,
1762 const char *fm, 1774 const char *fm,
1763 va_list ap); 1775 va_list ap);
1764 1776
1765 1777
1766/** 1778/**
@@ -1774,9 +1786,9 @@ typedef void
1774 */ 1786 */
1775_MHD_EXTERN void 1787_MHD_EXTERN void
1776MHD_daemon_set_logger (struct MHD_Daemon *daemon, 1788MHD_daemon_set_logger (struct MHD_Daemon *daemon,
1777 MHD_LoggingCallback logger, 1789 MHD_LoggingCallback logger,
1778 void *logger_cls) 1790 void *logger_cls)
1779 MHD_NONNULL(1); 1791MHD_NONNULL (1);
1780 1792
1781 1793
1782/** 1794/**
@@ -1784,7 +1796,8 @@ MHD_daemon_set_logger (struct MHD_Daemon *daemon,
1784 * 1796 *
1785 * @param daemon which instance to disable logging for 1797 * @param daemon which instance to disable logging for
1786 */ 1798 */
1787#define MHD_daemon_disable_logging(daemon) MHD_daemon_set_logger (daemon, NULL, NULL) 1799#define MHD_daemon_disable_logging(daemon) MHD_daemon_set_logger (daemon, NULL, \
1800 NULL)
1788 1801
1789 1802
1790/** 1803/**
@@ -1794,7 +1807,7 @@ MHD_daemon_set_logger (struct MHD_Daemon *daemon,
1794 */ 1807 */
1795_MHD_EXTERN void 1808_MHD_EXTERN void
1796MHD_daemon_suppress_date_no_clock (struct MHD_Daemon *daemon) 1809MHD_daemon_suppress_date_no_clock (struct MHD_Daemon *daemon)
1797 MHD_NONNULL(1); 1810MHD_NONNULL (1);
1798 1811
1799 1812
1800/** 1813/**
@@ -1816,7 +1829,7 @@ MHD_daemon_suppress_date_no_clock (struct MHD_Daemon *daemon)
1816 */ 1829 */
1817_MHD_EXTERN void 1830_MHD_EXTERN void
1818MHD_daemon_disable_itc (struct MHD_Daemon *daemon) 1831MHD_daemon_disable_itc (struct MHD_Daemon *daemon)
1819 MHD_NONNULL(1); 1832MHD_NONNULL (1);
1820 1833
1821 1834
1822/** 1835/**
@@ -1829,7 +1842,7 @@ MHD_daemon_disable_itc (struct MHD_Daemon *daemon)
1829 */ 1842 */
1830_MHD_EXTERN void 1843_MHD_EXTERN void
1831MHD_daemon_enable_turbo (struct MHD_Daemon *daemon) 1844MHD_daemon_enable_turbo (struct MHD_Daemon *daemon)
1832 MHD_NONNULL(1); 1845MHD_NONNULL (1);
1833 1846
1834 1847
1835/** 1848/**
@@ -1843,7 +1856,7 @@ MHD_daemon_enable_turbo (struct MHD_Daemon *daemon)
1843 */ 1856 */
1844_MHD_EXTERN void 1857_MHD_EXTERN void
1845MHD_daemon_disallow_suspend_resume (struct MHD_Daemon *daemon) 1858MHD_daemon_disallow_suspend_resume (struct MHD_Daemon *daemon)
1846 MHD_NONNULL(1); 1859MHD_NONNULL (1);
1847 1860
1848 1861
1849/** 1862/**
@@ -1859,7 +1872,7 @@ MHD_daemon_disallow_suspend_resume (struct MHD_Daemon *daemon)
1859 */ 1872 */
1860_MHD_EXTERN void 1873_MHD_EXTERN void
1861MHD_daemon_disallow_upgrade (struct MHD_Daemon *daemon) 1874MHD_daemon_disallow_upgrade (struct MHD_Daemon *daemon)
1862 MHD_NONNULL(1); 1875MHD_NONNULL (1);
1863 1876
1864 1877
1865/** 1878/**
@@ -1904,9 +1917,9 @@ enum MHD_FastOpenMethod
1904 */ 1917 */
1905_MHD_EXTERN enum MHD_Bool 1918_MHD_EXTERN enum MHD_Bool
1906MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon, 1919MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon,
1907 enum MHD_FastOpenMethod fom, 1920 enum MHD_FastOpenMethod fom,
1908 unsigned int queue_length) 1921 unsigned int queue_length)
1909 MHD_NONNULL(1); 1922MHD_NONNULL (1);
1910 1923
1911 1924
1912/** 1925/**
@@ -1958,9 +1971,9 @@ enum MHD_AddressFamily
1958 */ 1971 */
1959_MHD_EXTERN void 1972_MHD_EXTERN void
1960MHD_daemon_bind_port (struct MHD_Daemon *daemon, 1973MHD_daemon_bind_port (struct MHD_Daemon *daemon,
1961 enum MHD_AddressFamily af, 1974 enum MHD_AddressFamily af,
1962 uint16_t port) 1975 uint16_t port)
1963 MHD_NONNULL(1); 1976MHD_NONNULL (1);
1964 1977
1965 1978
1966/** 1979/**
@@ -1974,9 +1987,9 @@ MHD_daemon_bind_port (struct MHD_Daemon *daemon,
1974 */ 1987 */
1975_MHD_EXTERN void 1988_MHD_EXTERN void
1976MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon, 1989MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon,
1977 const struct sockaddr *sa, 1990 const struct sockaddr *sa,
1978 size_t sa_len) 1991 size_t sa_len)
1979 MHD_NONNULL(1); 1992MHD_NONNULL (1);
1980 1993
1981 1994
1982/** 1995/**
@@ -1988,8 +2001,8 @@ MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon,
1988 */ 2001 */
1989_MHD_EXTERN void 2002_MHD_EXTERN void
1990MHD_daemon_listen_backlog (struct MHD_Daemon *daemon, 2003MHD_daemon_listen_backlog (struct MHD_Daemon *daemon,
1991 int listen_backlog) 2004 int listen_backlog)
1992 MHD_NONNULL(1); 2005MHD_NONNULL (1);
1993 2006
1994 2007
1995/** 2008/**
@@ -2004,7 +2017,7 @@ MHD_daemon_listen_backlog (struct MHD_Daemon *daemon,
2004 */ 2017 */
2005_MHD_EXTERN void 2018_MHD_EXTERN void
2006MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon) 2019MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon)
2007 MHD_NONNULL(1); 2020MHD_NONNULL (1);
2008 2021
2009 2022
2010/** 2023/**
@@ -2023,8 +2036,8 @@ MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon)
2023 */ 2036 */
2024_MHD_EXTERN void 2037_MHD_EXTERN void
2025MHD_daemon_listen_socket (struct MHD_Daemon *daemon, 2038MHD_daemon_listen_socket (struct MHD_Daemon *daemon,
2026 MHD_socket listen_socket) 2039 MHD_socket listen_socket)
2027 MHD_NONNULL(1); 2040MHD_NONNULL (1);
2028 2041
2029 2042
2030/** 2043/**
@@ -2064,8 +2077,8 @@ enum MHD_EventLoopSyscall
2064 */ 2077 */
2065_MHD_EXTERN enum MHD_Bool 2078_MHD_EXTERN enum MHD_Bool
2066MHD_daemon_event_loop (struct MHD_Daemon *daemon, 2079MHD_daemon_event_loop (struct MHD_Daemon *daemon,
2067 enum MHD_EventLoopSyscall els) 2080 enum MHD_EventLoopSyscall els)
2068 MHD_NONNULL(1); 2081MHD_NONNULL (1);
2069 2082
2070 2083
2071/** 2084/**
@@ -2109,8 +2122,8 @@ enum MHD_ProtocolStrictLevel
2109 */ 2122 */
2110_MHD_EXTERN void 2123_MHD_EXTERN void
2111MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon, 2124MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon,
2112 enum MHD_ProtocolStrictLevel sl) 2125 enum MHD_ProtocolStrictLevel sl)
2113 MHD_NONNULL(1); 2126MHD_NONNULL (1);
2114 2127
2115 2128
2116/** 2129/**
@@ -2121,7 +2134,7 @@ MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon,
2121 */ 2134 */
2122_MHD_EXTERN void 2135_MHD_EXTERN void
2123MHD_daemon_enable_shoutcast (struct MHD_Daemon *daemon) 2136MHD_daemon_enable_shoutcast (struct MHD_Daemon *daemon)
2124 MHD_NONNULL(1); 2137MHD_NONNULL (1);
2125 2138
2126 2139
2127/** 2140/**
@@ -2141,9 +2154,9 @@ MHD_daemon_enable_shoutcast (struct MHD_Daemon *daemon)
2141 */ 2154 */
2142_MHD_EXTERN enum MHD_StatusCode 2155_MHD_EXTERN enum MHD_StatusCode
2143MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon, 2156MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon,
2144 const char *tls_backend, 2157 const char *tls_backend,
2145 const char *ciphers) 2158 const char *ciphers)
2146 MHD_NONNULL(1); 2159MHD_NONNULL (1);
2147 2160
2148 2161
2149/** 2162/**
@@ -2160,10 +2173,10 @@ MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon,
2160 */ 2173 */
2161_MHD_EXTERN enum MHD_StatusCode 2174_MHD_EXTERN enum MHD_StatusCode
2162MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, 2175MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
2163 const char *mem_key, 2176 const char *mem_key,
2164 const char *mem_cert, 2177 const char *mem_cert,
2165 const char *pass) 2178 const char *pass)
2166 MHD_NONNULL(1,2,3); 2179MHD_NONNULL (1,2,3);
2167 2180
2168 2181
2169/** 2182/**
@@ -2176,8 +2189,8 @@ MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
2176 */ 2189 */
2177_MHD_EXTERN enum MHD_StatusCode 2190_MHD_EXTERN enum MHD_StatusCode
2178MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon, 2191MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
2179 const char *dh) 2192 const char *dh)
2180 MHD_NONNULL(1); 2193MHD_NONNULL (1);
2181 2194
2182 2195
2183/** 2196/**
@@ -2190,14 +2203,14 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
2190 * @param[out] psk to be set to the pre-shared-key; should be allocated with malloc(), 2203 * @param[out] psk to be set to the pre-shared-key; should be allocated with malloc(),
2191 * will be freed by MHD 2204 * will be freed by MHD
2192 * @param[out] psk_size to be set to the number of bytes in @a psk 2205 * @param[out] psk_size to be set to the number of bytes in @a psk
2193 * @return 0 on success, -1 on errors 2206 * @return 0 on success, -1 on errors
2194 */ 2207 */
2195typedef int 2208typedef int
2196(*MHD_PskServerCredentialsCallback)(void *cls, 2209(*MHD_PskServerCredentialsCallback)(void *cls,
2197 const struct MHD_Connection *connection, 2210 const struct MHD_Connection *connection,
2198 const char *username, 2211 const char *username,
2199 void **psk, 2212 void **psk,
2200 size_t *psk_size); 2213 size_t *psk_size);
2201 2214
2202 2215
2203/** 2216/**
@@ -2210,9 +2223,9 @@ typedef int
2210 */ 2223 */
2211_MHD_EXTERN enum MHD_StatusCode 2224_MHD_EXTERN enum MHD_StatusCode
2212MHD_daemon_set_tls_psk_callback (struct MHD_Daemon *daemon, 2225MHD_daemon_set_tls_psk_callback (struct MHD_Daemon *daemon,
2213 MHD_PskServerCredentialsCallback psk_cb, 2226 MHD_PskServerCredentialsCallback psk_cb,
2214 void *psk_cb_cls) 2227 void *psk_cb_cls)
2215 MHD_NONNULL(1); 2228MHD_NONNULL (1);
2216 2229
2217 2230
2218/** 2231/**
@@ -2225,8 +2238,8 @@ MHD_daemon_set_tls_psk_callback (struct MHD_Daemon *daemon,
2225 */ 2238 */
2226_MHD_EXTERN enum MHD_StatusCode 2239_MHD_EXTERN enum MHD_StatusCode
2227MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon, 2240MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon,
2228 const char *mem_trust) 2241 const char *mem_trust)
2229 MHD_NONNULL(1); 2242MHD_NONNULL (1);
2230 2243
2231 2244
2232/** 2245/**
@@ -2238,8 +2251,8 @@ MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon,
2238 */ 2251 */
2239_MHD_EXTERN enum MHD_StatusCode 2252_MHD_EXTERN enum MHD_StatusCode
2240MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, 2253MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon,
2241 int gnutls_credentials) 2254 int gnutls_credentials)
2242 MHD_NONNULL(1); 2255MHD_NONNULL (1);
2243 2256
2244 2257
2245/** 2258/**
@@ -2261,8 +2274,8 @@ MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon,
2261 */ 2274 */
2262_MHD_EXTERN enum MHD_StatusCode 2275_MHD_EXTERN enum MHD_StatusCode
2263MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, 2276MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon,
2264 void *cb) 2277 void *cb)
2265 MHD_NONNULL(1); 2278MHD_NONNULL (1);
2266 2279
2267 2280
2268/** 2281/**
@@ -2308,7 +2321,7 @@ enum MHD_ThreadingMode
2308 * 2321 *
2309 * @return an `enum MHD_ThreadingMode` for a thread pool of size @a n 2322 * @return an `enum MHD_ThreadingMode` for a thread pool of size @a n
2310 */ 2323 */
2311#define MHD_TM_THREAD_POOL(n) ((enum MHD_ThreadingMode)(n)) 2324#define MHD_TM_THREAD_POOL(n) ((enum MHD_ThreadingMode) (n))
2312 2325
2313 2326
2314/** 2327/**
@@ -2320,8 +2333,8 @@ enum MHD_ThreadingMode
2320 */ 2333 */
2321_MHD_EXTERN void 2334_MHD_EXTERN void
2322MHD_daemon_threading_mode (struct MHD_Daemon *daemon, 2335MHD_daemon_threading_mode (struct MHD_Daemon *daemon,
2323 enum MHD_ThreadingMode tm) 2336 enum MHD_ThreadingMode tm)
2324 MHD_NONNULL(1); 2337MHD_NONNULL (1);
2325 2338
2326 2339
2327/** 2340/**
@@ -2334,9 +2347,9 @@ MHD_daemon_threading_mode (struct MHD_Daemon *daemon,
2334 * @return #MHD_YES if connection is allowed, #MHD_NO if not 2347 * @return #MHD_YES if connection is allowed, #MHD_NO if not
2335 */ 2348 */
2336typedef enum MHD_Bool 2349typedef enum MHD_Bool
2337(*MHD_AcceptPolicyCallback) (void *cls, 2350(*MHD_AcceptPolicyCallback)(void *cls,
2338 const struct sockaddr *addr, 2351 const struct sockaddr *addr,
2339 size_t addrlen); 2352 size_t addrlen);
2340 2353
2341 2354
2342/** 2355/**
@@ -2350,9 +2363,9 @@ typedef enum MHD_Bool
2350 */ 2363 */
2351_MHD_EXTERN void 2364_MHD_EXTERN void
2352MHD_daemon_accept_policy (struct MHD_Daemon *daemon, 2365MHD_daemon_accept_policy (struct MHD_Daemon *daemon,
2353 MHD_AcceptPolicyCallback apc, 2366 MHD_AcceptPolicyCallback apc,
2354 void *apc_cls) 2367 void *apc_cls)
2355 MHD_NONNULL(1); 2368MHD_NONNULL (1);
2356 2369
2357 2370
2358/** 2371/**
@@ -2367,8 +2380,8 @@ MHD_daemon_accept_policy (struct MHD_Daemon *daemon,
2367 */ 2380 */
2368typedef void * 2381typedef void *
2369(*MHD_EarlyUriLogCallback)(void *cls, 2382(*MHD_EarlyUriLogCallback)(void *cls,
2370 const char *uri, 2383 const char *uri,
2371 struct MHD_Request *request); 2384 struct MHD_Request *request);
2372 2385
2373 2386
2374/** 2387/**
@@ -2382,9 +2395,9 @@ typedef void *
2382 */ 2395 */
2383_MHD_EXTERN void 2396_MHD_EXTERN void
2384MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, 2397MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon,
2385 MHD_EarlyUriLogCallback cb, 2398 MHD_EarlyUriLogCallback cb,
2386 void *cb_cls) 2399 void *cb_cls)
2387 MHD_NONNULL(1); 2400MHD_NONNULL (1);
2388 2401
2389 2402
2390/** 2403/**
@@ -2431,8 +2444,8 @@ enum MHD_ConnectionNotificationCode
2431 */ 2444 */
2432typedef void 2445typedef void
2433(*MHD_NotifyConnectionCallback) (void *cls, 2446(*MHD_NotifyConnectionCallback) (void *cls,
2434 struct MHD_Connection *connection, 2447 struct MHD_Connection *connection,
2435 enum MHD_ConnectionNotificationCode toe); 2448 enum MHD_ConnectionNotificationCode toe);
2436 2449
2437 2450
2438/** 2451/**
@@ -2445,9 +2458,9 @@ typedef void
2445 */ 2458 */
2446_MHD_EXTERN void 2459_MHD_EXTERN void
2447MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon, 2460MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon,
2448 MHD_NotifyConnectionCallback ncc, 2461 MHD_NotifyConnectionCallback ncc,
2449 void *ncc_cls) 2462 void *ncc_cls)
2450 MHD_NONNULL(1); 2463MHD_NONNULL (1);
2451 2464
2452 2465
2453/** 2466/**
@@ -2463,9 +2476,9 @@ MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon,
2463 */ 2476 */
2464_MHD_EXTERN void 2477_MHD_EXTERN void
2465MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon, 2478MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon,
2466 size_t memory_limit_b, 2479 size_t memory_limit_b,
2467 size_t memory_increment_b) 2480 size_t memory_increment_b)
2468 MHD_NONNULL(1); 2481MHD_NONNULL (1);
2469 2482
2470 2483
2471/** 2484/**
@@ -2478,8 +2491,8 @@ MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon,
2478 */ 2491 */
2479_MHD_EXTERN void 2492_MHD_EXTERN void
2480MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon, 2493MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon,
2481 size_t stack_limit_b) 2494 size_t stack_limit_b)
2482 MHD_NONNULL(1); 2495MHD_NONNULL (1);
2483 2496
2484 2497
2485/** 2498/**
@@ -2499,9 +2512,9 @@ MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon,
2499 */ 2512 */
2500_MHD_EXTERN void 2513_MHD_EXTERN void
2501MHD_daemon_connection_limits (struct MHD_Daemon *daemon, 2514MHD_daemon_connection_limits (struct MHD_Daemon *daemon,
2502 unsigned int global_connection_limit, 2515 unsigned int global_connection_limit,
2503 unsigned int ip_connection_limit) 2516 unsigned int ip_connection_limit)
2504 MHD_NONNULL(1); 2517MHD_NONNULL (1);
2505 2518
2506 2519
2507/** 2520/**
@@ -2514,8 +2527,8 @@ MHD_daemon_connection_limits (struct MHD_Daemon *daemon,
2514 */ 2527 */
2515_MHD_EXTERN void 2528_MHD_EXTERN void
2516MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, 2529MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon,
2517 unsigned int timeout_s) 2530 unsigned int timeout_s)
2518 MHD_NONNULL(1); 2531MHD_NONNULL (1);
2519 2532
2520 2533
2521/** 2534/**
@@ -2532,8 +2545,8 @@ MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon,
2532 */ 2545 */
2533typedef size_t 2546typedef size_t
2534(*MHD_UnescapeCallback) (void *cls, 2547(*MHD_UnescapeCallback) (void *cls,
2535 struct MHD_Request *req, 2548 struct MHD_Request *req,
2536 char *s); 2549 char *s);
2537 2550
2538 2551
2539/** 2552/**
@@ -2549,9 +2562,9 @@ typedef size_t
2549 */ 2562 */
2550_MHD_EXTERN void 2563_MHD_EXTERN void
2551MHD_daemon_unescape_cb (struct MHD_Daemon *daemon, 2564MHD_daemon_unescape_cb (struct MHD_Daemon *daemon,
2552 MHD_UnescapeCallback unescape_cb, 2565 MHD_UnescapeCallback unescape_cb,
2553 void *unescape_cb_cls) 2566 void *unescape_cb_cls)
2554 MHD_NONNULL(1); 2567MHD_NONNULL (1);
2555 2568
2556 2569
2557/** 2570/**
@@ -2565,9 +2578,9 @@ MHD_daemon_unescape_cb (struct MHD_Daemon *daemon,
2565 */ 2578 */
2566_MHD_EXTERN void 2579_MHD_EXTERN void
2567MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon, 2580MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon,
2568 size_t buf_size, 2581 size_t buf_size,
2569 const void *buf) 2582 const void *buf)
2570 MHD_NONNULL(1,3); 2583MHD_NONNULL (1,3);
2571 2584
2572 2585
2573/** 2586/**
@@ -2579,8 +2592,8 @@ MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon,
2579 */ 2592 */
2580_MHD_EXTERN enum MHD_StatusCode 2593_MHD_EXTERN enum MHD_StatusCode
2581MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon, 2594MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon,
2582 size_t nc_length) 2595 size_t nc_length)
2583 MHD_NONNULL(1); 2596MHD_NONNULL (1);
2584 2597
2585 2598
2586/* ********************* connection options ************** */ 2599/* ********************* connection options ************** */
@@ -2596,8 +2609,8 @@ MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon,
2596 */ 2609 */
2597_MHD_EXTERN void 2610_MHD_EXTERN void
2598MHD_connection_set_timeout (struct MHD_Connection *connection, 2611MHD_connection_set_timeout (struct MHD_Connection *connection,
2599 unsigned int timeout_s) 2612 unsigned int timeout_s)
2600 MHD_NONNULL(1); 2613MHD_NONNULL (1);
2601 2614
2602 2615
2603/* **************** Request handling functions ***************** */ 2616/* **************** Request handling functions ***************** */
@@ -2678,10 +2691,10 @@ typedef int
2678 */ 2691 */
2679_MHD_EXTERN unsigned int 2692_MHD_EXTERN unsigned int
2680MHD_request_get_values (struct MHD_Request *request, 2693MHD_request_get_values (struct MHD_Request *request,
2681 enum MHD_ValueKind kind, 2694 enum MHD_ValueKind kind,
2682 MHD_KeyValueIterator iterator, 2695 MHD_KeyValueIterator iterator,
2683 void *iterator_cls) 2696 void *iterator_cls)
2684 MHD_NONNULL(1); 2697MHD_NONNULL (1);
2685 2698
2686 2699
2687/** 2700/**
@@ -2711,10 +2724,10 @@ MHD_request_get_values (struct MHD_Request *request,
2711 */ 2724 */
2712_MHD_EXTERN enum MHD_Bool 2725_MHD_EXTERN enum MHD_Bool
2713MHD_request_set_value (struct MHD_Request *request, 2726MHD_request_set_value (struct MHD_Request *request,
2714 enum MHD_ValueKind kind, 2727 enum MHD_ValueKind kind,
2715 const char *key, 2728 const char *key,
2716 const char *value) 2729 const char *value)
2717 MHD_NONNULL(1,3,4); 2730MHD_NONNULL (1,3,4);
2718 2731
2719 2732
2720/** 2733/**
@@ -2729,9 +2742,9 @@ MHD_request_set_value (struct MHD_Request *request,
2729 */ 2742 */
2730_MHD_EXTERN const char * 2743_MHD_EXTERN const char *
2731MHD_request_lookup_value (struct MHD_Request *request, 2744MHD_request_lookup_value (struct MHD_Request *request,
2732 enum MHD_ValueKind kind, 2745 enum MHD_ValueKind kind,
2733 const char *key) 2746 const char *key)
2734 MHD_NONNULL(1); 2747MHD_NONNULL (1);
2735 2748
2736 2749
2737 2750
@@ -2741,7 +2754,8 @@ MHD_request_lookup_value (struct MHD_Request *request,
2741 * @{ 2754 * @{
2742 */ 2755 */
2743/* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */ 2756/* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */
2744enum MHD_HTTP_StatusCode { 2757enum MHD_HTTP_StatusCode
2758{
2745 MHD_HTTP_CONTINUE = 100, 2759 MHD_HTTP_CONTINUE = 100,
2746 MHD_HTTP_SWITCHING_PROTOCOLS = 101, 2760 MHD_HTTP_SWITCHING_PROTOCOLS = 101,
2747 MHD_HTTP_PROCESSING = 102, 2761 MHD_HTTP_PROCESSING = 102,
@@ -2777,7 +2791,9 @@ enum MHD_HTTP_StatusCode {
2777 MHD_HTTP_NOT_ACCEPTABLE = 406, 2791 MHD_HTTP_NOT_ACCEPTABLE = 406,
2778/** @deprecated */ 2792/** @deprecated */
2779#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \ 2793#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \
2780 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") MHD_HTTP_NOT_ACCEPTABLE 2794 _MHD_DEPR_IN_MACRO ( \
2795 "Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") \
2796 MHD_HTTP_NOT_ACCEPTABLE
2781 MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED = 407, 2797 MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
2782 MHD_HTTP_REQUEST_TIMEOUT = 408, 2798 MHD_HTTP_REQUEST_TIMEOUT = 408,
2783 MHD_HTTP_CONFLICT = 409, 2799 MHD_HTTP_CONFLICT = 409,
@@ -2787,16 +2803,22 @@ enum MHD_HTTP_StatusCode {
2787 MHD_HTTP_PAYLOAD_TOO_LARGE = 413, 2803 MHD_HTTP_PAYLOAD_TOO_LARGE = 413,
2788/** @deprecated */ 2804/** @deprecated */
2789#define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE \ 2805#define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE \
2790 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_PAYLOAD_TOO_LARGE") MHD_HTTP_PAYLOAD_TOO_LARGE 2806 _MHD_DEPR_IN_MACRO ( \
2807 "Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_PAYLOAD_TOO_LARGE") \
2808 MHD_HTTP_PAYLOAD_TOO_LARGE
2791 MHD_HTTP_URI_TOO_LONG = 414, 2809 MHD_HTTP_URI_TOO_LONG = 414,
2792/** @deprecated */ 2810/** @deprecated */
2793#define MHD_HTTP_REQUEST_URI_TOO_LONG \ 2811#define MHD_HTTP_REQUEST_URI_TOO_LONG \
2794 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG") MHD_HTTP_URI_TOO_LONG 2812 _MHD_DEPR_IN_MACRO ( \
2813 "Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG") \
2814 MHD_HTTP_URI_TOO_LONG
2795 MHD_HTTP_UNSUPPORTED_MEDIA_TYPE = 415, 2815 MHD_HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
2796 MHD_HTTP_RANGE_NOT_SATISFIABLE = 416, 2816 MHD_HTTP_RANGE_NOT_SATISFIABLE = 416,
2797/** @deprecated */ 2817/** @deprecated */
2798#define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE \ 2818#define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE \
2799 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE") MHD_HTTP_RANGE_NOT_SATISFIABLE 2819 _MHD_DEPR_IN_MACRO ( \
2820 "Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE") \
2821 MHD_HTTP_RANGE_NOT_SATISFIABLE
2800 MHD_HTTP_EXPECTATION_FAILED = 417, 2822 MHD_HTTP_EXPECTATION_FAILED = 417,
2801 2823
2802 MHD_HTTP_MISDIRECTED_REQUEST = 421, 2824 MHD_HTTP_MISDIRECTED_REQUEST = 421,
@@ -2903,7 +2925,7 @@ MHD_action_suspend (void);
2903 */ 2925 */
2904_MHD_EXTERN void 2926_MHD_EXTERN void
2905MHD_request_resume (struct MHD_Request *request) 2927MHD_request_resume (struct MHD_Request *request)
2906 MHD_NONNULL(1); 2928MHD_NONNULL (1);
2907 2929
2908 2930
2909/* **************** Response manipulation functions ***************** */ 2931/* **************** Response manipulation functions ***************** */
@@ -2936,8 +2958,8 @@ struct MHD_Response;
2936 */ 2958 */
2937_MHD_EXTERN const struct MHD_Action * 2959_MHD_EXTERN const struct MHD_Action *
2938MHD_action_from_response (struct MHD_Response *response, 2960MHD_action_from_response (struct MHD_Response *response,
2939 enum MHD_Bool destroy_after_use) 2961 enum MHD_Bool destroy_after_use)
2940 MHD_NONNULL(1); 2962MHD_NONNULL (1);
2941 2963
2942 2964
2943/** 2965/**
@@ -2949,7 +2971,7 @@ MHD_action_from_response (struct MHD_Response *response,
2949 */ 2971 */
2950_MHD_EXTERN void 2972_MHD_EXTERN void
2951MHD_response_option_v10_only (struct MHD_Response *response) 2973MHD_response_option_v10_only (struct MHD_Response *response)
2952 MHD_NONNULL(1); 2974MHD_NONNULL (1);
2953 2975
2954 2976
2955/** 2977/**
@@ -3023,8 +3045,8 @@ enum MHD_RequestTerminationCode
3023 */ 3045 */
3024typedef void 3046typedef void
3025(*MHD_RequestTerminationCallback) (void *cls, 3047(*MHD_RequestTerminationCallback) (void *cls,
3026 enum MHD_RequestTerminationCode toe, 3048 enum MHD_RequestTerminationCode toe,
3027 void *request_context); 3049 void *request_context);
3028 3050
3029 3051
3030/** 3052/**
@@ -3037,9 +3059,10 @@ typedef void
3037 */ 3059 */
3038_MHD_EXTERN void 3060_MHD_EXTERN void
3039MHD_response_option_termination_callback (struct MHD_Response *response, 3061MHD_response_option_termination_callback (struct MHD_Response *response,
3040 MHD_RequestTerminationCallback termination_cb, 3062 MHD_RequestTerminationCallback
3041 void *termination_cb_cls) 3063 termination_cb,
3042 MHD_NONNULL(1); 3064 void *termination_cb_cls)
3065MHD_NONNULL (1);
3043 3066
3044 3067
3045/** 3068/**
@@ -3124,11 +3147,11 @@ typedef void
3124 */ 3147 */
3125_MHD_EXTERN struct MHD_Response * 3148_MHD_EXTERN struct MHD_Response *
3126MHD_response_from_callback (enum MHD_HTTP_StatusCode sc, 3149MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
3127 uint64_t size, 3150 uint64_t size,
3128 size_t block_size, 3151 size_t block_size,
3129 MHD_ContentReaderCallback crc, 3152 MHD_ContentReaderCallback crc,
3130 void *crc_cls, 3153 void *crc_cls,
3131 MHD_ContentReaderFreeCallback crfc); 3154 MHD_ContentReaderFreeCallback crfc);
3132 3155
3133 3156
3134/** 3157/**
@@ -3181,9 +3204,9 @@ enum MHD_ResponseMemoryMode
3181 */ 3204 */
3182_MHD_EXTERN struct MHD_Response * 3205_MHD_EXTERN struct MHD_Response *
3183MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc, 3206MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc,
3184 size_t size, 3207 size_t size,
3185 void *buffer, 3208 void *buffer,
3186 enum MHD_ResponseMemoryMode mode); 3209 enum MHD_ResponseMemoryMode mode);
3187 3210
3188 3211
3189/** 3212/**
@@ -3206,9 +3229,9 @@ MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc,
3206 */ 3229 */
3207_MHD_EXTERN struct MHD_Response * 3230_MHD_EXTERN struct MHD_Response *
3208MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, 3231MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
3209 int fd, 3232 int fd,
3210 uint64_t offset, 3233 uint64_t offset,
3211 uint64_t size); 3234 uint64_t size);
3212 3235
3213 3236
3214/** 3237/**
@@ -3255,9 +3278,9 @@ struct MHD_UpgradeResponseHandle;
3255 */ 3278 */
3256_MHD_EXTERN enum MHD_Bool 3279_MHD_EXTERN enum MHD_Bool
3257MHD_upgrade_operation (struct MHD_UpgradeResponseHandle *urh, 3280MHD_upgrade_operation (struct MHD_UpgradeResponseHandle *urh,
3258 enum MHD_UpgradeOperation operation, 3281 enum MHD_UpgradeOperation operation,
3259 ...) 3282 ...)
3260 MHD_NONNULL(1); 3283MHD_NONNULL (1);
3261 3284
3262 3285
3263/** 3286/**
@@ -3349,8 +3372,8 @@ typedef void
3349 */ 3372 */
3350_MHD_EXTERN struct MHD_Response * 3373_MHD_EXTERN struct MHD_Response *
3351MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, 3374MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
3352 void *upgrade_handler_cls) 3375 void *upgrade_handler_cls)
3353 MHD_NONNULL(1); 3376MHD_NONNULL (1);
3354 3377
3355 3378
3356/** 3379/**
@@ -3364,7 +3387,7 @@ MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
3364 */ 3387 */
3365_MHD_EXTERN void 3388_MHD_EXTERN void
3366MHD_response_queue_for_destroy (struct MHD_Response *response) 3389MHD_response_queue_for_destroy (struct MHD_Response *response)
3367 MHD_NONNULL(1); 3390MHD_NONNULL (1);
3368 3391
3369 3392
3370/** 3393/**
@@ -3380,8 +3403,8 @@ MHD_response_queue_for_destroy (struct MHD_Response *response)
3380_MHD_EXTERN enum MHD_Bool 3403_MHD_EXTERN enum MHD_Bool
3381MHD_response_add_header (struct MHD_Response *response, 3404MHD_response_add_header (struct MHD_Response *response,
3382 const char *header, 3405 const char *header,
3383 const char *content) 3406 const char *content)
3384 MHD_NONNULL(1,2,3); 3407MHD_NONNULL (1,2,3);
3385 3408
3386 3409
3387/** 3410/**
@@ -3398,7 +3421,7 @@ _MHD_EXTERN enum MHD_Bool
3398MHD_response_add_trailer (struct MHD_Response *response, 3421MHD_response_add_trailer (struct MHD_Response *response,
3399 const char *footer, 3422 const char *footer,
3400 const char *content) 3423 const char *content)
3401 MHD_NONNULL(1,2,3); 3424MHD_NONNULL (1,2,3);
3402 3425
3403 3426
3404/** 3427/**
@@ -3413,8 +3436,8 @@ MHD_response_add_trailer (struct MHD_Response *response,
3413_MHD_EXTERN enum MHD_Bool 3436_MHD_EXTERN enum MHD_Bool
3414MHD_response_del_header (struct MHD_Response *response, 3437MHD_response_del_header (struct MHD_Response *response,
3415 const char *header, 3438 const char *header,
3416 const char *content) 3439 const char *content)
3417 MHD_NONNULL(1,2,3); 3440MHD_NONNULL (1,2,3);
3418 3441
3419 3442
3420/** 3443/**
@@ -3430,8 +3453,8 @@ MHD_response_del_header (struct MHD_Response *response,
3430_MHD_EXTERN unsigned int 3453_MHD_EXTERN unsigned int
3431MHD_response_get_headers (struct MHD_Response *response, 3454MHD_response_get_headers (struct MHD_Response *response,
3432 MHD_KeyValueIterator iterator, 3455 MHD_KeyValueIterator iterator,
3433 void *iterator_cls) 3456 void *iterator_cls)
3434 MHD_NONNULL(1); 3457MHD_NONNULL (1);
3435 3458
3436 3459
3437/** 3460/**
@@ -3444,8 +3467,8 @@ MHD_response_get_headers (struct MHD_Response *response,
3444 */ 3467 */
3445_MHD_EXTERN const char * 3468_MHD_EXTERN const char *
3446MHD_response_get_header (struct MHD_Response *response, 3469MHD_response_get_header (struct MHD_Response *response,
3447 const char *key) 3470 const char *key)
3448 MHD_NONNULL(1,2); 3471MHD_NONNULL (1,2);
3449 3472
3450 3473
3451/* ************Upload and PostProcessor functions ********************** */ 3474/* ************Upload and PostProcessor functions ********************** */
@@ -3480,8 +3503,8 @@ MHD_action_continue (void);
3480 */ 3503 */
3481typedef const struct MHD_Action * 3504typedef const struct MHD_Action *
3482(*MHD_UploadCallback) (void *cls, 3505(*MHD_UploadCallback) (void *cls,
3483 const char *upload_data, 3506 const char *upload_data,
3484 size_t *upload_data_size); 3507 size_t *upload_data_size);
3485 3508
3486 3509
3487/** 3510/**
@@ -3494,8 +3517,8 @@ typedef const struct MHD_Action *
3494 */ 3517 */
3495_MHD_EXTERN const struct MHD_Action * 3518_MHD_EXTERN const struct MHD_Action *
3496MHD_action_process_upload (MHD_UploadCallback uc, 3519MHD_action_process_upload (MHD_UploadCallback uc,
3497 void *uc_cls) 3520 void *uc_cls)
3498 MHD_NONNULL(1); 3521MHD_NONNULL (1);
3499 3522
3500 3523
3501/** 3524/**
@@ -3559,9 +3582,9 @@ typedef const struct MHD_Action *
3559 */ 3582 */
3560_MHD_EXTERN const struct MHD_Action * 3583_MHD_EXTERN const struct MHD_Action *
3561MHD_action_parse_post (size_t buffer_size, 3584MHD_action_parse_post (size_t buffer_size,
3562 MHD_PostDataIterator iter, 3585 MHD_PostDataIterator iter,
3563 void *iter_cls) 3586 void *iter_cls)
3564 MHD_NONNULL(2); 3587MHD_NONNULL (2);
3565 3588
3566 3589
3567 3590
@@ -3730,10 +3753,10 @@ union MHD_ConnectionInformation
3730 */ 3753 */
3731_MHD_EXTERN enum MHD_Bool 3754_MHD_EXTERN enum MHD_Bool
3732MHD_connection_get_information_sz (struct MHD_Connection *connection, 3755MHD_connection_get_information_sz (struct MHD_Connection *connection,
3733 enum MHD_ConnectionInformationType info_type, 3756 enum MHD_ConnectionInformationType info_type,
3734 union MHD_ConnectionInformation *return_value, 3757 union MHD_ConnectionInformation *return_value,
3735 size_t return_value_size) 3758 size_t return_value_size)
3736 MHD_NONNULL(1,3); 3759MHD_NONNULL (1,3);
3737 3760
3738 3761
3739/** 3762/**
@@ -3750,7 +3773,8 @@ MHD_connection_get_information_sz (struct MHD_Connection *connection,
3750#define MHD_connection_get_information(connection, \ 3773#define MHD_connection_get_information(connection, \
3751 info_type, \ 3774 info_type, \
3752 return_value) \ 3775 return_value) \
3753 MHD_connection_get_information_sz ((connection),(info_type),(return_value),sizeof(union MHD_ConnectionInformation)) 3776 MHD_connection_get_information_sz ((connection),(info_type),(return_value), \
3777 sizeof(union MHD_ConnectionInformation))
3754 3778
3755 3779
3756/** 3780/**
@@ -3843,10 +3867,10 @@ enum MHD_RequestInformationType
3843 */ 3867 */
3844_MHD_EXTERN enum MHD_Bool 3868_MHD_EXTERN enum MHD_Bool
3845MHD_request_get_information_sz (struct MHD_Request *request, 3869MHD_request_get_information_sz (struct MHD_Request *request,
3846 enum MHD_RequestInformationType info_type, 3870 enum MHD_RequestInformationType info_type,
3847 union MHD_RequestInformation *return_value, 3871 union MHD_RequestInformation *return_value,
3848 size_t return_value_size) 3872 size_t return_value_size)
3849 MHD_NONNULL(1,3); 3873MHD_NONNULL (1,3);
3850 3874
3851 3875
3852/** 3876/**
@@ -3863,7 +3887,8 @@ MHD_request_get_information_sz (struct MHD_Request *request,
3863#define MHD_request_get_information (request, \ 3887#define MHD_request_get_information (request, \
3864 info_type, \ 3888 info_type, \
3865 return_value) \ 3889 return_value) \
3866 MHD_request_get_information_sz ((request), (info_type), (return_value), sizeof(union MHD_RequestInformation)) 3890 MHD_request_get_information_sz ((request), (info_type), (return_value), \
3891 sizeof(union MHD_RequestInformation))
3867 3892
3868 3893
3869/** 3894/**
@@ -3950,10 +3975,10 @@ union MHD_DaemonInformation
3950 */ 3975 */
3951_MHD_EXTERN enum MHD_Bool 3976_MHD_EXTERN enum MHD_Bool
3952MHD_daemon_get_information_sz (struct MHD_Daemon *daemon, 3977MHD_daemon_get_information_sz (struct MHD_Daemon *daemon,
3953 enum MHD_DaemonInformationType info_type, 3978 enum MHD_DaemonInformationType info_type,
3954 union MHD_DaemonInformation *return_value, 3979 union MHD_DaemonInformation *return_value,
3955 size_t return_value_size) 3980 size_t return_value_size)
3956 MHD_NONNULL(1,3); 3981MHD_NONNULL (1,3);
3957 3982
3958/** 3983/**
3959 * Obtain information about the given daemon. 3984 * Obtain information about the given daemon.
@@ -3969,7 +3994,8 @@ MHD_daemon_get_information_sz (struct MHD_Daemon *daemon,
3969#define MHD_daemon_get_information(daemon, \ 3994#define MHD_daemon_get_information(daemon, \
3970 info_type, \ 3995 info_type, \
3971 return_value) \ 3996 return_value) \
3972 MHD_daemon_get_information_sz((daemon), (info_type), (return_value), sizeof(union MHD_DaemonInformation)); 3997 MHD_daemon_get_information_sz ((daemon), (info_type), (return_value), \
3998 sizeof(union MHD_DaemonInformation));
3973 3999
3974 4000
3975/** 4001/**
@@ -4007,7 +4033,7 @@ typedef void
4007 */ 4033 */
4008_MHD_EXTERN void 4034_MHD_EXTERN void
4009MHD_set_panic_func (MHD_PanicCallback cb, 4035MHD_set_panic_func (MHD_PanicCallback cb,
4010 void *cls); 4036 void *cls);
4011 4037
4012 4038
4013/** 4039/**
@@ -4021,7 +4047,7 @@ MHD_set_panic_func (MHD_PanicCallback cb,
4021 */ 4047 */
4022_MHD_EXTERN size_t 4048_MHD_EXTERN size_t
4023MHD_http_unescape (char *val) 4049MHD_http_unescape (char *val)
4024 MHD_NONNULL(1); 4050MHD_NONNULL (1);
4025 4051
4026 4052
4027/** 4053/**
diff --git a/src/include/microhttpd_tls.h b/src/include/microhttpd_tls.h
index f5b48522..7bd7d477 100644
--- a/src/include/microhttpd_tls.h
+++ b/src/include/microhttpd_tls.h
@@ -54,9 +54,9 @@ struct MHD_TLS_Plugin
54{ 54{
55 /** 55 /**
56 * Closure with plugin's internal state, opaque to MHD. 56 * Closure with plugin's internal state, opaque to MHD.
57 */ 57 */
58 void *cls; 58 void *cls;
59 59
60 /** 60 /**
61 * Destroy the plugin, we are done with it. 61 * Destroy the plugin, we are done with it.
62 */ 62 */
@@ -77,9 +77,9 @@ struct MHD_TLS_Plugin
77 */ 77 */
78 enum MHD_StatusCode 78 enum MHD_StatusCode
79 (*init_kcp)(void *cls, 79 (*init_kcp)(void *cls,
80 const char *mem_key, 80 const char *mem_key,
81 const char *mem_cert, 81 const char *mem_cert,
82 const char *pass); 82 const char *pass);
83 83
84 84
85 /** 85 /**
@@ -91,7 +91,7 @@ struct MHD_TLS_Plugin
91 */ 91 */
92 enum MHD_StatusCode 92 enum MHD_StatusCode
93 (*init_dhparams)(void *cls, 93 (*init_dhparams)(void *cls,
94 const char *dh); 94 const char *dh);
95 95
96 96
97 /** 97 /**
@@ -103,7 +103,7 @@ struct MHD_TLS_Plugin
103 */ 103 */
104 enum MHD_StatusCode 104 enum MHD_StatusCode
105 (*init_mem_trust)(void *cls, 105 (*init_mem_trust)(void *cls,
106 const char *mem_trust); 106 const char *mem_trust);
107 107
108 108
109 /** 109 /**
@@ -116,59 +116,59 @@ struct MHD_TLS_Plugin
116 */ 116 */
117 struct MHD_TLS_ConnectionState * 117 struct MHD_TLS_ConnectionState *
118 (*setup_connection)(void *cls, 118 (*setup_connection)(void *cls,
119 ...); 119 ...);
120 120
121 121
122 enum MHD_Bool 122 enum MHD_Bool
123 (*handshake)(void *cls, 123 (*handshake)(void *cls,
124 struct MHD_TLS_ConnectionState *cs); 124 struct MHD_TLS_ConnectionState *cs);
125 125
126 126
127 enum MHD_Bool 127 enum MHD_Bool
128 (*idle_ready)(void *cls, 128 (*idle_ready)(void *cls,
129 struct MHD_TLS_ConnectionState *cs); 129 struct MHD_TLS_ConnectionState *cs);
130 130
131 131
132 enum MHD_Bool 132 enum MHD_Bool
133 (*update_event_loop_info)(void *cls, 133 (*update_event_loop_info)(void *cls,
134 struct MHD_TLS_ConnectionState *cs, 134 struct MHD_TLS_ConnectionState *cs,
135 enum MHD_RequestEventLoopInfo *eli); 135 enum MHD_RequestEventLoopInfo *eli);
136 136
137 ssize_t 137 ssize_t
138 (*send)(void *cls, 138 (*send)(void *cls,
139 struct MHD_TLS_ConnectionState *cs, 139 struct MHD_TLS_ConnectionState *cs,
140 const void *buf, 140 const void *buf,
141 size_t buf_size); 141 size_t buf_size);
142 142
143 143
144 ssize_t 144 ssize_t
145 (*recv)(void *cls, 145 (*recv)(void *cls,
146 struct MHD_TLS_ConnectionState *cs, 146 struct MHD_TLS_ConnectionState *cs,
147 void *buf, 147 void *buf,
148 size_t buf_size); 148 size_t buf_size);
149 149
150 150
151 const char * 151 const char *
152 (*strerror)(void *cls, 152 (*strerror)(void *cls,
153 int ec); 153 int ec);
154 154
155 enum MHD_Bool 155 enum MHD_Bool
156 (*check_record_pending)(void *cls, 156 (*check_record_pending)(void *cls,
157 struct MHD_TLS_ConnectionState *cs); 157 struct MHD_TLS_ConnectionState *cs);
158 158
159 enum MHD_Bool 159 enum MHD_Bool
160 (*shutdown_connection) (void *cls, 160 (*shutdown_connection)(void *cls,
161 struct MHD_TLS_ConnectionState *cs); 161 struct MHD_TLS_ConnectionState *cs);
162
162 163
163
164 void 164 void
165 (*teardown_connection)(void *cls, 165 (*teardown_connection)(void *cls,
166 struct MHD_TLS_ConnectionState *cs); 166 struct MHD_TLS_ConnectionState *cs);
167 167
168 /** 168 /**
169 * TODO: More functions here.... 169 * TODO: More functions here....
170 */ 170 */
171 171
172}; 172};
173 173
174 174
@@ -191,7 +191,7 @@ typedef struct MHD_TLS_Plugin *
191 */ 191 */
192#define MHD_TLS_INIT(body) \ 192#define MHD_TLS_INIT(body) \
193 struct MHD_TLS_Plugin * \ 193 struct MHD_TLS_Plugin * \
194 MHD_TLS_init_ ## MHD_TLS_ABI_VERSION (const char *ciphers) \\ 194 MHD_TLS_init_ ## MHD_TLS_ABI_VERSION (const char *ciphers) \ \
195 { body } 195 { body }
196 196
197#endif 197#endif
diff --git a/src/include/platform.h b/src/include/platform.h
index 20d4df52..05fe1cd4 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -94,7 +94,7 @@
94#if HAVE_SYS_SOCKET_H 94#if HAVE_SYS_SOCKET_H
95#include <sys/socket.h> 95#include <sys/socket.h>
96#endif 96#endif
97#if defined(_WIN32) && !defined(__CYGWIN__) 97#if defined(_WIN32) && ! defined(__CYGWIN__)
98#ifndef WIN32_LEAN_AND_MEAN 98#ifndef WIN32_LEAN_AND_MEAN
99/* Do not include unneeded parts of W32 headers. */ 99/* Do not include unneeded parts of W32 headers. */
100#define WIN32_LEAN_AND_MEAN 1 100#define WIN32_LEAN_AND_MEAN 1
@@ -103,28 +103,28 @@
103#include <ws2tcpip.h> 103#include <ws2tcpip.h>
104#endif /* _WIN32 && !__CYGWIN__ */ 104#endif /* _WIN32 && !__CYGWIN__ */
105 105
106#if defined(__CYGWIN__) && !defined(_SYS_TYPES_FD_SET) 106#if defined(__CYGWIN__) && ! defined(_SYS_TYPES_FD_SET)
107/* Do not define __USE_W32_SOCKETS under Cygwin! */ 107/* Do not define __USE_W32_SOCKETS under Cygwin! */
108#error Cygwin with winsock fd_set is not supported 108#error Cygwin with winsock fd_set is not supported
109#endif 109#endif
110 110
111#if defined(_WIN32) && !defined(__CYGWIN__) 111#if defined(_WIN32) && ! defined(__CYGWIN__)
112#define sleep(seconds) ((SleepEx((seconds)*1000, 1)==0)?0:(seconds)) 112#define sleep(seconds) ((SleepEx ((seconds) * 1000, 1)==0) ? 0 : (seconds))
113#define usleep(useconds) ((SleepEx((useconds)/1000, 1)==0)?0:-1) 113#define usleep(useconds) ((SleepEx ((useconds) / 1000, 1)==0) ? 0 : -1)
114#endif 114#endif
115 115
116#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 116#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
117#define _SSIZE_T_DEFINED 117#define _SSIZE_T_DEFINED
118typedef intptr_t ssize_t; 118typedef intptr_t ssize_t;
119#endif /* !_SSIZE_T_DEFINED */ 119#endif /* !_SSIZE_T_DEFINED */
120 120
121#if !defined(_WIN32) || defined(__CYGWIN__) 121#if ! defined(_WIN32) || defined(__CYGWIN__)
122typedef time_t _MHD_TIMEVAL_TV_SEC_TYPE; 122typedef time_t _MHD_TIMEVAL_TV_SEC_TYPE;
123#else /* _WIN32 && ! __CYGWIN__ */ 123#else /* _WIN32 && ! __CYGWIN__ */
124typedef long _MHD_TIMEVAL_TV_SEC_TYPE; 124typedef long _MHD_TIMEVAL_TV_SEC_TYPE;
125#endif /* _WIN32 && ! __CYGWIN__ */ 125#endif /* _WIN32 && ! __CYGWIN__ */
126 126
127#if !defined(IPPROTO_IPV6) && defined(_MSC_FULL_VER) && _WIN32_WINNT >= 0x0501 127#if ! defined(IPPROTO_IPV6) && defined(_MSC_FULL_VER) && _WIN32_WINNT >= 0x0501
128/* VC use IPPROTO_IPV6 as part of enum */ 128/* VC use IPPROTO_IPV6 as part of enum */
129#define IPPROTO_IPV6 IPPROTO_IPV6 129#define IPPROTO_IPV6 IPPROTO_IPV6
130#endif 130#endif
diff --git a/src/lib/action_continue.c b/src/lib/action_continue.c
index 20c351ad..9d98940b 100644
--- a/src/lib/action_continue.c
+++ b/src/lib/action_continue.c
@@ -35,11 +35,11 @@
35 */ 35 */
36static enum MHD_StatusCode 36static enum MHD_StatusCode
37cont_action (void *cls, 37cont_action (void *cls,
38 struct MHD_Request *request) 38 struct MHD_Request *request)
39{ 39{
40 (void) cls; 40 (void) cls;
41 (void) request; 41 (void) request;
42 /* not sure yet, but this function body may 42 /* not sure yet, but this function body may
43 just legitimately stay empty... */ 43 just legitimately stay empty... */
44 return MHD_SC_OK; 44 return MHD_SC_OK;
45} 45}
diff --git a/src/lib/action_from_response.c b/src/lib/action_from_response.c
index 43f33cb5..6253fb22 100644
--- a/src/lib/action_from_response.c
+++ b/src/lib/action_from_response.c
@@ -36,7 +36,7 @@
36 */ 36 */
37static enum MHD_StatusCode 37static enum MHD_StatusCode
38response_action (void *cls, 38response_action (void *cls,
39 struct MHD_Request *request) 39 struct MHD_Request *request)
40{ 40{
41 struct MHD_Response *response = cls; 41 struct MHD_Response *response = cls;
42 struct MHD_Daemon *daemon = request->daemon; 42 struct MHD_Daemon *daemon = request->daemon;
@@ -49,14 +49,15 @@ response_action (void *cls,
49#ifdef UPGRADE_SUPPORT 49#ifdef UPGRADE_SUPPORT
50 if ( (NULL != response->upgrade_handler) && 50 if ( (NULL != response->upgrade_handler) &&
51 daemon->disallow_upgrade ) 51 daemon->disallow_upgrade )
52 { 52 {
53#ifdef HAVE_MESSAGES 53#ifdef HAVE_MESSAGES
54 MHD_DLOG (daemon, 54 MHD_DLOG (daemon,
55 MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED, 55 MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED,
56 _("Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n")); 56 _ (
57 "Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
57#endif 58#endif
58 return MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED; 59 return MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED;
59 } 60 }
60#endif /* UPGRADE_SUPPORT */ 61#endif /* UPGRADE_SUPPORT */
61 request->response = response; 62 request->response = response;
62#if defined(_MHD_HAVE_SENDFILE) 63#if defined(_MHD_HAVE_SENDFILE)
@@ -74,21 +75,21 @@ response_action (void *cls,
74 (MHD_HTTP_OK > response->status_code) || 75 (MHD_HTTP_OK > response->status_code) ||
75 (MHD_HTTP_NO_CONTENT == response->status_code) || 76 (MHD_HTTP_NO_CONTENT == response->status_code) ||
76 (MHD_HTTP_NOT_MODIFIED == response->status_code) ) 77 (MHD_HTTP_NOT_MODIFIED == response->status_code) )
77 { 78 {
78 /* if this is a "HEAD" request, or a status code for 79 /* if this is a "HEAD" request, or a status code for
79 which a body is not allowed, pretend that we 80 which a body is not allowed, pretend that we
80 have already sent the full message body. */ 81 have already sent the full message body. */
81 request->response_write_position = response->total_size; 82 request->response_write_position = response->total_size;
82 } 83 }
83 if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && 84 if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) &&
84 ( (MHD_METHOD_POST == request->method) || 85 ( (MHD_METHOD_POST == request->method) ||
85 (MHD_METHOD_PUT == request->method) ) ) 86 (MHD_METHOD_PUT == request->method) ) )
86 { 87 {
87 /* response was queued "early", refuse to read body / footers or 88 /* response was queued "early", refuse to read body / footers or
88 further requests! */ 89 further requests! */
89 request->connection->read_closed = true; 90 request->connection->read_closed = true;
90 request->state = MHD_REQUEST_FOOTERS_RECEIVED; 91 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
91 } 92 }
92 if (! request->in_idle) 93 if (! request->in_idle)
93 (void) MHD_request_handle_idle_ (request); 94 (void) MHD_request_handle_idle_ (request);
94 return MHD_SC_OK; 95 return MHD_SC_OK;
@@ -114,16 +115,16 @@ response_action (void *cls,
114 */ 115 */
115_MHD_EXTERN const struct MHD_Action * 116_MHD_EXTERN const struct MHD_Action *
116MHD_action_from_response (struct MHD_Response *response, 117MHD_action_from_response (struct MHD_Response *response,
117 enum MHD_Bool destroy_after_use) 118 enum MHD_Bool destroy_after_use)
118{ 119{
119 response->action.action = &response_action; 120 response->action.action = &response_action;
120 response->action.action_cls = response; 121 response->action.action_cls = response;
121 if (! destroy_after_use) 122 if (! destroy_after_use)
122 { 123 {
123 MHD_mutex_lock_chk_ (&response->mutex); 124 MHD_mutex_lock_chk_ (&response->mutex);
124 response->reference_count++; 125 response->reference_count++;
125 MHD_mutex_unlock_chk_ (&response->mutex); 126 MHD_mutex_unlock_chk_ (&response->mutex);
126 } 127 }
127 return &response->action; 128 return &response->action;
128} 129}
129 130
diff --git a/src/lib/action_parse_post.c b/src/lib/action_parse_post.c
index c60e793d..53757933 100644
--- a/src/lib/action_parse_post.c
+++ b/src/lib/action_parse_post.c
@@ -52,8 +52,8 @@
52 */ 52 */
53const struct MHD_Action * 53const struct MHD_Action *
54MHD_action_parse_post (size_t buffer_size, 54MHD_action_parse_post (size_t buffer_size,
55 MHD_PostDataIterator iter, 55 MHD_PostDataIterator iter,
56 void *iter_cls) 56 void *iter_cls)
57{ 57{
58 return NULL; /* not yet implemented */ 58 return NULL; /* not yet implemented */
59} 59}
diff --git a/src/lib/action_process_upload.c b/src/lib/action_process_upload.c
index cafd5d3c..0e9722cd 100644
--- a/src/lib/action_process_upload.c
+++ b/src/lib/action_process_upload.c
@@ -49,13 +49,13 @@ struct UploadAction
49 * 49 *
50 * @param cls the `struct UploadAction` with the 50 * @param cls the `struct UploadAction` with the
51 * function we are to call for upload data 51 * function we are to call for upload data
52 * @param request the request for which we are to process 52 * @param request the request for which we are to process
53 * upload data 53 * upload data
54 * @return #MHD_SC_OK on success 54 * @return #MHD_SC_OK on success
55 */ 55 */
56static enum MHD_StatusCode 56static enum MHD_StatusCode
57upload_action (void *cls, 57upload_action (void *cls,
58 struct MHD_Request *request) 58 struct MHD_Request *request)
59{ 59{
60 struct UploadAction *ua = cls; 60 struct UploadAction *ua = cls;
61 61
@@ -75,7 +75,7 @@ upload_action (void *cls,
75 */ 75 */
76const struct MHD_Action * 76const struct MHD_Action *
77MHD_action_process_upload (MHD_UploadCallback uc, 77MHD_action_process_upload (MHD_UploadCallback uc,
78 void *uc_cls) 78 void *uc_cls)
79{ 79{
80 struct UploadAction *ua; 80 struct UploadAction *ua;
81 81
@@ -90,5 +90,3 @@ MHD_action_process_upload (MHD_UploadCallback uc,
90 90
91 91
92/* end of action_process_upload.c */ 92/* end of action_process_upload.c */
93
94
diff --git a/src/lib/action_suspend.c b/src/lib/action_suspend.c
index bf5adc34..c176e494 100644
--- a/src/lib/action_suspend.c
+++ b/src/lib/action_suspend.c
@@ -35,7 +35,7 @@
35 */ 35 */
36static enum MHD_StatusCode 36static enum MHD_StatusCode
37suspend_action (void *cls, 37suspend_action (void *cls,
38 struct MHD_Request *request) 38 struct MHD_Request *request)
39{ 39{
40 (void) cls; 40 (void) cls;
41 struct MHD_Connection *connection = request->connection; 41 struct MHD_Connection *connection = request->connection;
@@ -43,24 +43,24 @@ suspend_action (void *cls,
43 43
44 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 44 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
45 if (connection->resuming) 45 if (connection->resuming)
46 { 46 {
47 /* suspending again while we didn't even complete resuming yet */ 47 /* suspending again while we didn't even complete resuming yet */
48 connection->resuming = false; 48 connection->resuming = false;
49 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 49 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
50 return MHD_SC_OK; 50 return MHD_SC_OK;
51 } 51 }
52 if (daemon->threading_mode != MHD_TM_THREAD_PER_CONNECTION) 52 if (daemon->threading_mode != MHD_TM_THREAD_PER_CONNECTION)
53 { 53 {
54 if (connection->connection_timeout == 54 if (connection->connection_timeout ==
55 daemon->connection_default_timeout) 55 daemon->connection_default_timeout)
56 XDLL_remove (daemon->normal_timeout_head, 56 XDLL_remove (daemon->normal_timeout_head,
57 daemon->normal_timeout_tail, 57 daemon->normal_timeout_tail,
58 connection); 58 connection);
59 else 59 else
60 XDLL_remove (daemon->manual_timeout_head, 60 XDLL_remove (daemon->manual_timeout_head,
61 daemon->manual_timeout_tail, 61 daemon->manual_timeout_tail,
62 connection); 62 connection);
63 } 63 }
64 DLL_remove (daemon->connections_head, 64 DLL_remove (daemon->connections_head,
65 daemon->connections_tail, 65 daemon->connections_tail,
66 connection); 66 connection);
@@ -71,25 +71,25 @@ suspend_action (void *cls,
71 connection->suspended = true; 71 connection->suspended = true;
72#ifdef EPOLL_SUPPORT 72#ifdef EPOLL_SUPPORT
73 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 73 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
74 {
75 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
76 {
77 EDLL_remove (daemon->eready_head,
78 daemon->eready_tail,
79 connection);
80 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
81 }
82 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET))
74 { 83 {
75 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 84 if (0 != epoll_ctl (daemon->epoll_fd,
76 { 85 EPOLL_CTL_DEL,
77 EDLL_remove (daemon->eready_head, 86 connection->socket_fd,
78 daemon->eready_tail, 87 NULL))
79 connection); 88 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
80 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 89 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
81 }
82 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET))
83 {
84 if (0 != epoll_ctl (daemon->epoll_fd,
85 EPOLL_CTL_DEL,
86 connection->socket_fd,
87 NULL))
88 MHD_PANIC (_("Failed to remove FD from epoll set\n"));
89 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
90 }
91 connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED;
92 } 90 }
91 connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED;
92 }
93#endif 93#endif
94 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 94 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
95 return MHD_SC_OK; 95 return MHD_SC_OK;
diff --git a/src/lib/base64.c b/src/lib/base64.c
index 3dc7a142..d7d1ec92 100644
--- a/src/lib/base64.c
+++ b/src/lib/base64.c
@@ -9,45 +9,46 @@
9#include "base64.h" 9#include "base64.h"
10 10
11static const char base64_digits[] = 11static const char base64_digits[] =
12 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 14 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
15 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
16 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 16 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26,
17 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 17 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
18 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
24 24
25 25
26char * 26char *
27BASE64Decode(const char* src) 27BASE64Decode (const char*src)
28{ 28{
29 size_t in_len = strlen (src); 29 size_t in_len = strlen (src);
30 char* dest; 30 char*dest;
31 char* result; 31 char*result;
32 32
33 if (in_len % 4) 33 if (in_len % 4)
34 { 34 {
35 /* Wrong base64 string length */ 35 /* Wrong base64 string length */
36 return NULL; 36 return NULL;
37 } 37 }
38 result = dest = malloc(in_len / 4 * 3 + 1); 38 result = dest = malloc (in_len / 4 * 3 + 1);
39 if (NULL == result) 39 if (NULL == result)
40 return NULL; /* out of memory */ 40 return NULL; /* out of memory */
41 while (*src) { 41 while (*src)
42 char a = base64_digits[(unsigned char)*(src++)]; 42 {
43 char b = base64_digits[(unsigned char)*(src++)]; 43 char a = base64_digits[(unsigned char) *(src++)];
44 char c = base64_digits[(unsigned char)*(src++)]; 44 char b = base64_digits[(unsigned char) *(src++)];
45 char d = base64_digits[(unsigned char)*(src++)]; 45 char c = base64_digits[(unsigned char) *(src++)];
46 char d = base64_digits[(unsigned char) *(src++)];
46 *(dest++) = (a << 2) | ((b & 0x30) >> 4); 47 *(dest++) = (a << 2) | ((b & 0x30) >> 4);
47 if (c == (char)-1) 48 if (c == (char) -1)
48 break; 49 break;
49 *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2); 50 *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
50 if (d == (char)-1) 51 if (d == (char) -1)
51 break; 52 break;
52 *(dest++) = ((c & 0x03) << 6) | d; 53 *(dest++) = ((c & 0x03) << 6) | d;
53 } 54 }
diff --git a/src/lib/base64.h b/src/lib/base64.h
index ba96ca0c..65042c0b 100644
--- a/src/lib/base64.h
+++ b/src/lib/base64.h
@@ -12,6 +12,6 @@
12#include "platform.h" 12#include "platform.h"
13 13
14char * 14char *
15BASE64Decode(const char* src); 15BASE64Decode (const char*src);
16 16
17#endif /* !BASE64_H */ 17#endif /* !BASE64_H */
diff --git a/src/lib/connection_add.c b/src/lib/connection_add.c
index cd933d06..aaf04712 100644
--- a/src/lib/connection_add.c
+++ b/src/lib/connection_add.c
@@ -53,14 +53,14 @@ thread_main_connection_upgrade (struct MHD_Connection *con)
53 with the socket; */ 53 with the socket; */
54 if ( (NULL != daemon->tls_api) && 54 if ( (NULL != daemon->tls_api) &&
55 (MHD_ELS_POLL != daemon->event_loop_syscall) ) 55 (MHD_ELS_POLL != daemon->event_loop_syscall) )
56 { 56 {
57 MHD_daemon_upgrade_connection_with_select_ (con); 57 MHD_daemon_upgrade_connection_with_select_ (con);
58 } 58 }
59#ifdef HAVE_POLL 59#ifdef HAVE_POLL
60 else if (NULL != daemon->tls_api) 60 else if (NULL != daemon->tls_api)
61 { 61 {
62 MHD_daemon_upgrade_connection_with_poll_ (con); 62 MHD_daemon_upgrade_connection_with_poll_ (con);
63 } 63 }
64#endif 64#endif
65 /* end HTTPS */ 65 /* end HTTPS */
66#endif /* HTTPS_SUPPORT */ 66#endif /* HTTPS_SUPPORT */
@@ -111,342 +111,344 @@ thread_main_handle_connection (void *data)
111#endif /* ! HAVE_POLL */ 111#endif /* ! HAVE_POLL */
112 bool was_suspended = false; 112 bool was_suspended = false;
113 113
114 MHD_thread_init_(&con->pid); 114 MHD_thread_init_ (&con->pid);
115 115
116 while ( (! daemon->shutdown) && 116 while ( (! daemon->shutdown) &&
117 (MHD_REQUEST_CLOSED != con->request.state) ) 117 (MHD_REQUEST_CLOSED != con->request.state) )
118 { 118 {
119 const time_t timeout = daemon->connection_default_timeout; 119 const time_t timeout = daemon->connection_default_timeout;
120#ifdef UPGRADE_SUPPORT 120#ifdef UPGRADE_SUPPORT
121 struct MHD_UpgradeResponseHandle * const urh = con->request.urh; 121 struct MHD_UpgradeResponseHandle *const urh = con->request.urh;
122#else /* ! UPGRADE_SUPPORT */ 122#else /* ! UPGRADE_SUPPORT */
123 static const void * const urh = NULL; 123 static const void *const urh = NULL;
124#endif /* ! UPGRADE_SUPPORT */ 124#endif /* ! UPGRADE_SUPPORT */
125 125
126 if ( (con->suspended) && 126 if ( (con->suspended) &&
127 (NULL == urh) ) 127 (NULL == urh) )
128 {
129 /* Connection was suspended, wait for resume. */
130 was_suspended = true;
131 if (! use_poll)
132 {
133 FD_ZERO (&rs);
134 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
135 &rs,
136 NULL,
137 FD_SETSIZE))
128 { 138 {
129 /* Connection was suspended, wait for resume. */
130 was_suspended = true;
131 if (! use_poll)
132 {
133 FD_ZERO (&rs);
134 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
135 &rs,
136 NULL,
137 FD_SETSIZE))
138 {
139 #ifdef HAVE_MESSAGES 139 #ifdef HAVE_MESSAGES
140 MHD_DLOG (con->daemon, 140 MHD_DLOG (con->daemon,
141 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE, 141 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
142 _("Failed to add FD to fd_set\n")); 142 _ ("Failed to add FD to fd_set\n"));
143 #endif 143 #endif
144 goto exit; 144 goto exit;
145 } 145 }
146 if (0 > MHD_SYS_select_ (MHD_itc_r_fd_ (daemon->itc) + 1, 146 if (0 > MHD_SYS_select_ (MHD_itc_r_fd_ (daemon->itc) + 1,
147 &rs, 147 &rs,
148 NULL, 148 NULL,
149 NULL, 149 NULL,
150 NULL)) 150 NULL))
151 { 151 {
152 const int err = MHD_socket_get_error_(); 152 const int err = MHD_socket_get_error_ ();
153 153
154 if (MHD_SCKT_ERR_IS_EINTR_(err)) 154 if (MHD_SCKT_ERR_IS_EINTR_ (err))
155 continue; 155 continue;
156#ifdef HAVE_MESSAGES 156#ifdef HAVE_MESSAGES
157 MHD_DLOG (con->daemon, 157 MHD_DLOG (con->daemon,
158 MHD_SC_UNEXPECTED_SELECT_ERROR, 158 MHD_SC_UNEXPECTED_SELECT_ERROR,
159 _("Error during select (%d): `%s'\n"), 159 _ ("Error during select (%d): `%s'\n"),
160 err, 160 err,
161 MHD_socket_strerr_ (err)); 161 MHD_socket_strerr_ (err));
162#endif 162#endif
163 break; 163 break;
164 } 164 }
165 } 165 }
166#ifdef HAVE_POLL 166#ifdef HAVE_POLL
167 else /* use_poll */ 167 else /* use_poll */
168 { 168 {
169 p[0].events = POLLIN; 169 p[0].events = POLLIN;
170 p[0].fd = MHD_itc_r_fd_ (daemon->itc); 170 p[0].fd = MHD_itc_r_fd_ (daemon->itc);
171 p[0].revents = 0; 171 p[0].revents = 0;
172 if (0 > MHD_sys_poll_ (p, 172 if (0 > MHD_sys_poll_ (p,
173 1, 173 1,
174 -1)) 174 -1))
175 { 175 {
176 if (MHD_SCKT_LAST_ERR_IS_(MHD_SCKT_EINTR_)) 176 if (MHD_SCKT_LAST_ERR_IS_ (MHD_SCKT_EINTR_))
177 continue; 177 continue;
178#ifdef HAVE_MESSAGES 178#ifdef HAVE_MESSAGES
179 MHD_DLOG (con->daemon, 179 MHD_DLOG (con->daemon,
180 MHD_SC_UNEXPECTED_POLL_ERROR, 180 MHD_SC_UNEXPECTED_POLL_ERROR,
181 _("Error during poll: `%s'\n"), 181 _ ("Error during poll: `%s'\n"),
182 MHD_socket_last_strerr_ ()); 182 MHD_socket_last_strerr_ ());
183#endif 183#endif
184 break; 184 break;
185 } 185 }
186 } 186 }
187#endif /* HAVE_POLL */ 187#endif /* HAVE_POLL */
188 MHD_itc_clear_ (daemon->itc); 188 MHD_itc_clear_ (daemon->itc);
189 continue; /* Check again for resume. */ 189 continue; /* Check again for resume. */
190 } /* End of "suspended" branch. */ 190 } /* End of "suspended" branch. */
191 191
192 if (was_suspended) 192 if (was_suspended)
193 { 193 {
194 MHD_connection_update_last_activity_ (con); /* Reset timeout timer. */ 194 MHD_connection_update_last_activity_ (con); /* Reset timeout timer. */
195 /* Process response queued during suspend and update states. */ 195 /* Process response queued during suspend and update states. */
196 MHD_request_handle_idle_ (&con->request); 196 MHD_request_handle_idle_ (&con->request);
197 was_suspended = false; 197 was_suspended = false;
198 } 198 }
199 199
200 tvp = NULL; 200 tvp = NULL;
201 201
202 if ( (MHD_EVENT_LOOP_INFO_BLOCK == con->request.event_loop_info) 202 if ( (MHD_EVENT_LOOP_INFO_BLOCK == con->request.event_loop_info)
203#ifdef HTTPS_SUPPORT 203#ifdef HTTPS_SUPPORT
204 || ( (con->tls_read_ready) && 204 || ( (con->tls_read_ready) &&
205 (MHD_EVENT_LOOP_INFO_READ == con->request.event_loop_info) ) 205 (MHD_EVENT_LOOP_INFO_READ == con->request.event_loop_info) )
206#endif /* HTTPS_SUPPORT */ 206#endif /* HTTPS_SUPPORT */
207 ) 207 )
208 { 208 {
209 /* do not block: more data may be inside of TLS buffers waiting or 209 /* do not block: more data may be inside of TLS buffers waiting or
210 * application must provide response data */ 210 * application must provide response data */
211 tv.tv_sec = 0; 211 tv.tv_sec = 0;
212 tv.tv_usec = 0; 212 tv.tv_usec = 0;
213 tvp = &tv; 213 tvp = &tv;
214 } 214 }
215 if ( (NULL == tvp) && 215 if ( (NULL == tvp) &&
216 (timeout > 0) ) 216 (timeout > 0) )
217 { 217 {
218 now = MHD_monotonic_sec_counter(); 218 now = MHD_monotonic_sec_counter ();
219 if (now - con->last_activity > timeout) 219 if (now - con->last_activity > timeout)
220 tv.tv_sec = 0; 220 tv.tv_sec = 0;
221 else 221 else
222 { 222 {
223 const time_t seconds_left = timeout - (now - con->last_activity); 223 const time_t seconds_left = timeout - (now - con->last_activity);
224#if !defined(_WIN32) || defined(__CYGWIN__) 224#if ! defined(_WIN32) || defined(__CYGWIN__)
225 tv.tv_sec = seconds_left; 225 tv.tv_sec = seconds_left;
226#else /* _WIN32 && !__CYGWIN__ */ 226#else /* _WIN32 && !__CYGWIN__ */
227 if (seconds_left > TIMEVAL_TV_SEC_MAX) 227 if (seconds_left > TIMEVAL_TV_SEC_MAX)
228 tv.tv_sec = TIMEVAL_TV_SEC_MAX; 228 tv.tv_sec = TIMEVAL_TV_SEC_MAX;
229 else 229 else
230 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) seconds_left; 230 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) seconds_left;
231#endif /* _WIN32 && ! __CYGWIN__ */ 231#endif /* _WIN32 && ! __CYGWIN__ */
232 } 232 }
233 tv.tv_usec = 0; 233 tv.tv_usec = 0;
234 tvp = &tv; 234 tvp = &tv;
235 } 235 }
236 if (! use_poll) 236 if (! use_poll)
237 { 237 {
238 /* use select */ 238 /* use select */
239 bool err_state = false; 239 bool err_state = false;
240 240
241 FD_ZERO (&rs); 241 FD_ZERO (&rs);
242 FD_ZERO (&ws); 242 FD_ZERO (&ws);
243 FD_ZERO (&es); 243 FD_ZERO (&es);
244 maxsock = MHD_INVALID_SOCKET; 244 maxsock = MHD_INVALID_SOCKET;
245 switch (con->request.event_loop_info) 245 switch (con->request.event_loop_info)
246 { 246 {
247 case MHD_EVENT_LOOP_INFO_READ: 247 case MHD_EVENT_LOOP_INFO_READ:
248 if (! MHD_add_to_fd_set_ (con->socket_fd, 248 if (! MHD_add_to_fd_set_ (con->socket_fd,
249 &rs, 249 &rs,
250 &maxsock, 250 &maxsock,
251 FD_SETSIZE)) 251 FD_SETSIZE))
252 err_state = true; 252 err_state = true;
253 break; 253 break;
254 case MHD_EVENT_LOOP_INFO_WRITE: 254 case MHD_EVENT_LOOP_INFO_WRITE:
255 if (! MHD_add_to_fd_set_ (con->socket_fd, 255 if (! MHD_add_to_fd_set_ (con->socket_fd,
256 &ws, 256 &ws,
257 &maxsock, 257 &maxsock,
258 FD_SETSIZE)) 258 FD_SETSIZE))
259 err_state = true; 259 err_state = true;
260 break; 260 break;
261 case MHD_EVENT_LOOP_INFO_BLOCK: 261 case MHD_EVENT_LOOP_INFO_BLOCK:
262 if (! MHD_add_to_fd_set_ (con->socket_fd, 262 if (! MHD_add_to_fd_set_ (con->socket_fd,
263 &es, 263 &es,
264 &maxsock, 264 &maxsock,
265 FD_SETSIZE)) 265 FD_SETSIZE))
266 err_state = true; 266 err_state = true;
267 break; 267 break;
268 case MHD_EVENT_LOOP_INFO_CLEANUP: 268 case MHD_EVENT_LOOP_INFO_CLEANUP:
269 /* how did we get here!? */ 269 /* how did we get here!? */
270 goto exit; 270 goto exit;
271 } 271 }
272#if WINDOWS 272#if WINDOWS
273 if (MHD_ITC_IS_VALID_(daemon->itc) ) 273 if (MHD_ITC_IS_VALID_ (daemon->itc) )
274 { 274 {
275 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc), 275 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
276 &rs, 276 &rs,
277 &maxsock, 277 &maxsock,
278 FD_SETSIZE)) 278 FD_SETSIZE))
279 err_state = 1; 279 err_state = 1;
280 } 280 }
281#endif 281#endif
282 if (err_state) 282 if (err_state)
283 { 283 {
284#ifdef HAVE_MESSAGES 284#ifdef HAVE_MESSAGES
285 MHD_DLOG (con->daemon, 285 MHD_DLOG (con->daemon,
286 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE, 286 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
287 _("Failed to add FD to fd_set\n")); 287 _ ("Failed to add FD to fd_set\n"));
288#endif 288#endif
289 goto exit; 289 goto exit;
290 } 290 }
291 291
292 num_ready = MHD_SYS_select_ (maxsock + 1, 292 num_ready = MHD_SYS_select_ (maxsock + 1,
293 &rs, 293 &rs,
294 &ws, 294 &ws,
295 &es, 295 &es,
296 tvp); 296 tvp);
297 if (num_ready < 0) 297 if (num_ready < 0)
298 { 298 {
299 const int err = MHD_socket_get_error_(); 299 const int err = MHD_socket_get_error_ ();
300 300
301 if (MHD_SCKT_ERR_IS_EINTR_(err)) 301 if (MHD_SCKT_ERR_IS_EINTR_ (err))
302 continue; 302 continue;
303#ifdef HAVE_MESSAGES 303#ifdef HAVE_MESSAGES
304 MHD_DLOG (con->daemon, 304 MHD_DLOG (con->daemon,
305 MHD_SC_UNEXPECTED_SELECT_ERROR, 305 MHD_SC_UNEXPECTED_SELECT_ERROR,
306 _("Error during select (%d): `%s'\n"), 306 _ ("Error during select (%d): `%s'\n"),
307 err, 307 err,
308 MHD_socket_strerr_ (err)); 308 MHD_socket_strerr_ (err));
309#endif 309#endif
310 break; 310 break;
311 } 311 }
312#if WINDOWS 312#if WINDOWS
313 /* Clear ITC before other processing so additional 313 /* Clear ITC before other processing so additional
314 * signals will trigger select() again */ 314 * signals will trigger select() again */
315 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 315 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
316 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc), 316 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc),
317 &rs)) ) 317 &rs)) )
318 MHD_itc_clear_ (daemon->itc); 318 MHD_itc_clear_ (daemon->itc);
319#endif 319#endif
320 if (MHD_NO == 320 if (MHD_NO ==
321 MHD_connection_call_handlers_ (con, 321 MHD_connection_call_handlers_ (con,
322 FD_ISSET (con->socket_fd, 322 FD_ISSET (con->socket_fd,
323 &rs), 323 &rs),
324 FD_ISSET (con->socket_fd, 324 FD_ISSET (con->socket_fd,
325 &ws), 325 &ws),
326 FD_ISSET (con->socket_fd, 326 FD_ISSET (con->socket_fd,
327 &es)) ) 327 &es)) )
328 goto exit; 328 goto exit;
329 } 329 }
330#ifdef HAVE_POLL 330#ifdef HAVE_POLL
331 else 331 else
332 { 332 {
333 /* use poll */ 333 /* use poll */
334 memset (&p, 334 memset (&p,
335 0, 335 0,
336 sizeof (p)); 336 sizeof (p));
337 p[0].fd = con->socket_fd; 337 p[0].fd = con->socket_fd;
338 switch (con->request.event_loop_info) 338 switch (con->request.event_loop_info)
339 { 339 {
340 case MHD_EVENT_LOOP_INFO_READ: 340 case MHD_EVENT_LOOP_INFO_READ:
341 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; 341 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
342 break; 342 break;
343 case MHD_EVENT_LOOP_INFO_WRITE: 343 case MHD_EVENT_LOOP_INFO_WRITE:
344 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; 344 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
345 break; 345 break;
346 case MHD_EVENT_LOOP_INFO_BLOCK: 346 case MHD_EVENT_LOOP_INFO_BLOCK:
347 p[0].events |= MHD_POLL_EVENTS_ERR_DISC; 347 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
348 break; 348 break;
349 case MHD_EVENT_LOOP_INFO_CLEANUP: 349 case MHD_EVENT_LOOP_INFO_CLEANUP:
350 /* how did we get here!? */ 350 /* how did we get here!? */
351 goto exit; 351 goto exit;
352 } 352 }
353#if WINDOWS 353#if WINDOWS
354 extra_slot = 0; 354 extra_slot = 0;
355 if (MHD_ITC_IS_VALID_(daemon->itc)) 355 if (MHD_ITC_IS_VALID_ (daemon->itc))
356 { 356 {
357 p[1].events |= POLLIN; 357 p[1].events |= POLLIN;
358 p[1].fd = MHD_itc_r_fd_ (daemon->itc); 358 p[1].fd = MHD_itc_r_fd_ (daemon->itc);
359 p[1].revents = 0; 359 p[1].revents = 0;
360 extra_slot = 1; 360 extra_slot = 1;
361 } 361 }
362#endif 362#endif
363 if (MHD_sys_poll_ (p, 363 if (MHD_sys_poll_ (p,
364#if WINDOWS 364#if WINDOWS
365 1 + extra_slot, 365 1 + extra_slot,
366#else 366#else
367 1, 367 1,
368#endif 368#endif
369 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0) 369 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0)
370 { 370 {
371 if (MHD_SCKT_LAST_ERR_IS_(MHD_SCKT_EINTR_)) 371 if (MHD_SCKT_LAST_ERR_IS_ (MHD_SCKT_EINTR_))
372 continue; 372 continue;
373#ifdef HAVE_MESSAGES 373#ifdef HAVE_MESSAGES
374 MHD_DLOG (con->daemon, 374 MHD_DLOG (con->daemon,
375 MHD_SC_UNEXPECTED_POLL_ERROR, 375 MHD_SC_UNEXPECTED_POLL_ERROR,
376 _("Error during poll: `%s'\n"), 376 _ ("Error during poll: `%s'\n"),
377 MHD_socket_last_strerr_ ()); 377 MHD_socket_last_strerr_ ());
378#endif 378#endif
379 break; 379 break;
380 } 380 }
381#if WINDOWS 381#if WINDOWS
382 /* Clear ITC before other processing so additional 382 /* Clear ITC before other processing so additional
383 * signals will trigger poll() again */ 383 * signals will trigger poll() again */
384 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 384 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
385 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) ) 385 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) )
386 MHD_itc_clear_ (daemon->itc); 386 MHD_itc_clear_ (daemon->itc);
387#endif 387#endif
388 if (MHD_NO == 388 if (MHD_NO ==
389 MHD_connection_call_handlers_ (con, 389 MHD_connection_call_handlers_ (con,
390 0 != (p[0].revents & POLLIN), 390 (0 != (p[0].revents & POLLIN)),
391 0 != (p[0].revents & POLLOUT), 391 (0 != (p[0].revents & POLLOUT)),
392 0 != (p[0].revents & (POLLERR | MHD_POLL_REVENTS_ERR_DISC)))) 392 (0 != (p[0].revents & (POLLERR
393 goto exit; 393 |
394 } 394 MHD_POLL_REVENTS_ERR_DISC))) ))
395 goto exit;
396 }
395#endif 397#endif
396#ifdef UPGRADE_SUPPORT 398#ifdef UPGRADE_SUPPORT
397 if (MHD_REQUEST_UPGRADE == con->request.state) 399 if (MHD_REQUEST_UPGRADE == con->request.state)
398 { 400 {
399 /* Normal HTTP processing is finished, 401 /* Normal HTTP processing is finished,
400 * notify application. */ 402 * notify application. */
401 if (NULL != con->request.response->termination_cb) 403 if (NULL != con->request.response->termination_cb)
402 con->request.response->termination_cb 404 con->request.response->termination_cb
403 (con->request.response->termination_cb_cls, 405 (con->request.response->termination_cb_cls,
404 MHD_REQUEST_TERMINATED_COMPLETED_OK, 406 MHD_REQUEST_TERMINATED_COMPLETED_OK,
405 con->request.client_context); 407 con->request.client_context);
406 thread_main_connection_upgrade (con); 408 thread_main_connection_upgrade (con);
407 /* MHD_connection_finish_forward_() was called by thread_main_connection_upgrade(). */ 409 /* MHD_connection_finish_forward_() was called by thread_main_connection_upgrade(). */
408 410
409 /* "Upgraded" data will not be used in this thread from this point. */ 411 /* "Upgraded" data will not be used in this thread from this point. */
410 con->request.urh->clean_ready = true; 412 con->request.urh->clean_ready = true;
411 /* If 'urh->was_closed' set to true, connection will be 413 /* If 'urh->was_closed' set to true, connection will be
412 * moved immediately to cleanup list. Otherwise connection 414 * moved immediately to cleanup list. Otherwise connection
413 * will stay in suspended list until 'urh' will be marked 415 * will stay in suspended list until 'urh' will be marked
414 * with 'was_closed' by application. */ 416 * with 'was_closed' by application. */
415 MHD_request_resume (&con->request); 417 MHD_request_resume (&con->request);
416 418
417 /* skip usual clean up */ 419 /* skip usual clean up */
418 return (MHD_THRD_RTRN_TYPE_) 0; 420 return (MHD_THRD_RTRN_TYPE_) 0;
419 }
420#endif /* UPGRADE_SUPPORT */
421 } 421 }
422#endif /* UPGRADE_SUPPORT */
423 }
422#if DEBUG_CLOSE 424#if DEBUG_CLOSE
423#ifdef HAVE_MESSAGES 425#ifdef HAVE_MESSAGES
424 MHD_DLOG (con->daemon, 426 MHD_DLOG (con->daemon,
425 MHD_SC_THREAD_TERMINATING, 427 MHD_SC_THREAD_TERMINATING,
426 _("Processing thread terminating. Closing connection\n")); 428 _ ("Processing thread terminating. Closing connection\n"));
427#endif 429#endif
428#endif 430#endif
429 if (MHD_REQUEST_CLOSED != con->request.state) 431 if (MHD_REQUEST_CLOSED != con->request.state)
430 MHD_connection_close_ (con, 432 MHD_connection_close_ (con,
431 (daemon->shutdown) ? 433 (daemon->shutdown) ?
432 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: 434 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN :
433 MHD_REQUEST_TERMINATED_WITH_ERROR); 435 MHD_REQUEST_TERMINATED_WITH_ERROR);
434 MHD_request_handle_idle_ (&con->request); 436 MHD_request_handle_idle_ (&con->request);
435exit: 437exit:
436 if (NULL != con->request.response) 438 if (NULL != con->request.response)
437 { 439 {
438 MHD_response_queue_for_destroy (con->request.response); 440 MHD_response_queue_for_destroy (con->request.response);
439 con->request.response = NULL; 441 con->request.response = NULL;
440 } 442 }
441 443
442 if (MHD_INVALID_SOCKET != con->socket_fd) 444 if (MHD_INVALID_SOCKET != con->socket_fd)
443 { 445 {
444 shutdown (con->socket_fd, 446 shutdown (con->socket_fd,
445 SHUT_WR); 447 SHUT_WR);
446 /* 'socket_fd' can be used in other thread to signal shutdown. 448 /* 'socket_fd' can be used in other thread to signal shutdown.
447 * To avoid data races, do not close socket here. Daemon will 449 * To avoid data races, do not close socket here. Daemon will
448 * use more connections only after cleanup anyway. */ 450 * use more connections only after cleanup anyway. */
449 } 451 }
450 return (MHD_THRD_RTRN_TYPE_) 0; 452 return (MHD_THRD_RTRN_TYPE_) 0;
451} 453}
452 454
@@ -469,9 +471,9 @@ recv_param_adapter (struct MHD_Connection *connection,
469 471
470 if ( (MHD_INVALID_SOCKET == connection->socket_fd) || 472 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
471 (MHD_REQUEST_CLOSED == connection->request.state) ) 473 (MHD_REQUEST_CLOSED == connection->request.state) )
472 { 474 {
473 return MHD_ERR_NOTCONN_; 475 return MHD_ERR_NOTCONN_;
474 } 476 }
475 if (i > MHD_SCKT_SEND_MAX_SIZE_) 477 if (i > MHD_SCKT_SEND_MAX_SIZE_)
476 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ 478 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
477 479
@@ -479,25 +481,25 @@ recv_param_adapter (struct MHD_Connection *connection,
479 other, 481 other,
480 i); 482 i);
481 if (0 > ret) 483 if (0 > ret)
484 {
485 const int err = MHD_socket_get_error_ ();
486 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
482 { 487 {
483 const int err = MHD_socket_get_error_ ();
484 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
485 {
486#ifdef EPOLL_SUPPORT 488#ifdef EPOLL_SUPPORT
487 /* Got EAGAIN --- no longer read-ready */ 489 /* Got EAGAIN --- no longer read-ready */
488 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 490 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
489#endif /* EPOLL_SUPPORT */ 491#endif /* EPOLL_SUPPORT */
490 return MHD_ERR_AGAIN_; 492 return MHD_ERR_AGAIN_;
491 }
492 if (MHD_SCKT_ERR_IS_EINTR_ (err))
493 return MHD_ERR_AGAIN_;
494 if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
495 return MHD_ERR_CONNRESET_;
496 /* Treat any other error as hard error. */
497 return MHD_ERR_NOTCONN_;
498 } 493 }
494 if (MHD_SCKT_ERR_IS_EINTR_ (err))
495 return MHD_ERR_AGAIN_;
496 if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
497 return MHD_ERR_CONNRESET_;
498 /* Treat any other error as hard error. */
499 return MHD_ERR_NOTCONN_;
500 }
499#ifdef EPOLL_SUPPORT 501#ifdef EPOLL_SUPPORT
500 else if (i > (size_t)ret) 502 else if (i > (size_t) ret)
501 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 503 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
502#endif /* EPOLL_SUPPORT */ 504#endif /* EPOLL_SUPPORT */
503 return ret; 505 return ret;
@@ -522,9 +524,9 @@ send_param_adapter (struct MHD_Connection *connection,
522 524
523 if ( (MHD_INVALID_SOCKET == connection->socket_fd) || 525 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
524 (MHD_REQUEST_CLOSED == connection->request.state) ) 526 (MHD_REQUEST_CLOSED == connection->request.state) )
525 { 527 {
526 return MHD_ERR_NOTCONN_; 528 return MHD_ERR_NOTCONN_;
527 } 529 }
528 if (i > MHD_SCKT_SEND_MAX_SIZE_) 530 if (i > MHD_SCKT_SEND_MAX_SIZE_)
529 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ 531 i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
530 532
@@ -532,26 +534,26 @@ send_param_adapter (struct MHD_Connection *connection,
532 other, 534 other,
533 i); 535 i);
534 if (0 > ret) 536 if (0 > ret)
535 { 537 {
536 const int err = MHD_socket_get_error_(); 538 const int err = MHD_socket_get_error_ ();
537 539
538 if (MHD_SCKT_ERR_IS_EAGAIN_(err)) 540 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
539 { 541 {
540#ifdef EPOLL_SUPPORT 542#ifdef EPOLL_SUPPORT
541 /* EAGAIN --- no longer write-ready */ 543 /* EAGAIN --- no longer write-ready */
542 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 544 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
543#endif /* EPOLL_SUPPORT */ 545#endif /* EPOLL_SUPPORT */
544 return MHD_ERR_AGAIN_; 546 return MHD_ERR_AGAIN_;
545 }
546 if (MHD_SCKT_ERR_IS_EINTR_ (err))
547 return MHD_ERR_AGAIN_;
548 if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
549 return MHD_ERR_CONNRESET_;
550 /* Treat any other error as hard error. */
551 return MHD_ERR_NOTCONN_;
552 } 547 }
548 if (MHD_SCKT_ERR_IS_EINTR_ (err))
549 return MHD_ERR_AGAIN_;
550 if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
551 return MHD_ERR_CONNRESET_;
552 /* Treat any other error as hard error. */
553 return MHD_ERR_NOTCONN_;
554 }
553#ifdef EPOLL_SUPPORT 555#ifdef EPOLL_SUPPORT
554 else if (i > (size_t)ret) 556 else if (i > (size_t) ret)
555 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 557 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
556#endif /* EPOLL_SUPPORT */ 558#endif /* EPOLL_SUPPORT */
557 return ret; 559 return ret;
@@ -582,11 +584,11 @@ send_param_adapter (struct MHD_Connection *connection,
582 */ 584 */
583static enum MHD_StatusCode 585static enum MHD_StatusCode
584internal_add_connection (struct MHD_Daemon *daemon, 586internal_add_connection (struct MHD_Daemon *daemon,
585 MHD_socket client_socket, 587 MHD_socket client_socket,
586 const struct sockaddr *addr, 588 const struct sockaddr *addr,
587 socklen_t addrlen, 589 socklen_t addrlen,
588 bool external_add, 590 bool external_add,
589 bool non_blck) 591 bool non_blck)
590{ 592{
591 enum MHD_StatusCode sc; 593 enum MHD_StatusCode sc;
592 struct MHD_Connection *connection; 594 struct MHD_Connection *connection;
@@ -594,78 +596,78 @@ internal_add_connection (struct MHD_Daemon *daemon,
594 596
595 /* Direct add to master daemon could happen only with "external" add mode. */ 597 /* Direct add to master daemon could happen only with "external" add mode. */
596 mhd_assert ( (NULL == daemon->worker_pool) || 598 mhd_assert ( (NULL == daemon->worker_pool) ||
597 (external_add) ); 599 (external_add) );
598 if ( (external_add) && 600 if ( (external_add) &&
599 (NULL != daemon->worker_pool) ) 601 (NULL != daemon->worker_pool) )
600 { 602 {
601 unsigned int i; 603 unsigned int i;
602 604
603 /* have a pool, try to find a pool with capacity; we use the 605 /* have a pool, try to find a pool with capacity; we use the
604 socket as the initial offset into the pool for load 606 socket as the initial offset into the pool for load
605 balancing */ 607 balancing */
606 for (i = 0; i < daemon->worker_pool_size; ++i) 608 for (i = 0; i < daemon->worker_pool_size; ++i)
607 { 609 {
608 struct MHD_Daemon * const worker = 610 struct MHD_Daemon *const worker =
609 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size]; 611 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size];
610 if (worker->connections < worker->global_connection_limit) 612 if (worker->connections < worker->global_connection_limit)
611 return internal_add_connection (worker, 613 return internal_add_connection (worker,
612 client_socket, 614 client_socket,
613 addr, 615 addr,
614 addrlen, 616 addrlen,
615 true, 617 true,
616 non_blck); 618 non_blck);
617 } 619 }
618 /* all pools are at their connection limit, must refuse */ 620 /* all pools are at their connection limit, must refuse */
619 MHD_socket_close_chk_ (client_socket); 621 MHD_socket_close_chk_ (client_socket);
620#if ENFILE 622#if ENFILE
621 errno = ENFILE; 623 errno = ENFILE;
622#endif 624#endif
623 return MHD_SC_LIMIT_CONNECTIONS_REACHED; 625 return MHD_SC_LIMIT_CONNECTIONS_REACHED;
624 } 626 }
625 627
626 if ( (! MHD_SCKT_FD_FITS_FDSET_(client_socket, 628 if ( (! MHD_SCKT_FD_FITS_FDSET_ (client_socket,
627 NULL)) && 629 NULL)) &&
628 (MHD_ELS_SELECT == daemon->event_loop_syscall) ) 630 (MHD_ELS_SELECT == daemon->event_loop_syscall) )
629 { 631 {
630#ifdef HAVE_MESSAGES 632#ifdef HAVE_MESSAGES
631 MHD_DLOG (daemon, 633 MHD_DLOG (daemon,
632 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE, 634 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
633 _("Socket descriptor larger than FD_SETSIZE: %d > %d\n"), 635 _ ("Socket descriptor larger than FD_SETSIZE: %d > %d\n"),
634 (int) client_socket, 636 (int) client_socket,
635 (int) FD_SETSIZE); 637 (int) FD_SETSIZE);
636#endif 638#endif
637 MHD_socket_close_chk_ (client_socket); 639 MHD_socket_close_chk_ (client_socket);
638#if EINVAL 640#if EINVAL
639 errno = EINVAL; 641 errno = EINVAL;
640#endif 642#endif
641 return MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 643 return MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
642 } 644 }
643 645
644#ifdef MHD_socket_nosignal_ 646#ifdef MHD_socket_nosignal_
645 if (! MHD_socket_nosignal_ (client_socket)) 647 if (! MHD_socket_nosignal_ (client_socket))
646 { 648 {
647#ifdef HAVE_MESSAGES 649#ifdef HAVE_MESSAGES
648 MHD_DLOG (daemon, 650 MHD_DLOG (daemon,
649 MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED, 651 MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED,
650 _("Failed to set SO_NOSIGPIPE on accepted socket: %s\n"), 652 _ ("Failed to set SO_NOSIGPIPE on accepted socket: %s\n"),
651 MHD_socket_last_strerr_()); 653 MHD_socket_last_strerr_ ());
652#endif 654#endif
653#ifndef MSG_NOSIGNAL 655#ifndef MSG_NOSIGNAL
654 /* Cannot use socket as it can produce SIGPIPE. */ 656 /* Cannot use socket as it can produce SIGPIPE. */
655#ifdef ENOTSOCK 657#ifdef ENOTSOCK
656 errno = ENOTSOCK; 658 errno = ENOTSOCK;
657#endif /* ENOTSOCK */ 659#endif /* ENOTSOCK */
658 return MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED; 660 return MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED;
659#endif /* ! MSG_NOSIGNAL */ 661#endif /* ! MSG_NOSIGNAL */
660 } 662 }
661#endif /* MHD_socket_nosignal_ */ 663#endif /* MHD_socket_nosignal_ */
662 664
663 665
664#ifdef HAVE_MESSAGES 666#ifdef HAVE_MESSAGES
665#if DEBUG_CONNECT 667#if DEBUG_CONNECT
666 MHD_DLOG (daemon, 668 MHD_DLOG (daemon,
667 MHD_SC_CONNECTION_ACCEPTED, 669 MHD_SC_CONNECTION_ACCEPTED,
668 _("Accepted connection on socket %d\n"), 670 _ ("Accepted connection on socket %d\n"),
669 client_socket); 671 client_socket);
670#endif 672#endif
671#endif 673#endif
@@ -673,82 +675,83 @@ internal_add_connection (struct MHD_Daemon *daemon,
673 (MHD_NO == MHD_ip_limit_add (daemon, 675 (MHD_NO == MHD_ip_limit_add (daemon,
674 addr, 676 addr,
675 addrlen)) ) 677 addrlen)) )
676 { 678 {
677 /* above connection limit - reject */ 679 /* above connection limit - reject */
678#ifdef HAVE_MESSAGES 680#ifdef HAVE_MESSAGES
679 MHD_DLOG (daemon, 681 MHD_DLOG (daemon,
680 MHD_SC_LIMIT_CONNECTIONS_REACHED, 682 MHD_SC_LIMIT_CONNECTIONS_REACHED,
681 _("Server reached connection limit. Closing inbound connection.\n")); 683 _ (
684 "Server reached connection limit. Closing inbound connection.\n"));
682#endif 685#endif
683 MHD_socket_close_chk_ (client_socket); 686 MHD_socket_close_chk_ (client_socket);
684#if ENFILE 687#if ENFILE
685 errno = ENFILE; 688 errno = ENFILE;
686#endif 689#endif
687 return MHD_SC_LIMIT_CONNECTIONS_REACHED; 690 return MHD_SC_LIMIT_CONNECTIONS_REACHED;
688 } 691 }
689 692
690 /* apply connection acceptance policy if present */ 693 /* apply connection acceptance policy if present */
691 if ( (NULL != daemon->accept_policy_cb) && 694 if ( (NULL != daemon->accept_policy_cb) &&
692 (MHD_NO == 695 (MHD_NO ==
693 daemon->accept_policy_cb (daemon->accept_policy_cb_cls, 696 daemon->accept_policy_cb (daemon->accept_policy_cb_cls,
694 addr, 697 addr,
695 addrlen)) ) 698 addrlen)) )
696 { 699 {
697#if DEBUG_CLOSE 700#if DEBUG_CLOSE
698#ifdef HAVE_MESSAGES 701#ifdef HAVE_MESSAGES
699 MHD_DLOG (daemon, 702 MHD_DLOG (daemon,
700 MHD_SC_ACCEPT_POLICY_REJECTED, 703 MHD_SC_ACCEPT_POLICY_REJECTED,
701 _("Connection rejected by application. Closing connection.\n")); 704 _ ("Connection rejected by application. Closing connection.\n"));
702#endif 705#endif
703#endif 706#endif
704 MHD_socket_close_chk_ (client_socket); 707 MHD_socket_close_chk_ (client_socket);
705 MHD_ip_limit_del (daemon, 708 MHD_ip_limit_del (daemon,
706 addr, 709 addr,
707 addrlen); 710 addrlen);
708#if EACCESS 711#if EACCESS
709 errno = EACCESS; 712 errno = EACCESS;
710#endif 713#endif
711 return MHD_SC_ACCEPT_POLICY_REJECTED; 714 return MHD_SC_ACCEPT_POLICY_REJECTED;
712 } 715 }
713 716
714 if (NULL == 717 if (NULL ==
715 (connection = MHD_calloc_ (1, 718 (connection = MHD_calloc_ (1,
716 sizeof (struct MHD_Connection)))) 719 sizeof (struct MHD_Connection))))
717 { 720 {
718 eno = errno; 721 eno = errno;
719#ifdef HAVE_MESSAGES 722#ifdef HAVE_MESSAGES
720 MHD_DLOG (daemon, 723 MHD_DLOG (daemon,
721 MHD_SC_CONNECTION_MALLOC_FAILURE, 724 MHD_SC_CONNECTION_MALLOC_FAILURE,
722 "Error allocating memory: %s\n", 725 "Error allocating memory: %s\n",
723 MHD_strerror_ (errno)); 726 MHD_strerror_ (errno));
724#endif 727#endif
725 MHD_socket_close_chk_ (client_socket); 728 MHD_socket_close_chk_ (client_socket);
726 MHD_ip_limit_del (daemon, 729 MHD_ip_limit_del (daemon,
727 addr, 730 addr,
728 addrlen); 731 addrlen);
729 errno = eno; 732 errno = eno;
730 return MHD_SC_CONNECTION_MALLOC_FAILURE; 733 return MHD_SC_CONNECTION_MALLOC_FAILURE;
731 } 734 }
732 connection->pool 735 connection->pool
733 = MHD_pool_create (daemon->connection_memory_limit_b); 736 = MHD_pool_create (daemon->connection_memory_limit_b);
734 if (NULL == connection->pool) 737 if (NULL == connection->pool)
735 { 738 {
736#ifdef HAVE_MESSAGES 739#ifdef HAVE_MESSAGES
737 MHD_DLOG (daemon, 740 MHD_DLOG (daemon,
738 MHD_SC_POOL_MALLOC_FAILURE, 741 MHD_SC_POOL_MALLOC_FAILURE,
739 _("Error allocating memory: %s\n"), 742 _ ("Error allocating memory: %s\n"),
740 MHD_strerror_ (errno)); 743 MHD_strerror_ (errno));
741#endif 744#endif
742 MHD_socket_close_chk_ (client_socket); 745 MHD_socket_close_chk_ (client_socket);
743 MHD_ip_limit_del (daemon, 746 MHD_ip_limit_del (daemon,
744 addr, 747 addr,
745 addrlen); 748 addrlen);
746 free (connection); 749 free (connection);
747#if ENOMEM 750#if ENOMEM
748 errno = ENOMEM; 751 errno = ENOMEM;
749#endif 752#endif
750 return MHD_SC_POOL_MALLOC_FAILURE; 753 return MHD_SC_POOL_MALLOC_FAILURE;
751 } 754 }
752 755
753 connection->connection_timeout = daemon->connection_default_timeout; 756 connection->connection_timeout = daemon->connection_default_timeout;
754 memcpy (&connection->addr, 757 memcpy (&connection->addr,
@@ -758,148 +761,151 @@ internal_add_connection (struct MHD_Daemon *daemon,
758 connection->socket_fd = client_socket; 761 connection->socket_fd = client_socket;
759 connection->sk_nonblck = non_blck; 762 connection->sk_nonblck = non_blck;
760 connection->daemon = daemon; 763 connection->daemon = daemon;
761 connection->last_activity = MHD_monotonic_sec_counter(); 764 connection->last_activity = MHD_monotonic_sec_counter ();
762 765
763#ifdef HTTPS_SUPPORT 766#ifdef HTTPS_SUPPORT
764 if (NULL != daemon->tls_api) 767 if (NULL != daemon->tls_api)
768 {
769 connection->tls_cs
770 = daemon->tls_api->setup_connection (daemon->tls_api->cls,
771 NULL /* FIXME */);
772 if (NULL == connection->tls_cs)
765 { 773 {
766 connection->tls_cs 774 eno = EINVAL;
767 = daemon->tls_api->setup_connection (daemon->tls_api->cls, 775 sc = -1; // FIXME!
768 NULL /* FIXME */); 776 goto cleanup;
769 if (NULL == connection->tls_cs)
770 {
771 eno = EINVAL;
772 sc = -1; // FIXME!
773 goto cleanup;
774 }
775 } 777 }
778 }
776 else 779 else
777#endif /* ! HTTPS_SUPPORT */ 780#endif /* ! HTTPS_SUPPORT */
778 { 781 {
779 /* set default connection handlers */ 782 /* set default connection handlers */
780 connection->recv_cls = &recv_param_adapter; 783 connection->recv_cls = &recv_param_adapter;
781 connection->send_cls = &send_param_adapter; 784 connection->send_cls = &send_param_adapter;
782 } 785 }
783 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 786 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
784 /* Firm check under lock. */ 787 /* Firm check under lock. */
785 if (daemon->connections >= daemon->global_connection_limit) 788 if (daemon->connections >= daemon->global_connection_limit)
786 { 789 {
787 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 790 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
788 /* above connection limit - reject */ 791 /* above connection limit - reject */
789#ifdef HAVE_MESSAGES 792#ifdef HAVE_MESSAGES
790 MHD_DLOG (daemon, 793 MHD_DLOG (daemon,
791 MHD_SC_LIMIT_CONNECTIONS_REACHED, 794 MHD_SC_LIMIT_CONNECTIONS_REACHED,
792 _("Server reached connection limit. Closing inbound connection.\n")); 795 _ (
796 "Server reached connection limit. Closing inbound connection.\n"));
793#endif 797#endif
794#if ENFILE 798#if ENFILE
795 eno = ENFILE; 799 eno = ENFILE;
796#endif 800#endif
797 sc = MHD_SC_LIMIT_CONNECTIONS_REACHED; 801 sc = MHD_SC_LIMIT_CONNECTIONS_REACHED;
798 goto cleanup; 802 goto cleanup;
799 } 803 }
800 daemon->connections++; 804 daemon->connections++;
801 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 805 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
802 { 806 {
803 XDLL_insert (daemon->normal_timeout_head, 807 XDLL_insert (daemon->normal_timeout_head,
804 daemon->normal_timeout_tail, 808 daemon->normal_timeout_tail,
805 connection); 809 connection);
806 } 810 }
807 DLL_insert (daemon->connections_head, 811 DLL_insert (daemon->connections_head,
808 daemon->connections_tail, 812 daemon->connections_tail,
809 connection); 813 connection);
810 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 814 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
811 815
812 if (NULL != daemon->notify_connection_cb) 816 if (NULL != daemon->notify_connection_cb)
813 daemon->notify_connection_cb (daemon->notify_connection_cb_cls, 817 daemon->notify_connection_cb (daemon->notify_connection_cb_cls,
814 connection, 818 connection,
815 MHD_CONNECTION_NOTIFY_STARTED); 819 MHD_CONNECTION_NOTIFY_STARTED);
816 820
817 /* attempt to create handler thread */ 821 /* attempt to create handler thread */
818 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 822 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
823 {
824 if (! MHD_create_named_thread_ (&connection->pid,
825 "MHD-connection",
826 daemon->thread_stack_limit_b,
827 &thread_main_handle_connection,
828 connection))
819 { 829 {
820 if (! MHD_create_named_thread_ (&connection->pid, 830 eno = errno;
821 "MHD-connection",
822 daemon->thread_stack_limit_b,
823 &thread_main_handle_connection,
824 connection))
825 {
826 eno = errno;
827#ifdef HAVE_MESSAGES 831#ifdef HAVE_MESSAGES
828 MHD_DLOG (daemon, 832 MHD_DLOG (daemon,
829 MHD_SC_THREAD_LAUNCH_FAILURE, 833 MHD_SC_THREAD_LAUNCH_FAILURE,
830 "Failed to create a thread: %s\n", 834 "Failed to create a thread: %s\n",
831 MHD_strerror_ (eno)); 835 MHD_strerror_ (eno));
832#endif 836#endif
833 sc = MHD_SC_THREAD_LAUNCH_FAILURE; 837 sc = MHD_SC_THREAD_LAUNCH_FAILURE;
834 goto cleanup; 838 goto cleanup;
835 }
836 } 839 }
840 }
837 else 841 else
838 { 842 {
839 connection->pid = daemon->pid; 843 connection->pid = daemon->pid;
840 } 844 }
841#ifdef EPOLL_SUPPORT 845#ifdef EPOLL_SUPPORT
842 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 846 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
843 { 847 {
844 if ( (! daemon->enable_turbo) || 848 if ( (! daemon->enable_turbo) ||
845 (external_add)) 849 (external_add))
846 { /* Do not manipulate EReady DL-list in 'external_add' mode. */ 850 { /* Do not manipulate EReady DL-list in 'external_add' mode. */
847 struct epoll_event event; 851 struct epoll_event event;
848 852
849 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET; 853 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
850 event.data.ptr = connection; 854 event.data.ptr = connection;
851 if (0 != epoll_ctl (daemon->epoll_fd, 855 if (0 != epoll_ctl (daemon->epoll_fd,
852 EPOLL_CTL_ADD, 856 EPOLL_CTL_ADD,
853 client_socket, 857 client_socket,
854 &event)) 858 &event))
855 { 859 {
856 eno = errno; 860 eno = errno;
857#ifdef HAVE_MESSAGES 861#ifdef HAVE_MESSAGES
858 MHD_DLOG (daemon, 862 MHD_DLOG (daemon,
859 MHD_SC_EPOLL_CTL_ADD_FAILED, 863 MHD_SC_EPOLL_CTL_ADD_FAILED,
860 _("Call to epoll_ctl failed: %s\n"), 864 _ ("Call to epoll_ctl failed: %s\n"),
861 MHD_socket_last_strerr_ ()); 865 MHD_socket_last_strerr_ ());
862#endif 866#endif
863 sc = MHD_SC_EPOLL_CTL_ADD_FAILED; 867 sc = MHD_SC_EPOLL_CTL_ADD_FAILED;
864 goto cleanup; 868 goto cleanup;
865 } 869 }
866 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET; 870 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
867 } 871 }
868 else 872 else
869 { 873 {
870 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY 874 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY
871 | MHD_EPOLL_STATE_IN_EREADY_EDLL; 875 | MHD_EPOLL_STATE_WRITE_READY
872 EDLL_insert (daemon->eready_head, 876 | MHD_EPOLL_STATE_IN_EREADY_EDLL;
873 daemon->eready_tail, 877 EDLL_insert (daemon->eready_head,
874 connection); 878 daemon->eready_tail,
875 } 879 connection);
876 } 880 }
881 }
877 else /* This 'else' is combined with next 'if'. */ 882 else /* This 'else' is combined with next 'if'. */
878#endif 883#endif
879 if ( (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) && 884 if ( (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) &&
880 (external_add) && 885 (external_add) &&
881 (MHD_ITC_IS_VALID_(daemon->itc)) && 886 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
882 (! MHD_itc_activate_ (daemon->itc, 887 (! MHD_itc_activate_ (daemon->itc,
883 "n")) ) 888 "n")) )
884 { 889 {
885#ifdef HAVE_MESSAGES 890#ifdef HAVE_MESSAGES
886 MHD_DLOG (daemon, 891 MHD_DLOG (daemon,
887 MHD_SC_ITC_USE_FAILED, 892 MHD_SC_ITC_USE_FAILED,
888 _("Failed to signal new connection via inter-thread communication channel (not necessarily fatal, continuing anyway).")); 893 _ (
894 "Failed to signal new connection via inter-thread communication channel (not necessarily fatal, continuing anyway)."));
889#endif 895#endif
890 } 896 }
891 return MHD_SC_OK; 897 return MHD_SC_OK;
892 898
893 cleanup: 899cleanup:
894 if (NULL != daemon->notify_connection_cb) 900 if (NULL != daemon->notify_connection_cb)
895 daemon->notify_connection_cb (daemon->notify_connection_cb_cls, 901 daemon->notify_connection_cb (daemon->notify_connection_cb_cls,
896 connection, 902 connection,
897 MHD_CONNECTION_NOTIFY_CLOSED); 903 MHD_CONNECTION_NOTIFY_CLOSED);
898#ifdef HTTPS_SUPPORT 904#ifdef HTTPS_SUPPORT
899 if ( (NULL != daemon->tls_api) && 905 if ( (NULL != daemon->tls_api) &&
900 (NULL != connection->tls_cs) ) 906 (NULL != connection->tls_cs) )
901 daemon->tls_api->teardown_connection (daemon->tls_api->cls, 907 daemon->tls_api->teardown_connection (daemon->tls_api->cls,
902 connection->tls_cs); 908 connection->tls_cs);
903#endif /* HTTPS_SUPPORT */ 909#endif /* HTTPS_SUPPORT */
904 MHD_socket_close_chk_ (client_socket); 910 MHD_socket_close_chk_ (client_socket);
905 MHD_ip_limit_del (daemon, 911 MHD_ip_limit_del (daemon,
@@ -907,14 +913,14 @@ internal_add_connection (struct MHD_Daemon *daemon,
907 addrlen); 913 addrlen);
908 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 914 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
909 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 915 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
910 { 916 {
911 XDLL_remove (daemon->normal_timeout_head, 917 XDLL_remove (daemon->normal_timeout_head,
912 daemon->normal_timeout_tail, 918 daemon->normal_timeout_tail,
913 connection); 919 connection);
914 } 920 }
915 DLL_remove (daemon->connections_head, 921 DLL_remove (daemon->connections_head,
916 daemon->connections_tail, 922 daemon->connections_tail,
917 connection); 923 connection);
918 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 924 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
919 MHD_pool_destroy (connection->pool); 925 MHD_pool_destroy (connection->pool);
920 free (connection); 926 free (connection);
@@ -954,42 +960,42 @@ internal_add_connection (struct MHD_Daemon *daemon,
954 */ 960 */
955enum MHD_StatusCode 961enum MHD_StatusCode
956MHD_daemon_add_connection (struct MHD_Daemon *daemon, 962MHD_daemon_add_connection (struct MHD_Daemon *daemon,
957 MHD_socket client_socket, 963 MHD_socket client_socket,
958 const struct sockaddr *addr, 964 const struct sockaddr *addr,
959 socklen_t addrlen) 965 socklen_t addrlen)
960{ 966{
961 bool sk_nonbl; 967 bool sk_nonbl;
962 968
963 if (! MHD_socket_nonblocking_ (client_socket)) 969 if (! MHD_socket_nonblocking_ (client_socket))
964 { 970 {
965#ifdef HAVE_MESSAGES 971#ifdef HAVE_MESSAGES
966 MHD_DLOG (daemon, 972 MHD_DLOG (daemon,
967 MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED, 973 MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED,
968 _("Failed to set nonblocking mode on new client socket: %s\n"), 974 _ ("Failed to set nonblocking mode on new client socket: %s\n"),
969 MHD_socket_last_strerr_()); 975 MHD_socket_last_strerr_ ());
970#endif 976#endif
971 sk_nonbl = false; 977 sk_nonbl = false;
972 } 978 }
973 else 979 else
974 { 980 {
975 sk_nonbl = true; 981 sk_nonbl = true;
976 } 982 }
977 983
978 if ( (daemon->enable_turbo) && 984 if ( (daemon->enable_turbo) &&
979 (! MHD_socket_noninheritable_ (client_socket)) ) 985 (! MHD_socket_noninheritable_ (client_socket)) )
980 { 986 {
981#ifdef HAVE_MESSAGES 987#ifdef HAVE_MESSAGES
982 MHD_DLOG (daemon, 988 MHD_DLOG (daemon,
983 MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED, 989 MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED,
984 _("Failed to set noninheritable mode on new client socket.\n")); 990 _ ("Failed to set noninheritable mode on new client socket.\n"));
985#endif 991#endif
986 } 992 }
987 return internal_add_connection (daemon, 993 return internal_add_connection (daemon,
988 client_socket, 994 client_socket,
989 addr, 995 addr,
990 addrlen, 996 addrlen,
991 true, 997 true,
992 sk_nonbl); 998 sk_nonbl);
993} 999}
994 1000
995 1001
@@ -1033,94 +1039,98 @@ MHD_accept_connection_ (struct MHD_Daemon *daemon)
1033#endif /* ! USE_ACCEPT4 */ 1039#endif /* ! USE_ACCEPT4 */
1034 if ( (MHD_INVALID_SOCKET == s) || 1040 if ( (MHD_INVALID_SOCKET == s) ||
1035 (addrlen <= 0) ) 1041 (addrlen <= 0) )
1036 { 1042 {
1037 const int err = MHD_socket_get_error_ (); 1043 const int err = MHD_socket_get_error_ ();
1038 1044
1039 /* This could be a common occurance with multiple worker threads */ 1045 /* This could be a common occurance with multiple worker threads */
1040 if (MHD_SCKT_ERR_IS_ (err, 1046 if (MHD_SCKT_ERR_IS_ (err,
1041 MHD_SCKT_EINVAL_)) 1047 MHD_SCKT_EINVAL_))
1042 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; /* can happen during shutdown, let's hope this is the cause... */ 1048 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; /* can happen during shutdown, let's hope this is the cause... */
1043 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)) 1049 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_ (err))
1044 return MHD_SC_ACCEPT_FAST_DISCONNECT; /* do not print error if client just disconnected early */ 1050 return MHD_SC_ACCEPT_FAST_DISCONNECT; /* do not print error if client just disconnected early */
1045 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) ) 1051 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) )
1046 return MHD_SC_ACCEPT_FAILED_EAGAIN; 1052 return MHD_SC_ACCEPT_FAILED_EAGAIN;
1047 if (MHD_INVALID_SOCKET != s) 1053 if (MHD_INVALID_SOCKET != s)
1048 { 1054 {
1049 MHD_socket_close_chk_ (s); 1055 MHD_socket_close_chk_ (s);
1050 } 1056 }
1051 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) ) 1057 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) )
1052 { 1058 {
1053 /* system/process out of resources */ 1059 /* system/process out of resources */
1054 if (0 == daemon->connections) 1060 if (0 == daemon->connections)
1055 { 1061 {
1056#ifdef HAVE_MESSAGES 1062#ifdef HAVE_MESSAGES
1057 /* Not setting 'at_limit' flag, as there is no way it 1063 /* Not setting 'at_limit' flag, as there is no way it
1058 would ever be cleared. Instead trying to produce 1064 would ever be cleared. Instead trying to produce
1059 bit fat ugly warning. */ 1065 bit fat ugly warning. */
1060 MHD_DLOG (daemon, 1066 MHD_DLOG (daemon,
1061 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY, 1067 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY,
1062 _("Hit process or system resource limit at FIRST connection. This is really bad as there is no sane way to proceed. Will try busy waiting for system resources to become magically available.\n")); 1068 _ (
1069 "Hit process or system resource limit at FIRST connection. This is really bad as there is no sane way to proceed. Will try busy waiting for system resources to become magically available.\n"));
1063#endif 1070#endif
1064 return MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY; 1071 return MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY;
1065 } 1072 }
1066 else 1073 else
1067 { 1074 {
1068 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 1075 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
1069 daemon->at_limit = true; 1076 daemon->at_limit = true;
1070 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 1077 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
1071#ifdef HAVE_MESSAGES 1078#ifdef HAVE_MESSAGES
1072 MHD_DLOG (daemon, 1079 MHD_DLOG (daemon,
1073 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED, 1080 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED,
1074 _("Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"), 1081 _ (
1075 (unsigned int) daemon->connections); 1082 "Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
1083 (unsigned int) daemon->connections);
1076#endif 1084#endif
1077 return MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED; 1085 return MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED;
1078 } 1086 }
1079 } 1087 }
1080#ifdef HAVE_MESSAGES 1088#ifdef HAVE_MESSAGES
1081 MHD_DLOG (daemon, 1089 MHD_DLOG (daemon,
1082 MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY, 1090 MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY,
1083 _("Error accepting connection: %s\n"), 1091 _ ("Error accepting connection: %s\n"),
1084 MHD_socket_strerr_(err)); 1092 MHD_socket_strerr_ (err));
1085#endif 1093#endif
1086 return MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY; 1094 return MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY;
1087 } 1095 }
1088#if !defined(USE_ACCEPT4) || !defined(HAVE_SOCK_NONBLOCK) 1096#if ! defined(USE_ACCEPT4) || ! defined(HAVE_SOCK_NONBLOCK)
1089 if (! MHD_socket_nonblocking_ (s)) 1097 if (! MHD_socket_nonblocking_ (s))
1090 { 1098 {
1091#ifdef HAVE_MESSAGES 1099#ifdef HAVE_MESSAGES
1092 MHD_DLOG (daemon, 1100 MHD_DLOG (daemon,
1093 MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED, 1101 MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED,
1094 _("Failed to set nonblocking mode on incoming connection socket: %s\n"), 1102 _ (
1095 MHD_socket_last_strerr_()); 1103 "Failed to set nonblocking mode on incoming connection socket: %s\n"),
1104 MHD_socket_last_strerr_ ());
1096#endif 1105#endif
1097 } 1106 }
1098 else 1107 else
1099 sk_nonbl = true; 1108 sk_nonbl = true;
1100#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */ 1109#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */
1101#if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC) 1110#if ! defined(USE_ACCEPT4) || ! defined(SOCK_CLOEXEC)
1102 if (! MHD_socket_noninheritable_ (s)) 1111 if (! MHD_socket_noninheritable_ (s))
1103 { 1112 {
1104#ifdef HAVE_MESSAGES 1113#ifdef HAVE_MESSAGES
1105 MHD_DLOG (daemon, 1114 MHD_DLOG (daemon,
1106 MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED, 1115 MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED,
1107 _("Failed to set noninheritable mode on incoming connection socket.\n")); 1116 _ (
1117 "Failed to set noninheritable mode on incoming connection socket.\n"));
1108#endif 1118#endif
1109 } 1119 }
1110#endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */ 1120#endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */
1111#ifdef HAVE_MESSAGES 1121#ifdef HAVE_MESSAGES
1112#if DEBUG_CONNECT 1122#if DEBUG_CONNECT
1113 MHD_DLOG (daemon, 1123 MHD_DLOG (daemon,
1114 MHD_SC_CONNECTION_ACCEPTED, 1124 MHD_SC_CONNECTION_ACCEPTED,
1115 _("Accepted connection on socket %d\n"), 1125 _ ("Accepted connection on socket %d\n"),
1116 s); 1126 s);
1117#endif 1127#endif
1118#endif 1128#endif
1119 return internal_add_connection (daemon, 1129 return internal_add_connection (daemon,
1120 s, 1130 s,
1121 addr, 1131 addr,
1122 addrlen, 1132 addrlen,
1123 false, 1133 false,
1124 sk_nonbl); 1134 sk_nonbl);
1125} 1135}
1126 1136
diff --git a/src/lib/connection_add.h b/src/lib/connection_add.h
index 6957fd77..de8abd9a 100644
--- a/src/lib/connection_add.h
+++ b/src/lib/connection_add.h
@@ -32,10 +32,10 @@
32 * that process daemon's select()/poll()/etc. 32 * that process daemon's select()/poll()/etc.
33 * 33 *
34 * @param daemon handle with the listen socket 34 * @param daemon handle with the listen socket
35 * @return #MHD_SC_OK on success 35 * @return #MHD_SC_OK on success
36 */ 36 */
37enum MHD_StatusCode 37enum MHD_StatusCode
38MHD_accept_connection_ (struct MHD_Daemon *daemon) 38MHD_accept_connection_ (struct MHD_Daemon *daemon)
39 MHD_NONNULL (1); 39MHD_NONNULL (1);
40 40
41#endif 41#endif
diff --git a/src/lib/connection_call_handlers.c b/src/lib/connection_call_handlers.c
index af8860d6..c4fb448e 100644
--- a/src/lib/connection_call_handlers.c
+++ b/src/lib/connection_call_handlers.c
@@ -56,7 +56,8 @@
56 * minimal. 56 * minimal.
57 */ 57 */
58#ifdef HAVE_MESSAGES 58#ifdef HAVE_MESSAGES
59#define REQUEST_TOO_BIG "<html><head><title>Request too big</title></head><body>Your HTTP header was too big for the memory constraints of this webserver.</body></html>" 59#define REQUEST_TOO_BIG \
60 "<html><head><title>Request too big</title></head><body>Your HTTP header was too big for the memory constraints of this webserver.</body></html>"
60#else 61#else
61#define REQUEST_TOO_BIG "" 62#define REQUEST_TOO_BIG ""
62#endif 63#endif
@@ -69,7 +70,8 @@
69 * minimal. 70 * minimal.
70 */ 71 */
71#ifdef HAVE_MESSAGES 72#ifdef HAVE_MESSAGES
72#define REQUEST_LACKS_HOST "<html><head><title>&quot;Host:&quot; header required</title></head><body>In HTTP 1.1, requests must include a &quot;Host:&quot; header, and your HTTP 1.1 request lacked such a header.</body></html>" 73#define REQUEST_LACKS_HOST \
74 "<html><head><title>&quot;Host:&quot; header required</title></head><body>In HTTP 1.1, requests must include a &quot;Host:&quot; header, and your HTTP 1.1 request lacked such a header.</body></html>"
73#else 75#else
74#define REQUEST_LACKS_HOST "" 76#define REQUEST_LACKS_HOST ""
75#endif 77#endif
@@ -82,7 +84,8 @@
82 * minimal. 84 * minimal.
83 */ 85 */
84#ifdef HAVE_MESSAGES 86#ifdef HAVE_MESSAGES
85#define REQUEST_MALFORMED "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>" 87#define REQUEST_MALFORMED \
88 "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>"
86#else 89#else
87#define REQUEST_MALFORMED "" 90#define REQUEST_MALFORMED ""
88#endif 91#endif
@@ -94,7 +97,8 @@
94 * minimal. 97 * minimal.
95 */ 98 */
96#ifdef HAVE_MESSAGES 99#ifdef HAVE_MESSAGES
97#define INTERNAL_ERROR "<html><head><title>Internal server error</title></head><body>Please ask the developer of this Web server to carefully read the GNU libmicrohttpd documentation about connection management and blocking.</body></html>" 100#define INTERNAL_ERROR \
101 "<html><head><title>Internal server error</title></head><body>Please ask the developer of this Web server to carefully read the GNU libmicrohttpd documentation about connection management and blocking.</body></html>"
98#else 102#else
99#define INTERNAL_ERROR "" 103#define INTERNAL_ERROR ""
100#endif 104#endif
@@ -128,17 +132,18 @@ MHD_conn_init_static_ (void)
128#ifdef SF_FLAGS 132#ifdef SF_FLAGS
129 long sys_page_size = sysconf (_SC_PAGESIZE); 133 long sys_page_size = sysconf (_SC_PAGESIZE);
130 if (0 > sys_page_size) 134 if (0 > sys_page_size)
131 { /* Failed to get page size. */ 135 { /* Failed to get page size. */
132 freebsd_sendfile_flags_ = SF_NODISKIO; 136 freebsd_sendfile_flags_ = SF_NODISKIO;
133 freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO; 137 freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
134 } 138 }
135 else 139 else
136 { 140 {
137 freebsd_sendfile_flags_ = 141 freebsd_sendfile_flags_ =
138 SF_FLAGS((uint16_t)(MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO); 142 SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO);
139 freebsd_sendfile_flags_thd_p_c_ = 143 freebsd_sendfile_flags_thd_p_c_ =
140 SF_FLAGS((uint16_t)(MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size), SF_NODISKIO); 144 SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size),
141 } 145 SF_NODISKIO);
146 }
142#endif /* SF_FLAGS */ 147#endif /* SF_FLAGS */
143} 148}
144#endif /* HAVE_FREEBSD_SENDFILE */ 149#endif /* HAVE_FREEBSD_SENDFILE */
@@ -161,13 +166,13 @@ MHD_conn_init_static_ (void)
161 */ 166 */
162static void 167static void
163connection_close_error (struct MHD_Connection *connection, 168connection_close_error (struct MHD_Connection *connection,
164 enum MHD_StatusCode sc, 169 enum MHD_StatusCode sc,
165 const char *emsg) 170 const char *emsg)
166{ 171{
167#ifdef HAVE_MESSAGES 172#ifdef HAVE_MESSAGES
168 if (NULL != emsg) 173 if (NULL != emsg)
169 MHD_DLOG (connection->daemon, 174 MHD_DLOG (connection->daemon,
170 sc, 175 sc,
171 emsg); 176 emsg);
172#else /* ! HAVE_MESSAGES */ 177#else /* ! HAVE_MESSAGES */
173 (void) emsg; /* Mute compiler warning. */ 178 (void) emsg; /* Mute compiler warning. */
@@ -209,8 +214,8 @@ try_grow_read_buffer (struct MHD_Request *request)
209 if (0 == request->read_buffer_size) 214 if (0 == request->read_buffer_size)
210 new_size = daemon->connection_memory_limit_b / 2; 215 new_size = daemon->connection_memory_limit_b / 2;
211 else 216 else
212 new_size = request->read_buffer_size + 217 new_size = request->read_buffer_size
213 daemon->connection_memory_increment_b; 218 + daemon->connection_memory_increment_b;
214 buf = MHD_pool_reallocate (request->connection->pool, 219 buf = MHD_pool_reallocate (request->connection->pool,
215 request->read_buffer, 220 request->read_buffer,
216 request->read_buffer_size, 221 request->read_buffer_size,
@@ -245,16 +250,16 @@ MHD_request_handle_read_ (struct MHD_Request *request)
245 struct MHD_TLS_Plugin *tls; 250 struct MHD_TLS_Plugin *tls;
246 251
247 if ( (NULL != (tls = daemon->tls_api)) && 252 if ( (NULL != (tls = daemon->tls_api)) &&
248 (! tls->handshake (tls->cls, 253 (! tls->handshake (tls->cls,
249 connection->tls_cs)) ) 254 connection->tls_cs)) )
250 return; 255 return;
251 } 256 }
252#endif /* HTTPS_SUPPORT */ 257#endif /* HTTPS_SUPPORT */
253 258
254 /* make sure "read" has a reasonable number of bytes 259 /* make sure "read" has a reasonable number of bytes
255 in buffer to use per system call (if possible) */ 260 in buffer to use per system call (if possible) */
256 if (request->read_buffer_offset + 261 if (request->read_buffer_offset
257 daemon->connection_memory_increment_b > 262 + daemon->connection_memory_increment_b >
258 request->read_buffer_size) 263 request->read_buffer_size)
259 try_grow_read_buffer (request); 264 try_grow_read_buffer (request);
260 265
@@ -263,82 +268,84 @@ MHD_request_handle_read_ (struct MHD_Request *request)
263 bytes_read = connection->recv_cls (connection, 268 bytes_read = connection->recv_cls (connection,
264 &request->read_buffer 269 &request->read_buffer
265 [request->read_buffer_offset], 270 [request->read_buffer_offset],
266 request->read_buffer_size - 271 request->read_buffer_size
267 request->read_buffer_offset); 272 - request->read_buffer_offset);
268 if (bytes_read < 0) 273 if (bytes_read < 0)
274 {
275 if (MHD_ERR_AGAIN_ == bytes_read)
276 return; /* No new data to process. */
277 if (MHD_ERR_CONNRESET_ == bytes_read)
269 { 278 {
270 if (MHD_ERR_AGAIN_ == bytes_read)
271 return; /* No new data to process. */
272 if (MHD_ERR_CONNRESET_ == bytes_read)
273 {
274 CONNECTION_CLOSE_ERROR (connection,
275 (MHD_REQUEST_INIT == request->state)
276 ? MHD_SC_CONNECTION_CLOSED
277 : MHD_SC_CONNECTION_RESET_CLOSED,
278 (MHD_REQUEST_INIT == request->state)
279 ? NULL
280 : _("Socket disconnected while reading request.\n"));
281 return;
282 }
283 CONNECTION_CLOSE_ERROR (connection, 279 CONNECTION_CLOSE_ERROR (connection,
284 (MHD_REQUEST_INIT == request->state)
285 ? MHD_SC_CONNECTION_CLOSED
286 : MHD_SC_CONNECTION_READ_FAIL_CLOSED,
287 (MHD_REQUEST_INIT == request->state) 280 (MHD_REQUEST_INIT == request->state)
288 ? NULL 281 ? MHD_SC_CONNECTION_CLOSED
289 : _("Connection socket is closed due to error when reading request.\n")); 282 : MHD_SC_CONNECTION_RESET_CLOSED,
283 (MHD_REQUEST_INIT == request->state)
284 ? NULL
285 : _ (
286 "Socket disconnected while reading request.\n"));
290 return; 287 return;
291 } 288 }
289 CONNECTION_CLOSE_ERROR (connection,
290 (MHD_REQUEST_INIT == request->state)
291 ? MHD_SC_CONNECTION_CLOSED
292 : MHD_SC_CONNECTION_READ_FAIL_CLOSED,
293 (MHD_REQUEST_INIT == request->state)
294 ? NULL
295 : _ (
296 "Connection socket is closed due to error when reading request.\n"));
297 return;
298 }
292 299
293 if (0 == bytes_read) 300 if (0 == bytes_read)
294 { /* Remote side closed connection. */ 301 { /* Remote side closed connection. */
295 connection->read_closed = true; 302 connection->read_closed = true;
296 MHD_connection_close_ (connection, 303 MHD_connection_close_ (connection,
297 MHD_REQUEST_TERMINATED_CLIENT_ABORT); 304 MHD_REQUEST_TERMINATED_CLIENT_ABORT);
298 return; 305 return;
299 } 306 }
300 request->read_buffer_offset += bytes_read; 307 request->read_buffer_offset += bytes_read;
301 MHD_connection_update_last_activity_ (connection); 308 MHD_connection_update_last_activity_ (connection);
302#if DEBUG_STATES 309#if DEBUG_STATES
303 MHD_DLOG (daemon, 310 MHD_DLOG (daemon,
304 MHD_SC_STATE_MACHINE_STATUS_REPORT, 311 MHD_SC_STATE_MACHINE_STATUS_REPORT,
305 _("In function %s handling connection at state: %s\n"), 312 _ ("In function %s handling connection at state: %s\n"),
306 __FUNCTION__, 313 __FUNCTION__,
307 MHD_state_to_string (request->state)); 314 MHD_state_to_string (request->state));
308#endif 315#endif
309 switch (request->state) 316 switch (request->state)
317 {
318 case MHD_REQUEST_INIT:
319 case MHD_REQUEST_URL_RECEIVED:
320 case MHD_REQUEST_HEADER_PART_RECEIVED:
321 case MHD_REQUEST_HEADERS_RECEIVED:
322 case MHD_REQUEST_HEADERS_PROCESSED:
323 case MHD_REQUEST_CONTINUE_SENDING:
324 case MHD_REQUEST_CONTINUE_SENT:
325 case MHD_REQUEST_BODY_RECEIVED:
326 case MHD_REQUEST_FOOTER_PART_RECEIVED:
327 /* nothing to do but default action */
328 if (connection->read_closed)
310 { 329 {
311 case MHD_REQUEST_INIT: 330 MHD_connection_close_ (connection,
312 case MHD_REQUEST_URL_RECEIVED: 331 MHD_REQUEST_TERMINATED_READ_ERROR);
313 case MHD_REQUEST_HEADER_PART_RECEIVED: 332 }
314 case MHD_REQUEST_HEADERS_RECEIVED: 333 return;
315 case MHD_REQUEST_HEADERS_PROCESSED: 334 case MHD_REQUEST_CLOSED:
316 case MHD_REQUEST_CONTINUE_SENDING: 335 return;
317 case MHD_REQUEST_CONTINUE_SENT:
318 case MHD_REQUEST_BODY_RECEIVED:
319 case MHD_REQUEST_FOOTER_PART_RECEIVED:
320 /* nothing to do but default action */
321 if (connection->read_closed)
322 {
323 MHD_connection_close_ (connection,
324 MHD_REQUEST_TERMINATED_READ_ERROR);
325 }
326 return;
327 case MHD_REQUEST_CLOSED:
328 return;
329#ifdef UPGRADE_SUPPORT 336#ifdef UPGRADE_SUPPORT
330 case MHD_REQUEST_UPGRADE: 337 case MHD_REQUEST_UPGRADE:
331 mhd_assert (0); 338 mhd_assert (0);
332 return; 339 return;
333#endif /* UPGRADE_SUPPORT */ 340#endif /* UPGRADE_SUPPORT */
334 default: 341 default:
335 /* shrink read buffer to how much is actually used */ 342 /* shrink read buffer to how much is actually used */
336 MHD_pool_reallocate (connection->pool, 343 MHD_pool_reallocate (connection->pool,
337 request->read_buffer, 344 request->read_buffer,
338 request->read_buffer_size + 1, 345 request->read_buffer_size + 1,
339 request->read_buffer_offset); 346 request->read_buffer_offset);
340 break; 347 break;
341 } 348 }
342 return; 349 return;
343} 350}
344 351
@@ -361,9 +368,9 @@ sendfile_adapter (struct MHD_Connection *connection)
361 uint64_t left; 368 uint64_t left;
362 uint64_t offsetu64; 369 uint64_t offsetu64;
363#ifndef HAVE_SENDFILE64 370#ifndef HAVE_SENDFILE64
364 const uint64_t max_off_t = (uint64_t)OFF_T_MAX; 371 const uint64_t max_off_t = (uint64_t) OFF_T_MAX;
365#else /* HAVE_SENDFILE64 */ 372#else /* HAVE_SENDFILE64 */
366 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX; 373 const uint64_t max_off_t = (uint64_t) OFF64_T_MAX;
367#endif /* HAVE_SENDFILE64 */ 374#endif /* HAVE_SENDFILE64 */
368#ifdef MHD_LINUX_SOLARIS_SENDFILE 375#ifdef MHD_LINUX_SOLARIS_SENDFILE
369#ifndef HAVE_SENDFILE64 376#ifndef HAVE_SENDFILE64
@@ -379,8 +386,10 @@ sendfile_adapter (struct MHD_Connection *connection)
379#ifdef HAVE_DARWIN_SENDFILE 386#ifdef HAVE_DARWIN_SENDFILE
380 off_t len; 387 off_t len;
381#endif /* HAVE_DARWIN_SENDFILE */ 388#endif /* HAVE_DARWIN_SENDFILE */
382 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode); 389 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION ==
383 const size_t chunk_size = used_thr_p_c ? MHD_SENFILE_CHUNK_THR_P_C_ : MHD_SENFILE_CHUNK_; 390 daemon->threading_mode);
391 const size_t chunk_size = used_thr_p_c ? MHD_SENFILE_CHUNK_THR_P_C_ :
392 MHD_SENFILE_CHUNK_;
384 size_t send_size = 0; 393 size_t send_size = 0;
385 394
386 mhd_assert (MHD_resp_sender_sendfile == request->resp_sender); 395 mhd_assert (MHD_resp_sender_sendfile == request->resp_sender);
@@ -390,10 +399,10 @@ sendfile_adapter (struct MHD_Connection *connection)
390 * use 128KiB chunks (2MiB for thread-per-connection). */ 399 * use 128KiB chunks (2MiB for thread-per-connection). */
391 send_size = (left > chunk_size) ? chunk_size : (size_t) left; 400 send_size = (left > chunk_size) ? chunk_size : (size_t) left;
392 if (max_off_t < offsetu64) 401 if (max_off_t < offsetu64)
393 { /* Retry to send with standard 'send()'. */ 402 { /* Retry to send with standard 'send()'. */
394 request->resp_sender = MHD_resp_sender_std; 403 request->resp_sender = MHD_resp_sender_std;
395 return MHD_ERR_AGAIN_; 404 return MHD_ERR_AGAIN_;
396 } 405 }
397#ifdef MHD_LINUX_SOLARIS_SENDFILE 406#ifdef MHD_LINUX_SOLARIS_SENDFILE
398#ifndef HAVE_SENDFILE64 407#ifndef HAVE_SENDFILE64
399 offset = (off_t) offsetu64; 408 offset = (off_t) offsetu64;
@@ -409,54 +418,54 @@ sendfile_adapter (struct MHD_Connection *connection)
409 send_size); 418 send_size);
410#endif /* HAVE_SENDFILE64 */ 419#endif /* HAVE_SENDFILE64 */
411 if (0 > ret) 420 if (0 > ret)
412 { 421 {
413 const int err = MHD_socket_get_error_(); 422 const int err = MHD_socket_get_error_ ();
414 423
415 if (MHD_SCKT_ERR_IS_EAGAIN_(err)) 424 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
416 { 425 {
417#ifdef EPOLL_SUPPORT 426#ifdef EPOLL_SUPPORT
418 /* EAGAIN --- no longer write-ready */ 427 /* EAGAIN --- no longer write-ready */
419 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 428 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
420#endif /* EPOLL_SUPPORT */ 429#endif /* EPOLL_SUPPORT */
421 return MHD_ERR_AGAIN_; 430 return MHD_ERR_AGAIN_;
422 } 431 }
423 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 432 if (MHD_SCKT_ERR_IS_EINTR_ (err))
424 return MHD_ERR_AGAIN_; 433 return MHD_ERR_AGAIN_;
425#ifdef HAVE_LINUX_SENDFILE 434#ifdef HAVE_LINUX_SENDFILE
426 if (MHD_SCKT_ERR_IS_(err, 435 if (MHD_SCKT_ERR_IS_ (err,
427 MHD_SCKT_EBADF_)) 436 MHD_SCKT_EBADF_))
428 return MHD_ERR_BADF_; 437 return MHD_ERR_BADF_;
429 /* sendfile() failed with EINVAL if mmap()-like operations are not 438 /* sendfile() failed with EINVAL if mmap()-like operations are not
430 supported for FD or other 'unusual' errors occurred, so we should try 439 supported for FD or other 'unusual' errors occurred, so we should try
431 to fall back to 'SEND'; see also this thread for info on 440 to fall back to 'SEND'; see also this thread for info on
432 odd libc/Linux behavior with sendfile: 441 odd libc/Linux behavior with sendfile:
433 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ 442 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
443 request->resp_sender = MHD_resp_sender_std;
444 return MHD_ERR_AGAIN_;
445#else /* HAVE_SOLARIS_SENDFILE */
446 if ( (EAFNOSUPPORT == err) ||
447 (EINVAL == err) ||
448 (EOPNOTSUPP == err) )
449 { /* Retry with standard file reader. */
434 request->resp_sender = MHD_resp_sender_std; 450 request->resp_sender = MHD_resp_sender_std;
435 return MHD_ERR_AGAIN_; 451 return MHD_ERR_AGAIN_;
436#else /* HAVE_SOLARIS_SENDFILE */
437 if ( (EAFNOSUPPORT == err) ||
438 (EINVAL == err) ||
439 (EOPNOTSUPP == err) )
440 { /* Retry with standard file reader. */
441 request->resp_sender = MHD_resp_sender_std;
442 return MHD_ERR_AGAIN_;
443 }
444 if ( (ENOTCONN == err) ||
445 (EPIPE == err) )
446 {
447 return MHD_ERR_CONNRESET_;
448 }
449 return MHD_ERR_BADF_; /* Fail hard */
450#endif /* HAVE_SOLARIS_SENDFILE */
451 } 452 }
453 if ( (ENOTCONN == err) ||
454 (EPIPE == err) )
455 {
456 return MHD_ERR_CONNRESET_;
457 }
458 return MHD_ERR_BADF_; /* Fail hard */
459#endif /* HAVE_SOLARIS_SENDFILE */
460 }
452#ifdef EPOLL_SUPPORT 461#ifdef EPOLL_SUPPORT
453 else if (send_size > (size_t)ret) 462 else if (send_size > (size_t) ret)
454 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 463 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
455#endif /* EPOLL_SUPPORT */ 464#endif /* EPOLL_SUPPORT */
456#elif defined(HAVE_FREEBSD_SENDFILE) 465#elif defined(HAVE_FREEBSD_SENDFILE)
457#ifdef SF_FLAGS 466#ifdef SF_FLAGS
458 flags = used_thr_p_c ? 467 flags = used_thr_p_c ?
459 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_; 468 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
460#endif /* SF_FLAGS */ 469#endif /* SF_FLAGS */
461 if (0 != sendfile (file_fd, 470 if (0 != sendfile (file_fd,
462 connection->socket_fd, 471 connection->socket_fd,
@@ -465,26 +474,26 @@ sendfile_adapter (struct MHD_Connection *connection)
465 NULL, 474 NULL,
466 &sent_bytes, 475 &sent_bytes,
467 flags)) 476 flags))
477 {
478 const int err = MHD_socket_get_error_ ();
479 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) ||
480 MHD_SCKT_ERR_IS_EINTR_ (err) ||
481 (EBUSY == err) )
468 { 482 {
469 const int err = MHD_socket_get_error_(); 483 mhd_assert (SSIZE_MAX >= sent_bytes);
470 if (MHD_SCKT_ERR_IS_EAGAIN_(err) || 484 if (0 != sent_bytes)
471 MHD_SCKT_ERR_IS_EINTR_(err) || 485 return (ssize_t) sent_bytes;
472 EBUSY == err)
473 {
474 mhd_assert (SSIZE_MAX >= sent_bytes);
475 if (0 != sent_bytes)
476 return (ssize_t)sent_bytes;
477 486
478 return MHD_ERR_AGAIN_;
479 }
480 /* Some unrecoverable error. Possibly file FD is not suitable
481 * for sendfile(). Retry with standard send(). */
482 request->resp_sender = MHD_resp_sender_std;
483 return MHD_ERR_AGAIN_; 487 return MHD_ERR_AGAIN_;
484 } 488 }
489 /* Some unrecoverable error. Possibly file FD is not suitable
490 * for sendfile(). Retry with standard send(). */
491 request->resp_sender = MHD_resp_sender_std;
492 return MHD_ERR_AGAIN_;
493 }
485 mhd_assert (0 < sent_bytes); 494 mhd_assert (0 < sent_bytes);
486 mhd_assert (SSIZE_MAX >= sent_bytes); 495 mhd_assert (SSIZE_MAX >= sent_bytes);
487 ret = (ssize_t)sent_bytes; 496 ret = (ssize_t) sent_bytes;
488#elif defined(HAVE_DARWIN_SENDFILE) 497#elif defined(HAVE_DARWIN_SENDFILE)
489 len = (off_t) send_size; /* chunk always fit */ 498 len = (off_t) send_size; /* chunk always fit */
490 if (0 != sendfile (file_fd, 499 if (0 != sendfile (file_fd,
@@ -493,35 +502,35 @@ sendfile_adapter (struct MHD_Connection *connection)
493 &len, 502 &len,
494 NULL, 503 NULL,
495 0)) 504 0))
505 {
506 const int err = MHD_socket_get_error_ ();
507 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) ||
508 MHD_SCKT_ERR_IS_EINTR_ (err))
496 { 509 {
497 const int err = MHD_socket_get_error_(); 510 mhd_assert (0 <= len);
498 if (MHD_SCKT_ERR_IS_EAGAIN_(err) || 511 mhd_assert (SSIZE_MAX >= len);
499 MHD_SCKT_ERR_IS_EINTR_(err)) 512 mhd_assert (send_size >= (size_t) len);
500 { 513 if (0 != len)
501 mhd_assert (0 <= len); 514 return (ssize_t) len;
502 mhd_assert (SSIZE_MAX >= len);
503 mhd_assert (send_size >= (size_t)len);
504 if (0 != len)
505 return (ssize_t)len;
506 515
507 return MHD_ERR_AGAIN_; 516 return MHD_ERR_AGAIN_;
508 } 517 }
509 if (ENOTCONN == err || 518 if ((ENOTCONN == err) ||
510 EPIPE == err) 519 (EPIPE == err) )
511 return MHD_ERR_CONNRESET_; 520 return MHD_ERR_CONNRESET_;
512 if (ENOTSUP == err || 521 if ((ENOTSUP == err) ||
513 EOPNOTSUPP == err) 522 (EOPNOTSUPP == err) )
514 { /* This file FD is not suitable for sendfile(). 523 { /* This file FD is not suitable for sendfile().
515 * Retry with standard send(). */ 524 * Retry with standard send(). */
516 request->resp_sender = MHD_resp_sender_std; 525 request->resp_sender = MHD_resp_sender_std;
517 return MHD_ERR_AGAIN_; 526 return MHD_ERR_AGAIN_;
518 }
519 return MHD_ERR_BADF_; /* Return hard error. */
520 } 527 }
528 return MHD_ERR_BADF_; /* Return hard error. */
529 }
521 mhd_assert (0 <= len); 530 mhd_assert (0 <= len);
522 mhd_assert (SSIZE_MAX >= len); 531 mhd_assert (SSIZE_MAX >= len);
523 mhd_assert (send_size >= (size_t)len); 532 mhd_assert (send_size >= (size_t) len);
524 ret = (ssize_t)len; 533 ret = (ssize_t) len;
525#endif /* HAVE_FREEBSD_SENDFILE */ 534#endif /* HAVE_FREEBSD_SENDFILE */
526 return ret; 535 return ret;
527} 536}
@@ -547,7 +556,7 @@ check_write_done (struct MHD_Request *request,
547 request->write_buffer_send_offset = 0; 556 request->write_buffer_send_offset = 0;
548 request->state = next_state; 557 request->state = next_state;
549 MHD_pool_reallocate (request->connection->pool, 558 MHD_pool_reallocate (request->connection->pool,
550 request->write_buffer, 559 request->write_buffer,
551 request->write_buffer_size, 560 request->write_buffer_size,
552 0); 561 0);
553 request->write_buffer = NULL; 562 request->write_buffer = NULL;
@@ -579,47 +588,48 @@ try_ready_normal_body (struct MHD_Request *request)
579 (request->response_write_position == response->total_size) ) 588 (request->response_write_position == response->total_size) )
580 return true; /* 0-byte response is always ready */ 589 return true; /* 0-byte response is always ready */
581 if ( (response->data_start <= 590 if ( (response->data_start <=
582 request->response_write_position) && 591 request->response_write_position) &&
583 (response->data_size + response->data_start > 592 (response->data_size + response->data_start >
584 request->response_write_position) ) 593 request->response_write_position) )
585 return true; /* response already ready */ 594 return true; /* response already ready */
586#if defined(_MHD_HAVE_SENDFILE) 595#if defined(_MHD_HAVE_SENDFILE)
587 if (MHD_resp_sender_sendfile == request->resp_sender) 596 if (MHD_resp_sender_sendfile == request->resp_sender)
588 { 597 {
589 /* will use sendfile, no need to bother response crc */ 598 /* will use sendfile, no need to bother response crc */
590 return true; 599 return true;
591 } 600 }
592#endif /* _MHD_HAVE_SENDFILE */ 601#endif /* _MHD_HAVE_SENDFILE */
593 602
594 ret = response->crc (response->crc_cls, 603 ret = response->crc (response->crc_cls,
595 request->response_write_position, 604 request->response_write_position,
596 response->data, 605 response->data,
597 (size_t) MHD_MIN ((uint64_t) response->data_buffer_size, 606 (size_t) MHD_MIN ((uint64_t) response->data_buffer_size,
598 response->total_size - 607 response->total_size
599 request->response_write_position)); 608 - request->response_write_position));
600 if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) || 609 if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) ||
601 (((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) ) 610 (((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) )
602 { 611 {
603 /* either error or http 1.0 transfer, close socket! */ 612 /* either error or http 1.0 transfer, close socket! */
604 response->total_size = request->response_write_position; 613 response->total_size = request->response_write_position;
605 MHD_mutex_unlock_chk_ (&response->mutex); 614 MHD_mutex_unlock_chk_ (&response->mutex);
606 if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret) 615 if ( ((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret)
607 MHD_connection_close_ (connection, 616 MHD_connection_close_ (connection,
608 MHD_REQUEST_TERMINATED_COMPLETED_OK); 617 MHD_REQUEST_TERMINATED_COMPLETED_OK);
609 else 618 else
610 CONNECTION_CLOSE_ERROR (connection, 619 CONNECTION_CLOSE_ERROR (connection,
611 MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED, 620 MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED,
612 _("Closing connection (application reported error generating data)\n")); 621 _ (
613 return false; 622 "Closing connection (application reported error generating data)\n"));
614 } 623 return false;
624 }
615 response->data_start = request->response_write_position; 625 response->data_start = request->response_write_position;
616 response->data_size = ret; 626 response->data_size = ret;
617 if (0 == ret) 627 if (0 == ret)
618 { 628 {
619 request->state = MHD_REQUEST_NORMAL_BODY_UNREADY; 629 request->state = MHD_REQUEST_NORMAL_BODY_UNREADY;
620 MHD_mutex_unlock_chk_ (&response->mutex); 630 MHD_mutex_unlock_chk_ (&response->mutex);
621 return false; 631 return false;
622 } 632 }
623 return true; 633 return true;
624} 634}
625 635
@@ -647,93 +657,94 @@ try_ready_chunked_body (struct MHD_Request *request)
647 if (NULL == response->crc) 657 if (NULL == response->crc)
648 return true; 658 return true;
649 if (0 == request->write_buffer_size) 659 if (0 == request->write_buffer_size)
650 { 660 {
651 size = MHD_MIN (daemon->connection_memory_limit_b, 661 size = MHD_MIN (daemon->connection_memory_limit_b,
652 2 * (0xFFFFFF + sizeof(cbuf) + 2)); 662 2 * (0xFFFFFF + sizeof(cbuf) + 2));
653 do 663 do
654 { 664 {
655 size /= 2; 665 size /= 2;
656 if (size < 128) 666 if (size < 128)
657 { 667 {
658 MHD_mutex_unlock_chk_ (&response->mutex); 668 MHD_mutex_unlock_chk_ (&response->mutex);
659 /* not enough memory */ 669 /* not enough memory */
660 CONNECTION_CLOSE_ERROR (connection, 670 CONNECTION_CLOSE_ERROR (connection,
661 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE, 671 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE,
662 _("Closing connection (out of memory)\n")); 672 _ ("Closing connection (out of memory)\n"));
663 return false; 673 return false;
664 } 674 }
665 buf = MHD_pool_allocate (connection->pool, 675 buf = MHD_pool_allocate (connection->pool,
666 size, 676 size,
667 MHD_NO); 677 MHD_NO);
668 } 678 }
669 while (NULL == buf); 679 while (NULL == buf);
670 request->write_buffer_size = size; 680 request->write_buffer_size = size;
671 request->write_buffer = buf; 681 request->write_buffer = buf;
672 } 682 }
673 683
674 if (0 == response->total_size) 684 if (0 == response->total_size)
675 ret = 0; /* response must be empty, don't bother calling crc */ 685 ret = 0; /* response must be empty, don't bother calling crc */
676 else if ( (response->data_start <= 686 else if ( (response->data_start <=
677 request->response_write_position) && 687 request->response_write_position) &&
678 (response->data_start + response->data_size > 688 (response->data_start + response->data_size >
679 request->response_write_position) ) 689 request->response_write_position) )
680 { 690 {
681 /* difference between response_write_position and data_start is less 691 /* difference between response_write_position and data_start is less
682 than data_size which is size_t type, no need to check for overflow */ 692 than data_size which is size_t type, no need to check for overflow */
683 const size_t data_write_offset 693 const size_t data_write_offset
684 = (size_t)(request->response_write_position - response->data_start); 694 = (size_t) (request->response_write_position - response->data_start);
685 /* buffer already ready, use what is there for the chunk */ 695 /* buffer already ready, use what is there for the chunk */
686 ret = response->data_size - data_write_offset; 696 ret = response->data_size - data_write_offset;
687 if ( ((size_t) ret) > request->write_buffer_size - sizeof (cbuf) - 2 ) 697 if ( ((size_t) ret) > request->write_buffer_size - sizeof (cbuf) - 2 )
688 ret = request->write_buffer_size - sizeof (cbuf) - 2; 698 ret = request->write_buffer_size - sizeof (cbuf) - 2;
689 memcpy (&request->write_buffer[sizeof (cbuf)], 699 memcpy (&request->write_buffer[sizeof (cbuf)],
690 &response->data[data_write_offset], 700 &response->data[data_write_offset],
691 ret); 701 ret);
692 } 702 }
693 else 703 else
694 { 704 {
695 /* buffer not in range, try to fill it */ 705 /* buffer not in range, try to fill it */
696 ret = response->crc (response->crc_cls, 706 ret = response->crc (response->crc_cls,
697 request->response_write_position, 707 request->response_write_position,
698 &request->write_buffer[sizeof (cbuf)], 708 &request->write_buffer[sizeof (cbuf)],
699 request->write_buffer_size - sizeof (cbuf) - 2); 709 request->write_buffer_size - sizeof (cbuf) - 2);
700 } 710 }
701 if ( ((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) 711 if ( ((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret)
702 { 712 {
703 /* error, close socket! */ 713 /* error, close socket! */
704 response->total_size = request->response_write_position; 714 response->total_size = request->response_write_position;
705 MHD_mutex_unlock_chk_ (&response->mutex); 715 MHD_mutex_unlock_chk_ (&response->mutex);
706 CONNECTION_CLOSE_ERROR (connection, 716 CONNECTION_CLOSE_ERROR (connection,
707 MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED, 717 MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED,
708 _("Closing connection (application error generating response)\n")); 718 _ (
709 return false; 719 "Closing connection (application error generating response)\n"));
710 } 720 return false;
721 }
711 if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) || 722 if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) ||
712 (0 == response->total_size) ) 723 (0 == response->total_size) )
713 { 724 {
714 /* end of message, signal other side! */ 725 /* end of message, signal other side! */
715 memcpy (request->write_buffer, 726 memcpy (request->write_buffer,
716 "0\r\n", 727 "0\r\n",
717 3); 728 3);
718 request->write_buffer_append_offset = 3; 729 request->write_buffer_append_offset = 3;
719 request->write_buffer_send_offset = 0; 730 request->write_buffer_send_offset = 0;
720 response->total_size = request->response_write_position; 731 response->total_size = request->response_write_position;
721 return true; 732 return true;
722 } 733 }
723 if (0 == ret) 734 if (0 == ret)
724 { 735 {
725 request->state = MHD_REQUEST_CHUNKED_BODY_UNREADY; 736 request->state = MHD_REQUEST_CHUNKED_BODY_UNREADY;
726 MHD_mutex_unlock_chk_ (&response->mutex); 737 MHD_mutex_unlock_chk_ (&response->mutex);
727 return false; 738 return false;
728 } 739 }
729 if (ret > 0xFFFFFF) 740 if (ret > 0xFFFFFF)
730 ret = 0xFFFFFF; 741 ret = 0xFFFFFF;
731 cblen = MHD_snprintf_(cbuf, 742 cblen = MHD_snprintf_ (cbuf,
732 sizeof (cbuf), 743 sizeof (cbuf),
733 "%X\r\n", 744 "%X\r\n",
734 (unsigned int) ret); 745 (unsigned int) ret);
735 mhd_assert(cblen > 0); 746 mhd_assert (cblen > 0);
736 mhd_assert((size_t)cblen < sizeof(cbuf)); 747 mhd_assert ((size_t) cblen < sizeof(cbuf));
737 memcpy (&request->write_buffer[sizeof (cbuf) - cblen], 748 memcpy (&request->write_buffer[sizeof (cbuf) - cblen],
738 cbuf, 749 cbuf,
739 cblen); 750 cblen);
@@ -768,221 +779,224 @@ MHD_request_handle_write_ (struct MHD_Request *request)
768 struct MHD_TLS_Plugin *tls; 779 struct MHD_TLS_Plugin *tls;
769 780
770 if ( (NULL != (tls = daemon->tls_api)) && 781 if ( (NULL != (tls = daemon->tls_api)) &&
771 (! tls->handshake (tls->cls, 782 (! tls->handshake (tls->cls,
772 connection->tls_cs)) ) 783 connection->tls_cs)) )
773 return; 784 return;
774 } 785 }
775#endif /* HTTPS_SUPPORT */ 786#endif /* HTTPS_SUPPORT */
776 787
777#if DEBUG_STATES 788#if DEBUG_STATES
778 MHD_DLOG (daemon, 789 MHD_DLOG (daemon,
779 MHD_SC_STATE_MACHINE_STATUS_REPORT, 790 MHD_SC_STATE_MACHINE_STATUS_REPORT,
780 _("In function %s handling connection at state: %s\n"), 791 _ ("In function %s handling connection at state: %s\n"),
781 __FUNCTION__, 792 __FUNCTION__,
782 MHD_state_to_string (request->state)); 793 MHD_state_to_string (request->state));
783#endif 794#endif
784 switch (request->state) 795 switch (request->state)
785 { 796 {
786 case MHD_REQUEST_INIT: 797 case MHD_REQUEST_INIT:
787 case MHD_REQUEST_URL_RECEIVED: 798 case MHD_REQUEST_URL_RECEIVED:
788 case MHD_REQUEST_HEADER_PART_RECEIVED: 799 case MHD_REQUEST_HEADER_PART_RECEIVED:
789 case MHD_REQUEST_HEADERS_RECEIVED: 800 case MHD_REQUEST_HEADERS_RECEIVED:
790 mhd_assert (0); 801 mhd_assert (0);
791 return; 802 return;
792 case MHD_REQUEST_HEADERS_PROCESSED: 803 case MHD_REQUEST_HEADERS_PROCESSED:
793 return; 804 return;
794 case MHD_REQUEST_CONTINUE_SENDING: 805 case MHD_REQUEST_CONTINUE_SENDING:
795 ret = connection->send_cls (connection, 806 ret = connection->send_cls (connection,
796 &HTTP_100_CONTINUE 807 &HTTP_100_CONTINUE
797 [request->continue_message_write_offset], 808 [request->continue_message_write_offset],
798 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE) - 809 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)
799 request->continue_message_write_offset); 810 - request->continue_message_write_offset);
800 if (ret < 0) 811 if (ret < 0)
801 { 812 {
802 if (MHD_ERR_AGAIN_ == ret) 813 if (MHD_ERR_AGAIN_ == ret)
803 return; 814 return;
804#ifdef HAVE_MESSAGES 815#ifdef HAVE_MESSAGES
805 MHD_DLOG (daemon, 816 MHD_DLOG (daemon,
806 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED, 817 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
807 _("Failed to send data in request for %s.\n"), 818 _ ("Failed to send data in request for %s.\n"),
808 request->url); 819 request->url);
809#endif 820#endif
810 CONNECTION_CLOSE_ERROR (connection, 821 CONNECTION_CLOSE_ERROR (connection,
811 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED, 822 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
812 NULL); 823 NULL);
813 return;
814 }
815 request->continue_message_write_offset += ret;
816 MHD_connection_update_last_activity_ (connection);
817 return;
818 case MHD_REQUEST_CONTINUE_SENT:
819 case MHD_REQUEST_BODY_RECEIVED:
820 case MHD_REQUEST_FOOTER_PART_RECEIVED:
821 case MHD_REQUEST_FOOTERS_RECEIVED:
822 mhd_assert (0);
823 return; 824 return;
824 case MHD_REQUEST_HEADERS_SENDING: 825 }
825 ret = connection->send_cls (connection, 826 request->continue_message_write_offset += ret;
826 &request->write_buffer 827 MHD_connection_update_last_activity_ (connection);
827 [request->write_buffer_send_offset], 828 return;
828 request->write_buffer_append_offset - 829 case MHD_REQUEST_CONTINUE_SENT:
829 request->write_buffer_send_offset); 830 case MHD_REQUEST_BODY_RECEIVED:
830 if (ret < 0) 831 case MHD_REQUEST_FOOTER_PART_RECEIVED:
831 { 832 case MHD_REQUEST_FOOTERS_RECEIVED:
832 if (MHD_ERR_AGAIN_ == ret) 833 mhd_assert (0);
833 return; 834 return;
834 CONNECTION_CLOSE_ERROR (connection, 835 case MHD_REQUEST_HEADERS_SENDING:
835 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED, 836 ret = connection->send_cls (connection,
836 _("Connection was closed while sending response headers.\n")); 837 &request->write_buffer
837 return; 838 [request->write_buffer_send_offset],
838 } 839 request->write_buffer_append_offset
839 request->write_buffer_send_offset += ret; 840 - request->write_buffer_send_offset);
840 MHD_connection_update_last_activity_ (connection); 841 if (ret < 0)
841 if (MHD_REQUEST_HEADERS_SENDING != request->state) 842 {
843 if (MHD_ERR_AGAIN_ == ret)
842 return; 844 return;
843 check_write_done (request, 845 CONNECTION_CLOSE_ERROR (connection,
844 MHD_REQUEST_HEADERS_SENT); 846 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
847 _ (
848 "Connection was closed while sending response headers.\n"));
845 return; 849 return;
846 case MHD_REQUEST_HEADERS_SENT: 850 }
851 request->write_buffer_send_offset += ret;
852 MHD_connection_update_last_activity_ (connection);
853 if (MHD_REQUEST_HEADERS_SENDING != request->state)
847 return; 854 return;
848 case MHD_REQUEST_NORMAL_BODY_READY: 855 check_write_done (request,
849 response = request->response; 856 MHD_REQUEST_HEADERS_SENT);
850 if (request->response_write_position < 857 return;
851 request->response->total_size) 858 case MHD_REQUEST_HEADERS_SENT:
852 { 859 return;
853 uint64_t data_write_offset; 860 case MHD_REQUEST_NORMAL_BODY_READY:
854 861 response = request->response;
855 if (NULL != response->crc) 862 if (request->response_write_position <
856 MHD_mutex_lock_chk_ (&response->mutex); 863 request->response->total_size)
857 if (! try_ready_normal_body (request)) 864 {
858 { 865 uint64_t data_write_offset;
859 /* mutex was already unlocked by try_ready_normal_body */ 866
860 return; 867 if (NULL != response->crc)
861 } 868 MHD_mutex_lock_chk_ (&response->mutex);
869 if (! try_ready_normal_body (request))
870 {
871 /* mutex was already unlocked by try_ready_normal_body */
872 return;
873 }
862#if defined(_MHD_HAVE_SENDFILE) 874#if defined(_MHD_HAVE_SENDFILE)
863 if (MHD_resp_sender_sendfile == request->resp_sender) 875 if (MHD_resp_sender_sendfile == request->resp_sender)
864 { 876 {
865 ret = sendfile_adapter (connection); 877 ret = sendfile_adapter (connection);
866 } 878 }
867 else 879 else
868#else /* ! _MHD_HAVE_SENDFILE */ 880#else /* ! _MHD_HAVE_SENDFILE */
869 if (1) 881 if (1)
870#endif /* ! _MHD_HAVE_SENDFILE */ 882#endif /* ! _MHD_HAVE_SENDFILE */
871 { 883 {
872 data_write_offset = request->response_write_position 884 data_write_offset = request->response_write_position
873 - response->data_start; 885 - response->data_start;
874 if (data_write_offset > (uint64_t)SIZE_MAX) 886 if (data_write_offset > (uint64_t) SIZE_MAX)
875 MHD_PANIC (_("Data offset exceeds limit")); 887 MHD_PANIC (_ ("Data offset exceeds limit"));
876 ret = connection->send_cls (connection, 888 ret = connection->send_cls (connection,
877 &response->data 889 &response->data
878 [(size_t)data_write_offset], 890 [(size_t) data_write_offset],
879 response->data_size - 891 response->data_size
880 (size_t)data_write_offset); 892 - (size_t) data_write_offset);
881#if DEBUG_SEND_DATA 893#if DEBUG_SEND_DATA
882 if (ret > 0) 894 if (ret > 0)
883 fprintf (stderr, 895 fprintf (stderr,
884 _("Sent %d-byte DATA response: `%.*s'\n"), 896 _ ("Sent %d-byte DATA response: `%.*s'\n"),
885 (int) ret, 897 (int) ret,
886 (int) ret, 898 (int) ret,
887 &response->data[request->response_write_position - 899 &response->data[request->response_write_position
888 response->data_start]); 900 - response->data_start]);
889#endif 901#endif
890 } 902 }
891 if (NULL != response->crc) 903 if (NULL != response->crc)
892 MHD_mutex_unlock_chk_ (&response->mutex); 904 MHD_mutex_unlock_chk_ (&response->mutex);
893 if (ret < 0)
894 {
895 if (MHD_ERR_AGAIN_ == ret)
896 return;
897#ifdef HAVE_MESSAGES
898 MHD_DLOG (daemon,
899 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
900 _("Failed to send data in request for `%s'.\n"),
901 request->url);
902#endif
903 CONNECTION_CLOSE_ERROR (connection,
904 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
905 NULL);
906 return;
907 }
908 request->response_write_position += ret;
909 MHD_connection_update_last_activity_ (connection);
910 }
911 if (request->response_write_position ==
912 request->response->total_size)
913 request->state = MHD_REQUEST_FOOTERS_SENT; /* have no footers */
914 return;
915 case MHD_REQUEST_NORMAL_BODY_UNREADY:
916 mhd_assert (0);
917 return;
918 case MHD_REQUEST_CHUNKED_BODY_READY:
919 ret = connection->send_cls (connection,
920 &request->write_buffer
921 [request->write_buffer_send_offset],
922 request->write_buffer_append_offset -
923 request->write_buffer_send_offset);
924 if (ret < 0) 905 if (ret < 0)
925 { 906 {
926 if (MHD_ERR_AGAIN_ == ret) 907 if (MHD_ERR_AGAIN_ == ret)
927 return;
928 CONNECTION_CLOSE_ERROR (connection,
929 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
930 _("Connection was closed while sending response body.\n"));
931 return; 908 return;
932 } 909#ifdef HAVE_MESSAGES
933 request->write_buffer_send_offset += ret; 910 MHD_DLOG (daemon,
911 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
912 _ ("Failed to send data in request for `%s'.\n"),
913 request->url);
914#endif
915 CONNECTION_CLOSE_ERROR (connection,
916 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
917 NULL);
918 return;
919 }
920 request->response_write_position += ret;
934 MHD_connection_update_last_activity_ (connection); 921 MHD_connection_update_last_activity_ (connection);
935 if (MHD_REQUEST_CHUNKED_BODY_READY != request->state) 922 }
923 if (request->response_write_position ==
924 request->response->total_size)
925 request->state = MHD_REQUEST_FOOTERS_SENT; /* have no footers */
926 return;
927 case MHD_REQUEST_NORMAL_BODY_UNREADY:
928 mhd_assert (0);
929 return;
930 case MHD_REQUEST_CHUNKED_BODY_READY:
931 ret = connection->send_cls (connection,
932 &request->write_buffer
933 [request->write_buffer_send_offset],
934 request->write_buffer_append_offset
935 - request->write_buffer_send_offset);
936 if (ret < 0)
937 {
938 if (MHD_ERR_AGAIN_ == ret)
936 return; 939 return;
937 check_write_done (request, 940 CONNECTION_CLOSE_ERROR (connection,
938 (request->response->total_size == 941 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
939 request->response_write_position) ? 942 _ (
940 MHD_REQUEST_BODY_SENT : 943 "Connection was closed while sending response body.\n"));
941 MHD_REQUEST_CHUNKED_BODY_UNREADY);
942 return; 944 return;
943 case MHD_REQUEST_CHUNKED_BODY_UNREADY: 945 }
944 case MHD_REQUEST_BODY_SENT: 946 request->write_buffer_send_offset += ret;
945 mhd_assert (0); 947 MHD_connection_update_last_activity_ (connection);
948 if (MHD_REQUEST_CHUNKED_BODY_READY != request->state)
946 return; 949 return;
947 case MHD_REQUEST_FOOTERS_SENDING: 950 check_write_done (request,
948 ret = connection->send_cls (connection, 951 (request->response->total_size ==
949 &request->write_buffer 952 request->response_write_position) ?
950 [request->write_buffer_send_offset], 953 MHD_REQUEST_BODY_SENT :
951 request->write_buffer_append_offset - 954 MHD_REQUEST_CHUNKED_BODY_UNREADY);
952 request->write_buffer_send_offset); 955 return;
953 if (ret < 0) 956 case MHD_REQUEST_CHUNKED_BODY_UNREADY:
954 { 957 case MHD_REQUEST_BODY_SENT:
955 if (MHD_ERR_AGAIN_ == ret) 958 mhd_assert (0);
956 return; 959 return;
957 CONNECTION_CLOSE_ERROR (connection, 960 case MHD_REQUEST_FOOTERS_SENDING:
958 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED, 961 ret = connection->send_cls (connection,
959 _("Connection was closed while sending response body.\n")); 962 &request->write_buffer
960 return; 963 [request->write_buffer_send_offset],
961 } 964 request->write_buffer_append_offset
962 request->write_buffer_send_offset += ret; 965 - request->write_buffer_send_offset);
963 MHD_connection_update_last_activity_ (connection); 966 if (ret < 0)
964 if (MHD_REQUEST_FOOTERS_SENDING != request->state) 967 {
968 if (MHD_ERR_AGAIN_ == ret)
965 return; 969 return;
966 check_write_done (request, 970 CONNECTION_CLOSE_ERROR (connection,
967 MHD_REQUEST_FOOTERS_SENT); 971 MHD_SC_CONNECTION_WRITE_FAIL_CLOSED,
968 return; 972 _ (
969 case MHD_REQUEST_FOOTERS_SENT: 973 "Connection was closed while sending response body.\n"));
970 mhd_assert (0);
971 return; 974 return;
972 case MHD_REQUEST_CLOSED: 975 }
976 request->write_buffer_send_offset += ret;
977 MHD_connection_update_last_activity_ (connection);
978 if (MHD_REQUEST_FOOTERS_SENDING != request->state)
973 return; 979 return;
980 check_write_done (request,
981 MHD_REQUEST_FOOTERS_SENT);
982 return;
983 case MHD_REQUEST_FOOTERS_SENT:
984 mhd_assert (0);
985 return;
986 case MHD_REQUEST_CLOSED:
987 return;
974#ifdef UPGRADE_SUPPORT 988#ifdef UPGRADE_SUPPORT
975 case MHD_REQUEST_UPGRADE: 989 case MHD_REQUEST_UPGRADE:
976 mhd_assert (0); 990 mhd_assert (0);
977 return; 991 return;
978#endif /* UPGRADE_SUPPORT */ 992#endif /* UPGRADE_SUPPORT */
979 default: 993 default:
980 mhd_assert (0); 994 mhd_assert (0);
981 CONNECTION_CLOSE_ERROR (connection, 995 CONNECTION_CLOSE_ERROR (connection,
982 MHD_SC_STATEMACHINE_FAILURE_CONNECTION_CLOSED, 996 MHD_SC_STATEMACHINE_FAILURE_CONNECTION_CLOSED,
983 _("Internal error\n")); 997 _ ("Internal error\n"));
984 break; 998 break;
985 } 999 }
986} 1000}
987 1001
988 1002
@@ -1001,9 +1015,9 @@ MHD_request_handle_write_ (struct MHD_Request *request)
1001 */ 1015 */
1002static bool 1016static bool
1003MHD_lookup_header_token_ci (const struct MHD_Request *request, 1017MHD_lookup_header_token_ci (const struct MHD_Request *request,
1004 const char *header, 1018 const char *header,
1005 const char *token, 1019 const char *token,
1006 size_t token_len) 1020 size_t token_len)
1007{ 1021{
1008 struct MHD_HTTP_Header *pos; 1022 struct MHD_HTTP_Header *pos;
1009 1023
@@ -1014,16 +1028,16 @@ MHD_lookup_header_token_ci (const struct MHD_Request *request,
1014 (0 == token[0]) ) 1028 (0 == token[0]) )
1015 return false; 1029 return false;
1016 for (pos = request->headers_received; NULL != pos; pos = pos->next) 1030 for (pos = request->headers_received; NULL != pos; pos = pos->next)
1017 { 1031 {
1018 if ( (0 != (pos->kind & MHD_HEADER_KIND)) && 1032 if ( (0 != (pos->kind & MHD_HEADER_KIND)) &&
1019 ( (header == pos->header) || 1033 ( (header == pos->header) ||
1020 (MHD_str_equal_caseless_(header, 1034 (MHD_str_equal_caseless_ (header,
1021 pos->header)) ) && 1035 pos->header)) ) &&
1022 (MHD_str_has_token_caseless_ (pos->value, 1036 (MHD_str_has_token_caseless_ (pos->value,
1023 token, 1037 token,
1024 token_len)) ) 1038 token_len)) )
1025 return true; 1039 return true;
1026 } 1040 }
1027 return false; 1041 return false;
1028} 1042}
1029 1043
@@ -1040,7 +1054,7 @@ MHD_lookup_header_token_ci (const struct MHD_Request *request,
1040 * false otherwise 1054 * false otherwise
1041 */ 1055 */
1042#define MHD_lookup_header_s_token_ci(r,h,tkn) \ 1056#define MHD_lookup_header_s_token_ci(r,h,tkn) \
1043 MHD_lookup_header_token_ci((r),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) 1057 MHD_lookup_header_token_ci ((r),(h),(tkn),MHD_STATICSTR_LEN_ (tkn))
1044 1058
1045 1059
1046/** 1060/**
@@ -1071,27 +1085,27 @@ keepalive_possible (struct MHD_Request *request)
1071 return false; 1085 return false;
1072 1086
1073 if (MHD_str_equal_caseless_ (request->version_s, 1087 if (MHD_str_equal_caseless_ (request->version_s,
1074 MHD_HTTP_VERSION_1_1)) 1088 MHD_HTTP_VERSION_1_1))
1075 { 1089 {
1076 if (MHD_lookup_header_s_token_ci (request, 1090 if (MHD_lookup_header_s_token_ci (request,
1077 MHD_HTTP_HEADER_CONNECTION, 1091 MHD_HTTP_HEADER_CONNECTION,
1078 "upgrade")) 1092 "upgrade"))
1079 return false;
1080 if (MHD_lookup_header_s_token_ci (request,
1081 MHD_HTTP_HEADER_CONNECTION,
1082 "close"))
1083 return false;
1084 return true;
1085 }
1086 if (MHD_str_equal_caseless_ (request->version_s,
1087 MHD_HTTP_VERSION_1_0))
1088 {
1089 if (MHD_lookup_header_s_token_ci (request,
1090 MHD_HTTP_HEADER_CONNECTION,
1091 "Keep-Alive"))
1092 return true;
1093 return false; 1093 return false;
1094 } 1094 if (MHD_lookup_header_s_token_ci (request,
1095 MHD_HTTP_HEADER_CONNECTION,
1096 "close"))
1097 return false;
1098 return true;
1099 }
1100 if (MHD_str_equal_caseless_ (request->version_s,
1101 MHD_HTTP_VERSION_1_0))
1102 {
1103 if (MHD_lookup_header_s_token_ci (request,
1104 MHD_HTTP_HEADER_CONNECTION,
1105 "Keep-Alive"))
1106 return true;
1107 return false;
1108 }
1095 return false; 1109 return false;
1096} 1110}
1097 1111
@@ -1105,7 +1119,7 @@ keepalive_possible (struct MHD_Request *request)
1105 */ 1119 */
1106static void 1120static void
1107get_date_string (char *date, 1121get_date_string (char *date,
1108 size_t date_len) 1122 size_t date_len)
1109{ 1123{
1110 static const char *const days[] = { 1124 static const char *const days[] = {
1111 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 1125 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
@@ -1116,8 +1130,9 @@ get_date_string (char *date,
1116 }; 1130 };
1117 struct tm now; 1131 struct tm now;
1118 time_t t; 1132 time_t t;
1119#if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && !defined(HAVE_GMTIME_R) 1133#if ! defined(HAVE_C11_GMTIME_S) && ! defined(HAVE_W32_GMTIME_S) && \
1120 struct tm* pNow; 1134 ! defined(HAVE_GMTIME_R)
1135 struct tm*pNow;
1121#endif 1136#endif
1122 1137
1123 date[0] = 0; 1138 date[0] = 0;
@@ -1131,25 +1146,25 @@ get_date_string (char *date,
1131 &t)) 1146 &t))
1132 return; 1147 return;
1133#elif defined(HAVE_GMTIME_R) 1148#elif defined(HAVE_GMTIME_R)
1134 if (NULL == gmtime_r(&t, 1149 if (NULL == gmtime_r (&t,
1135 &now)) 1150 &now))
1136 return; 1151 return;
1137#else 1152#else
1138 pNow = gmtime(&t); 1153 pNow = gmtime (&t);
1139 if (NULL == pNow) 1154 if (NULL == pNow)
1140 return; 1155 return;
1141 now = *pNow; 1156 now = *pNow;
1142#endif 1157#endif
1143 MHD_snprintf_ (date, 1158 MHD_snprintf_ (date,
1144 date_len, 1159 date_len,
1145 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", 1160 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
1146 days[now.tm_wday % 7], 1161 days[now.tm_wday % 7],
1147 (unsigned int) now.tm_mday, 1162 (unsigned int) now.tm_mday,
1148 mons[now.tm_mon % 12], 1163 mons[now.tm_mon % 12],
1149 (unsigned int) (1900 + now.tm_year), 1164 (unsigned int) (1900 + now.tm_year),
1150 (unsigned int) now.tm_hour, 1165 (unsigned int) now.tm_hour,
1151 (unsigned int) now.tm_min, 1166 (unsigned int) now.tm_min,
1152 (unsigned int) now.tm_sec); 1167 (unsigned int) now.tm_sec);
1153} 1168}
1154 1169
1155 1170
@@ -1168,9 +1183,9 @@ get_date_string (char *date,
1168 */ 1183 */
1169static bool 1184static bool
1170check_response_header_token_ci (const struct MHD_Response *response, 1185check_response_header_token_ci (const struct MHD_Response *response,
1171 const char *key, 1186 const char *key,
1172 const char *token, 1187 const char *token,
1173 size_t token_len) 1188 size_t token_len)
1174{ 1189{
1175 struct MHD_HTTP_Header *pos; 1190 struct MHD_HTTP_Header *pos;
1176 1191
@@ -1183,15 +1198,15 @@ check_response_header_token_ci (const struct MHD_Response *response,
1183 for (pos = response->first_header; 1198 for (pos = response->first_header;
1184 NULL != pos; 1199 NULL != pos;
1185 pos = pos->next) 1200 pos = pos->next)
1186 { 1201 {
1187 if ( (pos->kind == MHD_HEADER_KIND) && 1202 if ( (pos->kind == MHD_HEADER_KIND) &&
1188 MHD_str_equal_caseless_ (pos->header, 1203 MHD_str_equal_caseless_ (pos->header,
1189 key) && 1204 key) &&
1190 MHD_str_has_token_caseless_ (pos->value, 1205 MHD_str_has_token_caseless_ (pos->value,
1191 token, 1206 token,
1192 token_len) ) 1207 token_len) )
1193 return true; 1208 return true;
1194 } 1209 }
1195 return false; 1210 return false;
1196} 1211}
1197 1212
@@ -1208,7 +1223,7 @@ check_response_header_token_ci (const struct MHD_Response *response,
1208 * false otherwise 1223 * false otherwise
1209 */ 1224 */
1210#define check_response_header_s_token_ci(r,k,tkn) \ 1225#define check_response_header_s_token_ci(r,k,tkn) \
1211 check_response_header_token_ci((r),(k),(tkn),MHD_STATICSTR_LEN_(tkn)) 1226 check_response_header_token_ci ((r),(k),(tkn),MHD_STATICSTR_LEN_ (tkn))
1212 1227
1213 1228
1214/** 1229/**
@@ -1248,58 +1263,58 @@ build_header_response (struct MHD_Request *request)
1248 1263
1249 mhd_assert (NULL != request->version_s); 1264 mhd_assert (NULL != request->version_s);
1250 if (0 == request->version_s[0]) 1265 if (0 == request->version_s[0])
1251 { 1266 {
1252 data = MHD_pool_allocate (connection->pool, 1267 data = MHD_pool_allocate (connection->pool,
1253 0, 1268 0,
1254 MHD_YES); 1269 MHD_YES);
1255 request->write_buffer = data; 1270 request->write_buffer = data;
1256 request->write_buffer_append_offset = 0; 1271 request->write_buffer_append_offset = 0;
1257 request->write_buffer_send_offset = 0; 1272 request->write_buffer_send_offset = 0;
1258 request->write_buffer_size = 0; 1273 request->write_buffer_size = 0;
1259 return true; 1274 return true;
1260 } 1275 }
1261 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state) 1276 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state)
1262 { 1277 {
1263 const char *reason_phrase; 1278 const char *reason_phrase;
1264 const char *version; 1279 const char *version;
1265 1280
1266 reason_phrase 1281 reason_phrase
1267 = MHD_get_reason_phrase_for (response->status_code); 1282 = MHD_get_reason_phrase_for (response->status_code);
1268 version 1283 version
1269 = (response->icy) 1284 = (response->icy)
1270 ? "ICY" 1285 ? "ICY"
1271 : ( (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_0, 1286 : ( (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_0,
1272 request->version_s)) 1287 request->version_s))
1273 ? MHD_HTTP_VERSION_1_0 1288 ? MHD_HTTP_VERSION_1_0
1274 : MHD_HTTP_VERSION_1_1); 1289 : MHD_HTTP_VERSION_1_1);
1275 MHD_snprintf_ (code, 1290 MHD_snprintf_ (code,
1276 sizeof (code), 1291 sizeof (code),
1277 "%s %u %s\r\n", 1292 "%s %u %s\r\n",
1278 version, 1293 version,
1279 response->status_code, 1294 response->status_code,
1280 reason_phrase); 1295 reason_phrase);
1281 off = strlen (code); 1296 off = strlen (code);
1282 /* estimate size */ 1297 /* estimate size */
1283 size = off + 2; /* +2 for extra "\r\n" at the end */ 1298 size = off + 2; /* +2 for extra "\r\n" at the end */
1284 kind = MHD_HEADER_KIND; 1299 kind = MHD_HEADER_KIND;
1285 if ( (! daemon->suppress_date) && 1300 if ( (! daemon->suppress_date) &&
1286 (NULL == MHD_response_get_header (response, 1301 (NULL == MHD_response_get_header (response,
1287 MHD_HTTP_HEADER_DATE)) ) 1302 MHD_HTTP_HEADER_DATE)) )
1288 get_date_string (date, 1303 get_date_string (date,
1289 sizeof (date)); 1304 sizeof (date));
1290 else 1305 else
1291 date[0] = '\0'; 1306 date[0] = '\0';
1292 datelen = strlen (date); 1307 datelen = strlen (date);
1293 size += datelen; 1308 size += datelen;
1294 } 1309 }
1295 else 1310 else
1296 { 1311 {
1297 /* 2 bytes for final CRLF of a Chunked-Body */ 1312 /* 2 bytes for final CRLF of a Chunked-Body */
1298 size = 2; 1313 size = 2;
1299 kind = MHD_FOOTER_KIND; 1314 kind = MHD_FOOTER_KIND;
1300 off = 0; 1315 off = 0;
1301 datelen = 0; 1316 datelen = 0;
1302 } 1317 }
1303 1318
1304 /* calculate extra headers we need to add, such as 'Connection: close', 1319 /* calculate extra headers we need to add, such as 'Connection: close',
1305 first see what was explicitly requested by the application */ 1320 first see what was explicitly requested by the application */
@@ -1309,153 +1324,154 @@ build_header_response (struct MHD_Request *request)
1309 must_add_content_length = false; 1324 must_add_content_length = false;
1310 response_has_close = false; 1325 response_has_close = false;
1311 switch (request->state) 1326 switch (request->state)
1312 { 1327 {
1313 case MHD_REQUEST_FOOTERS_RECEIVED: 1328 case MHD_REQUEST_FOOTERS_RECEIVED:
1314 response_has_close 1329 response_has_close
1315 = check_response_header_s_token_ci (response, 1330 = check_response_header_s_token_ci (response,
1316 MHD_HTTP_HEADER_CONNECTION, 1331 MHD_HTTP_HEADER_CONNECTION,
1317 "close"); 1332 "close");
1318 response_has_keepalive 1333 response_has_keepalive
1319 = check_response_header_s_token_ci (response, 1334 = check_response_header_s_token_ci (response,
1320 MHD_HTTP_HEADER_CONNECTION, 1335 MHD_HTTP_HEADER_CONNECTION,
1321 "Keep-Alive"); 1336 "Keep-Alive");
1322 client_requested_close 1337 client_requested_close
1323 = MHD_lookup_header_s_token_ci (request, 1338 = MHD_lookup_header_s_token_ci (request,
1324 MHD_HTTP_HEADER_CONNECTION, 1339 MHD_HTTP_HEADER_CONNECTION,
1325 "close"); 1340 "close");
1326 1341
1327 if (response->v10_only) 1342 if (response->v10_only)
1328 request->keepalive = MHD_CONN_MUST_CLOSE; 1343 request->keepalive = MHD_CONN_MUST_CLOSE;
1329#ifdef UPGRADE_SUPPORT 1344#ifdef UPGRADE_SUPPORT
1330 else if (NULL != response->upgrade_handler) 1345 else if (NULL != response->upgrade_handler)
1331 /* If this connection will not be "upgraded", it must be closed. */ 1346 /* If this connection will not be "upgraded", it must be closed. */
1332 request->keepalive = MHD_CONN_MUST_CLOSE; 1347 request->keepalive = MHD_CONN_MUST_CLOSE;
1333#endif /* UPGRADE_SUPPORT */ 1348#endif /* UPGRADE_SUPPORT */
1334 1349
1335 /* now analyze chunked encoding situation */ 1350 /* now analyze chunked encoding situation */
1336 request->have_chunked_upload = false; 1351 request->have_chunked_upload = false;
1337 1352
1338 if ( (MHD_SIZE_UNKNOWN == response->total_size) && 1353 if ( (MHD_SIZE_UNKNOWN == response->total_size) &&
1339#ifdef UPGRADE_SUPPORT 1354#ifdef UPGRADE_SUPPORT
1340 (NULL == response->upgrade_handler) && 1355 (NULL == response->upgrade_handler) &&
1341#endif /* UPGRADE_SUPPORT */ 1356#endif /* UPGRADE_SUPPORT */
1342 (! response_has_close) && 1357 (! response_has_close) &&
1343 (! client_requested_close) ) 1358 (! client_requested_close) )
1359 {
1360 /* size is unknown, and close was not explicitly requested;
1361 need to either to HTTP 1.1 chunked encoding or
1362 close the connection */
1363 /* 'close' header doesn't exist yet, see if we need to add one;
1364 if the client asked for a close, no need to start chunk'ing */
1365 if ( (keepalive_possible (request)) &&
1366 (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_1,
1367 request->version_s)) )
1368 {
1369 have_encoding
1370 = MHD_response_get_header (response,
1371 MHD_HTTP_HEADER_TRANSFER_ENCODING);
1372 if (NULL == have_encoding)
1344 { 1373 {
1345 /* size is unknown, and close was not explicitly requested; 1374 must_add_chunked_encoding = true;
1346 need to either to HTTP 1.1 chunked encoding or 1375 request->have_chunked_upload = true;
1347 close the connection */
1348 /* 'close' header doesn't exist yet, see if we need to add one;
1349 if the client asked for a close, no need to start chunk'ing */
1350 if ( (keepalive_possible (request)) &&
1351 (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_1,
1352 request->version_s)) )
1353 {
1354 have_encoding
1355 = MHD_response_get_header (response,
1356 MHD_HTTP_HEADER_TRANSFER_ENCODING);
1357 if (NULL == have_encoding)
1358 {
1359 must_add_chunked_encoding = true;
1360 request->have_chunked_upload = true;
1361 }
1362 else if (MHD_str_equal_caseless_ (have_encoding,
1363 "identity"))
1364 {
1365 /* application forced identity encoding, can't do 'chunked' */
1366 must_add_close = true;
1367 }
1368 else
1369 {
1370 request->have_chunked_upload = true;
1371 }
1372 }
1373 else
1374 {
1375 /* Keep alive or chunking not possible
1376 => set close header if not present */
1377 if (! response_has_close)
1378 must_add_close = true;
1379 }
1380 } 1376 }
1381 1377 else if (MHD_str_equal_caseless_ (have_encoding,
1382 /* check for other reasons to add 'close' header */ 1378 "identity"))
1383 if ( ( (client_requested_close) ||
1384 (connection->read_closed) ||
1385 (MHD_CONN_MUST_CLOSE == request->keepalive)) &&
1386 (! response_has_close) &&
1387#ifdef UPGRADE_SUPPORT
1388 (NULL == response->upgrade_handler) &&
1389#endif /* UPGRADE_SUPPORT */
1390 (! response->v10_only) )
1391 must_add_close = true;
1392
1393 /* check if we should add a 'content length' header */
1394 have_content_length
1395 = MHD_response_get_header (response,
1396 MHD_HTTP_HEADER_CONTENT_LENGTH);
1397
1398 /* MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED and 1xx-status
1399 codes SHOULD NOT have a Content-Length according to spec;
1400 also chunked encoding / unknown length or CONNECT... */
1401 if ( (MHD_SIZE_UNKNOWN != response->total_size) &&
1402 (MHD_HTTP_NO_CONTENT != response->status_code) &&
1403 (MHD_HTTP_NOT_MODIFIED != response->status_code) &&
1404 (MHD_HTTP_OK <= response->status_code) &&
1405 (NULL == have_content_length) &&
1406 (request->method != MHD_METHOD_CONNECT) )
1407 { 1379 {
1408 /* 1380 /* application forced identity encoding, can't do 'chunked' */
1409 Here we add a content-length if one is missing; however, 1381 must_add_close = true;
1410 for 'connect' methods, the responses MUST NOT include a
1411 content-length header *if* the response code is 2xx (in
1412 which case we expect there to be no body). Still,
1413 as we don't know the response code here in some cases, we
1414 simply only force adding a content-length header if this
1415 is not a 'connect' or if the response is not empty
1416 (which is kind of more sane, because if some crazy
1417 application did return content with a 2xx status code,
1418 then having a content-length might again be a good idea).
1419
1420 Note that the change from 'SHOULD NOT' to 'MUST NOT' is
1421 a recent development of the HTTP 1.1 specification.
1422 */
1423 content_length_len
1424 = MHD_snprintf_ (content_length_buf,
1425 sizeof (content_length_buf),
1426 MHD_HTTP_HEADER_CONTENT_LENGTH ": " MHD_UNSIGNED_LONG_LONG_PRINTF "\r\n",
1427 (MHD_UNSIGNED_LONG_LONG) response->total_size);
1428 must_add_content_length = true;
1429 } 1382 }
1430 1383 else
1431 /* check for adding keep alive */ 1384 {
1432 if ( (! response_has_keepalive) && 1385 request->have_chunked_upload = true;
1433 (! response_has_close) && 1386 }
1434 (! must_add_close) && 1387 }
1435 (MHD_CONN_MUST_CLOSE != request->keepalive) && 1388 else
1389 {
1390 /* Keep alive or chunking not possible
1391 => set close header if not present */
1392 if (! response_has_close)
1393 must_add_close = true;
1394 }
1395 }
1396
1397 /* check for other reasons to add 'close' header */
1398 if ( ( (client_requested_close) ||
1399 (connection->read_closed) ||
1400 (MHD_CONN_MUST_CLOSE == request->keepalive)) &&
1401 (! response_has_close) &&
1436#ifdef UPGRADE_SUPPORT 1402#ifdef UPGRADE_SUPPORT
1437 (NULL == response->upgrade_handler) && 1403 (NULL == response->upgrade_handler) &&
1438#endif /* UPGRADE_SUPPORT */ 1404#endif /* UPGRADE_SUPPORT */
1439 (keepalive_possible (request)) ) 1405 (! response->v10_only) )
1440 must_add_keep_alive = true; 1406 must_add_close = true;
1441 break; 1407
1442 case MHD_REQUEST_BODY_SENT: 1408 /* check if we should add a 'content length' header */
1443 response_has_keepalive = false; 1409 have_content_length
1444 break; 1410 = MHD_response_get_header (response,
1445 default: 1411 MHD_HTTP_HEADER_CONTENT_LENGTH);
1446 mhd_assert (0); 1412
1447 return MHD_NO; 1413 /* MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED and 1xx-status
1448 } 1414 codes SHOULD NOT have a Content-Length according to spec;
1415 also chunked encoding / unknown length or CONNECT... */
1416 if ( (MHD_SIZE_UNKNOWN != response->total_size) &&
1417 (MHD_HTTP_NO_CONTENT != response->status_code) &&
1418 (MHD_HTTP_NOT_MODIFIED != response->status_code) &&
1419 (MHD_HTTP_OK <= response->status_code) &&
1420 (NULL == have_content_length) &&
1421 (request->method != MHD_METHOD_CONNECT) )
1422 {
1423 /*
1424 Here we add a content-length if one is missing; however,
1425 for 'connect' methods, the responses MUST NOT include a
1426 content-length header *if* the response code is 2xx (in
1427 which case we expect there to be no body). Still,
1428 as we don't know the response code here in some cases, we
1429 simply only force adding a content-length header if this
1430 is not a 'connect' or if the response is not empty
1431 (which is kind of more sane, because if some crazy
1432 application did return content with a 2xx status code,
1433 then having a content-length might again be a good idea).
1434
1435 Note that the change from 'SHOULD NOT' to 'MUST NOT' is
1436 a recent development of the HTTP 1.1 specification.
1437 */
1438 content_length_len
1439 = MHD_snprintf_ (content_length_buf,
1440 sizeof (content_length_buf),
1441 MHD_HTTP_HEADER_CONTENT_LENGTH ": "
1442 MHD_UNSIGNED_LONG_LONG_PRINTF "\r\n",
1443 (MHD_UNSIGNED_LONG_LONG) response->total_size);
1444 must_add_content_length = true;
1445 }
1446
1447 /* check for adding keep alive */
1448 if ( (! response_has_keepalive) &&
1449 (! response_has_close) &&
1450 (! must_add_close) &&
1451 (MHD_CONN_MUST_CLOSE != request->keepalive) &&
1452#ifdef UPGRADE_SUPPORT
1453 (NULL == response->upgrade_handler) &&
1454#endif /* UPGRADE_SUPPORT */
1455 (keepalive_possible (request)) )
1456 must_add_keep_alive = true;
1457 break;
1458 case MHD_REQUEST_BODY_SENT:
1459 response_has_keepalive = false;
1460 break;
1461 default:
1462 mhd_assert (0);
1463 return MHD_NO;
1464 }
1449 1465
1450 if (MHD_CONN_MUST_CLOSE != request->keepalive) 1466 if (MHD_CONN_MUST_CLOSE != request->keepalive)
1451 { 1467 {
1452 if ( (must_add_close) || 1468 if ( (must_add_close) ||
1453 (response_has_close) ) 1469 (response_has_close) )
1454 request->keepalive = MHD_CONN_MUST_CLOSE; 1470 request->keepalive = MHD_CONN_MUST_CLOSE;
1455 else if ( (must_add_keep_alive) || 1471 else if ( (must_add_keep_alive) ||
1456 (response_has_keepalive) ) 1472 (response_has_keepalive) )
1457 request->keepalive = MHD_CONN_USE_KEEPALIVE; 1473 request->keepalive = MHD_CONN_USE_KEEPALIVE;
1458 } 1474 }
1459 1475
1460 if (must_add_close) 1476 if (must_add_close)
1461 size += MHD_STATICSTR_LEN_ ("Connection: close\r\n"); 1477 size += MHD_STATICSTR_LEN_ ("Connection: close\r\n");
@@ -1469,91 +1485,91 @@ build_header_response (struct MHD_Request *request)
1469 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) ); 1485 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) );
1470 1486
1471 for (pos = response->first_header; NULL != pos; pos = pos->next) 1487 for (pos = response->first_header; NULL != pos; pos = pos->next)
1472 { 1488 {
1473 /* TODO: add proper support for excluding "Keep-Alive" token. */ 1489 /* TODO: add proper support for excluding "Keep-Alive" token. */
1474 if ( (pos->kind == kind) && 1490 if ( (pos->kind == kind) &&
1475 (! ( (must_add_close) && 1491 (! ( (must_add_close) &&
1476 (response_has_keepalive) && 1492 (response_has_keepalive) &&
1477 (MHD_str_equal_caseless_(pos->header, 1493 (MHD_str_equal_caseless_ (pos->header,
1478 MHD_HTTP_HEADER_CONNECTION)) && 1494 MHD_HTTP_HEADER_CONNECTION)) &&
1479 (MHD_str_equal_caseless_(pos->value, 1495 (MHD_str_equal_caseless_ (pos->value,
1480 "Keep-Alive")) ) ) ) 1496 "Keep-Alive")) ) ) )
1481 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */ 1497 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */
1482 } 1498 }
1483 /* produce data */ 1499 /* produce data */
1484 data = MHD_pool_allocate (connection->pool, 1500 data = MHD_pool_allocate (connection->pool,
1485 size + 1, 1501 size + 1,
1486 MHD_NO); 1502 MHD_NO);
1487 if (NULL == data) 1503 if (NULL == data)
1488 { 1504 {
1489#ifdef HAVE_MESSAGES 1505#ifdef HAVE_MESSAGES
1490 MHD_DLOG (daemon, 1506 MHD_DLOG (daemon,
1491 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE, 1507 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE,
1492 "Not enough memory for write!\n"); 1508 "Not enough memory for write!\n");
1493#endif 1509#endif
1494 return false; 1510 return false;
1495 } 1511 }
1496 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state) 1512 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state)
1497 { 1513 {
1498 memcpy (data, 1514 memcpy (data,
1499 code, 1515 code,
1500 off); 1516 off);
1501 } 1517 }
1502 if (must_add_close) 1518 if (must_add_close)
1503 { 1519 {
1504 /* we must add the 'Connection: close' header */ 1520 /* we must add the 'Connection: close' header */
1505 memcpy (&data[off], 1521 memcpy (&data[off],
1506 "Connection: close\r\n", 1522 "Connection: close\r\n",
1507 MHD_STATICSTR_LEN_ ("Connection: close\r\n")); 1523 MHD_STATICSTR_LEN_ ("Connection: close\r\n"));
1508 off += MHD_STATICSTR_LEN_ ("Connection: close\r\n"); 1524 off += MHD_STATICSTR_LEN_ ("Connection: close\r\n");
1509 } 1525 }
1510 if (must_add_keep_alive) 1526 if (must_add_keep_alive)
1511 { 1527 {
1512 /* we must add the 'Connection: Keep-Alive' header */ 1528 /* we must add the 'Connection: Keep-Alive' header */
1513 memcpy (&data[off], 1529 memcpy (&data[off],
1514 "Connection: Keep-Alive\r\n", 1530 "Connection: Keep-Alive\r\n",
1515 MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n")); 1531 MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n"));
1516 off += MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n"); 1532 off += MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n");
1517 } 1533 }
1518 if (must_add_chunked_encoding) 1534 if (must_add_chunked_encoding)
1519 { 1535 {
1520 /* we must add the 'Transfer-Encoding: chunked' header */ 1536 /* we must add the 'Transfer-Encoding: chunked' header */
1521 memcpy (&data[off], 1537 memcpy (&data[off],
1522 "Transfer-Encoding: chunked\r\n", 1538 "Transfer-Encoding: chunked\r\n",
1523 MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n")); 1539 MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n"));
1524 off += MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n"); 1540 off += MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n");
1525 } 1541 }
1526 if (must_add_content_length) 1542 if (must_add_content_length)
1527 { 1543 {
1528 /* we must add the 'Content-Length' header */ 1544 /* we must add the 'Content-Length' header */
1529 memcpy (&data[off], 1545 memcpy (&data[off],
1530 content_length_buf, 1546 content_length_buf,
1531 content_length_len); 1547 content_length_len);
1532 off += content_length_len; 1548 off += content_length_len;
1533 } 1549 }
1534 for (pos = response->first_header; NULL != pos; pos = pos->next) 1550 for (pos = response->first_header; NULL != pos; pos = pos->next)
1535 { 1551 {
1536 /* TODO: add proper support for excluding "Keep-Alive" token. */ 1552 /* TODO: add proper support for excluding "Keep-Alive" token. */
1537 if ( (pos->kind == kind) && 1553 if ( (pos->kind == kind) &&
1538 (! ( (must_add_close) && 1554 (! ( (must_add_close) &&
1539 (response_has_keepalive) && 1555 (response_has_keepalive) &&
1540 (MHD_str_equal_caseless_(pos->header, 1556 (MHD_str_equal_caseless_ (pos->header,
1541 MHD_HTTP_HEADER_CONNECTION)) && 1557 MHD_HTTP_HEADER_CONNECTION)) &&
1542 (MHD_str_equal_caseless_(pos->value, 1558 (MHD_str_equal_caseless_ (pos->value,
1543 "Keep-Alive")) ) ) ) 1559 "Keep-Alive")) ) ) )
1544 off += MHD_snprintf_ (&data[off], 1560 off += MHD_snprintf_ (&data[off],
1545 size - off, 1561 size - off,
1546 "%s: %s\r\n", 1562 "%s: %s\r\n",
1547 pos->header, 1563 pos->header,
1548 pos->value); 1564 pos->value);
1549 } 1565 }
1550 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state) 1566 if (MHD_REQUEST_FOOTERS_RECEIVED == request->state)
1551 { 1567 {
1552 memcpy (&data[off], 1568 memcpy (&data[off],
1553 date, 1569 date,
1554 datelen); 1570 datelen);
1555 off += datelen; 1571 off += datelen;
1556 } 1572 }
1557 memcpy (&data[off], 1573 memcpy (&data[off],
1558 "\r\n", 1574 "\r\n",
1559 2); 1575 2);
@@ -1584,50 +1600,52 @@ build_header_response (struct MHD_Request *request)
1584 */ 1600 */
1585static void 1601static void
1586transmit_error_response (struct MHD_Request *request, 1602transmit_error_response (struct MHD_Request *request,
1587 enum MHD_StatusCode ec, 1603 enum MHD_StatusCode ec,
1588 enum MHD_HTTP_StatusCode status_code, 1604 enum MHD_HTTP_StatusCode status_code,
1589 const char *message) 1605 const char *message)
1590{ 1606{
1591 struct MHD_Response *response; 1607 struct MHD_Response *response;
1592 1608
1593 if (NULL == request->version_s) 1609 if (NULL == request->version_s)
1594 { 1610 {
1595 /* we were unable to process the full header line, so we don't 1611 /* we were unable to process the full header line, so we don't
1596 really know what version the client speaks; assume 1.0 */ 1612 really know what version the client speaks; assume 1.0 */
1597 request->version_s = MHD_HTTP_VERSION_1_0; 1613 request->version_s = MHD_HTTP_VERSION_1_0;
1598 } 1614 }
1599 request->state = MHD_REQUEST_FOOTERS_RECEIVED; 1615 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
1600 request->connection->read_closed = true; 1616 request->connection->read_closed = true;
1601#ifdef HAVE_MESSAGES 1617#ifdef HAVE_MESSAGES
1602 MHD_DLOG (request->daemon, 1618 MHD_DLOG (request->daemon,
1603 ec, 1619 ec,
1604 _("Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"), 1620 _ (
1621 "Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"),
1605 status_code, 1622 status_code,
1606 message); 1623 message);
1607#endif 1624#endif
1608 if (NULL != request->response) 1625 if (NULL != request->response)
1609 { 1626 {
1610 MHD_response_queue_for_destroy (request->response); 1627 MHD_response_queue_for_destroy (request->response);
1611 request->response = NULL; 1628 request->response = NULL;
1612 } 1629 }
1613 response = MHD_response_from_buffer (status_code, 1630 response = MHD_response_from_buffer (status_code,
1614 strlen (message), 1631 strlen (message),
1615 (void *) message, 1632 (void *) message,
1616 MHD_RESPMEM_PERSISTENT); 1633 MHD_RESPMEM_PERSISTENT);
1617 request->response = response; 1634 request->response = response;
1618 /* Do not reuse this connection. */ 1635 /* Do not reuse this connection. */
1619 request->keepalive = MHD_CONN_MUST_CLOSE; 1636 request->keepalive = MHD_CONN_MUST_CLOSE;
1620 if (! build_header_response (request)) 1637 if (! build_header_response (request))
1621 { 1638 {
1622 /* oops - close! */ 1639 /* oops - close! */
1623 CONNECTION_CLOSE_ERROR (request->connection, 1640 CONNECTION_CLOSE_ERROR (request->connection,
1624 ec, 1641 ec,
1625 _("Closing connection (failed to create response header)\n")); 1642 _ (
1626 } 1643 "Closing connection (failed to create response header)\n"));
1644 }
1627 else 1645 else
1628 { 1646 {
1629 request->state = MHD_REQUEST_HEADERS_SENDING; 1647 request->state = MHD_REQUEST_HEADERS_SENDING;
1630 } 1648 }
1631} 1649}
1632 1650
1633 1651
@@ -1640,7 +1658,8 @@ transmit_error_response (struct MHD_Request *request,
1640static enum MHD_Method 1658static enum MHD_Method
1641method_string_to_enum (const char *method) 1659method_string_to_enum (const char *method)
1642{ 1660{
1643 static const struct { 1661 static const struct
1662 {
1644 const char *key; 1663 const char *key;
1645 enum MHD_Method value; 1664 enum MHD_Method value;
1646 } methods[] = { 1665 } methods[] = {
@@ -1685,10 +1704,10 @@ method_string_to_enum (const char *method)
1685 }; 1704 };
1686 unsigned int i; 1705 unsigned int i;
1687 1706
1688 for (i=0;NULL != methods[i].key;i++) 1707 for (i = 0; NULL != methods[i].key; i++)
1689 if (0 == 1708 if (0 ==
1690 MHD_str_equal_caseless_ (method, 1709 MHD_str_equal_caseless_ (method,
1691 methods[i].key)) 1710 methods[i].key))
1692 return methods[i].value; 1711 return methods[i].value;
1693 return MHD_METHOD_UNKNOWN; 1712 return MHD_METHOD_UNKNOWN;
1694} 1713}
@@ -1706,27 +1725,27 @@ method_string_to_enum (const char *method)
1706 */ 1725 */
1707static bool 1726static bool
1708request_add_header (struct MHD_Request *request, 1727request_add_header (struct MHD_Request *request,
1709 const char *key, 1728 const char *key,
1710 const char *value, 1729 const char *value,
1711 enum MHD_ValueKind kind) 1730 enum MHD_ValueKind kind)
1712{ 1731{
1713 if (MHD_NO == 1732 if (MHD_NO ==
1714 MHD_request_set_value (request, 1733 MHD_request_set_value (request,
1715 kind, 1734 kind,
1716 key, 1735 key,
1717 value)) 1736 value))
1718 { 1737 {
1719#ifdef HAVE_MESSAGES 1738#ifdef HAVE_MESSAGES
1720 MHD_DLOG (request->daemon, 1739 MHD_DLOG (request->daemon,
1721 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE, 1740 MHD_SC_CONNECTION_POOL_MALLOC_FAILURE,
1722 _("Not enough memory in pool to allocate header record!\n")); 1741 _ ("Not enough memory in pool to allocate header record!\n"));
1723#endif 1742#endif
1724 transmit_error_response (request, 1743 transmit_error_response (request,
1725 MHD_SC_CLIENT_HEADER_TOO_BIG, 1744 MHD_SC_CLIENT_HEADER_TOO_BIG,
1726 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, 1745 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
1727 REQUEST_TOO_BIG); 1746 REQUEST_TOO_BIG);
1728 return false; 1747 return false;
1729 } 1748 }
1730 return true; 1749 return true;
1731} 1750}
1732 1751
@@ -1763,76 +1782,76 @@ parse_initial_message_line (struct MHD_Request *request,
1763 /* Skip any spaces. Not required by standard but allow 1782 /* Skip any spaces. Not required by standard but allow
1764 to be more tolerant. */ 1783 to be more tolerant. */
1765 while ( (' ' == uri[0]) && 1784 while ( (' ' == uri[0]) &&
1766 ( (size_t)(uri - line) < line_len) ) 1785 ( (size_t) (uri - line) < line_len) )
1767 uri++; 1786 uri++;
1768 if ((size_t)(uri - line) == line_len) 1787 if ((size_t) (uri - line) == line_len)
1769 { 1788 {
1770 curi = ""; 1789 curi = "";
1771 uri = NULL; 1790 uri = NULL;
1772 request->version_s = ""; 1791 request->version_s = "";
1773 args = NULL; 1792 args = NULL;
1774 url_end = line_len - (line - uri); // EH, this is garbage. FIXME! 1793 url_end = line_len - (line - uri); // EH, this is garbage. FIXME!
1775 } 1794 }
1776 else 1795 else
1796 {
1797 curi = uri;
1798 /* Search from back to accept misformed URI with space */
1799 http_version = line + line_len - 1;
1800 /* Skip any trailing spaces */
1801 while ( (' ' == http_version[0]) &&
1802 (http_version > uri) )
1803 http_version--;
1804 /* Find first space in reverse direction */
1805 while ( (' ' != http_version[0]) &&
1806 (http_version > uri) )
1807 http_version--;
1808 if (http_version > uri)
1809 {
1810 http_version[0] = '\0';
1811 request->version_s = http_version + 1;
1812 args = memchr (uri,
1813 '?',
1814 http_version - uri);
1815 }
1816 else
1777 { 1817 {
1778 curi = uri; 1818 request->version_s = "";
1779 /* Search from back to accept misformed URI with space */ 1819 args = memchr (uri,
1780 http_version = line + line_len - 1; 1820 '?',
1781 /* Skip any trailing spaces */ 1821 line_len - (uri - line));
1782 while ( (' ' == http_version[0]) &&
1783 (http_version > uri) )
1784 http_version--;
1785 /* Find first space in reverse direction */
1786 while ( (' ' != http_version[0]) &&
1787 (http_version > uri) )
1788 http_version--;
1789 if (http_version > uri)
1790 {
1791 http_version[0] = '\0';
1792 request->version_s = http_version + 1;
1793 args = memchr (uri,
1794 '?',
1795 http_version - uri);
1796 }
1797 else
1798 {
1799 request->version_s = "";
1800 args = memchr (uri,
1801 '?',
1802 line_len - (uri - line));
1803 }
1804 url_end = http_version - uri;
1805 } 1822 }
1823 url_end = http_version - uri;
1824 }
1806 if ( (MHD_PSL_STRICT == daemon->protocol_strict_level) && 1825 if ( (MHD_PSL_STRICT == daemon->protocol_strict_level) &&
1807 (NULL != memchr (curi, 1826 (NULL != memchr (curi,
1808 ' ', 1827 ' ',
1809 url_end)) ) 1828 url_end)) )
1810 { 1829 {
1811 /* space exists in URI and we are supposed to be strict, reject */ 1830 /* space exists in URI and we are supposed to be strict, reject */
1812 return MHD_NO; 1831 return MHD_NO;
1813 } 1832 }
1814 if (NULL != daemon->early_uri_logger_cb) 1833 if (NULL != daemon->early_uri_logger_cb)
1815 { 1834 {
1816 request->client_context 1835 request->client_context
1817 = daemon->early_uri_logger_cb (daemon->early_uri_logger_cb_cls, 1836 = daemon->early_uri_logger_cb (daemon->early_uri_logger_cb_cls,
1818 curi, 1837 curi,
1819 request); 1838 request);
1820 } 1839 }
1821 if (NULL != args) 1840 if (NULL != args)
1822 { 1841 {
1823 args[0] = '\0'; 1842 args[0] = '\0';
1824 args++; 1843 args++;
1825 /* note that this call clobbers 'args' */ 1844 /* note that this call clobbers 'args' */
1826 MHD_parse_arguments_ (request, 1845 MHD_parse_arguments_ (request,
1827 MHD_GET_ARGUMENT_KIND, 1846 MHD_GET_ARGUMENT_KIND,
1828 args, 1847 args,
1829 &request_add_header, 1848 &request_add_header,
1830 &unused_num_headers); 1849 &unused_num_headers);
1831 } 1850 }
1832 if (NULL != uri) 1851 if (NULL != uri)
1833 daemon->unescape_cb (daemon->unescape_cb_cls, 1852 daemon->unescape_cb (daemon->unescape_cb_cls,
1834 request, 1853 request,
1835 uri); 1854 uri);
1836 request->url = curi; 1855 request->url = curi;
1837 return true; 1856 return true;
1838} 1857}
@@ -1856,43 +1875,46 @@ process_header_line (struct MHD_Request *request,
1856 1875
1857 /* line should be normal header line, find colon */ 1876 /* line should be normal header line, find colon */
1858 colon = strchr (line, 1877 colon = strchr (line,
1859 ':'); 1878 ':');
1860 if (NULL == colon) 1879 if (NULL == colon)
1880 {
1881 /* error in header line, die hard */
1882 CONNECTION_CLOSE_ERROR (connection,
1883 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1884 _ (
1885 "Received malformed line (no colon). Closing connection.\n"));
1886 return false;
1887 }
1888 if (MHD_PSL_PERMISSIVE != request->daemon->protocol_strict_level)
1889 {
1890 /* check for whitespace before colon, which is not allowed
1891 by RFC 7230 section 3.2.4; we count space ' ' and
1892 tab '\t', but not '\r\n' as those would have ended the line. */
1893 const char *white;
1894
1895 white = strchr (line,
1896 (unsigned char) ' ');
1897 if ( (NULL != white) &&
1898 (white < colon) )
1861 { 1899 {
1862 /* error in header line, die hard */
1863 CONNECTION_CLOSE_ERROR (connection, 1900 CONNECTION_CLOSE_ERROR (connection,
1864 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED, 1901 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1865 _("Received malformed line (no colon). Closing connection.\n")); 1902 _ (
1903 "Whitespace before colon forbidden by RFC 7230. Closing connection.\n"));
1866 return false; 1904 return false;
1867 } 1905 }
1868 if (MHD_PSL_PERMISSIVE != request->daemon->protocol_strict_level) 1906 white = strchr (line,
1907 (unsigned char) '\t');
1908 if ( (NULL != white) &&
1909 (white < colon) )
1869 { 1910 {
1870 /* check for whitespace before colon, which is not allowed 1911 CONNECTION_CLOSE_ERROR (connection,
1871 by RFC 7230 section 3.2.4; we count space ' ' and 1912 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1872 tab '\t', but not '\r\n' as those would have ended the line. */ 1913 _ (
1873 const char *white; 1914 "Tab before colon forbidden by RFC 7230. Closing connection.\n"));
1874 1915 return false;
1875 white = strchr (line,
1876 (unsigned char) ' ');
1877 if ( (NULL != white) &&
1878 (white < colon) )
1879 {
1880 CONNECTION_CLOSE_ERROR (connection,
1881 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1882 _("Whitespace before colon forbidden by RFC 7230. Closing connection.\n"));
1883 return false;
1884 }
1885 white = strchr (line,
1886 (unsigned char) '\t');
1887 if ( (NULL != white) &&
1888 (white < colon) )
1889 {
1890 CONNECTION_CLOSE_ERROR (connection,
1891 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1892 _("Tab before colon forbidden by RFC 7230. Closing connection.\n"));
1893 return false;
1894 }
1895 } 1916 }
1917 }
1896 /* zero-terminate header */ 1918 /* zero-terminate header */
1897 colon[0] = '\0'; 1919 colon[0] = '\0';
1898 colon++; /* advance to value */ 1920 colon++; /* advance to value */
@@ -1935,69 +1957,69 @@ process_broken_line (struct MHD_Request *request,
1935 last = request->last; 1957 last = request->last;
1936 if ( (' ' == line[0]) || 1958 if ( (' ' == line[0]) ||
1937 ('\t' == line[0]) ) 1959 ('\t' == line[0]) )
1938 { 1960 {
1939 /* value was continued on the next line, see 1961 /* value was continued on the next line, see
1940 http://www.jmarshall.com/easy/http/ */ 1962 http://www.jmarshall.com/easy/http/ */
1941 last_len = strlen (last); 1963 last_len = strlen (last);
1942 /* skip whitespace at start of 2nd line */ 1964 /* skip whitespace at start of 2nd line */
1943 tmp = line; 1965 tmp = line;
1944 while ( (' ' == tmp[0]) || 1966 while ( (' ' == tmp[0]) ||
1945 ('\t' == tmp[0]) ) 1967 ('\t' == tmp[0]) )
1946 tmp++; 1968 tmp++;
1947 tmp_len = strlen (tmp); 1969 tmp_len = strlen (tmp);
1948 /* FIXME: we might be able to do this better (faster!), as most 1970 /* FIXME: we might be able to do this better (faster!), as most
1949 likely 'last' and 'line' should already be adjacent in 1971 likely 'last' and 'line' should already be adjacent in
1950 memory; however, doing this right gets tricky if we have a 1972 memory; however, doing this right gets tricky if we have a
1951 value continued over multiple lines (in which case we need to 1973 value continued over multiple lines (in which case we need to
1952 record how often we have done this so we can check for 1974 record how often we have done this so we can check for
1953 adjacency); also, in the case where these are not adjacent 1975 adjacency); also, in the case where these are not adjacent
1954 (not sure how it can happen!), we would want to allocate from 1976 (not sure how it can happen!), we would want to allocate from
1955 the end of the pool, so as to not destroy the read-buffer's 1977 the end of the pool, so as to not destroy the read-buffer's
1956 ability to grow nicely. */ 1978 ability to grow nicely. */
1957 last = MHD_pool_reallocate (connection->pool, 1979 last = MHD_pool_reallocate (connection->pool,
1958 last, 1980 last,
1959 last_len + 1, 1981 last_len + 1,
1960 last_len + tmp_len + 1); 1982 last_len + tmp_len + 1);
1961 if (NULL == last) 1983 if (NULL == last)
1962 {
1963 transmit_error_response (request,
1964 MHD_SC_CLIENT_HEADER_TOO_BIG,
1965 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
1966 REQUEST_TOO_BIG);
1967 return MHD_NO;
1968 }
1969 memcpy (&last[last_len],
1970 tmp,
1971 tmp_len + 1);
1972 request->last = last;
1973 return MHD_YES; /* possibly more than 2 lines... */
1974 }
1975 mhd_assert ( (NULL != last) &&
1976 (NULL != request->colon) );
1977 if (! request_add_header (request,
1978 last,
1979 request->colon,
1980 kind))
1981 { 1984 {
1982 transmit_error_response (request, 1985 transmit_error_response (request,
1983 MHD_SC_CLIENT_HEADER_TOO_BIG, 1986 MHD_SC_CLIENT_HEADER_TOO_BIG,
1984 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, 1987 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
1985 REQUEST_TOO_BIG); 1988 REQUEST_TOO_BIG);
1986 return false; 1989 return MHD_NO;
1987 } 1990 }
1991 memcpy (&last[last_len],
1992 tmp,
1993 tmp_len + 1);
1994 request->last = last;
1995 return MHD_YES; /* possibly more than 2 lines... */
1996 }
1997 mhd_assert ( (NULL != last) &&
1998 (NULL != request->colon) );
1999 if (! request_add_header (request,
2000 last,
2001 request->colon,
2002 kind))
2003 {
2004 transmit_error_response (request,
2005 MHD_SC_CLIENT_HEADER_TOO_BIG,
2006 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
2007 REQUEST_TOO_BIG);
2008 return false;
2009 }
1988 /* we still have the current line to deal with... */ 2010 /* we still have the current line to deal with... */
1989 if ('\0' != line[0]) 2011 if ('\0' != line[0])
2012 {
2013 if (! process_header_line (request,
2014 line))
1990 { 2015 {
1991 if (! process_header_line (request, 2016 transmit_error_response (request,
1992 line)) 2017 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
1993 { 2018 MHD_HTTP_BAD_REQUEST,
1994 transmit_error_response (request, 2019 REQUEST_MALFORMED);
1995 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED, 2020 return false;
1996 MHD_HTTP_BAD_REQUEST,
1997 REQUEST_MALFORMED);
1998 return false;
1999 }
2000 } 2021 }
2022 }
2001 return true; 2023 return true;
2002} 2024}
2003 2025
@@ -2032,22 +2054,22 @@ get_next_header_line (struct MHD_Request *request,
2032 pos++; 2054 pos++;
2033 if ( (pos == request->read_buffer_offset - 1) && 2055 if ( (pos == request->read_buffer_offset - 1) &&
2034 ('\n' != rbuf[pos]) ) 2056 ('\n' != rbuf[pos]) )
2057 {
2058 /* not found, consider growing... */
2059 if ( (request->read_buffer_offset == request->read_buffer_size) &&
2060 (! try_grow_read_buffer (request)) )
2035 { 2061 {
2036 /* not found, consider growing... */ 2062 transmit_error_response (request,
2037 if ( (request->read_buffer_offset == request->read_buffer_size) && 2063 MHD_SC_CLIENT_HEADER_TOO_BIG,
2038 (! try_grow_read_buffer (request)) ) 2064 (NULL != request->url)
2039 { 2065 ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
2040 transmit_error_response (request, 2066 : MHD_HTTP_URI_TOO_LONG,
2041 MHD_SC_CLIENT_HEADER_TOO_BIG, 2067 REQUEST_TOO_BIG);
2042 (NULL != request->url)
2043 ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
2044 : MHD_HTTP_URI_TOO_LONG,
2045 REQUEST_TOO_BIG);
2046 }
2047 if (line_len)
2048 *line_len = 0;
2049 return NULL;
2050 } 2068 }
2069 if (line_len)
2070 *line_len = 0;
2071 return NULL;
2072 }
2051 2073
2052 if (line_len) 2074 if (line_len)
2053 *line_len = pos; 2075 *line_len = pos;
@@ -2083,7 +2105,7 @@ get_next_header_line (struct MHD_Request *request,
2083 * @return true if force push is possible, false otherwise 2105 * @return true if force push is possible, false otherwise
2084 */ 2106 */
2085static bool 2107static bool
2086socket_flush_possible(struct MHD_Connection *connection) 2108socket_flush_possible (struct MHD_Connection *connection)
2087{ 2109{
2088 (void) connection; /* Mute compiler warning. */ 2110 (void) connection; /* Mute compiler warning. */
2089#if defined(TCP_CORK) || defined(TCP_PUSH) 2111#if defined(TCP_CORK) || defined(TCP_PUSH)
@@ -2105,21 +2127,21 @@ static bool
2105socket_start_extra_buffering (struct MHD_Connection *connection) 2127socket_start_extra_buffering (struct MHD_Connection *connection)
2106{ 2128{
2107 bool res = false; 2129 bool res = false;
2108 (void)connection; /* Mute compiler warning. */ 2130 (void) connection; /* Mute compiler warning. */
2109#if defined(TCP_CORK) || defined(TCP_NOPUSH) 2131#if defined(TCP_CORK) || defined(TCP_NOPUSH)
2110 const MHD_SCKT_OPT_BOOL_ on_val = 1; 2132 const MHD_SCKT_OPT_BOOL_ on_val = 1;
2111#if defined(TCP_NODELAY) 2133#if defined(TCP_NODELAY)
2112 const MHD_SCKT_OPT_BOOL_ off_val = 0; 2134 const MHD_SCKT_OPT_BOOL_ off_val = 0;
2113#endif /* TCP_NODELAY */ 2135#endif /* TCP_NODELAY */
2114 mhd_assert(NULL != connection); 2136 mhd_assert (NULL != connection);
2115#if defined(TCP_NOPUSH) && !defined(TCP_CORK) 2137#if defined(TCP_NOPUSH) && ! defined(TCP_CORK)
2116 /* Buffer data before sending */ 2138 /* Buffer data before sending */
2117 res = (0 == setsockopt (connection->socket_fd, 2139 res = (0 == setsockopt (connection->socket_fd,
2118 IPPROTO_TCP, 2140 IPPROTO_TCP,
2119 TCP_NOPUSH, 2141 TCP_NOPUSH,
2120 (const void *) &on_val, 2142 (const void *) &on_val,
2121 sizeof (on_val))) 2143 sizeof (on_val)))
2122 ? true : false; 2144 ? true : false;
2123#if defined(TCP_NODELAY) 2145#if defined(TCP_NODELAY)
2124 /* Enable Nagle's algorithm */ 2146 /* Enable Nagle's algorithm */
2125 /* TCP_NODELAY may interfere with TCP_NOPUSH */ 2147 /* TCP_NODELAY may interfere with TCP_NOPUSH */
@@ -2128,7 +2150,7 @@ socket_start_extra_buffering (struct MHD_Connection *connection)
2128 TCP_NODELAY, 2150 TCP_NODELAY,
2129 (const void *) &off_val, 2151 (const void *) &off_val,
2130 sizeof (off_val))) 2152 sizeof (off_val)))
2131 ? true : false; 2153 ? true : false;
2132#endif /* TCP_NODELAY */ 2154#endif /* TCP_NODELAY */
2133#else /* TCP_CORK */ 2155#else /* TCP_CORK */
2134#if defined(TCP_NODELAY) 2156#if defined(TCP_NODELAY)
@@ -2147,7 +2169,7 @@ socket_start_extra_buffering (struct MHD_Connection *connection)
2147 TCP_CORK, 2169 TCP_CORK,
2148 (const void *) &on_val, 2170 (const void *) &on_val,
2149 sizeof (on_val))) 2171 sizeof (on_val)))
2150 ? true : false; 2172 ? true : false;
2151#endif /* TCP_CORK */ 2173#endif /* TCP_CORK */
2152#endif /* TCP_CORK || TCP_NOPUSH */ 2174#endif /* TCP_CORK || TCP_NOPUSH */
2153 return res; 2175 return res;
@@ -2170,8 +2192,8 @@ socket_start_no_buffering (struct MHD_Connection *connection)
2170 const MHD_SCKT_OPT_BOOL_ off_val = 0; 2192 const MHD_SCKT_OPT_BOOL_ off_val = 0;
2171#endif /* TCP_CORK || TCP_NOPUSH */ 2193#endif /* TCP_CORK || TCP_NOPUSH */
2172 2194
2173 (void)connection; /* Mute compiler warning. */ 2195 (void) connection; /* Mute compiler warning. */
2174 mhd_assert(NULL != connection); 2196 mhd_assert (NULL != connection);
2175#if defined(TCP_CORK) 2197#if defined(TCP_CORK)
2176 /* Allow partial packets */ 2198 /* Allow partial packets */
2177 res &= (0 == setsockopt (connection->socket_fd, 2199 res &= (0 == setsockopt (connection->socket_fd,
@@ -2179,7 +2201,7 @@ socket_start_no_buffering (struct MHD_Connection *connection)
2179 TCP_CORK, 2201 TCP_CORK,
2180 (const void *) &off_val, 2202 (const void *) &off_val,
2181 sizeof (off_val))) 2203 sizeof (off_val)))
2182 ? true : false; 2204 ? true : false;
2183#endif /* TCP_CORK */ 2205#endif /* TCP_CORK */
2184#if defined(TCP_NODELAY) 2206#if defined(TCP_NODELAY)
2185 /* Disable Nagle's algorithm for sending packets without delay */ 2207 /* Disable Nagle's algorithm for sending packets without delay */
@@ -2188,16 +2210,16 @@ socket_start_no_buffering (struct MHD_Connection *connection)
2188 TCP_NODELAY, 2210 TCP_NODELAY,
2189 (const void *) &on_val, 2211 (const void *) &on_val,
2190 sizeof (on_val))) 2212 sizeof (on_val)))
2191 ? true : false; 2213 ? true : false;
2192#endif /* TCP_NODELAY */ 2214#endif /* TCP_NODELAY */
2193#if defined(TCP_NOPUSH) && !defined(TCP_CORK) 2215#if defined(TCP_NOPUSH) && ! defined(TCP_CORK)
2194 /* Disable extra buffering */ 2216 /* Disable extra buffering */
2195 res &= (0 == setsockopt (connection->socket_fd, 2217 res &= (0 == setsockopt (connection->socket_fd,
2196 IPPROTO_TCP, 2218 IPPROTO_TCP,
2197 TCP_NOPUSH, 2219 TCP_NOPUSH,
2198 (const void *) &off_val, 2220 (const void *) &off_val,
2199 sizeof (off_val))) 2221 sizeof (off_val)))
2200 ? true : false; 2222 ? true : false;
2201#endif /* TCP_NOPUSH && !TCP_CORK */ 2223#endif /* TCP_NOPUSH && !TCP_CORK */
2202 return res; 2224 return res;
2203#else /* !TCP_NODELAY */ 2225#else /* !TCP_NODELAY */
@@ -2217,21 +2239,21 @@ static bool
2217socket_start_no_buffering_flush (struct MHD_Connection *connection) 2239socket_start_no_buffering_flush (struct MHD_Connection *connection)
2218{ 2240{
2219 bool res = true; 2241 bool res = true;
2220#if defined(TCP_NOPUSH) && !defined(TCP_CORK) 2242#if defined(TCP_NOPUSH) && ! defined(TCP_CORK)
2221 const int dummy = 0; 2243 const int dummy = 0;
2222#endif /* !TCP_CORK */ 2244#endif /* !TCP_CORK */
2223 2245
2224 if (NULL == connection) 2246 if (NULL == connection)
2225 return false; /* FIXME: use MHD_NONNULL? */ 2247 return false; /* FIXME: use MHD_NONNULL? */
2226 res = socket_start_no_buffering (connection); 2248 res = socket_start_no_buffering (connection);
2227#if defined(TCP_NOPUSH) && !defined(TCP_CORK) 2249#if defined(TCP_NOPUSH) && ! defined(TCP_CORK)
2228 /* Force flush data with zero send otherwise Darwin and some BSD systems 2250 /* Force flush data with zero send otherwise Darwin and some BSD systems
2229 will add 5 seconds delay. Not required with TCP_CORK as switching off 2251 will add 5 seconds delay. Not required with TCP_CORK as switching off
2230 TCP_CORK always flushes socket buffer. */ 2252 TCP_CORK always flushes socket buffer. */
2231 res &= (0 <= MHD_send_ (connection->socket_fd, 2253 res &= (0 <= MHD_send_ (connection->socket_fd,
2232 &dummy, 2254 &dummy,
2233 0)) 2255 0))
2234 ? true : false; 2256 ? true : false;
2235#endif /* TCP_NOPUSH && !TCP_CORK*/ 2257#endif /* TCP_NOPUSH && !TCP_CORK*/
2236 return res; 2258 return res;
2237} 2259}
@@ -2254,7 +2276,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
2254 socklen_t param_size = sizeof (cork_val); 2276 socklen_t param_size = sizeof (cork_val);
2255#endif /* TCP_CORK */ 2277#endif /* TCP_CORK */
2256 2278
2257 mhd_assert(NULL != connection); 2279 mhd_assert (NULL != connection);
2258#if defined(TCP_CORK) 2280#if defined(TCP_CORK)
2259 /* Allow partial packets */ 2281 /* Allow partial packets */
2260 /* Disabling TCP_CORK will flush partial packet even if TCP_CORK wasn't enabled before 2282 /* Disabling TCP_CORK will flush partial packet even if TCP_CORK wasn't enabled before
@@ -2262,7 +2284,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
2262 if ( (0 != getsockopt (connection->socket_fd, 2284 if ( (0 != getsockopt (connection->socket_fd,
2263 IPPROTO_TCP, 2285 IPPROTO_TCP,
2264 TCP_CORK, 2286 TCP_CORK,
2265 (void*)&cork_val, 2287 (void*) &cork_val,
2266 &param_size)) || 2288 &param_size)) ||
2267 (0 != cork_val)) 2289 (0 != cork_val))
2268 res &= (0 == setsockopt (connection->socket_fd, 2290 res &= (0 == setsockopt (connection->socket_fd,
@@ -2270,7 +2292,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
2270 TCP_CORK, 2292 TCP_CORK,
2271 (const void *) &off_val, 2293 (const void *) &off_val,
2272 sizeof (off_val))) 2294 sizeof (off_val)))
2273 ? true : false; 2295 ? true : false;
2274#elif defined(TCP_NOPUSH) 2296#elif defined(TCP_NOPUSH)
2275 /* Disable extra buffering */ 2297 /* Disable extra buffering */
2276 /* No need to check current value as disabling TCP_NOPUSH will not flush partial 2298 /* No need to check current value as disabling TCP_NOPUSH will not flush partial
@@ -2280,7 +2302,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
2280 TCP_NOPUSH, 2302 TCP_NOPUSH,
2281 (const void *) &off_val, 2303 (const void *) &off_val,
2282 sizeof (off_val))) 2304 sizeof (off_val)))
2283 ? true : false; 2305 ? true : false;
2284#endif /* TCP_NOPUSH && !TCP_CORK */ 2306#endif /* TCP_NOPUSH && !TCP_CORK */
2285 /* Enable Nagle's algorithm for normal buffering */ 2307 /* Enable Nagle's algorithm for normal buffering */
2286 res &= (0 == setsockopt (connection->socket_fd, 2308 res &= (0 == setsockopt (connection->socket_fd,
@@ -2288,7 +2310,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
2288 TCP_NODELAY, 2310 TCP_NODELAY,
2289 (const void *) &off_val, 2311 (const void *) &off_val,
2290 sizeof (off_val))) 2312 sizeof (off_val)))
2291 ? true : false; 2313 ? true : false;
2292 return res; 2314 return res;
2293#else /* !TCP_NODELAY */ 2315#else /* !TCP_NODELAY */
2294 return false; 2316 return false;
@@ -2309,16 +2331,17 @@ need_100_continue (struct MHD_Request *request)
2309 const char *expect; 2331 const char *expect;
2310 2332
2311 return ( (NULL == request->response) && 2333 return ( (NULL == request->response) &&
2312 (NULL != request->version_s) && 2334 (NULL != request->version_s) &&
2313 (MHD_str_equal_caseless_(request->version_s, 2335 (MHD_str_equal_caseless_ (request->version_s,
2314 MHD_HTTP_VERSION_1_1)) && 2336 MHD_HTTP_VERSION_1_1)) &&
2315 (NULL != (expect = MHD_request_lookup_value (request, 2337 (NULL != (expect = MHD_request_lookup_value (request,
2316 MHD_HEADER_KIND, 2338 MHD_HEADER_KIND,
2317 MHD_HTTP_HEADER_EXPECT))) && 2339 MHD_HTTP_HEADER_EXPECT)))
2318 (MHD_str_equal_caseless_(expect, 2340 &&
2319 "100-continue")) && 2341 (MHD_str_equal_caseless_ (expect,
2320 (request->continue_message_write_offset < 2342 "100-continue")) &&
2321 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) ); 2343 (request->continue_message_write_offset <
2344 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) );
2322} 2345}
2323 2346
2324 2347
@@ -2342,94 +2365,94 @@ parse_cookie_header (struct MHD_Request *request)
2342 int quotes; 2365 int quotes;
2343 2366
2344 hdr = MHD_request_lookup_value (request, 2367 hdr = MHD_request_lookup_value (request,
2345 MHD_HEADER_KIND, 2368 MHD_HEADER_KIND,
2346 MHD_HTTP_HEADER_COOKIE); 2369 MHD_HTTP_HEADER_COOKIE);
2347 if (NULL == hdr) 2370 if (NULL == hdr)
2348 return true; 2371 return true;
2349 cpy = MHD_pool_allocate (request->connection->pool, 2372 cpy = MHD_pool_allocate (request->connection->pool,
2350 strlen (hdr) + 1, 2373 strlen (hdr) + 1,
2351 MHD_YES); 2374 MHD_YES);
2352 if (NULL == cpy) 2375 if (NULL == cpy)
2353 { 2376 {
2354#ifdef HAVE_MESSAGES 2377#ifdef HAVE_MESSAGES
2355 MHD_DLOG (request->daemon, 2378 MHD_DLOG (request->daemon,
2356 MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE, 2379 MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE,
2357 _("Not enough memory in pool to parse cookies!\n")); 2380 _ ("Not enough memory in pool to parse cookies!\n"));
2358#endif 2381#endif
2359 transmit_error_response (request, 2382 transmit_error_response (request,
2360 MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE, 2383 MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE,
2361 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, 2384 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
2362 REQUEST_TOO_BIG); 2385 REQUEST_TOO_BIG);
2363 return false; 2386 return false;
2364 } 2387 }
2365 memcpy (cpy, 2388 memcpy (cpy,
2366 hdr, 2389 hdr,
2367 strlen (hdr) + 1); 2390 strlen (hdr) + 1);
2368 pos = cpy; 2391 pos = cpy;
2369 while (NULL != pos) 2392 while (NULL != pos)
2370 { 2393 {
2371 while (' ' == *pos) 2394 while (' ' == *pos)
2372 pos++; /* skip spaces */ 2395 pos++; /* skip spaces */
2373 2396
2374 sce = pos; 2397 sce = pos;
2375 while ( ((*sce) != '\0') && 2398 while ( ((*sce) != '\0') &&
2376 ((*sce) != ',') && 2399 ((*sce) != ',') &&
2377 ((*sce) != ';') && 2400 ((*sce) != ';') &&
2378 ((*sce) != '=') ) 2401 ((*sce) != '=') )
2379 sce++; 2402 sce++;
2380 /* remove tailing whitespace (if any) from key */ 2403 /* remove tailing whitespace (if any) from key */
2381 ekill = sce - 1; 2404 ekill = sce - 1;
2382 while ( (*ekill == ' ') && 2405 while ( (*ekill == ' ') &&
2383 (ekill >= pos) ) 2406 (ekill >= pos) )
2384 *(ekill--) = '\0'; 2407 *(ekill--) = '\0';
2385 old = *sce; 2408 old = *sce;
2386 *sce = '\0'; 2409 *sce = '\0';
2387 if (old != '=') 2410 if (old != '=')
2388 { 2411 {
2389 /* value part omitted, use empty string... */ 2412 /* value part omitted, use empty string... */
2390 if (! request_add_header (request,
2391 pos,
2392 "",
2393 MHD_COOKIE_KIND))
2394 return false;
2395 if (old == '\0')
2396 break;
2397 pos = sce + 1;
2398 continue;
2399 }
2400 equals = sce + 1;
2401 quotes = 0;
2402 semicolon = equals;
2403 while ( ('\0' != semicolon[0]) &&
2404 ( (0 != quotes) ||
2405 ( (';' != semicolon[0]) &&
2406 (',' != semicolon[0]) ) ) )
2407 {
2408 if ('"' == semicolon[0])
2409 quotes = (quotes + 1) & 1;
2410 semicolon++;
2411 }
2412 if ('\0' == semicolon[0])
2413 semicolon = NULL;
2414 if (NULL != semicolon)
2415 {
2416 semicolon[0] = '\0';
2417 semicolon++;
2418 }
2419 /* remove quotes */
2420 if ( ('"' == equals[0]) &&
2421 ('"' == equals[strlen (equals) - 1]) )
2422 {
2423 equals[strlen (equals) - 1] = '\0';
2424 equals++;
2425 }
2426 if (! request_add_header (request, 2413 if (! request_add_header (request,
2427 pos, 2414 pos,
2428 equals, 2415 "",
2429 MHD_COOKIE_KIND)) 2416 MHD_COOKIE_KIND))
2430 return false; 2417 return false;
2431 pos = semicolon; 2418 if (old == '\0')
2432 } 2419 break;
2420 pos = sce + 1;
2421 continue;
2422 }
2423 equals = sce + 1;
2424 quotes = 0;
2425 semicolon = equals;
2426 while ( ('\0' != semicolon[0]) &&
2427 ( (0 != quotes) ||
2428 ( (';' != semicolon[0]) &&
2429 (',' != semicolon[0]) ) ) )
2430 {
2431 if ('"' == semicolon[0])
2432 quotes = (quotes + 1) & 1;
2433 semicolon++;
2434 }
2435 if ('\0' == semicolon[0])
2436 semicolon = NULL;
2437 if (NULL != semicolon)
2438 {
2439 semicolon[0] = '\0';
2440 semicolon++;
2441 }
2442 /* remove quotes */
2443 if ( ('"' == equals[0]) &&
2444 ('"' == equals[strlen (equals) - 1]) )
2445 {
2446 equals[strlen (equals) - 1] = '\0';
2447 equals++;
2448 }
2449 if (! request_add_header (request,
2450 pos,
2451 equals,
2452 MHD_COOKIE_KIND))
2453 return false;
2454 pos = semicolon;
2455 }
2433 return true; 2456 return true;
2434} 2457}
2435 2458
@@ -2454,64 +2477,64 @@ parse_request_headers (struct MHD_Request *request)
2454 parse_cookie_header (request); /* FIXME: return value ignored! */ 2477 parse_cookie_header (request); /* FIXME: return value ignored! */
2455 if ( (MHD_PSL_STRICT == daemon->protocol_strict_level) && 2478 if ( (MHD_PSL_STRICT == daemon->protocol_strict_level) &&
2456 (NULL != request->version_s) && 2479 (NULL != request->version_s) &&
2457 (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1, 2480 (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_1,
2458 request->version_s)) && 2481 request->version_s)) &&
2459 (NULL == 2482 (NULL ==
2460 MHD_request_lookup_value (request, 2483 MHD_request_lookup_value (request,
2461 MHD_HEADER_KIND, 2484 MHD_HEADER_KIND,
2462 MHD_HTTP_HEADER_HOST)) ) 2485 MHD_HTTP_HEADER_HOST)) )
2463 { 2486 {
2464 /* die, http 1.1 request without host and we are pedantic */ 2487 /* die, http 1.1 request without host and we are pedantic */
2465 request->state = MHD_REQUEST_FOOTERS_RECEIVED; 2488 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
2466 connection->read_closed = true; 2489 connection->read_closed = true;
2467#ifdef HAVE_MESSAGES 2490#ifdef HAVE_MESSAGES
2468 MHD_DLOG (daemon, 2491 MHD_DLOG (daemon,
2469 MHD_SC_HOST_HEADER_MISSING, 2492 MHD_SC_HOST_HEADER_MISSING,
2470 _("Received HTTP 1.1 request without `Host' header.\n")); 2493 _ ("Received HTTP 1.1 request without `Host' header.\n"));
2471#endif 2494#endif
2472 mhd_assert (NULL == request->response); 2495 mhd_assert (NULL == request->response);
2473 response = 2496 response =
2474 MHD_response_from_buffer (MHD_HTTP_BAD_REQUEST, 2497 MHD_response_from_buffer (MHD_HTTP_BAD_REQUEST,
2475 MHD_STATICSTR_LEN_ (REQUEST_LACKS_HOST), 2498 MHD_STATICSTR_LEN_ (REQUEST_LACKS_HOST),
2476 REQUEST_LACKS_HOST, 2499 REQUEST_LACKS_HOST,
2477 MHD_RESPMEM_PERSISTENT); 2500 MHD_RESPMEM_PERSISTENT);
2478 request->response = response; 2501 request->response = response;
2479 // FIXME: state machine advance? 2502 // FIXME: state machine advance?
2480 return; 2503 return;
2481 } 2504 }
2482 2505
2483 request->remaining_upload_size = 0; 2506 request->remaining_upload_size = 0;
2484 enc = MHD_request_lookup_value (request, 2507 enc = MHD_request_lookup_value (request,
2485 MHD_HEADER_KIND, 2508 MHD_HEADER_KIND,
2486 MHD_HTTP_HEADER_TRANSFER_ENCODING); 2509 MHD_HTTP_HEADER_TRANSFER_ENCODING);
2487 if (NULL != enc) 2510 if (NULL != enc)
2488 { 2511 {
2489 request->remaining_upload_size = MHD_SIZE_UNKNOWN; 2512 request->remaining_upload_size = MHD_SIZE_UNKNOWN;
2490 if (MHD_str_equal_caseless_ (enc, 2513 if (MHD_str_equal_caseless_ (enc,
2491 "chunked")) 2514 "chunked"))
2492 request->have_chunked_upload = true; 2515 request->have_chunked_upload = true;
2493 return; 2516 return;
2494 } 2517 }
2495 clen = MHD_request_lookup_value (request, 2518 clen = MHD_request_lookup_value (request,
2496 MHD_HEADER_KIND, 2519 MHD_HEADER_KIND,
2497 MHD_HTTP_HEADER_CONTENT_LENGTH); 2520 MHD_HTTP_HEADER_CONTENT_LENGTH);
2498 if (NULL == clen) 2521 if (NULL == clen)
2499 return; 2522 return;
2500 end = clen + MHD_str_to_uint64_ (clen, 2523 end = clen + MHD_str_to_uint64_ (clen,
2501 &request->remaining_upload_size); 2524 &request->remaining_upload_size);
2502 if ( (clen == end) || 2525 if ( (clen == end) ||
2503 ('\0' != *end) ) 2526 ('\0' != *end) )
2504 { 2527 {
2505 request->remaining_upload_size = 0; 2528 request->remaining_upload_size = 0;
2506#ifdef HAVE_MESSAGES 2529#ifdef HAVE_MESSAGES
2507 MHD_DLOG (request->daemon, 2530 MHD_DLOG (request->daemon,
2508 MHD_SC_CONTENT_LENGTH_MALFORMED, 2531 MHD_SC_CONTENT_LENGTH_MALFORMED,
2509 "Failed to parse `Content-Length' header. Closing connection.\n"); 2532 "Failed to parse `Content-Length' header. Closing connection.\n");
2510#endif 2533#endif
2511 CONNECTION_CLOSE_ERROR (connection, 2534 CONNECTION_CLOSE_ERROR (connection,
2512 MHD_SC_CONTENT_LENGTH_MALFORMED, 2535 MHD_SC_CONTENT_LENGTH_MALFORMED,
2513 NULL); 2536 NULL);
2514 } 2537 }
2515} 2538}
2516 2539
2517 2540
@@ -2531,19 +2554,20 @@ call_request_handler (struct MHD_Request *request)
2531 if (NULL != request->response) 2554 if (NULL != request->response)
2532 return; /* already queued a response */ 2555 return; /* already queued a response */
2533 if (NULL == (action = 2556 if (NULL == (action =
2534 daemon->rc (daemon->rc_cls, 2557 daemon->rc (daemon->rc_cls,
2535 request, 2558 request,
2536 request->url, 2559 request->url,
2537 request->method))) 2560 request->method)))
2538 { 2561 {
2539 /* serious internal error, close connection */ 2562 /* serious internal error, close connection */
2540 CONNECTION_CLOSE_ERROR (connection, 2563 CONNECTION_CLOSE_ERROR (connection,
2541 MHD_SC_APPLICATION_CALLBACK_FAILURE_CLOSED, 2564 MHD_SC_APPLICATION_CALLBACK_FAILURE_CLOSED,
2542 _("Application reported internal error, closing connection.\n")); 2565 _ (
2543 return; 2566 "Application reported internal error, closing connection.\n"));
2544 } 2567 return;
2568 }
2545 action->action (action->action_cls, 2569 action->action (action->action_cls,
2546 request); 2570 request);
2547} 2571}
2548 2572
2549 2573
@@ -2568,208 +2592,212 @@ process_request_body (struct MHD_Request *request)
2568 buffer_head = request->read_buffer; 2592 buffer_head = request->read_buffer;
2569 available = request->read_buffer_offset; 2593 available = request->read_buffer_offset;
2570 do 2594 do
2571 { 2595 {
2572 size_t to_be_processed; 2596 size_t to_be_processed;
2573 size_t left_unprocessed; 2597 size_t left_unprocessed;
2574 size_t processed_size; 2598 size_t processed_size;
2575 2599
2576 instant_retry = false; 2600 instant_retry = false;
2577 if ( (request->have_chunked_upload) && 2601 if ( (request->have_chunked_upload) &&
2578 (MHD_SIZE_UNKNOWN == request->remaining_upload_size) ) 2602 (MHD_SIZE_UNKNOWN == request->remaining_upload_size) )
2603 {
2604 if ( (request->current_chunk_offset == request->current_chunk_size) &&
2605 (0LLU != request->current_chunk_offset) &&
2606 (available >= 2) )
2607 {
2608 size_t i;
2609
2610 /* skip new line at the *end* of a chunk */
2611 i = 0;
2612 if ( ('\r' == buffer_head[i]) ||
2613 ('\n' == buffer_head[i]) )
2614 i++; /* skip 1st part of line feed */
2615 if ( ('\r' == buffer_head[i]) ||
2616 ('\n' == buffer_head[i]) )
2617 i++; /* skip 2nd part of line feed */
2618 if (0 == i)
2579 { 2619 {
2580 if ( (request->current_chunk_offset == request->current_chunk_size) && 2620 /* malformed encoding */
2581 (0LLU != request->current_chunk_offset) && 2621 CONNECTION_CLOSE_ERROR (connection,
2582 (available >= 2) ) 2622 MHD_SC_CHUNKED_ENCODING_MALFORMED,
2583 { 2623 _ (
2584 size_t i; 2624 "Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2585 2625 return;
2586 /* skip new line at the *end* of a chunk */
2587 i = 0;
2588 if ( ('\r' == buffer_head[i]) ||
2589 ('\n' == buffer_head[i]) )
2590 i++; /* skip 1st part of line feed */
2591 if ( ('\r' == buffer_head[i]) ||
2592 ('\n' == buffer_head[i]) )
2593 i++; /* skip 2nd part of line feed */
2594 if (0 == i)
2595 {
2596 /* malformed encoding */
2597 CONNECTION_CLOSE_ERROR (connection,
2598 MHD_SC_CHUNKED_ENCODING_MALFORMED,
2599 _("Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2600 return;
2601 }
2602 available -= i;
2603 buffer_head += i;
2604 request->current_chunk_offset = 0;
2605 request->current_chunk_size = 0;
2606 }
2607 if (request->current_chunk_offset <
2608 request->current_chunk_size)
2609 {
2610 uint64_t cur_chunk_left;
2611
2612 /* we are in the middle of a chunk, give
2613 as much as possible to the client (without
2614 crossing chunk boundaries) */
2615 cur_chunk_left
2616 = request->current_chunk_size - request->current_chunk_offset;
2617 if (cur_chunk_left > available)
2618 {
2619 to_be_processed = available;
2620 }
2621 else
2622 { /* cur_chunk_left <= (size_t)available */
2623 to_be_processed = (size_t)cur_chunk_left;
2624 if (available > to_be_processed)
2625 instant_retry = true;
2626 }
2627 }
2628 else
2629 {
2630 size_t i;
2631 size_t end_size;
2632 bool malformed;
2633
2634 /* we need to read chunk boundaries */
2635 i = 0;
2636 while (i < available)
2637 {
2638 if ( ('\r' == buffer_head[i]) ||
2639 ('\n' == buffer_head[i]) ||
2640 (';' == buffer_head[i]) )
2641 break;
2642 i++;
2643 if (i >= 16)
2644 break;
2645 }
2646 end_size = i;
2647 /* find beginning of CRLF (skip over chunk extensions) */
2648 if (';' == buffer_head[i])
2649 {
2650 while (i < available)
2651 {
2652 if ( ('\r' == buffer_head[i]) ||
2653 ('\n' == buffer_head[i]) )
2654 break;
2655 i++;
2656 }
2657 }
2658 /* take '\n' into account; if '\n' is the unavailable
2659 character, we will need to wait until we have it
2660 before going further */
2661 if ( (i + 1 >= available) &&
2662 ! ( (1 == i) &&
2663 (2 == available) &&
2664 ('0' == buffer_head[0]) ) )
2665 break; /* need more data... */
2666 i++;
2667 malformed = (end_size >= 16);
2668 if (! malformed)
2669 {
2670 size_t num_dig = MHD_strx_to_uint64_n_ (buffer_head,
2671 end_size,
2672 &request->current_chunk_size);
2673 malformed = (end_size != num_dig);
2674 }
2675 if (malformed)
2676 {
2677 /* malformed encoding */
2678 CONNECTION_CLOSE_ERROR (connection,
2679 MHD_SC_CHUNKED_ENCODING_MALFORMED,
2680 _("Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2681 return;
2682 }
2683 /* skip 2nd part of line feed */
2684 if ( (i < available) &&
2685 ( ('\r' == buffer_head[i]) ||
2686 ('\n' == buffer_head[i]) ) )
2687 i++;
2688
2689 buffer_head += i;
2690 available -= i;
2691 request->current_chunk_offset = 0;
2692
2693 if (available > 0)
2694 instant_retry = true;
2695 if (0LLU == request->current_chunk_size)
2696 {
2697 request->remaining_upload_size = 0;
2698 break;
2699 }
2700 continue;
2701 }
2702 } 2626 }
2627 available -= i;
2628 buffer_head += i;
2629 request->current_chunk_offset = 0;
2630 request->current_chunk_size = 0;
2631 }
2632 if (request->current_chunk_offset <
2633 request->current_chunk_size)
2634 {
2635 uint64_t cur_chunk_left;
2636
2637 /* we are in the middle of a chunk, give
2638 as much as possible to the client (without
2639 crossing chunk boundaries) */
2640 cur_chunk_left
2641 = request->current_chunk_size - request->current_chunk_offset;
2642 if (cur_chunk_left > available)
2643 {
2644 to_be_processed = available;
2645 }
2646 else
2647 { /* cur_chunk_left <= (size_t)available */
2648 to_be_processed = (size_t) cur_chunk_left;
2649 if (available > to_be_processed)
2650 instant_retry = true;
2651 }
2652 }
2703 else 2653 else
2654 {
2655 size_t i;
2656 size_t end_size;
2657 bool malformed;
2658
2659 /* we need to read chunk boundaries */
2660 i = 0;
2661 while (i < available)
2704 { 2662 {
2705 /* no chunked encoding, give all to the client */ 2663 if ( ('\r' == buffer_head[i]) ||
2706 if ( (0 != request->remaining_upload_size) && 2664 ('\n' == buffer_head[i]) ||
2707 (MHD_SIZE_UNKNOWN != request->remaining_upload_size) && 2665 (';' == buffer_head[i]) )
2708 (request->remaining_upload_size < available) ) 2666 break;
2709 { 2667 i++;
2710 to_be_processed = (size_t)request->remaining_upload_size; 2668 if (i >= 16)
2711 } 2669 break;
2712 else
2713 {
2714 /**
2715 * 1. no chunked encoding, give all to the client
2716 * 2. client may send large chunked data, but only a smaller part is available at one time.
2717 */
2718 to_be_processed = available;
2719 }
2720 } 2670 }
2721 left_unprocessed = to_be_processed; 2671 end_size = i;
2722#if FIXME_OLD_STYLE 2672 /* find beginning of CRLF (skip over chunk extensions) */
2723 if (MHD_NO == 2673 if (';' == buffer_head[i])
2724 daemon->rc (daemon->rc_cls, 2674 {
2725 request, 2675 while (i < available)
2726 request->url, 2676 {
2727 request->method, 2677 if ( ('\r' == buffer_head[i]) ||
2728 request->version, 2678 ('\n' == buffer_head[i]) )
2729 buffer_head, 2679 break;
2730 &left_unprocessed, 2680 i++;
2731 &request->client_context)) 2681 }
2682 }
2683 /* take '\n' into account; if '\n' is the unavailable
2684 character, we will need to wait until we have it
2685 before going further */
2686 if ( (i + 1 >= available) &&
2687 ! ( (1 == i) &&
2688 (2 == available) &&
2689 ('0' == buffer_head[0]) ) )
2690 break; /* need more data... */
2691 i++;
2692 malformed = (end_size >= 16);
2693 if (! malformed)
2694 {
2695 size_t num_dig = MHD_strx_to_uint64_n_ (buffer_head,
2696 end_size,
2697 &request->current_chunk_size);
2698 malformed = (end_size != num_dig);
2699 }
2700 if (malformed)
2732 { 2701 {
2733 /* serious internal error, close connection */ 2702 /* malformed encoding */
2734 CONNECTION_CLOSE_ERROR (connection, 2703 CONNECTION_CLOSE_ERROR (connection,
2735 MHD_SC_APPLICATION_CALLBACK_FAILURE_CLOSED, 2704 MHD_SC_CHUNKED_ENCODING_MALFORMED,
2736 _("Application reported internal error, closing connection.\n")); 2705 _ (
2706 "Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2737 return; 2707 return;
2738 } 2708 }
2709 /* skip 2nd part of line feed */
2710 if ( (i < available) &&
2711 ( ('\r' == buffer_head[i]) ||
2712 ('\n' == buffer_head[i]) ) )
2713 i++;
2714
2715 buffer_head += i;
2716 available -= i;
2717 request->current_chunk_offset = 0;
2718
2719 if (available > 0)
2720 instant_retry = true;
2721 if (0LLU == request->current_chunk_size)
2722 {
2723 request->remaining_upload_size = 0;
2724 break;
2725 }
2726 continue;
2727 }
2728 }
2729 else
2730 {
2731 /* no chunked encoding, give all to the client */
2732 if ( (0 != request->remaining_upload_size) &&
2733 (MHD_SIZE_UNKNOWN != request->remaining_upload_size) &&
2734 (request->remaining_upload_size < available) )
2735 {
2736 to_be_processed = (size_t) request->remaining_upload_size;
2737 }
2738 else
2739 {
2740 /**
2741 * 1. no chunked encoding, give all to the client
2742 * 2. client may send large chunked data, but only a smaller part is available at one time.
2743 */
2744 to_be_processed = available;
2745 }
2746 }
2747 left_unprocessed = to_be_processed;
2748#if FIXME_OLD_STYLE
2749 if (MHD_NO ==
2750 daemon->rc (daemon->rc_cls,
2751 request,
2752 request->url,
2753 request->method,
2754 request->version,
2755 buffer_head,
2756 &left_unprocessed,
2757 &request->client_context))
2758 {
2759 /* serious internal error, close connection */
2760 CONNECTION_CLOSE_ERROR (connection,
2761 MHD_SC_APPLICATION_CALLBACK_FAILURE_CLOSED,
2762 _ (
2763 "Application reported internal error, closing connection.\n"));
2764 return;
2765 }
2739#endif 2766#endif
2740 if (left_unprocessed > to_be_processed) 2767 if (left_unprocessed > to_be_processed)
2741 mhd_panic (mhd_panic_cls, 2768 mhd_panic (mhd_panic_cls,
2742 __FILE__, 2769 __FILE__,
2743 __LINE__ 2770 __LINE__
2744#ifdef HAVE_MESSAGES 2771#ifdef HAVE_MESSAGES
2745 , _("libmicrohttpd API violation") 2772 , _ ("libmicrohttpd API violation")
2746#else 2773#else
2747 , NULL 2774 , NULL
2748#endif 2775#endif
2749 ); 2776 );
2750 if (0 != left_unprocessed) 2777 if (0 != left_unprocessed)
2751 { 2778 {
2752 instant_retry = false; /* client did not process everything */ 2779 instant_retry = false; /* client did not process everything */
2753#ifdef HAVE_MESSAGES 2780#ifdef HAVE_MESSAGES
2754 /* client did not process all upload data, complain if 2781 /* client did not process all upload data, complain if
2755 the setup was incorrect, which may prevent us from 2782 the setup was incorrect, which may prevent us from
2756 handling the rest of the request */ 2783 handling the rest of the request */
2757 if ( (MHD_TM_EXTERNAL_EVENT_LOOP == daemon->threading_mode) && 2784 if ( (MHD_TM_EXTERNAL_EVENT_LOOP == daemon->threading_mode) &&
2758 (! connection->suspended) ) 2785 (! connection->suspended) )
2759 MHD_DLOG (daemon, 2786 MHD_DLOG (daemon,
2760 MHD_SC_APPLICATION_HUNG_CONNECTION, 2787 MHD_SC_APPLICATION_HUNG_CONNECTION,
2761 _("WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n")); 2788 _ (
2789 "WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n"));
2762#endif 2790#endif
2763 }
2764 processed_size = to_be_processed - left_unprocessed;
2765 if (request->have_chunked_upload)
2766 request->current_chunk_offset += processed_size;
2767 /* dh left "processed" bytes in buffer for next time... */
2768 buffer_head += processed_size;
2769 available -= processed_size;
2770 if (MHD_SIZE_UNKNOWN != request->remaining_upload_size)
2771 request->remaining_upload_size -= processed_size;
2772 } 2791 }
2792 processed_size = to_be_processed - left_unprocessed;
2793 if (request->have_chunked_upload)
2794 request->current_chunk_offset += processed_size;
2795 /* dh left "processed" bytes in buffer for next time... */
2796 buffer_head += processed_size;
2797 available -= processed_size;
2798 if (MHD_SIZE_UNKNOWN != request->remaining_upload_size)
2799 request->remaining_upload_size -= processed_size;
2800 }
2773 while (instant_retry); 2801 while (instant_retry);
2774 if (available > 0) 2802 if (available > 0)
2775 memmove (request->read_buffer, 2803 memmove (request->read_buffer,
@@ -2796,58 +2824,59 @@ cleanup_connection (struct MHD_Connection *connection)
2796 return; /* Prevent double cleanup. */ 2824 return; /* Prevent double cleanup. */
2797 connection->request.in_cleanup = true; 2825 connection->request.in_cleanup = true;
2798 if (NULL != connection->request.response) 2826 if (NULL != connection->request.response)
2799 { 2827 {
2800 MHD_response_queue_for_destroy (connection->request.response); 2828 MHD_response_queue_for_destroy (connection->request.response);
2801 connection->request.response = NULL; 2829 connection->request.response = NULL;
2802 } 2830 }
2803 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2831 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2804 if (connection->suspended) 2832 if (connection->suspended)
2805 { 2833 {
2806 DLL_remove (daemon->suspended_connections_head, 2834 DLL_remove (daemon->suspended_connections_head,
2807 daemon->suspended_connections_tail, 2835 daemon->suspended_connections_tail,
2808 connection); 2836 connection);
2809 connection->suspended = false; 2837 connection->suspended = false;
2810 } 2838 }
2811 else 2839 else
2840 {
2841 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
2812 { 2842 {
2813 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 2843 if (connection->connection_timeout ==
2814 { 2844 daemon->connection_default_timeout)
2815 if (connection->connection_timeout == 2845 XDLL_remove (daemon->normal_timeout_head,
2816 daemon->connection_default_timeout) 2846 daemon->normal_timeout_tail,
2817 XDLL_remove (daemon->normal_timeout_head, 2847 connection);
2818 daemon->normal_timeout_tail, 2848 else
2819 connection); 2849 XDLL_remove (daemon->manual_timeout_head,
2820 else 2850 daemon->manual_timeout_tail,
2821 XDLL_remove (daemon->manual_timeout_head, 2851 connection);
2822 daemon->manual_timeout_tail,
2823 connection);
2824 }
2825 DLL_remove (daemon->connections_head,
2826 daemon->connections_tail,
2827 connection);
2828 } 2852 }
2853 DLL_remove (daemon->connections_head,
2854 daemon->connections_tail,
2855 connection);
2856 }
2829 DLL_insert (daemon->cleanup_head, 2857 DLL_insert (daemon->cleanup_head,
2830 daemon->cleanup_tail, 2858 daemon->cleanup_tail,
2831 connection); 2859 connection);
2832 connection->resuming = false; 2860 connection->resuming = false;
2833 connection->request.in_idle = false; 2861 connection->request.in_idle = false;
2834 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2862 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2835 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 2863 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
2864 {
2865 /* if we were at the connection limit before and are in
2866 thread-per-connection mode, signal the main thread
2867 to resume accepting connections */
2868 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2869 (! MHD_itc_activate_ (daemon->itc,
2870 "c")) )
2836 { 2871 {
2837 /* if we were at the connection limit before and are in
2838 thread-per-connection mode, signal the main thread
2839 to resume accepting connections */
2840 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2841 (! MHD_itc_activate_ (daemon->itc,
2842 "c")) )
2843 {
2844#ifdef HAVE_MESSAGES 2872#ifdef HAVE_MESSAGES
2845 MHD_DLOG (daemon, 2873 MHD_DLOG (daemon,
2846 MHD_SC_ITC_USE_FAILED, 2874 MHD_SC_ITC_USE_FAILED,
2847 _("Failed to signal end of connection via inter-thread communication channel")); 2875 _ (
2876 "Failed to signal end of connection via inter-thread communication channel"));
2848#endif 2877#endif
2849 }
2850 } 2878 }
2879 }
2851} 2880}
2852 2881
2853 2882
@@ -2870,31 +2899,31 @@ connection_epoll_update_ (struct MHD_Connection *connection)
2870 (0 == (connection->epoll_state & MHD_EPOLL_STATE_SUSPENDED)) && 2899 (0 == (connection->epoll_state & MHD_EPOLL_STATE_SUSPENDED)) &&
2871 ( ( (MHD_EVENT_LOOP_INFO_WRITE == connection->request.event_loop_info) && 2900 ( ( (MHD_EVENT_LOOP_INFO_WRITE == connection->request.event_loop_info) &&
2872 (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY))) || 2901 (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY))) ||
2873 ( (MHD_EVENT_LOOP_INFO_READ == connection->request.event_loop_info) && 2902 ( (MHD_EVENT_LOOP_INFO_READ == connection->request.event_loop_info) &&
2874 (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) ) ) ) 2903 (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) ) ) )
2904 {
2905 /* add to epoll set */
2906 struct epoll_event event;
2907
2908 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
2909 event.data.ptr = connection;
2910 if (0 != epoll_ctl (daemon->epoll_fd,
2911 EPOLL_CTL_ADD,
2912 connection->socket_fd,
2913 &event))
2875 { 2914 {
2876 /* add to epoll set */
2877 struct epoll_event event;
2878
2879 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
2880 event.data.ptr = connection;
2881 if (0 != epoll_ctl (daemon->epoll_fd,
2882 EPOLL_CTL_ADD,
2883 connection->socket_fd,
2884 &event))
2885 {
2886#ifdef HAVE_MESSAGES 2915#ifdef HAVE_MESSAGES
2887 MHD_DLOG (daemon, 2916 MHD_DLOG (daemon,
2888 MHD_SC_EPOLL_CTL_ADD_FAILED, 2917 MHD_SC_EPOLL_CTL_ADD_FAILED,
2889 _("Call to epoll_ctl failed: %s\n"), 2918 _ ("Call to epoll_ctl failed: %s\n"),
2890 MHD_socket_last_strerr_ ()); 2919 MHD_socket_last_strerr_ ());
2891#endif 2920#endif
2892 connection->request.state = MHD_REQUEST_CLOSED; 2921 connection->request.state = MHD_REQUEST_CLOSED;
2893 cleanup_connection (connection); 2922 cleanup_connection (connection);
2894 return false; 2923 return false;
2895 }
2896 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
2897 } 2924 }
2925 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
2926 }
2898 return true; 2927 return true;
2899} 2928}
2900#endif 2929#endif
@@ -2922,142 +2951,142 @@ connection_update_event_loop_info (struct MHD_Connection *connection)
2922 struct MHD_TLS_Plugin *tls; 2951 struct MHD_TLS_Plugin *tls;
2923 2952
2924 if ( (NULL != (tls = daemon->tls_api)) && 2953 if ( (NULL != (tls = daemon->tls_api)) &&
2925 (tls->update_event_loop_info (tls->cls, 2954 (tls->update_event_loop_info (tls->cls,
2926 connection->tls_cs, 2955 connection->tls_cs,
2927 &request->event_loop_info)) ) 2956 &request->event_loop_info)) )
2928 return; /* TLS has decided what to do */ 2957 return; /* TLS has decided what to do */
2929 } 2958 }
2930#endif /* HTTPS_SUPPORT */ 2959#endif /* HTTPS_SUPPORT */
2931 while (1) 2960 while (1)
2932 { 2961 {
2933#if DEBUG_STATES 2962#if DEBUG_STATES
2934 MHD_DLOG (daemon, 2963 MHD_DLOG (daemon,
2935 MHD_SC_STATE_MACHINE_STATUS_REPORT, 2964 MHD_SC_STATE_MACHINE_STATUS_REPORT,
2936 _("In function %s handling connection at state: %s\n"), 2965 _ ("In function %s handling connection at state: %s\n"),
2937 __FUNCTION__, 2966 __FUNCTION__,
2938 MHD_state_to_string (request->state)); 2967 MHD_state_to_string (request->state));
2939#endif 2968#endif
2940 switch (request->state) 2969 switch (request->state)
2970 {
2971 case MHD_REQUEST_INIT:
2972 case MHD_REQUEST_URL_RECEIVED:
2973 case MHD_REQUEST_HEADER_PART_RECEIVED:
2974 /* while reading headers, we always grow the
2975 read buffer if needed, no size-check required */
2976 if ( (request->read_buffer_offset == request->read_buffer_size) &&
2977 (! try_grow_read_buffer (request)) )
2978 {
2979 transmit_error_response (request,
2980 MHD_SC_CLIENT_HEADER_TOO_BIG,
2981 (NULL != request->url)
2982 ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
2983 : MHD_HTTP_URI_TOO_LONG,
2984 REQUEST_TOO_BIG);
2985 continue;
2986 }
2987 if (! connection->read_closed)
2988 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
2989 else
2990 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
2991 break;
2992 case MHD_REQUEST_HEADERS_RECEIVED:
2993 mhd_assert (0);
2994 break;
2995 case MHD_REQUEST_HEADERS_PROCESSED:
2996 mhd_assert (0);
2997 break;
2998 case MHD_REQUEST_CONTINUE_SENDING:
2999 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3000 break;
3001 case MHD_REQUEST_CONTINUE_SENT:
3002 if (request->read_buffer_offset == request->read_buffer_size)
3003 {
3004 if ( (! try_grow_read_buffer (request)) &&
3005 (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) )
2941 { 3006 {
2942 case MHD_REQUEST_INIT: 3007 /* failed to grow the read buffer, and the client
2943 case MHD_REQUEST_URL_RECEIVED: 3008 which is supposed to handle the received data in
2944 case MHD_REQUEST_HEADER_PART_RECEIVED: 3009 a *blocking* fashion (in this mode) did not
2945 /* while reading headers, we always grow the 3010 handle the data as it was supposed to!
2946 read buffer if needed, no size-check required */ 3011
2947 if ( (request->read_buffer_offset == request->read_buffer_size) && 3012 => we would either have to do busy-waiting
2948 (! try_grow_read_buffer (request)) ) 3013 (on the client, which would likely fail),
2949 { 3014 or if we do nothing, we would just timeout
2950 transmit_error_response (request, 3015 on the connection (if a timeout is even set!).
2951 MHD_SC_CLIENT_HEADER_TOO_BIG, 3016
2952 (NULL != request->url) 3017 Solution: we kill the connection with an error */
2953 ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE 3018 transmit_error_response (request,
2954 : MHD_HTTP_URI_TOO_LONG, 3019 MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED,
2955 REQUEST_TOO_BIG); 3020 MHD_HTTP_INTERNAL_SERVER_ERROR,
2956 continue; 3021 INTERNAL_ERROR);
2957 } 3022 continue;
2958 if (! connection->read_closed)
2959 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
2960 else
2961 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
2962 break;
2963 case MHD_REQUEST_HEADERS_RECEIVED:
2964 mhd_assert (0);
2965 break;
2966 case MHD_REQUEST_HEADERS_PROCESSED:
2967 mhd_assert (0);
2968 break;
2969 case MHD_REQUEST_CONTINUE_SENDING:
2970 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
2971 break;
2972 case MHD_REQUEST_CONTINUE_SENT:
2973 if (request->read_buffer_offset == request->read_buffer_size)
2974 {
2975 if ( (! try_grow_read_buffer (request)) &&
2976 (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) )
2977 {
2978 /* failed to grow the read buffer, and the client
2979 which is supposed to handle the received data in
2980 a *blocking* fashion (in this mode) did not
2981 handle the data as it was supposed to!
2982
2983 => we would either have to do busy-waiting
2984 (on the client, which would likely fail),
2985 or if we do nothing, we would just timeout
2986 on the connection (if a timeout is even set!).
2987
2988 Solution: we kill the connection with an error */
2989 transmit_error_response (request,
2990 MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED,
2991 MHD_HTTP_INTERNAL_SERVER_ERROR,
2992 INTERNAL_ERROR);
2993 continue;
2994 }
2995 }
2996 if ( (request->read_buffer_offset < request->read_buffer_size) &&
2997 (! connection->read_closed) )
2998 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
2999 else
3000 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3001 break;
3002 case MHD_REQUEST_BODY_RECEIVED:
3003 case MHD_REQUEST_FOOTER_PART_RECEIVED:
3004 /* while reading footers, we always grow the
3005 read buffer if needed, no size-check required */
3006 if (connection->read_closed)
3007 {
3008 CONNECTION_CLOSE_ERROR (connection,
3009 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3010 NULL);
3011 continue;
3012 }
3013 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
3014 /* transition to FOOTERS_RECEIVED
3015 happens in read handler */
3016 break;
3017 case MHD_REQUEST_FOOTERS_RECEIVED:
3018 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3019 break;
3020 case MHD_REQUEST_HEADERS_SENDING:
3021 /* headers in buffer, keep writing */
3022 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3023 break;
3024 case MHD_REQUEST_HEADERS_SENT:
3025 mhd_assert (0);
3026 break;
3027 case MHD_REQUEST_NORMAL_BODY_READY:
3028 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3029 break;
3030 case MHD_REQUEST_NORMAL_BODY_UNREADY:
3031 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3032 break;
3033 case MHD_REQUEST_CHUNKED_BODY_READY:
3034 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3035 break;
3036 case MHD_REQUEST_CHUNKED_BODY_UNREADY:
3037 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3038 break;
3039 case MHD_REQUEST_BODY_SENT:
3040 mhd_assert (0);
3041 break;
3042 case MHD_REQUEST_FOOTERS_SENDING:
3043 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3044 break;
3045 case MHD_REQUEST_FOOTERS_SENT:
3046 mhd_assert (0);
3047 break;
3048 case MHD_REQUEST_CLOSED:
3049 request->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
3050 return; /* do nothing, not even reading */
3051#ifdef UPGRADE_SUPPORT
3052 case MHD_REQUEST_UPGRADE:
3053 mhd_assert (0);
3054 break;
3055#endif /* UPGRADE_SUPPORT */
3056 default:
3057 mhd_assert (0);
3058 } 3023 }
3024 }
3025 if ( (request->read_buffer_offset < request->read_buffer_size) &&
3026 (! connection->read_closed) )
3027 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
3028 else
3029 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3030 break;
3031 case MHD_REQUEST_BODY_RECEIVED:
3032 case MHD_REQUEST_FOOTER_PART_RECEIVED:
3033 /* while reading footers, we always grow the
3034 read buffer if needed, no size-check required */
3035 if (connection->read_closed)
3036 {
3037 CONNECTION_CLOSE_ERROR (connection,
3038 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3039 NULL);
3040 continue;
3041 }
3042 request->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
3043 /* transition to FOOTERS_RECEIVED
3044 happens in read handler */
3045 break;
3046 case MHD_REQUEST_FOOTERS_RECEIVED:
3047 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3048 break;
3049 case MHD_REQUEST_HEADERS_SENDING:
3050 /* headers in buffer, keep writing */
3051 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3052 break;
3053 case MHD_REQUEST_HEADERS_SENT:
3054 mhd_assert (0);
3055 break;
3056 case MHD_REQUEST_NORMAL_BODY_READY:
3057 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3058 break;
3059 case MHD_REQUEST_NORMAL_BODY_UNREADY:
3060 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3061 break;
3062 case MHD_REQUEST_CHUNKED_BODY_READY:
3063 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3064 break;
3065 case MHD_REQUEST_CHUNKED_BODY_UNREADY:
3066 request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
3067 break;
3068 case MHD_REQUEST_BODY_SENT:
3069 mhd_assert (0);
3070 break;
3071 case MHD_REQUEST_FOOTERS_SENDING:
3072 request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE;
3059 break; 3073 break;
3074 case MHD_REQUEST_FOOTERS_SENT:
3075 mhd_assert (0);
3076 break;
3077 case MHD_REQUEST_CLOSED:
3078 request->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
3079 return; /* do nothing, not even reading */
3080#ifdef UPGRADE_SUPPORT
3081 case MHD_REQUEST_UPGRADE:
3082 mhd_assert (0);
3083 break;
3084#endif /* UPGRADE_SUPPORT */
3085 default:
3086 mhd_assert (0);
3060 } 3087 }
3088 break;
3089 }
3061} 3090}
3062 3091
3063 3092
@@ -3082,491 +3111,494 @@ MHD_request_handle_idle_ (struct MHD_Request *request)
3082 3111
3083 request->in_idle = true; 3112 request->in_idle = true;
3084 while (! connection->suspended) 3113 while (! connection->suspended)
3085 { 3114 {
3086#ifdef HTTPS_SUPPORT 3115#ifdef HTTPS_SUPPORT
3087 struct MHD_TLS_Plugin *tls; 3116 struct MHD_TLS_Plugin *tls;
3088 3117
3089 if ( (NULL != (tls = daemon->tls_api)) && 3118 if ( (NULL != (tls = daemon->tls_api)) &&
3090 (! tls->idle_ready (tls->cls, 3119 (! tls->idle_ready (tls->cls,
3091 connection->tls_cs)) ) 3120 connection->tls_cs)) )
3092 break; 3121 break;
3093#endif /* HTTPS_SUPPORT */ 3122#endif /* HTTPS_SUPPORT */
3094#if DEBUG_STATES 3123#if DEBUG_STATES
3095 MHD_DLOG (daemon, 3124 MHD_DLOG (daemon,
3096 MHD_SC_STATE_MACHINE_STATUS_REPORT, 3125 MHD_SC_STATE_MACHINE_STATUS_REPORT,
3097 _("In function %s handling connection at state: %s\n"), 3126 _ ("In function %s handling connection at state: %s\n"),
3098 __FUNCTION__, 3127 __FUNCTION__,
3099 MHD_state_to_string (request->state)); 3128 MHD_state_to_string (request->state));
3100#endif 3129#endif
3101 switch (request->state) 3130 switch (request->state)
3131 {
3132 case MHD_REQUEST_INIT:
3133 line = get_next_header_line (request,
3134 &line_len);
3135 /* Check for empty string, as we might want
3136 to tolerate 'spurious' empty lines; also
3137 NULL means we didn't get a full line yet;
3138 line is not 0-terminated here. */
3139 if ( (NULL == line) ||
3140 (0 == line[0]) )
3141 {
3142 if (MHD_REQUEST_INIT != request->state)
3143 continue;
3144 if (connection->read_closed)
3102 { 3145 {
3103 case MHD_REQUEST_INIT: 3146 CONNECTION_CLOSE_ERROR (connection,
3104 line = get_next_header_line (request, 3147 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3105 &line_len); 3148 NULL);
3106 /* Check for empty string, as we might want
3107 to tolerate 'spurious' empty lines; also
3108 NULL means we didn't get a full line yet;
3109 line is not 0-terminated here. */
3110 if ( (NULL == line) ||
3111 (0 == line[0]) )
3112 {
3113 if (MHD_REQUEST_INIT != request->state)
3114 continue;
3115 if (connection->read_closed)
3116 {
3117 CONNECTION_CLOSE_ERROR (connection,
3118 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3119 NULL);
3120 continue;
3121 }
3122 break;
3123 }
3124 if (MHD_NO ==
3125 parse_initial_message_line (request,
3126 line,
3127 line_len))
3128 CONNECTION_CLOSE_ERROR (connection,
3129 MHD_SC_CONNECTION_CLOSED,
3130 NULL);
3131 else
3132 request->state = MHD_REQUEST_URL_RECEIVED;
3133 continue; 3149 continue;
3134 case MHD_REQUEST_URL_RECEIVED: 3150 }
3135 line = get_next_header_line (request, 3151 break;
3136 NULL); 3152 }
3137 if (NULL == line) 3153 if (MHD_NO ==
3138 { 3154 parse_initial_message_line (request,
3139 if (MHD_REQUEST_URL_RECEIVED != request->state) 3155 line,
3140 continue; 3156 line_len))
3141 if (connection->read_closed) 3157 CONNECTION_CLOSE_ERROR (connection,
3142 { 3158 MHD_SC_CONNECTION_CLOSED,
3143 CONNECTION_CLOSE_ERROR (connection, 3159 NULL);
3144 MHD_SC_CONNECTION_READ_FAIL_CLOSED, 3160 else
3145 NULL); 3161 request->state = MHD_REQUEST_URL_RECEIVED;
3146 continue; 3162 continue;
3147 } 3163 case MHD_REQUEST_URL_RECEIVED:
3148 break; 3164 line = get_next_header_line (request,
3149 } 3165 NULL);
3150 if (0 == line[0]) 3166 if (NULL == line)
3151 { 3167 {
3152 request->state = MHD_REQUEST_HEADERS_RECEIVED; 3168 if (MHD_REQUEST_URL_RECEIVED != request->state)
3153 request->header_size = (size_t) (line - request->read_buffer);
3154 continue;
3155 }
3156 if (! process_header_line (request,
3157 line))
3158 {
3159 transmit_error_response (request,
3160 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
3161 MHD_HTTP_BAD_REQUEST,
3162 REQUEST_MALFORMED);
3163 break;
3164 }
3165 request->state = MHD_REQUEST_HEADER_PART_RECEIVED;
3166 continue; 3169 continue;
3167 case MHD_REQUEST_HEADER_PART_RECEIVED: 3170 if (connection->read_closed)
3168 line = get_next_header_line (request, 3171 {
3169 NULL); 3172 CONNECTION_CLOSE_ERROR (connection,
3170 if (NULL == line) 3173 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3171 { 3174 NULL);
3172 if (request->state != MHD_REQUEST_HEADER_PART_RECEIVED)
3173 continue;
3174 if (connection->read_closed)
3175 {
3176 CONNECTION_CLOSE_ERROR (connection,
3177 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3178 NULL);
3179 continue;
3180 }
3181 break;
3182 }
3183 if (MHD_NO ==
3184 process_broken_line (request,
3185 line,
3186 MHD_HEADER_KIND))
3187 continue;
3188 if (0 == line[0])
3189 {
3190 request->state = MHD_REQUEST_HEADERS_RECEIVED;
3191 request->header_size = (size_t) (line - request->read_buffer);
3192 continue;
3193 }
3194 continue; 3175 continue;
3195 case MHD_REQUEST_HEADERS_RECEIVED: 3176 }
3196 parse_request_headers (request); 3177 break;
3197 if (MHD_REQUEST_CLOSED == request->state) 3178 }
3198 continue; 3179 if (0 == line[0])
3199 request->state = MHD_REQUEST_HEADERS_PROCESSED; 3180 {
3200 if (connection->suspended) 3181 request->state = MHD_REQUEST_HEADERS_RECEIVED;
3201 break; 3182 request->header_size = (size_t) (line - request->read_buffer);
3183 continue;
3184 }
3185 if (! process_header_line (request,
3186 line))
3187 {
3188 transmit_error_response (request,
3189 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
3190 MHD_HTTP_BAD_REQUEST,
3191 REQUEST_MALFORMED);
3192 break;
3193 }
3194 request->state = MHD_REQUEST_HEADER_PART_RECEIVED;
3195 continue;
3196 case MHD_REQUEST_HEADER_PART_RECEIVED:
3197 line = get_next_header_line (request,
3198 NULL);
3199 if (NULL == line)
3200 {
3201 if (request->state != MHD_REQUEST_HEADER_PART_RECEIVED)
3202 continue; 3202 continue;
3203 case MHD_REQUEST_HEADERS_PROCESSED: 3203 if (connection->read_closed)
3204 call_request_handler (request); /* first call */ 3204 {
3205 if (MHD_REQUEST_CLOSED == request->state) 3205 CONNECTION_CLOSE_ERROR (connection,
3206 continue; 3206 MHD_SC_CONNECTION_READ_FAIL_CLOSED,
3207 if (need_100_continue (request)) 3207 NULL);
3208 {
3209 request->state = MHD_REQUEST_CONTINUE_SENDING;
3210 if (socket_flush_possible (connection))
3211 socket_start_extra_buffering (connection);
3212 else
3213 socket_start_no_buffering (connection);
3214 break;
3215 }
3216 if ( (NULL != request->response) &&
3217 ( (MHD_METHOD_POST == request->method) ||
3218 (MHD_METHOD_PUT == request->method) ) )
3219 {
3220 /* we refused (no upload allowed!) */
3221 request->remaining_upload_size = 0;
3222 /* force close, in case client still tries to upload... */
3223 connection->read_closed = true;
3224 }
3225 request->state = (0 == request->remaining_upload_size)
3226 ? MHD_REQUEST_FOOTERS_RECEIVED
3227 : MHD_REQUEST_CONTINUE_SENT;
3228 if (connection->suspended)
3229 break;
3230 continue; 3208 continue;
3231 case MHD_REQUEST_CONTINUE_SENDING: 3209 }
3232 if (request->continue_message_write_offset == 3210 break;
3233 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) 3211 }
3234 { 3212 if (MHD_NO ==
3235 request->state = MHD_REQUEST_CONTINUE_SENT; 3213 process_broken_line (request,
3236 if (! socket_flush_possible (connection)) 3214 line,
3237 socket_start_no_buffering_flush (connection); 3215 MHD_HEADER_KIND))
3238 else 3216 continue;
3239 socket_start_normal_buffering (connection); 3217 if (0 == line[0])
3240 continue; 3218 {
3241 } 3219 request->state = MHD_REQUEST_HEADERS_RECEIVED;
3242 break; 3220 request->header_size = (size_t) (line - request->read_buffer);
3243 case MHD_REQUEST_CONTINUE_SENT: 3221 continue;
3244 if (0 != request->read_buffer_offset) 3222 }
3245 { 3223 continue;
3246 process_request_body (request); /* loop call */ 3224 case MHD_REQUEST_HEADERS_RECEIVED:
3247 if (MHD_REQUEST_CLOSED == request->state) 3225 parse_request_headers (request);
3248 continue; 3226 if (MHD_REQUEST_CLOSED == request->state)
3249 } 3227 continue;
3250 if ( (0 == request->remaining_upload_size) || 3228 request->state = MHD_REQUEST_HEADERS_PROCESSED;
3251 ( (MHD_SIZE_UNKNOWN == request->remaining_upload_size) && 3229 if (connection->suspended)
3252 (0 == request->read_buffer_offset) && 3230 break;
3253 (connection->read_closed) ) ) 3231 continue;
3254 { 3232 case MHD_REQUEST_HEADERS_PROCESSED:
3255 if ( (request->have_chunked_upload) && 3233 call_request_handler (request); /* first call */
3256 (! connection->read_closed) ) 3234 if (MHD_REQUEST_CLOSED == request->state)
3257 request->state = MHD_REQUEST_BODY_RECEIVED; 3235 continue;
3258 else 3236 if (need_100_continue (request))
3259 request->state = MHD_REQUEST_FOOTERS_RECEIVED; 3237 {
3260 if (connection->suspended) 3238 request->state = MHD_REQUEST_CONTINUE_SENDING;
3261 break; 3239 if (socket_flush_possible (connection))
3262 continue; 3240 socket_start_extra_buffering (connection);
3263 } 3241 else
3242 socket_start_no_buffering (connection);
3243 break;
3244 }
3245 if ( (NULL != request->response) &&
3246 ( (MHD_METHOD_POST == request->method) ||
3247 (MHD_METHOD_PUT == request->method) ) )
3248 {
3249 /* we refused (no upload allowed!) */
3250 request->remaining_upload_size = 0;
3251 /* force close, in case client still tries to upload... */
3252 connection->read_closed = true;
3253 }
3254 request->state = (0 == request->remaining_upload_size)
3255 ? MHD_REQUEST_FOOTERS_RECEIVED
3256 : MHD_REQUEST_CONTINUE_SENT;
3257 if (connection->suspended)
3258 break;
3259 continue;
3260 case MHD_REQUEST_CONTINUE_SENDING:
3261 if (request->continue_message_write_offset ==
3262 MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE))
3263 {
3264 request->state = MHD_REQUEST_CONTINUE_SENT;
3265 if (! socket_flush_possible (connection))
3266 socket_start_no_buffering_flush (connection);
3267 else
3268 socket_start_normal_buffering (connection);
3269 continue;
3270 }
3271 break;
3272 case MHD_REQUEST_CONTINUE_SENT:
3273 if (0 != request->read_buffer_offset)
3274 {
3275 process_request_body (request); /* loop call */
3276 if (MHD_REQUEST_CLOSED == request->state)
3277 continue;
3278 }
3279 if ( (0 == request->remaining_upload_size) ||
3280 ( (MHD_SIZE_UNKNOWN == request->remaining_upload_size) &&
3281 (0 == request->read_buffer_offset) &&
3282 (connection->read_closed) ) )
3283 {
3284 if ( (request->have_chunked_upload) &&
3285 (! connection->read_closed) )
3286 request->state = MHD_REQUEST_BODY_RECEIVED;
3287 else
3288 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
3289 if (connection->suspended)
3264 break; 3290 break;
3265 case MHD_REQUEST_BODY_RECEIVED: 3291 continue;
3266 line = get_next_header_line (request, 3292 }
3267 NULL); 3293 break;
3268 if (NULL == line) 3294 case MHD_REQUEST_BODY_RECEIVED:
3269 { 3295 line = get_next_header_line (request,
3270 if (request->state != MHD_REQUEST_BODY_RECEIVED) 3296 NULL);
3271 continue; 3297 if (NULL == line)
3272 if (connection->read_closed) 3298 {
3273 { 3299 if (request->state != MHD_REQUEST_BODY_RECEIVED)
3274 CONNECTION_CLOSE_ERROR (connection,
3275 MHD_SC_CONNECTION_CLOSED,
3276 NULL);
3277 continue;
3278 }
3279 break;
3280 }
3281 if (0 == line[0])
3282 {
3283 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
3284 if (connection->suspended)
3285 break;
3286 continue;
3287 }
3288 if (MHD_NO == process_header_line (request,
3289 line))
3290 {
3291 transmit_error_response (request,
3292 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
3293 MHD_HTTP_BAD_REQUEST,
3294 REQUEST_MALFORMED);
3295 break;
3296 }
3297 request->state = MHD_REQUEST_FOOTER_PART_RECEIVED;
3298 continue; 3300 continue;
3299 case MHD_REQUEST_FOOTER_PART_RECEIVED: 3301 if (connection->read_closed)
3300 line = get_next_header_line (request, 3302 {
3301 NULL); 3303 CONNECTION_CLOSE_ERROR (connection,
3302 if (NULL == line) 3304 MHD_SC_CONNECTION_CLOSED,
3303 { 3305 NULL);
3304 if (request->state != MHD_REQUEST_FOOTER_PART_RECEIVED)
3305 continue;
3306 if (connection->read_closed)
3307 {
3308 CONNECTION_CLOSE_ERROR (connection,
3309 MHD_SC_CONNECTION_CLOSED,
3310 NULL);
3311 continue;
3312 }
3313 break;
3314 }
3315 if (MHD_NO ==
3316 process_broken_line (request,
3317 line,
3318 MHD_FOOTER_KIND))
3319 continue;
3320 if (0 == line[0])
3321 {
3322 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
3323 if (connection->suspended)
3324 break;
3325 continue;
3326 }
3327 continue; 3306 continue;
3328 case MHD_REQUEST_FOOTERS_RECEIVED: 3307 }
3329 call_request_handler (request); /* "final" call */ 3308 break;
3330 if (request->state == MHD_REQUEST_CLOSED) 3309 }
3331 continue; 3310 if (0 == line[0])
3332 if (NULL == request->response) 3311 {
3333 break; /* try again next time */ 3312 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
3334 if (! build_header_response (request)) 3313 if (connection->suspended)
3335 {
3336 /* oops - close! */
3337 CONNECTION_CLOSE_ERROR (connection,
3338 MHD_SC_FAILED_RESPONSE_HEADER_GENERATION,
3339 _("Closing connection (failed to create response header)\n"));
3340 continue;
3341 }
3342 request->state = MHD_REQUEST_HEADERS_SENDING;
3343 if (MHD_NO != socket_flush_possible (connection))
3344 socket_start_extra_buffering (connection);
3345 else
3346 socket_start_no_buffering (connection);
3347
3348 break; 3314 break;
3349 case MHD_REQUEST_HEADERS_SENDING: 3315 continue;
3350 /* no default action */ 3316 }
3317 if (MHD_NO == process_header_line (request,
3318 line))
3319 {
3320 transmit_error_response (request,
3321 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED,
3322 MHD_HTTP_BAD_REQUEST,
3323 REQUEST_MALFORMED);
3324 break;
3325 }
3326 request->state = MHD_REQUEST_FOOTER_PART_RECEIVED;
3327 continue;
3328 case MHD_REQUEST_FOOTER_PART_RECEIVED:
3329 line = get_next_header_line (request,
3330 NULL);
3331 if (NULL == line)
3332 {
3333 if (request->state != MHD_REQUEST_FOOTER_PART_RECEIVED)
3334 continue;
3335 if (connection->read_closed)
3336 {
3337 CONNECTION_CLOSE_ERROR (connection,
3338 MHD_SC_CONNECTION_CLOSED,
3339 NULL);
3340 continue;
3341 }
3342 break;
3343 }
3344 if (MHD_NO ==
3345 process_broken_line (request,
3346 line,
3347 MHD_FOOTER_KIND))
3348 continue;
3349 if (0 == line[0])
3350 {
3351 request->state = MHD_REQUEST_FOOTERS_RECEIVED;
3352 if (connection->suspended)
3351 break; 3353 break;
3352 case MHD_REQUEST_HEADERS_SENT: 3354 continue;
3353 /* Some clients may take some actions right after header receive */ 3355 }
3354 if (MHD_NO != socket_flush_possible (connection)) 3356 continue;
3355 socket_start_no_buffering_flush (connection); 3357 case MHD_REQUEST_FOOTERS_RECEIVED:
3358 call_request_handler (request); /* "final" call */
3359 if (request->state == MHD_REQUEST_CLOSED)
3360 continue;
3361 if (NULL == request->response)
3362 break; /* try again next time */
3363 if (! build_header_response (request))
3364 {
3365 /* oops - close! */
3366 CONNECTION_CLOSE_ERROR (connection,
3367 MHD_SC_FAILED_RESPONSE_HEADER_GENERATION,
3368 _ (
3369 "Closing connection (failed to create response header)\n"));
3370 continue;
3371 }
3372 request->state = MHD_REQUEST_HEADERS_SENDING;
3373 if (MHD_NO != socket_flush_possible (connection))
3374 socket_start_extra_buffering (connection);
3375 else
3376 socket_start_no_buffering (connection);
3377
3378 break;
3379 case MHD_REQUEST_HEADERS_SENDING:
3380 /* no default action */
3381 break;
3382 case MHD_REQUEST_HEADERS_SENT:
3383 /* Some clients may take some actions right after header receive */
3384 if (MHD_NO != socket_flush_possible (connection))
3385 socket_start_no_buffering_flush (connection);
3356 3386
3357#ifdef UPGRADE_SUPPORT 3387#ifdef UPGRADE_SUPPORT
3358 if (NULL != request->response->upgrade_handler) 3388 if (NULL != request->response->upgrade_handler)
3359 { 3389 {
3360 socket_start_normal_buffering (connection); 3390 socket_start_normal_buffering (connection);
3361 request->state = MHD_REQUEST_UPGRADE; 3391 request->state = MHD_REQUEST_UPGRADE;
3362#if FIXME_LEGACY_STYLE 3392#if FIXME_LEGACY_STYLE
3363 /* This request is "upgraded". Pass socket to application. */ 3393 /* This request is "upgraded". Pass socket to application. */
3364 if (! MHD_response_execute_upgrade_ (request->response, 3394 if (! MHD_response_execute_upgrade_ (request->response,
3365 request)) 3395 request))
3366 { 3396 {
3367 /* upgrade failed, fail hard */ 3397 /* upgrade failed, fail hard */
3368 CONNECTION_CLOSE_ERROR (connection, 3398 CONNECTION_CLOSE_ERROR (connection,
3369 MHD_SC_CONNECTION_CLOSED, 3399 MHD_SC_CONNECTION_CLOSED,
3370 NULL); 3400 NULL);
3371 continue; 3401 continue;
3372 } 3402 }
3373#endif 3403#endif
3374 /* Response is not required anymore for this request. */ 3404 /* Response is not required anymore for this request. */
3375 { 3405 {
3376 struct MHD_Response * const resp = request->response; 3406 struct MHD_Response *const resp = request->response;
3377 3407
3378 request->response = NULL; 3408 request->response = NULL;
3379 MHD_response_queue_for_destroy (resp); 3409 MHD_response_queue_for_destroy (resp);
3380 } 3410 }
3381 continue; 3411 continue;
3382 } 3412 }
3383#endif /* UPGRADE_SUPPORT */ 3413#endif /* UPGRADE_SUPPORT */
3384 if (MHD_NO != socket_flush_possible (connection)) 3414 if (MHD_NO != socket_flush_possible (connection))
3385 socket_start_extra_buffering (connection); 3415 socket_start_extra_buffering (connection);
3386 else 3416 else
3387 socket_start_normal_buffering (connection); 3417 socket_start_normal_buffering (connection);
3388 3418
3389 if (request->have_chunked_upload) 3419 if (request->have_chunked_upload)
3390 request->state = MHD_REQUEST_CHUNKED_BODY_UNREADY; 3420 request->state = MHD_REQUEST_CHUNKED_BODY_UNREADY;
3391 else 3421 else
3392 request->state = MHD_REQUEST_NORMAL_BODY_UNREADY; 3422 request->state = MHD_REQUEST_NORMAL_BODY_UNREADY;
3393 continue; 3423 continue;
3394 case MHD_REQUEST_NORMAL_BODY_READY: 3424 case MHD_REQUEST_NORMAL_BODY_READY:
3395 /* nothing to do here */ 3425 /* nothing to do here */
3396 break; 3426 break;
3397 case MHD_REQUEST_NORMAL_BODY_UNREADY: 3427 case MHD_REQUEST_NORMAL_BODY_UNREADY:
3398 if (NULL != request->response->crc) 3428 if (NULL != request->response->crc)
3399 MHD_mutex_lock_chk_ (&request->response->mutex); 3429 MHD_mutex_lock_chk_ (&request->response->mutex);
3400 if (0 == request->response->total_size) 3430 if (0 == request->response->total_size)
3401 { 3431 {
3402 if (NULL != request->response->crc) 3432 if (NULL != request->response->crc)
3403 MHD_mutex_unlock_chk_ (&request->response->mutex); 3433 MHD_mutex_unlock_chk_ (&request->response->mutex);
3404 request->state = MHD_REQUEST_BODY_SENT; 3434 request->state = MHD_REQUEST_BODY_SENT;
3405 continue; 3435 continue;
3406 } 3436 }
3407 if (try_ready_normal_body (request)) 3437 if (try_ready_normal_body (request))
3408 { 3438 {
3409 if (NULL != request->response->crc) 3439 if (NULL != request->response->crc)
3410 MHD_mutex_unlock_chk_ (&request->response->mutex); 3440 MHD_mutex_unlock_chk_ (&request->response->mutex);
3411 request->state = MHD_REQUEST_NORMAL_BODY_READY; 3441 request->state = MHD_REQUEST_NORMAL_BODY_READY;
3412 /* Buffering for flushable socket was already enabled*/ 3442 /* Buffering for flushable socket was already enabled*/
3413 if (MHD_NO == socket_flush_possible (connection)) 3443 if (MHD_NO == socket_flush_possible (connection))
3414 socket_start_no_buffering (connection); 3444 socket_start_no_buffering (connection);
3415 break; 3445 break;
3416 } 3446 }
3417 /* mutex was already unlocked by "try_ready_normal_body */ 3447 /* mutex was already unlocked by "try_ready_normal_body */
3418 /* not ready, no socket action */ 3448 /* not ready, no socket action */
3419 break; 3449 break;
3420 case MHD_REQUEST_CHUNKED_BODY_READY: 3450 case MHD_REQUEST_CHUNKED_BODY_READY:
3421 /* nothing to do here */ 3451 /* nothing to do here */
3422 break; 3452 break;
3423 case MHD_REQUEST_CHUNKED_BODY_UNREADY: 3453 case MHD_REQUEST_CHUNKED_BODY_UNREADY:
3424 if (NULL != request->response->crc) 3454 if (NULL != request->response->crc)
3425 MHD_mutex_lock_chk_ (&request->response->mutex); 3455 MHD_mutex_lock_chk_ (&request->response->mutex);
3426 if ( (0 == request->response->total_size) || 3456 if ( (0 == request->response->total_size) ||
3427 (request->response_write_position == 3457 (request->response_write_position ==
3428 request->response->total_size) ) 3458 request->response->total_size) )
3429 { 3459 {
3430 if (NULL != request->response->crc) 3460 if (NULL != request->response->crc)
3431 MHD_mutex_unlock_chk_ (&request->response->mutex); 3461 MHD_mutex_unlock_chk_ (&request->response->mutex);
3432 request->state = MHD_REQUEST_BODY_SENT; 3462 request->state = MHD_REQUEST_BODY_SENT;
3433 continue; 3463 continue;
3434 } 3464 }
3435 if (try_ready_chunked_body (request)) 3465 if (try_ready_chunked_body (request))
3436 { 3466 {
3437 if (NULL != request->response->crc) 3467 if (NULL != request->response->crc)
3438 MHD_mutex_unlock_chk_ (&request->response->mutex); 3468 MHD_mutex_unlock_chk_ (&request->response->mutex);
3439 request->state = MHD_REQUEST_CHUNKED_BODY_READY; 3469 request->state = MHD_REQUEST_CHUNKED_BODY_READY;
3440 /* Buffering for flushable socket was already enabled */ 3470 /* Buffering for flushable socket was already enabled */
3441 if (MHD_NO == socket_flush_possible (connection)) 3471 if (MHD_NO == socket_flush_possible (connection))
3442 socket_start_no_buffering (connection); 3472 socket_start_no_buffering (connection);
3443 continue; 3473 continue;
3444 } 3474 }
3445 /* mutex was already unlocked by try_ready_chunked_body */ 3475 /* mutex was already unlocked by try_ready_chunked_body */
3446 break; 3476 break;
3447 case MHD_REQUEST_BODY_SENT: 3477 case MHD_REQUEST_BODY_SENT:
3448 if (! build_header_response (request)) 3478 if (! build_header_response (request))
3449 { 3479 {
3450 /* oops - close! */ 3480 /* oops - close! */
3451 CONNECTION_CLOSE_ERROR (connection, 3481 CONNECTION_CLOSE_ERROR (connection,
3452 MHD_SC_FAILED_RESPONSE_HEADER_GENERATION, 3482 MHD_SC_FAILED_RESPONSE_HEADER_GENERATION,
3453 _("Closing connection (failed to create response header)\n")); 3483 _ (
3454 continue; 3484 "Closing connection (failed to create response header)\n"));
3455 } 3485 continue;
3456 if ( (! request->have_chunked_upload) || 3486 }
3457 (request->write_buffer_send_offset == 3487 if ( (! request->have_chunked_upload) ||
3458 request->write_buffer_append_offset) ) 3488 (request->write_buffer_send_offset ==
3459 request->state = MHD_REQUEST_FOOTERS_SENT; 3489 request->write_buffer_append_offset) )
3460 else 3490 request->state = MHD_REQUEST_FOOTERS_SENT;
3461 request->state = MHD_REQUEST_FOOTERS_SENDING; 3491 else
3462 continue; 3492 request->state = MHD_REQUEST_FOOTERS_SENDING;
3463 case MHD_REQUEST_FOOTERS_SENDING: 3493 continue;
3464 /* no default action */ 3494 case MHD_REQUEST_FOOTERS_SENDING:
3465 break; 3495 /* no default action */
3466 case MHD_REQUEST_FOOTERS_SENT: 3496 break;
3467 { 3497 case MHD_REQUEST_FOOTERS_SENT:
3468 struct MHD_Response *response = request->response; 3498 {
3469 3499 struct MHD_Response *response = request->response;
3470 if (MHD_HTTP_PROCESSING == response->status_code) 3500
3471 { 3501 if (MHD_HTTP_PROCESSING == response->status_code)
3472 /* After this type of response, we allow sending another! */ 3502 {
3473 request->state = MHD_REQUEST_HEADERS_PROCESSED; 3503 /* After this type of response, we allow sending another! */
3474 MHD_response_queue_for_destroy (response); 3504 request->state = MHD_REQUEST_HEADERS_PROCESSED;
3475 request->response = NULL; 3505 MHD_response_queue_for_destroy (response);
3476 /* FIXME: maybe partially reset memory pool? */ 3506 request->response = NULL;
3477 continue; 3507 /* FIXME: maybe partially reset memory pool? */
3478 }
3479 if (socket_flush_possible (connection))
3480 socket_start_no_buffering_flush (connection);
3481 else
3482 socket_start_normal_buffering (connection);
3483
3484 if (NULL != response->termination_cb)
3485 {
3486 response->termination_cb (response->termination_cb_cls,
3487 MHD_REQUEST_TERMINATED_COMPLETED_OK,
3488 request->client_context);
3489 }
3490 MHD_response_queue_for_destroy (response);
3491 request->response = NULL;
3492 }
3493 if ( (MHD_CONN_USE_KEEPALIVE != request->keepalive) ||
3494 (connection->read_closed) )
3495 {
3496 /* have to close for some reason */
3497 MHD_connection_close_ (connection,
3498 MHD_REQUEST_TERMINATED_COMPLETED_OK);
3499 MHD_pool_destroy (connection->pool);
3500 connection->pool = NULL;
3501 request->read_buffer = NULL;
3502 request->read_buffer_size = 0;
3503 request->read_buffer_offset = 0;
3504 }
3505 else
3506 {
3507 /* can try to keep-alive */
3508 if (socket_flush_possible (connection))
3509 socket_start_normal_buffering (connection);
3510 request->version_s = NULL;
3511 request->state = MHD_REQUEST_INIT;
3512 request->last = NULL;
3513 request->colon = NULL;
3514 request->header_size = 0;
3515 request->keepalive = MHD_CONN_KEEPALIVE_UNKOWN;
3516 /* Reset the read buffer to the starting size,
3517 preserving the bytes we have already read. */
3518 request->read_buffer
3519 = MHD_pool_reset (connection->pool,
3520 request->read_buffer,
3521 request->read_buffer_offset,
3522 daemon->connection_memory_limit_b / 2);
3523 request->read_buffer_size
3524 = daemon->connection_memory_limit_b / 2;
3525 }
3526 // FIXME: this is too much, NULLs out some of the things
3527 // initialized above...
3528 memset (request,
3529 0,
3530 sizeof (struct MHD_Request));
3531 request->daemon = daemon;
3532 request->connection = connection;
3533 continue; 3508 continue;
3534 case MHD_REQUEST_CLOSED: 3509 }
3535 cleanup_connection (connection); 3510 if (socket_flush_possible (connection))
3536 request->in_idle = false; 3511 socket_start_no_buffering_flush (connection);
3537 return false; 3512 else
3513 socket_start_normal_buffering (connection);
3514
3515 if (NULL != response->termination_cb)
3516 {
3517 response->termination_cb (response->termination_cb_cls,
3518 MHD_REQUEST_TERMINATED_COMPLETED_OK,
3519 request->client_context);
3520 }
3521 MHD_response_queue_for_destroy (response);
3522 request->response = NULL;
3523 }
3524 if ( (MHD_CONN_USE_KEEPALIVE != request->keepalive) ||
3525 (connection->read_closed) )
3526 {
3527 /* have to close for some reason */
3528 MHD_connection_close_ (connection,
3529 MHD_REQUEST_TERMINATED_COMPLETED_OK);
3530 MHD_pool_destroy (connection->pool);
3531 connection->pool = NULL;
3532 request->read_buffer = NULL;
3533 request->read_buffer_size = 0;
3534 request->read_buffer_offset = 0;
3535 }
3536 else
3537 {
3538 /* can try to keep-alive */
3539 if (socket_flush_possible (connection))
3540 socket_start_normal_buffering (connection);
3541 request->version_s = NULL;
3542 request->state = MHD_REQUEST_INIT;
3543 request->last = NULL;
3544 request->colon = NULL;
3545 request->header_size = 0;
3546 request->keepalive = MHD_CONN_KEEPALIVE_UNKOWN;
3547 /* Reset the read buffer to the starting size,
3548 preserving the bytes we have already read. */
3549 request->read_buffer
3550 = MHD_pool_reset (connection->pool,
3551 request->read_buffer,
3552 request->read_buffer_offset,
3553 daemon->connection_memory_limit_b / 2);
3554 request->read_buffer_size
3555 = daemon->connection_memory_limit_b / 2;
3556 }
3557 // FIXME: this is too much, NULLs out some of the things
3558 // initialized above...
3559 memset (request,
3560 0,
3561 sizeof (struct MHD_Request));
3562 request->daemon = daemon;
3563 request->connection = connection;
3564 continue;
3565 case MHD_REQUEST_CLOSED:
3566 cleanup_connection (connection);
3567 request->in_idle = false;
3568 return false;
3538#ifdef UPGRADE_SUPPORT 3569#ifdef UPGRADE_SUPPORT
3539 case MHD_REQUEST_UPGRADE: 3570 case MHD_REQUEST_UPGRADE:
3540 request->in_idle = false; 3571 request->in_idle = false;
3541 return true; /* keep open */ 3572 return true; /* keep open */
3542#endif /* UPGRADE_SUPPORT */ 3573#endif /* UPGRADE_SUPPORT */
3543 default: 3574 default:
3544 mhd_assert (0); 3575 mhd_assert (0);
3545 break;
3546 }
3547 break; 3576 break;
3548 } 3577 }
3578 break;
3579 }
3549 if (! connection->suspended) 3580 if (! connection->suspended)
3581 {
3582 time_t timeout;
3583 timeout = connection->connection_timeout;
3584 if ( (0 != timeout) &&
3585 (timeout < (MHD_monotonic_sec_counter ()
3586 - connection->last_activity)) )
3550 { 3587 {
3551 time_t timeout; 3588 MHD_connection_close_ (connection,
3552 timeout = connection->connection_timeout; 3589 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
3553 if ( (0 != timeout) && 3590 request->in_idle = false;
3554 (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)) ) 3591 return true;
3555 {
3556 MHD_connection_close_ (connection,
3557 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
3558 request->in_idle = false;
3559 return true;
3560 }
3561 } 3592 }
3593 }
3562 connection_update_event_loop_info (connection); 3594 connection_update_event_loop_info (connection);
3563 ret = true; 3595 ret = true;
3564#ifdef EPOLL_SUPPORT 3596#ifdef EPOLL_SUPPORT
3565 if ( (! connection->suspended) && 3597 if ( (! connection->suspended) &&
3566 (MHD_ELS_EPOLL == daemon->event_loop_syscall) ) 3598 (MHD_ELS_EPOLL == daemon->event_loop_syscall) )
3567 { 3599 {
3568 ret = connection_epoll_update_ (connection); 3600 ret = connection_epoll_update_ (connection);
3569 } 3601 }
3570#endif /* EPOLL_SUPPORT */ 3602#endif /* EPOLL_SUPPORT */
3571 request->in_idle = false; 3603 request->in_idle = false;
3572 return ret; 3604 return ret;
@@ -3589,9 +3621,9 @@ MHD_request_handle_idle_ (struct MHD_Request *request)
3589// FIXME: rename connection->request? 3621// FIXME: rename connection->request?
3590int 3622int
3591MHD_connection_call_handlers_ (struct MHD_Connection *con, 3623MHD_connection_call_handlers_ (struct MHD_Connection *con,
3592 bool read_ready, 3624 bool read_ready,
3593 bool write_ready, 3625 bool write_ready,
3594 bool force_close) 3626 bool force_close)
3595{ 3627{
3596 struct MHD_Daemon *daemon = con->daemon; 3628 struct MHD_Daemon *daemon = con->daemon;
3597 int ret; 3629 int ret;
@@ -3604,38 +3636,38 @@ MHD_connection_call_handlers_ (struct MHD_Connection *con,
3604 read_ready = true; 3636 read_ready = true;
3605#endif /* HTTPS_SUPPORT */ 3637#endif /* HTTPS_SUPPORT */
3606 if (! force_close) 3638 if (! force_close)
3639 {
3640 if ( (MHD_EVENT_LOOP_INFO_READ ==
3641 con->request.event_loop_info) &&
3642 read_ready)
3607 { 3643 {
3608 if ( (MHD_EVENT_LOOP_INFO_READ == 3644 MHD_request_handle_read_ (&con->request);
3609 con->request.event_loop_info) && 3645 ret = MHD_request_handle_idle_ (&con->request);
3610 read_ready) 3646 states_info_processed = true;
3611 {
3612 MHD_request_handle_read_ (&con->request);
3613 ret = MHD_request_handle_idle_ (&con->request);
3614 states_info_processed = true;
3615 }
3616 /* No need to check value of 'ret' here as closed connection
3617 * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
3618 if ( (MHD_EVENT_LOOP_INFO_WRITE ==
3619 con->request.event_loop_info) &&
3620 write_ready)
3621 {
3622 MHD_request_handle_write_ (&con->request);
3623 ret = MHD_request_handle_idle_ (&con->request);
3624 states_info_processed = true;
3625 }
3626 } 3647 }
3627 else 3648 /* No need to check value of 'ret' here as closed connection
3649 * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
3650 if ( (MHD_EVENT_LOOP_INFO_WRITE ==
3651 con->request.event_loop_info) &&
3652 write_ready)
3628 { 3653 {
3629 MHD_connection_close_ (con, 3654 MHD_request_handle_write_ (&con->request);
3630 MHD_REQUEST_TERMINATED_WITH_ERROR); 3655 ret = MHD_request_handle_idle_ (&con->request);
3631 return MHD_request_handle_idle_ (&con->request); 3656 states_info_processed = true;
3632 } 3657 }
3658 }
3659 else
3660 {
3661 MHD_connection_close_ (con,
3662 MHD_REQUEST_TERMINATED_WITH_ERROR);
3663 return MHD_request_handle_idle_ (&con->request);
3664 }
3633 3665
3634 if (! states_info_processed) 3666 if (! states_info_processed)
3635 { /* Connection is not read or write ready, but external conditions 3667 { /* Connection is not read or write ready, but external conditions
3636 * may be changed and need to be processed. */ 3668 * may be changed and need to be processed. */
3637 ret = MHD_request_handle_idle_ (&con->request); 3669 ret = MHD_request_handle_idle_ (&con->request);
3638 } 3670 }
3639 /* Fast track for fast connections. */ 3671 /* Fast track for fast connections. */
3640 /* If full request was read by single read_handler() invocation 3672 /* If full request was read by single read_handler() invocation
3641 and headers were completely prepared by single MHD_request_handle_idle_() 3673 and headers were completely prepared by single MHD_request_handle_idle_()
@@ -3647,24 +3679,24 @@ MHD_connection_call_handlers_ (struct MHD_Connection *con,
3647 /* No need to check 'ret' as connection is always in 3679 /* No need to check 'ret' as connection is always in
3648 * MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */ 3680 * MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */
3649 else if (on_fasttrack && 3681 else if (on_fasttrack &&
3650 con->sk_nonblck) 3682 con->sk_nonblck)
3683 {
3684 if (MHD_REQUEST_HEADERS_SENDING == con->request.state)
3651 { 3685 {
3652 if (MHD_REQUEST_HEADERS_SENDING == con->request.state) 3686 MHD_request_handle_write_ (&con->request);
3653 { 3687 /* Always call 'MHD_request_handle_idle_()' after each read/write. */
3654 MHD_request_handle_write_ (&con->request); 3688 ret = MHD_request_handle_idle_ (&con->request);
3655 /* Always call 'MHD_request_handle_idle_()' after each read/write. */ 3689 }
3656 ret = MHD_request_handle_idle_ (&con->request); 3690 /* If all headers were sent by single write_handler() and
3657 } 3691 * response body is prepared by single MHD_request_handle_idle_()
3658 /* If all headers were sent by single write_handler() and 3692 * call - continue. */
3659 * response body is prepared by single MHD_request_handle_idle_() 3693 if ((MHD_REQUEST_NORMAL_BODY_READY == con->request.state) ||
3660 * call - continue. */ 3694 (MHD_REQUEST_CHUNKED_BODY_READY == con->request.state))
3661 if ((MHD_REQUEST_NORMAL_BODY_READY == con->request.state) || 3695 {
3662 (MHD_REQUEST_CHUNKED_BODY_READY == con->request.state)) 3696 MHD_request_handle_write_ (&con->request);
3663 { 3697 ret = MHD_request_handle_idle_ (&con->request);
3664 MHD_request_handle_write_ (&con->request);
3665 ret = MHD_request_handle_idle_ (&con->request);
3666 }
3667 } 3698 }
3699 }
3668 3700
3669 /* All connection's data and states are processed for this turn. 3701 /* All connection's data and states are processed for this turn.
3670 * If connection already has more data to be processed - use 3702 * If connection already has more data to be processed - use
@@ -3676,17 +3708,17 @@ MHD_connection_call_handlers_ (struct MHD_Connection *con,
3676 * without space in read buffer will be market as 'info block'. */ 3708 * without space in read buffer will be market as 'info block'. */
3677 if ( (! daemon->data_already_pending) && 3709 if ( (! daemon->data_already_pending) &&
3678 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) ) 3710 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) )
3679 { 3711 {
3680 if (MHD_EVENT_LOOP_INFO_BLOCK == 3712 if (MHD_EVENT_LOOP_INFO_BLOCK ==
3681 con->request.event_loop_info) 3713 con->request.event_loop_info)
3682 daemon->data_already_pending = true; 3714 daemon->data_already_pending = true;
3683#ifdef HTTPS_SUPPORT 3715#ifdef HTTPS_SUPPORT
3684 else if ( (con->tls_read_ready) && 3716 else if ( (con->tls_read_ready) &&
3685 (MHD_EVENT_LOOP_INFO_READ == 3717 (MHD_EVENT_LOOP_INFO_READ ==
3686 con->request.event_loop_info) ) 3718 con->request.event_loop_info) )
3687 daemon->data_already_pending = true; 3719 daemon->data_already_pending = true;
3688#endif /* HTTPS_SUPPORT */ 3720#endif /* HTTPS_SUPPORT */
3689 } 3721 }
3690 return ret; 3722 return ret;
3691} 3723}
3692 3724
diff --git a/src/lib/connection_call_handlers.h b/src/lib/connection_call_handlers.h
index 980e8064..6297bb9e 100644
--- a/src/lib/connection_call_handlers.h
+++ b/src/lib/connection_call_handlers.h
@@ -40,10 +40,10 @@
40 */ 40 */
41int 41int
42MHD_connection_call_handlers_ (struct MHD_Connection *con, 42MHD_connection_call_handlers_ (struct MHD_Connection *con,
43 bool read_ready, 43 bool read_ready,
44 bool write_ready, 44 bool write_ready,
45 bool force_close) 45 bool force_close)
46 MHD_NONNULL (1); 46MHD_NONNULL (1);
47 47
48 48
49/** 49/**
@@ -58,7 +58,7 @@ MHD_connection_call_handlers_ (struct MHD_Connection *con,
58 */ 58 */
59bool 59bool
60MHD_request_handle_idle_ (struct MHD_Request *request) 60MHD_request_handle_idle_ (struct MHD_Request *request)
61 MHD_NONNULL (1); 61MHD_NONNULL (1);
62
62 63
63
64#endif 64#endif
diff --git a/src/lib/connection_cleanup.c b/src/lib/connection_cleanup.c
index 8883213b..4f2cfb0f 100644
--- a/src/lib/connection_cleanup.c
+++ b/src/lib/connection_cleanup.c
@@ -49,7 +49,7 @@ connection_cleanup_upgraded (struct MHD_Connection *connection)
49 49
50 if (NULL != (tls = connection->daemon->tls_api)) 50 if (NULL != (tls = connection->daemon->tls_api))
51 (void) tls->shutdown_connection (tls->cls, 51 (void) tls->shutdown_connection (tls->cls,
52 connection->tls_cs); 52 connection->tls_cs);
53 } 53 }
54 if (MHD_INVALID_SOCKET != urh->mhd.socket) 54 if (MHD_INVALID_SOCKET != urh->mhd.socket)
55 MHD_socket_close_chk_ (urh->mhd.socket); 55 MHD_socket_close_chk_ (urh->mhd.socket);
@@ -65,7 +65,7 @@ connection_cleanup_upgraded (struct MHD_Connection *connection)
65/** 65/**
66 * Free resources associated with all closed connections. (destroy 66 * Free resources associated with all closed connections. (destroy
67 * responses, free buffers, etc.). All closed connections are kept in 67 * responses, free buffers, etc.). All closed connections are kept in
68 * the "cleanup" doubly-linked list. 68 * the "cleanup" doubly-linked list.
69 * 69 *
70 * @remark To be called only from thread that process daemon's 70 * @remark To be called only from thread that process daemon's
71 * select()/poll()/etc. 71 * select()/poll()/etc.
@@ -79,79 +79,79 @@ MHD_connection_cleanup_ (struct MHD_Daemon *daemon)
79 79
80 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 80 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
81 while (NULL != (pos = daemon->cleanup_tail)) 81 while (NULL != (pos = daemon->cleanup_tail))
82 { 82 {
83 DLL_remove (daemon->cleanup_head, 83 DLL_remove (daemon->cleanup_head,
84 daemon->cleanup_tail, 84 daemon->cleanup_tail,
85 pos); 85 pos);
86 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 86 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
87 87
88 if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) && 88 if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) &&
89 (! pos->thread_joined) && 89 (! pos->thread_joined) &&
90 (! MHD_join_thread_ (pos->pid.handle)) ) 90 (! MHD_join_thread_ (pos->pid.handle)) )
91 MHD_PANIC (_("Failed to join a thread\n")); 91 MHD_PANIC (_ ("Failed to join a thread\n"));
92#ifdef UPGRADE_SUPPORT 92#ifdef UPGRADE_SUPPORT
93 connection_cleanup_upgraded (pos); 93 connection_cleanup_upgraded (pos);
94#endif /* UPGRADE_SUPPORT */ 94#endif /* UPGRADE_SUPPORT */
95 MHD_pool_destroy (pos->pool); 95 MHD_pool_destroy (pos->pool);
96#ifdef HTTPS_SUPPORT 96#ifdef HTTPS_SUPPORT
97 { 97 {
98 struct MHD_TLS_Plugin *tls; 98 struct MHD_TLS_Plugin *tls;
99 99
100 if (NULL != (tls = daemon->tls_api)) 100 if (NULL != (tls = daemon->tls_api))
101 tls->teardown_connection (tls->cls, 101 tls->teardown_connection (tls->cls,
102 pos->tls_cs); 102 pos->tls_cs);
103 } 103 }
104#endif /* HTTPS_SUPPORT */ 104#endif /* HTTPS_SUPPORT */
105 105
106 /* clean up the connection */ 106 /* clean up the connection */
107 if (NULL != daemon->notify_connection_cb) 107 if (NULL != daemon->notify_connection_cb)
108 daemon->notify_connection_cb (daemon->notify_connection_cb_cls, 108 daemon->notify_connection_cb (daemon->notify_connection_cb_cls,
109 pos, 109 pos,
110 MHD_CONNECTION_NOTIFY_CLOSED); 110 MHD_CONNECTION_NOTIFY_CLOSED);
111 MHD_ip_limit_del (daemon, 111 MHD_ip_limit_del (daemon,
112 (const struct sockaddr *) &pos->addr, 112 (const struct sockaddr *) &pos->addr,
113 pos->addr_len); 113 pos->addr_len);
114#ifdef EPOLL_SUPPORT 114#ifdef EPOLL_SUPPORT
115 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 115 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
116 { 116 {
117 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 117 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
118 { 118 {
119 EDLL_remove (daemon->eready_head, 119 EDLL_remove (daemon->eready_head,
120 daemon->eready_tail, 120 daemon->eready_tail,
121 pos); 121 pos);
122 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 122 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
123 } 123 }
124 if ( (-1 != daemon->epoll_fd) && 124 if ( (-1 != daemon->epoll_fd) &&
125 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) ) 125 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
126 { 126 {
127 /* epoll documentation suggests that closing a FD 127 /* epoll documentation suggests that closing a FD
128 automatically removes it from the epoll set; however, 128 automatically removes it from the epoll set; however,
129 this is not true as if we fail to do manually remove it, 129 this is not true as if we fail to do manually remove it,
130 we are still seeing an event for this fd in epoll, 130 we are still seeing an event for this fd in epoll,
131 causing grief (use-after-free...) --- at least on my 131 causing grief (use-after-free...) --- at least on my
132 system. */ 132 system. */
133 if (0 != epoll_ctl (daemon->epoll_fd, 133 if (0 != epoll_ctl (daemon->epoll_fd,
134 EPOLL_CTL_DEL, 134 EPOLL_CTL_DEL,
135 pos->socket_fd, 135 pos->socket_fd,
136 NULL)) 136 NULL))
137 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 137 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
138 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET; 138 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
139 } 139 }
140 } 140 }
141#endif 141#endif
142 if (NULL != pos->request.response) 142 if (NULL != pos->request.response)
143 { 143 {
144 MHD_response_queue_for_destroy (pos->request.response); 144 MHD_response_queue_for_destroy (pos->request.response);
145 pos->request.response = NULL; 145 pos->request.response = NULL;
146 }
147 if (MHD_INVALID_SOCKET != pos->socket_fd)
148 MHD_socket_close_chk_ (pos->socket_fd);
149 free (pos);
150
151 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
152 daemon->connections--;
153 daemon->at_limit = false;
154 } 146 }
147 if (MHD_INVALID_SOCKET != pos->socket_fd)
148 MHD_socket_close_chk_ (pos->socket_fd);
149 free (pos);
150
151 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
152 daemon->connections--;
153 daemon->at_limit = false;
154 }
155 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 155 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
156} 156}
157 157
diff --git a/src/lib/connection_cleanup.h b/src/lib/connection_cleanup.h
index 26fbebaf..c6beeeee 100644
--- a/src/lib/connection_cleanup.h
+++ b/src/lib/connection_cleanup.h
@@ -18,7 +18,7 @@
18*/ 18*/
19/** 19/**
20 * @file lib/connection_cleanup.h 20 * @file lib/connection_cleanup.h
21 * @brief functions to cleanup completed connection 21 * @brief functions to cleanup completed connection
22 * @author Christian Grothoff 22 * @author Christian Grothoff
23 */ 23 */
24#ifndef CONNECTION_CLEANUP_H 24#ifndef CONNECTION_CLEANUP_H
@@ -28,7 +28,7 @@
28/** 28/**
29 * Free resources associated with all closed connections. (destroy 29 * Free resources associated with all closed connections. (destroy
30 * responses, free buffers, etc.). All closed connections are kept in 30 * responses, free buffers, etc.). All closed connections are kept in
31 * the "cleanup" doubly-linked list. 31 * the "cleanup" doubly-linked list.
32 * 32 *
33 * @remark To be called only from thread that process daemon's 33 * @remark To be called only from thread that process daemon's
34 * select()/poll()/etc. 34 * select()/poll()/etc.
@@ -37,6 +37,6 @@
37 */ 37 */
38void 38void
39MHD_connection_cleanup_ (struct MHD_Daemon *daemon) 39MHD_connection_cleanup_ (struct MHD_Daemon *daemon)
40 MHD_NONNULL (1); 40MHD_NONNULL (1);
41 41
42#endif 42#endif
diff --git a/src/lib/connection_close.c b/src/lib/connection_close.c
index 945997db..3c872b0b 100644
--- a/src/lib/connection_close.c
+++ b/src/lib/connection_close.c
@@ -40,33 +40,33 @@ MHD_connection_mark_closed_ (struct MHD_Connection *connection)
40 connection->request.state = MHD_REQUEST_CLOSED; 40 connection->request.state = MHD_REQUEST_CLOSED;
41 connection->request.event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; 41 connection->request.event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
42 if (! daemon->enable_turbo) 42 if (! daemon->enable_turbo)
43 { 43 {
44#ifdef HTTPS_SUPPORT 44#ifdef HTTPS_SUPPORT
45 struct MHD_TLS_Plugin *tls; 45 struct MHD_TLS_Plugin *tls;
46 46
47 /* For TLS connection use shutdown of TLS layer 47 /* For TLS connection use shutdown of TLS layer
48 * and do not shutdown TCP socket. This give more 48 * and do not shutdown TCP socket. This give more
49 * chances to send TLS closure data to remote side. 49 * chances to send TLS closure data to remote side.
50 * Closure of TLS layer will be interpreted by 50 * Closure of TLS layer will be interpreted by
51 * remote side as end of transmission. */ 51 * remote side as end of transmission. */
52 if (NULL != (tls = daemon->tls_api)) 52 if (NULL != (tls = daemon->tls_api))
53 { 53 {
54 if (MHD_YES != 54 if (MHD_YES !=
55 tls->shutdown_connection (tls->cls, 55 tls->shutdown_connection (tls->cls,
56 connection->tls_cs)) 56 connection->tls_cs))
57 { 57 {
58 (void) shutdown (connection->socket_fd, 58 (void) shutdown (connection->socket_fd,
59 SHUT_WR); 59 SHUT_WR);
60 /* FIXME: log errors */ 60 /* FIXME: log errors */
61 } 61 }
62 } 62 }
63 else /* Combined with next 'shutdown()'. */ 63 else /* Combined with next 'shutdown()'. */
64#endif /* HTTPS_SUPPORT */ 64#endif /* HTTPS_SUPPORT */
65 { 65 {
66 (void) shutdown (connection->socket_fd, 66 (void) shutdown (connection->socket_fd,
67 SHUT_WR); /* FIXME: log errors */ 67 SHUT_WR); /* FIXME: log errors */
68 }
69 } 68 }
69 }
70} 70}
71 71
72 72
@@ -90,14 +90,14 @@ MHD_connection_close_ (struct MHD_Connection *connection,
90 (void) rtc; // FIXME 90 (void) rtc; // FIXME
91 MHD_connection_mark_closed_ (connection); 91 MHD_connection_mark_closed_ (connection);
92 if (NULL != resp) 92 if (NULL != resp)
93 { 93 {
94 connection->request.response = NULL; 94 connection->request.response = NULL;
95 MHD_response_queue_for_destroy (resp); 95 MHD_response_queue_for_destroy (resp);
96 } 96 }
97 if (NULL != daemon->notify_connection_cb) 97 if (NULL != daemon->notify_connection_cb)
98 daemon->notify_connection_cb (daemon->notify_connection_cb_cls, 98 daemon->notify_connection_cb (daemon->notify_connection_cb_cls,
99 connection, 99 connection,
100 MHD_CONNECTION_NOTIFY_CLOSED); 100 MHD_CONNECTION_NOTIFY_CLOSED);
101} 101}
102 102
103/* end of connection_close.c */ 103/* end of connection_close.c */
diff --git a/src/lib/connection_close.h b/src/lib/connection_close.h
index 41f141d2..c8e159ee 100644
--- a/src/lib/connection_close.h
+++ b/src/lib/connection_close.h
@@ -35,7 +35,7 @@
35 */ 35 */
36void 36void
37MHD_connection_mark_closed_ (struct MHD_Connection *connection) 37MHD_connection_mark_closed_ (struct MHD_Connection *connection)
38 MHD_NONNULL (1); 38MHD_NONNULL (1);
39 39
40 40
41/** 41/**
@@ -51,6 +51,6 @@ MHD_connection_mark_closed_ (struct MHD_Connection *connection)
51void 51void
52MHD_connection_close_ (struct MHD_Connection *connection, 52MHD_connection_close_ (struct MHD_Connection *connection,
53 enum MHD_RequestTerminationCode rtc) 53 enum MHD_RequestTerminationCode rtc)
54 MHD_NONNULL (1); 54MHD_NONNULL (1);
55 55
56#endif 56#endif
diff --git a/src/lib/connection_finish_forward.c b/src/lib/connection_finish_forward.c
index 335a03bf..1ea9aa31 100644
--- a/src/lib/connection_finish_forward.c
+++ b/src/lib/connection_finish_forward.c
@@ -55,34 +55,34 @@ MHD_connection_finish_forward_ (struct MHD_Connection *connection)
55 EPOLL_CTL_DEL, 55 EPOLL_CTL_DEL,
56 connection->socket_fd, 56 connection->socket_fd,
57 NULL)) ) 57 NULL)) )
58 { 58 {
59 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 59 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
60 } 60 }
61 if (urh->in_eready_list) 61 if (urh->in_eready_list)
62 { 62 {
63 EDLL_remove (daemon->eready_urh_head, 63 EDLL_remove (daemon->eready_urh_head,
64 daemon->eready_urh_tail, 64 daemon->eready_urh_tail,
65 urh); 65 urh);
66 urh->in_eready_list = false; 66 urh->in_eready_list = false;
67 } 67 }
68#endif /* EPOLL_SUPPORT */ 68#endif /* EPOLL_SUPPORT */
69 if (MHD_INVALID_SOCKET != urh->mhd.socket) 69 if (MHD_INVALID_SOCKET != urh->mhd.socket)
70 { 70 {
71#if EPOLL_SUPPORT 71#if EPOLL_SUPPORT
72 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 72 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
73 (0 != epoll_ctl (daemon->epoll_upgrade_fd, 73 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
74 EPOLL_CTL_DEL, 74 EPOLL_CTL_DEL,
75 urh->mhd.socket, 75 urh->mhd.socket,
76 NULL)) ) 76 NULL)) )
77 { 77 {
78 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 78 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
79 }
80#endif /* EPOLL_SUPPORT */
81 /* Reflect remote disconnect to application by breaking
82 * socketpair connection. */
83 shutdown (urh->mhd.socket,
84 SHUT_RDWR);
85 } 79 }
80#endif /* EPOLL_SUPPORT */
81 /* Reflect remote disconnect to application by breaking
82 * socketpair connection. */
83 shutdown (urh->mhd.socket,
84 SHUT_RDWR);
85 }
86 /* Socketpair sockets will remain open as they will be 86 /* Socketpair sockets will remain open as they will be
87 * used with MHD_UPGRADE_ACTION_CLOSE. They will be 87 * used with MHD_UPGRADE_ACTION_CLOSE. They will be
88 * closed by MHD_cleanup_upgraded_connection_() during 88 * closed by MHD_cleanup_upgraded_connection_() during
diff --git a/src/lib/connection_finish_forward.h b/src/lib/connection_finish_forward.h
index c6c04f42..ebb77d12 100644
--- a/src/lib/connection_finish_forward.h
+++ b/src/lib/connection_finish_forward.h
@@ -39,6 +39,6 @@
39 */ 39 */
40void 40void
41MHD_connection_finish_forward_ (struct MHD_Connection *connection) 41MHD_connection_finish_forward_ (struct MHD_Connection *connection)
42 MHD_NONNULL (1); 42MHD_NONNULL (1);
43 43
44#endif 44#endif
diff --git a/src/lib/connection_info.c b/src/lib/connection_info.c
index 88055fa4..d83b34c5 100644
--- a/src/lib/connection_info.c
+++ b/src/lib/connection_info.c
@@ -42,13 +42,13 @@
42 */ 42 */
43enum MHD_Bool 43enum MHD_Bool
44MHD_connection_get_information_sz (struct MHD_Connection *connection, 44MHD_connection_get_information_sz (struct MHD_Connection *connection,
45 enum MHD_ConnectionInformationType info_type, 45 enum MHD_ConnectionInformationType info_type,
46 union MHD_ConnectionInformation *return_value, 46 union MHD_ConnectionInformation *return_value,
47 size_t return_value_size) 47 size_t return_value_size)
48{ 48{
49#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \ 49#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \
50 return MHD_NO 50 return MHD_NO
51 51
52 switch (info_type) 52 switch (info_type)
53 { 53 {
54#ifdef HTTPS_SUPPORT 54#ifdef HTTPS_SUPPORT
@@ -63,7 +63,7 @@ MHD_connection_get_information_sz (struct MHD_Connection *connection,
63 CHECK_SIZE (int); 63 CHECK_SIZE (int);
64 if (NULL == connection->tls_cs) 64 if (NULL == connection->tls_cs)
65 return MHD_NO; 65 return MHD_NO;
66 //return_value->protocol 66 // return_value->protocol
67 // = gnutls_protocol_get_version (connection->tls_session); 67 // = gnutls_protocol_get_version (connection->tls_session);
68 return MHD_NO; // FIXME: to be implemented 68 return MHD_NO; // FIXME: to be implemented
69 case MHD_CONNECTION_INFORMATION_GNUTLS_SESSION: 69 case MHD_CONNECTION_INFORMATION_GNUTLS_SESSION:
@@ -103,7 +103,7 @@ MHD_connection_get_information_sz (struct MHD_Connection *connection,
103 default: 103 default:
104 return MHD_NO; 104 return MHD_NO;
105 } 105 }
106 106
107#undef CHECK_SIZE 107#undef CHECK_SIZE
108} 108}
109 109
diff --git a/src/lib/connection_options.c b/src/lib/connection_options.c
index 00652161..ce31b315 100644
--- a/src/lib/connection_options.c
+++ b/src/lib/connection_options.c
@@ -35,44 +35,44 @@
35 */ 35 */
36void 36void
37MHD_connection_set_timeout (struct MHD_Connection *connection, 37MHD_connection_set_timeout (struct MHD_Connection *connection,
38 unsigned int timeout_s) 38 unsigned int timeout_s)
39{ 39{
40 struct MHD_Daemon *daemon = connection->daemon; 40 struct MHD_Daemon *daemon = connection->daemon;
41 41
42 connection->last_activity = MHD_monotonic_sec_counter(); 42 connection->last_activity = MHD_monotonic_sec_counter ();
43 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 43 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
44 { 44 {
45 /* Simple case, no need to lock to update DLLs */ 45 /* Simple case, no need to lock to update DLLs */
46 connection->connection_timeout = (time_t) timeout_s; 46 connection->connection_timeout = (time_t) timeout_s;
47 return; 47 return;
48 } 48 }
49 49
50 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 50 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
51 if (! connection->suspended) 51 if (! connection->suspended)
52 { 52 {
53 if (connection->connection_timeout == 53 if (connection->connection_timeout ==
54 daemon->connection_default_timeout) 54 daemon->connection_default_timeout)
55 XDLL_remove (daemon->normal_timeout_head, 55 XDLL_remove (daemon->normal_timeout_head,
56 daemon->normal_timeout_tail, 56 daemon->normal_timeout_tail,
57 connection); 57 connection);
58 else 58 else
59 XDLL_remove (daemon->manual_timeout_head, 59 XDLL_remove (daemon->manual_timeout_head,
60 daemon->manual_timeout_tail, 60 daemon->manual_timeout_tail,
61 connection); 61 connection);
62 } 62 }
63 connection->connection_timeout = (time_t) timeout_s; 63 connection->connection_timeout = (time_t) timeout_s;
64 if (! connection->suspended) 64 if (! connection->suspended)
65 { 65 {
66 if (connection->connection_timeout == 66 if (connection->connection_timeout ==
67 daemon->connection_default_timeout) 67 daemon->connection_default_timeout)
68 XDLL_insert (daemon->normal_timeout_head, 68 XDLL_insert (daemon->normal_timeout_head,
69 daemon->normal_timeout_tail, 69 daemon->normal_timeout_tail,
70 connection); 70 connection);
71 else 71 else
72 XDLL_insert (daemon->manual_timeout_head, 72 XDLL_insert (daemon->manual_timeout_head,
73 daemon->manual_timeout_tail, 73 daemon->manual_timeout_tail,
74 connection); 74 connection);
75 } 75 }
76 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 76 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
77} 77}
78 78
@@ -95,7 +95,7 @@ MHD_update_last_activity_ (struct MHD_Connection *connection)
95 if (connection->suspended) 95 if (connection->suspended)
96 return; /* no activity on suspended connections */ 96 return; /* no activity on suspended connections */
97 97
98 connection->last_activity = MHD_monotonic_sec_counter(); 98 connection->last_activity = MHD_monotonic_sec_counter ();
99 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 99 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
100 return; /* each connection has personal timeout */ 100 return; /* each connection has personal timeout */
101 101
@@ -106,11 +106,11 @@ MHD_update_last_activity_ (struct MHD_Connection *connection)
106 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 106 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
107 /* move connection to head of timeout list (by remove + add operation) */ 107 /* move connection to head of timeout list (by remove + add operation) */
108 XDLL_remove (daemon->normal_timeout_head, 108 XDLL_remove (daemon->normal_timeout_head,
109 daemon->normal_timeout_tail, 109 daemon->normal_timeout_tail,
110 connection); 110 connection);
111 XDLL_insert (daemon->normal_timeout_head, 111 XDLL_insert (daemon->normal_timeout_head,
112 daemon->normal_timeout_tail, 112 daemon->normal_timeout_tail,
113 connection); 113 connection);
114 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 114 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
115} 115}
116 116
diff --git a/src/lib/connection_update_last_activity.c b/src/lib/connection_update_last_activity.c
index 7253dc83..741da681 100644
--- a/src/lib/connection_update_last_activity.c
+++ b/src/lib/connection_update_last_activity.c
@@ -43,7 +43,7 @@ MHD_connection_update_last_activity_ (struct MHD_Connection *connection)
43 if (connection->suspended) 43 if (connection->suspended)
44 return; /* no activity on suspended connections */ 44 return; /* no activity on suspended connections */
45 45
46 connection->last_activity = MHD_monotonic_sec_counter(); 46 connection->last_activity = MHD_monotonic_sec_counter ();
47 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 47 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
48 return; /* each connection has personal timeout */ 48 return; /* each connection has personal timeout */
49 49
@@ -53,13 +53,12 @@ MHD_connection_update_last_activity_ (struct MHD_Connection *connection)
53 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 53 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
54 /* move connection to head of timeout list (by remove + add operation) */ 54 /* move connection to head of timeout list (by remove + add operation) */
55 XDLL_remove (daemon->normal_timeout_head, 55 XDLL_remove (daemon->normal_timeout_head,
56 daemon->normal_timeout_tail, 56 daemon->normal_timeout_tail,
57 connection); 57 connection);
58 XDLL_insert (daemon->normal_timeout_head, 58 XDLL_insert (daemon->normal_timeout_head,
59 daemon->normal_timeout_tail, 59 daemon->normal_timeout_tail,
60 connection); 60 connection);
61 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 61 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
62} 62}
63 63
64/* end of connection_update_last_activity.c */ 64/* end of connection_update_last_activity.c */
65
diff --git a/src/lib/connection_update_last_activity.h b/src/lib/connection_update_last_activity.h
index 8383b6be..ee9f9975 100644
--- a/src/lib/connection_update_last_activity.h
+++ b/src/lib/connection_update_last_activity.h
@@ -35,6 +35,6 @@
35 */ 35 */
36void 36void
37MHD_connection_update_last_activity_ (struct MHD_Connection *connection) 37MHD_connection_update_last_activity_ (struct MHD_Connection *connection)
38 MHD_NONNULL (1); 38MHD_NONNULL (1);
39 39
40#endif 40#endif
diff --git a/src/lib/daemon_close_all_connections.c b/src/lib/daemon_close_all_connections.c
index d4b825da..1a777494 100644
--- a/src/lib/daemon_close_all_connections.c
+++ b/src/lib/daemon_close_all_connections.c
@@ -45,10 +45,10 @@ close_connection (struct MHD_Connection *pos)
45 struct MHD_Daemon *daemon = pos->daemon; 45 struct MHD_Daemon *daemon = pos->daemon;
46 46
47 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 47 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
48 { 48 {
49 MHD_connection_mark_closed_ (pos); 49 MHD_connection_mark_closed_ (pos);
50 return; /* must let thread to do the rest */ 50 return; /* must let thread to do the rest */
51 } 51 }
52 MHD_connection_close_ (pos, 52 MHD_connection_close_ (pos,
53 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); 53 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
54 54
@@ -59,18 +59,18 @@ close_connection (struct MHD_Connection *pos)
59 if (pos->connection_timeout == 59 if (pos->connection_timeout ==
60 pos->daemon->connection_default_timeout) 60 pos->daemon->connection_default_timeout)
61 XDLL_remove (daemon->normal_timeout_head, 61 XDLL_remove (daemon->normal_timeout_head,
62 daemon->normal_timeout_tail, 62 daemon->normal_timeout_tail,
63 pos); 63 pos);
64 else 64 else
65 XDLL_remove (daemon->manual_timeout_head, 65 XDLL_remove (daemon->manual_timeout_head,
66 daemon->manual_timeout_tail, 66 daemon->manual_timeout_tail,
67 pos); 67 pos);
68 DLL_remove (daemon->connections_head, 68 DLL_remove (daemon->connections_head,
69 daemon->connections_tail, 69 daemon->connections_tail,
70 pos); 70 pos);
71 DLL_insert (daemon->cleanup_head, 71 DLL_insert (daemon->cleanup_head,
72 daemon->cleanup_tail, 72 daemon->cleanup_tail,
73 pos); 73 pos);
74 74
75 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 75 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
76} 76}
@@ -89,7 +89,8 @@ void
89MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon) 89MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
90{ 90{
91 struct MHD_Connection *pos; 91 struct MHD_Connection *pos;
92 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode); 92 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION ==
93 daemon->threading_mode);
93#ifdef UPGRADE_SUPPORT 94#ifdef UPGRADE_SUPPORT
94 const bool upg_allowed = (! daemon->disallow_upgrade); 95 const bool upg_allowed = (! daemon->disallow_upgrade);
95#endif /* UPGRADE_SUPPORT */ 96#endif /* UPGRADE_SUPPORT */
@@ -103,16 +104,16 @@ MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
103 /* give upgraded HTTPS connections a chance to finish */ 104 /* give upgraded HTTPS connections a chance to finish */
104 /* 'daemon->urh_head' is not used in thread-per-connection mode. */ 105 /* 'daemon->urh_head' is not used in thread-per-connection mode. */
105 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 106 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
106 { 107 {
107 urhn = urh->prev; 108 urhn = urh->prev;
108 /* call generic forwarding function for passing data 109 /* call generic forwarding function for passing data
109 with chance to detect that application is done. */ 110 with chance to detect that application is done. */
110 MHD_upgrade_response_handle_process_ (urh); 111 MHD_upgrade_response_handle_process_ (urh);
111 MHD_connection_finish_forward_ (urh->connection); 112 MHD_connection_finish_forward_ (urh->connection);
112 urh->clean_ready = true; 113 urh->clean_ready = true;
113 /* Resuming will move connection to cleanup list. */ 114 /* Resuming will move connection to cleanup list. */
114 MHD_request_resume (&urh->connection->request); 115 MHD_request_resume (&urh->connection->request);
115 } 116 }
116#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 117#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
117 118
118 /* Give suspended connections a chance to resume to avoid 119 /* Give suspended connections a chance to resume to avoid
@@ -120,89 +121,93 @@ MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
120 connections left in case of a tight race with a recently 121 connections left in case of a tight race with a recently
121 resumed connection. */ 122 resumed connection. */
122 if (! daemon->disallow_suspend_resume) 123 if (! daemon->disallow_suspend_resume)
123 { 124 {
124 daemon->resuming = true; /* Force check for pending resume. */ 125 daemon->resuming = true; /* Force check for pending resume. */
125 MHD_resume_suspended_connections_ (daemon); 126 MHD_resume_suspended_connections_ (daemon);
126 } 127 }
127 /* first, make sure all threads are aware of shutdown; need to 128 /* first, make sure all threads are aware of shutdown; need to
128 traverse DLLs in peace... */ 129 traverse DLLs in peace... */
129 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 130 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
130#ifdef UPGRADE_SUPPORT 131#ifdef UPGRADE_SUPPORT
131 if (upg_allowed) 132 if (upg_allowed)
132 { 133 {
133 struct MHD_Connection * susp; 134 struct MHD_Connection *susp;
134 135
135 susp = daemon->suspended_connections_tail; 136 susp = daemon->suspended_connections_tail;
136 while (NULL != susp) 137 while (NULL != susp)
137 { 138 {
138 if (NULL == susp->request.urh) /* "Upgraded" connection? */ 139 if (NULL == susp->request.urh) /* "Upgraded" connection? */
139 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 140 MHD_PANIC (_ (
141 "MHD_stop_daemon() called while we have suspended connections.\n"));
140#ifdef HTTPS_SUPPORT 142#ifdef HTTPS_SUPPORT
141 else if (used_tls && 143 else if (used_tls &&
142 used_thr_p_c && 144 used_thr_p_c &&
143 (! susp->request.urh->clean_ready) ) 145 (! susp->request.urh->clean_ready) )
144 shutdown (susp->request.urh->app.socket, 146 shutdown (susp->request.urh->app.socket,
145 SHUT_RDWR); /* Wake thread by shutdown of app socket. */ 147 SHUT_RDWR); /* Wake thread by shutdown of app socket. */
146#endif /* HTTPS_SUPPORT */ 148#endif /* HTTPS_SUPPORT */
147 else 149 else
148 { 150 {
149#ifdef HAVE_MESSAGES 151#ifdef HAVE_MESSAGES
150 if (! susp->request.urh->was_closed) 152 if (! susp->request.urh->was_closed)
151 MHD_DLOG (daemon, 153 MHD_DLOG (daemon,
152 MHD_SC_SHUTDOWN_WITH_OPEN_UPGRADED_CONNECTION, 154 MHD_SC_SHUTDOWN_WITH_OPEN_UPGRADED_CONNECTION,
153 _("Initiated daemon shutdown while \"upgraded\" connection was not closed.\n")); 155 _ (
156 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
154#endif 157#endif
155 susp->request.urh->was_closed = true; 158 susp->request.urh->was_closed = true;
156 /* If thread-per-connection is used, connection's thread 159 /* If thread-per-connection is used, connection's thread
157 * may still processing "upgrade" (exiting). */ 160 * may still processing "upgrade" (exiting). */
158 if (! used_thr_p_c) 161 if (! used_thr_p_c)
159 MHD_connection_finish_forward_ (susp); 162 MHD_connection_finish_forward_ (susp);
160 /* Do not use MHD_resume_connection() as mutex is 163 /* Do not use MHD_resume_connection() as mutex is
161 * already locked. */ 164 * already locked. */
162 susp->resuming = true; 165 susp->resuming = true;
163 daemon->resuming = true; 166 daemon->resuming = true;
164 } 167 }
165 susp = susp->prev; 168 susp = susp->prev;
166 }
167 } 169 }
170 }
168 else /* This 'else' is combined with next 'if' */ 171 else /* This 'else' is combined with next 'if' */
169#endif /* UPGRADE_SUPPORT */ 172#endif /* UPGRADE_SUPPORT */
170 if (NULL != daemon->suspended_connections_head) 173 if (NULL != daemon->suspended_connections_head)
171 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 174 MHD_PANIC (_ (
175 "MHD_stop_daemon() called while we have suspended connections.\n"));
172 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) 176 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
173 { 177 {
174 shutdown (pos->socket_fd, 178 shutdown (pos->socket_fd,
175 SHUT_RDWR); 179 SHUT_RDWR);
176#if MHD_WINSOCK_SOCKETS 180#if MHD_WINSOCK_SOCKETS
177 if ( (used_thr_p_c) && 181 if ( (used_thr_p_c) &&
178 (MHD_ITC_IS_VALID_(daemon->itc)) && 182 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
179 (! MHD_itc_activate_ (daemon->itc, 183 (! MHD_itc_activate_ (daemon->itc,
180 "e")) ) 184 "e")) )
181 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel")); 185 MHD_PANIC (_ (
186 "Failed to signal shutdown via inter-thread communication channel"));
182#endif 187#endif
183 } 188 }
184 189
185 /* now, collect per-connection threads */ 190 /* now, collect per-connection threads */
186 if (used_thr_p_c) 191 if (used_thr_p_c)
192 {
193 pos = daemon->connections_tail;
194 while (NULL != pos)
187 { 195 {
188 pos = daemon->connections_tail; 196 if (! pos->thread_joined)
189 while (NULL != pos)
190 { 197 {
191 if (! pos->thread_joined) 198 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
192 { 199 if (! MHD_join_thread_ (pos->pid.handle))
193 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 200 MHD_PANIC (_ ("Failed to join a thread\n"));
194 if (! MHD_join_thread_ (pos->pid.handle)) 201 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
195 MHD_PANIC (_("Failed to join a thread\n")); 202 pos->thread_joined = true;
196 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 203 /* The thread may have concurrently modified the DLL,
197 pos->thread_joined = true; 204 need to restart from the beginning */
198 /* The thread may have concurrently modified the DLL, 205 pos = daemon->connections_tail;
199 need to restart from the beginning */ 206 continue;
200 pos = daemon->connections_tail;
201 continue;
202 }
203 pos = pos->prev;
204 } 207 }
208 pos = pos->prev;
205 } 209 }
210 }
206 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 211 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
207 212
208#ifdef UPGRADE_SUPPORT 213#ifdef UPGRADE_SUPPORT
@@ -211,10 +216,10 @@ MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
211 /* "Upgraded" connections that were not closed explicitly by 216 /* "Upgraded" connections that were not closed explicitly by
212 * application should be moved to cleanup list too. */ 217 * application should be moved to cleanup list too. */
213 if (upg_allowed) 218 if (upg_allowed)
214 { 219 {
215 daemon->resuming = true; /* Force check for pending resume. */ 220 daemon->resuming = true; /* Force check for pending resume. */
216 MHD_resume_suspended_connections_ (daemon); 221 MHD_resume_suspended_connections_ (daemon);
217 } 222 }
218#endif /* UPGRADE_SUPPORT */ 223#endif /* UPGRADE_SUPPORT */
219 224
220 /* now that we're alone, move everyone to cleanup */ 225 /* now that we're alone, move everyone to cleanup */
@@ -222,7 +227,7 @@ MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
222 { 227 {
223 if ( (used_thr_p_c) && 228 if ( (used_thr_p_c) &&
224 (! pos->thread_joined) ) 229 (! pos->thread_joined) )
225 MHD_PANIC (_("Failed to join a thread\n")); 230 MHD_PANIC (_ ("Failed to join a thread\n"));
226 close_connection (pos); 231 close_connection (pos);
227 } 232 }
228 MHD_connection_cleanup_ (daemon); 233 MHD_connection_cleanup_ (daemon);
diff --git a/src/lib/daemon_close_all_connections.h b/src/lib/daemon_close_all_connections.h
index 340b0d47..2716f9ba 100644
--- a/src/lib/daemon_close_all_connections.h
+++ b/src/lib/daemon_close_all_connections.h
@@ -37,6 +37,6 @@
37 */ 37 */
38void 38void
39MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon) 39MHD_daemon_close_all_connections_ (struct MHD_Daemon *daemon)
40 MHD_NONNULL (1); 40MHD_NONNULL (1);
41 41
42#endif 42#endif
diff --git a/src/lib/daemon_create.c b/src/lib/daemon_create.c
index a2173d88..cd3d0ec4 100644
--- a/src/lib/daemon_create.c
+++ b/src/lib/daemon_create.c
@@ -38,16 +38,16 @@
38 */ 38 */
39static void 39static void
40file_logger (void *cls, 40file_logger (void *cls,
41 enum MHD_StatusCode sc, 41 enum MHD_StatusCode sc,
42 const char *fm, 42 const char *fm,
43 va_list ap) 43 va_list ap)
44{ 44{
45 FILE *f = cls; 45 FILE *f = cls;
46 46
47 (void) sc; 47 (void) sc;
48 (void) vfprintf (f, 48 (void) vfprintf (f,
49 fm, 49 fm,
50 ap); 50 ap);
51} 51}
52 52
53 53
@@ -84,16 +84,16 @@ unescape_wrapper (void *cls,
84 */ 84 */
85struct MHD_Daemon * 85struct MHD_Daemon *
86MHD_daemon_create (MHD_RequestCallback cb, 86MHD_daemon_create (MHD_RequestCallback cb,
87 void *cb_cls) 87 void *cb_cls)
88{ 88{
89 struct MHD_Daemon *daemon; 89 struct MHD_Daemon *daemon;
90 90
91 MHD_check_global_init_(); 91 MHD_check_global_init_ ();
92 if (NULL == (daemon = malloc (sizeof (struct MHD_Daemon)))) 92 if (NULL == (daemon = malloc (sizeof (struct MHD_Daemon))))
93 return NULL; 93 return NULL;
94 memset (daemon, 94 memset (daemon,
95 0, 95 0,
96 sizeof (struct MHD_Daemon)); 96 sizeof (struct MHD_Daemon));
97#ifdef EPOLL_SUPPORT 97#ifdef EPOLL_SUPPORT
98 daemon->epoll_itc_marker = "itc_marker"; 98 daemon->epoll_itc_marker = "itc_marker";
99#endif 99#endif
@@ -107,29 +107,29 @@ MHD_daemon_create (MHD_RequestCallback cb,
107#if ENABLE_DAUTH 107#if ENABLE_DAUTH
108 daemon->digest_nc_length = DIGEST_NC_LENGTH_DEFAULT; 108 daemon->digest_nc_length = DIGEST_NC_LENGTH_DEFAULT;
109#endif 109#endif
110 daemon->listen_backlog = LISTEN_BACKLOG_DEFAULT; 110 daemon->listen_backlog = LISTEN_BACKLOG_DEFAULT;
111 daemon->fo_queue_length = FO_QUEUE_LENGTH_DEFAULT; 111 daemon->fo_queue_length = FO_QUEUE_LENGTH_DEFAULT;
112 daemon->listen_socket = MHD_INVALID_SOCKET; 112 daemon->listen_socket = MHD_INVALID_SOCKET;
113 113
114 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) 114 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
115 { 115 {
116 free (daemon); 116 free (daemon);
117 return NULL; 117 return NULL;
118 } 118 }
119 if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) 119 if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex))
120 { 120 {
121 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 121 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
122 free (daemon); 122 free (daemon);
123 return NULL; 123 return NULL;
124 } 124 }
125#ifdef DAUTH_SUPPORT 125#ifdef DAUTH_SUPPORT
126 if (! MHD_mutex_init_ (&daemon->nnc_lock)) 126 if (! MHD_mutex_init_ (&daemon->nnc_lock))
127 { 127 {
128 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 128 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
129 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); 129 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
130 free (daemon); 130 free (daemon);
131 return NULL; 131 return NULL;
132 } 132 }
133#endif 133#endif
134 return daemon; 134 return daemon;
135} 135}
diff --git a/src/lib/daemon_destroy.c b/src/lib/daemon_destroy.c
index b4f34d16..a76c2d6b 100644
--- a/src/lib/daemon_destroy.c
+++ b/src/lib/daemon_destroy.c
@@ -46,35 +46,36 @@ stop_workers (struct MHD_Daemon *daemon)
46 fd = daemon->listen_socket; 46 fd = daemon->listen_socket;
47 /* Let workers shutdown in parallel. */ 47 /* Let workers shutdown in parallel. */
48 for (i = 0; i < daemon->worker_pool_size; i++) 48 for (i = 0; i < daemon->worker_pool_size; i++)
49 {
50 daemon->worker_pool[i].shutdown = true;
51 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc))
49 { 52 {
50 daemon->worker_pool[i].shutdown = true; 53 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc,
51 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc)) 54 "e"))
52 { 55 MHD_PANIC (_ (
53 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, 56 "Failed to signal shutdown via inter-thread communication channel."));
54 "e"))
55 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel."));
56 }
57 else
58 {
59 /* Better hope shutdown() works... */
60 mhd_assert (MHD_INVALID_SOCKET != fd);
61 }
62 } 57 }
63#ifdef HAVE_LISTEN_SHUTDOWN 58 else
64 if (MHD_INVALID_SOCKET != fd)
65 { 59 {
66 (void) shutdown (fd, 60 /* Better hope shutdown() works... */
67 SHUT_RDWR); 61 mhd_assert (MHD_INVALID_SOCKET != fd);
68 } 62 }
63 }
64#ifdef HAVE_LISTEN_SHUTDOWN
65 if (MHD_INVALID_SOCKET != fd)
66 {
67 (void) shutdown (fd,
68 SHUT_RDWR);
69 }
69#endif /* HAVE_LISTEN_SHUTDOWN */ 70#endif /* HAVE_LISTEN_SHUTDOWN */
70 for (i = 0; i < daemon->worker_pool_size; ++i) 71 for (i = 0; i < daemon->worker_pool_size; ++i)
71 { 72 {
72 MHD_daemon_destroy (&daemon->worker_pool[i]); 73 MHD_daemon_destroy (&daemon->worker_pool[i]);
73 } 74 }
74 free (daemon->worker_pool); 75 free (daemon->worker_pool);
75 daemon->worker_pool = NULL; 76 daemon->worker_pool = NULL;
76 /* FIXME: does this still hold? */ 77 /* FIXME: does this still hold? */
77 mhd_assert (MHD_ITC_IS_INVALID_(daemon->itc)); 78 mhd_assert (MHD_ITC_IS_INVALID_ (daemon->itc));
78#ifdef EPOLL_SUPPORT 79#ifdef EPOLL_SUPPORT
79 mhd_assert (-1 == daemon->epoll_fd); 80 mhd_assert (-1 == daemon->epoll_fd);
80#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 81#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -104,65 +105,66 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon)
104 /* FIXME: convert from here to microhttpd2-style API! */ 105 /* FIXME: convert from here to microhttpd2-style API! */
105 106
106 if (NULL != daemon->worker_pool) 107 if (NULL != daemon->worker_pool)
107 { /* Master daemon with worker pool. */ 108 { /* Master daemon with worker pool. */
108 stop_workers (daemon); 109 stop_workers (daemon);
109 } 110 }
110 else 111 else
112 {
113 mhd_assert (0 == daemon->worker_pool_size);
114 /* Worker daemon or single-thread daemon. */
115 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode)
111 { 116 {
112 mhd_assert (0 == daemon->worker_pool_size); 117 /* Worker daemon or single daemon with internal thread(s). */
113 /* Worker daemon or single-thread daemon. */ 118 /* Separate thread(s) is used for polling sockets. */
114 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) 119 if (MHD_ITC_IS_VALID_ (daemon->itc))
115 { 120 {
116 /* Worker daemon or single daemon with internal thread(s). */ 121 if (! MHD_itc_activate_ (daemon->itc,
117 /* Separate thread(s) is used for polling sockets. */ 122 "e"))
118 if (MHD_ITC_IS_VALID_(daemon->itc)) 123 MHD_PANIC (_ (
119 { 124 "Failed to signal shutdown via inter-thread communication channel"));
120 if (! MHD_itc_activate_ (daemon->itc, 125 }
121 "e"))
122 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel"));
123 }
124 else
125 {
126#ifdef HAVE_LISTEN_SHUTDOWN
127 if (MHD_INVALID_SOCKET != fd)
128 {
129 if (NULL == daemon->master)
130 (void) shutdown (fd,
131 SHUT_RDWR);
132 }
133 else
134#endif /* HAVE_LISTEN_SHUTDOWN */
135 mhd_assert (false); /* Should never happen */
136 }
137
138 if (! MHD_join_thread_ (daemon->pid.handle))
139 {
140 MHD_PANIC (_("Failed to join a thread\n"));
141 }
142 /* close_all_connections() was called in daemon thread. */
143 }
144 else 126 else
127 {
128#ifdef HAVE_LISTEN_SHUTDOWN
129 if (MHD_INVALID_SOCKET != fd)
145 { 130 {
146 /* No internal threads are used for polling sockets 131 if (NULL == daemon->master)
147 (external event loop) */ 132 (void) shutdown (fd,
148 MHD_daemon_close_all_connections_ (daemon); 133 SHUT_RDWR);
149 } 134 }
150 if (MHD_ITC_IS_VALID_ (daemon->itc)) 135 else
151 MHD_itc_destroy_chk_ (daemon->itc); 136#endif /* HAVE_LISTEN_SHUTDOWN */
137 mhd_assert (false); /* Should never happen */
138 }
139
140 if (! MHD_join_thread_ (daemon->pid.handle))
141 {
142 MHD_PANIC (_ ("Failed to join a thread\n"));
143 }
144 /* close_all_connections() was called in daemon thread. */
145 }
146 else
147 {
148 /* No internal threads are used for polling sockets
149 (external event loop) */
150 MHD_daemon_close_all_connections_ (daemon);
151 }
152 if (MHD_ITC_IS_VALID_ (daemon->itc))
153 MHD_itc_destroy_chk_ (daemon->itc);
152 154
153#ifdef EPOLL_SUPPORT 155#ifdef EPOLL_SUPPORT
154 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 156 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
155 (-1 != daemon->epoll_fd) ) 157 (-1 != daemon->epoll_fd) )
156 MHD_socket_close_chk_ (daemon->epoll_fd); 158 MHD_socket_close_chk_ (daemon->epoll_fd);
157#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 159#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
158 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 160 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
159 (-1 != daemon->epoll_upgrade_fd) ) 161 (-1 != daemon->epoll_upgrade_fd) )
160 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd); 162 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
161#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 163#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
162#endif /* EPOLL_SUPPORT */ 164#endif /* EPOLL_SUPPORT */
163 165
164 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 166 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
165 } 167 }
166 168
167 if (NULL != daemon->master) 169 if (NULL != daemon->master)
168 return; 170 return;
@@ -175,18 +177,18 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon)
175 /* TLS clean up */ 177 /* TLS clean up */
176#ifdef HTTPS_SUPPORT 178#ifdef HTTPS_SUPPORT
177 if (NULL != daemon->tls_api) 179 if (NULL != daemon->tls_api)
178 { 180 {
179#if FIXME_TLS_API 181#if FIXME_TLS_API
180 if (daemon->have_dhparams) 182 if (daemon->have_dhparams)
181 { 183 {
182 gnutls_dh_params_deinit (daemon->https_mem_dhparams); 184 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
183 daemon->have_dhparams = false; 185 daemon->have_dhparams = false;
184 }
185 gnutls_priority_deinit (daemon->priority_cache);
186 if (daemon->x509_cred)
187 gnutls_certificate_free_credentials (daemon->x509_cred);
188#endif
189 } 186 }
187 gnutls_priority_deinit (daemon->priority_cache);
188 if (daemon->x509_cred)
189 gnutls_certificate_free_credentials (daemon->x509_cred);
190#endif
191 }
190#endif /* HTTPS_SUPPORT */ 192#endif /* HTTPS_SUPPORT */
191 193
192#ifdef DAUTH_SUPPORT 194#ifdef DAUTH_SUPPORT
diff --git a/src/lib/daemon_epoll.c b/src/lib/daemon_epoll.c
index 4bed148f..b25ba9a7 100644
--- a/src/lib/daemon_epoll.c
+++ b/src/lib/daemon_epoll.c
@@ -53,9 +53,9 @@
53 * 'false' otherwise 53 * 'false' otherwise
54 */ 54 */
55static bool 55static bool
56is_urh_ready (struct MHD_UpgradeResponseHandle * const urh) 56is_urh_ready (struct MHD_UpgradeResponseHandle *const urh)
57{ 57{
58 const struct MHD_Connection * const connection = urh->connection; 58 const struct MHD_Connection *const connection = urh->connection;
59 59
60 if ( (0 == urh->in_buffer_size) && 60 if ( (0 == urh->in_buffer_size) &&
61 (0 == urh->out_buffer_size) && 61 (0 == urh->out_buffer_size) &&
@@ -80,7 +80,7 @@ is_urh_ready (struct MHD_UpgradeResponseHandle * const urh)
80 return true; 80 return true;
81 81
82 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) && 82 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) &&
83 (urh->in_buffer_used > 0) ) 83 (urh->in_buffer_used > 0) )
84 return true; 84 return true;
85 85
86 return false; 86 return false;
@@ -103,99 +103,99 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
103{ 103{
104 struct epoll_event events[MAX_EVENTS]; 104 struct epoll_event events[MAX_EVENTS];
105 int num_events; 105 int num_events;
106 struct MHD_UpgradeResponseHandle * pos; 106 struct MHD_UpgradeResponseHandle *pos;
107 struct MHD_UpgradeResponseHandle * prev; 107 struct MHD_UpgradeResponseHandle *prev;
108 108
109 num_events = MAX_EVENTS; 109 num_events = MAX_EVENTS;
110 while (MAX_EVENTS == num_events) 110 while (MAX_EVENTS == num_events)
111 {
112 unsigned int i;
113
114 /* update event masks */
115 num_events = epoll_wait (daemon->epoll_upgrade_fd,
116 events,
117 MAX_EVENTS,
118 0);
119 if (-1 == num_events)
111 { 120 {
112 unsigned int i; 121 const int err = MHD_socket_get_error_ ();
113 122 if (MHD_SCKT_ERR_IS_EINTR_ (err))
114 /* update event masks */ 123 return MHD_SC_OK;
115 num_events = epoll_wait (daemon->epoll_upgrade_fd,
116 events,
117 MAX_EVENTS,
118 0);
119 if (-1 == num_events)
120 {
121 const int err = MHD_socket_get_error_ ();
122 if (MHD_SCKT_ERR_IS_EINTR_ (err))
123 return MHD_SC_OK;
124#ifdef HAVE_MESSAGES 124#ifdef HAVE_MESSAGES
125 MHD_DLOG (daemon, 125 MHD_DLOG (daemon,
126 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR, 126 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR,
127 _("Call to epoll_wait failed: %s\n"), 127 _ ("Call to epoll_wait failed: %s\n"),
128 MHD_socket_strerr_ (err)); 128 MHD_socket_strerr_ (err));
129#endif 129#endif
130 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR; 130 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR;
131 } 131 }
132 for (i = 0; i < (unsigned int) num_events; i++) 132 for (i = 0; i < (unsigned int) num_events; i++)
133 { 133 {
134 struct UpgradeEpollHandle * const ueh = events[i].data.ptr; 134 struct UpgradeEpollHandle *const ueh = events[i].data.ptr;
135 struct MHD_UpgradeResponseHandle * const urh = ueh->urh; 135 struct MHD_UpgradeResponseHandle *const urh = ueh->urh;
136 bool new_err_state = false; 136 bool new_err_state = false;
137 137
138 if (urh->clean_ready) 138 if (urh->clean_ready)
139 continue; 139 continue;
140 140
141 /* Update ueh state based on what is ready according to epoll() */ 141 /* Update ueh state based on what is ready according to epoll() */
142 if (0 != (events[i].events & EPOLLIN)) 142 if (0 != (events[i].events & EPOLLIN))
143 ueh->celi |= MHD_EPOLL_STATE_READ_READY; 143 ueh->celi |= MHD_EPOLL_STATE_READ_READY;
144 if (0 != (events[i].events & EPOLLOUT)) 144 if (0 != (events[i].events & EPOLLOUT))
145 ueh->celi |= MHD_EPOLL_STATE_WRITE_READY; 145 ueh->celi |= MHD_EPOLL_STATE_WRITE_READY;
146 if (0 != (events[i].events & EPOLLHUP)) 146 if (0 != (events[i].events & EPOLLHUP))
147 ueh->celi |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY; 147 ueh->celi |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY;
148 148
149 if ( (0 == (ueh->celi & MHD_EPOLL_STATE_ERROR)) && 149 if ( (0 == (ueh->celi & MHD_EPOLL_STATE_ERROR)) &&
150 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) ) 150 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
151 { 151 {
152 /* Process new error state only one time 152 /* Process new error state only one time
153 * and avoid continuously marking this connection 153 * and avoid continuously marking this connection
154 * as 'ready'. */ 154 * as 'ready'. */
155 ueh->celi |= MHD_EPOLL_STATE_ERROR; 155 ueh->celi |= MHD_EPOLL_STATE_ERROR;
156 new_err_state = true; 156 new_err_state = true;
157 } 157 }
158 158
159 if (! urh->in_eready_list) 159 if (! urh->in_eready_list)
160 { 160 {
161 if (new_err_state || 161 if (new_err_state ||
162 is_urh_ready(urh)) 162 is_urh_ready (urh))
163 { 163 {
164 EDLL_insert (daemon->eready_urh_head, 164 EDLL_insert (daemon->eready_urh_head,
165 daemon->eready_urh_tail, 165 daemon->eready_urh_tail,
166 urh); 166 urh);
167 urh->in_eready_list = true; 167 urh->in_eready_list = true;
168 }
169 }
170 } 168 }
169 }
171 } 170 }
171 }
172 prev = daemon->eready_urh_tail; 172 prev = daemon->eready_urh_tail;
173 while (NULL != (pos = prev)) 173 while (NULL != (pos = prev))
174 {
175 prev = pos->prevE;
176 MHD_upgrade_response_handle_process_ (pos);
177 if (! is_urh_ready (pos))
174 { 178 {
175 prev = pos->prevE; 179 EDLL_remove (daemon->eready_urh_head,
176 MHD_upgrade_response_handle_process_ (pos); 180 daemon->eready_urh_tail,
177 if (! is_urh_ready(pos)) 181 pos);
178 { 182 pos->in_eready_list = false;
179 EDLL_remove (daemon->eready_urh_head, 183 }
180 daemon->eready_urh_tail, 184 /* Finished forwarding? */
181 pos); 185 if ( (0 == pos->in_buffer_size) &&
182 pos->in_eready_list = false; 186 (0 == pos->out_buffer_size) &&
183 } 187 (0 == pos->in_buffer_used) &&
184 /* Finished forwarding? */ 188 (0 == pos->out_buffer_used) )
185 if ( (0 == pos->in_buffer_size) && 189 {
186 (0 == pos->out_buffer_size) && 190 MHD_connection_finish_forward_ (pos->connection);
187 (0 == pos->in_buffer_used) && 191 pos->clean_ready = true;
188 (0 == pos->out_buffer_used) ) 192 /* If 'pos->was_closed' already was set to true, connection
189 { 193 * will be moved immediately to cleanup list. Otherwise
190 MHD_connection_finish_forward_ (pos->connection); 194 * connection will stay in suspended list until 'pos' will
191 pos->clean_ready = true; 195 * be marked with 'was_closed' by application. */
192 /* If 'pos->was_closed' already was set to true, connection 196 MHD_request_resume (&pos->connection->request);
193 * will be moved immediately to cleanup list. Otherwise
194 * connection will stay in suspended list until 'pos' will
195 * be marked with 'was_closed' by application. */
196 MHD_request_resume (&pos->connection->request);
197 }
198 } 197 }
198 }
199 199
200 return MHD_SC_OK; 200 return MHD_SC_OK;
201} 201}
@@ -212,10 +212,10 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
212 */ 212 */
213enum MHD_StatusCode 213enum MHD_StatusCode
214MHD_daemon_epoll_ (struct MHD_Daemon *daemon, 214MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
215 bool may_block) 215 bool may_block)
216{ 216{
217#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 217#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
218 static const char * const upgrade_marker = "upgrade_ptr"; 218 static const char *const upgrade_marker = "upgrade_ptr";
219#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 219#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
220 struct MHD_Connection *pos; 220 struct MHD_Connection *pos;
221 struct MHD_Connection *prev; 221 struct MHD_Connection *prev;
@@ -239,24 +239,24 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
239 (daemon->connections < daemon->global_connection_limit) && 239 (daemon->connections < daemon->global_connection_limit) &&
240 (! daemon->listen_socket_in_epoll) && 240 (! daemon->listen_socket_in_epoll) &&
241 (! daemon->at_limit) ) 241 (! daemon->at_limit) )
242 {
243 event.events = EPOLLIN;
244 event.data.ptr = daemon;
245 if (0 != epoll_ctl (daemon->epoll_fd,
246 EPOLL_CTL_ADD,
247 ls,
248 &event))
242 { 249 {
243 event.events = EPOLLIN;
244 event.data.ptr = daemon;
245 if (0 != epoll_ctl (daemon->epoll_fd,
246 EPOLL_CTL_ADD,
247 ls,
248 &event))
249 {
250#ifdef HAVE_MESSAGES 250#ifdef HAVE_MESSAGES
251 MHD_DLOG (daemon, 251 MHD_DLOG (daemon,
252 MHD_SC_EPOLL_CTL_ADD_FAILED, 252 MHD_SC_EPOLL_CTL_ADD_FAILED,
253 _("Call to epoll_ctl failed: %s\n"), 253 _ ("Call to epoll_ctl failed: %s\n"),
254 MHD_socket_last_strerr_ ()); 254 MHD_socket_last_strerr_ ());
255#endif 255#endif
256 return MHD_SC_EPOLL_CTL_ADD_FAILED; 256 return MHD_SC_EPOLL_CTL_ADD_FAILED;
257 }
258 daemon->listen_socket_in_epoll = true;
259 } 257 }
258 daemon->listen_socket_in_epoll = true;
259 }
260 if ( (daemon->was_quiesced) && 260 if ( (daemon->was_quiesced) &&
261 (daemon->listen_socket_in_epoll) ) 261 (daemon->listen_socket_in_epoll) )
262 { 262 {
@@ -271,58 +271,58 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
271#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 271#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
272 if ( (! daemon->upgrade_fd_in_epoll) && 272 if ( (! daemon->upgrade_fd_in_epoll) &&
273 (-1 != daemon->epoll_upgrade_fd) ) 273 (-1 != daemon->epoll_upgrade_fd) )
274 {
275 event.events = EPOLLIN | EPOLLOUT;
276 event.data.ptr = (void *) upgrade_marker;
277 if (0 != epoll_ctl (daemon->epoll_fd,
278 EPOLL_CTL_ADD,
279 daemon->epoll_upgrade_fd,
280 &event))
274 { 281 {
275 event.events = EPOLLIN | EPOLLOUT;
276 event.data.ptr = (void *) upgrade_marker;
277 if (0 != epoll_ctl (daemon->epoll_fd,
278 EPOLL_CTL_ADD,
279 daemon->epoll_upgrade_fd,
280 &event))
281 {
282#ifdef HAVE_MESSAGES 282#ifdef HAVE_MESSAGES
283 MHD_DLOG (daemon, 283 MHD_DLOG (daemon,
284 MHD_SC_EPOLL_CTL_ADD_FAILED, 284 MHD_SC_EPOLL_CTL_ADD_FAILED,
285 _("Call to epoll_ctl failed: %s\n"), 285 _ ("Call to epoll_ctl failed: %s\n"),
286 MHD_socket_last_strerr_ ()); 286 MHD_socket_last_strerr_ ());
287#endif 287#endif
288 return MHD_SC_EPOLL_CTL_ADD_FAILED; 288 return MHD_SC_EPOLL_CTL_ADD_FAILED;
289 }
290 daemon->upgrade_fd_in_epoll = true;
291 } 289 }
290 daemon->upgrade_fd_in_epoll = true;
291 }
292#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 292#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
293 if ( (daemon->listen_socket_in_epoll) && 293 if ( (daemon->listen_socket_in_epoll) &&
294 ( (daemon->connections == daemon->global_connection_limit) || 294 ( (daemon->connections == daemon->global_connection_limit) ||
295 (daemon->at_limit) || 295 (daemon->at_limit) ||
296 (daemon->was_quiesced) ) ) 296 (daemon->was_quiesced) ) )
297 { 297 {
298 /* we're at the connection limit, disable listen socket 298 /* we're at the connection limit, disable listen socket
299 for event loop for now */ 299 for event loop for now */
300 if (0 != epoll_ctl (daemon->epoll_fd, 300 if (0 != epoll_ctl (daemon->epoll_fd,
301 EPOLL_CTL_DEL, 301 EPOLL_CTL_DEL,
302 ls, 302 ls,
303 NULL)) 303 NULL))
304 MHD_PANIC (_("Failed to remove listen FD from epoll set\n")); 304 MHD_PANIC (_ ("Failed to remove listen FD from epoll set\n"));
305 daemon->listen_socket_in_epoll = false; 305 daemon->listen_socket_in_epoll = false;
306 } 306 }
307 307
308 if ( (! daemon->disallow_suspend_resume) && 308 if ( (! daemon->disallow_suspend_resume) &&
309 (MHD_resume_suspended_connections_ (daemon)) ) 309 (MHD_resume_suspended_connections_ (daemon)) )
310 may_block = false; 310 may_block = false;
311 311
312 if (may_block) 312 if (may_block)
313 {
314 if (MHD_SC_OK == /* FIXME: distinguish between NO_TIMEOUT and errors */
315 MHD_daemon_get_timeout (daemon,
316 &timeout_ll))
313 { 317 {
314 if (MHD_SC_OK == /* FIXME: distinguish between NO_TIMEOUT and errors */ 318 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX)
315 MHD_daemon_get_timeout (daemon, 319 timeout_ms = INT_MAX;
316 &timeout_ll))
317 {
318 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX)
319 timeout_ms = INT_MAX;
320 else
321 timeout_ms = (int) timeout_ll;
322 }
323 else 320 else
324 timeout_ms = -1; 321 timeout_ms = (int) timeout_ll;
325 } 322 }
323 else
324 timeout_ms = -1;
325 }
326 else 326 else
327 timeout_ms = 0; 327 timeout_ms = 0;
328 328
@@ -337,113 +337,114 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
337 than unfair behavior... */ 337 than unfair behavior... */
338 num_events = MAX_EVENTS; 338 num_events = MAX_EVENTS;
339 while (MAX_EVENTS == num_events) 339 while (MAX_EVENTS == num_events)
340 {
341 /* update event masks */
342 num_events = epoll_wait (daemon->epoll_fd,
343 events,
344 MAX_EVENTS,
345 timeout_ms);
346 if (-1 == num_events)
340 { 347 {
341 /* update event masks */ 348 const int err = MHD_socket_get_error_ ();
342 num_events = epoll_wait (daemon->epoll_fd, 349 if (MHD_SCKT_ERR_IS_EINTR_ (err))
343 events, 350 return MHD_SC_OK;
344 MAX_EVENTS,
345 timeout_ms);
346 if (-1 == num_events)
347 {
348 const int err = MHD_socket_get_error_ ();
349 if (MHD_SCKT_ERR_IS_EINTR_ (err))
350 return MHD_SC_OK;
351#ifdef HAVE_MESSAGES 351#ifdef HAVE_MESSAGES
352 MHD_DLOG (daemon, 352 MHD_DLOG (daemon,
353 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR, 353 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR,
354 _("Call to epoll_wait failed: %s\n"), 354 _ ("Call to epoll_wait failed: %s\n"),
355 MHD_socket_strerr_ (err)); 355 MHD_socket_strerr_ (err));
356#endif 356#endif
357 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR; 357 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR;
358 } 358 }
359 for (i=0;i<(unsigned int) num_events;i++) 359 for (i = 0; i<(unsigned int) num_events; i++)
360 { 360 {
361 /* First, check for the values of `ptr` that would indicate 361 /* First, check for the values of `ptr` that would indicate
362 that this event is not about a normal connection. */ 362 that this event is not about a normal connection. */
363 if (NULL == events[i].data.ptr) 363 if (NULL == events[i].data.ptr)
364 continue; /* shutdown signal! */ 364 continue; /* shutdown signal! */
365#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 365#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
366 if (upgrade_marker == events[i].data.ptr) 366 if (upgrade_marker == events[i].data.ptr)
367 { 367 {
368 /* activity on an upgraded connection, we process 368 /* activity on an upgraded connection, we process
369 those in a separate epoll() */ 369 those in a separate epoll() */
370 run_upgraded = true; 370 run_upgraded = true;
371 continue; 371 continue;
372 } 372 }
373#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 373#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
374 if (daemon->epoll_itc_marker == events[i].data.ptr) 374 if (daemon->epoll_itc_marker == events[i].data.ptr)
375 { 375 {
376 /* It's OK to clear ITC here as all external 376 /* It's OK to clear ITC here as all external
377 conditions will be processed later. */ 377 conditions will be processed later. */
378 MHD_itc_clear_ (daemon->itc); 378 MHD_itc_clear_ (daemon->itc);
379 continue; 379 continue;
380 } 380 }
381 if (daemon == events[i].data.ptr) 381 if (daemon == events[i].data.ptr)
382 { 382 {
383 /* Check for error conditions on listen socket. */ 383 /* Check for error conditions on listen socket. */
384 /* FIXME: Initiate MHD_quiesce_daemon() to prevent busy waiting? */ 384 /* FIXME: Initiate MHD_quiesce_daemon() to prevent busy waiting? */
385 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP))) 385 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
386 { 386 {
387 unsigned int series_length = 0; 387 unsigned int series_length = 0;
388 /* Run 'accept' until it fails or daemon at limit of connections. 388 /* Run 'accept' until it fails or daemon at limit of connections.
389 * Do not accept more then 10 connections at once. The rest will 389 * Do not accept more then 10 connections at once. The rest will
390 * be accepted on next turn (level trigger is used for listen 390 * be accepted on next turn (level trigger is used for listen
391 * socket). */ 391 * socket). */
392 while ( (MHD_SC_OK == 392 while ( (MHD_SC_OK ==
393 MHD_accept_connection_ (daemon)) && 393 MHD_accept_connection_ (daemon)) &&
394 (series_length < 10) && 394 (series_length < 10) &&
395 (daemon->connections < daemon->global_connection_limit) && 395 (daemon->connections < daemon->global_connection_limit) &&
396 (! daemon->at_limit) ) 396 (! daemon->at_limit) )
397 series_length++; 397 series_length++;
398 } 398 }
399 continue; 399 continue;
400 } 400 }
401 /* this is an event relating to a 'normal' connection, 401 /* this is an event relating to a 'normal' connection,
402 remember the event and if appropriate mark the 402 remember the event and if appropriate mark the
403 connection as 'eready'. */ 403 connection as 'eready'. */
404 pos = events[i].data.ptr; 404 pos = events[i].data.ptr;
405 /* normal processing: update read/write data */ 405 /* normal processing: update read/write data */
406 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP))) 406 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
407 { 407 {
408 pos->epoll_state |= MHD_EPOLL_STATE_ERROR; 408 pos->epoll_state |= MHD_EPOLL_STATE_ERROR;
409 if (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 409 if (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
410 { 410 {
411 EDLL_insert (daemon->eready_head, 411 EDLL_insert (daemon->eready_head,
412 daemon->eready_tail, 412 daemon->eready_tail,
413 pos); 413 pos);
414 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 414 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
415 } 415 }
416 } 416 }
417 else 417 else
418 { 418 {
419 if (0 != (events[i].events & EPOLLIN)) 419 if (0 != (events[i].events & EPOLLIN))
420 { 420 {
421 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY; 421 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
422 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->request.event_loop_info) || 422 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->request.event_loop_info) ||
423 (pos->request.read_buffer_size > pos->request.read_buffer_offset) ) && 423 (pos->request.read_buffer_size >
424 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) ) 424 pos->request.read_buffer_offset) ) &&
425 { 425 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
426 EDLL_insert (daemon->eready_head, 426 {
427 daemon->eready_tail, 427 EDLL_insert (daemon->eready_head,
428 pos); 428 daemon->eready_tail,
429 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 429 pos);
430 } 430 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
431 } 431 }
432 if (0 != (events[i].events & EPOLLOUT)) 432 }
433 { 433 if (0 != (events[i].events & EPOLLOUT))
434 pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY; 434 {
435 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->request.event_loop_info) && 435 pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY;
436 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) ) 436 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->request.event_loop_info) &&
437 { 437 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
438 EDLL_insert (daemon->eready_head, 438 {
439 daemon->eready_tail, 439 EDLL_insert (daemon->eready_head,
440 pos); 440 daemon->eready_tail,
441 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 441 pos);
442 } 442 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
443 } 443 }
444 }
445 } 444 }
445 }
446 } 446 }
447 }
447 448
448#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 449#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
449 if (run_upgraded) 450 if (run_upgraded)
@@ -453,28 +454,32 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
453 /* process events for connections */ 454 /* process events for connections */
454 prev = daemon->eready_tail; 455 prev = daemon->eready_tail;
455 while (NULL != (pos = prev)) 456 while (NULL != (pos = prev))
457 {
458 prev = pos->prevE;
459 MHD_connection_call_handlers_ (pos,
460 0 != (pos->epoll_state
461 & MHD_EPOLL_STATE_READ_READY),
462 0 != (pos->epoll_state
463 & MHD_EPOLL_STATE_WRITE_READY),
464 0 != (pos->epoll_state
465 & MHD_EPOLL_STATE_ERROR));
466 if (MHD_EPOLL_STATE_IN_EREADY_EDLL ==
467 (pos->epoll_state & (MHD_EPOLL_STATE_SUSPENDED
468 | MHD_EPOLL_STATE_IN_EREADY_EDLL)))
456 { 469 {
457 prev = pos->prevE; 470 if ( ((MHD_EVENT_LOOP_INFO_READ == pos->request.event_loop_info) &&
458 MHD_connection_call_handlers_ (pos, 471 (0 == (pos->epoll_state & MHD_EPOLL_STATE_READ_READY)) ) ||
459 0 != (pos->epoll_state & MHD_EPOLL_STATE_READ_READY), 472 ((MHD_EVENT_LOOP_INFO_WRITE == pos->request.event_loop_info) &&
460 0 != (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY), 473 (0 == (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ) ||
461 0 != (pos->epoll_state & MHD_EPOLL_STATE_ERROR)); 474 (MHD_EVENT_LOOP_INFO_CLEANUP == pos->request.event_loop_info) )
462 if (MHD_EPOLL_STATE_IN_EREADY_EDLL == 475 {
463 (pos->epoll_state & (MHD_EPOLL_STATE_SUSPENDED | MHD_EPOLL_STATE_IN_EREADY_EDLL))) 476 EDLL_remove (daemon->eready_head,
464 { 477 daemon->eready_tail,
465 if ( (MHD_EVENT_LOOP_INFO_READ == pos->request.event_loop_info && 478 pos);
466 0 == (pos->epoll_state & MHD_EPOLL_STATE_READ_READY) ) || 479 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
467 (MHD_EVENT_LOOP_INFO_WRITE == pos->request.event_loop_info && 480 }
468 0 == (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY) ) ||
469 MHD_EVENT_LOOP_INFO_CLEANUP == pos->request.event_loop_info)
470 {
471 EDLL_remove (daemon->eready_head,
472 daemon->eready_tail,
473 pos);
474 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
475 }
476 }
477 } 481 }
482 }
478 483
479 /* Finally, handle timed-out connections; we need to do this here 484 /* Finally, handle timed-out connections; we need to do this here
480 as the epoll mechanism won't call the 'MHD_request_handle_idle_()' on everything, 485 as the epoll mechanism won't call the 'MHD_request_handle_idle_()' on everything,
@@ -486,22 +491,22 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
486 do not bother to sort that (presumably very short) list. */ 491 do not bother to sort that (presumably very short) list. */
487 prev = daemon->manual_timeout_tail; 492 prev = daemon->manual_timeout_tail;
488 while (NULL != (pos = prev)) 493 while (NULL != (pos = prev))
489 { 494 {
490 prev = pos->prevX; 495 prev = pos->prevX;
491 MHD_request_handle_idle_ (&pos->request); 496 MHD_request_handle_idle_ (&pos->request);
492 } 497 }
493 /* Connections with the default timeout are sorted by prepending 498 /* Connections with the default timeout are sorted by prepending
494 them to the head of the list whenever we touch the connection; 499 them to the head of the list whenever we touch the connection;
495 thus it suffices to iterate from the tail until the first 500 thus it suffices to iterate from the tail until the first
496 connection is NOT timed out */ 501 connection is NOT timed out */
497 prev = daemon->normal_timeout_tail; 502 prev = daemon->normal_timeout_tail;
498 while (NULL != (pos = prev)) 503 while (NULL != (pos = prev))
499 { 504 {
500 prev = pos->prevX; 505 prev = pos->prevX;
501 MHD_request_handle_idle_ (&pos->request); 506 MHD_request_handle_idle_ (&pos->request);
502 if (MHD_REQUEST_CLOSED != pos->request.state) 507 if (MHD_REQUEST_CLOSED != pos->request.state)
503 break; /* sorted by timeout, no need to visit the rest! */ 508 break; /* sorted by timeout, no need to visit the rest! */
504 } 509 }
505 return MHD_SC_OK; 510 return MHD_SC_OK;
506} 511}
507#endif 512#endif
diff --git a/src/lib/daemon_epoll.h b/src/lib/daemon_epoll.h
index 50452d8d..37d0e423 100644
--- a/src/lib/daemon_epoll.h
+++ b/src/lib/daemon_epoll.h
@@ -38,8 +38,8 @@
38 */ 38 */
39enum MHD_StatusCode 39enum MHD_StatusCode
40MHD_daemon_epoll_ (struct MHD_Daemon *daemon, 40MHD_daemon_epoll_ (struct MHD_Daemon *daemon,
41 bool may_block) 41 bool may_block)
42 MHD_NONNULL (1); 42MHD_NONNULL (1);
43 43
44#endif 44#endif
45 45
diff --git a/src/lib/daemon_get_timeout.c b/src/lib/daemon_get_timeout.c
index fcf3ecbc..604c52e2 100644
--- a/src/lib/daemon_get_timeout.c
+++ b/src/lib/daemon_get_timeout.c
@@ -46,7 +46,7 @@
46 */ 46 */
47enum MHD_StatusCode 47enum MHD_StatusCode
48MHD_daemon_get_timeout (struct MHD_Daemon *daemon, 48MHD_daemon_get_timeout (struct MHD_Daemon *daemon,
49 MHD_UNSIGNED_LONG_LONG *timeout) 49 MHD_UNSIGNED_LONG_LONG *timeout)
50{ 50{
51 time_t earliest_deadline; 51 time_t earliest_deadline;
52 time_t now; 52 time_t now;
@@ -54,71 +54,71 @@ MHD_daemon_get_timeout (struct MHD_Daemon *daemon,
54 bool have_timeout; 54 bool have_timeout;
55 55
56 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) 56 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode)
57 { 57 {
58#ifdef HAVE_MESSAGES 58#ifdef HAVE_MESSAGES
59 MHD_DLOG (daemon, 59 MHD_DLOG (daemon,
60 MHD_SC_CONFIGURATION_MISMATCH_FOR_GET_TIMEOUT, 60 MHD_SC_CONFIGURATION_MISMATCH_FOR_GET_TIMEOUT,
61 _("Illegal call to MHD_get_timeout\n")); 61 _ ("Illegal call to MHD_get_timeout\n"));
62#endif 62#endif
63 return MHD_SC_CONFIGURATION_MISSMATCH_FOR_GET_TIMEOUT; 63 return MHD_SC_CONFIGURATION_MISSMATCH_FOR_GET_TIMEOUT;
64 } 64 }
65 65
66 if (daemon->data_already_pending) 66 if (daemon->data_already_pending)
67 { 67 {
68 /* Some data already waiting to be processed. */ 68 /* Some data already waiting to be processed. */
69 *timeout = 0; 69 *timeout = 0;
70 return MHD_SC_OK; 70 return MHD_SC_OK;
71 } 71 }
72 72
73#ifdef EPOLL_SUPPORT 73#ifdef EPOLL_SUPPORT
74 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 74 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
75 ((NULL != daemon->eready_head) 75 ((NULL != daemon->eready_head)
76#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT) 76#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
77 || (NULL != daemon->eready_urh_head) 77 || (NULL != daemon->eready_urh_head)
78#endif /* UPGRADE_SUPPORT && HTTPS_SUPPORT */ 78#endif /* UPGRADE_SUPPORT && HTTPS_SUPPORT */
79 ) ) 79 ) )
80 { 80 {
81 /* Some connection(s) already have some data pending. */ 81 /* Some connection(s) already have some data pending. */
82 *timeout = 0; 82 *timeout = 0;
83 return MHD_SC_OK; 83 return MHD_SC_OK;
84 } 84 }
85#endif /* EPOLL_SUPPORT */ 85#endif /* EPOLL_SUPPORT */
86 86
87 have_timeout = false; 87 have_timeout = false;
88 earliest_deadline = 0; /* avoid compiler warnings */ 88 earliest_deadline = 0; /* avoid compiler warnings */
89 for (pos = daemon->manual_timeout_tail; NULL != pos; pos = pos->prevX) 89 for (pos = daemon->manual_timeout_tail; NULL != pos; pos = pos->prevX)
90 {
91 if (0 != pos->connection_timeout)
90 { 92 {
91 if (0 != pos->connection_timeout) 93 if ( (! have_timeout) ||
92 { 94 (earliest_deadline - pos->last_activity > pos->connection_timeout) )
93 if ( (! have_timeout) || 95 earliest_deadline = pos->last_activity + pos->connection_timeout;
94 (earliest_deadline - pos->last_activity > pos->connection_timeout) ) 96 have_timeout = true;
95 earliest_deadline = pos->last_activity + pos->connection_timeout;
96 have_timeout = true;
97 }
98 } 97 }
98 }
99 /* normal timeouts are sorted, so we only need to look at the 'tail' (oldest) */ 99 /* normal timeouts are sorted, so we only need to look at the 'tail' (oldest) */
100 pos = daemon->normal_timeout_tail; 100 pos = daemon->normal_timeout_tail;
101 if ( (NULL != pos) && 101 if ( (NULL != pos) &&
102 (0 != pos->connection_timeout) ) 102 (0 != pos->connection_timeout) )
103 { 103 {
104 if ( (! have_timeout) || 104 if ( (! have_timeout) ||
105 (earliest_deadline - pos->connection_timeout > pos->last_activity) ) 105 (earliest_deadline - pos->connection_timeout > pos->last_activity) )
106 earliest_deadline = pos->last_activity + pos->connection_timeout; 106 earliest_deadline = pos->last_activity + pos->connection_timeout;
107 have_timeout = true; 107 have_timeout = true;
108 } 108 }
109 109
110 if (! have_timeout) 110 if (! have_timeout)
111 return MHD_SC_NO_TIMEOUT; 111 return MHD_SC_NO_TIMEOUT;
112 now = MHD_monotonic_sec_counter(); 112 now = MHD_monotonic_sec_counter ();
113 if (earliest_deadline < now) 113 if (earliest_deadline < now)
114 *timeout = 0; 114 *timeout = 0;
115 else 115 else
116 { 116 {
117 const time_t second_left = earliest_deadline - now; 117 const time_t second_left = earliest_deadline - now;
118 if (second_left > ULLONG_MAX / 1000) /* Ignore compiler warning: 'second_left' is always positive. */ 118 if (second_left > ULLONG_MAX / 1000) /* Ignore compiler warning: 'second_left' is always positive. */
119 *timeout = ULLONG_MAX; 119 *timeout = ULLONG_MAX;
120 else 120 else
121 *timeout = 1000LL * second_left; 121 *timeout = 1000LL * second_left;
122 } 122 }
123 return MHD_SC_OK; 123 return MHD_SC_OK;
124} 124}
diff --git a/src/lib/daemon_info.c b/src/lib/daemon_info.c
index b0c5ec14..d32f244b 100644
--- a/src/lib/daemon_info.c
+++ b/src/lib/daemon_info.c
@@ -43,62 +43,62 @@
43 */ 43 */
44enum MHD_Bool 44enum MHD_Bool
45MHD_daemon_get_information_sz (struct MHD_Daemon *daemon, 45MHD_daemon_get_information_sz (struct MHD_Daemon *daemon,
46 enum MHD_DaemonInformationType info_type, 46 enum MHD_DaemonInformationType info_type,
47 union MHD_DaemonInformation *return_value, 47 union MHD_DaemonInformation *return_value,
48 size_t return_value_size) 48 size_t return_value_size)
49{ 49{
50#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \ 50#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \
51 return MHD_NO 51 return MHD_NO
52 52
53 switch (info_type) 53 switch (info_type)
54 { 54 {
55 case MHD_DAEMON_INFORMATION_LISTEN_SOCKET: 55 case MHD_DAEMON_INFORMATION_LISTEN_SOCKET:
56 CHECK_SIZE (MHD_socket); 56 CHECK_SIZE (MHD_socket);
57 return_value->listen_socket 57 return_value->listen_socket
58 = daemon->listen_socket; 58 = daemon->listen_socket;
59 return MHD_YES; 59 return MHD_YES;
60#ifdef EPOLL_SUPPORT 60#ifdef EPOLL_SUPPORT
61 case MHD_DAEMON_INFORMATION_EPOLL_FD: 61 case MHD_DAEMON_INFORMATION_EPOLL_FD:
62 CHECK_SIZE (int); 62 CHECK_SIZE (int);
63 // FIXME: maybe return MHD_NO if we are not using EPOLL? 63 // FIXME: maybe return MHD_NO if we are not using EPOLL?
64 return_value->epoll_fd = daemon->epoll_fd; 64 return_value->epoll_fd = daemon->epoll_fd;
65 return MHD_YES; 65 return MHD_YES;
66#endif 66#endif
67 case MHD_DAEMON_INFORMATION_CURRENT_CONNECTIONS: 67 case MHD_DAEMON_INFORMATION_CURRENT_CONNECTIONS:
68 CHECK_SIZE (unsigned int); 68 CHECK_SIZE (unsigned int);
69 if (MHD_TM_EXTERNAL_EVENT_LOOP == daemon->threading_mode) 69 if (MHD_TM_EXTERNAL_EVENT_LOOP == daemon->threading_mode)
70 { 70 {
71 /* Assumes that MHD_run() in not called in other thread 71 /* Assumes that MHD_run() in not called in other thread
72 (of the application) at the same time. */ 72 (of the application) at the same time. */
73 MHD_connection_cleanup_ (daemon); 73 MHD_connection_cleanup_ (daemon);
74 return_value->num_connections 74 return_value->num_connections
75 = daemon->connections; 75 = daemon->connections;
76 }
77 else if (daemon->worker_pool)
78 {
79 unsigned int i;
80 /* Collect the connection information stored in the workers. */
81 return_value->num_connections = 0;
82 for (i = 0; i < daemon->worker_pool_size; i++)
83 {
84 /* FIXME: next line is thread-safe only if read is atomic. */
85 return_value->num_connections
86 += daemon->worker_pool[i].connections;
87 }
88 }
89 else
90 return_value->num_connections
91 = daemon->connections;
92 return MHD_YES;
93 case MHD_DAEMON_INFORMATION_BIND_PORT:
94 CHECK_SIZE (uint16_t);
95 // FIXME: return MHD_NO if port is not known/UNIX?
96 return_value->port = daemon->listen_port;
97 return MHD_YES;
98 default:
99 return MHD_NO;
100 } 76 }
101 77 else if (daemon->worker_pool)
78 {
79 unsigned int i;
80 /* Collect the connection information stored in the workers. */
81 return_value->num_connections = 0;
82 for (i = 0; i < daemon->worker_pool_size; i++)
83 {
84 /* FIXME: next line is thread-safe only if read is atomic. */
85 return_value->num_connections
86 += daemon->worker_pool[i].connections;
87 }
88 }
89 else
90 return_value->num_connections
91 = daemon->connections;
92 return MHD_YES;
93 case MHD_DAEMON_INFORMATION_BIND_PORT:
94 CHECK_SIZE (uint16_t);
95 // FIXME: return MHD_NO if port is not known/UNIX?
96 return_value->port = daemon->listen_port;
97 return MHD_YES;
98 default:
99 return MHD_NO;
100 }
101
102#undef CHECK_SIZE 102#undef CHECK_SIZE
103} 103}
104 104
diff --git a/src/lib/daemon_ip_limit.c b/src/lib/daemon_ip_limit.c
index 4a131c92..21550265 100644
--- a/src/lib/daemon_ip_limit.c
+++ b/src/lib/daemon_ip_limit.c
@@ -89,7 +89,7 @@ get_master (struct MHD_Daemon *daemon)
89static void 89static void
90MHD_ip_count_lock (struct MHD_Daemon *daemon) 90MHD_ip_count_lock (struct MHD_Daemon *daemon)
91{ 91{
92 MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex); 92 MHD_mutex_lock_chk_ (&daemon->per_ip_connection_mutex);
93} 93}
94 94
95 95
@@ -101,7 +101,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
101static void 101static void
102MHD_ip_count_unlock (struct MHD_Daemon *daemon) 102MHD_ip_count_unlock (struct MHD_Daemon *daemon)
103{ 103{
104 MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex); 104 MHD_mutex_unlock_chk_ (&daemon->per_ip_connection_mutex);
105} 105}
106 106
107 107
@@ -135,37 +135,37 @@ MHD_ip_addr_compare (const void *a1,
135 */ 135 */
136static int 136static int
137MHD_ip_addr_to_key (const struct sockaddr *addr, 137MHD_ip_addr_to_key (const struct sockaddr *addr,
138 socklen_t addrlen, 138 socklen_t addrlen,
139 struct MHD_IPCount *key) 139 struct MHD_IPCount *key)
140{ 140{
141 memset(key, 141 memset (key,
142 0, 142 0,
143 sizeof(*key)); 143 sizeof(*key));
144 144
145 /* IPv4 addresses */ 145 /* IPv4 addresses */
146 if (sizeof (struct sockaddr_in) == addrlen) 146 if (sizeof (struct sockaddr_in) == addrlen)
147 { 147 {
148 const struct sockaddr_in *addr4 = (const struct sockaddr_in*) addr; 148 const struct sockaddr_in *addr4 = (const struct sockaddr_in*) addr;
149 149
150 key->family = AF_INET; 150 key->family = AF_INET;
151 memcpy (&key->addr.ipv4, 151 memcpy (&key->addr.ipv4,
152 &addr4->sin_addr, 152 &addr4->sin_addr,
153 sizeof(addr4->sin_addr)); 153 sizeof(addr4->sin_addr));
154 return MHD_YES; 154 return MHD_YES;
155 } 155 }
156 156
157#if HAVE_INET6 157#if HAVE_INET6
158 /* IPv6 addresses */ 158 /* IPv6 addresses */
159 if (sizeof (struct sockaddr_in6) == addrlen) 159 if (sizeof (struct sockaddr_in6) == addrlen)
160 { 160 {
161 const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*) addr; 161 const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*) addr;
162 162
163 key->family = AF_INET6; 163 key->family = AF_INET6;
164 memcpy (&key->addr.ipv6, 164 memcpy (&key->addr.ipv6,
165 &addr6->sin6_addr, 165 &addr6->sin6_addr,
166 sizeof(addr6->sin6_addr)); 166 sizeof(addr6->sin6_addr));
167 return MHD_YES; 167 return MHD_YES;
168 } 168 }
169#endif 169#endif
170 170
171 /* Some other address */ 171 /* Some other address */
@@ -186,8 +186,8 @@ MHD_ip_addr_to_key (const struct sockaddr *addr,
186 */ 186 */
187int 187int
188MHD_ip_limit_add (struct MHD_Daemon *daemon, 188MHD_ip_limit_add (struct MHD_Daemon *daemon,
189 const struct sockaddr *addr, 189 const struct sockaddr *addr,
190 socklen_t addrlen) 190 socklen_t addrlen)
191{ 191{
192 struct MHD_IPCount *key; 192 struct MHD_IPCount *key;
193 void **nodep; 193 void **nodep;
@@ -206,31 +206,31 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
206 if (MHD_NO == MHD_ip_addr_to_key (addr, 206 if (MHD_NO == MHD_ip_addr_to_key (addr,
207 addrlen, 207 addrlen,
208 key)) 208 key))
209 { 209 {
210 /* Allow unhandled address types through */ 210 /* Allow unhandled address types through */
211 free (key); 211 free (key);
212 return MHD_YES; 212 return MHD_YES;
213 } 213 }
214 MHD_ip_count_lock (daemon); 214 MHD_ip_count_lock (daemon);
215 215
216 /* Search for the IP address */ 216 /* Search for the IP address */
217 if (NULL == (nodep = tsearch (key, 217 if (NULL == (nodep = tsearch (key,
218 &daemon->per_ip_connection_count, 218 &daemon->per_ip_connection_count,
219 &MHD_ip_addr_compare))) 219 &MHD_ip_addr_compare)))
220 { 220 {
221#ifdef HAVE_MESSAGES 221#ifdef HAVE_MESSAGES
222 MHD_DLOG (daemon, 222 MHD_DLOG (daemon,
223 MHD_SC_IP_COUNTER_FAILURE, 223 MHD_SC_IP_COUNTER_FAILURE,
224 _("Failed to add IP connection count node\n")); 224 _ ("Failed to add IP connection count node\n"));
225#endif 225#endif
226 MHD_ip_count_unlock (daemon); 226 MHD_ip_count_unlock (daemon);
227 free (key); 227 free (key);
228 return MHD_NO; 228 return MHD_NO;
229 } 229 }
230 node = *nodep; 230 node = *nodep;
231 /* If we got an existing node back, free the one we created */ 231 /* If we got an existing node back, free the one we created */
232 if (node != key) 232 if (node != key)
233 free(key); 233 free (key);
234 key = (struct MHD_IPCount *) node; 234 key = (struct MHD_IPCount *) node;
235 /* Test if there is room for another connection; if so, 235 /* Test if there is room for another connection; if so,
236 * increment count */ 236 * increment count */
@@ -253,8 +253,8 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
253 */ 253 */
254void 254void
255MHD_ip_limit_del (struct MHD_Daemon *daemon, 255MHD_ip_limit_del (struct MHD_Daemon *daemon,
256 const struct sockaddr *addr, 256 const struct sockaddr *addr,
257 socklen_t addrlen) 257 socklen_t addrlen)
258{ 258{
259 struct MHD_IPCount search_key; 259 struct MHD_IPCount search_key;
260 struct MHD_IPCount *found_key; 260 struct MHD_IPCount *found_key;
@@ -274,27 +274,27 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
274 274
275 /* Search for the IP address */ 275 /* Search for the IP address */
276 if (NULL == (nodep = tfind (&search_key, 276 if (NULL == (nodep = tfind (&search_key,
277 &daemon->per_ip_connection_count, 277 &daemon->per_ip_connection_count,
278 &MHD_ip_addr_compare))) 278 &MHD_ip_addr_compare)))
279 { 279 {
280 /* Something's wrong if we couldn't find an IP address 280 /* Something's wrong if we couldn't find an IP address
281 * that was previously added */ 281 * that was previously added */
282 MHD_PANIC (_("Failed to find previously-added IP address\n")); 282 MHD_PANIC (_ ("Failed to find previously-added IP address\n"));
283 } 283 }
284 found_key = (struct MHD_IPCount *) *nodep; 284 found_key = (struct MHD_IPCount *) *nodep;
285 /* Validate existing count for IP address */ 285 /* Validate existing count for IP address */
286 if (0 == found_key->count) 286 if (0 == found_key->count)
287 { 287 {
288 MHD_PANIC (_("Previously-added IP address had counter of zero\n")); 288 MHD_PANIC (_ ("Previously-added IP address had counter of zero\n"));
289 } 289 }
290 /* Remove the node entirely if count reduces to 0 */ 290 /* Remove the node entirely if count reduces to 0 */
291 if (0 == --found_key->count) 291 if (0 == --found_key->count)
292 { 292 {
293 tdelete (found_key, 293 tdelete (found_key,
294 &daemon->per_ip_connection_count, 294 &daemon->per_ip_connection_count,
295 &MHD_ip_addr_compare); 295 &MHD_ip_addr_compare);
296 free (found_key); 296 free (found_key);
297 } 297 }
298 298
299 MHD_ip_count_unlock (daemon); 299 MHD_ip_count_unlock (daemon);
300} 300}
diff --git a/src/lib/daemon_ip_limit.h b/src/lib/daemon_ip_limit.h
index 5f22db05..9c587825 100644
--- a/src/lib/daemon_ip_limit.h
+++ b/src/lib/daemon_ip_limit.h
@@ -38,9 +38,9 @@
38 */ 38 */
39int 39int
40MHD_ip_limit_add (struct MHD_Daemon *daemon, 40MHD_ip_limit_add (struct MHD_Daemon *daemon,
41 const struct sockaddr *addr, 41 const struct sockaddr *addr,
42 socklen_t addrlen) 42 socklen_t addrlen)
43 MHD_NONNULL (1,2); 43MHD_NONNULL (1,2);
44 44
45 45
46/** 46/**
@@ -53,8 +53,8 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
53 */ 53 */
54void 54void
55MHD_ip_limit_del (struct MHD_Daemon *daemon, 55MHD_ip_limit_del (struct MHD_Daemon *daemon,
56 const struct sockaddr *addr, 56 const struct sockaddr *addr,
57 socklen_t addrlen) 57 socklen_t addrlen)
58 MHD_NONNULL (1,2); 58MHD_NONNULL (1,2);
59 59
60#endif 60#endif
diff --git a/src/lib/daemon_options.c b/src/lib/daemon_options.c
index 4d7bbdf1..04c9cb2f 100644
--- a/src/lib/daemon_options.c
+++ b/src/lib/daemon_options.c
@@ -38,8 +38,8 @@
38 */ 38 */
39void 39void
40MHD_daemon_set_logger (struct MHD_Daemon *daemon, 40MHD_daemon_set_logger (struct MHD_Daemon *daemon,
41 MHD_LoggingCallback logger, 41 MHD_LoggingCallback logger,
42 void *logger_cls) 42 void *logger_cls)
43{ 43{
44 daemon->logger = logger; 44 daemon->logger = logger;
45 daemon->logger_cls = logger_cls; 45 daemon->logger_cls = logger_cls;
@@ -148,8 +148,8 @@ MHD_daemon_disallow_upgrade (struct MHD_Daemon *daemon)
148 */ 148 */
149enum MHD_Bool 149enum MHD_Bool
150MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon, 150MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon,
151 enum MHD_FastOpenMethod fom, 151 enum MHD_FastOpenMethod fom,
152 unsigned int queue_length) 152 unsigned int queue_length)
153{ 153{
154 daemon->fast_open_method = fom; 154 daemon->fast_open_method = fom;
155 daemon->fo_queue_length = queue_length; 155 daemon->fo_queue_length = queue_length;
@@ -185,8 +185,8 @@ MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon,
185 */ 185 */
186void 186void
187MHD_daemon_bind_port (struct MHD_Daemon *daemon, 187MHD_daemon_bind_port (struct MHD_Daemon *daemon,
188 enum MHD_AddressFamily af, 188 enum MHD_AddressFamily af,
189 uint16_t port) 189 uint16_t port)
190{ 190{
191 daemon->listen_af = af; 191 daemon->listen_af = af;
192 daemon->listen_port = port; 192 daemon->listen_port = port;
@@ -204,12 +204,12 @@ MHD_daemon_bind_port (struct MHD_Daemon *daemon,
204 */ 204 */
205void 205void
206MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon, 206MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon,
207 const struct sockaddr *sa, 207 const struct sockaddr *sa,
208 size_t sa_len) 208 size_t sa_len)
209{ 209{
210 memcpy (&daemon->listen_sa, 210 memcpy (&daemon->listen_sa,
211 sa, 211 sa,
212 sa_len); 212 sa_len);
213 daemon->listen_sa_len = sa_len; 213 daemon->listen_sa_len = sa_len;
214} 214}
215 215
@@ -223,7 +223,7 @@ MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon,
223 */ 223 */
224void 224void
225MHD_daemon_listen_backlog (struct MHD_Daemon *daemon, 225MHD_daemon_listen_backlog (struct MHD_Daemon *daemon,
226 int listen_backlog) 226 int listen_backlog)
227{ 227{
228 daemon->listen_backlog = listen_backlog; 228 daemon->listen_backlog = listen_backlog;
229} 229}
@@ -275,7 +275,7 @@ MHD_daemon_enable_shoutcast (struct MHD_Daemon *daemon)
275 */ 275 */
276void 276void
277MHD_daemon_listen_socket (struct MHD_Daemon *daemon, 277MHD_daemon_listen_socket (struct MHD_Daemon *daemon,
278 MHD_socket listen_socket) 278 MHD_socket listen_socket)
279{ 279{
280 daemon->listen_socket = listen_socket; 280 daemon->listen_socket = listen_socket;
281} 281}
@@ -290,7 +290,7 @@ MHD_daemon_listen_socket (struct MHD_Daemon *daemon,
290 */ 290 */
291enum MHD_Bool 291enum MHD_Bool
292MHD_daemon_event_loop (struct MHD_Daemon *daemon, 292MHD_daemon_event_loop (struct MHD_Daemon *daemon,
293 enum MHD_EventLoopSyscall els) 293 enum MHD_EventLoopSyscall els)
294{ 294{
295 switch (els) 295 switch (els)
296 { 296 {
@@ -326,7 +326,7 @@ MHD_daemon_event_loop (struct MHD_Daemon *daemon,
326 */ 326 */
327void 327void
328MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon, 328MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon,
329 enum MHD_ProtocolStrictLevel sl) 329 enum MHD_ProtocolStrictLevel sl)
330{ 330{
331 daemon->protocol_strict_level = sl; 331 daemon->protocol_strict_level = sl;
332} 332}
@@ -349,8 +349,8 @@ MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon,
349 */ 349 */
350enum MHD_StatusCode 350enum MHD_StatusCode
351MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon, 351MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon,
352 const char *tls_backend, 352 const char *tls_backend,
353 const char *ciphers) 353 const char *ciphers)
354{ 354{
355#if ! (defined(HTTPS_SUPPORT) && defined (HAVE_DLFCN_H)) 355#if ! (defined(HTTPS_SUPPORT) && defined (HAVE_DLFCN_H))
356 return MHD_SC_TLS_DISABLED; 356 return MHD_SC_TLS_DISABLED;
@@ -361,18 +361,18 @@ MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon,
361 361
362 /* todo: .dll on W32? */ 362 /* todo: .dll on W32? */
363 res = MHD_snprintf_ (filename, 363 res = MHD_snprintf_ (filename,
364 sizeof (filename), 364 sizeof (filename),
365 "%s/libmicrohttpd_tls_%s.so", 365 "%s/libmicrohttpd_tls_%s.so",
366 MHD_PLUGIN_INSTALL_PREFIX, 366 MHD_PLUGIN_INSTALL_PREFIX,
367 tls_backend); 367 tls_backend);
368 if (0 >= res) 368 if (0 >= res)
369 return MHD_SC_TLS_BACKEND_UNSUPPORTED; /* string too long? */ 369 return MHD_SC_TLS_BACKEND_UNSUPPORTED; /* string too long? */
370 if (NULL == 370 if (NULL ==
371 (daemon->tls_backend_lib = dlopen (filename, 371 (daemon->tls_backend_lib = dlopen (filename,
372 RTLD_NOW | RTLD_LOCAL))) 372 RTLD_NOW | RTLD_LOCAL)))
373 return MHD_SC_TLS_BACKEND_UNSUPPORTED; /* plugin not found */ 373 return MHD_SC_TLS_BACKEND_UNSUPPORTED; /* plugin not found */
374 if (NULL == (init = dlsym (daemon->tls_backend_lib, 374 if (NULL == (init = dlsym (daemon->tls_backend_lib,
375 "MHD_TLS_init_" MHD_TLS_ABI_VERSION_STR))) 375 "MHD_TLS_init_" MHD_TLS_ABI_VERSION_STR)))
376 376
377 { 377 {
378 dlclose (daemon->tls_backend_lib); 378 dlclose (daemon->tls_backend_lib);
@@ -405,9 +405,9 @@ MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon,
405 */ 405 */
406enum MHD_StatusCode 406enum MHD_StatusCode
407MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, 407MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
408 const char *mem_key, 408 const char *mem_key,
409 const char *mem_cert, 409 const char *mem_cert,
410 const char *pass) 410 const char *pass)
411{ 411{
412#ifndef HTTPS_SUPPORT 412#ifndef HTTPS_SUPPORT
413 return MHD_SC_TLS_DISABLED; 413 return MHD_SC_TLS_DISABLED;
@@ -417,9 +417,9 @@ MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
417 if (NULL == (plugin = daemon->tls_api)) 417 if (NULL == (plugin = daemon->tls_api))
418 return MHD_SC_TLS_BACKEND_UNINITIALIZED; 418 return MHD_SC_TLS_BACKEND_UNINITIALIZED;
419 return plugin->init_kcp (plugin->cls, 419 return plugin->init_kcp (plugin->cls,
420 mem_key, 420 mem_key,
421 mem_cert, 421 mem_cert,
422 pass); 422 pass);
423#endif 423#endif
424} 424}
425 425
@@ -435,7 +435,7 @@ MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon,
435 */ 435 */
436enum MHD_StatusCode 436enum MHD_StatusCode
437MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon, 437MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
438 const char *dh) 438 const char *dh)
439{ 439{
440#ifndef HTTPS_SUPPORT 440#ifndef HTTPS_SUPPORT
441 return MHD_SC_TLS_DISABLED; 441 return MHD_SC_TLS_DISABLED;
@@ -445,7 +445,7 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
445 if (NULL == (plugin = daemon->tls_api)) 445 if (NULL == (plugin = daemon->tls_api))
446 return MHD_SC_TLS_BACKEND_UNINITIALIZED; 446 return MHD_SC_TLS_BACKEND_UNINITIALIZED;
447 return plugin->init_dhparams (plugin->cls, 447 return plugin->init_dhparams (plugin->cls,
448 dh); 448 dh);
449#endif 449#endif
450} 450}
451 451
@@ -461,7 +461,7 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
461 */ 461 */
462enum MHD_StatusCode 462enum MHD_StatusCode
463MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon, 463MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon,
464 const char *mem_trust) 464 const char *mem_trust)
465{ 465{
466#ifndef HTTPS_SUPPORT 466#ifndef HTTPS_SUPPORT
467 return MHD_SC_TLS_DISABLED; 467 return MHD_SC_TLS_DISABLED;
@@ -471,7 +471,7 @@ MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon,
471 if (NULL == (plugin = daemon->tls_api)) 471 if (NULL == (plugin = daemon->tls_api))
472 return MHD_SC_TLS_BACKEND_UNINITIALIZED; 472 return MHD_SC_TLS_BACKEND_UNINITIALIZED;
473 return plugin->init_mem_trust (plugin->cls, 473 return plugin->init_mem_trust (plugin->cls,
474 mem_trust); 474 mem_trust);
475#endif 475#endif
476} 476}
477 477
@@ -485,7 +485,7 @@ MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon,
485 */ 485 */
486enum MHD_StatusCode 486enum MHD_StatusCode
487MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, 487MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon,
488 int gnutls_credentials) 488 int gnutls_credentials)
489{ 489{
490#ifndef HTTPS_SUPPORT 490#ifndef HTTPS_SUPPORT
491 return MHD_SC_TLS_DISABLED; 491 return MHD_SC_TLS_DISABLED;
@@ -518,7 +518,7 @@ MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon,
518 */ 518 */
519enum MHD_StatusCode 519enum MHD_StatusCode
520MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, 520MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon,
521 void *cb) 521 void *cb)
522{ 522{
523#ifndef HTTPS_SUPPORT 523#ifndef HTTPS_SUPPORT
524 return MHD_SC_TLS_DISABLED; 524 return MHD_SC_TLS_DISABLED;
@@ -541,7 +541,7 @@ MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon,
541 */ 541 */
542void 542void
543MHD_daemon_threading_mode (struct MHD_Daemon *daemon, 543MHD_daemon_threading_mode (struct MHD_Daemon *daemon,
544 enum MHD_ThreadingMode tm) 544 enum MHD_ThreadingMode tm)
545{ 545{
546 daemon->threading_mode = tm; 546 daemon->threading_mode = tm;
547} 547}
@@ -558,8 +558,8 @@ MHD_daemon_threading_mode (struct MHD_Daemon *daemon,
558 */ 558 */
559void 559void
560MHD_daemon_accept_policy (struct MHD_Daemon *daemon, 560MHD_daemon_accept_policy (struct MHD_Daemon *daemon,
561 MHD_AcceptPolicyCallback apc, 561 MHD_AcceptPolicyCallback apc,
562 void *apc_cls) 562 void *apc_cls)
563{ 563{
564 daemon->accept_policy_cb = apc; 564 daemon->accept_policy_cb = apc;
565 daemon->accept_policy_cb_cls = apc_cls; 565 daemon->accept_policy_cb_cls = apc_cls;
@@ -577,8 +577,8 @@ MHD_daemon_accept_policy (struct MHD_Daemon *daemon,
577 */ 577 */
578void 578void
579MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, 579MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon,
580 MHD_EarlyUriLogCallback cb, 580 MHD_EarlyUriLogCallback cb,
581 void *cb_cls) 581 void *cb_cls)
582{ 582{
583 daemon->early_uri_logger_cb = cb; 583 daemon->early_uri_logger_cb = cb;
584 daemon->early_uri_logger_cb_cls = cb_cls; 584 daemon->early_uri_logger_cb_cls = cb_cls;
@@ -595,8 +595,8 @@ MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon,
595 */ 595 */
596void 596void
597MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon, 597MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon,
598 MHD_NotifyConnectionCallback ncc, 598 MHD_NotifyConnectionCallback ncc,
599 void *ncc_cls) 599 void *ncc_cls)
600{ 600{
601 daemon->notify_connection_cb = ncc; 601 daemon->notify_connection_cb = ncc;
602 daemon->notify_connection_cb_cls = ncc_cls; 602 daemon->notify_connection_cb_cls = ncc_cls;
@@ -616,8 +616,8 @@ MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon,
616 */ 616 */
617void 617void
618MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon, 618MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon,
619 size_t memory_limit_b, 619 size_t memory_limit_b,
620 size_t memory_increment_b) 620 size_t memory_increment_b)
621{ 621{
622 if (memory_increment_b >= memory_limit_b) 622 if (memory_increment_b >= memory_limit_b)
623 MHD_PANIC ("sane memory increment must be below memory limit"); 623 MHD_PANIC ("sane memory increment must be below memory limit");
@@ -636,7 +636,7 @@ MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon,
636 */ 636 */
637void 637void
638MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon, 638MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon,
639 size_t stack_limit_b) 639 size_t stack_limit_b)
640{ 640{
641 daemon->thread_stack_limit_b = stack_limit_b; 641 daemon->thread_stack_limit_b = stack_limit_b;
642} 642}
@@ -659,8 +659,8 @@ MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon,
659 */ 659 */
660void 660void
661MHD_daemon_connection_limits (struct MHD_Daemon *daemon, 661MHD_daemon_connection_limits (struct MHD_Daemon *daemon,
662 unsigned int global_connection_limit, 662 unsigned int global_connection_limit,
663 unsigned int ip_connection_limit) 663 unsigned int ip_connection_limit)
664{ 664{
665 daemon->global_connection_limit = global_connection_limit; 665 daemon->global_connection_limit = global_connection_limit;
666 daemon->ip_connection_limit = ip_connection_limit; 666 daemon->ip_connection_limit = ip_connection_limit;
@@ -677,7 +677,7 @@ MHD_daemon_connection_limits (struct MHD_Daemon *daemon,
677 */ 677 */
678void 678void
679MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, 679MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon,
680 unsigned int timeout_s) 680 unsigned int timeout_s)
681{ 681{
682 daemon->connection_default_timeout = (time_t) timeout_s; 682 daemon->connection_default_timeout = (time_t) timeout_s;
683} 683}
@@ -696,8 +696,8 @@ MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon,
696 */ 696 */
697void 697void
698MHD_daemon_unescape_cb (struct MHD_Daemon *daemon, 698MHD_daemon_unescape_cb (struct MHD_Daemon *daemon,
699 MHD_UnescapeCallback unescape_cb, 699 MHD_UnescapeCallback unescape_cb,
700 void *unescape_cb_cls) 700 void *unescape_cb_cls)
701{ 701{
702 daemon->unescape_cb = unescape_cb; 702 daemon->unescape_cb = unescape_cb;
703 daemon->unescape_cb_cls = unescape_cb_cls; 703 daemon->unescape_cb_cls = unescape_cb_cls;
@@ -715,8 +715,8 @@ MHD_daemon_unescape_cb (struct MHD_Daemon *daemon,
715 */ 715 */
716void 716void
717MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon, 717MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon,
718 size_t buf_size, 718 size_t buf_size,
719 const void *buf) 719 const void *buf)
720{ 720{
721#if ENABLE_DAUTH 721#if ENABLE_DAUTH
722 daemon->digest_auth_random_buf = buf; 722 daemon->digest_auth_random_buf = buf;
@@ -739,34 +739,34 @@ MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon,
739 */ 739 */
740enum MHD_StatusCode 740enum MHD_StatusCode
741MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon, 741MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon,
742 size_t nc_length) 742 size_t nc_length)
743{ 743{
744#if ENABLE_DAUTH 744#if ENABLE_DAUTH
745 if ( ( (size_t) (nc_length * sizeof (struct MHD_NonceNc))) / 745 if ( ( (size_t) (nc_length * sizeof (struct MHD_NonceNc)))
746 sizeof (struct MHD_NonceNc) != nc_length) 746 / sizeof (struct MHD_NonceNc) != nc_length)
747 { 747 {
748#ifdef HAVE_MESSAGES 748#ifdef HAVE_MESSAGES
749 MHD_DLOG (daemon, 749 MHD_DLOG (daemon,
750 _("Specified value for NC_SIZE too large\n")); 750 _ ("Specified value for NC_SIZE too large\n"));
751#endif 751#endif
752 return MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG; 752 return MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG;
753 } 753 }
754 if (0 < nc_length) 754 if (0 < nc_length)
755 {
756 if (NULL != daemon->nnc)
757 free (daemon->nnc);
758 daemon->nnc = malloc (daemon->nonce_nc_size
759 * sizeof (struct MHD_NonceNc));
760 if (NULL == daemon->nnc)
755 { 761 {
756 if (NULL != daemon->nnc)
757 free (daemon->nnc);
758 daemon->nnc = malloc (daemon->nonce_nc_size *
759 sizeof (struct MHD_NonceNc));
760 if (NULL == daemon->nnc)
761 {
762#ifdef HAVE_MESSAGES 762#ifdef HAVE_MESSAGES
763 MHD_DLOG (daemon, 763 MHD_DLOG (daemon,
764 _("Failed to allocate memory for nonce-nc map: %s\n"), 764 _ ("Failed to allocate memory for nonce-nc map: %s\n"),
765 MHD_strerror_ (errno)); 765 MHD_strerror_ (errno));
766#endif 766#endif
767 return MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE; 767 return MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE;
768 }
769 } 768 }
769 }
770 daemon->digest_nc_length = nc_length; 770 daemon->digest_nc_length = nc_length;
771 return MHD_SC_OK; 771 return MHD_SC_OK;
772#else 772#else
diff --git a/src/lib/daemon_poll.c b/src/lib/daemon_poll.c
index 80599e93..1fea9fd6 100644
--- a/src/lib/daemon_poll.c
+++ b/src/lib/daemon_poll.c
@@ -45,7 +45,7 @@
45 */ 45 */
46static void 46static void
47urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh, 47urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh,
48 struct pollfd p[2]) 48 struct pollfd p[2])
49{ 49{
50 p[0].events = 0; 50 p[0].events = 0;
51 p[1].events = 0; 51 p[1].events = 0;
@@ -86,12 +86,12 @@ urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh,
86 */ 86 */
87static void 87static void
88urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh, 88urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh,
89 struct pollfd p[2]) 89 struct pollfd p[2])
90{ 90{
91 p[0].fd = urh->connection->socket_fd; 91 p[0].fd = urh->connection->socket_fd;
92 p[1].fd = urh->mhd.socket; 92 p[1].fd = urh->mhd.socket;
93 urh_update_pollfd (urh, 93 urh_update_pollfd (urh,
94 p); 94 p);
95} 95}
96 96
97 97
@@ -102,7 +102,7 @@ urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh,
102 */ 102 */
103static void 103static void
104urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh, 104urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh,
105 struct pollfd p[2]) 105 struct pollfd p[2])
106{ 106{
107 /* Reset read/write ready, preserve error state. */ 107 /* Reset read/write ready, preserve error state. */
108 urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); 108 urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY);
@@ -138,7 +138,7 @@ urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh,
138 */ 138 */
139enum MHD_StatusCode 139enum MHD_StatusCode
140MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, 140MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
141 bool may_block) 141 bool may_block)
142{ 142{
143 unsigned int num_connections; 143 unsigned int num_connections;
144 struct MHD_Connection *pos; 144 struct MHD_Connection *pos;
@@ -171,103 +171,103 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
171 MHD_socket ls; 171 MHD_socket ls;
172 172
173 p = MHD_calloc_ ((2 + num_connections), 173 p = MHD_calloc_ ((2 + num_connections),
174 sizeof (struct pollfd)); 174 sizeof (struct pollfd));
175 if (NULL == p) 175 if (NULL == p)
176 { 176 {
177#ifdef HAVE_MESSAGES 177#ifdef HAVE_MESSAGES
178 MHD_DLOG (daemon, 178 MHD_DLOG (daemon,
179 MHD_SC_POLL_MALLOC_FAILURE, 179 MHD_SC_POLL_MALLOC_FAILURE,
180 _("Error allocating memory: %s\n"), 180 _ ("Error allocating memory: %s\n"),
181 MHD_strerror_(errno)); 181 MHD_strerror_ (errno));
182#endif 182#endif
183 return MHD_SC_POLL_MALLOC_FAILURE; 183 return MHD_SC_POLL_MALLOC_FAILURE;
184 } 184 }
185 poll_server = 0; 185 poll_server = 0;
186 poll_listen = -1; 186 poll_listen = -1;
187 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && 187 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
188 (! daemon->was_quiesced) && 188 (! daemon->was_quiesced) &&
189 (daemon->connections < daemon->global_connection_limit) && 189 (daemon->connections < daemon->global_connection_limit) &&
190 (! daemon->at_limit) ) 190 (! daemon->at_limit) )
191 { 191 {
192 /* only listen if we are not at the connection limit */ 192 /* only listen if we are not at the connection limit */
193 p[poll_server].fd = ls; 193 p[poll_server].fd = ls;
194 p[poll_server].events = POLLIN; 194 p[poll_server].events = POLLIN;
195 p[poll_server].revents = 0; 195 p[poll_server].revents = 0;
196 poll_listen = (int) poll_server; 196 poll_listen = (int) poll_server;
197 poll_server++; 197 poll_server++;
198 } 198 }
199 poll_itc_idx = -1; 199 poll_itc_idx = -1;
200 if (MHD_ITC_IS_VALID_(daemon->itc)) 200 if (MHD_ITC_IS_VALID_ (daemon->itc))
201 { 201 {
202 p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc); 202 p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc);
203 p[poll_server].events = POLLIN; 203 p[poll_server].events = POLLIN;
204 p[poll_server].revents = 0; 204 p[poll_server].revents = 0;
205 poll_itc_idx = (int) poll_server; 205 poll_itc_idx = (int) poll_server;
206 poll_server++; 206 poll_server++;
207 } 207 }
208 if (! may_block) 208 if (! may_block)
209 timeout = 0; 209 timeout = 0;
210 else if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) || 210 else if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) ||
211 (MHD_SC_OK != /* FIXME: distinguish between NO_TIMEOUT and errors! */ 211 (MHD_SC_OK != /* FIXME: distinguish between NO_TIMEOUT and errors! */
212 MHD_daemon_get_timeout (daemon, 212 MHD_daemon_get_timeout (daemon,
213 &ltimeout)) ) 213 &ltimeout)) )
214 timeout = -1; 214 timeout = -1;
215 else 215 else
216 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout; 216 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout;
217 217
218 i = 0; 218 i = 0;
219 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) 219 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
220 {
221 p[poll_server + i].fd = pos->socket_fd;
222 switch (pos->request.event_loop_info)
220 { 223 {
221 p[poll_server+i].fd = pos->socket_fd; 224 case MHD_EVENT_LOOP_INFO_READ:
222 switch (pos->request.event_loop_info) 225 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
223 { 226 break;
224 case MHD_EVENT_LOOP_INFO_READ: 227 case MHD_EVENT_LOOP_INFO_WRITE:
225 p[poll_server+i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; 228 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
226 break; 229 break;
227 case MHD_EVENT_LOOP_INFO_WRITE: 230 case MHD_EVENT_LOOP_INFO_BLOCK:
228 p[poll_server+i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; 231 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
229 break; 232 break;
230 case MHD_EVENT_LOOP_INFO_BLOCK: 233 case MHD_EVENT_LOOP_INFO_CLEANUP:
231 p[poll_server+i].events |= MHD_POLL_EVENTS_ERR_DISC; 234 timeout = 0; /* clean up "pos" immediately */
232 break; 235 break;
233 case MHD_EVENT_LOOP_INFO_CLEANUP:
234 timeout = 0; /* clean up "pos" immediately */
235 break;
236 }
237 i++;
238 } 236 }
237 i++;
238 }
239#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 239#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
240 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) 240 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
241 { 241 {
242 urh_to_pollfd (urh, 242 urh_to_pollfd (urh,
243 &(p[poll_server+i])); 243 &(p[poll_server + i]));
244 i += 2; 244 i += 2;
245 } 245 }
246#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 246#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
247 if (0 == poll_server + num_connections) 247 if (0 == poll_server + num_connections)
248 {
249 free (p);
250 return MHD_SC_OK;
251 }
252 if (MHD_sys_poll_ (p,
253 poll_server + num_connections,
254 timeout) < 0)
255 {
256 const int err = MHD_socket_get_error_ ();
257 if (MHD_SCKT_ERR_IS_EINTR_ (err))
248 { 258 {
249 free (p); 259 free (p);
250 return MHD_SC_OK; 260 return MHD_SC_OK;
251 } 261 }
252 if (MHD_sys_poll_(p,
253 poll_server + num_connections,
254 timeout) < 0)
255 {
256 const int err = MHD_socket_get_error_ ();
257 if (MHD_SCKT_ERR_IS_EINTR_ (err))
258 {
259 free(p);
260 return MHD_SC_OK;
261 }
262#ifdef HAVE_MESSAGES 262#ifdef HAVE_MESSAGES
263 MHD_DLOG (daemon, 263 MHD_DLOG (daemon,
264 MHD_SC_UNEXPECTED_POLL_ERROR, 264 MHD_SC_UNEXPECTED_POLL_ERROR,
265 _("poll failed: %s\n"), 265 _ ("poll failed: %s\n"),
266 MHD_socket_strerr_ (err)); 266 MHD_socket_strerr_ (err));
267#endif 267#endif
268 free(p); 268 free (p);
269 return MHD_SC_UNEXPECTED_POLL_ERROR; 269 return MHD_SC_UNEXPECTED_POLL_ERROR;
270 } 270 }
271 271
272 /* Reset. New value will be set when connections are processed. */ 272 /* Reset. New value will be set when connections are processed. */
273 daemon->data_already_pending = false; 273 daemon->data_already_pending = false;
@@ -281,67 +281,69 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
281 281
282 /* handle shutdown */ 282 /* handle shutdown */
283 if (daemon->shutdown) 283 if (daemon->shutdown)
284 { 284 {
285 free(p); 285 free (p);
286 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; 286 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
287 } 287 }
288 i = 0; 288 i = 0;
289 prev = daemon->connections_tail; 289 prev = daemon->connections_tail;
290 while (NULL != (pos = prev)) 290 while (NULL != (pos = prev))
291 { 291 {
292 prev = pos->prev; 292 prev = pos->prev;
293 /* first, sanity checks */ 293 /* first, sanity checks */
294 if (i >= num_connections) 294 if (i >= num_connections)
295 break; /* connection list changed somehow, retry later ... */ 295 break; /* connection list changed somehow, retry later ... */
296 if (p[poll_server+i].fd != pos->socket_fd) 296 if (p[poll_server + i].fd != pos->socket_fd)
297 continue; /* fd mismatch, something else happened, retry later ... */ 297 continue; /* fd mismatch, something else happened, retry later ... */
298 MHD_connection_call_handlers_ (pos, 298 MHD_connection_call_handlers_ (pos,
299 0 != (p[poll_server+i].revents & POLLIN), 299 0 != (p[poll_server + i].revents & POLLIN),
300 0 != (p[poll_server+i].revents & POLLOUT), 300 0 != (p[poll_server + i].revents
301 0 != (p[poll_server+i].revents & MHD_POLL_REVENTS_ERR_DISC)); 301 & POLLOUT),
302 i++; 302 0 != (p[poll_server + i].revents
303 } 303 & MHD_POLL_REVENTS_ERR_DISC));
304 i++;
305 }
304#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 306#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
305 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 307 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
308 {
309 if (i >= num_connections)
310 break; /* connection list changed somehow, retry later ... */
311
312 /* Get next connection here as connection can be removed
313 * from 'daemon->urh_head' list. */
314 urhn = urh->prev;
315 /* Check for fd mismatch. FIXME: required for safety? */
316 if ((p[poll_server + i].fd != urh->connection->socket_fd) ||
317 (p[poll_server + i + 1].fd != urh->mhd.socket))
318 break;
319 urh_from_pollfd (urh,
320 &p[poll_server + i]);
321 i += 2;
322 MHD_upgrade_response_handle_process_ (urh);
323 /* Finished forwarding? */
324 if ( (0 == urh->in_buffer_size) &&
325 (0 == urh->out_buffer_size) &&
326 (0 == urh->in_buffer_used) &&
327 (0 == urh->out_buffer_used) )
306 { 328 {
307 if (i >= num_connections) 329 /* MHD_connection_finish_forward_() will remove connection from
308 break; /* connection list changed somehow, retry later ... */ 330 * 'daemon->urh_head' list. */
309 331 MHD_connection_finish_forward_ (urh->connection);
310 /* Get next connection here as connection can be removed 332 urh->clean_ready = true;
311 * from 'daemon->urh_head' list. */ 333 /* If 'urh->was_closed' already was set to true, connection will be
312 urhn = urh->prev; 334 * moved immediately to cleanup list. Otherwise connection
313 /* Check for fd mismatch. FIXME: required for safety? */ 335 * will stay in suspended list until 'urh' will be marked
314 if ((p[poll_server+i].fd != urh->connection->socket_fd) || 336 * with 'was_closed' by application. */
315 (p[poll_server+i+1].fd != urh->mhd.socket)) 337 MHD_request_resume (&urh->connection->request);
316 break;
317 urh_from_pollfd (urh,
318 &p[poll_server+i]);
319 i += 2;
320 MHD_upgrade_response_handle_process_ (urh);
321 /* Finished forwarding? */
322 if ( (0 == urh->in_buffer_size) &&
323 (0 == urh->out_buffer_size) &&
324 (0 == urh->in_buffer_used) &&
325 (0 == urh->out_buffer_used) )
326 {
327 /* MHD_connection_finish_forward_() will remove connection from
328 * 'daemon->urh_head' list. */
329 MHD_connection_finish_forward_ (urh->connection);
330 urh->clean_ready = true;
331 /* If 'urh->was_closed' already was set to true, connection will be
332 * moved immediately to cleanup list. Otherwise connection
333 * will stay in suspended list until 'urh' will be marked
334 * with 'was_closed' by application. */
335 MHD_request_resume (&urh->connection->request);
336 }
337 } 338 }
339 }
338#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 340#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
339 /* handle 'listen' FD */ 341 /* handle 'listen' FD */
340 if ( (-1 != poll_listen) && 342 if ( (-1 != poll_listen) &&
341 (0 != (p[poll_listen].revents & POLLIN)) ) 343 (0 != (p[poll_listen].revents & POLLIN)) )
342 (void) MHD_accept_connection_ (daemon); 344 (void) MHD_accept_connection_ (daemon);
343 345
344 free(p); 346 free (p);
345 } 347 }
346 return MHD_SC_OK; 348 return MHD_SC_OK;
347} 349}
@@ -356,7 +358,7 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
356 */ 358 */
357enum MHD_StatusCode 359enum MHD_StatusCode
358MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, 360MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
359 bool may_block) 361 bool may_block)
360{ 362{
361 struct pollfd p[2]; 363 struct pollfd p[2];
362 int timeout; 364 int timeout;
@@ -374,21 +376,21 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
374 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && 376 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
375 (! daemon->was_quiesced) ) 377 (! daemon->was_quiesced) )
376 378
377 { 379 {
378 p[poll_count].fd = ls; 380 p[poll_count].fd = ls;
379 p[poll_count].events = POLLIN; 381 p[poll_count].events = POLLIN;
380 p[poll_count].revents = 0; 382 p[poll_count].revents = 0;
381 poll_listen = poll_count; 383 poll_listen = poll_count;
382 poll_count++; 384 poll_count++;
383 } 385 }
384 if (MHD_ITC_IS_VALID_(daemon->itc)) 386 if (MHD_ITC_IS_VALID_ (daemon->itc))
385 { 387 {
386 p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc); 388 p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc);
387 p[poll_count].events = POLLIN; 389 p[poll_count].events = POLLIN;
388 p[poll_count].revents = 0; 390 p[poll_count].revents = 0;
389 poll_itc_idx = poll_count; 391 poll_itc_idx = poll_count;
390 poll_count++; 392 poll_count++;
391 } 393 }
392 394
393 if (! daemon->disallow_suspend_resume) 395 if (! daemon->disallow_suspend_resume)
394 (void) MHD_resume_suspended_connections_ (daemon); 396 (void) MHD_resume_suspended_connections_ (daemon);
@@ -399,22 +401,22 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
399 timeout = -1; 401 timeout = -1;
400 if (0 == poll_count) 402 if (0 == poll_count)
401 return MHD_SC_OK; 403 return MHD_SC_OK;
402 if (MHD_sys_poll_(p, 404 if (MHD_sys_poll_ (p,
403 poll_count, 405 poll_count,
404 timeout) < 0) 406 timeout) < 0)
405 { 407 {
406 const int err = MHD_socket_get_error_ (); 408 const int err = MHD_socket_get_error_ ();
407 409
408 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 410 if (MHD_SCKT_ERR_IS_EINTR_ (err))
409 return MHD_SC_OK; 411 return MHD_SC_OK;
410#ifdef HAVE_MESSAGES 412#ifdef HAVE_MESSAGES
411 MHD_DLOG (daemon, 413 MHD_DLOG (daemon,
412 MHD_SC_UNEXPECTED_POLL_ERROR, 414 MHD_SC_UNEXPECTED_POLL_ERROR,
413 _("poll failed: %s\n"), 415 _ ("poll failed: %s\n"),
414 MHD_socket_strerr_ (err)); 416 MHD_socket_strerr_ (err));
415#endif 417#endif
416 return MHD_SC_UNEXPECTED_POLL_ERROR; 418 return MHD_SC_UNEXPECTED_POLL_ERROR;
417 } 419 }
418 if ( (-1 != poll_itc_idx) && 420 if ( (-1 != poll_itc_idx) &&
419 (0 != (p[poll_itc_idx].revents & POLLIN)) ) 421 (0 != (p[poll_itc_idx].revents & POLLIN)) )
420 MHD_itc_clear_ (daemon->itc); 422 MHD_itc_clear_ (daemon->itc);
@@ -439,16 +441,16 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
439 */ 441 */
440enum MHD_StatusCode 442enum MHD_StatusCode
441MHD_daemon_poll_ (struct MHD_Daemon *daemon, 443MHD_daemon_poll_ (struct MHD_Daemon *daemon,
442 bool may_block) 444 bool may_block)
443{ 445{
444#ifdef HAVE_POLL 446#ifdef HAVE_POLL
445 if (daemon->shutdown) 447 if (daemon->shutdown)
446 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; 448 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
447 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 449 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
448 return MHD_daemon_poll_all_ (daemon, 450 return MHD_daemon_poll_all_ (daemon,
449 may_block); 451 may_block);
450 return MHD_daemon_poll_listen_socket_ (daemon, 452 return MHD_daemon_poll_listen_socket_ (daemon,
451 may_block); 453 may_block);
452#else 454#else
453 /* This code should be dead, as we should have checked 455 /* This code should be dead, as we should have checked
454 this earlier... */ 456 this earlier... */
@@ -472,47 +474,47 @@ MHD_daemon_upgrade_connection_with_poll_ (struct MHD_Connection *con)
472 struct pollfd p[2]; 474 struct pollfd p[2];
473 475
474 memset (p, 476 memset (p,
475 0, 477 0,
476 sizeof (p)); 478 sizeof (p));
477 p[0].fd = urh->connection->socket_fd; 479 p[0].fd = urh->connection->socket_fd;
478 p[1].fd = urh->mhd.socket; 480 p[1].fd = urh->mhd.socket;
479 481
480 while ( (0 != urh->in_buffer_size) || 482 while ( (0 != urh->in_buffer_size) ||
481 (0 != urh->out_buffer_size) || 483 (0 != urh->out_buffer_size) ||
482 (0 != urh->in_buffer_used) || 484 (0 != urh->in_buffer_used) ||
483 (0 != urh->out_buffer_used) ) 485 (0 != urh->out_buffer_used) )
484 { 486 {
485 int timeout; 487 int timeout;
486 488
487 urh_update_pollfd (urh, 489 urh_update_pollfd (urh,
488 p); 490 p);
489 491
490 if ( (con->tls_read_ready) && 492 if ( (con->tls_read_ready) &&
491 (urh->in_buffer_used < urh->in_buffer_size)) 493 (urh->in_buffer_used < urh->in_buffer_size))
492 timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */ 494 timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */
493 else 495 else
494 timeout = -1; 496 timeout = -1;
495 497
496 if (MHD_sys_poll_ (p, 498 if (MHD_sys_poll_ (p,
497 2, 499 2,
498 timeout) < 0) 500 timeout) < 0)
499 { 501 {
500 const int err = MHD_socket_get_error_ (); 502 const int err = MHD_socket_get_error_ ();
501 503
502 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 504 if (MHD_SCKT_ERR_IS_EINTR_ (err))
503 continue; 505 continue;
504#ifdef HAVE_MESSAGES 506#ifdef HAVE_MESSAGES
505 MHD_DLOG (con->daemon, 507 MHD_DLOG (con->daemon,
506 MHD_SC_UNEXPECTED_POLL_ERROR, 508 MHD_SC_UNEXPECTED_POLL_ERROR,
507 _("Error during poll: `%s'\n"), 509 _ ("Error during poll: `%s'\n"),
508 MHD_socket_strerr_ (err)); 510 MHD_socket_strerr_ (err));
509#endif 511#endif
510 break; 512 break;
511 }
512 urh_from_pollfd (urh,
513 p);
514 MHD_upgrade_response_handle_process_ (urh);
515 } 513 }
514 urh_from_pollfd (urh,
515 p);
516 MHD_upgrade_response_handle_process_ (urh);
517 }
516} 518}
517#endif 519#endif
518#endif 520#endif
diff --git a/src/lib/daemon_poll.h b/src/lib/daemon_poll.h
index fc5663b0..3c408620 100644
--- a/src/lib/daemon_poll.h
+++ b/src/lib/daemon_poll.h
@@ -37,8 +37,8 @@
37 */ 37 */
38enum MHD_StatusCode 38enum MHD_StatusCode
39MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, 39MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
40 bool may_block) 40 bool may_block)
41 MHD_NONNULL(1); 41MHD_NONNULL (1);
42 42
43 43
44/** 44/**
@@ -50,8 +50,8 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon,
50 */ 50 */
51enum MHD_StatusCode 51enum MHD_StatusCode
52MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, 52MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
53 bool may_block) 53 bool may_block)
54 MHD_NONNULL (1); 54MHD_NONNULL (1);
55 55
56 56
57/** 57/**
@@ -63,8 +63,8 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon,
63 */ 63 */
64enum MHD_StatusCode 64enum MHD_StatusCode
65MHD_daemon_poll_ (struct MHD_Daemon *daemon, 65MHD_daemon_poll_ (struct MHD_Daemon *daemon,
66 bool may_block) 66 bool may_block)
67 MHD_NONNULL (1); 67MHD_NONNULL (1);
68#endif 68#endif
69 69
70 70
@@ -78,7 +78,7 @@ MHD_daemon_poll_ (struct MHD_Daemon *daemon,
78 */ 78 */
79void 79void
80MHD_daemon_upgrade_connection_with_poll_ (struct MHD_Connection *con) 80MHD_daemon_upgrade_connection_with_poll_ (struct MHD_Connection *con)
81 MHD_NONNULL(1); 81MHD_NONNULL (1);
82#endif 82#endif
83#endif 83#endif
84 84
diff --git a/src/lib/daemon_quiesce.c b/src/lib/daemon_quiesce.c
index 0d920608..c7275099 100644
--- a/src/lib/daemon_quiesce.c
+++ b/src/lib/daemon_quiesce.c
@@ -54,75 +54,76 @@ MHD_daemon_quiesce (struct MHD_Daemon *daemon)
54 return MHD_INVALID_SOCKET; 54 return MHD_INVALID_SOCKET;
55 if ( (daemon->disable_itc) && 55 if ( (daemon->disable_itc) &&
56 (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) ) 56 (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) )
57 { 57 {
58#ifdef HAVE_MESSAGES 58#ifdef HAVE_MESSAGES
59 MHD_DLOG (daemon, 59 MHD_DLOG (daemon,
60 MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC, 60 MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC,
61 "Using MHD_quiesce_daemon in this mode requires ITC\n"); 61 "Using MHD_quiesce_daemon in this mode requires ITC\n");
62#endif 62#endif
63 return MHD_INVALID_SOCKET; 63 return MHD_INVALID_SOCKET;
64 } 64 }
65 65
66 if (NULL != daemon->worker_pool) 66 if (NULL != daemon->worker_pool)
67 {
68 unsigned int i;
69
70 for (i = 0; i < daemon->worker_pool_size; i++)
67 { 71 {
68 unsigned int i; 72 struct MHD_Daemon *worker = &daemon->worker_pool[i];
69 73
70 for (i = 0; i < daemon->worker_pool_size; i++) 74 worker->was_quiesced = true;
71 {
72 struct MHD_Daemon *worker = &daemon->worker_pool[i];
73
74 worker->was_quiesced = true;
75#ifdef EPOLL_SUPPORT
76 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
77 (-1 != worker->epoll_fd) &&
78 (worker->listen_socket_in_epoll) )
79 {
80 if (0 != epoll_ctl (worker->epoll_fd,
81 EPOLL_CTL_DEL,
82 listen_socket,
83 NULL))
84 MHD_PANIC (_("Failed to remove listen FD from epoll set\n"));
85 worker->listen_socket_in_epoll = false;
86 }
87 else
88#endif
89 if (MHD_ITC_IS_VALID_(worker->itc))
90 {
91 if (! MHD_itc_activate_ (worker->itc,
92 "q"))
93 MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel"));
94 }
95 }
96 daemon->was_quiesced = true;
97#ifdef EPOLL_SUPPORT 75#ifdef EPOLL_SUPPORT
98 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 76 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
99 (-1 != daemon->epoll_fd) && 77 (-1 != worker->epoll_fd) &&
100 (daemon->listen_socket_in_epoll) ) 78 (worker->listen_socket_in_epoll) )
101 { 79 {
102 if (0 != epoll_ctl (daemon->epoll_fd, 80 if (0 != epoll_ctl (worker->epoll_fd,
103 EPOLL_CTL_DEL, 81 EPOLL_CTL_DEL,
104 listen_socket, 82 listen_socket,
105 NULL)) 83 NULL))
106 MHD_PANIC ("Failed to remove listen FD from epoll set\n"); 84 MHD_PANIC (_ ("Failed to remove listen FD from epoll set\n"));
107 daemon->listen_socket_in_epoll = false; 85 worker->listen_socket_in_epoll = false;
108 } 86 }
87 else
109#endif 88#endif
89 if (MHD_ITC_IS_VALID_ (worker->itc))
90 {
91 if (! MHD_itc_activate_ (worker->itc,
92 "q"))
93 MHD_PANIC (_ (
94 "Failed to signal quiesce via inter-thread communication channel"));
95 }
110 } 96 }
111 97 daemon->was_quiesced = true;
112 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 98#ifdef EPOLL_SUPPORT
99 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
100 (-1 != daemon->epoll_fd) &&
101 (daemon->listen_socket_in_epoll) )
102 {
103 if (0 != epoll_ctl (daemon->epoll_fd,
104 EPOLL_CTL_DEL,
105 listen_socket,
106 NULL))
107 MHD_PANIC ("Failed to remove listen FD from epoll set\n");
108 daemon->listen_socket_in_epoll = false;
109 }
110#endif
111 }
112
113 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
113 (! MHD_itc_activate_ (daemon->itc, 114 (! MHD_itc_activate_ (daemon->itc,
114 "q")) ) 115 "q")) )
115 MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); 116 MHD_PANIC (_ (
117 "Failed to signal quiesce via inter-thread communication channel"));
116 118
117 /* FIXME: we might want some bi-directional communication here 119 /* FIXME: we might want some bi-directional communication here
118 (in both the thread-pool and single-thread case!) 120 (in both the thread-pool and single-thread case!)
119 to be sure that the threads have stopped using the listen 121 to be sure that the threads have stopped using the listen
120 socket, otherwise there is still the possibility of a race 122 socket, otherwise there is still the possibility of a race
121 between a thread accept()ing and the caller closing and 123 between a thread accept()ing and the caller closing and
122 re-binding the socket. */ 124 re-binding the socket. */
123 125
124 return listen_socket; 126 return listen_socket;
125} 127}
126 128
127/* end of daemon_quiesce.c */ 129/* end of daemon_quiesce.c */
128
diff --git a/src/lib/daemon_run.c b/src/lib/daemon_run.c
index 129f7efb..cae500da 100644
--- a/src/lib/daemon_run.c
+++ b/src/lib/daemon_run.c
@@ -57,26 +57,26 @@ MHD_daemon_run (struct MHD_Daemon *daemon)
57 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) 57 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode)
58 return MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_EXTERNAL; 58 return MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_EXTERNAL;
59 switch (daemon->event_loop_syscall) 59 switch (daemon->event_loop_syscall)
60 { 60 {
61 case MHD_ELS_POLL: 61 case MHD_ELS_POLL:
62 sc = MHD_daemon_poll_ (daemon, 62 sc = MHD_daemon_poll_ (daemon,
63 MHD_NO); 63 MHD_NO);
64 MHD_connection_cleanup_ (daemon); 64 MHD_connection_cleanup_ (daemon);
65 return sc; 65 return sc;
66#ifdef EPOLL_SUPPORT 66#ifdef EPOLL_SUPPORT
67 case MHD_ELS_EPOLL: 67 case MHD_ELS_EPOLL:
68 sc = MHD_daemon_epoll_ (daemon, 68 sc = MHD_daemon_epoll_ (daemon,
69 MHD_NO); 69 MHD_NO);
70 MHD_connection_cleanup_ (daemon); 70 MHD_connection_cleanup_ (daemon);
71 return sc; 71 return sc;
72#endif 72#endif
73 case MHD_ELS_SELECT: 73 case MHD_ELS_SELECT:
74 return MHD_daemon_select_ (daemon, 74 return MHD_daemon_select_ (daemon,
75 MHD_NO); 75 MHD_NO);
76 /* MHD_select does MHD_connection_cleanup_ already */ 76 /* MHD_select does MHD_connection_cleanup_ already */
77 default: 77 default:
78 return MHD_SC_CONFIGURATION_UNEXPECTED_ELS; 78 return MHD_SC_CONFIGURATION_UNEXPECTED_ELS;
79 } 79 }
80} 80}
81 81
82/* end of daemon_run.c */ 82/* end of daemon_run.c */
diff --git a/src/lib/daemon_select.c b/src/lib/daemon_select.c
index 08281d8c..69913a9a 100644
--- a/src/lib/daemon_select.c
+++ b/src/lib/daemon_select.c
@@ -66,17 +66,17 @@
66 */ 66 */
67enum MHD_StatusCode 67enum MHD_StatusCode
68MHD_daemon_get_fdset (struct MHD_Daemon *daemon, 68MHD_daemon_get_fdset (struct MHD_Daemon *daemon,
69 fd_set *read_fd_set, 69 fd_set *read_fd_set,
70 fd_set *write_fd_set, 70 fd_set *write_fd_set,
71 fd_set *except_fd_set, 71 fd_set *except_fd_set,
72 MHD_socket *max_fd) 72 MHD_socket *max_fd)
73{ 73{
74 return MHD_daemon_get_fdset2 (daemon, 74 return MHD_daemon_get_fdset2 (daemon,
75 read_fd_set, 75 read_fd_set,
76 write_fd_set, 76 write_fd_set,
77 except_fd_set, 77 except_fd_set,
78 max_fd, 78 max_fd,
79 _MHD_SYS_DEFAULT_FD_SETSIZE); 79 _MHD_SYS_DEFAULT_FD_SETSIZE);
80} 80}
81 81
82 82
@@ -108,55 +108,55 @@ urh_to_fdset (struct MHD_UpgradeResponseHandle *urh,
108 /* Do not add to 'es' only if socket is closed 108 /* Do not add to 'es' only if socket is closed
109 * or not used anymore. */ 109 * or not used anymore. */
110 if (MHD_INVALID_SOCKET != conn_sckt) 110 if (MHD_INVALID_SOCKET != conn_sckt)
111 { 111 {
112 if ( (urh->in_buffer_used < urh->in_buffer_size) && 112 if ( (urh->in_buffer_used < urh->in_buffer_size) &&
113 (! MHD_add_to_fd_set_ (conn_sckt, 113 (! MHD_add_to_fd_set_ (conn_sckt,
114 rs, 114 rs,
115 max_fd, 115 max_fd,
116 fd_setsize)) ) 116 fd_setsize)) )
117 res = false; 117 res = false;
118 if ( (0 != urh->out_buffer_used) && 118 if ( (0 != urh->out_buffer_used) &&
119 (! MHD_add_to_fd_set_ (conn_sckt, 119 (! MHD_add_to_fd_set_ (conn_sckt,
120 ws, 120 ws,
121 max_fd, 121 max_fd,
122 fd_setsize)) ) 122 fd_setsize)) )
123 res = false; 123 res = false;
124 /* Do not monitor again for errors if error was detected before as 124 /* Do not monitor again for errors if error was detected before as
125 * error state is remembered. */ 125 * error state is remembered. */
126 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) && 126 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) &&
127 ((0 != urh->in_buffer_size) || 127 ((0 != urh->in_buffer_size) ||
128 (0 != urh->out_buffer_size) || 128 (0 != urh->out_buffer_size) ||
129 (0 != urh->out_buffer_used))) 129 (0 != urh->out_buffer_used)))
130 MHD_add_to_fd_set_ (conn_sckt, 130 MHD_add_to_fd_set_ (conn_sckt,
131 es, 131 es,
132 max_fd, 132 max_fd,
133 fd_setsize); 133 fd_setsize);
134 } 134 }
135 if (MHD_INVALID_SOCKET != mhd_sckt) 135 if (MHD_INVALID_SOCKET != mhd_sckt)
136 { 136 {
137 if ( (urh->out_buffer_used < urh->out_buffer_size) && 137 if ( (urh->out_buffer_used < urh->out_buffer_size) &&
138 (! MHD_add_to_fd_set_ (mhd_sckt, 138 (! MHD_add_to_fd_set_ (mhd_sckt,
139 rs, 139 rs,
140 max_fd, 140 max_fd,
141 fd_setsize)) ) 141 fd_setsize)) )
142 res = false; 142 res = false;
143 if ( (0 != urh->in_buffer_used) && 143 if ( (0 != urh->in_buffer_used) &&
144 (! MHD_add_to_fd_set_ (mhd_sckt, 144 (! MHD_add_to_fd_set_ (mhd_sckt,
145 ws, 145 ws,
146 max_fd, 146 max_fd,
147 fd_setsize)) ) 147 fd_setsize)) )
148 res = false; 148 res = false;
149 /* Do not monitor again for errors if error was detected before as 149 /* Do not monitor again for errors if error was detected before as
150 * error state is remembered. */ 150 * error state is remembered. */
151 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) && 151 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) &&
152 ((0 != urh->out_buffer_size) || 152 ((0 != urh->out_buffer_size) ||
153 (0 != urh->in_buffer_size) || 153 (0 != urh->in_buffer_size) ||
154 (0 != urh->in_buffer_used))) 154 (0 != urh->in_buffer_used)))
155 MHD_add_to_fd_set_ (mhd_sckt, 155 MHD_add_to_fd_set_ (mhd_sckt,
156 es, 156 es,
157 max_fd, 157 max_fd,
158 fd_setsize); 158 fd_setsize);
159 } 159 }
160 160
161 return res; 161 return res;
162} 162}
@@ -207,77 +207,77 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
207 * or INFO_WRITE sockets will not fit 'except_fd_set'. */ 207 * or INFO_WRITE sockets will not fit 'except_fd_set'. */
208 /* Start from oldest connections. Make sense for W32 FDSETs. */ 208 /* Start from oldest connections. Make sense for W32 FDSETs. */
209 for (pos = daemon->connections_tail; NULL != pos; pos = posn) 209 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
210 {
211 posn = pos->prev;
212
213 switch (pos->request.event_loop_info)
210 { 214 {
211 posn = pos->prev; 215 case MHD_EVENT_LOOP_INFO_READ:
212 216 if (! MHD_add_to_fd_set_ (pos->socket_fd,
213 switch (pos->request.event_loop_info) 217 read_fd_set,
214 { 218 max_fd,
215 case MHD_EVENT_LOOP_INFO_READ: 219 fd_setsize))
216 if (! MHD_add_to_fd_set_ (pos->socket_fd, 220 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
217 read_fd_set,
218 max_fd,
219 fd_setsize))
220 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
221#ifdef MHD_POSIX_SOCKETS 221#ifdef MHD_POSIX_SOCKETS
222 MHD_add_to_fd_set_ (pos->socket_fd, 222 MHD_add_to_fd_set_ (pos->socket_fd,
223 except_fd_set, 223 except_fd_set,
224 max_fd, 224 max_fd,
225 fd_setsize); 225 fd_setsize);
226#endif /* MHD_POSIX_SOCKETS */ 226#endif /* MHD_POSIX_SOCKETS */
227 break; 227 break;
228 case MHD_EVENT_LOOP_INFO_WRITE: 228 case MHD_EVENT_LOOP_INFO_WRITE:
229 if (! MHD_add_to_fd_set_ (pos->socket_fd, 229 if (! MHD_add_to_fd_set_ (pos->socket_fd,
230 write_fd_set, 230 write_fd_set,
231 max_fd, 231 max_fd,
232 fd_setsize)) 232 fd_setsize))
233 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 233 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
234#ifdef MHD_POSIX_SOCKETS 234#ifdef MHD_POSIX_SOCKETS
235 MHD_add_to_fd_set_ (pos->socket_fd, 235 MHD_add_to_fd_set_ (pos->socket_fd,
236 except_fd_set, 236 except_fd_set,
237 max_fd, 237 max_fd,
238 fd_setsize); 238 fd_setsize);
239#endif /* MHD_POSIX_SOCKETS */ 239#endif /* MHD_POSIX_SOCKETS */
240 break; 240 break;
241 case MHD_EVENT_LOOP_INFO_BLOCK: 241 case MHD_EVENT_LOOP_INFO_BLOCK:
242 if ( (NULL == except_fd_set) || 242 if ( (NULL == except_fd_set) ||
243 ! MHD_add_to_fd_set_ (pos->socket_fd, 243 ! MHD_add_to_fd_set_ (pos->socket_fd,
244 except_fd_set, 244 except_fd_set,
245 max_fd, 245 max_fd,
246 fd_setsize)) 246 fd_setsize))
247 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 247 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
248 break; 248 break;
249 case MHD_EVENT_LOOP_INFO_CLEANUP: 249 case MHD_EVENT_LOOP_INFO_CLEANUP:
250 /* this should never happen */ 250 /* this should never happen */
251 break; 251 break;
252 }
253 } 252 }
253 }
254#ifdef MHD_WINSOCK_SOCKETS 254#ifdef MHD_WINSOCK_SOCKETS
255 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets 255 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets
256 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will 256 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will
257 * not be pushed out. */ 257 * not be pushed out. */
258 for (pos = daemon->connections_tail; NULL != pos; pos = posn) 258 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
259 { 259 {
260 posn = pos->prev; 260 posn = pos->prev;
261 MHD_add_to_fd_set_ (pos->socket_fd, 261 MHD_add_to_fd_set_ (pos->socket_fd,
262 except_fd_set, 262 except_fd_set,
263 max_fd, 263 max_fd,
264 fd_setsize); 264 fd_setsize);
265 } 265 }
266#endif /* MHD_WINSOCK_SOCKETS */ 266#endif /* MHD_WINSOCK_SOCKETS */
267#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 267#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
268 { 268 {
269 struct MHD_UpgradeResponseHandle *urh; 269 struct MHD_UpgradeResponseHandle *urh;
270 270
271 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) 271 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
272 { 272 {
273 if (! urh_to_fdset (urh, 273 if (! urh_to_fdset (urh,
274 read_fd_set, 274 read_fd_set,
275 write_fd_set, 275 write_fd_set,
276 except_fd_set, 276 except_fd_set,
277 max_fd, 277 max_fd,
278 fd_setsize)) 278 fd_setsize))
279 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 279 result = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
280 } 280 }
281 } 281 }
282#endif 282#endif
283 return result; 283 return result;
@@ -313,11 +313,11 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
313 */ 313 */
314enum MHD_StatusCode 314enum MHD_StatusCode
315MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon, 315MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon,
316 fd_set *read_fd_set, 316 fd_set *read_fd_set,
317 fd_set *write_fd_set, 317 fd_set *write_fd_set,
318 fd_set *except_fd_set, 318 fd_set *except_fd_set,
319 MHD_socket *max_fd, 319 MHD_socket *max_fd,
320 unsigned int fd_setsize) 320 unsigned int fd_setsize)
321{ 321{
322 if ( (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) || 322 if ( (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) ||
323 (MHD_ELS_POLL == daemon->event_loop_syscall) ) 323 (MHD_ELS_POLL == daemon->event_loop_syscall) )
@@ -325,28 +325,28 @@ MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon,
325 325
326#ifdef EPOLL_SUPPORT 326#ifdef EPOLL_SUPPORT
327 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 327 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
328 { 328 {
329 if (daemon->shutdown) 329 if (daemon->shutdown)
330 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; 330 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
331 331
332 /* we're in epoll mode, use the epoll FD as a stand-in for 332 /* we're in epoll mode, use the epoll FD as a stand-in for
333 the entire event set */ 333 the entire event set */
334 334
335 return MHD_add_to_fd_set_ (daemon->epoll_fd, 335 return MHD_add_to_fd_set_ (daemon->epoll_fd,
336 read_fd_set, 336 read_fd_set,
337 max_fd, 337 max_fd,
338 fd_setsize) 338 fd_setsize)
339 ? MHD_SC_OK 339 ? MHD_SC_OK
340 : MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 340 : MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
341 } 341 }
342#endif 342#endif
343 343
344 return internal_get_fdset2 (daemon, 344 return internal_get_fdset2 (daemon,
345 read_fd_set, 345 read_fd_set,
346 write_fd_set, 346 write_fd_set,
347 except_fd_set, 347 except_fd_set,
348 max_fd, 348 max_fd,
349 fd_setsize); 349 fd_setsize);
350} 350}
351 351
352 352
@@ -374,23 +374,23 @@ urh_from_fdset (struct MHD_UpgradeResponseHandle *urh,
374 urh->mhd.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); 374 urh->mhd.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY);
375 375
376 if (MHD_INVALID_SOCKET != conn_sckt) 376 if (MHD_INVALID_SOCKET != conn_sckt)
377 { 377 {
378 if (FD_ISSET (conn_sckt, rs)) 378 if (FD_ISSET (conn_sckt, rs))
379 urh->app.celi |= MHD_EPOLL_STATE_READ_READY; 379 urh->app.celi |= MHD_EPOLL_STATE_READ_READY;
380 if (FD_ISSET (conn_sckt, ws)) 380 if (FD_ISSET (conn_sckt, ws))
381 urh->app.celi |= MHD_EPOLL_STATE_WRITE_READY; 381 urh->app.celi |= MHD_EPOLL_STATE_WRITE_READY;
382 if (FD_ISSET (conn_sckt, es)) 382 if (FD_ISSET (conn_sckt, es))
383 urh->app.celi |= MHD_EPOLL_STATE_ERROR; 383 urh->app.celi |= MHD_EPOLL_STATE_ERROR;
384 } 384 }
385 if ((MHD_INVALID_SOCKET != mhd_sckt)) 385 if ((MHD_INVALID_SOCKET != mhd_sckt))
386 { 386 {
387 if (FD_ISSET (mhd_sckt, rs)) 387 if (FD_ISSET (mhd_sckt, rs))
388 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY; 388 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY;
389 if (FD_ISSET (mhd_sckt, ws)) 389 if (FD_ISSET (mhd_sckt, ws))
390 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY; 390 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY;
391 if (FD_ISSET (mhd_sckt, es)) 391 if (FD_ISSET (mhd_sckt, es))
392 urh->mhd.celi |= MHD_EPOLL_STATE_ERROR; 392 urh->mhd.celi |= MHD_EPOLL_STATE_ERROR;
393 } 393 }
394} 394}
395#endif 395#endif
396 396
@@ -425,7 +425,7 @@ internal_run_from_select (struct MHD_Daemon *daemon,
425 /* Clear ITC to avoid spinning select */ 425 /* Clear ITC to avoid spinning select */
426 /* Do it before any other processing so new signals 426 /* Do it before any other processing so new signals
427 will trigger select again and will be processed */ 427 will trigger select again and will be processed */
428 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 428 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
429 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc), 429 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc),
430 read_fd_set)) ) 430 read_fd_set)) )
431 MHD_itc_clear_ (daemon->itc); 431 MHD_itc_clear_ (daemon->itc);
@@ -438,49 +438,49 @@ internal_run_from_select (struct MHD_Daemon *daemon,
438 (void) MHD_accept_connection_ (daemon); 438 (void) MHD_accept_connection_ (daemon);
439 439
440 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 440 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
441 {
442 /* do not have a thread per connection, process all connections now */
443 prev = daemon->connections_tail;
444 while (NULL != (pos = prev))
441 { 445 {
442 /* do not have a thread per connection, process all connections now */ 446 prev = pos->prev;
443 prev = daemon->connections_tail; 447 ds = pos->socket_fd;
444 while (NULL != (pos = prev)) 448 if (MHD_INVALID_SOCKET == ds)
445 { 449 continue;
446 prev = pos->prev; 450 MHD_connection_call_handlers_ (pos,
447 ds = pos->socket_fd; 451 FD_ISSET (ds,
448 if (MHD_INVALID_SOCKET == ds) 452 read_fd_set),
449 continue; 453 FD_ISSET (ds,
450 MHD_connection_call_handlers_ (pos, 454 write_fd_set),
451 FD_ISSET (ds, 455 FD_ISSET (ds,
452 read_fd_set), 456 except_fd_set));
453 FD_ISSET (ds,
454 write_fd_set),
455 FD_ISSET (ds,
456 except_fd_set));
457 }
458 } 457 }
458 }
459 459
460#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 460#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
461 /* handle upgraded HTTPS connections */ 461 /* handle upgraded HTTPS connections */
462 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 462 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
463 {
464 urhn = urh->prev;
465 /* update urh state based on select() output */
466 urh_from_fdset (urh,
467 read_fd_set,
468 write_fd_set,
469 except_fd_set);
470 /* call generic forwarding function for passing data */
471 MHD_upgrade_response_handle_process_ (urh);
472 /* Finished forwarding? */
473 if ( (0 == urh->in_buffer_size) &&
474 (0 == urh->out_buffer_size) &&
475 (0 == urh->in_buffer_used) &&
476 (0 == urh->out_buffer_used) )
463 { 477 {
464 urhn = urh->prev; 478 MHD_connection_finish_forward_ (urh->connection);
465 /* update urh state based on select() output */ 479 urh->clean_ready = true;
466 urh_from_fdset (urh, 480 /* Resuming will move connection to cleanup list. */
467 read_fd_set, 481 MHD_request_resume (&urh->connection->request);
468 write_fd_set,
469 except_fd_set);
470 /* call generic forwarding function for passing data */
471 MHD_upgrade_response_handle_process_ (urh);
472 /* Finished forwarding? */
473 if ( (0 == urh->in_buffer_size) &&
474 (0 == urh->out_buffer_size) &&
475 (0 == urh->in_buffer_used) &&
476 (0 == urh->out_buffer_used) )
477 {
478 MHD_connection_finish_forward_ (urh->connection);
479 urh->clean_ready = true;
480 /* Resuming will move connection to cleanup list. */
481 MHD_request_resume (&urh->connection->request);
482 }
483 } 482 }
483 }
484#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 484#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
485 MHD_connection_cleanup_ (daemon); 485 MHD_connection_cleanup_ (daemon);
486 return MHD_SC_OK; 486 return MHD_SC_OK;
@@ -500,80 +500,80 @@ MHD_daemon_upgrade_connection_with_select_ (struct MHD_Connection *con)
500 struct MHD_UpgradeResponseHandle *urh = con->request.urh; 500 struct MHD_UpgradeResponseHandle *urh = con->request.urh;
501 501
502 while ( (0 != urh->in_buffer_size) || 502 while ( (0 != urh->in_buffer_size) ||
503 (0 != urh->out_buffer_size) || 503 (0 != urh->out_buffer_size) ||
504 (0 != urh->in_buffer_used) || 504 (0 != urh->in_buffer_used) ||
505 (0 != urh->out_buffer_used) ) 505 (0 != urh->out_buffer_used) )
506 {
507 /* use select */
508 fd_set rs;
509 fd_set ws;
510 fd_set es;
511 MHD_socket max_fd;
512 int num_ready;
513 bool result;
514
515 FD_ZERO (&rs);
516 FD_ZERO (&ws);
517 FD_ZERO (&es);
518 max_fd = MHD_INVALID_SOCKET;
519 result = urh_to_fdset (urh,
520 &rs,
521 &ws,
522 &es,
523 &max_fd,
524 FD_SETSIZE);
525 if (! result)
506 { 526 {
507 /* use select */
508 fd_set rs;
509 fd_set ws;
510 fd_set es;
511 MHD_socket max_fd;
512 int num_ready;
513 bool result;
514
515 FD_ZERO (&rs);
516 FD_ZERO (&ws);
517 FD_ZERO (&es);
518 max_fd = MHD_INVALID_SOCKET;
519 result = urh_to_fdset (urh,
520 &rs,
521 &ws,
522 &es,
523 &max_fd,
524 FD_SETSIZE);
525 if (! result)
526 {
527#ifdef HAVE_MESSAGES 527#ifdef HAVE_MESSAGES
528 MHD_DLOG (con->daemon, 528 MHD_DLOG (con->daemon,
529 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE, 529 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
530 _("Error preparing select\n")); 530 _ ("Error preparing select\n"));
531#endif 531#endif
532 break; 532 break;
533 } 533 }
534 /* FIXME: does this check really needed? */ 534 /* FIXME: does this check really needed? */
535 if (MHD_INVALID_SOCKET != max_fd) 535 if (MHD_INVALID_SOCKET != max_fd)
536 { 536 {
537 struct timeval* tvp; 537 struct timeval*tvp;
538 struct timeval tv; 538 struct timeval tv;
539 if ( (con->tls_read_ready) && 539 if ( (con->tls_read_ready) &&
540 (urh->in_buffer_used < urh->in_buffer_size)) 540 (urh->in_buffer_used < urh->in_buffer_size))
541 { /* No need to wait if incoming data is already pending in TLS buffers. */ 541 { /* No need to wait if incoming data is already pending in TLS buffers. */
542 tv.tv_sec = 0; 542 tv.tv_sec = 0;
543 tv.tv_usec = 0; 543 tv.tv_usec = 0;
544 tvp = &tv; 544 tvp = &tv;
545 } 545 }
546 else
547 tvp = NULL;
548 num_ready = MHD_SYS_select_ (max_fd + 1,
549 &rs,
550 &ws,
551 &es,
552 tvp);
553 }
554 else 546 else
555 num_ready = 0; 547 tvp = NULL;
556 if (num_ready < 0) 548 num_ready = MHD_SYS_select_ (max_fd + 1,
557 { 549 &rs,
558 const int err = MHD_socket_get_error_(); 550 &ws,
551 &es,
552 tvp);
553 }
554 else
555 num_ready = 0;
556 if (num_ready < 0)
557 {
558 const int err = MHD_socket_get_error_ ();
559 559
560 if (MHD_SCKT_ERR_IS_EINTR_(err)) 560 if (MHD_SCKT_ERR_IS_EINTR_ (err))
561 continue; 561 continue;
562#ifdef HAVE_MESSAGES 562#ifdef HAVE_MESSAGES
563 MHD_DLOG (con->daemon, 563 MHD_DLOG (con->daemon,
564 MHD_SC_UNEXPECTED_SELECT_ERROR, 564 MHD_SC_UNEXPECTED_SELECT_ERROR,
565 _("Error during select (%d): `%s'\n"), 565 _ ("Error during select (%d): `%s'\n"),
566 err, 566 err,
567 MHD_socket_strerr_ (err)); 567 MHD_socket_strerr_ (err));
568#endif 568#endif
569 break; 569 break;
570 }
571 urh_from_fdset (urh,
572 &rs,
573 &ws,
574 &es);
575 MHD_upgrade_response_handle_process_ (urh);
576 } 570 }
571 urh_from_fdset (urh,
572 &rs,
573 &ws,
574 &es);
575 MHD_upgrade_response_handle_process_ (urh);
576 }
577} 577}
578#endif 578#endif
579 579
@@ -602,37 +602,37 @@ MHD_daemon_upgrade_connection_with_select_ (struct MHD_Connection *con)
602 */ 602 */
603enum MHD_StatusCode 603enum MHD_StatusCode
604MHD_daemon_run_from_select (struct MHD_Daemon *daemon, 604MHD_daemon_run_from_select (struct MHD_Daemon *daemon,
605 const fd_set *read_fd_set, 605 const fd_set *read_fd_set,
606 606
607 607
608 const fd_set *write_fd_set, 608 const fd_set *write_fd_set,
609 const fd_set *except_fd_set) 609 const fd_set *except_fd_set)
610{ 610{
611 if ( (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) || 611 if ( (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) ||
612 (MHD_ELS_POLL == daemon->event_loop_syscall) ) 612 (MHD_ELS_POLL == daemon->event_loop_syscall) )
613 return MHD_SC_CONFIGURATION_MISSMATCH_FOR_RUN_SELECT; 613 return MHD_SC_CONFIGURATION_MISSMATCH_FOR_RUN_SELECT;
614 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 614 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
615 { 615 {
616#ifdef EPOLL_SUPPORT 616#ifdef EPOLL_SUPPORT
617 enum MHD_StatusCode sc; 617 enum MHD_StatusCode sc;
618 618
619 sc = MHD_daemon_epoll_ (daemon, 619 sc = MHD_daemon_epoll_ (daemon,
620 MHD_NO); 620 MHD_NO);
621 MHD_connection_cleanup_ (daemon); 621 MHD_connection_cleanup_ (daemon);
622 return sc; 622 return sc;
623#else /* ! EPOLL_SUPPORT */ 623#else /* ! EPOLL_SUPPORT */
624 return MHD_NO; 624 return MHD_NO;
625#endif /* ! EPOLL_SUPPORT */ 625#endif /* ! EPOLL_SUPPORT */
626 } 626 }
627 627
628 /* Resuming external connections when using an extern mainloop */ 628 /* Resuming external connections when using an extern mainloop */
629 if (! daemon->disallow_suspend_resume) 629 if (! daemon->disallow_suspend_resume)
630 (void) MHD_resume_suspended_connections_ (daemon); 630 (void) MHD_resume_suspended_connections_ (daemon);
631 631
632 return internal_run_from_select (daemon, 632 return internal_run_from_select (daemon,
633 read_fd_set, 633 read_fd_set,
634 write_fd_set, 634 write_fd_set,
635 except_fd_set); 635 except_fd_set);
636} 636}
637 637
638 638
@@ -646,7 +646,7 @@ MHD_daemon_run_from_select (struct MHD_Daemon *daemon,
646 */ 646 */
647enum MHD_StatusCode 647enum MHD_StatusCode
648MHD_daemon_select_ (struct MHD_Daemon *daemon, 648MHD_daemon_select_ (struct MHD_Daemon *daemon,
649 int may_block) 649 int may_block)
650{ 650{
651 int num_ready; 651 int num_ready;
652 fd_set rs; 652 fd_set rs;
@@ -675,74 +675,75 @@ MHD_daemon_select_ (struct MHD_Daemon *daemon,
675 may_block = MHD_NO; 675 may_block = MHD_NO;
676 676
677 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) 677 if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode)
678 { 678 {
679 679
680 /* single-threaded, go over everything */ 680 /* single-threaded, go over everything */
681 if (MHD_SC_OK != 681 if (MHD_SC_OK !=
682 (sc = internal_get_fdset2 (daemon, 682 (sc = internal_get_fdset2 (daemon,
683 &rs, 683 &rs,
684 &ws, 684 &ws,
685 &es, 685 &es,
686 &maxsock, 686 &maxsock,
687 FD_SETSIZE))) 687 FD_SETSIZE)))
688 { 688 {
689#ifdef HAVE_MESSAGES 689#ifdef HAVE_MESSAGES
690 MHD_DLOG (daemon, 690 MHD_DLOG (daemon,
691 sc, 691 sc,
692 _("Could not obtain daemon fdsets")); 692 _ ("Could not obtain daemon fdsets"));
693#endif 693#endif
694 }
695 } 694 }
695 }
696 else 696 else
697 {
698 /* accept only, have one thread per connection */
699 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
700 (! daemon->was_quiesced) &&
701 (! MHD_add_to_fd_set_ (ls,
702 &rs,
703 &maxsock,
704 FD_SETSIZE)) )
697 { 705 {
698 /* accept only, have one thread per connection */
699 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
700 (! daemon->was_quiesced) &&
701 (! MHD_add_to_fd_set_ (ls,
702 &rs,
703 &maxsock,
704 FD_SETSIZE)) )
705 {
706#ifdef HAVE_MESSAGES 706#ifdef HAVE_MESSAGES
707 MHD_DLOG (daemon, 707 MHD_DLOG (daemon,
708 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE, 708 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
709 _("Could not add listen socket to fdset")); 709 _ ("Could not add listen socket to fdset"));
710#endif 710#endif
711 return MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 711 return MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
712 }
713 } 712 }
714 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 713 }
714 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
715 (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc), 715 (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
716 &rs, 716 &rs,
717 &maxsock, 717 &maxsock,
718 FD_SETSIZE)) ) 718 FD_SETSIZE)) )
719 { 719 {
720#if defined(MHD_WINSOCK_SOCKETS) 720#if defined(MHD_WINSOCK_SOCKETS)
721 /* fdset limit reached, new connections 721 /* fdset limit reached, new connections
722 cannot be handled. Remove listen socket FD 722 cannot be handled. Remove listen socket FD
723 from fdset and retry to add ITC FD. */ 723 from fdset and retry to add ITC FD. */
724 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && 724 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
725 (! daemon->was_quiesced) ) 725 (! daemon->was_quiesced) )
726 { 726 {
727 FD_CLR (ls, 727 FD_CLR (ls,
728 &rs); 728 &rs);
729 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_(daemon->itc), 729 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
730 &rs, 730 &rs,
731 &maxsock, 731 &maxsock,
732 FD_SETSIZE)) 732 FD_SETSIZE))
733 { 733 {
734#endif /* MHD_WINSOCK_SOCKETS */ 734#endif /* MHD_WINSOCK_SOCKETS */
735 sc = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE; 735 sc = MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE;
736#ifdef HAVE_MESSAGES 736#ifdef HAVE_MESSAGES
737 MHD_DLOG (daemon, 737 MHD_DLOG (daemon,
738 sc, 738 sc,
739 _("Could not add control inter-thread communication channel FD to fdset")); 739 _ (
740 "Could not add control inter-thread communication channel FD to fdset"));
740#endif 741#endif
741#if defined(MHD_WINSOCK_SOCKETS) 742#if defined(MHD_WINSOCK_SOCKETS)
742 } 743 }
743 } 744}
744#endif /* MHD_WINSOCK_SOCKETS */ 745#endif /* MHD_WINSOCK_SOCKETS */
745 } 746 }
746 /* Stop listening if we are at the configured connection limit */ 747 /* Stop listening if we are at the configured connection limit */
747 /* If we're at the connection limit, no point in really 748 /* If we're at the connection limit, no point in really
748 accepting new connections; however, make sure we do not miss 749 accepting new connections; however, make sure we do not miss
@@ -750,35 +751,35 @@ MHD_daemon_select_ (struct MHD_Daemon *daemon,
750 only do this optimization if we have a signaling ITC in 751 only do this optimization if we have a signaling ITC in
751 place. */ 752 place. */
752 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && 753 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) &&
753 (MHD_ITC_IS_VALID_(daemon->itc)) && 754 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
754 ( (daemon->connections == daemon->global_connection_limit) || 755 ( (daemon->connections == daemon->global_connection_limit) ||
755 (daemon->at_limit) ) ) 756 (daemon->at_limit) ) )
756 { 757 {
757 FD_CLR (ls, 758 FD_CLR (ls,
758 &rs); 759 &rs);
759 } 760 }
760 tv = NULL; 761 tv = NULL;
761 if (MHD_SC_OK != sc) 762 if (MHD_SC_OK != sc)
762 may_block = MHD_NO; 763 may_block = MHD_NO;
763 if (MHD_NO == may_block) 764 if (MHD_NO == may_block)
764 { 765 {
765 timeout.tv_usec = 0; 766 timeout.tv_usec = 0;
766 timeout.tv_sec = 0; 767 timeout.tv_sec = 0;
767 tv = &timeout; 768 tv = &timeout;
768 } 769 }
769 else if ( (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) && 770 else if ( (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) &&
770 (MHD_SC_OK == 771 (MHD_SC_OK ==
771 MHD_daemon_get_timeout (daemon, 772 MHD_daemon_get_timeout (daemon,
772 &ltimeout)) ) 773 &ltimeout)) )
773 { 774 {
774 /* ltimeout is in ms */ 775 /* ltimeout is in ms */
775 timeout.tv_usec = (ltimeout % 1000) * 1000; 776 timeout.tv_usec = (ltimeout % 1000) * 1000;
776 if (ltimeout / 1000 > TIMEVAL_TV_SEC_MAX) 777 if (ltimeout / 1000 > TIMEVAL_TV_SEC_MAX)
777 timeout.tv_sec = TIMEVAL_TV_SEC_MAX; 778 timeout.tv_sec = TIMEVAL_TV_SEC_MAX;
778 else 779 else
779 timeout.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE)(ltimeout / 1000); 780 timeout.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) (ltimeout / 1000);
780 tv = &timeout; 781 tv = &timeout;
781 } 782 }
782 num_ready = MHD_SYS_select_ (maxsock + 1, 783 num_ready = MHD_SYS_select_ (maxsock + 1,
783 &rs, 784 &rs,
784 &ws, 785 &ws,
@@ -787,24 +788,24 @@ MHD_daemon_select_ (struct MHD_Daemon *daemon,
787 if (daemon->shutdown) 788 if (daemon->shutdown)
788 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; 789 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
789 if (num_ready < 0) 790 if (num_ready < 0)
790 { 791 {
791 const int err = MHD_socket_get_error_ (); 792 const int err = MHD_socket_get_error_ ();
792 793
793 if (MHD_SCKT_ERR_IS_EINTR_(err)) 794 if (MHD_SCKT_ERR_IS_EINTR_ (err))
794 return sc; 795 return sc;
795#ifdef HAVE_MESSAGES 796#ifdef HAVE_MESSAGES
796 MHD_DLOG (daemon, 797 MHD_DLOG (daemon,
797 MHD_SC_UNEXPECTED_SELECT_ERROR, 798 MHD_SC_UNEXPECTED_SELECT_ERROR,
798 _("select failed: %s\n"), 799 _ ("select failed: %s\n"),
799 MHD_socket_strerr_ (err)); 800 MHD_socket_strerr_ (err));
800#endif 801#endif
801 return MHD_SC_UNEXPECTED_SELECT_ERROR; 802 return MHD_SC_UNEXPECTED_SELECT_ERROR;
802 } 803 }
803 if (MHD_SC_OK != 804 if (MHD_SC_OK !=
804 (sc2 = internal_run_from_select (daemon, 805 (sc2 = internal_run_from_select (daemon,
805 &rs, 806 &rs,
806 &ws, 807 &ws,
807 &es))) 808 &es)))
808 return sc2; 809 return sc2;
809 return sc; 810 return sc;
810} 811}
diff --git a/src/lib/daemon_select.h b/src/lib/daemon_select.h
index d6e9e106..7dac8a80 100644
--- a/src/lib/daemon_select.h
+++ b/src/lib/daemon_select.h
@@ -36,8 +36,8 @@
36 */ 36 */
37enum MHD_StatusCode 37enum MHD_StatusCode
38MHD_daemon_select_ (struct MHD_Daemon *daemon, 38MHD_daemon_select_ (struct MHD_Daemon *daemon,
39 int may_block) 39 int may_block)
40 MHD_NONNULL(1); 40MHD_NONNULL (1);
41 41
42 42
43#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 43#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -49,7 +49,7 @@ MHD_daemon_select_ (struct MHD_Daemon *daemon,
49 */ 49 */
50void 50void
51MHD_daemon_upgrade_connection_with_select_ (struct MHD_Connection *con) 51MHD_daemon_upgrade_connection_with_select_ (struct MHD_Connection *con)
52 MHD_NONNULL(1); 52MHD_NONNULL (1);
53#endif 53#endif
54 54
55#endif 55#endif
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c
index 52124c77..c8c498be 100644
--- a/src/lib/daemon_start.c
+++ b/src/lib/daemon_start.c
@@ -46,63 +46,64 @@ configure_listen_reuse (struct MHD_Daemon *daemon)
46 /* Apply the socket options according to 46 /* Apply the socket options according to
47 listening_address_reuse. */ 47 listening_address_reuse. */
48 if (daemon->allow_address_reuse) 48 if (daemon->allow_address_reuse)
49 { 49 {
50 /* User requested to allow reusing listening address:port. */ 50 /* User requested to allow reusing listening address:port. */
51#ifndef MHD_WINSOCK_SOCKETS 51#ifndef MHD_WINSOCK_SOCKETS
52 /* Use SO_REUSEADDR on non-W32 platforms, and do not fail if 52 /* Use SO_REUSEADDR on non-W32 platforms, and do not fail if
53 * it doesn't work. */ 53 * it doesn't work. */
54 if (0 > setsockopt (daemon->listen_socket, 54 if (0 > setsockopt (daemon->listen_socket,
55 SOL_SOCKET, 55 SOL_SOCKET,
56 SO_REUSEADDR, 56 SO_REUSEADDR,
57 (void *) &on, 57 (void *) &on,
58 sizeof (on))) 58 sizeof (on)))
59 { 59 {
60#ifdef HAVE_MESSAGES 60#ifdef HAVE_MESSAGES
61 MHD_DLOG (daemon, 61 MHD_DLOG (daemon,
62 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED, 62 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED,
63 _("setsockopt failed: %s\n"), 63 _ ("setsockopt failed: %s\n"),
64 MHD_socket_last_strerr_ ()); 64 MHD_socket_last_strerr_ ());
65#endif 65#endif
66 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED; 66 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED;
67 } 67 }
68 return MHD_SC_OK; 68 return MHD_SC_OK;
69#endif /* ! MHD_WINSOCK_SOCKETS */ 69#endif /* ! MHD_WINSOCK_SOCKETS */
70 /* Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms. 70 /* Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms.
71 * Fail if SO_REUSEPORT is not defined or setsockopt fails. 71 * Fail if SO_REUSEPORT is not defined or setsockopt fails.
72 */ 72 */
73 /* SO_REUSEADDR on W32 has the same semantics 73 /* SO_REUSEADDR on W32 has the same semantics
74 as SO_REUSEPORT on BSD/Linux */ 74 as SO_REUSEPORT on BSD/Linux */
75#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT) 75#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
76 if (0 > setsockopt (daemon->listen_socket, 76 if (0 > setsockopt (daemon->listen_socket,
77 SOL_SOCKET, 77 SOL_SOCKET,
78#ifndef MHD_WINSOCK_SOCKETS 78#ifndef MHD_WINSOCK_SOCKETS
79 SO_REUSEPORT, 79 SO_REUSEPORT,
80#else /* MHD_WINSOCK_SOCKETS */ 80#else /* MHD_WINSOCK_SOCKETS */
81 SO_REUSEADDR, 81 SO_REUSEADDR,
82#endif /* MHD_WINSOCK_SOCKETS */ 82#endif /* MHD_WINSOCK_SOCKETS */
83 (void *) &on, 83 (void *) &on,
84 sizeof (on))) 84 sizeof (on)))
85 { 85 {
86#ifdef HAVE_MESSAGES 86#ifdef HAVE_MESSAGES
87 MHD_DLOG (daemon, 87 MHD_DLOG (daemon,
88 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED, 88 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED,
89 _("setsockopt failed: %s\n"), 89 _ ("setsockopt failed: %s\n"),
90 MHD_socket_last_strerr_ ()); 90 MHD_socket_last_strerr_ ());
91#endif 91#endif
92 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED; 92 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED;
93 } 93 }
94 return MHD_SC_OK; 94 return MHD_SC_OK;
95#else /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */ 95#else /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */
96 /* we're supposed to allow address:port re-use, but 96 /* we're supposed to allow address:port re-use, but
97 on this platform we cannot; fail hard */ 97 on this platform we cannot; fail hard */
98#ifdef HAVE_MESSAGES 98#ifdef HAVE_MESSAGES
99 MHD_DLOG (daemon, 99 MHD_DLOG (daemon,
100 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED, 100 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED,
101 _("Cannot allow listening address reuse: SO_REUSEPORT not defined\n")); 101 _ (
102 "Cannot allow listening address reuse: SO_REUSEPORT not defined\n"));
102#endif 103#endif
103 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED; 104 return MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED;
104#endif /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */ 105#endif /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */
105 } 106 }
106 107
107 /* if (! daemon->allow_address_reuse) */ 108 /* if (! daemon->allow_address_reuse) */
108 /* User requested to disallow reusing listening address:port. 109 /* User requested to disallow reusing listening address:port.
@@ -111,32 +112,33 @@ configure_listen_reuse (struct MHD_Daemon *daemon)
111 * Fail if MHD was compiled for W32 without SO_EXCLUSIVEADDRUSE 112 * Fail if MHD was compiled for W32 without SO_EXCLUSIVEADDRUSE
112 * or setsockopt fails. 113 * or setsockopt fails.
113 */ 114 */
114#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \ 115#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
115 (defined(__sun) && defined(SO_EXCLBIND)) 116 (defined(__sun) && defined(SO_EXCLBIND))
116 if (0 > setsockopt (daemon->listen_socket, 117 if (0 > setsockopt (daemon->listen_socket,
117 SOL_SOCKET, 118 SOL_SOCKET,
118#ifdef SO_EXCLUSIVEADDRUSE 119#ifdef SO_EXCLUSIVEADDRUSE
119 SO_EXCLUSIVEADDRUSE, 120 SO_EXCLUSIVEADDRUSE,
120#else /* SO_EXCLBIND */ 121#else /* SO_EXCLBIND */
121 SO_EXCLBIND, 122 SO_EXCLBIND,
122#endif /* SO_EXCLBIND */ 123#endif /* SO_EXCLBIND */
123 (void *) &on, 124 (void *) &on,
124 sizeof (on))) 125 sizeof (on)))
125 { 126 {
126#ifdef HAVE_MESSAGES 127#ifdef HAVE_MESSAGES
127 MHD_DLOG (daemon, 128 MHD_DLOG (daemon,
128 MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_FAILED, 129 MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_FAILED,
129 _("setsockopt failed: %s\n"), 130 _ ("setsockopt failed: %s\n"),
130 MHD_socket_last_strerr_ ()); 131 MHD_socket_last_strerr_ ());
131#endif 132#endif
132 return MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_FAILED; 133 return MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_FAILED;
133 } 134 }
134 return MHD_SC_OK; 135 return MHD_SC_OK;
135#elif defined(MHD_WINSOCK_SOCKETS) /* SO_EXCLUSIVEADDRUSE not defined on W32? */ 136#elif defined(MHD_WINSOCK_SOCKETS) /* SO_EXCLUSIVEADDRUSE not defined on W32? */
136#ifdef HAVE_MESSAGES 137#ifdef HAVE_MESSAGES
137 MHD_DLOG (daemon, 138 MHD_DLOG (daemon,
138 MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_NOT_SUPPORTED, 139 MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_NOT_SUPPORTED,
139 _("Cannot disallow listening address reuse: SO_EXCLUSIVEADDRUSE not defined\n")); 140 _ (
141 "Cannot disallow listening address reuse: SO_EXCLUSIVEADDRUSE not defined\n"));
140#endif 142#endif
141 return MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_NOT_SUPPORTED; 143 return MHD_SC_LISTEN_ADDRESS_REUSE_DISABLE_NOT_SUPPORTED;
142#endif /* MHD_WINSOCK_SOCKETS */ 144#endif /* MHD_WINSOCK_SOCKETS */
@@ -166,86 +168,86 @@ open_listen_socket (struct MHD_Daemon *daemon)
166 pf = -1; 168 pf = -1;
167 /* Determine address family */ 169 /* Determine address family */
168 switch (daemon->listen_af) 170 switch (daemon->listen_af)
171 {
172 case MHD_AF_NONE:
173 if (0 == daemon->listen_sa_len)
169 { 174 {
170 case MHD_AF_NONE: 175 /* no listening desired, that's OK */
171 if (0 == daemon->listen_sa_len) 176 return MHD_SC_OK;
172 { 177 }
173 /* no listening desired, that's OK */ 178 /* we have a listen address, get AF from there! */
174 return MHD_SC_OK; 179 switch (daemon->listen_sa.ss_family)
175 } 180 {
176 /* we have a listen address, get AF from there! */ 181 case AF_INET:
177 switch (daemon->listen_sa.ss_family) 182 pf = PF_INET;
178 { 183 use_v6 = false;
179 case AF_INET: 184 break;
180 pf = PF_INET;
181 use_v6 = false;
182 break;
183#ifdef AF_INET6 185#ifdef AF_INET6
184 case AF_INET6: 186 case AF_INET6:
185 pf = PF_INET6;
186 use_v6 = true;
187 break;
188#endif
189#ifdef AF_UNIX
190 case AF_UNIX:
191 pf = PF_UNIX;
192 use_v6 = false;
193 break;
194#endif
195 default:
196 return MHD_SC_AF_NOT_SUPPORTED_BY_BUILD;
197 } /* switch on ss_family */
198 break; /* MHD_AF_NONE */
199 case MHD_AF_AUTO:
200#if HAVE_INET6
201 pf = PF_INET6; 187 pf = PF_INET6;
202 use_v6 = true; 188 use_v6 = true;
203#else
204 pf = PF_INET;
205 use_v6 = false;
206#endif
207 break; 189 break;
208 case MHD_AF_INET4: 190#endif
191#ifdef AF_UNIX
192 case AF_UNIX:
193 pf = PF_UNIX;
209 use_v6 = false; 194 use_v6 = false;
210 pf = PF_INET;
211 break; 195 break;
212 case MHD_AF_INET6: 196#endif
213 case MHD_AF_DUAL: 197 default:
198 return MHD_SC_AF_NOT_SUPPORTED_BY_BUILD;
199 } /* switch on ss_family */
200 break; /* MHD_AF_NONE */
201 case MHD_AF_AUTO:
214#if HAVE_INET6 202#if HAVE_INET6
215 pf = PF_INET6; 203 pf = PF_INET6;
216 use_v6 = true; 204 use_v6 = true;
217 break; 205#else
206 pf = PF_INET;
207 use_v6 = false;
208#endif
209 break;
210 case MHD_AF_INET4:
211 use_v6 = false;
212 pf = PF_INET;
213 break;
214 case MHD_AF_INET6:
215 case MHD_AF_DUAL:
216#if HAVE_INET6
217 pf = PF_INET6;
218 use_v6 = true;
219 break;
218#else 220#else
219#ifdef HAVE_MESSAGES 221#ifdef HAVE_MESSAGES
220 MHD_DLOG (daemon, 222 MHD_DLOG (daemon,
221 MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD, 223 MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD,
222 _("IPv6 not supported by this build\n")); 224 _ ("IPv6 not supported by this build\n"));
223#endif 225#endif
224 return MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD; 226 return MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD;
225#endif 227#endif
226 } 228 }
227 mhd_assert (-1 != pf); 229 mhd_assert (-1 != pf);
228 /* try to open listen socket */ 230 /* try to open listen socket */
229 try_open_listen_socket: 231try_open_listen_socket:
230 daemon->listen_socket = MHD_socket_create_listen_(pf); 232 daemon->listen_socket = MHD_socket_create_listen_ (pf);
231 if ( (MHD_INVALID_SOCKET == daemon->listen_socket) && 233 if ( (MHD_INVALID_SOCKET == daemon->listen_socket) &&
232 (MHD_AF_AUTO == daemon->listen_af) && 234 (MHD_AF_AUTO == daemon->listen_af) &&
233 (use_v6) ) 235 (use_v6) )
234 { 236 {
235 use_v6 = false; 237 use_v6 = false;
236 pf = PF_INET; 238 pf = PF_INET;
237 goto try_open_listen_socket; 239 goto try_open_listen_socket;
238 } 240 }
239 if (MHD_INVALID_SOCKET == daemon->listen_socket) 241 if (MHD_INVALID_SOCKET == daemon->listen_socket)
240 { 242 {
241#ifdef HAVE_MESSAGES 243#ifdef HAVE_MESSAGES
242 MHD_DLOG (daemon, 244 MHD_DLOG (daemon,
243 MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET, 245 MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET,
244 _("Failed to create socket for listening: %s\n"), 246 _ ("Failed to create socket for listening: %s\n"),
245 MHD_socket_last_strerr_ ()); 247 MHD_socket_last_strerr_ ());
246#endif 248#endif
247 return MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET; 249 return MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET;
248 } 250 }
249 251
250 if (MHD_SC_OK != 252 if (MHD_SC_OK !=
251 (sc = configure_listen_reuse (daemon))) 253 (sc = configure_listen_reuse (daemon)))
@@ -253,156 +255,157 @@ open_listen_socket (struct MHD_Daemon *daemon)
253 255
254 /* configure for dual stack (or not) */ 256 /* configure for dual stack (or not) */
255 if (use_v6) 257 if (use_v6)
256 { 258 {
257#if defined IPPROTO_IPV6 && defined IPV6_V6ONLY 259#if defined IPPROTO_IPV6 && defined IPV6_V6ONLY
258 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options" 260 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options"
259 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx); 261 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx);
260 and may also be missing on older POSIX systems; good luck if you have any of those, 262 and may also be missing on older POSIX systems; good luck if you have any of those,
261 your IPv6 socket may then also bind against IPv4 anyway... */ 263 your IPv6 socket may then also bind against IPv4 anyway... */
262 const MHD_SCKT_OPT_BOOL_ v6_only = 264 const MHD_SCKT_OPT_BOOL_ v6_only =
263 (MHD_AF_INET6 == daemon->listen_af); 265 (MHD_AF_INET6 == daemon->listen_af);
264 if (0 > setsockopt (daemon->listen_socket, 266 if (0 > setsockopt (daemon->listen_socket,
265 IPPROTO_IPV6, 267 IPPROTO_IPV6,
266 IPV6_V6ONLY, 268 IPV6_V6ONLY,
267 (const void *) &v6_only, 269 (const void *) &v6_only,
268 sizeof (v6_only))) 270 sizeof (v6_only)))
269 { 271 {
270#ifdef HAVE_MESSAGES 272#ifdef HAVE_MESSAGES
271 MHD_DLOG (daemon, 273 MHD_DLOG (daemon,
272 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_FAILED, 274 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_FAILED,
273 _("setsockopt failed: %s\n"), 275 _ ("setsockopt failed: %s\n"),
274 MHD_socket_last_strerr_ ()); 276 MHD_socket_last_strerr_ ());
275#endif 277#endif
276 } 278 }
277#else 279#else
278#ifdef HAVE_MESSAGES 280#ifdef HAVE_MESSAGES
279 MHD_DLOG (daemon, 281 MHD_DLOG (daemon,
280 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED, 282 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED,
281 _("Cannot explicitly setup dual stack behavior on this platform\n")); 283 _ (
284 "Cannot explicitly setup dual stack behavior on this platform\n"));
282#endif 285#endif
283#endif 286#endif
284 } 287 }
285 288
286 /* Determine address to bind to */ 289 /* Determine address to bind to */
287 if (0 != daemon->listen_sa_len) 290 if (0 != daemon->listen_sa_len)
288 { 291 {
289 /* Bind address explicitly given */ 292 /* Bind address explicitly given */
290 sa = (const struct sockaddr *) &daemon->listen_sa; 293 sa = (const struct sockaddr *) &daemon->listen_sa;
291 addrlen = daemon->listen_sa_len; 294 addrlen = daemon->listen_sa_len;
292 } 295 }
293 else 296 else
294 { 297 {
295 /* Compute bind address based on port and AF */ 298 /* Compute bind address based on port and AF */
296#if HAVE_INET6 299#if HAVE_INET6
297 if (use_v6) 300 if (use_v6)
298 { 301 {
299#ifdef IN6ADDR_ANY_INIT 302#ifdef IN6ADDR_ANY_INIT
300 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT; 303 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
301#endif 304#endif
302 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &ss; 305 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &ss;
303 306
304 addrlen = sizeof (struct sockaddr_in6); 307 addrlen = sizeof (struct sockaddr_in6);
305 memset (sin6, 308 memset (sin6,
306 0, 309 0,
307 sizeof (struct sockaddr_in6)); 310 sizeof (struct sockaddr_in6));
308 sin6->sin6_family = AF_INET6; 311 sin6->sin6_family = AF_INET6;
309 sin6->sin6_port = htons (daemon->listen_port); 312 sin6->sin6_port = htons (daemon->listen_port);
310#ifdef IN6ADDR_ANY_INIT 313#ifdef IN6ADDR_ANY_INIT
311 sin6->sin6_addr = static_in6any; 314 sin6->sin6_addr = static_in6any;
312#endif 315#endif
313#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 316#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
314 sin6->sin6_len = sizeof (struct sockaddr_in6); 317 sin6->sin6_len = sizeof (struct sockaddr_in6);
315#endif 318#endif
316 } 319 }
317 else 320 else
318#endif 321#endif
319 { 322 {
320 struct sockaddr_in *sin4 = (struct sockaddr_in *) &ss; 323 struct sockaddr_in *sin4 = (struct sockaddr_in *) &ss;
321 324
322 addrlen = sizeof (struct sockaddr_in); 325 addrlen = sizeof (struct sockaddr_in);
323 memset (sin4, 326 memset (sin4,
324 0, 327 0,
325 sizeof (struct sockaddr_in)); 328 sizeof (struct sockaddr_in));
326 sin4->sin_family = AF_INET; 329 sin4->sin_family = AF_INET;
327 sin4->sin_port = htons (daemon->listen_port); 330 sin4->sin_port = htons (daemon->listen_port);
328 if (0 != INADDR_ANY) 331 if (0 != INADDR_ANY)
329 sin4->sin_addr.s_addr = htonl (INADDR_ANY); 332 sin4->sin_addr.s_addr = htonl (INADDR_ANY);
330#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 333#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
331 sin4->sin_len = sizeof (struct sockaddr_in); 334 sin4->sin_len = sizeof (struct sockaddr_in);
332#endif 335#endif
333 }
334 sa = (const struct sockaddr *) &ss;
335 } 336 }
337 sa = (const struct sockaddr *) &ss;
338 }
336 339
337 /* actually do the bind() */ 340 /* actually do the bind() */
338 if (-1 == bind (daemon->listen_socket, 341 if (-1 == bind (daemon->listen_socket,
339 sa, 342 sa,
340 addrlen)) 343 addrlen))
341 { 344 {
342#ifdef HAVE_MESSAGES 345#ifdef HAVE_MESSAGES
343 unsigned int port = 0; 346 unsigned int port = 0;
344 347
345 switch (sa->sa_family) 348 switch (sa->sa_family)
346 { 349 {
347 case AF_INET: 350 case AF_INET:
348 if (addrlen == sizeof (struct sockaddr_in)) 351 if (addrlen == sizeof (struct sockaddr_in))
349 port = ntohs (((const struct sockaddr_in *) sa)->sin_port); 352 port = ntohs (((const struct sockaddr_in *) sa)->sin_port);
350 else 353 else
351 port = UINT16_MAX + 1; /* indicate size error */ 354 port = UINT16_MAX + 1; /* indicate size error */
352 break; 355 break;
353 case AF_INET6: 356 case AF_INET6:
354 if (addrlen == sizeof (struct sockaddr_in6)) 357 if (addrlen == sizeof (struct sockaddr_in6))
355 port = ntohs (((const struct sockaddr_in6 *) sa)->sin6_port); 358 port = ntohs (((const struct sockaddr_in6 *) sa)->sin6_port);
356 else 359 else
357 port = UINT16_MAX + 1; /* indicate size error */ 360 port = UINT16_MAX + 1; /* indicate size error */
358 break; 361 break;
359 default: 362 default:
360 port = UINT_MAX; /* AF_UNIX? */ 363 port = UINT_MAX; /* AF_UNIX? */
361 break; 364 break;
362 }
363 MHD_DLOG (daemon,
364 MHD_SC_LISTEN_SOCKET_BIND_FAILED,
365 _("Failed to bind to port %u: %s\n"),
366 port,
367 MHD_socket_last_strerr_ ());
368#endif
369 return MHD_SC_LISTEN_SOCKET_BIND_FAILED;
370 } 365 }
366 MHD_DLOG (daemon,
367 MHD_SC_LISTEN_SOCKET_BIND_FAILED,
368 _ ("Failed to bind to port %u: %s\n"),
369 port,
370 MHD_socket_last_strerr_ ());
371#endif
372 return MHD_SC_LISTEN_SOCKET_BIND_FAILED;
373 }
371 374
372 /* setup TCP_FASTOPEN */ 375 /* setup TCP_FASTOPEN */
373#ifdef TCP_FASTOPEN 376#ifdef TCP_FASTOPEN
374 if (MHD_FOM_DISABLE != daemon->fast_open_method) 377 if (MHD_FOM_DISABLE != daemon->fast_open_method)
378 {
379 if (0 != setsockopt (daemon->listen_socket,
380 IPPROTO_TCP,
381 TCP_FASTOPEN,
382 &daemon->fo_queue_length,
383 sizeof (daemon->fo_queue_length)))
375 { 384 {
376 if (0 != setsockopt (daemon->listen_socket,
377 IPPROTO_TCP,
378 TCP_FASTOPEN,
379 &daemon->fo_queue_length,
380 sizeof (daemon->fo_queue_length)))
381 {
382#ifdef HAVE_MESSAGES 385#ifdef HAVE_MESSAGES
383 MHD_DLOG (daemon, 386 MHD_DLOG (daemon,
384 MHD_SC_FAST_OPEN_FAILURE, 387 MHD_SC_FAST_OPEN_FAILURE,
385 _("setsockopt failed: %s\n"), 388 _ ("setsockopt failed: %s\n"),
386 MHD_socket_last_strerr_ ()); 389 MHD_socket_last_strerr_ ());
387#endif 390#endif
388 if (MHD_FOM_REQUIRE == daemon->fast_open_method) 391 if (MHD_FOM_REQUIRE == daemon->fast_open_method)
389 return MHD_SC_FAST_OPEN_FAILURE; 392 return MHD_SC_FAST_OPEN_FAILURE;
390 } 393 }
391 } 394 }
392#endif 395#endif
393 396
394 /* setup listening */ 397 /* setup listening */
395 if (0 > listen (daemon->listen_socket, 398 if (0 > listen (daemon->listen_socket,
396 daemon->listen_backlog)) 399 daemon->listen_backlog))
397 { 400 {
398#ifdef HAVE_MESSAGES 401#ifdef HAVE_MESSAGES
399 MHD_DLOG (daemon, 402 MHD_DLOG (daemon,
400 MHD_SC_LISTEN_FAILURE, 403 MHD_SC_LISTEN_FAILURE,
401 _("Failed to listen for connections: %s\n"), 404 _ ("Failed to listen for connections: %s\n"),
402 MHD_socket_last_strerr_ ()); 405 MHD_socket_last_strerr_ ());
403#endif 406#endif
404 return MHD_SC_LISTEN_FAILURE; 407 return MHD_SC_LISTEN_FAILURE;
405 } 408 }
406 return MHD_SC_OK; 409 return MHD_SC_OK;
407} 410}
408 411
@@ -426,65 +429,66 @@ get_listen_port_number (struct MHD_Daemon *daemon)
426 return; /* nothing to be done */ 429 return; /* nothing to be done */
427 430
428 memset (&servaddr, 431 memset (&servaddr,
429 0, 432 0,
430 sizeof (struct sockaddr_storage)); 433 sizeof (struct sockaddr_storage));
431 addrlen = sizeof (servaddr); 434 addrlen = sizeof (servaddr);
432 if (0 != getsockname (daemon->listen_socket, 435 if (0 != getsockname (daemon->listen_socket,
433 (struct sockaddr *) &servaddr, 436 (struct sockaddr *) &servaddr,
434 &addrlen)) 437 &addrlen))
435 { 438 {
436#ifdef HAVE_MESSAGES 439#ifdef HAVE_MESSAGES
437 MHD_DLOG (daemon, 440 MHD_DLOG (daemon,
438 MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE, 441 MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE,
439 _("Failed to get listen port number: %s\n"), 442 _ ("Failed to get listen port number: %s\n"),
440 MHD_socket_last_strerr_ ()); 443 MHD_socket_last_strerr_ ());
441#endif /* HAVE_MESSAGES */ 444#endif /* HAVE_MESSAGES */
442 return; 445 return;
443 } 446 }
444#ifdef MHD_POSIX_SOCKETS 447#ifdef MHD_POSIX_SOCKETS
445 if (sizeof (servaddr) < addrlen) 448 if (sizeof (servaddr) < addrlen)
446 { 449 {
447 /* should be impossible with `struct sockaddr_storage` */ 450 /* should be impossible with `struct sockaddr_storage` */
448#ifdef HAVE_MESSAGES 451#ifdef HAVE_MESSAGES
449 MHD_DLOG (daemon, 452 MHD_DLOG (daemon,
450 MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE, 453 MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE,
451 _("Failed to get listen port number (`struct sockaddr_storage` too small!?)\n")); 454 _ (
455 "Failed to get listen port number (`struct sockaddr_storage` too small!?)\n"));
452#endif /* HAVE_MESSAGES */ 456#endif /* HAVE_MESSAGES */
453 return; 457 return;
454 } 458 }
455#endif /* MHD_POSIX_SOCKETS */ 459#endif /* MHD_POSIX_SOCKETS */
456 switch (servaddr.ss_family) 460 switch (servaddr.ss_family)
461 {
462 case AF_INET:
457 { 463 {
458 case AF_INET: 464 struct sockaddr_in *s4 = (struct sockaddr_in *) &servaddr;
459 {
460 struct sockaddr_in *s4 = (struct sockaddr_in *) &servaddr;
461 465
462 daemon->listen_port = ntohs (s4->sin_port); 466 daemon->listen_port = ntohs (s4->sin_port);
463 break; 467 break;
464 } 468 }
465#ifdef HAVE_INET6 469#ifdef HAVE_INET6
466 case AF_INET6: 470 case AF_INET6:
467 { 471 {
468 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &servaddr; 472 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &servaddr;
469 473
470 daemon->listen_port = ntohs(s6->sin6_port); 474 daemon->listen_port = ntohs (s6->sin6_port);
471 break; 475 break;
472 } 476 }
473#endif /* HAVE_INET6 */ 477#endif /* HAVE_INET6 */
474#ifdef AF_UNIX 478#ifdef AF_UNIX
475 case AF_UNIX: 479 case AF_UNIX:
476 daemon->listen_port = 0; /* special value for UNIX domain sockets */ 480 daemon->listen_port = 0; /* special value for UNIX domain sockets */
477 break; 481 break;
478#endif 482#endif
479 default: 483 default:
480#ifdef HAVE_MESSAGES 484#ifdef HAVE_MESSAGES
481 MHD_DLOG (daemon, 485 MHD_DLOG (daemon,
482 MHD_SC_LISTEN_PORT_INTROSPECTION_UNKNOWN_AF, 486 MHD_SC_LISTEN_PORT_INTROSPECTION_UNKNOWN_AF,
483 _("Unknown address family!\n")); 487 _ ("Unknown address family!\n"));
484#endif 488#endif
485 daemon->listen_port = 0; /* ugh */ 489 daemon->listen_port = 0; /* ugh */
486 break; 490 break;
487 } 491 }
488} 492}
489 493
490 494
@@ -501,7 +505,7 @@ setup_epoll_fd (struct MHD_Daemon *daemon)
501 int fd; 505 int fd;
502 506
503#ifndef HAVE_MESSAGES 507#ifndef HAVE_MESSAGES
504 (void)daemon; /* Mute compiler warning. */ 508 (void) daemon; /* Mute compiler warning. */
505#endif /* ! HAVE_MESSAGES */ 509#endif /* ! HAVE_MESSAGES */
506 510
507#ifdef USE_EPOLL_CREATE1 511#ifdef USE_EPOLL_CREATE1
@@ -510,24 +514,24 @@ setup_epoll_fd (struct MHD_Daemon *daemon)
510 fd = epoll_create (MAX_EVENTS); 514 fd = epoll_create (MAX_EVENTS);
511#endif /* ! USE_EPOLL_CREATE1 */ 515#endif /* ! USE_EPOLL_CREATE1 */
512 if (MHD_INVALID_SOCKET == fd) 516 if (MHD_INVALID_SOCKET == fd)
513 { 517 {
514#ifdef HAVE_MESSAGES 518#ifdef HAVE_MESSAGES
515 MHD_DLOG (daemon, 519 MHD_DLOG (daemon,
516 MHD_SC_EPOLL_CTL_CREATE_FAILED, 520 MHD_SC_EPOLL_CTL_CREATE_FAILED,
517 _("Call to epoll_create1 failed: %s\n"), 521 _ ("Call to epoll_create1 failed: %s\n"),
518 MHD_socket_last_strerr_ ()); 522 MHD_socket_last_strerr_ ());
519#endif 523#endif
520 return MHD_INVALID_SOCKET; 524 return MHD_INVALID_SOCKET;
521 } 525 }
522#if !defined(USE_EPOLL_CREATE1) 526#if ! defined(USE_EPOLL_CREATE1)
523 if (! MHD_socket_noninheritable_ (fd)) 527 if (! MHD_socket_noninheritable_ (fd))
524 { 528 {
525#ifdef HAVE_MESSAGES 529#ifdef HAVE_MESSAGES
526 MHD_DLOG (daemon, 530 MHD_DLOG (daemon,
527 MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED, 531 MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED,
528 _("Failed to set noninheritable mode on epoll FD.\n")); 532 _ ("Failed to set noninheritable mode on epoll FD.\n"));
529#endif 533#endif
530 } 534 }
531#endif /* ! USE_EPOLL_CREATE1 */ 535#endif /* ! USE_EPOLL_CREATE1 */
532 return fd; 536 return fd;
533} 537}
@@ -554,11 +558,11 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
554 return MHD_SC_EPOLL_CTL_CREATE_FAILED; 558 return MHD_SC_EPOLL_CTL_CREATE_FAILED;
555#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 559#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
556 if (! daemon->disallow_upgrade) 560 if (! daemon->disallow_upgrade)
557 { 561 {
558 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon); 562 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
559 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd) 563 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd)
560 return MHD_SC_EPOLL_CTL_CREATE_FAILED; 564 return MHD_SC_EPOLL_CTL_CREATE_FAILED;
561 } 565 }
562#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 566#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
563 if ( (MHD_INVALID_SOCKET == (ls = daemon->listen_socket)) || 567 if ( (MHD_INVALID_SOCKET == (ls = daemon->listen_socket)) ||
564 (daemon->was_quiesced) ) 568 (daemon->was_quiesced) )
@@ -566,37 +570,37 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
566 event.events = EPOLLIN; 570 event.events = EPOLLIN;
567 event.data.ptr = daemon; 571 event.data.ptr = daemon;
568 if (0 != epoll_ctl (daemon->epoll_fd, 572 if (0 != epoll_ctl (daemon->epoll_fd,
569 EPOLL_CTL_ADD, 573 EPOLL_CTL_ADD,
570 ls, 574 ls,
571 &event)) 575 &event))
572 { 576 {
573#ifdef HAVE_MESSAGES 577#ifdef HAVE_MESSAGES
574 MHD_DLOG (daemon, 578 MHD_DLOG (daemon,
575 MHD_SC_EPOLL_CTL_ADD_FAILED, 579 MHD_SC_EPOLL_CTL_ADD_FAILED,
576 _("Call to epoll_ctl failed: %s\n"), 580 _ ("Call to epoll_ctl failed: %s\n"),
577 MHD_socket_last_strerr_ ()); 581 MHD_socket_last_strerr_ ());
578#endif 582#endif
579 return MHD_SC_EPOLL_CTL_ADD_FAILED; 583 return MHD_SC_EPOLL_CTL_ADD_FAILED;
580 } 584 }
581 daemon->listen_socket_in_epoll = true; 585 daemon->listen_socket_in_epoll = true;
582 if (MHD_ITC_IS_VALID_(daemon->itc)) 586 if (MHD_ITC_IS_VALID_ (daemon->itc))
587 {
588 event.events = EPOLLIN;
589 event.data.ptr = (void *) daemon->epoll_itc_marker;
590 if (0 != epoll_ctl (daemon->epoll_fd,
591 EPOLL_CTL_ADD,
592 MHD_itc_r_fd_ (daemon->itc),
593 &event))
583 { 594 {
584 event.events = EPOLLIN;
585 event.data.ptr = (void *) daemon->epoll_itc_marker;
586 if (0 != epoll_ctl (daemon->epoll_fd,
587 EPOLL_CTL_ADD,
588 MHD_itc_r_fd_ (daemon->itc),
589 &event))
590 {
591#ifdef HAVE_MESSAGES 595#ifdef HAVE_MESSAGES
592 MHD_DLOG (daemon, 596 MHD_DLOG (daemon,
593 MHD_SC_EPOLL_CTL_ADD_FAILED, 597 MHD_SC_EPOLL_CTL_ADD_FAILED,
594 _("Call to epoll_ctl failed: %s\n"), 598 _ ("Call to epoll_ctl failed: %s\n"),
595 MHD_socket_last_strerr_ ()); 599 MHD_socket_last_strerr_ ());
596#endif 600#endif
597 return MHD_SC_EPOLL_CTL_ADD_FAILED; 601 return MHD_SC_EPOLL_CTL_ADD_FAILED;
598 }
599 } 602 }
603 }
600 return MHD_SC_OK; 604 return MHD_SC_OK;
601} 605}
602#endif 606#endif
@@ -616,35 +620,35 @@ MHD_polling_thread (void *cls)
616 620
617 MHD_thread_init_ (&daemon->pid); 621 MHD_thread_init_ (&daemon->pid);
618 while (! daemon->shutdown) 622 while (! daemon->shutdown)
623 {
624 switch (daemon->event_loop_syscall)
619 { 625 {
620 switch (daemon->event_loop_syscall) 626 case MHD_ELS_AUTO:
621 { 627 MHD_PANIC ("MHD_ELS_AUTO should have been mapped to preferred style");
622 case MHD_ELS_AUTO: 628 break;
623 MHD_PANIC ("MHD_ELS_AUTO should have been mapped to preferred style"); 629 case MHD_ELS_SELECT:
624 break; 630 MHD_daemon_select_ (daemon,
625 case MHD_ELS_SELECT: 631 MHD_YES);
626 MHD_daemon_select_ (daemon, 632 break;
627 MHD_YES); 633 case MHD_ELS_POLL:
628 break;
629 case MHD_ELS_POLL:
630#if HAVE_POLL 634#if HAVE_POLL
631 MHD_daemon_poll_ (daemon, 635 MHD_daemon_poll_ (daemon,
632 MHD_YES); 636 MHD_YES);
633#else 637#else
634 MHD_PANIC ("MHD_ELS_POLL not supported, should have failed earlier"); 638 MHD_PANIC ("MHD_ELS_POLL not supported, should have failed earlier");
635#endif 639#endif
636 break; 640 break;
637 case MHD_ELS_EPOLL: 641 case MHD_ELS_EPOLL:
638#ifdef EPOLL_SUPPORT 642#ifdef EPOLL_SUPPORT
639 MHD_daemon_epoll_ (daemon, 643 MHD_daemon_epoll_ (daemon,
640 MHD_YES); 644 MHD_YES);
641#else 645#else
642 MHD_PANIC ("MHD_ELS_EPOLL not supported, should have failed earlier"); 646 MHD_PANIC ("MHD_ELS_EPOLL not supported, should have failed earlier");
643#endif 647#endif
644 break; 648 break;
645 }
646 MHD_connection_cleanup_ (daemon);
647 } 649 }
650 MHD_connection_cleanup_ (daemon);
651 }
648 /* Resume any pending for resume connections, join 652 /* Resume any pending for resume connections, join
649 * all connection's threads (if any) and finally cleanup 653 * all connection's threads (if any) and finally cleanup
650 * everything. */ 654 * everything. */
@@ -652,7 +656,7 @@ MHD_polling_thread (void *cls)
652 MHD_resume_suspended_connections_ (daemon); 656 MHD_resume_suspended_connections_ (daemon);
653 MHD_daemon_close_all_connections_ (daemon); 657 MHD_daemon_close_all_connections_ (daemon);
654 658
655 return (MHD_THRD_RTRN_TYPE_)0; 659 return (MHD_THRD_RTRN_TYPE_) 0;
656} 660}
657 661
658 662
@@ -669,114 +673,116 @@ setup_thread_pool (struct MHD_Daemon *daemon)
669 * due to integer division). Also keep track of how many 673 * due to integer division). Also keep track of how many
670 * connections are leftover after an equal split. */ 674 * connections are leftover after an equal split. */
671 unsigned int conns_per_thread = daemon->global_connection_limit 675 unsigned int conns_per_thread = daemon->global_connection_limit
672 / daemon->threading_mode; 676 / daemon->threading_mode;
673 unsigned int leftover_conns = daemon->global_connection_limit 677 unsigned int leftover_conns = daemon->global_connection_limit
674 % daemon->threading_mode; 678 % daemon->threading_mode;
675 int i; 679 int i;
676 enum MHD_StatusCode sc; 680 enum MHD_StatusCode sc;
677 681
678 /* Allocate memory for pooled objects */ 682 /* Allocate memory for pooled objects */
679 daemon->worker_pool = MHD_calloc_ (daemon->threading_mode, 683 daemon->worker_pool = MHD_calloc_ (daemon->threading_mode,
680 sizeof (struct MHD_Daemon)); 684 sizeof (struct MHD_Daemon));
681 if (NULL == daemon->worker_pool) 685 if (NULL == daemon->worker_pool)
682 return MHD_SC_THREAD_POOL_MALLOC_FAILURE; 686 return MHD_SC_THREAD_POOL_MALLOC_FAILURE;
683 687
684 /* Start the workers in the pool */ 688 /* Start the workers in the pool */
685 for (i = 0; i < daemon->threading_mode; i++) 689 for (i = 0; i < daemon->threading_mode; i++)
690 {
691 /* Create copy of the Daemon object for each worker */
692 struct MHD_Daemon *d = &daemon->worker_pool[i];
693
694 memcpy (d,
695 daemon,
696 sizeof (struct MHD_Daemon));
697 /* Adjust pooling params for worker daemons; note that memcpy()
698 has already copied MHD_USE_INTERNAL_POLLING_THREAD thread mode into
699 the worker threads. */
700 d->master = daemon;
701 d->worker_pool_size = 0;
702 d->worker_pool = NULL;
703 /* Divide available connections evenly amongst the threads.
704 * Thread indexes in [0, leftover_conns) each get one of the
705 * leftover connections. */
706 d->global_connection_limit = conns_per_thread;
707 if (((unsigned int) i) < leftover_conns)
708 ++d->global_connection_limit;
709
710 if (! daemon->disable_itc)
686 { 711 {
687 /* Create copy of the Daemon object for each worker */ 712 if (! MHD_itc_init_ (d->itc))
688 struct MHD_Daemon *d = &daemon->worker_pool[i]; 713 {
689
690 memcpy (d,
691 daemon,
692 sizeof (struct MHD_Daemon));
693 /* Adjust pooling params for worker daemons; note that memcpy()
694 has already copied MHD_USE_INTERNAL_POLLING_THREAD thread mode into
695 the worker threads. */
696 d->master = daemon;
697 d->worker_pool_size = 0;
698 d->worker_pool = NULL;
699 /* Divide available connections evenly amongst the threads.
700 * Thread indexes in [0, leftover_conns) each get one of the
701 * leftover connections. */
702 d->global_connection_limit = conns_per_thread;
703 if (((unsigned int) i) < leftover_conns)
704 ++d->global_connection_limit;
705
706 if (! daemon->disable_itc)
707 {
708 if (! MHD_itc_init_ (d->itc))
709 {
710#ifdef HAVE_MESSAGES 714#ifdef HAVE_MESSAGES
711 MHD_DLOG (daemon, 715 MHD_DLOG (daemon,
712 MHD_SC_ITC_INITIALIZATION_FAILED, 716 MHD_SC_ITC_INITIALIZATION_FAILED,
713 _("Failed to create worker inter-thread communication channel: %s\n"), 717 _ (
714 MHD_itc_last_strerror_() ); 718 "Failed to create worker inter-thread communication channel: %s\n"),
715#endif 719 MHD_itc_last_strerror_ () );
716 sc = MHD_SC_ITC_INITIALIZATION_FAILED; 720#endif
717 goto thread_failed; 721 sc = MHD_SC_ITC_INITIALIZATION_FAILED;
718 } 722 goto thread_failed;
719 if ( (MHD_ELS_SELECT == daemon->event_loop_syscall) && 723 }
720 (! MHD_SCKT_FD_FITS_FDSET_(MHD_itc_r_fd_ (d->itc), 724 if ( (MHD_ELS_SELECT == daemon->event_loop_syscall) &&
721 NULL)) ) 725 (! MHD_SCKT_FD_FITS_FDSET_ (MHD_itc_r_fd_ (d->itc),
722 { 726 NULL)) )
727 {
723#ifdef HAVE_MESSAGES 728#ifdef HAVE_MESSAGES
724 MHD_DLOG (daemon, 729 MHD_DLOG (daemon,
725 MHD_SC_ITC_DESCRIPTOR_TOO_LARGE, 730 MHD_SC_ITC_DESCRIPTOR_TOO_LARGE,
726 _("File descriptor for inter-thread communication channel exceeds maximum value\n")); 731 _ (
727#endif 732 "File descriptor for inter-thread communication channel exceeds maximum value\n"));
728 MHD_itc_destroy_chk_ (d->itc); 733#endif
729 sc = MHD_SC_ITC_DESCRIPTOR_TOO_LARGE; 734 MHD_itc_destroy_chk_ (d->itc);
730 goto thread_failed; 735 sc = MHD_SC_ITC_DESCRIPTOR_TOO_LARGE;
731 } 736 goto thread_failed;
732 } 737 }
733 else 738 }
734 { 739 else
735 MHD_itc_set_invalid_ (d->itc); 740 {
736 } 741 MHD_itc_set_invalid_ (d->itc);
742 }
737 743
738#ifdef EPOLL_SUPPORT 744#ifdef EPOLL_SUPPORT
739 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 745 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
740 (MHD_SC_OK != (sc = setup_epoll_to_listen (d))) ) 746 (MHD_SC_OK != (sc = setup_epoll_to_listen (d))) )
741 goto thread_failed; 747 goto thread_failed;
742#endif 748#endif
743 749
744 /* Must init cleanup connection mutex for each worker */ 750 /* Must init cleanup connection mutex for each worker */
745 if (! MHD_mutex_init_ (&d->cleanup_connection_mutex)) 751 if (! MHD_mutex_init_ (&d->cleanup_connection_mutex))
746 { 752 {
747#ifdef HAVE_MESSAGES 753#ifdef HAVE_MESSAGES
748 MHD_DLOG (daemon, 754 MHD_DLOG (daemon,
749 MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE, 755 MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE,
750 _("MHD failed to initialize cleanup connection mutex\n")); 756 _ ("MHD failed to initialize cleanup connection mutex\n"));
751#endif 757#endif
752 if (! daemon->disable_itc) 758 if (! daemon->disable_itc)
753 MHD_itc_destroy_chk_ (d->itc); 759 MHD_itc_destroy_chk_ (d->itc);
754 sc = MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE; 760 sc = MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE;
755 goto thread_failed; 761 goto thread_failed;
756 } 762 }
757 763
758 /* Spawn the worker thread */ 764 /* Spawn the worker thread */
759 if (! MHD_create_named_thread_ (&d->pid, 765 if (! MHD_create_named_thread_ (&d->pid,
760 "MHD-worker", 766 "MHD-worker",
761 daemon->thread_stack_limit_b, 767 daemon->thread_stack_limit_b,
762 &MHD_polling_thread, 768 &MHD_polling_thread,
763 d)) 769 d))
764 { 770 {
765#ifdef HAVE_MESSAGES 771#ifdef HAVE_MESSAGES
766 MHD_DLOG (daemon, 772 MHD_DLOG (daemon,
767 MHD_SC_THREAD_POOL_LAUNCH_FAILURE, 773 MHD_SC_THREAD_POOL_LAUNCH_FAILURE,
768 _("Failed to create pool thread: %s\n"), 774 _ ("Failed to create pool thread: %s\n"),
769 MHD_strerror_ (errno)); 775 MHD_strerror_ (errno));
770#endif 776#endif
771 /* Free memory for this worker; cleanup below handles 777 /* Free memory for this worker; cleanup below handles
772 * all previously-created workers. */ 778 * all previously-created workers. */
773 if (! daemon->disable_itc) 779 if (! daemon->disable_itc)
774 MHD_itc_destroy_chk_ (d->itc); 780 MHD_itc_destroy_chk_ (d->itc);
775 MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); 781 MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
776 sc = MHD_SC_THREAD_POOL_LAUNCH_FAILURE; 782 sc = MHD_SC_THREAD_POOL_LAUNCH_FAILURE;
777 goto thread_failed; 783 goto thread_failed;
778 } 784 }
779 } /* end for() */ 785 } /* end for() */
780 return MHD_SC_OK; 786 return MHD_SC_OK;
781 787
782thread_failed: 788thread_failed:
@@ -785,14 +791,14 @@ thread_failed:
785 assumes a 0-sized thread pool means we had been in the default 791 assumes a 0-sized thread pool means we had been in the default
786 MHD_USE_INTERNAL_POLLING_THREAD mode. */ 792 MHD_USE_INTERNAL_POLLING_THREAD mode. */
787 if (0 == i) 793 if (0 == i)
794 {
795 if (NULL != daemon->worker_pool)
788 { 796 {
789 if (NULL != daemon->worker_pool) 797 free (daemon->worker_pool);
790 { 798 daemon->worker_pool = NULL;
791 free (daemon->worker_pool);
792 daemon->worker_pool = NULL;
793 }
794 return MHD_SC_THREAD_LAUNCH_FAILURE;
795 } 799 }
800 return MHD_SC_THREAD_LAUNCH_FAILURE;
801 }
796 /* Shutdown worker threads we've already created. Pretend 802 /* Shutdown worker threads we've already created. Pretend
797 as though we had fully initialized our daemon, but 803 as though we had fully initialized our daemon, but
798 with a smaller number of threads than had been 804 with a smaller number of threads than had been
@@ -817,63 +823,65 @@ MHD_daemon_start (struct MHD_Daemon *daemon)
817 enum MHD_StatusCode sc; 823 enum MHD_StatusCode sc;
818 824
819 if (MHD_ELS_AUTO == daemon->event_loop_syscall) 825 if (MHD_ELS_AUTO == daemon->event_loop_syscall)
820 { 826 {
821#if EPOLL_SUPPORT 827#if EPOLL_SUPPORT
822 /* We do not support thread-per-connection in combination 828 /* We do not support thread-per-connection in combination
823 with epoll, so use poll in this case, otherwise prefer 829 with epoll, so use poll in this case, otherwise prefer
824 epoll. */ 830 epoll. */
825 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 831 if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
826 daemon->event_loop_syscall = MHD_ELS_POLL;
827 else
828 daemon->event_loop_syscall = MHD_ELS_EPOLL;
829#elif HAVE_POLL
830 daemon->event_loop_syscall = MHD_ELS_POLL; 832 daemon->event_loop_syscall = MHD_ELS_POLL;
833 else
834 daemon->event_loop_syscall = MHD_ELS_EPOLL;
835#elif HAVE_POLL
836 daemon->event_loop_syscall = MHD_ELS_POLL;
831#else 837#else
832 daemon->event_loop_syscall = MHD_ELS_SELECT; 838 daemon->event_loop_syscall = MHD_ELS_SELECT;
833#endif 839#endif
834 } 840 }
835 841
836#ifdef EPOLL_SUPPORT 842#ifdef EPOLL_SUPPORT
837 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 843 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
838 (0 == daemon->worker_pool_size) && 844 (0 == daemon->worker_pool_size) &&
839 (MHD_INVALID_SOCKET != daemon->listen_socket) && 845 (MHD_INVALID_SOCKET != daemon->listen_socket) &&
840 (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) ) 846 (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) )
841 { 847 {
842#ifdef HAVE_MESSAGES 848#ifdef HAVE_MESSAGES
843 MHD_DLOG (daemon, 849 MHD_DLOG (daemon,
844 MHD_SC_SYSCALL_THREAD_COMBINATION_INVALID, 850 MHD_SC_SYSCALL_THREAD_COMBINATION_INVALID,
845 _("Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_EPOLL is not supported.\n")); 851 _ (
852 "Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_EPOLL is not supported.\n"));
846#endif 853#endif
847 return MHD_SC_SYSCALL_THREAD_COMBINATION_INVALID; 854 return MHD_SC_SYSCALL_THREAD_COMBINATION_INVALID;
848 } 855 }
849#endif 856#endif
850 857
851 /* Setup ITC */ 858 /* Setup ITC */
852 if ( (! daemon->disable_itc) && 859 if ( (! daemon->disable_itc) &&
853 (0 == daemon->worker_pool_size) ) 860 (0 == daemon->worker_pool_size) )
861 {
862 if (! MHD_itc_init_ (daemon->itc))
854 { 863 {
855 if (! MHD_itc_init_ (daemon->itc))
856 {
857#ifdef HAVE_MESSAGES 864#ifdef HAVE_MESSAGES
858 MHD_DLOG (daemon, 865 MHD_DLOG (daemon,
859 MHD_SC_ITC_INITIALIZATION_FAILED, 866 MHD_SC_ITC_INITIALIZATION_FAILED,
860 _("Failed to create inter-thread communication channel: %s\n"), 867 _ ("Failed to create inter-thread communication channel: %s\n"),
861 MHD_itc_last_strerror_ ()); 868 MHD_itc_last_strerror_ ());
862#endif 869#endif
863 return MHD_SC_ITC_INITIALIZATION_FAILED; 870 return MHD_SC_ITC_INITIALIZATION_FAILED;
864 } 871 }
865 if ( (MHD_ELS_SELECT == daemon->event_loop_syscall) && 872 if ( (MHD_ELS_SELECT == daemon->event_loop_syscall) &&
866 (! MHD_SCKT_FD_FITS_FDSET_(MHD_itc_r_fd_ (daemon->itc), 873 (! MHD_SCKT_FD_FITS_FDSET_ (MHD_itc_r_fd_ (daemon->itc),
867 NULL)) ) 874 NULL)) )
868 { 875 {
869#ifdef HAVE_MESSAGES 876#ifdef HAVE_MESSAGES
870 MHD_DLOG (daemon, 877 MHD_DLOG (daemon,
871 MHD_SC_ITC_DESCRIPTOR_TOO_LARGE, 878 MHD_SC_ITC_DESCRIPTOR_TOO_LARGE,
872 _("File descriptor for inter-thread communication channel exceeds maximum value\n")); 879 _ (
880 "File descriptor for inter-thread communication channel exceeds maximum value\n"));
873#endif 881#endif
874 return MHD_SC_ITC_DESCRIPTOR_TOO_LARGE; 882 return MHD_SC_ITC_DESCRIPTOR_TOO_LARGE;
875 }
876 } 883 }
884 }
877 885
878 if (MHD_SC_OK != (sc = open_listen_socket (daemon))) 886 if (MHD_SC_OK != (sc = open_listen_socket (daemon)))
879 return sc; 887 return sc;
@@ -881,39 +889,39 @@ MHD_daemon_start (struct MHD_Daemon *daemon)
881 /* Check listen socket is in range (if we are limited) */ 889 /* Check listen socket is in range (if we are limited) */
882 if ( (MHD_INVALID_SOCKET != daemon->listen_socket) && 890 if ( (MHD_INVALID_SOCKET != daemon->listen_socket) &&
883 (MHD_ELS_SELECT == daemon->event_loop_syscall) && 891 (MHD_ELS_SELECT == daemon->event_loop_syscall) &&
884 (! MHD_SCKT_FD_FITS_FDSET_(daemon->listen_socket, 892 (! MHD_SCKT_FD_FITS_FDSET_ (daemon->listen_socket,
885 NULL)) ) 893 NULL)) )
886 { 894 {
887#ifdef HAVE_MESSAGES 895#ifdef HAVE_MESSAGES
888 MHD_DLOG (daemon, 896 MHD_DLOG (daemon,
889 MHD_SC_LISTEN_SOCKET_TOO_LARGE, 897 MHD_SC_LISTEN_SOCKET_TOO_LARGE,
890 _("Socket descriptor larger than FD_SETSIZE: %d > %d\n"), 898 _ ("Socket descriptor larger than FD_SETSIZE: %d > %d\n"),
891 daemon->listen_socket, 899 daemon->listen_socket,
892 FD_SETSIZE); 900 FD_SETSIZE);
893#endif 901#endif
894 return MHD_SC_LISTEN_SOCKET_TOO_LARGE; 902 return MHD_SC_LISTEN_SOCKET_TOO_LARGE;
895 } 903 }
896 904
897 /* set listen socket to non-blocking */ 905 /* set listen socket to non-blocking */
898 if ( (MHD_INVALID_SOCKET != daemon->listen_socket) && 906 if ( (MHD_INVALID_SOCKET != daemon->listen_socket) &&
899 (! MHD_socket_nonblocking_ (daemon->listen_socket)) ) 907 (! MHD_socket_nonblocking_ (daemon->listen_socket)) )
900 { 908 {
901#ifdef HAVE_MESSAGES 909#ifdef HAVE_MESSAGES
902 MHD_DLOG (daemon, 910 MHD_DLOG (daemon,
903 MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE, 911 MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE,
904 _("Failed to set nonblocking mode on listening socket: %s\n"), 912 _ ("Failed to set nonblocking mode on listening socket: %s\n"),
905 MHD_socket_last_strerr_()); 913 MHD_socket_last_strerr_ ());
906#endif 914#endif
907 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) || 915 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) ||
908 (daemon->worker_pool_size > 0) ) 916 (daemon->worker_pool_size > 0) )
909 { 917 {
910 /* Accept must be non-blocking. Multiple children may wake 918 /* Accept must be non-blocking. Multiple children may wake
911 * up to handle a new connection, but only one will win the 919 * up to handle a new connection, but only one will win the
912 * race. The others must immediately return. As this is 920 * race. The others must immediately return. As this is
913 * not possible, we must fail hard here. */ 921 * not possible, we must fail hard here. */
914 return MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE; 922 return MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE;
915 }
916 } 923 }
924 }
917 925
918#ifdef EPOLL_SUPPORT 926#ifdef EPOLL_SUPPORT
919 /* Setup epoll */ 927 /* Setup epoll */
@@ -928,30 +936,31 @@ MHD_daemon_start (struct MHD_Daemon *daemon)
928 external event loop and do have a listen socket) */ 936 external event loop and do have a listen socket) */
929 /* FIXME: why no worker thread if we have no listen socket? */ 937 /* FIXME: why no worker thread if we have no listen socket? */
930 if ( ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) || 938 if ( ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) ||
931 (1 == daemon->threading_mode) ) && 939 (1 == daemon->threading_mode) ) &&
932 (MHD_INVALID_SOCKET != daemon->listen_socket) && 940 (MHD_INVALID_SOCKET != daemon->listen_socket) &&
933 (! MHD_create_named_thread_ (&daemon->pid, 941 (! MHD_create_named_thread_ (&daemon->pid,
934 (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) 942 (MHD_TM_THREAD_PER_CONNECTION ==
935 ? "MHD-listen" 943 daemon->threading_mode)
936 : "MHD-single", 944 ? "MHD-listen"
937 daemon->thread_stack_limit_b, 945 : "MHD-single",
938 &MHD_polling_thread, 946 daemon->thread_stack_limit_b,
939 daemon) ) ) 947 &MHD_polling_thread,
940 { 948 daemon) ) )
949 {
941#ifdef HAVE_MESSAGES 950#ifdef HAVE_MESSAGES
942 MHD_DLOG (daemon, 951 MHD_DLOG (daemon,
943 MHD_SC_THREAD_MAIN_LAUNCH_FAILURE, 952 MHD_SC_THREAD_MAIN_LAUNCH_FAILURE,
944 _("Failed to create listen thread: %s\n"), 953 _ ("Failed to create listen thread: %s\n"),
945 MHD_strerror_ (errno)); 954 MHD_strerror_ (errno));
946#endif 955#endif
947 return MHD_SC_THREAD_MAIN_LAUNCH_FAILURE; 956 return MHD_SC_THREAD_MAIN_LAUNCH_FAILURE;
948 } 957 }
949 958
950 /* Setup worker threads */ 959 /* Setup worker threads */
951 /* FIXME: why no thread pool if we have no listen socket? */ 960 /* FIXME: why no thread pool if we have no listen socket? */
952 if ( (1 < daemon->threading_mode) && 961 if ( (1 < daemon->threading_mode) &&
953 (MHD_INVALID_SOCKET != daemon->listen_socket) && 962 (MHD_INVALID_SOCKET != daemon->listen_socket) &&
954 (MHD_SC_OK != (sc = setup_thread_pool (daemon))) ) 963 (MHD_SC_OK != (sc = setup_thread_pool (daemon))) )
955 return sc; 964 return sc;
956 965
957 /* make sure we know our listen port (if any) */ 966 /* make sure we know our listen port (if any) */
diff --git a/src/lib/init.c b/src/lib/init.c
index b23bdadf..5dcb02c4 100644
--- a/src/lib/init.c
+++ b/src/lib/init.c
@@ -36,7 +36,7 @@ volatile unsigned int global_init_count = 0;
36/** 36/**
37 * Global initialisation mutex 37 * Global initialisation mutex
38 */ 38 */
39MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); 39MHD_MUTEX_STATIC_DEFN_INIT_ (global_init_mutex_);
40#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 40#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
41 41
42#endif 42#endif
@@ -59,21 +59,21 @@ static int mhd_winsock_inited_ = 0;
59 */ 59 */
60static void 60static void
61mhd_panic_std (void *cls, 61mhd_panic_std (void *cls,
62 const char *file, 62 const char *file,
63 unsigned int line, 63 unsigned int line,
64 const char *reason) 64 const char *reason)
65{ 65{
66 (void)cls; /* Mute compiler warning. */ 66 (void) cls; /* Mute compiler warning. */
67#ifdef HAVE_MESSAGES 67#ifdef HAVE_MESSAGES
68 fprintf (stderr, 68 fprintf (stderr,
69 _("Fatal error in GNU libmicrohttpd %s:%u: %s\n"), 69 _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
70 file, 70 file,
71 line, 71 line,
72 reason); 72 reason);
73#else /* ! HAVE_MESSAGES */ 73#else /* ! HAVE_MESSAGES */
74 (void)file; /* Mute compiler warning. */ 74 (void) file; /* Mute compiler warning. */
75 (void)line; /* Mute compiler warning. */ 75 (void) line; /* Mute compiler warning. */
76 (void)reason; /* Mute compiler warning. */ 76 (void) reason; /* Mute compiler warning. */
77#endif 77#endif
78 abort (); 78 abort ();
79} 79}
@@ -93,13 +93,13 @@ MHD_init (void)
93 mhd_panic = &mhd_panic_std; 93 mhd_panic = &mhd_panic_std;
94 94
95#if defined(_WIN32) && ! defined(__CYGWIN__) 95#if defined(_WIN32) && ! defined(__CYGWIN__)
96 if (0 != WSAStartup (MAKEWORD(2, 2), 96 if (0 != WSAStartup (MAKEWORD (2, 2),
97 &wsd)) 97 &wsd))
98 MHD_PANIC (_("Failed to initialize winsock\n")); 98 MHD_PANIC (_ ("Failed to initialize winsock\n"));
99 mhd_winsock_inited_ = 1; 99 mhd_winsock_inited_ = 1;
100 if ( (2 != LOBYTE(wsd.wVersion)) && 100 if ( (2 != LOBYTE (wsd.wVersion)) &&
101 (2 != HIBYTE(wsd.wVersion)) ) 101 (2 != HIBYTE (wsd.wVersion)) )
102 MHD_PANIC (_("Winsock version 2.2 is not available\n")); 102 MHD_PANIC (_ ("Winsock version 2.2 is not available\n"));
103#endif 103#endif
104 MHD_monotonic_sec_counter_init (); 104 MHD_monotonic_sec_counter_init ();
105#ifdef HAVE_FREEBSD_SENDFILE 105#ifdef HAVE_FREEBSD_SENDFILE
@@ -116,14 +116,14 @@ MHD_fini (void)
116{ 116{
117#if defined(_WIN32) && ! defined(__CYGWIN__) 117#if defined(_WIN32) && ! defined(__CYGWIN__)
118 if (mhd_winsock_inited_) 118 if (mhd_winsock_inited_)
119 WSACleanup(); 119 WSACleanup ();
120#endif 120#endif
121 MHD_monotonic_sec_counter_finish (); 121 MHD_monotonic_sec_counter_finish ();
122} 122}
123 123
124#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED 124#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
125 125
126_SET_INIT_AND_DEINIT_FUNCS(MHD_init, MHD_fini); 126_SET_INIT_AND_DEINIT_FUNCS (MHD_init, MHD_fini);
127 127
128#else 128#else
129 129
@@ -135,12 +135,12 @@ void
135MHD_check_global_init_ (void) 135MHD_check_global_init_ (void)
136{ 136{
137#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 137#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
138 MHD_mutex_lock_chk_(&global_init_mutex_); 138 MHD_mutex_lock_chk_ (&global_init_mutex_);
139#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 139#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
140 if (0 == global_init_count++) 140 if (0 == global_init_count++)
141 MHD_init (); 141 MHD_init ();
142#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 142#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
143 MHD_mutex_unlock_chk_(&global_init_mutex_); 143 MHD_mutex_unlock_chk_ (&global_init_mutex_);
144#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 144#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
145} 145}
146#endif 146#endif
diff --git a/src/lib/init.h b/src/lib/init.h
index fae96159..2d9a9389 100644
--- a/src/lib/init.h
+++ b/src/lib/init.h
@@ -31,7 +31,7 @@
31 * Do nothing - global initialisation is 31 * Do nothing - global initialisation is
32 * performed by library constructor. 32 * performed by library constructor.
33 */ 33 */
34#define MHD_check_global_init_() (void)0 34#define MHD_check_global_init_() (void) 0
35#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */ 35#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */
36/** 36/**
37 * Check whether global initialisation was performed 37 * Check whether global initialisation was performed
diff --git a/src/lib/internal.c b/src/lib/internal.c
index 75eae8a4..04d83624 100644
--- a/src/lib/internal.c
+++ b/src/lib/internal.c
@@ -35,50 +35,50 @@ const char *
35MHD_state_to_string (enum MHD_CONNECTION_STATE state) 35MHD_state_to_string (enum MHD_CONNECTION_STATE state)
36{ 36{
37 switch (state) 37 switch (state)
38 { 38 {
39 case MHD_CONNECTION_INIT: 39 case MHD_CONNECTION_INIT:
40 return "connection init"; 40 return "connection init";
41 case MHD_CONNECTION_URL_RECEIVED: 41 case MHD_CONNECTION_URL_RECEIVED:
42 return "connection url received"; 42 return "connection url received";
43 case MHD_CONNECTION_HEADER_PART_RECEIVED: 43 case MHD_CONNECTION_HEADER_PART_RECEIVED:
44 return "header partially received"; 44 return "header partially received";
45 case MHD_CONNECTION_HEADERS_RECEIVED: 45 case MHD_CONNECTION_HEADERS_RECEIVED:
46 return "headers received"; 46 return "headers received";
47 case MHD_CONNECTION_HEADERS_PROCESSED: 47 case MHD_CONNECTION_HEADERS_PROCESSED:
48 return "headers processed"; 48 return "headers processed";
49 case MHD_CONNECTION_CONTINUE_SENDING: 49 case MHD_CONNECTION_CONTINUE_SENDING:
50 return "continue sending"; 50 return "continue sending";
51 case MHD_CONNECTION_CONTINUE_SENT: 51 case MHD_CONNECTION_CONTINUE_SENT:
52 return "continue sent"; 52 return "continue sent";
53 case MHD_CONNECTION_BODY_RECEIVED: 53 case MHD_CONNECTION_BODY_RECEIVED:
54 return "body received"; 54 return "body received";
55 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 55 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
56 return "footer partially received"; 56 return "footer partially received";
57 case MHD_CONNECTION_FOOTERS_RECEIVED: 57 case MHD_CONNECTION_FOOTERS_RECEIVED:
58 return "footers received"; 58 return "footers received";
59 case MHD_CONNECTION_HEADERS_SENDING: 59 case MHD_CONNECTION_HEADERS_SENDING:
60 return "headers sending"; 60 return "headers sending";
61 case MHD_CONNECTION_HEADERS_SENT: 61 case MHD_CONNECTION_HEADERS_SENT:
62 return "headers sent"; 62 return "headers sent";
63 case MHD_CONNECTION_NORMAL_BODY_READY: 63 case MHD_CONNECTION_NORMAL_BODY_READY:
64 return "normal body ready"; 64 return "normal body ready";
65 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 65 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
66 return "normal body unready"; 66 return "normal body unready";
67 case MHD_CONNECTION_CHUNKED_BODY_READY: 67 case MHD_CONNECTION_CHUNKED_BODY_READY:
68 return "chunked body ready"; 68 return "chunked body ready";
69 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 69 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
70 return "chunked body unready"; 70 return "chunked body unready";
71 case MHD_CONNECTION_BODY_SENT: 71 case MHD_CONNECTION_BODY_SENT:
72 return "body sent"; 72 return "body sent";
73 case MHD_CONNECTION_FOOTERS_SENDING: 73 case MHD_CONNECTION_FOOTERS_SENDING:
74 return "footers sending"; 74 return "footers sending";
75 case MHD_CONNECTION_FOOTERS_SENT: 75 case MHD_CONNECTION_FOOTERS_SENT:
76 return "footers sent"; 76 return "footers sent";
77 case MHD_CONNECTION_CLOSED: 77 case MHD_CONNECTION_CLOSED:
78 return "closed"; 78 return "closed";
79 default: 79 default:
80 return "unrecognized connection state"; 80 return "unrecognized connection state";
81 } 81 }
82} 82}
83#endif 83#endif
84#endif 84#endif
@@ -91,7 +91,7 @@ MHD_state_to_string (enum MHD_CONNECTION_STATE state)
91 */ 91 */
92void 92void
93MHD_DLOG (const struct MHD_Daemon *daemon, 93MHD_DLOG (const struct MHD_Daemon *daemon,
94 enum MHD_StatusCode sc, 94 enum MHD_StatusCode sc,
95 const char *format, 95 const char *format,
96 ...) 96 ...)
97{ 97{
@@ -100,11 +100,11 @@ MHD_DLOG (const struct MHD_Daemon *daemon,
100 if (NULL == daemon->logger) 100 if (NULL == daemon->logger)
101 return; 101 return;
102 va_start (va, 102 va_start (va,
103 format); 103 format);
104 daemon->logger (daemon->logger_cls, 104 daemon->logger (daemon->logger_cls,
105 sc, 105 sc,
106 format, 106 format,
107 va); 107 va);
108 va_end (va); 108 va_end (va);
109} 109}
110#endif 110#endif
@@ -120,7 +120,7 @@ MHD_unescape_plus (char *arg)
120{ 120{
121 char *p; 121 char *p;
122 122
123 for (p=strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+')) 123 for (p = strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+'))
124 *p = ' '; 124 *p = ' ';
125} 125}
126 126
@@ -141,28 +141,28 @@ MHD_http_unescape (char *val)
141 char *wpos = val; 141 char *wpos = val;
142 142
143 while ('\0' != *rpos) 143 while ('\0' != *rpos)
144 {
145 uint32_t num;
146 switch (*rpos)
144 { 147 {
145 uint32_t num; 148 case '%':
146 switch (*rpos) 149 if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
147 { 150 2,
148 case '%': 151 &num))
149 if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 152 {
150 2, 153 *wpos = (char) ((unsigned char) num);
151 &num)) 154 wpos++;
152 { 155 rpos += 3;
153 *wpos = (char)((unsigned char) num); 156 break;
154 wpos++; 157 }
155 rpos += 3; 158 /* TODO: add bad sequence handling */
156 break; 159 /* intentional fall through! */
157 } 160 default:
158 /* TODO: add bad sequence handling */ 161 *wpos = *rpos;
159 /* intentional fall through! */ 162 wpos++;
160 default: 163 rpos++;
161 *wpos = *rpos;
162 wpos++;
163 rpos++;
164 }
165 } 164 }
165 }
166 *wpos = '\0'; /* add 0-terminator */ 166 *wpos = '\0'; /* add 0-terminator */
167 return wpos - val; /* = strlen(val) */ 167 return wpos - val; /* = strlen(val) */
168} 168}
@@ -184,10 +184,10 @@ MHD_http_unescape (char *val)
184 */ 184 */
185bool 185bool
186MHD_parse_arguments_ (struct MHD_Request *request, 186MHD_parse_arguments_ (struct MHD_Request *request,
187 enum MHD_ValueKind kind, 187 enum MHD_ValueKind kind,
188 char *args, 188 char *args,
189 MHD_ArgumentIterator_ cb, 189 MHD_ArgumentIterator_ cb,
190 unsigned int *num_headers) 190 unsigned int *num_headers)
191{ 191{
192 struct MHD_Daemon *daemon = request->daemon; 192 struct MHD_Daemon *daemon = request->daemon;
193 char *equals; 193 char *equals;
@@ -195,88 +195,88 @@ MHD_parse_arguments_ (struct MHD_Request *request,
195 195
196 *num_headers = 0; 196 *num_headers = 0;
197 while ( (NULL != args) && 197 while ( (NULL != args) &&
198 ('\0' != args[0]) ) 198 ('\0' != args[0]) )
199 {
200 equals = strchr (args, '=');
201 amper = strchr (args, '&');
202 if (NULL == amper)
199 { 203 {
200 equals = strchr (args, '='); 204 /* last argument */
201 amper = strchr (args, '&'); 205 if (NULL == equals)
202 if (NULL == amper) 206 {
203 { 207 /* last argument, without '=' */
204 /* last argument */ 208 MHD_unescape_plus (args);
205 if (NULL == equals) 209 daemon->unescape_cb (daemon->unescape_cb_cls,
206 { 210 request,
207 /* last argument, without '=' */ 211 args);
208 MHD_unescape_plus (args); 212 if (! cb (request,
209 daemon->unescape_cb (daemon->unescape_cb_cls, 213 args,
210 request, 214 NULL,
211 args); 215 kind))
212 if (! cb (request, 216 return false;
213 args, 217 (*num_headers)++;
214 NULL, 218 break;
215 kind)) 219 }
216 return false; 220 /* got 'foo=bar' */
217 (*num_headers)++;
218 break;
219 }
220 /* got 'foo=bar' */
221 equals[0] = '\0';
222 equals++;
223 MHD_unescape_plus (args);
224 daemon->unescape_cb (daemon->unescape_cb_cls,
225 request,
226 args);
227 MHD_unescape_plus (equals);
228 daemon->unescape_cb (daemon->unescape_cb_cls,
229 request,
230 equals);
231 if (! cb (request,
232 args,
233 equals,
234 kind))
235 return false;
236 (*num_headers)++;
237 break;
238 }
239 /* amper is non-NULL here */
240 amper[0] = '\0';
241 amper++;
242 if ( (NULL == equals) ||
243 (equals >= amper) )
244 {
245 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
246 MHD_unescape_plus (args);
247 daemon->unescape_cb (daemon->unescape_cb_cls,
248 request,
249 args);
250 if (! cb (request,
251 args,
252 NULL,
253 kind))
254 return false;
255 /* continue with 'bar' */
256 (*num_headers)++;
257 args = amper;
258 continue;
259 }
260 /* equals and amper are non-NULL here, and equals < amper,
261 so we got regular 'foo=value&bar...'-kind of argument */
262 equals[0] = '\0'; 221 equals[0] = '\0';
263 equals++; 222 equals++;
264 MHD_unescape_plus (args); 223 MHD_unescape_plus (args);
265 daemon->unescape_cb (daemon->unescape_cb_cls, 224 daemon->unescape_cb (daemon->unescape_cb_cls,
266 request, 225 request,
267 args); 226 args);
268 MHD_unescape_plus (equals); 227 MHD_unescape_plus (equals);
269 daemon->unescape_cb (daemon->unescape_cb_cls, 228 daemon->unescape_cb (daemon->unescape_cb_cls,
270 request, 229 request,
271 equals); 230 equals);
231 if (! cb (request,
232 args,
233 equals,
234 kind))
235 return false;
236 (*num_headers)++;
237 break;
238 }
239 /* amper is non-NULL here */
240 amper[0] = '\0';
241 amper++;
242 if ( (NULL == equals) ||
243 (equals >= amper) )
244 {
245 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
246 MHD_unescape_plus (args);
247 daemon->unescape_cb (daemon->unescape_cb_cls,
248 request,
249 args);
272 if (! cb (request, 250 if (! cb (request,
273 args, 251 args,
274 equals, 252 NULL,
275 kind)) 253 kind))
276 return false; 254 return false;
255 /* continue with 'bar' */
277 (*num_headers)++; 256 (*num_headers)++;
278 args = amper; 257 args = amper;
258 continue;
279 } 259 }
260 /* equals and amper are non-NULL here, and equals < amper,
261 so we got regular 'foo=value&bar...'-kind of argument */
262 equals[0] = '\0';
263 equals++;
264 MHD_unescape_plus (args);
265 daemon->unescape_cb (daemon->unescape_cb_cls,
266 request,
267 args);
268 MHD_unescape_plus (equals);
269 daemon->unescape_cb (daemon->unescape_cb_cls,
270 request,
271 equals);
272 if (! cb (request,
273 args,
274 equals,
275 kind))
276 return false;
277 (*num_headers)++;
278 args = amper;
279 }
280 return true; 280 return true;
281} 281}
282 282
diff --git a/src/lib/internal.h b/src/lib/internal.h
index bd3bd1c6..b5ec3039 100644
--- a/src/lib/internal.h
+++ b/src/lib/internal.h
@@ -58,14 +58,16 @@
58 * 58 *
59 * @param msg error message (const char *) 59 * @param msg error message (const char *)
60 */ 60 */
61#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0) 61#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
62 BUILTIN_NOT_REACHED; } while (0)
62#else 63#else
63/** 64/**
64 * Trigger 'panic' action based on fatal errors. 65 * Trigger 'panic' action based on fatal errors.
65 * 66 *
66 * @param msg error message (const char *) 67 * @param msg error message (const char *)
67 */ 68 */
68#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0) 69#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
70 BUILTIN_NOT_REACHED; } while (0)
69#endif 71#endif
70 72
71#include "mhd_threads.h" 73#include "mhd_threads.h"
@@ -82,8 +84,8 @@
82 */ 84 */
83void 85void
84MHD_DLOG (const struct MHD_Daemon *daemon, 86MHD_DLOG (const struct MHD_Daemon *daemon,
85 enum MHD_StatusCode sc, 87 enum MHD_StatusCode sc,
86 const char *format, 88 const char *format,
87 ...); 89 ...);
88#endif 90#endif
89 91
@@ -93,9 +95,9 @@ MHD_DLOG (const struct MHD_Daemon *daemon,
93 * @param fd the FD to close 95 * @param fd the FD to close
94 */ 96 */
95#define MHD_fd_close_chk_(fd) do { \ 97#define MHD_fd_close_chk_(fd) do { \
96 if ( (0 != close ((fd)) && (EBADF == errno)) ) \ 98 if ( (0 != close ((fd)) && (EBADF == errno)) ) \
97 MHD_PANIC(_("Failed to close FD.\n")); \ 99 MHD_PANIC (_ ("Failed to close FD.\n")); \
98 } while(0) 100} while (0)
99 101
100/** 102/**
101 * Should we perform additional sanity checks at runtime (on our internal 103 * Should we perform additional sanity checks at runtime (on our internal
@@ -128,10 +130,11 @@ extern MHD_PanicCallback mhd_panic;
128extern void *mhd_panic_cls; 130extern void *mhd_panic_cls;
129 131
130/* If we have Clang or gcc >= 4.5, use __buildin_unreachable() */ 132/* If we have Clang or gcc >= 4.5, use __buildin_unreachable() */
131#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 133#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= \
132#define BUILTIN_NOT_REACHED __builtin_unreachable() 134 5)
135#define BUILTIN_NOT_REACHED __builtin_unreachable ()
133#elif defined(_MSC_FULL_VER) 136#elif defined(_MSC_FULL_VER)
134#define BUILTIN_NOT_REACHED __assume(0) 137#define BUILTIN_NOT_REACHED __assume (0)
135#else 138#else
136#define BUILTIN_NOT_REACHED 139#define BUILTIN_NOT_REACHED
137#endif 140#endif
@@ -140,7 +143,7 @@ extern void *mhd_panic_cls;
140/** 143/**
141 * Determine length of static string / macro strings at compile time. 144 * Determine length of static string / macro strings at compile time.
142 */ 145 */
143#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 146#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
144#endif /* ! MHD_STATICSTR_LEN_ */ 147#endif /* ! MHD_STATICSTR_LEN_ */
145 148
146 149
@@ -1534,8 +1537,8 @@ struct MHD_Daemon
1534 * @return #MHD_SC_OK on success, otherwise an error code 1537 * @return #MHD_SC_OK on success, otherwise an error code
1535 */ 1538 */
1536typedef enum MHD_StatusCode 1539typedef enum MHD_StatusCode
1537(*ActionCallback) (void *cls, 1540(*ActionCallback)(void *cls,
1538 struct MHD_Request *request); 1541 struct MHD_Request *request);
1539 1542
1540 1543
1541/** 1544/**
@@ -1703,9 +1706,9 @@ struct MHD_Response
1703 */ 1706 */
1704typedef bool 1707typedef bool
1705(*MHD_ArgumentIterator_)(struct MHD_Request *request, 1708(*MHD_ArgumentIterator_)(struct MHD_Request *request,
1706 const char *key, 1709 const char *key,
1707 const char *value, 1710 const char *value,
1708 enum MHD_ValueKind kind); 1711 enum MHD_ValueKind kind);
1709 1712
1710 1713
1711/** 1714/**
@@ -1724,10 +1727,10 @@ typedef bool
1724 */ 1727 */
1725bool 1728bool
1726MHD_parse_arguments_ (struct MHD_Request *request, 1729MHD_parse_arguments_ (struct MHD_Request *request,
1727 enum MHD_ValueKind kind, 1730 enum MHD_ValueKind kind,
1728 char *args, 1731 char *args,
1729 MHD_ArgumentIterator_ cb, 1732 MHD_ArgumentIterator_ cb,
1730 unsigned int *num_headers); 1733 unsigned int *num_headers);
1731 1734
1732 1735
1733 1736
@@ -1740,15 +1743,15 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1740 * @param element element to insert 1743 * @param element element to insert
1741 */ 1744 */
1742#define DLL_insert(head,tail,element) do { \ 1745#define DLL_insert(head,tail,element) do { \
1743 mhd_assert (NULL == (element)->next); \ 1746 mhd_assert (NULL == (element)->next); \
1744 mhd_assert (NULL == (element)->prev); \ 1747 mhd_assert (NULL == (element)->prev); \
1745 (element)->next = (head); \ 1748 (element)->next = (head); \
1746 (element)->prev = NULL; \ 1749 (element)->prev = NULL; \
1747 if ((tail) == NULL) \ 1750 if ((tail) == NULL) \
1748 (tail) = element; \ 1751 (tail) = element; \
1749 else \ 1752 else \
1750 (head)->prev = element; \ 1753 (head)->prev = element; \
1751 (head) = (element); } while (0) 1754 (head) = (element); } while (0)
1752 1755
1753 1756
1754/** 1757/**
@@ -1760,18 +1763,18 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1760 * @param element element to remove 1763 * @param element element to remove
1761 */ 1764 */
1762#define DLL_remove(head,tail,element) do { \ 1765#define DLL_remove(head,tail,element) do { \
1763 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \ 1766 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
1764 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \ 1767 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
1765 if ((element)->prev == NULL) \ 1768 if ((element)->prev == NULL) \
1766 (head) = (element)->next; \ 1769 (head) = (element)->next; \
1767 else \ 1770 else \
1768 (element)->prev->next = (element)->next; \ 1771 (element)->prev->next = (element)->next; \
1769 if ((element)->next == NULL) \ 1772 if ((element)->next == NULL) \
1770 (tail) = (element)->prev; \ 1773 (tail) = (element)->prev; \
1771 else \ 1774 else \
1772 (element)->next->prev = (element)->prev; \ 1775 (element)->next->prev = (element)->prev; \
1773 (element)->next = NULL; \ 1776 (element)->next = NULL; \
1774 (element)->prev = NULL; } while (0) 1777 (element)->prev = NULL; } while (0)
1775 1778
1776 1779
1777 1780
@@ -1784,15 +1787,15 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1784 * @param element element to insert 1787 * @param element element to insert
1785 */ 1788 */
1786#define XDLL_insert(head,tail,element) do { \ 1789#define XDLL_insert(head,tail,element) do { \
1787 mhd_assert (NULL == (element)->nextX); \ 1790 mhd_assert (NULL == (element)->nextX); \
1788 mhd_assert (NULL == (element)->prevX); \ 1791 mhd_assert (NULL == (element)->prevX); \
1789 (element)->nextX = (head); \ 1792 (element)->nextX = (head); \
1790 (element)->prevX = NULL; \ 1793 (element)->prevX = NULL; \
1791 if (NULL == (tail)) \ 1794 if (NULL == (tail)) \
1792 (tail) = element; \ 1795 (tail) = element; \
1793 else \ 1796 else \
1794 (head)->prevX = element; \ 1797 (head)->prevX = element; \
1795 (head) = (element); } while (0) 1798 (head) = (element); } while (0)
1796 1799
1797 1800
1798/** 1801/**
@@ -1804,18 +1807,18 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1804 * @param element element to remove 1807 * @param element element to remove
1805 */ 1808 */
1806#define XDLL_remove(head,tail,element) do { \ 1809#define XDLL_remove(head,tail,element) do { \
1807 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \ 1810 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
1808 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \ 1811 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
1809 if (NULL == (element)->prevX) \ 1812 if (NULL == (element)->prevX) \
1810 (head) = (element)->nextX; \ 1813 (head) = (element)->nextX; \
1811 else \ 1814 else \
1812 (element)->prevX->nextX = (element)->nextX; \ 1815 (element)->prevX->nextX = (element)->nextX; \
1813 if (NULL == (element)->nextX) \ 1816 if (NULL == (element)->nextX) \
1814 (tail) = (element)->prevX; \ 1817 (tail) = (element)->prevX; \
1815 else \ 1818 else \
1816 (element)->nextX->prevX = (element)->prevX; \ 1819 (element)->nextX->prevX = (element)->prevX; \
1817 (element)->nextX = NULL; \ 1820 (element)->nextX = NULL; \
1818 (element)->prevX = NULL; } while (0) 1821 (element)->prevX = NULL; } while (0)
1819 1822
1820 1823
1821/** 1824/**
@@ -1827,13 +1830,13 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1827 * @param element element to insert 1830 * @param element element to insert
1828 */ 1831 */
1829#define EDLL_insert(head,tail,element) do { \ 1832#define EDLL_insert(head,tail,element) do { \
1830 (element)->nextE = (head); \ 1833 (element)->nextE = (head); \
1831 (element)->prevE = NULL; \ 1834 (element)->prevE = NULL; \
1832 if ((tail) == NULL) \ 1835 if ((tail) == NULL) \
1833 (tail) = element; \ 1836 (tail) = element; \
1834 else \ 1837 else \
1835 (head)->prevE = element; \ 1838 (head)->prevE = element; \
1836 (head) = (element); } while (0) 1839 (head) = (element); } while (0)
1837 1840
1838 1841
1839/** 1842/**
@@ -1845,16 +1848,16 @@ MHD_parse_arguments_ (struct MHD_Request *request,
1845 * @param element element to remove 1848 * @param element element to remove
1846 */ 1849 */
1847#define EDLL_remove(head,tail,element) do { \ 1850#define EDLL_remove(head,tail,element) do { \
1848 if ((element)->prevE == NULL) \ 1851 if ((element)->prevE == NULL) \
1849 (head) = (element)->nextE; \ 1852 (head) = (element)->nextE; \
1850 else \ 1853 else \
1851 (element)->prevE->nextE = (element)->nextE; \ 1854 (element)->prevE->nextE = (element)->nextE; \
1852 if ((element)->nextE == NULL) \ 1855 if ((element)->nextE == NULL) \
1853 (tail) = (element)->prevE; \ 1856 (tail) = (element)->prevE; \
1854 else \ 1857 else \
1855 (element)->nextE->prevE = (element)->prevE; \ 1858 (element)->nextE->prevE = (element)->prevE; \
1856 (element)->nextE = NULL; \ 1859 (element)->nextE = NULL; \
1857 (element)->prevE = NULL; } while (0) 1860 (element)->prevE = NULL; } while (0)
1858 1861
1859 1862
1860 1863
diff --git a/src/lib/md5.c b/src/lib/md5.c
index a7eb35fe..3d0f7493 100644
--- a/src/lib/md5.c
+++ b/src/lib/md5.c
@@ -20,21 +20,21 @@
20#include "md5.h" 20#include "md5.h"
21#include "mhd_byteorder.h" 21#include "mhd_byteorder.h"
22 22
23#define PUT_64BIT_LE(cp, value) do { \ 23#define PUT_64BIT_LE(cp, value) do { \
24 (cp)[7] = (uint8_t)((value) >> 56); \ 24 (cp)[7] = (uint8_t) ((value) >> 56); \
25 (cp)[6] = (uint8_t)((value) >> 48); \ 25 (cp)[6] = (uint8_t) ((value) >> 48); \
26 (cp)[5] = (uint8_t)((value) >> 40); \ 26 (cp)[5] = (uint8_t) ((value) >> 40); \
27 (cp)[4] = (uint8_t)((value) >> 32); \ 27 (cp)[4] = (uint8_t) ((value) >> 32); \
28 (cp)[3] = (uint8_t)((value) >> 24); \ 28 (cp)[3] = (uint8_t) ((value) >> 24); \
29 (cp)[2] = (uint8_t)((value) >> 16); \ 29 (cp)[2] = (uint8_t) ((value) >> 16); \
30 (cp)[1] = (uint8_t)((value) >> 8); \ 30 (cp)[1] = (uint8_t) ((value) >> 8); \
31 (cp)[0] = (uint8_t)((value)); } while (0) 31 (cp)[0] = (uint8_t) ((value)); } while (0)
32 32
33#define PUT_32BIT_LE(cp, value) do { \ 33#define PUT_32BIT_LE(cp, value) do { \
34 (cp)[3] = (uint8_t)((value) >> 24); \ 34 (cp)[3] = (uint8_t) ((value) >> 24); \
35 (cp)[2] = (uint8_t)((value) >> 16); \ 35 (cp)[2] = (uint8_t) ((value) >> 16); \
36 (cp)[1] = (uint8_t)((value) >> 8); \ 36 (cp)[1] = (uint8_t) ((value) >> 8); \
37 (cp)[0] = (uint8_t)((value)); } while (0) 37 (cp)[0] = (uint8_t) ((value)); } while (0)
38 38
39static uint8_t PADDING[MD5_BLOCK_SIZE] = { 39static uint8_t PADDING[MD5_BLOCK_SIZE] = {
40 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -47,9 +47,9 @@ static uint8_t PADDING[MD5_BLOCK_SIZE] = {
47 * initialization constants. 47 * initialization constants.
48 */ 48 */
49void 49void
50MHD_MD5Init(struct MD5Context *ctx) 50MHD_MD5Init (struct MD5Context *ctx)
51{ 51{
52 if (!ctx) 52 if (! ctx)
53 return; 53 return;
54 54
55 ctx->count = 0; 55 ctx->count = 0;
@@ -64,26 +64,26 @@ MHD_MD5Init(struct MD5Context *ctx)
64 * of bytes. 64 * of bytes.
65 */ 65 */
66void 66void
67MHD_MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len) 67MHD_MD5Update (struct MD5Context *ctx, const unsigned char *input, size_t len)
68{ 68{
69 size_t have, need; 69 size_t have, need;
70 70
71 if (!ctx || !input) 71 if (! ctx || ! input)
72 return; 72 return;
73 73
74 /* Check how many bytes we already have and how many more we need. */ 74 /* Check how many bytes we already have and how many more we need. */
75 have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1)); 75 have = (size_t) ((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1));
76 need = MD5_BLOCK_SIZE - have; 76 need = MD5_BLOCK_SIZE - have;
77 77
78 /* Update bitcount */ 78 /* Update bitcount */
79 ctx->count += (uint64_t)len << 3; 79 ctx->count += (uint64_t) len << 3;
80 80
81 if (len >= need) 81 if (len >= need)
82 { 82 {
83 if (have != 0) 83 if (have != 0)
84 { 84 {
85 memcpy(ctx->buffer + have, input, need); 85 memcpy (ctx->buffer + have, input, need);
86 MD5Transform(ctx->state, ctx->buffer); 86 MD5Transform (ctx->state, ctx->buffer);
87 input += need; 87 input += need;
88 len -= need; 88 len -= need;
89 have = 0; 89 have = 0;
@@ -92,7 +92,7 @@ MHD_MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len)
92 /* Process data in MD5_BLOCK_SIZE-byte chunks. */ 92 /* Process data in MD5_BLOCK_SIZE-byte chunks. */
93 while (len >= MD5_BLOCK_SIZE) 93 while (len >= MD5_BLOCK_SIZE)
94 { 94 {
95 MD5Transform(ctx->state, input); 95 MD5Transform (ctx->state, input);
96 input += MD5_BLOCK_SIZE; 96 input += MD5_BLOCK_SIZE;
97 len -= MD5_BLOCK_SIZE; 97 len -= MD5_BLOCK_SIZE;
98 } 98 }
@@ -100,7 +100,7 @@ MHD_MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len)
100 100
101 /* Handle any remaining bytes of data. */ 101 /* Handle any remaining bytes of data. */
102 if (len != 0) 102 if (len != 0)
103 memcpy(ctx->buffer + have, input, len); 103 memcpy (ctx->buffer + have, input, len);
104} 104}
105 105
106/* 106/*
@@ -108,42 +108,42 @@ MHD_MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len)
108 * 1 0* (64-bit count of bits processed, MSB-first) 108 * 1 0* (64-bit count of bits processed, MSB-first)
109 */ 109 */
110void 110void
111MD5Pad(struct MD5Context *ctx) 111MD5Pad (struct MD5Context *ctx)
112{ 112{
113 uint8_t count[8]; 113 uint8_t count[8];
114 size_t padlen; 114 size_t padlen;
115 115
116 if (!ctx) 116 if (! ctx)
117 return; 117 return;
118 118
119 /* Convert count to 8 bytes in little endian order. */ 119 /* Convert count to 8 bytes in little endian order. */
120 PUT_64BIT_LE(count, ctx->count); 120 PUT_64BIT_LE (count, ctx->count);
121 121
122 /* Pad out to 56 mod 64. */ 122 /* Pad out to 56 mod 64. */
123 padlen = MD5_BLOCK_SIZE - 123 padlen = MD5_BLOCK_SIZE
124 ((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1)); 124 - ((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1));
125 if (padlen < 1 + 8) 125 if (padlen < 1 + 8)
126 padlen += MD5_BLOCK_SIZE; 126 padlen += MD5_BLOCK_SIZE;
127 MHD_MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ 127 MHD_MD5Update (ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
128 MHD_MD5Update(ctx, count, 8); 128 MHD_MD5Update (ctx, count, 8);
129} 129}
130 130
131/* 131/*
132 * Final wrapup--call MD5Pad, fill in digest and zero out ctx. 132 * Final wrapup--call MD5Pad, fill in digest and zero out ctx.
133 */ 133 */
134void 134void
135MHD_MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx) 135MHD_MD5Final (unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx)
136{ 136{
137 int i; 137 int i;
138 138
139 if (!ctx || !digest) 139 if (! ctx || ! digest)
140 return; 140 return;
141 141
142 MD5Pad(ctx); 142 MD5Pad (ctx);
143 for (i = 0; i < 4; i++) 143 for (i = 0; i < 4; i++)
144 PUT_32BIT_LE(digest + i * 4, ctx->state[i]); 144 PUT_32BIT_LE (digest + i * 4, ctx->state[i]);
145 145
146 memset(ctx, 0, sizeof(*ctx)); 146 memset (ctx, 0, sizeof(*ctx));
147} 147}
148 148
149 149
@@ -151,13 +151,13 @@ MHD_MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx)
151 151
152/* #define F1(x, y, z) (x & y | ~x & z) */ 152/* #define F1(x, y, z) (x & y | ~x & z) */
153#define F1(x, y, z) (z ^ (x & (y ^ z))) 153#define F1(x, y, z) (z ^ (x & (y ^ z)))
154#define F2(x, y, z) F1(z, x, y) 154#define F2(x, y, z) F1 (z, x, y)
155#define F3(x, y, z) (x ^ y ^ z) 155#define F3(x, y, z) (x ^ y ^ z)
156#define F4(x, y, z) (y ^ (x | ~z)) 156#define F4(x, y, z) (y ^ (x | ~z))
157 157
158/* This is the central step in the MD5 algorithm. */ 158/* This is the central step in the MD5 algorithm. */
159#define MD5STEP(f, w, x, y, z, data, s) \ 159#define MD5STEP(f, w, x, y, z, data, s) \
160 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) 160 (w += f (x, y, z) + data, w = w << s | w >> (32 - s), w += x)
161 161
162/* 162/*
163 * The core of the MD5 algorithm, this alters an existing MD5 hash to 163 * The core of the MD5 algorithm, this alters an existing MD5 hash to
@@ -165,20 +165,20 @@ MHD_MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx)
165 * the data and converts bytes into longwords for this routine. 165 * the data and converts bytes into longwords for this routine.
166 */ 166 */
167void 167void
168MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE]) 168MD5Transform (uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE])
169{ 169{
170 uint32_t a, b, c, d, in[MD5_BLOCK_SIZE / 4]; 170 uint32_t a, b, c, d, in[MD5_BLOCK_SIZE / 4];
171 171
172#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 172#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
173 memcpy(in, block, sizeof(in)); 173 memcpy (in, block, sizeof(in));
174#else 174#else
175 for (a = 0; a < MD5_BLOCK_SIZE / 4; a++) 175 for (a = 0; a < MD5_BLOCK_SIZE / 4; a++)
176 { 176 {
177 in[a] = (uint32_t)( 177 in[a] = (uint32_t) (
178 (uint32_t)(block[a * 4 + 0]) | 178 (uint32_t) (block[a * 4 + 0])
179 (uint32_t)(block[a * 4 + 1]) << 8 | 179 | (uint32_t) (block[a * 4 + 1]) << 8
180 (uint32_t)(block[a * 4 + 2]) << 16 | 180 | (uint32_t) (block[a * 4 + 2]) << 16
181 (uint32_t)(block[a * 4 + 3]) << 24); 181 | (uint32_t) (block[a * 4 + 3]) << 24);
182 } 182 }
183#endif 183#endif
184 184
@@ -187,73 +187,73 @@ MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE])
187 c = state[2]; 187 c = state[2];
188 d = state[3]; 188 d = state[3];
189 189
190 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); 190 MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478, 7);
191 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); 191 MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
192 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); 192 MD5STEP (F1, c, d, a, b, in[2] + 0x242070db, 17);
193 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); 193 MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
194 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); 194 MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
195 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); 195 MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62a, 12);
196 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); 196 MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613, 17);
197 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); 197 MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501, 22);
198 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); 198 MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8, 7);
199 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); 199 MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
200 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); 200 MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
201 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); 201 MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7be, 22);
202 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); 202 MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122, 7);
203 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); 203 MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193, 12);
204 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); 204 MD5STEP (F1, c, d, a, b, in[14] + 0xa679438e, 17);
205 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); 205 MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821, 22);
206 206
207 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); 207 MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562, 5);
208 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); 208 MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340, 9);
209 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); 209 MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51, 14);
210 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); 210 MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
211 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); 211 MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105d, 5);
212 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); 212 MD5STEP (F2, d, a, b, c, in[10] + 0x02441453, 9);
213 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); 213 MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
214 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); 214 MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
215 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); 215 MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
216 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); 216 MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6, 9);
217 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); 217 MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
218 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); 218 MD5STEP (F2, b, c, d, a, in[8] + 0x455a14ed, 20);
219 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); 219 MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
220 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); 220 MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
221 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); 221 MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9, 14);
222 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); 222 MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
223 223
224 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); 224 MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942, 4);
225 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); 225 MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681, 11);
226 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); 226 MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
227 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); 227 MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380c, 23);
228 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); 228 MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44, 4);
229 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); 229 MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
230 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); 230 MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
231 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); 231 MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
232 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); 232 MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
233 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); 233 MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
234 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); 234 MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
235 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); 235 MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05, 23);
236 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); 236 MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
237 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); 237 MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
238 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); 238 MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
239 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); 239 MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
240 240
241 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); 241 MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244, 6);
242 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); 242 MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97, 10);
243 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); 243 MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7, 15);
244 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); 244 MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039, 21);
245 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); 245 MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3, 6);
246 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); 246 MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
247 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); 247 MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47d, 15);
248 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); 248 MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1, 21);
249 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); 249 MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
250 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); 250 MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
251 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); 251 MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314, 15);
252 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); 252 MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
253 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); 253 MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82, 6);
254 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); 254 MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235, 10);
255 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); 255 MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
256 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); 256 MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391, 21);
257 257
258 state[0] += a; 258 state[0] += a;
259 state[1] += b; 259 state[1] += b;
diff --git a/src/lib/md5.h b/src/lib/md5.h
index 7a6f84e6..8e95b29b 100644
--- a/src/lib/md5.h
+++ b/src/lib/md5.h
@@ -20,45 +20,47 @@
20 20
21#include "platform.h" 21#include "platform.h"
22 22
23#define MD5_BLOCK_SIZE 64 23#define MD5_BLOCK_SIZE 64
24#define MD5_DIGEST_SIZE 16 24#define MD5_DIGEST_SIZE 16
25#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1) 25#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1)
26 26
27struct MD5Context 27struct MD5Context
28{ 28{
29 uint32_t state[4]; /* state */ 29 uint32_t state[4]; /* state */
30 uint64_t count; /* number of bits, mod 2^64 */ 30 uint64_t count; /* number of bits, mod 2^64 */
31 uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */ 31 uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */
32}; 32};
33 33
34/* 34/*
35 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious 35 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
36 * initialization constants. 36 * initialization constants.
37 */ 37 */
38void MHD_MD5Init(struct MD5Context *ctx); 38void MHD_MD5Init (struct MD5Context *ctx);
39 39
40/* 40/*
41 * Update context to reflect the concatenation of another buffer full 41 * Update context to reflect the concatenation of another buffer full
42 * of bytes. 42 * of bytes.
43 */ 43 */
44void MHD_MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len); 44void MHD_MD5Update (struct MD5Context *ctx, const unsigned char *input, size_t
45 len);
45 46
46/* 47/*
47 * Pad pad to 64-byte boundary with the bit pattern 48 * Pad pad to 64-byte boundary with the bit pattern
48 * 1 0* (64-bit count of bits processed, MSB-first) 49 * 1 0* (64-bit count of bits processed, MSB-first)
49 */ 50 */
50void MD5Pad(struct MD5Context *ctx); 51void MD5Pad (struct MD5Context *ctx);
51 52
52/* 53/*
53 * Final wrapup--call MD5Pad, fill in digest and zero out ctx. 54 * Final wrapup--call MD5Pad, fill in digest and zero out ctx.
54 */ 55 */
55void MHD_MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx); 56void MHD_MD5Final (unsigned char digest[MD5_DIGEST_SIZE], struct
57 MD5Context *ctx);
56 58
57/* 59/*
58 * The core of the MD5 algorithm, this alters an existing MD5 hash to 60 * The core of the MD5 algorithm, this alters an existing MD5 hash to
59 * reflect the addition of 16 longwords of new data. MHD_MD5Update blocks 61 * reflect the addition of 16 longwords of new data. MHD_MD5Update blocks
60 * the data and converts bytes into longwords for this routine. 62 * the data and converts bytes into longwords for this routine.
61 */ 63 */
62void MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE]); 64void MD5Transform (uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE]);
63 65
64#endif /* !MHD_MD5_H */ 66#endif /* !MHD_MD5_H */
diff --git a/src/lib/memorypool.c b/src/lib/memorypool.c
index 8ef1e2d1..9f7472e1 100644
--- a/src/lib/memorypool.c
+++ b/src/lib/memorypool.c
@@ -25,11 +25,11 @@
25#include "memorypool.h" 25#include "memorypool.h"
26 26
27/* define MAP_ANONYMOUS for Mac OS X */ 27/* define MAP_ANONYMOUS for Mac OS X */
28#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) 28#if defined(MAP_ANON) && ! defined(MAP_ANONYMOUS)
29#define MAP_ANONYMOUS MAP_ANON 29#define MAP_ANONYMOUS MAP_ANON
30#endif 30#endif
31#ifndef MAP_FAILED 31#ifndef MAP_FAILED
32#define MAP_FAILED ((void*)-1) 32#define MAP_FAILED ((void*) -1)
33#endif 33#endif
34 34
35/** 35/**
@@ -40,7 +40,7 @@
40/** 40/**
41 * Round up 'n' to a multiple of ALIGN_SIZE. 41 * Round up 'n' to a multiple of ALIGN_SIZE.
42 */ 42 */
43#define ROUND_TO_ALIGN(n) ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1))) 43#define ROUND_TO_ALIGN(n) ((n + (ALIGN_SIZE - 1)) & (~(ALIGN_SIZE - 1)))
44 44
45 45
46/** 46/**
@@ -110,11 +110,11 @@ MHD_pool_create (size_t max)
110 if (max <= 32 * 1024) 110 if (max <= 32 * 1024)
111 pool->memory = MAP_FAILED; 111 pool->memory = MAP_FAILED;
112 else 112 else
113#if defined(MAP_ANONYMOUS) && !defined(_WIN32) 113#if defined(MAP_ANONYMOUS) && ! defined(_WIN32)
114 pool->memory = mmap (NULL, 114 pool->memory = mmap (NULL,
115 max, 115 max,
116 PROT_READ | PROT_WRITE, 116 PROT_READ | PROT_WRITE,
117 MAP_PRIVATE | MAP_ANONYMOUS, 117 MAP_PRIVATE | MAP_ANONYMOUS,
118 -1, 118 -1,
119 0); 119 0);
120#elif defined(_WIN32) 120#elif defined(_WIN32)
@@ -128,19 +128,19 @@ MHD_pool_create (size_t max)
128#endif 128#endif
129 if ( (MAP_FAILED == pool->memory) || 129 if ( (MAP_FAILED == pool->memory) ||
130 (NULL == pool->memory)) 130 (NULL == pool->memory))
131 {
132 pool->memory = malloc (max);
133 if (NULL == pool->memory)
131 { 134 {
132 pool->memory = malloc (max); 135 free (pool);
133 if (NULL == pool->memory) 136 return NULL;
134 {
135 free (pool);
136 return NULL;
137 }
138 pool->is_mmap = false;
139 } 137 }
138 pool->is_mmap = false;
139 }
140 else 140 else
141 { 141 {
142 pool->is_mmap = true; 142 pool->is_mmap = true;
143 } 143 }
144 pool->pos = 0; 144 pool->pos = 0;
145 pool->end = max; 145 pool->end = max;
146 pool->size = max; 146 pool->size = max;
@@ -161,7 +161,7 @@ MHD_pool_destroy (struct MemoryPool *pool)
161 if (! pool->is_mmap) 161 if (! pool->is_mmap)
162 free (pool->memory); 162 free (pool->memory);
163 else 163 else
164#if defined(MAP_ANONYMOUS) && !defined(_WIN32) 164#if defined(MAP_ANONYMOUS) && ! defined(_WIN32)
165 munmap (pool->memory, 165 munmap (pool->memory,
166 pool->size); 166 pool->size);
167#elif defined(_WIN32) 167#elif defined(_WIN32)
@@ -201,7 +201,7 @@ MHD_pool_get_free (struct MemoryPool *pool)
201 */ 201 */
202void * 202void *
203MHD_pool_allocate (struct MemoryPool *pool, 203MHD_pool_allocate (struct MemoryPool *pool,
204 size_t size, 204 size_t size,
205 int from_end) 205 int from_end)
206{ 206{
207 void *ret; 207 void *ret;
@@ -214,15 +214,15 @@ MHD_pool_allocate (struct MemoryPool *pool,
214 (pool->pos + asize < pool->pos)) 214 (pool->pos + asize < pool->pos))
215 return NULL; 215 return NULL;
216 if (from_end == MHD_YES) 216 if (from_end == MHD_YES)
217 { 217 {
218 ret = &pool->memory[pool->end - asize]; 218 ret = &pool->memory[pool->end - asize];
219 pool->end -= asize; 219 pool->end -= asize;
220 } 220 }
221 else 221 else
222 { 222 {
223 ret = &pool->memory[pool->pos]; 223 ret = &pool->memory[pool->pos];
224 pool->pos += asize; 224 pool->pos += asize;
225 } 225 }
226 return ret; 226 return ret;
227} 227}
228 228
@@ -247,8 +247,8 @@ MHD_pool_allocate (struct MemoryPool *pool,
247void * 247void *
248MHD_pool_reallocate (struct MemoryPool *pool, 248MHD_pool_reallocate (struct MemoryPool *pool,
249 void *old, 249 void *old,
250 size_t old_size, 250 size_t old_size,
251 size_t new_size) 251 size_t new_size)
252{ 252{
253 void *ret; 253 void *ret;
254 size_t asize; 254 size_t asize;
@@ -263,35 +263,35 @@ MHD_pool_reallocate (struct MemoryPool *pool,
263 263
264 if ( (pool->pos >= old_size) && 264 if ( (pool->pos >= old_size) &&
265 (&pool->memory[pool->pos - old_size] == old) ) 265 (&pool->memory[pool->pos - old_size] == old) )
266 {
267 /* was the previous allocation - optimize! */
268 if (pool->pos + asize - old_size <= pool->end)
266 { 269 {
267 /* was the previous allocation - optimize! */ 270 /* fits */
268 if (pool->pos + asize - old_size <= pool->end) 271 pool->pos += asize - old_size;
269 { 272 if (asize < old_size) /* shrinking - zero again! */
270 /* fits */ 273 memset (&pool->memory[pool->pos],
271 pool->pos += asize - old_size; 274 0,
272 if (asize < old_size) /* shrinking - zero again! */ 275 old_size - asize);
273 memset (&pool->memory[pool->pos], 276 return old;
274 0,
275 old_size - asize);
276 return old;
277 }
278 /* does not fit */
279 return NULL;
280 } 277 }
278 /* does not fit */
279 return NULL;
280 }
281 if (asize <= old_size) 281 if (asize <= old_size)
282 return old; /* cannot shrink, no need to move */ 282 return old; /* cannot shrink, no need to move */
283 if ((pool->pos + asize >= pool->pos) && 283 if ((pool->pos + asize >= pool->pos) &&
284 (pool->pos + asize <= pool->end)) 284 (pool->pos + asize <= pool->end))
285 { 285 {
286 /* fits */ 286 /* fits */
287 ret = &pool->memory[pool->pos]; 287 ret = &pool->memory[pool->pos];
288 if (0 != old_size) 288 if (0 != old_size)
289 memmove (ret, 289 memmove (ret,
290 old, 290 old,
291 old_size); 291 old_size);
292 pool->pos += asize; 292 pool->pos += asize;
293 return ret; 293 return ret;
294 } 294 }
295 /* does not fit */ 295 /* does not fit */
296 return NULL; 296 return NULL;
297} 297}
@@ -312,19 +312,19 @@ MHD_pool_reallocate (struct MemoryPool *pool,
312 */ 312 */
313void * 313void *
314MHD_pool_reset (struct MemoryPool *pool, 314MHD_pool_reset (struct MemoryPool *pool,
315 void *keep, 315 void *keep,
316 size_t copy_bytes, 316 size_t copy_bytes,
317 size_t new_size) 317 size_t new_size)
318{ 318{
319 if ( (NULL != keep) && 319 if ( (NULL != keep) &&
320 (keep != pool->memory) ) 320 (keep != pool->memory) )
321 { 321 {
322 if (0 != copy_bytes) 322 if (0 != copy_bytes)
323 memmove (pool->memory, 323 memmove (pool->memory,
324 keep, 324 keep,
325 copy_bytes); 325 copy_bytes);
326 keep = pool->memory; 326 keep = pool->memory;
327 } 327 }
328 pool->end = pool->size; 328 pool->end = pool->size;
329 /* technically not needed, but safer to zero out */ 329 /* technically not needed, but safer to zero out */
330 if (pool->size > copy_bytes) 330 if (pool->size > copy_bytes)
diff --git a/src/lib/memorypool.h b/src/lib/memorypool.h
index 36136af8..774b05ba 100644
--- a/src/lib/memorypool.h
+++ b/src/lib/memorypool.h
@@ -70,7 +70,7 @@ MHD_pool_destroy (struct MemoryPool *pool);
70 */ 70 */
71void * 71void *
72MHD_pool_allocate (struct MemoryPool *pool, 72MHD_pool_allocate (struct MemoryPool *pool,
73 size_t size, 73 size_t size,
74 int from_end); 74 int from_end);
75 75
76 76
@@ -93,9 +93,9 @@ MHD_pool_allocate (struct MemoryPool *pool,
93 */ 93 */
94void * 94void *
95MHD_pool_reallocate (struct MemoryPool *pool, 95MHD_pool_reallocate (struct MemoryPool *pool,
96 void *old, 96 void *old,
97 size_t old_size, 97 size_t old_size,
98 size_t new_size); 98 size_t new_size);
99 99
100 100
101/** 101/**
@@ -123,8 +123,8 @@ MHD_pool_get_free (struct MemoryPool *pool);
123 */ 123 */
124void * 124void *
125MHD_pool_reset (struct MemoryPool *pool, 125MHD_pool_reset (struct MemoryPool *pool,
126 void *keep, 126 void *keep,
127 size_t copy_bytes, 127 size_t copy_bytes,
128 size_t new_size); 128 size_t new_size);
129 129
130#endif 130#endif
diff --git a/src/lib/mhd_assert.h b/src/lib/mhd_assert.h
index c720ce5c..e99632d0 100644
--- a/src/lib/mhd_assert.h
+++ b/src/lib/mhd_assert.h
@@ -28,21 +28,21 @@
28 28
29#include "mhd_options.h" 29#include "mhd_options.h"
30#ifdef NDEBUG 30#ifdef NDEBUG
31# define mhd_assert(ignore) ((void)0) 31# define mhd_assert(ignore) ((void) 0)
32#else /* _DEBUG */ 32#else /* _DEBUG */
33# ifdef HAVE_ASSERT 33# ifdef HAVE_ASSERT
34# include <assert.h> 34# include <assert.h>
35# define mhd_assert(CHK) assert(CHK) 35# define mhd_assert(CHK) assert (CHK)
36# else /* ! HAVE_ASSERT */ 36# else /* ! HAVE_ASSERT */
37# include <stdio.h> 37# include <stdio.h>
38# include <stdlib.h> 38# include <stdlib.h>
39# define mhd_assert(CHK) \ 39# define mhd_assert(CHK) \
40 do { \ 40 do { \
41 if (!(CHK)) { \ 41 if (! (CHK)) { \
42 fprintf(stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \ 42 fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \
43 __FILE__, (unsigned)__LINE__, #CHK); \ 43 __FILE__, (unsigned) __LINE__, #CHK); \
44 fflush(stderr); abort(); } \ 44 fflush (stderr); abort (); } \
45 } while(0) 45 } while (0)
46# endif /* ! HAVE_ASSERT */ 46# endif /* ! HAVE_ASSERT */
47#endif /* _DEBUG */ 47#endif /* _DEBUG */
48 48
diff --git a/src/lib/mhd_byteorder.h b/src/lib/mhd_byteorder.h
index 66689804..230ae803 100644
--- a/src/lib/mhd_byteorder.h
+++ b/src/lib/mhd_byteorder.h
@@ -71,7 +71,8 @@
71#if defined(__BYTE_ORDER__) 71#if defined(__BYTE_ORDER__)
72#if defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 72#if defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
73#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 73#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
74#elif defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 74#elif defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == \
75 __ORDER_LITTLE_ENDIAN__
75#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 76#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
76#elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ 77#elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
77#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN 78#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
@@ -106,36 +107,40 @@
106/* Byte order specification didn't detected in system headers */ 107/* Byte order specification didn't detected in system headers */
107/* Try some guessing */ 108/* Try some guessing */
108 109
109#if (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) || \ 110#if (defined(__BIG_ENDIAN__) && ! defined(__LITTLE_ENDIAN__)) || \
110 (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) 111 (defined(_BIG_ENDIAN) && ! defined(_LITTLE_ENDIAN))
111/* Seems that we are on big endian platform */ 112/* Seems that we are on big endian platform */
112#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 113#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
113#elif (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ 114#elif (defined(__LITTLE_ENDIAN__) && ! defined(__BIG_ENDIAN__)) || \
114 (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) 115 (defined(_LITTLE_ENDIAN) && ! defined(_BIG_ENDIAN))
115/* Seems that we are on little endian platform */ 116/* Seems that we are on little endian platform */
116#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 117#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
117#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \ 118#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
118 defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \ 119 defined(__x86_64) || \
119 defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \ 120 defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \
120 defined(_M_IX86) || defined(_X86_) || defined (__THW_INTEL__) 121 defined(__i386__) || defined(__i486__) || defined(__i586__) || \
122 defined(__i686__) || \
123 defined(_M_IX86) || defined(_X86_) || defined (__THW_INTEL__)
121/* x86 family is little endian */ 124/* x86 family is little endian */
122#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 125#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
123#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ 126#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
124 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) 127 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
125/* Looks like we are on ARM/MIPS in big endian mode */ 128/* Looks like we are on ARM/MIPS in big endian mode */
126#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 129#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
127#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ 130#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
128 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) 131 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
129/* Looks like we are on ARM/MIPS in little endian mode */ 132/* Looks like we are on ARM/MIPS in little endian mode */
130#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 133#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
131#elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || \ 134#elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || \
132 defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \ 135 defined(__hppa) || \
133 defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__) 136 defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \
137 defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
134/* Looks like we are on big endian platform */ 138/* Looks like we are on big endian platform */
135#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 139#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
136#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || \ 140#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
137 defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \ 141 defined(__ia64) || \
138 defined(__BFIN__) || defined(bfin) || defined(BFIN) 142 defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \
143 defined(__BFIN__) || defined(bfin) || defined(BFIN)
139/* Looks like we are on little endian platform */ 144/* Looks like we are on little endian platform */
140#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 145#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
141#elif defined(_WIN32) 146#elif defined(_WIN32)
@@ -151,9 +156,11 @@
151#ifdef _MHD_BYTE_ORDER 156#ifdef _MHD_BYTE_ORDER
152/* Some safety checks */ 157/* Some safety checks */
153#if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN 158#if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN
154#error Configure detected big endian byte order but headers specify different byte order 159#error \
155#elif !defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 160 Configure detected big endian byte order but headers specify different byte order
156#error Configure did not detect big endian byte order but headers specify big endian byte order 161#elif ! defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
162#error \
163 Configure did not detect big endian byte order but headers specify big endian byte order
157#endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */ 164#endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */
158#endif /* _MHD_BYTE_ORDER */ 165#endif /* _MHD_BYTE_ORDER */
159 166
diff --git a/src/lib/mhd_compat.c b/src/lib/mhd_compat.c
index 3abdc367..6f6c6f9c 100644
--- a/src/lib/mhd_compat.c
+++ b/src/lib/mhd_compat.c
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "mhd_compat.h" 27#include "mhd_compat.h"
28#if defined(_WIN32) && !defined(__CYGWIN__) 28#if defined(_WIN32) && ! defined(__CYGWIN__)
29#include <stdint.h> 29#include <stdint.h>
30#include <time.h> 30#include <time.h>
31#ifndef HAVE_SNPRINTF 31#ifndef HAVE_SNPRINTF
@@ -38,7 +38,7 @@
38#include <string.h> /* for memset() */ 38#include <string.h> /* for memset() */
39#endif /* ! HAVE_CALLOC */ 39#endif /* ! HAVE_CALLOC */
40 40
41#if defined(_WIN32) && !defined(__CYGWIN__) 41#if defined(_WIN32) && ! defined(__CYGWIN__)
42 42
43#ifndef HAVE_SNPRINTF 43#ifndef HAVE_SNPRINTF
44/* Emulate snprintf function on W32 */ 44/* Emulate snprintf function on W32 */
@@ -61,16 +61,16 @@ W32_snprintf (char *__restrict s,
61 format, 61 format,
62 args); 62 args);
63 va_end (args); 63 va_end (args);
64 if ((int)n == ret) 64 if ((int) n == ret)
65 s[n - 1] = 0; 65 s[n - 1] = 0;
66 if (ret >= 0) 66 if (ret >= 0)
67 return ret; 67 return ret;
68 } 68 }
69 va_start(args, 69 va_start (args,
70 format); 70 format);
71 ret = _vscprintf (format, 71 ret = _vscprintf (format,
72 args); 72 args);
73 va_end(args); 73 va_end (args);
74 if ( (0 <= ret) && 74 if ( (0 <= ret) &&
75 (0 != n) && 75 (0 != n) &&
76 (NULL == s) ) 76 (NULL == s) )
@@ -85,30 +85,30 @@ W32_snprintf (char *__restrict s,
85#ifndef HAVE_CALLOC 85#ifndef HAVE_CALLOC
86 86
87#ifdef __has_builtin 87#ifdef __has_builtin
88# if __has_builtin(__builtin_mul_overflow) 88# if __has_builtin (__builtin_mul_overflow)
89# define MHD_HAVE_NUL_OVERFLOW 1 89# define MHD_HAVE_NUL_OVERFLOW 1
90# endif 90# endif
91#elif __GNUC__+0 >= 5 91#elif __GNUC__ + 0 >= 5
92# define MHD_HAVE_NUL_OVERFLOW 1 92# define MHD_HAVE_NUL_OVERFLOW 1
93#endif /* __GNUC__ >= 5 */ 93#endif /* __GNUC__ >= 5 */
94 94
95 95
96void *MHD_calloc_(size_t nelem, size_t elsize) 96void *MHD_calloc_ (size_t nelem, size_t elsize)
97{ 97{
98 size_t alloc_size; 98 size_t alloc_size;
99 void *ptr; 99 void *ptr;
100#ifdef MHD_HAVE_NUL_OVERFLOW 100#ifdef MHD_HAVE_NUL_OVERFLOW
101 if (__builtin_mul_overflow(nelem, elsize, &alloc_size) || 0 == alloc_size) 101 if (__builtin_mul_overflow (nelem, elsize, &alloc_size) ||(0 == alloc_size))
102 return NULL; 102 return NULL;
103#else /* ! MHD_HAVE_NUL_OVERFLOW */ 103#else /* ! MHD_HAVE_NUL_OVERFLOW */
104 alloc_size = nelem * elsize; 104 alloc_size = nelem * elsize;
105 if (0 == alloc_size || elsize != alloc_size / nelem) 105 if ((0 == alloc_size)||(elsize != alloc_size / nelem))
106 return NULL; 106 return NULL;
107#endif /* ! MHD_HAVE_NUL_OVERFLOW */ 107#endif /* ! MHD_HAVE_NUL_OVERFLOW */
108 ptr = malloc (alloc_size); 108 ptr = malloc (alloc_size);
109 if (NULL == ptr) 109 if (NULL == ptr)
110 return NULL; 110 return NULL;
111 memset(ptr, 0, alloc_size); 111 memset (ptr, 0, alloc_size);
112 return ptr; 112 return ptr;
113} 113}
114#endif /* ! HAVE_CALLOC */ 114#endif /* ! HAVE_CALLOC */
diff --git a/src/lib/mhd_compat.h b/src/lib/mhd_compat.h
index b4e2c66c..6b38a03e 100644
--- a/src/lib/mhd_compat.h
+++ b/src/lib/mhd_compat.h
@@ -40,8 +40,8 @@
40#include <string.h> 40#include <string.h>
41#endif /* HAVE_STRING_H */ 41#endif /* HAVE_STRING_H */
42 42
43 /* MHD_strerror_ is strerror */ 43/* MHD_strerror_ is strerror */
44#define MHD_strerror_(errnum) strerror((errnum)) 44#define MHD_strerror_(errnum) strerror ((errnum))
45 45
46/* Platform-independent snprintf name */ 46/* Platform-independent snprintf name */
47#if defined(HAVE_SNPRINTF) 47#if defined(HAVE_SNPRINTF)
@@ -49,10 +49,12 @@
49#else /* ! HAVE_SNPRINTF */ 49#else /* ! HAVE_SNPRINTF */
50#if defined(_WIN32) && ! defined(__CYGWIN__) 50#if defined(_WIN32) && ! defined(__CYGWIN__)
51/* Emulate snprintf function on W32 */ 51/* Emulate snprintf function on W32 */
52int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...); 52int W32_snprintf (char *__restrict s, size_t n, const char *__restrict format,
53 ...);
53#define MHD_snprintf_ W32_snprintf 54#define MHD_snprintf_ W32_snprintf
54#else /* ! _WIN32 || __CYGWIN__ */ 55#else /* ! _WIN32 || __CYGWIN__ */
55#error Your platform does not support snprintf() and MHD does not know how to emulate it on your platform. 56#error \
57 Your platform does not support snprintf() and MHD does not know how to emulate it on your platform.
56#endif /* ! _WIN32 || __CYGWIN__ */ 58#endif /* ! _WIN32 || __CYGWIN__ */
57#endif /* ! HAVE_SNPRINTF */ 59#endif /* ! HAVE_SNPRINTF */
58 60
@@ -61,14 +63,14 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ..
61 * Generate pseudo random number at least 30-bit wide. 63 * Generate pseudo random number at least 30-bit wide.
62 * @return pseudo random number at least 30-bit wide. 64 * @return pseudo random number at least 30-bit wide.
63 */ 65 */
64#define MHD_random_() random() 66#define MHD_random_() random ()
65#else /* HAVE_RANDOM */ 67#else /* HAVE_RANDOM */
66#ifdef HAVE_RAND 68#ifdef HAVE_RAND
67/** 69/**
68 * Generate pseudo random number at least 30-bit wide. 70 * Generate pseudo random number at least 30-bit wide.
69 * @return pseudo random number at least 30-bit wide. 71 * @return pseudo random number at least 30-bit wide.
70 */ 72 */
71#define MHD_random_() ( (((long)rand()) << 15) + (long)rand() ) 73#define MHD_random_() ( (((long) rand ()) << 15) + (long) rand () )
72#endif /* HAVE_RAND */ 74#endif /* HAVE_RAND */
73#endif /* HAVE_RANDOM */ 75#endif /* HAVE_RANDOM */
74 76
@@ -76,12 +78,12 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ..
76/** 78/**
77 * MHD_calloc_ is platform-independent calloc() 79 * MHD_calloc_ is platform-independent calloc()
78 */ 80 */
79#define MHD_calloc_(n,s) calloc((n),(s)) 81#define MHD_calloc_(n,s) calloc ((n),(s))
80#else /* ! HAVE_CALLOC */ 82#else /* ! HAVE_CALLOC */
81/** 83/**
82 * MHD_calloc_ is platform-independent calloc() 84 * MHD_calloc_ is platform-independent calloc()
83 */ 85 */
84void *MHD_calloc_(size_t nelem, size_t elsize); 86void *MHD_calloc_ (size_t nelem, size_t elsize);
85#endif /* ! HAVE_CALLOC */ 87#endif /* ! HAVE_CALLOC */
86 88
87#endif /* MHD_COMPAT_H */ 89#endif /* MHD_COMPAT_H */
diff --git a/src/lib/mhd_itc.c b/src/lib/mhd_itc.c
index 8aeee576..6c81ef62 100644
--- a/src/lib/mhd_itc.c
+++ b/src/lib/mhd_itc.c
@@ -34,7 +34,7 @@
34 34
35 35
36#if defined(_MHD_ITC_PIPE) 36#if defined(_MHD_ITC_PIPE)
37#if !defined(_WIN32) || defined(__CYGWIN__) 37#if ! defined(_WIN32) || defined(__CYGWIN__)
38 38
39#ifndef HAVE_PIPE2_FUNC 39#ifndef HAVE_PIPE2_FUNC
40/** 40/**
@@ -48,7 +48,7 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc)
48{ 48{
49 unsigned int i; 49 unsigned int i;
50 50
51 for (i=0;i<2;i++) 51 for (i = 0; i<2; i++)
52 { 52 {
53 int flags; 53 int flags;
54 54
@@ -63,7 +63,7 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc)
63 flags | O_NONBLOCK)) ) 63 flags | O_NONBLOCK)) )
64 return 0; 64 return 0;
65 } 65 }
66 return !0; 66 return ! 0;
67} 67}
68#endif /* ! HAVE_PIPE2_FUNC */ 68#endif /* ! HAVE_PIPE2_FUNC */
69#endif /* !_WIN32 || __CYGWIN__ */ 69#endif /* !_WIN32 || __CYGWIN__ */
diff --git a/src/lib/mhd_itc.h b/src/lib/mhd_itc.h
index 01331f13..8e303ef9 100644
--- a/src/lib/mhd_itc.h
+++ b/src/lib/mhd_itc.h
@@ -41,8 +41,9 @@
41# include <stdlib.h> 41# include <stdlib.h>
42/* Simple implementation of MHD_PANIC, to be used outside lib */ 42/* Simple implementation of MHD_PANIC, to be used outside lib */
43# define MHD_PANIC(msg) do { fprintf (stderr, \ 43# define MHD_PANIC(msg) do { fprintf (stderr, \
44 "Abnormal termination at %d line in file %s: %s\n", \ 44 "Abnormal termination at %d line in file %s: %s\n", \
45 (int)__LINE__, __FILE__, msg); abort();} while(0) 45 (int) __LINE__, __FILE__, msg); abort (); \
46} while (0)
46#endif /* ! MHD_PANIC */ 47#endif /* ! MHD_PANIC */
47 48
48#if defined(_MHD_ITC_EVENTFD) 49#if defined(_MHD_ITC_EVENTFD)
@@ -63,12 +64,13 @@
63 * @param itc the itc to initialise 64 * @param itc the itc to initialise
64 * @return non-zero if succeeded, zero otherwise 65 * @return non-zero if succeeded, zero otherwise
65 */ 66 */
66#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) 67#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC \
68 | EFD_NONBLOCK)))
67 69
68/** 70/**
69 * Get description string of last errno for itc operations. 71 * Get description string of last errno for itc operations.
70 */ 72 */
71#define MHD_itc_last_strerror_() strerror(errno) 73#define MHD_itc_last_strerror_() strerror (errno)
72 74
73/** 75/**
74 * Internal static const helper for MHD_itc_activate_() 76 * Internal static const helper for MHD_itc_activate_()
@@ -82,7 +84,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
82 * @return non-zero if succeeded, zero otherwise 84 * @return non-zero if succeeded, zero otherwise
83 */ 85 */
84#define MHD_itc_activate_(itc, str) \ 86#define MHD_itc_activate_(itc, str) \
85 ((write((itc).fd, (const void*)&_MHD_itc_wr_data, 8) > 0) || (EAGAIN == errno)) 87 ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, 8) > 0) || (EAGAIN == \
88 errno))
86 89
87/** 90/**
88 * Return read FD of @a itc which can be used for poll(), select() etc. 91 * Return read FD of @a itc which can be used for poll(), select() etc.
@@ -104,8 +107,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
104 */ 107 */
105#define MHD_itc_clear_(itc) \ 108#define MHD_itc_clear_(itc) \
106 do { uint64_t __b; int __r; \ 109 do { uint64_t __b; int __r; \
107 __r = read((itc).fd, &__b, sizeof(__b)); \ 110 __r = read ((itc).fd, &__b, sizeof(__b)); \
108 (void)__r; } while(0) 111 (void) __r; } while (0)
109 112
110/** 113/**
111 * Destroy previously initialised ITC. Note that close() 114 * Destroy previously initialised ITC. Note that close()
@@ -155,20 +158,20 @@ static const uint64_t _MHD_itc_wr_data = 1;
155 * @return non-zero if succeeded, zero otherwise 158 * @return non-zero if succeeded, zero otherwise
156 */ 159 */
157#ifdef HAVE_PIPE2_FUNC 160#ifdef HAVE_PIPE2_FUNC
158# define MHD_itc_init_(itc) (!pipe2((itc).fd, O_CLOEXEC | O_NONBLOCK)) 161# define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK))
159#else /* ! HAVE_PIPE2_FUNC */ 162#else /* ! HAVE_PIPE2_FUNC */
160# define MHD_itc_init_(itc) \ 163# define MHD_itc_init_(itc) \
161 ( (!pipe((itc).fd)) ? \ 164 ( (! pipe ((itc).fd)) ? \
162 (MHD_itc_nonblocking_((itc)) ? \ 165 (MHD_itc_nonblocking_ ((itc)) ? \
163 (!0) : \ 166 (! 0) : \
164 (MHD_itc_destroy_((itc)), 0) ) \ 167 (MHD_itc_destroy_ ((itc)), 0) ) \
165 : (0) ) 168 : (0) )
166#endif /* ! HAVE_PIPE2_FUNC */ 169#endif /* ! HAVE_PIPE2_FUNC */
167 170
168/** 171/**
169 * Get description string of last errno for itc operations. 172 * Get description string of last errno for itc operations.
170 */ 173 */
171#define MHD_itc_last_strerror_() strerror(errno) 174#define MHD_itc_last_strerror_() strerror (errno)
172 175
173/** 176/**
174 * Activate signal on @a itc 177 * Activate signal on @a itc
@@ -177,7 +180,7 @@ static const uint64_t _MHD_itc_wr_data = 1;
177 * @return non-zero if succeeded, zero otherwise 180 * @return non-zero if succeeded, zero otherwise
178 */ 181 */
179#define MHD_itc_activate_(itc, str) \ 182#define MHD_itc_activate_(itc, str) \
180 ((write((itc).fd[1], (const void*)(str), 1) > 0) || (EAGAIN == errno)) 183 ((write ((itc).fd[1], (const void*) (str), 1) > 0) || (EAGAIN == errno))
181 184
182 185
183/** 186/**
@@ -200,8 +203,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
200 */ 203 */
201#define MHD_itc_clear_(itc) do \ 204#define MHD_itc_clear_(itc) do \
202 { long __b; \ 205 { long __b; \
203 while(0 < read((itc).fd[0], &__b, sizeof(__b))) \ 206 while (0 < read ((itc).fd[0], &__b, sizeof(__b))) \
204 {} } while(0) 207 {} } while (0)
205 208
206/** 209/**
207 * Destroy previously initialised ITC 210 * Destroy previously initialised ITC
@@ -210,8 +213,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
210 */ 213 */
211#define MHD_itc_destroy_(itc) \ 214#define MHD_itc_destroy_(itc) \
212 ( (0 == close ((itc).fd[0])) ? \ 215 ( (0 == close ((itc).fd[0])) ? \
213 (0 == close ((itc).fd[1])) : \ 216 (0 == close ((itc).fd[1])) : \
214 ((close ((itc).fd[1])), 0) ) 217 ((close ((itc).fd[1])), 0) )
215 218
216/** 219/**
217 * Check whether ITC has valid value. 220 * Check whether ITC has valid value.
@@ -231,14 +234,14 @@ static const uint64_t _MHD_itc_wr_data = 1;
231#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1) 234#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1)
232 235
233#ifndef HAVE_PIPE2_FUNC 236#ifndef HAVE_PIPE2_FUNC
234 /** 237/**
235 * Change itc FD options to be non-blocking. 238 * Change itc FD options to be non-blocking.
236 * 239 *
237 * @param fd the FD to manipulate 240 * @param fd the FD to manipulate
238 * @return non-zero if succeeded, zero otherwise 241 * @return non-zero if succeeded, zero otherwise
239 */ 242 */
240 int 243int
241 MHD_itc_nonblocking_ (struct MHD_itc_ itc); 244MHD_itc_nonblocking_ (struct MHD_itc_ itc);
242#endif /* ! HAVE_PIPE2_FUNC */ 245#endif /* ! HAVE_PIPE2_FUNC */
243 246
244 247
@@ -255,20 +258,20 @@ static const uint64_t _MHD_itc_wr_data = 1;
255 * @return non-zero if succeeded, zero otherwise 258 * @return non-zero if succeeded, zero otherwise
256 */ 259 */
257#ifdef MHD_socket_pair_nblk_ 260#ifdef MHD_socket_pair_nblk_
258# define MHD_itc_init_(itc) MHD_socket_pair_nblk_((itc).sk) 261# define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk)
259#else /* ! MHD_socket_pair_nblk_ */ 262#else /* ! MHD_socket_pair_nblk_ */
260# define MHD_itc_init_(itc) \ 263# define MHD_itc_init_(itc) \
261 (MHD_socket_pair_((itc).sk) ? \ 264 (MHD_socket_pair_ ((itc).sk) ? \
262 (MHD_itc_nonblocking_((itc)) ? \ 265 (MHD_itc_nonblocking_ ((itc)) ? \
263 (!0) : \ 266 (! 0) : \
264 (MHD_itc_destroy_((itc)), 0) ) \ 267 (MHD_itc_destroy_ ((itc)), 0) ) \
265 : (0)) 268 : (0))
266#endif /* ! MHD_socket_pair_nblk_ */ 269#endif /* ! MHD_socket_pair_nblk_ */
267 270
268/** 271/**
269 * Get description string of last error for itc operations. 272 * Get description string of last error for itc operations.
270 */ 273 */
271#define MHD_itc_last_strerror_() MHD_socket_last_strerr_() 274#define MHD_itc_last_strerror_() MHD_socket_last_strerr_ ()
272 275
273/** 276/**
274 * Activate signal on @a itc 277 * Activate signal on @a itc
@@ -277,8 +280,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
277 * @return non-zero if succeeded, zero otherwise 280 * @return non-zero if succeeded, zero otherwise
278 */ 281 */
279#define MHD_itc_activate_(itc, str) \ 282#define MHD_itc_activate_(itc, str) \
280 ((MHD_send_((itc).sk[1], (str), 1) > 0) || \ 283 ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \
281 (MHD_SCKT_ERR_IS_EAGAIN_(MHD_socket_get_error_()))) 284 (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())))
282 285
283/** 286/**
284 * Return read FD of @a itc which can be used for poll(), select() etc. 287 * Return read FD of @a itc which can be used for poll(), select() etc.
@@ -300,10 +303,10 @@ static const uint64_t _MHD_itc_wr_data = 1;
300 */ 303 */
301#define MHD_itc_clear_(itc) do \ 304#define MHD_itc_clear_(itc) do \
302 { long __b; \ 305 { long __b; \
303 while(0 < recv((itc).sk[0], \ 306 while (0 < recv ((itc).sk[0], \
304 (char*)&__b, \ 307 (char*) &__b, \
305 sizeof(__b), 0)) \ 308 sizeof(__b), 0)) \
306 {} } while(0) 309 {} } while (0)
307 310
308/** 311/**
309 * Destroy previously initialised ITC 312 * Destroy previously initialised ITC
@@ -311,9 +314,9 @@ static const uint64_t _MHD_itc_wr_data = 1;
311 * @return non-zero if succeeded, zero otherwise 314 * @return non-zero if succeeded, zero otherwise
312 */ 315 */
313#define MHD_itc_destroy_(itc) \ 316#define MHD_itc_destroy_(itc) \
314 ( MHD_socket_close_((itc).sk[0]) ? \ 317 (MHD_socket_close_ ((itc).sk[0]) ? \
315 MHD_socket_close_((itc).sk[1]) : \ 318 MHD_socket_close_ ((itc).sk[1]) : \
316 ((void)MHD_socket_close_((itc).sk[1]), 0) ) 319 ((void) MHD_socket_close_ ((itc).sk[1]), 0) )
317 320
318 321
319/** 322/**
@@ -331,10 +334,12 @@ static const uint64_t _MHD_itc_wr_data = 1;
331 * Set @a itc to invalid value. 334 * Set @a itc to invalid value.
332 * @param itc the itc to set 335 * @param itc the itc to set
333 */ 336 */
334#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = MHD_INVALID_SOCKET) 337#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = \
338 MHD_INVALID_SOCKET)
335 339
336#ifndef MHD_socket_pair_nblk_ 340#ifndef MHD_socket_pair_nblk_
337# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip).sk[0]) && MHD_socket_nonblocking_((pip).sk[1])) 341# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_ ((pip).sk[0]) && \
342 MHD_socket_nonblocking_ ((pip).sk[1]))
338#endif /* ! MHD_socket_pair_nblk_ */ 343#endif /* ! MHD_socket_pair_nblk_ */
339 344
340#endif /* _MHD_ITC_SOCKETPAIR */ 345#endif /* _MHD_ITC_SOCKETPAIR */
@@ -345,9 +350,9 @@ static const uint64_t _MHD_itc_wr_data = 1;
345 * @param itc the itc to destroy 350 * @param itc the itc to destroy
346 */ 351 */
347#define MHD_itc_destroy_chk_(itc) do { \ 352#define MHD_itc_destroy_chk_(itc) do { \
348 if (!MHD_itc_destroy_(itc)) \ 353 if (! MHD_itc_destroy_ (itc)) \
349 MHD_PANIC(_("Failed to destroy ITC.\n")); \ 354 MHD_PANIC (_ ("Failed to destroy ITC.\n")); \
350 } while(0) 355} while (0)
351 356
352/** 357/**
353 * Check whether ITC has invalid value. 358 * Check whether ITC has invalid value.
@@ -358,6 +363,6 @@ static const uint64_t _MHD_itc_wr_data = 1;
358 * @return boolean true if @a itc has invalid value, 363 * @return boolean true if @a itc has invalid value,
359 * boolean false otherwise. 364 * boolean false otherwise.
360 */ 365 */
361#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_(itc)) 366#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_ (itc))
362 367
363#endif /* MHD_ITC_H */ 368#endif /* MHD_ITC_H */
diff --git a/src/lib/mhd_itc_types.h b/src/lib/mhd_itc_types.h
index 04966d36..36d4218b 100644
--- a/src/lib/mhd_itc_types.h
+++ b/src/lib/mhd_itc_types.h
@@ -32,7 +32,7 @@
32#include "mhd_options.h" 32#include "mhd_options.h"
33 33
34/* Force socketpair on native W32 */ 34/* Force socketpair on native W32 */
35#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR) 35#if defined(_WIN32) && ! defined(__CYGWIN__) && ! defined(_MHD_ITC_SOCKETPAIR)
36#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform 36#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
37#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */ 37#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
38 38
diff --git a/src/lib/mhd_limits.h b/src/lib/mhd_limits.h
index 41d33a8f..87b41447 100644
--- a/src/lib/mhd_limits.h
+++ b/src/lib/mhd_limits.h
@@ -32,17 +32,17 @@
32#include <limits.h> 32#include <limits.h>
33#endif /* HAVE_LIMITS_H */ 33#endif /* HAVE_LIMITS_H */
34 34
35#define MHD_UNSIGNED_TYPE_MAX_(type) ((type)-1) 35#define MHD_UNSIGNED_TYPE_MAX_(type) ((type) - 1)
36/* Assume 8 bits per byte, no padding bits. */ 36/* Assume 8 bits per byte, no padding bits. */
37#define MHD_SIGNED_TYPE_MAX_(type) \ 37#define MHD_SIGNED_TYPE_MAX_(type) \
38 ( (type)((( ((type)1) << (sizeof(type)*8 - 2)) - 1)*2 + 1) ) 38 ( (type) ((( ((type) 1) << (sizeof(type) * 8 - 2)) - 1) * 2 + 1) )
39#define MHD_TYPE_IS_SIGNED_(type) (((type)0)>((type)-1)) 39#define MHD_TYPE_IS_SIGNED_(type) (((type) 0)>((type) - 1))
40 40
41#ifndef UINT_MAX 41#ifndef UINT_MAX
42#ifdef __UINT_MAX__ 42#ifdef __UINT_MAX__
43#define UINT_MAX __UINT_MAX__ 43#define UINT_MAX __UINT_MAX__
44#else /* ! __UINT_MAX__ */ 44#else /* ! __UINT_MAX__ */
45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_(unsigned int) 45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_ (unsigned int)
46#endif /* ! __UINT_MAX__ */ 46#endif /* ! __UINT_MAX__ */
47#endif /* !UINT_MAX */ 47#endif /* !UINT_MAX */
48 48
@@ -50,19 +50,19 @@
50#ifdef __LONG_MAX__ 50#ifdef __LONG_MAX__
51#define LONG_MAX __LONG_MAX__ 51#define LONG_MAX __LONG_MAX__
52#else /* ! __LONG_MAX__ */ 52#else /* ! __LONG_MAX__ */
53#define LONG_MAX MHD_SIGNED_TYPE_MAX(long) 53#define LONG_MAX MHD_SIGNED_TYPE_MAX (long)
54#endif /* ! __LONG_MAX__ */ 54#endif /* ! __LONG_MAX__ */
55#endif /* !OFF_T_MAX */ 55#endif /* !OFF_T_MAX */
56 56
57#ifndef ULLONG_MAX 57#ifndef ULLONG_MAX
58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_(MHD_UNSIGNED_LONG_LONG) 58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_ (MHD_UNSIGNED_LONG_LONG)
59#endif /* !ULLONG_MAX */ 59#endif /* !ULLONG_MAX */
60 60
61#ifndef INT32_MAX 61#ifndef INT32_MAX
62#ifdef __INT32_MAX__ 62#ifdef __INT32_MAX__
63#define INT32_MAX __INT32_MAX__ 63#define INT32_MAX __INT32_MAX__
64#else /* ! __INT32_MAX__ */ 64#else /* ! __INT32_MAX__ */
65#define INT32_MAX ((int32_t)0x7FFFFFFF) 65#define INT32_MAX ((int32_t) 0x7FFFFFFF)
66#endif /* ! __INT32_MAX__ */ 66#endif /* ! __INT32_MAX__ */
67#endif /* !INT32_MAX */ 67#endif /* !INT32_MAX */
68 68
@@ -70,7 +70,7 @@
70#ifdef __UINT32_MAX__ 70#ifdef __UINT32_MAX__
71#define UINT32_MAX __UINT32_MAX__ 71#define UINT32_MAX __UINT32_MAX__
72#else /* ! __UINT32_MAX__ */ 72#else /* ! __UINT32_MAX__ */
73#define UINT32_MAX ((int32_t)0xFFFFFFFF) 73#define UINT32_MAX ((int32_t) 0xFFFFFFFF)
74#endif /* ! __UINT32_MAX__ */ 74#endif /* ! __UINT32_MAX__ */
75#endif /* !UINT32_MAX */ 75#endif /* !UINT32_MAX */
76 76
@@ -78,7 +78,7 @@
78#ifdef __UINT64_MAX__ 78#ifdef __UINT64_MAX__
79#define UINT64_MAX __UINT64_MAX__ 79#define UINT64_MAX __UINT64_MAX__
80#else /* ! __UINT64_MAX__ */ 80#else /* ! __UINT64_MAX__ */
81#define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFF) 81#define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFF)
82#endif /* ! __UINT64_MAX__ */ 82#endif /* ! __UINT64_MAX__ */
83#endif /* !UINT64_MAX */ 83#endif /* !UINT64_MAX */
84 84
@@ -86,7 +86,7 @@
86#ifdef __INT64_MAX__ 86#ifdef __INT64_MAX__
87#define INT64_MAX __INT64_MAX__ 87#define INT64_MAX __INT64_MAX__
88#else /* ! __INT64_MAX__ */ 88#else /* ! __INT64_MAX__ */
89#define INT64_MAX ((int64_t)0x7FFFFFFFFFFFFFFF) 89#define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
90#endif /* ! __UINT64_MAX__ */ 90#endif /* ! __UINT64_MAX__ */
91#endif /* !INT64_MAX */ 91#endif /* !INT64_MAX */
92 92
@@ -96,8 +96,8 @@
96#elif defined(UINTPTR_MAX) 96#elif defined(UINTPTR_MAX)
97#define SIZE_MAX UINTPTR_MAX 97#define SIZE_MAX UINTPTR_MAX
98#else /* ! __SIZE_MAX__ */ 98#else /* ! __SIZE_MAX__ */
99#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_(size_t) 99#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_ (size_t)
100#endif /* ! __SIZE_MAX__ */ 100#endif /* ! __SIZE_MAX__ */
101#endif /* !SIZE_MAX */ 101#endif /* !SIZE_MAX */
102 102
103#ifndef SSIZE_MAX 103#ifndef SSIZE_MAX
@@ -108,7 +108,7 @@
108#elif defined(INTPTR_MAX) 108#elif defined(INTPTR_MAX)
109#define SSIZE_MAX INTPTR_MAX 109#define SSIZE_MAX INTPTR_MAX
110#else 110#else
111#define SSIZE_MAN MHD_SIGNED_TYPE_MAX_(ssize_t) 111#define SSIZE_MAN MHD_SIGNED_TYPE_MAX_ (ssize_t)
112#endif 112#endif
113#endif /* ! SSIZE_MAX */ 113#endif /* ! SSIZE_MAX */
114 114
@@ -120,19 +120,19 @@
120#elif defined(__APPLE__) && defined(__MACH__) 120#elif defined(__APPLE__) && defined(__MACH__)
121#define OFF_T_MAX INT64_MAX 121#define OFF_T_MAX INT64_MAX
122#else 122#else
123#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_(off_t) 123#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_ (off_t)
124#endif 124#endif
125#endif /* !OFF_T_MAX */ 125#endif /* !OFF_T_MAX */
126 126
127#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX) 127#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
128#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_(uint64_t) 128#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_ (uint64_t)
129#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */ 129#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
130 130
131#ifndef TIME_T_MAX 131#ifndef TIME_T_MAX
132#define TIME_T_MAX ((time_t) \ 132#define TIME_T_MAX ((time_t) \
133 ( MHD_TYPE_IS_SIGNED_(time_t) ? \ 133 (MHD_TYPE_IS_SIGNED_ (time_t) ? \
134 MHD_SIGNED_TYPE_MAX_(time_t) : \ 134 MHD_SIGNED_TYPE_MAX_ (time_t) : \
135 MHD_UNSIGNED_TYPE_MAX_(time_t))) 135 MHD_UNSIGNED_TYPE_MAX_ (time_t)))
136#endif /* !TIME_T_MAX */ 136#endif /* !TIME_T_MAX */
137 137
138#ifndef TIMEVAL_TV_SEC_MAX 138#ifndef TIMEVAL_TV_SEC_MAX
diff --git a/src/lib/mhd_locks.h b/src/lib/mhd_locks.h
index 21db56c4..8c9b0844 100644
--- a/src/lib/mhd_locks.h
+++ b/src/lib/mhd_locks.h
@@ -59,14 +59,15 @@
59# include <stdlib.h> 59# include <stdlib.h>
60/* Simple implementation of MHD_PANIC, to be used outside lib */ 60/* Simple implementation of MHD_PANIC, to be used outside lib */
61# define MHD_PANIC(msg) do { fprintf (stderr, \ 61# define MHD_PANIC(msg) do { fprintf (stderr, \
62 "Abnormal termination at %d line in file %s: %s\n", \ 62 "Abnormal termination at %d line in file %s: %s\n", \
63 (int)__LINE__, __FILE__, msg); abort();} while(0) 63 (int) __LINE__, __FILE__, msg); abort (); \
64} while (0)
64#endif /* ! MHD_PANIC */ 65#endif /* ! MHD_PANIC */
65 66
66#if defined(MHD_PTHREAD_MUTEX_) 67#if defined(MHD_PTHREAD_MUTEX_)
67 typedef pthread_mutex_t MHD_mutex_; 68typedef pthread_mutex_t MHD_mutex_;
68#elif defined(MHD_W32_MUTEX_) 69#elif defined(MHD_W32_MUTEX_)
69 typedef CRITICAL_SECTION MHD_mutex_; 70typedef CRITICAL_SECTION MHD_mutex_;
70#endif 71#endif
71 72
72#if defined(MHD_PTHREAD_MUTEX_) 73#if defined(MHD_PTHREAD_MUTEX_)
@@ -75,14 +76,15 @@
75 * @param pmutex pointer to the mutex 76 * @param pmutex pointer to the mutex
76 * @return nonzero on success, zero otherwise 77 * @return nonzero on success, zero otherwise
77 */ 78 */
78#define MHD_mutex_init_(pmutex) (!(pthread_mutex_init((pmutex), NULL))) 79#define MHD_mutex_init_(pmutex) (! (pthread_mutex_init ((pmutex), NULL)))
79#elif defined(MHD_W32_MUTEX_) 80#elif defined(MHD_W32_MUTEX_)
80/** 81/**
81 * Initialise new mutex. 82 * Initialise new mutex.
82 * @param pmutex pointer to mutex 83 * @param pmutex pointer to mutex
83 * @return nonzero on success, zero otherwise 84 * @return nonzero on success, zero otherwise
84 */ 85 */
85#define MHD_mutex_init_(pmutex) (InitializeCriticalSectionAndSpinCount((pmutex),16)) 86#define MHD_mutex_init_(pmutex) (InitializeCriticalSectionAndSpinCount ( \
87 (pmutex),16))
86#endif 88#endif
87 89
88#if defined(MHD_PTHREAD_MUTEX_) 90#if defined(MHD_PTHREAD_MUTEX_)
@@ -90,7 +92,8 @@
90/** 92/**
91 * Define static mutex and statically initialise it. 93 * Define static mutex and statically initialise it.
92 */ 94 */
93# define MHD_MUTEX_STATIC_DEFN_INIT_(m) static MHD_mutex_ m = PTHREAD_MUTEX_INITIALIZER 95# define MHD_MUTEX_STATIC_DEFN_INIT_(m) static MHD_mutex_ m = \
96 PTHREAD_MUTEX_INITIALIZER
94# endif /* PTHREAD_MUTEX_INITIALIZER */ 97# endif /* PTHREAD_MUTEX_INITIALIZER */
95#endif 98#endif
96 99
@@ -100,14 +103,14 @@
100 * @param pmutex pointer to mutex 103 * @param pmutex pointer to mutex
101 * @return nonzero on success, zero otherwise 104 * @return nonzero on success, zero otherwise
102 */ 105 */
103#define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex)))) 106#define MHD_mutex_destroy_(pmutex) (! (pthread_mutex_destroy ((pmutex))))
104#elif defined(MHD_W32_MUTEX_) 107#elif defined(MHD_W32_MUTEX_)
105/** 108/**
106 * Destroy previously initialised mutex. 109 * Destroy previously initialised mutex.
107 * @param pmutex pointer to mutex 110 * @param pmutex pointer to mutex
108 * @return Always nonzero 111 * @return Always nonzero
109 */ 112 */
110#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0) 113#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection ((pmutex)), ! 0)
111#endif 114#endif
112 115
113/** 116/**
@@ -116,9 +119,9 @@
116 * @param pmutex pointer to mutex 119 * @param pmutex pointer to mutex
117 */ 120 */
118#define MHD_mutex_destroy_chk_(pmutex) do { \ 121#define MHD_mutex_destroy_chk_(pmutex) do { \
119 if (!MHD_mutex_destroy_(pmutex)) \ 122 if (! MHD_mutex_destroy_ (pmutex)) \
120 MHD_PANIC(_("Failed to destroy mutex.\n")); \ 123 MHD_PANIC (_ ("Failed to destroy mutex.\n")); \
121 } while(0) 124} while (0)
122 125
123 126
124#if defined(MHD_PTHREAD_MUTEX_) 127#if defined(MHD_PTHREAD_MUTEX_)
@@ -129,7 +132,7 @@
129 * @param pmutex pointer to mutex 132 * @param pmutex pointer to mutex
130 * @return nonzero on success, zero otherwise 133 * @return nonzero on success, zero otherwise
131 */ 134 */
132#define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex)))) 135#define MHD_mutex_lock_(pmutex) (! (pthread_mutex_lock ((pmutex))))
133#elif defined(MHD_W32_MUTEX_) 136#elif defined(MHD_W32_MUTEX_)
134/** 137/**
135 * Acquire lock on previously initialised mutex. 138 * Acquire lock on previously initialised mutex.
@@ -138,7 +141,7 @@
138 * @param pmutex pointer to mutex 141 * @param pmutex pointer to mutex
139 * @return Always nonzero 142 * @return Always nonzero
140 */ 143 */
141#define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0) 144#define MHD_mutex_lock_(pmutex) (EnterCriticalSection ((pmutex)), ! 0)
142#endif 145#endif
143 146
144/** 147/**
@@ -149,9 +152,9 @@
149 * @param pmutex pointer to mutex 152 * @param pmutex pointer to mutex
150 */ 153 */
151#define MHD_mutex_lock_chk_(pmutex) do { \ 154#define MHD_mutex_lock_chk_(pmutex) do { \
152 if (!MHD_mutex_lock_(pmutex)) \ 155 if (! MHD_mutex_lock_ (pmutex)) \
153 MHD_PANIC(_("Failed to lock mutex.\n")); \ 156 MHD_PANIC (_ ("Failed to lock mutex.\n")); \
154 } while(0) 157} while (0)
155 158
156#if defined(MHD_PTHREAD_MUTEX_) 159#if defined(MHD_PTHREAD_MUTEX_)
157/** 160/**
@@ -159,14 +162,14 @@
159 * @param pmutex pointer to mutex 162 * @param pmutex pointer to mutex
160 * @return nonzero on success, zero otherwise 163 * @return nonzero on success, zero otherwise
161 */ 164 */
162#define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex)))) 165#define MHD_mutex_unlock_(pmutex) (! (pthread_mutex_unlock ((pmutex))))
163#elif defined(MHD_W32_MUTEX_) 166#elif defined(MHD_W32_MUTEX_)
164/** 167/**
165 * Unlock previously initialised and locked mutex. 168 * Unlock previously initialised and locked mutex.
166 * @param pmutex pointer to mutex 169 * @param pmutex pointer to mutex
167 * @return Always nonzero 170 * @return Always nonzero
168 */ 171 */
169#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0) 172#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection ((pmutex)), ! 0)
170#endif 173#endif
171 174
172/** 175/**
@@ -175,9 +178,9 @@
175 * @param pmutex pointer to mutex 178 * @param pmutex pointer to mutex
176 */ 179 */
177#define MHD_mutex_unlock_chk_(pmutex) do { \ 180#define MHD_mutex_unlock_chk_(pmutex) do { \
178 if (!MHD_mutex_unlock_(pmutex)) \ 181 if (! MHD_mutex_unlock_ (pmutex)) \
179 MHD_PANIC(_("Failed to unlock mutex.\n")); \ 182 MHD_PANIC (_ ("Failed to unlock mutex.\n")); \
180 } while(0) 183} while (0)
181 184
182 185
183#endif /* ! MHD_LOCKS_H */ 186#endif /* ! MHD_LOCKS_H */
diff --git a/src/lib/mhd_mono_clock.c b/src/lib/mhd_mono_clock.c
index 97dbfb9f..eee911fb 100644
--- a/src/lib/mhd_mono_clock.c
+++ b/src/lib/mhd_mono_clock.c
@@ -76,7 +76,8 @@ static clockid_t mono_clock_id = _MHD_UNWANTED_CLOCK;
76#endif /* HAVE_CLOCK_GETTIME */ 76#endif /* HAVE_CLOCK_GETTIME */
77 77
78/* sync clocks; reduce chance of value wrap */ 78/* sync clocks; reduce chance of value wrap */
79#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GET_TIME) || defined(HAVE_GETHRTIME) 79#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GET_TIME) || \
80 defined(HAVE_GETHRTIME)
80static time_t mono_clock_start; 81static time_t mono_clock_start;
81#endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GET_TIME || HAVE_GETHRTIME */ 82#endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GET_TIME || HAVE_GETHRTIME */
82static time_t sys_clock_start; 83static time_t sys_clock_start;
@@ -124,9 +125,9 @@ enum _MHD_mono_clock_source
124 */ 125 */
125 _MHD_CLOCK_GETTICKCOUNT64, 126 _MHD_CLOCK_GETTICKCOUNT64,
126 127
127 /** 128 /**
128 * QueryPerformanceCounter() / QueryPerformanceFrequency() 129 * QueryPerformanceCounter() / QueryPerformanceFrequency()
129 */ 130 */
130 _MHD_CLOCK_PERFCOUNTER 131 _MHD_CLOCK_PERFCOUNTER
131}; 132};
132 133
@@ -153,8 +154,8 @@ MHD_monotonic_sec_counter_init (void)
153 /* just a little syntactic trick to get the 154 /* just a little syntactic trick to get the
154 various following ifdef's to work out nicely */ 155 various following ifdef's to work out nicely */
155 if (0) 156 if (0)
156 { 157 {
157 } 158 }
158 else 159 else
159#ifdef HAVE_CLOCK_GETTIME 160#ifdef HAVE_CLOCK_GETTIME
160#ifdef CLOCK_MONOTONIC_COARSE 161#ifdef CLOCK_MONOTONIC_COARSE
@@ -163,11 +164,11 @@ MHD_monotonic_sec_counter_init (void)
163 /* but preferred since it's fast */ 164 /* but preferred since it's fast */
164 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE, 165 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE,
165 &ts)) 166 &ts))
166 { 167 {
167 mono_clock_id = CLOCK_MONOTONIC_COARSE; 168 mono_clock_id = CLOCK_MONOTONIC_COARSE;
168 mono_clock_start = ts.tv_sec; 169 mono_clock_start = ts.tv_sec;
169 mono_clock_source = _MHD_CLOCK_GETTIME; 170 mono_clock_source = _MHD_CLOCK_GETTIME;
170 } 171 }
171 else 172 else
172#endif /* CLOCK_MONOTONIC_COARSE */ 173#endif /* CLOCK_MONOTONIC_COARSE */
173#ifdef CLOCK_MONOTONIC_FAST 174#ifdef CLOCK_MONOTONIC_FAST
@@ -175,11 +176,11 @@ MHD_monotonic_sec_counter_init (void)
175 /* Can be affected by frequency adjustment, but preferred since it's fast */ 176 /* Can be affected by frequency adjustment, but preferred since it's fast */
176 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, 177 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST,
177 &ts)) 178 &ts))
178 { 179 {
179 mono_clock_id = CLOCK_MONOTONIC_FAST; 180 mono_clock_id = CLOCK_MONOTONIC_FAST;
180 mono_clock_start = ts.tv_sec; 181 mono_clock_start = ts.tv_sec;
181 mono_clock_source = _MHD_CLOCK_GETTIME; 182 mono_clock_source = _MHD_CLOCK_GETTIME;
182 } 183 }
183 else 184 else
184#endif /* CLOCK_MONOTONIC_COARSE */ 185#endif /* CLOCK_MONOTONIC_COARSE */
185#ifdef CLOCK_MONOTONIC_RAW 186#ifdef CLOCK_MONOTONIC_RAW
@@ -187,11 +188,11 @@ MHD_monotonic_sec_counter_init (void)
187 /* Not affected by frequency adjustment, but don't count time in suspend */ 188 /* Not affected by frequency adjustment, but don't count time in suspend */
188 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW, 189 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW,
189 &ts)) 190 &ts))
190 { 191 {
191 mono_clock_id = CLOCK_MONOTONIC_RAW; 192 mono_clock_id = CLOCK_MONOTONIC_RAW;
192 mono_clock_start = ts.tv_sec; 193 mono_clock_start = ts.tv_sec;
193 mono_clock_source = _MHD_CLOCK_GETTIME; 194 mono_clock_source = _MHD_CLOCK_GETTIME;
194 } 195 }
195 else 196 else
196#endif /* CLOCK_MONOTONIC_RAW */ 197#endif /* CLOCK_MONOTONIC_RAW */
197#ifdef CLOCK_BOOTTIME 198#ifdef CLOCK_BOOTTIME
@@ -200,11 +201,11 @@ MHD_monotonic_sec_counter_init (void)
200 /* but can be slower value-getting than other clocks */ 201 /* but can be slower value-getting than other clocks */
201 if (0 == clock_gettime (CLOCK_BOOTTIME, 202 if (0 == clock_gettime (CLOCK_BOOTTIME,
202 &ts)) 203 &ts))
203 { 204 {
204 mono_clock_id = CLOCK_BOOTTIME; 205 mono_clock_id = CLOCK_BOOTTIME;
205 mono_clock_start = ts.tv_sec; 206 mono_clock_start = ts.tv_sec;
206 mono_clock_source = _MHD_CLOCK_GETTIME; 207 mono_clock_source = _MHD_CLOCK_GETTIME;
207 } 208 }
208 else 209 else
209#endif /* CLOCK_BOOTTIME */ 210#endif /* CLOCK_BOOTTIME */
210#ifdef CLOCK_MONOTONIC 211#ifdef CLOCK_MONOTONIC
@@ -213,11 +214,11 @@ MHD_monotonic_sec_counter_init (void)
213 /* On Linux it's not truly monotonic as it doesn't count time in suspend */ 214 /* On Linux it's not truly monotonic as it doesn't count time in suspend */
214 if (0 == clock_gettime (CLOCK_MONOTONIC, 215 if (0 == clock_gettime (CLOCK_MONOTONIC,
215 &ts)) 216 &ts))
216 { 217 {
217 mono_clock_id = CLOCK_MONOTONIC; 218 mono_clock_id = CLOCK_MONOTONIC;
218 mono_clock_start = ts.tv_sec; 219 mono_clock_start = ts.tv_sec;
219 mono_clock_source = _MHD_CLOCK_GETTIME; 220 mono_clock_source = _MHD_CLOCK_GETTIME;
220 } 221 }
221 else 222 else
222#endif /* CLOCK_BOOTTIME */ 223#endif /* CLOCK_BOOTTIME */
223#endif /* HAVE_CLOCK_GETTIME */ 224#endif /* HAVE_CLOCK_GETTIME */
@@ -225,15 +226,15 @@ MHD_monotonic_sec_counter_init (void)
225 /* Darwin-specific monotonic clock */ 226 /* Darwin-specific monotonic clock */
226 /* Should be monotonic as clock_set_time function always unconditionally */ 227 /* Should be monotonic as clock_set_time function always unconditionally */
227 /* failed on latest kernels */ 228 /* failed on latest kernels */
228 if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self(), 229 if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self (),
229 SYSTEM_CLOCK, 230 SYSTEM_CLOCK,
230 &mono_clock_service)) && 231 &mono_clock_service)) &&
231 (KERN_SUCCESS == clock_get_time (mono_clock_service, 232 (KERN_SUCCESS == clock_get_time (mono_clock_service,
232 &cur_time)) ) 233 &cur_time)) )
233 { 234 {
234 mono_clock_start = cur_time.tv_sec; 235 mono_clock_start = cur_time.tv_sec;
235 mono_clock_source = _MHD_CLOCK_GET_TIME; 236 mono_clock_source = _MHD_CLOCK_GET_TIME;
236 } 237 }
237 else 238 else
238#endif /* HAVE_CLOCK_GET_TIME */ 239#endif /* HAVE_CLOCK_GET_TIME */
239#ifdef _WIN32 240#ifdef _WIN32
@@ -241,25 +242,25 @@ MHD_monotonic_sec_counter_init (void)
241 /* W32 Vista or later specific monotonic clock */ 242 /* W32 Vista or later specific monotonic clock */
242 /* Available since Vista, ~15ms accuracy */ 243 /* Available since Vista, ~15ms accuracy */
243 if (1) 244 if (1)
244 { 245 {
245 tick_start = GetTickCount64 (); 246 tick_start = GetTickCount64 ();
246 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64; 247 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64;
247 } 248 }
248 else 249 else
249#else /* _WIN32_WINNT < 0x0600 */ 250#else /* _WIN32_WINNT < 0x0600 */
250 /* W32 specific monotonic clock */ 251 /* W32 specific monotonic clock */
251 /* Available on Windows 2000 and later */ 252 /* Available on Windows 2000 and later */
252 if (1) 253 if (1)
253 { 254 {
254 LARGE_INTEGER freq; 255 LARGE_INTEGER freq;
255 LARGE_INTEGER perf_counter; 256 LARGE_INTEGER perf_counter;
256 257
257 QueryPerformanceFrequency (&freq); /* never fail on XP and later */ 258 QueryPerformanceFrequency (&freq); /* never fail on XP and later */
258 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ 259 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
259 perf_freq = freq.QuadPart; 260 perf_freq = freq.QuadPart;
260 perf_start = perf_counter.QuadPart; 261 perf_start = perf_counter.QuadPart;
261 mono_clock_source = _MHD_CLOCK_PERFCOUNTER; 262 mono_clock_source = _MHD_CLOCK_PERFCOUNTER;
262 } 263 }
263 else 264 else
264#endif /* _WIN32_WINNT < 0x0600 */ 265#endif /* _WIN32_WINNT < 0x0600 */
265#endif /* _WIN32 */ 266#endif /* _WIN32 */
@@ -269,11 +270,11 @@ MHD_monotonic_sec_counter_init (void)
269 /* Not preferred due to be potentially resource-hungry */ 270 /* Not preferred due to be potentially resource-hungry */
270 if (0 == clock_gettime (CLOCK_HIGHRES, 271 if (0 == clock_gettime (CLOCK_HIGHRES,
271 &ts)) 272 &ts))
272 { 273 {
273 mono_clock_id = CLOCK_HIGHRES; 274 mono_clock_id = CLOCK_HIGHRES;
274 mono_clock_start = ts.tv_sec; 275 mono_clock_start = ts.tv_sec;
275 mono_clock_source = _MHD_CLOCK_GETTIME; 276 mono_clock_source = _MHD_CLOCK_GETTIME;
276 } 277 }
277 else 278 else
278#endif /* CLOCK_HIGHRES */ 279#endif /* CLOCK_HIGHRES */
279#endif /* HAVE_CLOCK_GETTIME */ 280#endif /* HAVE_CLOCK_GETTIME */
@@ -281,26 +282,26 @@ MHD_monotonic_sec_counter_init (void)
281 /* HP-UX and Solaris monotonic clock */ 282 /* HP-UX and Solaris monotonic clock */
282 /* Not preferred due to be potentially resource-hungry */ 283 /* Not preferred due to be potentially resource-hungry */
283 if (1) 284 if (1)
284 { 285 {
285 hrtime_start = gethrtime (); 286 hrtime_start = gethrtime ();
286 mono_clock_source = _MHD_CLOCK_GETHRTIME; 287 mono_clock_source = _MHD_CLOCK_GETHRTIME;
287 } 288 }
288 else 289 else
289#endif /* HAVE_GETHRTIME */ 290#endif /* HAVE_GETHRTIME */
290 { 291 {
291 /* no suitable clock source was found */ 292 /* no suitable clock source was found */
292 mono_clock_source = _MHD_CLOCK_NO_SOURCE; 293 mono_clock_source = _MHD_CLOCK_NO_SOURCE;
293 } 294 }
294 295
295#ifdef HAVE_CLOCK_GET_TIME 296#ifdef HAVE_CLOCK_GET_TIME
296 if ( (_MHD_CLOCK_GET_TIME != mono_clock_source) && 297 if ( (_MHD_CLOCK_GET_TIME != mono_clock_source) &&
297 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) ) 298 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) )
298 { 299 {
299 /* clock service was initialised but clock_get_time failed */ 300 /* clock service was initialised but clock_get_time failed */
300 mach_port_deallocate (mach_task_self(), 301 mach_port_deallocate (mach_task_self (),
301 mono_clock_service); 302 mono_clock_service);
302 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 303 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
303 } 304 }
304#else 305#else
305 (void) mono_clock_source; /* avoid compiler warning */ 306 (void) mono_clock_source; /* avoid compiler warning */
306#endif /* HAVE_CLOCK_GET_TIME */ 307#endif /* HAVE_CLOCK_GET_TIME */
@@ -317,11 +318,11 @@ MHD_monotonic_sec_counter_finish (void)
317{ 318{
318#ifdef HAVE_CLOCK_GET_TIME 319#ifdef HAVE_CLOCK_GET_TIME
319 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 320 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
320 { 321 {
321 mach_port_deallocate (mach_task_self(), 322 mach_port_deallocate (mach_task_self (),
322 mono_clock_service); 323 mono_clock_service);
323 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 324 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
324 } 325 }
325#endif /* HAVE_CLOCK_GET_TIME */ 326#endif /* HAVE_CLOCK_GET_TIME */
326} 327}
327 328
@@ -340,37 +341,38 @@ MHD_monotonic_sec_counter (void)
340 struct timespec ts; 341 struct timespec ts;
341 342
342 if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) && 343 if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) &&
343 (0 == clock_gettime (mono_clock_id , 344 (0 == clock_gettime (mono_clock_id,
344 &ts)) ) 345 &ts)) )
345 return ts.tv_sec - mono_clock_start; 346 return ts.tv_sec - mono_clock_start;
346#endif /* HAVE_CLOCK_GETTIME */ 347#endif /* HAVE_CLOCK_GETTIME */
347#ifdef HAVE_CLOCK_GET_TIME 348#ifdef HAVE_CLOCK_GET_TIME
348 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 349 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
349 { 350 {
350 mach_timespec_t cur_time; 351 mach_timespec_t cur_time;
351 352
352 if (KERN_SUCCESS == clock_get_time(mono_clock_service, 353 if (KERN_SUCCESS == clock_get_time (mono_clock_service,
353 &cur_time)) 354 &cur_time))
354 return cur_time.tv_sec - mono_clock_start; 355 return cur_time.tv_sec - mono_clock_start;
355 } 356 }
356#endif /* HAVE_CLOCK_GET_TIME */ 357#endif /* HAVE_CLOCK_GET_TIME */
357#if defined(_WIN32) 358#if defined(_WIN32)
358#if _WIN32_WINNT >= 0x0600 359#if _WIN32_WINNT >= 0x0600
359 if (1) 360 if (1)
360 return (time_t)(((uint64_t)(GetTickCount64() - tick_start)) / 1000); 361 return (time_t) (((uint64_t) (GetTickCount64 () - tick_start)) / 1000);
361#else /* _WIN32_WINNT < 0x0600 */ 362#else /* _WIN32_WINNT < 0x0600 */
362 if (0 != perf_freq) 363 if (0 != perf_freq)
363 { 364 {
364 LARGE_INTEGER perf_counter; 365 LARGE_INTEGER perf_counter;
365 366
366 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ 367 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
367 return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq); 368 return (time_t) (((uint64_t) (perf_counter.QuadPart - perf_start))
368 } 369 / perf_freq);
370 }
369#endif /* _WIN32_WINNT < 0x0600 */ 371#endif /* _WIN32_WINNT < 0x0600 */
370#endif /* _WIN32 */ 372#endif /* _WIN32 */
371#ifdef HAVE_GETHRTIME 373#ifdef HAVE_GETHRTIME
372 if (1) 374 if (1)
373 return (time_t)(((uint64_t) (gethrtime () - hrtime_start)) / 1000000000); 375 return (time_t) (((uint64_t) (gethrtime () - hrtime_start)) / 1000000000);
374#endif /* HAVE_GETHRTIME */ 376#endif /* HAVE_GETHRTIME */
375 377
376 return time (NULL) - sys_clock_start; 378 return time (NULL) - sys_clock_start;
diff --git a/src/lib/mhd_mono_clock.h b/src/lib/mhd_mono_clock.h
index f4722af2..92485e00 100644
--- a/src/lib/mhd_mono_clock.h
+++ b/src/lib/mhd_mono_clock.h
@@ -37,14 +37,14 @@
37 * Initialise monotonic seconds counter. 37 * Initialise monotonic seconds counter.
38 */ 38 */
39void 39void
40MHD_monotonic_sec_counter_init(void); 40MHD_monotonic_sec_counter_init (void);
41 41
42 42
43/** 43/**
44 * Deinitialise monotonic seconds counter by freeing any allocated resources 44 * Deinitialise monotonic seconds counter by freeing any allocated resources
45 */ 45 */
46void 46void
47MHD_monotonic_sec_counter_finish(void); 47MHD_monotonic_sec_counter_finish (void);
48 48
49 49
50/** 50/**
@@ -55,6 +55,6 @@ MHD_monotonic_sec_counter_finish(void);
55 * @return number of seconds from some fixed moment 55 * @return number of seconds from some fixed moment
56 */ 56 */
57time_t 57time_t
58MHD_monotonic_sec_counter(void); 58MHD_monotonic_sec_counter (void);
59 59
60#endif /* MHD_MONO_CLOCK_H */ 60#endif /* MHD_MONO_CLOCK_H */
diff --git a/src/lib/mhd_sockets.c b/src/lib/mhd_sockets.c
index 356d288f..248b9a68 100644
--- a/src/lib/mhd_sockets.c
+++ b/src/lib/mhd_sockets.c
@@ -37,10 +37,10 @@
37 * @param err the WinSock error code. 37 * @param err the WinSock error code.
38 * @return pointer to string description of specified WinSock error. 38 * @return pointer to string description of specified WinSock error.
39 */ 39 */
40const char* MHD_W32_strerror_winsock_(int err) 40const char*MHD_W32_strerror_winsock_ (int err)
41{ 41{
42 switch (err) 42 switch (err)
43 { 43 {
44 case 0: 44 case 0:
45 return "No error"; 45 return "No error";
46 case WSA_INVALID_HANDLE: 46 case WSA_INVALID_HANDLE:
@@ -233,7 +233,7 @@ const char* MHD_W32_strerror_winsock_(int err)
233 return "Invalid QoS shaping rate object"; 233 return "Invalid QoS shaping rate object";
234 case WSA_QOS_RESERVED_PETYPE: 234 case WSA_QOS_RESERVED_PETYPE:
235 return "Reserved policy QoS element type"; 235 return "Reserved policy QoS element type";
236 } 236 }
237 return "Unknown winsock error"; 237 return "Unknown winsock error";
238} 238}
239 239
@@ -246,113 +246,114 @@ const char* MHD_W32_strerror_winsock_(int err)
246 * @return non-zero if succeeded, zero otherwise 246 * @return non-zero if succeeded, zero otherwise
247 */ 247 */
248int 248int
249MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk) 249MHD_W32_socket_pair_ (SOCKET sockets_pair[2], int non_blk)
250{ 250{
251 int i; 251 int i;
252 252
253 if (! sockets_pair) 253 if (! sockets_pair)
254 { 254 {
255 WSASetLastError (WSAEFAULT); 255 WSASetLastError (WSAEFAULT);
256 return 0; 256 return 0;
257 } 257 }
258 258
259#define PAIRMAXTRYIES 800 259#define PAIRMAXTRYIES 800
260 for (i = 0; i < PAIRMAXTRYIES; i++) 260 for (i = 0; i < PAIRMAXTRYIES; i++)
261 {
262 struct sockaddr_in listen_addr;
263 SOCKET listen_s;
264 static const int c_addinlen = sizeof(struct sockaddr_in); /* help compiler to optimize */
265 int addr_len = c_addinlen;
266 unsigned long on_val = 1;
267 unsigned long off_val = 0;
268
269 listen_s = socket (AF_INET,
270 SOCK_STREAM,
271 IPPROTO_TCP);
272 if (INVALID_SOCKET == listen_s)
273 break; /* can't create even single socket */
274
275 listen_addr.sin_family = AF_INET;
276 listen_addr.sin_port = 0; /* same as htons(0) */
277 listen_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
278 if ( ((0 == bind (listen_s,
279 (struct sockaddr*) &listen_addr,
280 c_addinlen)) &&
281 (0 == listen (listen_s,
282 1) ) &&
283 (0 == getsockname (listen_s,
284 (struct sockaddr*) &listen_addr,
285 &addr_len))) )
261 { 286 {
262 struct sockaddr_in listen_addr; 287 SOCKET client_s = socket (AF_INET,
263 SOCKET listen_s; 288 SOCK_STREAM,
264 static const int c_addinlen = sizeof(struct sockaddr_in); /* help compiler to optimize */ 289 IPPROTO_TCP);
265 int addr_len = c_addinlen; 290 struct sockaddr_in accepted_from_addr;
266 unsigned long on_val = 1; 291 struct sockaddr_in client_addr;
267 unsigned long off_val = 0; 292 SOCKET server_s;
268 293
269 listen_s = socket (AF_INET, 294 if (INVALID_SOCKET == client_s)
270 SOCK_STREAM, 295 {
271 IPPROTO_TCP); 296 /* try again */
272 if (INVALID_SOCKET == listen_s) 297 closesocket (listen_s);
273 break; /* can't create even single socket */ 298 continue;
274 299 }
275 listen_addr.sin_family = AF_INET; 300
276 listen_addr.sin_port = 0; /* same as htons(0) */ 301 if ( (0 != ioctlsocket (client_s,
277 listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 302 FIONBIO,
278 if ( (0 == bind (listen_s, 303 &on_val)) ||
279 (struct sockaddr*) &listen_addr, 304 ( (0 != connect (client_s,
280 c_addinlen) && 305 (struct sockaddr*) &listen_addr,
281 (0 == listen (listen_s, 306 c_addinlen)) &&
282 1) ) && 307 (WSAGetLastError () != WSAEWOULDBLOCK)) )
283 (0 == getsockname (listen_s, 308 {
284 (struct sockaddr*) &listen_addr, 309 /* try again */
285 &addr_len))) ) 310 closesocket (listen_s);
286 { 311 closesocket (client_s);
287 SOCKET client_s = socket(AF_INET, 312 continue;
288 SOCK_STREAM, 313 }
289 IPPROTO_TCP); 314
290 struct sockaddr_in accepted_from_addr; 315 addr_len = c_addinlen;
291 struct sockaddr_in client_addr; 316 server_s = accept (listen_s,
292 SOCKET server_s; 317 (struct sockaddr*) &accepted_from_addr,
293 318 &addr_len);
294 if (INVALID_SOCKET == client_s) 319 if (INVALID_SOCKET == server_s)
295 { 320 {
296 /* try again */ 321 /* try again */
297 closesocket (listen_s); 322 closesocket (listen_s);
298 continue; 323 closesocket (client_s);
299 } 324 continue;
300 325 }
301 if ( (0 != ioctlsocket (client_s, 326
302 FIONBIO, 327 addr_len = c_addinlen;
303 &on_val)) || 328 if ( (0 == getsockname (client_s,
304 ( (0 != connect (client_s, 329 (struct sockaddr*) &client_addr,
305 (struct sockaddr*) &listen_addr, 330 &addr_len)) &&
306 c_addinlen)) && 331 (accepted_from_addr.sin_family == client_addr.sin_family) &&
307 (WSAGetLastError() != WSAEWOULDBLOCK)) ) 332 (accepted_from_addr.sin_port == client_addr.sin_port) &&
308 { 333 (accepted_from_addr.sin_addr.s_addr ==
309 /* try again */ 334 client_addr.sin_addr.s_addr) &&
310 closesocket (listen_s); 335 ( (0 != non_blk) ?
311 closesocket (client_s); 336 (0 == ioctlsocket (server_s,
312 continue; 337 FIONBIO,
313 } 338 &on_val)) :
314 339 (0 == ioctlsocket (client_s,
315 addr_len = c_addinlen; 340 FIONBIO,
316 server_s = accept (listen_s, 341 &off_val)) ) )
317 (struct sockaddr*) &accepted_from_addr, 342 {
318 &addr_len); 343 closesocket (listen_s);
319 if (INVALID_SOCKET == server_s) 344 sockets_pair[0] = server_s;
320 { 345 sockets_pair[1] = client_s;
321 /* try again */ 346 return ! 0;
322 closesocket (listen_s); 347 }
323 closesocket (client_s); 348 closesocket (server_s);
324 continue; 349 closesocket (client_s);
325 }
326
327 addr_len = c_addinlen;
328 if ( (0 == getsockname (client_s,
329 (struct sockaddr*) &client_addr,
330 &addr_len)) &&
331 (accepted_from_addr.sin_family == client_addr.sin_family) &&
332 (accepted_from_addr.sin_port == client_addr.sin_port) &&
333 (accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr) &&
334 ( (0 != non_blk) ?
335 (0 == ioctlsocket(server_s,
336 FIONBIO,
337 &on_val)) :
338 (0 == ioctlsocket(client_s,
339 FIONBIO,
340 &off_val)) ) )
341 {
342 closesocket (listen_s);
343 sockets_pair[0] = server_s;
344 sockets_pair[1] = client_s;
345 return !0;
346 }
347 closesocket (server_s);
348 closesocket (client_s);
349 }
350 closesocket(listen_s);
351 } 350 }
351 closesocket (listen_s);
352 }
352 353
353 sockets_pair[0] = INVALID_SOCKET; 354 sockets_pair[0] = INVALID_SOCKET;
354 sockets_pair[1] = INVALID_SOCKET; 355 sockets_pair[1] = INVALID_SOCKET;
355 WSASetLastError(WSAECONNREFUSED); 356 WSASetLastError (WSAECONNREFUSED);
356 357
357 return 0; 358 return 0;
358} 359}
@@ -383,9 +384,9 @@ MHD_add_to_fd_set_ (MHD_socket fd,
383 set, 384 set,
384 fd_setsize)) 385 fd_setsize))
385 return 0; 386 return 0;
386 MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd, 387 MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_ (fd,
387 set, 388 set,
388 fd_setsize); 389 fd_setsize);
389 if ( (NULL != max_fd) && 390 if ( (NULL != max_fd) &&
390 ( (fd > *max_fd) || 391 ( (fd > *max_fd) ||
391 (MHD_INVALID_SOCKET == *max_fd) ) ) 392 (MHD_INVALID_SOCKET == *max_fd) ) )
@@ -424,7 +425,7 @@ MHD_socket_nonblocking_ (MHD_socket sock)
424 &flags)) 425 &flags))
425 return 0; 426 return 0;
426#endif /* MHD_WINSOCK_SOCKETS */ 427#endif /* MHD_WINSOCK_SOCKETS */
427 return !0; 428 return ! 0;
428} 429}
429 430
430 431
@@ -452,12 +453,12 @@ MHD_socket_noninheritable_ (MHD_socket sock)
452 flags | FD_CLOEXEC)) ) 453 flags | FD_CLOEXEC)) )
453 return 0; 454 return 0;
454#elif defined(MHD_WINSOCK_SOCKETS) 455#elif defined(MHD_WINSOCK_SOCKETS)
455 if (! SetHandleInformation ((HANDLE)sock, 456 if (! SetHandleInformation ((HANDLE) sock,
456 HANDLE_FLAG_INHERIT, 457 HANDLE_FLAG_INHERIT,
457 0)) 458 0))
458 return 0; 459 return 0;
459#endif /* MHD_WINSOCK_SOCKETS */ 460#endif /* MHD_WINSOCK_SOCKETS */
460 return !0; 461 return ! 0;
461} 462}
462 463
463 464
@@ -477,7 +478,7 @@ MHD_socket_create_listen_ (int pf)
477 fd = socket (pf, 478 fd = socket (pf,
478 SOCK_STREAM | SOCK_CLOEXEC, 479 SOCK_STREAM | SOCK_CLOEXEC,
479 0); 480 0);
480 cloexec_set = !0; 481 cloexec_set = ! 0;
481#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT) 482#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
482 fd = WSASocketW (pf, 483 fd = WSASocketW (pf,
483 SOCK_STREAM, 484 SOCK_STREAM,
@@ -485,27 +486,27 @@ MHD_socket_create_listen_ (int pf)
485 NULL, 486 NULL,
486 0, 487 0,
487 WSA_FLAG_NO_HANDLE_INHERIT); 488 WSA_FLAG_NO_HANDLE_INHERIT);
488 cloexec_set = !0; 489 cloexec_set = ! 0;
489#else /* !SOCK_CLOEXEC */ 490#else /* !SOCK_CLOEXEC */
490 fd = MHD_INVALID_SOCKET; 491 fd = MHD_INVALID_SOCKET;
491#endif /* !SOCK_CLOEXEC */ 492#endif /* !SOCK_CLOEXEC */
492 if (MHD_INVALID_SOCKET == fd) 493 if (MHD_INVALID_SOCKET == fd)
493 { 494 {
494 fd = socket (pf, 495 fd = socket (pf,
495 SOCK_STREAM, 496 SOCK_STREAM,
496 0); 497 0);
497 cloexec_set = 0; 498 cloexec_set = 0;
498 } 499 }
499 if (MHD_INVALID_SOCKET == fd) 500 if (MHD_INVALID_SOCKET == fd)
500 return MHD_INVALID_SOCKET; 501 return MHD_INVALID_SOCKET;
501#ifdef MHD_socket_nosignal_ 502#ifdef MHD_socket_nosignal_
502 if(! MHD_socket_nosignal_(fd)) 503 if (! MHD_socket_nosignal_ (fd))
503 { 504 {
504 const int err = MHD_socket_get_error_ (); 505 const int err = MHD_socket_get_error_ ();
505 (void) MHD_socket_close_ (fd); 506 (void) MHD_socket_close_ (fd);
506 MHD_socket_fset_error_ (err); 507 MHD_socket_fset_error_ (err);
507 return MHD_INVALID_SOCKET; 508 return MHD_INVALID_SOCKET;
508 } 509 }
509#endif /* MHD_socket_nosignal_ */ 510#endif /* MHD_socket_nosignal_ */
510 if (! cloexec_set) 511 if (! cloexec_set)
511 (void) MHD_socket_noninheritable_ (fd); 512 (void) MHD_socket_noninheritable_ (fd);
diff --git a/src/lib/mhd_sockets.h b/src/lib/mhd_sockets.h
index 9be34144..ebe40275 100644
--- a/src/lib/mhd_sockets.h
+++ b/src/lib/mhd_sockets.h
@@ -36,8 +36,8 @@
36 36
37#include <errno.h> 37#include <errno.h>
38 38
39#if !defined(MHD_POSIX_SOCKETS) && !defined(MHD_WINSOCK_SOCKETS) 39#if ! defined(MHD_POSIX_SOCKETS) && ! defined(MHD_WINSOCK_SOCKETS)
40# if !defined(_WIN32) || defined(__CYGWIN__) 40# if ! defined(_WIN32) || defined(__CYGWIN__)
41# define MHD_POSIX_SOCKETS 1 41# define MHD_POSIX_SOCKETS 1
42# else /* defined(_WIN32) && !defined(__CYGWIN__) */ 42# else /* defined(_WIN32) && !defined(__CYGWIN__) */
43# define MHD_WINSOCK_SOCKETS 1 43# define MHD_WINSOCK_SOCKETS 1
@@ -92,7 +92,7 @@
92# include <sys/epoll.h> 92# include <sys/epoll.h>
93# endif 93# endif
94# ifdef HAVE_NETINET_TCP_H 94# ifdef HAVE_NETINET_TCP_H
95 /* for TCP_FASTOPEN and TCP_CORK */ 95/* for TCP_FASTOPEN and TCP_CORK */
96# include <netinet/tcp.h> 96# include <netinet/tcp.h>
97# endif 97# endif
98# ifdef HAVE_STRING_H 98# ifdef HAVE_STRING_H
@@ -111,10 +111,10 @@
111#endif 111#endif
112 112
113#include <stddef.h> 113#include <stddef.h>
114#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 114#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
115# include <stdint.h> 115# include <stdint.h>
116# define _SSIZE_T_DEFINED 116# define _SSIZE_T_DEFINED
117 typedef intptr_t ssize_t; 117typedef intptr_t ssize_t;
118#endif /* !_SSIZE_T_DEFINED */ 118#endif /* !_SSIZE_T_DEFINED */
119 119
120#include "mhd_limits.h" 120#include "mhd_limits.h"
@@ -123,7 +123,7 @@
123# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE 123# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE
124#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 124#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
125# include "sysfdsetsize.h" 125# include "sysfdsetsize.h"
126# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value() 126# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value ()
127#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 127#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
128 128
129#ifndef MHD_PANIC 129#ifndef MHD_PANIC
@@ -131,8 +131,9 @@
131# include <stdlib.h> 131# include <stdlib.h>
132/* Simple implementation of MHD_PANIC, to be used outside lib */ 132/* Simple implementation of MHD_PANIC, to be used outside lib */
133# define MHD_PANIC(msg) do { fprintf (stderr, \ 133# define MHD_PANIC(msg) do { fprintf (stderr, \
134 "Abnormal termination at %d line in file %s: %s\n", \ 134 "Abnormal termination at %d line in file %s: %s\n", \
135 (int)__LINE__, __FILE__, msg); abort();} while(0) 135 (int) __LINE__, __FILE__, msg); abort (); \
136} while (0)
136#endif /* ! MHD_PANIC */ 137#endif /* ! MHD_PANIC */
137 138
138#ifndef MHD_SOCKET_DEFINED 139#ifndef MHD_SOCKET_DEFINED
@@ -140,10 +141,10 @@
140 * MHD_socket is type for socket FDs 141 * MHD_socket is type for socket FDs
141 */ 142 */
142# if defined(MHD_POSIX_SOCKETS) 143# if defined(MHD_POSIX_SOCKETS)
143 typedef int MHD_socket; 144typedef int MHD_socket;
144# define MHD_INVALID_SOCKET (-1) 145# define MHD_INVALID_SOCKET (-1)
145# elif defined(MHD_WINSOCK_SOCKETS) 146# elif defined(MHD_WINSOCK_SOCKETS)
146 typedef SOCKET MHD_socket; 147typedef SOCKET MHD_socket;
147# define MHD_INVALID_SOCKET (INVALID_SOCKET) 148# define MHD_INVALID_SOCKET (INVALID_SOCKET)
148# endif /* MHD_WINSOCK_SOCKETS */ 149# endif /* MHD_WINSOCK_SOCKETS */
149 150
@@ -168,17 +169,18 @@
168# define MAYBE_MSG_NOSIGNAL 0 169# define MAYBE_MSG_NOSIGNAL 0
169#endif /* ! MSG_NOSIGNAL */ 170#endif /* ! MSG_NOSIGNAL */
170 171
171#if !defined(SHUT_WR) && defined(SD_SEND) 172#if ! defined(SHUT_WR) && defined(SD_SEND)
172# define SHUT_WR SD_SEND 173# define SHUT_WR SD_SEND
173#endif 174#endif
174#if !defined(SHUT_RD) && defined(SD_RECEIVE) 175#if ! defined(SHUT_RD) && defined(SD_RECEIVE)
175# define SHUT_RD SD_RECEIVE 176# define SHUT_RD SD_RECEIVE
176#endif 177#endif
177#if !defined(SHUT_RDWR) && defined(SD_BOTH) 178#if ! defined(SHUT_RDWR) && defined(SD_BOTH)
178# define SHUT_RDWR SD_BOTH 179# define SHUT_RDWR SD_BOTH
179#endif 180#endif
180 181
181#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC)) 182#if HAVE_ACCEPT4 + 0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || \
183 defined(SOCK_CLOEXEC))
182# define USE_ACCEPT4 1 184# define USE_ACCEPT4 1
183#endif 185#endif
184 186
@@ -198,25 +200,25 @@
198 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt() 200 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt()
199 */ 201 */
200#ifdef MHD_POSIX_SOCKETS 202#ifdef MHD_POSIX_SOCKETS
201 typedef int MHD_SCKT_OPT_BOOL_; 203typedef int MHD_SCKT_OPT_BOOL_;
202#else /* MHD_WINSOCK_SOCKETS */ 204#else /* MHD_WINSOCK_SOCKETS */
203 typedef BOOL MHD_SCKT_OPT_BOOL_; 205typedef BOOL MHD_SCKT_OPT_BOOL_;
204#endif /* MHD_WINSOCK_SOCKETS */ 206#endif /* MHD_WINSOCK_SOCKETS */
205 207
206/** 208/**
207 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv 209 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv
208 * functions 210 * functions
209 */ 211 */
210#if !defined(MHD_WINSOCK_SOCKETS) 212#if ! defined(MHD_WINSOCK_SOCKETS)
211 typedef size_t MHD_SCKT_SEND_SIZE_; 213typedef size_t MHD_SCKT_SEND_SIZE_;
212#else 214#else
213 typedef int MHD_SCKT_SEND_SIZE_; 215typedef int MHD_SCKT_SEND_SIZE_;
214#endif 216#endif
215 217
216/** 218/**
217 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value. 219 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value.
218 */ 220 */
219#if !defined(MHD_WINSOCK_SOCKETS) 221#if ! defined(MHD_WINSOCK_SOCKETS)
220# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX 222# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX
221#else 223#else
222# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX 224# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX
@@ -232,10 +234,10 @@
232 * counted as success, only EBADF counts as an error!), 234 * counted as success, only EBADF counts as an error!),
233 * boolean false otherwise. 235 * boolean false otherwise.
234 */ 236 */
235#if !defined(MHD_WINSOCK_SOCKETS) 237#if ! defined(MHD_WINSOCK_SOCKETS)
236# define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno)) 238# define MHD_socket_close_(fd) ((0 == close ((fd))) || (EBADF != errno))
237#else 239#else
238# define MHD_socket_close_(fd) (0 == closesocket((fd))) 240# define MHD_socket_close_(fd) (0 == closesocket ((fd)))
239#endif 241#endif
240 242
241/** 243/**
@@ -244,9 +246,9 @@
244 * @param fd socket to close 246 * @param fd socket to close
245 */ 247 */
246#define MHD_socket_close_chk_(fd) do { \ 248#define MHD_socket_close_chk_(fd) do { \
247 if (!MHD_socket_close_(fd)) \ 249 if (! MHD_socket_close_ (fd)) \
248 MHD_PANIC(_("Close socket failed.\n")); \ 250 MHD_PANIC (_ ("Close socket failed.\n")); \
249 } while(0) 251} while (0)
250 252
251 253
252/** 254/**
@@ -257,7 +259,8 @@
257 * @return ssize_t type value 259 * @return ssize_t type value
258 */ 260 */
259#define MHD_send_(s,b,l) \ 261#define MHD_send_(s,b,l) \
260 ((ssize_t)send((s),(const void*)(b),((MHD_SCKT_SEND_SIZE_)l), MAYBE_MSG_NOSIGNAL)) 262 ((ssize_t) send ((s),(const void*) (b),((MHD_SCKT_SEND_SIZE_) l), \
263 MAYBE_MSG_NOSIGNAL))
261 264
262 265
263/** 266/**
@@ -268,7 +271,7 @@
268 * @return ssize_t type value 271 * @return ssize_t type value
269 */ 272 */
270#define MHD_recv_(s,b,l) \ 273#define MHD_recv_(s,b,l) \
271 ((ssize_t)recv((s),(void*)(b),((MHD_SCKT_SEND_SIZE_)l), 0)) 274 ((ssize_t) recv ((s),(void*) (b),((MHD_SCKT_SEND_SIZE_) l), 0))
272 275
273 276
274/** 277/**
@@ -281,11 +284,18 @@
281 * boolean false otherwise. 284 * boolean false otherwise.
282 */ 285 */
283#if defined(MHD_POSIX_SOCKETS) 286#if defined(MHD_POSIX_SOCKETS)
284# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < ((MHD_socket)setsize)) 287# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < \
288 ((MHD_socket) \
289 setsize))
285#elif defined(MHD_WINSOCK_SOCKETS) 290#elif defined(MHD_WINSOCK_SOCKETS)
286# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*)(pset)==(void*)0) || \ 291# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*) (pset)== \
287 (((fd_set*)(pset))->fd_count < ((unsigned)setsize)) || \ 292 (void*) 0) || \
288 (FD_ISSET((fd),(pset))) ) 293 (((fd_set*) (pset)) \
294 ->fd_count < \
295 ((unsigned) \
296 setsize)) || \
297 (FD_ISSET ((fd), \
298 (pset))) )
289#endif 299#endif
290 300
291/** 301/**
@@ -296,7 +306,9 @@
296 * @return boolean true if FD can be added to fd_set, 306 * @return boolean true if FD can be added to fd_set,
297 * boolean false otherwise. 307 * boolean false otherwise.
298 */ 308 */
299#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE) 309#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), \
310 (pset), \
311 FD_SETSIZE)
300 312
301/** 313/**
302 * Add FD to fd_set with specified FD_SETSIZE. 314 * Add FD to fd_set with specified FD_SETSIZE.
@@ -307,34 +319,35 @@
307 * system definition of FD_SET() is not used. 319 * system definition of FD_SET() is not used.
308 */ 320 */
309#if defined(MHD_POSIX_SOCKETS) 321#if defined(MHD_POSIX_SOCKETS)
310# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET((fd),(pset)) 322# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET ((fd), \
323 (pset))
311#elif defined(MHD_WINSOCK_SOCKETS) 324#elif defined(MHD_WINSOCK_SOCKETS)
312# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ 325# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \
313 do { \ 326 do { \
314 u_int _i_ = 0; \ 327 u_int _i_ = 0; \
315 fd_set* const _s_ = (fd_set*)(pset); \ 328 fd_set*const _s_ = (fd_set*) (pset); \
316 while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) {++_i_;} \ 329 while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \
317 if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = (fd);} \ 330 if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \
318 } while(0) 331 } while (0)
319#endif 332#endif
320 333
321 /* MHD_SYS_select_ is wrapper macro for system select() function */ 334/* MHD_SYS_select_ is wrapper macro for system select() function */
322#if !defined(MHD_WINSOCK_SOCKETS) 335#if ! defined(MHD_WINSOCK_SOCKETS)
323# define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) 336# define MHD_SYS_select_(n,r,w,e,t) select ((n),(r),(w),(e),(t))
324#else 337#else
325# define MHD_SYS_select_(n,r,w,e,t) \ 338# define MHD_SYS_select_(n,r,w,e,t) \
326( ( (((void*)(r) == (void*)0) || ((fd_set*)(r))->fd_count == 0) && \ 339 ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \
327 (((void*)(w) == (void*)0) || ((fd_set*)(w))->fd_count == 0) && \ 340 (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \
328 (((void*)(e) == (void*)0) || ((fd_set*)(e))->fd_count == 0) ) ? \ 341 (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \
329 ( ((void*)(t) == (void*)0) ? 0 : \ 342 ( ((void*) (t) == (void*) 0) ? 0 : \
330 (Sleep(((struct timeval*)(t))->tv_sec * 1000 + \ 343 (Sleep (((struct timeval*) (t))->tv_sec * 1000 \
331 ((struct timeval*)(t))->tv_usec / 1000), 0) ) : \ 344 + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \
332 (select((int)0,(r),(w),(e),(t))) ) 345 (select ((int) 0,(r),(w),(e),(t))) )
333#endif 346#endif
334 347
335#if defined(HAVE_POLL) 348#if defined(HAVE_POLL)
336/* MHD_sys_poll_ is wrapper macro for system poll() function */ 349/* MHD_sys_poll_ is wrapper macro for system poll() function */
337# if !defined(MHD_WINSOCK_SOCKETS) 350# if ! defined(MHD_WINSOCK_SOCKETS)
338# define MHD_sys_poll_ poll 351# define MHD_sys_poll_ poll
339# else /* MHD_WINSOCK_SOCKETS */ 352# else /* MHD_WINSOCK_SOCKETS */
340# define MHD_sys_poll_ WSAPoll 353# define MHD_sys_poll_ WSAPoll
@@ -363,16 +376,19 @@
363# elif defined(__linux__) 376# elif defined(__linux__)
364# define MHD_POLL_EVENTS_ERR_DISC POLLPRI 377# define MHD_POLL_EVENTS_ERR_DISC POLLPRI
365# else /* ! __linux__ */ 378# else /* ! __linux__ */
366# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO) 379# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO \
380 | MHD_POLLRDBAND_OR_ZERO)
367# endif /* ! __linux__ */ 381# endif /* ! __linux__ */
368/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. 382/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect.
369 * Note: Out-of-band data is treated as error. */ 383 * Note: Out-of-band data is treated as error. */
370# define MHD_POLL_REVENTS_ERR_DISC \ 384# define MHD_POLL_REVENTS_ERR_DISC \
371 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR | POLLHUP) 385 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
386 | POLLERR | POLLHUP)
372/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors. 387/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors.
373 * Note: Out-of-band data is treated as error. */ 388 * Note: Out-of-band data is treated as error. */
374# define MHD_POLL_REVENTS_ERRROR \ 389# define MHD_POLL_REVENTS_ERRROR \
375 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR) 390 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
391 | POLLERR)
376#endif /* HAVE_POLL */ 392#endif /* HAVE_POLL */
377 393
378#define MHD_SCKT_MISSING_ERR_CODE_ 31450 394#define MHD_SCKT_MISSING_ERR_CODE_ 31450
@@ -506,30 +522,30 @@
506#if defined(MHD_POSIX_SOCKETS) 522#if defined(MHD_POSIX_SOCKETS)
507# define MHD_socket_get_error_() (errno) 523# define MHD_socket_get_error_() (errno)
508#elif defined(MHD_WINSOCK_SOCKETS) 524#elif defined(MHD_WINSOCK_SOCKETS)
509# define MHD_socket_get_error_() WSAGetLastError() 525# define MHD_socket_get_error_() WSAGetLastError ()
510#endif 526#endif
511 527
512#ifdef MHD_WINSOCK_SOCKETS 528#ifdef MHD_WINSOCK_SOCKETS
513 /* POSIX-W32 sockets compatibility functions */ 529/* POSIX-W32 sockets compatibility functions */
514 530
515/** 531/**
516 * Return pointer to string description of specified WinSock error 532 * Return pointer to string description of specified WinSock error
517 * @param err the WinSock error code. 533 * @param err the WinSock error code.
518 * @return pointer to string description of specified WinSock error. 534 * @return pointer to string description of specified WinSock error.
519 */ 535 */
520 const char* MHD_W32_strerror_winsock_(int err); 536const char*MHD_W32_strerror_winsock_ (int err);
521#endif /* MHD_WINSOCK_SOCKETS */ 537#endif /* MHD_WINSOCK_SOCKETS */
522 538
523/* MHD_socket_last_strerr_ is description string of specified socket error code */ 539/* MHD_socket_last_strerr_ is description string of specified socket error code */
524#if defined(MHD_POSIX_SOCKETS) 540#if defined(MHD_POSIX_SOCKETS)
525# define MHD_socket_strerr_(err) strerror((err)) 541# define MHD_socket_strerr_(err) strerror ((err))
526#elif defined(MHD_WINSOCK_SOCKETS) 542#elif defined(MHD_WINSOCK_SOCKETS)
527# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err)) 543# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_ ((err))
528#endif 544#endif
529 545
530/* MHD_socket_last_strerr_ is description string of last errno (non-W32) / 546/* MHD_socket_last_strerr_ is description string of last errno (non-W32) /
531 * description string of last socket error (W32) */ 547 * description string of last socket error (W32) */
532#define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_()) 548#define MHD_socket_last_strerr_() MHD_socket_strerr_ (MHD_socket_get_error_ ())
533 549
534/** 550/**
535 * MHD_socket_fset_error_() set socket system native error code. 551 * MHD_socket_fset_error_() set socket system native error code.
@@ -537,7 +553,7 @@
537#if defined(MHD_POSIX_SOCKETS) 553#if defined(MHD_POSIX_SOCKETS)
538# define MHD_socket_fset_error_(err) (errno = (err)) 554# define MHD_socket_fset_error_(err) (errno = (err))
539#elif defined(MHD_WINSOCK_SOCKETS) 555#elif defined(MHD_WINSOCK_SOCKETS)
540# define MHD_socket_fset_error_(err) (WSASetLastError((err))) 556# define MHD_socket_fset_error_(err) (WSASetLastError ((err)))
541#endif 557#endif
542 558
543/** 559/**
@@ -549,7 +565,8 @@
549 * and error was not set. 565 * and error was not set.
550 */ 566 */
551#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ 567#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \
552 (MHD_socket_fset_error_((err)), !0) : 0 ) 568 (MHD_socket_fset_error_ ((err)), ! 0) : \
569 0)
553 570
554/** 571/**
555 * MHD_socket_set_error_() set socket system native error code to 572 * MHD_socket_set_error_() set socket system native error code to
@@ -562,7 +579,8 @@
562 (errno = ENOSYS) : (errno = (err)) ) 579 (errno = ENOSYS) : (errno = (err)) )
563# elif defined(EOPNOTSUPP) 580# elif defined(EOPNOTSUPP)
564# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 581# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
565 (errno = EOPNOTSUPP) : (errno = (err)) ) 582 (errno = EOPNOTSUPP) : (errno = \
583 (err)) )
566# elif defined (EFAULT) 584# elif defined (EFAULT)
567# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 585# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
568 (errno = EFAULT) : (errno = (err)) ) 586 (errno = EFAULT) : (errno = (err)) )
@@ -570,13 +588,14 @@
570# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 588# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
571 (errno = EINVAL) : (errno = (err)) ) 589 (errno = EINVAL) : (errno = (err)) )
572# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ 590# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */
573# warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. 591# warning \
592 No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system.
574# define MHD_socket_set_error_(err) (errno = (err)) 593# define MHD_socket_set_error_(err) (errno = (err))
575# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ 594# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/
576#elif defined(MHD_WINSOCK_SOCKETS) 595#elif defined(MHD_WINSOCK_SOCKETS)
577# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 596# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
578 (WSASetLastError((WSAEOPNOTSUPP))) : \ 597 (WSASetLastError ((WSAEOPNOTSUPP))) : \
579 (WSASetLastError((err))) ) 598 (WSASetLastError ((err))) )
580#endif 599#endif
581 600
582/** 601/**
@@ -600,7 +619,8 @@
600 * last socket error equals to MHD_SCKT_E*_ @a code; 619 * last socket error equals to MHD_SCKT_E*_ @a code;
601 * boolean false otherwise 620 * boolean false otherwise
602 */ 621 */
603#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code)) 622#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), \
623 (code))
604 624
605/* Specific error code checks */ 625/* Specific error code checks */
606 626
@@ -610,7 +630,7 @@
610 * @return boolean true if @a err is equal to sockets' EINTR code; 630 * @return boolean true if @a err is equal to sockets' EINTR code;
611 * boolean false otherwise. 631 * boolean false otherwise.
612 */ 632 */
613#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_) 633#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EINTR_)
614 634
615/** 635/**
616 * Check whether given socket error is equal to system's 636 * Check whether given socket error is equal to system's
@@ -619,10 +639,12 @@
619 * boolean false otherwise. 639 * boolean false otherwise.
620 */ 640 */
621#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ 641#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_
622# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) 642# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_)
623#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 643#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
624# define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \ 644# define MHD_SCKT_ERR_IS_EAGAIN_(err) (MHD_SCKT_ERR_IS_ ((err), \
625 MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) ) 645 MHD_SCKT_EAGAIN_) || \
646 MHD_SCKT_ERR_IS_ ((err), \
647 MHD_SCKT_EWOULDBLOCK_) )
626#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 648#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
627 649
628/** 650/**
@@ -630,10 +652,17 @@
630 * @return boolean true if @a err is any kind of "low resource" error, 652 * @return boolean true if @a err is any kind of "low resource" error,
631 * boolean false otherwise. 653 * boolean false otherwise.
632 */ 654 */
633#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \ 655#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) (MHD_SCKT_ERR_IS_ ((err), \
634 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \ 656 MHD_SCKT_EMFILE_) \
635 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \ 657 || \
636 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) ) 658 MHD_SCKT_ERR_IS_ ((err), \
659 MHD_SCKT_ENFILE_) \
660 || \
661 MHD_SCKT_ERR_IS_ ((err), \
662 MHD_SCKT_ENOMEM_) \
663 || \
664 MHD_SCKT_ERR_IS_ ((err), \
665 MHD_SCKT_ENOBUFS_) )
637 666
638/** 667/**
639 * Check whether is given socket error is type of "incoming connection 668 * Check whether is given socket error is type of "incoming connection
@@ -642,9 +671,11 @@
642 * boolean false otherwise. 671 * boolean false otherwise.
643 */ 672 */
644#if defined(MHD_POSIX_SOCKETS) 673#if defined(MHD_POSIX_SOCKETS)
645# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_) 674# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
675 MHD_SCKT_ECONNABORTED_)
646#elif defined(MHD_WINSOCK_SOCKETS) 676#elif defined(MHD_WINSOCK_SOCKETS)
647# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) 677# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
678 MHD_SCKT_ECONNRESET_)
648#endif 679#endif
649 680
650/** 681/**
@@ -653,8 +684,11 @@
653 * @return boolean true is @a err match described socket error code, 684 * @return boolean true is @a err match described socket error code,
654 * boolean false otherwise. 685 * boolean false otherwise.
655 */ 686 */
656#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \ 687#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) (MHD_SCKT_ERR_IS_ ((err), \
657 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)) 688 MHD_SCKT_ECONNRESET_) \
689 || \
690 MHD_SCKT_ERR_IS_ ((err), \
691 MHD_SCKT_ECONNABORTED_))
658 692
659/* Specific error code set */ 693/* Specific error code set */
660 694
@@ -663,12 +697,16 @@
663 * available on platform. 697 * available on platform.
664 */ 698 */
665#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ 699#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_
666# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 700# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
701 MHD_SCKT_ENOMEM_)
667#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ 702#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_
668# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_) 703# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
704 MHD_SCKT_ENOBUFS_)
669#else 705#else
670# warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. 706# warning \
671# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 707 No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system.
708# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
709 MHD_SCKT_ENOMEM_)
672#endif 710#endif
673 711
674/* Socket functions */ 712/* Socket functions */
@@ -680,22 +718,26 @@
680#endif /* AF_UNIX */ 718#endif /* AF_UNIX */
681 719
682#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) 720#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL)
683# define MHD_socket_pair_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM, 0, (fdarr))) 721# define MHD_socket_pair_(fdarr) (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, \
722 (fdarr)))
684# if defined(HAVE_SOCK_NONBLOCK) 723# if defined(HAVE_SOCK_NONBLOCK)
685# define MHD_socket_pair_nblk_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr))) 724# define MHD_socket_pair_nblk_(fdarr) (! socketpair (MHD_SCKT_LOCAL, \
725 SOCK_STREAM \
726 | SOCK_NONBLOCK, 0, \
727 (fdarr)))
686# endif /* HAVE_SOCK_NONBLOCK*/ 728# endif /* HAVE_SOCK_NONBLOCK*/
687#elif defined(MHD_WINSOCK_SOCKETS) 729#elif defined(MHD_WINSOCK_SOCKETS)
688 /** 730/**
689 * Create pair of mutually connected TCP/IP sockets on loopback address 731 * Create pair of mutually connected TCP/IP sockets on loopback address
690 * @param sockets_pair array to receive resulted sockets 732 * @param sockets_pair array to receive resulted sockets
691 * @param non_blk if set to non-zero value, sockets created in non-blocking mode 733 * @param non_blk if set to non-zero value, sockets created in non-blocking mode
692 * otherwise sockets will be in blocking mode 734 * otherwise sockets will be in blocking mode
693 * @return non-zero if succeeded, zero otherwise 735 * @return non-zero if succeeded, zero otherwise
694 */ 736 */
695 int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk); 737int MHD_W32_socket_pair_ (SOCKET sockets_pair[2], int non_blk);
696 738
697# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0) 739# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_ ((fdarr), 0)
698# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1) 740# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_ ((fdarr), 1)
699#endif 741#endif
700 742
701/** 743/**
@@ -737,7 +779,7 @@ MHD_socket_noninheritable_ (MHD_socket sock);
737 779
738 780
739#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) 781#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
740 static const int _MHD_socket_int_one = 1; 782static const int _MHD_socket_int_one = 1;
741/** 783/**
742 * Change socket options to no signal on remote disconnect. 784 * Change socket options to no signal on remote disconnect.
743 * 785 *
@@ -745,7 +787,8 @@ MHD_socket_noninheritable_ (MHD_socket sock);
745 * @return non-zero if succeeded, zero otherwise 787 * @return non-zero if succeeded, zero otherwise
746 */ 788 */
747# define MHD_socket_nosignal_(sock) \ 789# define MHD_socket_nosignal_(sock) \
748 (!setsockopt((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one,sizeof(_MHD_socket_int_one))) 790 (! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one, \
791 sizeof(_MHD_socket_int_one)))
749#endif /* SOL_SOCKET && SO_NOSIGPIPE */ 792#endif /* SOL_SOCKET && SO_NOSIGPIPE */
750 793
751/** 794/**
diff --git a/src/lib/mhd_str.c b/src/lib/mhd_str.c
index d0b03ead..6f2d7b98 100644
--- a/src/lib/mhd_str.c
+++ b/src/lib/mhd_str.c
@@ -117,8 +117,8 @@ _MHD_static_inline bool
117isasciixdigit (char c) 117isasciixdigit (char c)
118{ 118{
119 return isasciidigit (c) || 119 return isasciidigit (c) ||
120 ( (c >= 'A') && (c <= 'F') ) || 120 ( (c >= 'A') && (c <= 'F') ) ||
121 ( (c >= 'a') && (c <= 'f') ); 121 ( (c >= 'a') && (c <= 'f') );
122} 122}
123 123
124 124
@@ -181,7 +181,7 @@ _MHD_static_inline int
181todigitvalue (char c) 181todigitvalue (char c)
182{ 182{
183 if (isasciidigit (c)) 183 if (isasciidigit (c))
184 return (unsigned char)(c - '0'); 184 return (unsigned char) (c - '0');
185 185
186 return -1; 186 return -1;
187} 187}
@@ -198,11 +198,11 @@ _MHD_static_inline int
198toxdigitvalue (char c) 198toxdigitvalue (char c)
199{ 199{
200 if (isasciidigit (c)) 200 if (isasciidigit (c))
201 return (unsigned char)(c - '0'); 201 return (unsigned char) (c - '0');
202 if ( (c >= 'A') && (c <= 'F') ) 202 if ( (c >= 'A') && (c <= 'F') )
203 return (unsigned char)(c - 'A' + 10); 203 return (unsigned char) (c - 'A' + 10);
204 if ( (c >= 'a') && (c <= 'f') ) 204 if ( (c >= 'a') && (c <= 'f') )
205 return (unsigned char)(c - 'a' + 10); 205 return (unsigned char) (c - 'a' + 10);
206 206
207 return -1; 207 return -1;
208} 208}
@@ -216,7 +216,7 @@ toxdigitvalue (char c)
216 * @return boolean true if character is lower case letter, 216 * @return boolean true if character is lower case letter,
217 * boolean false otherwise 217 * boolean false otherwise
218 */ 218 */
219#define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z') 219#define isasciilower(c) (((char) (c)) >= 'a' && ((char) (c)) <= 'z')
220 220
221 221
222/** 222/**
@@ -226,7 +226,7 @@ toxdigitvalue (char c)
226 * @return boolean true if character is upper case letter, 226 * @return boolean true if character is upper case letter,
227 * boolean false otherwise 227 * boolean false otherwise
228 */ 228 */
229#define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z') 229#define isasciiupper(c) (((char) (c)) >= 'A' && ((char) (c)) <= 'Z')
230 230
231 231
232/** 232/**
@@ -236,7 +236,7 @@ toxdigitvalue (char c)
236 * @return boolean true if character is letter, boolean false 236 * @return boolean true if character is letter, boolean false
237 * otherwise 237 * otherwise
238 */ 238 */
239#define isasciialpha(c) (isasciilower(c) || isasciiupper(c)) 239#define isasciialpha(c) (isasciilower (c) || isasciiupper (c))
240 240
241 241
242/** 242/**
@@ -246,7 +246,7 @@ toxdigitvalue (char c)
246 * @return boolean true if character is decimal digit, boolean false 246 * @return boolean true if character is decimal digit, boolean false
247 * otherwise 247 * otherwise
248 */ 248 */
249#define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9') 249#define isasciidigit(c) (((char) (c)) >= '0' && ((char) (c)) <= '9')
250 250
251 251
252/** 252/**
@@ -256,9 +256,9 @@ toxdigitvalue (char c)
256 * @return boolean true if character is hexadecimal digit, 256 * @return boolean true if character is hexadecimal digit,
257 * boolean false otherwise 257 * boolean false otherwise
258 */ 258 */
259#define isasciixdigit(c) (isasciidigit((c)) || \ 259#define isasciixdigit(c) (isasciidigit ((c)) || \
260 (((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \ 260 (((char) (c)) >= 'A' && ((char) (c)) <= 'F') || \
261 (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ) 261 (((char) (c)) >= 'a' && ((char) (c)) <= 'f') )
262 262
263 263
264/** 264/**
@@ -268,7 +268,7 @@ toxdigitvalue (char c)
268 * @return boolean true if character is decimal digit or letter, 268 * @return boolean true if character is decimal digit or letter,
269 * boolean false otherwise 269 * boolean false otherwise
270 */ 270 */
271#define isasciialnum(c) (isasciialpha(c) || isasciidigit(c)) 271#define isasciialnum(c) (isasciialpha (c) || isasciidigit (c))
272 272
273 273
274/** 274/**
@@ -280,7 +280,8 @@ toxdigitvalue (char c)
280 * @param c character to convert 280 * @param c character to convert
281 * @return converted to lower case character 281 * @return converted to lower case character
282 */ 282 */
283#define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c))) 283#define toasciilower(c) ((isasciiupper (c)) ? (((char) (c)) - 'A' + 'a') : \
284 ((char) (c)))
284 285
285 286
286/** 287/**
@@ -292,7 +293,8 @@ toxdigitvalue (char c)
292 * @param c character to convert 293 * @param c character to convert
293 * @return converted to upper case character 294 * @return converted to upper case character
294 */ 295 */
295#define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c))) 296#define toasciiupper(c) ((isasciilower (c)) ? (((char) (c)) - 'a' + 'A') : \
297 ((char) (c)))
296 298
297 299
298/** 300/**
@@ -301,7 +303,8 @@ toxdigitvalue (char c)
301 * @param c character to convert 303 * @param c character to convert
302 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 304 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
303 */ 305 */
304#define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1)) 306#define todigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \
307 (int) (-1))
305 308
306 309
307/** 310/**
@@ -309,11 +312,12 @@ toxdigitvalue (char c)
309 * @param c character to convert 312 * @param c character to convert
310 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 313 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
311 */ 314 */
312#define toxdigitvalue(c) ( isasciidigit(c) ? (int)(((char)(c)) - '0') : \ 315#define toxdigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \
313 ( (((char)(c)) >= 'A' && ((char)(c)) <= 'F') ? \ 316 ( (((char) (c)) >= 'A' && ((char) (c)) <= 'F') ? \
314 (int)(((unsigned char)(c)) - 'A' + 10) : \ 317 (int) (((unsigned char) (c)) - 'A' + 10) : \
315 ( (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ? \ 318 ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \
316 (int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) ))) 319 (int) (((unsigned char) (c)) - 'a' + 10) : \
320 (int) (-1) )))
317#endif /* !INLINE_FUNC */ 321#endif /* !INLINE_FUNC */
318 322
319 323
@@ -326,19 +330,19 @@ toxdigitvalue (char c)
326 * @return non-zero if two strings are equal, zero otherwise. 330 * @return non-zero if two strings are equal, zero otherwise.
327 */ 331 */
328int 332int
329MHD_str_equal_caseless_ (const char * str1, 333MHD_str_equal_caseless_ (const char *str1,
330 const char * str2) 334 const char *str2)
331{ 335{
332 while (0 != (*str1)) 336 while (0 != (*str1))
333 { 337 {
334 const char c1 = *str1; 338 const char c1 = *str1;
335 const char c2 = *str2; 339 const char c2 = *str2;
336 if ( (c1 != c2) && 340 if ( (c1 != c2) &&
337 (toasciilower (c1) != toasciilower (c2)) ) 341 (toasciilower (c1) != toasciilower (c2)) )
338 return 0; 342 return 0;
339 str1++; 343 str1++;
340 str2++; 344 str2++;
341 } 345 }
342 return 0 == (*str2); 346 return 0 == (*str2);
343} 347}
344#endif /* ! MHD_FAVOR_SMALL_CODE */ 348#endif /* ! MHD_FAVOR_SMALL_CODE */
@@ -356,23 +360,23 @@ MHD_str_equal_caseless_ (const char * str1,
356 * @return non-zero if two strings are equal, zero otherwise. 360 * @return non-zero if two strings are equal, zero otherwise.
357 */ 361 */
358int 362int
359MHD_str_equal_caseless_n_ (const char * const str1, 363MHD_str_equal_caseless_n_ (const char *const str1,
360 const char * const str2, 364 const char *const str2,
361 size_t maxlen) 365 size_t maxlen)
362{ 366{
363 size_t i; 367 size_t i;
364 368
365 for (i = 0; i < maxlen; ++i) 369 for (i = 0; i < maxlen; ++i)
366 { 370 {
367 const char c1 = str1[i]; 371 const char c1 = str1[i];
368 const char c2 = str2[i]; 372 const char c2 = str2[i];
369 if (0 == c2) 373 if (0 == c2)
370 return 0 == c1; 374 return 0 == c1;
371 if ( (c1 != c2) && 375 if ( (c1 != c2) &&
372 (toasciilower (c1) != toasciilower (c2)) ) 376 (toasciilower (c1) != toasciilower (c2)) )
373 return 0; 377 return 0;
374 } 378 }
375 return !0; 379 return ! 0;
376} 380}
377 381
378 382
@@ -390,46 +394,49 @@ MHD_str_equal_caseless_n_ (const char * const str1,
390 * @return non-zero if two strings are equal, zero otherwise. 394 * @return non-zero if two strings are equal, zero otherwise.
391 */ 395 */
392bool 396bool
393MHD_str_has_token_caseless_ (const char * str, 397MHD_str_has_token_caseless_ (const char *str,
394 const char * const token, 398 const char *const token,
395 size_t token_len) 399 size_t token_len)
396{ 400{
397 if (0 == token_len) 401 if (0 == token_len)
398 return false; 402 return false;
399 403
400 while (0 != *str) 404 while (0 != *str)
405 {
406 size_t i;
407 /* Skip all whitespaces and empty tokens. */
408 while (' ' == *str || '\t' == *str || ',' == *str)
409 str++;
410
411 /* Check for token match. */
412 i = 0;
413 while (1)
401 { 414 {
402 size_t i; 415 const char sc = *(str++);
403 /* Skip all whitespaces and empty tokens. */ 416 const char tc = token[i++];
404 while (' ' == *str || '\t' == *str || ',' == *str) str++; 417
405 418 if (0 == sc)
406 /* Check for token match. */ 419 return false;
407 i = 0; 420 if ( (sc != tc) &&
408 while (1) 421 (toasciilower (sc) != toasciilower (tc)) )
409 { 422 break;
410 const char sc = *(str++); 423 if (i >= token_len)
411 const char tc = token[i++]; 424 {
412 425 /* Check whether substring match token fully or
413 if (0 == sc) 426 * has additional unmatched chars at tail. */
414 return false; 427 while (' ' == *str || '\t' == *str)
415 if ( (sc != tc) && 428 str++;
416 (toasciilower (sc) != toasciilower (tc)) ) 429 /* End of (sub)string? */
417 break; 430 if ((0 == *str) ||(',' == *str) )
418 if (i >= token_len) 431 return true;
419 { 432 /* Unmatched chars at end of substring. */
420 /* Check whether substring match token fully or 433 break;
421 * has additional unmatched chars at tail. */ 434 }
422 while (' ' == *str || '\t' == *str) str++;
423 /* End of (sub)string? */
424 if (0 == *str || ',' == *str)
425 return true;
426 /* Unmatched chars at end of substring. */
427 break;
428 }
429 }
430 /* Find next substring. */
431 while (0 != *str && ',' != *str) str++;
432 } 435 }
436 /* Find next substring. */
437 while (0 != *str && ',' != *str)
438 str++;
439 }
433 return false; 440 return false;
434} 441}
435 442
@@ -450,25 +457,25 @@ size_t
450MHD_str_to_uint64_ (const char *str, 457MHD_str_to_uint64_ (const char *str,
451 uint64_t *out_val) 458 uint64_t *out_val)
452{ 459{
453 const char * const start = str; 460 const char *const start = str;
454 uint64_t res; 461 uint64_t res;
455 462
456 if (!str || !out_val || !isasciidigit(str[0])) 463 if (! str || ! out_val || ! isasciidigit (str[0]))
457 return 0; 464 return 0;
458 465
459 res = 0; 466 res = 0;
460 do 467 do
461 { 468 {
462 const int digit = (unsigned char)(*str) - '0'; 469 const int digit = (unsigned char) (*str) - '0';
463 if ( (res > (UINT64_MAX / 10)) || 470 if ( (res > (UINT64_MAX / 10)) ||
464 ( (res == (UINT64_MAX / 10)) && 471 ( (res == (UINT64_MAX / 10)) &&
465 ((uint64_t)digit > (UINT64_MAX % 10)) ) ) 472 ((uint64_t) digit > (UINT64_MAX % 10)) ) )
466 return 0; 473 return 0;
467 474
468 res *= 10; 475 res *= 10;
469 res += digit; 476 res += digit;
470 str++; 477 str++;
471 } while (isasciidigit (*str)); 478 } while (isasciidigit (*str));
472 479
473 *out_val = res; 480 *out_val = res;
474 return str - start; 481 return str - start;
@@ -489,34 +496,34 @@ MHD_str_to_uint64_ (const char *str,
489 * then possible to store in uint64_t or @a out_val is NULL 496 * then possible to store in uint64_t or @a out_val is NULL
490 */ 497 */
491size_t 498size_t
492MHD_str_to_uint64_n_ (const char * str, 499MHD_str_to_uint64_n_ (const char *str,
493 size_t maxlen, 500 size_t maxlen,
494 uint64_t *out_val) 501 uint64_t *out_val)
495{ 502{
496 uint64_t res; 503 uint64_t res;
497 size_t i; 504 size_t i;
498 505
499 if (!str || !maxlen || !out_val || !isasciidigit (str[0])) 506 if (! str || ! maxlen || ! out_val || ! isasciidigit (str[0]))
500 return 0; 507 return 0;
501 508
502 res = 0; 509 res = 0;
503 i = 0; 510 i = 0;
504 do 511 do
505 { 512 {
506 const int digit = (unsigned char)str[i] - '0'; 513 const int digit = (unsigned char) str[i] - '0';
507 514
508 if ( (res > (UINT64_MAX / 10)) || 515 if ( (res > (UINT64_MAX / 10)) ||
509 ( (res == (UINT64_MAX / 10)) && 516 ( (res == (UINT64_MAX / 10)) &&
510 ((uint64_t)digit > (UINT64_MAX % 10)) ) ) 517 ((uint64_t) digit > (UINT64_MAX % 10)) ) )
511 return 0; 518 return 0;
512 519
513 res *= 10; 520 res *= 10;
514 res += digit; 521 res += digit;
515 i++; 522 i++;
516 } while ( (i < maxlen) && 523 } while ( (i < maxlen) &&
517 isasciidigit (str[i]) ); 524 isasciidigit (str[i]) );
518 525
519 *out_val= res; 526 *out_val = res;
520 return i; 527 return i;
521} 528}
522 529
@@ -532,31 +539,32 @@ MHD_str_to_uint64_n_ (const char * str,
532 * then possible to store in uint32_t or @a out_val is NULL 539 * then possible to store in uint32_t or @a out_val is NULL
533 */ 540 */
534size_t 541size_t
535MHD_strx_to_uint32_ (const char * str, 542MHD_strx_to_uint32_ (const char *str,
536 uint32_t *out_val) 543 uint32_t *out_val)
537{ 544{
538 const char * const start = str; 545 const char *const start = str;
539 uint32_t res; 546 uint32_t res;
540 int digit; 547 int digit;
541 548
542 if (!str || !out_val) 549 if (! str || ! out_val)
543 return 0; 550 return 0;
544 551
545 res = 0; 552 res = 0;
546 digit = toxdigitvalue (*str); 553 digit = toxdigitvalue (*str);
547 while (digit >= 0) 554 while (digit >= 0)
555 {
556 if ( (res < (UINT32_MAX / 16)) ||
557 ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit <= (UINT32_MAX
558 % 16)) ) )
548 { 559 {
549 if ( (res < (UINT32_MAX / 16)) || 560 res *= 16;
550 (res == (UINT32_MAX / 16) && (uint32_t)digit <= (UINT32_MAX % 16)) ) 561 res += digit;
551 {
552 res *= 16;
553 res += digit;
554 }
555 else
556 return 0;
557 str++;
558 digit = toxdigitvalue (*str);
559 } 562 }
563 else
564 return 0;
565 str++;
566 digit = toxdigitvalue (*str);
567 }
560 568
561 if (str - start > 0) 569 if (str - start > 0)
562 *out_val = res; 570 *out_val = res;
@@ -585,21 +593,22 @@ MHD_strx_to_uint32_n_ (const char *str,
585 size_t i; 593 size_t i;
586 uint32_t res; 594 uint32_t res;
587 int digit; 595 int digit;
588 if (!str || !out_val) 596 if (! str || ! out_val)
589 return 0; 597 return 0;
590 598
591 res = 0; 599 res = 0;
592 i = 0; 600 i = 0;
593 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 601 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
594 { 602 {
595 if ( (res > (UINT32_MAX / 16)) || 603 if ( (res > (UINT32_MAX / 16)) ||
596 (res == (UINT32_MAX / 16) && (uint32_t)digit > (UINT32_MAX % 16)) ) 604 ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit > (UINT32_MAX
597 return 0; 605 % 16)) ) )
606 return 0;
598 607
599 res *= 16; 608 res *= 16;
600 res += digit; 609 res += digit;
601 i++; 610 i++;
602 } 611 }
603 612
604 if (i) 613 if (i)
605 *out_val = res; 614 *out_val = res;
@@ -621,27 +630,28 @@ size_t
621MHD_strx_to_uint64_ (const char *str, 630MHD_strx_to_uint64_ (const char *str,
622 uint64_t *out_val) 631 uint64_t *out_val)
623{ 632{
624 const char * const start = str; 633 const char *const start = str;
625 uint64_t res; 634 uint64_t res;
626 int digit; 635 int digit;
627 if (!str || !out_val) 636 if (! str || ! out_val)
628 return 0; 637 return 0;
629 638
630 res = 0; 639 res = 0;
631 digit = toxdigitvalue (*str); 640 digit = toxdigitvalue (*str);
632 while (digit >= 0) 641 while (digit >= 0)
642 {
643 if ( (res < (UINT64_MAX / 16)) ||
644 ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit <= (UINT64_MAX
645 % 16)) ) )
633 { 646 {
634 if ( (res < (UINT64_MAX / 16)) || 647 res *= 16;
635 (res == (UINT64_MAX / 16) && (uint64_t)digit <= (UINT64_MAX % 16)) ) 648 res += digit;
636 {
637 res *= 16;
638 res += digit;
639 }
640 else
641 return 0;
642 str++;
643 digit = toxdigitvalue (*str);
644 } 649 }
650 else
651 return 0;
652 str++;
653 digit = toxdigitvalue (*str);
654 }
645 655
646 if (str - start > 0) 656 if (str - start > 0)
647 *out_val = res; 657 *out_val = res;
@@ -663,28 +673,29 @@ MHD_strx_to_uint64_ (const char *str,
663 * then possible to store in uint64_t or @a out_val is NULL 673 * then possible to store in uint64_t or @a out_val is NULL
664 */ 674 */
665size_t 675size_t
666MHD_strx_to_uint64_n_ (const char * str, 676MHD_strx_to_uint64_n_ (const char *str,
667 size_t maxlen, 677 size_t maxlen,
668 uint64_t *out_val) 678 uint64_t *out_val)
669{ 679{
670 size_t i; 680 size_t i;
671 uint64_t res; 681 uint64_t res;
672 int digit; 682 int digit;
673 if (!str || !out_val) 683 if (! str || ! out_val)
674 return 0; 684 return 0;
675 685
676 res = 0; 686 res = 0;
677 i = 0; 687 i = 0;
678 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 688 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
679 { 689 {
680 if ( (res > (UINT64_MAX / 16)) || 690 if ( (res > (UINT64_MAX / 16)) ||
681 (res == (UINT64_MAX / 16) && (uint64_t)digit > (UINT64_MAX % 16)) ) 691 ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit > (UINT64_MAX
682 return 0; 692 % 16)) ) )
693 return 0;
683 694
684 res *= 16; 695 res *= 16;
685 res += digit; 696 res += digit;
686 i++; 697 i++;
687 } 698 }
688 699
689 if (i) 700 if (i)
690 *out_val = res; 701 *out_val = res;
@@ -713,7 +724,7 @@ MHD_strx_to_uint64_n_ (const char * str,
713size_t 724size_t
714MHD_str_to_uvalue_n_ (const char *str, 725MHD_str_to_uvalue_n_ (const char *str,
715 size_t maxlen, 726 size_t maxlen,
716 void * out_val, 727 void *out_val,
717 size_t val_size, 728 size_t val_size,
718 uint64_t max_val, 729 uint64_t max_val,
719 int base) 730 int base)
@@ -725,34 +736,34 @@ MHD_str_to_uvalue_n_ (const char *str,
725 const uint64_t max_v_mod_b = max_val % base; 736 const uint64_t max_v_mod_b = max_val % base;
726 /* 'digit->value' must be function, not macro */ 737 /* 'digit->value' must be function, not macro */
727 int (*const dfunc)(char) = (base == 16) ? 738 int (*const dfunc)(char) = (base == 16) ?
728 toxdigitvalue : todigitvalue; 739 toxdigitvalue : todigitvalue;
729 740
730 if ( !str || !out_val || 741 if ( ! str || ! out_val ||
731 (base != 16 && base != 10) ) 742 ((base != 16)&&(base != 10)) )
732 return 0; 743 return 0;
733 744
734 res = 0; 745 res = 0;
735 i = 0; 746 i = 0;
736 while (maxlen > i && 0 <= (digit = dfunc (str[i]))) 747 while (maxlen > i && 0 <= (digit = dfunc (str[i])))
737 { 748 {
738 if ( ((max_v_div_b) < res) || 749 if ( ((max_v_div_b) < res) ||
739 ((max_v_div_b) == res && (max_v_mod_b) < (uint64_t)digit) ) 750 (( (max_v_div_b) == res) &&( (max_v_mod_b) < (uint64_t) digit) ) )
740 return 0; 751 return 0;
741 752
742 res *= base; 753 res *= base;
743 res += digit; 754 res += digit;
744 i++; 755 i++;
745 } 756 }
746 757
747 if (i) 758 if (i)
748 { 759 {
749 if (8 == val_size) 760 if (8 == val_size)
750 *(uint64_t*)out_val = res; 761 *(uint64_t*) out_val = res;
751 else if (4 == val_size) 762 else if (4 == val_size)
752 *(uint32_t*)out_val = (uint32_t)res; 763 *(uint32_t*) out_val = (uint32_t) res;
753 else 764 else
754 return 0; 765 return 0;
755 } 766 }
756 return i; 767 return i;
757} 768}
758#endif /* MHD_FAVOR_SMALL_CODE */ 769#endif /* MHD_FAVOR_SMALL_CODE */
diff --git a/src/lib/mhd_str.h b/src/lib/mhd_str.h
index 410cc36e..f0f6511d 100644
--- a/src/lib/mhd_str.h
+++ b/src/lib/mhd_str.h
@@ -42,7 +42,7 @@
42/** 42/**
43 * Determine length of static string / macro strings at compile time. 43 * Determine length of static string / macro strings at compile time.
44 */ 44 */
45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
46#endif /* ! MHD_STATICSTR_LEN_ */ 46#endif /* ! MHD_STATICSTR_LEN_ */
47 47
48/* 48/*
@@ -58,11 +58,12 @@
58 * @return non-zero if two strings are equal, zero otherwise. 58 * @return non-zero if two strings are equal, zero otherwise.
59 */ 59 */
60int 60int
61MHD_str_equal_caseless_ (const char * str1, 61MHD_str_equal_caseless_ (const char *str1,
62 const char * str2); 62 const char *str2);
63#else /* MHD_FAVOR_SMALL_CODE */ 63#else /* MHD_FAVOR_SMALL_CODE */
64/* Reuse MHD_str_equal_caseless_n_() to reduce size */ 64/* Reuse MHD_str_equal_caseless_n_() to reduce size */
65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_((s1),(s2), SIZE_MAX) 65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
66 SIZE_MAX)
66#endif /* MHD_FAVOR_SMALL_CODE */ 67#endif /* MHD_FAVOR_SMALL_CODE */
67 68
68 69
@@ -77,9 +78,9 @@ MHD_str_equal_caseless_ (const char * str1,
77 * @return non-zero if two strings are equal, zero otherwise. 78 * @return non-zero if two strings are equal, zero otherwise.
78 */ 79 */
79int 80int
80MHD_str_equal_caseless_n_ (const char * const str1, 81MHD_str_equal_caseless_n_ (const char *const str1,
81 const char * const str2, 82 const char *const str2,
82 size_t maxlen); 83 size_t maxlen);
83 84
84 85
85/** 86/**
@@ -96,8 +97,8 @@ MHD_str_equal_caseless_n_ (const char * const str1,
96 * @return non-zero if two strings are equal, zero otherwise. 97 * @return non-zero if two strings are equal, zero otherwise.
97 */ 98 */
98bool 99bool
99MHD_str_has_token_caseless_ (const char * str, 100MHD_str_has_token_caseless_ (const char *str,
100 const char * const token, 101 const char *const token,
101 size_t token_len); 102 size_t token_len);
102 103
103/** 104/**
@@ -111,7 +112,7 @@ MHD_str_has_token_caseless_ (const char * str,
111 * @return non-zero if two strings are equal, zero otherwise. 112 * @return non-zero if two strings are equal, zero otherwise.
112 */ 113 */
113#define MHD_str_has_s_token_caseless_(str,tkn) \ 114#define MHD_str_has_s_token_caseless_(str,tkn) \
114 MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn)) 115 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
115 116
116#ifndef MHD_FAVOR_SMALL_CODE 117#ifndef MHD_FAVOR_SMALL_CODE
117/* Use individual function for each case to improve speed */ 118/* Use individual function for each case to improve speed */
@@ -126,13 +127,13 @@ MHD_str_has_token_caseless_ (const char * str,
126 * then possible to store in uint64_t or @a out_val is NULL 127 * then possible to store in uint64_t or @a out_val is NULL
127 */ 128 */
128size_t 129size_t
129MHD_str_to_uint64_ (const char * str, 130MHD_str_to_uint64_ (const char *str,
130 uint64_t * out_val); 131 uint64_t *out_val);
131 132
132/** 133/**
133 * Convert not more then @a maxlen decimal US-ASCII digits in string to 134 * Convert not more then @a maxlen decimal US-ASCII digits in string to
134 * number in uint64_t. 135 * number in uint64_t.
135 * Conversion stopped at first non-digit character or after @a maxlen 136 * Conversion stopped at first non-digit character or after @a maxlen
136 * digits. 137 * digits.
137 * @param str string to convert 138 * @param str string to convert
138 * @param maxlen maximum number of characters to process 139 * @param maxlen maximum number of characters to process
@@ -142,9 +143,9 @@ MHD_str_to_uint64_ (const char * str,
142 * then possible to store in uint64_t or @a out_val is NULL 143 * then possible to store in uint64_t or @a out_val is NULL
143 */ 144 */
144size_t 145size_t
145MHD_str_to_uint64_n_ (const char * str, 146MHD_str_to_uint64_n_ (const char *str,
146 size_t maxlen, 147 size_t maxlen,
147 uint64_t * out_val); 148 uint64_t *out_val);
148 149
149 150
150/** 151/**
@@ -152,19 +153,19 @@ MHD_str_to_uint64_n_ (const char * str,
152 * Conversion stopped at first non-digit character. 153 * Conversion stopped at first non-digit character.
153 * @param str string to convert 154 * @param str string to convert
154 * @param out_val pointer to uint32_t to store result of conversion 155 * @param out_val pointer to uint32_t to store result of conversion
155 * @return non-zero number of characters processed on succeed, 156 * @return non-zero number of characters processed on succeed,
156 * zero if no digit is found, resulting value is larger 157 * zero if no digit is found, resulting value is larger
157 * then possible to store in uint32_t or @a out_val is NULL 158 * then possible to store in uint32_t or @a out_val is NULL
158 */ 159 */
159size_t 160size_t
160MHD_strx_to_uint32_ (const char * str, 161MHD_strx_to_uint32_ (const char *str,
161 uint32_t * out_val); 162 uint32_t *out_val);
162 163
163 164
164/** 165/**
165 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 166 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
166 * to number in uint32_t. 167 * to number in uint32_t.
167 * Conversion stopped at first non-digit character or after @a maxlen 168 * Conversion stopped at first non-digit character or after @a maxlen
168 * digits. 169 * digits.
169 * @param str string to convert 170 * @param str string to convert
170 * @param maxlen maximum number of characters to process 171 * @param maxlen maximum number of characters to process
@@ -174,9 +175,9 @@ MHD_strx_to_uint32_ (const char * str,
174 * then possible to store in uint32_t or @a out_val is NULL 175 * then possible to store in uint32_t or @a out_val is NULL
175 */ 176 */
176size_t 177size_t
177MHD_strx_to_uint32_n_ (const char * str, 178MHD_strx_to_uint32_n_ (const char *str,
178 size_t maxlen, 179 size_t maxlen,
179 uint32_t * out_val); 180 uint32_t *out_val);
180 181
181 182
182/** 183/**
@@ -184,19 +185,19 @@ MHD_strx_to_uint32_n_ (const char * str,
184 * Conversion stopped at first non-digit character. 185 * Conversion stopped at first non-digit character.
185 * @param str string to convert 186 * @param str string to convert
186 * @param out_val pointer to uint64_t to store result of conversion 187 * @param out_val pointer to uint64_t to store result of conversion
187 * @return non-zero number of characters processed on succeed, 188 * @return non-zero number of characters processed on succeed,
188 * zero if no digit is found, resulting value is larger 189 * zero if no digit is found, resulting value is larger
189 * then possible to store in uint64_t or @a out_val is NULL 190 * then possible to store in uint64_t or @a out_val is NULL
190 */ 191 */
191size_t 192size_t
192MHD_strx_to_uint64_ (const char * str, 193MHD_strx_to_uint64_ (const char *str,
193 uint64_t * out_val); 194 uint64_t *out_val);
194 195
195 196
196/** 197/**
197 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 198 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
198 * to number in uint64_t. 199 * to number in uint64_t.
199 * Conversion stopped at first non-digit character or after @a maxlen 200 * Conversion stopped at first non-digit character or after @a maxlen
200 * digits. 201 * digits.
201 * @param str string to convert 202 * @param str string to convert
202 * @param maxlen maximum number of characters to process 203 * @param maxlen maximum number of characters to process
@@ -206,9 +207,9 @@ MHD_strx_to_uint64_ (const char * str,
206 * then possible to store in uint64_t or @a out_val is NULL 207 * then possible to store in uint64_t or @a out_val is NULL
207 */ 208 */
208size_t 209size_t
209MHD_strx_to_uint64_n_ (const char * str, 210MHD_strx_to_uint64_n_ (const char *str,
210 size_t maxlen, 211 size_t maxlen,
211 uint64_t * out_val); 212 uint64_t *out_val);
212 213
213#else /* MHD_FAVOR_SMALL_CODE */ 214#else /* MHD_FAVOR_SMALL_CODE */
214/* Use one universal function and macros to reduce size */ 215/* Use one universal function and macros to reduce size */
@@ -216,7 +217,7 @@ MHD_strx_to_uint64_n_ (const char * str,
216/** 217/**
217 * Generic function for converting not more then @a maxlen 218 * Generic function for converting not more then @a maxlen
218 * hexadecimal or decimal US-ASCII digits in string to number. 219 * hexadecimal or decimal US-ASCII digits in string to number.
219 * Conversion stopped at first non-digit character or after @a maxlen 220 * Conversion stopped at first non-digit character or after @a maxlen
220 * digits. 221 * digits.
221 * To be used only within macro. 222 * To be used only within macro.
222 * @param str the string to convert 223 * @param str the string to convert
@@ -230,36 +231,44 @@ MHD_strx_to_uint64_n_ (const char * str,
230 * then @ max_val or @a out_val is NULL 231 * then @ max_val or @a out_val is NULL
231 */ 232 */
232size_t 233size_t
233MHD_str_to_uvalue_n_ (const char * str, 234MHD_str_to_uvalue_n_ (const char *str,
234 size_t maxlen, 235 size_t maxlen,
235 void * out_val, 236 void *out_val,
236 size_t val_size, 237 size_t val_size,
237 uint64_t max_val, 238 uint64_t max_val,
238 int base); 239 int base);
239 240
240#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 241#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
241 sizeof(uint64_t),UINT64_MAX,10) 242 sizeof(uint64_t), \
243 UINT64_MAX,10)
242 244
243#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 245#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
244 sizeof(uint64_t),UINT64_MAX,10) 246 sizeof(uint64_t), \
247 UINT64_MAX,10)
245 248
246#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 249#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
247 sizeof(size_t),SIZE_MAX,16) 250 sizeof(size_t),SIZE_MAX, \
251 16)
248 252
249#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 253#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
250 sizeof(size_t),SIZE_MAX,16) 254 sizeof(size_t), \
255 SIZE_MAX,16)
251 256
252#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 257#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
253 sizeof(uint32_t),UINT32_MAX,16) 258 sizeof(uint32_t), \
259 UINT32_MAX,16)
254 260
255#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 261#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
256 sizeof(uint32_t),UINT32_MAX,16) 262 sizeof(uint32_t), \
263 UINT32_MAX,16)
257 264
258#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 265#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
259 sizeof(uint64_t),UINT64_MAX,16) 266 sizeof(uint64_t), \
267 UINT64_MAX,16)
260 268
261#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 269#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
262 sizeof(uint64_t),UINT64_MAX,16) 270 sizeof(uint64_t), \
271 UINT64_MAX,16)
263 272
264#endif /* MHD_FAVOR_SMALL_CODE */ 273#endif /* MHD_FAVOR_SMALL_CODE */
265 274
diff --git a/src/lib/mhd_threads.c b/src/lib/mhd_threads.c
index 6578e4b1..a90090f4 100644
--- a/src/lib/mhd_threads.c
+++ b/src/lib/mhd_threads.c
@@ -46,12 +46,14 @@
46#else /* MHD_USE_THREAD_NAME_ */ 46#else /* MHD_USE_THREAD_NAME_ */
47 47
48#if defined(MHD_USE_POSIX_THREADS) 48#if defined(MHD_USE_POSIX_THREADS)
49#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 49#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
50 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
50# define MHD_USE_THREAD_ATTR_SETNAME 1 51# define MHD_USE_THREAD_ATTR_SETNAME 1
51#endif /* HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD || HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI */ 52#endif /* HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD || HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI */
52 53
53#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ 54#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
54 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 55 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
56 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
55 57
56/** 58/**
57 * Set thread name 59 * Set thread name
@@ -61,25 +63,25 @@
61 * @return non-zero on success, zero otherwise 63 * @return non-zero on success, zero otherwise
62 */ 64 */
63static int 65static int
64MHD_set_thread_name_(const MHD_thread_ID_ thread_id, 66MHD_set_thread_name_ (const MHD_thread_ID_ thread_id,
65 const char *thread_name) 67 const char *thread_name)
66{ 68{
67 if (NULL == thread_name) 69 if (NULL == thread_name)
68 return 0; 70 return 0;
69 71
70#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) 72#if defined(HAVE_PTHREAD_SETNAME_NP_GNU)
71 return !pthread_setname_np (thread_id, thread_name); 73 return ! pthread_setname_np (thread_id, thread_name);
72#elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) 74#elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD)
73 /* FreeBSD and OpenBSD use different name and void return type */ 75 /* FreeBSD and OpenBSD use different name and void return type */
74 pthread_set_name_np (thread_id, thread_name); 76 pthread_set_name_np (thread_id, thread_name);
75 return !0; 77 return ! 0;
76#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 78#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
77 /* NetBSD use 3 arguments: second argument is string in printf-like format, 79 /* NetBSD use 3 arguments: second argument is string in printf-like format,
78 * third argument is single argument for printf; 80 * third argument is single argument for printf;
79 * OSF1 use 3 arguments too, but last one always must be zero (NULL). 81 * OSF1 use 3 arguments too, but last one always must be zero (NULL).
80 * MHD doesn't use '%' in thread names, so both form are used in same way. 82 * MHD doesn't use '%' in thread names, so both form are used in same way.
81 */ 83 */
82 return !pthread_setname_np (thread_id, thread_name, 0); 84 return ! pthread_setname_np (thread_id, thread_name, 0);
83#endif /* HAVE_PTHREAD_SETNAME_NP_NETBSD */ 85#endif /* HAVE_PTHREAD_SETNAME_NP_NETBSD */
84} 86}
85 87
@@ -90,10 +92,10 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
90 * @param n name to set 92 * @param n name to set
91 * @return non-zero on success, zero otherwise 93 * @return non-zero on success, zero otherwise
92 */ 94 */
93#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n)) 95#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n))
94#else /* __QNXNTO__ */ 96#else /* __QNXNTO__ */
95/* Special case for QNX Neutrino - using zero for thread ID sets name faster. */ 97/* Special case for QNX Neutrino - using zero for thread ID sets name faster. */
96#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(0,(n)) 98#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n))
97#endif /* __QNXNTO__ */ 99#endif /* __QNXNTO__ */
98#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) 100#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
99 101
@@ -102,7 +104,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
102 * @param n name to set 104 * @param n name to set
103 * @return non-zero on success, zero otherwise 105 * @return non-zero on success, zero otherwise
104 */ 106 */
105#define MHD_set_cur_thread_name_(n) (!(pthread_setname_np((n)))) 107#define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n))))
106#endif /* HAVE_PTHREAD_SETNAME_NP_DARWIN */ 108#endif /* HAVE_PTHREAD_SETNAME_NP_DARWIN */
107 109
108#elif defined(MHD_USE_W32_THREADS) 110#elif defined(MHD_USE_W32_THREADS)
@@ -117,8 +119,8 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
117 * @return non-zero on success, zero otherwise 119 * @return non-zero on success, zero otherwise
118 */ 120 */
119static int 121static int
120MHD_set_thread_name_(const MHD_thread_ID_ thread_id, 122MHD_set_thread_name_ (const MHD_thread_ID_ thread_id,
121 const char *thread_name) 123 const char *thread_name)
122{ 124{
123 static const DWORD VC_SETNAME_EXC = 0x406D1388; 125 static const DWORD VC_SETNAME_EXC = 0x406D1388;
124#pragma pack(push,8) 126#pragma pack(push,8)
@@ -149,7 +151,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
149 __except (EXCEPTION_EXECUTE_HANDLER) 151 __except (EXCEPTION_EXECUTE_HANDLER)
150 {} 152 {}
151 153
152 return !0; 154 return ! 0;
153} 155}
154 156
155 157
@@ -158,7 +160,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
158 * @param n name to set 160 * @param n name to set
159 * @return non-zero on success, zero otherwise 161 * @return non-zero on success, zero otherwise
160 */ 162 */
161#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(-1,(n)) 163#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
162#endif /* _MSC_FULL_VER */ 164#endif /* _MSC_FULL_VER */
163#endif /* MHD_USE_W32_THREADS */ 165#endif /* MHD_USE_W32_THREADS */
164 166
@@ -184,21 +186,21 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
184 int res; 186 int res;
185 187
186 if (0 != stack_size) 188 if (0 != stack_size)
189 {
190 pthread_attr_t attr;
191 res = pthread_attr_init (&attr);
192 if (0 == res)
187 { 193 {
188 pthread_attr_t attr; 194 res = pthread_attr_setstacksize (&attr,
189 res = pthread_attr_init (&attr); 195 stack_size);
190 if (0 == res) 196 if (0 == res)
191 { 197 res = pthread_create (&(thread->handle),
192 res = pthread_attr_setstacksize (&attr, 198 &attr,
193 stack_size); 199 start_routine,
194 if (0 == res) 200 arg);
195 res = pthread_create (&(thread->handle), 201 pthread_attr_destroy (&attr);
196 &attr,
197 start_routine,
198 arg);
199 pthread_attr_destroy (&attr);
200 }
201 } 202 }
203 }
202 else 204 else
203 res = pthread_create (&(thread->handle), 205 res = pthread_create (&(thread->handle),
204 NULL, 206 NULL,
@@ -208,28 +210,28 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
208 if (0 != res) 210 if (0 != res)
209 errno = res; 211 errno = res;
210 212
211 return !res; 213 return ! res;
212#elif defined(MHD_USE_W32_THREADS) 214#elif defined(MHD_USE_W32_THREADS)
213#if SIZE_MAX != UINT_MAX 215#if SIZE_MAX != UINT_MAX
214 if (stack_size > UINT_MAX) 216 if (stack_size > UINT_MAX)
215 { 217 {
216 errno = EINVAL; 218 errno = EINVAL;
217 return 0; 219 return 0;
218 } 220 }
219#endif /* SIZE_MAX != UINT_MAX */ 221#endif /* SIZE_MAX != UINT_MAX */
220 222
221 thread->handle = (MHD_thread_handle_) 223 thread->handle = (MHD_thread_handle_)
222 _beginthreadex (NULL, 224 _beginthreadex (NULL,
223 (unsigned int) stack_size, 225 (unsigned int) stack_size,
224 start_routine, 226 start_routine,
225 arg, 227 arg,
226 0, 228 0,
227 NULL); 229 NULL);
228 230
229 if ((MHD_thread_handle_)-1 == thread->handle) 231 if ((MHD_thread_handle_) - 1 == thread->handle)
230 return 0; 232 return 0;
231 233
232 return !0; 234 return ! 0;
233#endif 235#endif
234} 236}
235 237
@@ -258,21 +260,21 @@ struct MHD_named_helper_param_
258static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ 260static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
259named_thread_starter (void *data) 261named_thread_starter (void *data)
260{ 262{
261 struct MHD_named_helper_param_ * const param = 263 struct MHD_named_helper_param_ *const param =
262 (struct MHD_named_helper_param_ *) data; 264 (struct MHD_named_helper_param_ *) data;
263 void * arg; 265 void *arg;
264 MHD_THREAD_START_ROUTINE_ thr_func; 266 MHD_THREAD_START_ROUTINE_ thr_func;
265 267
266 if (NULL == data) 268 if (NULL == data)
267 return (MHD_THRD_RTRN_TYPE_)0; 269 return (MHD_THRD_RTRN_TYPE_) 0;
268 270
269 MHD_set_cur_thread_name_ (param->name); 271 MHD_set_cur_thread_name_ (param->name);
270 272
271 arg = param->arg; 273 arg = param->arg;
272 thr_func = param->start_routine; 274 thr_func = param->start_routine;
273 free(data); 275 free (data);
274 276
275 return thr_func(arg); 277 return thr_func (arg);
276} 278}
277#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */ 279#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */
278 280
@@ -289,7 +291,7 @@ named_thread_starter (void *data)
289 */ 291 */
290int 292int
291MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, 293MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
292 const char* thread_name, 294 const char*thread_name,
293 size_t stack_size, 295 size_t stack_size,
294 MHD_THREAD_START_ROUTINE_ start_routine, 296 MHD_THREAD_START_ROUTINE_ start_routine,
295 void *arg) 297 void *arg)
@@ -300,41 +302,41 @@ MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
300 302
301 res = pthread_attr_init (&attr); 303 res = pthread_attr_init (&attr);
302 if (0 == res) 304 if (0 == res)
303 { 305 {
304#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) 306#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
305 /* NetBSD use 3 arguments: second argument is string in printf-like format, 307 /* NetBSD use 3 arguments: second argument is string in printf-like format,
306 * third argument is single argument for printf; 308 * third argument is single argument for printf;
307 * OSF1 use 3 arguments too, but last one always must be zero (NULL). 309 * OSF1 use 3 arguments too, but last one always must be zero (NULL).
308 * MHD doesn't use '%' in thread names, so both form are used in same way. 310 * MHD doesn't use '%' in thread names, so both form are used in same way.
309 */ 311 */
310 res = pthread_attr_setname_np (&attr, thread_name, 0); 312 res = pthread_attr_setname_np (&attr, thread_name, 0);
311#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 313#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
312 res = pthread_attr_setname_np (&attr, thread_name); 314 res = pthread_attr_setname_np (&attr, thread_name);
313#else 315#else
314#error No pthread_attr_setname_np() function. 316#error No pthread_attr_setname_np() function.
315#endif 317#endif
316 if (res == 0 && 0 != stack_size) 318 if ((res == 0) &&(0 != stack_size) )
317 res = pthread_attr_setstacksize (&attr, 319 res = pthread_attr_setstacksize (&attr,
318 stack_size); 320 stack_size);
319 if (0 == res) 321 if (0 == res)
320 res = pthread_create (&(thread->handle), 322 res = pthread_create (&(thread->handle),
321 &attr, 323 &attr,
322 start_routine, 324 start_routine,
323 arg); 325 arg);
324 pthread_attr_destroy (&attr); 326 pthread_attr_destroy (&attr);
325 } 327 }
326 if (0 != res) 328 if (0 != res)
327 errno = res; 329 errno = res;
328 330
329 return !res; 331 return ! res;
330#else /* ! MHD_USE_THREAD_ATTR_SETNAME */ 332#else /* ! MHD_USE_THREAD_ATTR_SETNAME */
331 struct MHD_named_helper_param_ *param; 333 struct MHD_named_helper_param_ *param;
332 334
333 if (NULL == thread_name) 335 if (NULL == thread_name)
334 { 336 {
335 errno = EINVAL; 337 errno = EINVAL;
336 return 0; 338 return 0;
337 } 339 }
338 340
339 param = malloc (sizeof (struct MHD_named_helper_param_)); 341 param = malloc (sizeof (struct MHD_named_helper_param_));
340 if (NULL == param) 342 if (NULL == param)
@@ -347,16 +349,16 @@ MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
347 /* Set thread name in thread itself to avoid problems with 349 /* Set thread name in thread itself to avoid problems with
348 * threads which terminated before name is set in other thread. 350 * threads which terminated before name is set in other thread.
349 */ 351 */
350 if (! MHD_create_thread_(thread, 352 if (! MHD_create_thread_ (thread,
351 stack_size, 353 stack_size,
352 &named_thread_starter, 354 &named_thread_starter,
353 (void*)param)) 355 (void*) param))
354 { 356 {
355 free (param); 357 free (param);
356 return 0; 358 return 0;
357 } 359 }
358 360
359 return !0; 361 return ! 0;
360#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */ 362#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */
361} 363}
362 364
diff --git a/src/lib/mhd_threads.h b/src/lib/mhd_threads.h
index 6d69b9ed..79520d53 100644
--- a/src/lib/mhd_threads.h
+++ b/src/lib/mhd_threads.h
@@ -58,23 +58,26 @@
58 58
59#ifndef MHD_NO_THREAD_NAMES 59#ifndef MHD_NO_THREAD_NAMES
60# if defined(MHD_USE_POSIX_THREADS) 60# if defined(MHD_USE_POSIX_THREADS)
61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \ 61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
62 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \ 62 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \
63 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 63 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \
64 defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \
65 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
66 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
64# define MHD_USE_THREAD_NAME_ 67# define MHD_USE_THREAD_NAME_
65# endif /* HAVE_PTHREAD_SETNAME_NP */ 68# endif /* HAVE_PTHREAD_SETNAME_NP */
66# elif defined(MHD_USE_W32_THREADS) 69# elif defined(MHD_USE_W32_THREADS)
67# ifdef _MSC_FULL_VER 70# ifdef _MSC_FULL_VER
68 /* Thread names only available with VC compiler */ 71/* Thread names only available with VC compiler */
69# define MHD_USE_THREAD_NAME_ 72# define MHD_USE_THREAD_NAME_
70# endif /* _MSC_FULL_VER */ 73# endif /* _MSC_FULL_VER */
71# endif 74# endif
72#endif 75#endif
73 76
74#if defined(MHD_USE_POSIX_THREADS) 77#if defined(MHD_USE_POSIX_THREADS)
75 typedef pthread_t MHD_thread_handle_; 78typedef pthread_t MHD_thread_handle_;
76#elif defined(MHD_USE_W32_THREADS) 79#elif defined(MHD_USE_W32_THREADS)
77 typedef HANDLE MHD_thread_handle_; 80typedef HANDLE MHD_thread_handle_;
78#endif 81#endif
79 82
80#if defined(MHD_USE_POSIX_THREADS) 83#if defined(MHD_USE_POSIX_THREADS)
@@ -86,9 +89,9 @@
86#endif 89#endif
87 90
88#if defined(MHD_USE_POSIX_THREADS) 91#if defined(MHD_USE_POSIX_THREADS)
89 typedef pthread_t MHD_thread_ID_; 92typedef pthread_t MHD_thread_ID_;
90#elif defined(MHD_USE_W32_THREADS) 93#elif defined(MHD_USE_W32_THREADS)
91 typedef DWORD MHD_thread_ID_; 94typedef DWORD MHD_thread_ID_;
92#endif 95#endif
93 96
94/* Depending on implementation, pthread_create() MAY set thread ID into 97/* Depending on implementation, pthread_create() MAY set thread ID into
@@ -100,27 +103,27 @@
100 * to save some resources. */ 103 * to save some resources. */
101#if defined(MHD_USE_POSIX_THREADS) 104#if defined(MHD_USE_POSIX_THREADS)
102# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD 105# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD
103 union _MHD_thread_handle_ID_ 106union _MHD_thread_handle_ID_
104 { 107{
105 MHD_thread_handle_ handle; /**< To be used in other threads */ 108 MHD_thread_handle_ handle; /**< To be used in other threads */
106 MHD_thread_ID_ ID; /**< To be used in thread itself */ 109 MHD_thread_ID_ ID; /**< To be used in thread itself */
107 }; 110};
108 typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 111typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
109# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 112# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
110 struct _MHD_thread_handle_ID_ 113struct _MHD_thread_handle_ID_
111 { 114{
112 MHD_thread_handle_ handle; /**< To be used in other threads */ 115 MHD_thread_handle_ handle; /**< To be used in other threads */
113 MHD_thread_ID_ ID; /**< To be used in thread itself */ 116 MHD_thread_ID_ ID; /**< To be used in thread itself */
114 }; 117};
115 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 118typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
116# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 119# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
117#elif defined(MHD_USE_W32_THREADS) 120#elif defined(MHD_USE_W32_THREADS)
118 struct _MHD_thread_handle_ID_ 121struct _MHD_thread_handle_ID_
119 { 122{
120 MHD_thread_handle_ handle; /**< To be used in other threads */ 123 MHD_thread_handle_ handle; /**< To be used in other threads */
121 MHD_thread_ID_ ID; /**< To be used in thread itself */ 124 MHD_thread_ID_ ID; /**< To be used in thread itself */
122 }; 125};
123 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 126typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
124#endif 127#endif
125 128
126#if defined(MHD_USE_POSIX_THREADS) 129#if defined(MHD_USE_POSIX_THREADS)
@@ -129,14 +132,17 @@
129 * @param thread handle to watch 132 * @param thread handle to watch
130 * @return nonzero on success, zero otherwise 133 * @return nonzero on success, zero otherwise
131 */ 134 */
132#define MHD_join_thread_(thread) (!pthread_join((thread), NULL)) 135#define MHD_join_thread_(thread) (! pthread_join ((thread), NULL))
133#elif defined(MHD_USE_W32_THREADS) 136#elif defined(MHD_USE_W32_THREADS)
134/** 137/**
135 * Wait until specified thread is ended and free thread handle on success. 138 * Wait until specified thread is ended and free thread handle on success.
136 * @param thread handle to watch 139 * @param thread handle to watch
137 * @return nonzero on success, zero otherwise 140 * @return nonzero on success, zero otherwise
138 */ 141 */
139#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0) 142#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject ( \
143 (thread), INFINITE) ? (CloseHandle ( \
144 (thread)), ! 0) : \
145 0)
140#endif 146#endif
141 147
142#if defined(MHD_USE_POSIX_THREADS) 148#if defined(MHD_USE_POSIX_THREADS)
@@ -145,14 +151,14 @@
145 * @param ID thread ID to match 151 * @param ID thread ID to match
146 * @return nonzero on match, zero otherwise 152 * @return nonzero on match, zero otherwise
147 */ 153 */
148#define MHD_thread_ID_match_current_(ID) (pthread_equal((ID), pthread_self())) 154#define MHD_thread_ID_match_current_(ID) (pthread_equal ((ID), pthread_self ()))
149#elif defined(MHD_USE_W32_THREADS) 155#elif defined(MHD_USE_W32_THREADS)
150/** 156/**
151 * Check whether provided thread ID match current thread. 157 * Check whether provided thread ID match current thread.
152 * @param ID thread ID to match 158 * @param ID thread ID to match
153 * @return nonzero on match, zero otherwise 159 * @return nonzero on match, zero otherwise
154 */ 160 */
155#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId() == (ID)) 161#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId () == (ID))
156#endif 162#endif
157 163
158#if defined(MHD_USE_POSIX_THREADS) 164#if defined(MHD_USE_POSIX_THREADS)
@@ -161,20 +167,22 @@
161 * Initialise thread ID. 167 * Initialise thread ID.
162 * @param thread_handle_ID_ptr pointer to thread handle-ID 168 * @param thread_handle_ID_ptr pointer to thread handle-ID
163 */ 169 */
164#define MHD_thread_init_(thread_handle_ID_ptr) (void)0 170#define MHD_thread_init_(thread_handle_ID_ptr) (void) 0
165# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 171# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
166/** 172/**
167 * Initialise thread ID. 173 * Initialise thread ID.
168 * @param thread_handle_ID_ptr pointer to thread handle-ID 174 * @param thread_handle_ID_ptr pointer to thread handle-ID
169 */ 175 */
170#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=pthread_self()) 176#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
177 pthread_self ())
171# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 178# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
172#elif defined(MHD_USE_W32_THREADS) 179#elif defined(MHD_USE_W32_THREADS)
173/** 180/**
174 * Initialise thread ID. 181 * Initialise thread ID.
175 * @param thread_handle_ID_ptr pointer to thread handle-ID 182 * @param thread_handle_ID_ptr pointer to thread handle-ID
176 */ 183 */
177#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=GetCurrentThreadId()) 184#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
185 GetCurrentThreadId ())
178#endif 186#endif
179 187
180/** 188/**
@@ -205,7 +213,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
205 void *arg); 213 void *arg);
206 214
207#ifndef MHD_USE_THREAD_NAME_ 215#ifndef MHD_USE_THREAD_NAME_
208#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_((t),(s),(r),(a)) 216#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_ ((t),(s),(r),(a))
209#else /* MHD_USE_THREAD_NAME_ */ 217#else /* MHD_USE_THREAD_NAME_ */
210/** 218/**
211 * Create a named thread and set the attributes according to our options. 219 * Create a named thread and set the attributes according to our options.
@@ -219,7 +227,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
219 */ 227 */
220int 228int
221MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, 229MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
222 const char* thread_name, 230 const char*thread_name,
223 size_t stack_size, 231 size_t stack_size,
224 MHD_THREAD_START_ROUTINE_ start_routine, 232 MHD_THREAD_START_ROUTINE_ start_routine,
225 void *arg); 233 void *arg);
diff --git a/src/lib/reason_phrase.c b/src/lib/reason_phrase.c
index 97ace0a3..e3692837 100644
--- a/src/lib/reason_phrase.c
+++ b/src/lib/reason_phrase.c
@@ -27,7 +27,7 @@
27#include "internal.h" 27#include "internal.h"
28 28
29#ifndef NULL 29#ifndef NULL
30#define NULL ((void*)0) 30#define NULL ((void*) 0)
31#endif 31#endif
32 32
33static const char *const invalid_hundred[] = { 33static const char *const invalid_hundred[] = {
diff --git a/src/lib/request.c b/src/lib/request.c
index 02cce55c..5b932bfa 100644
--- a/src/lib/request.c
+++ b/src/lib/request.c
@@ -40,9 +40,9 @@
40 */ 40 */
41unsigned int 41unsigned int
42MHD_request_get_values (struct MHD_Request *request, 42MHD_request_get_values (struct MHD_Request *request,
43 enum MHD_ValueKind kind, 43 enum MHD_ValueKind kind,
44 MHD_KeyValueIterator iterator, 44 MHD_KeyValueIterator iterator,
45 void *iterator_cls) 45 void *iterator_cls)
46{ 46{
47 int ret; 47 int ret;
48 struct MHD_HTTP_Header *pos; 48 struct MHD_HTTP_Header *pos;
@@ -51,18 +51,18 @@ MHD_request_get_values (struct MHD_Request *request,
51 for (pos = request->headers_received; 51 for (pos = request->headers_received;
52 NULL != pos; 52 NULL != pos;
53 pos = pos->next) 53 pos = pos->next)
54 {
55 if (0 != (pos->kind & kind))
54 { 56 {
55 if (0 != (pos->kind & kind)) 57 ret++;
56 { 58 if ( (NULL != iterator) &&
57 ret++; 59 (MHD_YES != iterator (iterator_cls,
58 if ( (NULL != iterator) && 60 pos->kind,
59 (MHD_YES != iterator (iterator_cls, 61 pos->header,
60 pos->kind, 62 pos->value)) )
61 pos->header, 63 return ret;
62 pos->value)) )
63 return ret;
64 }
65 } 64 }
65 }
66 return ret; 66 return ret;
67} 67}
68 68
@@ -94,9 +94,9 @@ MHD_request_get_values (struct MHD_Request *request,
94 */ 94 */
95enum MHD_Bool 95enum MHD_Bool
96MHD_request_set_value (struct MHD_Request *request, 96MHD_request_set_value (struct MHD_Request *request,
97 enum MHD_ValueKind kind, 97 enum MHD_ValueKind kind,
98 const char *key, 98 const char *key,
99 const char *value) 99 const char *value)
100{ 100{
101 struct MHD_HTTP_Header *pos; 101 struct MHD_HTTP_Header *pos;
102 102
@@ -111,15 +111,15 @@ MHD_request_set_value (struct MHD_Request *request,
111 pos->next = NULL; 111 pos->next = NULL;
112 /* append 'pos' to the linked list of headers */ 112 /* append 'pos' to the linked list of headers */
113 if (NULL == request->headers_received_tail) 113 if (NULL == request->headers_received_tail)
114 { 114 {
115 request->headers_received = pos; 115 request->headers_received = pos;
116 request->headers_received_tail = pos; 116 request->headers_received_tail = pos;
117 } 117 }
118 else 118 else
119 { 119 {
120 request->headers_received_tail->next = pos; 120 request->headers_received_tail->next = pos;
121 request->headers_received_tail = pos; 121 request->headers_received_tail = pos;
122 } 122 }
123 return MHD_YES; 123 return MHD_YES;
124} 124}
125 125
@@ -136,27 +136,25 @@ MHD_request_set_value (struct MHD_Request *request,
136 */ 136 */
137const char * 137const char *
138MHD_request_lookup_value (struct MHD_Request *request, 138MHD_request_lookup_value (struct MHD_Request *request,
139 enum MHD_ValueKind kind, 139 enum MHD_ValueKind kind,
140 const char *key) 140 const char *key)
141{ 141{
142 struct MHD_HTTP_Header *pos; 142 struct MHD_HTTP_Header *pos;
143 143
144 for (pos = request->headers_received; 144 for (pos = request->headers_received;
145 NULL != pos; 145 NULL != pos;
146 pos = pos->next) 146 pos = pos->next)
147 { 147 {
148 if ((0 != (pos->kind & kind)) && 148 if ((0 != (pos->kind & kind)) &&
149 ( (key == pos->header) || 149 ( (key == pos->header) ||
150 ( (NULL != pos->header) && 150 ( (NULL != pos->header) &&
151 (NULL != key) && 151 (NULL != key) &&
152 (MHD_str_equal_caseless_(key, 152 (MHD_str_equal_caseless_ (key,
153 pos->header))))) 153 pos->header)))))
154 return pos->value; 154 return pos->value;
155 } 155 }
156 return NULL; 156 return NULL;
157} 157}
158 158
159 159
160/* end of request.c */ 160/* end of request.c */
161
162
diff --git a/src/lib/request_info.c b/src/lib/request_info.c
index 5f481d98..51aae075 100644
--- a/src/lib/request_info.c
+++ b/src/lib/request_info.c
@@ -42,11 +42,11 @@
42 */ 42 */
43enum MHD_Bool 43enum MHD_Bool
44MHD_request_get_information_sz (struct MHD_Request *request, 44MHD_request_get_information_sz (struct MHD_Request *request,
45 enum MHD_RequestInformationType info_type, 45 enum MHD_RequestInformationType info_type,
46 union MHD_RequestInformation *return_value, 46 union MHD_RequestInformation *return_value,
47 size_t return_value_size) 47 size_t return_value_size)
48{ 48{
49#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \ 49#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \
50 return MHD_NO 50 return MHD_NO
51 51
52 switch (info_type) 52 switch (info_type)
@@ -70,8 +70,8 @@ MHD_request_get_information_sz (struct MHD_Request *request,
70 case MHD_REQUEST_INFORMATION_HEADER_SIZE: 70 case MHD_REQUEST_INFORMATION_HEADER_SIZE:
71 CHECK_SIZE (size_t); 71 CHECK_SIZE (size_t);
72 if ( (MHD_REQUEST_HEADERS_RECEIVED > request->state) || 72 if ( (MHD_REQUEST_HEADERS_RECEIVED > request->state) ||
73 (MHD_REQUEST_CLOSED == request->state) ) 73 (MHD_REQUEST_CLOSED == request->state) )
74 return MHD_NO; /* invalid, too early! */ 74 return MHD_NO; /* invalid, too early! */
75 return_value->header_size = request->header_size; 75 return_value->header_size = request->header_size;
76 return MHD_YES; 76 return MHD_YES;
77 77
diff --git a/src/lib/request_resume.c b/src/lib/request_resume.c
index a69107b9..be513f53 100644
--- a/src/lib/request_resume.c
+++ b/src/lib/request_resume.c
@@ -45,21 +45,23 @@ MHD_request_resume (struct MHD_Request *request)
45 struct MHD_Daemon *daemon = request->daemon; 45 struct MHD_Daemon *daemon = request->daemon;
46 46
47 if (daemon->disallow_suspend_resume) 47 if (daemon->disallow_suspend_resume)
48 MHD_PANIC (_("Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); 48 MHD_PANIC (_ (
49 "Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
49 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 50 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
50 request->connection->resuming = true; 51 request->connection->resuming = true;
51 daemon->resuming = true; 52 daemon->resuming = true;
52 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 53 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
53 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 54 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
54 (! MHD_itc_activate_ (daemon->itc, 55 (! MHD_itc_activate_ (daemon->itc,
55 "r")) ) 56 "r")) )
56 { 57 {
57#ifdef HAVE_MESSAGES 58#ifdef HAVE_MESSAGES
58 MHD_DLOG (daemon, 59 MHD_DLOG (daemon,
59 MHD_SC_ITC_USE_FAILED, 60 MHD_SC_ITC_USE_FAILED,
60 _("Failed to signal resume via inter-thread communication channel.")); 61 _ (
62 "Failed to signal resume via inter-thread communication channel."));
61#endif 63#endif
62 } 64 }
63} 65}
64 66
65 67
@@ -80,115 +82,118 @@ MHD_resume_suspended_connections_ (struct MHD_Daemon *daemon)
80 struct MHD_Connection *pos; 82 struct MHD_Connection *pos;
81 struct MHD_Connection *prev = NULL; 83 struct MHD_Connection *prev = NULL;
82 bool ret; 84 bool ret;
83 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode); 85 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION ==
86 daemon->threading_mode);
84 87
85 mhd_assert (NULL == daemon->worker_pool); 88 mhd_assert (NULL == daemon->worker_pool);
86 ret = false; 89 ret = false;
87 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 90 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
88 91
89 if (daemon->resuming) 92 if (daemon->resuming)
90 { 93 {
91 prev = daemon->suspended_connections_tail; 94 prev = daemon->suspended_connections_tail;
92 /* During shutdown check for resuming is forced. */ 95 /* During shutdown check for resuming is forced. */
93 mhd_assert((NULL != prev) || (daemon->shutdown)); 96 mhd_assert ((NULL != prev) || (daemon->shutdown));
94 } 97 }
95 98
96 daemon->resuming = false; 99 daemon->resuming = false;
97 100
98 while (NULL != (pos = prev)) 101 while (NULL != (pos = prev))
99 { 102 {
100#ifdef UPGRADE_SUPPORT 103#ifdef UPGRADE_SUPPORT
101 struct MHD_UpgradeResponseHandle * const urh = pos->request.urh; 104 struct MHD_UpgradeResponseHandle *const urh = pos->request.urh;
102#else /* ! UPGRADE_SUPPORT */ 105#else /* ! UPGRADE_SUPPORT */
103 static const void * const urh = NULL; 106 static const void *const urh = NULL;
104#endif /* ! UPGRADE_SUPPORT */ 107#endif /* ! UPGRADE_SUPPORT */
105 prev = pos->prev; 108 prev = pos->prev;
106 if ( (! pos->resuming) 109 if ( (! pos->resuming)
107#ifdef UPGRADE_SUPPORT 110#ifdef UPGRADE_SUPPORT
108 || ( (NULL != urh) && 111 || ( (NULL != urh) &&
109 ( (! urh->was_closed) || 112 ( (! urh->was_closed) ||
110 (! urh->clean_ready) ) ) 113 (! urh->clean_ready) ) )
111#endif /* UPGRADE_SUPPORT */ 114#endif /* UPGRADE_SUPPORT */
112 ) 115 )
113 continue; 116 continue;
114 ret = true; 117 ret = true;
115 mhd_assert (pos->suspended); 118 mhd_assert (pos->suspended);
116 DLL_remove (daemon->suspended_connections_head, 119 DLL_remove (daemon->suspended_connections_head,
117 daemon->suspended_connections_tail, 120 daemon->suspended_connections_tail,
121 pos);
122 pos->suspended = false;
123 if (NULL == urh)
124 {
125 DLL_insert (daemon->connections_head,
126 daemon->connections_tail,
118 pos); 127 pos);
119 pos->suspended = false; 128 if (! used_thr_p_c)
120 if (NULL == urh) 129 {
121 { 130 /* Reset timeout timer on resume. */
122 DLL_insert (daemon->connections_head, 131 if (0 != pos->connection_timeout)
123 daemon->connections_tail, 132 pos->last_activity = MHD_monotonic_sec_counter ();
124 pos); 133
125 if (! used_thr_p_c) 134 if (pos->connection_timeout == daemon->connection_default_timeout)
126 { 135 XDLL_insert (daemon->normal_timeout_head,
127 /* Reset timeout timer on resume. */ 136 daemon->normal_timeout_tail,
128 if (0 != pos->connection_timeout) 137 pos);
129 pos->last_activity = MHD_monotonic_sec_counter(); 138 else
130 139 XDLL_insert (daemon->manual_timeout_head,
131 if (pos->connection_timeout == daemon->connection_default_timeout) 140 daemon->manual_timeout_tail,
132 XDLL_insert (daemon->normal_timeout_head, 141 pos);
133 daemon->normal_timeout_tail, 142 }
134 pos);
135 else
136 XDLL_insert (daemon->manual_timeout_head,
137 daemon->manual_timeout_tail,
138 pos);
139 }
140#ifdef EPOLL_SUPPORT 143#ifdef EPOLL_SUPPORT
141 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 144 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
142 { 145 {
143 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 146 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
144 MHD_PANIC ("Resumed connection was already in EREADY set\n"); 147 MHD_PANIC ("Resumed connection was already in EREADY set\n");
145 /* we always mark resumed connections as ready, as we 148 /* we always mark resumed connections as ready, as we
146 might have missed the edge poll event during suspension */ 149 might have missed the edge poll event during suspension */
147 EDLL_insert (daemon->eready_head, 150 EDLL_insert (daemon->eready_head,
148 daemon->eready_tail, 151 daemon->eready_tail,
149 pos); 152 pos);
150 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL | \ 153 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL \
151 MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY; 154 | MHD_EPOLL_STATE_READ_READY
152 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED; 155 | MHD_EPOLL_STATE_WRITE_READY;
153 } 156 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED;
157 }
154#endif 158#endif
155 } 159 }
156#ifdef UPGRADE_SUPPORT 160#ifdef UPGRADE_SUPPORT
157 else 161 else
158 { 162 {
159 struct MHD_Response *response = pos->request.response; 163 struct MHD_Response *response = pos->request.response;
160 164
161 /* Data forwarding was finished (for TLS connections) AND 165 /* Data forwarding was finished (for TLS connections) AND
162 * application was closed upgraded connection. 166 * application was closed upgraded connection.
163 * Insert connection into cleanup list. */ 167 * Insert connection into cleanup list. */
164 if ( (NULL != response) && 168 if ( (NULL != response) &&
165 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) && 169 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) &&
166 (NULL != response->termination_cb) ) 170 (NULL != response->termination_cb) )
167 response->termination_cb (response->termination_cb_cls, 171 response->termination_cb (response->termination_cb_cls,
168 MHD_REQUEST_TERMINATED_COMPLETED_OK, 172 MHD_REQUEST_TERMINATED_COMPLETED_OK,
169 &pos->request.client_context); 173 &pos->request.client_context);
170 DLL_insert (daemon->cleanup_head, 174 DLL_insert (daemon->cleanup_head,
171 daemon->cleanup_tail, 175 daemon->cleanup_tail,
172 pos); 176 pos);
173 177
174 }
175#endif /* UPGRADE_SUPPORT */
176 pos->resuming = false;
177 } 178 }
179#endif /* UPGRADE_SUPPORT */
180 pos->resuming = false;
181 }
178 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 182 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
179 if ( (used_thr_p_c) && 183 if ( (used_thr_p_c) &&
180 (ret) ) 184 (ret) )
181 { /* Wake up suspended connections. */ 185 { /* Wake up suspended connections. */
182 if (! MHD_itc_activate_(daemon->itc, 186 if (! MHD_itc_activate_ (daemon->itc,
183 "w")) 187 "w"))
184 { 188 {
185#ifdef HAVE_MESSAGES 189#ifdef HAVE_MESSAGES
186 MHD_DLOG (daemon, 190 MHD_DLOG (daemon,
187 MHD_SC_ITC_USE_FAILED, 191 MHD_SC_ITC_USE_FAILED,
188 _("Failed to signal resume of connection via inter-thread communication channel.")); 192 _ (
193 "Failed to signal resume of connection via inter-thread communication channel."));
189#endif 194#endif
190 }
191 } 195 }
196 }
192 return ret; 197 return ret;
193} 198}
194 199
diff --git a/src/lib/request_resume.h b/src/lib/request_resume.h
index d23ff9e8..dad43467 100644
--- a/src/lib/request_resume.h
+++ b/src/lib/request_resume.h
@@ -38,6 +38,6 @@
38 */ 38 */
39bool 39bool
40MHD_resume_suspended_connections_ (struct MHD_Daemon *daemon) 40MHD_resume_suspended_connections_ (struct MHD_Daemon *daemon)
41 MHD_NONNULL(1); 41MHD_NONNULL (1);
42 42
43#endif 43#endif
diff --git a/src/lib/response.c b/src/lib/response.c
index ff23c7fd..47dd98d6 100644
--- a/src/lib/response.c
+++ b/src/lib/response.c
@@ -38,9 +38,9 @@
38 */ 38 */
39static bool 39static bool
40add_response_entry (struct MHD_Response *response, 40add_response_entry (struct MHD_Response *response,
41 enum MHD_ValueKind kind, 41 enum MHD_ValueKind kind,
42 const char *header, 42 const char *header,
43 const char *content) 43 const char *content)
44{ 44{
45 struct MHD_HTTP_Header *hdr; 45 struct MHD_HTTP_Header *hdr;
46 46
@@ -58,16 +58,16 @@ add_response_entry (struct MHD_Response *response,
58 if (NULL == (hdr = malloc (sizeof (struct MHD_HTTP_Header)))) 58 if (NULL == (hdr = malloc (sizeof (struct MHD_HTTP_Header))))
59 return false; 59 return false;
60 if (NULL == (hdr->header = strdup (header))) 60 if (NULL == (hdr->header = strdup (header)))
61 { 61 {
62 free (hdr); 62 free (hdr);
63 return false; 63 return false;
64 } 64 }
65 if (NULL == (hdr->value = strdup (content))) 65 if (NULL == (hdr->value = strdup (content)))
66 { 66 {
67 free (hdr->header); 67 free (hdr->header);
68 free (hdr); 68 free (hdr);
69 return false; 69 return false;
70 } 70 }
71 hdr->kind = kind; 71 hdr->kind = kind;
72 hdr->next = response->first_header; 72 hdr->next = response->first_header;
73 response->first_header = hdr; 73 response->first_header = hdr;
@@ -91,22 +91,22 @@ MHD_response_queue_for_destroy (struct MHD_Response *response)
91 91
92 MHD_mutex_lock_chk_ (&response->mutex); 92 MHD_mutex_lock_chk_ (&response->mutex);
93 if (0 != --(response->reference_count)) 93 if (0 != --(response->reference_count))
94 { 94 {
95 MHD_mutex_unlock_chk_ (&response->mutex); 95 MHD_mutex_unlock_chk_ (&response->mutex);
96 return; 96 return;
97 } 97 }
98 MHD_mutex_unlock_chk_ (&response->mutex); 98 MHD_mutex_unlock_chk_ (&response->mutex);
99 MHD_mutex_destroy_chk_ (&response->mutex); 99 MHD_mutex_destroy_chk_ (&response->mutex);
100 if (NULL != response->crfc) 100 if (NULL != response->crfc)
101 response->crfc (response->crc_cls); 101 response->crfc (response->crc_cls);
102 while (NULL != response->first_header) 102 while (NULL != response->first_header)
103 { 103 {
104 pos = response->first_header; 104 pos = response->first_header;
105 response->first_header = pos->next; 105 response->first_header = pos->next;
106 free (pos->header); 106 free (pos->header);
107 free (pos->value); 107 free (pos->value);
108 free (pos); 108 free (pos);
109 } 109 }
110 free (response); 110 free (response);
111} 111}
112 112
@@ -124,12 +124,12 @@ MHD_response_queue_for_destroy (struct MHD_Response *response)
124enum MHD_Bool 124enum MHD_Bool
125MHD_response_add_header (struct MHD_Response *response, 125MHD_response_add_header (struct MHD_Response *response,
126 const char *header, 126 const char *header,
127 const char *content) 127 const char *content)
128{ 128{
129 return add_response_entry (response, 129 return add_response_entry (response,
130 MHD_HEADER_KIND, 130 MHD_HEADER_KIND,
131 header, 131 header,
132 content) ? MHD_YES : MHD_NO; 132 content) ? MHD_YES : MHD_NO;
133} 133}
134 134
135 135
@@ -149,9 +149,9 @@ MHD_response_add_trailer (struct MHD_Response *response,
149 const char *content) 149 const char *content)
150{ 150{
151 return add_response_entry (response, 151 return add_response_entry (response,
152 MHD_FOOTER_KIND, 152 MHD_FOOTER_KIND,
153 footer, 153 footer,
154 content) ? MHD_YES : MHD_NO; 154 content) ? MHD_YES : MHD_NO;
155} 155}
156 156
157 157
@@ -167,7 +167,7 @@ MHD_response_add_trailer (struct MHD_Response *response,
167enum MHD_Bool 167enum MHD_Bool
168MHD_response_del_header (struct MHD_Response *response, 168MHD_response_del_header (struct MHD_Response *response,
169 const char *header, 169 const char *header,
170 const char *content) 170 const char *content)
171{ 171{
172 struct MHD_HTTP_Header *pos; 172 struct MHD_HTTP_Header *pos;
173 struct MHD_HTTP_Header *prev; 173 struct MHD_HTTP_Header *prev;
@@ -175,24 +175,24 @@ MHD_response_del_header (struct MHD_Response *response,
175 prev = NULL; 175 prev = NULL;
176 pos = response->first_header; 176 pos = response->first_header;
177 while (NULL != pos) 177 while (NULL != pos)
178 {
179 if ((0 == strcmp (header,
180 pos->header)) &&
181 (0 == strcmp (content,
182 pos->value)))
178 { 183 {
179 if ((0 == strcmp (header, 184 free (pos->header);
180 pos->header)) && 185 free (pos->value);
181 (0 == strcmp (content, 186 if (NULL == prev)
182 pos->value))) 187 response->first_header = pos->next;
183 { 188 else
184 free (pos->header); 189 prev->next = pos->next;
185 free (pos->value); 190 free (pos);
186 if (NULL == prev) 191 return MHD_YES;
187 response->first_header = pos->next;
188 else
189 prev->next = pos->next;
190 free (pos);
191 return MHD_YES;
192 }
193 prev = pos;
194 pos = pos->next;
195 } 192 }
193 prev = pos;
194 pos = pos->next;
195 }
196 return MHD_NO; 196 return MHD_NO;
197} 197}
198 198
@@ -210,7 +210,7 @@ MHD_response_del_header (struct MHD_Response *response,
210unsigned int 210unsigned int
211MHD_response_get_headers (struct MHD_Response *response, 211MHD_response_get_headers (struct MHD_Response *response,
212 MHD_KeyValueIterator iterator, 212 MHD_KeyValueIterator iterator,
213 void *iterator_cls) 213 void *iterator_cls)
214{ 214{
215 unsigned int numHeaders = 0; 215 unsigned int numHeaders = 0;
216 struct MHD_HTTP_Header *pos; 216 struct MHD_HTTP_Header *pos;
@@ -218,15 +218,15 @@ MHD_response_get_headers (struct MHD_Response *response,
218 for (pos = response->first_header; 218 for (pos = response->first_header;
219 NULL != pos; 219 NULL != pos;
220 pos = pos->next) 220 pos = pos->next)
221 { 221 {
222 numHeaders++; 222 numHeaders++;
223 if ( (NULL != iterator) && 223 if ( (NULL != iterator) &&
224 (MHD_YES != iterator (iterator_cls, 224 (MHD_YES != iterator (iterator_cls,
225 pos->kind, 225 pos->kind,
226 pos->header, 226 pos->header,
227 pos->value)) ) 227 pos->value)) )
228 break; 228 break;
229 } 229 }
230 return numHeaders; 230 return numHeaders;
231} 231}
232 232
@@ -241,18 +241,18 @@ MHD_response_get_headers (struct MHD_Response *response,
241 */ 241 */
242const char * 242const char *
243MHD_response_get_header (struct MHD_Response *response, 243MHD_response_get_header (struct MHD_Response *response,
244 const char *key) 244 const char *key)
245{ 245{
246 struct MHD_HTTP_Header *pos; 246 struct MHD_HTTP_Header *pos;
247 247
248 for (pos = response->first_header; 248 for (pos = response->first_header;
249 NULL != pos; 249 NULL != pos;
250 pos = pos->next) 250 pos = pos->next)
251 { 251 {
252 if (MHD_str_equal_caseless_ (pos->header, 252 if (MHD_str_equal_caseless_ (pos->header,
253 key)) 253 key))
254 return pos->value; 254 return pos->value;
255 } 255 }
256 return NULL; 256 return NULL;
257} 257}
258 258
diff --git a/src/lib/response_for_upgrade.c b/src/lib/response_for_upgrade.c
index 0d843b8e..ef66b029 100644
--- a/src/lib/response_for_upgrade.c
+++ b/src/lib/response_for_upgrade.c
@@ -57,21 +57,21 @@
57 */ 57 */
58struct MHD_Response * 58struct MHD_Response *
59MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, 59MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
60 void *upgrade_handler_cls) 60 void *upgrade_handler_cls)
61{ 61{
62#ifdef UPGRADE_SUPPORT 62#ifdef UPGRADE_SUPPORT
63 struct MHD_Response *response; 63 struct MHD_Response *response;
64 64
65 mhd_assert (NULL != upgrade_handler); 65 mhd_assert (NULL != upgrade_handler);
66 response = MHD_calloc_ (1, 66 response = MHD_calloc_ (1,
67 sizeof (struct MHD_Response)); 67 sizeof (struct MHD_Response));
68 if (NULL == response) 68 if (NULL == response)
69 return NULL; 69 return NULL;
70 if (! MHD_mutex_init_ (&response->mutex)) 70 if (! MHD_mutex_init_ (&response->mutex))
71 { 71 {
72 free (response); 72 free (response);
73 return NULL; 73 return NULL;
74 } 74 }
75 response->upgrade_handler = upgrade_handler; 75 response->upgrade_handler = upgrade_handler;
76 response->upgrade_handler_cls = upgrade_handler_cls; 76 response->upgrade_handler_cls = upgrade_handler_cls;
77 response->status_code = MHD_HTTP_SWITCHING_PROTOCOLS; 77 response->status_code = MHD_HTTP_SWITCHING_PROTOCOLS;
@@ -81,10 +81,10 @@ MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
81 MHD_response_add_header (response, 81 MHD_response_add_header (response,
82 MHD_HTTP_HEADER_CONNECTION, 82 MHD_HTTP_HEADER_CONNECTION,
83 "Upgrade")) 83 "Upgrade"))
84 { 84 {
85 MHD_response_queue_for_destroy (response); 85 MHD_response_queue_for_destroy (response);
86 return NULL; 86 return NULL;
87 } 87 }
88 return response; 88 return response;
89#else 89#else
90 return NULL; 90 return NULL;
diff --git a/src/lib/response_from_buffer.c b/src/lib/response_from_buffer.c
index a53537b0..a65a0298 100644
--- a/src/lib/response_from_buffer.c
+++ b/src/lib/response_from_buffer.c
@@ -39,44 +39,44 @@
39 */ 39 */
40struct MHD_Response * 40struct MHD_Response *
41MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc, 41MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc,
42 size_t size, 42 size_t size,
43 void *buffer, 43 void *buffer,
44 enum MHD_ResponseMemoryMode mode) 44 enum MHD_ResponseMemoryMode mode)
45{ 45{
46 struct MHD_Response *response; 46 struct MHD_Response *response;
47 void *tmp; 47 void *tmp;
48 48
49 mhd_assert ( (NULL != buffer) || 49 mhd_assert ( (NULL != buffer) ||
50 (0 == size) ); 50 (0 == size) );
51 if (NULL == 51 if (NULL ==
52 (response = MHD_calloc_ (1, 52 (response = MHD_calloc_ (1,
53 sizeof (struct MHD_Response)))) 53 sizeof (struct MHD_Response))))
54 return NULL; 54 return NULL;
55 response->fd = -1; 55 response->fd = -1;
56 if (! MHD_mutex_init_ (&response->mutex)) 56 if (! MHD_mutex_init_ (&response->mutex))
57 { 57 {
58 free (response); 58 free (response);
59 return NULL; 59 return NULL;
60 } 60 }
61 if ( (MHD_RESPMEM_MUST_COPY == mode) && 61 if ( (MHD_RESPMEM_MUST_COPY == mode) &&
62 (size > 0) ) 62 (size > 0) )
63 {
64 if (NULL == (tmp = malloc (size)))
63 { 65 {
64 if (NULL == (tmp = malloc (size))) 66 MHD_mutex_destroy_chk_ (&response->mutex);
65 { 67 free (response);
66 MHD_mutex_destroy_chk_ (&response->mutex); 68 return NULL;
67 free (response);
68 return NULL;
69 }
70 memcpy (tmp,
71 buffer,
72 size);
73 buffer = tmp;
74 } 69 }
70 memcpy (tmp,
71 buffer,
72 size);
73 buffer = tmp;
74 }
75 if (MHD_RESPMEM_PERSISTENT != mode) 75 if (MHD_RESPMEM_PERSISTENT != mode)
76 { 76 {
77 response->crfc = &free; 77 response->crfc = &free;
78 response->crc_cls = buffer; 78 response->crc_cls = buffer;
79 } 79 }
80 response->status_code = sc; 80 response->status_code = sc;
81 response->reference_count = 1; 81 response->reference_count = 1;
82 response->total_size = size; 82 response->total_size = size;
diff --git a/src/lib/response_from_callback.c b/src/lib/response_from_callback.c
index 1fd65bf0..e00033ce 100644
--- a/src/lib/response_from_callback.c
+++ b/src/lib/response_from_callback.c
@@ -44,11 +44,11 @@
44 */ 44 */
45struct MHD_Response * 45struct MHD_Response *
46MHD_response_from_callback (enum MHD_HTTP_StatusCode sc, 46MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
47 uint64_t size, 47 uint64_t size,
48 size_t block_size, 48 size_t block_size,
49 MHD_ContentReaderCallback crc, 49 MHD_ContentReaderCallback crc,
50 void *crc_cls, 50 void *crc_cls,
51 MHD_ContentReaderFreeCallback crfc) 51 MHD_ContentReaderFreeCallback crfc)
52{ 52{
53 struct MHD_Response *response; 53 struct MHD_Response *response;
54 54
@@ -56,8 +56,8 @@ MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
56 mhd_assert (0 != block_size); 56 mhd_assert (0 != block_size);
57 if (NULL == 57 if (NULL ==
58 (response = MHD_calloc_ (1, 58 (response = MHD_calloc_ (1,
59 sizeof (struct MHD_Response) + 59 sizeof (struct MHD_Response)
60 block_size))) 60 + block_size)))
61 return NULL; 61 return NULL;
62 response->fd = -1; 62 response->fd = -1;
63 response->status_code = sc; 63 response->status_code = sc;
diff --git a/src/lib/response_from_fd.c b/src/lib/response_from_fd.c
index ac0a54d1..ffeb2b91 100644
--- a/src/lib/response_from_fd.c
+++ b/src/lib/response_from_fd.c
@@ -57,34 +57,34 @@ file_reader (void *cls,
57 size_t max) 57 size_t max)
58{ 58{
59 struct MHD_Response *response = cls; 59 struct MHD_Response *response = cls;
60#if !defined(_WIN32) || defined(__CYGWIN__) 60#if ! defined(_WIN32) || defined(__CYGWIN__)
61 ssize_t n; 61 ssize_t n;
62#else /* _WIN32 && !__CYGWIN__ */ 62#else /* _WIN32 && !__CYGWIN__ */
63 const HANDLE fh = (HANDLE) _get_osfhandle (response->fd); 63 const HANDLE fh = (HANDLE) _get_osfhandle (response->fd);
64#endif /* _WIN32 && !__CYGWIN__ */ 64#endif /* _WIN32 && !__CYGWIN__ */
65 const int64_t offset64 = (int64_t)(pos + response->fd_off); 65 const int64_t offset64 = (int64_t) (pos + response->fd_off);
66 66
67 if (offset64 < 0) 67 if (offset64 < 0)
68 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 68 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
69 69
70#if !defined(_WIN32) || defined(__CYGWIN__) 70#if ! defined(_WIN32) || defined(__CYGWIN__)
71 if (max > SSIZE_MAX) 71 if (max > SSIZE_MAX)
72 max = SSIZE_MAX; /* Clamp to maximum return value. */ 72 max = SSIZE_MAX; /* Clamp to maximum return value. */
73 73
74#if defined(HAVE_PREAD64) 74#if defined(HAVE_PREAD64)
75 n = pread64 (response->fd, 75 n = pread64 (response->fd,
76 buf, 76 buf,
77 max, 77 max,
78 offset64); 78 offset64);
79#elif defined(HAVE_PREAD) 79#elif defined(HAVE_PREAD)
80 if ( (sizeof(off_t) < sizeof (uint64_t)) && 80 if ( (sizeof(off_t) < sizeof (uint64_t)) &&
81 (offset64 > (uint64_t)INT32_MAX) ) 81 (offset64 > (uint64_t) INT32_MAX) )
82 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read at required position is not possible. */ 82 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read at required position is not possible. */
83 83
84 n = pread (response->fd, 84 n = pread (response->fd,
85 buf, 85 buf,
86 max, 86 max,
87 (off_t) offset64); 87 (off_t) offset64);
88#else /* ! HAVE_PREAD */ 88#else /* ! HAVE_PREAD */
89#if defined(HAVE_LSEEK64) 89#if defined(HAVE_LSEEK64)
90 if (lseek64 (response->fd, 90 if (lseek64 (response->fd,
@@ -93,7 +93,7 @@ file_reader (void *cls,
93 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */ 93 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */
94#else /* ! HAVE_LSEEK64 */ 94#else /* ! HAVE_LSEEK64 */
95 if ( (sizeof(off_t) < sizeof (uint64_t)) && 95 if ( (sizeof(off_t) < sizeof (uint64_t)) &&
96 (offset64 > (uint64_t)INT32_MAX) ) 96 (offset64 > (uint64_t) INT32_MAX) )
97 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 97 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
98 98
99 if (lseek (response->fd, 99 if (lseek (response->fd,
@@ -115,25 +115,25 @@ file_reader (void *cls,
115 if (INVALID_HANDLE_VALUE == fh) 115 if (INVALID_HANDLE_VALUE == fh)
116 return MHD_CONTENT_READER_END_WITH_ERROR; /* Value of 'response->fd' is not valid. */ 116 return MHD_CONTENT_READER_END_WITH_ERROR; /* Value of 'response->fd' is not valid. */
117 else 117 else
118 { 118 {
119 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0}; /* Initialize to zero. */ 119 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0}; /* Initialize to zero. */
120 ULARGE_INTEGER pos_uli; 120 ULARGE_INTEGER pos_uli;
121 DWORD toRead = (max > INT32_MAX) ? INT32_MAX : (DWORD) max; 121 DWORD toRead = (max > INT32_MAX) ? INT32_MAX : (DWORD) max;
122 DWORD resRead; 122 DWORD resRead;
123 123
124 pos_uli.QuadPart = (uint64_t) offset64; /* Simple transformation 64bit -> 2x32bit. */ 124 pos_uli.QuadPart = (uint64_t) offset64; /* Simple transformation 64bit -> 2x32bit. */
125 f_ol.Offset = pos_uli.LowPart; 125 f_ol.Offset = pos_uli.LowPart;
126 f_ol.OffsetHigh = pos_uli.HighPart; 126 f_ol.OffsetHigh = pos_uli.HighPart;
127 if (! ReadFile (fh, 127 if (! ReadFile (fh,
128 (void*)buf, 128 (void*) buf,
129 toRead, 129 toRead,
130 &resRead, 130 &resRead,
131 &f_ol)) 131 &f_ol))
132 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read error. */ 132 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read error. */
133 if (0 == resRead) 133 if (0 == resRead)
134 return MHD_CONTENT_READER_END_OF_STREAM; 134 return MHD_CONTENT_READER_END_OF_STREAM;
135 return (ssize_t) resRead; 135 return (ssize_t) resRead;
136 } 136 }
137#endif /* _WIN32 && !__CYGWIN__ */ 137#endif /* _WIN32 && !__CYGWIN__ */
138} 138}
139 139
@@ -174,18 +174,18 @@ free_callback (void *cls)
174 */ 174 */
175struct MHD_Response * 175struct MHD_Response *
176MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, 176MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
177 int fd, 177 int fd,
178 uint64_t offset, 178 uint64_t offset,
179 uint64_t size) 179 uint64_t size)
180{ 180{
181 struct MHD_Response *response; 181 struct MHD_Response *response;
182 182
183 mhd_assert (-1 != fd); 183 mhd_assert (-1 != fd);
184#if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 184#if ! defined(HAVE___LSEEKI64) && ! defined(HAVE_LSEEK64)
185 if ( (sizeof (uint64_t) > sizeof (off_t)) && 185 if ( (sizeof (uint64_t) > sizeof (off_t)) &&
186 ( (size > (uint64_t)INT32_MAX) || 186 ( (size > (uint64_t) INT32_MAX) ||
187 (offset > (uint64_t)INT32_MAX) || 187 (offset > (uint64_t) INT32_MAX) ||
188 ((size + offset) >= (uint64_t)INT32_MAX) ) ) 188 ((size + offset) >= (uint64_t) INT32_MAX) ) )
189 return NULL; 189 return NULL;
190#endif 190#endif
191 if ( ((int64_t) size < 0) || 191 if ( ((int64_t) size < 0) ||
@@ -194,11 +194,11 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
194 return NULL; 194 return NULL;
195 195
196 response = MHD_response_from_callback (sc, 196 response = MHD_response_from_callback (sc,
197 size, 197 size,
198 MHD_FILE_READ_BLOCK_SIZE, 198 MHD_FILE_READ_BLOCK_SIZE,
199 &file_reader, 199 &file_reader,
200 NULL, 200 NULL,
201 &free_callback); 201 &free_callback);
202 if (NULL == response) 202 if (NULL == response)
203 return NULL; 203 return NULL;
204 response->fd = fd; 204 response->fd = fd;
@@ -208,4 +208,3 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
208} 208}
209 209
210/* end of response_from_fd.c */ 210/* end of response_from_fd.c */
211
diff --git a/src/lib/response_options.c b/src/lib/response_options.c
index 406d1d32..e349627a 100644
--- a/src/lib/response_options.c
+++ b/src/lib/response_options.c
@@ -49,8 +49,9 @@ MHD_response_option_v10_only (struct MHD_Response *response)
49 */ 49 */
50void 50void
51MHD_response_option_termination_callback (struct MHD_Response *response, 51MHD_response_option_termination_callback (struct MHD_Response *response,
52 MHD_RequestTerminationCallback termination_cb, 52 MHD_RequestTerminationCallback
53 void *termination_cb_cls) 53 termination_cb,
54 void *termination_cb_cls)
54{ 55{
55 /* Q: should we assert termination_cb non-NULL? */ 56 /* Q: should we assert termination_cb non-NULL? */
56 response->termination_cb = termination_cb; 57 response->termination_cb = termination_cb;
diff --git a/src/lib/sysfdsetsize.c b/src/lib/sysfdsetsize.c
index fe7fba75..4929b3d2 100644
--- a/src/lib/sysfdsetsize.c
+++ b/src/lib/sysfdsetsize.c
@@ -56,7 +56,7 @@
56#include <sys/socket.h> 56#include <sys/socket.h>
57#endif /* HAVE_SYS_SOCKET_H */ 57#endif /* HAVE_SYS_SOCKET_H */
58 58
59#if defined(_WIN32) && !defined(__CYGWIN__) 59#if defined(_WIN32) && ! defined(__CYGWIN__)
60#ifndef WIN32_LEAN_AND_MEAN 60#ifndef WIN32_LEAN_AND_MEAN
61#define WIN32_LEAN_AND_MEAN 1 61#define WIN32_LEAN_AND_MEAN 1
62#endif /* !WIN32_LEAN_AND_MEAN */ 62#endif /* !WIN32_LEAN_AND_MEAN */
diff --git a/src/lib/tsearch.c b/src/lib/tsearch.c
index fe5fcd5b..e43d758f 100644
--- a/src/lib/tsearch.c
+++ b/src/lib/tsearch.c
@@ -13,7 +13,7 @@
13#include <stdlib.h> 13#include <stdlib.h>
14 14
15 15
16typedef struct node 16typedef struct node
17{ 17{
18 const void *key; 18 const void *key;
19 struct node *llink; 19 struct node *llink;
@@ -24,35 +24,35 @@ typedef struct node
24/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ 24/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */
25/* find or insert datum into search tree */ 25/* find or insert datum into search tree */
26void * 26void *
27tsearch (const void *vkey, /* key to be located */ 27tsearch (const void *vkey, /* key to be located */
28 void **vrootp, /* address of tree root */ 28 void **vrootp, /* address of tree root */
29 int (*compar)(const void *, const void *)) 29 int (*compar)(const void *, const void *))
30{ 30{
31 node_t *q; 31 node_t *q;
32 node_t **rootp = (node_t **)vrootp; 32 node_t **rootp = (node_t **) vrootp;
33 33
34 if (NULL == rootp) 34 if (NULL == rootp)
35 return NULL; 35 return NULL;
36 36
37 while (*rootp != NULL) 37 while (*rootp != NULL)
38 { /* Knuth's T1: */ 38 { /* Knuth's T1: */
39 int r; 39 int r;
40 40
41 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 41 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
42 return *rootp; /* we found it! */ 42 return *rootp; /* we found it! */
43 43
44 rootp = (r < 0) ? 44 rootp = (r < 0) ?
45 &(*rootp)->llink : /* T3: follow left branch */ 45 &(*rootp)->llink : /* T3: follow left branch */
46 &(*rootp)->rlink; /* T4: follow right branch */ 46 &(*rootp)->rlink; /* T4: follow right branch */
47 } 47 }
48 48
49 q = malloc (sizeof(node_t)); /* T5: key not found */ 49 q = malloc (sizeof(node_t)); /* T5: key not found */
50 if (q) 50 if (q)
51 { /* make new node */ 51 { /* make new node */
52 *rootp = q; /* link new node to old */ 52 *rootp = q; /* link new node to old */
53 q->key = vkey; /* initialize new node */ 53 q->key = vkey; /* initialize new node */
54 q->llink = q->rlink = NULL; 54 q->llink = q->rlink = NULL;
55 } 55 }
56 return q; 56 return q;
57} 57}
58 58
@@ -61,24 +61,24 @@ tsearch (const void *vkey, /* key to be located */
61/* find a node, or return NULL */ 61/* find a node, or return NULL */
62void * 62void *
63tfind (const void *vkey, /* key to be found */ 63tfind (const void *vkey, /* key to be found */
64 void * const *vrootp, /* address of the tree root */ 64 void *const *vrootp, /* address of the tree root */
65 int (*compar)(const void *, const void *)) 65 int (*compar)(const void *, const void *))
66{ 66{
67 node_t * const *rootp = (node_t * const*)vrootp; 67 node_t *const *rootp = (node_t *const*) vrootp;
68 68
69 if (NULL == rootp) 69 if (NULL == rootp)
70 return NULL; 70 return NULL;
71 71
72 while (*rootp != NULL) 72 while (*rootp != NULL)
73 { /* T1: */ 73 { /* T1: */
74 int r; 74 int r;
75 75
76 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 76 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
77 return *rootp; /* key found */ 77 return *rootp; /* key found */
78 rootp = (r < 0) ? 78 rootp = (r < 0) ?
79 &(*rootp)->llink : /* T3: follow left branch */ 79 &(*rootp)->llink : /* T3: follow left branch */
80 &(*rootp)->rlink; /* T4: follow right branch */ 80 &(*rootp)->rlink; /* T4: follow right branch */
81 } 81 }
82 return NULL; 82 return NULL;
83} 83}
84 84
@@ -92,51 +92,51 @@ tfind (const void *vkey, /* key to be found */
92 * compar: function to carry out node comparisons 92 * compar: function to carry out node comparisons
93 */ 93 */
94void * 94void *
95tdelete (const void * __restrict vkey, 95tdelete (const void *__restrict vkey,
96 void ** __restrict vrootp, 96 void **__restrict vrootp,
97 int (*compar)(const void *, const void *)) 97 int (*compar)(const void *, const void *))
98{ 98{
99 node_t **rootp = (node_t **)vrootp; 99 node_t **rootp = (node_t **) vrootp;
100 node_t *p; 100 node_t *p;
101 node_t *q; 101 node_t *q;
102 node_t *r; 102 node_t *r;
103 int cmp; 103 int cmp;
104 104
105 if (rootp == NULL || (p = *rootp) == NULL) 105 if ((rootp == NULL)||((p = *rootp) == NULL))
106 return NULL; 106 return NULL;
107 107
108 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) 108 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0)
109 { 109 {
110 p = *rootp; 110 p = *rootp;
111 rootp = (cmp < 0) ? 111 rootp = (cmp < 0) ?
112 &(*rootp)->llink : /* follow llink branch */ 112 &(*rootp)->llink : /* follow llink branch */
113 &(*rootp)->rlink; /* follow rlink branch */ 113 &(*rootp)->rlink; /* follow rlink branch */
114 if (*rootp == NULL) 114 if (*rootp == NULL)
115 return NULL; /* key not found */ 115 return NULL; /* key not found */
116 } 116 }
117 r = (*rootp)->rlink; /* D1: */ 117 r = (*rootp)->rlink; /* D1: */
118 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ 118 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
119 { 119 {
120 q = r;
121 }
122 else if (r != NULL)
123 { /* Right link is NULL? */
124 if (r->llink == NULL)
125 { /* D2: Find successor */
126 r->llink = q;
120 q = r; 127 q = r;
121 } 128 }
122 else if (r != NULL) 129 else
123 { /* Right link is NULL? */ 130 { /* D3: Find NULL link */
124 if (r->llink == NULL) 131 for (q = r->llink; q->llink != NULL; q = r->llink)
125 { /* D2: Find successor */ 132 r = q;
126 r->llink = q; 133 r->llink = q->rlink;
127 q = r; 134 q->llink = (*rootp)->llink;
128 } 135 q->rlink = (*rootp)->rlink;
129 else
130 { /* D3: Find NULL link */
131 for (q = r->llink; q->llink != NULL; q = r->llink)
132 r = q;
133 r->llink = q->rlink;
134 q->llink = (*rootp)->llink;
135 q->rlink = (*rootp)->rlink;
136 }
137 } 136 }
138 free(*rootp); /* D4: Free node */ 137 }
139 *rootp = q; /* link parent to new node */ 138 free (*rootp); /* D4: Free node */
139 *rootp = q; /* link parent to new node */
140 return p; 140 return p;
141} 141}
142 142
diff --git a/src/lib/tsearch.h b/src/lib/tsearch.h
index aa186495..0cfe16a7 100644
--- a/src/lib/tsearch.h
+++ b/src/lib/tsearch.h
@@ -14,22 +14,22 @@ extern "C" {
14#endif /* __cplusplus */ 14#endif /* __cplusplus */
15 15
16 16
17void * 17void *
18tdelete (const void * __restrict, 18 tdelete (const void *__restrict,
19 void ** __restrict, 19 void **__restrict,
20 int (*)(const void *, const void *)); 20 int (*)(const void *, const void *));
21 21
22 22
23void * 23void *
24tfind (const void *, 24 tfind (const void *,
25 void * const *, 25 void *const *,
26 int (*)(const void *, const void *)); 26 int (*)(const void *, const void *));
27 27
28 28
29void * 29void *
30tsearch (const void *, 30 tsearch (const void *,
31 void **, 31 void **,
32 int (*)(const void *, const void *)); 32 int (*)(const void *, const void *));
33 33
34#if defined(__cplusplus) 34#if defined(__cplusplus)
35}; 35};
diff --git a/src/lib/upgrade_process.c b/src/lib/upgrade_process.c
index 75924eee..353f2753 100644
--- a/src/lib/upgrade_process.c
+++ b/src/lib/upgrade_process.c
@@ -41,59 +41,62 @@ MHD_upgrade_response_handle_process_ (struct MHD_UpgradeResponseHandle *urh)
41 * pointers to 'connection' and 'daemon' are not changed 41 * pointers to 'connection' and 'daemon' are not changed
42 * during this processing, so no need to chain dereference 42 * during this processing, so no need to chain dereference
43 * each time. */ 43 * each time. */
44 struct MHD_Connection * const connection = urh->connection; 44 struct MHD_Connection *const connection = urh->connection;
45 struct MHD_Daemon * const daemon = connection->daemon; 45 struct MHD_Daemon *const daemon = connection->daemon;
46 /* Prevent data races: use same value of 'was_closed' throughout 46 /* Prevent data races: use same value of 'was_closed' throughout
47 * this function. If 'was_closed' changed externally in the middle 47 * this function. If 'was_closed' changed externally in the middle
48 * of processing - it will be processed on next iteration. */ 48 * of processing - it will be processed on next iteration. */
49 bool was_closed; 49 bool was_closed;
50 struct MHD_TLS_Plugin *tls = daemon->tls_api; 50 struct MHD_TLS_Plugin *tls = daemon->tls_api;
51 51
52 if (daemon->shutdown) 52 if (daemon->shutdown)
53 { 53 {
54 /* Daemon shutting down, application will not receive any more data. */ 54 /* Daemon shutting down, application will not receive any more data. */
55#ifdef HAVE_MESSAGES 55#ifdef HAVE_MESSAGES
56 if (! urh->was_closed) 56 if (! urh->was_closed)
57 { 57 {
58 MHD_DLOG (daemon, 58 MHD_DLOG (daemon,
59 MHD_SC_DAEMON_ALREADY_SHUTDOWN, 59 MHD_SC_DAEMON_ALREADY_SHUTDOWN,
60 _("Initiated daemon shutdown while \"upgraded\" connection was not closed.\n")); 60 _ (
61 } 61 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
62#endif
63 urh->was_closed = true;
64 } 62 }
63#endif
64 urh->was_closed = true;
65 }
65 was_closed = urh->was_closed; 66 was_closed = urh->was_closed;
66 if (was_closed) 67 if (was_closed)
68 {
69 /* Application was closed connections: no more data
70 * can be forwarded to application socket. */
71 if (0 < urh->in_buffer_used)
67 { 72 {
68 /* Application was closed connections: no more data
69 * can be forwarded to application socket. */
70 if (0 < urh->in_buffer_used)
71 {
72#ifdef HAVE_MESSAGES 73#ifdef HAVE_MESSAGES
73 MHD_DLOG (daemon, 74 MHD_DLOG (daemon,
74 MHD_SC_UPGRADE_FORWARD_INCOMPLETE, 75 MHD_SC_UPGRADE_FORWARD_INCOMPLETE,
75 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \ 76 _ (
76 " bytes of data received from remote side: application shut down socket\n"), 77 "Failed to forward to application "
77 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used); 78 MHD_UNSIGNED_LONG_LONG_PRINTF \
79 " bytes of data received from remote side: application shut down socket\n"),
80 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used);
78#endif 81#endif
79 82
80 }
81 /* If application signaled MHD about socket closure then
82 * check for any pending data even if socket is not marked
83 * as 'ready' (signal may arrive after poll()/select()).
84 * Socketpair for forwarding is always in non-blocking mode
85 * so no risk that recv() will block the thread. */
86 if (0 != urh->out_buffer_size)
87 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY;
88 /* Discard any data received form remote. */
89 urh->in_buffer_used = 0;
90 /* Do not try to push data to application. */
91 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
92 /* Reading from remote client is not required anymore. */
93 urh->in_buffer_size = 0;
94 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
95 connection->tls_read_ready = false;
96 } 83 }
84 /* If application signaled MHD about socket closure then
85 * check for any pending data even if socket is not marked
86 * as 'ready' (signal may arrive after poll()/select()).
87 * Socketpair for forwarding is always in non-blocking mode
88 * so no risk that recv() will block the thread. */
89 if (0 != urh->out_buffer_size)
90 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY;
91 /* Discard any data received form remote. */
92 urh->in_buffer_used = 0;
93 /* Do not try to push data to application. */
94 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
95 /* Reading from remote client is not required anymore. */
96 urh->in_buffer_size = 0;
97 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
98 connection->tls_read_ready = false;
99 }
97 100
98 /* On some platforms (W32, possibly Darwin) failed send() (send() will always 101 /* On some platforms (W32, possibly Darwin) failed send() (send() will always
99 * fail after remote disconnect was detected) may discard data in system 102 * fail after remote disconnect was detected) may discard data in system
@@ -114,245 +117,249 @@ MHD_upgrade_response_handle_process_ (struct MHD_UpgradeResponseHandle *urh)
114 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->app.celi)) || 117 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->app.celi)) ||
115 (connection->tls_read_ready) ) && 118 (connection->tls_read_ready) ) &&
116 (urh->in_buffer_used < urh->in_buffer_size) ) 119 (urh->in_buffer_used < urh->in_buffer_size) )
117 { 120 {
118 ssize_t res; 121 ssize_t res;
119 size_t buf_size; 122 size_t buf_size;
120 123
121 buf_size = urh->in_buffer_size - urh->in_buffer_used; 124 buf_size = urh->in_buffer_size - urh->in_buffer_used;
122 if (buf_size > SSIZE_MAX) 125 if (buf_size > SSIZE_MAX)
123 buf_size = SSIZE_MAX; 126 buf_size = SSIZE_MAX;
124 127
125 connection->tls_read_ready = false; 128 connection->tls_read_ready = false;
126 res = tls->recv (tls->cls, 129 res = tls->recv (tls->cls,
127 connection->tls_cs, 130 connection->tls_cs,
128 &urh->in_buffer[urh->in_buffer_used], 131 &urh->in_buffer[urh->in_buffer_used],
129 buf_size); 132 buf_size);
130 if (0 >= res) 133 if (0 >= res)
131 { 134 {
132 // FIXME: define GNUTLS-independent error codes! 135 // FIXME: define GNUTLS-independent error codes!
133 if (GNUTLS_E_INTERRUPTED != res) 136 if (GNUTLS_E_INTERRUPTED != res)
134 { 137 {
135 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 138 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
136 if (GNUTLS_E_AGAIN != res) 139 if (GNUTLS_E_AGAIN != res)
137 {
138 /* Unrecoverable error on socket was detected or
139 * socket was disconnected/shut down. */
140 /* Stop trying to read from this TLS socket. */
141 urh->in_buffer_size = 0;
142 }
143 }
144 }
145 else /* 0 < res */
146 {
147 urh->in_buffer_used += res;
148 if (buf_size > (size_t)res)
149 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
150 else if (0 < tls->check_record_pending (tls->cls,
151 connection->tls_cs))
152 connection->tls_read_ready = true;
153 }
154 if (MHD_EPOLL_STATE_ERROR ==
155 ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi))
156 { 140 {
157 /* Unrecoverable error on socket was detected and all 141 /* Unrecoverable error on socket was detected or
158 * pending data was read from system buffers. */ 142 * socket was disconnected/shut down. */
159 /* Stop trying to read from this TLS socket. */ 143 /* Stop trying to read from this TLS socket. */
160 urh->in_buffer_size = 0; 144 urh->in_buffer_size = 0;
161 } 145 }
146 }
162 } 147 }
148 else /* 0 < res */
149 {
150 urh->in_buffer_used += res;
151 if (buf_size > (size_t) res)
152 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
153 else if (0 < tls->check_record_pending (tls->cls,
154 connection->tls_cs))
155 connection->tls_read_ready = true;
156 }
157 if (MHD_EPOLL_STATE_ERROR ==
158 ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi))
159 {
160 /* Unrecoverable error on socket was detected and all
161 * pending data was read from system buffers. */
162 /* Stop trying to read from this TLS socket. */
163 urh->in_buffer_size = 0;
164 }
165 }
163 166
164 /* 167 /*
165 * handle reading from application 168 * handle reading from application
166 */ 169 */
167 if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) && 170 if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
168 (urh->out_buffer_used < urh->out_buffer_size) ) 171 (urh->out_buffer_used < urh->out_buffer_size) )
169 { 172 {
170 ssize_t res; 173 ssize_t res;
171 size_t buf_size; 174 size_t buf_size;
172 175
173 buf_size = urh->out_buffer_size - urh->out_buffer_used; 176 buf_size = urh->out_buffer_size - urh->out_buffer_used;
174 if (buf_size > MHD_SCKT_SEND_MAX_SIZE_) 177 if (buf_size > MHD_SCKT_SEND_MAX_SIZE_)
175 buf_size = MHD_SCKT_SEND_MAX_SIZE_; 178 buf_size = MHD_SCKT_SEND_MAX_SIZE_;
176 179
177 res = MHD_recv_ (urh->mhd.socket, 180 res = MHD_recv_ (urh->mhd.socket,
178 &urh->out_buffer[urh->out_buffer_used], 181 &urh->out_buffer[urh->out_buffer_used],
179 buf_size); 182 buf_size);
180 if (0 >= res) 183 if (0 >= res)
181 { 184 {
182 const int err = MHD_socket_get_error_ (); 185 const int err = MHD_socket_get_error_ ();
183 if ((0 == res) || 186 if ((0 == res) ||
184 ((! MHD_SCKT_ERR_IS_EINTR_ (err)) && 187 ((! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
185 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)))) 188 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err))))
186 { 189 {
187 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 190 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
188 if ((0 == res) || 191 if ((0 == res) ||
189 (was_closed) || 192 (was_closed) ||
190 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) || 193 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
191 (! MHD_SCKT_ERR_IS_EAGAIN_ (err))) 194 (! MHD_SCKT_ERR_IS_EAGAIN_ (err)))
192 {
193 /* Socket disconnect/shutdown was detected;
194 * Application signaled about closure of 'upgraded' socket;
195 * or persistent / unrecoverable error. */
196 /* Do not try to pull more data from application. */
197 urh->out_buffer_size = 0;
198 }
199 }
200 }
201 else /* 0 < res */
202 {
203 urh->out_buffer_used += res;
204 if (buf_size > (size_t)res)
205 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
206 }
207 if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
208 ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
209 (was_closed) ) )
210 { 195 {
211 /* Unrecoverable error on socket was detected and all 196 /* Socket disconnect/shutdown was detected;
212 * pending data was read from system buffers. */ 197 * Application signaled about closure of 'upgraded' socket;
198 * or persistent / unrecoverable error. */
213 /* Do not try to pull more data from application. */ 199 /* Do not try to pull more data from application. */
214 urh->out_buffer_size = 0; 200 urh->out_buffer_size = 0;
215 } 201 }
202 }
203 }
204 else /* 0 < res */
205 {
206 urh->out_buffer_used += res;
207 if (buf_size > (size_t) res)
208 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
216 } 209 }
210 if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
211 ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
212 (was_closed) ) )
213 {
214 /* Unrecoverable error on socket was detected and all
215 * pending data was read from system buffers. */
216 /* Do not try to pull more data from application. */
217 urh->out_buffer_size = 0;
218 }
219 }
217 220
218 /* 221 /*
219 * handle writing to remote HTTPS client 222 * handle writing to remote HTTPS client
220 */ 223 */
221 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) && 224 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) &&
222 (urh->out_buffer_used > 0) ) 225 (urh->out_buffer_used > 0) )
223 { 226 {
224 ssize_t res; 227 ssize_t res;
225 size_t data_size; 228 size_t data_size;
226 229
227 data_size = urh->out_buffer_used; 230 data_size = urh->out_buffer_used;
228 if (data_size > SSIZE_MAX) 231 if (data_size > SSIZE_MAX)
229 data_size = SSIZE_MAX; 232 data_size = SSIZE_MAX;
230 233
231 res = tls->send (tls->cls, 234 res = tls->send (tls->cls,
232 connection->tls_cs, 235 connection->tls_cs,
233 urh->out_buffer, 236 urh->out_buffer,
234 data_size); 237 data_size);
235 if (0 >= res) 238 if (0 >= res)
239 {
240 // FIXME: define GNUTLS-independent error codes!
241 if (GNUTLS_E_INTERRUPTED != res)
242 {
243 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
244 if (GNUTLS_E_INTERRUPTED != res)
236 { 245 {
237 // FIXME: define GNUTLS-independent error codes! 246 /* TLS connection shut down or
238 if (GNUTLS_E_INTERRUPTED != res) 247 * persistent / unrecoverable error. */
239 {
240 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
241 if (GNUTLS_E_INTERRUPTED != res)
242 {
243 /* TLS connection shut down or
244 * persistent / unrecoverable error. */
245#ifdef HAVE_MESSAGES 248#ifdef HAVE_MESSAGES
246 MHD_DLOG (daemon, 249 MHD_DLOG (daemon,
247 MHD_SC_UPGRADE_FORWARD_INCOMPLETE, 250 MHD_SC_UPGRADE_FORWARD_INCOMPLETE,
248 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \ 251 _ (
249 " bytes of data received from application: %s\n"), 252 "Failed to forward to remote client "
250 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used, 253 MHD_UNSIGNED_LONG_LONG_PRINTF \
251 tls->strerror (tls->cls, 254 " bytes of data received from application: %s\n"),
252 res)); 255 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used,
256 tls->strerror (tls->cls,
257 res));
253#endif 258#endif
254 /* Discard any data unsent to remote. */ 259 /* Discard any data unsent to remote. */
255 urh->out_buffer_used = 0; 260 urh->out_buffer_used = 0;
256 /* Do not try to pull more data from application. */
257 urh->out_buffer_size = 0;
258 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
259 }
260 }
261 }
262 else /* 0 < res */
263 {
264 const size_t next_out_buffer_used = urh->out_buffer_used - res;
265 if (0 != next_out_buffer_used)
266 {
267 memmove (urh->out_buffer,
268 &urh->out_buffer[res],
269 next_out_buffer_used);
270 if (data_size > (size_t)res)
271 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
272 }
273 urh->out_buffer_used = next_out_buffer_used;
274 }
275 if ( (0 == urh->out_buffer_used) &&
276 (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) )
277 {
278 /* Unrecoverable error on socket was detected and all
279 * pending data was sent to remote. */
280 /* Do not try to send to remote anymore. */
281 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
282 /* Do not try to pull more data from application. */ 261 /* Do not try to pull more data from application. */
283 urh->out_buffer_size = 0; 262 urh->out_buffer_size = 0;
284 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 263 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
285 } 264 }
265 }
286 } 266 }
267 else /* 0 < res */
268 {
269 const size_t next_out_buffer_used = urh->out_buffer_used - res;
270 if (0 != next_out_buffer_used)
271 {
272 memmove (urh->out_buffer,
273 &urh->out_buffer[res],
274 next_out_buffer_used);
275 if (data_size > (size_t) res)
276 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
277 }
278 urh->out_buffer_used = next_out_buffer_used;
279 }
280 if ( (0 == urh->out_buffer_used) &&
281 (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) )
282 {
283 /* Unrecoverable error on socket was detected and all
284 * pending data was sent to remote. */
285 /* Do not try to send to remote anymore. */
286 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
287 /* Do not try to pull more data from application. */
288 urh->out_buffer_size = 0;
289 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
290 }
291 }
287 292
288 /* 293 /*
289 * handle writing to application 294 * handle writing to application
290 */ 295 */
291 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) && 296 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) &&
292 (urh->in_buffer_used > 0) ) 297 (urh->in_buffer_used > 0) )
293 { 298 {
294 ssize_t res; 299 ssize_t res;
295 size_t data_size; 300 size_t data_size;
296 301
297 data_size = urh->in_buffer_used; 302 data_size = urh->in_buffer_used;
298 if (data_size > MHD_SCKT_SEND_MAX_SIZE_) 303 if (data_size > MHD_SCKT_SEND_MAX_SIZE_)
299 data_size = MHD_SCKT_SEND_MAX_SIZE_; 304 data_size = MHD_SCKT_SEND_MAX_SIZE_;
300 305
301 res = MHD_send_ (urh->mhd.socket, 306 res = MHD_send_ (urh->mhd.socket,
302 urh->in_buffer, 307 urh->in_buffer,
303 data_size); 308 data_size);
304 if (0 >= res) 309 if (0 >= res)
310 {
311 const int err = MHD_socket_get_error_ ();
312 if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
313 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err)) )
314 {
315 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
316 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err))
305 { 317 {
306 const int err = MHD_socket_get_error_ (); 318 /* Socketpair connection shut down or
307 if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) && 319 * persistent / unrecoverable error. */
308 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) )
309 {
310 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
311 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err))
312 {
313 /* Socketpair connection shut down or
314 * persistent / unrecoverable error. */
315#ifdef HAVE_MESSAGES 320#ifdef HAVE_MESSAGES
316 MHD_DLOG (daemon, 321 MHD_DLOG (daemon,
317 MHD_SC_UPGRADE_FORWARD_INCOMPLETE, 322 MHD_SC_UPGRADE_FORWARD_INCOMPLETE,
318 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \ 323 _ (
319 " bytes of data received from remote side: %s\n"), 324 "Failed to forward to application "
320 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used, 325 MHD_UNSIGNED_LONG_LONG_PRINTF \
321 MHD_socket_strerr_ (err)); 326 " bytes of data received from remote side: %s\n"),
327 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used,
328 MHD_socket_strerr_ (err));
322#endif 329#endif
323 /* Discard any data received form remote. */ 330 /* Discard any data received form remote. */
324 urh->in_buffer_used = 0; 331 urh->in_buffer_used = 0;
325 /* Reading from remote client is not required anymore. */
326 urh->in_buffer_size = 0;
327 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
328 connection->tls_read_ready = false;
329 }
330 }
331 }
332 else /* 0 < res */
333 {
334 const size_t next_in_buffer_used = urh->in_buffer_used - res;
335 if (0 != next_in_buffer_used)
336 {
337 memmove (urh->in_buffer,
338 &urh->in_buffer[res],
339 next_in_buffer_used);
340 if (data_size > (size_t)res)
341 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
342 }
343 urh->in_buffer_used = next_in_buffer_used;
344 }
345 if ( (0 == urh->in_buffer_used) &&
346 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) )
347 {
348 /* Do not try to push data to application. */
349 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
350 /* Reading from remote client is not required anymore. */ 332 /* Reading from remote client is not required anymore. */
351 urh->in_buffer_size = 0; 333 urh->in_buffer_size = 0;
352 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 334 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
353 connection->tls_read_ready = false; 335 connection->tls_read_ready = false;
354 } 336 }
337 }
338 }
339 else /* 0 < res */
340 {
341 const size_t next_in_buffer_used = urh->in_buffer_used - res;
342 if (0 != next_in_buffer_used)
343 {
344 memmove (urh->in_buffer,
345 &urh->in_buffer[res],
346 next_in_buffer_used);
347 if (data_size > (size_t) res)
348 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
349 }
350 urh->in_buffer_used = next_in_buffer_used;
351 }
352 if ( (0 == urh->in_buffer_used) &&
353 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) )
354 {
355 /* Do not try to push data to application. */
356 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
357 /* Reading from remote client is not required anymore. */
358 urh->in_buffer_size = 0;
359 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
360 connection->tls_read_ready = false;
355 } 361 }
362 }
356 363
357 /* Check whether data is present in TLS buffers 364 /* Check whether data is present in TLS buffers
358 * and incoming forward buffer have some space. */ 365 * and incoming forward buffer have some space. */
@@ -364,24 +371,26 @@ MHD_upgrade_response_handle_process_ (struct MHD_UpgradeResponseHandle *urh)
364 if ( (daemon->shutdown) && 371 if ( (daemon->shutdown) &&
365 ( (0 != urh->out_buffer_size) || 372 ( (0 != urh->out_buffer_size) ||
366 (0 != urh->out_buffer_used) ) ) 373 (0 != urh->out_buffer_used) ) )
367 { 374 {
368 /* Daemon shutting down, discard any remaining forward data. */ 375 /* Daemon shutting down, discard any remaining forward data. */
369#ifdef HAVE_MESSAGES 376#ifdef HAVE_MESSAGES
370 if (0 < urh->out_buffer_used) 377 if (0 < urh->out_buffer_used)
371 MHD_DLOG (daemon, 378 MHD_DLOG (daemon,
372 MHD_SC_UPGRADE_FORWARD_INCOMPLETE, 379 MHD_SC_UPGRADE_FORWARD_INCOMPLETE,
373 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \ 380 _ (
374 " bytes of data received from application: daemon shut down\n"), 381 "Failed to forward to remote client "
375 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used); 382 MHD_UNSIGNED_LONG_LONG_PRINTF \
383 " bytes of data received from application: daemon shut down\n"),
384 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used);
376#endif 385#endif
377 /* Discard any data unsent to remote. */ 386 /* Discard any data unsent to remote. */
378 urh->out_buffer_used = 0; 387 urh->out_buffer_used = 0;
379 /* Do not try to sent to remote anymore. */ 388 /* Do not try to sent to remote anymore. */
380 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 389 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
381 /* Do not try to pull more data from application. */ 390 /* Do not try to pull more data from application. */
382 urh->out_buffer_size = 0; 391 urh->out_buffer_size = 0;
383 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 392 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
384 } 393 }
385} 394}
386#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 395#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
387 396
diff --git a/src/lib/upgrade_process.h b/src/lib/upgrade_process.h
index 36a7ddff..8b0d4119 100644
--- a/src/lib/upgrade_process.h
+++ b/src/lib/upgrade_process.h
@@ -36,7 +36,7 @@
36 */ 36 */
37void 37void
38MHD_upgrade_response_handle_process_ (struct MHD_UpgradeResponseHandle *urh) 38MHD_upgrade_response_handle_process_ (struct MHD_UpgradeResponseHandle *urh)
39 MHD_NONNULL(1); 39MHD_NONNULL (1);
40 40
41 41
42#endif 42#endif
diff --git a/src/lib/version.c b/src/lib/version.c
index 472a8c04..5bf4ab01 100644
--- a/src/lib/version.c
+++ b/src/lib/version.c
@@ -40,13 +40,13 @@ MHD_get_version (void)
40 static char ver[12] = "\0\0\0\0\0\0\0\0\0\0\0"; 40 static char ver[12] = "\0\0\0\0\0\0\0\0\0\0\0";
41 if (0 == ver[0]) 41 if (0 == ver[0])
42 { 42 {
43 int res = MHD_snprintf_(ver, 43 int res = MHD_snprintf_ (ver,
44 sizeof(ver), 44 sizeof(ver),
45 "%x.%x.%x", 45 "%x.%x.%x",
46 (((int)MHD_VERSION >> 24) & 0xFF), 46 (((int) MHD_VERSION >> 24) & 0xFF),
47 (((int)MHD_VERSION >> 16) & 0xFF), 47 (((int) MHD_VERSION >> 16) & 0xFF),
48 (((int)MHD_VERSION >> 8) & 0xFF)); 48 (((int) MHD_VERSION >> 8) & 0xFF));
49 if (0 >= res || sizeof(ver) <= res) 49 if ((0 >= res)||(sizeof(ver) <= res))
50 return "0.0.0"; /* Can't return real version*/ 50 return "0.0.0"; /* Can't return real version*/
51 } 51 }
52 return ver; 52 return ver;
@@ -66,141 +66,142 @@ MHD_get_version (void)
66 * @ingroup specialized 66 * @ingroup specialized
67 */ 67 */
68_MHD_EXTERN enum MHD_Bool 68_MHD_EXTERN enum MHD_Bool
69MHD_is_feature_supported(enum MHD_Feature feature) 69MHD_is_feature_supported (enum MHD_Feature feature)
70{ 70{
71 switch(feature) 71 switch (feature)
72 { 72 {
73 case MHD_FEATURE_MESSAGES: 73 case MHD_FEATURE_MESSAGES:
74#ifdef HAVE_MESSAGES 74#ifdef HAVE_MESSAGES
75 return MHD_YES; 75 return MHD_YES;
76#else 76#else
77 return MHD_NO; 77 return MHD_NO;
78#endif 78#endif
79 case MHD_FEATURE_TLS: 79 case MHD_FEATURE_TLS:
80#ifdef HTTPS_SUPPORT 80#ifdef HTTPS_SUPPORT
81 return MHD_YES; 81 return MHD_YES;
82#else /* ! HTTPS_SUPPORT */ 82#else /* ! HTTPS_SUPPORT */
83 return MHD_NO; 83 return MHD_NO;
84#endif /* ! HTTPS_SUPPORT */ 84#endif /* ! HTTPS_SUPPORT */
85 case MHD_FEATURE_HTTPS_CERT_CALLBACK: 85 case MHD_FEATURE_HTTPS_CERT_CALLBACK:
86#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3 86#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
87 return MHD_YES; 87 return MHD_YES;
88#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */ 88#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
89 return MHD_NO; 89 return MHD_NO;
90#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */ 90#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
91 case MHD_FEATURE_IPv6: 91 case MHD_FEATURE_IPv6:
92#ifdef HAVE_INET6 92#ifdef HAVE_INET6
93 return MHD_YES; 93 return MHD_YES;
94#else 94#else
95 return MHD_NO; 95 return MHD_NO;
96#endif 96#endif
97 case MHD_FEATURE_IPv6_ONLY: 97 case MHD_FEATURE_IPv6_ONLY:
98#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) 98#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
99 return MHD_YES; 99 return MHD_YES;
100#else 100#else
101 return MHD_NO; 101 return MHD_NO;
102#endif 102#endif
103 case MHD_FEATURE_POLL: 103 case MHD_FEATURE_POLL:
104#ifdef HAVE_POLL 104#ifdef HAVE_POLL
105 return MHD_YES; 105 return MHD_YES;
106#else 106#else
107 return MHD_NO; 107 return MHD_NO;
108#endif 108#endif
109 case MHD_FEATURE_EPOLL: 109 case MHD_FEATURE_EPOLL:
110#ifdef EPOLL_SUPPORT 110#ifdef EPOLL_SUPPORT
111 return MHD_YES; 111 return MHD_YES;
112#else 112#else
113 return MHD_NO; 113 return MHD_NO;
114#endif 114#endif
115 case MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET: 115 case MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET:
116#ifdef HAVE_LISTEN_SHUTDOWN 116#ifdef HAVE_LISTEN_SHUTDOWN
117 return MHD_YES; 117 return MHD_YES;
118#else 118#else
119 return MHD_NO; 119 return MHD_NO;
120#endif 120#endif
121 case MHD_FEATURE_SOCKETPAIR: 121 case MHD_FEATURE_SOCKETPAIR:
122#ifdef _MHD_ITC_SOCKETPAIR 122#ifdef _MHD_ITC_SOCKETPAIR
123 return MHD_YES; 123 return MHD_YES;
124#else 124#else
125 return MHD_NO; 125 return MHD_NO;
126#endif 126#endif
127 case MHD_FEATURE_TCP_FASTOPEN: 127 case MHD_FEATURE_TCP_FASTOPEN:
128#ifdef TCP_FASTOPEN 128#ifdef TCP_FASTOPEN
129 return MHD_YES; 129 return MHD_YES;
130#else 130#else
131 return MHD_NO; 131 return MHD_NO;
132#endif 132#endif
133 case MHD_FEATURE_BASIC_AUTH: 133 case MHD_FEATURE_BASIC_AUTH:
134#ifdef BAUTH_SUPPORT 134#ifdef BAUTH_SUPPORT
135 return MHD_YES; 135 return MHD_YES;
136#else 136#else
137 return MHD_NO; 137 return MHD_NO;
138#endif 138#endif
139 case MHD_FEATURE_DIGEST_AUTH: 139 case MHD_FEATURE_DIGEST_AUTH:
140#ifdef DAUTH_SUPPORT 140#ifdef DAUTH_SUPPORT
141 return MHD_YES; 141 return MHD_YES;
142#else 142#else
143 return MHD_NO; 143 return MHD_NO;
144#endif 144#endif
145 case MHD_FEATURE_POSTPROCESSOR: 145 case MHD_FEATURE_POSTPROCESSOR:
146#ifdef HAVE_POSTPROCESSOR 146#ifdef HAVE_POSTPROCESSOR
147 return MHD_YES; 147 return MHD_YES;
148#else 148#else
149 return MHD_NO; 149 return MHD_NO;
150#endif 150#endif
151 case MHD_FEATURE_HTTPS_KEY_PASSWORD: 151 case MHD_FEATURE_HTTPS_KEY_PASSWORD:
152#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111 152#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
153 return MHD_YES; 153 return MHD_YES;
154#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */ 154#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
155 return MHD_NO; 155 return MHD_NO;
156#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */ 156#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
157 case MHD_FEATURE_LARGE_FILE: 157 case MHD_FEATURE_LARGE_FILE:
158#if defined(HAVE_PREAD64) || defined(_WIN32) 158#if defined(HAVE_PREAD64) || defined(_WIN32)
159 return MHD_YES; 159 return MHD_YES;
160#elif defined(HAVE_PREAD) 160#elif defined(HAVE_PREAD)
161 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES; 161 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES;
162#elif defined(HAVE_LSEEK64) 162#elif defined(HAVE_LSEEK64)
163 return MHD_YES; 163 return MHD_YES;
164#else 164#else
165 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES; 165 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES;
166#endif 166#endif
167 case MHD_FEATURE_THREAD_NAMES: 167 case MHD_FEATURE_THREAD_NAMES:
168#if defined(MHD_USE_THREAD_NAME_) 168#if defined(MHD_USE_THREAD_NAME_)
169 return MHD_YES; 169 return MHD_YES;
170#else 170#else
171 return MHD_NO; 171 return MHD_NO;
172#endif 172#endif
173 case MHD_FEATURE_UPGRADE: 173 case MHD_FEATURE_UPGRADE:
174#if defined(UPGRADE_SUPPORT) 174#if defined(UPGRADE_SUPPORT)
175 return MHD_YES; 175 return MHD_YES;
176#else 176#else
177 return MHD_NO; 177 return MHD_NO;
178#endif 178#endif
179 case MHD_FEATURE_RESPONSES_SHARED_FD: 179 case MHD_FEATURE_RESPONSES_SHARED_FD:
180#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32) 180#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
181 return MHD_YES; 181 return MHD_YES;
182#else 182#else
183 return MHD_NO; 183 return MHD_NO;
184#endif 184#endif
185 case MHD_FEATURE_AUTODETECT_BIND_PORT: 185 case MHD_FEATURE_AUTODETECT_BIND_PORT:
186#ifdef MHD_USE_GETSOCKNAME 186#ifdef MHD_USE_GETSOCKNAME
187 return MHD_YES; 187 return MHD_YES;
188#else 188#else
189 return MHD_NO; 189 return MHD_NO;
190#endif 190#endif
191 case MHD_FEATURE_AUTOSUPPRESS_SIGPIPE: 191 case MHD_FEATURE_AUTOSUPPRESS_SIGPIPE:
192#if defined(MHD_WINSOCK_SOCKETS) || defined(MHD_socket_nosignal_) || defined (MSG_NOSIGNAL) 192#if defined(MHD_WINSOCK_SOCKETS) || defined(MHD_socket_nosignal_) || \
193 return MHD_YES; 193 defined (MSG_NOSIGNAL)
194 return MHD_YES;
194#else 195#else
195 return MHD_NO; 196 return MHD_NO;
196#endif 197#endif
197 case MHD_FEATURE_SENDFILE: 198 case MHD_FEATURE_SENDFILE:
198#ifdef _MHD_HAVE_SENDFILE 199#ifdef _MHD_HAVE_SENDFILE
199 return MHD_YES; 200 return MHD_YES;
200#else 201#else
201 return MHD_NO; 202 return MHD_NO;
202#endif 203#endif
203 204
204 } 205 }
205 return MHD_NO; 206 return MHD_NO;
206} 207}
diff --git a/src/microhttpd/base64.c b/src/microhttpd/base64.c
index 3dc7a142..d7d1ec92 100644
--- a/src/microhttpd/base64.c
+++ b/src/microhttpd/base64.c
@@ -9,45 +9,46 @@
9#include "base64.h" 9#include "base64.h"
10 10
11static const char base64_digits[] = 11static const char base64_digits[] =
12 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 14 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
15 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
16 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 16 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26,
17 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 17 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
18 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
24 24
25 25
26char * 26char *
27BASE64Decode(const char* src) 27BASE64Decode (const char*src)
28{ 28{
29 size_t in_len = strlen (src); 29 size_t in_len = strlen (src);
30 char* dest; 30 char*dest;
31 char* result; 31 char*result;
32 32
33 if (in_len % 4) 33 if (in_len % 4)
34 { 34 {
35 /* Wrong base64 string length */ 35 /* Wrong base64 string length */
36 return NULL; 36 return NULL;
37 } 37 }
38 result = dest = malloc(in_len / 4 * 3 + 1); 38 result = dest = malloc (in_len / 4 * 3 + 1);
39 if (NULL == result) 39 if (NULL == result)
40 return NULL; /* out of memory */ 40 return NULL; /* out of memory */
41 while (*src) { 41 while (*src)
42 char a = base64_digits[(unsigned char)*(src++)]; 42 {
43 char b = base64_digits[(unsigned char)*(src++)]; 43 char a = base64_digits[(unsigned char) *(src++)];
44 char c = base64_digits[(unsigned char)*(src++)]; 44 char b = base64_digits[(unsigned char) *(src++)];
45 char d = base64_digits[(unsigned char)*(src++)]; 45 char c = base64_digits[(unsigned char) *(src++)];
46 char d = base64_digits[(unsigned char) *(src++)];
46 *(dest++) = (a << 2) | ((b & 0x30) >> 4); 47 *(dest++) = (a << 2) | ((b & 0x30) >> 4);
47 if (c == (char)-1) 48 if (c == (char) -1)
48 break; 49 break;
49 *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2); 50 *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
50 if (d == (char)-1) 51 if (d == (char) -1)
51 break; 52 break;
52 *(dest++) = ((c & 0x03) << 6) | d; 53 *(dest++) = ((c & 0x03) << 6) | d;
53 } 54 }
diff --git a/src/microhttpd/base64.h b/src/microhttpd/base64.h
index ba96ca0c..65042c0b 100644
--- a/src/microhttpd/base64.h
+++ b/src/microhttpd/base64.h
@@ -12,6 +12,6 @@
12#include "platform.h" 12#include "platform.h"
13 13
14char * 14char *
15BASE64Decode(const char* src); 15BASE64Decode (const char*src);
16 16
17#endif /* !BASE64_H */ 17#endif /* !BASE64_H */
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
index a9df9998..74ebafcb 100644
--- a/src/microhttpd/connection.h
+++ b/src/microhttpd/connection.h
@@ -153,7 +153,7 @@ MHD_connection_close_ (struct MHD_Connection *connection,
153void 153void
154MHD_connection_finish_forward_ (struct MHD_Connection *connection); 154MHD_connection_finish_forward_ (struct MHD_Connection *connection);
155#else /* ! HTTPS_SUPPORT */ 155#else /* ! HTTPS_SUPPORT */
156#define MHD_connection_finish_forward_(conn) (void)conn 156#define MHD_connection_finish_forward_(conn) (void) conn
157#endif /* ! HTTPS_SUPPORT */ 157#endif /* ! HTTPS_SUPPORT */
158 158
159 159
diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c
index 8202329b..108e1fc6 100644
--- a/src/microhttpd/connection_https.c
+++ b/src/microhttpd/connection_https.c
@@ -59,22 +59,22 @@ recv_tls_adapter (struct MHD_Connection *connection,
59 i); 59 i);
60 if ( (GNUTLS_E_AGAIN == res) || 60 if ( (GNUTLS_E_AGAIN == res) ||
61 (GNUTLS_E_INTERRUPTED == res) ) 61 (GNUTLS_E_INTERRUPTED == res) )
62 { 62 {
63#ifdef EPOLL_SUPPORT 63#ifdef EPOLL_SUPPORT
64 if (GNUTLS_E_AGAIN == res) 64 if (GNUTLS_E_AGAIN == res)
65 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; 65 connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
66#endif 66#endif
67 /* Any network errors means that buffer is empty. */ 67 /* Any network errors means that buffer is empty. */
68 connection->tls_read_ready = false; 68 connection->tls_read_ready = false;
69 return MHD_ERR_AGAIN_; 69 return MHD_ERR_AGAIN_;
70 } 70 }
71 if (res < 0) 71 if (res < 0)
72 { 72 {
73 /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication 73 /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication
74 disrupted); interpret as a hard error */ 74 disrupted); interpret as a hard error */
75 connection->tls_read_ready = false; 75 connection->tls_read_ready = false;
76 return MHD_ERR_NOTCONN_; 76 return MHD_ERR_NOTCONN_;
77 } 77 }
78 78
79#ifdef EPOLL_SUPPORT 79#ifdef EPOLL_SUPPORT
80 /* Unlike non-TLS connections, do not reset "read-ready" if 80 /* Unlike non-TLS connections, do not reset "read-ready" if
@@ -83,8 +83,9 @@ recv_tls_adapter (struct MHD_Connection *connection,
83#endif /* EPOLL_SUPPORT */ 83#endif /* EPOLL_SUPPORT */
84 84
85 /* Check whether TLS buffers still have some unread data. */ 85 /* Check whether TLS buffers still have some unread data. */
86 connection->tls_read_ready = ( ((size_t)res == i) && 86 connection->tls_read_ready = ( ((size_t) res == i) &&
87 (0 != gnutls_record_check_pending (connection->tls_session)) ); 87 (0 != gnutls_record_check_pending (
88 connection->tls_session)) );
88 return res; 89 return res;
89} 90}
90 91
@@ -113,19 +114,19 @@ send_tls_adapter (struct MHD_Connection *connection,
113 i); 114 i);
114 if ( (GNUTLS_E_AGAIN == res) || 115 if ( (GNUTLS_E_AGAIN == res) ||
115 (GNUTLS_E_INTERRUPTED == res) ) 116 (GNUTLS_E_INTERRUPTED == res) )
116 { 117 {
117#ifdef EPOLL_SUPPORT 118#ifdef EPOLL_SUPPORT
118 if (GNUTLS_E_AGAIN == res) 119 if (GNUTLS_E_AGAIN == res)
119 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 120 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
120#endif 121#endif
121 return MHD_ERR_AGAIN_; 122 return MHD_ERR_AGAIN_;
122 } 123 }
123 if (res < 0) 124 if (res < 0)
124 { 125 {
125 /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication 126 /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication
126 disrupted); interpret as a hard error */ 127 disrupted); interpret as a hard error */
127 return MHD_ERR_NOTCONN_; 128 return MHD_ERR_NOTCONN_;
128 } 129 }
129#ifdef EPOLL_SUPPORT 130#ifdef EPOLL_SUPPORT
130 /* Unlike non-TLS connections, do not reset "write-ready" if 131 /* Unlike non-TLS connections, do not reset "write-ready" if
131 * sent amount smaller than provided amount, as TLS 132 * sent amount smaller than provided amount, as TLS
@@ -151,32 +152,32 @@ MHD_run_tls_handshake_ (struct MHD_Connection *connection)
151 152
152 if ((MHD_TLS_CONN_INIT == connection->tls_state) || 153 if ((MHD_TLS_CONN_INIT == connection->tls_state) ||
153 (MHD_TLS_CONN_HANDSHAKING == connection->tls_state)) 154 (MHD_TLS_CONN_HANDSHAKING == connection->tls_state))
155 {
156 ret = gnutls_handshake (connection->tls_session);
157 if (ret == GNUTLS_E_SUCCESS)
154 { 158 {
155 ret = gnutls_handshake (connection->tls_session); 159 /* set connection TLS state to enable HTTP processing */
156 if (ret == GNUTLS_E_SUCCESS) 160 connection->tls_state = MHD_TLS_CONN_CONNECTED;
157 { 161 MHD_update_last_activity_ (connection);
158 /* set connection TLS state to enable HTTP processing */ 162 return true;
159 connection->tls_state = MHD_TLS_CONN_CONNECTED; 163 }
160 MHD_update_last_activity_ (connection); 164 if ( (GNUTLS_E_AGAIN == ret) ||
161 return true; 165 (GNUTLS_E_INTERRUPTED == ret) )
162 } 166 {
163 if ( (GNUTLS_E_AGAIN == ret) || 167 connection->tls_state = MHD_TLS_CONN_HANDSHAKING;
164 (GNUTLS_E_INTERRUPTED == ret) ) 168 /* handshake not done */
165 {
166 connection->tls_state = MHD_TLS_CONN_HANDSHAKING;
167 /* handshake not done */
168 return false;
169 }
170 /* handshake failed */
171 connection->tls_state = MHD_TLS_CONN_TLS_FAILED;
172#ifdef HAVE_MESSAGES
173 MHD_DLOG (connection->daemon,
174 _("Error: received handshake message out of context\n"));
175#endif
176 MHD_connection_close_ (connection,
177 MHD_REQUEST_TERMINATED_WITH_ERROR);
178 return false; 169 return false;
179 } 170 }
171 /* handshake failed */
172 connection->tls_state = MHD_TLS_CONN_TLS_FAILED;
173#ifdef HAVE_MESSAGES
174 MHD_DLOG (connection->daemon,
175 _ ("Error: received handshake message out of context\n"));
176#endif
177 MHD_connection_close_ (connection,
178 MHD_REQUEST_TERMINATED_WITH_ERROR);
179 return false;
180 }
180 return true; 181 return true;
181} 182}
182 183
@@ -205,23 +206,23 @@ bool
205MHD_tls_connection_shutdown (struct MHD_Connection *connection) 206MHD_tls_connection_shutdown (struct MHD_Connection *connection)
206{ 207{
207 if (MHD_TLS_CONN_WR_CLOSED > connection->tls_state) 208 if (MHD_TLS_CONN_WR_CLOSED > connection->tls_state)
209 {
210 const int res =
211 gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR);
212 if (GNUTLS_E_SUCCESS == res)
213 {
214 connection->tls_state = MHD_TLS_CONN_WR_CLOSED;
215 return true;
216 }
217 if ((GNUTLS_E_AGAIN == res) ||
218 (GNUTLS_E_INTERRUPTED == res))
208 { 219 {
209 const int res = 220 connection->tls_state = MHD_TLS_CONN_WR_CLOSING;
210 gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR); 221 return true;
211 if (GNUTLS_E_SUCCESS == res)
212 {
213 connection->tls_state = MHD_TLS_CONN_WR_CLOSED;
214 return true;
215 }
216 if ((GNUTLS_E_AGAIN == res) ||
217 (GNUTLS_E_INTERRUPTED == res))
218 {
219 connection->tls_state = MHD_TLS_CONN_WR_CLOSING;
220 return true;
221 }
222 else
223 connection->tls_state = MHD_TLS_CONN_TLS_FAILED;
224 } 222 }
223 else
224 connection->tls_state = MHD_TLS_CONN_TLS_FAILED;
225 }
225 return false; 226 return false;
226} 227}
227 228
diff --git a/src/microhttpd/connection_https.h b/src/microhttpd/connection_https.h
index e91a84d3..142c8da8 100644
--- a/src/microhttpd/connection_https.h
+++ b/src/microhttpd/connection_https.h
@@ -35,7 +35,7 @@
35 * 35 *
36 * @param connection which callbacks should be modified 36 * @param connection which callbacks should be modified
37 */ 37 */
38void 38void
39MHD_set_https_callbacks (struct MHD_Connection *connection); 39MHD_set_https_callbacks (struct MHD_Connection *connection);
40 40
41 41
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index fb4abd5d..97e0ec30 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -115,7 +115,7 @@ close_all_connections (struct MHD_Daemon *daemon);
115 */ 115 */
116static int 116static int
117MHD_epoll (struct MHD_Daemon *daemon, 117MHD_epoll (struct MHD_Daemon *daemon,
118 int may_block); 118 int may_block);
119 119
120#endif /* EPOLL_SUPPORT */ 120#endif /* EPOLL_SUPPORT */
121 121
@@ -130,21 +130,21 @@ MHD_epoll (struct MHD_Daemon *daemon,
130 */ 130 */
131static void 131static void
132mhd_panic_std (void *cls, 132mhd_panic_std (void *cls,
133 const char *file, 133 const char *file,
134 unsigned int line, 134 unsigned int line,
135 const char *reason) 135 const char *reason)
136{ 136{
137 (void)cls; /* Mute compiler warning. */ 137 (void) cls; /* Mute compiler warning. */
138#ifdef HAVE_MESSAGES 138#ifdef HAVE_MESSAGES
139 fprintf (stderr, 139 fprintf (stderr,
140 _("Fatal error in GNU libmicrohttpd %s:%u: %s\n"), 140 _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
141 file, 141 file,
142 line, 142 line,
143 reason); 143 reason);
144#else /* ! HAVE_MESSAGES */ 144#else /* ! HAVE_MESSAGES */
145 (void)file; /* Mute compiler warning. */ 145 (void) file; /* Mute compiler warning. */
146 (void)line; /* Mute compiler warning. */ 146 (void) line; /* Mute compiler warning. */
147 (void)reason; /* Mute compiler warning. */ 147 (void) reason; /* Mute compiler warning. */
148#endif 148#endif
149 abort (); 149 abort ();
150} 150}
@@ -164,7 +164,7 @@ void *mhd_panic_cls = NULL;
164 * Globally initialise library. 164 * Globally initialise library.
165 */ 165 */
166void 166void
167MHD_init(void); 167MHD_init (void);
168 168
169 169
170#if defined(MHD_WINSOCK_SOCKETS) 170#if defined(MHD_WINSOCK_SOCKETS)
@@ -179,7 +179,7 @@ static int mhd_winsock_inited_ = 0;
179 * Do nothing - global initialisation is 179 * Do nothing - global initialisation is
180 * performed by library constructor. 180 * performed by library constructor.
181 */ 181 */
182#define MHD_check_global_init_() (void)0 182#define MHD_check_global_init_() (void) 0
183#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */ 183#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */
184/** 184/**
185 * Track global initialisation 185 * Track global initialisation
@@ -191,7 +191,7 @@ volatile int global_init_count = 0;
191/** 191/**
192 * Global initialisation mutex 192 * Global initialisation mutex
193 */ 193 */
194MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); 194MHD_MUTEX_STATIC_DEFN_INIT_ (global_init_mutex_);
195#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 195#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
196#endif 196#endif
197 197
@@ -205,14 +205,14 @@ MHD_check_global_init_ (void)
205{ 205{
206#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 206#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
207#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 207#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
208 MHD_mutex_lock_chk_(&global_init_mutex_); 208 MHD_mutex_lock_chk_ (&global_init_mutex_);
209#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 209#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
210#endif 210#endif
211 if (0 == global_init_count++) 211 if (0 == global_init_count++)
212 MHD_init (); 212 MHD_init ();
213#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 213#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
214#ifdef MHD_MUTEX_STATIC_DEFN_INIT_ 214#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
215 MHD_mutex_unlock_chk_(&global_init_mutex_); 215 MHD_mutex_unlock_chk_ (&global_init_mutex_);
216#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ 216#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
217#endif 217#endif
218} 218}
@@ -227,9 +227,9 @@ MHD_default_logger_ (void *cls,
227 const char *fm, 227 const char *fm,
228 va_list ap) 228 va_list ap)
229{ 229{
230 vfprintf ((FILE*)cls, fm, ap); 230 vfprintf ((FILE*) cls, fm, ap);
231#ifdef _DEBUG 231#ifdef _DEBUG
232 fflush ((FILE*)cls); 232 fflush ((FILE*) cls);
233#endif /* _DEBUG */ 233#endif /* _DEBUG */
234} 234}
235 235
@@ -308,7 +308,7 @@ static void
308MHD_ip_count_lock (struct MHD_Daemon *daemon) 308MHD_ip_count_lock (struct MHD_Daemon *daemon)
309{ 309{
310#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 310#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
311 MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex); 311 MHD_mutex_lock_chk_ (&daemon->per_ip_connection_mutex);
312#else 312#else
313 (void) daemon; 313 (void) daemon;
314#endif 314#endif
@@ -324,7 +324,7 @@ static void
324MHD_ip_count_unlock (struct MHD_Daemon *daemon) 324MHD_ip_count_unlock (struct MHD_Daemon *daemon)
325{ 325{
326#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 326#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
327 MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex); 327 MHD_mutex_unlock_chk_ (&daemon->per_ip_connection_mutex);
328#else 328#else
329 (void) daemon; 329 (void) daemon;
330#endif 330#endif
@@ -361,37 +361,37 @@ MHD_ip_addr_compare (const void *a1,
361 */ 361 */
362static int 362static int
363MHD_ip_addr_to_key (const struct sockaddr *addr, 363MHD_ip_addr_to_key (const struct sockaddr *addr,
364 socklen_t addrlen, 364 socklen_t addrlen,
365 struct MHD_IPCount *key) 365 struct MHD_IPCount *key)
366{ 366{
367 memset(key, 367 memset (key,
368 0, 368 0,
369 sizeof(*key)); 369 sizeof(*key));
370 370
371 /* IPv4 addresses */ 371 /* IPv4 addresses */
372 if (sizeof (struct sockaddr_in) == addrlen) 372 if (sizeof (struct sockaddr_in) == addrlen)
373 { 373 {
374 const struct sockaddr_in *addr4 = (const struct sockaddr_in*) addr; 374 const struct sockaddr_in *addr4 = (const struct sockaddr_in*) addr;
375 375
376 key->family = AF_INET; 376 key->family = AF_INET;
377 memcpy (&key->addr.ipv4, 377 memcpy (&key->addr.ipv4,
378 &addr4->sin_addr, 378 &addr4->sin_addr,
379 sizeof(addr4->sin_addr)); 379 sizeof(addr4->sin_addr));
380 return MHD_YES; 380 return MHD_YES;
381 } 381 }
382 382
383#if HAVE_INET6 383#if HAVE_INET6
384 /* IPv6 addresses */ 384 /* IPv6 addresses */
385 if (sizeof (struct sockaddr_in6) == addrlen) 385 if (sizeof (struct sockaddr_in6) == addrlen)
386 { 386 {
387 const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*) addr; 387 const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*) addr;
388 388
389 key->family = AF_INET6; 389 key->family = AF_INET6;
390 memcpy (&key->addr.ipv6, 390 memcpy (&key->addr.ipv6,
391 &addr6->sin6_addr, 391 &addr6->sin6_addr,
392 sizeof(addr6->sin6_addr)); 392 sizeof(addr6->sin6_addr));
393 return MHD_YES; 393 return MHD_YES;
394 } 394 }
395#endif 395#endif
396 396
397 /* Some other address */ 397 /* Some other address */
@@ -412,8 +412,8 @@ MHD_ip_addr_to_key (const struct sockaddr *addr,
412 */ 412 */
413static int 413static int
414MHD_ip_limit_add (struct MHD_Daemon *daemon, 414MHD_ip_limit_add (struct MHD_Daemon *daemon,
415 const struct sockaddr *addr, 415 const struct sockaddr *addr,
416 socklen_t addrlen) 416 socklen_t addrlen)
417{ 417{
418 struct MHD_IPCount *key; 418 struct MHD_IPCount *key;
419 void **nodep; 419 void **nodep;
@@ -432,30 +432,30 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
432 if (MHD_NO == MHD_ip_addr_to_key (addr, 432 if (MHD_NO == MHD_ip_addr_to_key (addr,
433 addrlen, 433 addrlen,
434 key)) 434 key))
435 { 435 {
436 /* Allow unhandled address types through */ 436 /* Allow unhandled address types through */
437 free (key); 437 free (key);
438 return MHD_YES; 438 return MHD_YES;
439 } 439 }
440 MHD_ip_count_lock (daemon); 440 MHD_ip_count_lock (daemon);
441 441
442 /* Search for the IP address */ 442 /* Search for the IP address */
443 if (NULL == (nodep = tsearch (key, 443 if (NULL == (nodep = tsearch (key,
444 &daemon->per_ip_connection_count, 444 &daemon->per_ip_connection_count,
445 &MHD_ip_addr_compare))) 445 &MHD_ip_addr_compare)))
446 { 446 {
447#ifdef HAVE_MESSAGES 447#ifdef HAVE_MESSAGES
448 MHD_DLOG (daemon, 448 MHD_DLOG (daemon,
449 _("Failed to add IP connection count node\n")); 449 _ ("Failed to add IP connection count node\n"));
450#endif 450#endif
451 MHD_ip_count_unlock (daemon); 451 MHD_ip_count_unlock (daemon);
452 free (key); 452 free (key);
453 return MHD_NO; 453 return MHD_NO;
454 } 454 }
455 node = *nodep; 455 node = *nodep;
456 /* If we got an existing node back, free the one we created */ 456 /* If we got an existing node back, free the one we created */
457 if (node != key) 457 if (node != key)
458 free(key); 458 free (key);
459 key = (struct MHD_IPCount *) node; 459 key = (struct MHD_IPCount *) node;
460 /* Test if there is room for another connection; if so, 460 /* Test if there is room for another connection; if so,
461 * increment count */ 461 * increment count */
@@ -478,8 +478,8 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
478 */ 478 */
479static void 479static void
480MHD_ip_limit_del (struct MHD_Daemon *daemon, 480MHD_ip_limit_del (struct MHD_Daemon *daemon,
481 const struct sockaddr *addr, 481 const struct sockaddr *addr,
482 socklen_t addrlen) 482 socklen_t addrlen)
483{ 483{
484 struct MHD_IPCount search_key; 484 struct MHD_IPCount search_key;
485 struct MHD_IPCount *found_key; 485 struct MHD_IPCount *found_key;
@@ -499,27 +499,27 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
499 499
500 /* Search for the IP address */ 500 /* Search for the IP address */
501 if (NULL == (nodep = tfind (&search_key, 501 if (NULL == (nodep = tfind (&search_key,
502 &daemon->per_ip_connection_count, 502 &daemon->per_ip_connection_count,
503 &MHD_ip_addr_compare))) 503 &MHD_ip_addr_compare)))
504 { 504 {
505 /* Something's wrong if we couldn't find an IP address 505 /* Something's wrong if we couldn't find an IP address
506 * that was previously added */ 506 * that was previously added */
507 MHD_PANIC (_("Failed to find previously-added IP address\n")); 507 MHD_PANIC (_ ("Failed to find previously-added IP address\n"));
508 } 508 }
509 found_key = (struct MHD_IPCount *) *nodep; 509 found_key = (struct MHD_IPCount *) *nodep;
510 /* Validate existing count for IP address */ 510 /* Validate existing count for IP address */
511 if (0 == found_key->count) 511 if (0 == found_key->count)
512 { 512 {
513 MHD_PANIC (_("Previously-added IP address had counter of zero\n")); 513 MHD_PANIC (_ ("Previously-added IP address had counter of zero\n"));
514 } 514 }
515 /* Remove the node entirely if count reduces to 0 */ 515 /* Remove the node entirely if count reduces to 0 */
516 if (0 == --found_key->count) 516 if (0 == --found_key->count)
517 { 517 {
518 tdelete (found_key, 518 tdelete (found_key,
519 &daemon->per_ip_connection_count, 519 &daemon->per_ip_connection_count,
520 &MHD_ip_addr_compare); 520 &MHD_ip_addr_compare);
521 free (found_key); 521 free (found_key);
522 } 522 }
523 523
524 MHD_ip_count_unlock (daemon); 524 MHD_ip_count_unlock (daemon);
525} 525}
@@ -541,103 +541,104 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
541 541
542#if GNUTLS_VERSION_MAJOR >= 3 542#if GNUTLS_VERSION_MAJOR >= 3
543 if (NULL != daemon->cert_callback) 543 if (NULL != daemon->cert_callback)
544 { 544 {
545 gnutls_certificate_set_retrieve_function2 (daemon->x509_cred, 545 gnutls_certificate_set_retrieve_function2 (daemon->x509_cred,
546 daemon->cert_callback); 546 daemon->cert_callback);
547 } 547 }
548#endif 548#endif
549#if GNUTLS_VERSION_NUMBER >= 0x030603 549#if GNUTLS_VERSION_NUMBER >= 0x030603
550 else if (NULL != daemon->cert_callback2) 550 else if (NULL != daemon->cert_callback2)
551 { 551 {
552 gnutls_certificate_set_retrieve_function3 (daemon->x509_cred, 552 gnutls_certificate_set_retrieve_function3 (daemon->x509_cred,
553 daemon->cert_callback2); 553 daemon->cert_callback2);
554 } 554 }
555#endif 555#endif
556 556
557 if (NULL != daemon->https_mem_trust) 557 if (NULL != daemon->https_mem_trust)
558 {
559 size_t paramlen;
560 paramlen = strlen (daemon->https_mem_trust);
561 if (UINT_MAX < paramlen)
558 { 562 {
559 size_t paramlen;
560 paramlen = strlen (daemon->https_mem_trust);
561 if (UINT_MAX < paramlen)
562 {
563#ifdef HAVE_MESSAGES 563#ifdef HAVE_MESSAGES
564 MHD_DLOG(daemon, 564 MHD_DLOG (daemon,
565 "Too long trust certificate\n"); 565 "Too long trust certificate\n");
566#endif 566#endif
567 return -1; 567 return -1;
568 } 568 }
569 cert.data = (unsigned char *) daemon->https_mem_trust; 569 cert.data = (unsigned char *) daemon->https_mem_trust;
570 cert.size = (unsigned int) paramlen; 570 cert.size = (unsigned int) paramlen;
571 if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, 571 if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred,
572 &cert, 572 &cert,
573 GNUTLS_X509_FMT_PEM) < 0) 573 GNUTLS_X509_FMT_PEM) < 0)
574 { 574 {
575#ifdef HAVE_MESSAGES 575#ifdef HAVE_MESSAGES
576 MHD_DLOG(daemon, 576 MHD_DLOG (daemon,
577 "Bad trust certificate format\n"); 577 "Bad trust certificate format\n");
578#endif 578#endif
579 return -1; 579 return -1;
580 }
581 } 580 }
581 }
582 582
583 if (daemon->have_dhparams) 583 if (daemon->have_dhparams)
584 { 584 {
585 gnutls_certificate_set_dh_params (daemon->x509_cred, 585 gnutls_certificate_set_dh_params (daemon->x509_cred,
586 daemon->https_mem_dhparams); 586 daemon->https_mem_dhparams);
587 } 587 }
588 /* certificate & key loaded from memory */ 588 /* certificate & key loaded from memory */
589 if ( (NULL != daemon->https_mem_cert) && 589 if ( (NULL != daemon->https_mem_cert) &&
590 (NULL != daemon->https_mem_key) ) 590 (NULL != daemon->https_mem_key) )
591 { 591 {
592 size_t param1len; 592 size_t param1len;
593 size_t param2len; 593 size_t param2len;
594 594
595 param1len = strlen (daemon->https_mem_key); 595 param1len = strlen (daemon->https_mem_key);
596 param2len = strlen (daemon->https_mem_cert); 596 param2len = strlen (daemon->https_mem_cert);
597 if ( (UINT_MAX < param1len) || 597 if ( (UINT_MAX < param1len) ||
598 (UINT_MAX < param2len) ) 598 (UINT_MAX < param2len) )
599 { 599 {
600#ifdef HAVE_MESSAGES 600#ifdef HAVE_MESSAGES
601 MHD_DLOG(daemon, 601 MHD_DLOG (daemon,
602 "Too long key or certificate\n"); 602 "Too long key or certificate\n");
603#endif 603#endif
604 return -1; 604 return -1;
605 } 605 }
606 key.data = (unsigned char *) daemon->https_mem_key; 606 key.data = (unsigned char *) daemon->https_mem_key;
607 key.size = (unsigned int)param1len; 607 key.size = (unsigned int) param1len;
608 cert.data = (unsigned char *) daemon->https_mem_cert; 608 cert.data = (unsigned char *) daemon->https_mem_cert;
609 cert.size = (unsigned int)param2len; 609 cert.size = (unsigned int) param2len;
610 610
611 if (NULL != daemon->https_key_password) { 611 if (NULL != daemon->https_key_password)
612 {
612#if GNUTLS_VERSION_NUMBER >= 0x030111 613#if GNUTLS_VERSION_NUMBER >= 0x030111
613 ret = gnutls_certificate_set_x509_key_mem2 (daemon->x509_cred, 614 ret = gnutls_certificate_set_x509_key_mem2 (daemon->x509_cred,
614 &cert, 615 &cert,
615 &key, 616 &key,
616 GNUTLS_X509_FMT_PEM, 617 GNUTLS_X509_FMT_PEM,
617 daemon->https_key_password, 618 daemon->https_key_password,
618 0); 619 0);
619#else 620#else
620#ifdef HAVE_MESSAGES 621#ifdef HAVE_MESSAGES
621 MHD_DLOG (daemon, 622 MHD_DLOG (daemon,
622 _("Failed to setup x509 certificate/key: pre 3.X.X version " \ 623 _ ("Failed to setup x509 certificate/key: pre 3.X.X version " \
623 "of GnuTLS does not support setting key password")); 624 "of GnuTLS does not support setting key password"));
624#endif 625#endif
625 return -1; 626 return -1;
626#endif 627#endif
627 } 628 }
628 else 629 else
629 ret = gnutls_certificate_set_x509_key_mem (daemon->x509_cred, 630 ret = gnutls_certificate_set_x509_key_mem (daemon->x509_cred,
630 &cert, 631 &cert,
631 &key, 632 &key,
632 GNUTLS_X509_FMT_PEM); 633 GNUTLS_X509_FMT_PEM);
633#ifdef HAVE_MESSAGES 634#ifdef HAVE_MESSAGES
634 if (0 != ret) 635 if (0 != ret)
635 MHD_DLOG (daemon, 636 MHD_DLOG (daemon,
636 "GnuTLS failed to setup x509 certificate/key: %s\n", 637 "GnuTLS failed to setup x509 certificate/key: %s\n",
637 gnutls_strerror (ret)); 638 gnutls_strerror (ret));
638#endif 639#endif
639 return ret; 640 return ret;
640 } 641 }
641#if GNUTLS_VERSION_MAJOR >= 3 642#if GNUTLS_VERSION_MAJOR >= 3
642 if (NULL != daemon->cert_callback) 643 if (NULL != daemon->cert_callback)
643 return 0; 644 return 0;
@@ -663,25 +664,25 @@ static int
663MHD_TLS_init (struct MHD_Daemon *daemon) 664MHD_TLS_init (struct MHD_Daemon *daemon)
664{ 665{
665 switch (daemon->cred_type) 666 switch (daemon->cred_type)
666 { 667 {
667 case GNUTLS_CRD_CERTIFICATE: 668 case GNUTLS_CRD_CERTIFICATE:
668 if (0 != 669 if (0 !=
669 gnutls_certificate_allocate_credentials (&daemon->x509_cred)) 670 gnutls_certificate_allocate_credentials (&daemon->x509_cred))
670 return GNUTLS_E_MEMORY_ERROR; 671 return GNUTLS_E_MEMORY_ERROR;
671 return MHD_init_daemon_certificate (daemon); 672 return MHD_init_daemon_certificate (daemon);
672 case GNUTLS_CRD_PSK: 673 case GNUTLS_CRD_PSK:
673 if (0 != 674 if (0 !=
674 gnutls_psk_allocate_server_credentials (&daemon->psk_cred)) 675 gnutls_psk_allocate_server_credentials (&daemon->psk_cred))
675 return GNUTLS_E_MEMORY_ERROR; 676 return GNUTLS_E_MEMORY_ERROR;
676 return 0; 677 return 0;
677 default: 678 default:
678#ifdef HAVE_MESSAGES 679#ifdef HAVE_MESSAGES
679 MHD_DLOG (daemon, 680 MHD_DLOG (daemon,
680 _("Error: invalid credentials type %d specified.\n"), 681 _ ("Error: invalid credentials type %d specified.\n"),
681 daemon->cred_type); 682 daemon->cred_type);
682#endif 683#endif
683 return -1; 684 return -1;
684 } 685 }
685} 686}
686#endif /* HTTPS_SUPPORT */ 687#endif /* HTTPS_SUPPORT */
687 688
@@ -761,55 +762,55 @@ urh_to_fdset (struct MHD_UpgradeResponseHandle *urh,
761 /* Do not add to 'es' only if socket is closed 762 /* Do not add to 'es' only if socket is closed
762 * or not used anymore. */ 763 * or not used anymore. */
763 if (MHD_INVALID_SOCKET != conn_sckt) 764 if (MHD_INVALID_SOCKET != conn_sckt)
764 { 765 {
765 if ( (urh->in_buffer_used < urh->in_buffer_size) && 766 if ( (urh->in_buffer_used < urh->in_buffer_size) &&
766 (! MHD_add_to_fd_set_ (conn_sckt, 767 (! MHD_add_to_fd_set_ (conn_sckt,
767 rs, 768 rs,
768 max_fd, 769 max_fd,
769 fd_setsize)) ) 770 fd_setsize)) )
770 res = false; 771 res = false;
771 if ( (0 != urh->out_buffer_used) && 772 if ( (0 != urh->out_buffer_used) &&
772 (! MHD_add_to_fd_set_ (conn_sckt, 773 (! MHD_add_to_fd_set_ (conn_sckt,
773 ws, 774 ws,
774 max_fd, 775 max_fd,
775 fd_setsize)) ) 776 fd_setsize)) )
776 res = false; 777 res = false;
777 /* Do not monitor again for errors if error was detected before as 778 /* Do not monitor again for errors if error was detected before as
778 * error state is remembered. */ 779 * error state is remembered. */
779 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) && 780 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) &&
780 ((0 != urh->in_buffer_size) || 781 ((0 != urh->in_buffer_size) ||
781 (0 != urh->out_buffer_size) || 782 (0 != urh->out_buffer_size) ||
782 (0 != urh->out_buffer_used))) 783 (0 != urh->out_buffer_used)))
783 MHD_add_to_fd_set_ (conn_sckt, 784 MHD_add_to_fd_set_ (conn_sckt,
784 es, 785 es,
785 max_fd, 786 max_fd,
786 fd_setsize); 787 fd_setsize);
787 } 788 }
788 if (MHD_INVALID_SOCKET != mhd_sckt) 789 if (MHD_INVALID_SOCKET != mhd_sckt)
789 { 790 {
790 if ( (urh->out_buffer_used < urh->out_buffer_size) && 791 if ( (urh->out_buffer_used < urh->out_buffer_size) &&
791 (! MHD_add_to_fd_set_ (mhd_sckt, 792 (! MHD_add_to_fd_set_ (mhd_sckt,
792 rs, 793 rs,
793 max_fd, 794 max_fd,
794 fd_setsize)) ) 795 fd_setsize)) )
795 res = false; 796 res = false;
796 if ( (0 != urh->in_buffer_used) && 797 if ( (0 != urh->in_buffer_used) &&
797 (! MHD_add_to_fd_set_ (mhd_sckt, 798 (! MHD_add_to_fd_set_ (mhd_sckt,
798 ws, 799 ws,
799 max_fd, 800 max_fd,
800 fd_setsize)) ) 801 fd_setsize)) )
801 res = false; 802 res = false;
802 /* Do not monitor again for errors if error was detected before as 803 /* Do not monitor again for errors if error was detected before as
803 * error state is remembered. */ 804 * error state is remembered. */
804 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) && 805 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) &&
805 ((0 != urh->out_buffer_size) || 806 ((0 != urh->out_buffer_size) ||
806 (0 != urh->in_buffer_size) || 807 (0 != urh->in_buffer_size) ||
807 (0 != urh->in_buffer_used))) 808 (0 != urh->in_buffer_used)))
808 MHD_add_to_fd_set_ (mhd_sckt, 809 MHD_add_to_fd_set_ (mhd_sckt,
809 es, 810 es,
810 max_fd, 811 max_fd,
811 fd_setsize); 812 fd_setsize);
812 } 813 }
813 814
814 return res; 815 return res;
815} 816}
@@ -838,23 +839,23 @@ urh_from_fdset (struct MHD_UpgradeResponseHandle *urh,
838 urh->mhd.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); 839 urh->mhd.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY);
839 840
840 if (MHD_INVALID_SOCKET != conn_sckt) 841 if (MHD_INVALID_SOCKET != conn_sckt)
841 { 842 {
842 if (FD_ISSET (conn_sckt, rs)) 843 if (FD_ISSET (conn_sckt, rs))
843 urh->app.celi |= MHD_EPOLL_STATE_READ_READY; 844 urh->app.celi |= MHD_EPOLL_STATE_READ_READY;
844 if (FD_ISSET (conn_sckt, ws)) 845 if (FD_ISSET (conn_sckt, ws))
845 urh->app.celi |= MHD_EPOLL_STATE_WRITE_READY; 846 urh->app.celi |= MHD_EPOLL_STATE_WRITE_READY;
846 if (FD_ISSET (conn_sckt, es)) 847 if (FD_ISSET (conn_sckt, es))
847 urh->app.celi |= MHD_EPOLL_STATE_ERROR; 848 urh->app.celi |= MHD_EPOLL_STATE_ERROR;
848 } 849 }
849 if ((MHD_INVALID_SOCKET != mhd_sckt)) 850 if ((MHD_INVALID_SOCKET != mhd_sckt))
850 { 851 {
851 if (FD_ISSET (mhd_sckt, rs)) 852 if (FD_ISSET (mhd_sckt, rs))
852 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY; 853 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY;
853 if (FD_ISSET (mhd_sckt, ws)) 854 if (FD_ISSET (mhd_sckt, ws))
854 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY; 855 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY;
855 if (FD_ISSET (mhd_sckt, es)) 856 if (FD_ISSET (mhd_sckt, es))
856 urh->mhd.celi |= MHD_EPOLL_STATE_ERROR; 857 urh->mhd.celi |= MHD_EPOLL_STATE_ERROR;
857 } 858 }
858} 859}
859 860
860#ifdef HAVE_POLL 861#ifdef HAVE_POLL
@@ -869,7 +870,7 @@ urh_from_fdset (struct MHD_UpgradeResponseHandle *urh,
869 */ 870 */
870static void 871static void
871urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh, 872urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh,
872 struct pollfd p[2]) 873 struct pollfd p[2])
873{ 874{
874 p[0].events = 0; 875 p[0].events = 0;
875 p[1].events = 0; 876 p[1].events = 0;
@@ -910,12 +911,12 @@ urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh,
910 */ 911 */
911static void 912static void
912urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh, 913urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh,
913 struct pollfd p[2]) 914 struct pollfd p[2])
914{ 915{
915 p[0].fd = urh->connection->socket_fd; 916 p[0].fd = urh->connection->socket_fd;
916 p[1].fd = urh->mhd.socket; 917 p[1].fd = urh->mhd.socket;
917 urh_update_pollfd (urh, 918 urh_update_pollfd (urh,
918 p); 919 p);
919} 920}
920 921
921 922
@@ -926,7 +927,7 @@ urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh,
926 */ 927 */
927static void 928static void
928urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh, 929urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh,
929 struct pollfd p[2]) 930 struct pollfd p[2])
930{ 931{
931 /* Reset read/write ready, preserve error state. */ 932 /* Reset read/write ready, preserve error state. */
932 urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); 933 urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY);
@@ -998,85 +999,85 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
998 * or INFO_WRITE sockets will not fit 'except_fd_set'. */ 999 * or INFO_WRITE sockets will not fit 'except_fd_set'. */
999 /* Start from oldest connections. Make sense for W32 FDSETs. */ 1000 /* Start from oldest connections. Make sense for W32 FDSETs. */
1000 for (pos = daemon->connections_tail; NULL != pos; pos = posn) 1001 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
1001 { 1002 {
1002 posn = pos->prev; 1003 posn = pos->prev;
1003 1004
1004 switch (pos->event_loop_info) 1005 switch (pos->event_loop_info)
1005 { 1006 {
1006 case MHD_EVENT_LOOP_INFO_READ: 1007 case MHD_EVENT_LOOP_INFO_READ:
1007 if (! MHD_add_to_fd_set_ (pos->socket_fd, 1008 if (! MHD_add_to_fd_set_ (pos->socket_fd,
1008 read_fd_set, 1009 read_fd_set,
1009 max_fd, 1010 max_fd,
1010 fd_setsize)) 1011 fd_setsize))
1011 result = MHD_NO; 1012 result = MHD_NO;
1012#ifdef MHD_POSIX_SOCKETS 1013#ifdef MHD_POSIX_SOCKETS
1013 MHD_add_to_fd_set_ (pos->socket_fd, 1014 MHD_add_to_fd_set_ (pos->socket_fd,
1014 except_fd_set, 1015 except_fd_set,
1015 max_fd, 1016 max_fd,
1016 fd_setsize); 1017 fd_setsize);
1017#endif /* MHD_POSIX_SOCKETS */ 1018#endif /* MHD_POSIX_SOCKETS */
1018 break; 1019 break;
1019 case MHD_EVENT_LOOP_INFO_WRITE: 1020 case MHD_EVENT_LOOP_INFO_WRITE:
1020 if (! MHD_add_to_fd_set_ (pos->socket_fd, 1021 if (! MHD_add_to_fd_set_ (pos->socket_fd,
1021 write_fd_set, 1022 write_fd_set,
1022 max_fd, 1023 max_fd,
1023 fd_setsize)) 1024 fd_setsize))
1024 result = MHD_NO; 1025 result = MHD_NO;
1025#ifdef MHD_POSIX_SOCKETS 1026#ifdef MHD_POSIX_SOCKETS
1026 MHD_add_to_fd_set_ (pos->socket_fd, 1027 MHD_add_to_fd_set_ (pos->socket_fd,
1027 except_fd_set, 1028 except_fd_set,
1028 max_fd, 1029 max_fd,
1029 fd_setsize); 1030 fd_setsize);
1030#endif /* MHD_POSIX_SOCKETS */ 1031#endif /* MHD_POSIX_SOCKETS */
1031 break; 1032 break;
1032 case MHD_EVENT_LOOP_INFO_BLOCK: 1033 case MHD_EVENT_LOOP_INFO_BLOCK:
1033 if ( (NULL == except_fd_set) || 1034 if ( (NULL == except_fd_set) ||
1034 ! MHD_add_to_fd_set_ (pos->socket_fd, 1035 ! MHD_add_to_fd_set_ (pos->socket_fd,
1035 except_fd_set, 1036 except_fd_set,
1036 max_fd, 1037 max_fd,
1037 fd_setsize)) 1038 fd_setsize))
1038 result = MHD_NO; 1039 result = MHD_NO;
1039 break; 1040 break;
1040 case MHD_EVENT_LOOP_INFO_CLEANUP: 1041 case MHD_EVENT_LOOP_INFO_CLEANUP:
1041 /* this should never happen */ 1042 /* this should never happen */
1042 break; 1043 break;
1043 }
1044 } 1044 }
1045 }
1045#ifdef MHD_WINSOCK_SOCKETS 1046#ifdef MHD_WINSOCK_SOCKETS
1046 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets 1047 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets
1047 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will 1048 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will
1048 * not be pushed out. */ 1049 * not be pushed out. */
1049 for (pos = daemon->connections_tail; NULL != pos; pos = posn) 1050 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
1050 { 1051 {
1051 posn = pos->prev; 1052 posn = pos->prev;
1052 MHD_add_to_fd_set_ (pos->socket_fd, 1053 MHD_add_to_fd_set_ (pos->socket_fd,
1053 except_fd_set, 1054 except_fd_set,
1054 max_fd, 1055 max_fd,
1055 fd_setsize); 1056 fd_setsize);
1056 } 1057 }
1057#endif /* MHD_WINSOCK_SOCKETS */ 1058#endif /* MHD_WINSOCK_SOCKETS */
1058#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 1059#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1059 { 1060 {
1060 struct MHD_UpgradeResponseHandle *urh; 1061 struct MHD_UpgradeResponseHandle *urh;
1061 1062
1062 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) 1063 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
1063 { 1064 {
1064 if (MHD_NO == 1065 if (MHD_NO ==
1065 urh_to_fdset (urh, 1066 urh_to_fdset (urh,
1066 read_fd_set, 1067 read_fd_set,
1067 write_fd_set, 1068 write_fd_set,
1068 except_fd_set, 1069 except_fd_set,
1069 max_fd, 1070 max_fd,
1070 fd_setsize)) 1071 fd_setsize))
1071 result = MHD_NO; 1072 result = MHD_NO;
1072 } 1073 }
1073 } 1074 }
1074#endif 1075#endif
1075#if DEBUG_CONNECT 1076#if DEBUG_CONNECT
1076#ifdef HAVE_MESSAGES 1077#ifdef HAVE_MESSAGES
1077 if (NULL != max_fd) 1078 if (NULL != max_fd)
1078 MHD_DLOG (daemon, 1079 MHD_DLOG (daemon,
1079 _("Maximum socket in select set: %d\n"), 1080 _ ("Maximum socket in select set: %d\n"),
1080 *max_fd); 1081 *max_fd);
1081#endif 1082#endif
1082#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 1083#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
@@ -1118,11 +1119,11 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
1118 */ 1119 */
1119int 1120int
1120MHD_get_fdset2 (struct MHD_Daemon *daemon, 1121MHD_get_fdset2 (struct MHD_Daemon *daemon,
1121 fd_set *read_fd_set, 1122 fd_set *read_fd_set,
1122 fd_set *write_fd_set, 1123 fd_set *write_fd_set,
1123 fd_set *except_fd_set, 1124 fd_set *except_fd_set,
1124 MHD_socket *max_fd, 1125 MHD_socket *max_fd,
1125 unsigned int fd_setsize) 1126 unsigned int fd_setsize)
1126{ 1127{
1127 fd_set es; 1128 fd_set es;
1128 1129
@@ -1134,38 +1135,38 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
1134 return MHD_NO; 1135 return MHD_NO;
1135 1136
1136 if (NULL == except_fd_set) 1137 if (NULL == except_fd_set)
1137 { /* Workaround to maintain backward compatibility. */ 1138 { /* Workaround to maintain backward compatibility. */
1138#ifdef HAVE_MESSAGES 1139#ifdef HAVE_MESSAGES
1139 MHD_DLOG (daemon, 1140 MHD_DLOG (daemon,
1140 _("MHD_get_fdset2() called with except_fd_set " 1141 _ ("MHD_get_fdset2() called with except_fd_set "
1141 "set to NULL. Such behavior is unsupported.\n")); 1142 "set to NULL. Such behavior is unsupported.\n"));
1142#endif 1143#endif
1143 FD_ZERO (&es); 1144 FD_ZERO (&es);
1144 except_fd_set = &es; 1145 except_fd_set = &es;
1145 } 1146 }
1146 1147
1147#ifdef EPOLL_SUPPORT 1148#ifdef EPOLL_SUPPORT
1148 if (0 != (daemon->options & MHD_USE_EPOLL)) 1149 if (0 != (daemon->options & MHD_USE_EPOLL))
1149 { 1150 {
1150 if (daemon->shutdown) 1151 if (daemon->shutdown)
1151 return MHD_NO; 1152 return MHD_NO;
1152 1153
1153 /* we're in epoll mode, use the epoll FD as a stand-in for 1154 /* we're in epoll mode, use the epoll FD as a stand-in for
1154 the entire event set */ 1155 the entire event set */
1155 1156
1156 return MHD_add_to_fd_set_ (daemon->epoll_fd, 1157 return MHD_add_to_fd_set_ (daemon->epoll_fd,
1157 read_fd_set, 1158 read_fd_set,
1158 max_fd, 1159 max_fd,
1159 fd_setsize) ? MHD_YES : MHD_NO; 1160 fd_setsize) ? MHD_YES : MHD_NO;
1160 } 1161 }
1161#endif 1162#endif
1162 1163
1163 return internal_get_fdset2 (daemon, 1164 return internal_get_fdset2 (daemon,
1164 read_fd_set, 1165 read_fd_set,
1165 write_fd_set, 1166 write_fd_set,
1166 except_fd_set, 1167 except_fd_set,
1167 max_fd, 1168 max_fd,
1168 fd_setsize); 1169 fd_setsize);
1169} 1170}
1170 1171
1171 1172
@@ -1197,37 +1198,37 @@ call_handlers (struct MHD_Connection *con,
1197 if (con->tls_read_ready) 1198 if (con->tls_read_ready)
1198 read_ready = true; 1199 read_ready = true;
1199#endif /* HTTPS_SUPPORT */ 1200#endif /* HTTPS_SUPPORT */
1200 if (!force_close) 1201 if (! force_close)
1202 {
1203 if ( (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) &&
1204 read_ready)
1201 { 1205 {
1202 if ( (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) && 1206 MHD_connection_handle_read (con);
1203 read_ready) 1207 ret = MHD_connection_handle_idle (con);
1204 { 1208 states_info_processed = true;
1205 MHD_connection_handle_read (con);
1206 ret = MHD_connection_handle_idle (con);
1207 states_info_processed = true;
1208 }
1209 /* No need to check value of 'ret' here as closed connection
1210 * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
1211 if ( (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info) &&
1212 write_ready)
1213 {
1214 MHD_connection_handle_write (con);
1215 ret = MHD_connection_handle_idle (con);
1216 states_info_processed = true;
1217 }
1218 } 1209 }
1219 else 1210 /* No need to check value of 'ret' here as closed connection
1211 * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
1212 if ( (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info) &&
1213 write_ready)
1220 { 1214 {
1221 MHD_connection_close_ (con, 1215 MHD_connection_handle_write (con);
1222 MHD_REQUEST_TERMINATED_WITH_ERROR); 1216 ret = MHD_connection_handle_idle (con);
1223 return MHD_connection_handle_idle (con); 1217 states_info_processed = true;
1224 } 1218 }
1219 }
1220 else
1221 {
1222 MHD_connection_close_ (con,
1223 MHD_REQUEST_TERMINATED_WITH_ERROR);
1224 return MHD_connection_handle_idle (con);
1225 }
1225 1226
1226 if (!states_info_processed) 1227 if (! states_info_processed)
1227 { /* Connection is not read or write ready, but external conditions 1228 { /* Connection is not read or write ready, but external conditions
1228 * may be changed and need to be processed. */ 1229 * may be changed and need to be processed. */
1229 ret = MHD_connection_handle_idle (con); 1230 ret = MHD_connection_handle_idle (con);
1230 } 1231 }
1231 /* Fast track for fast connections. */ 1232 /* Fast track for fast connections. */
1232 /* If full request was read by single read_handler() invocation 1233 /* If full request was read by single read_handler() invocation
1233 and headers were completely prepared by single MHD_connection_handle_idle() 1234 and headers were completely prepared by single MHD_connection_handle_idle()
@@ -1239,23 +1240,23 @@ call_handlers (struct MHD_Connection *con,
1239 /* No need to check 'ret' as connection is always in 1240 /* No need to check 'ret' as connection is always in
1240 * MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */ 1241 * MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */
1241 else if (on_fasttrack && con->sk_nonblck) 1242 else if (on_fasttrack && con->sk_nonblck)
1243 {
1244 if (MHD_CONNECTION_HEADERS_SENDING == con->state)
1242 { 1245 {
1243 if (MHD_CONNECTION_HEADERS_SENDING == con->state) 1246 MHD_connection_handle_write (con);
1244 { 1247 /* Always call 'MHD_connection_handle_idle()' after each read/write. */
1245 MHD_connection_handle_write (con); 1248 ret = MHD_connection_handle_idle (con);
1246 /* Always call 'MHD_connection_handle_idle()' after each read/write. */
1247 ret = MHD_connection_handle_idle (con);
1248 }
1249 /* If all headers were sent by single write_handler() and
1250 * response body is prepared by single MHD_connection_handle_idle()
1251 * call - continue. */
1252 if ((MHD_CONNECTION_NORMAL_BODY_READY == con->state) ||
1253 (MHD_CONNECTION_CHUNKED_BODY_READY == con->state))
1254 {
1255 MHD_connection_handle_write (con);
1256 ret = MHD_connection_handle_idle (con);
1257 }
1258 } 1249 }
1250 /* If all headers were sent by single write_handler() and
1251 * response body is prepared by single MHD_connection_handle_idle()
1252 * call - continue. */
1253 if ((MHD_CONNECTION_NORMAL_BODY_READY == con->state) ||
1254 (MHD_CONNECTION_CHUNKED_BODY_READY == con->state))
1255 {
1256 MHD_connection_handle_write (con);
1257 ret = MHD_connection_handle_idle (con);
1258 }
1259 }
1259 1260
1260 /* All connection's data and states are processed for this turn. 1261 /* All connection's data and states are processed for this turn.
1261 * If connection already has more data to be processed - use 1262 * If connection already has more data to be processed - use
@@ -1267,15 +1268,15 @@ call_handlers (struct MHD_Connection *con,
1267 * without space in read buffer will be marked as 'info block'. */ 1268 * without space in read buffer will be marked as 'info block'. */
1268 if ( (! con->daemon->data_already_pending) && 1269 if ( (! con->daemon->data_already_pending) &&
1269 (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) 1270 (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) )
1270 { 1271 {
1271 if (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info) 1272 if (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info)
1272 con->daemon->data_already_pending = true; 1273 con->daemon->data_already_pending = true;
1273#ifdef HTTPS_SUPPORT 1274#ifdef HTTPS_SUPPORT
1274 else if ( (con->tls_read_ready) && 1275 else if ( (con->tls_read_ready) &&
1275 (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) ) 1276 (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) )
1276 con->daemon->data_already_pending = true; 1277 con->daemon->data_already_pending = true;
1277#endif /* HTTPS_SUPPORT */ 1278#endif /* HTTPS_SUPPORT */
1278 } 1279 }
1279 return ret; 1280 return ret;
1280} 1281}
1281 1282
@@ -1330,55 +1331,58 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1330 * pointers to 'connection' and 'daemon' are not changed 1331 * pointers to 'connection' and 'daemon' are not changed
1331 * during this processing, so no need to chain dereference 1332 * during this processing, so no need to chain dereference
1332 * each time. */ 1333 * each time. */
1333 struct MHD_Connection * const connection = urh->connection; 1334 struct MHD_Connection *const connection = urh->connection;
1334 struct MHD_Daemon * const daemon = connection->daemon; 1335 struct MHD_Daemon *const daemon = connection->daemon;
1335 /* Prevent data races: use same value of 'was_closed' throughout 1336 /* Prevent data races: use same value of 'was_closed' throughout
1336 * this function. If 'was_closed' changed externally in the middle 1337 * this function. If 'was_closed' changed externally in the middle
1337 * of processing - it will be processed on next iteration. */ 1338 * of processing - it will be processed on next iteration. */
1338 bool was_closed; 1339 bool was_closed;
1339 if (daemon->shutdown) 1340 if (daemon->shutdown)
1340 { 1341 {
1341 /* Daemon shutting down, application will not receive any more data. */ 1342 /* Daemon shutting down, application will not receive any more data. */
1342#ifdef HAVE_MESSAGES 1343#ifdef HAVE_MESSAGES
1343 if (! urh->was_closed) 1344 if (! urh->was_closed)
1344 { 1345 {
1345 MHD_DLOG (daemon, 1346 MHD_DLOG (daemon,
1346 _("Initiated daemon shutdown while \"upgraded\" connection was not closed.\n")); 1347 _ (
1347 } 1348 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
1348#endif
1349 urh->was_closed = true;
1350 } 1349 }
1350#endif
1351 urh->was_closed = true;
1352 }
1351 was_closed = urh->was_closed; 1353 was_closed = urh->was_closed;
1352 if (was_closed) 1354 if (was_closed)
1355 {
1356 /* Application was closed connections: no more data
1357 * can be forwarded to application socket. */
1358 if (0 < urh->in_buffer_used)
1353 { 1359 {
1354 /* Application was closed connections: no more data
1355 * can be forwarded to application socket. */
1356 if (0 < urh->in_buffer_used)
1357 {
1358#ifdef HAVE_MESSAGES 1360#ifdef HAVE_MESSAGES
1359 MHD_DLOG (daemon, 1361 MHD_DLOG (daemon,
1360 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \ 1362 _ (
1361 " bytes of data received from remote side: application shut down socket\n"), 1363 "Failed to forward to application "
1362 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used); 1364 MHD_UNSIGNED_LONG_LONG_PRINTF \
1363#endif 1365 " bytes of data received from remote side: application shut down socket\n"),
1364 1366 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used);
1365 } 1367#endif
1366 /* If application signaled MHD about socket closure then 1368
1367 * check for any pending data even if socket is not marked 1369 }
1368 * as 'ready' (signal may arrive after poll()/select()). 1370 /* If application signaled MHD about socket closure then
1369 * Socketpair for forwarding is always in non-blocking mode 1371 * check for any pending data even if socket is not marked
1370 * so no risk that recv() will block the thread. */ 1372 * as 'ready' (signal may arrive after poll()/select()).
1371 if (0 != urh->out_buffer_size) 1373 * Socketpair for forwarding is always in non-blocking mode
1372 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY; 1374 * so no risk that recv() will block the thread. */
1373 /* Discard any data received form remote. */ 1375 if (0 != urh->out_buffer_size)
1374 urh->in_buffer_used = 0; 1376 urh->mhd.celi |= MHD_EPOLL_STATE_READ_READY;
1375 /* Do not try to push data to application. */ 1377 /* Discard any data received form remote. */
1376 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1378 urh->in_buffer_used = 0;
1377 /* Reading from remote client is not required anymore. */ 1379 /* Do not try to push data to application. */
1378 urh->in_buffer_size = 0; 1380 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1379 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1381 /* Reading from remote client is not required anymore. */
1380 connection->tls_read_ready = false; 1382 urh->in_buffer_size = 0;
1381 } 1383 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1384 connection->tls_read_ready = false;
1385 }
1382 1386
1383 /* On some platforms (W32, possibly Darwin) failed send() (send() will always 1387 /* On some platforms (W32, possibly Darwin) failed send() (send() will always
1384 * fail after remote disconnect was detected) may discard data in system 1388 * fail after remote disconnect was detected) may discard data in system
@@ -1399,237 +1403,241 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1399 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->app.celi)) || 1403 if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->app.celi)) ||
1400 (connection->tls_read_ready) ) && 1404 (connection->tls_read_ready) ) &&
1401 (urh->in_buffer_used < urh->in_buffer_size) ) 1405 (urh->in_buffer_used < urh->in_buffer_size) )
1402 { 1406 {
1403 ssize_t res; 1407 ssize_t res;
1404 size_t buf_size; 1408 size_t buf_size;
1405 1409
1406 buf_size = urh->in_buffer_size - urh->in_buffer_used; 1410 buf_size = urh->in_buffer_size - urh->in_buffer_used;
1407 if (buf_size > SSIZE_MAX) 1411 if (buf_size > SSIZE_MAX)
1408 buf_size = SSIZE_MAX; 1412 buf_size = SSIZE_MAX;
1409 1413
1410 connection->tls_read_ready = false; 1414 connection->tls_read_ready = false;
1411 res = gnutls_record_recv (connection->tls_session, 1415 res = gnutls_record_recv (connection->tls_session,
1412 &urh->in_buffer[urh->in_buffer_used], 1416 &urh->in_buffer[urh->in_buffer_used],
1413 buf_size); 1417 buf_size);
1414 if (0 >= res) 1418 if (0 >= res)
1415 { 1419 {
1416 if (GNUTLS_E_INTERRUPTED != res) 1420 if (GNUTLS_E_INTERRUPTED != res)
1417 { 1421 {
1418 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1422 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1419 if (GNUTLS_E_AGAIN != res) 1423 if (GNUTLS_E_AGAIN != res)
1420 {
1421 /* Unrecoverable error on socket was detected or
1422 * socket was disconnected/shut down. */
1423 /* Stop trying to read from this TLS socket. */
1424 urh->in_buffer_size = 0;
1425 }
1426 }
1427 }
1428 else /* 0 < res */
1429 {
1430 urh->in_buffer_used += res;
1431 if (buf_size > (size_t)res)
1432 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1433 else if (0 < gnutls_record_check_pending (connection->tls_session))
1434 connection->tls_read_ready = true;
1435 }
1436 if (MHD_EPOLL_STATE_ERROR ==
1437 ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi))
1438 { 1424 {
1439 /* Unrecoverable error on socket was detected and all 1425 /* Unrecoverable error on socket was detected or
1440 * pending data was read from system buffers. */ 1426 * socket was disconnected/shut down. */
1441 /* Stop trying to read from this TLS socket. */ 1427 /* Stop trying to read from this TLS socket. */
1442 urh->in_buffer_size = 0; 1428 urh->in_buffer_size = 0;
1443 } 1429 }
1430 }
1431 }
1432 else /* 0 < res */
1433 {
1434 urh->in_buffer_used += res;
1435 if (buf_size > (size_t) res)
1436 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1437 else if (0 < gnutls_record_check_pending (connection->tls_session))
1438 connection->tls_read_ready = true;
1439 }
1440 if (MHD_EPOLL_STATE_ERROR ==
1441 ((MHD_EPOLL_STATE_ERROR | MHD_EPOLL_STATE_READ_READY) & urh->app.celi))
1442 {
1443 /* Unrecoverable error on socket was detected and all
1444 * pending data was read from system buffers. */
1445 /* Stop trying to read from this TLS socket. */
1446 urh->in_buffer_size = 0;
1444 } 1447 }
1448 }
1445 1449
1446 /* 1450 /*
1447 * handle reading from application 1451 * handle reading from application
1448 */ 1452 */
1449 if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) && 1453 if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
1450 (urh->out_buffer_used < urh->out_buffer_size) ) 1454 (urh->out_buffer_used < urh->out_buffer_size) )
1451 { 1455 {
1452 ssize_t res; 1456 ssize_t res;
1453 size_t buf_size; 1457 size_t buf_size;
1454 1458
1455 buf_size = urh->out_buffer_size - urh->out_buffer_used; 1459 buf_size = urh->out_buffer_size - urh->out_buffer_used;
1456 if (buf_size > MHD_SCKT_SEND_MAX_SIZE_) 1460 if (buf_size > MHD_SCKT_SEND_MAX_SIZE_)
1457 buf_size = MHD_SCKT_SEND_MAX_SIZE_; 1461 buf_size = MHD_SCKT_SEND_MAX_SIZE_;
1458 1462
1459 res = MHD_recv_ (urh->mhd.socket, 1463 res = MHD_recv_ (urh->mhd.socket,
1460 &urh->out_buffer[urh->out_buffer_used], 1464 &urh->out_buffer[urh->out_buffer_used],
1461 buf_size); 1465 buf_size);
1462 if (0 >= res) 1466 if (0 >= res)
1463 { 1467 {
1464 const int err = MHD_socket_get_error_ (); 1468 const int err = MHD_socket_get_error_ ();
1465 if ((0 == res) || 1469 if ((0 == res) ||
1466 ((! MHD_SCKT_ERR_IS_EINTR_ (err)) && 1470 ((! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
1467 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)))) 1471 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err))))
1468 { 1472 {
1469 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1473 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1470 if ((0 == res) || 1474 if ((0 == res) ||
1471 (was_closed) || 1475 (was_closed) ||
1472 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) || 1476 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
1473 (! MHD_SCKT_ERR_IS_EAGAIN_ (err))) 1477 (! MHD_SCKT_ERR_IS_EAGAIN_ (err)))
1474 {
1475 /* Socket disconnect/shutdown was detected;
1476 * Application signaled about closure of 'upgraded' socket;
1477 * or persistent / unrecoverable error. */
1478 /* Do not try to pull more data from application. */
1479 urh->out_buffer_size = 0;
1480 }
1481 }
1482 }
1483 else /* 0 < res */
1484 {
1485 urh->out_buffer_used += res;
1486 if (buf_size > (size_t)res)
1487 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1488 }
1489 if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
1490 ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
1491 (was_closed) ) )
1492 { 1478 {
1493 /* Unrecoverable error on socket was detected and all 1479 /* Socket disconnect/shutdown was detected;
1494 * pending data was read from system buffers. */ 1480 * Application signaled about closure of 'upgraded' socket;
1481 * or persistent / unrecoverable error. */
1495 /* Do not try to pull more data from application. */ 1482 /* Do not try to pull more data from application. */
1496 urh->out_buffer_size = 0; 1483 urh->out_buffer_size = 0;
1497 } 1484 }
1485 }
1486 }
1487 else /* 0 < res */
1488 {
1489 urh->out_buffer_used += res;
1490 if (buf_size > (size_t) res)
1491 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1492 }
1493 if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->mhd.celi)) &&
1494 ( (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) ||
1495 (was_closed) ) )
1496 {
1497 /* Unrecoverable error on socket was detected and all
1498 * pending data was read from system buffers. */
1499 /* Do not try to pull more data from application. */
1500 urh->out_buffer_size = 0;
1498 } 1501 }
1502 }
1499 1503
1500 /* 1504 /*
1501 * handle writing to remote HTTPS client 1505 * handle writing to remote HTTPS client
1502 */ 1506 */
1503 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) && 1507 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->app.celi)) &&
1504 (urh->out_buffer_used > 0) ) 1508 (urh->out_buffer_used > 0) )
1505 { 1509 {
1506 ssize_t res; 1510 ssize_t res;
1507 size_t data_size; 1511 size_t data_size;
1508 1512
1509 data_size = urh->out_buffer_used; 1513 data_size = urh->out_buffer_used;
1510 if (data_size > SSIZE_MAX) 1514 if (data_size > SSIZE_MAX)
1511 data_size = SSIZE_MAX; 1515 data_size = SSIZE_MAX;
1512 1516
1513 res = gnutls_record_send (connection->tls_session, 1517 res = gnutls_record_send (connection->tls_session,
1514 urh->out_buffer, 1518 urh->out_buffer,
1515 data_size); 1519 data_size);
1516 if (0 >= res) 1520 if (0 >= res)
1517 { 1521 {
1518 if (GNUTLS_E_INTERRUPTED != res) 1522 if (GNUTLS_E_INTERRUPTED != res)
1519 { 1523 {
1520 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1524 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1521 if (GNUTLS_E_AGAIN != res) 1525 if (GNUTLS_E_AGAIN != res)
1522 {
1523 /* TLS connection shut down or
1524 * persistent / unrecoverable error. */
1525#ifdef HAVE_MESSAGES
1526 MHD_DLOG (daemon,
1527 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \
1528 " bytes of data received from application: %s\n"),
1529 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used,
1530 gnutls_strerror(res));
1531#endif
1532 /* Discard any data unsent to remote. */
1533 urh->out_buffer_used = 0;
1534 /* Do not try to pull more data from application. */
1535 urh->out_buffer_size = 0;
1536 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1537 }
1538 }
1539 }
1540 else /* 0 < res */
1541 {
1542 const size_t next_out_buffer_used = urh->out_buffer_used - res;
1543 if (0 != next_out_buffer_used)
1544 {
1545 memmove (urh->out_buffer,
1546 &urh->out_buffer[res],
1547 next_out_buffer_used);
1548 if (data_size > (size_t)res)
1549 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1550 }
1551 urh->out_buffer_used = next_out_buffer_used;
1552 }
1553 if ( (0 == urh->out_buffer_used) &&
1554 (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) )
1555 { 1526 {
1556 /* Unrecoverable error on socket was detected and all 1527 /* TLS connection shut down or
1557 * pending data was sent to remote. */ 1528 * persistent / unrecoverable error. */
1558 /* Do not try to send to remote anymore. */ 1529#ifdef HAVE_MESSAGES
1559 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1530 MHD_DLOG (daemon,
1531 _ (
1532 "Failed to forward to remote client "
1533 MHD_UNSIGNED_LONG_LONG_PRINTF \
1534 " bytes of data received from application: %s\n"),
1535 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used,
1536 gnutls_strerror (res));
1537#endif
1538 /* Discard any data unsent to remote. */
1539 urh->out_buffer_used = 0;
1560 /* Do not try to pull more data from application. */ 1540 /* Do not try to pull more data from application. */
1561 urh->out_buffer_size = 0; 1541 urh->out_buffer_size = 0;
1562 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1542 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1563 } 1543 }
1544 }
1564 } 1545 }
1546 else /* 0 < res */
1547 {
1548 const size_t next_out_buffer_used = urh->out_buffer_used - res;
1549 if (0 != next_out_buffer_used)
1550 {
1551 memmove (urh->out_buffer,
1552 &urh->out_buffer[res],
1553 next_out_buffer_used);
1554 if (data_size > (size_t) res)
1555 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1556 }
1557 urh->out_buffer_used = next_out_buffer_used;
1558 }
1559 if ( (0 == urh->out_buffer_used) &&
1560 (0 != (MHD_EPOLL_STATE_ERROR & urh->app.celi)) )
1561 {
1562 /* Unrecoverable error on socket was detected and all
1563 * pending data was sent to remote. */
1564 /* Do not try to send to remote anymore. */
1565 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1566 /* Do not try to pull more data from application. */
1567 urh->out_buffer_size = 0;
1568 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1569 }
1570 }
1565 1571
1566 /* 1572 /*
1567 * handle writing to application 1573 * handle writing to application
1568 */ 1574 */
1569 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) && 1575 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) &&
1570 (urh->in_buffer_used > 0) ) 1576 (urh->in_buffer_used > 0) )
1571 { 1577 {
1572 ssize_t res; 1578 ssize_t res;
1573 size_t data_size; 1579 size_t data_size;
1574 1580
1575 data_size = urh->in_buffer_used; 1581 data_size = urh->in_buffer_used;
1576 if (data_size > MHD_SCKT_SEND_MAX_SIZE_) 1582 if (data_size > MHD_SCKT_SEND_MAX_SIZE_)
1577 data_size = MHD_SCKT_SEND_MAX_SIZE_; 1583 data_size = MHD_SCKT_SEND_MAX_SIZE_;
1578 1584
1579 res = MHD_send_ (urh->mhd.socket, 1585 res = MHD_send_ (urh->mhd.socket,
1580 urh->in_buffer, 1586 urh->in_buffer,
1581 data_size); 1587 data_size);
1582 if (0 >= res) 1588 if (0 >= res)
1583 { 1589 {
1584 const int err = MHD_socket_get_error_ (); 1590 const int err = MHD_socket_get_error_ ();
1585 if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) && 1591 if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
1586 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) ) 1592 (! MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err)) )
1587 { 1593 {
1588 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1594 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1589 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err)) 1595 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err))
1590 {
1591 /* Socketpair connection shut down or
1592 * persistent / unrecoverable error. */
1593#ifdef HAVE_MESSAGES
1594 MHD_DLOG (daemon,
1595 _("Failed to forward to application " MHD_UNSIGNED_LONG_LONG_PRINTF \
1596 " bytes of data received from remote side: %s\n"),
1597 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used,
1598 MHD_socket_strerr_ (err));
1599#endif
1600 /* Discard any data received form remote. */
1601 urh->in_buffer_used = 0;
1602 /* Reading from remote client is not required anymore. */
1603 urh->in_buffer_size = 0;
1604 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1605 connection->tls_read_ready = false;
1606 }
1607 }
1608 }
1609 else /* 0 < res */
1610 {
1611 const size_t next_in_buffer_used = urh->in_buffer_used - res;
1612 if (0 != next_in_buffer_used)
1613 {
1614 memmove (urh->in_buffer,
1615 &urh->in_buffer[res],
1616 next_in_buffer_used);
1617 if (data_size > (size_t)res)
1618 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1619 }
1620 urh->in_buffer_used = next_in_buffer_used;
1621 }
1622 if ( (0 == urh->in_buffer_used) &&
1623 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) )
1624 { 1596 {
1625 /* Do not try to push data to application. */ 1597 /* Socketpair connection shut down or
1626 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1598 * persistent / unrecoverable error. */
1599#ifdef HAVE_MESSAGES
1600 MHD_DLOG (daemon,
1601 _ (
1602 "Failed to forward to application "
1603 MHD_UNSIGNED_LONG_LONG_PRINTF \
1604 " bytes of data received from remote side: %s\n"),
1605 (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used,
1606 MHD_socket_strerr_ (err));
1607#endif
1608 /* Discard any data received form remote. */
1609 urh->in_buffer_used = 0;
1627 /* Reading from remote client is not required anymore. */ 1610 /* Reading from remote client is not required anymore. */
1628 urh->in_buffer_size = 0; 1611 urh->in_buffer_size = 0;
1629 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY; 1612 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1630 connection->tls_read_ready = false; 1613 connection->tls_read_ready = false;
1631 } 1614 }
1615 }
1616 }
1617 else /* 0 < res */
1618 {
1619 const size_t next_in_buffer_used = urh->in_buffer_used - res;
1620 if (0 != next_in_buffer_used)
1621 {
1622 memmove (urh->in_buffer,
1623 &urh->in_buffer[res],
1624 next_in_buffer_used);
1625 if (data_size > (size_t) res)
1626 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1627 }
1628 urh->in_buffer_used = next_in_buffer_used;
1629 }
1630 if ( (0 == urh->in_buffer_used) &&
1631 (0 != (MHD_EPOLL_STATE_ERROR & urh->mhd.celi)) )
1632 {
1633 /* Do not try to push data to application. */
1634 urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1635 /* Reading from remote client is not required anymore. */
1636 urh->in_buffer_size = 0;
1637 urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
1638 connection->tls_read_ready = false;
1632 } 1639 }
1640 }
1633 1641
1634 /* Check whether data is present in TLS buffers 1642 /* Check whether data is present in TLS buffers
1635 * and incoming forward buffer have some space. */ 1643 * and incoming forward buffer have some space. */
@@ -1641,23 +1649,25 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1641 if ( (daemon->shutdown) && 1649 if ( (daemon->shutdown) &&
1642 ( (0 != urh->out_buffer_size) || 1650 ( (0 != urh->out_buffer_size) ||
1643 (0 != urh->out_buffer_used) ) ) 1651 (0 != urh->out_buffer_used) ) )
1644 { 1652 {
1645 /* Daemon shutting down, discard any remaining forward data. */ 1653 /* Daemon shutting down, discard any remaining forward data. */
1646#ifdef HAVE_MESSAGES 1654#ifdef HAVE_MESSAGES
1647 if (0 < urh->out_buffer_used) 1655 if (0 < urh->out_buffer_used)
1648 MHD_DLOG (daemon, 1656 MHD_DLOG (daemon,
1649 _("Failed to forward to remote client " MHD_UNSIGNED_LONG_LONG_PRINTF \ 1657 _ (
1650 " bytes of data received from application: daemon shut down\n"), 1658 "Failed to forward to remote client "
1651 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used); 1659 MHD_UNSIGNED_LONG_LONG_PRINTF \
1652#endif 1660 " bytes of data received from application: daemon shut down\n"),
1653 /* Discard any data unsent to remote. */ 1661 (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used);
1654 urh->out_buffer_used = 0; 1662#endif
1655 /* Do not try to sent to remote anymore. */ 1663 /* Discard any data unsent to remote. */
1656 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY; 1664 urh->out_buffer_used = 0;
1657 /* Do not try to pull more data from application. */ 1665 /* Do not try to sent to remote anymore. */
1658 urh->out_buffer_size = 0; 1666 urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
1659 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1667 /* Do not try to pull more data from application. */
1660 } 1668 urh->out_buffer_size = 0;
1669 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1670 }
1661} 1671}
1662#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 1672#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
1663 1673
@@ -1682,128 +1692,128 @@ thread_main_connection_upgrade (struct MHD_Connection *con)
1682 until the application tells us that it is done 1692 until the application tells us that it is done
1683 with the socket; */ 1693 with the socket; */
1684 if ( (0 != (daemon->options & MHD_USE_TLS)) && 1694 if ( (0 != (daemon->options & MHD_USE_TLS)) &&
1685 (0 == (daemon->options & MHD_USE_POLL))) 1695 (0 == (daemon->options & MHD_USE_POLL)))
1686 { 1696 {
1687 while ( (0 != urh->in_buffer_size) || 1697 while ( (0 != urh->in_buffer_size) ||
1688 (0 != urh->out_buffer_size) || 1698 (0 != urh->out_buffer_size) ||
1689 (0 != urh->in_buffer_used) || 1699 (0 != urh->in_buffer_used) ||
1690 (0 != urh->out_buffer_used) ) 1700 (0 != urh->out_buffer_used) )
1691 { 1701 {
1692 /* use select */ 1702 /* use select */
1693 fd_set rs; 1703 fd_set rs;
1694 fd_set ws; 1704 fd_set ws;
1695 fd_set es; 1705 fd_set es;
1696 MHD_socket max_fd; 1706 MHD_socket max_fd;
1697 int num_ready; 1707 int num_ready;
1698 bool result; 1708 bool result;
1699 1709
1700 FD_ZERO (&rs); 1710 FD_ZERO (&rs);
1701 FD_ZERO (&ws); 1711 FD_ZERO (&ws);
1702 FD_ZERO (&es); 1712 FD_ZERO (&es);
1703 max_fd = MHD_INVALID_SOCKET; 1713 max_fd = MHD_INVALID_SOCKET;
1704 result = urh_to_fdset (urh, 1714 result = urh_to_fdset (urh,
1705 &rs, 1715 &rs,
1706 &ws, 1716 &ws,
1707 &es, 1717 &es,
1708 &max_fd, 1718 &max_fd,
1709 FD_SETSIZE); 1719 FD_SETSIZE);
1710 if (! result) 1720 if (! result)
1711 { 1721 {
1712#ifdef HAVE_MESSAGES 1722#ifdef HAVE_MESSAGES
1713 MHD_DLOG (con->daemon, 1723 MHD_DLOG (con->daemon,
1714 _("Error preparing select\n")); 1724 _ ("Error preparing select\n"));
1715#endif 1725#endif
1716 break; 1726 break;
1717 } 1727 }
1718 /* FIXME: does this check really needed? */ 1728 /* FIXME: does this check really needed? */
1719 if (MHD_INVALID_SOCKET != max_fd) 1729 if (MHD_INVALID_SOCKET != max_fd)
1720 { 1730 {
1721 struct timeval* tvp; 1731 struct timeval*tvp;
1722 struct timeval tv; 1732 struct timeval tv;
1723 if ( (con->tls_read_ready) && 1733 if ( (con->tls_read_ready) &&
1724 (urh->in_buffer_used < urh->in_buffer_size)) 1734 (urh->in_buffer_used < urh->in_buffer_size))
1725 { /* No need to wait if incoming data is already pending in TLS buffers. */ 1735 { /* No need to wait if incoming data is already pending in TLS buffers. */
1726 tv.tv_sec = 0; 1736 tv.tv_sec = 0;
1727 tv.tv_usec = 0; 1737 tv.tv_usec = 0;
1728 tvp = &tv; 1738 tvp = &tv;
1729 }
1730 else
1731 tvp = NULL;
1732 num_ready = MHD_SYS_select_ (max_fd + 1,
1733 &rs,
1734 &ws,
1735 &es,
1736 tvp);
1737 }
1738 else
1739 num_ready = 0;
1740 if (num_ready < 0)
1741 {
1742 const int err = MHD_socket_get_error_();
1743
1744 if (MHD_SCKT_ERR_IS_EINTR_(err))
1745 continue;
1746#ifdef HAVE_MESSAGES
1747 MHD_DLOG (con->daemon,
1748 _("Error during select (%d): `%s'\n"),
1749 err,
1750 MHD_socket_strerr_ (err));
1751#endif
1752 break;
1753 }
1754 urh_from_fdset (urh,
1755 &rs,
1756 &ws,
1757 &es);
1758 process_urh (urh);
1759 } 1739 }
1740 else
1741 tvp = NULL;
1742 num_ready = MHD_SYS_select_ (max_fd + 1,
1743 &rs,
1744 &ws,
1745 &es,
1746 tvp);
1747 }
1748 else
1749 num_ready = 0;
1750 if (num_ready < 0)
1751 {
1752 const int err = MHD_socket_get_error_ ();
1753
1754 if (MHD_SCKT_ERR_IS_EINTR_ (err))
1755 continue;
1756#ifdef HAVE_MESSAGES
1757 MHD_DLOG (con->daemon,
1758 _ ("Error during select (%d): `%s'\n"),
1759 err,
1760 MHD_socket_strerr_ (err));
1761#endif
1762 break;
1763 }
1764 urh_from_fdset (urh,
1765 &rs,
1766 &ws,
1767 &es);
1768 process_urh (urh);
1760 } 1769 }
1770 }
1761#ifdef HAVE_POLL 1771#ifdef HAVE_POLL
1762 else if (0 != (daemon->options & MHD_USE_TLS)) 1772 else if (0 != (daemon->options & MHD_USE_TLS))
1763 { 1773 {
1764 /* use poll() */ 1774 /* use poll() */
1765 struct pollfd p[2]; 1775 struct pollfd p[2];
1766 memset (p, 1776 memset (p,
1767 0, 1777 0,
1768 sizeof (p)); 1778 sizeof (p));
1769 p[0].fd = urh->connection->socket_fd; 1779 p[0].fd = urh->connection->socket_fd;
1770 p[1].fd = urh->mhd.socket; 1780 p[1].fd = urh->mhd.socket;
1781
1782 while ( (0 != urh->in_buffer_size) ||
1783 (0 != urh->out_buffer_size) ||
1784 (0 != urh->in_buffer_used) ||
1785 (0 != urh->out_buffer_used) )
1786 {
1787 int timeout;
1788
1789 urh_update_pollfd (urh, p);
1790
1791 if ( (con->tls_read_ready) &&
1792 (urh->in_buffer_used < urh->in_buffer_size))
1793 timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */
1794 else
1795 timeout = -1;
1771 1796
1772 while ( (0 != urh->in_buffer_size) || 1797 if (MHD_sys_poll_ (p,
1773 (0 != urh->out_buffer_size) || 1798 2,
1774 (0 != urh->in_buffer_used) || 1799 timeout) < 0)
1775 (0 != urh->out_buffer_used) ) 1800 {
1776 { 1801 const int err = MHD_socket_get_error_ ();
1777 int timeout; 1802
1778 1803 if (MHD_SCKT_ERR_IS_EINTR_ (err))
1779 urh_update_pollfd(urh, p); 1804 continue;
1780 1805#ifdef HAVE_MESSAGES
1781 if ( (con->tls_read_ready) && 1806 MHD_DLOG (con->daemon,
1782 (urh->in_buffer_used < urh->in_buffer_size)) 1807 _ ("Error during poll: `%s'\n"),
1783 timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */ 1808 MHD_socket_strerr_ (err));
1784 else 1809#endif
1785 timeout = -1; 1810 break;
1786 1811 }
1787 if (MHD_sys_poll_ (p, 1812 urh_from_pollfd (urh,
1788 2, 1813 p);
1789 timeout) < 0) 1814 process_urh (urh);
1790 {
1791 const int err = MHD_socket_get_error_ ();
1792
1793 if (MHD_SCKT_ERR_IS_EINTR_ (err))
1794 continue;
1795#ifdef HAVE_MESSAGES
1796 MHD_DLOG (con->daemon,
1797 _("Error during poll: `%s'\n"),
1798 MHD_socket_strerr_ (err));
1799#endif
1800 break;
1801 }
1802 urh_from_pollfd (urh,
1803 p);
1804 process_urh (urh);
1805 }
1806 } 1815 }
1816 }
1807 /* end POLL */ 1817 /* end POLL */
1808#endif 1818#endif
1809 /* end HTTPS */ 1819 /* end HTTPS */
@@ -1854,346 +1864,348 @@ thread_main_handle_connection (void *data)
1854 const bool use_poll = 0; 1864 const bool use_poll = 0;
1855#endif /* ! HAVE_POLL */ 1865#endif /* ! HAVE_POLL */
1856 bool was_suspended = false; 1866 bool was_suspended = false;
1857 MHD_thread_init_(&(con->pid)); 1867 MHD_thread_init_ (&(con->pid));
1858 1868
1859 while ( (! daemon->shutdown) && 1869 while ( (! daemon->shutdown) &&
1860 (MHD_CONNECTION_CLOSED != con->state) ) 1870 (MHD_CONNECTION_CLOSED != con->state) )
1861 { 1871 {
1862 const time_t timeout = daemon->connection_timeout; 1872 const time_t timeout = daemon->connection_timeout;
1863#ifdef UPGRADE_SUPPORT 1873#ifdef UPGRADE_SUPPORT
1864 struct MHD_UpgradeResponseHandle * const urh = con->urh; 1874 struct MHD_UpgradeResponseHandle *const urh = con->urh;
1865#else /* ! UPGRADE_SUPPORT */ 1875#else /* ! UPGRADE_SUPPORT */
1866 static const void * const urh = NULL; 1876 static const void *const urh = NULL;
1867#endif /* ! UPGRADE_SUPPORT */ 1877#endif /* ! UPGRADE_SUPPORT */
1868 1878
1869 if ( (con->suspended) && 1879 if ( (con->suspended) &&
1870 (NULL == urh) ) 1880 (NULL == urh) )
1881 {
1882 /* Connection was suspended, wait for resume. */
1883 was_suspended = true;
1884 if (! use_poll)
1885 {
1886 FD_ZERO (&rs);
1887 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
1888 &rs,
1889 NULL,
1890 FD_SETSIZE))
1871 { 1891 {
1872 /* Connection was suspended, wait for resume. */
1873 was_suspended = true;
1874 if (! use_poll)
1875 {
1876 FD_ZERO (&rs);
1877 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
1878 &rs,
1879 NULL,
1880 FD_SETSIZE))
1881 {
1882 #ifdef HAVE_MESSAGES 1892 #ifdef HAVE_MESSAGES
1883 MHD_DLOG (con->daemon, 1893 MHD_DLOG (con->daemon,
1884 _("Failed to add FD to fd_set\n")); 1894 _ ("Failed to add FD to fd_set\n"));
1885 #endif 1895 #endif
1886 goto exit; 1896 goto exit;
1887 } 1897 }
1888 if (0 > MHD_SYS_select_ (MHD_itc_r_fd_ (daemon->itc) + 1, 1898 if (0 > MHD_SYS_select_ (MHD_itc_r_fd_ (daemon->itc) + 1,
1889 &rs, 1899 &rs,
1890 NULL, 1900 NULL,
1891 NULL, 1901 NULL,
1892 NULL)) 1902 NULL))
1893 { 1903 {
1894 const int err = MHD_socket_get_error_(); 1904 const int err = MHD_socket_get_error_ ();
1895
1896 if (MHD_SCKT_ERR_IS_EINTR_(err))
1897 continue;
1898#ifdef HAVE_MESSAGES
1899 MHD_DLOG (con->daemon,
1900 _("Error during select (%d): `%s'\n"),
1901 err,
1902 MHD_socket_strerr_ (err));
1903#endif
1904 break;
1905 }
1906 }
1907#ifdef HAVE_POLL
1908 else /* use_poll */
1909 {
1910 p[0].events = POLLIN;
1911 p[0].fd = MHD_itc_r_fd_ (daemon->itc);
1912 p[0].revents = 0;
1913 if (0 > MHD_sys_poll_ (p,
1914 1,
1915 -1))
1916 {
1917 if (MHD_SCKT_LAST_ERR_IS_(MHD_SCKT_EINTR_))
1918 continue;
1919#ifdef HAVE_MESSAGES
1920 MHD_DLOG (con->daemon,
1921 _("Error during poll: `%s'\n"),
1922 MHD_socket_last_strerr_ ());
1923#endif
1924 break;
1925 }
1926 }
1927#endif /* HAVE_POLL */
1928 MHD_itc_clear_ (daemon->itc);
1929 continue; /* Check again for resume. */
1930 } /* End of "suspended" branch. */
1931 1905
1932 if (was_suspended) 1906 if (MHD_SCKT_ERR_IS_EINTR_ (err))
1907 continue;
1908#ifdef HAVE_MESSAGES
1909 MHD_DLOG (con->daemon,
1910 _ ("Error during select (%d): `%s'\n"),
1911 err,
1912 MHD_socket_strerr_ (err));
1913#endif
1914 break;
1915 }
1916 }
1917#ifdef HAVE_POLL
1918 else /* use_poll */
1919 {
1920 p[0].events = POLLIN;
1921 p[0].fd = MHD_itc_r_fd_ (daemon->itc);
1922 p[0].revents = 0;
1923 if (0 > MHD_sys_poll_ (p,
1924 1,
1925 -1))
1933 { 1926 {
1934 MHD_update_last_activity_ (con); /* Reset timeout timer. */ 1927 if (MHD_SCKT_LAST_ERR_IS_ (MHD_SCKT_EINTR_))
1935 /* Process response queued during suspend and update states. */ 1928 continue;
1936 MHD_connection_handle_idle (con); 1929#ifdef HAVE_MESSAGES
1937 was_suspended = false; 1930 MHD_DLOG (con->daemon,
1931 _ ("Error during poll: `%s'\n"),
1932 MHD_socket_last_strerr_ ());
1933#endif
1934 break;
1938 } 1935 }
1936 }
1937#endif /* HAVE_POLL */
1938 MHD_itc_clear_ (daemon->itc);
1939 continue; /* Check again for resume. */
1940 } /* End of "suspended" branch. */
1939 1941
1940 tvp = NULL; 1942 if (was_suspended)
1943 {
1944 MHD_update_last_activity_ (con); /* Reset timeout timer. */
1945 /* Process response queued during suspend and update states. */
1946 MHD_connection_handle_idle (con);
1947 was_suspended = false;
1948 }
1941 1949
1942 if ( (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info) 1950 tvp = NULL;
1951
1952 if ( (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info)
1943#ifdef HTTPS_SUPPORT 1953#ifdef HTTPS_SUPPORT
1944 || ( (con->tls_read_ready) && 1954 || ( (con->tls_read_ready) &&
1945 (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) ) 1955 (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) )
1946#endif /* HTTPS_SUPPORT */ 1956#endif /* HTTPS_SUPPORT */
1947 ) 1957 )
1948 { 1958 {
1949 /* do not block: more data may be inside of TLS buffers waiting or 1959 /* do not block: more data may be inside of TLS buffers waiting or
1950 * application must provide response data */ 1960 * application must provide response data */
1951 tv.tv_sec = 0; 1961 tv.tv_sec = 0;
1952 tv.tv_usec = 0; 1962 tv.tv_usec = 0;
1953 tvp = &tv; 1963 tvp = &tv;
1954 } 1964 }
1955 if ( (NULL == tvp) && 1965 if ( (NULL == tvp) &&
1956 (timeout > 0) ) 1966 (timeout > 0) )
1957 { 1967 {
1958 now = MHD_monotonic_sec_counter(); 1968 now = MHD_monotonic_sec_counter ();
1959 if (now - con->last_activity > timeout) 1969 if (now - con->last_activity > timeout)
1960 tv.tv_sec = 0; 1970 tv.tv_sec = 0;
1961 else 1971 else
1962 { 1972 {
1963 const time_t seconds_left = timeout - (now - con->last_activity); 1973 const time_t seconds_left = timeout - (now - con->last_activity);
1964#if !defined(_WIN32) || defined(__CYGWIN__) 1974#if ! defined(_WIN32) || defined(__CYGWIN__)
1965 tv.tv_sec = seconds_left; 1975 tv.tv_sec = seconds_left;
1966#else /* _WIN32 && !__CYGWIN__ */ 1976#else /* _WIN32 && !__CYGWIN__ */
1967 if (seconds_left > TIMEVAL_TV_SEC_MAX) 1977 if (seconds_left > TIMEVAL_TV_SEC_MAX)
1968 tv.tv_sec = TIMEVAL_TV_SEC_MAX; 1978 tv.tv_sec = TIMEVAL_TV_SEC_MAX;
1969 else 1979 else
1970 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) seconds_left; 1980 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) seconds_left;
1971#endif /* _WIN32 && ! __CYGWIN__ */ 1981#endif /* _WIN32 && ! __CYGWIN__ */
1972 } 1982 }
1973 tv.tv_usec = 0; 1983 tv.tv_usec = 0;
1974 tvp = &tv; 1984 tvp = &tv;
1975 } 1985 }
1976 if (! use_poll) 1986 if (! use_poll)
1977 { 1987 {
1978 /* use select */ 1988 /* use select */
1979 bool err_state = false; 1989 bool err_state = false;
1980 1990
1981 FD_ZERO (&rs); 1991 FD_ZERO (&rs);
1982 FD_ZERO (&ws); 1992 FD_ZERO (&ws);
1983 FD_ZERO (&es); 1993 FD_ZERO (&es);
1984 maxsock = MHD_INVALID_SOCKET; 1994 maxsock = MHD_INVALID_SOCKET;
1985 switch (con->event_loop_info) 1995 switch (con->event_loop_info)
1986 { 1996 {
1987 case MHD_EVENT_LOOP_INFO_READ: 1997 case MHD_EVENT_LOOP_INFO_READ:
1988 if (! MHD_add_to_fd_set_ (con->socket_fd, 1998 if (! MHD_add_to_fd_set_ (con->socket_fd,
1989 &rs, 1999 &rs,
1990 &maxsock, 2000 &maxsock,
1991 FD_SETSIZE)) 2001 FD_SETSIZE))
1992 err_state = true; 2002 err_state = true;
1993 break; 2003 break;
1994 case MHD_EVENT_LOOP_INFO_WRITE: 2004 case MHD_EVENT_LOOP_INFO_WRITE:
1995 if (! MHD_add_to_fd_set_ (con->socket_fd, 2005 if (! MHD_add_to_fd_set_ (con->socket_fd,
1996 &ws, 2006 &ws,
1997 &maxsock, 2007 &maxsock,
1998 FD_SETSIZE)) 2008 FD_SETSIZE))
1999 err_state = true; 2009 err_state = true;
2000 break; 2010 break;
2001 case MHD_EVENT_LOOP_INFO_BLOCK: 2011 case MHD_EVENT_LOOP_INFO_BLOCK:
2002 if (! MHD_add_to_fd_set_ (con->socket_fd, 2012 if (! MHD_add_to_fd_set_ (con->socket_fd,
2003 &es, 2013 &es,
2004 &maxsock, 2014 &maxsock,
2005 FD_SETSIZE)) 2015 FD_SETSIZE))
2006 err_state = true; 2016 err_state = true;
2007 break; 2017 break;
2008 case MHD_EVENT_LOOP_INFO_CLEANUP: 2018 case MHD_EVENT_LOOP_INFO_CLEANUP:
2009 /* how did we get here!? */ 2019 /* how did we get here!? */
2010 goto exit; 2020 goto exit;
2011 } 2021 }
2012#if WINDOWS 2022#if WINDOWS
2013 if (MHD_ITC_IS_VALID_(daemon->itc) ) 2023 if (MHD_ITC_IS_VALID_ (daemon->itc) )
2014 { 2024 {
2015 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc), 2025 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
2016 &rs, 2026 &rs,
2017 &maxsock, 2027 &maxsock,
2018 FD_SETSIZE)) 2028 FD_SETSIZE))
2019 err_state = 1; 2029 err_state = 1;
2020 } 2030 }
2021#endif 2031#endif
2022 if (err_state) 2032 if (err_state)
2023 { 2033 {
2024#ifdef HAVE_MESSAGES 2034#ifdef HAVE_MESSAGES
2025 MHD_DLOG (con->daemon, 2035 MHD_DLOG (con->daemon,
2026 _("Failed to add FD to fd_set\n")); 2036 _ ("Failed to add FD to fd_set\n"));
2027#endif 2037#endif
2028 goto exit; 2038 goto exit;
2029 } 2039 }
2030 2040
2031 num_ready = MHD_SYS_select_ (maxsock + 1, 2041 num_ready = MHD_SYS_select_ (maxsock + 1,
2032 &rs, 2042 &rs,
2033 &ws, 2043 &ws,
2034 &es, 2044 &es,
2035 tvp); 2045 tvp);
2036 if (num_ready < 0) 2046 if (num_ready < 0)
2037 { 2047 {
2038 const int err = MHD_socket_get_error_(); 2048 const int err = MHD_socket_get_error_ ();
2039 2049
2040 if (MHD_SCKT_ERR_IS_EINTR_(err)) 2050 if (MHD_SCKT_ERR_IS_EINTR_ (err))
2041 continue; 2051 continue;
2042#ifdef HAVE_MESSAGES 2052#ifdef HAVE_MESSAGES
2043 MHD_DLOG (con->daemon, 2053 MHD_DLOG (con->daemon,
2044 _("Error during select (%d): `%s'\n"), 2054 _ ("Error during select (%d): `%s'\n"),
2045 err, 2055 err,
2046 MHD_socket_strerr_ (err)); 2056 MHD_socket_strerr_ (err));
2047#endif 2057#endif
2048 break; 2058 break;
2049 } 2059 }
2050#if WINDOWS 2060#if WINDOWS
2051 /* Clear ITC before other processing so additional 2061 /* Clear ITC before other processing so additional
2052 * signals will trigger select() again */ 2062 * signals will trigger select() again */
2053 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 2063 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2054 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc), 2064 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc),
2055 &rs)) ) 2065 &rs)) )
2056 MHD_itc_clear_ (daemon->itc); 2066 MHD_itc_clear_ (daemon->itc);
2057#endif 2067#endif
2058 if (MHD_NO == 2068 if (MHD_NO ==
2059 call_handlers (con, 2069 call_handlers (con,
2060 FD_ISSET (con->socket_fd, 2070 FD_ISSET (con->socket_fd,
2061 &rs), 2071 &rs),
2062 FD_ISSET (con->socket_fd, 2072 FD_ISSET (con->socket_fd,
2063 &ws), 2073 &ws),
2064 FD_ISSET (con->socket_fd, 2074 FD_ISSET (con->socket_fd,
2065 &es)) ) 2075 &es)) )
2066 goto exit; 2076 goto exit;
2067 } 2077 }
2068#ifdef HAVE_POLL 2078#ifdef HAVE_POLL
2069 else 2079 else
2070 { 2080 {
2071 /* use poll */ 2081 /* use poll */
2072 memset (&p, 2082 memset (&p,
2073 0, 2083 0,
2074 sizeof (p)); 2084 sizeof (p));
2075 p[0].fd = con->socket_fd; 2085 p[0].fd = con->socket_fd;
2076 switch (con->event_loop_info) 2086 switch (con->event_loop_info)
2077 { 2087 {
2078 case MHD_EVENT_LOOP_INFO_READ: 2088 case MHD_EVENT_LOOP_INFO_READ:
2079 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; 2089 p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
2080 break; 2090 break;
2081 case MHD_EVENT_LOOP_INFO_WRITE: 2091 case MHD_EVENT_LOOP_INFO_WRITE:
2082 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; 2092 p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
2083 break; 2093 break;
2084 case MHD_EVENT_LOOP_INFO_BLOCK: 2094 case MHD_EVENT_LOOP_INFO_BLOCK:
2085 p[0].events |= MHD_POLL_EVENTS_ERR_DISC; 2095 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
2086 break; 2096 break;
2087 case MHD_EVENT_LOOP_INFO_CLEANUP: 2097 case MHD_EVENT_LOOP_INFO_CLEANUP:
2088 /* how did we get here!? */ 2098 /* how did we get here!? */
2089 goto exit; 2099 goto exit;
2090 } 2100 }
2091#if WINDOWS 2101#if WINDOWS
2092 extra_slot = 0; 2102 extra_slot = 0;
2093 if (MHD_ITC_IS_VALID_(daemon->itc)) 2103 if (MHD_ITC_IS_VALID_ (daemon->itc))
2094 { 2104 {
2095 p[1].events |= POLLIN; 2105 p[1].events |= POLLIN;
2096 p[1].fd = MHD_itc_r_fd_ (daemon->itc); 2106 p[1].fd = MHD_itc_r_fd_ (daemon->itc);
2097 p[1].revents = 0; 2107 p[1].revents = 0;
2098 extra_slot = 1; 2108 extra_slot = 1;
2099 } 2109 }
2100#endif 2110#endif
2101 if (MHD_sys_poll_ (p, 2111 if (MHD_sys_poll_ (p,
2102#if WINDOWS 2112#if WINDOWS
2103 1 + extra_slot, 2113 1 + extra_slot,
2104#else 2114#else
2105 1, 2115 1,
2106#endif 2116#endif
2107 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0) 2117 (NULL == tvp) ? -1 : tv.tv_sec * 1000) < 0)
2108 { 2118 {
2109 if (MHD_SCKT_LAST_ERR_IS_(MHD_SCKT_EINTR_)) 2119 if (MHD_SCKT_LAST_ERR_IS_ (MHD_SCKT_EINTR_))
2110 continue; 2120 continue;
2111#ifdef HAVE_MESSAGES 2121#ifdef HAVE_MESSAGES
2112 MHD_DLOG (con->daemon, 2122 MHD_DLOG (con->daemon,
2113 _("Error during poll: `%s'\n"), 2123 _ ("Error during poll: `%s'\n"),
2114 MHD_socket_last_strerr_ ()); 2124 MHD_socket_last_strerr_ ());
2115#endif 2125#endif
2116 break; 2126 break;
2117 } 2127 }
2118#if WINDOWS 2128#if WINDOWS
2119 /* Clear ITC before other processing so additional 2129 /* Clear ITC before other processing so additional
2120 * signals will trigger poll() again */ 2130 * signals will trigger poll() again */
2121 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 2131 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2122 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) ) 2132 (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) )
2123 MHD_itc_clear_ (daemon->itc); 2133 MHD_itc_clear_ (daemon->itc);
2124#endif 2134#endif
2125 if (MHD_NO == 2135 if (MHD_NO ==
2126 call_handlers (con, 2136 call_handlers (con,
2127 0 != (p[0].revents & POLLIN), 2137 (0 != (p[0].revents & POLLIN)),
2128 0 != (p[0].revents & POLLOUT), 2138 (0 != (p[0].revents & POLLOUT)),
2129 0 != (p[0].revents & (POLLERR | MHD_POLL_REVENTS_ERR_DISC)))) 2139 (0 != (p[0].revents & (POLLERR
2130 goto exit; 2140 | MHD_POLL_REVENTS_ERR_DISC))) ))
2131 } 2141 goto exit;
2142 }
2132#endif 2143#endif
2133#ifdef UPGRADE_SUPPORT 2144#ifdef UPGRADE_SUPPORT
2134 if (MHD_CONNECTION_UPGRADE == con->state) 2145 if (MHD_CONNECTION_UPGRADE == con->state)
2135 { 2146 {
2136 /* Normal HTTP processing is finished, 2147 /* Normal HTTP processing is finished,
2137 * notify application. */ 2148 * notify application. */
2138 if ( (NULL != daemon->notify_completed) && 2149 if ( (NULL != daemon->notify_completed) &&
2139 (con->client_aware) ) 2150 (con->client_aware) )
2140 daemon->notify_completed (daemon->notify_completed_cls, 2151 daemon->notify_completed (daemon->notify_completed_cls,
2141 con, 2152 con,
2142 &con->client_context, 2153 &con->client_context,
2143 MHD_REQUEST_TERMINATED_COMPLETED_OK); 2154 MHD_REQUEST_TERMINATED_COMPLETED_OK);
2144 con->client_aware = false; 2155 con->client_aware = false;
2145 2156
2146 thread_main_connection_upgrade (con); 2157 thread_main_connection_upgrade (con);
2147 /* MHD_connection_finish_forward_() was called by thread_main_connection_upgrade(). */ 2158 /* MHD_connection_finish_forward_() was called by thread_main_connection_upgrade(). */
2148 2159
2149 /* "Upgraded" data will not be used in this thread from this point. */ 2160 /* "Upgraded" data will not be used in this thread from this point. */
2150 con->urh->clean_ready = true; 2161 con->urh->clean_ready = true;
2151 /* If 'urh->was_closed' set to true, connection will be 2162 /* If 'urh->was_closed' set to true, connection will be
2152 * moved immediately to cleanup list. Otherwise connection 2163 * moved immediately to cleanup list. Otherwise connection
2153 * will stay in suspended list until 'urh' will be marked 2164 * will stay in suspended list until 'urh' will be marked
2154 * with 'was_closed' by application. */ 2165 * with 'was_closed' by application. */
2155 MHD_resume_connection(con); 2166 MHD_resume_connection (con);
2156 2167
2157 /* skip usual clean up */ 2168 /* skip usual clean up */
2158 return (MHD_THRD_RTRN_TYPE_) 0; 2169 return (MHD_THRD_RTRN_TYPE_) 0;
2159 }
2160#endif /* UPGRADE_SUPPORT */
2161 } 2170 }
2171#endif /* UPGRADE_SUPPORT */
2172 }
2162#if DEBUG_CLOSE 2173#if DEBUG_CLOSE
2163#ifdef HAVE_MESSAGES 2174#ifdef HAVE_MESSAGES
2164 MHD_DLOG (con->daemon, 2175 MHD_DLOG (con->daemon,
2165 _("Processing thread terminating. Closing connection\n")); 2176 _ ("Processing thread terminating. Closing connection\n"));
2166#endif 2177#endif
2167#endif 2178#endif
2168 if (MHD_CONNECTION_CLOSED != con->state) 2179 if (MHD_CONNECTION_CLOSED != con->state)
2169 MHD_connection_close_ (con, 2180 MHD_connection_close_ (con,
2170 (daemon->shutdown) ? 2181 (daemon->shutdown) ?
2171 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: 2182 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN :
2172 MHD_REQUEST_TERMINATED_WITH_ERROR); 2183 MHD_REQUEST_TERMINATED_WITH_ERROR);
2173 MHD_connection_handle_idle (con); 2184 MHD_connection_handle_idle (con);
2174exit: 2185exit:
2175 if (NULL != con->response) 2186 if (NULL != con->response)
2176 { 2187 {
2177 MHD_destroy_response (con->response); 2188 MHD_destroy_response (con->response);
2178 con->response = NULL; 2189 con->response = NULL;
2179 } 2190 }
2180 2191
2181 if (MHD_INVALID_SOCKET != con->socket_fd) 2192 if (MHD_INVALID_SOCKET != con->socket_fd)
2182 { 2193 {
2183 shutdown (con->socket_fd, 2194 shutdown (con->socket_fd,
2184 SHUT_WR); 2195 SHUT_WR);
2185 /* 'socket_fd' can be used in other thread to signal shutdown. 2196 /* 'socket_fd' can be used in other thread to signal shutdown.
2186 * To avoid data races, do not close socket here. Daemon will 2197 * To avoid data races, do not close socket here. Daemon will
2187 * use more connections only after cleanup anyway. */ 2198 * use more connections only after cleanup anyway. */
2188 } 2199 }
2189 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 2200 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2190 (! MHD_itc_activate_ (daemon->itc, "t")) ) 2201 (! MHD_itc_activate_ (daemon->itc, "t")) )
2191 { 2202 {
2192#ifdef HAVE_MESSAGES 2203#ifdef HAVE_MESSAGES
2193 MHD_DLOG (daemon, 2204 MHD_DLOG (daemon,
2194 _("Failed to signal thread termination via inter-thread communication channel.")); 2205 _ (
2206 "Failed to signal thread termination via inter-thread communication channel."));
2195#endif 2207#endif
2196 } 2208 }
2197 return (MHD_THRD_RTRN_TYPE_) 0; 2209 return (MHD_THRD_RTRN_TYPE_) 0;
2198} 2210}
2199#endif 2211#endif
@@ -2210,8 +2222,8 @@ static void
2210MHD_cleanup_connections (struct MHD_Daemon *daemon); 2222MHD_cleanup_connections (struct MHD_Daemon *daemon);
2211 2223
2212#if defined(HTTPS_SUPPORT) 2224#if defined(HTTPS_SUPPORT)
2213#if !defined(MHD_WINSOCK_SOCKETS) && !defined(MHD_socket_nosignal_) && \ 2225#if ! defined(MHD_WINSOCK_SOCKETS) && ! defined(MHD_socket_nosignal_) && \
2214 (GNUTLS_VERSION_NUMBER+0 < 0x030402) && defined(MSG_NOSIGNAL) 2226 (GNUTLS_VERSION_NUMBER + 0 < 0x030402) && defined(MSG_NOSIGNAL)
2215/** 2227/**
2216 * Older version of GnuTLS do not support suppressing of SIGPIPE signal. 2228 * Older version of GnuTLS do not support suppressing of SIGPIPE signal.
2217 * Use push function replacement with suppressing SIGPIPE signal where necessary 2229 * Use push function replacement with suppressing SIGPIPE signal where necessary
@@ -2226,15 +2238,15 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon);
2226 * for TLS library. 2238 * for TLS library.
2227 */ 2239 */
2228static ssize_t 2240static ssize_t
2229MHD_tls_push_func_(gnutls_transport_ptr_t trnsp, 2241MHD_tls_push_func_ (gnutls_transport_ptr_t trnsp,
2230 const void *data, 2242 const void *data,
2231 size_t data_size) 2243 size_t data_size)
2232{ 2244{
2233#if (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX) 2245#if (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX)
2234 if (data_size > MHD_SCKT_SEND_MAX_SIZE_) 2246 if (data_size > MHD_SCKT_SEND_MAX_SIZE_)
2235 data_size = MHD_SCKT_SEND_MAX_SIZE_; 2247 data_size = MHD_SCKT_SEND_MAX_SIZE_;
2236#endif /* (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX) */ 2248#endif /* (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX) */
2237 return MHD_send_ ((MHD_socket)(intptr_t)(trnsp), data, data_size); 2249 return MHD_send_ ((MHD_socket) (intptr_t) (trnsp), data, data_size);
2238} 2250}
2239#endif /* MHD_TLSLIB_DONT_SUPPRESS_SIGPIPE */ 2251#endif /* MHD_TLSLIB_DONT_SUPPRESS_SIGPIPE */
2240 2252
@@ -2249,8 +2261,8 @@ MHD_tls_push_func_(gnutls_transport_ptr_t trnsp,
2249 */ 2261 */
2250static int 2262static int
2251psk_gnutls_adapter (gnutls_session_t session, 2263psk_gnutls_adapter (gnutls_session_t session,
2252 const char *username, 2264 const char *username,
2253 gnutls_datum_t *key) 2265 gnutls_datum_t *key)
2254{ 2266{
2255 struct MHD_Connection *connection; 2267 struct MHD_Connection *connection;
2256 struct MHD_Daemon *daemon; 2268 struct MHD_Daemon *daemon;
@@ -2262,7 +2274,7 @@ psk_gnutls_adapter (gnutls_session_t session,
2262 { 2274 {
2263#ifdef HAVE_MESSAGES 2275#ifdef HAVE_MESSAGES
2264 /* Cannot use our logger, we don't even have "daemon" */ 2276 /* Cannot use our logger, we don't even have "daemon" */
2265 MHD_PANIC (_("Internal server error. This should be impossible.\n")); 2277 MHD_PANIC (_ ("Internal server error. This should be impossible.\n"));
2266#endif 2278#endif
2267 return -1; 2279 return -1;
2268 } 2280 }
@@ -2272,46 +2284,47 @@ psk_gnutls_adapter (gnutls_session_t session,
2272 { 2284 {
2273#ifdef HAVE_MESSAGES 2285#ifdef HAVE_MESSAGES
2274 MHD_DLOG (daemon, 2286 MHD_DLOG (daemon,
2275 _("PSK not supported by this server.\n")); 2287 _ ("PSK not supported by this server.\n"));
2276#endif 2288#endif
2277 return -1; 2289 return -1;
2278 } 2290 }
2279 if (0 != daemon->cred_callback (daemon->cred_callback_cls, 2291 if (0 != daemon->cred_callback (daemon->cred_callback_cls,
2280 connection, 2292 connection,
2281 username, 2293 username,
2282 &app_psk, 2294 &app_psk,
2283 &app_psk_size)) 2295 &app_psk_size))
2284 return -1; 2296 return -1;
2285 if (NULL == (key->data = gnutls_malloc (app_psk_size))) 2297 if (NULL == (key->data = gnutls_malloc (app_psk_size)))
2286 { 2298 {
2287#ifdef HAVE_MESSAGES 2299#ifdef HAVE_MESSAGES
2288 MHD_DLOG (daemon, 2300 MHD_DLOG (daemon,
2289 _("PSK authentication failed: gnutls_malloc failed to allocate memory\n")); 2301 _ (
2302 "PSK authentication failed: gnutls_malloc failed to allocate memory\n"));
2290#endif 2303#endif
2291 free (app_psk); 2304 free (app_psk);
2292 return -1; 2305 return -1;
2293 } 2306 }
2294 if (UINT_MAX < app_psk_size) 2307 if (UINT_MAX < app_psk_size)
2295 { 2308 {
2296#ifdef HAVE_MESSAGES 2309#ifdef HAVE_MESSAGES
2297 MHD_DLOG (daemon, 2310 MHD_DLOG (daemon,
2298 _("PSK authentication failed: PSK too long\n")); 2311 _ ("PSK authentication failed: PSK too long\n"));
2299#endif 2312#endif
2300 free (app_psk); 2313 free (app_psk);
2301 return -1; 2314 return -1;
2302 } 2315 }
2303 key->size = (unsigned int)app_psk_size; 2316 key->size = (unsigned int) app_psk_size;
2304 memcpy (key->data, 2317 memcpy (key->data,
2305 app_psk, 2318 app_psk,
2306 app_psk_size); 2319 app_psk_size);
2307 free (app_psk); 2320 free (app_psk);
2308 return 0; 2321 return 0;
2309#else 2322#else
2310#ifdef HAVE_MESSAGES 2323#ifdef HAVE_MESSAGES
2311 MHD_DLOG (daemon, 2324 MHD_DLOG (daemon,
2312 _("PSK not supported by this server.\n")); 2325 _ ("PSK not supported by this server.\n"));
2313#endif 2326#endif
2314 return -1; 2327 return -1;
2315#endif 2328#endif
2316} 2329}
2317#endif /* HTTPS_SUPPORT */ 2330#endif /* HTTPS_SUPPORT */
@@ -2360,71 +2373,71 @@ internal_add_connection (struct MHD_Daemon *daemon,
2360#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2373#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2361 mhd_assert ((NULL == daemon->worker_pool) || (external_add)); 2374 mhd_assert ((NULL == daemon->worker_pool) || (external_add));
2362 if ((external_add) && (NULL != daemon->worker_pool)) 2375 if ((external_add) && (NULL != daemon->worker_pool))
2363 { 2376 {
2364 /* have a pool, try to find a pool with capacity; we use the 2377 /* have a pool, try to find a pool with capacity; we use the
2365 socket as the initial offset into the pool for load 2378 socket as the initial offset into the pool for load
2366 balancing */ 2379 balancing */
2367 for (i = 0; i < daemon->worker_pool_size; ++i) 2380 for (i = 0; i < daemon->worker_pool_size; ++i)
2368 { 2381 {
2369 struct MHD_Daemon * const worker = 2382 struct MHD_Daemon *const worker =
2370 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size]; 2383 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size];
2371 if (worker->connections < worker->connection_limit) 2384 if (worker->connections < worker->connection_limit)
2372 return internal_add_connection (worker, 2385 return internal_add_connection (worker,
2373 client_socket, 2386 client_socket,
2374 addr, 2387 addr,
2375 addrlen, 2388 addrlen,
2376 true, 2389 true,
2377 non_blck); 2390 non_blck);
2378 } 2391 }
2379 /* all pools are at their connection limit, must refuse */ 2392 /* all pools are at their connection limit, must refuse */
2380 MHD_socket_close_chk_ (client_socket); 2393 MHD_socket_close_chk_ (client_socket);
2381#if ENFILE 2394#if ENFILE
2382 errno = ENFILE; 2395 errno = ENFILE;
2383#endif 2396#endif
2384 return MHD_NO; 2397 return MHD_NO;
2385 } 2398 }
2386#endif 2399#endif
2387 2400
2388 if ( (! MHD_SCKT_FD_FITS_FDSET_(client_socket, 2401 if ( (! MHD_SCKT_FD_FITS_FDSET_ (client_socket,
2389 NULL)) && 2402 NULL)) &&
2390 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) ) 2403 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) )
2391 { 2404 {
2392#ifdef HAVE_MESSAGES 2405#ifdef HAVE_MESSAGES
2393 MHD_DLOG (daemon, 2406 MHD_DLOG (daemon,
2394 _("Socket descriptor larger than FD_SETSIZE: %d > %d\n"), 2407 _ ("Socket descriptor larger than FD_SETSIZE: %d > %d\n"),
2395 (int) client_socket, 2408 (int) client_socket,
2396 (int) FD_SETSIZE); 2409 (int) FD_SETSIZE);
2397#endif 2410#endif
2398 MHD_socket_close_chk_ (client_socket); 2411 MHD_socket_close_chk_ (client_socket);
2399#if EINVAL 2412#if EINVAL
2400 errno = EINVAL; 2413 errno = EINVAL;
2401#endif 2414#endif
2402 return MHD_NO; 2415 return MHD_NO;
2403 } 2416 }
2404 2417
2405#ifdef MHD_socket_nosignal_ 2418#ifdef MHD_socket_nosignal_
2406 if (! MHD_socket_nosignal_ (client_socket)) 2419 if (! MHD_socket_nosignal_ (client_socket))
2407 { 2420 {
2408#ifdef HAVE_MESSAGES 2421#ifdef HAVE_MESSAGES
2409 MHD_DLOG (daemon, 2422 MHD_DLOG (daemon,
2410 _("Failed to set SO_NOSIGPIPE on accepted socket: %s\n"), 2423 _ ("Failed to set SO_NOSIGPIPE on accepted socket: %s\n"),
2411 MHD_socket_last_strerr_()); 2424 MHD_socket_last_strerr_ ());
2412#endif 2425#endif
2413#ifndef MSG_NOSIGNAL 2426#ifndef MSG_NOSIGNAL
2414 /* Cannot use socket as it can produce SIGPIPE. */ 2427 /* Cannot use socket as it can produce SIGPIPE. */
2415#ifdef ENOTSOCK 2428#ifdef ENOTSOCK
2416 errno = ENOTSOCK; 2429 errno = ENOTSOCK;
2417#endif /* ENOTSOCK */ 2430#endif /* ENOTSOCK */
2418 return MHD_NO; 2431 return MHD_NO;
2419#endif /* ! MSG_NOSIGNAL */ 2432#endif /* ! MSG_NOSIGNAL */
2420 } 2433 }
2421#endif /* MHD_socket_nosignal_ */ 2434#endif /* MHD_socket_nosignal_ */
2422 2435
2423 2436
2424#ifdef HAVE_MESSAGES 2437#ifdef HAVE_MESSAGES
2425#if DEBUG_CONNECT 2438#if DEBUG_CONNECT
2426 MHD_DLOG (daemon, 2439 MHD_DLOG (daemon,
2427 _("Accepted connection on socket %d\n"), 2440 _ ("Accepted connection on socket %d\n"),
2428 client_socket); 2441 client_socket);
2429#endif 2442#endif
2430#endif 2443#endif
@@ -2432,93 +2445,94 @@ internal_add_connection (struct MHD_Daemon *daemon,
2432 (MHD_NO == MHD_ip_limit_add (daemon, 2445 (MHD_NO == MHD_ip_limit_add (daemon,
2433 addr, 2446 addr,
2434 addrlen)) ) 2447 addrlen)) )
2435 { 2448 {
2436 /* above connection limit - reject */ 2449 /* above connection limit - reject */
2437#ifdef HAVE_MESSAGES 2450#ifdef HAVE_MESSAGES
2438 MHD_DLOG (daemon, 2451 MHD_DLOG (daemon,
2439 _("Server reached connection limit. Closing inbound connection.\n")); 2452 _ (
2453 "Server reached connection limit. Closing inbound connection.\n"));
2440#endif 2454#endif
2441 MHD_socket_close_chk_ (client_socket); 2455 MHD_socket_close_chk_ (client_socket);
2442#if ENFILE 2456#if ENFILE
2443 errno = ENFILE; 2457 errno = ENFILE;
2444#endif 2458#endif
2445 return MHD_NO; 2459 return MHD_NO;
2446 } 2460 }
2447 2461
2448 /* apply connection acceptance policy if present */ 2462 /* apply connection acceptance policy if present */
2449 if ( (NULL != daemon->apc) && 2463 if ( (NULL != daemon->apc) &&
2450 (MHD_NO == daemon->apc (daemon->apc_cls, 2464 (MHD_NO == daemon->apc (daemon->apc_cls,
2451 addr, 2465 addr,
2452 addrlen)) ) 2466 addrlen)) )
2453 { 2467 {
2454#if DEBUG_CLOSE 2468#if DEBUG_CLOSE
2455#ifdef HAVE_MESSAGES 2469#ifdef HAVE_MESSAGES
2456 MHD_DLOG (daemon, 2470 MHD_DLOG (daemon,
2457 _("Connection rejected by application. Closing connection.\n")); 2471 _ ("Connection rejected by application. Closing connection.\n"));
2458#endif 2472#endif
2459#endif 2473#endif
2460 MHD_socket_close_chk_ (client_socket); 2474 MHD_socket_close_chk_ (client_socket);
2461 MHD_ip_limit_del (daemon, 2475 MHD_ip_limit_del (daemon,
2462 addr, 2476 addr,
2463 addrlen); 2477 addrlen);
2464#if EACCESS 2478#if EACCESS
2465 errno = EACCESS; 2479 errno = EACCESS;
2466#endif 2480#endif
2467 return MHD_NO; 2481 return MHD_NO;
2468 } 2482 }
2469 2483
2470 if (NULL == (connection = MHD_calloc_ (1, sizeof (struct MHD_Connection)))) 2484 if (NULL == (connection = MHD_calloc_ (1, sizeof (struct MHD_Connection))))
2471 { 2485 {
2472 eno = errno; 2486 eno = errno;
2473#ifdef HAVE_MESSAGES 2487#ifdef HAVE_MESSAGES
2474 MHD_DLOG (daemon, 2488 MHD_DLOG (daemon,
2475 "Error allocating memory: %s\n", 2489 "Error allocating memory: %s\n",
2476 MHD_strerror_ (errno)); 2490 MHD_strerror_ (errno));
2477#endif 2491#endif
2478 MHD_socket_close_chk_ (client_socket); 2492 MHD_socket_close_chk_ (client_socket);
2479 MHD_ip_limit_del (daemon, 2493 MHD_ip_limit_del (daemon,
2480 addr, 2494 addr,
2481 addrlen); 2495 addrlen);
2482 errno = eno; 2496 errno = eno;
2483 return MHD_NO; 2497 return MHD_NO;
2484 } 2498 }
2485 connection->pool = MHD_pool_create (daemon->pool_size); 2499 connection->pool = MHD_pool_create (daemon->pool_size);
2486 if (NULL == connection->pool) 2500 if (NULL == connection->pool)
2487 { 2501 {
2488#ifdef HAVE_MESSAGES 2502#ifdef HAVE_MESSAGES
2489 MHD_DLOG (daemon, 2503 MHD_DLOG (daemon,
2490 _("Error allocating memory: %s\n"), 2504 _ ("Error allocating memory: %s\n"),
2491 MHD_strerror_ (errno)); 2505 MHD_strerror_ (errno));
2492#endif 2506#endif
2493 MHD_socket_close_chk_ (client_socket); 2507 MHD_socket_close_chk_ (client_socket);
2494 MHD_ip_limit_del (daemon, 2508 MHD_ip_limit_del (daemon,
2495 addr, 2509 addr,
2496 addrlen); 2510 addrlen);
2497 free (connection); 2511 free (connection);
2498#if ENOMEM 2512#if ENOMEM
2499 errno = ENOMEM; 2513 errno = ENOMEM;
2500#endif 2514#endif
2501 return MHD_NO; 2515 return MHD_NO;
2502 } 2516 }
2503 2517
2504 connection->connection_timeout = daemon->connection_timeout; 2518 connection->connection_timeout = daemon->connection_timeout;
2505 if (NULL == (connection->addr = malloc (addrlen))) 2519 if (NULL == (connection->addr = malloc (addrlen)))
2506 { 2520 {
2507 eno = errno; 2521 eno = errno;
2508#ifdef HAVE_MESSAGES 2522#ifdef HAVE_MESSAGES
2509 MHD_DLOG (daemon, 2523 MHD_DLOG (daemon,
2510 _("Error allocating memory: %s\n"), 2524 _ ("Error allocating memory: %s\n"),
2511 MHD_strerror_ (errno)); 2525 MHD_strerror_ (errno));
2512#endif 2526#endif
2513 MHD_socket_close_chk_ (client_socket); 2527 MHD_socket_close_chk_ (client_socket);
2514 MHD_ip_limit_del (daemon, 2528 MHD_ip_limit_del (daemon,
2515 addr, 2529 addr,
2516 addrlen); 2530 addrlen);
2517 MHD_pool_destroy (connection->pool); 2531 MHD_pool_destroy (connection->pool);
2518 free (connection); 2532 free (connection);
2519 errno = eno; 2533 errno = eno;
2520 return MHD_NO; 2534 return MHD_NO;
2521 } 2535 }
2522 memcpy (connection->addr, 2536 memcpy (connection->addr,
2523 addr, 2537 addr,
2524 addrlen); 2538 addrlen);
@@ -2526,125 +2540,127 @@ internal_add_connection (struct MHD_Daemon *daemon,
2526 connection->socket_fd = client_socket; 2540 connection->socket_fd = client_socket;
2527 connection->sk_nonblck = non_blck; 2541 connection->sk_nonblck = non_blck;
2528 connection->daemon = daemon; 2542 connection->daemon = daemon;
2529 connection->last_activity = MHD_monotonic_sec_counter(); 2543 connection->last_activity = MHD_monotonic_sec_counter ();
2530 2544
2531 if (0 == (daemon->options & MHD_USE_TLS)) 2545 if (0 == (daemon->options & MHD_USE_TLS))
2532 { 2546 {
2533 /* set default connection handlers */ 2547 /* set default connection handlers */
2534 MHD_set_http_callbacks_ (connection); 2548 MHD_set_http_callbacks_ (connection);
2535 } 2549 }
2536 else 2550 else
2537 { 2551 {
2538#ifdef HTTPS_SUPPORT 2552#ifdef HTTPS_SUPPORT
2539#if (GNUTLS_VERSION_NUMBER+0 >= 0x030500) 2553#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030500)
2540 gnutls_init_flags_t 2554 gnutls_init_flags_t
2541#else 2555#else
2542 unsigned int 2556 unsigned int
2543#endif 2557#endif
2544 flags; 2558 flags;
2545 2559
2546 flags = GNUTLS_SERVER; 2560 flags = GNUTLS_SERVER;
2547#if (GNUTLS_VERSION_NUMBER+0 >= 0x030402) 2561#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
2548 flags |= GNUTLS_NO_SIGNAL; 2562 flags |= GNUTLS_NO_SIGNAL;
2549#endif /* GNUTLS_VERSION_NUMBER >= 0x030402 */ 2563#endif /* GNUTLS_VERSION_NUMBER >= 0x030402 */
2550#if GNUTLS_VERSION_MAJOR >= 3 2564#if GNUTLS_VERSION_MAJOR >= 3
2551 flags |= GNUTLS_NONBLOCK; 2565 flags |= GNUTLS_NONBLOCK;
2552#endif /* GNUTLS_VERSION_MAJOR >= 3*/ 2566#endif /* GNUTLS_VERSION_MAJOR >= 3*/
2553#if (GNUTLS_VERSION_NUMBER+0 >= 0x030603) 2567#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030603)
2554 if (0 != (daemon->options & MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT)) 2568 if (0 != (daemon->options & MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT))
2555 flags |= GNUTLS_POST_HANDSHAKE_AUTH; 2569 flags |= GNUTLS_POST_HANDSHAKE_AUTH;
2556#endif 2570#endif
2557#if (GNUTLS_VERSION_NUMBER+0 >= 0x030605) 2571#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030605)
2558 if (0 != (daemon->options & MHD_USE_INSECURE_TLS_EARLY_DATA)) 2572 if (0 != (daemon->options & MHD_USE_INSECURE_TLS_EARLY_DATA))
2559 flags |= GNUTLS_ENABLE_EARLY_DATA; 2573 flags |= GNUTLS_ENABLE_EARLY_DATA;
2560#endif 2574#endif
2561 connection->tls_state = MHD_TLS_CONN_INIT; 2575 connection->tls_state = MHD_TLS_CONN_INIT;
2562 MHD_set_https_callbacks (connection); 2576 MHD_set_https_callbacks (connection);
2563 gnutls_init (&connection->tls_session, 2577 gnutls_init (&connection->tls_session,
2564 flags); 2578 flags);
2565 gnutls_priority_set (connection->tls_session, 2579 gnutls_priority_set (connection->tls_session,
2566 daemon->priority_cache); 2580 daemon->priority_cache);
2567 gnutls_session_set_ptr (connection->tls_session, 2581 gnutls_session_set_ptr (connection->tls_session,
2568 connection); 2582 connection);
2569 switch (daemon->cred_type) 2583 switch (daemon->cred_type)
2570 { 2584 {
2571 /* set needed credentials for certificate authentication. */ 2585 /* set needed credentials for certificate authentication. */
2572 case GNUTLS_CRD_CERTIFICATE: 2586 case GNUTLS_CRD_CERTIFICATE:
2573 gnutls_credentials_set (connection->tls_session, 2587 gnutls_credentials_set (connection->tls_session,
2574 GNUTLS_CRD_CERTIFICATE, 2588 GNUTLS_CRD_CERTIFICATE,
2575 daemon->x509_cred); 2589 daemon->x509_cred);
2576 break; 2590 break;
2577 case GNUTLS_CRD_PSK: 2591 case GNUTLS_CRD_PSK:
2578 gnutls_credentials_set (connection->tls_session, 2592 gnutls_credentials_set (connection->tls_session,
2579 GNUTLS_CRD_PSK, 2593 GNUTLS_CRD_PSK,
2580 daemon->psk_cred); 2594 daemon->psk_cred);
2581 gnutls_psk_set_server_credentials_function (daemon->psk_cred, 2595 gnutls_psk_set_server_credentials_function (daemon->psk_cred,
2582 &psk_gnutls_adapter); 2596 &psk_gnutls_adapter);
2583 break; 2597 break;
2584 default: 2598 default:
2585#ifdef HAVE_MESSAGES 2599#ifdef HAVE_MESSAGES
2586 MHD_DLOG (connection->daemon, 2600 MHD_DLOG (connection->daemon,
2587 _("Failed to setup TLS credentials: unknown credential type %d\n"), 2601 _ (
2588 daemon->cred_type); 2602 "Failed to setup TLS credentials: unknown credential type %d\n"),
2589#endif 2603 daemon->cred_type);
2590 MHD_socket_close_chk_ (client_socket); 2604#endif
2591 MHD_ip_limit_del (daemon, 2605 MHD_socket_close_chk_ (client_socket);
2592 addr, 2606 MHD_ip_limit_del (daemon,
2593 addrlen); 2607 addr,
2594 free (connection->addr); 2608 addrlen);
2595 free (connection); 2609 free (connection->addr);
2596 MHD_PANIC (_("Unknown credential type")); 2610 free (connection);
2611 MHD_PANIC (_ ("Unknown credential type"));
2597#if EINVAL 2612#if EINVAL
2598 errno = EINVAL; 2613 errno = EINVAL;
2599#endif 2614#endif
2600 return MHD_NO; 2615 return MHD_NO;
2601 } 2616 }
2602#if (GNUTLS_VERSION_NUMBER+0 >= 0x030109) && !defined(_WIN64) 2617#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
2603 gnutls_transport_set_int (connection->tls_session, 2618 gnutls_transport_set_int (connection->tls_session,
2604 (int)(client_socket)); 2619 (int) (client_socket));
2605#else /* GnuTLS before 3.1.9 or Win x64 */ 2620#else /* GnuTLS before 3.1.9 or Win x64 */
2606 gnutls_transport_set_ptr (connection->tls_session, 2621 gnutls_transport_set_ptr (connection->tls_session,
2607 (gnutls_transport_ptr_t)(intptr_t)(client_socket)); 2622 (gnutls_transport_ptr_t) (intptr_t) (client_socket));
2608#endif /* GnuTLS before 3.1.9 */ 2623#endif /* GnuTLS before 3.1.9 */
2609#ifdef MHD_TLSLIB_NEED_PUSH_FUNC 2624#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2610 gnutls_transport_set_push_function (connection->tls_session, 2625 gnutls_transport_set_push_function (connection->tls_session,
2611 MHD_tls_push_func_); 2626 MHD_tls_push_func_);
2612#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */ 2627#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */
2613 if (daemon->https_mem_trust) 2628 if (daemon->https_mem_trust)
2614 gnutls_certificate_server_set_request (connection->tls_session, 2629 gnutls_certificate_server_set_request (connection->tls_session,
2615 GNUTLS_CERT_REQUEST); 2630 GNUTLS_CERT_REQUEST);
2616#else /* ! HTTPS_SUPPORT */ 2631#else /* ! HTTPS_SUPPORT */
2617 eno = EINVAL; 2632 eno = EINVAL;
2618 goto cleanup; 2633 goto cleanup;
2619#endif /* ! HTTPS_SUPPORT */ 2634#endif /* ! HTTPS_SUPPORT */
2620 } 2635 }
2621 2636
2622#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2637#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2623 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2638 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2624#endif 2639#endif
2625 /* Firm check under lock. */ 2640 /* Firm check under lock. */
2626 if (daemon->connections >= daemon->connection_limit) 2641 if (daemon->connections >= daemon->connection_limit)
2627 { 2642 {
2628#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2643#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2629 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2644 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2630#endif 2645#endif
2631 /* above connection limit - reject */ 2646 /* above connection limit - reject */
2632#ifdef HAVE_MESSAGES 2647#ifdef HAVE_MESSAGES
2633 MHD_DLOG (daemon, 2648 MHD_DLOG (daemon,
2634 _("Server reached connection limit. Closing inbound connection.\n")); 2649 _ (
2650 "Server reached connection limit. Closing inbound connection.\n"));
2635#endif 2651#endif
2636#if ENFILE 2652#if ENFILE
2637 eno = ENFILE; 2653 eno = ENFILE;
2638#endif 2654#endif
2639 goto cleanup; 2655 goto cleanup;
2640 } 2656 }
2641 daemon->connections++; 2657 daemon->connections++;
2642 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2658 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2643 { 2659 {
2644 XDLL_insert (daemon->normal_timeout_head, 2660 XDLL_insert (daemon->normal_timeout_head,
2645 daemon->normal_timeout_tail, 2661 daemon->normal_timeout_tail,
2646 connection); 2662 connection);
2647 } 2663 }
2648 DLL_insert (daemon->connections_head, 2664 DLL_insert (daemon->connections_head,
2649 daemon->connections_tail, 2665 daemon->connections_tail,
2650 connection); 2666 connection);
@@ -2659,80 +2675,82 @@ internal_add_connection (struct MHD_Daemon *daemon,
2659#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2675#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2660 /* attempt to create handler thread */ 2676 /* attempt to create handler thread */
2661 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2677 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2678 {
2679 if (! MHD_create_named_thread_ (&connection->pid,
2680 "MHD-connection",
2681 daemon->thread_stack_size,
2682 &thread_main_handle_connection,
2683 connection))
2662 { 2684 {
2663 if (! MHD_create_named_thread_ (&connection->pid, 2685 eno = errno;
2664 "MHD-connection",
2665 daemon->thread_stack_size,
2666 &thread_main_handle_connection,
2667 connection))
2668 {
2669 eno = errno;
2670#ifdef HAVE_MESSAGES 2686#ifdef HAVE_MESSAGES
2671 MHD_DLOG (daemon, 2687 MHD_DLOG (daemon,
2672 "Failed to create a thread: %s\n", 2688 "Failed to create a thread: %s\n",
2673 MHD_strerror_ (eno)); 2689 MHD_strerror_ (eno));
2674#endif 2690#endif
2675 goto cleanup; 2691 goto cleanup;
2676 }
2677 } 2692 }
2693 }
2678 else 2694 else
2679 connection->pid = daemon->pid; 2695 connection->pid = daemon->pid;
2680#endif 2696#endif
2681#ifdef EPOLL_SUPPORT 2697#ifdef EPOLL_SUPPORT
2682 if (0 != (daemon->options & MHD_USE_EPOLL)) 2698 if (0 != (daemon->options & MHD_USE_EPOLL))
2683 { 2699 {
2684 if ((0 == (daemon->options & MHD_USE_TURBO)) || (external_add)) 2700 if ((0 == (daemon->options & MHD_USE_TURBO)) || (external_add))
2685 { /* Do not manipulate EReady DL-list in 'external_add' mode. */ 2701 { /* Do not manipulate EReady DL-list in 'external_add' mode. */
2686 struct epoll_event event; 2702 struct epoll_event event;
2687 2703
2688 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET; 2704 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
2689 event.data.ptr = connection; 2705 event.data.ptr = connection;
2690 if (0 != epoll_ctl (daemon->epoll_fd, 2706 if (0 != epoll_ctl (daemon->epoll_fd,
2691 EPOLL_CTL_ADD, 2707 EPOLL_CTL_ADD,
2692 client_socket, 2708 client_socket,
2693 &event)) 2709 &event))
2694 { 2710 {
2695 eno = errno; 2711 eno = errno;
2696#ifdef HAVE_MESSAGES 2712#ifdef HAVE_MESSAGES
2697 MHD_DLOG (daemon, 2713 MHD_DLOG (daemon,
2698 _("Call to epoll_ctl failed: %s\n"), 2714 _ ("Call to epoll_ctl failed: %s\n"),
2699 MHD_socket_last_strerr_ ()); 2715 MHD_socket_last_strerr_ ());
2700#endif 2716#endif
2701 goto cleanup; 2717 goto cleanup;
2702 } 2718 }
2703 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET; 2719 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
2704 } 2720 }
2705 else 2721 else
2706 { 2722 {
2707 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY 2723 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY
2708 | MHD_EPOLL_STATE_IN_EREADY_EDLL; 2724 | MHD_EPOLL_STATE_WRITE_READY
2709 EDLL_insert (daemon->eready_head, 2725 | MHD_EPOLL_STATE_IN_EREADY_EDLL;
2726 EDLL_insert (daemon->eready_head,
2710 daemon->eready_tail, 2727 daemon->eready_tail,
2711 connection); 2728 connection);
2712 }
2713 } 2729 }
2730 }
2714 else /* This 'else' is combined with next 'if'. */ 2731 else /* This 'else' is combined with next 'if'. */
2715#endif 2732#endif
2716 if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2733 if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2717 (external_add) && 2734 (external_add) &&
2718 (MHD_ITC_IS_VALID_(daemon->itc)) && 2735 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2719 (! MHD_itc_activate_ (daemon->itc, "n")) ) 2736 (! MHD_itc_activate_ (daemon->itc, "n")) )
2720 { 2737 {
2721#ifdef HAVE_MESSAGES 2738#ifdef HAVE_MESSAGES
2722 MHD_DLOG (daemon, 2739 MHD_DLOG (daemon,
2723 _("Failed to signal new connection via inter-thread communication channel.")); 2740 _ (
2741 "Failed to signal new connection via inter-thread communication channel."));
2724#endif 2742#endif
2725 } 2743 }
2726 return MHD_YES; 2744 return MHD_YES;
2727 cleanup: 2745cleanup:
2728 if (NULL != daemon->notify_connection) 2746 if (NULL != daemon->notify_connection)
2729 daemon->notify_connection (daemon->notify_connection_cls, 2747 daemon->notify_connection (daemon->notify_connection_cls,
2730 connection, 2748 connection,
2731 &connection->socket_context, 2749 &connection->socket_context,
2732 MHD_CONNECTION_NOTIFY_CLOSED); 2750 MHD_CONNECTION_NOTIFY_CLOSED);
2733#ifdef HTTPS_SUPPORT 2751#ifdef HTTPS_SUPPORT
2734 if (NULL != connection->tls_session) 2752 if (NULL != connection->tls_session)
2735 gnutls_deinit (connection->tls_session); 2753 gnutls_deinit (connection->tls_session);
2736#endif /* HTTPS_SUPPORT */ 2754#endif /* HTTPS_SUPPORT */
2737 MHD_socket_close_chk_ (client_socket); 2755 MHD_socket_close_chk_ (client_socket);
2738 MHD_ip_limit_del (daemon, 2756 MHD_ip_limit_del (daemon,
@@ -2742,14 +2760,14 @@ internal_add_connection (struct MHD_Daemon *daemon,
2742 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2760 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2743#endif 2761#endif
2744 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2762 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2745 { 2763 {
2746 XDLL_remove (daemon->normal_timeout_head, 2764 XDLL_remove (daemon->normal_timeout_head,
2747 daemon->normal_timeout_tail, 2765 daemon->normal_timeout_tail,
2748 connection); 2766 connection);
2749 } 2767 }
2750 DLL_remove (daemon->connections_head, 2768 DLL_remove (daemon->connections_head,
2751 daemon->connections_tail, 2769 daemon->connections_tail,
2752 connection); 2770 connection);
2753#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2771#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2754 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2772 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2755#endif 2773#endif
@@ -2782,25 +2800,25 @@ internal_suspend_connection_ (struct MHD_Connection *connection)
2782 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2800 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2783#endif 2801#endif
2784 if (connection->resuming) 2802 if (connection->resuming)
2785 { 2803 {
2786 /* suspending again while we didn't even complete resuming yet */ 2804 /* suspending again while we didn't even complete resuming yet */
2787 connection->resuming = false; 2805 connection->resuming = false;
2788#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2806#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2789 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2807 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2790#endif 2808#endif
2791 return; 2809 return;
2792 } 2810 }
2793 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2811 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2794 { 2812 {
2795 if (connection->connection_timeout == daemon->connection_timeout) 2813 if (connection->connection_timeout == daemon->connection_timeout)
2796 XDLL_remove (daemon->normal_timeout_head, 2814 XDLL_remove (daemon->normal_timeout_head,
2797 daemon->normal_timeout_tail, 2815 daemon->normal_timeout_tail,
2798 connection); 2816 connection);
2799 else 2817 else
2800 XDLL_remove (daemon->manual_timeout_head, 2818 XDLL_remove (daemon->manual_timeout_head,
2801 daemon->manual_timeout_tail, 2819 daemon->manual_timeout_tail,
2802 connection); 2820 connection);
2803 } 2821 }
2804 DLL_remove (daemon->connections_head, 2822 DLL_remove (daemon->connections_head,
2805 daemon->connections_tail, 2823 daemon->connections_tail,
2806 connection); 2824 connection);
@@ -2811,25 +2829,25 @@ internal_suspend_connection_ (struct MHD_Connection *connection)
2811 connection->suspended = true; 2829 connection->suspended = true;
2812#ifdef EPOLL_SUPPORT 2830#ifdef EPOLL_SUPPORT
2813 if (0 != (daemon->options & MHD_USE_EPOLL)) 2831 if (0 != (daemon->options & MHD_USE_EPOLL))
2832 {
2833 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
2814 { 2834 {
2815 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 2835 EDLL_remove (daemon->eready_head,
2816 { 2836 daemon->eready_tail,
2817 EDLL_remove (daemon->eready_head, 2837 connection);
2818 daemon->eready_tail, 2838 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
2819 connection); 2839 }
2820 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 2840 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET))
2821 } 2841 {
2822 if (0 != (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) 2842 if (0 != epoll_ctl (daemon->epoll_fd,
2823 { 2843 EPOLL_CTL_DEL,
2824 if (0 != epoll_ctl (daemon->epoll_fd, 2844 connection->socket_fd,
2825 EPOLL_CTL_DEL, 2845 NULL))
2826 connection->socket_fd, 2846 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
2827 NULL)) 2847 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
2828 MHD_PANIC (_("Failed to remove FD from epoll set\n"));
2829 connection->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
2830 }
2831 connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED;
2832 } 2848 }
2849 connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED;
2850 }
2833#endif 2851#endif
2834#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2852#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2835 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2853 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
@@ -2871,19 +2889,21 @@ internal_suspend_connection_ (struct MHD_Connection *connection)
2871void 2889void
2872MHD_suspend_connection (struct MHD_Connection *connection) 2890MHD_suspend_connection (struct MHD_Connection *connection)
2873{ 2891{
2874 struct MHD_Daemon * const daemon = connection->daemon; 2892 struct MHD_Daemon *const daemon = connection->daemon;
2875 2893
2876 if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) 2894 if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME))
2877 MHD_PANIC (_("Cannot suspend connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); 2895 MHD_PANIC (_ (
2896 "Cannot suspend connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
2878#ifdef UPGRADE_SUPPORT 2897#ifdef UPGRADE_SUPPORT
2879 if (NULL != connection->urh) 2898 if (NULL != connection->urh)
2880 { 2899 {
2881#ifdef HAVE_MESSAGES 2900#ifdef HAVE_MESSAGES
2882 MHD_DLOG (daemon, 2901 MHD_DLOG (daemon,
2883 _("Error: connection scheduled for \"upgrade\" cannot be suspended")); 2902 _ (
2903 "Error: connection scheduled for \"upgrade\" cannot be suspended"));
2884#endif /* HAVE_MESSAGES */ 2904#endif /* HAVE_MESSAGES */
2885 return; 2905 return;
2886 } 2906 }
2887#endif /* UPGRADE_SUPPORT */ 2907#endif /* UPGRADE_SUPPORT */
2888 internal_suspend_connection_ (connection); 2908 internal_suspend_connection_ (connection);
2889} 2909}
@@ -2903,7 +2923,8 @@ MHD_resume_connection (struct MHD_Connection *connection)
2903 struct MHD_Daemon *daemon = connection->daemon; 2923 struct MHD_Daemon *daemon = connection->daemon;
2904 2924
2905 if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) 2925 if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME))
2906 MHD_PANIC (_("Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); 2926 MHD_PANIC (_ (
2927 "Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
2907#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2928#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2908 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2929 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2909#endif 2930#endif
@@ -2912,14 +2933,15 @@ MHD_resume_connection (struct MHD_Connection *connection)
2912#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2933#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2913 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2934 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2914#endif 2935#endif
2915 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 2936 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
2916 (! MHD_itc_activate_ (daemon->itc, "r")) ) 2937 (! MHD_itc_activate_ (daemon->itc, "r")) )
2917 { 2938 {
2918#ifdef HAVE_MESSAGES 2939#ifdef HAVE_MESSAGES
2919 MHD_DLOG (daemon, 2940 MHD_DLOG (daemon,
2920 _("Failed to signal resume via inter-thread communication channel.")); 2941 _ (
2942 "Failed to signal resume via inter-thread communication channel."));
2921#endif 2943#endif
2922 } 2944 }
2923} 2945}
2924 2946
2925 2947
@@ -2938,7 +2960,8 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
2938 struct MHD_Connection *pos; 2960 struct MHD_Connection *pos;
2939 struct MHD_Connection *prev = NULL; 2961 struct MHD_Connection *prev = NULL;
2940 int ret; 2962 int ret;
2941 const bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); 2963 const bool used_thr_p_c = (0 != (daemon->options
2964 & MHD_USE_THREAD_PER_CONNECTION));
2942#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2965#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2943 mhd_assert (NULL == daemon->worker_pool); 2966 mhd_assert (NULL == daemon->worker_pool);
2944#endif 2967#endif
@@ -2947,112 +2970,114 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
2947 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2970 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2948#endif 2971#endif
2949 if (daemon->resuming) 2972 if (daemon->resuming)
2950 { 2973 {
2951 prev = daemon->suspended_connections_tail; 2974 prev = daemon->suspended_connections_tail;
2952 /* During shutdown check for resuming is forced. */ 2975 /* During shutdown check for resuming is forced. */
2953 mhd_assert((NULL != prev) || (daemon->shutdown)); 2976 mhd_assert ((NULL != prev) || (daemon->shutdown));
2954 } 2977 }
2955 2978
2956 daemon->resuming = false; 2979 daemon->resuming = false;
2957 2980
2958 while (NULL != (pos = prev)) 2981 while (NULL != (pos = prev))
2959 { 2982 {
2960#ifdef UPGRADE_SUPPORT 2983#ifdef UPGRADE_SUPPORT
2961 struct MHD_UpgradeResponseHandle * const urh = pos->urh; 2984 struct MHD_UpgradeResponseHandle *const urh = pos->urh;
2962#else /* ! UPGRADE_SUPPORT */ 2985#else /* ! UPGRADE_SUPPORT */
2963 static const void * const urh = NULL; 2986 static const void *const urh = NULL;
2964#endif /* ! UPGRADE_SUPPORT */ 2987#endif /* ! UPGRADE_SUPPORT */
2965 prev = pos->prev; 2988 prev = pos->prev;
2966 if ( (! pos->resuming) 2989 if ( (! pos->resuming)
2967#ifdef UPGRADE_SUPPORT 2990#ifdef UPGRADE_SUPPORT
2968 || ( (NULL != urh) && 2991 || ( (NULL != urh) &&
2969 ( (! urh->was_closed) || 2992 ( (! urh->was_closed) ||
2970 (! urh->clean_ready) ) ) 2993 (! urh->clean_ready) ) )
2971#endif /* UPGRADE_SUPPORT */ 2994#endif /* UPGRADE_SUPPORT */
2972 ) 2995 )
2973 continue; 2996 continue;
2974 ret = MHD_YES; 2997 ret = MHD_YES;
2975 mhd_assert (pos->suspended); 2998 mhd_assert (pos->suspended);
2976 DLL_remove (daemon->suspended_connections_head, 2999 DLL_remove (daemon->suspended_connections_head,
2977 daemon->suspended_connections_tail, 3000 daemon->suspended_connections_tail,
3001 pos);
3002 pos->suspended = false;
3003 if (NULL == urh)
3004 {
3005 DLL_insert (daemon->connections_head,
3006 daemon->connections_tail,
2978 pos); 3007 pos);
2979 pos->suspended = false; 3008 if (! used_thr_p_c)
2980 if (NULL == urh) 3009 {
2981 { 3010 /* Reset timeout timer on resume. */
2982 DLL_insert (daemon->connections_head, 3011 if (0 != pos->connection_timeout)
2983 daemon->connections_tail, 3012 pos->last_activity = MHD_monotonic_sec_counter ();
2984 pos); 3013
2985 if (! used_thr_p_c) 3014 if (pos->connection_timeout == daemon->connection_timeout)
2986 { 3015 XDLL_insert (daemon->normal_timeout_head,
2987 /* Reset timeout timer on resume. */ 3016 daemon->normal_timeout_tail,
2988 if (0 != pos->connection_timeout) 3017 pos);
2989 pos->last_activity = MHD_monotonic_sec_counter(); 3018 else
2990 3019 XDLL_insert (daemon->manual_timeout_head,
2991 if (pos->connection_timeout == daemon->connection_timeout) 3020 daemon->manual_timeout_tail,
2992 XDLL_insert (daemon->normal_timeout_head, 3021 pos);
2993 daemon->normal_timeout_tail, 3022 }
2994 pos);
2995 else
2996 XDLL_insert (daemon->manual_timeout_head,
2997 daemon->manual_timeout_tail,
2998 pos);
2999 }
3000#ifdef EPOLL_SUPPORT 3023#ifdef EPOLL_SUPPORT
3001 if (0 != (daemon->options & MHD_USE_EPOLL)) 3024 if (0 != (daemon->options & MHD_USE_EPOLL))
3002 { 3025 {
3003 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 3026 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
3004 MHD_PANIC ("Resumed connection was already in EREADY set\n"); 3027 MHD_PANIC ("Resumed connection was already in EREADY set\n");
3005 /* we always mark resumed connections as ready, as we 3028 /* we always mark resumed connections as ready, as we
3006 might have missed the edge poll event during suspension */ 3029 might have missed the edge poll event during suspension */
3007 EDLL_insert (daemon->eready_head, 3030 EDLL_insert (daemon->eready_head,
3008 daemon->eready_tail, 3031 daemon->eready_tail,
3009 pos); 3032 pos);
3010 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL | \ 3033 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL \
3011 MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY; 3034 | MHD_EPOLL_STATE_READ_READY
3012 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED; 3035 | MHD_EPOLL_STATE_WRITE_READY;
3013 } 3036 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED;
3037 }
3014#endif 3038#endif
3015 } 3039 }
3016#ifdef UPGRADE_SUPPORT 3040#ifdef UPGRADE_SUPPORT
3017 else 3041 else
3018 { 3042 {
3019 /* Data forwarding was finished (for TLS connections) AND 3043 /* Data forwarding was finished (for TLS connections) AND
3020 * application was closed upgraded connection. 3044 * application was closed upgraded connection.
3021 * Insert connection into cleanup list. */ 3045 * Insert connection into cleanup list. */
3022 3046
3023 if ( (NULL != daemon->notify_completed) && 3047 if ( (NULL != daemon->notify_completed) &&
3024 (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3048 (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3025 (pos->client_aware) ) 3049 (pos->client_aware) )
3026 { 3050 {
3027 daemon->notify_completed (daemon->notify_completed_cls, 3051 daemon->notify_completed (daemon->notify_completed_cls,
3028 pos, 3052 pos,
3029 &pos->client_context, 3053 &pos->client_context,
3030 MHD_REQUEST_TERMINATED_COMPLETED_OK); 3054 MHD_REQUEST_TERMINATED_COMPLETED_OK);
3031 pos->client_aware = false; 3055 pos->client_aware = false;
3032 } 3056 }
3033 DLL_insert (daemon->cleanup_head, 3057 DLL_insert (daemon->cleanup_head,
3034 daemon->cleanup_tail, 3058 daemon->cleanup_tail,
3035 pos); 3059 pos);
3036 3060
3037 }
3038#endif /* UPGRADE_SUPPORT */
3039 pos->resuming = false;
3040 } 3061 }
3062#endif /* UPGRADE_SUPPORT */
3063 pos->resuming = false;
3064 }
3041#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3065#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3042 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 3066 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
3043#endif 3067#endif
3044 if ( (used_thr_p_c) && 3068 if ( (used_thr_p_c) &&
3045 (MHD_NO != ret) ) 3069 (MHD_NO != ret) )
3046 { /* Wake up suspended connections. */ 3070 { /* Wake up suspended connections. */
3047 if (! MHD_itc_activate_(daemon->itc, 3071 if (! MHD_itc_activate_ (daemon->itc,
3048 "w")) 3072 "w"))
3049 { 3073 {
3050#ifdef HAVE_MESSAGES 3074#ifdef HAVE_MESSAGES
3051 MHD_DLOG (daemon, 3075 MHD_DLOG (daemon,
3052 _("Failed to signal resume of connection via inter-thread communication channel.")); 3076 _ (
3077 "Failed to signal resume of connection via inter-thread communication channel."));
3053#endif 3078#endif
3054 }
3055 } 3079 }
3080 }
3056 return ret; 3081 return ret;
3057} 3082}
3058 3083
@@ -3093,34 +3118,34 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3093 bool sk_nonbl; 3118 bool sk_nonbl;
3094 3119
3095 if (! MHD_socket_nonblocking_ (client_socket)) 3120 if (! MHD_socket_nonblocking_ (client_socket))
3096 { 3121 {
3097#ifdef HAVE_MESSAGES 3122#ifdef HAVE_MESSAGES
3098 MHD_DLOG (daemon, 3123 MHD_DLOG (daemon,
3099 _("Failed to set nonblocking mode on new client socket: %s\n"), 3124 _ ("Failed to set nonblocking mode on new client socket: %s\n"),
3100 MHD_socket_last_strerr_()); 3125 MHD_socket_last_strerr_ ());
3101#endif 3126#endif
3102 sk_nonbl = 0; 3127 sk_nonbl = 0;
3103 } 3128 }
3104 else 3129 else
3105 sk_nonbl = !0; 3130 sk_nonbl = ! 0;
3106 3131
3107 if ( (0 != (daemon->options & MHD_USE_TURBO)) && 3132 if ( (0 != (daemon->options & MHD_USE_TURBO)) &&
3108 (! MHD_socket_noninheritable_ (client_socket)) ) 3133 (! MHD_socket_noninheritable_ (client_socket)) )
3109 { 3134 {
3110#ifdef HAVE_MESSAGES 3135#ifdef HAVE_MESSAGES
3111 MHD_DLOG (daemon, 3136 MHD_DLOG (daemon,
3112 _("Failed to set noninheritable mode on new client socket.\n")); 3137 _ ("Failed to set noninheritable mode on new client socket.\n"));
3113#endif 3138#endif
3114 } 3139 }
3115 3140
3116 if ( (0 == (daemon->options & MHD_USE_TURBO)) && 3141 if ( (0 == (daemon->options & MHD_USE_TURBO)) &&
3117 (! MHD_socket_buffering_reset_ (client_socket)) ) 3142 (! MHD_socket_buffering_reset_ (client_socket)) )
3118 { 3143 {
3119#ifdef HAVE_MESSAGES 3144#ifdef HAVE_MESSAGES
3120 MHD_DLOG (daemon, 3145 MHD_DLOG (daemon,
3121 _("Failed to reset buffering mode on new client socket.\n")); 3146 _ ("Failed to reset buffering mode on new client socket.\n"));
3122#endif 3147#endif
3123 } 3148 }
3124 return internal_add_connection (daemon, 3149 return internal_add_connection (daemon,
3125 client_socket, 3150 client_socket,
3126 addr, 3151 addr,
@@ -3179,94 +3204,98 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
3179#endif /* ! USE_ACCEPT4 */ 3204#endif /* ! USE_ACCEPT4 */
3180 if ( (MHD_INVALID_SOCKET == s) || 3205 if ( (MHD_INVALID_SOCKET == s) ||
3181 (addrlen <= 0) ) 3206 (addrlen <= 0) )
3182 { 3207 {
3183 const int err = MHD_socket_get_error_ (); 3208 const int err = MHD_socket_get_error_ ();
3184 3209
3185 /* This could be a common occurance with multiple worker threads */ 3210 /* This could be a common occurance with multiple worker threads */
3186 if (MHD_SCKT_ERR_IS_ (err, 3211 if (MHD_SCKT_ERR_IS_ (err,
3187 MHD_SCKT_EINVAL_)) 3212 MHD_SCKT_EINVAL_))
3188 return MHD_NO; /* can happen during shutdown */ 3213 return MHD_NO; /* can happen during shutdown */
3189 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)) 3214 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_ (err))
3190 return MHD_NO; /* do not print error if client just disconnected early */ 3215 return MHD_NO; /* do not print error if client just disconnected early */
3216#ifdef HAVE_MESSAGES
3217 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err) )
3218 MHD_DLOG (daemon,
3219 _ ("Error accepting connection: %s\n"),
3220 MHD_socket_strerr_ (err));
3221#endif
3222 if (MHD_INVALID_SOCKET != s)
3223 {
3224 MHD_socket_close_chk_ (s);
3225 }
3226 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) )
3227 {
3228 /* system/process out of resources */
3229 if (0 == daemon->connections)
3230 {
3191#ifdef HAVE_MESSAGES 3231#ifdef HAVE_MESSAGES
3192 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err) ) 3232 /* Not setting 'at_limit' flag, as there is no way it
3233 would ever be cleared. Instead trying to produce
3234 bit fat ugly warning. */
3193 MHD_DLOG (daemon, 3235 MHD_DLOG (daemon,
3194 _("Error accepting connection: %s\n"), 3236 _ (
3195 MHD_socket_strerr_(err)); 3237 "Hit process or system resource limit at FIRST connection. This is really bad as there is no sane way to proceed. Will try busy waiting for system resources to become magically available.\n"));
3196#endif 3238#endif
3197 if (MHD_INVALID_SOCKET != s) 3239 }
3198 { 3240 else
3199 MHD_socket_close_chk_ (s); 3241 {
3200 }
3201 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) )
3202 {
3203 /* system/process out of resources */
3204 if (0 == daemon->connections)
3205 {
3206#ifdef HAVE_MESSAGES
3207 /* Not setting 'at_limit' flag, as there is no way it
3208 would ever be cleared. Instead trying to produce
3209 bit fat ugly warning. */
3210 MHD_DLOG (daemon,
3211 _("Hit process or system resource limit at FIRST connection. This is really bad as there is no sane way to proceed. Will try busy waiting for system resources to become magically available.\n"));
3212#endif
3213 }
3214 else
3215 {
3216#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3242#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3217 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 3243 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
3218#endif 3244#endif
3219 daemon->at_limit = true; 3245 daemon->at_limit = true;
3220#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3246#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3221 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 3247 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
3222#endif 3248#endif
3223#ifdef HAVE_MESSAGES 3249#ifdef HAVE_MESSAGES
3224 MHD_DLOG (daemon, 3250 MHD_DLOG (daemon,
3225 _("Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"), 3251 _ (
3226 (unsigned int) daemon->connections); 3252 "Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
3253 (unsigned int) daemon->connections);
3227#endif 3254#endif
3228 } 3255 }
3229 }
3230 return MHD_NO;
3231 } 3256 }
3257 return MHD_NO;
3258 }
3232#if defined(MHD_TCP_CORK_NOPUSH) || defined(HAVE_MSG_MORE) 3259#if defined(MHD_TCP_CORK_NOPUSH) || defined(HAVE_MSG_MORE)
3233 /* We will use TCP_CORK or TCP_NOPUSH or MSG_MORE to control 3260 /* We will use TCP_CORK or TCP_NOPUSH or MSG_MORE to control
3234 transmission, disable Nagle's algorithm (always) */ 3261 transmission, disable Nagle's algorithm (always) */
3235 if (0 != MHD_socket_set_nodelay_ (s, 3262 if (0 != MHD_socket_set_nodelay_ (s,
3236 true)) 3263 true))
3237 { 3264 {
3238#ifdef HAVE_MESSAGES 3265#ifdef HAVE_MESSAGES
3239 MHD_DLOG (daemon, 3266 MHD_DLOG (daemon,
3240 _("Failed to disable TCP Nagle on socket: %s\n"), 3267 _ ("Failed to disable TCP Nagle on socket: %s\n"),
3241 MHD_socket_last_strerr_()); 3268 MHD_socket_last_strerr_ ());
3242 } 3269 }
3243#endif 3270#endif
3244#endif 3271#endif
3245#if !defined(USE_ACCEPT4) || !defined(HAVE_SOCK_NONBLOCK) 3272#if ! defined(USE_ACCEPT4) || ! defined(HAVE_SOCK_NONBLOCK)
3246 if (! MHD_socket_nonblocking_ (s)) 3273 if (! MHD_socket_nonblocking_ (s))
3247 { 3274 {
3248#ifdef HAVE_MESSAGES 3275#ifdef HAVE_MESSAGES
3249 MHD_DLOG (daemon, 3276 MHD_DLOG (daemon,
3250 _("Failed to set nonblocking mode on incoming connection socket: %s\n"), 3277 _ (
3251 MHD_socket_last_strerr_()); 3278 "Failed to set nonblocking mode on incoming connection socket: %s\n"),
3279 MHD_socket_last_strerr_ ());
3252#endif 3280#endif
3253 } 3281 }
3254 else 3282 else
3255 sk_nonbl = !0; 3283 sk_nonbl = ! 0;
3256#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */ 3284#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */
3257#if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC) 3285#if ! defined(USE_ACCEPT4) || ! defined(SOCK_CLOEXEC)
3258 if (! MHD_socket_noninheritable_ (s)) 3286 if (! MHD_socket_noninheritable_ (s))
3259 { 3287 {
3260#ifdef HAVE_MESSAGES 3288#ifdef HAVE_MESSAGES
3261 MHD_DLOG (daemon, 3289 MHD_DLOG (daemon,
3262 _("Failed to set noninheritable mode on incoming connection socket.\n")); 3290 _ (
3291 "Failed to set noninheritable mode on incoming connection socket.\n"));
3263#endif 3292#endif
3264 } 3293 }
3265#endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */ 3294#endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */
3266#ifdef HAVE_MESSAGES 3295#ifdef HAVE_MESSAGES
3267#if DEBUG_CONNECT 3296#if DEBUG_CONNECT
3268 MHD_DLOG (daemon, 3297 MHD_DLOG (daemon,
3269 _("Accepted connection on socket %d\n"), 3298 _ ("Accepted connection on socket %d\n"),
3270 s); 3299 s);
3271#endif 3300#endif
3272#endif 3301#endif
@@ -3298,80 +3327,80 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
3298 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 3327 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
3299#endif 3328#endif
3300 while (NULL != (pos = daemon->cleanup_tail)) 3329 while (NULL != (pos = daemon->cleanup_tail))
3301 { 3330 {
3302 DLL_remove (daemon->cleanup_head, 3331 DLL_remove (daemon->cleanup_head,
3303 daemon->cleanup_tail, 3332 daemon->cleanup_tail,
3304 pos); 3333 pos);
3305#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3334#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3306 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 3335 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
3307 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3336 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3308 (! pos->thread_joined) && 3337 (! pos->thread_joined) &&
3309 (! MHD_join_thread_ (pos->pid.handle)) ) 3338 (! MHD_join_thread_ (pos->pid.handle)) )
3310 MHD_PANIC (_("Failed to join a thread\n")); 3339 MHD_PANIC (_ ("Failed to join a thread\n"));
3311#endif 3340#endif
3312#ifdef UPGRADE_SUPPORT 3341#ifdef UPGRADE_SUPPORT
3313 cleanup_upgraded_connection (pos); 3342 cleanup_upgraded_connection (pos);
3314#endif /* UPGRADE_SUPPORT */ 3343#endif /* UPGRADE_SUPPORT */
3315 MHD_pool_destroy (pos->pool); 3344 MHD_pool_destroy (pos->pool);
3316#ifdef HTTPS_SUPPORT 3345#ifdef HTTPS_SUPPORT
3317 if (NULL != pos->tls_session) 3346 if (NULL != pos->tls_session)
3318 gnutls_deinit (pos->tls_session); 3347 gnutls_deinit (pos->tls_session);
3319#endif /* HTTPS_SUPPORT */ 3348#endif /* HTTPS_SUPPORT */
3320 3349
3321 /* clean up the connection */ 3350 /* clean up the connection */
3322 if (NULL != daemon->notify_connection) 3351 if (NULL != daemon->notify_connection)
3323 daemon->notify_connection (daemon->notify_connection_cls, 3352 daemon->notify_connection (daemon->notify_connection_cls,
3324 pos, 3353 pos,
3325 &pos->socket_context, 3354 &pos->socket_context,
3326 MHD_CONNECTION_NOTIFY_CLOSED); 3355 MHD_CONNECTION_NOTIFY_CLOSED);
3327 MHD_ip_limit_del (daemon, 3356 MHD_ip_limit_del (daemon,
3328 pos->addr, 3357 pos->addr,
3329 pos->addr_len); 3358 pos->addr_len);
3330#ifdef EPOLL_SUPPORT 3359#ifdef EPOLL_SUPPORT
3331 if (0 != (daemon->options & MHD_USE_EPOLL)) 3360 if (0 != (daemon->options & MHD_USE_EPOLL))
3332 { 3361 {
3333 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 3362 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
3334 { 3363 {
3335 EDLL_remove (daemon->eready_head, 3364 EDLL_remove (daemon->eready_head,
3336 daemon->eready_tail, 3365 daemon->eready_tail,
3337 pos); 3366 pos);
3338 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 3367 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
3339 } 3368 }
3340 if ( (-1 != daemon->epoll_fd) && 3369 if ( (-1 != daemon->epoll_fd) &&
3341 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) ) 3370 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
3342 { 3371 {
3343 /* epoll documentation suggests that closing a FD 3372 /* epoll documentation suggests that closing a FD
3344 automatically removes it from the epoll set; however, 3373 automatically removes it from the epoll set; however,
3345 this is not true as if we fail to do manually remove it, 3374 this is not true as if we fail to do manually remove it,
3346 we are still seeing an event for this fd in epoll, 3375 we are still seeing an event for this fd in epoll,
3347 causing grief (use-after-free...) --- at least on my 3376 causing grief (use-after-free...) --- at least on my
3348 system. */ 3377 system. */
3349 if (0 != epoll_ctl (daemon->epoll_fd, 3378 if (0 != epoll_ctl (daemon->epoll_fd,
3350 EPOLL_CTL_DEL, 3379 EPOLL_CTL_DEL,
3351 pos->socket_fd, 3380 pos->socket_fd,
3352 NULL)) 3381 NULL))
3353 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 3382 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
3354 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET; 3383 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
3355 } 3384 }
3356 } 3385 }
3357#endif 3386#endif
3358 if (NULL != pos->response) 3387 if (NULL != pos->response)
3359 { 3388 {
3360 MHD_destroy_response (pos->response); 3389 MHD_destroy_response (pos->response);
3361 pos->response = NULL; 3390 pos->response = NULL;
3362 } 3391 }
3363 if (MHD_INVALID_SOCKET != pos->socket_fd) 3392 if (MHD_INVALID_SOCKET != pos->socket_fd)
3364 MHD_socket_close_chk_ (pos->socket_fd); 3393 MHD_socket_close_chk_ (pos->socket_fd);
3365 if (NULL != pos->addr) 3394 if (NULL != pos->addr)
3366 free (pos->addr); 3395 free (pos->addr);
3367 free (pos); 3396 free (pos);
3368 3397
3369#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3398#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3370 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 3399 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
3371#endif 3400#endif
3372 daemon->connections--; 3401 daemon->connections--;
3373 daemon->at_limit = false; 3402 daemon->at_limit = false;
3374 } 3403 }
3375#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3404#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3376 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 3405 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
3377#endif 3406#endif
@@ -3408,71 +3437,71 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3408 bool have_timeout; 3437 bool have_timeout;
3409 3438
3410 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3439 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
3411 { 3440 {
3412#ifdef HAVE_MESSAGES 3441#ifdef HAVE_MESSAGES
3413 MHD_DLOG (daemon, 3442 MHD_DLOG (daemon,
3414 _("Illegal call to MHD_get_timeout\n")); 3443 _ ("Illegal call to MHD_get_timeout\n"));
3415#endif 3444#endif
3416 return MHD_NO; 3445 return MHD_NO;
3417 } 3446 }
3418 3447
3419 if (daemon->data_already_pending) 3448 if (daemon->data_already_pending)
3420 { 3449 {
3421 /* Some data already waiting to be processed. */ 3450 /* Some data already waiting to be processed. */
3422 *timeout = 0; 3451 *timeout = 0;
3423 return MHD_YES; 3452 return MHD_YES;
3424 } 3453 }
3425 3454
3426#ifdef EPOLL_SUPPORT 3455#ifdef EPOLL_SUPPORT
3427 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 3456 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
3428 ((NULL != daemon->eready_head) 3457 ((NULL != daemon->eready_head)
3429#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT) 3458#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
3430 || (NULL != daemon->eready_urh_head) 3459 || (NULL != daemon->eready_urh_head)
3431#endif /* UPGRADE_SUPPORT && HTTPS_SUPPORT */ 3460#endif /* UPGRADE_SUPPORT && HTTPS_SUPPORT */
3432 ) ) 3461 ) )
3433 { 3462 {
3434 /* Some connection(s) already have some data pending. */ 3463 /* Some connection(s) already have some data pending. */
3435 *timeout = 0; 3464 *timeout = 0;
3436 return MHD_YES; 3465 return MHD_YES;
3437 } 3466 }
3438#endif /* EPOLL_SUPPORT */ 3467#endif /* EPOLL_SUPPORT */
3439 3468
3440 have_timeout = false; 3469 have_timeout = false;
3441 earliest_deadline = 0; /* avoid compiler warnings */ 3470 earliest_deadline = 0; /* avoid compiler warnings */
3442 for (pos = daemon->manual_timeout_tail; NULL != pos; pos = pos->prevX) 3471 for (pos = daemon->manual_timeout_tail; NULL != pos; pos = pos->prevX)
3472 {
3473 if (0 != pos->connection_timeout)
3443 { 3474 {
3444 if (0 != pos->connection_timeout) 3475 if ( (! have_timeout) ||
3445 { 3476 (earliest_deadline - pos->last_activity > pos->connection_timeout) )
3446 if ( (! have_timeout) || 3477 earliest_deadline = pos->last_activity + pos->connection_timeout;
3447 (earliest_deadline - pos->last_activity > pos->connection_timeout) ) 3478 have_timeout = true;
3448 earliest_deadline = pos->last_activity + pos->connection_timeout;
3449 have_timeout = true;
3450 }
3451 } 3479 }
3480 }
3452 /* normal timeouts are sorted, so we only need to look at the 'tail' (oldest) */ 3481 /* normal timeouts are sorted, so we only need to look at the 'tail' (oldest) */
3453 pos = daemon->normal_timeout_tail; 3482 pos = daemon->normal_timeout_tail;
3454 if ( (NULL != pos) && 3483 if ( (NULL != pos) &&
3455 (0 != pos->connection_timeout) ) 3484 (0 != pos->connection_timeout) )
3456 { 3485 {
3457 if ( (! have_timeout) || 3486 if ( (! have_timeout) ||
3458 (earliest_deadline - pos->connection_timeout > pos->last_activity) ) 3487 (earliest_deadline - pos->connection_timeout > pos->last_activity) )
3459 earliest_deadline = pos->last_activity + pos->connection_timeout; 3488 earliest_deadline = pos->last_activity + pos->connection_timeout;
3460 have_timeout = true; 3489 have_timeout = true;
3461 } 3490 }
3462 3491
3463 if (! have_timeout) 3492 if (! have_timeout)
3464 return MHD_NO; 3493 return MHD_NO;
3465 now = MHD_monotonic_sec_counter(); 3494 now = MHD_monotonic_sec_counter ();
3466 if (earliest_deadline < now) 3495 if (earliest_deadline < now)
3467 *timeout = 0; 3496 *timeout = 0;
3468 else 3497 else
3469 { 3498 {
3470 const time_t second_left = earliest_deadline - now; 3499 const time_t second_left = earliest_deadline - now;
3471 3500
3472 if (((unsigned long long)second_left) > ULLONG_MAX / 1000) 3501 if (((unsigned long long) second_left) > ULLONG_MAX / 1000)
3473 *timeout = ULLONG_MAX; 3502 *timeout = ULLONG_MAX;
3474 else 3503 else
3475 *timeout = 1000LLU * (unsigned long long) second_left; 3504 *timeout = 1000LLU * (unsigned long long) second_left;
3476 } 3505 }
3477 return MHD_YES; 3506 return MHD_YES;
3478} 3507}
@@ -3508,7 +3537,7 @@ internal_run_from_select (struct MHD_Daemon *daemon,
3508 /* Clear ITC to avoid spinning select */ 3537 /* Clear ITC to avoid spinning select */
3509 /* Do it before any other processing so new signals 3538 /* Do it before any other processing so new signals
3510 will trigger select again and will be processed */ 3539 will trigger select again and will be processed */
3511 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 3540 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
3512 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc), 3541 (FD_ISSET (MHD_itc_r_fd_ (daemon->itc),
3513 read_fd_set)) ) 3542 read_fd_set)) )
3514 MHD_itc_clear_ (daemon->itc); 3543 MHD_itc_clear_ (daemon->itc);
@@ -3521,49 +3550,49 @@ internal_run_from_select (struct MHD_Daemon *daemon,
3521 (void) MHD_accept_connection (daemon); 3550 (void) MHD_accept_connection (daemon);
3522 3551
3523 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3552 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
3553 {
3554 /* do not have a thread per connection, process all connections now */
3555 prev = daemon->connections_tail;
3556 while (NULL != (pos = prev))
3524 { 3557 {
3525 /* do not have a thread per connection, process all connections now */ 3558 prev = pos->prev;
3526 prev = daemon->connections_tail; 3559 ds = pos->socket_fd;
3527 while (NULL != (pos = prev)) 3560 if (MHD_INVALID_SOCKET == ds)
3528 { 3561 continue;
3529 prev = pos->prev; 3562 call_handlers (pos,
3530 ds = pos->socket_fd; 3563 FD_ISSET (ds,
3531 if (MHD_INVALID_SOCKET == ds) 3564 read_fd_set),
3532 continue; 3565 FD_ISSET (ds,
3533 call_handlers (pos, 3566 write_fd_set),
3534 FD_ISSET (ds, 3567 FD_ISSET (ds,
3535 read_fd_set), 3568 except_fd_set));
3536 FD_ISSET (ds,
3537 write_fd_set),
3538 FD_ISSET (ds,
3539 except_fd_set));
3540 }
3541 } 3569 }
3570 }
3542 3571
3543#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3572#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3544 /* handle upgraded HTTPS connections */ 3573 /* handle upgraded HTTPS connections */
3545 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 3574 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
3575 {
3576 urhn = urh->prev;
3577 /* update urh state based on select() output */
3578 urh_from_fdset (urh,
3579 read_fd_set,
3580 write_fd_set,
3581 except_fd_set);
3582 /* call generic forwarding function for passing data */
3583 process_urh (urh);
3584 /* Finished forwarding? */
3585 if ( (0 == urh->in_buffer_size) &&
3586 (0 == urh->out_buffer_size) &&
3587 (0 == urh->in_buffer_used) &&
3588 (0 == urh->out_buffer_used) )
3546 { 3589 {
3547 urhn = urh->prev; 3590 MHD_connection_finish_forward_ (urh->connection);
3548 /* update urh state based on select() output */ 3591 urh->clean_ready = true;
3549 urh_from_fdset (urh, 3592 /* Resuming will move connection to cleanup list. */
3550 read_fd_set, 3593 MHD_resume_connection (urh->connection);
3551 write_fd_set,
3552 except_fd_set);
3553 /* call generic forwarding function for passing data */
3554 process_urh (urh);
3555 /* Finished forwarding? */
3556 if ( (0 == urh->in_buffer_size) &&
3557 (0 == urh->out_buffer_size) &&
3558 (0 == urh->in_buffer_used) &&
3559 (0 == urh->out_buffer_used) )
3560 {
3561 MHD_connection_finish_forward_ (urh->connection);
3562 urh->clean_ready = true;
3563 /* Resuming will move connection to cleanup list. */
3564 MHD_resume_connection(urh->connection);
3565 }
3566 } 3594 }
3595 }
3567#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 3596#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
3568 MHD_cleanup_connections (daemon); 3597 MHD_cleanup_connections (daemon);
3569 return MHD_YES; 3598 return MHD_YES;
@@ -3599,33 +3628,33 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3599 const fd_set *except_fd_set) 3628 const fd_set *except_fd_set)
3600{ 3629{
3601 fd_set es; 3630 fd_set es;
3602 if (0 != (daemon->options & 3631 if (0 != (daemon->options
3603 (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_POLL)) ) 3632 & (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_POLL)) )
3604 return MHD_NO; 3633 return MHD_NO;
3605 if (NULL == read_fd_set || NULL == write_fd_set) 3634 if ((NULL == read_fd_set)||(NULL == write_fd_set))
3606 return MHD_NO; 3635 return MHD_NO;
3607 if (NULL == except_fd_set) 3636 if (NULL == except_fd_set)
3608 { /* Workaround to maintain backward compatibility. */ 3637 { /* Workaround to maintain backward compatibility. */
3609#ifdef HAVE_MESSAGES 3638#ifdef HAVE_MESSAGES
3610 MHD_DLOG (daemon, 3639 MHD_DLOG (daemon,
3611 _("MHD_run_from_select() called with except_fd_set " 3640 _ ("MHD_run_from_select() called with except_fd_set "
3612 "set to NULL. Such behavior is deprecated.\n")); 3641 "set to NULL. Such behavior is deprecated.\n"));
3613#endif 3642#endif
3614 FD_ZERO (&es); 3643 FD_ZERO (&es);
3615 except_fd_set = &es; 3644 except_fd_set = &es;
3616 } 3645 }
3617 if (0 != (daemon->options & MHD_USE_EPOLL)) 3646 if (0 != (daemon->options & MHD_USE_EPOLL))
3618 { 3647 {
3619#ifdef EPOLL_SUPPORT 3648#ifdef EPOLL_SUPPORT
3620 int ret = MHD_epoll (daemon, 3649 int ret = MHD_epoll (daemon,
3621 MHD_NO); 3650 MHD_NO);
3622 3651
3623 MHD_cleanup_connections (daemon); 3652 MHD_cleanup_connections (daemon);
3624 return ret; 3653 return ret;
3625#else /* ! EPOLL_SUPPORT */ 3654#else /* ! EPOLL_SUPPORT */
3626 return MHD_NO; 3655 return MHD_NO;
3627#endif /* ! EPOLL_SUPPORT */ 3656#endif /* ! EPOLL_SUPPORT */
3628 } 3657 }
3629 3658
3630 /* Resuming external connections when using an extern mainloop */ 3659 /* Resuming external connections when using an extern mainloop */
3631 if (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) 3660 if (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME))
@@ -3648,7 +3677,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3648 */ 3677 */
3649static int 3678static int
3650MHD_select (struct MHD_Daemon *daemon, 3679MHD_select (struct MHD_Daemon *daemon,
3651 int may_block) 3680 int may_block)
3652{ 3681{
3653 int num_ready; 3682 int num_ready;
3654 fd_set rs; 3683 fd_set rs;
@@ -3676,71 +3705,72 @@ MHD_select (struct MHD_Daemon *daemon,
3676 may_block = MHD_NO; 3705 may_block = MHD_NO;
3677 3706
3678 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3707 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
3708 {
3709 /* single-threaded, go over everything */
3710 if (MHD_NO ==
3711 internal_get_fdset2 (daemon,
3712 &rs,
3713 &ws,
3714 &es,
3715 &maxsock,
3716 FD_SETSIZE))
3679 { 3717 {
3680 /* single-threaded, go over everything */
3681 if (MHD_NO ==
3682 internal_get_fdset2 (daemon,
3683 &rs,
3684 &ws,
3685 &es,
3686 &maxsock,
3687 FD_SETSIZE))
3688 {
3689#ifdef HAVE_MESSAGES 3718#ifdef HAVE_MESSAGES
3690 MHD_DLOG (daemon, 3719 MHD_DLOG (daemon,
3691 _("Could not obtain daemon fdsets")); 3720 _ ("Could not obtain daemon fdsets"));
3692#endif 3721#endif
3693 err_state = MHD_YES; 3722 err_state = MHD_YES;
3694 }
3695 } 3723 }
3724 }
3696 else 3725 else
3726 {
3727 /* accept only, have one thread per connection */
3728 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
3729 (! daemon->was_quiesced) &&
3730 (! MHD_add_to_fd_set_ (ls,
3731 &rs,
3732 &maxsock,
3733 FD_SETSIZE)) )
3697 { 3734 {
3698 /* accept only, have one thread per connection */
3699 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
3700 (! daemon->was_quiesced) &&
3701 (! MHD_add_to_fd_set_ (ls,
3702 &rs,
3703 &maxsock,
3704 FD_SETSIZE)) )
3705 {
3706#ifdef HAVE_MESSAGES 3735#ifdef HAVE_MESSAGES
3707 MHD_DLOG (daemon, 3736 MHD_DLOG (daemon,
3708 _("Could not add listen socket to fdset")); 3737 _ ("Could not add listen socket to fdset"));
3709#endif 3738#endif
3710 return MHD_NO; 3739 return MHD_NO;
3711 }
3712 } 3740 }
3713 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 3741 }
3742 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
3714 (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc), 3743 (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
3715 &rs, 3744 &rs,
3716 &maxsock, 3745 &maxsock,
3717 FD_SETSIZE)) ) 3746 FD_SETSIZE)) )
3718 { 3747 {
3719#if defined(MHD_WINSOCK_SOCKETS) 3748#if defined(MHD_WINSOCK_SOCKETS)
3720 /* fdset limit reached, new connections 3749 /* fdset limit reached, new connections
3721 cannot be handled. Remove listen socket FD 3750 cannot be handled. Remove listen socket FD
3722 from fdset and retry to add ITC FD. */ 3751 from fdset and retry to add ITC FD. */
3723 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) && 3752 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
3724 (! daemon->was_quiesced) ) 3753 (! daemon->was_quiesced) )
3725 { 3754 {
3726 FD_CLR (ls, 3755 FD_CLR (ls,
3727 &rs); 3756 &rs);
3728 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_(daemon->itc), 3757 if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc),
3729 &rs, 3758 &rs,
3730 &maxsock, 3759 &maxsock,
3731 FD_SETSIZE)) 3760 FD_SETSIZE))
3732 { 3761 {
3733#endif /* MHD_WINSOCK_SOCKETS */ 3762#endif /* MHD_WINSOCK_SOCKETS */
3734#ifdef HAVE_MESSAGES 3763#ifdef HAVE_MESSAGES
3735 MHD_DLOG (daemon, 3764 MHD_DLOG (daemon,
3736 _("Could not add control inter-thread communication channel FD to fdset")); 3765 _ (
3766 "Could not add control inter-thread communication channel FD to fdset"));
3737#endif 3767#endif
3738 err_state = MHD_YES; 3768 err_state = MHD_YES;
3739#if defined(MHD_WINSOCK_SOCKETS) 3769#if defined(MHD_WINSOCK_SOCKETS)
3740 } 3770 }
3741 } 3771}
3742#endif /* MHD_WINSOCK_SOCKETS */ 3772#endif /* MHD_WINSOCK_SOCKETS */
3743 } 3773 }
3744 /* Stop listening if we are at the configured connection limit */ 3774 /* Stop listening if we are at the configured connection limit */
3745 /* If we're at the connection limit, no point in really 3775 /* If we're at the connection limit, no point in really
3746 accepting new connections; however, make sure we do not miss 3776 accepting new connections; however, make sure we do not miss
@@ -3748,33 +3778,33 @@ MHD_select (struct MHD_Daemon *daemon,
3748 only do this optimization if we have a signaling ITC in 3778 only do this optimization if we have a signaling ITC in
3749 place. */ 3779 place. */
3750 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) && 3780 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
3751 (MHD_ITC_IS_VALID_(daemon->itc)) && 3781 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
3752 ( (daemon->connections == daemon->connection_limit) || 3782 ( (daemon->connections == daemon->connection_limit) ||
3753 (daemon->at_limit) ) ) 3783 (daemon->at_limit) ) )
3754 { 3784 {
3755 FD_CLR (ls, 3785 FD_CLR (ls,
3756 &rs); 3786 &rs);
3757 } 3787 }
3758 tv = NULL; 3788 tv = NULL;
3759 if (MHD_YES == err_state) 3789 if (MHD_YES == err_state)
3760 may_block = MHD_NO; 3790 may_block = MHD_NO;
3761 if (MHD_NO == may_block) 3791 if (MHD_NO == may_block)
3762 { 3792 {
3763 timeout.tv_usec = 0; 3793 timeout.tv_usec = 0;
3764 timeout.tv_sec = 0; 3794 timeout.tv_sec = 0;
3765 tv = &timeout; 3795 tv = &timeout;
3766 } 3796 }
3767 else if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3797 else if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3768 (MHD_YES == MHD_get_timeout (daemon, &ltimeout)) ) 3798 (MHD_YES == MHD_get_timeout (daemon, &ltimeout)) )
3769 { 3799 {
3770 /* ltimeout is in ms */ 3800 /* ltimeout is in ms */
3771 timeout.tv_usec = (ltimeout % 1000) * 1000; 3801 timeout.tv_usec = (ltimeout % 1000) * 1000;
3772 if (ltimeout / 1000 > TIMEVAL_TV_SEC_MAX) 3802 if (ltimeout / 1000 > TIMEVAL_TV_SEC_MAX)
3773 timeout.tv_sec = TIMEVAL_TV_SEC_MAX; 3803 timeout.tv_sec = TIMEVAL_TV_SEC_MAX;
3774 else 3804 else
3775 timeout.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE)(ltimeout / 1000); 3805 timeout.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) (ltimeout / 1000);
3776 tv = &timeout; 3806 tv = &timeout;
3777 } 3807 }
3778 num_ready = MHD_SYS_select_ (maxsock + 1, 3808 num_ready = MHD_SYS_select_ (maxsock + 1,
3779 &rs, 3809 &rs,
3780 &ws, 3810 &ws,
@@ -3783,17 +3813,17 @@ MHD_select (struct MHD_Daemon *daemon,
3783 if (daemon->shutdown) 3813 if (daemon->shutdown)
3784 return MHD_NO; 3814 return MHD_NO;
3785 if (num_ready < 0) 3815 if (num_ready < 0)
3786 { 3816 {
3787 const int err = MHD_socket_get_error_ (); 3817 const int err = MHD_socket_get_error_ ();
3788 if (MHD_SCKT_ERR_IS_EINTR_(err)) 3818 if (MHD_SCKT_ERR_IS_EINTR_ (err))
3789 return (MHD_NO == err_state) ? MHD_YES : MHD_NO; 3819 return (MHD_NO == err_state) ? MHD_YES : MHD_NO;
3790#ifdef HAVE_MESSAGES 3820#ifdef HAVE_MESSAGES
3791 MHD_DLOG (daemon, 3821 MHD_DLOG (daemon,
3792 _("select failed: %s\n"), 3822 _ ("select failed: %s\n"),
3793 MHD_socket_strerr_ (err)); 3823 MHD_socket_strerr_ (err));
3794#endif 3824#endif
3795 return MHD_NO; 3825 return MHD_NO;
3796 } 3826 }
3797 if (MHD_YES == internal_run_from_select (daemon, 3827 if (MHD_YES == internal_run_from_select (daemon,
3798 &rs, 3828 &rs,
3799 &ws, 3829 &ws,
@@ -3814,7 +3844,7 @@ MHD_select (struct MHD_Daemon *daemon,
3814 */ 3844 */
3815static int 3845static int
3816MHD_poll_all (struct MHD_Daemon *daemon, 3846MHD_poll_all (struct MHD_Daemon *daemon,
3817 int may_block) 3847 int may_block)
3818{ 3848{
3819 unsigned int num_connections; 3849 unsigned int num_connections;
3820 struct MHD_Connection *pos; 3850 struct MHD_Connection *pos;
@@ -3846,44 +3876,44 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3846 struct pollfd *p; 3876 struct pollfd *p;
3847 MHD_socket ls; 3877 MHD_socket ls;
3848 3878
3849 p = MHD_calloc_ ((2 + (size_t)num_connections), 3879 p = MHD_calloc_ ((2 + (size_t) num_connections),
3850 sizeof (struct pollfd)); 3880 sizeof (struct pollfd));
3851 if (NULL == p) 3881 if (NULL == p)
3852 { 3882 {
3853#ifdef HAVE_MESSAGES 3883#ifdef HAVE_MESSAGES
3854 MHD_DLOG (daemon, 3884 MHD_DLOG (daemon,
3855 _("Error allocating memory: %s\n"), 3885 _ ("Error allocating memory: %s\n"),
3856 MHD_strerror_(errno)); 3886 MHD_strerror_ (errno));
3857#endif 3887#endif
3858 return MHD_NO; 3888 return MHD_NO;
3859 } 3889 }
3860 poll_server = 0; 3890 poll_server = 0;
3861 poll_listen = -1; 3891 poll_listen = -1;
3862 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) && 3892 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
3863 (! daemon->was_quiesced) && 3893 (! daemon->was_quiesced) &&
3864 (daemon->connections < daemon->connection_limit) && 3894 (daemon->connections < daemon->connection_limit) &&
3865 (! daemon->at_limit) ) 3895 (! daemon->at_limit) )
3866 { 3896 {
3867 /* only listen if we are not at the connection limit */ 3897 /* only listen if we are not at the connection limit */
3868 p[poll_server].fd = ls; 3898 p[poll_server].fd = ls;
3869 p[poll_server].events = POLLIN; 3899 p[poll_server].events = POLLIN;
3870 p[poll_server].revents = 0; 3900 p[poll_server].revents = 0;
3871 poll_listen = (int) poll_server; 3901 poll_listen = (int) poll_server;
3872 poll_server++; 3902 poll_server++;
3873 } 3903 }
3874 poll_itc_idx = -1; 3904 poll_itc_idx = -1;
3875 if (MHD_ITC_IS_VALID_(daemon->itc)) 3905 if (MHD_ITC_IS_VALID_ (daemon->itc))
3876 { 3906 {
3877 p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc); 3907 p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc);
3878 p[poll_server].events = POLLIN; 3908 p[poll_server].events = POLLIN;
3879 p[poll_server].revents = 0; 3909 p[poll_server].revents = 0;
3880 poll_itc_idx = (int) poll_server; 3910 poll_itc_idx = (int) poll_server;
3881 poll_server++; 3911 poll_server++;
3882 } 3912 }
3883 if (may_block == MHD_NO) 3913 if (may_block == MHD_NO)
3884 timeout = 0; 3914 timeout = 0;
3885 else if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || 3915 else if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
3886 (MHD_YES != MHD_get_timeout (daemon, 3916 (MHD_YES != MHD_get_timeout (daemon,
3887 &ltimeout)) ) 3917 &ltimeout)) )
3888 timeout = -1; 3918 timeout = -1;
3889 else 3919 else
@@ -3891,55 +3921,55 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3891 3921
3892 i = 0; 3922 i = 0;
3893 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) 3923 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
3924 {
3925 p[poll_server + i].fd = pos->socket_fd;
3926 switch (pos->event_loop_info)
3894 { 3927 {
3895 p[poll_server+i].fd = pos->socket_fd; 3928 case MHD_EVENT_LOOP_INFO_READ:
3896 switch (pos->event_loop_info) 3929 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
3897 { 3930 break;
3898 case MHD_EVENT_LOOP_INFO_READ: 3931 case MHD_EVENT_LOOP_INFO_WRITE:
3899 p[poll_server+i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; 3932 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
3900 break; 3933 break;
3901 case MHD_EVENT_LOOP_INFO_WRITE: 3934 case MHD_EVENT_LOOP_INFO_BLOCK:
3902 p[poll_server+i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; 3935 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
3903 break; 3936 break;
3904 case MHD_EVENT_LOOP_INFO_BLOCK: 3937 case MHD_EVENT_LOOP_INFO_CLEANUP:
3905 p[poll_server+i].events |= MHD_POLL_EVENTS_ERR_DISC; 3938 timeout = 0; /* clean up "pos" immediately */
3906 break; 3939 break;
3907 case MHD_EVENT_LOOP_INFO_CLEANUP:
3908 timeout = 0; /* clean up "pos" immediately */
3909 break;
3910 }
3911 i++;
3912 } 3940 }
3941 i++;
3942 }
3913#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3943#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3914 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) 3944 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
3915 { 3945 {
3916 urh_to_pollfd(urh, &(p[poll_server+i])); 3946 urh_to_pollfd (urh, &(p[poll_server + i]));
3917 i += 2; 3947 i += 2;
3918 } 3948 }
3919#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 3949#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
3920 if (0 == poll_server + num_connections) 3950 if (0 == poll_server + num_connections)
3951 {
3952 free (p);
3953 return MHD_YES;
3954 }
3955 if (MHD_sys_poll_ (p,
3956 poll_server + num_connections,
3957 timeout) < 0)
3958 {
3959 const int err = MHD_socket_get_error_ ();
3960 if (MHD_SCKT_ERR_IS_EINTR_ (err))
3921 { 3961 {
3922 free(p); 3962 free (p);
3923 return MHD_YES;
3924 }
3925 if (MHD_sys_poll_(p,
3926 poll_server + num_connections,
3927 timeout) < 0)
3928 {
3929 const int err = MHD_socket_get_error_ ();
3930 if (MHD_SCKT_ERR_IS_EINTR_ (err))
3931 {
3932 free(p);
3933 return MHD_YES; 3963 return MHD_YES;
3934 } 3964 }
3935#ifdef HAVE_MESSAGES 3965#ifdef HAVE_MESSAGES
3936 MHD_DLOG (daemon, 3966 MHD_DLOG (daemon,
3937 _("poll failed: %s\n"), 3967 _ ("poll failed: %s\n"),
3938 MHD_socket_strerr_ (err)); 3968 MHD_socket_strerr_ (err));
3939#endif 3969#endif
3940 free(p); 3970 free (p);
3941 return MHD_NO; 3971 return MHD_NO;
3942 } 3972 }
3943 3973
3944 /* Reset. New value will be set when connections are processed. */ 3974 /* Reset. New value will be set when connections are processed. */
3945 daemon->data_already_pending = false; 3975 daemon->data_already_pending = false;
@@ -3953,67 +3983,68 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3953 3983
3954 /* handle shutdown */ 3984 /* handle shutdown */
3955 if (daemon->shutdown) 3985 if (daemon->shutdown)
3956 { 3986 {
3957 free(p); 3987 free (p);
3958 return MHD_NO; 3988 return MHD_NO;
3959 } 3989 }
3960 i = 0; 3990 i = 0;
3961 prev = daemon->connections_tail; 3991 prev = daemon->connections_tail;
3962 while (NULL != (pos = prev)) 3992 while (NULL != (pos = prev))
3963 { 3993 {
3964 prev = pos->prev; 3994 prev = pos->prev;
3965 /* first, sanity checks */ 3995 /* first, sanity checks */
3966 if (i >= num_connections) 3996 if (i >= num_connections)
3967 break; /* connection list changed somehow, retry later ... */ 3997 break; /* connection list changed somehow, retry later ... */
3968 if (p[poll_server+i].fd != pos->socket_fd) 3998 if (p[poll_server + i].fd != pos->socket_fd)
3969 continue; /* fd mismatch, something else happened, retry later ... */ 3999 continue; /* fd mismatch, something else happened, retry later ... */
3970 call_handlers (pos, 4000 call_handlers (pos,
3971 0 != (p[poll_server+i].revents & POLLIN), 4001 0 != (p[poll_server + i].revents & POLLIN),
3972 0 != (p[poll_server+i].revents & POLLOUT), 4002 0 != (p[poll_server + i].revents & POLLOUT),
3973 0 != (p[poll_server+i].revents & MHD_POLL_REVENTS_ERR_DISC)); 4003 0 != (p[poll_server + i].revents
3974 i++; 4004 & MHD_POLL_REVENTS_ERR_DISC));
3975 } 4005 i++;
4006 }
3976#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4007#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3977 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 4008 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
4009 {
4010 if (i >= num_connections)
4011 break; /* connection list changed somehow, retry later ... */
4012
4013 /* Get next connection here as connection can be removed
4014 * from 'daemon->urh_head' list. */
4015 urhn = urh->prev;
4016 /* Check for fd mismatch. FIXME: required for safety? */
4017 if ((p[poll_server + i].fd != urh->connection->socket_fd) ||
4018 (p[poll_server + i + 1].fd != urh->mhd.socket))
4019 break;
4020 urh_from_pollfd (urh,
4021 &p[poll_server + i]);
4022 i += 2;
4023 process_urh (urh);
4024 /* Finished forwarding? */
4025 if ( (0 == urh->in_buffer_size) &&
4026 (0 == urh->out_buffer_size) &&
4027 (0 == urh->in_buffer_used) &&
4028 (0 == urh->out_buffer_used) )
3978 { 4029 {
3979 if (i >= num_connections) 4030 /* MHD_connection_finish_forward_() will remove connection from
3980 break; /* connection list changed somehow, retry later ... */ 4031 * 'daemon->urh_head' list. */
3981 4032 MHD_connection_finish_forward_ (urh->connection);
3982 /* Get next connection here as connection can be removed 4033 urh->clean_ready = true;
3983 * from 'daemon->urh_head' list. */ 4034 /* If 'urh->was_closed' already was set to true, connection will be
3984 urhn = urh->prev; 4035 * moved immediately to cleanup list. Otherwise connection
3985 /* Check for fd mismatch. FIXME: required for safety? */ 4036 * will stay in suspended list until 'urh' will be marked
3986 if ((p[poll_server+i].fd != urh->connection->socket_fd) || 4037 * with 'was_closed' by application. */
3987 (p[poll_server+i+1].fd != urh->mhd.socket)) 4038 MHD_resume_connection (urh->connection);
3988 break;
3989 urh_from_pollfd (urh,
3990 &p[poll_server+i]);
3991 i += 2;
3992 process_urh (urh);
3993 /* Finished forwarding? */
3994 if ( (0 == urh->in_buffer_size) &&
3995 (0 == urh->out_buffer_size) &&
3996 (0 == urh->in_buffer_used) &&
3997 (0 == urh->out_buffer_used) )
3998 {
3999 /* MHD_connection_finish_forward_() will remove connection from
4000 * 'daemon->urh_head' list. */
4001 MHD_connection_finish_forward_ (urh->connection);
4002 urh->clean_ready = true;
4003 /* If 'urh->was_closed' already was set to true, connection will be
4004 * moved immediately to cleanup list. Otherwise connection
4005 * will stay in suspended list until 'urh' will be marked
4006 * with 'was_closed' by application. */
4007 MHD_resume_connection(urh->connection);
4008 }
4009 } 4039 }
4040 }
4010#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 4041#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
4011 /* handle 'listen' FD */ 4042 /* handle 'listen' FD */
4012 if ( (-1 != poll_listen) && 4043 if ( (-1 != poll_listen) &&
4013 (0 != (p[poll_listen].revents & POLLIN)) ) 4044 (0 != (p[poll_listen].revents & POLLIN)) )
4014 (void) MHD_accept_connection (daemon); 4045 (void) MHD_accept_connection (daemon);
4015 4046
4016 free(p); 4047 free (p);
4017 } 4048 }
4018 return MHD_YES; 4049 return MHD_YES;
4019} 4050}
@@ -4028,7 +4059,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
4028 */ 4059 */
4029static int 4060static int
4030MHD_poll_listen_socket (struct MHD_Daemon *daemon, 4061MHD_poll_listen_socket (struct MHD_Daemon *daemon,
4031 int may_block) 4062 int may_block)
4032{ 4063{
4033 struct pollfd p[2]; 4064 struct pollfd p[2];
4034 int timeout; 4065 int timeout;
@@ -4046,21 +4077,21 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
4046 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) && 4077 if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) &&
4047 (! daemon->was_quiesced) ) 4078 (! daemon->was_quiesced) )
4048 4079
4049 { 4080 {
4050 p[poll_count].fd = ls; 4081 p[poll_count].fd = ls;
4051 p[poll_count].events = POLLIN; 4082 p[poll_count].events = POLLIN;
4052 p[poll_count].revents = 0; 4083 p[poll_count].revents = 0;
4053 poll_listen = poll_count; 4084 poll_listen = poll_count;
4054 poll_count++; 4085 poll_count++;
4055 } 4086 }
4056 if (MHD_ITC_IS_VALID_(daemon->itc)) 4087 if (MHD_ITC_IS_VALID_ (daemon->itc))
4057 { 4088 {
4058 p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc); 4089 p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc);
4059 p[poll_count].events = POLLIN; 4090 p[poll_count].events = POLLIN;
4060 p[poll_count].revents = 0; 4091 p[poll_count].revents = 0;
4061 poll_itc_idx = poll_count; 4092 poll_itc_idx = poll_count;
4062 poll_count++; 4093 poll_count++;
4063 } 4094 }
4064 4095
4065 if (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) 4096 if (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME))
4066 (void) resume_suspended_connections (daemon); 4097 (void) resume_suspended_connections (daemon);
@@ -4071,21 +4102,21 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
4071 timeout = -1; 4102 timeout = -1;
4072 if (0 == poll_count) 4103 if (0 == poll_count)
4073 return MHD_YES; 4104 return MHD_YES;
4074 if (MHD_sys_poll_(p, 4105 if (MHD_sys_poll_ (p,
4075 poll_count, 4106 poll_count,
4076 timeout) < 0) 4107 timeout) < 0)
4077 { 4108 {
4078 const int err = MHD_socket_get_error_ (); 4109 const int err = MHD_socket_get_error_ ();
4079 4110
4080 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 4111 if (MHD_SCKT_ERR_IS_EINTR_ (err))
4081 return MHD_YES; 4112 return MHD_YES;
4082#ifdef HAVE_MESSAGES 4113#ifdef HAVE_MESSAGES
4083 MHD_DLOG (daemon, 4114 MHD_DLOG (daemon,
4084 _("poll failed: %s\n"), 4115 _ ("poll failed: %s\n"),
4085 MHD_socket_strerr_ (err)); 4116 MHD_socket_strerr_ (err));
4086#endif 4117#endif
4087 return MHD_NO; 4118 return MHD_NO;
4088 } 4119 }
4089 if ( (-1 != poll_itc_idx) && 4120 if ( (-1 != poll_itc_idx) &&
4090 (0 != (p[poll_itc_idx].revents & POLLIN)) ) 4121 (0 != (p[poll_itc_idx].revents & POLLIN)) )
4091 MHD_itc_clear_ (daemon->itc); 4122 MHD_itc_clear_ (daemon->itc);
@@ -4110,7 +4141,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
4110 */ 4141 */
4111static int 4142static int
4112MHD_poll (struct MHD_Daemon *daemon, 4143MHD_poll (struct MHD_Daemon *daemon,
4113 int may_block) 4144 int may_block)
4114{ 4145{
4115#ifdef HAVE_POLL 4146#ifdef HAVE_POLL
4116 if (daemon->shutdown) 4147 if (daemon->shutdown)
@@ -4151,9 +4182,9 @@ MHD_poll (struct MHD_Daemon *daemon,
4151 * 'false' otherwise 4182 * 'false' otherwise
4152 */ 4183 */
4153static bool 4184static bool
4154is_urh_ready(struct MHD_UpgradeResponseHandle * const urh) 4185is_urh_ready (struct MHD_UpgradeResponseHandle *const urh)
4155{ 4186{
4156 const struct MHD_Connection * const connection = urh->connection; 4187 const struct MHD_Connection *const connection = urh->connection;
4157 4188
4158 if ( (0 == urh->in_buffer_size) && 4189 if ( (0 == urh->in_buffer_size) &&
4159 (0 == urh->out_buffer_size) && 4190 (0 == urh->out_buffer_size) &&
@@ -4173,7 +4204,7 @@ is_urh_ready(struct MHD_UpgradeResponseHandle * const urh)
4173 (urh->out_buffer_used > 0) ) 4204 (urh->out_buffer_used > 0) )
4174 return true; 4205 return true;
4175 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) && 4206 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->mhd.celi)) &&
4176 (urh->in_buffer_used > 0) ) 4207 (urh->in_buffer_used > 0) )
4177 return true; 4208 return true;
4178 return false; 4209 return false;
4179} 4210}
@@ -4192,98 +4223,98 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
4192{ 4223{
4193 struct epoll_event events[MAX_EVENTS]; 4224 struct epoll_event events[MAX_EVENTS];
4194 int num_events; 4225 int num_events;
4195 struct MHD_UpgradeResponseHandle * pos; 4226 struct MHD_UpgradeResponseHandle *pos;
4196 struct MHD_UpgradeResponseHandle * prev; 4227 struct MHD_UpgradeResponseHandle *prev;
4197 4228
4198 num_events = MAX_EVENTS; 4229 num_events = MAX_EVENTS;
4199 while (0 != num_events) 4230 while (0 != num_events)
4231 {
4232 unsigned int i;
4233 /* update event masks */
4234 num_events = epoll_wait (daemon->epoll_upgrade_fd,
4235 events,
4236 MAX_EVENTS,
4237 0);
4238 if (-1 == num_events)
4200 { 4239 {
4201 unsigned int i; 4240 const int err = MHD_socket_get_error_ ();
4202 /* update event masks */
4203 num_events = epoll_wait (daemon->epoll_upgrade_fd,
4204 events,
4205 MAX_EVENTS,
4206 0);
4207 if (-1 == num_events)
4208 {
4209 const int err = MHD_socket_get_error_ ();
4210 4241
4211 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 4242 if (MHD_SCKT_ERR_IS_EINTR_ (err))
4212 return MHD_YES; 4243 return MHD_YES;
4213#ifdef HAVE_MESSAGES 4244#ifdef HAVE_MESSAGES
4214 MHD_DLOG (daemon, 4245 MHD_DLOG (daemon,
4215 _("Call to epoll_wait failed: %s\n"), 4246 _ ("Call to epoll_wait failed: %s\n"),
4216 MHD_socket_strerr_ (err)); 4247 MHD_socket_strerr_ (err));
4217#endif 4248#endif
4218 return MHD_NO; 4249 return MHD_NO;
4219 } 4250 }
4220 for (i = 0; i < (unsigned int) num_events; i++) 4251 for (i = 0; i < (unsigned int) num_events; i++)
4221 { 4252 {
4222 struct UpgradeEpollHandle * const ueh = events[i].data.ptr; 4253 struct UpgradeEpollHandle *const ueh = events[i].data.ptr;
4223 struct MHD_UpgradeResponseHandle * const urh = ueh->urh; 4254 struct MHD_UpgradeResponseHandle *const urh = ueh->urh;
4224 bool new_err_state = false; 4255 bool new_err_state = false;
4225 4256
4226 if (urh->clean_ready) 4257 if (urh->clean_ready)
4227 continue; 4258 continue;
4259
4260 /* Update ueh state based on what is ready according to epoll() */
4261 if (0 != (events[i].events & EPOLLIN))
4262 ueh->celi |= MHD_EPOLL_STATE_READ_READY;
4263 if (0 != (events[i].events & EPOLLOUT))
4264 ueh->celi |= MHD_EPOLL_STATE_WRITE_READY;
4265 if (0 != (events[i].events & EPOLLHUP))
4266 ueh->celi |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY;
4228 4267
4229 /* Update ueh state based on what is ready according to epoll() */ 4268 if ( (0 == (ueh->celi & MHD_EPOLL_STATE_ERROR)) &&
4230 if (0 != (events[i].events & EPOLLIN)) 4269 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
4231 ueh->celi |= MHD_EPOLL_STATE_READ_READY; 4270 {
4232 if (0 != (events[i].events & EPOLLOUT)) 4271 /* Process new error state only one time
4233 ueh->celi |= MHD_EPOLL_STATE_WRITE_READY; 4272 * and avoid continuously marking this connection
4234 if (0 != (events[i].events & EPOLLHUP)) 4273 * as 'ready'. */
4235 ueh->celi |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY; 4274 ueh->celi |= MHD_EPOLL_STATE_ERROR;
4236 4275 new_err_state = true;
4237 if ( (0 == (ueh->celi & MHD_EPOLL_STATE_ERROR)) && 4276 }
4238 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) ) 4277
4239 { 4278 if (! urh->in_eready_list)
4240 /* Process new error state only one time 4279 {
4241 * and avoid continuously marking this connection 4280 if (new_err_state ||
4242 * as 'ready'. */ 4281 is_urh_ready (urh))
4243 ueh->celi |= MHD_EPOLL_STATE_ERROR; 4282 {
4244 new_err_state = true; 4283 EDLL_insert (daemon->eready_urh_head,
4245 } 4284 daemon->eready_urh_tail,
4246 4285 urh);
4247 if (! urh->in_eready_list) 4286 urh->in_eready_list = true;
4248 {
4249 if (new_err_state ||
4250 is_urh_ready(urh))
4251 {
4252 EDLL_insert (daemon->eready_urh_head,
4253 daemon->eready_urh_tail,
4254 urh);
4255 urh->in_eready_list = true;
4256 }
4257 }
4258 } 4287 }
4288 }
4259 } 4289 }
4290 }
4260 prev = daemon->eready_urh_tail; 4291 prev = daemon->eready_urh_tail;
4261 while (NULL != (pos = prev)) 4292 while (NULL != (pos = prev))
4262 { 4293 {
4263 prev = pos->prevE; 4294 prev = pos->prevE;
4264 process_urh (pos); 4295 process_urh (pos);
4265 if (! is_urh_ready(pos)) 4296 if (! is_urh_ready (pos))
4266 { 4297 {
4267 EDLL_remove (daemon->eready_urh_head, 4298 EDLL_remove (daemon->eready_urh_head,
4268 daemon->eready_urh_tail, 4299 daemon->eready_urh_tail,
4269 pos); 4300 pos);
4270 pos->in_eready_list = false; 4301 pos->in_eready_list = false;
4271 } 4302 }
4272 /* Finished forwarding? */ 4303 /* Finished forwarding? */
4273 if ( (0 == pos->in_buffer_size) && 4304 if ( (0 == pos->in_buffer_size) &&
4274 (0 == pos->out_buffer_size) && 4305 (0 == pos->out_buffer_size) &&
4275 (0 == pos->in_buffer_used) && 4306 (0 == pos->in_buffer_used) &&
4276 (0 == pos->out_buffer_used) ) 4307 (0 == pos->out_buffer_used) )
4277 { 4308 {
4278 MHD_connection_finish_forward_ (pos->connection); 4309 MHD_connection_finish_forward_ (pos->connection);
4279 pos->clean_ready = true; 4310 pos->clean_ready = true;
4280 /* If 'pos->was_closed' already was set to true, connection 4311 /* If 'pos->was_closed' already was set to true, connection
4281 * will be moved immediately to cleanup list. Otherwise 4312 * will be moved immediately to cleanup list. Otherwise
4282 * connection will stay in suspended list until 'pos' will 4313 * connection will stay in suspended list until 'pos' will
4283 * be marked with 'was_closed' by application. */ 4314 * be marked with 'was_closed' by application. */
4284 MHD_resume_connection (pos->connection); 4315 MHD_resume_connection (pos->connection);
4285 }
4286 } 4316 }
4317 }
4287 4318
4288 return MHD_YES; 4319 return MHD_YES;
4289} 4320}
@@ -4293,7 +4324,7 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
4293/** 4324/**
4294 * Pointer-marker to distinguish ITC slot in epoll sets. 4325 * Pointer-marker to distinguish ITC slot in epoll sets.
4295 */ 4326 */
4296static const char * const epoll_itc_marker = "itc_marker"; 4327static const char *const epoll_itc_marker = "itc_marker";
4297 4328
4298 4329
4299/** 4330/**
@@ -4309,7 +4340,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
4309 int may_block) 4340 int may_block)
4310{ 4341{
4311#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4342#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4312 static const char * const upgrade_marker = "upgrade_ptr"; 4343 static const char *const upgrade_marker = "upgrade_ptr";
4313#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 4344#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
4314 struct MHD_Connection *pos; 4345 struct MHD_Connection *pos;
4315 struct MHD_Connection *prev; 4346 struct MHD_Connection *prev;
@@ -4333,89 +4364,89 @@ MHD_epoll (struct MHD_Daemon *daemon,
4333 (daemon->connections < daemon->connection_limit) && 4364 (daemon->connections < daemon->connection_limit) &&
4334 (! daemon->listen_socket_in_epoll) && 4365 (! daemon->listen_socket_in_epoll) &&
4335 (! daemon->at_limit) ) 4366 (! daemon->at_limit) )
4367 {
4368 event.events = EPOLLIN;
4369 event.data.ptr = daemon;
4370 if (0 != epoll_ctl (daemon->epoll_fd,
4371 EPOLL_CTL_ADD,
4372 ls,
4373 &event))
4336 { 4374 {
4337 event.events = EPOLLIN;
4338 event.data.ptr = daemon;
4339 if (0 != epoll_ctl (daemon->epoll_fd,
4340 EPOLL_CTL_ADD,
4341 ls,
4342 &event))
4343 {
4344#ifdef HAVE_MESSAGES 4375#ifdef HAVE_MESSAGES
4345 MHD_DLOG (daemon, 4376 MHD_DLOG (daemon,
4346 _("Call to epoll_ctl failed: %s\n"), 4377 _ ("Call to epoll_ctl failed: %s\n"),
4347 MHD_socket_last_strerr_ ()); 4378 MHD_socket_last_strerr_ ());
4348#endif 4379#endif
4349 return MHD_NO; 4380 return MHD_NO;
4350 }
4351 daemon->listen_socket_in_epoll = true;
4352 } 4381 }
4382 daemon->listen_socket_in_epoll = true;
4383 }
4353 if ( (daemon->was_quiesced) && 4384 if ( (daemon->was_quiesced) &&
4354 (daemon->listen_socket_in_epoll) ) 4385 (daemon->listen_socket_in_epoll) )
4355 { 4386 {
4356 if ( (0 != epoll_ctl (daemon->epoll_fd, 4387 if ( (0 != epoll_ctl (daemon->epoll_fd,
4357 EPOLL_CTL_DEL, 4388 EPOLL_CTL_DEL,
4358 ls, 4389 ls,
4359 NULL)) && 4390 NULL)) &&
4360 (ENOENT != errno) ) /* ENOENT can happen due to race with 4391 (ENOENT != errno) ) /* ENOENT can happen due to race with
4361 #MHD_quiesce_daemon() */ 4392 #MHD_quiesce_daemon() */
4362 MHD_PANIC ("Failed to remove listen FD from epoll set\n"); 4393 MHD_PANIC ("Failed to remove listen FD from epoll set\n");
4363 daemon->listen_socket_in_epoll = false; 4394 daemon->listen_socket_in_epoll = false;
4364 } 4395 }
4365 4396
4366#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4397#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4367 if ( ( (! daemon->upgrade_fd_in_epoll) && 4398 if ( ( (! daemon->upgrade_fd_in_epoll) &&
4368 (-1 != daemon->epoll_upgrade_fd) ) ) 4399 (-1 != daemon->epoll_upgrade_fd) ) )
4400 {
4401 event.events = EPOLLIN | EPOLLOUT;
4402 event.data.ptr = (void *) upgrade_marker;
4403 if (0 != epoll_ctl (daemon->epoll_fd,
4404 EPOLL_CTL_ADD,
4405 daemon->epoll_upgrade_fd,
4406 &event))
4369 { 4407 {
4370 event.events = EPOLLIN | EPOLLOUT;
4371 event.data.ptr = (void *) upgrade_marker;
4372 if (0 != epoll_ctl (daemon->epoll_fd,
4373 EPOLL_CTL_ADD,
4374 daemon->epoll_upgrade_fd,
4375 &event))
4376 {
4377#ifdef HAVE_MESSAGES 4408#ifdef HAVE_MESSAGES
4378 MHD_DLOG (daemon, 4409 MHD_DLOG (daemon,
4379 _("Call to epoll_ctl failed: %s\n"), 4410 _ ("Call to epoll_ctl failed: %s\n"),
4380 MHD_socket_last_strerr_ ()); 4411 MHD_socket_last_strerr_ ());
4381#endif 4412#endif
4382 return MHD_NO; 4413 return MHD_NO;
4383 }
4384 daemon->upgrade_fd_in_epoll = true;
4385 } 4414 }
4415 daemon->upgrade_fd_in_epoll = true;
4416 }
4386#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 4417#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
4387 if ( (daemon->listen_socket_in_epoll) && 4418 if ( (daemon->listen_socket_in_epoll) &&
4388 ( (daemon->connections == daemon->connection_limit) || 4419 ( (daemon->connections == daemon->connection_limit) ||
4389 (daemon->at_limit) || 4420 (daemon->at_limit) ||
4390 (daemon->was_quiesced) ) ) 4421 (daemon->was_quiesced) ) )
4391 { 4422 {
4392 /* we're at the connection limit, disable listen socket 4423 /* we're at the connection limit, disable listen socket
4393 for event loop for now */ 4424 for event loop for now */
4394 if (0 != epoll_ctl (daemon->epoll_fd, 4425 if (0 != epoll_ctl (daemon->epoll_fd,
4395 EPOLL_CTL_DEL, 4426 EPOLL_CTL_DEL,
4396 ls, 4427 ls,
4397 NULL)) 4428 NULL))
4398 MHD_PANIC (_("Failed to remove listen FD from epoll set\n")); 4429 MHD_PANIC (_ ("Failed to remove listen FD from epoll set\n"));
4399 daemon->listen_socket_in_epoll = false; 4430 daemon->listen_socket_in_epoll = false;
4400 } 4431 }
4401 4432
4402 if ( (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) && 4433 if ( (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) &&
4403 (MHD_YES == resume_suspended_connections (daemon)) ) 4434 (MHD_YES == resume_suspended_connections (daemon)) )
4404 may_block = MHD_NO; 4435 may_block = MHD_NO;
4405 4436
4406 if (MHD_YES == may_block) 4437 if (MHD_YES == may_block)
4438 {
4439 if (MHD_YES == MHD_get_timeout (daemon,
4440 &timeout_ll))
4407 { 4441 {
4408 if (MHD_YES == MHD_get_timeout (daemon, 4442 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX)
4409 &timeout_ll)) 4443 timeout_ms = INT_MAX;
4410 {
4411 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX)
4412 timeout_ms = INT_MAX;
4413 else
4414 timeout_ms = (int) timeout_ll;
4415 }
4416 else 4444 else
4417 timeout_ms = -1; 4445 timeout_ms = (int) timeout_ll;
4418 } 4446 }
4447 else
4448 timeout_ms = -1;
4449 }
4419 else 4450 else
4420 timeout_ms = 0; 4451 timeout_ms = 0;
4421 4452
@@ -4430,111 +4461,111 @@ MHD_epoll (struct MHD_Daemon *daemon,
4430 than unfair behavior... */ 4461 than unfair behavior... */
4431 num_events = MAX_EVENTS; 4462 num_events = MAX_EVENTS;
4432 while (MAX_EVENTS == num_events) 4463 while (MAX_EVENTS == num_events)
4464 {
4465 /* update event masks */
4466 num_events = epoll_wait (daemon->epoll_fd,
4467 events,
4468 MAX_EVENTS,
4469 timeout_ms);
4470 if (-1 == num_events)
4433 { 4471 {
4434 /* update event masks */ 4472 const int err = MHD_socket_get_error_ ();
4435 num_events = epoll_wait (daemon->epoll_fd, 4473 if (MHD_SCKT_ERR_IS_EINTR_ (err))
4436 events, 4474 return MHD_YES;
4437 MAX_EVENTS,
4438 timeout_ms);
4439 if (-1 == num_events)
4440 {
4441 const int err = MHD_socket_get_error_ ();
4442 if (MHD_SCKT_ERR_IS_EINTR_ (err))
4443 return MHD_YES;
4444#ifdef HAVE_MESSAGES 4475#ifdef HAVE_MESSAGES
4445 MHD_DLOG (daemon, 4476 MHD_DLOG (daemon,
4446 _("Call to epoll_wait failed: %s\n"), 4477 _ ("Call to epoll_wait failed: %s\n"),
4447 MHD_socket_strerr_ (err)); 4478 MHD_socket_strerr_ (err));
4448#endif 4479#endif
4449 return MHD_NO; 4480 return MHD_NO;
4450 } 4481 }
4451 for (i=0;i<(unsigned int) num_events;i++) 4482 for (i = 0; i<(unsigned int) num_events; i++)
4452 { 4483 {
4453 /* First, check for the values of `ptr` that would indicate 4484 /* First, check for the values of `ptr` that would indicate
4454 that this event is not about a normal connection. */ 4485 that this event is not about a normal connection. */
4455 if (NULL == events[i].data.ptr) 4486 if (NULL == events[i].data.ptr)
4456 continue; /* shutdown signal! */ 4487 continue; /* shutdown signal! */
4457#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4488#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4458 if (upgrade_marker == events[i].data.ptr) 4489 if (upgrade_marker == events[i].data.ptr)
4459 { 4490 {
4460 /* activity on an upgraded connection, we process 4491 /* activity on an upgraded connection, we process
4461 those in a separate epoll() */ 4492 those in a separate epoll() */
4462 run_upgraded = true; 4493 run_upgraded = true;
4463 continue; 4494 continue;
4464 } 4495 }
4465#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 4496#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
4466 if (epoll_itc_marker == events[i].data.ptr) 4497 if (epoll_itc_marker == events[i].data.ptr)
4467 { 4498 {
4468 /* It's OK to clear ITC here as all external 4499 /* It's OK to clear ITC here as all external
4469 conditions will be processed later. */ 4500 conditions will be processed later. */
4470 MHD_itc_clear_ (daemon->itc); 4501 MHD_itc_clear_ (daemon->itc);
4471 continue; 4502 continue;
4472 } 4503 }
4473 if (daemon == events[i].data.ptr) 4504 if (daemon == events[i].data.ptr)
4474 { 4505 {
4475 /* Check for error conditions on listen socket. */ 4506 /* Check for error conditions on listen socket. */
4476 /* FIXME: Initiate MHD_quiesce_daemon() to prevent busy waiting? */ 4507 /* FIXME: Initiate MHD_quiesce_daemon() to prevent busy waiting? */
4477 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP))) 4508 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
4478 { 4509 {
4479 unsigned int series_length = 0; 4510 unsigned int series_length = 0;
4480 /* Run 'accept' until it fails or daemon at limit of connections. 4511 /* Run 'accept' until it fails or daemon at limit of connections.
4481 * Do not accept more then 10 connections at once. The rest will 4512 * Do not accept more then 10 connections at once. The rest will
4482 * be accepted on next turn (level trigger is used for listen 4513 * be accepted on next turn (level trigger is used for listen
4483 * socket). */ 4514 * socket). */
4484 while ( (MHD_YES == MHD_accept_connection (daemon)) && 4515 while ( (MHD_YES == MHD_accept_connection (daemon)) &&
4485 (series_length < 10) && 4516 (series_length < 10) &&
4486 (daemon->connections < daemon->connection_limit) && 4517 (daemon->connections < daemon->connection_limit) &&
4487 (! daemon->at_limit) ) 4518 (! daemon->at_limit) )
4488 series_length++; 4519 series_length++;
4489 }
4490 continue;
4491 }
4492 /* this is an event relating to a 'normal' connection,
4493 remember the event and if appropriate mark the
4494 connection as 'eready'. */
4495 pos = events[i].data.ptr;
4496 /* normal processing: update read/write data */
4497 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
4498 {
4499 pos->epoll_state |= MHD_EPOLL_STATE_ERROR;
4500 if (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
4501 {
4502 EDLL_insert (daemon->eready_head,
4503 daemon->eready_tail,
4504 pos);
4505 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4506 }
4507 }
4508 else
4509 {
4510 if (0 != (events[i].events & EPOLLIN))
4511 {
4512 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
4513 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
4514 (pos->read_buffer_size > pos->read_buffer_offset) ) &&
4515 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
4516 {
4517 EDLL_insert (daemon->eready_head,
4518 daemon->eready_tail,
4519 pos);
4520 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4521 }
4522 }
4523 if (0 != (events[i].events & EPOLLOUT))
4524 {
4525 pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY;
4526 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
4527 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
4528 {
4529 EDLL_insert (daemon->eready_head,
4530 daemon->eready_tail,
4531 pos);
4532 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4533 }
4534 }
4535 }
4536 } 4520 }
4521 continue;
4522 }
4523 /* this is an event relating to a 'normal' connection,
4524 remember the event and if appropriate mark the
4525 connection as 'eready'. */
4526 pos = events[i].data.ptr;
4527 /* normal processing: update read/write data */
4528 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
4529 {
4530 pos->epoll_state |= MHD_EPOLL_STATE_ERROR;
4531 if (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
4532 {
4533 EDLL_insert (daemon->eready_head,
4534 daemon->eready_tail,
4535 pos);
4536 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4537 }
4538 }
4539 else
4540 {
4541 if (0 != (events[i].events & EPOLLIN))
4542 {
4543 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
4544 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
4545 (pos->read_buffer_size > pos->read_buffer_offset) ) &&
4546 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
4547 {
4548 EDLL_insert (daemon->eready_head,
4549 daemon->eready_tail,
4550 pos);
4551 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4552 }
4553 }
4554 if (0 != (events[i].events & EPOLLOUT))
4555 {
4556 pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY;
4557 if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
4558 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
4559 {
4560 EDLL_insert (daemon->eready_head,
4561 daemon->eready_tail,
4562 pos);
4563 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
4564 }
4565 }
4566 }
4537 } 4567 }
4568 }
4538 4569
4539#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4570#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4540 if (run_upgraded || (NULL != daemon->eready_urh_head)) 4571 if (run_upgraded || (NULL != daemon->eready_urh_head))
@@ -4544,28 +4575,29 @@ MHD_epoll (struct MHD_Daemon *daemon,
4544 /* process events for connections */ 4575 /* process events for connections */
4545 prev = daemon->eready_tail; 4576 prev = daemon->eready_tail;
4546 while (NULL != (pos = prev)) 4577 while (NULL != (pos = prev))
4547 { 4578 {
4548 prev = pos->prevE; 4579 prev = pos->prevE;
4549 call_handlers (pos, 4580 call_handlers (pos,
4550 0 != (pos->epoll_state & MHD_EPOLL_STATE_READ_READY), 4581 0 != (pos->epoll_state & MHD_EPOLL_STATE_READ_READY),
4551 0 != (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY), 4582 0 != (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY),
4552 0 != (pos->epoll_state & MHD_EPOLL_STATE_ERROR)); 4583 0 != (pos->epoll_state & MHD_EPOLL_STATE_ERROR));
4553 if (MHD_EPOLL_STATE_IN_EREADY_EDLL == 4584 if (MHD_EPOLL_STATE_IN_EREADY_EDLL ==
4554 (pos->epoll_state & (MHD_EPOLL_STATE_SUSPENDED | MHD_EPOLL_STATE_IN_EREADY_EDLL))) 4585 (pos->epoll_state & (MHD_EPOLL_STATE_SUSPENDED
4555 { 4586 | MHD_EPOLL_STATE_IN_EREADY_EDLL)))
4556 if ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info && 4587 {
4557 0 == (pos->epoll_state & MHD_EPOLL_STATE_READ_READY) ) || 4588 if ( ((MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) &&
4558 (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info && 4589 (0 == (pos->epoll_state & MHD_EPOLL_STATE_READ_READY)) ) ||
4559 0 == (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY) ) || 4590 ((MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
4560 MHD_EVENT_LOOP_INFO_CLEANUP == pos->event_loop_info) 4591 (0 == (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ) ||
4561 { 4592 (MHD_EVENT_LOOP_INFO_CLEANUP == pos->event_loop_info) )
4562 EDLL_remove (daemon->eready_head, 4593 {
4563 daemon->eready_tail, 4594 EDLL_remove (daemon->eready_head,
4564 pos); 4595 daemon->eready_tail,
4565 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 4596 pos);
4566 } 4597 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
4567 } 4598 }
4568 } 4599 }
4600 }
4569 4601
4570 /* Finally, handle timed-out connections; we need to do this here 4602 /* Finally, handle timed-out connections; we need to do this here
4571 as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, 4603 as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything,
@@ -4577,22 +4609,22 @@ MHD_epoll (struct MHD_Daemon *daemon,
4577 do not bother to sort that (presumably very short) list. */ 4609 do not bother to sort that (presumably very short) list. */
4578 prev = daemon->manual_timeout_tail; 4610 prev = daemon->manual_timeout_tail;
4579 while (NULL != (pos = prev)) 4611 while (NULL != (pos = prev))
4580 { 4612 {
4581 prev = pos->prevX; 4613 prev = pos->prevX;
4582 MHD_connection_handle_idle (pos); 4614 MHD_connection_handle_idle (pos);
4583 } 4615 }
4584 /* Connections with the default timeout are sorted by prepending 4616 /* Connections with the default timeout are sorted by prepending
4585 them to the head of the list whenever we touch the connection; 4617 them to the head of the list whenever we touch the connection;
4586 thus it suffices to iterate from the tail until the first 4618 thus it suffices to iterate from the tail until the first
4587 connection is NOT timed out */ 4619 connection is NOT timed out */
4588 prev = daemon->normal_timeout_tail; 4620 prev = daemon->normal_timeout_tail;
4589 while (NULL != (pos = prev)) 4621 while (NULL != (pos = prev))
4590 { 4622 {
4591 prev = pos->prevX; 4623 prev = pos->prevX;
4592 MHD_connection_handle_idle (pos); 4624 MHD_connection_handle_idle (pos);
4593 if (MHD_CONNECTION_CLOSED != pos->state) 4625 if (MHD_CONNECTION_CLOSED != pos->state)
4594 break; /* sorted by timeout, no need to visit the rest! */ 4626 break; /* sorted by timeout, no need to visit the rest! */
4595 } 4627 }
4596 return MHD_YES; 4628 return MHD_YES;
4597} 4629}
4598#endif 4630#endif
@@ -4625,22 +4657,22 @@ MHD_run (struct MHD_Daemon *daemon)
4625 (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) ) 4657 (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) )
4626 return MHD_NO; 4658 return MHD_NO;
4627 if (0 != (daemon->options & MHD_USE_POLL)) 4659 if (0 != (daemon->options & MHD_USE_POLL))
4628 { 4660 {
4629 MHD_poll (daemon, MHD_NO); 4661 MHD_poll (daemon, MHD_NO);
4630 MHD_cleanup_connections (daemon); 4662 MHD_cleanup_connections (daemon);
4631 } 4663 }
4632#ifdef EPOLL_SUPPORT 4664#ifdef EPOLL_SUPPORT
4633 else if (0 != (daemon->options & MHD_USE_EPOLL)) 4665 else if (0 != (daemon->options & MHD_USE_EPOLL))
4634 { 4666 {
4635 MHD_epoll (daemon, MHD_NO); 4667 MHD_epoll (daemon, MHD_NO);
4636 MHD_cleanup_connections (daemon); 4668 MHD_cleanup_connections (daemon);
4637 } 4669 }
4638#endif 4670#endif
4639 else 4671 else
4640 { 4672 {
4641 MHD_select (daemon, MHD_NO); 4673 MHD_select (daemon, MHD_NO);
4642 /* MHD_select does MHD_cleanup_connections already */ 4674 /* MHD_select does MHD_cleanup_connections already */
4643 } 4675 }
4644 return MHD_YES; 4676 return MHD_YES;
4645} 4677}
4646 4678
@@ -4659,10 +4691,10 @@ close_connection (struct MHD_Connection *pos)
4659 struct MHD_Daemon *daemon = pos->daemon; 4691 struct MHD_Daemon *daemon = pos->daemon;
4660 4692
4661 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 4693 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
4662 { 4694 {
4663 MHD_connection_mark_closed_ (pos); 4695 MHD_connection_mark_closed_ (pos);
4664 return; /* must let thread to do the rest */ 4696 return; /* must let thread to do the rest */
4665 } 4697 }
4666 MHD_connection_close_ (pos, 4698 MHD_connection_close_ (pos,
4667 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); 4699 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
4668#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 4700#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -4672,18 +4704,18 @@ close_connection (struct MHD_Connection *pos)
4672 mhd_assert (! pos->resuming); 4704 mhd_assert (! pos->resuming);
4673 if (pos->connection_timeout == daemon->connection_timeout) 4705 if (pos->connection_timeout == daemon->connection_timeout)
4674 XDLL_remove (daemon->normal_timeout_head, 4706 XDLL_remove (daemon->normal_timeout_head,
4675 daemon->normal_timeout_tail, 4707 daemon->normal_timeout_tail,
4676 pos); 4708 pos);
4677 else 4709 else
4678 XDLL_remove (daemon->manual_timeout_head, 4710 XDLL_remove (daemon->manual_timeout_head,
4679 daemon->manual_timeout_tail, 4711 daemon->manual_timeout_tail,
4680 pos); 4712 pos);
4681 DLL_remove (daemon->connections_head, 4713 DLL_remove (daemon->connections_head,
4682 daemon->connections_tail, 4714 daemon->connections_tail,
4683 pos); 4715 pos);
4684 DLL_insert (daemon->cleanup_head, 4716 DLL_insert (daemon->cleanup_head,
4685 daemon->cleanup_tail, 4717 daemon->cleanup_tail,
4686 pos); 4718 pos);
4687#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 4719#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4688 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 4720 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
4689#endif 4721#endif
@@ -4703,19 +4735,19 @@ MHD_polling_thread (void *cls)
4703{ 4735{
4704 struct MHD_Daemon *daemon = cls; 4736 struct MHD_Daemon *daemon = cls;
4705 4737
4706 MHD_thread_init_(&(daemon->pid)); 4738 MHD_thread_init_ (&(daemon->pid));
4707 while (! daemon->shutdown) 4739 while (! daemon->shutdown)
4708 { 4740 {
4709 if (0 != (daemon->options & MHD_USE_POLL)) 4741 if (0 != (daemon->options & MHD_USE_POLL))
4710 MHD_poll (daemon, MHD_YES); 4742 MHD_poll (daemon, MHD_YES);
4711#ifdef EPOLL_SUPPORT 4743#ifdef EPOLL_SUPPORT
4712 else if (0 != (daemon->options & MHD_USE_EPOLL)) 4744 else if (0 != (daemon->options & MHD_USE_EPOLL))
4713 MHD_epoll (daemon, MHD_YES); 4745 MHD_epoll (daemon, MHD_YES);
4714#endif 4746#endif
4715 else 4747 else
4716 MHD_select (daemon, MHD_YES); 4748 MHD_select (daemon, MHD_YES);
4717 MHD_cleanup_connections (daemon); 4749 MHD_cleanup_connections (daemon);
4718 } 4750 }
4719 4751
4720 /* Resume any pending for resume connections, join 4752 /* Resume any pending for resume connections, join
4721 * all connection's threads (if any) and finally cleanup 4753 * all connection's threads (if any) and finally cleanup
@@ -4724,7 +4756,7 @@ MHD_polling_thread (void *cls)
4724 resume_suspended_connections (daemon); 4756 resume_suspended_connections (daemon);
4725 close_all_connections (daemon); 4757 close_all_connections (daemon);
4726 4758
4727 return (MHD_THRD_RTRN_TYPE_)0; 4759 return (MHD_THRD_RTRN_TYPE_) 0;
4728} 4760}
4729#endif 4761#endif
4730 4762
@@ -4830,59 +4862,61 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
4830 return MHD_INVALID_SOCKET; 4862 return MHD_INVALID_SOCKET;
4831 if ( (0 == (daemon->options & (MHD_USE_ITC))) && 4863 if ( (0 == (daemon->options & (MHD_USE_ITC))) &&
4832 (0 != (daemon->options & (MHD_USE_INTERNAL_POLLING_THREAD))) ) 4864 (0 != (daemon->options & (MHD_USE_INTERNAL_POLLING_THREAD))) )
4833 { 4865 {
4834#ifdef HAVE_MESSAGES 4866#ifdef HAVE_MESSAGES
4835 MHD_DLOG (daemon, 4867 MHD_DLOG (daemon,
4836 "Using MHD_quiesce_daemon in this mode requires MHD_USE_ITC\n"); 4868 "Using MHD_quiesce_daemon in this mode requires MHD_USE_ITC\n");
4837#endif 4869#endif
4838 return MHD_INVALID_SOCKET; 4870 return MHD_INVALID_SOCKET;
4839 } 4871 }
4840 4872
4841#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 4873#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
4842 if (NULL != daemon->worker_pool) 4874 if (NULL != daemon->worker_pool)
4843 for (i = 0; i < daemon->worker_pool_size; i++) 4875 for (i = 0; i < daemon->worker_pool_size; i++)
4844 { 4876 {
4845 daemon->worker_pool[i].was_quiesced = true; 4877 daemon->worker_pool[i].was_quiesced = true;
4846#ifdef EPOLL_SUPPORT 4878#ifdef EPOLL_SUPPORT
4847 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 4879 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
4848 (-1 != daemon->worker_pool[i].epoll_fd) && 4880 (-1 != daemon->worker_pool[i].epoll_fd) &&
4849 (daemon->worker_pool[i].listen_socket_in_epoll) ) 4881 (daemon->worker_pool[i].listen_socket_in_epoll) )
4850 { 4882 {
4851 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd, 4883 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
4852 EPOLL_CTL_DEL, 4884 EPOLL_CTL_DEL,
4853 ret, 4885 ret,
4854 NULL)) 4886 NULL))
4855 MHD_PANIC (_("Failed to remove listen FD from epoll set\n")); 4887 MHD_PANIC (_ ("Failed to remove listen FD from epoll set\n"));
4856 daemon->worker_pool[i].listen_socket_in_epoll = false; 4888 daemon->worker_pool[i].listen_socket_in_epoll = false;
4857 } 4889 }
4858 else 4890 else
4859#endif 4891#endif
4860 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc)) 4892 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc))
4861 { 4893 {
4862 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q")) 4894 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q"))
4863 MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); 4895 MHD_PANIC (_ (
4864 } 4896 "Failed to signal quiesce via inter-thread communication channel"));
4865 } 4897 }
4898 }
4866#endif 4899#endif
4867 daemon->was_quiesced = true; 4900 daemon->was_quiesced = true;
4868#ifdef EPOLL_SUPPORT 4901#ifdef EPOLL_SUPPORT
4869 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 4902 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
4870 (-1 != daemon->epoll_fd) && 4903 (-1 != daemon->epoll_fd) &&
4871 (daemon->listen_socket_in_epoll) ) 4904 (daemon->listen_socket_in_epoll) )
4872 { 4905 {
4873 if ( (0 != epoll_ctl (daemon->epoll_fd, 4906 if ( (0 != epoll_ctl (daemon->epoll_fd,
4874 EPOLL_CTL_DEL, 4907 EPOLL_CTL_DEL,
4875 ret, 4908 ret,
4876 NULL)) && 4909 NULL)) &&
4877 (ENOENT != errno) ) /* ENOENT can happen due to race with 4910 (ENOENT != errno) ) /* ENOENT can happen due to race with
4878 #MHD_epoll() */ 4911 #MHD_epoll() */
4879 MHD_PANIC ("Failed to remove listen FD from epoll set\n"); 4912 MHD_PANIC ("Failed to remove listen FD from epoll set\n");
4880 daemon->listen_socket_in_epoll = false; 4913 daemon->listen_socket_in_epoll = false;
4881 } 4914 }
4882#endif 4915#endif
4883 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 4916 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
4884 (! MHD_itc_activate_ (daemon->itc, "q")) ) 4917 (! MHD_itc_activate_ (daemon->itc, "q")) )
4885 MHD_PANIC (_("failed to signal quiesce via inter-thread communication channel")); 4918 MHD_PANIC (_ (
4919 "failed to signal quiesce via inter-thread communication channel"));
4886 return ret; 4920 return ret;
4887} 4921}
4888 4922
@@ -4924,8 +4958,8 @@ parse_options_va (struct MHD_Daemon *daemon,
4924 */ 4958 */
4925static int 4959static int
4926parse_options (struct MHD_Daemon *daemon, 4960parse_options (struct MHD_Daemon *daemon,
4927 const struct sockaddr **servaddr, 4961 const struct sockaddr **servaddr,
4928 ...) 4962 ...)
4929{ 4963{
4930 va_list ap; 4964 va_list ap;
4931 int ret; 4965 int ret;
@@ -4968,521 +5002,537 @@ parse_options_va (struct MHD_Daemon *daemon,
4968#endif /* HTTPS_SUPPORT */ 5002#endif /* HTTPS_SUPPORT */
4969 5003
4970 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int))) 5004 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int)))
4971 { 5005 {
4972 switch (opt) 5006 switch (opt)
4973 { 5007 {
4974 case MHD_OPTION_CONNECTION_MEMORY_LIMIT: 5008 case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
4975 daemon->pool_size = va_arg (ap, 5009 daemon->pool_size = va_arg (ap,
4976 size_t); 5010 size_t);
4977 break; 5011 break;
4978 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT: 5012 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT:
4979 daemon->pool_increment= va_arg (ap, 5013 daemon->pool_increment = va_arg (ap,
4980 size_t); 5014 size_t);
4981 break; 5015 break;
4982 case MHD_OPTION_CONNECTION_LIMIT: 5016 case MHD_OPTION_CONNECTION_LIMIT:
4983 daemon->connection_limit = va_arg (ap, 5017 daemon->connection_limit = va_arg (ap,
4984 unsigned int); 5018 unsigned int);
4985 break; 5019 break;
4986 case MHD_OPTION_CONNECTION_TIMEOUT: 5020 case MHD_OPTION_CONNECTION_TIMEOUT:
4987 uv = va_arg (ap, 5021 uv = va_arg (ap,
4988 unsigned int); 5022 unsigned int);
4989 daemon->connection_timeout = (time_t)uv; 5023 daemon->connection_timeout = (time_t) uv;
4990 /* Next comparison could be always false on some platforms and whole branch will 5024 /* Next comparison could be always false on some platforms and whole branch will
4991 * be optimized out on those platforms. On others it will be compiled into real 5025 * be optimized out on those platforms. On others it will be compiled into real
4992 * check. */ 5026 * check. */
4993 if ( ( (MHD_TYPE_IS_SIGNED_(time_t)) && 5027 if ( ( (MHD_TYPE_IS_SIGNED_ (time_t)) &&
4994 (daemon->connection_timeout < 0) ) || /* Compiler may warn on some platforms, ignore warning. */ 5028 (daemon->connection_timeout < 0) ) || /* Compiler may warn on some platforms, ignore warning. */
4995 (uv != (unsigned int)daemon->connection_timeout) ) 5029 (uv != (unsigned int) daemon->connection_timeout) )
4996 { 5030 {
4997#ifdef HAVE_MESSAGES 5031#ifdef HAVE_MESSAGES
4998 MHD_DLOG (daemon, 5032 MHD_DLOG (daemon,
4999 _("Warning: Too large timeout value, ignored.\n")); 5033 _ ("Warning: Too large timeout value, ignored.\n"));
5000#endif 5034#endif
5001 daemon->connection_timeout = 0; 5035 daemon->connection_timeout = 0;
5002 } 5036 }
5003 break; 5037 break;
5004 case MHD_OPTION_NOTIFY_COMPLETED: 5038 case MHD_OPTION_NOTIFY_COMPLETED:
5005 daemon->notify_completed = va_arg (ap, 5039 daemon->notify_completed = va_arg (ap,
5006 MHD_RequestCompletedCallback); 5040 MHD_RequestCompletedCallback);
5007 daemon->notify_completed_cls = va_arg (ap, 5041 daemon->notify_completed_cls = va_arg (ap,
5008 void *); 5042 void *);
5009 break; 5043 break;
5010 case MHD_OPTION_NOTIFY_CONNECTION: 5044 case MHD_OPTION_NOTIFY_CONNECTION:
5011 daemon->notify_connection = va_arg (ap, 5045 daemon->notify_connection = va_arg (ap,
5012 MHD_NotifyConnectionCallback); 5046 MHD_NotifyConnectionCallback);
5013 daemon->notify_connection_cls = va_arg (ap, 5047 daemon->notify_connection_cls = va_arg (ap,
5014 void *); 5048 void *);
5015 break; 5049 break;
5016 case MHD_OPTION_PER_IP_CONNECTION_LIMIT: 5050 case MHD_OPTION_PER_IP_CONNECTION_LIMIT:
5017 daemon->per_ip_connection_limit = va_arg (ap, 5051 daemon->per_ip_connection_limit = va_arg (ap,
5018 unsigned int); 5052 unsigned int);
5019 break; 5053 break;
5020 case MHD_OPTION_SOCK_ADDR: 5054 case MHD_OPTION_SOCK_ADDR:
5021 *servaddr = va_arg (ap, 5055 *servaddr = va_arg (ap,
5022 const struct sockaddr *); 5056 const struct sockaddr *);
5023 break; 5057 break;
5024 case MHD_OPTION_URI_LOG_CALLBACK: 5058 case MHD_OPTION_URI_LOG_CALLBACK:
5025 daemon->uri_log_callback = va_arg (ap, 5059 daemon->uri_log_callback = va_arg (ap,
5026 LogCallback); 5060 LogCallback);
5027 daemon->uri_log_callback_cls = va_arg (ap, 5061 daemon->uri_log_callback_cls = va_arg (ap,
5028 void *); 5062 void *);
5029 break; 5063 break;
5030#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 5064#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5031 case MHD_OPTION_THREAD_POOL_SIZE: 5065 case MHD_OPTION_THREAD_POOL_SIZE:
5032 daemon->worker_pool_size = va_arg (ap, 5066 daemon->worker_pool_size = va_arg (ap,
5033 unsigned int); 5067 unsigned int);
5034 if (0 == daemon->worker_pool_size) 5068 if (0 == daemon->worker_pool_size)
5035 { 5069 {
5036#ifdef HAVE_MESSAGES 5070#ifdef HAVE_MESSAGES
5037 MHD_DLOG (daemon, 5071 MHD_DLOG (daemon,
5038 _("Warning: Zero size, specified for thread pool size, is ignored. " 5072 _ (
5039 "Thread pool is not used.\n")); 5073 "Warning: Zero size, specified for thread pool size, is ignored. "
5040#endif 5074 "Thread pool is not used.\n"));
5041 }
5042 else if (1 == daemon->worker_pool_size)
5043 {
5044#ifdef HAVE_MESSAGES
5045 MHD_DLOG (daemon,
5046 _("Warning: \"1\", specified for thread pool size, is ignored. "
5047 "Thread pool is not used.\n"));
5048#endif
5049 daemon->worker_pool_size = 0;
5050 }
5051 /* Next comparison could be always false on some platforms and whole branch will
5052 * be optimized out on those platforms. On others it will be compiled into real
5053 * check. */
5054 else if (daemon->worker_pool_size >= (SIZE_MAX / sizeof (struct MHD_Daemon))) /* Compiler may warn on some platforms, ignore warning. */
5055 {
5056#ifdef HAVE_MESSAGES
5057 MHD_DLOG (daemon,
5058 _("Specified thread pool size (%u) too big\n"),
5059 daemon->worker_pool_size);
5060#endif
5061 return MHD_NO;
5062 }
5063 else
5064 {
5065 if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD))
5066 {
5067#ifdef HAVE_MESSAGES
5068 MHD_DLOG (daemon,
5069 _("MHD_OPTION_THREAD_POOL_SIZE option is specified but "
5070 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
5071#endif
5072 return MHD_NO;
5073 }
5074 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
5075 {
5076#ifdef HAVE_MESSAGES
5077 MHD_DLOG (daemon,
5078 _("Both MHD_OPTION_THREAD_POOL_SIZE option and "
5079 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
5080#endif
5081 return MHD_NO;
5082 }
5083 }
5084 break;
5085#endif 5075#endif
5086#ifdef HTTPS_SUPPORT 5076 }
5087 case MHD_OPTION_HTTPS_MEM_KEY: 5077 else if (1 == daemon->worker_pool_size)
5088 pstr = va_arg (ap, 5078 {
5089 const char *);
5090 if (0 != (daemon->options & MHD_USE_TLS))
5091 daemon->https_mem_key = pstr;
5092#ifdef HAVE_MESSAGES 5079#ifdef HAVE_MESSAGES
5093 else 5080 MHD_DLOG (daemon,
5094 MHD_DLOG (daemon, 5081 _ (
5095 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5082 "Warning: \"1\", specified for thread pool size, is ignored. "
5096 opt); 5083 "Thread pool is not used.\n"));
5097#endif 5084#endif
5098 break; 5085 daemon->worker_pool_size = 0;
5099 case MHD_OPTION_HTTPS_KEY_PASSWORD: 5086 }
5100 pstr = va_arg (ap, 5087 /* Next comparison could be always false on some platforms and whole branch will
5101 const char *); 5088 * be optimized out on those platforms. On others it will be compiled into real
5102 if (0 != (daemon->options & MHD_USE_TLS)) 5089 * check. */
5103 daemon->https_key_password = pstr; 5090 else if (daemon->worker_pool_size >= (SIZE_MAX / sizeof (struct
5091 MHD_Daemon))) /* Compiler may warn on some platforms, ignore warning. */
5092 {
5104#ifdef HAVE_MESSAGES 5093#ifdef HAVE_MESSAGES
5105 else 5094 MHD_DLOG (daemon,
5106 MHD_DLOG (daemon, 5095 _ ("Specified thread pool size (%u) too big\n"),
5107 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5096 daemon->worker_pool_size);
5108 opt);
5109#endif 5097#endif
5110 break; 5098 return MHD_NO;
5111 case MHD_OPTION_HTTPS_MEM_CERT: 5099 }
5112 pstr = va_arg (ap, 5100 else
5113 const char *); 5101 {
5114 if (0 != (daemon->options & MHD_USE_TLS)) 5102 if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD))
5115 daemon->https_mem_cert = pstr; 5103 {
5116#ifdef HAVE_MESSAGES 5104#ifdef HAVE_MESSAGES
5117 else 5105 MHD_DLOG (daemon,
5118 MHD_DLOG (daemon, 5106 _ ("MHD_OPTION_THREAD_POOL_SIZE option is specified but "
5119 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5107 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
5120 opt);
5121#endif 5108#endif
5122 break; 5109 return MHD_NO;
5123 case MHD_OPTION_HTTPS_MEM_TRUST: 5110 }
5124 pstr = va_arg (ap, 5111 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
5125 const char *); 5112 {
5126 if (0 != (daemon->options & MHD_USE_TLS))
5127 daemon->https_mem_trust = pstr;
5128#ifdef HAVE_MESSAGES 5113#ifdef HAVE_MESSAGES
5129 else 5114 MHD_DLOG (daemon,
5130 MHD_DLOG (daemon, 5115 _ ("Both MHD_OPTION_THREAD_POOL_SIZE option and "
5131 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5116 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
5132 opt);
5133#endif 5117#endif
5134 break; 5118 return MHD_NO;
5135 case MHD_OPTION_HTTPS_CRED_TYPE: 5119 }
5136 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap, 5120 }
5137 int); 5121 break;
5138 break;
5139 case MHD_OPTION_HTTPS_MEM_DHPARAMS:
5140 pstr = va_arg (ap,
5141 const char *);
5142 if (0 != (daemon->options & MHD_USE_TLS))
5143 {
5144 gnutls_datum_t dhpar;
5145 size_t pstr_len;
5146
5147 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
5148 {
5149#ifdef HAVE_MESSAGES
5150 MHD_DLOG (daemon,
5151 _("Error initializing DH parameters\n"));
5152#endif
5153 return MHD_NO;
5154 }
5155 dhpar.data = (unsigned char *) pstr;
5156 pstr_len = strlen (pstr);
5157 if (UINT_MAX < pstr_len)
5158 {
5159#ifdef HAVE_MESSAGES
5160 MHD_DLOG (daemon,
5161 _("Diffie-Hellman parameters string too long\n"));
5162#endif
5163 return MHD_NO;
5164 }
5165 dhpar.size = (unsigned int) pstr_len;
5166 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
5167 &dhpar,
5168 GNUTLS_X509_FMT_PEM) < 0)
5169 {
5170#ifdef HAVE_MESSAGES
5171 MHD_DLOG (daemon,
5172 _("Bad Diffie-Hellman parameters format\n"));
5173#endif
5174 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
5175 return MHD_NO;
5176 }
5177 daemon->have_dhparams = true;
5178 }
5179#ifdef HAVE_MESSAGES
5180 else
5181 MHD_DLOG (daemon,
5182 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5183 opt);
5184#endif 5122#endif
5185 break; 5123#ifdef HTTPS_SUPPORT
5186 case MHD_OPTION_HTTPS_PRIORITIES: 5124 case MHD_OPTION_HTTPS_MEM_KEY:
5187 pstr = va_arg (ap, 5125 pstr = va_arg (ap,
5188 const char *); 5126 const char *);
5189 if (0 != (daemon->options & MHD_USE_TLS)) 5127 if (0 != (daemon->options & MHD_USE_TLS))
5190 { 5128 daemon->https_mem_key = pstr;
5191 gnutls_priority_deinit (daemon->priority_cache); 5129#ifdef HAVE_MESSAGES
5192 ret = gnutls_priority_init (&daemon->priority_cache, 5130 else
5193 pstr, 5131 MHD_DLOG (daemon,
5194 NULL); 5132 _ (
5195 if (GNUTLS_E_SUCCESS != ret) 5133 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5196 { 5134 opt);
5197#ifdef HAVE_MESSAGES 5135#endif
5198 MHD_DLOG (daemon, 5136 break;
5199 _("Setting priorities to `%s' failed: %s\n"), 5137 case MHD_OPTION_HTTPS_KEY_PASSWORD:
5200 pstr, 5138 pstr = va_arg (ap,
5201 gnutls_strerror (ret)); 5139 const char *);
5202#endif 5140 if (0 != (daemon->options & MHD_USE_TLS))
5203 daemon->priority_cache = NULL; 5141 daemon->https_key_password = pstr;
5204 return MHD_NO; 5142#ifdef HAVE_MESSAGES
5205 } 5143 else
5206 } 5144 MHD_DLOG (daemon,
5207#ifdef HAVE_MESSAGES 5145 _ (
5208 else 5146 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5209 MHD_DLOG (daemon, 5147 opt);
5210 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5148#endif
5211 opt); 5149 break;
5150 case MHD_OPTION_HTTPS_MEM_CERT:
5151 pstr = va_arg (ap,
5152 const char *);
5153 if (0 != (daemon->options & MHD_USE_TLS))
5154 daemon->https_mem_cert = pstr;
5155#ifdef HAVE_MESSAGES
5156 else
5157 MHD_DLOG (daemon,
5158 _ (
5159 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5160 opt);
5161#endif
5162 break;
5163 case MHD_OPTION_HTTPS_MEM_TRUST:
5164 pstr = va_arg (ap,
5165 const char *);
5166 if (0 != (daemon->options & MHD_USE_TLS))
5167 daemon->https_mem_trust = pstr;
5168#ifdef HAVE_MESSAGES
5169 else
5170 MHD_DLOG (daemon,
5171 _ (
5172 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5173 opt);
5174#endif
5175 break;
5176 case MHD_OPTION_HTTPS_CRED_TYPE:
5177 daemon->cred_type = (gnutls_credentials_type_t) va_arg (ap,
5178 int);
5179 break;
5180 case MHD_OPTION_HTTPS_MEM_DHPARAMS:
5181 pstr = va_arg (ap,
5182 const char *);
5183 if (0 != (daemon->options & MHD_USE_TLS))
5184 {
5185 gnutls_datum_t dhpar;
5186 size_t pstr_len;
5187
5188 if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
5189 {
5190#ifdef HAVE_MESSAGES
5191 MHD_DLOG (daemon,
5192 _ ("Error initializing DH parameters\n"));
5212#endif 5193#endif
5213 break; 5194 return MHD_NO;
5214 case MHD_OPTION_HTTPS_CERT_CALLBACK: 5195 }
5215#if GNUTLS_VERSION_MAJOR < 3 5196 dhpar.data = (unsigned char *) pstr;
5197 pstr_len = strlen (pstr);
5198 if (UINT_MAX < pstr_len)
5199 {
5200#ifdef HAVE_MESSAGES
5201 MHD_DLOG (daemon,
5202 _ ("Diffie-Hellman parameters string too long\n"));
5203#endif
5204 return MHD_NO;
5205 }
5206 dhpar.size = (unsigned int) pstr_len;
5207 if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
5208 &dhpar,
5209 GNUTLS_X509_FMT_PEM) < 0)
5210 {
5216#ifdef HAVE_MESSAGES 5211#ifdef HAVE_MESSAGES
5217 MHD_DLOG (daemon, 5212 MHD_DLOG (daemon,
5218 _("MHD_OPTION_HTTPS_CERT_CALLBACK requires building MHD with GnuTLS >= 3.0\n")); 5213 _ ("Bad Diffie-Hellman parameters format\n"));
5219#endif 5214#endif
5215 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
5220 return MHD_NO; 5216 return MHD_NO;
5217 }
5218 daemon->have_dhparams = true;
5219 }
5220#ifdef HAVE_MESSAGES
5221 else
5222 MHD_DLOG (daemon,
5223 _ (
5224 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5225 opt);
5226#endif
5227 break;
5228 case MHD_OPTION_HTTPS_PRIORITIES:
5229 pstr = va_arg (ap,
5230 const char *);
5231 if (0 != (daemon->options & MHD_USE_TLS))
5232 {
5233 gnutls_priority_deinit (daemon->priority_cache);
5234 ret = gnutls_priority_init (&daemon->priority_cache,
5235 pstr,
5236 NULL);
5237 if (GNUTLS_E_SUCCESS != ret)
5238 {
5239#ifdef HAVE_MESSAGES
5240 MHD_DLOG (daemon,
5241 _ ("Setting priorities to `%s' failed: %s\n"),
5242 pstr,
5243 gnutls_strerror (ret));
5244#endif
5245 daemon->priority_cache = NULL;
5246 return MHD_NO;
5247 }
5248 }
5249#ifdef HAVE_MESSAGES
5250 else
5251 MHD_DLOG (daemon,
5252 _ (
5253 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5254 opt);
5255#endif
5256 break;
5257 case MHD_OPTION_HTTPS_CERT_CALLBACK:
5258#if GNUTLS_VERSION_MAJOR < 3
5259#ifdef HAVE_MESSAGES
5260 MHD_DLOG (daemon,
5261 _ (
5262 "MHD_OPTION_HTTPS_CERT_CALLBACK requires building MHD with GnuTLS >= 3.0\n"));
5263#endif
5264 return MHD_NO;
5221#else 5265#else
5222 pgcrf = va_arg (ap, 5266 pgcrf = va_arg (ap,
5223 gnutls_certificate_retrieve_function2 *); 5267 gnutls_certificate_retrieve_function2 *);
5224 if (0 != (daemon->options & MHD_USE_TLS)) 5268 if (0 != (daemon->options & MHD_USE_TLS))
5225 daemon->cert_callback = pgcrf; 5269 daemon->cert_callback = pgcrf;
5226 else 5270 else
5227#ifdef HAVE_MESSAGES 5271#ifdef HAVE_MESSAGES
5228 MHD_DLOG (daemon, 5272 MHD_DLOG (daemon,
5229 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5273 _ (
5230 opt); 5274 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5275 opt);
5231#endif 5276#endif
5232 break; 5277 break;
5233#endif 5278#endif
5234 case MHD_OPTION_HTTPS_CERT_CALLBACK2: 5279 case MHD_OPTION_HTTPS_CERT_CALLBACK2:
5235#if GNUTLS_VERSION_NUMBER < 0x030603 5280#if GNUTLS_VERSION_NUMBER < 0x030603
5236#ifdef HAVE_MESSAGES 5281#ifdef HAVE_MESSAGES
5237 MHD_DLOG (daemon, 5282 MHD_DLOG (daemon,
5238 _("MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building MHD with GnuTLS >= 3.6.3\n")); 5283 _ (
5284 "MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building MHD with GnuTLS >= 3.6.3\n"));
5239#endif 5285#endif
5240 return MHD_NO; 5286 return MHD_NO;
5241#else 5287#else
5242 pgcrf2 = va_arg (ap, 5288 pgcrf2 = va_arg (ap,
5243 gnutls_certificate_retrieve_function3 *); 5289 gnutls_certificate_retrieve_function3 *);
5244 if (0 != (daemon->options & MHD_USE_TLS)) 5290 if (0 != (daemon->options & MHD_USE_TLS))
5245 daemon->cert_callback2 = pgcrf2; 5291 daemon->cert_callback2 = pgcrf2;
5246 else 5292 else
5247#ifdef HAVE_MESSAGES 5293#ifdef HAVE_MESSAGES
5248 MHD_DLOG (daemon, 5294 MHD_DLOG (daemon,
5249 _("MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"), 5295 _ (
5250 opt); 5296 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set\n"),
5297 opt);
5251#endif 5298#endif
5252 break; 5299 break;
5253#endif 5300#endif
5254#endif /* HTTPS_SUPPORT */ 5301#endif /* HTTPS_SUPPORT */
5255#ifdef DAUTH_SUPPORT 5302#ifdef DAUTH_SUPPORT
5256 case MHD_OPTION_DIGEST_AUTH_RANDOM: 5303 case MHD_OPTION_DIGEST_AUTH_RANDOM:
5257 daemon->digest_auth_rand_size = va_arg (ap, 5304 daemon->digest_auth_rand_size = va_arg (ap,
5258 size_t); 5305 size_t);
5259 daemon->digest_auth_random = va_arg (ap, 5306 daemon->digest_auth_random = va_arg (ap,
5260 const char *); 5307 const char *);
5261 break; 5308 break;
5262 case MHD_OPTION_NONCE_NC_SIZE: 5309 case MHD_OPTION_NONCE_NC_SIZE:
5263 daemon->nonce_nc_size = va_arg (ap, 5310 daemon->nonce_nc_size = va_arg (ap,
5264 unsigned int); 5311 unsigned int);
5265 break; 5312 break;
5266#endif 5313#endif
5267 case MHD_OPTION_LISTEN_SOCKET: 5314 case MHD_OPTION_LISTEN_SOCKET:
5268 if (0 != (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) 5315 if (0 != (daemon->options & MHD_USE_NO_LISTEN_SOCKET))
5269 { 5316 {
5270#ifdef HAVE_MESSAGES
5271 MHD_DLOG (daemon,
5272 _("MHD_OPTION_LISTEN_SOCKET specified for daemon "
5273 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
5274#endif
5275 return MHD_NO;
5276 }
5277 else
5278 daemon->listen_fd = va_arg (ap,
5279 MHD_socket);
5280 break;
5281 case MHD_OPTION_EXTERNAL_LOGGER:
5282#ifdef HAVE_MESSAGES 5317#ifdef HAVE_MESSAGES
5283 daemon->custom_error_log = va_arg (ap, 5318 MHD_DLOG (daemon,
5284 VfprintfFunctionPointerType); 5319 _ ("MHD_OPTION_LISTEN_SOCKET specified for daemon "
5285 daemon->custom_error_log_cls = va_arg (ap, 5320 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
5286 void *); 5321#endif
5322 return MHD_NO;
5323 }
5324 else
5325 daemon->listen_fd = va_arg (ap,
5326 MHD_socket);
5327 break;
5328 case MHD_OPTION_EXTERNAL_LOGGER:
5329#ifdef HAVE_MESSAGES
5330 daemon->custom_error_log = va_arg (ap,
5331 VfprintfFunctionPointerType);
5332 daemon->custom_error_log_cls = va_arg (ap,
5333 void *);
5287#else 5334#else
5288 va_arg (ap, 5335 va_arg (ap,
5289 VfprintfFunctionPointerType); 5336 VfprintfFunctionPointerType);
5290 va_arg (ap, 5337 va_arg (ap,
5291 void *); 5338 void *);
5292#endif 5339#endif
5293 break; 5340 break;
5294#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 5341#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5295 case MHD_OPTION_THREAD_STACK_SIZE: 5342 case MHD_OPTION_THREAD_STACK_SIZE:
5296 daemon->thread_stack_size = va_arg (ap, 5343 daemon->thread_stack_size = va_arg (ap,
5297 size_t); 5344 size_t);
5298 break; 5345 break;
5299#endif 5346#endif
5300 case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE: 5347 case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE:
5301#ifdef TCP_FASTOPEN 5348#ifdef TCP_FASTOPEN
5302 daemon->fastopen_queue_size = va_arg (ap, 5349 daemon->fastopen_queue_size = va_arg (ap,
5303 unsigned int); 5350 unsigned int);
5304 break; 5351 break;
5305#else /* ! TCP_FASTOPEN */ 5352#else /* ! TCP_FASTOPEN */
5306#ifdef HAVE_MESSAGES 5353#ifdef HAVE_MESSAGES
5307 MHD_DLOG (daemon, 5354 MHD_DLOG (daemon,
5308 _("TCP fastopen is not supported on this platform\n")); 5355 _ ("TCP fastopen is not supported on this platform\n"));
5309 return MHD_NO; 5356 return MHD_NO;
5310#endif /* HAVE_MESSAGES */ 5357#endif /* HAVE_MESSAGES */
5311#endif /* ! TCP_FASTOPEN */ 5358#endif /* ! TCP_FASTOPEN */
5312 case MHD_OPTION_LISTENING_ADDRESS_REUSE: 5359 case MHD_OPTION_LISTENING_ADDRESS_REUSE:
5313 daemon->listening_address_reuse = va_arg (ap, 5360 daemon->listening_address_reuse = va_arg (ap,
5314 unsigned int) ? 1 : -1; 5361 unsigned int) ? 1 : -1;
5315 break; 5362 break;
5316 case MHD_OPTION_LISTEN_BACKLOG_SIZE: 5363 case MHD_OPTION_LISTEN_BACKLOG_SIZE:
5317 daemon->listen_backlog_size = va_arg (ap, 5364 daemon->listen_backlog_size = va_arg (ap,
5318 unsigned int); 5365 unsigned int);
5319 break; 5366 break;
5320 case MHD_OPTION_STRICT_FOR_CLIENT: 5367 case MHD_OPTION_STRICT_FOR_CLIENT:
5321 daemon->strict_for_client = va_arg (ap, int); 5368 daemon->strict_for_client = va_arg (ap, int);
5322#ifdef HAVE_MESSAGES 5369#ifdef HAVE_MESSAGES
5323 if ( (0 != (daemon->options & MHD_USE_PEDANTIC_CHECKS)) && 5370 if ( (0 != (daemon->options & MHD_USE_PEDANTIC_CHECKS)) &&
5324 (1 != daemon->strict_for_client) ) 5371 (1 != daemon->strict_for_client) )
5325 { 5372 {
5326 MHD_DLOG (daemon, 5373 MHD_DLOG (daemon,
5327 _("Flag MHD_USE_PEDANTIC_CHECKS is ignored because " 5374 _ ("Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
5328 "another behavior is specified by MHD_OPTION_STRICT_CLIENT.\n")); 5375 "another behavior is specified by MHD_OPTION_STRICT_CLIENT.\n"));
5329 } 5376 }
5330#endif /* HAVE_MESSAGES */ 5377#endif /* HAVE_MESSAGES */
5331 break; 5378 break;
5332 case MHD_OPTION_ARRAY: 5379 case MHD_OPTION_ARRAY:
5333 oa = va_arg (ap, struct MHD_OptionItem*); 5380 oa = va_arg (ap, struct MHD_OptionItem*);
5334 i = 0; 5381 i = 0;
5335 while (MHD_OPTION_END != (opt = oa[i].option)) 5382 while (MHD_OPTION_END != (opt = oa[i].option))
5336 { 5383 {
5337 switch (opt) 5384 switch (opt)
5338 { 5385 {
5339 /* all options taking 'size_t' */ 5386 /* all options taking 'size_t' */
5340 case MHD_OPTION_CONNECTION_MEMORY_LIMIT: 5387 case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
5341 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT: 5388 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT:
5342 case MHD_OPTION_THREAD_STACK_SIZE: 5389 case MHD_OPTION_THREAD_STACK_SIZE:
5343 if (MHD_YES != parse_options (daemon, 5390 if (MHD_YES != parse_options (daemon,
5344 servaddr, 5391 servaddr,
5345 opt, 5392 opt,
5346 (size_t) oa[i].value, 5393 (size_t) oa[i].value,
5347 MHD_OPTION_END)) 5394 MHD_OPTION_END))
5348 return MHD_NO; 5395 return MHD_NO;
5349 break; 5396 break;
5350 /* all options taking 'unsigned int' */ 5397 /* all options taking 'unsigned int' */
5351 case MHD_OPTION_NONCE_NC_SIZE: 5398 case MHD_OPTION_NONCE_NC_SIZE:
5352 case MHD_OPTION_CONNECTION_LIMIT: 5399 case MHD_OPTION_CONNECTION_LIMIT:
5353 case MHD_OPTION_CONNECTION_TIMEOUT: 5400 case MHD_OPTION_CONNECTION_TIMEOUT:
5354 case MHD_OPTION_PER_IP_CONNECTION_LIMIT: 5401 case MHD_OPTION_PER_IP_CONNECTION_LIMIT:
5355 case MHD_OPTION_THREAD_POOL_SIZE: 5402 case MHD_OPTION_THREAD_POOL_SIZE:
5356 case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE: 5403 case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE:
5357 case MHD_OPTION_LISTENING_ADDRESS_REUSE: 5404 case MHD_OPTION_LISTENING_ADDRESS_REUSE:
5358 case MHD_OPTION_LISTEN_BACKLOG_SIZE: 5405 case MHD_OPTION_LISTEN_BACKLOG_SIZE:
5359 if (MHD_YES != parse_options (daemon, 5406 if (MHD_YES != parse_options (daemon,
5360 servaddr, 5407 servaddr,
5361 opt, 5408 opt,
5362 (unsigned int) oa[i].value, 5409 (unsigned int) oa[i].value,
5363 MHD_OPTION_END)) 5410 MHD_OPTION_END))
5364 return MHD_NO; 5411 return MHD_NO;
5365 break; 5412 break;
5366 /* all options taking 'enum' */ 5413 /* all options taking 'enum' */
5367#ifdef HTTPS_SUPPORT 5414#ifdef HTTPS_SUPPORT
5368 case MHD_OPTION_HTTPS_CRED_TYPE: 5415 case MHD_OPTION_HTTPS_CRED_TYPE:
5369 if (MHD_YES != parse_options (daemon, 5416 if (MHD_YES != parse_options (daemon,
5370 servaddr, 5417 servaddr,
5371 opt, 5418 opt,
5372 (gnutls_credentials_type_t) oa[i].value, 5419 (gnutls_credentials_type_t) oa[i].value,
5373 MHD_OPTION_END)) 5420 MHD_OPTION_END))
5374 return MHD_NO; 5421 return MHD_NO;
5375 break; 5422 break;
5376#endif /* HTTPS_SUPPORT */ 5423#endif /* HTTPS_SUPPORT */
5377 /* all options taking 'MHD_socket' */ 5424 /* all options taking 'MHD_socket' */
5378 case MHD_OPTION_LISTEN_SOCKET: 5425 case MHD_OPTION_LISTEN_SOCKET:
5379 if (MHD_YES != parse_options (daemon, 5426 if (MHD_YES != parse_options (daemon,
5380 servaddr, 5427 servaddr,
5381 opt, 5428 opt,
5382 (MHD_socket) oa[i].value, 5429 (MHD_socket) oa[i].value,
5383 MHD_OPTION_END)) 5430 MHD_OPTION_END))
5384 return MHD_NO; 5431 return MHD_NO;
5385 break; 5432 break;
5386 /* all options taking 'int' */ 5433 /* all options taking 'int' */
5387 case MHD_OPTION_STRICT_FOR_CLIENT: 5434 case MHD_OPTION_STRICT_FOR_CLIENT:
5388 if (MHD_YES != parse_options (daemon, 5435 if (MHD_YES != parse_options (daemon,
5389 servaddr, 5436 servaddr,
5390 opt, 5437 opt,
5391 (int) oa[i].value, 5438 (int) oa[i].value,
5392 MHD_OPTION_END)) 5439 MHD_OPTION_END))
5393 return MHD_NO; 5440 return MHD_NO;
5394 break; 5441 break;
5395 /* all options taking one pointer */ 5442 /* all options taking one pointer */
5396 case MHD_OPTION_SOCK_ADDR: 5443 case MHD_OPTION_SOCK_ADDR:
5397 case MHD_OPTION_HTTPS_MEM_KEY: 5444 case MHD_OPTION_HTTPS_MEM_KEY:
5398 case MHD_OPTION_HTTPS_KEY_PASSWORD: 5445 case MHD_OPTION_HTTPS_KEY_PASSWORD:
5399 case MHD_OPTION_HTTPS_MEM_CERT: 5446 case MHD_OPTION_HTTPS_MEM_CERT:
5400 case MHD_OPTION_HTTPS_MEM_TRUST: 5447 case MHD_OPTION_HTTPS_MEM_TRUST:
5401 case MHD_OPTION_HTTPS_MEM_DHPARAMS: 5448 case MHD_OPTION_HTTPS_MEM_DHPARAMS:
5402 case MHD_OPTION_HTTPS_PRIORITIES: 5449 case MHD_OPTION_HTTPS_PRIORITIES:
5403 case MHD_OPTION_ARRAY: 5450 case MHD_OPTION_ARRAY:
5404 case MHD_OPTION_HTTPS_CERT_CALLBACK: 5451 case MHD_OPTION_HTTPS_CERT_CALLBACK:
5405 case MHD_OPTION_HTTPS_CERT_CALLBACK2: 5452 case MHD_OPTION_HTTPS_CERT_CALLBACK2:
5406 if (MHD_YES != parse_options (daemon, 5453 if (MHD_YES != parse_options (daemon,
5407 servaddr, 5454 servaddr,
5408 opt, 5455 opt,
5409 oa[i].ptr_value, 5456 oa[i].ptr_value,
5410 MHD_OPTION_END)) 5457 MHD_OPTION_END))
5411 return MHD_NO; 5458 return MHD_NO;
5412 break; 5459 break;
5413 /* all options taking two pointers */ 5460 /* all options taking two pointers */
5414 case MHD_OPTION_NOTIFY_COMPLETED: 5461 case MHD_OPTION_NOTIFY_COMPLETED:
5415 case MHD_OPTION_NOTIFY_CONNECTION: 5462 case MHD_OPTION_NOTIFY_CONNECTION:
5416 case MHD_OPTION_URI_LOG_CALLBACK: 5463 case MHD_OPTION_URI_LOG_CALLBACK:
5417 case MHD_OPTION_EXTERNAL_LOGGER: 5464 case MHD_OPTION_EXTERNAL_LOGGER:
5418 case MHD_OPTION_UNESCAPE_CALLBACK:
5419 case MHD_OPTION_GNUTLS_PSK_CRED_HANDLER:
5420 if (MHD_YES != parse_options (daemon,
5421 servaddr,
5422 opt,
5423 (void *) oa[i].value,
5424 oa[i].ptr_value,
5425 MHD_OPTION_END))
5426 return MHD_NO;
5427 break;
5428 /* options taking size_t-number followed by pointer */
5429 case MHD_OPTION_DIGEST_AUTH_RANDOM:
5430 if (MHD_YES != parse_options (daemon,
5431 servaddr,
5432 opt,
5433 (size_t) oa[i].value,
5434 oa[i].ptr_value,
5435 MHD_OPTION_END))
5436 return MHD_NO;
5437 break;
5438 default:
5439 return MHD_NO;
5440 }
5441 i++;
5442 }
5443 break;
5444 case MHD_OPTION_UNESCAPE_CALLBACK: 5465 case MHD_OPTION_UNESCAPE_CALLBACK:
5445 daemon->unescape_callback = va_arg (ap, 5466 case MHD_OPTION_GNUTLS_PSK_CRED_HANDLER:
5446 UnescapeCallback); 5467 if (MHD_YES != parse_options (daemon,
5447 daemon->unescape_callback_cls = va_arg (ap, 5468 servaddr,
5448 void *); 5469 opt,
5470 (void *) oa[i].value,
5471 oa[i].ptr_value,
5472 MHD_OPTION_END))
5473 return MHD_NO;
5449 break; 5474 break;
5475 /* options taking size_t-number followed by pointer */
5476 case MHD_OPTION_DIGEST_AUTH_RANDOM:
5477 if (MHD_YES != parse_options (daemon,
5478 servaddr,
5479 opt,
5480 (size_t) oa[i].value,
5481 oa[i].ptr_value,
5482 MHD_OPTION_END))
5483 return MHD_NO;
5484 break;
5485 default:
5486 return MHD_NO;
5487 }
5488 i++;
5489 }
5490 break;
5491 case MHD_OPTION_UNESCAPE_CALLBACK:
5492 daemon->unescape_callback = va_arg (ap,
5493 UnescapeCallback);
5494 daemon->unescape_callback_cls = va_arg (ap,
5495 void *);
5496 break;
5450#ifdef HTTPS_SUPPORT 5497#ifdef HTTPS_SUPPORT
5451 case MHD_OPTION_GNUTLS_PSK_CRED_HANDLER: 5498 case MHD_OPTION_GNUTLS_PSK_CRED_HANDLER:
5452#if GNUTLS_VERSION_MAJOR >= 3 5499#if GNUTLS_VERSION_MAJOR >= 3
5453 daemon->cred_callback = va_arg (ap, 5500 daemon->cred_callback = va_arg (ap,
5454 MHD_PskServerCredentialsCallback); 5501 MHD_PskServerCredentialsCallback);
5455 daemon->cred_callback_cls = va_arg (ap, 5502 daemon->cred_callback_cls = va_arg (ap,
5456 void *); 5503 void *);
5457 break; 5504 break;
5458#else 5505#else
5459 MHD_DLOG (daemon, 5506 MHD_DLOG (daemon,
5460 _("MHD HTTPS option %d passed to MHD compiled without GNUtls >= 3\n"), 5507 _ (
5461 opt); 5508 "MHD HTTPS option %d passed to MHD compiled without GNUtls >= 3\n"),
5462 return MHD_NO; 5509 opt);
5510 return MHD_NO;
5463#endif 5511#endif
5464#endif /* HTTPS_SUPPORT */ 5512#endif /* HTTPS_SUPPORT */
5465 default: 5513 default:
5466#ifdef HAVE_MESSAGES 5514#ifdef HAVE_MESSAGES
5467 if ( ( (opt >= MHD_OPTION_HTTPS_MEM_KEY) && 5515 if ( ( (opt >= MHD_OPTION_HTTPS_MEM_KEY) &&
5468 (opt <= MHD_OPTION_HTTPS_PRIORITIES) ) || 5516 (opt <= MHD_OPTION_HTTPS_PRIORITIES) ) ||
5469 (opt == MHD_OPTION_HTTPS_MEM_TRUST) || 5517 (opt == MHD_OPTION_HTTPS_MEM_TRUST) ||
5470 (opt == MHD_OPTION_GNUTLS_PSK_CRED_HANDLER) ) 5518 (opt == MHD_OPTION_GNUTLS_PSK_CRED_HANDLER) )
5471 { 5519 {
5472 MHD_DLOG (daemon, 5520 MHD_DLOG (daemon,
5473 _("MHD HTTPS option %d passed to MHD compiled without HTTPS support\n"), 5521 _ (
5474 opt); 5522 "MHD HTTPS option %d passed to MHD compiled without HTTPS support\n"),
5475 } 5523 opt);
5476 else 5524 }
5477 { 5525 else
5478 MHD_DLOG (daemon, 5526 {
5479 _("Invalid option %d! (Did you terminate the list with MHD_OPTION_END?)\n"), 5527 MHD_DLOG (daemon,
5480 opt); 5528 _ (
5481 } 5529 "Invalid option %d! (Did you terminate the list with MHD_OPTION_END?)\n"),
5482#endif 5530 opt);
5483 return MHD_NO; 5531 }
5484 } 5532#endif
5533 return MHD_NO;
5485 } 5534 }
5535 }
5486 return MHD_YES; 5536 return MHD_YES;
5487} 5537}
5488 5538
@@ -5494,7 +5544,7 @@ setup_epoll_fd (struct MHD_Daemon *daemon)
5494 int fd; 5544 int fd;
5495 5545
5496#ifndef HAVE_MESSAGES 5546#ifndef HAVE_MESSAGES
5497 (void)daemon; /* Mute compiler warning. */ 5547 (void) daemon; /* Mute compiler warning. */
5498#endif /* ! HAVE_MESSAGES */ 5548#endif /* ! HAVE_MESSAGES */
5499 5549
5500#ifdef USE_EPOLL_CREATE1 5550#ifdef USE_EPOLL_CREATE1
@@ -5503,22 +5553,22 @@ setup_epoll_fd (struct MHD_Daemon *daemon)
5503 fd = epoll_create (MAX_EVENTS); 5553 fd = epoll_create (MAX_EVENTS);
5504#endif /* ! USE_EPOLL_CREATE1 */ 5554#endif /* ! USE_EPOLL_CREATE1 */
5505 if (MHD_INVALID_SOCKET == fd) 5555 if (MHD_INVALID_SOCKET == fd)
5506 { 5556 {
5507#ifdef HAVE_MESSAGES 5557#ifdef HAVE_MESSAGES
5508 MHD_DLOG (daemon, 5558 MHD_DLOG (daemon,
5509 _("Call to epoll_create1 failed: %s\n"), 5559 _ ("Call to epoll_create1 failed: %s\n"),
5510 MHD_socket_last_strerr_ ()); 5560 MHD_socket_last_strerr_ ());
5511#endif 5561#endif
5512 return MHD_INVALID_SOCKET; 5562 return MHD_INVALID_SOCKET;
5513 } 5563 }
5514#if !defined(USE_EPOLL_CREATE1) 5564#if ! defined(USE_EPOLL_CREATE1)
5515 if (! MHD_socket_noninheritable_ (fd)) 5565 if (! MHD_socket_noninheritable_ (fd))
5516 { 5566 {
5517#ifdef HAVE_MESSAGES 5567#ifdef HAVE_MESSAGES
5518 MHD_DLOG (daemon, 5568 MHD_DLOG (daemon,
5519 _("Failed to set noninheritable mode on epoll FD.\n")); 5569 _ ("Failed to set noninheritable mode on epoll FD.\n"));
5520#endif 5570#endif
5521 } 5571 }
5522#endif /* ! USE_EPOLL_CREATE1 */ 5572#endif /* ! USE_EPOLL_CREATE1 */
5523 return fd; 5573 return fd;
5524} 5574}
@@ -5544,11 +5594,11 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
5544 return MHD_NO; 5594 return MHD_NO;
5545#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 5595#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5546 if (0 != (MHD_ALLOW_UPGRADE & daemon->options)) 5596 if (0 != (MHD_ALLOW_UPGRADE & daemon->options))
5547 { 5597 {
5548 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon); 5598 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
5549 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd) 5599 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd)
5550 return MHD_NO; 5600 return MHD_NO;
5551 } 5601 }
5552#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 5602#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
5553 if ( (MHD_INVALID_SOCKET == (ls = daemon->listen_fd)) || 5603 if ( (MHD_INVALID_SOCKET == (ls = daemon->listen_fd)) ||
5554 (daemon->was_quiesced) ) 5604 (daemon->was_quiesced) )
@@ -5556,35 +5606,35 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
5556 event.events = EPOLLIN; 5606 event.events = EPOLLIN;
5557 event.data.ptr = daemon; 5607 event.data.ptr = daemon;
5558 if (0 != epoll_ctl (daemon->epoll_fd, 5608 if (0 != epoll_ctl (daemon->epoll_fd,
5559 EPOLL_CTL_ADD, 5609 EPOLL_CTL_ADD,
5560 ls, 5610 ls,
5561 &event)) 5611 &event))
5562 { 5612 {
5563#ifdef HAVE_MESSAGES 5613#ifdef HAVE_MESSAGES
5564 MHD_DLOG (daemon, 5614 MHD_DLOG (daemon,
5565 _("Call to epoll_ctl failed: %s\n"), 5615 _ ("Call to epoll_ctl failed: %s\n"),
5566 MHD_socket_last_strerr_ ()); 5616 MHD_socket_last_strerr_ ());
5567#endif 5617#endif
5568 return MHD_NO; 5618 return MHD_NO;
5569 } 5619 }
5570 daemon->listen_socket_in_epoll = true; 5620 daemon->listen_socket_in_epoll = true;
5571 if (MHD_ITC_IS_VALID_(daemon->itc)) 5621 if (MHD_ITC_IS_VALID_ (daemon->itc))
5622 {
5623 event.events = EPOLLIN;
5624 event.data.ptr = (void *) epoll_itc_marker;
5625 if (0 != epoll_ctl (daemon->epoll_fd,
5626 EPOLL_CTL_ADD,
5627 MHD_itc_r_fd_ (daemon->itc),
5628 &event))
5572 { 5629 {
5573 event.events = EPOLLIN;
5574 event.data.ptr = (void *) epoll_itc_marker;
5575 if (0 != epoll_ctl (daemon->epoll_fd,
5576 EPOLL_CTL_ADD,
5577 MHD_itc_r_fd_ (daemon->itc),
5578 &event))
5579 {
5580#ifdef HAVE_MESSAGES 5630#ifdef HAVE_MESSAGES
5581 MHD_DLOG (daemon, 5631 MHD_DLOG (daemon,
5582 _("Call to epoll_ctl failed: %s\n"), 5632 _ ("Call to epoll_ctl failed: %s\n"),
5583 MHD_socket_last_strerr_ ()); 5633 MHD_socket_last_strerr_ ());
5584#endif 5634#endif
5585 return MHD_NO; 5635 return MHD_NO;
5586 }
5587 } 5636 }
5637 }
5588 return MHD_YES; 5638 return MHD_YES;
5589} 5639}
5590#endif 5640#endif
@@ -5618,7 +5668,7 @@ MHD_start_daemon_va (unsigned int flags,
5618 void *apc_cls, 5668 void *apc_cls,
5619 MHD_AccessHandlerCallback dh, 5669 MHD_AccessHandlerCallback dh,
5620 void *dh_cls, 5670 void *dh_cls,
5621 va_list ap) 5671 va_list ap)
5622{ 5672{
5623 const MHD_SCKT_OPT_BOOL_ on = 1; 5673 const MHD_SCKT_OPT_BOOL_ on = 1;
5624 struct MHD_Daemon *daemon; 5674 struct MHD_Daemon *daemon;
@@ -5635,7 +5685,7 @@ MHD_start_daemon_va (unsigned int flags,
5635 enum MHD_FLAG eflags; /* same type as in MHD_Daemon */ 5685 enum MHD_FLAG eflags; /* same type as in MHD_Daemon */
5636 enum MHD_FLAG *pflags; 5686 enum MHD_FLAG *pflags;
5637 5687
5638 MHD_check_global_init_(); 5688 MHD_check_global_init_ ();
5639 eflags = (enum MHD_FLAG) flags; 5689 eflags = (enum MHD_FLAG) flags;
5640 pflags = &eflags; 5690 pflags = &eflags;
5641#ifndef HAVE_INET6 5691#ifndef HAVE_INET6
@@ -5659,56 +5709,61 @@ MHD_start_daemon_va (unsigned int flags,
5659 return NULL; 5709 return NULL;
5660#endif 5710#endif
5661 if (0 != (*pflags & MHD_ALLOW_UPGRADE)) 5711 if (0 != (*pflags & MHD_ALLOW_UPGRADE))
5662 { 5712 {
5663#ifdef UPGRADE_SUPPORT 5713#ifdef UPGRADE_SUPPORT
5664 *pflags |= MHD_ALLOW_SUSPEND_RESUME; 5714 *pflags |= MHD_ALLOW_SUSPEND_RESUME;
5665#else /* ! UPGRADE_SUPPORT */ 5715#else /* ! UPGRADE_SUPPORT */
5666 return NULL; 5716 return NULL;
5667#endif /* ! UPGRADE_SUPPORT */ 5717#endif /* ! UPGRADE_SUPPORT */
5668 } 5718 }
5669 if (NULL == dh) 5719 if (NULL == dh)
5670 return NULL; 5720 return NULL;
5671 5721
5672 /* Check for invalid combinations of flags. */ 5722 /* Check for invalid combinations of flags. */
5673 if ( ((0 != (*pflags & MHD_USE_POLL)) && (0 != (*pflags & MHD_USE_EPOLL))) || 5723 if ( ((0 != (*pflags & MHD_USE_POLL)) && (0 != (*pflags & MHD_USE_EPOLL))) ||
5674 ((0 != (*pflags & MHD_USE_EPOLL)) && (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION))) || 5724 ((0 != (*pflags & MHD_USE_EPOLL)) && (0 != (*pflags
5725 &
5726 MHD_USE_THREAD_PER_CONNECTION)))
5727 ||
5675 ((0 != (*pflags & MHD_USE_POLL)) && 5728 ((0 != (*pflags & MHD_USE_POLL)) &&
5676 (0 == (*pflags & (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION)))) || 5729 (0 == (*pflags & (MHD_USE_INTERNAL_POLLING_THREAD
5677 ((0 != (*pflags & MHD_USE_AUTO)) && (0 != (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL)))) ) 5730 | MHD_USE_THREAD_PER_CONNECTION)))) ||
5731 ((0 != (*pflags & MHD_USE_AUTO)) && (0 != (*pflags & (MHD_USE_POLL
5732 | MHD_USE_EPOLL)))) )
5678 return NULL; 5733 return NULL;
5679 5734
5680 if (0 != (*pflags & MHD_USE_AUTO)) 5735 if (0 != (*pflags & MHD_USE_AUTO))
5736 {
5737 if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION))
5681 { 5738 {
5682 if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) 5739 /* Thread per connection with internal polling thread. */
5683 {
5684 /* Thread per connection with internal polling thread. */
5685#ifdef HAVE_POLL 5740#ifdef HAVE_POLL
5686 *pflags |= MHD_USE_POLL; 5741 *pflags |= MHD_USE_POLL;
5687#else /* ! HAVE_POLL */ 5742#else /* ! HAVE_POLL */
5688 /* use select() - do not modify flags */ 5743 /* use select() - do not modify flags */
5689#endif /* ! HAVE_POLL */ 5744#endif /* ! HAVE_POLL */
5690 } 5745 }
5691 else if (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) 5746 else if (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD))
5692 { 5747 {
5693 /* Internal polling thread. */ 5748 /* Internal polling thread. */
5694#if defined(EPOLL_SUPPORT) 5749#if defined(EPOLL_SUPPORT)
5695 *pflags |= MHD_USE_EPOLL; 5750 *pflags |= MHD_USE_EPOLL;
5696#elif defined(HAVE_POLL) 5751#elif defined(HAVE_POLL)
5697 *pflags |= MHD_USE_POLL; 5752 *pflags |= MHD_USE_POLL;
5698#else /* !HAVE_POLL && !EPOLL_SUPPORT */ 5753#else /* !HAVE_POLL && !EPOLL_SUPPORT */
5699 /* use select() - do not modify flags */ 5754 /* use select() - do not modify flags */
5700#endif /* !HAVE_POLL && !EPOLL_SUPPORT */ 5755#endif /* !HAVE_POLL && !EPOLL_SUPPORT */
5701 } 5756 }
5702 else 5757 else
5703 { 5758 {
5704 /* Internal threads are not used - "external" polling mode. */ 5759 /* Internal threads are not used - "external" polling mode. */
5705#if defined(EPOLL_SUPPORT) 5760#if defined(EPOLL_SUPPORT)
5706 *pflags |= MHD_USE_EPOLL; 5761 *pflags |= MHD_USE_EPOLL;
5707#else /* ! EPOLL_SUPPORT */ 5762#else /* ! EPOLL_SUPPORT */
5708 /* use select() - do not modify flags */ 5763 /* use select() - do not modify flags */
5709#endif /* ! EPOLL_SUPPORT */ 5764#endif /* ! EPOLL_SUPPORT */
5710 }
5711 } 5765 }
5766 }
5712 5767
5713 if (NULL == (daemon = MHD_calloc_ (1, sizeof (struct MHD_Daemon)))) 5768 if (NULL == (daemon = MHD_calloc_ (1, sizeof (struct MHD_Daemon))))
5714 return NULL; 5769 return NULL;
@@ -5722,17 +5777,18 @@ MHD_start_daemon_va (unsigned int flags,
5722#ifdef HTTPS_SUPPORT 5777#ifdef HTTPS_SUPPORT
5723 daemon->priority_cache = NULL; 5778 daemon->priority_cache = NULL;
5724 if (0 != (*pflags & MHD_USE_TLS)) 5779 if (0 != (*pflags & MHD_USE_TLS))
5725 { 5780 {
5726 gnutls_priority_init (&daemon->priority_cache, 5781 gnutls_priority_init (&daemon->priority_cache,
5727 "NORMAL", 5782 "NORMAL",
5728 NULL); 5783 NULL);
5729 } 5784 }
5730#endif /* HTTPS_SUPPORT */ 5785#endif /* HTTPS_SUPPORT */
5731 daemon->listen_fd = MHD_INVALID_SOCKET; 5786 daemon->listen_fd = MHD_INVALID_SOCKET;
5732 daemon->listening_address_reuse = 0; 5787 daemon->listening_address_reuse = 0;
5733 daemon->options = *pflags; 5788 daemon->options = *pflags;
5734 pflags = &daemon->options; 5789 pflags = &daemon->options;
5735 daemon->strict_for_client = (0 != (*pflags & MHD_USE_PEDANTIC_CHECKS)) ? 1 : 0; 5790 daemon->strict_for_client = (0 != (*pflags & MHD_USE_PEDANTIC_CHECKS)) ? 1 :
5791 0;
5736 daemon->port = port; 5792 daemon->port = port;
5737 daemon->apc = apc; 5793 daemon->apc = apc;
5738 daemon->apc_cls = apc_cls; 5794 daemon->apc_cls = apc_cls;
@@ -5756,24 +5812,25 @@ MHD_start_daemon_va (unsigned int flags,
5756#endif 5812#endif
5757 if ( (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) && 5813 if ( (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) &&
5758 (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) ) 5814 (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) )
5759 { 5815 {
5760#ifdef HAVE_MESSAGES 5816#ifdef HAVE_MESSAGES
5761 MHD_DLOG (daemon, 5817 MHD_DLOG (daemon,
5762 _("Warning: MHD_USE_THREAD_PER_CONNECTION must be used only with " 5818 _ (
5763 "MHD_USE_INTERNAL_POLLING_THREAD. Flag MHD_USE_INTERNAL_POLLING_THREAD " 5819 "Warning: MHD_USE_THREAD_PER_CONNECTION must be used only with "
5764 "was added. Consider setting MHD_USE_INTERNAL_POLLING_THREAD explicitly.\n")); 5820 "MHD_USE_INTERNAL_POLLING_THREAD. Flag MHD_USE_INTERNAL_POLLING_THREAD "
5821 "was added. Consider setting MHD_USE_INTERNAL_POLLING_THREAD explicitly.\n"));
5765#endif 5822#endif
5766 *pflags |= MHD_USE_INTERNAL_POLLING_THREAD; 5823 *pflags |= MHD_USE_INTERNAL_POLLING_THREAD;
5767 } 5824 }
5768 if (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) 5825 if (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD))
5769 *pflags &= ~MHD_USE_ITC; /* useless if we are using 'external' select */ 5826 *pflags &= ~MHD_USE_ITC; /* useless if we are using 'external' select */
5770 else 5827 else
5771 { 5828 {
5772#ifdef HAVE_LISTEN_SHUTDOWN 5829#ifdef HAVE_LISTEN_SHUTDOWN
5773 if (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET)) 5830 if (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET))
5774#endif 5831#endif
5775 *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */ 5832 *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */
5776 } 5833 }
5777#ifdef DAUTH_SUPPORT 5834#ifdef DAUTH_SUPPORT
5778 daemon->digest_auth_rand_size = 0; 5835 daemon->digest_auth_rand_size = 0;
5779 daemon->digest_auth_random = NULL; 5836 daemon->digest_auth_random = NULL;
@@ -5781,24 +5838,24 @@ MHD_start_daemon_va (unsigned int flags,
5781#endif 5838#endif
5782#ifdef HTTPS_SUPPORT 5839#ifdef HTTPS_SUPPORT
5783 if (0 != (*pflags & MHD_USE_TLS)) 5840 if (0 != (*pflags & MHD_USE_TLS))
5784 { 5841 {
5785 daemon->cred_type = GNUTLS_CRD_CERTIFICATE; 5842 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
5786 } 5843 }
5787#endif /* HTTPS_SUPPORT */ 5844#endif /* HTTPS_SUPPORT */
5788 5845
5789 5846
5790 if (MHD_YES != parse_options_va (daemon, 5847 if (MHD_YES != parse_options_va (daemon,
5791 &servaddr, 5848 &servaddr,
5792 ap)) 5849 ap))
5793 { 5850 {
5794#ifdef HTTPS_SUPPORT 5851#ifdef HTTPS_SUPPORT
5795 if ( (0 != (*pflags & MHD_USE_TLS)) && 5852 if ( (0 != (*pflags & MHD_USE_TLS)) &&
5796 (NULL != daemon->priority_cache) ) 5853 (NULL != daemon->priority_cache) )
5797 gnutls_priority_deinit (daemon->priority_cache); 5854 gnutls_priority_deinit (daemon->priority_cache);
5798#endif /* HTTPS_SUPPORT */ 5855#endif /* HTTPS_SUPPORT */
5799 free (daemon); 5856 free (daemon);
5800 return NULL; 5857 return NULL;
5801 } 5858 }
5802 5859
5803 if ( (NULL != daemon->notify_completed) && 5860 if ( (NULL != daemon->notify_completed) &&
5804 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) 5861 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) )
@@ -5807,7 +5864,7 @@ MHD_start_daemon_va (unsigned int flags,
5807#ifndef NDEBUG 5864#ifndef NDEBUG
5808#ifdef HAVE_MESSAGES 5865#ifdef HAVE_MESSAGES
5809 MHD_DLOG (daemon, 5866 MHD_DLOG (daemon,
5810 _("Using debug build of libmicrohttpd.\n") ); 5867 _ ("Using debug build of libmicrohttpd.\n") );
5811#endif /* HAVE_MESSAGES */ 5868#endif /* HAVE_MESSAGES */
5812#endif /* ! NDEBUG */ 5869#endif /* ! NDEBUG */
5813 5870
@@ -5816,466 +5873,471 @@ MHD_start_daemon_va (unsigned int flags,
5816 && (0 == daemon->worker_pool_size) 5873 && (0 == daemon->worker_pool_size)
5817#endif 5874#endif
5818 ) 5875 )
5876 {
5877 if (! MHD_itc_init_ (daemon->itc))
5819 { 5878 {
5820 if (! MHD_itc_init_ (daemon->itc))
5821 {
5822#ifdef HAVE_MESSAGES 5879#ifdef HAVE_MESSAGES
5823 MHD_DLOG (daemon, 5880 MHD_DLOG (daemon,
5824 _("Failed to create inter-thread communication channel: %s\n"), 5881 _ ("Failed to create inter-thread communication channel: %s\n"),
5825 MHD_itc_last_strerror_ ()); 5882 MHD_itc_last_strerror_ ());
5826#endif 5883#endif
5827#ifdef HTTPS_SUPPORT 5884#ifdef HTTPS_SUPPORT
5828 if (NULL != daemon->priority_cache) 5885 if (NULL != daemon->priority_cache)
5829 gnutls_priority_deinit (daemon->priority_cache); 5886 gnutls_priority_deinit (daemon->priority_cache);
5830#endif /* HTTPS_SUPPORT */ 5887#endif /* HTTPS_SUPPORT */
5831 free (daemon); 5888 free (daemon);
5832 return NULL; 5889 return NULL;
5833 } 5890 }
5834 if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) && 5891 if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) &&
5835 (! MHD_SCKT_FD_FITS_FDSET_(MHD_itc_r_fd_ (daemon->itc), 5892 (! MHD_SCKT_FD_FITS_FDSET_ (MHD_itc_r_fd_ (daemon->itc),
5836 NULL)) ) 5893 NULL)) )
5837 { 5894 {
5838#ifdef HAVE_MESSAGES 5895#ifdef HAVE_MESSAGES
5839 MHD_DLOG (daemon, 5896 MHD_DLOG (daemon,
5840 _("file descriptor for inter-thread communication channel exceeds maximum value\n")); 5897 _ (
5898 "file descriptor for inter-thread communication channel exceeds maximum value\n"));
5841#endif 5899#endif
5842 MHD_itc_destroy_chk_ (daemon->itc); 5900 MHD_itc_destroy_chk_ (daemon->itc);
5843#ifdef HTTPS_SUPPORT 5901#ifdef HTTPS_SUPPORT
5844 if (NULL != daemon->priority_cache) 5902 if (NULL != daemon->priority_cache)
5845 gnutls_priority_deinit (daemon->priority_cache); 5903 gnutls_priority_deinit (daemon->priority_cache);
5846#endif /* HTTPS_SUPPORT */ 5904#endif /* HTTPS_SUPPORT */
5847 free (daemon); 5905 free (daemon);
5848 return NULL; 5906 return NULL;
5849 }
5850 } 5907 }
5908 }
5851 5909
5852#ifdef DAUTH_SUPPORT 5910#ifdef DAUTH_SUPPORT
5853 if (daemon->nonce_nc_size > 0) 5911 if (daemon->nonce_nc_size > 0)
5912 {
5913 if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc)))
5914 / sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size)
5854 { 5915 {
5855 if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) /
5856 sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size)
5857 {
5858#ifdef HAVE_MESSAGES 5916#ifdef HAVE_MESSAGES
5859 MHD_DLOG (daemon, 5917 MHD_DLOG (daemon,
5860 _("Specified value for NC_SIZE too large\n")); 5918 _ ("Specified value for NC_SIZE too large\n"));
5861#endif 5919#endif
5862#ifdef HTTPS_SUPPORT 5920#ifdef HTTPS_SUPPORT
5863 if (0 != (*pflags & MHD_USE_TLS)) 5921 if (0 != (*pflags & MHD_USE_TLS))
5864 gnutls_priority_deinit (daemon->priority_cache); 5922 gnutls_priority_deinit (daemon->priority_cache);
5865#endif /* HTTPS_SUPPORT */ 5923#endif /* HTTPS_SUPPORT */
5866 free (daemon); 5924 free (daemon);
5867 return NULL; 5925 return NULL;
5868 } 5926 }
5869 daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc)); 5927 daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc));
5870 if (NULL == daemon->nnc) 5928 if (NULL == daemon->nnc)
5871 { 5929 {
5872#ifdef HAVE_MESSAGES 5930#ifdef HAVE_MESSAGES
5873 MHD_DLOG (daemon, 5931 MHD_DLOG (daemon,
5874 _("Failed to allocate memory for nonce-nc map: %s\n"), 5932 _ ("Failed to allocate memory for nonce-nc map: %s\n"),
5875 MHD_strerror_ (errno)); 5933 MHD_strerror_ (errno));
5876#endif 5934#endif
5877#ifdef HTTPS_SUPPORT 5935#ifdef HTTPS_SUPPORT
5878 if (0 != (*pflags & MHD_USE_TLS)) 5936 if (0 != (*pflags & MHD_USE_TLS))
5879 gnutls_priority_deinit (daemon->priority_cache); 5937 gnutls_priority_deinit (daemon->priority_cache);
5880#endif /* HTTPS_SUPPORT */ 5938#endif /* HTTPS_SUPPORT */
5881 free (daemon); 5939 free (daemon);
5882 return NULL; 5940 return NULL;
5883 }
5884 } 5941 }
5942 }
5885 5943
5886#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 5944#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5887 if (! MHD_mutex_init_ (&daemon->nnc_lock)) 5945 if (! MHD_mutex_init_ (&daemon->nnc_lock))
5888 { 5946 {
5889#ifdef HAVE_MESSAGES 5947#ifdef HAVE_MESSAGES
5890 MHD_DLOG (daemon, 5948 MHD_DLOG (daemon,
5891 _("MHD failed to initialize nonce-nc mutex\n")); 5949 _ ("MHD failed to initialize nonce-nc mutex\n"));
5892#endif 5950#endif
5893#ifdef HTTPS_SUPPORT 5951#ifdef HTTPS_SUPPORT
5894 if (0 != (*pflags & MHD_USE_TLS)) 5952 if (0 != (*pflags & MHD_USE_TLS))
5895 gnutls_priority_deinit (daemon->priority_cache); 5953 gnutls_priority_deinit (daemon->priority_cache);
5896#endif /* HTTPS_SUPPORT */ 5954#endif /* HTTPS_SUPPORT */
5897 free (daemon->nnc); 5955 free (daemon->nnc);
5898 free (daemon); 5956 free (daemon);
5899 return NULL; 5957 return NULL;
5900 } 5958 }
5901#endif 5959#endif
5902#endif 5960#endif
5903 5961
5904 /* Thread pooling currently works only with internal select thread mode */ 5962 /* Thread pooling currently works only with internal select thread mode */
5905#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 5963#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5906 if ( (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && 5964 if ( (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) &&
5907 (daemon->worker_pool_size > 0) ) 5965 (daemon->worker_pool_size > 0) )
5908 { 5966 {
5909#ifdef HAVE_MESSAGES 5967#ifdef HAVE_MESSAGES
5910 MHD_DLOG (daemon, 5968 MHD_DLOG (daemon,
5911 _("MHD thread pooling only works with MHD_USE_INTERNAL_POLLING_THREAD\n")); 5969 _ (
5970 "MHD thread pooling only works with MHD_USE_INTERNAL_POLLING_THREAD\n"));
5912#endif 5971#endif
5913 goto free_and_fail; 5972 goto free_and_fail;
5914 } 5973 }
5915#endif 5974#endif
5916 if ( (MHD_INVALID_SOCKET == daemon->listen_fd) && 5975 if ( (MHD_INVALID_SOCKET == daemon->listen_fd) &&
5917 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) 5976 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) )
5918 { 5977 {
5919 /* try to open listen socket */ 5978 /* try to open listen socket */
5920 int domain; 5979 int domain;
5921 5980
5922#ifdef HAVE_INET6 5981#ifdef HAVE_INET6
5923 domain = (*pflags & MHD_USE_IPv6) ? PF_INET6 : PF_INET; 5982 domain = (*pflags & MHD_USE_IPv6) ? PF_INET6 : PF_INET;
5924#else /* ! HAVE_INET6 */ 5983#else /* ! HAVE_INET6 */
5925 if (*pflags & MHD_USE_IPv6) 5984 if (*pflags & MHD_USE_IPv6)
5926 goto free_and_fail; 5985 goto free_and_fail;
5927 domain = PF_INET; 5986 domain = PF_INET;
5928#endif /* ! HAVE_INET6 */ 5987#endif /* ! HAVE_INET6 */
5929 5988
5930 listen_fd = MHD_socket_create_listen_(domain); 5989 listen_fd = MHD_socket_create_listen_ (domain);
5931 if (MHD_INVALID_SOCKET == listen_fd) 5990 if (MHD_INVALID_SOCKET == listen_fd)
5932 { 5991 {
5933#ifdef HAVE_MESSAGES 5992#ifdef HAVE_MESSAGES
5934 MHD_DLOG (daemon, 5993 MHD_DLOG (daemon,
5935 _("Failed to create socket for listening: %s\n"), 5994 _ ("Failed to create socket for listening: %s\n"),
5936 MHD_socket_last_strerr_ ()); 5995 MHD_socket_last_strerr_ ());
5937#endif 5996#endif
5938 goto free_and_fail; 5997 goto free_and_fail;
5939 } 5998 }
5940 5999
5941 /* Apply the socket options according to listening_address_reuse. */ 6000 /* Apply the socket options according to listening_address_reuse. */
5942 if (0 == daemon->listening_address_reuse) 6001 if (0 == daemon->listening_address_reuse)
5943 { 6002 {
5944#ifndef MHD_WINSOCK_SOCKETS 6003#ifndef MHD_WINSOCK_SOCKETS
5945 /* No user requirement, use "traditional" default SO_REUSEADDR 6004 /* No user requirement, use "traditional" default SO_REUSEADDR
5946 * on non-W32 platforms, and do not fail if it doesn't work. 6005 * on non-W32 platforms, and do not fail if it doesn't work.
5947 * Don't use it on W32, because on W32 it will allow multiple 6006 * Don't use it on W32, because on W32 it will allow multiple
5948 * bind to the same address:port, like SO_REUSEPORT on others. */ 6007 * bind to the same address:port, like SO_REUSEPORT on others. */
5949 if (0 > setsockopt (listen_fd, 6008 if (0 > setsockopt (listen_fd,
5950 SOL_SOCKET, 6009 SOL_SOCKET,
5951 SO_REUSEADDR, 6010 SO_REUSEADDR,
5952 (void*)&on, sizeof (on))) 6011 (void*) &on, sizeof (on)))
5953 { 6012 {
5954#ifdef HAVE_MESSAGES 6013#ifdef HAVE_MESSAGES
5955 MHD_DLOG (daemon, 6014 MHD_DLOG (daemon,
5956 _("setsockopt failed: %s\n"), 6015 _ ("setsockopt failed: %s\n"),
5957 MHD_socket_last_strerr_ ()); 6016 MHD_socket_last_strerr_ ());
5958#endif 6017#endif
5959 } 6018 }
5960#endif /* ! MHD_WINSOCK_SOCKETS */ 6019#endif /* ! MHD_WINSOCK_SOCKETS */
5961 } 6020 }
5962 else if (daemon->listening_address_reuse > 0) 6021 else if (daemon->listening_address_reuse > 0)
5963 { 6022 {
5964 /* User requested to allow reusing listening address:port. */ 6023 /* User requested to allow reusing listening address:port. */
5965#ifndef MHD_WINSOCK_SOCKETS 6024#ifndef MHD_WINSOCK_SOCKETS
5966 /* Use SO_REUSEADDR on non-W32 platforms, and do not fail if 6025 /* Use SO_REUSEADDR on non-W32 platforms, and do not fail if
5967 * it doesn't work. */ 6026 * it doesn't work. */
5968 if (0 > setsockopt (listen_fd, 6027 if (0 > setsockopt (listen_fd,
5969 SOL_SOCKET, 6028 SOL_SOCKET,
5970 SO_REUSEADDR, 6029 SO_REUSEADDR,
5971 (void*)&on, sizeof (on))) 6030 (void*) &on, sizeof (on)))
5972 { 6031 {
5973#ifdef HAVE_MESSAGES 6032#ifdef HAVE_MESSAGES
5974 MHD_DLOG (daemon, 6033 MHD_DLOG (daemon,
5975 _("setsockopt failed: %s\n"), 6034 _ ("setsockopt failed: %s\n"),
5976 MHD_socket_last_strerr_ ()); 6035 MHD_socket_last_strerr_ ());
5977#endif 6036#endif
5978 } 6037 }
5979#endif /* ! MHD_WINSOCK_SOCKETS */ 6038#endif /* ! MHD_WINSOCK_SOCKETS */
5980 /* Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms. 6039 /* Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms.
5981 * Fail if SO_REUSEPORT is not defined or setsockopt fails. 6040 * Fail if SO_REUSEPORT is not defined or setsockopt fails.
5982 */ 6041 */
5983 /* SO_REUSEADDR on W32 has the same semantics 6042 /* SO_REUSEADDR on W32 has the same semantics
5984 as SO_REUSEPORT on BSD/Linux */ 6043 as SO_REUSEPORT on BSD/Linux */
5985#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT) 6044#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
5986 if (0 > setsockopt (listen_fd, 6045 if (0 > setsockopt (listen_fd,
5987 SOL_SOCKET, 6046 SOL_SOCKET,
5988#ifndef MHD_WINSOCK_SOCKETS 6047#ifndef MHD_WINSOCK_SOCKETS
5989 SO_REUSEPORT, 6048 SO_REUSEPORT,
5990#else /* MHD_WINSOCK_SOCKETS */ 6049#else /* MHD_WINSOCK_SOCKETS */
5991 SO_REUSEADDR, 6050 SO_REUSEADDR,
5992#endif /* MHD_WINSOCK_SOCKETS */ 6051#endif /* MHD_WINSOCK_SOCKETS */
5993 (void *) &on, 6052 (void *) &on,
5994 sizeof (on))) 6053 sizeof (on)))
5995 { 6054 {
5996#ifdef HAVE_MESSAGES 6055#ifdef HAVE_MESSAGES
5997 MHD_DLOG (daemon, 6056 MHD_DLOG (daemon,
5998 _("setsockopt failed: %s\n"), 6057 _ ("setsockopt failed: %s\n"),
5999 MHD_socket_last_strerr_ ()); 6058 MHD_socket_last_strerr_ ());
6000#endif 6059#endif
6001 goto free_and_fail; 6060 goto free_and_fail;
6002 } 6061 }
6003#else /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */ 6062#else /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */
6004 /* we're supposed to allow address:port re-use, but 6063 /* we're supposed to allow address:port re-use, but
6005 on this platform we cannot; fail hard */ 6064 on this platform we cannot; fail hard */
6006#ifdef HAVE_MESSAGES 6065#ifdef HAVE_MESSAGES
6007 MHD_DLOG (daemon, 6066 MHD_DLOG (daemon,
6008 _("Cannot allow listening address reuse: SO_REUSEPORT not defined\n")); 6067 _ (
6068 "Cannot allow listening address reuse: SO_REUSEPORT not defined\n"));
6009#endif 6069#endif
6010 goto free_and_fail; 6070 goto free_and_fail;
6011#endif /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */ 6071#endif /* !MHD_WINSOCK_SOCKETS && !SO_REUSEPORT */
6012 } 6072 }
6013 else /* if (daemon->listening_address_reuse < 0) */ 6073 else /* if (daemon->listening_address_reuse < 0) */
6014 { 6074 {
6015 /* User requested to disallow reusing listening address:port. 6075 /* User requested to disallow reusing listening address:port.
6016 * Do nothing except for Windows where SO_EXCLUSIVEADDRUSE 6076 * Do nothing except for Windows where SO_EXCLUSIVEADDRUSE
6017 * is used and Solaris with SO_EXCLBIND. 6077 * is used and Solaris with SO_EXCLBIND.
6018 * Fail if MHD was compiled for W32 without SO_EXCLUSIVEADDRUSE 6078 * Fail if MHD was compiled for W32 without SO_EXCLUSIVEADDRUSE
6019 * or setsockopt fails. 6079 * or setsockopt fails.
6020 */ 6080 */
6021#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \ 6081#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
6022 (defined(__sun) && defined(SO_EXCLBIND)) 6082 (defined(__sun) && defined(SO_EXCLBIND))
6023 if (0 > setsockopt (listen_fd, 6083 if (0 > setsockopt (listen_fd,
6024 SOL_SOCKET, 6084 SOL_SOCKET,
6025#ifdef SO_EXCLUSIVEADDRUSE 6085#ifdef SO_EXCLUSIVEADDRUSE
6026 SO_EXCLUSIVEADDRUSE, 6086 SO_EXCLUSIVEADDRUSE,
6027#else /* SO_EXCLBIND */ 6087#else /* SO_EXCLBIND */
6028 SO_EXCLBIND, 6088 SO_EXCLBIND,
6029#endif /* SO_EXCLBIND */ 6089#endif /* SO_EXCLBIND */
6030 (void *) &on, 6090 (void *) &on,
6031 sizeof (on))) 6091 sizeof (on)))
6032 { 6092 {
6033#ifdef HAVE_MESSAGES 6093#ifdef HAVE_MESSAGES
6034 MHD_DLOG (daemon, 6094 MHD_DLOG (daemon,
6035 _("setsockopt failed: %s\n"), 6095 _ ("setsockopt failed: %s\n"),
6036 MHD_socket_last_strerr_ ()); 6096 MHD_socket_last_strerr_ ());
6037#endif 6097#endif
6038 goto free_and_fail; 6098 goto free_and_fail;
6039 } 6099 }
6040#elif defined(MHD_WINSOCK_SOCKETS) /* SO_EXCLUSIVEADDRUSE not defined on W32? */ 6100#elif defined(MHD_WINSOCK_SOCKETS) /* SO_EXCLUSIVEADDRUSE not defined on W32? */
6041#ifdef HAVE_MESSAGES 6101#ifdef HAVE_MESSAGES
6042 MHD_DLOG (daemon, 6102 MHD_DLOG (daemon,
6043 _("Cannot disallow listening address reuse: SO_EXCLUSIVEADDRUSE not defined\n")); 6103 _ (
6104 "Cannot disallow listening address reuse: SO_EXCLUSIVEADDRUSE not defined\n"));
6044#endif 6105#endif
6045 goto free_and_fail; 6106 goto free_and_fail;
6046#endif /* MHD_WINSOCK_SOCKETS */ 6107#endif /* MHD_WINSOCK_SOCKETS */
6047 } 6108 }
6048 6109
6049 /* check for user supplied sockaddr */ 6110 /* check for user supplied sockaddr */
6050#if HAVE_INET6 6111#if HAVE_INET6
6051 if (0 != (*pflags & MHD_USE_IPv6)) 6112 if (0 != (*pflags & MHD_USE_IPv6))
6052 addrlen = sizeof (struct sockaddr_in6); 6113 addrlen = sizeof (struct sockaddr_in6);
6053 else 6114 else
6054#endif 6115#endif
6055 addrlen = sizeof (struct sockaddr_in); 6116 addrlen = sizeof (struct sockaddr_in);
6056 if (NULL == servaddr) 6117 if (NULL == servaddr)
6057 { 6118 {
6058#if HAVE_INET6 6119#if HAVE_INET6
6059 if (0 != (*pflags & MHD_USE_IPv6)) 6120 if (0 != (*pflags & MHD_USE_IPv6))
6060 { 6121 {
6061#ifdef IN6ADDR_ANY_INIT 6122#ifdef IN6ADDR_ANY_INIT
6062 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT; 6123 static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT;
6063#endif 6124#endif
6064 memset (&servaddr6, 6125 memset (&servaddr6,
6065 0, 6126 0,
6066 sizeof (struct sockaddr_in6)); 6127 sizeof (struct sockaddr_in6));
6067 servaddr6.sin6_family = AF_INET6; 6128 servaddr6.sin6_family = AF_INET6;
6068 servaddr6.sin6_port = htons (port); 6129 servaddr6.sin6_port = htons (port);
6069#ifdef IN6ADDR_ANY_INIT 6130#ifdef IN6ADDR_ANY_INIT
6070 servaddr6.sin6_addr = static_in6any; 6131 servaddr6.sin6_addr = static_in6any;
6071#endif 6132#endif
6072#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 6133#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
6073 servaddr6.sin6_len = sizeof (struct sockaddr_in6); 6134 servaddr6.sin6_len = sizeof (struct sockaddr_in6);
6074#endif 6135#endif
6075 servaddr = (struct sockaddr *) &servaddr6; 6136 servaddr = (struct sockaddr *) &servaddr6;
6076 } 6137 }
6077 else 6138 else
6078#endif 6139#endif
6079 { 6140 {
6080 memset (&servaddr4, 6141 memset (&servaddr4,
6081 0, 6142 0,
6082 sizeof (struct sockaddr_in)); 6143 sizeof (struct sockaddr_in));
6083 servaddr4.sin_family = AF_INET; 6144 servaddr4.sin_family = AF_INET;
6084 servaddr4.sin_port = htons (port); 6145 servaddr4.sin_port = htons (port);
6085 if (0 != INADDR_ANY) 6146 if (0 != INADDR_ANY)
6086 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY); 6147 servaddr4.sin_addr.s_addr = htonl (INADDR_ANY);
6087#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 6148#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
6088 servaddr4.sin_len = sizeof (struct sockaddr_in); 6149 servaddr4.sin_len = sizeof (struct sockaddr_in);
6089#endif 6150#endif
6090 servaddr = (struct sockaddr *) &servaddr4; 6151 servaddr = (struct sockaddr *) &servaddr4;
6091 } 6152 }
6092 } 6153 }
6093 daemon->listen_fd = listen_fd; 6154 daemon->listen_fd = listen_fd;
6094 6155
6095 if (0 != (*pflags & MHD_USE_IPv6)) 6156 if (0 != (*pflags & MHD_USE_IPv6))
6096 { 6157 {
6097#ifdef IPPROTO_IPV6 6158#ifdef IPPROTO_IPV6
6098#ifdef IPV6_V6ONLY 6159#ifdef IPV6_V6ONLY
6099 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options" 6160 /* Note: "IPV6_V6ONLY" is declared by Windows Vista ff., see "IPPROTO_IPV6 Socket Options"
6100 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx); 6161 (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx);
6101 and may also be missing on older POSIX systems; good luck if you have any of those, 6162 and may also be missing on older POSIX systems; good luck if you have any of those,
6102 your IPv6 socket may then also bind against IPv4 anyway... */ 6163 your IPv6 socket may then also bind against IPv4 anyway... */
6103 const MHD_SCKT_OPT_BOOL_ v6_only = 6164 const MHD_SCKT_OPT_BOOL_ v6_only =
6104 (MHD_USE_DUAL_STACK != (*pflags & MHD_USE_DUAL_STACK)); 6165 (MHD_USE_DUAL_STACK != (*pflags & MHD_USE_DUAL_STACK));
6105 if (0 > setsockopt (listen_fd, 6166 if (0 > setsockopt (listen_fd,
6106 IPPROTO_IPV6, IPV6_V6ONLY, 6167 IPPROTO_IPV6, IPV6_V6ONLY,
6107 (const void *) &v6_only, 6168 (const void *) &v6_only,
6108 sizeof (v6_only))) 6169 sizeof (v6_only)))
6109 { 6170 {
6110#ifdef HAVE_MESSAGES 6171#ifdef HAVE_MESSAGES
6111 MHD_DLOG (daemon, 6172 MHD_DLOG (daemon,
6112 _("setsockopt failed: %s\n"), 6173 _ ("setsockopt failed: %s\n"),
6113 MHD_socket_last_strerr_ ()); 6174 MHD_socket_last_strerr_ ());
6114#endif 6175#endif
6115 } 6176 }
6116#endif 6177#endif
6117#endif 6178#endif
6118 } 6179 }
6119 if (-1 == bind (listen_fd, servaddr, addrlen)) 6180 if (-1 == bind (listen_fd, servaddr, addrlen))
6120 { 6181 {
6121#ifdef HAVE_MESSAGES 6182#ifdef HAVE_MESSAGES
6122 MHD_DLOG (daemon, 6183 MHD_DLOG (daemon,
6123 _("Failed to bind to port %u: %s\n"), 6184 _ ("Failed to bind to port %u: %s\n"),
6124 (unsigned int) port, 6185 (unsigned int) port,
6125 MHD_socket_last_strerr_ ()); 6186 MHD_socket_last_strerr_ ());
6126#endif 6187#endif
6127 MHD_socket_close_chk_ (listen_fd); 6188 MHD_socket_close_chk_ (listen_fd);
6128 goto free_and_fail; 6189 goto free_and_fail;
6129 } 6190 }
6130#ifdef TCP_FASTOPEN 6191#ifdef TCP_FASTOPEN
6131 if (0 != (*pflags & MHD_USE_TCP_FASTOPEN)) 6192 if (0 != (*pflags & MHD_USE_TCP_FASTOPEN))
6193 {
6194 if (0 == daemon->fastopen_queue_size)
6195 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
6196 if (0 != setsockopt (listen_fd,
6197 IPPROTO_TCP,
6198 TCP_FASTOPEN,
6199 (const void*) &daemon->fastopen_queue_size,
6200 sizeof (daemon->fastopen_queue_size)))
6132 { 6201 {
6133 if (0 == daemon->fastopen_queue_size)
6134 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT;
6135 if (0 != setsockopt (listen_fd,
6136 IPPROTO_TCP,
6137 TCP_FASTOPEN,
6138 (const void*)&daemon->fastopen_queue_size,
6139 sizeof (daemon->fastopen_queue_size)))
6140 {
6141#ifdef HAVE_MESSAGES 6202#ifdef HAVE_MESSAGES
6142 MHD_DLOG (daemon, 6203 MHD_DLOG (daemon,
6143 _("setsockopt failed: %s\n"), 6204 _ ("setsockopt failed: %s\n"),
6144 MHD_socket_last_strerr_ ()); 6205 MHD_socket_last_strerr_ ());
6145#endif 6206#endif
6146 }
6147 } 6207 }
6208 }
6148#endif 6209#endif
6149 if (listen (listen_fd, 6210 if (listen (listen_fd,
6150 daemon->listen_backlog_size) < 0) 6211 daemon->listen_backlog_size) < 0)
6151 { 6212 {
6152#ifdef HAVE_MESSAGES 6213#ifdef HAVE_MESSAGES
6153 MHD_DLOG (daemon, 6214 MHD_DLOG (daemon,
6154 _("Failed to listen for connections: %s\n"), 6215 _ ("Failed to listen for connections: %s\n"),
6155 MHD_socket_last_strerr_ ()); 6216 MHD_socket_last_strerr_ ());
6156#endif 6217#endif
6157 MHD_socket_close_chk_ (listen_fd); 6218 MHD_socket_close_chk_ (listen_fd);
6158 goto free_and_fail; 6219 goto free_and_fail;
6159 }
6160 } 6220 }
6221 }
6161 else 6222 else
6162 { 6223 {
6163 listen_fd = daemon->listen_fd; 6224 listen_fd = daemon->listen_fd;
6164 } 6225 }
6165 6226
6166#ifdef HAVE_GETSOCKNAME 6227#ifdef HAVE_GETSOCKNAME
6167 if ( (0 == daemon->port) && 6228 if ( (0 == daemon->port) &&
6168 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) 6229 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) )
6169 { /* Get port number. */ 6230 { /* Get port number. */
6170 struct sockaddr_storage bindaddr; 6231 struct sockaddr_storage bindaddr;
6171 6232
6172 memset (&bindaddr, 6233 memset (&bindaddr,
6173 0, 6234 0,
6174 sizeof (struct sockaddr_storage)); 6235 sizeof (struct sockaddr_storage));
6175 addrlen = sizeof (struct sockaddr_storage); 6236 addrlen = sizeof (struct sockaddr_storage);
6176#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 6237#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
6177 bindaddr.ss_len = addrlen; 6238 bindaddr.ss_len = addrlen;
6178#endif 6239#endif
6179 if (0 != getsockname (listen_fd, 6240 if (0 != getsockname (listen_fd,
6180 (struct sockaddr *) &bindaddr, 6241 (struct sockaddr *) &bindaddr,
6181 &addrlen)) 6242 &addrlen))
6182 { 6243 {
6183#ifdef HAVE_MESSAGES 6244#ifdef HAVE_MESSAGES
6184 MHD_DLOG (daemon, 6245 MHD_DLOG (daemon,
6185 _("Failed to get listen port number: %s\n"), 6246 _ ("Failed to get listen port number: %s\n"),
6186 MHD_socket_last_strerr_ ()); 6247 MHD_socket_last_strerr_ ());
6187#endif /* HAVE_MESSAGES */ 6248#endif /* HAVE_MESSAGES */
6188 } 6249 }
6189#ifdef MHD_POSIX_SOCKETS 6250#ifdef MHD_POSIX_SOCKETS
6190 else if (sizeof (bindaddr) < addrlen) 6251 else if (sizeof (bindaddr) < addrlen)
6191 { 6252 {
6192 /* should be impossible with `struct sockaddr_storage` */ 6253 /* should be impossible with `struct sockaddr_storage` */
6193#ifdef HAVE_MESSAGES 6254#ifdef HAVE_MESSAGES
6194 MHD_DLOG (daemon, 6255 MHD_DLOG (daemon,
6195 _("Failed to get listen port number (`struct sockaddr_storage` too small!?)\n")); 6256 _ (
6257 "Failed to get listen port number (`struct sockaddr_storage` too small!?)\n"));
6196#endif /* HAVE_MESSAGES */ 6258#endif /* HAVE_MESSAGES */
6197 } 6259 }
6198#ifndef __linux__ 6260#ifndef __linux__
6199 else if (0 == addrlen) 6261 else if (0 == addrlen)
6200 { 6262 {
6201 /* Many non-Linux-based platforms return zero addrlen 6263 /* Many non-Linux-based platforms return zero addrlen
6202 * for AF_UNIX sockets */ 6264 * for AF_UNIX sockets */
6203 daemon->port = 0; /* special value for UNIX domain sockets */ 6265 daemon->port = 0; /* special value for UNIX domain sockets */
6204 } 6266 }
6205#endif /* __linux__ */ 6267#endif /* __linux__ */
6206#endif /* MHD_POSIX_SOCKETS */ 6268#endif /* MHD_POSIX_SOCKETS */
6207 else 6269 else
6270 {
6271 switch (bindaddr.ss_family)
6272 {
6273 case AF_INET:
6208 { 6274 {
6209 switch (bindaddr.ss_family) 6275 struct sockaddr_in *s4 = (struct sockaddr_in *) &bindaddr;
6210 {
6211 case AF_INET:
6212 {
6213 struct sockaddr_in *s4 = (struct sockaddr_in *) &bindaddr;
6214 6276
6215 daemon->port = ntohs (s4->sin_port); 6277 daemon->port = ntohs (s4->sin_port);
6216 break; 6278 break;
6217 } 6279 }
6218#ifdef HAVE_INET6 6280#ifdef HAVE_INET6
6219 case AF_INET6: 6281 case AF_INET6:
6220 { 6282 {
6221 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &bindaddr; 6283 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &bindaddr;
6222 6284
6223 daemon->port = ntohs(s6->sin6_port); 6285 daemon->port = ntohs (s6->sin6_port);
6224 mhd_assert (0 != (*pflags & MHD_USE_IPv6)); 6286 mhd_assert (0 != (*pflags & MHD_USE_IPv6));
6225 break; 6287 break;
6226 } 6288 }
6227#endif /* HAVE_INET6 */ 6289#endif /* HAVE_INET6 */
6228#ifdef AF_UNIX 6290#ifdef AF_UNIX
6229 case AF_UNIX: 6291 case AF_UNIX:
6230 daemon->port = 0; /* special value for UNIX domain sockets */ 6292 daemon->port = 0; /* special value for UNIX domain sockets */
6231 break; 6293 break;
6232#endif 6294#endif
6233 default: 6295 default:
6234#ifdef HAVE_MESSAGES 6296#ifdef HAVE_MESSAGES
6235 MHD_DLOG (daemon, 6297 MHD_DLOG (daemon,
6236 _("Unknown address family!\n")); 6298 _ ("Unknown address family!\n"));
6237#endif 6299#endif
6238 daemon->port = 0; /* ugh */ 6300 daemon->port = 0; /* ugh */
6239 break; 6301 break;
6240 } 6302 }
6241 }
6242 } 6303 }
6304 }
6243#endif /* HAVE_GETSOCKNAME */ 6305#endif /* HAVE_GETSOCKNAME */
6244 if ( (MHD_INVALID_SOCKET != listen_fd) && 6306 if ( (MHD_INVALID_SOCKET != listen_fd) &&
6245 (! MHD_socket_nonblocking_ (listen_fd)) ) 6307 (! MHD_socket_nonblocking_ (listen_fd)) )
6246 { 6308 {
6247#ifdef HAVE_MESSAGES 6309#ifdef HAVE_MESSAGES
6248 MHD_DLOG (daemon, 6310 MHD_DLOG (daemon,
6249 _("Failed to set nonblocking mode on listening socket: %s\n"), 6311 _ ("Failed to set nonblocking mode on listening socket: %s\n"),
6250 MHD_socket_last_strerr_()); 6312 MHD_socket_last_strerr_ ());
6251#endif 6313#endif
6252 if (0 != (*pflags & MHD_USE_EPOLL) 6314 if (0 != (*pflags & MHD_USE_EPOLL)
6253#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6315#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6254 || (daemon->worker_pool_size > 0) 6316 || (daemon->worker_pool_size > 0)
6255#endif 6317#endif
6256 ) 6318 )
6257 { 6319 {
6258 /* Accept must be non-blocking. Multiple children may wake up 6320 /* Accept must be non-blocking. Multiple children may wake up
6259 * to handle a new connection, but only one will win the race. 6321 * to handle a new connection, but only one will win the race.
6260 * The others must immediately return. */ 6322 * The others must immediately return. */
6261 MHD_socket_close_chk_ (listen_fd); 6323 MHD_socket_close_chk_ (listen_fd);
6262 goto free_and_fail; 6324 goto free_and_fail;
6263 }
6264 } 6325 }
6326 }
6265 if ( (MHD_INVALID_SOCKET != listen_fd) && 6327 if ( (MHD_INVALID_SOCKET != listen_fd) &&
6266 (! MHD_SCKT_FD_FITS_FDSET_(listen_fd, 6328 (! MHD_SCKT_FD_FITS_FDSET_ (listen_fd,
6267 NULL)) && 6329 NULL)) &&
6268 (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL)) ) ) 6330 (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL)) ) )
6269 { 6331 {
6270#ifdef HAVE_MESSAGES 6332#ifdef HAVE_MESSAGES
6271 MHD_DLOG (daemon, 6333 MHD_DLOG (daemon,
6272 _("Socket descriptor larger than FD_SETSIZE: %d > %d\n"), 6334 _ ("Socket descriptor larger than FD_SETSIZE: %d > %d\n"),
6273 listen_fd, 6335 listen_fd,
6274 FD_SETSIZE); 6336 FD_SETSIZE);
6275#endif 6337#endif
6276 MHD_socket_close_chk_ (listen_fd); 6338 MHD_socket_close_chk_ (listen_fd);
6277 goto free_and_fail; 6339 goto free_and_fail;
6278 } 6340 }
6279 6341
6280#ifdef EPOLL_SUPPORT 6342#ifdef EPOLL_SUPPORT
6281 if ( (0 != (*pflags & MHD_USE_EPOLL)) 6343 if ( (0 != (*pflags & MHD_USE_EPOLL))
@@ -6283,193 +6345,197 @@ MHD_start_daemon_va (unsigned int flags,
6283 && (0 == daemon->worker_pool_size) 6345 && (0 == daemon->worker_pool_size)
6284#endif 6346#endif
6285 ) 6347 )
6348 {
6349 if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION))
6286 { 6350 {
6287 if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION))
6288 {
6289#ifdef HAVE_MESSAGES 6351#ifdef HAVE_MESSAGES
6290 MHD_DLOG (daemon, 6352 MHD_DLOG (daemon,
6291 _("Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_EPOLL is not supported.\n")); 6353 _ (
6354 "Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_EPOLL is not supported.\n"));
6292#endif 6355#endif
6293 goto free_and_fail; 6356 goto free_and_fail;
6294 }
6295 if (MHD_YES != setup_epoll_to_listen (daemon))
6296 goto free_and_fail;
6297 } 6357 }
6358 if (MHD_YES != setup_epoll_to_listen (daemon))
6359 goto free_and_fail;
6360 }
6298#endif /* EPOLL_SUPPORT */ 6361#endif /* EPOLL_SUPPORT */
6299 6362
6300#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6363#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6301 if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) 6364 if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex))
6302 { 6365 {
6303#ifdef HAVE_MESSAGES 6366#ifdef HAVE_MESSAGES
6304 MHD_DLOG (daemon, 6367 MHD_DLOG (daemon,
6305 _("MHD failed to initialize IP connection limit mutex\n")); 6368 _ ("MHD failed to initialize IP connection limit mutex\n"));
6306#endif 6369#endif
6307 if (MHD_INVALID_SOCKET != listen_fd) 6370 if (MHD_INVALID_SOCKET != listen_fd)
6308 MHD_socket_close_chk_ (listen_fd); 6371 MHD_socket_close_chk_ (listen_fd);
6309 goto free_and_fail; 6372 goto free_and_fail;
6310 } 6373 }
6311 if (0 == daemon->worker_pool_size) 6374 if (0 == daemon->worker_pool_size)
6312 { /* Initialise connection mutex only if this daemon will handle 6375 { /* Initialise connection mutex only if this daemon will handle
6313 * any connections by itself. */ 6376 * any connections by itself. */
6314 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) 6377 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
6315 { 6378 {
6316#ifdef HAVE_MESSAGES 6379#ifdef HAVE_MESSAGES
6317 MHD_DLOG (daemon, 6380 MHD_DLOG (daemon,
6318 _("MHD failed to initialize IP connection limit mutex\n")); 6381 _ ("MHD failed to initialize IP connection limit mutex\n"));
6319#endif 6382#endif
6320#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6383#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6321 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 6384 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
6322#endif 6385#endif
6323 if (MHD_INVALID_SOCKET != listen_fd) 6386 if (MHD_INVALID_SOCKET != listen_fd)
6324 MHD_socket_close_chk_ (listen_fd); 6387 MHD_socket_close_chk_ (listen_fd);
6325 goto free_and_fail; 6388 goto free_and_fail;
6326 }
6327 } 6389 }
6390 }
6328#endif 6391#endif
6329 6392
6330#ifdef HTTPS_SUPPORT 6393#ifdef HTTPS_SUPPORT
6331 /* initialize HTTPS daemon certificate aspects & send / recv functions */ 6394 /* initialize HTTPS daemon certificate aspects & send / recv functions */
6332 if ( (0 != (*pflags & MHD_USE_TLS)) && 6395 if ( (0 != (*pflags & MHD_USE_TLS)) &&
6333 (0 != MHD_TLS_init (daemon)) ) 6396 (0 != MHD_TLS_init (daemon)) )
6334 { 6397 {
6335#ifdef HAVE_MESSAGES 6398#ifdef HAVE_MESSAGES
6336 MHD_DLOG (daemon, 6399 MHD_DLOG (daemon,
6337 _("Failed to initialize TLS support\n")); 6400 _ ("Failed to initialize TLS support\n"));
6338#endif 6401#endif
6339 if (MHD_INVALID_SOCKET != listen_fd) 6402 if (MHD_INVALID_SOCKET != listen_fd)
6340 MHD_socket_close_chk_ (listen_fd); 6403 MHD_socket_close_chk_ (listen_fd);
6341#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6404#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6342 if (0 == daemon->worker_pool_size) 6405 if (0 == daemon->worker_pool_size)
6343 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 6406 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
6344 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); 6407 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
6345#endif 6408#endif
6346 goto free_and_fail; 6409 goto free_and_fail;
6347 } 6410 }
6348#endif /* HTTPS_SUPPORT */ 6411#endif /* HTTPS_SUPPORT */
6349#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6412#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6350 if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && 6413 if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) &&
6351 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) 6414 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) )
6415 {
6416 if (0 == daemon->worker_pool_size)
6352 { 6417 {
6353 if (0 == daemon->worker_pool_size) 6418 if (! MHD_create_named_thread_ (&daemon->pid,
6419 (*pflags
6420 & MHD_USE_THREAD_PER_CONNECTION) ?
6421 "MHD-listen" : "MHD-single",
6422 daemon->thread_stack_size,
6423 &MHD_polling_thread,
6424 daemon) )
6425 {
6426#ifdef HAVE_MESSAGES
6427 MHD_DLOG (daemon,
6428 _ ("Failed to create listen thread: %s\n"),
6429 MHD_strerror_ (errno));
6430#endif
6431 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
6432 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
6433 if (MHD_INVALID_SOCKET != listen_fd)
6434 MHD_socket_close_chk_ (listen_fd);
6435 goto free_and_fail;
6436 }
6437 }
6438 else /* 0 < daemon->worker_pool_size */
6439 {
6440 /* Coarse-grained count of connections per thread (note error
6441 * due to integer division). Also keep track of how many
6442 * connections are leftover after an equal split. */
6443 unsigned int conns_per_thread = daemon->connection_limit
6444 / daemon->worker_pool_size;
6445 unsigned int leftover_conns = daemon->connection_limit
6446 % daemon->worker_pool_size;
6447
6448 i = 0; /* we need this in case fcntl or malloc fails */
6449
6450 /* Allocate memory for pooled objects */
6451 daemon->worker_pool = malloc (sizeof (struct MHD_Daemon)
6452 * daemon->worker_pool_size);
6453 if (NULL == daemon->worker_pool)
6454 goto thread_failed;
6455
6456 /* Start the workers in the pool */
6457 for (i = 0; i < daemon->worker_pool_size; ++i)
6458 {
6459 /* Create copy of the Daemon object for each worker */
6460 struct MHD_Daemon *d = &daemon->worker_pool[i];
6461
6462 memcpy (d, daemon, sizeof (struct MHD_Daemon));
6463 /* Adjust pooling params for worker daemons; note that memcpy()
6464 has already copied MHD_USE_INTERNAL_POLLING_THREAD thread mode into
6465 the worker threads. */
6466 d->master = daemon;
6467 d->worker_pool_size = 0;
6468 d->worker_pool = NULL;
6469
6470 if (0 != (*pflags & MHD_USE_ITC))
6354 { 6471 {
6355 if (! MHD_create_named_thread_ (&daemon->pid, 6472 if (! MHD_itc_init_ (d->itc))
6356 (*pflags & MHD_USE_THREAD_PER_CONNECTION) ? 6473 {
6357 "MHD-listen" : "MHD-single", 6474#ifdef HAVE_MESSAGES
6358 daemon->thread_stack_size, 6475 MHD_DLOG (daemon,
6359 &MHD_polling_thread, 6476 _ (
6360 daemon) ) 6477 "Failed to create worker inter-thread communication channel: %s\n"),
6361 { 6478 MHD_itc_last_strerror_ () );
6362#ifdef HAVE_MESSAGES 6479#endif
6363 MHD_DLOG (daemon, 6480 goto thread_failed;
6364 _("Failed to create listen thread: %s\n"), 6481 }
6365 MHD_strerror_ (errno)); 6482 if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) &&
6366#endif 6483 (! MHD_SCKT_FD_FITS_FDSET_ (MHD_itc_r_fd_ (d->itc),
6367 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 6484 NULL)) )
6368 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); 6485 {
6369 if (MHD_INVALID_SOCKET != listen_fd) 6486#ifdef HAVE_MESSAGES
6370 MHD_socket_close_chk_ (listen_fd); 6487 MHD_DLOG (daemon,
6371 goto free_and_fail; 6488 _ (
6372 } 6489 "File descriptor for worker inter-thread communication channel exceeds maximum value\n"));
6490#endif
6491 MHD_itc_destroy_chk_ (d->itc);
6492 goto thread_failed;
6493 }
6373 } 6494 }
6374 else /* 0 < daemon->worker_pool_size */ 6495 else
6496 MHD_itc_set_invalid_ (d->itc);
6497
6498 /* Divide available connections evenly amongst the threads.
6499 * Thread indexes in [0, leftover_conns) each get one of the
6500 * leftover connections. */
6501 d->connection_limit = conns_per_thread;
6502 if (i < leftover_conns)
6503 ++d->connection_limit;
6504#ifdef EPOLL_SUPPORT
6505 if ( (0 != (*pflags & MHD_USE_EPOLL)) &&
6506 (MHD_YES != setup_epoll_to_listen (d)) )
6507 goto thread_failed;
6508#endif
6509 /* Must init cleanup connection mutex for each worker */
6510 if (! MHD_mutex_init_ (&d->cleanup_connection_mutex))
6375 { 6511 {
6376 /* Coarse-grained count of connections per thread (note error 6512#ifdef HAVE_MESSAGES
6377 * due to integer division). Also keep track of how many 6513 MHD_DLOG (daemon,
6378 * connections are leftover after an equal split. */ 6514 _ ("MHD failed to initialize cleanup connection mutex\n"));
6379 unsigned int conns_per_thread = daemon->connection_limit 6515#endif
6380 / daemon->worker_pool_size; 6516 goto thread_failed;
6381 unsigned int leftover_conns = daemon->connection_limit 6517 }
6382 % daemon->worker_pool_size;
6383
6384 i = 0; /* we need this in case fcntl or malloc fails */
6385
6386 /* Allocate memory for pooled objects */
6387 daemon->worker_pool = malloc (sizeof (struct MHD_Daemon)
6388 * daemon->worker_pool_size);
6389 if (NULL == daemon->worker_pool)
6390 goto thread_failed;
6391 6518
6392 /* Start the workers in the pool */ 6519 /* Spawn the worker thread */
6393 for (i = 0; i < daemon->worker_pool_size; ++i) 6520 if (! MHD_create_named_thread_ (&d->pid,
6394 { 6521 "MHD-worker",
6395 /* Create copy of the Daemon object for each worker */ 6522 daemon->thread_stack_size,
6396 struct MHD_Daemon *d = &daemon->worker_pool[i]; 6523 &MHD_polling_thread,
6397 6524 d))
6398 memcpy (d, daemon, sizeof (struct MHD_Daemon)); 6525 {
6399 /* Adjust pooling params for worker daemons; note that memcpy() 6526#ifdef HAVE_MESSAGES
6400 has already copied MHD_USE_INTERNAL_POLLING_THREAD thread mode into 6527 MHD_DLOG (daemon,
6401 the worker threads. */ 6528 _ ("Failed to create pool thread: %s\n"),
6402 d->master = daemon; 6529 MHD_strerror_ (errno));
6403 d->worker_pool_size = 0; 6530#endif
6404 d->worker_pool = NULL; 6531 /* Free memory for this worker; cleanup below handles
6405 6532 * all previously-created workers. */
6406 if (0 != (*pflags & MHD_USE_ITC)) 6533 MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
6407 { 6534 goto thread_failed;
6408 if (! MHD_itc_init_ (d->itc))
6409 {
6410#ifdef HAVE_MESSAGES
6411 MHD_DLOG (daemon,
6412 _("Failed to create worker inter-thread communication channel: %s\n"),
6413 MHD_itc_last_strerror_() );
6414#endif
6415 goto thread_failed;
6416 }
6417 if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) &&
6418 (! MHD_SCKT_FD_FITS_FDSET_(MHD_itc_r_fd_ (d->itc),
6419 NULL)) )
6420 {
6421#ifdef HAVE_MESSAGES
6422 MHD_DLOG (daemon,
6423 _("File descriptor for worker inter-thread communication channel exceeds maximum value\n"));
6424#endif
6425 MHD_itc_destroy_chk_ (d->itc);
6426 goto thread_failed;
6427 }
6428 }
6429 else
6430 MHD_itc_set_invalid_ (d->itc);
6431
6432 /* Divide available connections evenly amongst the threads.
6433 * Thread indexes in [0, leftover_conns) each get one of the
6434 * leftover connections. */
6435 d->connection_limit = conns_per_thread;
6436 if (i < leftover_conns)
6437 ++d->connection_limit;
6438#ifdef EPOLL_SUPPORT
6439 if ( (0 != (*pflags & MHD_USE_EPOLL)) &&
6440 (MHD_YES != setup_epoll_to_listen (d)) )
6441 goto thread_failed;
6442#endif
6443 /* Must init cleanup connection mutex for each worker */
6444 if (! MHD_mutex_init_ (&d->cleanup_connection_mutex))
6445 {
6446#ifdef HAVE_MESSAGES
6447 MHD_DLOG (daemon,
6448 _("MHD failed to initialize cleanup connection mutex\n"));
6449#endif
6450 goto thread_failed;
6451 }
6452
6453 /* Spawn the worker thread */
6454 if (! MHD_create_named_thread_ (&d->pid,
6455 "MHD-worker",
6456 daemon->thread_stack_size,
6457 &MHD_polling_thread,
6458 d))
6459 {
6460#ifdef HAVE_MESSAGES
6461 MHD_DLOG (daemon,
6462 _("Failed to create pool thread: %s\n"),
6463 MHD_strerror_ (errno));
6464#endif
6465 /* Free memory for this worker; cleanup below handles
6466 * all previously-created workers. */
6467 MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
6468 goto thread_failed;
6469 }
6470 }
6471 } 6535 }
6536 }
6472 } 6537 }
6538 }
6473#endif 6539#endif
6474#ifdef HTTPS_SUPPORT 6540#ifdef HTTPS_SUPPORT
6475 /* API promises to never use the password after initialization, 6541 /* API promises to never use the password after initialization,
@@ -6486,14 +6552,14 @@ thread_failed:
6486 assumes a 0-sized thread pool means we had been in the default 6552 assumes a 0-sized thread pool means we had been in the default
6487 MHD_USE_INTERNAL_POLLING_THREAD mode. */ 6553 MHD_USE_INTERNAL_POLLING_THREAD mode. */
6488 if (0 == i) 6554 if (0 == i)
6489 { 6555 {
6490 if (MHD_INVALID_SOCKET != listen_fd) 6556 if (MHD_INVALID_SOCKET != listen_fd)
6491 MHD_socket_close_chk_ (listen_fd); 6557 MHD_socket_close_chk_ (listen_fd);
6492 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); 6558 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
6493 if (NULL != daemon->worker_pool) 6559 if (NULL != daemon->worker_pool)
6494 free (daemon->worker_pool); 6560 free (daemon->worker_pool);
6495 goto free_and_fail; 6561 goto free_and_fail;
6496 } 6562 }
6497 6563
6498 /* Shutdown worker threads we've already created. Pretend 6564 /* Shutdown worker threads we've already created. Pretend
6499 as though we had fully initialized our daemon, but 6565 as though we had fully initialized our daemon, but
@@ -6504,20 +6570,20 @@ thread_failed:
6504 return NULL; 6570 return NULL;
6505#endif 6571#endif
6506 6572
6507 free_and_fail: 6573free_and_fail:
6508 /* clean up basic memory state in 'daemon' and return NULL to 6574 /* clean up basic memory state in 'daemon' and return NULL to
6509 indicate failure */ 6575 indicate failure */
6510#ifdef EPOLL_SUPPORT 6576#ifdef EPOLL_SUPPORT
6511#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 6577#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
6512 if (daemon->upgrade_fd_in_epoll) 6578 if (daemon->upgrade_fd_in_epoll)
6513 { 6579 {
6514 if (0 != epoll_ctl (daemon->epoll_fd, 6580 if (0 != epoll_ctl (daemon->epoll_fd,
6515 EPOLL_CTL_DEL, 6581 EPOLL_CTL_DEL,
6516 daemon->epoll_upgrade_fd, 6582 daemon->epoll_upgrade_fd,
6517 NULL)) 6583 NULL))
6518 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 6584 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
6519 daemon->upgrade_fd_in_epoll = false; 6585 daemon->upgrade_fd_in_epoll = false;
6520 } 6586 }
6521#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 6587#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
6522 if (-1 != daemon->epoll_fd) 6588 if (-1 != daemon->epoll_fd)
6523 close (daemon->epoll_fd); 6589 close (daemon->epoll_fd);
@@ -6542,7 +6608,7 @@ thread_failed:
6542 gnutls_psk_free_server_credentials (daemon->psk_cred); 6608 gnutls_psk_free_server_credentials (daemon->psk_cred);
6543 } 6609 }
6544#endif /* HTTPS_SUPPORT */ 6610#endif /* HTTPS_SUPPORT */
6545 if (MHD_ITC_IS_VALID_(daemon->itc)) 6611 if (MHD_ITC_IS_VALID_ (daemon->itc))
6546 MHD_itc_destroy_chk_ (daemon->itc); 6612 MHD_itc_destroy_chk_ (daemon->itc);
6547 free (daemon); 6613 free (daemon);
6548 return NULL; 6614 return NULL;
@@ -6561,7 +6627,8 @@ static void
6561close_all_connections (struct MHD_Daemon *daemon) 6627close_all_connections (struct MHD_Daemon *daemon)
6562{ 6628{
6563 struct MHD_Connection *pos; 6629 struct MHD_Connection *pos;
6564 const bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); 6630 const bool used_thr_p_c = (0 != (daemon->options
6631 & MHD_USE_THREAD_PER_CONNECTION));
6565#ifdef UPGRADE_SUPPORT 6632#ifdef UPGRADE_SUPPORT
6566 const bool upg_allowed = (0 != (daemon->options & MHD_ALLOW_UPGRADE)); 6633 const bool upg_allowed = (0 != (daemon->options & MHD_ALLOW_UPGRADE));
6567#endif /* UPGRADE_SUPPORT */ 6634#endif /* UPGRADE_SUPPORT */
@@ -6577,16 +6644,16 @@ close_all_connections (struct MHD_Daemon *daemon)
6577 /* give upgraded HTTPS connections a chance to finish */ 6644 /* give upgraded HTTPS connections a chance to finish */
6578 /* 'daemon->urh_head' is not used in thread-per-connection mode. */ 6645 /* 'daemon->urh_head' is not used in thread-per-connection mode. */
6579 for (urh = daemon->urh_tail; NULL != urh; urh = urhn) 6646 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
6580 { 6647 {
6581 urhn = urh->prev; 6648 urhn = urh->prev;
6582 /* call generic forwarding function for passing data 6649 /* call generic forwarding function for passing data
6583 with chance to detect that application is done. */ 6650 with chance to detect that application is done. */
6584 process_urh (urh); 6651 process_urh (urh);
6585 MHD_connection_finish_forward_ (urh->connection); 6652 MHD_connection_finish_forward_ (urh->connection);
6586 urh->clean_ready = true; 6653 urh->clean_ready = true;
6587 /* Resuming will move connection to cleanup list. */ 6654 /* Resuming will move connection to cleanup list. */
6588 MHD_resume_connection(urh->connection); 6655 MHD_resume_connection (urh->connection);
6589 } 6656 }
6590#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 6657#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
6591 6658
6592 /* Give suspended connections a chance to resume to avoid 6659 /* Give suspended connections a chance to resume to avoid
@@ -6594,10 +6661,10 @@ close_all_connections (struct MHD_Daemon *daemon)
6594 connections left in case of a tight race with a recently 6661 connections left in case of a tight race with a recently
6595 resumed connection. */ 6662 resumed connection. */
6596 if (0 != (MHD_TEST_ALLOW_SUSPEND_RESUME & daemon->options)) 6663 if (0 != (MHD_TEST_ALLOW_SUSPEND_RESUME & daemon->options))
6597 { 6664 {
6598 daemon->resuming = true; /* Force check for pending resume. */ 6665 daemon->resuming = true; /* Force check for pending resume. */
6599 resume_suspended_connections (daemon); 6666 resume_suspended_connections (daemon);
6600 } 6667 }
6601 /* first, make sure all threads are aware of shutdown; need to 6668 /* first, make sure all threads are aware of shutdown; need to
6602 traverse DLLs in peace... */ 6669 traverse DLLs in peace... */
6603#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6670#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -6605,79 +6672,83 @@ close_all_connections (struct MHD_Daemon *daemon)
6605#endif 6672#endif
6606#ifdef UPGRADE_SUPPORT 6673#ifdef UPGRADE_SUPPORT
6607 if (upg_allowed) 6674 if (upg_allowed)
6608 { 6675 {
6609 struct MHD_Connection * susp; 6676 struct MHD_Connection *susp;
6610 6677
6611 susp = daemon->suspended_connections_tail; 6678 susp = daemon->suspended_connections_tail;
6612 while (NULL != susp) 6679 while (NULL != susp)
6613 { 6680 {
6614 if (NULL == susp->urh) /* "Upgraded" connection? */ 6681 if (NULL == susp->urh) /* "Upgraded" connection? */
6615 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 6682 MHD_PANIC (_ (
6683 "MHD_stop_daemon() called while we have suspended connections.\n"));
6616#ifdef HTTPS_SUPPORT 6684#ifdef HTTPS_SUPPORT
6617 else if (used_tls && 6685 else if (used_tls &&
6618 used_thr_p_c && 6686 used_thr_p_c &&
6619 (! susp->urh->clean_ready) ) 6687 (! susp->urh->clean_ready) )
6620 shutdown (susp->urh->app.socket, 6688 shutdown (susp->urh->app.socket,
6621 SHUT_RDWR); /* Wake thread by shutdown of app socket. */ 6689 SHUT_RDWR); /* Wake thread by shutdown of app socket. */
6622#endif /* HTTPS_SUPPORT */ 6690#endif /* HTTPS_SUPPORT */
6623 else 6691 else
6624 { 6692 {
6625#ifdef HAVE_MESSAGES 6693#ifdef HAVE_MESSAGES
6626 if (! susp->urh->was_closed) 6694 if (! susp->urh->was_closed)
6627 MHD_DLOG (daemon, 6695 MHD_DLOG (daemon,
6628 _("Initiated daemon shutdown while \"upgraded\" connection was not closed.\n")); 6696 _ (
6629#endif 6697 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
6630 susp->urh->was_closed = true; 6698#endif
6631 /* If thread-per-connection is used, connection's thread 6699 susp->urh->was_closed = true;
6632 * may still processing "upgrade" (exiting). */ 6700 /* If thread-per-connection is used, connection's thread
6633 if (! used_thr_p_c) 6701 * may still processing "upgrade" (exiting). */
6634 MHD_connection_finish_forward_ (susp); 6702 if (! used_thr_p_c)
6635 /* Do not use MHD_resume_connection() as mutex is 6703 MHD_connection_finish_forward_ (susp);
6636 * already locked. */ 6704 /* Do not use MHD_resume_connection() as mutex is
6637 susp->resuming = true; 6705 * already locked. */
6638 daemon->resuming = true; 6706 susp->resuming = true;
6639 } 6707 daemon->resuming = true;
6640 susp = susp->prev; 6708 }
6641 } 6709 susp = susp->prev;
6642 } 6710 }
6711 }
6643 else /* This 'else' is combined with next 'if' */ 6712 else /* This 'else' is combined with next 'if' */
6644#endif /* UPGRADE_SUPPORT */ 6713#endif /* UPGRADE_SUPPORT */
6645 if (NULL != daemon->suspended_connections_head) 6714 if (NULL != daemon->suspended_connections_head)
6646 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 6715 MHD_PANIC (_ (
6716 "MHD_stop_daemon() called while we have suspended connections.\n"));
6647 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) 6717 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
6648 { 6718 {
6649 shutdown (pos->socket_fd, 6719 shutdown (pos->socket_fd,
6650 SHUT_RDWR); 6720 SHUT_RDWR);
6651#if MHD_WINSOCK_SOCKETS 6721#if MHD_WINSOCK_SOCKETS
6652 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 6722 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
6653 (MHD_ITC_IS_VALID_(daemon->itc)) && 6723 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
6654 (! MHD_itc_activate_ (daemon->itc, "e")) ) 6724 (! MHD_itc_activate_ (daemon->itc, "e")) )
6655 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel")); 6725 MHD_PANIC (_ (
6726 "Failed to signal shutdown via inter-thread communication channel"));
6656#endif 6727#endif
6657 } 6728 }
6658 6729
6659#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6730#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6660 /* now, collect per-connection threads */ 6731 /* now, collect per-connection threads */
6661 if (used_thr_p_c) 6732 if (used_thr_p_c)
6733 {
6734 pos = daemon->connections_tail;
6735 while (NULL != pos)
6662 { 6736 {
6663 pos = daemon->connections_tail; 6737 if (! pos->thread_joined)
6664 while (NULL != pos)
6665 { 6738 {
6666 if (! pos->thread_joined) 6739 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
6667 { 6740 if (! MHD_join_thread_ (pos->pid.handle))
6668 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 6741 MHD_PANIC (_ ("Failed to join a thread\n"));
6669 if (! MHD_join_thread_ (pos->pid.handle)) 6742 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
6670 MHD_PANIC (_("Failed to join a thread\n")); 6743 pos->thread_joined = true;
6671 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 6744 /* The thread may have concurrently modified the DLL,
6672 pos->thread_joined = true; 6745 need to restart from the beginning */
6673 /* The thread may have concurrently modified the DLL, 6746 pos = daemon->connections_tail;
6674 need to restart from the beginning */ 6747 continue;
6675 pos = daemon->connections_tail;
6676 continue;
6677 }
6678 pos = pos->prev;
6679 } 6748 }
6749 pos = pos->prev;
6680 } 6750 }
6751 }
6681 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 6752 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
6682#endif 6753#endif
6683 6754
@@ -6687,10 +6758,10 @@ close_all_connections (struct MHD_Daemon *daemon)
6687 /* "Upgraded" connections that were not closed explicitly by 6758 /* "Upgraded" connections that were not closed explicitly by
6688 * application should be moved to cleanup list too. */ 6759 * application should be moved to cleanup list too. */
6689 if (upg_allowed) 6760 if (upg_allowed)
6690 { 6761 {
6691 daemon->resuming = true; /* Force check for pending resume. */ 6762 daemon->resuming = true; /* Force check for pending resume. */
6692 resume_suspended_connections (daemon); 6763 resume_suspended_connections (daemon);
6693 } 6764 }
6694#endif /* UPGRADE_SUPPORT */ 6765#endif /* UPGRADE_SUPPORT */
6695 6766
6696 /* now that we're alone, move everyone to cleanup */ 6767 /* now that we're alone, move everyone to cleanup */
@@ -6699,7 +6770,7 @@ close_all_connections (struct MHD_Daemon *daemon)
6699#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6770#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6700 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 6771 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
6701 (! pos->thread_joined) ) 6772 (! pos->thread_joined) )
6702 MHD_PANIC (_("Failed to join a thread\n")); 6773 MHD_PANIC (_ ("Failed to join a thread\n"));
6703#endif 6774#endif
6704 close_connection (pos); 6775 close_connection (pos);
6705 } 6776 }
@@ -6732,137 +6803,139 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
6732 6803
6733#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6804#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6734 if (NULL != daemon->worker_pool) 6805 if (NULL != daemon->worker_pool)
6735 { /* Master daemon with worker pool. */ 6806 { /* Master daemon with worker pool. */
6736 mhd_assert (1 < daemon->worker_pool_size); 6807 mhd_assert (1 < daemon->worker_pool_size);
6737 mhd_assert (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)); 6808 mhd_assert (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD));
6738 6809
6739 /* Let workers shutdown in parallel. */ 6810 /* Let workers shutdown in parallel. */
6740 for (i = 0; i < daemon->worker_pool_size; ++i) 6811 for (i = 0; i < daemon->worker_pool_size; ++i)
6741 { 6812 {
6742 daemon->worker_pool[i].shutdown = true; 6813 daemon->worker_pool[i].shutdown = true;
6743 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc)) 6814 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc))
6744 { 6815 {
6745 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, 6816 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc,
6746 "e")) 6817 "e"))
6747 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel.")); 6818 MHD_PANIC (_ (
6748 } 6819 "Failed to signal shutdown via inter-thread communication channel."));
6749 else 6820 }
6750 mhd_assert (MHD_INVALID_SOCKET != fd); 6821 else
6751 } 6822 mhd_assert (MHD_INVALID_SOCKET != fd);
6823 }
6752#ifdef HAVE_LISTEN_SHUTDOWN 6824#ifdef HAVE_LISTEN_SHUTDOWN
6753 if (MHD_INVALID_SOCKET != fd) 6825 if (MHD_INVALID_SOCKET != fd)
6754 { 6826 {
6755 (void) shutdown (fd, 6827 (void) shutdown (fd,
6756 SHUT_RDWR); 6828 SHUT_RDWR);
6757 } 6829 }
6758#endif /* HAVE_LISTEN_SHUTDOWN */ 6830#endif /* HAVE_LISTEN_SHUTDOWN */
6759 for (i = 0; i < daemon->worker_pool_size; ++i) 6831 for (i = 0; i < daemon->worker_pool_size; ++i)
6760 { 6832 {
6761 MHD_stop_daemon (&daemon->worker_pool[i]); 6833 MHD_stop_daemon (&daemon->worker_pool[i]);
6762 } 6834 }
6763 free (daemon->worker_pool); 6835 free (daemon->worker_pool);
6764 mhd_assert (MHD_ITC_IS_INVALID_(daemon->itc)); 6836 mhd_assert (MHD_ITC_IS_INVALID_ (daemon->itc));
6765#ifdef EPOLL_SUPPORT 6837#ifdef EPOLL_SUPPORT
6766 mhd_assert (-1 == daemon->epoll_fd); 6838 mhd_assert (-1 == daemon->epoll_fd);
6767#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 6839#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
6768 mhd_assert (-1 == daemon->epoll_upgrade_fd); 6840 mhd_assert (-1 == daemon->epoll_upgrade_fd);
6769#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 6841#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
6770#endif /* EPOLL_SUPPORT */ 6842#endif /* EPOLL_SUPPORT */
6771 } 6843 }
6772 else 6844 else
6773#endif 6845#endif
6774 { /* Worker daemon or single daemon. */ 6846 { /* Worker daemon or single daemon. */
6775#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6847#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6776 if (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) 6848 if (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD))
6777 { /* Worker daemon or single daemon with internal thread(s). */ 6849 { /* Worker daemon or single daemon with internal thread(s). */
6778 mhd_assert (0 == daemon->worker_pool_size); 6850 mhd_assert (0 == daemon->worker_pool_size);
6779 /* Separate thread(s) is used for polling sockets. */ 6851 /* Separate thread(s) is used for polling sockets. */
6780 if (MHD_ITC_IS_VALID_ (daemon->itc)) 6852 if (MHD_ITC_IS_VALID_ (daemon->itc))
6781 { 6853 {
6782 if (! MHD_itc_activate_ (daemon->itc, 6854 if (! MHD_itc_activate_ (daemon->itc,
6783 "e")) 6855 "e"))
6784 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel")); 6856 MHD_PANIC (_ (
6785 } 6857 "Failed to signal shutdown via inter-thread communication channel"));
6786 else 6858 }
6787 {
6788#ifdef HAVE_LISTEN_SHUTDOWN
6789 if (MHD_INVALID_SOCKET != fd)
6790 {
6791 if (NULL == daemon->master)
6792 (void) shutdown (fd,
6793 SHUT_RDWR);
6794 }
6795 else
6796#endif /* HAVE_LISTEN_SHUTDOWN */
6797 mhd_assert (false); /* Should never happen */
6798 }
6799
6800 if (! MHD_join_thread_ (daemon->pid.handle))
6801 {
6802 MHD_PANIC (_("Failed to join a thread\n"));
6803 }
6804 /* close_all_connections() was called in daemon thread. */
6805 }
6806 else 6859 else
6807#endif 6860 {
6861#ifdef HAVE_LISTEN_SHUTDOWN
6862 if (MHD_INVALID_SOCKET != fd)
6808 { 6863 {
6809 /* No internal threads are used for polling sockets. */ 6864 if (NULL == daemon->master)
6810 close_all_connections (daemon); 6865 (void) shutdown (fd,
6866 SHUT_RDWR);
6811 } 6867 }
6812 if (MHD_ITC_IS_VALID_ (daemon->itc)) 6868 else
6813 MHD_itc_destroy_chk_ (daemon->itc); 6869#endif /* HAVE_LISTEN_SHUTDOWN */
6870 mhd_assert (false); /* Should never happen */
6871 }
6872
6873 if (! MHD_join_thread_ (daemon->pid.handle))
6874 {
6875 MHD_PANIC (_ ("Failed to join a thread\n"));
6876 }
6877 /* close_all_connections() was called in daemon thread. */
6878 }
6879 else
6880#endif
6881 {
6882 /* No internal threads are used for polling sockets. */
6883 close_all_connections (daemon);
6884 }
6885 if (MHD_ITC_IS_VALID_ (daemon->itc))
6886 MHD_itc_destroy_chk_ (daemon->itc);
6814 6887
6815#ifdef EPOLL_SUPPORT 6888#ifdef EPOLL_SUPPORT
6816 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 6889 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
6817 (-1 != daemon->epoll_fd) ) 6890 (-1 != daemon->epoll_fd) )
6818 MHD_socket_close_chk_ (daemon->epoll_fd); 6891 MHD_socket_close_chk_ (daemon->epoll_fd);
6819#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 6892#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
6820 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 6893 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
6821 (-1 != daemon->epoll_upgrade_fd) ) 6894 (-1 != daemon->epoll_upgrade_fd) )
6822 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd); 6895 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
6823#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 6896#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
6824#endif /* EPOLL_SUPPORT */ 6897#endif /* EPOLL_SUPPORT */
6825 6898
6826#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6899#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6827 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 6900 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
6828#endif 6901#endif
6829 } 6902 }
6830 6903
6831 if (NULL == daemon->master) 6904 if (NULL == daemon->master)
6832 { /* Cleanup that should be done only one time in master/single daemon. 6905 { /* Cleanup that should be done only one time in master/single daemon.
6833 * Do not perform this cleanup in worker daemons. */ 6906 * Do not perform this cleanup in worker daemons. */
6834 6907
6835 if (MHD_INVALID_SOCKET != fd) 6908 if (MHD_INVALID_SOCKET != fd)
6836 MHD_socket_close_chk_ (fd); 6909 MHD_socket_close_chk_ (fd);
6837 6910
6838 /* TLS clean up */ 6911 /* TLS clean up */
6839#ifdef HTTPS_SUPPORT 6912#ifdef HTTPS_SUPPORT
6840 if (daemon->have_dhparams) 6913 if (daemon->have_dhparams)
6841 { 6914 {
6842 gnutls_dh_params_deinit (daemon->https_mem_dhparams); 6915 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
6843 daemon->have_dhparams = false; 6916 daemon->have_dhparams = false;
6844 } 6917 }
6845 if (0 != (daemon->options & MHD_USE_TLS)) 6918 if (0 != (daemon->options & MHD_USE_TLS))
6846 { 6919 {
6847 gnutls_priority_deinit (daemon->priority_cache); 6920 gnutls_priority_deinit (daemon->priority_cache);
6848 if (daemon->x509_cred) 6921 if (daemon->x509_cred)
6849 gnutls_certificate_free_credentials (daemon->x509_cred); 6922 gnutls_certificate_free_credentials (daemon->x509_cred);
6850 if (daemon->psk_cred) 6923 if (daemon->psk_cred)
6851 gnutls_psk_free_server_credentials (daemon->psk_cred); 6924 gnutls_psk_free_server_credentials (daemon->psk_cred);
6852 } 6925 }
6853#endif /* HTTPS_SUPPORT */ 6926#endif /* HTTPS_SUPPORT */
6854 6927
6855#ifdef DAUTH_SUPPORT 6928#ifdef DAUTH_SUPPORT
6856 free (daemon->nnc); 6929 free (daemon->nnc);
6857#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6930#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6858 MHD_mutex_destroy_chk_ (&daemon->nnc_lock); 6931 MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
6859#endif 6932#endif
6860#endif 6933#endif
6861#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6934#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6862 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); 6935 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
6863#endif 6936#endif
6864 free (daemon); 6937 free (daemon);
6865 } 6938 }
6866} 6939}
6867 6940
6868 6941
@@ -6879,51 +6952,51 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
6879 */ 6952 */
6880const union MHD_DaemonInfo * 6953const union MHD_DaemonInfo *
6881MHD_get_daemon_info (struct MHD_Daemon *daemon, 6954MHD_get_daemon_info (struct MHD_Daemon *daemon,
6882 enum MHD_DaemonInfoType info_type, 6955 enum MHD_DaemonInfoType info_type,
6883 ...) 6956 ...)
6884{ 6957{
6885 if (NULL == daemon) 6958 if (NULL == daemon)
6886 return NULL; 6959 return NULL;
6887 switch (info_type) 6960 switch (info_type)
6888 { 6961 {
6889 case MHD_DAEMON_INFO_KEY_SIZE: 6962 case MHD_DAEMON_INFO_KEY_SIZE:
6890 return NULL; /* no longer supported */ 6963 return NULL; /* no longer supported */
6891 case MHD_DAEMON_INFO_MAC_KEY_SIZE: 6964 case MHD_DAEMON_INFO_MAC_KEY_SIZE:
6892 return NULL; /* no longer supported */ 6965 return NULL; /* no longer supported */
6893 case MHD_DAEMON_INFO_LISTEN_FD: 6966 case MHD_DAEMON_INFO_LISTEN_FD:
6894 return (const union MHD_DaemonInfo *) &daemon->listen_fd; 6967 return (const union MHD_DaemonInfo *) &daemon->listen_fd;
6895#ifdef EPOLL_SUPPORT 6968#ifdef EPOLL_SUPPORT
6896 case MHD_DAEMON_INFO_EPOLL_FD: 6969 case MHD_DAEMON_INFO_EPOLL_FD:
6897 return (const union MHD_DaemonInfo *) &daemon->epoll_fd; 6970 return (const union MHD_DaemonInfo *) &daemon->epoll_fd;
6898#endif 6971#endif
6899 case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: 6972 case MHD_DAEMON_INFO_CURRENT_CONNECTIONS:
6900 if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) 6973 if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD))
6901 { 6974 {
6902 /* Assume that MHD_run() in not called in other thread 6975 /* Assume that MHD_run() in not called in other thread
6903 * at the same time. */ 6976 * at the same time. */
6904 MHD_cleanup_connections (daemon); 6977 MHD_cleanup_connections (daemon);
6905 } 6978 }
6906#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6979#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6907 else if (daemon->worker_pool) 6980 else if (daemon->worker_pool)
6908 { 6981 {
6909 unsigned int i; 6982 unsigned int i;
6910 /* Collect the connection information stored in the workers. */ 6983 /* Collect the connection information stored in the workers. */
6911 daemon->connections = 0; 6984 daemon->connections = 0;
6912 for (i = 0; i < daemon->worker_pool_size; i++) 6985 for (i = 0; i < daemon->worker_pool_size; i++)
6913 { 6986 {
6914 /* FIXME: next line is thread-safe only if read is atomic. */ 6987 /* FIXME: next line is thread-safe only if read is atomic. */
6915 daemon->connections += daemon->worker_pool[i].connections; 6988 daemon->connections += daemon->worker_pool[i].connections;
6916 } 6989 }
6917 }
6918#endif
6919 return (const union MHD_DaemonInfo *) &daemon->connections;
6920 case MHD_DAEMON_INFO_FLAGS:
6921 return (const union MHD_DaemonInfo *) &daemon->options;
6922 case MHD_DAEMON_INFO_BIND_PORT:
6923 return (const union MHD_DaemonInfo *) &daemon->port;
6924 default:
6925 return NULL;
6926 } 6990 }
6991#endif
6992 return (const union MHD_DaemonInfo *) &daemon->connections;
6993 case MHD_DAEMON_INFO_FLAGS:
6994 return (const union MHD_DaemonInfo *) &daemon->options;
6995 case MHD_DAEMON_INFO_BIND_PORT:
6996 return (const union MHD_DaemonInfo *) &daemon->port;
6997 default:
6998 return NULL;
6999 }
6927} 7000}
6928 7001
6929 7002
@@ -6967,13 +7040,13 @@ MHD_get_version (void)
6967 static char ver[12] = "\0\0\0\0\0\0\0\0\0\0\0"; 7040 static char ver[12] = "\0\0\0\0\0\0\0\0\0\0\0";
6968 if (0 == ver[0]) 7041 if (0 == ver[0])
6969 { 7042 {
6970 int res = MHD_snprintf_(ver, 7043 int res = MHD_snprintf_ (ver,
6971 sizeof(ver), 7044 sizeof(ver),
6972 "%x.%x.%x", 7045 "%x.%x.%x",
6973 (((int)MHD_VERSION >> 24) & 0xFF), 7046 (((int) MHD_VERSION >> 24) & 0xFF),
6974 (((int)MHD_VERSION >> 16) & 0xFF), 7047 (((int) MHD_VERSION >> 16) & 0xFF),
6975 (((int)MHD_VERSION >> 8) & 0xFF)); 7048 (((int) MHD_VERSION >> 8) & 0xFF));
6976 if (0 >= res || sizeof(ver) <= res) 7049 if ((0 >= res)||(sizeof(ver) <= res))
6977 return "0.0.0"; /* Can't return real version*/ 7050 return "0.0.0"; /* Can't return real version*/
6978 } 7051 }
6979 return ver; 7052 return ver;
@@ -6993,154 +7066,155 @@ MHD_get_version (void)
6993 * @ingroup specialized 7066 * @ingroup specialized
6994 */ 7067 */
6995_MHD_EXTERN int 7068_MHD_EXTERN int
6996MHD_is_feature_supported(enum MHD_FEATURE feature) 7069MHD_is_feature_supported (enum MHD_FEATURE feature)
6997{ 7070{
6998 switch(feature) 7071 switch (feature)
6999 { 7072 {
7000 case MHD_FEATURE_MESSAGES: 7073 case MHD_FEATURE_MESSAGES:
7001#ifdef HAVE_MESSAGES 7074#ifdef HAVE_MESSAGES
7002 return MHD_YES; 7075 return MHD_YES;
7003#else 7076#else
7004 return MHD_NO; 7077 return MHD_NO;
7005#endif 7078#endif
7006 case MHD_FEATURE_TLS: 7079 case MHD_FEATURE_TLS:
7007#ifdef HTTPS_SUPPORT 7080#ifdef HTTPS_SUPPORT
7008 return MHD_YES; 7081 return MHD_YES;
7009#else /* ! HTTPS_SUPPORT */ 7082#else /* ! HTTPS_SUPPORT */
7010 return MHD_NO; 7083 return MHD_NO;
7011#endif /* ! HTTPS_SUPPORT */ 7084#endif /* ! HTTPS_SUPPORT */
7012 case MHD_FEATURE_HTTPS_CERT_CALLBACK: 7085 case MHD_FEATURE_HTTPS_CERT_CALLBACK:
7013#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3 7086#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
7014 return MHD_YES; 7087 return MHD_YES;
7015#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */ 7088#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
7016 return MHD_NO; 7089 return MHD_NO;
7017#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */ 7090#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
7018 case MHD_FEATURE_HTTPS_CERT_CALLBACK2: 7091 case MHD_FEATURE_HTTPS_CERT_CALLBACK2:
7019#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603 7092#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
7020 return MHD_YES; 7093 return MHD_YES;
7021#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030603 */ 7094#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030603 */
7022 return MHD_NO; 7095 return MHD_NO;
7023#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030603 */ 7096#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030603 */
7024 case MHD_FEATURE_IPv6: 7097 case MHD_FEATURE_IPv6:
7025#ifdef HAVE_INET6 7098#ifdef HAVE_INET6
7026 return MHD_YES; 7099 return MHD_YES;
7027#else 7100#else
7028 return MHD_NO; 7101 return MHD_NO;
7029#endif 7102#endif
7030 case MHD_FEATURE_IPv6_ONLY: 7103 case MHD_FEATURE_IPv6_ONLY:
7031#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) 7104#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
7032 return MHD_YES; 7105 return MHD_YES;
7033#else 7106#else
7034 return MHD_NO; 7107 return MHD_NO;
7035#endif 7108#endif
7036 case MHD_FEATURE_POLL: 7109 case MHD_FEATURE_POLL:
7037#ifdef HAVE_POLL 7110#ifdef HAVE_POLL
7038 return MHD_YES; 7111 return MHD_YES;
7039#else 7112#else
7040 return MHD_NO; 7113 return MHD_NO;
7041#endif 7114#endif
7042 case MHD_FEATURE_EPOLL: 7115 case MHD_FEATURE_EPOLL:
7043#ifdef EPOLL_SUPPORT 7116#ifdef EPOLL_SUPPORT
7044 return MHD_YES; 7117 return MHD_YES;
7045#else 7118#else
7046 return MHD_NO; 7119 return MHD_NO;
7047#endif 7120#endif
7048 case MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET: 7121 case MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET:
7049#ifdef HAVE_LISTEN_SHUTDOWN 7122#ifdef HAVE_LISTEN_SHUTDOWN
7050 return MHD_YES; 7123 return MHD_YES;
7051#else 7124#else
7052 return MHD_NO; 7125 return MHD_NO;
7053#endif 7126#endif
7054 case MHD_FEATURE_SOCKETPAIR: 7127 case MHD_FEATURE_SOCKETPAIR:
7055#ifdef _MHD_ITC_SOCKETPAIR 7128#ifdef _MHD_ITC_SOCKETPAIR
7056 return MHD_YES; 7129 return MHD_YES;
7057#else 7130#else
7058 return MHD_NO; 7131 return MHD_NO;
7059#endif 7132#endif
7060 case MHD_FEATURE_TCP_FASTOPEN: 7133 case MHD_FEATURE_TCP_FASTOPEN:
7061#ifdef TCP_FASTOPEN 7134#ifdef TCP_FASTOPEN
7062 return MHD_YES; 7135 return MHD_YES;
7063#else 7136#else
7064 return MHD_NO; 7137 return MHD_NO;
7065#endif 7138#endif
7066 case MHD_FEATURE_BASIC_AUTH: 7139 case MHD_FEATURE_BASIC_AUTH:
7067#ifdef BAUTH_SUPPORT 7140#ifdef BAUTH_SUPPORT
7068 return MHD_YES; 7141 return MHD_YES;
7069#else 7142#else
7070 return MHD_NO; 7143 return MHD_NO;
7071#endif 7144#endif
7072 case MHD_FEATURE_DIGEST_AUTH: 7145 case MHD_FEATURE_DIGEST_AUTH:
7073#ifdef DAUTH_SUPPORT 7146#ifdef DAUTH_SUPPORT
7074 return MHD_YES; 7147 return MHD_YES;
7075#else 7148#else
7076 return MHD_NO; 7149 return MHD_NO;
7077#endif 7150#endif
7078 case MHD_FEATURE_POSTPROCESSOR: 7151 case MHD_FEATURE_POSTPROCESSOR:
7079#ifdef HAVE_POSTPROCESSOR 7152#ifdef HAVE_POSTPROCESSOR
7080 return MHD_YES; 7153 return MHD_YES;
7081#else 7154#else
7082 return MHD_NO; 7155 return MHD_NO;
7083#endif 7156#endif
7084 case MHD_FEATURE_HTTPS_KEY_PASSWORD: 7157 case MHD_FEATURE_HTTPS_KEY_PASSWORD:
7085#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111 7158#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
7086 return MHD_YES; 7159 return MHD_YES;
7087#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */ 7160#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
7088 return MHD_NO; 7161 return MHD_NO;
7089#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */ 7162#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
7090 case MHD_FEATURE_LARGE_FILE: 7163 case MHD_FEATURE_LARGE_FILE:
7091#if defined(HAVE_PREAD64) || defined(_WIN32) 7164#if defined(HAVE_PREAD64) || defined(_WIN32)
7092 return MHD_YES; 7165 return MHD_YES;
7093#elif defined(HAVE_PREAD) 7166#elif defined(HAVE_PREAD)
7094 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES; 7167 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES;
7095#elif defined(HAVE_LSEEK64) 7168#elif defined(HAVE_LSEEK64)
7096 return MHD_YES; 7169 return MHD_YES;
7097#else 7170#else
7098 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES; 7171 return (sizeof(uint64_t) > sizeof(off_t)) ? MHD_NO : MHD_YES;
7099#endif 7172#endif
7100 case MHD_FEATURE_THREAD_NAMES: 7173 case MHD_FEATURE_THREAD_NAMES:
7101#if defined(MHD_USE_THREAD_NAME_) 7174#if defined(MHD_USE_THREAD_NAME_)
7102 return MHD_YES; 7175 return MHD_YES;
7103#else 7176#else
7104 return MHD_NO; 7177 return MHD_NO;
7105#endif 7178#endif
7106 case MHD_FEATURE_UPGRADE: 7179 case MHD_FEATURE_UPGRADE:
7107#if defined(UPGRADE_SUPPORT) 7180#if defined(UPGRADE_SUPPORT)
7108 return MHD_YES; 7181 return MHD_YES;
7109#else 7182#else
7110 return MHD_NO; 7183 return MHD_NO;
7111#endif 7184#endif
7112 case MHD_FEATURE_RESPONSES_SHARED_FD: 7185 case MHD_FEATURE_RESPONSES_SHARED_FD:
7113#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32) 7186#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
7114 return MHD_YES; 7187 return MHD_YES;
7115#else 7188#else
7116 return MHD_NO; 7189 return MHD_NO;
7117#endif 7190#endif
7118 case MHD_FEATURE_AUTODETECT_BIND_PORT: 7191 case MHD_FEATURE_AUTODETECT_BIND_PORT:
7119#ifdef MHD_USE_GETSOCKNAME 7192#ifdef MHD_USE_GETSOCKNAME
7120 return MHD_YES; 7193 return MHD_YES;
7121#else 7194#else
7122 return MHD_NO; 7195 return MHD_NO;
7123#endif 7196#endif
7124 case MHD_FEATURE_AUTOSUPPRESS_SIGPIPE: 7197 case MHD_FEATURE_AUTOSUPPRESS_SIGPIPE:
7125#if defined(MHD_WINSOCK_SOCKETS) || defined(MHD_socket_nosignal_) || defined (MSG_NOSIGNAL) 7198#if defined(MHD_WINSOCK_SOCKETS) || defined(MHD_socket_nosignal_) || \
7126 return MHD_YES; 7199 defined (MSG_NOSIGNAL)
7200 return MHD_YES;
7127#else 7201#else
7128 return MHD_NO; 7202 return MHD_NO;
7129#endif 7203#endif
7130 case MHD_FEATURE_SENDFILE: 7204 case MHD_FEATURE_SENDFILE:
7131#ifdef _MHD_HAVE_SENDFILE 7205#ifdef _MHD_HAVE_SENDFILE
7132 return MHD_YES; 7206 return MHD_YES;
7133#else 7207#else
7134 return MHD_NO; 7208 return MHD_NO;
7135#endif 7209#endif
7136 case MHD_FEATURE_THREADS: 7210 case MHD_FEATURE_THREADS:
7137#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 7211#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7138 return MHD_YES; 7212 return MHD_YES;
7139#else 7213#else
7140 return MHD_NO; 7214 return MHD_NO;
7141#endif 7215#endif
7142 7216
7143 } 7217 }
7144 return MHD_NO; 7218 return MHD_NO;
7145} 7219}
7146 7220
@@ -7158,12 +7232,12 @@ gcry_w32_mutex_init (void **ppmtx)
7158 7232
7159 if (NULL == *ppmtx) 7233 if (NULL == *ppmtx)
7160 return ENOMEM; 7234 return ENOMEM;
7161 if (!MHD_mutex_init_ ((MHD_mutex_*)*ppmtx)) 7235 if (! MHD_mutex_init_ ((MHD_mutex_*) *ppmtx))
7162 { 7236 {
7163 free (*ppmtx); 7237 free (*ppmtx);
7164 *ppmtx = NULL; 7238 *ppmtx = NULL;
7165 return EPERM; 7239 return EPERM;
7166 } 7240 }
7167 7241
7168 return 0; 7242 return 0;
7169} 7243}
@@ -7172,7 +7246,7 @@ gcry_w32_mutex_init (void **ppmtx)
7172static int 7246static int
7173gcry_w32_mutex_destroy (void **ppmtx) 7247gcry_w32_mutex_destroy (void **ppmtx)
7174{ 7248{
7175 int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : EINVAL; 7249 int res = (MHD_mutex_destroy_ ((MHD_mutex_*) *ppmtx)) ? 0 : EINVAL;
7176 free (*ppmtx); 7250 free (*ppmtx);
7177 return res; 7251 return res;
7178} 7252}
@@ -7181,14 +7255,14 @@ gcry_w32_mutex_destroy (void **ppmtx)
7181static int 7255static int
7182gcry_w32_mutex_lock (void **ppmtx) 7256gcry_w32_mutex_lock (void **ppmtx)
7183{ 7257{
7184 return MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL; 7258 return MHD_mutex_lock_ ((MHD_mutex_*) *ppmtx) ? 0 : EINVAL;
7185} 7259}
7186 7260
7187 7261
7188static int 7262static int
7189gcry_w32_mutex_unlock (void **ppmtx) 7263gcry_w32_mutex_unlock (void **ppmtx)
7190{ 7264{
7191 return MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx) ? 0 : EINVAL; 7265 return MHD_mutex_unlock_ ((MHD_mutex_*) *ppmtx) ? 0 : EINVAL;
7192} 7266}
7193 7267
7194 7268
@@ -7196,7 +7270,8 @@ static struct gcry_thread_cbs gcry_threads_w32 = {
7196 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)), 7270 (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)),
7197 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy, 7271 NULL, gcry_w32_mutex_init, gcry_w32_mutex_destroy,
7198 gcry_w32_mutex_lock, gcry_w32_mutex_unlock, 7272 gcry_w32_mutex_lock, gcry_w32_mutex_unlock,
7199 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; 7273 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
7274};
7200 7275
7201#endif /* defined(MHD_W32_MUTEX_) */ 7276#endif /* defined(MHD_W32_MUTEX_) */
7202#endif /* HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 */ 7277#endif /* HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 */
@@ -7206,7 +7281,7 @@ static struct gcry_thread_cbs gcry_threads_w32 = {
7206 * Initialize do setup work. 7281 * Initialize do setup work.
7207 */ 7282 */
7208void 7283void
7209MHD_init(void) 7284MHD_init (void)
7210{ 7285{
7211#if defined(MHD_WINSOCK_SOCKETS) 7286#if defined(MHD_WINSOCK_SOCKETS)
7212 WSADATA wsd; 7287 WSADATA wsd;
@@ -7216,11 +7291,11 @@ MHD_init(void)
7216 mhd_panic = &mhd_panic_std; 7291 mhd_panic = &mhd_panic_std;
7217 7292
7218#if defined(MHD_WINSOCK_SOCKETS) 7293#if defined(MHD_WINSOCK_SOCKETS)
7219 if (0 != WSAStartup(MAKEWORD(2, 2), &wsd)) 7294 if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
7220 MHD_PANIC (_("Failed to initialize winsock\n")); 7295 MHD_PANIC (_ ("Failed to initialize winsock\n"));
7221 mhd_winsock_inited_ = 1; 7296 mhd_winsock_inited_ = 1;
7222 if (2 != LOBYTE(wsd.wVersion) && 2 != HIBYTE(wsd.wVersion)) 7297 if ((2 != LOBYTE (wsd.wVersion))&&(2 != HIBYTE (wsd.wVersion)))
7223 MHD_PANIC (_("Winsock version 2.2 is not available\n")); 7298 MHD_PANIC (_ ("Winsock version 2.2 is not available\n"));
7224#endif /* MHD_WINSOCK_SOCKETS */ 7299#endif /* MHD_WINSOCK_SOCKETS */
7225#ifdef HTTPS_SUPPORT 7300#ifdef HTTPS_SUPPORT
7226#ifdef MHD_HTTPS_REQUIRE_GRYPT 7301#ifdef MHD_HTTPS_REQUIRE_GRYPT
@@ -7228,21 +7303,22 @@ MHD_init(void)
7228#if defined(MHD_USE_POSIX_THREADS) 7303#if defined(MHD_USE_POSIX_THREADS)
7229 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS, 7304 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
7230 &gcry_threads_pthread)) 7305 &gcry_threads_pthread))
7231 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n")); 7306 MHD_PANIC (_ ("Failed to initialise multithreading in libgcrypt\n"));
7232#elif defined(MHD_W32_MUTEX_) 7307#elif defined(MHD_W32_MUTEX_)
7233 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS, 7308 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
7234 &gcry_threads_w32)) 7309 &gcry_threads_w32))
7235 MHD_PANIC (_("Failed to initialise multithreading in libgcrypt\n")); 7310 MHD_PANIC (_ ("Failed to initialise multithreading in libgcrypt\n"));
7236#endif /* defined(MHD_W32_MUTEX_) */ 7311#endif /* defined(MHD_W32_MUTEX_) */
7237 gcry_check_version (NULL); 7312 gcry_check_version (NULL);
7238#else 7313#else
7239 if (NULL == gcry_check_version ("1.6.0")) 7314 if (NULL == gcry_check_version ("1.6.0"))
7240 MHD_PANIC (_("libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n")); 7315 MHD_PANIC (_ (
7316 "libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n"));
7241#endif 7317#endif
7242#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 7318#endif /* MHD_HTTPS_REQUIRE_GRYPT */
7243 gnutls_global_init (); 7319 gnutls_global_init ();
7244#endif /* HTTPS_SUPPORT */ 7320#endif /* HTTPS_SUPPORT */
7245 MHD_monotonic_sec_counter_init(); 7321 MHD_monotonic_sec_counter_init ();
7246#ifdef HAVE_FREEBSD_SENDFILE 7322#ifdef HAVE_FREEBSD_SENDFILE
7247 MHD_conn_init_static_ (); 7323 MHD_conn_init_static_ ();
7248#endif /* HAVE_FREEBSD_SENDFILE */ 7324#endif /* HAVE_FREEBSD_SENDFILE */
@@ -7251,20 +7327,20 @@ MHD_init(void)
7251 7327
7252 7328
7253void 7329void
7254MHD_fini(void) 7330MHD_fini (void)
7255{ 7331{
7256#ifdef HTTPS_SUPPORT 7332#ifdef HTTPS_SUPPORT
7257 gnutls_global_deinit (); 7333 gnutls_global_deinit ();
7258#endif /* HTTPS_SUPPORT */ 7334#endif /* HTTPS_SUPPORT */
7259#if defined(MHD_WINSOCK_SOCKETS) 7335#if defined(MHD_WINSOCK_SOCKETS)
7260 if (mhd_winsock_inited_) 7336 if (mhd_winsock_inited_)
7261 WSACleanup(); 7337 WSACleanup ();
7262#endif /* MHD_WINSOCK_SOCKETS */ 7338#endif /* MHD_WINSOCK_SOCKETS */
7263 MHD_monotonic_sec_counter_finish(); 7339 MHD_monotonic_sec_counter_finish ();
7264} 7340}
7265 7341
7266#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED 7342#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
7267_SET_INIT_AND_DEINIT_FUNCS(MHD_init, MHD_fini); 7343_SET_INIT_AND_DEINIT_FUNCS (MHD_init, MHD_fini);
7268#endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */ 7344#endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */
7269 7345
7270/* end of daemon.c */ 7346/* end of daemon.c */
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index ce7edb79..95aee7b4 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -82,13 +82,15 @@
82/** 82/**
83 * Check that @a n is below #MAX_NONCE 83 * Check that @a n is below #MAX_NONCE
84 */ 84 */
85#define VLA_CHECK_LEN_DIGEST(n) do { if ((n) > MAX_DIGEST) mhd_panic(mhd_panic_cls, __FILE__, __LINE__, "VLA too big"); } while (0) 85#define VLA_CHECK_LEN_DIGEST(n) do { if ((n) > MAX_DIGEST) mhd_panic ( \
86 mhd_panic_cls, __FILE__, __LINE__, \
87 "VLA too big"); } while (0)
86 88
87 89
88/** 90/**
89 * Beginning string for any valid Digest authentication header. 91 * Beginning string for any valid Digest authentication header.
90 */ 92 */
91#define _BASE "Digest " 93#define _BASE "Digest "
92 94
93/** 95/**
94 * Maximum length of a username for digest authentication. 96 * Maximum length of a username for digest authentication.
@@ -149,7 +151,7 @@ struct DigestAlgorithm
149 */ 151 */
150 void 152 void
151 (*update)(void *ctx, 153 (*update)(void *ctx,
152 const uint8_t *data, 154 const uint8_t *data,
153 size_t length); 155 size_t length);
154 156
155 /** 157 /**
@@ -161,7 +163,7 @@ struct DigestAlgorithm
161 */ 163 */
162 void 164 void
163 (*digest)(void *ctx, 165 (*digest)(void *ctx,
164 uint8_t *digest); 166 uint8_t *digest);
165}; 167};
166 168
167 169
@@ -174,19 +176,19 @@ struct DigestAlgorithm
174 */ 176 */
175static void 177static void
176cvthex (const unsigned char *bin, 178cvthex (const unsigned char *bin,
177 size_t len, 179 size_t len,
178 char *hex) 180 char *hex)
179{ 181{
180 size_t i; 182 size_t i;
181 unsigned int j; 183 unsigned int j;
182 184
183 for (i = 0; i < len; ++i) 185 for (i = 0; i < len; ++i)
184 { 186 {
185 j = (bin[i] >> 4) & 0x0f; 187 j = (bin[i] >> 4) & 0x0f;
186 hex[i * 2] = (char)((j <= 9) ? (j + '0') : (j - 10 + 'a')); 188 hex[i * 2] = (char) ((j <= 9) ? (j + '0') : (j - 10 + 'a'));
187 j = bin[i] & 0x0f; 189 j = bin[i] & 0x0f;
188 hex[i * 2 + 1] = (char)((j <= 9) ? (j + '0') : (j - 10 + 'a')); 190 hex[i * 2 + 1] = (char) ((j <= 9) ? (j + '0') : (j - 10 + 'a'));
189 } 191 }
190 hex[len * 2] = '\0'; 192 hex[len * 2] = '\0';
191} 193}
192 194
@@ -201,54 +203,54 @@ cvthex (const unsigned char *bin,
201 * @param[in,out] da digest implementation, must match @a alg; the 203 * @param[in,out] da digest implementation, must match @a alg; the
202 * da->sessionkey will be initialized to the digest in HEX 204 * da->sessionkey will be initialized to the digest in HEX
203 * @param digest An `unsigned char *' pointer to the binary MD5 sum 205 * @param digest An `unsigned char *' pointer to the binary MD5 sum
204 * for the precalculated hash value "username:realm:password" 206 * for the precalculated hash value "username:realm:password"
205 * of #MHD_MD5_DIGEST_SIZE or #MHD_SHA256_DIGEST_SIZE bytes 207 * of #MHD_MD5_DIGEST_SIZE or #MHD_SHA256_DIGEST_SIZE bytes
206 * @param nonce A `char *' pointer to the nonce value 208 * @param nonce A `char *' pointer to the nonce value
207 * @param cnonce A `char *' pointer to the cnonce value 209 * @param cnonce A `char *' pointer to the cnonce value
208 */ 210 */
209static void 211static void
210digest_calc_ha1_from_digest (const char *alg, 212digest_calc_ha1_from_digest (const char *alg,
211 struct DigestAlgorithm *da, 213 struct DigestAlgorithm *da,
212 const uint8_t *digest, 214 const uint8_t *digest,
213 const char *nonce, 215 const char *nonce,
214 const char *cnonce) 216 const char *cnonce)
215{ 217{
216 if ( (MHD_str_equal_caseless_(alg, 218 if ( (MHD_str_equal_caseless_ (alg,
217 "md5-sess")) || 219 "md5-sess")) ||
218 (MHD_str_equal_caseless_(alg, 220 (MHD_str_equal_caseless_ (alg,
219 "sha-256-sess")) ) 221 "sha-256-sess")) )
220 { 222 {
221 uint8_t dig[VLA_ARRAY_LEN_DIGEST(da->digest_size)]; 223 uint8_t dig[VLA_ARRAY_LEN_DIGEST (da->digest_size)];
222 224
223 VLA_CHECK_LEN_DIGEST(da->digest_size); 225 VLA_CHECK_LEN_DIGEST (da->digest_size);
224 da->init (da->ctx); 226 da->init (da->ctx);
225 da->update (da->ctx, 227 da->update (da->ctx,
226 digest, 228 digest,
227 MHD_MD5_DIGEST_SIZE); 229 MHD_MD5_DIGEST_SIZE);
228 da->update (da->ctx, 230 da->update (da->ctx,
229 (const unsigned char *) ":", 231 (const unsigned char *) ":",
230 1); 232 1);
231 da->update (da->ctx, 233 da->update (da->ctx,
232 (const unsigned char *) nonce, 234 (const unsigned char *) nonce,
233 strlen (nonce)); 235 strlen (nonce));
234 da->update (da->ctx, 236 da->update (da->ctx,
235 (const unsigned char *) ":", 237 (const unsigned char *) ":",
236 1); 238 1);
237 da->update (da->ctx, 239 da->update (da->ctx,
238 (const unsigned char *) cnonce, 240 (const unsigned char *) cnonce,
239 strlen (cnonce)); 241 strlen (cnonce));
240 da->digest (da->ctx, 242 da->digest (da->ctx,
241 dig); 243 dig);
242 cvthex (dig, 244 cvthex (dig,
243 sizeof (dig), 245 sizeof (dig),
244 da->sessionkey); 246 da->sessionkey);
245 } 247 }
246 else 248 else
247 { 249 {
248 cvthex (digest, 250 cvthex (digest,
249 da->digest_size, 251 da->digest_size,
250 da->sessionkey); 252 da->sessionkey);
251 } 253 }
252} 254}
253 255
254 256
@@ -268,20 +270,20 @@ digest_calc_ha1_from_digest (const char *alg,
268 */ 270 */
269static void 271static void
270digest_calc_ha1_from_user (const char *alg, 272digest_calc_ha1_from_user (const char *alg,
271 const char *username, 273 const char *username,
272 const char *realm, 274 const char *realm,
273 const char *password, 275 const char *password,
274 const char *nonce, 276 const char *nonce,
275 const char *cnonce, 277 const char *cnonce,
276 struct DigestAlgorithm *da) 278 struct DigestAlgorithm *da)
277{ 279{
278 unsigned char ha1[VLA_ARRAY_LEN_DIGEST(da->digest_size)]; 280 unsigned char ha1[VLA_ARRAY_LEN_DIGEST (da->digest_size)];
279 281
280 VLA_CHECK_LEN_DIGEST(da->digest_size); 282 VLA_CHECK_LEN_DIGEST (da->digest_size);
281 da->init (da->ctx); 283 da->init (da->ctx);
282 da->update (da->ctx, 284 da->update (da->ctx,
283 (const unsigned char *) username, 285 (const unsigned char *) username,
284 strlen (username)); 286 strlen (username));
285 da->update (da->ctx, 287 da->update (da->ctx,
286 (const unsigned char *) ":", 288 (const unsigned char *) ":",
287 1); 289 1);
@@ -322,20 +324,20 @@ digest_calc_ha1_from_user (const char *alg,
322 */ 324 */
323static void 325static void
324digest_calc_response (const char *ha1, 326digest_calc_response (const char *ha1,
325 const char *nonce, 327 const char *nonce,
326 const char *noncecount, 328 const char *noncecount,
327 const char *cnonce, 329 const char *cnonce,
328 const char *qop, 330 const char *qop,
329 const char *method, 331 const char *method,
330 const char *uri, 332 const char *uri,
331 const char *hentity, 333 const char *hentity,
332 struct DigestAlgorithm *da) 334 struct DigestAlgorithm *da)
333{ 335{
334 unsigned char ha2[VLA_ARRAY_LEN_DIGEST(da->digest_size)]; 336 unsigned char ha2[VLA_ARRAY_LEN_DIGEST (da->digest_size)];
335 unsigned char resphash[VLA_ARRAY_LEN_DIGEST(da->digest_size)]; 337 unsigned char resphash[VLA_ARRAY_LEN_DIGEST (da->digest_size)];
336 (void)hentity; /* Unused. Silence compiler warning. */ 338 (void) hentity; /* Unused. Silence compiler warning. */
337 339
338 VLA_CHECK_LEN_DIGEST(da->digest_size); 340 VLA_CHECK_LEN_DIGEST (da->digest_size);
339 da->init (da->ctx); 341 da->init (da->ctx);
340 da->update (da->ctx, 342 da->update (da->ctx,
341 (const unsigned char *) method, 343 (const unsigned char *) method,
@@ -344,22 +346,22 @@ digest_calc_response (const char *ha1,
344 (const unsigned char *) ":", 346 (const unsigned char *) ":",
345 1); 347 1);
346 da->update (da->ctx, 348 da->update (da->ctx,
347 (const unsigned char *) uri, 349 (const unsigned char *) uri,
348 strlen (uri)); 350 strlen (uri));
349#if 0 351#if 0
350 if (0 == strcasecmp (qop, 352 if (0 == strcasecmp (qop,
351 "auth-int")) 353 "auth-int"))
352 { 354 {
353 /* This is dead code since the rest of this module does 355 /* This is dead code since the rest of this module does
354 not support auth-int. */ 356 not support auth-int. */
357 da->update (da->ctx,
358 ":",
359 1);
360 if (NULL != hentity)
355 da->update (da->ctx, 361 da->update (da->ctx,
356 ":", 362 hentity,
357 1); 363 strlen (hentity));
358 if (NULL != hentity) 364 }
359 da->update (da->ctx,
360 hentity,
361 strlen (hentity));
362 }
363#endif 365#endif
364 da->digest (da->ctx, 366 da->digest (da->ctx,
365 ha2); 367 ha2);
@@ -381,26 +383,26 @@ digest_calc_response (const char *ha1,
381 (const unsigned char*) ":", 383 (const unsigned char*) ":",
382 1); 384 1);
383 if ('\0' != *qop) 385 if ('\0' != *qop)
384 { 386 {
385 da->update (da->ctx, 387 da->update (da->ctx,
386 (const unsigned char *) noncecount, 388 (const unsigned char *) noncecount,
387 strlen (noncecount)); 389 strlen (noncecount));
388 da->update (da->ctx, 390 da->update (da->ctx,
389 (const unsigned char *) ":", 391 (const unsigned char *) ":",
390 1); 392 1);
391 da->update (da->ctx, 393 da->update (da->ctx,
392 (const unsigned char *) cnonce, 394 (const unsigned char *) cnonce,
393 strlen (cnonce)); 395 strlen (cnonce));
394 da->update (da->ctx, 396 da->update (da->ctx,
395 (const unsigned char *) ":", 397 (const unsigned char *) ":",
396 1); 398 1);
397 da->update (da->ctx, 399 da->update (da->ctx,
398 (const unsigned char *) qop, 400 (const unsigned char *) qop,
399 strlen (qop)); 401 strlen (qop));
400 da->update (da->ctx, 402 da->update (da->ctx,
401 (const unsigned char *) ":", 403 (const unsigned char *) ":",
402 1); 404 1);
403 } 405 }
404 da->update (da->ctx, 406 da->update (da->ctx,
405 (const unsigned char *) da->sessionkey, 407 (const unsigned char *) da->sessionkey,
406 da->digest_size * 2); 408 da->digest_size * 2);
@@ -428,9 +430,9 @@ digest_calc_response (const char *ha1,
428 */ 430 */
429static size_t 431static size_t
430lookup_sub_value (char *dest, 432lookup_sub_value (char *dest,
431 size_t size, 433 size_t size,
432 const char *data, 434 const char *data,
433 const char *key) 435 const char *key)
434{ 436{
435 size_t keylen; 437 size_t keylen;
436 size_t len; 438 size_t len;
@@ -445,67 +447,67 @@ lookup_sub_value (char *dest,
445 keylen = strlen (key); 447 keylen = strlen (key);
446 ptr = data; 448 ptr = data;
447 while ('\0' != *ptr) 449 while ('\0' != *ptr)
450 {
451 if (NULL == (eq = strchr (ptr,
452 '=')))
453 return 0;
454 q1 = eq + 1;
455 while (' ' == *q1)
456 q1++;
457 if ('\"' != *q1)
458 {
459 q2 = strchr (q1,
460 ',');
461 qn = q2;
462 }
463 else
464 {
465 q1++;
466 q2 = strchr (q1,
467 '\"');
468 if (NULL == q2)
469 return 0; /* end quote not found */
470 qn = q2 + 1;
471 }
472 if ( (MHD_str_equal_caseless_n_ (ptr,
473 key,
474 keylen)) &&
475 (eq == &ptr[keylen]) )
448 { 476 {
449 if (NULL == (eq = strchr (ptr, 477 if (NULL == q2)
450 '='))) 478 {
451 return 0; 479 len = strlen (q1) + 1;
452 q1 = eq + 1; 480 if (size > len)
453 while (' ' == *q1) 481 size = len;
454 q1++; 482 size--;
455 if ('\"' != *q1) 483 strncpy (dest,
456 { 484 q1,
457 q2 = strchr (q1, 485 size);
458 ','); 486 dest[size] = '\0';
459 qn = q2; 487 return size;
460 } 488 }
461 else 489 else
462 { 490 {
463 q1++; 491 if (size > (size_t) ((q2 - q1) + 1))
464 q2 = strchr (q1, 492 size = (q2 - q1) + 1;
465 '\"'); 493 size--;
466 if (NULL == q2) 494 memcpy (dest,
467 return 0; /* end quote not found */ 495 q1,
468 qn = q2 + 1; 496 size);
469 } 497 dest[size] = '\0';
470 if ( (MHD_str_equal_caseless_n_(ptr, 498 return size;
471 key, 499 }
472 keylen)) &&
473 (eq == &ptr[keylen]) )
474 {
475 if (NULL == q2)
476 {
477 len = strlen (q1) + 1;
478 if (size > len)
479 size = len;
480 size--;
481 strncpy (dest,
482 q1,
483 size);
484 dest[size] = '\0';
485 return size;
486 }
487 else
488 {
489 if (size > (size_t) ((q2 - q1) + 1))
490 size = (q2 - q1) + 1;
491 size--;
492 memcpy (dest,
493 q1,
494 size);
495 dest[size] = '\0';
496 return size;
497 }
498 }
499 if (NULL == qn)
500 return 0;
501 ptr = strchr (qn,
502 ',');
503 if (NULL == ptr)
504 return 0;
505 ptr++;
506 while (' ' == *ptr)
507 ptr++;
508 } 500 }
501 if (NULL == qn)
502 return 0;
503 ptr = strchr (qn,
504 ',');
505 if (NULL == ptr)
506 return 0;
507 ptr++;
508 while (' ' == *ptr)
509 ptr++;
510 }
509 return 0; 511 return 0;
510} 512}
511 513
@@ -521,8 +523,8 @@ lookup_sub_value (char *dest,
521 */ 523 */
522static int 524static int
523check_nonce_nc (struct MHD_Connection *connection, 525check_nonce_nc (struct MHD_Connection *connection,
524 const char *nonce, 526 const char *nonce,
525 uint64_t nc) 527 uint64_t nc)
526{ 528{
527 struct MHD_Daemon *daemon = connection->daemon; 529 struct MHD_Daemon *daemon = connection->daemon;
528 struct MHD_NonceNc *nn; 530 struct MHD_NonceNc *nn;
@@ -544,10 +546,10 @@ check_nonce_nc (struct MHD_Connection *connection,
544 off = 0; 546 off = 0;
545 np = nonce; 547 np = nonce;
546 while ('\0' != *np) 548 while ('\0' != *np)
547 { 549 {
548 off = (off << 8) | (*np ^ (off >> 24)); 550 off = (off << 8) | (*np ^ (off >> 24));
549 np++; 551 np++;
550 } 552 }
551 off = off % mod; 553 off = off % mod;
552 /* 554 /*
553 * Look for the nonce, if it does exist and its corresponding 555 * Look for the nonce, if it does exist and its corresponding
@@ -559,47 +561,48 @@ check_nonce_nc (struct MHD_Connection *connection,
559 MHD_mutex_lock_chk_ (&daemon->nnc_lock); 561 MHD_mutex_lock_chk_ (&daemon->nnc_lock);
560#endif 562#endif
561 if (0 == nc) 563 if (0 == nc)
562 { 564 {
563 /* Fresh nonce, reinitialize array */ 565 /* Fresh nonce, reinitialize array */
564 memcpy (nn->nonce, 566 memcpy (nn->nonce,
565 nonce, 567 nonce,
566 noncelen); 568 noncelen);
567 nn->nc = 0; 569 nn->nc = 0;
568 nn->nmask = 0; 570 nn->nmask = 0;
569#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 571#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
570 MHD_mutex_unlock_chk_ (&daemon->nnc_lock); 572 MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
571#endif 573#endif
572 return MHD_YES; 574 return MHD_YES;
573 } 575 }
574 /* Note that we use 64 here, as we do not store the 576 /* Note that we use 64 here, as we do not store the
575 bit for 'nn->nc' itself in 'nn->nmask' */ 577 bit for 'nn->nc' itself in 'nn->nmask' */
576 if ( (nc < nn->nc) && 578 if ( (nc < nn->nc) &&
577 (nc + 64 > nc /* checking for overflow */) && 579 (nc + 64 > nc /* checking for overflow */) &&
578 (nc + 64 >= nn->nc) && 580 (nc + 64 >= nn->nc) &&
579 (0 == ((1LLU << (nn->nc - nc - 1)) & nn->nmask)) ) 581 (0 == ((1LLU << (nn->nc - nc - 1)) & nn->nmask)) )
580 { 582 {
581 /* Out-of-order nonce, but within 64-bit bitmask, set bit */ 583 /* Out-of-order nonce, but within 64-bit bitmask, set bit */
582 nn->nmask |= (1LLU << (nn->nc - nc - 1)); 584 nn->nmask |= (1LLU << (nn->nc - nc - 1));
583#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 585#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
584 MHD_mutex_unlock_chk_ (&daemon->nnc_lock); 586 MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
585#endif 587#endif
586 return MHD_YES; 588 return MHD_YES;
587 } 589 }
588 590
589 if ( (nc <= nn->nc) || 591 if ( (nc <= nn->nc) ||
590 (0 != strcmp (nn->nonce, 592 (0 != strcmp (nn->nonce,
591 nonce)) ) 593 nonce)) )
592 { 594 {
593 /* Nonce does not match, fail */ 595 /* Nonce does not match, fail */
594#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 596#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
595 MHD_mutex_unlock_chk_ (&daemon->nnc_lock); 597 MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
596#endif 598#endif
597#ifdef HAVE_MESSAGES 599#ifdef HAVE_MESSAGES
598 MHD_DLOG (daemon, 600 MHD_DLOG (daemon,
599 _("Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n")); 601 _ (
602 "Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n"));
600#endif 603#endif
601 return MHD_NO; 604 return MHD_NO;
602 } 605 }
603 /* Nonce is larger, shift bitmask and bump limit */ 606 /* Nonce is larger, shift bitmask and bump limit */
604 if (64 > nc - nn->nc) 607 if (64 > nc - nn->nc)
605 nn->nmask <<= (nc - nn->nc); /* small jump, less than mask width */ 608 nn->nmask <<= (nc - nn->nc); /* small jump, less than mask width */
@@ -618,12 +621,12 @@ check_nonce_nc (struct MHD_Connection *connection,
618 * 621 *
619 * @param connection The MHD connection structure 622 * @param connection The MHD connection structure
620 * @return NULL if no username could be found, a pointer 623 * @return NULL if no username could be found, a pointer
621 * to the username if found 624 * to the username if found
622 * @warning Returned value must be freed by #MHD_free(). 625 * @warning Returned value must be freed by #MHD_free().
623 * @ingroup authentication 626 * @ingroup authentication
624 */ 627 */
625char * 628char *
626MHD_digest_auth_get_username(struct MHD_Connection *connection) 629MHD_digest_auth_get_username (struct MHD_Connection *connection)
627{ 630{
628 size_t len; 631 size_t len;
629 char user[MAX_USERNAME_LENGTH]; 632 char user[MAX_USERNAME_LENGTH];
@@ -632,7 +635,8 @@ MHD_digest_auth_get_username(struct MHD_Connection *connection)
632 if (MHD_NO == MHD_lookup_connection_value_n (connection, 635 if (MHD_NO == MHD_lookup_connection_value_n (connection,
633 MHD_HEADER_KIND, 636 MHD_HEADER_KIND,
634 MHD_HTTP_HEADER_AUTHORIZATION, 637 MHD_HTTP_HEADER_AUTHORIZATION,
635 MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION), 638 MHD_STATICSTR_LEN_ (
639 MHD_HTTP_HEADER_AUTHORIZATION),
636 &header, 640 &header,
637 NULL)) 641 NULL))
638 return NULL; 642 return NULL;
@@ -642,9 +646,9 @@ MHD_digest_auth_get_username(struct MHD_Connection *connection)
642 return NULL; 646 return NULL;
643 header += MHD_STATICSTR_LEN_ (_BASE); 647 header += MHD_STATICSTR_LEN_ (_BASE);
644 if (0 == (len = lookup_sub_value (user, 648 if (0 == (len = lookup_sub_value (user,
645 sizeof (user), 649 sizeof (user),
646 header, 650 header,
647 "username"))) 651 "username")))
648 return NULL; 652 return NULL;
649 return strdup (user); 653 return strdup (user);
650} 654}
@@ -667,24 +671,24 @@ MHD_digest_auth_get_username(struct MHD_Connection *connection)
667 */ 671 */
668static void 672static void
669calculate_nonce (uint32_t nonce_time, 673calculate_nonce (uint32_t nonce_time,
670 const char *method, 674 const char *method,
671 const char *rnd, 675 const char *rnd,
672 size_t rnd_size, 676 size_t rnd_size,
673 const char *uri, 677 const char *uri,
674 const char *realm, 678 const char *realm,
675 struct DigestAlgorithm *da, 679 struct DigestAlgorithm *da,
676 char *nonce) 680 char *nonce)
677{ 681{
678 unsigned char timestamp[TIMESTAMP_BIN_SIZE]; 682 unsigned char timestamp[TIMESTAMP_BIN_SIZE];
679 unsigned char tmpnonce[VLA_ARRAY_LEN_DIGEST(da->digest_size)]; 683 unsigned char tmpnonce[VLA_ARRAY_LEN_DIGEST (da->digest_size)];
680 char timestamphex[TIMESTAMP_BIN_SIZE * 2 + 1]; 684 char timestamphex[TIMESTAMP_BIN_SIZE * 2 + 1];
681 685
682 VLA_CHECK_LEN_DIGEST(da->digest_size); 686 VLA_CHECK_LEN_DIGEST (da->digest_size);
683 da->init (da->ctx); 687 da->init (da->ctx);
684 timestamp[0] = (unsigned char)((nonce_time & 0xff000000) >> 0x18); 688 timestamp[0] = (unsigned char) ((nonce_time & 0xff000000) >> 0x18);
685 timestamp[1] = (unsigned char)((nonce_time & 0x00ff0000) >> 0x10); 689 timestamp[1] = (unsigned char) ((nonce_time & 0x00ff0000) >> 0x10);
686 timestamp[2] = (unsigned char)((nonce_time & 0x0000ff00) >> 0x08); 690 timestamp[2] = (unsigned char) ((nonce_time & 0x0000ff00) >> 0x08);
687 timestamp[3] = (unsigned char)((nonce_time & 0x000000ff)); 691 timestamp[3] = (unsigned char) ((nonce_time & 0x000000ff));
688 da->update (da->ctx, 692 da->update (da->ctx,
689 timestamp, 693 timestamp,
690 sizeof (timestamp)); 694 sizeof (timestamp));
@@ -742,37 +746,37 @@ calculate_nonce (uint32_t nonce_time,
742 */ 746 */
743static int 747static int
744test_header (struct MHD_Connection *connection, 748test_header (struct MHD_Connection *connection,
745 const char *key, 749 const char *key,
746 size_t key_size, 750 size_t key_size,
747 const char *value, 751 const char *value,
748 size_t value_size, 752 size_t value_size,
749 enum MHD_ValueKind kind) 753 enum MHD_ValueKind kind)
750{ 754{
751 struct MHD_HTTP_Header *pos; 755 struct MHD_HTTP_Header *pos;
752 756
753 for (pos = connection->headers_received; NULL != pos; pos = pos->next) 757 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
754 { 758 {
755 if (kind != pos->kind) 759 if (kind != pos->kind)
756 continue; 760 continue;
757 if (key_size != pos->header_size) 761 if (key_size != pos->header_size)
758 continue; 762 continue;
759 if (value_size != pos->value_size) 763 if (value_size != pos->value_size)
760 continue; 764 continue;
761 if (0 != memcmp (key, 765 if (0 != memcmp (key,
762 pos->header, 766 pos->header,
763 key_size)) 767 key_size))
764 continue; 768 continue;
765 if ( (NULL == value) && 769 if ( (NULL == value) &&
766 (NULL == pos->value) ) 770 (NULL == pos->value) )
767 return MHD_YES;
768 if ( (NULL == value) ||
769 (NULL == pos->value) ||
770 (0 != memcmp (value,
771 pos->value,
772 value_size)) )
773 continue;
774 return MHD_YES; 771 return MHD_YES;
775 } 772 if ( (NULL == value) ||
773 (NULL == pos->value) ||
774 (0 != memcmp (value,
775 pos->value,
776 value_size)) )
777 continue;
778 return MHD_YES;
779 }
776 return MHD_NO; 780 return MHD_NO;
777} 781}
778 782
@@ -789,7 +793,7 @@ test_header (struct MHD_Connection *connection,
789 */ 793 */
790static int 794static int
791check_argument_match (struct MHD_Connection *connection, 795check_argument_match (struct MHD_Connection *connection,
792 const char *args) 796 const char *args)
793{ 797{
794 struct MHD_HTTP_Header *pos; 798 struct MHD_HTTP_Header *pos;
795 char *argb; 799 char *argb;
@@ -798,35 +802,35 @@ check_argument_match (struct MHD_Connection *connection,
798 802
799 argb = strdup (args); 803 argb = strdup (args);
800 if (NULL == argb) 804 if (NULL == argb)
801 { 805 {
802#ifdef HAVE_MESSAGES 806#ifdef HAVE_MESSAGES
803 MHD_DLOG (connection->daemon, 807 MHD_DLOG (connection->daemon,
804 _("Failed to allocate memory for copy of URI arguments\n")); 808 _ ("Failed to allocate memory for copy of URI arguments\n"));
805#endif /* HAVE_MESSAGES */ 809#endif /* HAVE_MESSAGES */
806 return MHD_NO; 810 return MHD_NO;
807 } 811 }
808 ret = MHD_parse_arguments_ (connection, 812 ret = MHD_parse_arguments_ (connection,
809 MHD_GET_ARGUMENT_KIND, 813 MHD_GET_ARGUMENT_KIND,
810 argb, 814 argb,
811 &test_header, 815 &test_header,
812 &num_headers); 816 &num_headers);
813 free (argb); 817 free (argb);
814 if (MHD_YES != ret) 818 if (MHD_YES != ret)
815 { 819 {
816 return MHD_NO; 820 return MHD_NO;
817 } 821 }
818 /* also check that the number of headers matches */ 822 /* also check that the number of headers matches */
819 for (pos = connection->headers_received; NULL != pos; pos = pos->next) 823 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
820 { 824 {
821 if (MHD_GET_ARGUMENT_KIND != pos->kind) 825 if (MHD_GET_ARGUMENT_KIND != pos->kind)
822 continue; 826 continue;
823 num_headers--; 827 num_headers--;
824 } 828 }
825 if (0 != num_headers) 829 if (0 != num_headers)
826 { 830 {
827 /* argument count mismatch */ 831 /* argument count mismatch */
828 return MHD_NO; 832 return MHD_NO;
829 } 833 }
830 return MHD_YES; 834 return MHD_YES;
831} 835}
832 836
@@ -842,51 +846,52 @@ check_argument_match (struct MHD_Connection *connection,
842 * @param username The username needs to be authenticated 846 * @param username The username needs to be authenticated
843 * @param password The password used in the authentication 847 * @param password The password used in the authentication
844 * @param digest An optional binary hash 848 * @param digest An optional binary hash
845 * of the precalculated hash value "username:realm:password" 849 * of the precalculated hash value "username:realm:password"
846 * (must contain "da->digest_size" bytes or be NULL) 850 * (must contain "da->digest_size" bytes or be NULL)
847 * @param nonce_timeout The amount of time for a nonce to be 851 * @param nonce_timeout The amount of time for a nonce to be
848 * invalid in seconds 852 * invalid in seconds
849 * @return #MHD_YES if authenticated, #MHD_NO if not, 853 * @return #MHD_YES if authenticated, #MHD_NO if not,
850 * #MHD_INVALID_NONCE if nonce is invalid 854 * #MHD_INVALID_NONCE if nonce is invalid
851 * @ingroup authentication 855 * @ingroup authentication
852 */ 856 */
853static int 857static int
854digest_auth_check_all (struct MHD_Connection *connection, 858digest_auth_check_all (struct MHD_Connection *connection,
855 struct DigestAlgorithm *da, 859 struct DigestAlgorithm *da,
856 const char *realm, 860 const char *realm,
857 const char *username, 861 const char *username,
858 const char *password, 862 const char *password,
859 const uint8_t *digest, 863 const uint8_t *digest,
860 unsigned int nonce_timeout) 864 unsigned int nonce_timeout)
861{ 865{
862 struct MHD_Daemon *daemon = connection->daemon; 866 struct MHD_Daemon *daemon = connection->daemon;
863 size_t len; 867 size_t len;
864 const char *header; 868 const char *header;
865 char nonce[MAX_NONCE_LENGTH]; 869 char nonce[MAX_NONCE_LENGTH];
866 char cnonce[MAX_NONCE_LENGTH]; 870 char cnonce[MAX_NONCE_LENGTH];
867 char ha1[VLA_ARRAY_LEN_DIGEST(da->digest_size) * 2 + 1]; 871 char ha1[VLA_ARRAY_LEN_DIGEST (da->digest_size) * 2 + 1];
868 char qop[15]; /* auth,auth-int */ 872 char qop[15]; /* auth,auth-int */
869 char nc[20]; 873 char nc[20];
870 char response[MAX_AUTH_RESPONSE_LENGTH]; 874 char response[MAX_AUTH_RESPONSE_LENGTH];
871 const char *hentity = NULL; /* "auth-int" is not supported */ 875 const char *hentity = NULL; /* "auth-int" is not supported */
872 char noncehashexp[NONCE_STD_LEN(VLA_ARRAY_LEN_DIGEST(da->digest_size)) + 1]; 876 char noncehashexp[NONCE_STD_LEN (VLA_ARRAY_LEN_DIGEST (da->digest_size)) + 1];
873 uint32_t nonce_time; 877 uint32_t nonce_time;
874 uint32_t t; 878 uint32_t t;
875 size_t left; /* number of characters left in 'header' for 'uri' */ 879 size_t left; /* number of characters left in 'header' for 'uri' */
876 uint64_t nci; 880 uint64_t nci;
877 char *qmark; 881 char *qmark;
878 882
879 VLA_CHECK_LEN_DIGEST(da->digest_size); 883 VLA_CHECK_LEN_DIGEST (da->digest_size);
880 if (MHD_NO == MHD_lookup_connection_value_n (connection, 884 if (MHD_NO == MHD_lookup_connection_value_n (connection,
881 MHD_HEADER_KIND, 885 MHD_HEADER_KIND,
882 MHD_HTTP_HEADER_AUTHORIZATION, 886 MHD_HTTP_HEADER_AUTHORIZATION,
883 MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION), 887 MHD_STATICSTR_LEN_ (
888 MHD_HTTP_HEADER_AUTHORIZATION),
884 &header, 889 &header,
885 NULL)) 890 NULL))
886 return MHD_NO; 891 return MHD_NO;
887 if (0 != strncmp (header, 892 if (0 != strncmp (header,
888 _BASE, 893 _BASE,
889 MHD_STATICSTR_LEN_(_BASE))) 894 MHD_STATICSTR_LEN_ (_BASE)))
890 return MHD_NO; 895 return MHD_NO;
891 header += MHD_STATICSTR_LEN_ (_BASE); 896 header += MHD_STATICSTR_LEN_ (_BASE);
892 left = strlen (header); 897 left = strlen (header);
@@ -895,11 +900,11 @@ digest_auth_check_all (struct MHD_Connection *connection,
895 char un[MAX_USERNAME_LENGTH]; 900 char un[MAX_USERNAME_LENGTH];
896 901
897 len = lookup_sub_value (un, 902 len = lookup_sub_value (un,
898 sizeof (un), 903 sizeof (un),
899 header, 904 header,
900 "username"); 905 "username");
901 if ( (0 == len) || 906 if ( (0 == len) ||
902 (0 != strcmp (username, 907 (0 != strcmp (username,
903 un)) ) 908 un)) )
904 return MHD_NO; 909 return MHD_NO;
905 left -= strlen ("username") + len; 910 left -= strlen ("username") + len;
@@ -913,15 +918,15 @@ digest_auth_check_all (struct MHD_Connection *connection,
913 header, 918 header,
914 "realm"); 919 "realm");
915 if ( (0 == len) || 920 if ( (0 == len) ||
916 (0 != strcmp (realm, 921 (0 != strcmp (realm,
917 r)) ) 922 r)) )
918 return MHD_NO; 923 return MHD_NO;
919 left -= strlen ("realm") + len; 924 left -= strlen ("realm") + len;
920 } 925 }
921 926
922 if (0 == (len = lookup_sub_value (nonce, 927 if (0 == (len = lookup_sub_value (nonce,
923 sizeof (nonce), 928 sizeof (nonce),
924 header, 929 header,
925 "nonce"))) 930 "nonce")))
926 return MHD_NO; 931 return MHD_NO;
927 left -= strlen ("nonce") + len; 932 left -= strlen ("nonce") + len;
@@ -940,14 +945,14 @@ digest_auth_check_all (struct MHD_Connection *connection,
940 MHD_strx_to_uint32_n_ (nonce + len - TIMESTAMP_BIN_SIZE * 2, 945 MHD_strx_to_uint32_n_ (nonce + len - TIMESTAMP_BIN_SIZE * 2,
941 TIMESTAMP_BIN_SIZE * 2, 946 TIMESTAMP_BIN_SIZE * 2,
942 &nonce_time)) 947 &nonce_time))
943 { 948 {
944#ifdef HAVE_MESSAGES 949#ifdef HAVE_MESSAGES
945 MHD_DLOG (daemon, 950 MHD_DLOG (daemon,
946 _("Authentication failed, invalid timestamp format.\n")); 951 _ ("Authentication failed, invalid timestamp format.\n"));
947#endif 952#endif
948 return MHD_NO; 953 return MHD_NO;
949 } 954 }
950 t = (uint32_t) MHD_monotonic_sec_counter(); 955 t = (uint32_t) MHD_monotonic_sec_counter ();
951 /* 956 /*
952 * First level vetting for the nonce validity: if the timestamp 957 * First level vetting for the nonce validity: if the timestamp
953 * attached to the nonce exceeds `nonce_timeout', then the nonce is 958 * attached to the nonce exceeds `nonce_timeout', then the nonce is
@@ -955,10 +960,10 @@ digest_auth_check_all (struct MHD_Connection *connection,
955 */ 960 */
956 if ( (t > nonce_time + nonce_timeout) || 961 if ( (t > nonce_time + nonce_timeout) ||
957 (nonce_time + nonce_timeout < nonce_time) ) 962 (nonce_time + nonce_timeout < nonce_time) )
958 { 963 {
959 /* too old */ 964 /* too old */
960 return MHD_INVALID_NONCE; 965 return MHD_INVALID_NONCE;
961 } 966 }
962 967
963 calculate_nonce (nonce_time, 968 calculate_nonce (nonce_time,
964 connection->method, 969 connection->method,
@@ -980,9 +985,9 @@ digest_auth_check_all (struct MHD_Connection *connection,
980 985
981 if (0 != strcmp (nonce, 986 if (0 != strcmp (nonce,
982 noncehashexp)) 987 noncehashexp))
983 { 988 {
984 return MHD_INVALID_NONCE; 989 return MHD_INVALID_NONCE;
985 } 990 }
986 if ( (0 == lookup_sub_value (cnonce, 991 if ( (0 == lookup_sub_value (cnonce,
987 sizeof (cnonce), 992 sizeof (cnonce),
988 header, 993 header,
@@ -1003,23 +1008,23 @@ digest_auth_check_all (struct MHD_Connection *connection,
1003 sizeof (response), 1008 sizeof (response),
1004 header, 1009 header,
1005 "response")) ) 1010 "response")) )
1006 { 1011 {
1007#ifdef HAVE_MESSAGES 1012#ifdef HAVE_MESSAGES
1008 MHD_DLOG (daemon, 1013 MHD_DLOG (daemon,
1009 _("Authentication failed, invalid format.\n")); 1014 _ ("Authentication failed, invalid format.\n"));
1010#endif 1015#endif
1011 return MHD_NO; 1016 return MHD_NO;
1012 } 1017 }
1013 if (len != MHD_strx_to_uint64_n_ (nc, 1018 if (len != MHD_strx_to_uint64_n_ (nc,
1014 len, 1019 len,
1015 &nci)) 1020 &nci))
1016 { 1021 {
1017#ifdef HAVE_MESSAGES 1022#ifdef HAVE_MESSAGES
1018 MHD_DLOG (daemon, 1023 MHD_DLOG (daemon,
1019 _("Authentication failed, invalid nc format.\n")); 1024 _ ("Authentication failed, invalid nc format.\n"));
1020#endif 1025#endif
1021 return MHD_NO; /* invalid nonce format */ 1026 return MHD_NO; /* invalid nonce format */
1022 } 1027 }
1023 1028
1024 /* 1029 /*
1025 * Checking if that combination of nonce and nc is sound 1030 * Checking if that combination of nonce and nc is sound
@@ -1030,64 +1035,64 @@ digest_auth_check_all (struct MHD_Connection *connection,
1030 check_nonce_nc (connection, 1035 check_nonce_nc (connection,
1031 nonce, 1036 nonce,
1032 nci)) 1037 nci))
1033 { 1038 {
1034 return MHD_NO; 1039 return MHD_NO;
1035 } 1040 }
1036 1041
1037 { 1042 {
1038 char *uri; 1043 char *uri;
1039 1044
1040 uri = malloc (left + 1); 1045 uri = malloc (left + 1);
1041 if (NULL == uri) 1046 if (NULL == uri)
1042 { 1047 {
1043#ifdef HAVE_MESSAGES 1048#ifdef HAVE_MESSAGES
1044 MHD_DLOG(daemon, 1049 MHD_DLOG (daemon,
1045 _("Failed to allocate memory for auth header processing\n")); 1050 _ ("Failed to allocate memory for auth header processing\n"));
1046#endif /* HAVE_MESSAGES */ 1051#endif /* HAVE_MESSAGES */
1047 return MHD_NO; 1052 return MHD_NO;
1048 } 1053 }
1049 if (0 == lookup_sub_value (uri, 1054 if (0 == lookup_sub_value (uri,
1050 left + 1, 1055 left + 1,
1051 header, 1056 header,
1052 "uri")) 1057 "uri"))
1053 { 1058 {
1054 free (uri); 1059 free (uri);
1055 return MHD_NO; 1060 return MHD_NO;
1056 } 1061 }
1057 if (NULL != digest) 1062 if (NULL != digest)
1058 { 1063 {
1059 /* This will initialize da->sessionkey (ha1) */ 1064 /* This will initialize da->sessionkey (ha1) */
1060 digest_calc_ha1_from_digest (da->alg, 1065 digest_calc_ha1_from_digest (da->alg,
1061 da, 1066 da,
1062 digest, 1067 digest,
1063 nonce, 1068 nonce,
1064 cnonce); 1069 cnonce);
1065 } 1070 }
1066 else 1071 else
1067 { 1072 {
1068 /* This will initialize da->sessionkey (ha1) */ 1073 /* This will initialize da->sessionkey (ha1) */
1069 mhd_assert (NULL != password); /* NULL == digest => password != NULL */ 1074 mhd_assert (NULL != password); /* NULL == digest => password != NULL */
1070 digest_calc_ha1_from_user (da->alg, 1075 digest_calc_ha1_from_user (da->alg,
1071 username, 1076 username,
1072 realm, 1077 realm,
1073 password, 1078 password,
1074 nonce, 1079 nonce,
1075 cnonce, 1080 cnonce,
1076 da); 1081 da);
1077 } 1082 }
1078 memcpy (ha1, 1083 memcpy (ha1,
1079 da->sessionkey, 1084 da->sessionkey,
1080 sizeof (ha1)); 1085 sizeof (ha1));
1081 /* This will initialize da->sessionkey (respexp) */ 1086 /* This will initialize da->sessionkey (respexp) */
1082 digest_calc_response (ha1, 1087 digest_calc_response (ha1,
1083 nonce, 1088 nonce,
1084 nc, 1089 nc,
1085 cnonce, 1090 cnonce,
1086 qop, 1091 qop,
1087 connection->method, 1092 connection->method,
1088 uri, 1093 uri,
1089 hentity, 1094 hentity,
1090 da); 1095 da);
1091 qmark = strchr (uri, 1096 qmark = strchr (uri,
1092 '?'); 1097 '?');
1093 if (NULL != qmark) 1098 if (NULL != qmark)
@@ -1102,7 +1107,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
1102 { 1107 {
1103#ifdef HAVE_MESSAGES 1108#ifdef HAVE_MESSAGES
1104 MHD_DLOG (daemon, 1109 MHD_DLOG (daemon,
1105 _("Authentication failed, URI does not match.\n")); 1110 _ ("Authentication failed, URI does not match.\n"));
1106#endif 1111#endif
1107 free (uri); 1112 free (uri);
1108 return MHD_NO; 1113 return MHD_NO;
@@ -1112,26 +1117,26 @@ digest_auth_check_all (struct MHD_Connection *connection,
1112 const char *args = qmark; 1117 const char *args = qmark;
1113 1118
1114 if (NULL == args) 1119 if (NULL == args)
1115 args = ""; 1120 args = "";
1116 else 1121 else
1117 args++; 1122 args++;
1118 if (MHD_YES != 1123 if (MHD_YES !=
1119 check_argument_match (connection, 1124 check_argument_match (connection,
1120 args) ) 1125 args) )
1121 { 1126 {
1122#ifdef HAVE_MESSAGES 1127#ifdef HAVE_MESSAGES
1123 MHD_DLOG (daemon, 1128 MHD_DLOG (daemon,
1124 _("Authentication failed, arguments do not match.\n")); 1129 _ ("Authentication failed, arguments do not match.\n"));
1125#endif 1130#endif
1126 free (uri); 1131 free (uri);
1127 return MHD_NO; 1132 return MHD_NO;
1128 } 1133 }
1129 } 1134 }
1130 free (uri); 1135 free (uri);
1131 return (0 == strcmp (response, 1136 return (0 == strcmp (response,
1132 da->sessionkey)) 1137 da->sessionkey))
1133 ? MHD_YES 1138 ? MHD_YES
1134 : MHD_NO; 1139 : MHD_NO;
1135 } 1140 }
1136} 1141}
1137 1142
@@ -1148,17 +1153,17 @@ digest_auth_check_all (struct MHD_Connection *connection,
1148 * @param username The username needs to be authenticated 1153 * @param username The username needs to be authenticated
1149 * @param password The password used in the authentication 1154 * @param password The password used in the authentication
1150 * @param nonce_timeout The amount of time for a nonce to be 1155 * @param nonce_timeout The amount of time for a nonce to be
1151 * invalid in seconds 1156 * invalid in seconds
1152 * @return #MHD_YES if authenticated, #MHD_NO if not, 1157 * @return #MHD_YES if authenticated, #MHD_NO if not,
1153 * #MHD_INVALID_NONCE if nonce is invalid 1158 * #MHD_INVALID_NONCE if nonce is invalid
1154 * @ingroup authentication 1159 * @ingroup authentication
1155 */ 1160 */
1156_MHD_EXTERN int 1161_MHD_EXTERN int
1157MHD_digest_auth_check (struct MHD_Connection *connection, 1162MHD_digest_auth_check (struct MHD_Connection *connection,
1158 const char *realm, 1163 const char *realm,
1159 const char *username, 1164 const char *username,
1160 const char *password, 1165 const char *password,
1161 unsigned int nonce_timeout) 1166 unsigned int nonce_timeout)
1162{ 1167{
1163 return MHD_digest_auth_check2 (connection, 1168 return MHD_digest_auth_check2 (connection,
1164 realm, 1169 realm,
@@ -1189,29 +1194,29 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
1189 struct DigestAlgorithm da; \ 1194 struct DigestAlgorithm da; \
1190 \ 1195 \
1191 do { \ 1196 do { \
1192 switch (algo) { \ 1197 switch (algo) { \
1193 case MHD_DIGEST_ALG_MD5: \ 1198 case MHD_DIGEST_ALG_MD5: \
1194 da.digest_size = MD5_DIGEST_SIZE; \ 1199 da.digest_size = MD5_DIGEST_SIZE; \
1195 da.ctx = &ctx.md5; \ 1200 da.ctx = &ctx.md5; \
1196 da.alg = "md5"; \ 1201 da.alg = "md5"; \
1197 da.sessionkey = skey.md5; \ 1202 da.sessionkey = skey.md5; \
1198 da.init = &MHD_MD5Init; \ 1203 da.init = &MHD_MD5Init; \
1199 da.update = &MHD_MD5Update; \ 1204 da.update = &MHD_MD5Update; \
1200 da.digest = &MHD_MD5Final; \ 1205 da.digest = &MHD_MD5Final; \
1201 break; \ 1206 break; \
1202 case MHD_DIGEST_ALG_AUTO: \ 1207 case MHD_DIGEST_ALG_AUTO: \
1203 /* auto == SHA256, fall-though thus intentional! */ \ 1208 /* auto == SHA256, fall-though thus intentional! */ \
1204 case MHD_DIGEST_ALG_SHA256: \ 1209 case MHD_DIGEST_ALG_SHA256: \
1205 da.digest_size = SHA256_DIGEST_SIZE; \ 1210 da.digest_size = SHA256_DIGEST_SIZE; \
1206 da.ctx = &ctx.sha256; \ 1211 da.ctx = &ctx.sha256; \
1207 da.alg = "sha-256"; \ 1212 da.alg = "sha-256"; \
1208 da.sessionkey = skey.sha256; \ 1213 da.sessionkey = skey.sha256; \
1209 da.init = &MHD_SHA256_init; \ 1214 da.init = &MHD_SHA256_init; \
1210 da.update = &MHD_SHA256_update; \ 1215 da.update = &MHD_SHA256_update; \
1211 da.digest = &sha256_finish; \ 1216 da.digest = &sha256_finish; \
1212 break; \ 1217 break; \
1213 } \ 1218 } \
1214 } while(0) 1219 } while (0)
1215 1220
1216 1221
1217 1222
@@ -1223,19 +1228,19 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
1223 * @param username The username needs to be authenticated 1228 * @param username The username needs to be authenticated
1224 * @param password The password used in the authentication 1229 * @param password The password used in the authentication
1225 * @param nonce_timeout The amount of time for a nonce to be 1230 * @param nonce_timeout The amount of time for a nonce to be
1226 * invalid in seconds 1231 * invalid in seconds
1227 * @param algo digest algorithms allowed for verification 1232 * @param algo digest algorithms allowed for verification
1228 * @return #MHD_YES if authenticated, #MHD_NO if not, 1233 * @return #MHD_YES if authenticated, #MHD_NO if not,
1229 * #MHD_INVALID_NONCE if nonce is invalid 1234 * #MHD_INVALID_NONCE if nonce is invalid
1230 * @ingroup authentication 1235 * @ingroup authentication
1231 */ 1236 */
1232_MHD_EXTERN int 1237_MHD_EXTERN int
1233MHD_digest_auth_check2 (struct MHD_Connection *connection, 1238MHD_digest_auth_check2 (struct MHD_Connection *connection,
1234 const char *realm, 1239 const char *realm,
1235 const char *username, 1240 const char *username,
1236 const char *password, 1241 const char *password,
1237 unsigned int nonce_timeout, 1242 unsigned int nonce_timeout,
1238 enum MHD_DigestAuthAlgorithm algo) 1243 enum MHD_DigestAuthAlgorithm algo)
1239{ 1244{
1240 SETUP_DA (algo, da); 1245 SETUP_DA (algo, da);
1241 1246
@@ -1256,36 +1261,36 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection,
1256 * @param realm The realm presented to the client 1261 * @param realm The realm presented to the client
1257 * @param username The username needs to be authenticated 1262 * @param username The username needs to be authenticated
1258 * @param digest An `unsigned char *' pointer to the binary MD5 sum 1263 * @param digest An `unsigned char *' pointer to the binary MD5 sum
1259 * for the precalculated hash value "username:realm:password" 1264 * for the precalculated hash value "username:realm:password"
1260 * of #MHD_MD5_DIGEST_SIZE bytes 1265 * of #MHD_MD5_DIGEST_SIZE bytes
1261 * @param digest_size number of bytes in @a digest 1266 * @param digest_size number of bytes in @a digest
1262 * @param nonce_timeout The amount of time for a nonce to be 1267 * @param nonce_timeout The amount of time for a nonce to be
1263 * invalid in seconds 1268 * invalid in seconds
1264 * @param algo digest algorithms allowed for verification 1269 * @param algo digest algorithms allowed for verification
1265 * @return #MHD_YES if authenticated, #MHD_NO if not, 1270 * @return #MHD_YES if authenticated, #MHD_NO if not,
1266 * #MHD_INVALID_NONCE if nonce is invalid 1271 * #MHD_INVALID_NONCE if nonce is invalid
1267 * @ingroup authentication 1272 * @ingroup authentication
1268 */ 1273 */
1269_MHD_EXTERN int 1274_MHD_EXTERN int
1270MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, 1275MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
1271 const char *realm, 1276 const char *realm,
1272 const char *username, 1277 const char *username,
1273 const uint8_t *digest, 1278 const uint8_t *digest,
1274 size_t digest_size, 1279 size_t digest_size,
1275 unsigned int nonce_timeout, 1280 unsigned int nonce_timeout,
1276 enum MHD_DigestAuthAlgorithm algo) 1281 enum MHD_DigestAuthAlgorithm algo)
1277{ 1282{
1278 SETUP_DA (algo, da); 1283 SETUP_DA (algo, da);
1279 1284
1280 if (da.digest_size != digest_size) 1285 if (da.digest_size != digest_size)
1281 MHD_PANIC (_("digest size missmatch")); /* API violation! */ 1286 MHD_PANIC (_ ("digest size missmatch")); /* API violation! */
1282 return digest_auth_check_all (connection, 1287 return digest_auth_check_all (connection,
1283 &da, 1288 &da,
1284 realm, 1289 realm,
1285 username, 1290 username,
1286 NULL, 1291 NULL,
1287 digest, 1292 digest,
1288 nonce_timeout); 1293 nonce_timeout);
1289} 1294}
1290 1295
1291 1296
@@ -1298,20 +1303,20 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
1298 * @param realm The realm presented to the client 1303 * @param realm The realm presented to the client
1299 * @param username The username needs to be authenticated 1304 * @param username The username needs to be authenticated
1300 * @param digest An `unsigned char *' pointer to the binary digest 1305 * @param digest An `unsigned char *' pointer to the binary digest
1301 * for the precalculated hash value "username:realm:password" 1306 * for the precalculated hash value "username:realm:password"
1302 * of @a digest_size bytes 1307 * of @a digest_size bytes
1303 * @param nonce_timeout The amount of time for a nonce to be 1308 * @param nonce_timeout The amount of time for a nonce to be
1304 * invalid in seconds 1309 * invalid in seconds
1305 * @return #MHD_YES if authenticated, #MHD_NO if not, 1310 * @return #MHD_YES if authenticated, #MHD_NO if not,
1306 * #MHD_INVALID_NONCE if nonce is invalid 1311 * #MHD_INVALID_NONCE if nonce is invalid
1307 * @ingroup authentication 1312 * @ingroup authentication
1308 */ 1313 */
1309_MHD_EXTERN int 1314_MHD_EXTERN int
1310MHD_digest_auth_check_digest (struct MHD_Connection *connection, 1315MHD_digest_auth_check_digest (struct MHD_Connection *connection,
1311 const char *realm, 1316 const char *realm,
1312 const char *username, 1317 const char *username,
1313 const uint8_t digest[MHD_MD5_DIGEST_SIZE], 1318 const uint8_t digest[MHD_MD5_DIGEST_SIZE],
1314 unsigned int nonce_timeout) 1319 unsigned int nonce_timeout)
1315{ 1320{
1316 return MHD_digest_auth_check_digest2 (connection, 1321 return MHD_digest_auth_check_digest2 (connection,
1317 realm, 1322 realm,
@@ -1333,29 +1338,29 @@ MHD_digest_auth_check_digest (struct MHD_Connection *connection,
1333 * body; note that this function will set the "WWW Authenticate" 1338 * body; note that this function will set the "WWW Authenticate"
1334 * header and that the caller should not do this 1339 * header and that the caller should not do this
1335 * @param signal_stale #MHD_YES if the nonce is invalid to add 1340 * @param signal_stale #MHD_YES if the nonce is invalid to add
1336 * 'stale=true' to the authentication header 1341 * 'stale=true' to the authentication header
1337 * @param algo digest algorithm to use 1342 * @param algo digest algorithm to use
1338 * @return #MHD_YES on success, #MHD_NO otherwise 1343 * @return #MHD_YES on success, #MHD_NO otherwise
1339 * @ingroup authentication 1344 * @ingroup authentication
1340 */ 1345 */
1341int 1346int
1342MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, 1347MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
1343 const char *realm, 1348 const char *realm,
1344 const char *opaque, 1349 const char *opaque,
1345 struct MHD_Response *response, 1350 struct MHD_Response *response,
1346 int signal_stale, 1351 int signal_stale,
1347 enum MHD_DigestAuthAlgorithm algo) 1352 enum MHD_DigestAuthAlgorithm algo)
1348{ 1353{
1349 int ret; 1354 int ret;
1350 int hlen; 1355 int hlen;
1351 SETUP_DA (algo, da); 1356 SETUP_DA (algo, da);
1352 1357
1353 { 1358 {
1354 char nonce[NONCE_STD_LEN(VLA_ARRAY_LEN_DIGEST (da.digest_size)) + 1]; 1359 char nonce[NONCE_STD_LEN (VLA_ARRAY_LEN_DIGEST (da.digest_size)) + 1];
1355 1360
1356 VLA_CHECK_LEN_DIGEST(da.digest_size); 1361 VLA_CHECK_LEN_DIGEST (da.digest_size);
1357 /* Generating the server nonce */ 1362 /* Generating the server nonce */
1358 calculate_nonce ((uint32_t) MHD_monotonic_sec_counter(), 1363 calculate_nonce ((uint32_t) MHD_monotonic_sec_counter (),
1359 connection->method, 1364 connection->method,
1360 connection->daemon->digest_auth_random, 1365 connection->daemon->digest_auth_random,
1361 connection->daemon->digest_auth_rand_size, 1366 connection->daemon->digest_auth_rand_size,
@@ -1367,13 +1372,14 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
1367 check_nonce_nc (connection, 1372 check_nonce_nc (connection,
1368 nonce, 1373 nonce,
1369 0)) 1374 0))
1370 { 1375 {
1371#ifdef HAVE_MESSAGES 1376#ifdef HAVE_MESSAGES
1372 MHD_DLOG (connection->daemon, 1377 MHD_DLOG (connection->daemon,
1373 _("Could not register nonce (is the nonce array size zero?).\n")); 1378 _ (
1379 "Could not register nonce (is the nonce array size zero?).\n"));
1374#endif 1380#endif
1375 return MHD_NO; 1381 return MHD_NO;
1376 } 1382 }
1377 /* Building the authentication header */ 1383 /* Building the authentication header */
1378 hlen = MHD_snprintf_ (NULL, 1384 hlen = MHD_snprintf_ (NULL,
1379 0, 1385 0,
@@ -1386,54 +1392,54 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
1386 ? ",stale=\"true\"" 1392 ? ",stale=\"true\""
1387 : ""); 1393 : "");
1388 if (hlen > 0) 1394 if (hlen > 0)
1389 { 1395 {
1390 char *header; 1396 char *header;
1391 1397
1392 header = MHD_calloc_ (1, 1398 header = MHD_calloc_ (1,
1393 hlen + 1); 1399 hlen + 1);
1394 if (NULL == header) 1400 if (NULL == header)
1395 { 1401 {
1396#ifdef HAVE_MESSAGES 1402#ifdef HAVE_MESSAGES
1397 MHD_DLOG(connection->daemon, 1403 MHD_DLOG (connection->daemon,
1398 _("Failed to allocate memory for auth response header\n")); 1404 _ ("Failed to allocate memory for auth response header\n"));
1399#endif /* HAVE_MESSAGES */ 1405#endif /* HAVE_MESSAGES */
1400 return MHD_NO; 1406 return MHD_NO;
1401 }
1402
1403 if (MHD_snprintf_ (header,
1404 hlen + 1,
1405 "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\",algorithm=%s%s",
1406 realm,
1407 nonce,
1408 opaque,
1409 da.alg,
1410 signal_stale
1411 ? ",stale=\"true\""
1412 : "") == hlen)
1413 ret = MHD_add_response_header(response,
1414 MHD_HTTP_HEADER_WWW_AUTHENTICATE,
1415 header);
1416 else
1417 ret = MHD_NO;
1418 free (header);
1419 } 1407 }
1408
1409 if (MHD_snprintf_ (header,
1410 hlen + 1,
1411 "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\",algorithm=%s%s",
1412 realm,
1413 nonce,
1414 opaque,
1415 da.alg,
1416 signal_stale
1417 ? ",stale=\"true\""
1418 : "") == hlen)
1419 ret = MHD_add_response_header (response,
1420 MHD_HTTP_HEADER_WWW_AUTHENTICATE,
1421 header);
1422 else
1423 ret = MHD_NO;
1424 free (header);
1425 }
1420 else 1426 else
1421 ret = MHD_NO; 1427 ret = MHD_NO;
1422 } 1428 }
1423 1429
1424 if (MHD_YES == ret) 1430 if (MHD_YES == ret)
1425 { 1431 {
1426 ret = MHD_queue_response (connection, 1432 ret = MHD_queue_response (connection,
1427 MHD_HTTP_UNAUTHORIZED, 1433 MHD_HTTP_UNAUTHORIZED,
1428 response); 1434 response);
1429 } 1435 }
1430 else 1436 else
1431 { 1437 {
1432#ifdef HAVE_MESSAGES 1438#ifdef HAVE_MESSAGES
1433 MHD_DLOG (connection->daemon, 1439 MHD_DLOG (connection->daemon,
1434 _("Failed to add Digest auth header\n")); 1440 _ ("Failed to add Digest auth header\n"));
1435#endif /* HAVE_MESSAGES */ 1441#endif /* HAVE_MESSAGES */
1436 } 1442 }
1437 return ret; 1443 return ret;
1438} 1444}
1439 1445
@@ -1450,16 +1456,16 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
1450 * body; note that this function will set the "WWW Authenticate" 1456 * body; note that this function will set the "WWW Authenticate"
1451 * header and that the caller should not do this 1457 * header and that the caller should not do this
1452 * @param signal_stale #MHD_YES if the nonce is invalid to add 1458 * @param signal_stale #MHD_YES if the nonce is invalid to add
1453 * 'stale=true' to the authentication header 1459 * 'stale=true' to the authentication header
1454 * @return #MHD_YES on success, #MHD_NO otherwise 1460 * @return #MHD_YES on success, #MHD_NO otherwise
1455 * @ingroup authentication 1461 * @ingroup authentication
1456 */ 1462 */
1457int 1463int
1458MHD_queue_auth_fail_response (struct MHD_Connection *connection, 1464MHD_queue_auth_fail_response (struct MHD_Connection *connection,
1459 const char *realm, 1465 const char *realm,
1460 const char *opaque, 1466 const char *opaque,
1461 struct MHD_Response *response, 1467 struct MHD_Response *response,
1462 int signal_stale) 1468 int signal_stale)
1463{ 1469{
1464 return MHD_queue_auth_fail_response2 (connection, 1470 return MHD_queue_auth_fail_response2 (connection,
1465 realm, 1471 realm,
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index ff861545..109ebfe2 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -36,50 +36,50 @@ const char *
36MHD_state_to_string (enum MHD_CONNECTION_STATE state) 36MHD_state_to_string (enum MHD_CONNECTION_STATE state)
37{ 37{
38 switch (state) 38 switch (state)
39 { 39 {
40 case MHD_CONNECTION_INIT: 40 case MHD_CONNECTION_INIT:
41 return "connection init"; 41 return "connection init";
42 case MHD_CONNECTION_URL_RECEIVED: 42 case MHD_CONNECTION_URL_RECEIVED:
43 return "connection url received"; 43 return "connection url received";
44 case MHD_CONNECTION_HEADER_PART_RECEIVED: 44 case MHD_CONNECTION_HEADER_PART_RECEIVED:
45 return "header partially received"; 45 return "header partially received";
46 case MHD_CONNECTION_HEADERS_RECEIVED: 46 case MHD_CONNECTION_HEADERS_RECEIVED:
47 return "headers received"; 47 return "headers received";
48 case MHD_CONNECTION_HEADERS_PROCESSED: 48 case MHD_CONNECTION_HEADERS_PROCESSED:
49 return "headers processed"; 49 return "headers processed";
50 case MHD_CONNECTION_CONTINUE_SENDING: 50 case MHD_CONNECTION_CONTINUE_SENDING:
51 return "continue sending"; 51 return "continue sending";
52 case MHD_CONNECTION_CONTINUE_SENT: 52 case MHD_CONNECTION_CONTINUE_SENT:
53 return "continue sent"; 53 return "continue sent";
54 case MHD_CONNECTION_BODY_RECEIVED: 54 case MHD_CONNECTION_BODY_RECEIVED:
55 return "body received"; 55 return "body received";
56 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 56 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
57 return "footer partially received"; 57 return "footer partially received";
58 case MHD_CONNECTION_FOOTERS_RECEIVED: 58 case MHD_CONNECTION_FOOTERS_RECEIVED:
59 return "footers received"; 59 return "footers received";
60 case MHD_CONNECTION_HEADERS_SENDING: 60 case MHD_CONNECTION_HEADERS_SENDING:
61 return "headers sending"; 61 return "headers sending";
62 case MHD_CONNECTION_HEADERS_SENT: 62 case MHD_CONNECTION_HEADERS_SENT:
63 return "headers sent"; 63 return "headers sent";
64 case MHD_CONNECTION_NORMAL_BODY_READY: 64 case MHD_CONNECTION_NORMAL_BODY_READY:
65 return "normal body ready"; 65 return "normal body ready";
66 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 66 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
67 return "normal body unready"; 67 return "normal body unready";
68 case MHD_CONNECTION_CHUNKED_BODY_READY: 68 case MHD_CONNECTION_CHUNKED_BODY_READY:
69 return "chunked body ready"; 69 return "chunked body ready";
70 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 70 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
71 return "chunked body unready"; 71 return "chunked body unready";
72 case MHD_CONNECTION_BODY_SENT: 72 case MHD_CONNECTION_BODY_SENT:
73 return "body sent"; 73 return "body sent";
74 case MHD_CONNECTION_FOOTERS_SENDING: 74 case MHD_CONNECTION_FOOTERS_SENDING:
75 return "footers sending"; 75 return "footers sending";
76 case MHD_CONNECTION_FOOTERS_SENT: 76 case MHD_CONNECTION_FOOTERS_SENT:
77 return "footers sent"; 77 return "footers sent";
78 case MHD_CONNECTION_CLOSED: 78 case MHD_CONNECTION_CLOSED:
79 return "closed"; 79 return "closed";
80 default: 80 default:
81 return "unrecognized connection state"; 81 return "unrecognized connection state";
82 } 82 }
83} 83}
84#endif 84#endif
85#endif 85#endif
@@ -118,7 +118,7 @@ MHD_unescape_plus (char *arg)
118{ 118{
119 char *p; 119 char *p;
120 120
121 for (p=strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+')) 121 for (p = strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+'))
122 *p = ' '; 122 *p = ' ';
123} 123}
124 124
@@ -139,28 +139,28 @@ MHD_http_unescape (char *val)
139 char *wpos = val; 139 char *wpos = val;
140 140
141 while ('\0' != *rpos) 141 while ('\0' != *rpos)
142 {
143 uint32_t num;
144 switch (*rpos)
142 { 145 {
143 uint32_t num; 146 case '%':
144 switch (*rpos) 147 if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
145 { 148 2,
146 case '%': 149 &num))
147 if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 150 {
148 2, 151 *wpos = (char) ((unsigned char) num);
149 &num)) 152 wpos++;
150 { 153 rpos += 3;
151 *wpos = (char)((unsigned char) num); 154 break;
152 wpos++; 155 }
153 rpos += 3; 156 /* TODO: add bad sequence handling */
154 break; 157 /* intentional fall through! */
155 } 158 default:
156 /* TODO: add bad sequence handling */ 159 *wpos = *rpos;
157 /* intentional fall through! */ 160 wpos++;
158 default: 161 rpos++;
159 *wpos = *rpos;
160 wpos++;
161 rpos++;
162 }
163 } 162 }
163 }
164 *wpos = '\0'; /* add 0-terminator */ 164 *wpos = '\0'; /* add 0-terminator */
165 return wpos - val; 165 return wpos - val;
166} 166}
@@ -182,10 +182,10 @@ MHD_http_unescape (char *val)
182 */ 182 */
183int 183int
184MHD_parse_arguments_ (struct MHD_Connection *connection, 184MHD_parse_arguments_ (struct MHD_Connection *connection,
185 enum MHD_ValueKind kind, 185 enum MHD_ValueKind kind,
186 char *args, 186 char *args,
187 MHD_ArgumentIterator_ cb, 187 MHD_ArgumentIterator_ cb,
188 unsigned int *num_headers) 188 unsigned int *num_headers)
189{ 189{
190 struct MHD_Daemon *daemon = connection->daemon; 190 struct MHD_Daemon *daemon = connection->daemon;
191 char *equals; 191 char *equals;
@@ -193,78 +193,33 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
193 193
194 *num_headers = 0; 194 *num_headers = 0;
195 while ( (NULL != args) && 195 while ( (NULL != args) &&
196 ('\0' != args[0]) ) 196 ('\0' != args[0]) )
197 {
198 size_t key_len;
199 size_t value_len;
200 equals = strchr (args, '=');
201 amper = strchr (args, '&');
202 if (NULL == amper)
197 { 203 {
198 size_t key_len; 204 /* last argument */
199 size_t value_len; 205 if (NULL == equals)
200 equals = strchr (args, '='); 206 {
201 amper = strchr (args, '&'); 207 /* last argument, without '=' */
202 if (NULL == amper) 208 MHD_unescape_plus (args);
203 { 209 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
204 /* last argument */ 210 connection,
205 if (NULL == equals) 211 args);
206 { 212 if (MHD_YES != cb (connection,
207 /* last argument, without '=' */ 213 args,
208 MHD_unescape_plus (args); 214 key_len,
209 key_len = daemon->unescape_callback (daemon->unescape_callback_cls, 215 NULL,
210 connection, 216 0,
211 args); 217 kind))
212 if (MHD_YES != cb (connection, 218 return MHD_NO;
213 args, 219 (*num_headers)++;
214 key_len, 220 break;
215 NULL, 221 }
216 0, 222 /* got 'foo=bar' */
217 kind))
218 return MHD_NO;
219 (*num_headers)++;
220 break;
221 }
222 /* got 'foo=bar' */
223 equals[0] = '\0';
224 equals++;
225 MHD_unescape_plus (args);
226 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
227 connection,
228 args);
229 MHD_unescape_plus (equals);
230 value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
231 connection,
232 equals);
233 if (MHD_YES != cb (connection,
234 args,
235 key_len,
236 equals,
237 value_len,
238 kind))
239 return MHD_NO;
240 (*num_headers)++;
241 break;
242 }
243 /* amper is non-NULL here */
244 amper[0] = '\0';
245 amper++;
246 if ( (NULL == equals) ||
247 (equals >= amper) )
248 {
249 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
250 MHD_unescape_plus (args);
251 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
252 connection,
253 args);
254 if (MHD_YES != cb (connection,
255 args,
256 key_len,
257 NULL,
258 0,
259 kind))
260 return MHD_NO;
261 /* continue with 'bar' */
262 (*num_headers)++;
263 args = amper;
264 continue;
265 }
266 /* equals and amper are non-NULL here, and equals < amper,
267 so we got regular 'foo=value&bar...'-kind of argument */
268 equals[0] = '\0'; 223 equals[0] = '\0';
269 equals++; 224 equals++;
270 MHD_unescape_plus (args); 225 MHD_unescape_plus (args);
@@ -276,15 +231,60 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
276 connection, 231 connection,
277 equals); 232 equals);
278 if (MHD_YES != cb (connection, 233 if (MHD_YES != cb (connection,
279 args, 234 args,
280 key_len, 235 key_len,
281 equals, 236 equals,
282 value_len, 237 value_len,
283 kind)) 238 kind))
284 return MHD_NO; 239 return MHD_NO;
285 (*num_headers)++; 240 (*num_headers)++;
241 break;
242 }
243 /* amper is non-NULL here */
244 amper[0] = '\0';
245 amper++;
246 if ( (NULL == equals) ||
247 (equals >= amper) )
248 {
249 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
250 MHD_unescape_plus (args);
251 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
252 connection,
253 args);
254 if (MHD_YES != cb (connection,
255 args,
256 key_len,
257 NULL,
258 0,
259 kind))
260 return MHD_NO;
261 /* continue with 'bar' */
262 (*num_headers)++;
286 args = amper; 263 args = amper;
264 continue;
287 } 265 }
266 /* equals and amper are non-NULL here, and equals < amper,
267 so we got regular 'foo=value&bar...'-kind of argument */
268 equals[0] = '\0';
269 equals++;
270 MHD_unescape_plus (args);
271 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
272 connection,
273 args);
274 MHD_unescape_plus (equals);
275 value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
276 connection,
277 equals);
278 if (MHD_YES != cb (connection,
279 args,
280 key_len,
281 equals,
282 value_len,
283 kind))
284 return MHD_NO;
285 (*num_headers)++;
286 args = amper;
287 }
288 return MHD_YES; 288 return MHD_YES;
289} 289}
290 290
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index ac43d819..5cf35790 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -55,14 +55,16 @@
55 * 55 *
56 * @param msg error message (const char *) 56 * @param msg error message (const char *)
57 */ 57 */
58#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0) 58#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
59 BUILTIN_NOT_REACHED; } while (0)
59#else 60#else
60/** 61/**
61 * Trigger 'panic' action based on fatal errors. 62 * Trigger 'panic' action based on fatal errors.
62 * 63 *
63 * @param msg error message (const char *) 64 * @param msg error message (const char *)
64 */ 65 */
65#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0) 66#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
67 BUILTIN_NOT_REACHED; } while (0)
66#endif 68#endif
67 69
68#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 70#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -78,9 +80,9 @@
78 * @param fd the FD to close 80 * @param fd the FD to close
79 */ 81 */
80#define MHD_fd_close_chk_(fd) do { \ 82#define MHD_fd_close_chk_(fd) do { \
81 if ( (0 != close ((fd)) && (EBADF == errno)) ) \ 83 if ( (0 != close ((fd)) && (EBADF == errno)) ) \
82 MHD_PANIC(_("Failed to close FD.\n")); \ 84 MHD_PANIC (_ ("Failed to close FD.\n")); \
83 } while(0) 85} while (0)
84 86
85/** 87/**
86 * Should we perform additional sanity checks at runtime (on our internal 88 * Should we perform additional sanity checks at runtime (on our internal
@@ -113,10 +115,11 @@ extern MHD_PanicCallback mhd_panic;
113extern void *mhd_panic_cls; 115extern void *mhd_panic_cls;
114 116
115/* If we have Clang or gcc >= 4.5, use __buildin_unreachable() */ 117/* If we have Clang or gcc >= 4.5, use __buildin_unreachable() */
116#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 118#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= \
117#define BUILTIN_NOT_REACHED __builtin_unreachable() 119 5)
120#define BUILTIN_NOT_REACHED __builtin_unreachable ()
118#elif defined(_MSC_FULL_VER) 121#elif defined(_MSC_FULL_VER)
119#define BUILTIN_NOT_REACHED __assume(0) 122#define BUILTIN_NOT_REACHED __assume (0)
120#else 123#else
121#define BUILTIN_NOT_REACHED 124#define BUILTIN_NOT_REACHED
122#endif 125#endif
@@ -125,7 +128,7 @@ extern void *mhd_panic_cls;
125/** 128/**
126 * Determine length of static string / macro strings at compile time. 129 * Determine length of static string / macro strings at compile time.
127 */ 130 */
128#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 131#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
129#endif /* ! MHD_STATICSTR_LEN_ */ 132#endif /* ! MHD_STATICSTR_LEN_ */
130 133
131 134
@@ -250,7 +253,7 @@ struct MHD_NonceNc
250 */ 253 */
251void 254void
252MHD_DLOG (const struct MHD_Daemon *daemon, 255MHD_DLOG (const struct MHD_Daemon *daemon,
253 const char *format, 256 const char *format,
254 ...); 257 ...);
255#endif 258#endif
256 259
@@ -1758,15 +1761,15 @@ struct MHD_Daemon
1758 * @param element element to insert 1761 * @param element element to insert
1759 */ 1762 */
1760#define DLL_insert(head,tail,element) do { \ 1763#define DLL_insert(head,tail,element) do { \
1761 mhd_assert (NULL == (element)->next); \ 1764 mhd_assert (NULL == (element)->next); \
1762 mhd_assert (NULL == (element)->prev); \ 1765 mhd_assert (NULL == (element)->prev); \
1763 (element)->next = (head); \ 1766 (element)->next = (head); \
1764 (element)->prev = NULL; \ 1767 (element)->prev = NULL; \
1765 if ((tail) == NULL) \ 1768 if ((tail) == NULL) \
1766 (tail) = element; \ 1769 (tail) = element; \
1767 else \ 1770 else \
1768 (head)->prev = element; \ 1771 (head)->prev = element; \
1769 (head) = (element); } while (0) 1772 (head) = (element); } while (0)
1770 1773
1771 1774
1772/** 1775/**
@@ -1779,18 +1782,18 @@ struct MHD_Daemon
1779 * @param element element to remove 1782 * @param element element to remove
1780 */ 1783 */
1781#define DLL_remove(head,tail,element) do { \ 1784#define DLL_remove(head,tail,element) do { \
1782 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \ 1785 mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
1783 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \ 1786 mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
1784 if ((element)->prev == NULL) \ 1787 if ((element)->prev == NULL) \
1785 (head) = (element)->next; \ 1788 (head) = (element)->next; \
1786 else \ 1789 else \
1787 (element)->prev->next = (element)->next; \ 1790 (element)->prev->next = (element)->next; \
1788 if ((element)->next == NULL) \ 1791 if ((element)->next == NULL) \
1789 (tail) = (element)->prev; \ 1792 (tail) = (element)->prev; \
1790 else \ 1793 else \
1791 (element)->next->prev = (element)->prev; \ 1794 (element)->next->prev = (element)->prev; \
1792 (element)->next = NULL; \ 1795 (element)->next = NULL; \
1793 (element)->prev = NULL; } while (0) 1796 (element)->prev = NULL; } while (0)
1794 1797
1795 1798
1796 1799
@@ -1803,15 +1806,15 @@ struct MHD_Daemon
1803 * @param element element to insert 1806 * @param element element to insert
1804 */ 1807 */
1805#define XDLL_insert(head,tail,element) do { \ 1808#define XDLL_insert(head,tail,element) do { \
1806 mhd_assert (NULL == (element)->nextX); \ 1809 mhd_assert (NULL == (element)->nextX); \
1807 mhd_assert (NULL == (element)->prevX); \ 1810 mhd_assert (NULL == (element)->prevX); \
1808 (element)->nextX = (head); \ 1811 (element)->nextX = (head); \
1809 (element)->prevX = NULL; \ 1812 (element)->prevX = NULL; \
1810 if (NULL == (tail)) \ 1813 if (NULL == (tail)) \
1811 (tail) = element; \ 1814 (tail) = element; \
1812 else \ 1815 else \
1813 (head)->prevX = element; \ 1816 (head)->prevX = element; \
1814 (head) = (element); } while (0) 1817 (head) = (element); } while (0)
1815 1818
1816 1819
1817/** 1820/**
@@ -1824,18 +1827,18 @@ struct MHD_Daemon
1824 * @param element element to remove 1827 * @param element element to remove
1825 */ 1828 */
1826#define XDLL_remove(head,tail,element) do { \ 1829#define XDLL_remove(head,tail,element) do { \
1827 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \ 1830 mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
1828 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \ 1831 mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
1829 if (NULL == (element)->prevX) \ 1832 if (NULL == (element)->prevX) \
1830 (head) = (element)->nextX; \ 1833 (head) = (element)->nextX; \
1831 else \ 1834 else \
1832 (element)->prevX->nextX = (element)->nextX; \ 1835 (element)->prevX->nextX = (element)->nextX; \
1833 if (NULL == (element)->nextX) \ 1836 if (NULL == (element)->nextX) \
1834 (tail) = (element)->prevX; \ 1837 (tail) = (element)->prevX; \
1835 else \ 1838 else \
1836 (element)->nextX->prevX = (element)->prevX; \ 1839 (element)->nextX->prevX = (element)->prevX; \
1837 (element)->nextX = NULL; \ 1840 (element)->nextX = NULL; \
1838 (element)->prevX = NULL; } while (0) 1841 (element)->prevX = NULL; } while (0)
1839 1842
1840 1843
1841/** 1844/**
@@ -1847,13 +1850,13 @@ struct MHD_Daemon
1847 * @param element element to insert 1850 * @param element element to insert
1848 */ 1851 */
1849#define EDLL_insert(head,tail,element) do { \ 1852#define EDLL_insert(head,tail,element) do { \
1850 (element)->nextE = (head); \ 1853 (element)->nextE = (head); \
1851 (element)->prevE = NULL; \ 1854 (element)->prevE = NULL; \
1852 if ((tail) == NULL) \ 1855 if ((tail) == NULL) \
1853 (tail) = element; \ 1856 (tail) = element; \
1854 else \ 1857 else \
1855 (head)->prevE = element; \ 1858 (head)->prevE = element; \
1856 (head) = (element); } while (0) 1859 (head) = (element); } while (0)
1857 1860
1858 1861
1859/** 1862/**
@@ -1866,16 +1869,16 @@ struct MHD_Daemon
1866 * @param element element to remove 1869 * @param element element to remove
1867 */ 1870 */
1868#define EDLL_remove(head,tail,element) do { \ 1871#define EDLL_remove(head,tail,element) do { \
1869 if ((element)->prevE == NULL) \ 1872 if ((element)->prevE == NULL) \
1870 (head) = (element)->nextE; \ 1873 (head) = (element)->nextE; \
1871 else \ 1874 else \
1872 (element)->prevE->nextE = (element)->nextE; \ 1875 (element)->prevE->nextE = (element)->nextE; \
1873 if ((element)->nextE == NULL) \ 1876 if ((element)->nextE == NULL) \
1874 (tail) = (element)->prevE; \ 1877 (tail) = (element)->prevE; \
1875 else \ 1878 else \
1876 (element)->nextE->prevE = (element)->prevE; \ 1879 (element)->nextE->prevE = (element)->prevE; \
1877 (element)->nextE = NULL; \ 1880 (element)->nextE = NULL; \
1878 (element)->prevE = NULL; } while (0) 1881 (element)->prevE = NULL; } while (0)
1879 1882
1880 1883
1881/** 1884/**
@@ -1902,11 +1905,11 @@ MHD_unescape_plus (char *arg);
1902 */ 1905 */
1903typedef int 1906typedef int
1904(*MHD_ArgumentIterator_)(struct MHD_Connection *connection, 1907(*MHD_ArgumentIterator_)(struct MHD_Connection *connection,
1905 const char *key, 1908 const char *key,
1906 size_t key_size, 1909 size_t key_size,
1907 const char *value, 1910 const char *value,
1908 size_t value_size, 1911 size_t value_size,
1909 enum MHD_ValueKind kind); 1912 enum MHD_ValueKind kind);
1910 1913
1911 1914
1912/** 1915/**
@@ -1925,10 +1928,10 @@ typedef int
1925 */ 1928 */
1926int 1929int
1927MHD_parse_arguments_ (struct MHD_Connection *connection, 1930MHD_parse_arguments_ (struct MHD_Connection *connection,
1928 enum MHD_ValueKind kind, 1931 enum MHD_ValueKind kind,
1929 char *args, 1932 char *args,
1930 MHD_ArgumentIterator_ cb, 1933 MHD_ArgumentIterator_ cb,
1931 unsigned int *num_headers); 1934 unsigned int *num_headers);
1932 1935
1933 1936
1934/** 1937/**
@@ -1966,8 +1969,8 @@ MHD_check_response_header_token_ci (const struct MHD_Response *response,
1966 * false otherwise 1969 * false otherwise
1967 */ 1970 */
1968#define MHD_check_response_header_s_token_ci(r,k,tkn) \ 1971#define MHD_check_response_header_s_token_ci(r,k,tkn) \
1969 MHD_check_response_header_token_ci((r),(k),MHD_STATICSTR_LEN_(k),\ 1972 MHD_check_response_header_token_ci ((r),(k),MHD_STATICSTR_LEN_ (k), \
1970 (tkn),MHD_STATICSTR_LEN_(tkn)) 1973 (tkn),MHD_STATICSTR_LEN_ (tkn))
1971 1974
1972 1975
1973/** 1976/**
diff --git a/src/microhttpd/md5.c b/src/microhttpd/md5.c
index 25f25372..39b66185 100644
--- a/src/microhttpd/md5.c
+++ b/src/microhttpd/md5.c
@@ -58,7 +58,7 @@ MD5Transform (uint32_t state[4],
58 */ 58 */
59void 59void
60MHD_MD5Final (void *ctx_, 60MHD_MD5Final (void *ctx_,
61 uint8_t digest[MD5_DIGEST_SIZE]) 61 uint8_t digest[MD5_DIGEST_SIZE])
62{ 62{
63 struct MD5Context *ctx = ctx_; 63 struct MD5Context *ctx = ctx_;
64 uint64_t count_bits; 64 uint64_t count_bits;
@@ -75,27 +75,28 @@ MHD_MD5Final (void *ctx_,
75 ctx->buffer[have_bytes++] = 0x80; /* First padding byte is 0x80 */ 75 ctx->buffer[have_bytes++] = 0x80; /* First padding byte is 0x80 */
76 76
77 if (MD5_BLOCK_SIZE - have_bytes < 8) 77 if (MD5_BLOCK_SIZE - have_bytes < 8)
78 { /* Not enough space to put number of bits */ 78 { /* Not enough space to put number of bits */
79 while (have_bytes < MD5_BLOCK_SIZE) ctx->buffer[have_bytes++] = 0; 79 while (have_bytes < MD5_BLOCK_SIZE)
80 MD5Transform(ctx->state, ctx->buffer); 80 ctx->buffer[have_bytes++] = 0;
81 have_bytes = 0; /* Additional block */ 81 MD5Transform (ctx->state, ctx->buffer);
82 } 82 have_bytes = 0; /* Additional block */
83 }
83 /* Pad out to 56 */ 84 /* Pad out to 56 */
84 memset(ctx->buffer + have_bytes, 0, MD5_BLOCK_SIZE - have_bytes - 8); 85 memset (ctx->buffer + have_bytes, 0, MD5_BLOCK_SIZE - have_bytes - 8);
85 86
86 /* Put number of bits */ 87 /* Put number of bits */
87 count_bits = ctx->count << 3; 88 count_bits = ctx->count << 3;
88 _MHD_PUT_64BIT_LE(ctx->buffer + 56, count_bits); 89 _MHD_PUT_64BIT_LE (ctx->buffer + 56, count_bits);
89 MD5Transform(ctx->state, ctx->buffer); 90 MD5Transform (ctx->state, ctx->buffer);
90 91
91 /* Put digest in LE mode */ 92 /* Put digest in LE mode */
92 _MHD_PUT_32BIT_LE(digest, ctx->state[0]); 93 _MHD_PUT_32BIT_LE (digest, ctx->state[0]);
93 _MHD_PUT_32BIT_LE(digest + 4, ctx->state[1]); 94 _MHD_PUT_32BIT_LE (digest + 4, ctx->state[1]);
94 _MHD_PUT_32BIT_LE(digest + 8, ctx->state[2]); 95 _MHD_PUT_32BIT_LE (digest + 8, ctx->state[2]);
95 _MHD_PUT_32BIT_LE(digest + 12, ctx->state[3]); 96 _MHD_PUT_32BIT_LE (digest + 12, ctx->state[3]);
96 97
97 /* Erase buffer */ 98 /* Erase buffer */
98 memset(ctx, 0, sizeof(*ctx)); 99 memset (ctx, 0, sizeof(*ctx));
99} 100}
100 101
101 102
@@ -109,13 +110,13 @@ MHD_MD5Final (void *ctx_,
109 110
110/* #define F1(x, y, z) (x & y | ~x & z) */ 111/* #define F1(x, y, z) (x & y | ~x & z) */
111#define F1(x, y, z) (z ^ (x & (y ^ z))) 112#define F1(x, y, z) (z ^ (x & (y ^ z)))
112#define F2(x, y, z) F1(z, x, y) 113#define F2(x, y, z) F1 (z, x, y)
113#define F3(x, y, z) (x ^ y ^ z) 114#define F3(x, y, z) (x ^ y ^ z)
114#define F4(x, y, z) (y ^ (x | ~z)) 115#define F4(x, y, z) (y ^ (x | ~z))
115 116
116/* This is the central step in the MD5 algorithm. */ 117/* This is the central step in the MD5 algorithm. */
117#define MD5STEP(f, w, x, y, z, data, s) \ 118#define MD5STEP(f, w, x, y, z, data, s) \
118 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) 119 (w += f (x, y, z) + data, w = w << s | w >> (32 - s), w += x)
119 120
120/** 121/**
121 * The core of the MD5 algorithm, this alters an existing MD5 hash to 122 * The core of the MD5 algorithm, this alters an existing MD5 hash to
@@ -129,14 +130,14 @@ MD5Transform (uint32_t state[4],
129 uint32_t a, b, c, d; 130 uint32_t a, b, c, d;
130 131
131#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 132#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
132 const uint32_t *in = (const uint32_t *)block; 133 const uint32_t *in = (const uint32_t *) block;
133#else 134#else
134 uint32_t in[MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD]; 135 uint32_t in[MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD];
135 int i; 136 int i;
136 137
137 for (i = 0; i < MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD; i++) 138 for (i = 0; i < MD5_BLOCK_SIZE / MD5_BYTES_IN_WORD; i++)
138 { 139 {
139 in[i] = _MHD_GET_32BIT_LE(block + i * MD5_BYTES_IN_WORD); 140 in[i] = _MHD_GET_32BIT_LE (block + i * MD5_BYTES_IN_WORD);
140 } 141 }
141#endif 142#endif
142 143
@@ -145,73 +146,73 @@ MD5Transform (uint32_t state[4],
145 c = state[2]; 146 c = state[2];
146 d = state[3]; 147 d = state[3];
147 148
148 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); 149 MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478, 7);
149 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); 150 MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
150 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); 151 MD5STEP (F1, c, d, a, b, in[2] + 0x242070db, 17);
151 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); 152 MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
152 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); 153 MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
153 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); 154 MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62a, 12);
154 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); 155 MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613, 17);
155 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); 156 MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501, 22);
156 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); 157 MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8, 7);
157 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); 158 MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
158 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); 159 MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
159 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); 160 MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7be, 22);
160 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); 161 MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122, 7);
161 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); 162 MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193, 12);
162 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); 163 MD5STEP (F1, c, d, a, b, in[14] + 0xa679438e, 17);
163 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); 164 MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821, 22);
164 165
165 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); 166 MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562, 5);
166 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); 167 MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340, 9);
167 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); 168 MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51, 14);
168 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); 169 MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
169 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); 170 MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105d, 5);
170 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); 171 MD5STEP (F2, d, a, b, c, in[10] + 0x02441453, 9);
171 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); 172 MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
172 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); 173 MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
173 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); 174 MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
174 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); 175 MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6, 9);
175 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); 176 MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
176 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); 177 MD5STEP (F2, b, c, d, a, in[8] + 0x455a14ed, 20);
177 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); 178 MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
178 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); 179 MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
179 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); 180 MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9, 14);
180 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); 181 MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
181 182
182 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); 183 MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942, 4);
183 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); 184 MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681, 11);
184 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); 185 MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
185 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); 186 MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380c, 23);
186 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); 187 MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44, 4);
187 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); 188 MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
188 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); 189 MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
189 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); 190 MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
190 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); 191 MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
191 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); 192 MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
192 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); 193 MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
193 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); 194 MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05, 23);
194 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); 195 MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
195 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); 196 MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
196 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); 197 MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
197 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); 198 MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
198 199
199 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); 200 MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244, 6);
200 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); 201 MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97, 10);
201 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); 202 MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7, 15);
202 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); 203 MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039, 21);
203 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); 204 MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3, 6);
204 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); 205 MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
205 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); 206 MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47d, 15);
206 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); 207 MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1, 21);
207 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); 208 MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
208 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); 209 MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
209 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); 210 MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314, 15);
210 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); 211 MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
211 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); 212 MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82, 6);
212 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); 213 MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235, 10);
213 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); 214 MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
214 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); 215 MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391, 21);
215 216
216 state[0] += a; 217 state[0] += a;
217 state[1] += b; 218 state[1] += b;
@@ -226,8 +227,8 @@ MD5Transform (uint32_t state[4],
226 */ 227 */
227void 228void
228MHD_MD5Update (void *ctx_, 229MHD_MD5Update (void *ctx_,
229 const uint8_t *input, 230 const uint8_t *input,
230 size_t len) 231 size_t len)
231{ 232{
232 struct MD5Context *ctx = ctx_; 233 struct MD5Context *ctx = ctx_;
233 size_t have, need; 234 size_t have, need;
@@ -236,11 +237,11 @@ MHD_MD5Update (void *ctx_,
236 mhd_assert ((ctx != NULL) || (len == 0)); 237 mhd_assert ((ctx != NULL) || (len == 0));
237 238
238 /* Check how many bytes we already have and how many more we need. */ 239 /* Check how many bytes we already have and how many more we need. */
239 have = (size_t)((ctx->count) & (MD5_BLOCK_SIZE - 1)); 240 have = (size_t) ((ctx->count) & (MD5_BLOCK_SIZE - 1));
240 need = MD5_BLOCK_SIZE - have; 241 need = MD5_BLOCK_SIZE - have;
241 242
242 /* Update bytecount */ 243 /* Update bytecount */
243 ctx->count += (uint64_t)len; 244 ctx->count += (uint64_t) len;
244 245
245 if (len >= need) 246 if (len >= need)
246 { 247 {
@@ -249,7 +250,7 @@ MHD_MD5Update (void *ctx_,
249 memcpy (ctx->buffer + have, 250 memcpy (ctx->buffer + have,
250 input, 251 input,
251 need); 252 need);
252 MD5Transform(ctx->state, ctx->buffer); 253 MD5Transform (ctx->state, ctx->buffer);
253 input += need; 254 input += need;
254 len -= need; 255 len -= need;
255 have = 0; 256 have = 0;
diff --git a/src/microhttpd/md5.h b/src/microhttpd/md5.h
index 3c1d1c1c..f81d91cb 100644
--- a/src/microhttpd/md5.h
+++ b/src/microhttpd/md5.h
@@ -22,15 +22,15 @@
22#include <stdint.h> 22#include <stdint.h>
23#include <stddef.h> 23#include <stddef.h>
24 24
25#define MD5_BLOCK_SIZE 64 25#define MD5_BLOCK_SIZE 64
26#define MD5_DIGEST_SIZE 16 26#define MD5_DIGEST_SIZE 16
27#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1) 27#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1)
28 28
29struct MD5Context 29struct MD5Context
30{ 30{
31 uint32_t state[4]; /* state */ 31 uint32_t state[4]; /* state */
32 uint64_t count; /* number of bytes, mod 2^64 */ 32 uint64_t count; /* number of bytes, mod 2^64 */
33 uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */ 33 uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */
34}; 34};
35 35
36 36
@@ -52,8 +52,8 @@ MHD_MD5Init (void *ctx_);
52 */ 52 */
53void 53void
54MHD_MD5Update (void *ctx_, 54MHD_MD5Update (void *ctx_,
55 const uint8_t *input, 55 const uint8_t *input,
56 size_t len); 56 size_t len);
57 57
58 58
59/** 59/**
@@ -63,7 +63,7 @@ MHD_MD5Update (void *ctx_,
63 */ 63 */
64void 64void
65MHD_MD5Final (void *ctx_, 65MHD_MD5Final (void *ctx_,
66 uint8_t digest[MD5_DIGEST_SIZE]); 66 uint8_t digest[MD5_DIGEST_SIZE]);
67 67
68 68
69#endif /* !MHD_MD5_H */ 69#endif /* !MHD_MD5_H */
diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h
index abd53365..6f5d539d 100644
--- a/src/microhttpd/memorypool.h
+++ b/src/microhttpd/memorypool.h
@@ -105,9 +105,9 @@ MHD_pool_allocate (struct MemoryPool *pool,
105 */ 105 */
106void * 106void *
107MHD_pool_reallocate (struct MemoryPool *pool, 107MHD_pool_reallocate (struct MemoryPool *pool,
108 void *old, 108 void *old,
109 size_t old_size, 109 size_t old_size,
110 size_t new_size); 110 size_t new_size);
111 111
112 112
113/** 113/**
@@ -135,8 +135,8 @@ MHD_pool_get_free (struct MemoryPool *pool);
135 */ 135 */
136void * 136void *
137MHD_pool_reset (struct MemoryPool *pool, 137MHD_pool_reset (struct MemoryPool *pool,
138 void *keep, 138 void *keep,
139 size_t copy_bytes, 139 size_t copy_bytes,
140 size_t new_size); 140 size_t new_size);
141 141
142#endif 142#endif
diff --git a/src/microhttpd/mhd_assert.h b/src/microhttpd/mhd_assert.h
index c720ce5c..e99632d0 100644
--- a/src/microhttpd/mhd_assert.h
+++ b/src/microhttpd/mhd_assert.h
@@ -28,21 +28,21 @@
28 28
29#include "mhd_options.h" 29#include "mhd_options.h"
30#ifdef NDEBUG 30#ifdef NDEBUG
31# define mhd_assert(ignore) ((void)0) 31# define mhd_assert(ignore) ((void) 0)
32#else /* _DEBUG */ 32#else /* _DEBUG */
33# ifdef HAVE_ASSERT 33# ifdef HAVE_ASSERT
34# include <assert.h> 34# include <assert.h>
35# define mhd_assert(CHK) assert(CHK) 35# define mhd_assert(CHK) assert (CHK)
36# else /* ! HAVE_ASSERT */ 36# else /* ! HAVE_ASSERT */
37# include <stdio.h> 37# include <stdio.h>
38# include <stdlib.h> 38# include <stdlib.h>
39# define mhd_assert(CHK) \ 39# define mhd_assert(CHK) \
40 do { \ 40 do { \
41 if (!(CHK)) { \ 41 if (! (CHK)) { \
42 fprintf(stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \ 42 fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \
43 __FILE__, (unsigned)__LINE__, #CHK); \ 43 __FILE__, (unsigned) __LINE__, #CHK); \
44 fflush(stderr); abort(); } \ 44 fflush (stderr); abort (); } \
45 } while(0) 45 } while (0)
46# endif /* ! HAVE_ASSERT */ 46# endif /* ! HAVE_ASSERT */
47#endif /* _DEBUG */ 47#endif /* _DEBUG */
48 48
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index ac2a13ce..34e49d15 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -28,7 +28,8 @@
28 28
29#include "mhd_byteorder.h" 29#include "mhd_byteorder.h"
30#include <stdint.h> 30#include <stdint.h>
31#if defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) 31#if defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \
32 defined(__OPTIMIZE__)))
32/* Declarations for VC & Clang/C2 built-ins */ 33/* Declarations for VC & Clang/C2 built-ins */
33#include <intrin.h> 34#include <intrin.h>
34#endif /* _MSC_FULL_VER */ 35#endif /* _MSC_FULL_VER */
@@ -41,48 +42,50 @@
41 42
42#ifdef MHD_HAVE___BUILTIN_BSWAP32 43#ifdef MHD_HAVE___BUILTIN_BSWAP32
43#define _MHD_BYTES_SWAP32(value32) \ 44#define _MHD_BYTES_SWAP32(value32) \
44 ((uint32_t)__builtin_bswap32((uint32_t)value32)) 45 ((uint32_t) __builtin_bswap32 ((uint32_t) value32))
45#elif defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) 46#elif defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \
47 defined(__OPTIMIZE__)))
46/* Clang/C2 may not inline this function if optimizations are turned off. */ 48/* Clang/C2 may not inline this function if optimizations are turned off. */
47#ifndef __clang__ 49#ifndef __clang__
48#pragma intrinsic(_byteswap_ulong) 50#pragma intrinsic(_byteswap_ulong)
49#endif /* ! __clang__ */ 51#endif /* ! __clang__ */
50#define _MHD_BYTES_SWAP32(value32) \ 52#define _MHD_BYTES_SWAP32(value32) \
51 ((uint32_t)_byteswap_ulong((uint32_t)value32)) 53 ((uint32_t) _byteswap_ulong ((uint32_t) value32))
52#elif __has_builtin(__builtin_bswap32) 54#elif __has_builtin (__builtin_bswap32)
53#define _MHD_BYTES_SWAP32(value32) \ 55#define _MHD_BYTES_SWAP32(value32) \
54 ((uint32_t)__builtin_bswap32((uint32_t)value32)) 56 ((uint32_t) __builtin_bswap32 ((uint32_t) value32))
55#else /* ! __has_builtin(__builtin_bswap32) */ 57#else /* ! __has_builtin(__builtin_bswap32) */
56#define _MHD_BYTES_SWAP32(value32) \ 58#define _MHD_BYTES_SWAP32(value32) \
57 ( (((uint32_t)(value32)) << 24) | \ 59 ( (((uint32_t) (value32)) << 24) \
58 ((((uint32_t)(value32)) & ((uint32_t)0x0000FF00)) << 8) | \ 60 | ((((uint32_t) (value32)) & ((uint32_t) 0x0000FF00)) << 8) \
59 ((((uint32_t)(value32)) & ((uint32_t)0x00FF0000)) >> 8) | \ 61 | ((((uint32_t) (value32)) & ((uint32_t) 0x00FF0000)) >> 8) \
60 (((uint32_t)(value32)) >> 24) ) 62 | (((uint32_t) (value32)) >> 24) )
61#endif /* ! __has_builtin(__builtin_bswap32) */ 63#endif /* ! __has_builtin(__builtin_bswap32) */
62 64
63#ifdef MHD_HAVE___BUILTIN_BSWAP64 65#ifdef MHD_HAVE___BUILTIN_BSWAP64
64#define _MHD_BYTES_SWAP64(value64) \ 66#define _MHD_BYTES_SWAP64(value64) \
65 ((uint64_t)__builtin_bswap64((uint64_t)value64)) 67 ((uint64_t) __builtin_bswap64 ((uint64_t) value64))
66#elif defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) 68#elif defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \
69 defined(__OPTIMIZE__)))
67/* Clang/C2 may not inline this function if optimizations are turned off. */ 70/* Clang/C2 may not inline this function if optimizations are turned off. */
68#ifndef __clang__ 71#ifndef __clang__
69#pragma intrinsic(_byteswap_uint64) 72#pragma intrinsic(_byteswap_uint64)
70#endif /* ! __clang__ */ 73#endif /* ! __clang__ */
71#define _MHD_BYTES_SWAP64(value64) \ 74#define _MHD_BYTES_SWAP64(value64) \
72 ((uint64_t)_byteswap_uint64((uint64_t)value64)) 75 ((uint64_t) _byteswap_uint64 ((uint64_t) value64))
73#elif __has_builtin(__builtin_bswap64) 76#elif __has_builtin (__builtin_bswap64)
74#define _MHD_BYTES_SWAP64(value64) \ 77#define _MHD_BYTES_SWAP64(value64) \
75 ((uint64_t)__builtin_bswap64((uint64_t)value64)) 78 ((uint64_t) __builtin_bswap64 ((uint64_t) value64))
76#else /* ! __has_builtin(__builtin_bswap64) */ 79#else /* ! __has_builtin(__builtin_bswap64) */
77#define _MHD_BYTES_SWAP64(value64) \ 80#define _MHD_BYTES_SWAP64(value64) \
78 ( (((uint64_t)(value64)) << 56) | \ 81 ( (((uint64_t) (value64)) << 56) \
79 ((((uint64_t)(value64)) & ((uint64_t)0x000000000000FF00)) << 40) | \ 82 | ((((uint64_t) (value64)) & ((uint64_t) 0x000000000000FF00)) << 40) \
80 ((((uint64_t)(value64)) & ((uint64_t)0x0000000000FF0000)) << 24) | \ 83 | ((((uint64_t) (value64)) & ((uint64_t) 0x0000000000FF0000)) << 24) \
81 ((((uint64_t)(value64)) & ((uint64_t)0x00000000FF000000)) << 8) | \ 84 | ((((uint64_t) (value64)) & ((uint64_t) 0x00000000FF000000)) << 8) \
82 ((((uint64_t)(value64)) & ((uint64_t)0x000000FF00000000)) >> 8) | \ 85 | ((((uint64_t) (value64)) & ((uint64_t) 0x000000FF00000000)) >> 8) \
83 ((((uint64_t)(value64)) & ((uint64_t)0x0000FF0000000000)) >> 24) | \ 86 | ((((uint64_t) (value64)) & ((uint64_t) 0x0000FF0000000000)) >> 24) \
84 ((((uint64_t)(value64)) & ((uint64_t)0x00FF000000000000)) >> 40) | \ 87 | ((((uint64_t) (value64)) & ((uint64_t) 0x00FF000000000000)) >> 40) \
85 (((uint64_t)(value64)) >> 56) ) 88 | (((uint64_t) (value64)) >> 56) )
86#endif /* ! __has_builtin(__builtin_bswap64) */ 89#endif /* ! __has_builtin(__builtin_bswap64) */
87 90
88 91
@@ -92,22 +95,22 @@
92 */ 95 */
93#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 96#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
94#define _MHD_PUT_64BIT_LE(addr, value64) \ 97#define _MHD_PUT_64BIT_LE(addr, value64) \
95 ((*(uint64_t*)(addr)) = (uint64_t)(value64)) 98 ((*(uint64_t*) (addr)) = (uint64_t) (value64))
96#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 99#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
97#define _MHD_PUT_64BIT_LE(addr, value64) \ 100#define _MHD_PUT_64BIT_LE(addr, value64) \
98 ((*(uint64_t*)(addr)) = _MHD_BYTES_SWAP64(value64)) 101 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64))
99#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 102#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
100/* Endianess was not detected or non-standard like PDP-endian */ 103/* Endianess was not detected or non-standard like PDP-endian */
101#define _MHD_PUT_64BIT_LE(addr, value64) do { \ 104#define _MHD_PUT_64BIT_LE(addr, value64) do { \
102 ((uint8_t*)(addr))[0] = (uint8_t)((uint64_t)(value64)); \ 105 ((uint8_t*) (addr))[0] = (uint8_t) ((uint64_t) (value64)); \
103 ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 8); \ 106 ((uint8_t*) (addr))[1] = (uint8_t) (((uint64_t) (value64)) >> 8); \
104 ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 16); \ 107 ((uint8_t*) (addr))[2] = (uint8_t) (((uint64_t) (value64)) >> 16); \
105 ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 24); \ 108 ((uint8_t*) (addr))[3] = (uint8_t) (((uint64_t) (value64)) >> 24); \
106 ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 32); \ 109 ((uint8_t*) (addr))[4] = (uint8_t) (((uint64_t) (value64)) >> 32); \
107 ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 40); \ 110 ((uint8_t*) (addr))[5] = (uint8_t) (((uint64_t) (value64)) >> 40); \
108 ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 48); \ 111 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 48); \
109 ((uint8_t*)(addr))[7] = (uint8_t)(((uint64_t)(value64)) >> 56); \ 112 ((uint8_t*) (addr))[7] = (uint8_t) (((uint64_t) (value64)) >> 56); \
110 } while (0) 113} while (0)
111#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 114#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
112 115
113/* _MHD_PUT_32BIT_LE (addr, value32) 116/* _MHD_PUT_32BIT_LE (addr, value32)
@@ -116,18 +119,18 @@
116 */ 119 */
117#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 120#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
118#define _MHD_PUT_32BIT_LE(addr,value32) \ 121#define _MHD_PUT_32BIT_LE(addr,value32) \
119 ((*(uint32_t*)(addr)) = (uint32_t)(value32)) 122 ((*(uint32_t*) (addr)) = (uint32_t) (value32))
120#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 123#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
121#define _MHD_PUT_32BIT_LE(addr, value32) \ 124#define _MHD_PUT_32BIT_LE(addr, value32) \
122 ((*(uint32_t*)(addr)) = _MHD_BYTES_SWAP32(value32)) 125 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32))
123#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 126#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
124/* Endianess was not detected or non-standard like PDP-endian */ 127/* Endianess was not detected or non-standard like PDP-endian */
125#define _MHD_PUT_32BIT_LE(addr, value32) do { \ 128#define _MHD_PUT_32BIT_LE(addr, value32) do { \
126 ((uint8_t*)(addr))[0] = (uint8_t)((uint32_t)(value32)); \ 129 ((uint8_t*) (addr))[0] = (uint8_t) ((uint32_t) (value32)); \
127 ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 8); \ 130 ((uint8_t*) (addr))[1] = (uint8_t) (((uint32_t) (value32)) >> 8); \
128 ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 16); \ 131 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 16); \
129 ((uint8_t*)(addr))[3] = (uint8_t)(((uint32_t)(value32)) >> 24); \ 132 ((uint8_t*) (addr))[3] = (uint8_t) (((uint32_t) (value32)) >> 24); \
130 } while (0) 133} while (0)
131#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 134#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
132 135
133/* _MHD_GET_32BIT_LE (addr) 136/* _MHD_GET_32BIT_LE (addr)
@@ -136,17 +139,17 @@
136 */ 139 */
137#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 140#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
138#define _MHD_GET_32BIT_LE(addr) \ 141#define _MHD_GET_32BIT_LE(addr) \
139 (*(const uint32_t*)(addr)) 142 (*(const uint32_t*) (addr))
140#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 143#elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
141#define _MHD_GET_32BIT_LE(addr) \ 144#define _MHD_GET_32BIT_LE(addr) \
142 _MHD_BYTES_SWAP32(*(const uint32_t*)(addr)) 145 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr))
143#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 146#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
144/* Endianess was not detected or non-standard like PDP-endian */ 147/* Endianess was not detected or non-standard like PDP-endian */
145#define _MHD_GET_32BIT_LE(addr) \ 148#define _MHD_GET_32BIT_LE(addr) \
146 ( ( (uint32_t)(((const uint8_t*)addr)[0])) | \ 149 ( ( (uint32_t) (((const uint8_t*) addr)[0])) \
147 (((uint32_t)(((const uint8_t*)addr)[1])) << 8) | \ 150 | (((uint32_t) (((const uint8_t*) addr)[1])) << 8) \
148 (((uint32_t)(((const uint8_t*)addr)[2])) << 16) | \ 151 | (((uint32_t) (((const uint8_t*) addr)[2])) << 16) \
149 (((uint32_t)(((const uint8_t*)addr)[3])) << 24) ) 152 | (((uint32_t) (((const uint8_t*) addr)[3])) << 24) )
150#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 153#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
151 154
152 155
@@ -156,22 +159,22 @@
156 */ 159 */
157#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 160#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
158#define _MHD_PUT_64BIT_BE(addr, value64) \ 161#define _MHD_PUT_64BIT_BE(addr, value64) \
159 ((*(uint64_t*)(addr)) = (uint64_t)(value64)) 162 ((*(uint64_t*) (addr)) = (uint64_t) (value64))
160#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 163#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
161#define _MHD_PUT_64BIT_BE(addr, value64) \ 164#define _MHD_PUT_64BIT_BE(addr, value64) \
162 ((*(uint64_t*)(addr)) = _MHD_BYTES_SWAP64(value64)) 165 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64))
163#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 166#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
164/* Endianess was not detected or non-standard like PDP-endian */ 167/* Endianess was not detected or non-standard like PDP-endian */
165#define _MHD_PUT_64BIT_BE(addr, value64) do { \ 168#define _MHD_PUT_64BIT_BE(addr, value64) do { \
166 ((uint8_t*)(addr))[7] = (uint8_t)((uint64_t)(value64)); \ 169 ((uint8_t*) (addr))[7] = (uint8_t) ((uint64_t) (value64)); \
167 ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 8); \ 170 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 8); \
168 ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 16); \ 171 ((uint8_t*) (addr))[5] = (uint8_t) (((uint64_t) (value64)) >> 16); \
169 ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 24); \ 172 ((uint8_t*) (addr))[4] = (uint8_t) (((uint64_t) (value64)) >> 24); \
170 ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 32); \ 173 ((uint8_t*) (addr))[3] = (uint8_t) (((uint64_t) (value64)) >> 32); \
171 ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 40); \ 174 ((uint8_t*) (addr))[2] = (uint8_t) (((uint64_t) (value64)) >> 40); \
172 ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 48); \ 175 ((uint8_t*) (addr))[1] = (uint8_t) (((uint64_t) (value64)) >> 48); \
173 ((uint8_t*)(addr))[0] = (uint8_t)(((uint64_t)(value64)) >> 56); \ 176 ((uint8_t*) (addr))[0] = (uint8_t) (((uint64_t) (value64)) >> 56); \
174 } while (0) 177} while (0)
175#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 178#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
176 179
177/* _MHD_PUT_32BIT_BE (addr, value32) 180/* _MHD_PUT_32BIT_BE (addr, value32)
@@ -180,18 +183,18 @@
180 */ 183 */
181#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 184#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
182#define _MHD_PUT_32BIT_BE(addr, value32) \ 185#define _MHD_PUT_32BIT_BE(addr, value32) \
183 ((*(uint32_t*)(addr)) = (uint32_t)(value32)) 186 ((*(uint32_t*) (addr)) = (uint32_t) (value32))
184#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 187#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
185#define _MHD_PUT_32BIT_BE(addr, value32) \ 188#define _MHD_PUT_32BIT_BE(addr, value32) \
186 ((*(uint32_t*)(addr)) = _MHD_BYTES_SWAP32(value32)) 189 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32))
187#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 190#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
188/* Endianess was not detected or non-standard like PDP-endian */ 191/* Endianess was not detected or non-standard like PDP-endian */
189#define _MHD_PUT_32BIT_BE(addr, value32) do { \ 192#define _MHD_PUT_32BIT_BE(addr, value32) do { \
190 ((uint8_t*)(addr))[3] = (uint8_t)((uint32_t)(value32)); \ 193 ((uint8_t*) (addr))[3] = (uint8_t) ((uint32_t) (value32)); \
191 ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 8); \ 194 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 8); \
192 ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 16); \ 195 ((uint8_t*) (addr))[1] = (uint8_t) (((uint32_t) (value32)) >> 16); \
193 ((uint8_t*)(addr))[0] = (uint8_t)(((uint32_t)(value32)) >> 24); \ 196 ((uint8_t*) (addr))[0] = (uint8_t) (((uint32_t) (value32)) >> 24); \
194 } while (0) 197} while (0)
195#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 198#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
196 199
197/* _MHD_GET_32BIT_BE (addr) 200/* _MHD_GET_32BIT_BE (addr)
@@ -200,17 +203,17 @@
200 */ 203 */
201#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 204#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
202#define _MHD_GET_32BIT_BE(addr) \ 205#define _MHD_GET_32BIT_BE(addr) \
203 (*(const uint32_t*)(addr)) 206 (*(const uint32_t*) (addr))
204#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 207#elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
205#define _MHD_GET_32BIT_BE(addr) \ 208#define _MHD_GET_32BIT_BE(addr) \
206 _MHD_BYTES_SWAP32(*(const uint32_t*)(addr)) 209 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr))
207#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 210#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
208/* Endianess was not detected or non-standard like PDP-endian */ 211/* Endianess was not detected or non-standard like PDP-endian */
209#define _MHD_GET_32BIT_BE(addr) \ 212#define _MHD_GET_32BIT_BE(addr) \
210 ( (((uint32_t)(((const uint8_t*)addr)[0])) << 24) | \ 213 ( (((uint32_t) (((const uint8_t*) addr)[0])) << 24) \
211 (((uint32_t)(((const uint8_t*)addr)[1])) << 16) | \ 214 | (((uint32_t) (((const uint8_t*) addr)[1])) << 16) \
212 (((uint32_t)(((const uint8_t*)addr)[2])) << 8) | \ 215 | (((uint32_t) (((const uint8_t*) addr)[2])) << 8) \
213 ((uint32_t) (((const uint8_t*)addr)[3])) ) 216 | ((uint32_t) (((const uint8_t*) addr)[3])) )
214#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 217#endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
215 218
216 219
@@ -218,17 +221,18 @@
218 * Rotate right 32-bit value by number of bits. 221 * Rotate right 32-bit value by number of bits.
219 * bits parameter must be more than zero and must be less than 32. 222 * bits parameter must be more than zero and must be less than 32.
220 */ 223 */
221#if defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) 224#if defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \
225 defined(__OPTIMIZE__)))
222/* Clang/C2 do not inline this function if optimizations are turned off. */ 226/* Clang/C2 do not inline this function if optimizations are turned off. */
223#ifndef __clang__ 227#ifndef __clang__
224#pragma intrinsic(_rotr) 228#pragma intrinsic(_rotr)
225#endif /* ! __clang__ */ 229#endif /* ! __clang__ */
226#define _MHD_ROTR32(value32, bits) \ 230#define _MHD_ROTR32(value32, bits) \
227 ((uint32_t)_rotr((uint32_t)(value32),(bits))) 231 ((uint32_t) _rotr ((uint32_t) (value32),(bits)))
228#else /* ! _MSC_FULL_VER */ 232#else /* ! _MSC_FULL_VER */
229/* Defined in form which modern compiler could optimize. */ 233/* Defined in form which modern compiler could optimize. */
230#define _MHD_ROTR32(value32, bits) \ 234#define _MHD_ROTR32(value32, bits) \
231 (((uint32_t)(value32)) >> (bits) | ((uint32_t)(value32)) << (32 - bits)) 235 (((uint32_t) (value32)) >> (bits) | ((uint32_t) (value32)) << (32 - bits))
232#endif /* ! _MSC_FULL_VER */ 236#endif /* ! _MSC_FULL_VER */
233 237
234 238
diff --git a/src/microhttpd/mhd_byteorder.h b/src/microhttpd/mhd_byteorder.h
index f053aa0e..f1f03f44 100644
--- a/src/microhttpd/mhd_byteorder.h
+++ b/src/microhttpd/mhd_byteorder.h
@@ -73,7 +73,8 @@
73#if defined(__BYTE_ORDER__) 73#if defined(__BYTE_ORDER__)
74#if defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 74#if defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
75#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 75#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
76#elif defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 76#elif defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == \
77 __ORDER_LITTLE_ENDIAN__
77#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 78#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
78#elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ 79#elif defined(__ORDER_PDP_ENDIAN__) && __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
79#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN 80#define _MHD_BYTE_ORDER _MHD_PDP_ENDIAN
@@ -108,36 +109,40 @@
108/* Byte order specification didn't detected in system headers */ 109/* Byte order specification didn't detected in system headers */
109/* Try some guessing */ 110/* Try some guessing */
110 111
111#if (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) || \ 112#if (defined(__BIG_ENDIAN__) && ! defined(__LITTLE_ENDIAN__)) || \
112 (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) 113 (defined(_BIG_ENDIAN) && ! defined(_LITTLE_ENDIAN))
113/* Seems that we are on big endian platform */ 114/* Seems that we are on big endian platform */
114#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 115#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
115#elif (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ 116#elif (defined(__LITTLE_ENDIAN__) && ! defined(__BIG_ENDIAN__)) || \
116 (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) 117 (defined(_LITTLE_ENDIAN) && ! defined(_BIG_ENDIAN))
117/* Seems that we are on little endian platform */ 118/* Seems that we are on little endian platform */
118#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 119#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
119#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \ 120#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
120 defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \ 121 defined(__x86_64) || \
121 defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \ 122 defined(_M_X64) || defined(_M_AMD64) || defined(i386) || defined(__i386) || \
122 defined(_M_IX86) || defined(_X86_) || defined (__THW_INTEL__) 123 defined(__i386__) || defined(__i486__) || defined(__i586__) || \
124 defined(__i686__) || \
125 defined(_M_IX86) || defined(_X86_) || defined (__THW_INTEL__)
123/* x86 family is little endian */ 126/* x86 family is little endian */
124#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 127#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
125#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ 128#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
126 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) 129 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
127/* Looks like we are on ARM/MIPS in big endian mode */ 130/* Looks like we are on ARM/MIPS in big endian mode */
128#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 131#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
129#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ 132#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
130 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) 133 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
131/* Looks like we are on ARM/MIPS in little endian mode */ 134/* Looks like we are on ARM/MIPS in little endian mode */
132#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 135#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
133#elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || \ 136#elif defined(__m68k__) || defined(M68000) || defined(__hppa__) || \
134 defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \ 137 defined(__hppa) || \
135 defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__) 138 defined(__HPPA__) || defined(__370__) || defined(__THW_370__) || \
139 defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
136/* Looks like we are on big endian platform */ 140/* Looks like we are on big endian platform */
137#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN 141#define _MHD_BYTE_ORDER _MHD_BIG_ENDIAN
138#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || \ 142#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
139 defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \ 143 defined(__ia64) || \
140 defined(__BFIN__) || defined(bfin) || defined(BFIN) 144 defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \
145 defined(__BFIN__) || defined(bfin) || defined(BFIN)
141/* Looks like we are on little endian platform */ 146/* Looks like we are on little endian platform */
142#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN 147#define _MHD_BYTE_ORDER _MHD_LITTLE_ENDIAN
143#elif defined(_WIN32) 148#elif defined(_WIN32)
@@ -153,9 +158,11 @@
153#ifdef _MHD_BYTE_ORDER 158#ifdef _MHD_BYTE_ORDER
154/* Some safety checks */ 159/* Some safety checks */
155#if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN 160#if defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN
156#error Configure detected big endian byte order but headers specify different byte order 161#error \
157#elif !defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN 162 Configure detected big endian byte order but headers specify different byte order
158#error Configure did not detect big endian byte order but headers specify big endian byte order 163#elif ! defined(WORDS_BIGENDIAN) && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
164#error \
165 Configure did not detect big endian byte order but headers specify big endian byte order
159#endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */ 166#endif /* !WORDS_BIGENDIAN && _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN */
160#endif /* _MHD_BYTE_ORDER */ 167#endif /* _MHD_BYTE_ORDER */
161 168
diff --git a/src/microhttpd/mhd_compat.c b/src/microhttpd/mhd_compat.c
index 3abdc367..6f6c6f9c 100644
--- a/src/microhttpd/mhd_compat.c
+++ b/src/microhttpd/mhd_compat.c
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "mhd_compat.h" 27#include "mhd_compat.h"
28#if defined(_WIN32) && !defined(__CYGWIN__) 28#if defined(_WIN32) && ! defined(__CYGWIN__)
29#include <stdint.h> 29#include <stdint.h>
30#include <time.h> 30#include <time.h>
31#ifndef HAVE_SNPRINTF 31#ifndef HAVE_SNPRINTF
@@ -38,7 +38,7 @@
38#include <string.h> /* for memset() */ 38#include <string.h> /* for memset() */
39#endif /* ! HAVE_CALLOC */ 39#endif /* ! HAVE_CALLOC */
40 40
41#if defined(_WIN32) && !defined(__CYGWIN__) 41#if defined(_WIN32) && ! defined(__CYGWIN__)
42 42
43#ifndef HAVE_SNPRINTF 43#ifndef HAVE_SNPRINTF
44/* Emulate snprintf function on W32 */ 44/* Emulate snprintf function on W32 */
@@ -61,16 +61,16 @@ W32_snprintf (char *__restrict s,
61 format, 61 format,
62 args); 62 args);
63 va_end (args); 63 va_end (args);
64 if ((int)n == ret) 64 if ((int) n == ret)
65 s[n - 1] = 0; 65 s[n - 1] = 0;
66 if (ret >= 0) 66 if (ret >= 0)
67 return ret; 67 return ret;
68 } 68 }
69 va_start(args, 69 va_start (args,
70 format); 70 format);
71 ret = _vscprintf (format, 71 ret = _vscprintf (format,
72 args); 72 args);
73 va_end(args); 73 va_end (args);
74 if ( (0 <= ret) && 74 if ( (0 <= ret) &&
75 (0 != n) && 75 (0 != n) &&
76 (NULL == s) ) 76 (NULL == s) )
@@ -85,30 +85,30 @@ W32_snprintf (char *__restrict s,
85#ifndef HAVE_CALLOC 85#ifndef HAVE_CALLOC
86 86
87#ifdef __has_builtin 87#ifdef __has_builtin
88# if __has_builtin(__builtin_mul_overflow) 88# if __has_builtin (__builtin_mul_overflow)
89# define MHD_HAVE_NUL_OVERFLOW 1 89# define MHD_HAVE_NUL_OVERFLOW 1
90# endif 90# endif
91#elif __GNUC__+0 >= 5 91#elif __GNUC__ + 0 >= 5
92# define MHD_HAVE_NUL_OVERFLOW 1 92# define MHD_HAVE_NUL_OVERFLOW 1
93#endif /* __GNUC__ >= 5 */ 93#endif /* __GNUC__ >= 5 */
94 94
95 95
96void *MHD_calloc_(size_t nelem, size_t elsize) 96void *MHD_calloc_ (size_t nelem, size_t elsize)
97{ 97{
98 size_t alloc_size; 98 size_t alloc_size;
99 void *ptr; 99 void *ptr;
100#ifdef MHD_HAVE_NUL_OVERFLOW 100#ifdef MHD_HAVE_NUL_OVERFLOW
101 if (__builtin_mul_overflow(nelem, elsize, &alloc_size) || 0 == alloc_size) 101 if (__builtin_mul_overflow (nelem, elsize, &alloc_size) ||(0 == alloc_size))
102 return NULL; 102 return NULL;
103#else /* ! MHD_HAVE_NUL_OVERFLOW */ 103#else /* ! MHD_HAVE_NUL_OVERFLOW */
104 alloc_size = nelem * elsize; 104 alloc_size = nelem * elsize;
105 if (0 == alloc_size || elsize != alloc_size / nelem) 105 if ((0 == alloc_size)||(elsize != alloc_size / nelem))
106 return NULL; 106 return NULL;
107#endif /* ! MHD_HAVE_NUL_OVERFLOW */ 107#endif /* ! MHD_HAVE_NUL_OVERFLOW */
108 ptr = malloc (alloc_size); 108 ptr = malloc (alloc_size);
109 if (NULL == ptr) 109 if (NULL == ptr)
110 return NULL; 110 return NULL;
111 memset(ptr, 0, alloc_size); 111 memset (ptr, 0, alloc_size);
112 return ptr; 112 return ptr;
113} 113}
114#endif /* ! HAVE_CALLOC */ 114#endif /* ! HAVE_CALLOC */
diff --git a/src/microhttpd/mhd_compat.h b/src/microhttpd/mhd_compat.h
index b4e2c66c..6b38a03e 100644
--- a/src/microhttpd/mhd_compat.h
+++ b/src/microhttpd/mhd_compat.h
@@ -40,8 +40,8 @@
40#include <string.h> 40#include <string.h>
41#endif /* HAVE_STRING_H */ 41#endif /* HAVE_STRING_H */
42 42
43 /* MHD_strerror_ is strerror */ 43/* MHD_strerror_ is strerror */
44#define MHD_strerror_(errnum) strerror((errnum)) 44#define MHD_strerror_(errnum) strerror ((errnum))
45 45
46/* Platform-independent snprintf name */ 46/* Platform-independent snprintf name */
47#if defined(HAVE_SNPRINTF) 47#if defined(HAVE_SNPRINTF)
@@ -49,10 +49,12 @@
49#else /* ! HAVE_SNPRINTF */ 49#else /* ! HAVE_SNPRINTF */
50#if defined(_WIN32) && ! defined(__CYGWIN__) 50#if defined(_WIN32) && ! defined(__CYGWIN__)
51/* Emulate snprintf function on W32 */ 51/* Emulate snprintf function on W32 */
52int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...); 52int W32_snprintf (char *__restrict s, size_t n, const char *__restrict format,
53 ...);
53#define MHD_snprintf_ W32_snprintf 54#define MHD_snprintf_ W32_snprintf
54#else /* ! _WIN32 || __CYGWIN__ */ 55#else /* ! _WIN32 || __CYGWIN__ */
55#error Your platform does not support snprintf() and MHD does not know how to emulate it on your platform. 56#error \
57 Your platform does not support snprintf() and MHD does not know how to emulate it on your platform.
56#endif /* ! _WIN32 || __CYGWIN__ */ 58#endif /* ! _WIN32 || __CYGWIN__ */
57#endif /* ! HAVE_SNPRINTF */ 59#endif /* ! HAVE_SNPRINTF */
58 60
@@ -61,14 +63,14 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ..
61 * Generate pseudo random number at least 30-bit wide. 63 * Generate pseudo random number at least 30-bit wide.
62 * @return pseudo random number at least 30-bit wide. 64 * @return pseudo random number at least 30-bit wide.
63 */ 65 */
64#define MHD_random_() random() 66#define MHD_random_() random ()
65#else /* HAVE_RANDOM */ 67#else /* HAVE_RANDOM */
66#ifdef HAVE_RAND 68#ifdef HAVE_RAND
67/** 69/**
68 * Generate pseudo random number at least 30-bit wide. 70 * Generate pseudo random number at least 30-bit wide.
69 * @return pseudo random number at least 30-bit wide. 71 * @return pseudo random number at least 30-bit wide.
70 */ 72 */
71#define MHD_random_() ( (((long)rand()) << 15) + (long)rand() ) 73#define MHD_random_() ( (((long) rand ()) << 15) + (long) rand () )
72#endif /* HAVE_RAND */ 74#endif /* HAVE_RAND */
73#endif /* HAVE_RANDOM */ 75#endif /* HAVE_RANDOM */
74 76
@@ -76,12 +78,12 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ..
76/** 78/**
77 * MHD_calloc_ is platform-independent calloc() 79 * MHD_calloc_ is platform-independent calloc()
78 */ 80 */
79#define MHD_calloc_(n,s) calloc((n),(s)) 81#define MHD_calloc_(n,s) calloc ((n),(s))
80#else /* ! HAVE_CALLOC */ 82#else /* ! HAVE_CALLOC */
81/** 83/**
82 * MHD_calloc_ is platform-independent calloc() 84 * MHD_calloc_ is platform-independent calloc()
83 */ 85 */
84void *MHD_calloc_(size_t nelem, size_t elsize); 86void *MHD_calloc_ (size_t nelem, size_t elsize);
85#endif /* ! HAVE_CALLOC */ 87#endif /* ! HAVE_CALLOC */
86 88
87#endif /* MHD_COMPAT_H */ 89#endif /* MHD_COMPAT_H */
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c
index 8aeee576..6c81ef62 100644
--- a/src/microhttpd/mhd_itc.c
+++ b/src/microhttpd/mhd_itc.c
@@ -34,7 +34,7 @@
34 34
35 35
36#if defined(_MHD_ITC_PIPE) 36#if defined(_MHD_ITC_PIPE)
37#if !defined(_WIN32) || defined(__CYGWIN__) 37#if ! defined(_WIN32) || defined(__CYGWIN__)
38 38
39#ifndef HAVE_PIPE2_FUNC 39#ifndef HAVE_PIPE2_FUNC
40/** 40/**
@@ -48,7 +48,7 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc)
48{ 48{
49 unsigned int i; 49 unsigned int i;
50 50
51 for (i=0;i<2;i++) 51 for (i = 0; i<2; i++)
52 { 52 {
53 int flags; 53 int flags;
54 54
@@ -63,7 +63,7 @@ MHD_itc_nonblocking_ (struct MHD_itc_ itc)
63 flags | O_NONBLOCK)) ) 63 flags | O_NONBLOCK)) )
64 return 0; 64 return 0;
65 } 65 }
66 return !0; 66 return ! 0;
67} 67}
68#endif /* ! HAVE_PIPE2_FUNC */ 68#endif /* ! HAVE_PIPE2_FUNC */
69#endif /* !_WIN32 || __CYGWIN__ */ 69#endif /* !_WIN32 || __CYGWIN__ */
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
index 01331f13..8e303ef9 100644
--- a/src/microhttpd/mhd_itc.h
+++ b/src/microhttpd/mhd_itc.h
@@ -41,8 +41,9 @@
41# include <stdlib.h> 41# include <stdlib.h>
42/* Simple implementation of MHD_PANIC, to be used outside lib */ 42/* Simple implementation of MHD_PANIC, to be used outside lib */
43# define MHD_PANIC(msg) do { fprintf (stderr, \ 43# define MHD_PANIC(msg) do { fprintf (stderr, \
44 "Abnormal termination at %d line in file %s: %s\n", \ 44 "Abnormal termination at %d line in file %s: %s\n", \
45 (int)__LINE__, __FILE__, msg); abort();} while(0) 45 (int) __LINE__, __FILE__, msg); abort (); \
46} while (0)
46#endif /* ! MHD_PANIC */ 47#endif /* ! MHD_PANIC */
47 48
48#if defined(_MHD_ITC_EVENTFD) 49#if defined(_MHD_ITC_EVENTFD)
@@ -63,12 +64,13 @@
63 * @param itc the itc to initialise 64 * @param itc the itc to initialise
64 * @return non-zero if succeeded, zero otherwise 65 * @return non-zero if succeeded, zero otherwise
65 */ 66 */
66#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) 67#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC \
68 | EFD_NONBLOCK)))
67 69
68/** 70/**
69 * Get description string of last errno for itc operations. 71 * Get description string of last errno for itc operations.
70 */ 72 */
71#define MHD_itc_last_strerror_() strerror(errno) 73#define MHD_itc_last_strerror_() strerror (errno)
72 74
73/** 75/**
74 * Internal static const helper for MHD_itc_activate_() 76 * Internal static const helper for MHD_itc_activate_()
@@ -82,7 +84,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
82 * @return non-zero if succeeded, zero otherwise 84 * @return non-zero if succeeded, zero otherwise
83 */ 85 */
84#define MHD_itc_activate_(itc, str) \ 86#define MHD_itc_activate_(itc, str) \
85 ((write((itc).fd, (const void*)&_MHD_itc_wr_data, 8) > 0) || (EAGAIN == errno)) 87 ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, 8) > 0) || (EAGAIN == \
88 errno))
86 89
87/** 90/**
88 * Return read FD of @a itc which can be used for poll(), select() etc. 91 * Return read FD of @a itc which can be used for poll(), select() etc.
@@ -104,8 +107,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
104 */ 107 */
105#define MHD_itc_clear_(itc) \ 108#define MHD_itc_clear_(itc) \
106 do { uint64_t __b; int __r; \ 109 do { uint64_t __b; int __r; \
107 __r = read((itc).fd, &__b, sizeof(__b)); \ 110 __r = read ((itc).fd, &__b, sizeof(__b)); \
108 (void)__r; } while(0) 111 (void) __r; } while (0)
109 112
110/** 113/**
111 * Destroy previously initialised ITC. Note that close() 114 * Destroy previously initialised ITC. Note that close()
@@ -155,20 +158,20 @@ static const uint64_t _MHD_itc_wr_data = 1;
155 * @return non-zero if succeeded, zero otherwise 158 * @return non-zero if succeeded, zero otherwise
156 */ 159 */
157#ifdef HAVE_PIPE2_FUNC 160#ifdef HAVE_PIPE2_FUNC
158# define MHD_itc_init_(itc) (!pipe2((itc).fd, O_CLOEXEC | O_NONBLOCK)) 161# define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK))
159#else /* ! HAVE_PIPE2_FUNC */ 162#else /* ! HAVE_PIPE2_FUNC */
160# define MHD_itc_init_(itc) \ 163# define MHD_itc_init_(itc) \
161 ( (!pipe((itc).fd)) ? \ 164 ( (! pipe ((itc).fd)) ? \
162 (MHD_itc_nonblocking_((itc)) ? \ 165 (MHD_itc_nonblocking_ ((itc)) ? \
163 (!0) : \ 166 (! 0) : \
164 (MHD_itc_destroy_((itc)), 0) ) \ 167 (MHD_itc_destroy_ ((itc)), 0) ) \
165 : (0) ) 168 : (0) )
166#endif /* ! HAVE_PIPE2_FUNC */ 169#endif /* ! HAVE_PIPE2_FUNC */
167 170
168/** 171/**
169 * Get description string of last errno for itc operations. 172 * Get description string of last errno for itc operations.
170 */ 173 */
171#define MHD_itc_last_strerror_() strerror(errno) 174#define MHD_itc_last_strerror_() strerror (errno)
172 175
173/** 176/**
174 * Activate signal on @a itc 177 * Activate signal on @a itc
@@ -177,7 +180,7 @@ static const uint64_t _MHD_itc_wr_data = 1;
177 * @return non-zero if succeeded, zero otherwise 180 * @return non-zero if succeeded, zero otherwise
178 */ 181 */
179#define MHD_itc_activate_(itc, str) \ 182#define MHD_itc_activate_(itc, str) \
180 ((write((itc).fd[1], (const void*)(str), 1) > 0) || (EAGAIN == errno)) 183 ((write ((itc).fd[1], (const void*) (str), 1) > 0) || (EAGAIN == errno))
181 184
182 185
183/** 186/**
@@ -200,8 +203,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
200 */ 203 */
201#define MHD_itc_clear_(itc) do \ 204#define MHD_itc_clear_(itc) do \
202 { long __b; \ 205 { long __b; \
203 while(0 < read((itc).fd[0], &__b, sizeof(__b))) \ 206 while (0 < read ((itc).fd[0], &__b, sizeof(__b))) \
204 {} } while(0) 207 {} } while (0)
205 208
206/** 209/**
207 * Destroy previously initialised ITC 210 * Destroy previously initialised ITC
@@ -210,8 +213,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
210 */ 213 */
211#define MHD_itc_destroy_(itc) \ 214#define MHD_itc_destroy_(itc) \
212 ( (0 == close ((itc).fd[0])) ? \ 215 ( (0 == close ((itc).fd[0])) ? \
213 (0 == close ((itc).fd[1])) : \ 216 (0 == close ((itc).fd[1])) : \
214 ((close ((itc).fd[1])), 0) ) 217 ((close ((itc).fd[1])), 0) )
215 218
216/** 219/**
217 * Check whether ITC has valid value. 220 * Check whether ITC has valid value.
@@ -231,14 +234,14 @@ static const uint64_t _MHD_itc_wr_data = 1;
231#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1) 234#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1)
232 235
233#ifndef HAVE_PIPE2_FUNC 236#ifndef HAVE_PIPE2_FUNC
234 /** 237/**
235 * Change itc FD options to be non-blocking. 238 * Change itc FD options to be non-blocking.
236 * 239 *
237 * @param fd the FD to manipulate 240 * @param fd the FD to manipulate
238 * @return non-zero if succeeded, zero otherwise 241 * @return non-zero if succeeded, zero otherwise
239 */ 242 */
240 int 243int
241 MHD_itc_nonblocking_ (struct MHD_itc_ itc); 244MHD_itc_nonblocking_ (struct MHD_itc_ itc);
242#endif /* ! HAVE_PIPE2_FUNC */ 245#endif /* ! HAVE_PIPE2_FUNC */
243 246
244 247
@@ -255,20 +258,20 @@ static const uint64_t _MHD_itc_wr_data = 1;
255 * @return non-zero if succeeded, zero otherwise 258 * @return non-zero if succeeded, zero otherwise
256 */ 259 */
257#ifdef MHD_socket_pair_nblk_ 260#ifdef MHD_socket_pair_nblk_
258# define MHD_itc_init_(itc) MHD_socket_pair_nblk_((itc).sk) 261# define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk)
259#else /* ! MHD_socket_pair_nblk_ */ 262#else /* ! MHD_socket_pair_nblk_ */
260# define MHD_itc_init_(itc) \ 263# define MHD_itc_init_(itc) \
261 (MHD_socket_pair_((itc).sk) ? \ 264 (MHD_socket_pair_ ((itc).sk) ? \
262 (MHD_itc_nonblocking_((itc)) ? \ 265 (MHD_itc_nonblocking_ ((itc)) ? \
263 (!0) : \ 266 (! 0) : \
264 (MHD_itc_destroy_((itc)), 0) ) \ 267 (MHD_itc_destroy_ ((itc)), 0) ) \
265 : (0)) 268 : (0))
266#endif /* ! MHD_socket_pair_nblk_ */ 269#endif /* ! MHD_socket_pair_nblk_ */
267 270
268/** 271/**
269 * Get description string of last error for itc operations. 272 * Get description string of last error for itc operations.
270 */ 273 */
271#define MHD_itc_last_strerror_() MHD_socket_last_strerr_() 274#define MHD_itc_last_strerror_() MHD_socket_last_strerr_ ()
272 275
273/** 276/**
274 * Activate signal on @a itc 277 * Activate signal on @a itc
@@ -277,8 +280,8 @@ static const uint64_t _MHD_itc_wr_data = 1;
277 * @return non-zero if succeeded, zero otherwise 280 * @return non-zero if succeeded, zero otherwise
278 */ 281 */
279#define MHD_itc_activate_(itc, str) \ 282#define MHD_itc_activate_(itc, str) \
280 ((MHD_send_((itc).sk[1], (str), 1) > 0) || \ 283 ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \
281 (MHD_SCKT_ERR_IS_EAGAIN_(MHD_socket_get_error_()))) 284 (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())))
282 285
283/** 286/**
284 * Return read FD of @a itc which can be used for poll(), select() etc. 287 * Return read FD of @a itc which can be used for poll(), select() etc.
@@ -300,10 +303,10 @@ static const uint64_t _MHD_itc_wr_data = 1;
300 */ 303 */
301#define MHD_itc_clear_(itc) do \ 304#define MHD_itc_clear_(itc) do \
302 { long __b; \ 305 { long __b; \
303 while(0 < recv((itc).sk[0], \ 306 while (0 < recv ((itc).sk[0], \
304 (char*)&__b, \ 307 (char*) &__b, \
305 sizeof(__b), 0)) \ 308 sizeof(__b), 0)) \
306 {} } while(0) 309 {} } while (0)
307 310
308/** 311/**
309 * Destroy previously initialised ITC 312 * Destroy previously initialised ITC
@@ -311,9 +314,9 @@ static const uint64_t _MHD_itc_wr_data = 1;
311 * @return non-zero if succeeded, zero otherwise 314 * @return non-zero if succeeded, zero otherwise
312 */ 315 */
313#define MHD_itc_destroy_(itc) \ 316#define MHD_itc_destroy_(itc) \
314 ( MHD_socket_close_((itc).sk[0]) ? \ 317 (MHD_socket_close_ ((itc).sk[0]) ? \
315 MHD_socket_close_((itc).sk[1]) : \ 318 MHD_socket_close_ ((itc).sk[1]) : \
316 ((void)MHD_socket_close_((itc).sk[1]), 0) ) 319 ((void) MHD_socket_close_ ((itc).sk[1]), 0) )
317 320
318 321
319/** 322/**
@@ -331,10 +334,12 @@ static const uint64_t _MHD_itc_wr_data = 1;
331 * Set @a itc to invalid value. 334 * Set @a itc to invalid value.
332 * @param itc the itc to set 335 * @param itc the itc to set
333 */ 336 */
334#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = MHD_INVALID_SOCKET) 337#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = \
338 MHD_INVALID_SOCKET)
335 339
336#ifndef MHD_socket_pair_nblk_ 340#ifndef MHD_socket_pair_nblk_
337# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip).sk[0]) && MHD_socket_nonblocking_((pip).sk[1])) 341# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_ ((pip).sk[0]) && \
342 MHD_socket_nonblocking_ ((pip).sk[1]))
338#endif /* ! MHD_socket_pair_nblk_ */ 343#endif /* ! MHD_socket_pair_nblk_ */
339 344
340#endif /* _MHD_ITC_SOCKETPAIR */ 345#endif /* _MHD_ITC_SOCKETPAIR */
@@ -345,9 +350,9 @@ static const uint64_t _MHD_itc_wr_data = 1;
345 * @param itc the itc to destroy 350 * @param itc the itc to destroy
346 */ 351 */
347#define MHD_itc_destroy_chk_(itc) do { \ 352#define MHD_itc_destroy_chk_(itc) do { \
348 if (!MHD_itc_destroy_(itc)) \ 353 if (! MHD_itc_destroy_ (itc)) \
349 MHD_PANIC(_("Failed to destroy ITC.\n")); \ 354 MHD_PANIC (_ ("Failed to destroy ITC.\n")); \
350 } while(0) 355} while (0)
351 356
352/** 357/**
353 * Check whether ITC has invalid value. 358 * Check whether ITC has invalid value.
@@ -358,6 +363,6 @@ static const uint64_t _MHD_itc_wr_data = 1;
358 * @return boolean true if @a itc has invalid value, 363 * @return boolean true if @a itc has invalid value,
359 * boolean false otherwise. 364 * boolean false otherwise.
360 */ 365 */
361#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_(itc)) 366#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_ (itc))
362 367
363#endif /* MHD_ITC_H */ 368#endif /* MHD_ITC_H */
diff --git a/src/microhttpd/mhd_itc_types.h b/src/microhttpd/mhd_itc_types.h
index 04966d36..36d4218b 100644
--- a/src/microhttpd/mhd_itc_types.h
+++ b/src/microhttpd/mhd_itc_types.h
@@ -32,7 +32,7 @@
32#include "mhd_options.h" 32#include "mhd_options.h"
33 33
34/* Force socketpair on native W32 */ 34/* Force socketpair on native W32 */
35#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR) 35#if defined(_WIN32) && ! defined(__CYGWIN__) && ! defined(_MHD_ITC_SOCKETPAIR)
36#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform 36#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
37#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */ 37#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
38 38
diff --git a/src/microhttpd/mhd_limits.h b/src/microhttpd/mhd_limits.h
index 40ae2e26..b97fce6f 100644
--- a/src/microhttpd/mhd_limits.h
+++ b/src/microhttpd/mhd_limits.h
@@ -32,17 +32,17 @@
32#include <limits.h> 32#include <limits.h>
33#endif /* HAVE_LIMITS_H */ 33#endif /* HAVE_LIMITS_H */
34 34
35#define MHD_UNSIGNED_TYPE_MAX_(type) ((type)-1) 35#define MHD_UNSIGNED_TYPE_MAX_(type) ((type) - 1)
36/* Assume 8 bits per byte, no padding bits. */ 36/* Assume 8 bits per byte, no padding bits. */
37#define MHD_SIGNED_TYPE_MAX_(type) \ 37#define MHD_SIGNED_TYPE_MAX_(type) \
38 ( (type)((( ((type)1) << (sizeof(type)*8 - 2)) - 1)*2 + 1) ) 38 ( (type) ((( ((type) 1) << (sizeof(type) * 8 - 2)) - 1) * 2 + 1) )
39#define MHD_TYPE_IS_SIGNED_(type) (((type)0)>((type)-1)) 39#define MHD_TYPE_IS_SIGNED_(type) (((type) 0)>((type) - 1))
40 40
41#ifndef UINT_MAX 41#ifndef UINT_MAX
42#ifdef __UINT_MAX__ 42#ifdef __UINT_MAX__
43#define UINT_MAX __UINT_MAX__ 43#define UINT_MAX __UINT_MAX__
44#else /* ! __UINT_MAX__ */ 44#else /* ! __UINT_MAX__ */
45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_(unsigned int) 45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_ (unsigned int)
46#endif /* ! __UINT_MAX__ */ 46#endif /* ! __UINT_MAX__ */
47#endif /* !UINT_MAX */ 47#endif /* !UINT_MAX */
48 48
@@ -50,19 +50,19 @@
50#ifdef __LONG_MAX__ 50#ifdef __LONG_MAX__
51#define LONG_MAX __LONG_MAX__ 51#define LONG_MAX __LONG_MAX__
52#else /* ! __LONG_MAX__ */ 52#else /* ! __LONG_MAX__ */
53#define LONG_MAX MHD_SIGNED_TYPE_MAX(long) 53#define LONG_MAX MHD_SIGNED_TYPE_MAX (long)
54#endif /* ! __LONG_MAX__ */ 54#endif /* ! __LONG_MAX__ */
55#endif /* !OFF_T_MAX */ 55#endif /* !OFF_T_MAX */
56 56
57#ifndef ULLONG_MAX 57#ifndef ULLONG_MAX
58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_(MHD_UNSIGNED_LONG_LONG) 58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_ (MHD_UNSIGNED_LONG_LONG)
59#endif /* !ULLONG_MAX */ 59#endif /* !ULLONG_MAX */
60 60
61#ifndef INT32_MAX 61#ifndef INT32_MAX
62#ifdef __INT32_MAX__ 62#ifdef __INT32_MAX__
63#define INT32_MAX __INT32_MAX__ 63#define INT32_MAX __INT32_MAX__
64#else /* ! __INT32_MAX__ */ 64#else /* ! __INT32_MAX__ */
65#define INT32_MAX ((int32_t)0x7FFFFFFF) 65#define INT32_MAX ((int32_t) 0x7FFFFFFF)
66#endif /* ! __INT32_MAX__ */ 66#endif /* ! __INT32_MAX__ */
67#endif /* !INT32_MAX */ 67#endif /* !INT32_MAX */
68 68
@@ -70,7 +70,7 @@
70#ifdef __UINT32_MAX__ 70#ifdef __UINT32_MAX__
71#define UINT32_MAX __UINT32_MAX__ 71#define UINT32_MAX __UINT32_MAX__
72#else /* ! __UINT32_MAX__ */ 72#else /* ! __UINT32_MAX__ */
73#define UINT32_MAX ((int32_t)0xFFFFFFFF) 73#define UINT32_MAX ((int32_t) 0xFFFFFFFF)
74#endif /* ! __UINT32_MAX__ */ 74#endif /* ! __UINT32_MAX__ */
75#endif /* !UINT32_MAX */ 75#endif /* !UINT32_MAX */
76 76
@@ -78,7 +78,7 @@
78#ifdef __UINT64_MAX__ 78#ifdef __UINT64_MAX__
79#define UINT64_MAX __UINT64_MAX__ 79#define UINT64_MAX __UINT64_MAX__
80#else /* ! __UINT64_MAX__ */ 80#else /* ! __UINT64_MAX__ */
81#define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFF) 81#define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFF)
82#endif /* ! __UINT64_MAX__ */ 82#endif /* ! __UINT64_MAX__ */
83#endif /* !UINT64_MAX */ 83#endif /* !UINT64_MAX */
84 84
@@ -86,7 +86,7 @@
86#ifdef __INT64_MAX__ 86#ifdef __INT64_MAX__
87#define INT64_MAX __INT64_MAX__ 87#define INT64_MAX __INT64_MAX__
88#else /* ! __INT64_MAX__ */ 88#else /* ! __INT64_MAX__ */
89#define INT64_MAX ((int64_t)0x7FFFFFFFFFFFFFFF) 89#define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
90#endif /* ! __UINT64_MAX__ */ 90#endif /* ! __UINT64_MAX__ */
91#endif /* !INT64_MAX */ 91#endif /* !INT64_MAX */
92 92
@@ -96,8 +96,8 @@
96#elif defined(UINTPTR_MAX) 96#elif defined(UINTPTR_MAX)
97#define SIZE_MAX UINTPTR_MAX 97#define SIZE_MAX UINTPTR_MAX
98#else /* ! __SIZE_MAX__ */ 98#else /* ! __SIZE_MAX__ */
99#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_(size_t) 99#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_ (size_t)
100#endif /* ! __SIZE_MAX__ */ 100#endif /* ! __SIZE_MAX__ */
101#endif /* !SIZE_MAX */ 101#endif /* !SIZE_MAX */
102 102
103#ifndef SSIZE_MAX 103#ifndef SSIZE_MAX
@@ -108,7 +108,7 @@
108#elif defined(INTPTR_MAX) 108#elif defined(INTPTR_MAX)
109#define SSIZE_MAX INTPTR_MAX 109#define SSIZE_MAX INTPTR_MAX
110#else 110#else
111#define SSIZE_MAX MHD_SIGNED_TYPE_MAX_(ssize_t) 111#define SSIZE_MAX MHD_SIGNED_TYPE_MAX_ (ssize_t)
112#endif 112#endif
113#endif /* ! SSIZE_MAX */ 113#endif /* ! SSIZE_MAX */
114 114
@@ -120,19 +120,19 @@
120#elif defined(__APPLE__) && defined(__MACH__) 120#elif defined(__APPLE__) && defined(__MACH__)
121#define OFF_T_MAX INT64_MAX 121#define OFF_T_MAX INT64_MAX
122#else 122#else
123#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_(off_t) 123#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_ (off_t)
124#endif 124#endif
125#endif /* !OFF_T_MAX */ 125#endif /* !OFF_T_MAX */
126 126
127#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX) 127#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
128#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_(uint64_t) 128#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_ (uint64_t)
129#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */ 129#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
130 130
131#ifndef TIME_T_MAX 131#ifndef TIME_T_MAX
132#define TIME_T_MAX ((time_t) \ 132#define TIME_T_MAX ((time_t) \
133 ( MHD_TYPE_IS_SIGNED_(time_t) ? \ 133 (MHD_TYPE_IS_SIGNED_ (time_t) ? \
134 MHD_SIGNED_TYPE_MAX_(time_t) : \ 134 MHD_SIGNED_TYPE_MAX_ (time_t) : \
135 MHD_UNSIGNED_TYPE_MAX_(time_t))) 135 MHD_UNSIGNED_TYPE_MAX_ (time_t)))
136#endif /* !TIME_T_MAX */ 136#endif /* !TIME_T_MAX */
137 137
138#ifndef TIMEVAL_TV_SEC_MAX 138#ifndef TIMEVAL_TV_SEC_MAX
diff --git a/src/microhttpd/mhd_locks.h b/src/microhttpd/mhd_locks.h
index 21db56c4..8c9b0844 100644
--- a/src/microhttpd/mhd_locks.h
+++ b/src/microhttpd/mhd_locks.h
@@ -59,14 +59,15 @@
59# include <stdlib.h> 59# include <stdlib.h>
60/* Simple implementation of MHD_PANIC, to be used outside lib */ 60/* Simple implementation of MHD_PANIC, to be used outside lib */
61# define MHD_PANIC(msg) do { fprintf (stderr, \ 61# define MHD_PANIC(msg) do { fprintf (stderr, \
62 "Abnormal termination at %d line in file %s: %s\n", \ 62 "Abnormal termination at %d line in file %s: %s\n", \
63 (int)__LINE__, __FILE__, msg); abort();} while(0) 63 (int) __LINE__, __FILE__, msg); abort (); \
64} while (0)
64#endif /* ! MHD_PANIC */ 65#endif /* ! MHD_PANIC */
65 66
66#if defined(MHD_PTHREAD_MUTEX_) 67#if defined(MHD_PTHREAD_MUTEX_)
67 typedef pthread_mutex_t MHD_mutex_; 68typedef pthread_mutex_t MHD_mutex_;
68#elif defined(MHD_W32_MUTEX_) 69#elif defined(MHD_W32_MUTEX_)
69 typedef CRITICAL_SECTION MHD_mutex_; 70typedef CRITICAL_SECTION MHD_mutex_;
70#endif 71#endif
71 72
72#if defined(MHD_PTHREAD_MUTEX_) 73#if defined(MHD_PTHREAD_MUTEX_)
@@ -75,14 +76,15 @@
75 * @param pmutex pointer to the mutex 76 * @param pmutex pointer to the mutex
76 * @return nonzero on success, zero otherwise 77 * @return nonzero on success, zero otherwise
77 */ 78 */
78#define MHD_mutex_init_(pmutex) (!(pthread_mutex_init((pmutex), NULL))) 79#define MHD_mutex_init_(pmutex) (! (pthread_mutex_init ((pmutex), NULL)))
79#elif defined(MHD_W32_MUTEX_) 80#elif defined(MHD_W32_MUTEX_)
80/** 81/**
81 * Initialise new mutex. 82 * Initialise new mutex.
82 * @param pmutex pointer to mutex 83 * @param pmutex pointer to mutex
83 * @return nonzero on success, zero otherwise 84 * @return nonzero on success, zero otherwise
84 */ 85 */
85#define MHD_mutex_init_(pmutex) (InitializeCriticalSectionAndSpinCount((pmutex),16)) 86#define MHD_mutex_init_(pmutex) (InitializeCriticalSectionAndSpinCount ( \
87 (pmutex),16))
86#endif 88#endif
87 89
88#if defined(MHD_PTHREAD_MUTEX_) 90#if defined(MHD_PTHREAD_MUTEX_)
@@ -90,7 +92,8 @@
90/** 92/**
91 * Define static mutex and statically initialise it. 93 * Define static mutex and statically initialise it.
92 */ 94 */
93# define MHD_MUTEX_STATIC_DEFN_INIT_(m) static MHD_mutex_ m = PTHREAD_MUTEX_INITIALIZER 95# define MHD_MUTEX_STATIC_DEFN_INIT_(m) static MHD_mutex_ m = \
96 PTHREAD_MUTEX_INITIALIZER
94# endif /* PTHREAD_MUTEX_INITIALIZER */ 97# endif /* PTHREAD_MUTEX_INITIALIZER */
95#endif 98#endif
96 99
@@ -100,14 +103,14 @@
100 * @param pmutex pointer to mutex 103 * @param pmutex pointer to mutex
101 * @return nonzero on success, zero otherwise 104 * @return nonzero on success, zero otherwise
102 */ 105 */
103#define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex)))) 106#define MHD_mutex_destroy_(pmutex) (! (pthread_mutex_destroy ((pmutex))))
104#elif defined(MHD_W32_MUTEX_) 107#elif defined(MHD_W32_MUTEX_)
105/** 108/**
106 * Destroy previously initialised mutex. 109 * Destroy previously initialised mutex.
107 * @param pmutex pointer to mutex 110 * @param pmutex pointer to mutex
108 * @return Always nonzero 111 * @return Always nonzero
109 */ 112 */
110#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0) 113#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection ((pmutex)), ! 0)
111#endif 114#endif
112 115
113/** 116/**
@@ -116,9 +119,9 @@
116 * @param pmutex pointer to mutex 119 * @param pmutex pointer to mutex
117 */ 120 */
118#define MHD_mutex_destroy_chk_(pmutex) do { \ 121#define MHD_mutex_destroy_chk_(pmutex) do { \
119 if (!MHD_mutex_destroy_(pmutex)) \ 122 if (! MHD_mutex_destroy_ (pmutex)) \
120 MHD_PANIC(_("Failed to destroy mutex.\n")); \ 123 MHD_PANIC (_ ("Failed to destroy mutex.\n")); \
121 } while(0) 124} while (0)
122 125
123 126
124#if defined(MHD_PTHREAD_MUTEX_) 127#if defined(MHD_PTHREAD_MUTEX_)
@@ -129,7 +132,7 @@
129 * @param pmutex pointer to mutex 132 * @param pmutex pointer to mutex
130 * @return nonzero on success, zero otherwise 133 * @return nonzero on success, zero otherwise
131 */ 134 */
132#define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex)))) 135#define MHD_mutex_lock_(pmutex) (! (pthread_mutex_lock ((pmutex))))
133#elif defined(MHD_W32_MUTEX_) 136#elif defined(MHD_W32_MUTEX_)
134/** 137/**
135 * Acquire lock on previously initialised mutex. 138 * Acquire lock on previously initialised mutex.
@@ -138,7 +141,7 @@
138 * @param pmutex pointer to mutex 141 * @param pmutex pointer to mutex
139 * @return Always nonzero 142 * @return Always nonzero
140 */ 143 */
141#define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0) 144#define MHD_mutex_lock_(pmutex) (EnterCriticalSection ((pmutex)), ! 0)
142#endif 145#endif
143 146
144/** 147/**
@@ -149,9 +152,9 @@
149 * @param pmutex pointer to mutex 152 * @param pmutex pointer to mutex
150 */ 153 */
151#define MHD_mutex_lock_chk_(pmutex) do { \ 154#define MHD_mutex_lock_chk_(pmutex) do { \
152 if (!MHD_mutex_lock_(pmutex)) \ 155 if (! MHD_mutex_lock_ (pmutex)) \
153 MHD_PANIC(_("Failed to lock mutex.\n")); \ 156 MHD_PANIC (_ ("Failed to lock mutex.\n")); \
154 } while(0) 157} while (0)
155 158
156#if defined(MHD_PTHREAD_MUTEX_) 159#if defined(MHD_PTHREAD_MUTEX_)
157/** 160/**
@@ -159,14 +162,14 @@
159 * @param pmutex pointer to mutex 162 * @param pmutex pointer to mutex
160 * @return nonzero on success, zero otherwise 163 * @return nonzero on success, zero otherwise
161 */ 164 */
162#define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex)))) 165#define MHD_mutex_unlock_(pmutex) (! (pthread_mutex_unlock ((pmutex))))
163#elif defined(MHD_W32_MUTEX_) 166#elif defined(MHD_W32_MUTEX_)
164/** 167/**
165 * Unlock previously initialised and locked mutex. 168 * Unlock previously initialised and locked mutex.
166 * @param pmutex pointer to mutex 169 * @param pmutex pointer to mutex
167 * @return Always nonzero 170 * @return Always nonzero
168 */ 171 */
169#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0) 172#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection ((pmutex)), ! 0)
170#endif 173#endif
171 174
172/** 175/**
@@ -175,9 +178,9 @@
175 * @param pmutex pointer to mutex 178 * @param pmutex pointer to mutex
176 */ 179 */
177#define MHD_mutex_unlock_chk_(pmutex) do { \ 180#define MHD_mutex_unlock_chk_(pmutex) do { \
178 if (!MHD_mutex_unlock_(pmutex)) \ 181 if (! MHD_mutex_unlock_ (pmutex)) \
179 MHD_PANIC(_("Failed to unlock mutex.\n")); \ 182 MHD_PANIC (_ ("Failed to unlock mutex.\n")); \
180 } while(0) 183} while (0)
181 184
182 185
183#endif /* ! MHD_LOCKS_H */ 186#endif /* ! MHD_LOCKS_H */
diff --git a/src/microhttpd/mhd_mono_clock.c b/src/microhttpd/mhd_mono_clock.c
index 97dbfb9f..eee911fb 100644
--- a/src/microhttpd/mhd_mono_clock.c
+++ b/src/microhttpd/mhd_mono_clock.c
@@ -76,7 +76,8 @@ static clockid_t mono_clock_id = _MHD_UNWANTED_CLOCK;
76#endif /* HAVE_CLOCK_GETTIME */ 76#endif /* HAVE_CLOCK_GETTIME */
77 77
78/* sync clocks; reduce chance of value wrap */ 78/* sync clocks; reduce chance of value wrap */
79#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GET_TIME) || defined(HAVE_GETHRTIME) 79#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GET_TIME) || \
80 defined(HAVE_GETHRTIME)
80static time_t mono_clock_start; 81static time_t mono_clock_start;
81#endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GET_TIME || HAVE_GETHRTIME */ 82#endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GET_TIME || HAVE_GETHRTIME */
82static time_t sys_clock_start; 83static time_t sys_clock_start;
@@ -124,9 +125,9 @@ enum _MHD_mono_clock_source
124 */ 125 */
125 _MHD_CLOCK_GETTICKCOUNT64, 126 _MHD_CLOCK_GETTICKCOUNT64,
126 127
127 /** 128 /**
128 * QueryPerformanceCounter() / QueryPerformanceFrequency() 129 * QueryPerformanceCounter() / QueryPerformanceFrequency()
129 */ 130 */
130 _MHD_CLOCK_PERFCOUNTER 131 _MHD_CLOCK_PERFCOUNTER
131}; 132};
132 133
@@ -153,8 +154,8 @@ MHD_monotonic_sec_counter_init (void)
153 /* just a little syntactic trick to get the 154 /* just a little syntactic trick to get the
154 various following ifdef's to work out nicely */ 155 various following ifdef's to work out nicely */
155 if (0) 156 if (0)
156 { 157 {
157 } 158 }
158 else 159 else
159#ifdef HAVE_CLOCK_GETTIME 160#ifdef HAVE_CLOCK_GETTIME
160#ifdef CLOCK_MONOTONIC_COARSE 161#ifdef CLOCK_MONOTONIC_COARSE
@@ -163,11 +164,11 @@ MHD_monotonic_sec_counter_init (void)
163 /* but preferred since it's fast */ 164 /* but preferred since it's fast */
164 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE, 165 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE,
165 &ts)) 166 &ts))
166 { 167 {
167 mono_clock_id = CLOCK_MONOTONIC_COARSE; 168 mono_clock_id = CLOCK_MONOTONIC_COARSE;
168 mono_clock_start = ts.tv_sec; 169 mono_clock_start = ts.tv_sec;
169 mono_clock_source = _MHD_CLOCK_GETTIME; 170 mono_clock_source = _MHD_CLOCK_GETTIME;
170 } 171 }
171 else 172 else
172#endif /* CLOCK_MONOTONIC_COARSE */ 173#endif /* CLOCK_MONOTONIC_COARSE */
173#ifdef CLOCK_MONOTONIC_FAST 174#ifdef CLOCK_MONOTONIC_FAST
@@ -175,11 +176,11 @@ MHD_monotonic_sec_counter_init (void)
175 /* Can be affected by frequency adjustment, but preferred since it's fast */ 176 /* Can be affected by frequency adjustment, but preferred since it's fast */
176 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, 177 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST,
177 &ts)) 178 &ts))
178 { 179 {
179 mono_clock_id = CLOCK_MONOTONIC_FAST; 180 mono_clock_id = CLOCK_MONOTONIC_FAST;
180 mono_clock_start = ts.tv_sec; 181 mono_clock_start = ts.tv_sec;
181 mono_clock_source = _MHD_CLOCK_GETTIME; 182 mono_clock_source = _MHD_CLOCK_GETTIME;
182 } 183 }
183 else 184 else
184#endif /* CLOCK_MONOTONIC_COARSE */ 185#endif /* CLOCK_MONOTONIC_COARSE */
185#ifdef CLOCK_MONOTONIC_RAW 186#ifdef CLOCK_MONOTONIC_RAW
@@ -187,11 +188,11 @@ MHD_monotonic_sec_counter_init (void)
187 /* Not affected by frequency adjustment, but don't count time in suspend */ 188 /* Not affected by frequency adjustment, but don't count time in suspend */
188 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW, 189 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW,
189 &ts)) 190 &ts))
190 { 191 {
191 mono_clock_id = CLOCK_MONOTONIC_RAW; 192 mono_clock_id = CLOCK_MONOTONIC_RAW;
192 mono_clock_start = ts.tv_sec; 193 mono_clock_start = ts.tv_sec;
193 mono_clock_source = _MHD_CLOCK_GETTIME; 194 mono_clock_source = _MHD_CLOCK_GETTIME;
194 } 195 }
195 else 196 else
196#endif /* CLOCK_MONOTONIC_RAW */ 197#endif /* CLOCK_MONOTONIC_RAW */
197#ifdef CLOCK_BOOTTIME 198#ifdef CLOCK_BOOTTIME
@@ -200,11 +201,11 @@ MHD_monotonic_sec_counter_init (void)
200 /* but can be slower value-getting than other clocks */ 201 /* but can be slower value-getting than other clocks */
201 if (0 == clock_gettime (CLOCK_BOOTTIME, 202 if (0 == clock_gettime (CLOCK_BOOTTIME,
202 &ts)) 203 &ts))
203 { 204 {
204 mono_clock_id = CLOCK_BOOTTIME; 205 mono_clock_id = CLOCK_BOOTTIME;
205 mono_clock_start = ts.tv_sec; 206 mono_clock_start = ts.tv_sec;
206 mono_clock_source = _MHD_CLOCK_GETTIME; 207 mono_clock_source = _MHD_CLOCK_GETTIME;
207 } 208 }
208 else 209 else
209#endif /* CLOCK_BOOTTIME */ 210#endif /* CLOCK_BOOTTIME */
210#ifdef CLOCK_MONOTONIC 211#ifdef CLOCK_MONOTONIC
@@ -213,11 +214,11 @@ MHD_monotonic_sec_counter_init (void)
213 /* On Linux it's not truly monotonic as it doesn't count time in suspend */ 214 /* On Linux it's not truly monotonic as it doesn't count time in suspend */
214 if (0 == clock_gettime (CLOCK_MONOTONIC, 215 if (0 == clock_gettime (CLOCK_MONOTONIC,
215 &ts)) 216 &ts))
216 { 217 {
217 mono_clock_id = CLOCK_MONOTONIC; 218 mono_clock_id = CLOCK_MONOTONIC;
218 mono_clock_start = ts.tv_sec; 219 mono_clock_start = ts.tv_sec;
219 mono_clock_source = _MHD_CLOCK_GETTIME; 220 mono_clock_source = _MHD_CLOCK_GETTIME;
220 } 221 }
221 else 222 else
222#endif /* CLOCK_BOOTTIME */ 223#endif /* CLOCK_BOOTTIME */
223#endif /* HAVE_CLOCK_GETTIME */ 224#endif /* HAVE_CLOCK_GETTIME */
@@ -225,15 +226,15 @@ MHD_monotonic_sec_counter_init (void)
225 /* Darwin-specific monotonic clock */ 226 /* Darwin-specific monotonic clock */
226 /* Should be monotonic as clock_set_time function always unconditionally */ 227 /* Should be monotonic as clock_set_time function always unconditionally */
227 /* failed on latest kernels */ 228 /* failed on latest kernels */
228 if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self(), 229 if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self (),
229 SYSTEM_CLOCK, 230 SYSTEM_CLOCK,
230 &mono_clock_service)) && 231 &mono_clock_service)) &&
231 (KERN_SUCCESS == clock_get_time (mono_clock_service, 232 (KERN_SUCCESS == clock_get_time (mono_clock_service,
232 &cur_time)) ) 233 &cur_time)) )
233 { 234 {
234 mono_clock_start = cur_time.tv_sec; 235 mono_clock_start = cur_time.tv_sec;
235 mono_clock_source = _MHD_CLOCK_GET_TIME; 236 mono_clock_source = _MHD_CLOCK_GET_TIME;
236 } 237 }
237 else 238 else
238#endif /* HAVE_CLOCK_GET_TIME */ 239#endif /* HAVE_CLOCK_GET_TIME */
239#ifdef _WIN32 240#ifdef _WIN32
@@ -241,25 +242,25 @@ MHD_monotonic_sec_counter_init (void)
241 /* W32 Vista or later specific monotonic clock */ 242 /* W32 Vista or later specific monotonic clock */
242 /* Available since Vista, ~15ms accuracy */ 243 /* Available since Vista, ~15ms accuracy */
243 if (1) 244 if (1)
244 { 245 {
245 tick_start = GetTickCount64 (); 246 tick_start = GetTickCount64 ();
246 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64; 247 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64;
247 } 248 }
248 else 249 else
249#else /* _WIN32_WINNT < 0x0600 */ 250#else /* _WIN32_WINNT < 0x0600 */
250 /* W32 specific monotonic clock */ 251 /* W32 specific monotonic clock */
251 /* Available on Windows 2000 and later */ 252 /* Available on Windows 2000 and later */
252 if (1) 253 if (1)
253 { 254 {
254 LARGE_INTEGER freq; 255 LARGE_INTEGER freq;
255 LARGE_INTEGER perf_counter; 256 LARGE_INTEGER perf_counter;
256 257
257 QueryPerformanceFrequency (&freq); /* never fail on XP and later */ 258 QueryPerformanceFrequency (&freq); /* never fail on XP and later */
258 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ 259 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
259 perf_freq = freq.QuadPart; 260 perf_freq = freq.QuadPart;
260 perf_start = perf_counter.QuadPart; 261 perf_start = perf_counter.QuadPart;
261 mono_clock_source = _MHD_CLOCK_PERFCOUNTER; 262 mono_clock_source = _MHD_CLOCK_PERFCOUNTER;
262 } 263 }
263 else 264 else
264#endif /* _WIN32_WINNT < 0x0600 */ 265#endif /* _WIN32_WINNT < 0x0600 */
265#endif /* _WIN32 */ 266#endif /* _WIN32 */
@@ -269,11 +270,11 @@ MHD_monotonic_sec_counter_init (void)
269 /* Not preferred due to be potentially resource-hungry */ 270 /* Not preferred due to be potentially resource-hungry */
270 if (0 == clock_gettime (CLOCK_HIGHRES, 271 if (0 == clock_gettime (CLOCK_HIGHRES,
271 &ts)) 272 &ts))
272 { 273 {
273 mono_clock_id = CLOCK_HIGHRES; 274 mono_clock_id = CLOCK_HIGHRES;
274 mono_clock_start = ts.tv_sec; 275 mono_clock_start = ts.tv_sec;
275 mono_clock_source = _MHD_CLOCK_GETTIME; 276 mono_clock_source = _MHD_CLOCK_GETTIME;
276 } 277 }
277 else 278 else
278#endif /* CLOCK_HIGHRES */ 279#endif /* CLOCK_HIGHRES */
279#endif /* HAVE_CLOCK_GETTIME */ 280#endif /* HAVE_CLOCK_GETTIME */
@@ -281,26 +282,26 @@ MHD_monotonic_sec_counter_init (void)
281 /* HP-UX and Solaris monotonic clock */ 282 /* HP-UX and Solaris monotonic clock */
282 /* Not preferred due to be potentially resource-hungry */ 283 /* Not preferred due to be potentially resource-hungry */
283 if (1) 284 if (1)
284 { 285 {
285 hrtime_start = gethrtime (); 286 hrtime_start = gethrtime ();
286 mono_clock_source = _MHD_CLOCK_GETHRTIME; 287 mono_clock_source = _MHD_CLOCK_GETHRTIME;
287 } 288 }
288 else 289 else
289#endif /* HAVE_GETHRTIME */ 290#endif /* HAVE_GETHRTIME */
290 { 291 {
291 /* no suitable clock source was found */ 292 /* no suitable clock source was found */
292 mono_clock_source = _MHD_CLOCK_NO_SOURCE; 293 mono_clock_source = _MHD_CLOCK_NO_SOURCE;
293 } 294 }
294 295
295#ifdef HAVE_CLOCK_GET_TIME 296#ifdef HAVE_CLOCK_GET_TIME
296 if ( (_MHD_CLOCK_GET_TIME != mono_clock_source) && 297 if ( (_MHD_CLOCK_GET_TIME != mono_clock_source) &&
297 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) ) 298 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) )
298 { 299 {
299 /* clock service was initialised but clock_get_time failed */ 300 /* clock service was initialised but clock_get_time failed */
300 mach_port_deallocate (mach_task_self(), 301 mach_port_deallocate (mach_task_self (),
301 mono_clock_service); 302 mono_clock_service);
302 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 303 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
303 } 304 }
304#else 305#else
305 (void) mono_clock_source; /* avoid compiler warning */ 306 (void) mono_clock_source; /* avoid compiler warning */
306#endif /* HAVE_CLOCK_GET_TIME */ 307#endif /* HAVE_CLOCK_GET_TIME */
@@ -317,11 +318,11 @@ MHD_monotonic_sec_counter_finish (void)
317{ 318{
318#ifdef HAVE_CLOCK_GET_TIME 319#ifdef HAVE_CLOCK_GET_TIME
319 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 320 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
320 { 321 {
321 mach_port_deallocate (mach_task_self(), 322 mach_port_deallocate (mach_task_self (),
322 mono_clock_service); 323 mono_clock_service);
323 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 324 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
324 } 325 }
325#endif /* HAVE_CLOCK_GET_TIME */ 326#endif /* HAVE_CLOCK_GET_TIME */
326} 327}
327 328
@@ -340,37 +341,38 @@ MHD_monotonic_sec_counter (void)
340 struct timespec ts; 341 struct timespec ts;
341 342
342 if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) && 343 if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) &&
343 (0 == clock_gettime (mono_clock_id , 344 (0 == clock_gettime (mono_clock_id,
344 &ts)) ) 345 &ts)) )
345 return ts.tv_sec - mono_clock_start; 346 return ts.tv_sec - mono_clock_start;
346#endif /* HAVE_CLOCK_GETTIME */ 347#endif /* HAVE_CLOCK_GETTIME */
347#ifdef HAVE_CLOCK_GET_TIME 348#ifdef HAVE_CLOCK_GET_TIME
348 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 349 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
349 { 350 {
350 mach_timespec_t cur_time; 351 mach_timespec_t cur_time;
351 352
352 if (KERN_SUCCESS == clock_get_time(mono_clock_service, 353 if (KERN_SUCCESS == clock_get_time (mono_clock_service,
353 &cur_time)) 354 &cur_time))
354 return cur_time.tv_sec - mono_clock_start; 355 return cur_time.tv_sec - mono_clock_start;
355 } 356 }
356#endif /* HAVE_CLOCK_GET_TIME */ 357#endif /* HAVE_CLOCK_GET_TIME */
357#if defined(_WIN32) 358#if defined(_WIN32)
358#if _WIN32_WINNT >= 0x0600 359#if _WIN32_WINNT >= 0x0600
359 if (1) 360 if (1)
360 return (time_t)(((uint64_t)(GetTickCount64() - tick_start)) / 1000); 361 return (time_t) (((uint64_t) (GetTickCount64 () - tick_start)) / 1000);
361#else /* _WIN32_WINNT < 0x0600 */ 362#else /* _WIN32_WINNT < 0x0600 */
362 if (0 != perf_freq) 363 if (0 != perf_freq)
363 { 364 {
364 LARGE_INTEGER perf_counter; 365 LARGE_INTEGER perf_counter;
365 366
366 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ 367 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
367 return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq); 368 return (time_t) (((uint64_t) (perf_counter.QuadPart - perf_start))
368 } 369 / perf_freq);
370 }
369#endif /* _WIN32_WINNT < 0x0600 */ 371#endif /* _WIN32_WINNT < 0x0600 */
370#endif /* _WIN32 */ 372#endif /* _WIN32 */
371#ifdef HAVE_GETHRTIME 373#ifdef HAVE_GETHRTIME
372 if (1) 374 if (1)
373 return (time_t)(((uint64_t) (gethrtime () - hrtime_start)) / 1000000000); 375 return (time_t) (((uint64_t) (gethrtime () - hrtime_start)) / 1000000000);
374#endif /* HAVE_GETHRTIME */ 376#endif /* HAVE_GETHRTIME */
375 377
376 return time (NULL) - sys_clock_start; 378 return time (NULL) - sys_clock_start;
diff --git a/src/microhttpd/mhd_mono_clock.h b/src/microhttpd/mhd_mono_clock.h
index f4722af2..92485e00 100644
--- a/src/microhttpd/mhd_mono_clock.h
+++ b/src/microhttpd/mhd_mono_clock.h
@@ -37,14 +37,14 @@
37 * Initialise monotonic seconds counter. 37 * Initialise monotonic seconds counter.
38 */ 38 */
39void 39void
40MHD_monotonic_sec_counter_init(void); 40MHD_monotonic_sec_counter_init (void);
41 41
42 42
43/** 43/**
44 * Deinitialise monotonic seconds counter by freeing any allocated resources 44 * Deinitialise monotonic seconds counter by freeing any allocated resources
45 */ 45 */
46void 46void
47MHD_monotonic_sec_counter_finish(void); 47MHD_monotonic_sec_counter_finish (void);
48 48
49 49
50/** 50/**
@@ -55,6 +55,6 @@ MHD_monotonic_sec_counter_finish(void);
55 * @return number of seconds from some fixed moment 55 * @return number of seconds from some fixed moment
56 */ 56 */
57time_t 57time_t
58MHD_monotonic_sec_counter(void); 58MHD_monotonic_sec_counter (void);
59 59
60#endif /* MHD_MONO_CLOCK_H */ 60#endif /* MHD_MONO_CLOCK_H */
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index b3fb25da..e50be96e 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -55,68 +55,69 @@ pre_cork_setsockopt (struct MHD_Connection *connection,
55 55
56 /* If sk_cork_on is already what we pass in, return. */ 56 /* If sk_cork_on is already what we pass in, return. */
57 if (connection->sk_cork_on == want_cork) 57 if (connection->sk_cork_on == want_cork)
58 { 58 {
59 /* nothing to do, success! */ 59 /* nothing to do, success! */
60 return; 60 return;
61 } 61 }
62 if (! want_cork) 62 if (! want_cork)
63 return; /* nothing to do *pre* syscall! */ 63 return; /* nothing to do *pre* syscall! */
64 ret = MHD_socket_cork_ (connection->socket_fd, 64 ret = MHD_socket_cork_ (connection->socket_fd,
65 true); 65 true);
66 if (0 == ret) 66 if (0 == ret)
67 { 67 {
68 connection->sk_cork_on = true; 68 connection->sk_cork_on = true;
69 return; 69 return;
70 } 70 }
71 switch (errno) 71 switch (errno)
72 { 72 {
73 case ENOTSOCK: 73 case ENOTSOCK:
74 /* FIXME: Could be we are talking to a pipe, maybe remember this 74 /* FIXME: Could be we are talking to a pipe, maybe remember this
75 and avoid all setsockopt() in the future? */ 75 and avoid all setsockopt() in the future? */
76 break; 76 break;
77 case EBADF: 77 case EBADF:
78 /* FIXME: should we die hard here? */ 78 /* FIXME: should we die hard here? */
79 break; 79 break;
80 case EINVAL: 80 case EINVAL:
81 /* FIXME: optlen invalid, should at least log this, maybe die */ 81 /* FIXME: optlen invalid, should at least log this, maybe die */
82#ifdef HAVE_MESSAGES 82#ifdef HAVE_MESSAGES
83 MHD_DLOG (daemon, 83 MHD_DLOG (daemon,
84 _("optlen invalid: %s\n"), 84 _ ("optlen invalid: %s\n"),
85 MHD_socket_last_strerr_()); 85 MHD_socket_last_strerr_ ());
86#endif 86#endif
87 break; 87 break;
88 case EFAULT: 88 case EFAULT:
89 /* wopsie, should at leats log this, FIXME: maybe die */ 89 /* wopsie, should at leats log this, FIXME: maybe die */
90#ifdef HAVE_MESSAGES 90#ifdef HAVE_MESSAGES
91 MHD_DLOG (daemon, 91 MHD_DLOG (daemon,
92 _("The addresss pointed to by optval is not a valid part of the process address space: %s\n"), 92 _ (
93 MHD_socket_last_strerr_()); 93 "The addresss pointed to by optval is not a valid part of the process address space: %s\n"),
94 MHD_socket_last_strerr_ ());
94#endif 95#endif
95 break; 96 break;
96 case ENOPROTOOPT: 97 case ENOPROTOOPT:
97 /* optlen unknown, should at least log this */ 98 /* optlen unknown, should at least log this */
98#ifdef HAVE_MESSAGES 99#ifdef HAVE_MESSAGES
99 MHD_DLOG (daemon, 100 MHD_DLOG (daemon,
100 _("The option is unknown: %s\n"), 101 _ ("The option is unknown: %s\n"),
101 MHD_socket_last_strerr_()); 102 MHD_socket_last_strerr_ ());
102#endif 103#endif
103 break; 104 break;
104 default: 105 default:
105 /* any others? man page does not list more... */ 106 /* any others? man page does not list more... */
106 break; 107 break;
107 } 108 }
108#else 109#else
109 /* CORK/NOPUSH/MSG_MORE do not exist on this platform, 110 /* CORK/NOPUSH/MSG_MORE do not exist on this platform,
110 so we must toggle Naggle's algorithm on/off instead 111 so we must toggle Naggle's algorithm on/off instead
111 (otherwise we keep it always off) */ 112 (otherwise we keep it always off) */
112 if (connection->sk_cork_on == want_cork) 113 if (connection->sk_cork_on == want_cork)
113 { 114 {
114 /* nothing to do, success! */ 115 /* nothing to do, success! */
115 return; 116 return;
116 } 117 }
117 if ( (want_cork) && 118 if ( (want_cork) &&
118 (0 == MHD_socket_set_nodelay_ (connection->socket_fd, 119 (0 == MHD_socket_set_nodelay_ (connection->socket_fd,
119 false)) ) 120 false)) )
120 connection->sk_cork_on = true; 121 connection->sk_cork_on = true;
121#endif 122#endif
122} 123}
@@ -139,10 +140,10 @@ post_cork_setsockopt (struct MHD_Connection *connection,
139 140
140 /* If sk_cork_on is already what we pass in, return. */ 141 /* If sk_cork_on is already what we pass in, return. */
141 if (connection->sk_cork_on == want_cork) 142 if (connection->sk_cork_on == want_cork)
142 { 143 {
143 /* nothing to do, success! */ 144 /* nothing to do, success! */
144 return; 145 return;
145 } 146 }
146 if (want_cork) 147 if (want_cork)
147 return; /* nothing to do *post* syscall (in fact, we should never 148 return; /* nothing to do *post* syscall (in fact, we should never
148 get here, as sk_cork_on should have succeeded in the 149 get here, as sk_cork_on should have succeeded in the
@@ -150,59 +151,60 @@ post_cork_setsockopt (struct MHD_Connection *connection,
150 ret = MHD_socket_cork_ (connection->socket_fd, 151 ret = MHD_socket_cork_ (connection->socket_fd,
151 false); 152 false);
152 if (0 == ret) 153 if (0 == ret)
153 { 154 {
154 connection->sk_cork_on = false; 155 connection->sk_cork_on = false;
155 return; 156 return;
156 } 157 }
157 switch (errno) 158 switch (errno)
158 { 159 {
159 case ENOTSOCK: 160 case ENOTSOCK:
160 /* FIXME: Could be we are talking to a pipe, maybe remember this 161 /* FIXME: Could be we are talking to a pipe, maybe remember this
161 and avoid all setsockopt() in the future? */ 162 and avoid all setsockopt() in the future? */
162 break; 163 break;
163 case EBADF: 164 case EBADF:
164 /* FIXME: should we die hard here? */ 165 /* FIXME: should we die hard here? */
165 break; 166 break;
166 case EINVAL: 167 case EINVAL:
167 /* FIXME: optlen invalid, should at least log this, maybe die */ 168 /* FIXME: optlen invalid, should at least log this, maybe die */
168#ifdef HAVE_MESSAGES 169#ifdef HAVE_MESSAGES
169 MHD_DLOG (daemon, 170 MHD_DLOG (daemon,
170 _("optlen invalid: %s\n"), 171 _ ("optlen invalid: %s\n"),
171 MHD_socket_last_strerr_()); 172 MHD_socket_last_strerr_ ());
172#endif 173#endif
173 break; 174 break;
174 case EFAULT: 175 case EFAULT:
175 /* wopsie, should at leats log this, FIXME: maybe die */ 176 /* wopsie, should at leats log this, FIXME: maybe die */
176#ifdef HAVE_MESSAGES 177#ifdef HAVE_MESSAGES
177 MHD_DLOG (daemon, 178 MHD_DLOG (daemon,
178 _("The addresss pointed to by optval is not a valid part of the process address space: %s\n"), 179 _ (
179 MHD_socket_last_strerr_()); 180 "The addresss pointed to by optval is not a valid part of the process address space: %s\n"),
181 MHD_socket_last_strerr_ ());
180#endif 182#endif
181 break; 183 break;
182 case ENOPROTOOPT: 184 case ENOPROTOOPT:
183 /* optlen unknown, should at least log this */ 185 /* optlen unknown, should at least log this */
184#ifdef HAVE_MESSAGES 186#ifdef HAVE_MESSAGES
185 MHD_DLOG (daemon, 187 MHD_DLOG (daemon,
186 _("The option is unknown: %s\n"), 188 _ ("The option is unknown: %s\n"),
187 MHD_socket_last_strerr_()); 189 MHD_socket_last_strerr_ ());
188#endif 190#endif
189 break; 191 break;
190 default: 192 default:
191 /* any others? man page does not list more... */ 193 /* any others? man page does not list more... */
192 break; 194 break;
193 } 195 }
194#else 196#else
195 /* CORK/NOPUSH/MSG_MORE do not exist on this platform, 197 /* CORK/NOPUSH/MSG_MORE do not exist on this platform,
196 so we must toggle Naggle's algorithm on/off instead 198 so we must toggle Naggle's algorithm on/off instead
197 (otherwise we keep it always off) */ 199 (otherwise we keep it always off) */
198 if (connection->sk_cork_on == want_cork) 200 if (connection->sk_cork_on == want_cork)
199 { 201 {
200 /* nothing to do, success! */ 202 /* nothing to do, success! */
201 return; 203 return;
202 } 204 }
203 if ( (! want_cork) && 205 if ( (! want_cork) &&
204 (0 == MHD_socket_set_nodelay_ (connection->socket_fd, 206 (0 == MHD_socket_set_nodelay_ (connection->socket_fd,
205 true)) ) 207 true)) )
206 connection->sk_cork_on = false; 208 connection->sk_cork_on = false;
207#endif 209#endif
208} 210}
@@ -403,7 +405,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
403 { 405 {
404 struct msghdr msg; 406 struct msghdr msg;
405 407
406 memset(&msg, 0, sizeof(struct msghdr)); 408 memset (&msg, 0, sizeof(struct msghdr));
407 msg.msg_iov = vector; 409 msg.msg_iov = vector;
408 msg.msg_iovlen = 2; 410 msg.msg_iovlen = 2;
409 411
@@ -473,9 +475,9 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
473 uint64_t left; 475 uint64_t left;
474 uint64_t offsetu64; 476 uint64_t offsetu64;
475#ifndef HAVE_SENDFILE64 477#ifndef HAVE_SENDFILE64
476 const uint64_t max_off_t = (uint64_t)OFF_T_MAX; 478 const uint64_t max_off_t = (uint64_t) OFF_T_MAX;
477#else /* HAVE_SENDFILE64 */ 479#else /* HAVE_SENDFILE64 */
478 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX; 480 const uint64_t max_off_t = (uint64_t) OFF64_T_MAX;
479#endif /* HAVE_SENDFILE64 */ 481#endif /* HAVE_SENDFILE64 */
480#ifdef MHD_LINUX_SOLARIS_SENDFILE 482#ifdef MHD_LINUX_SOLARIS_SENDFILE
481#ifndef HAVE_SENDFILE64 483#ifndef HAVE_SENDFILE64
@@ -491,23 +493,26 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
491#ifdef HAVE_DARWIN_SENDFILE 493#ifdef HAVE_DARWIN_SENDFILE
492 off_t len; 494 off_t len;
493#endif /* HAVE_DARWIN_SENDFILE */ 495#endif /* HAVE_DARWIN_SENDFILE */
494 const bool used_thr_p_c = (0 != (connection->daemon->options & MHD_USE_THREAD_PER_CONNECTION)); 496 const bool used_thr_p_c = (0 != (connection->daemon->options
495 const size_t chunk_size = used_thr_p_c ? MHD_SENFILE_CHUNK_THR_P_C_ : MHD_SENFILE_CHUNK_; 497 & MHD_USE_THREAD_PER_CONNECTION));
498 const size_t chunk_size = used_thr_p_c ? MHD_SENFILE_CHUNK_THR_P_C_ :
499 MHD_SENFILE_CHUNK_;
496 size_t send_size = 0; 500 size_t send_size = 0;
497 mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender); 501 mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
498 502
499 pre_cork_setsockopt (connection, false); 503 pre_cork_setsockopt (connection, false);
500 504
501 offsetu64 = connection->response_write_position + connection->response->fd_off; 505 offsetu64 = connection->response_write_position
506 + connection->response->fd_off;
502 left = connection->response->total_size - connection->response_write_position; 507 left = connection->response->total_size - connection->response_write_position;
503 /* Do not allow system to stick sending on single fast connection: 508 /* Do not allow system to stick sending on single fast connection:
504 * use 128KiB chunks (2MiB for thread-per-connection). */ 509 * use 128KiB chunks (2MiB for thread-per-connection). */
505 send_size = (left > chunk_size) ? chunk_size : (size_t) left; 510 send_size = (left > chunk_size) ? chunk_size : (size_t) left;
506 if (max_off_t < offsetu64) 511 if (max_off_t < offsetu64)
507 { /* Retry to send with standard 'send()'. */ 512 { /* Retry to send with standard 'send()'. */
508 connection->resp_sender = MHD_resp_sender_std; 513 connection->resp_sender = MHD_resp_sender_std;
509 return MHD_ERR_AGAIN_; 514 return MHD_ERR_AGAIN_;
510 } 515 }
511#ifdef MHD_LINUX_SOLARIS_SENDFILE 516#ifdef MHD_LINUX_SOLARIS_SENDFILE
512#ifndef HAVE_SENDFILE64 517#ifndef HAVE_SENDFILE64
513 offset = (off_t) offsetu64; 518 offset = (off_t) offsetu64;
@@ -523,53 +528,53 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
523 send_size); 528 send_size);
524#endif /* HAVE_SENDFILE64 */ 529#endif /* HAVE_SENDFILE64 */
525 if (0 > ret) 530 if (0 > ret)
531 {
532 const int err = MHD_socket_get_error_ ();
533 if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
526 { 534 {
527 const int err = MHD_socket_get_error_();
528 if (MHD_SCKT_ERR_IS_EAGAIN_(err))
529 {
530#ifdef EPOLL_SUPPORT 535#ifdef EPOLL_SUPPORT
531 /* EAGAIN --- no longer write-ready */ 536 /* EAGAIN --- no longer write-ready */
532 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 537 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
533#endif /* EPOLL_SUPPORT */ 538#endif /* EPOLL_SUPPORT */
534 return MHD_ERR_AGAIN_; 539 return MHD_ERR_AGAIN_;
535 } 540 }
536 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 541 if (MHD_SCKT_ERR_IS_EINTR_ (err))
537 return MHD_ERR_AGAIN_; 542 return MHD_ERR_AGAIN_;
538#ifdef HAVE_LINUX_SENDFILE 543#ifdef HAVE_LINUX_SENDFILE
539 if (MHD_SCKT_ERR_IS_(err, 544 if (MHD_SCKT_ERR_IS_ (err,
540 MHD_SCKT_EBADF_)) 545 MHD_SCKT_EBADF_))
541 return MHD_ERR_BADF_; 546 return MHD_ERR_BADF_;
542 /* sendfile() failed with EINVAL if mmap()-like operations are not 547 /* sendfile() failed with EINVAL if mmap()-like operations are not
543 supported for FD or other 'unusual' errors occurred, so we should try 548 supported for FD or other 'unusual' errors occurred, so we should try
544 to fall back to 'SEND'; see also this thread for info on 549 to fall back to 'SEND'; see also this thread for info on
545 odd libc/Linux behavior with sendfile: 550 odd libc/Linux behavior with sendfile:
546 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ 551 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
552 connection->resp_sender = MHD_resp_sender_std;
553 return MHD_ERR_AGAIN_;
554#else /* HAVE_SOLARIS_SENDFILE */
555 if ( (EAFNOSUPPORT == err) ||
556 (EINVAL == err) ||
557 (EOPNOTSUPP == err) )
558 { /* Retry with standard file reader. */
547 connection->resp_sender = MHD_resp_sender_std; 559 connection->resp_sender = MHD_resp_sender_std;
548 return MHD_ERR_AGAIN_; 560 return MHD_ERR_AGAIN_;
549#else /* HAVE_SOLARIS_SENDFILE */
550 if ( (EAFNOSUPPORT == err) ||
551 (EINVAL == err) ||
552 (EOPNOTSUPP == err) )
553 { /* Retry with standard file reader. */
554 connection->resp_sender = MHD_resp_sender_std;
555 return MHD_ERR_AGAIN_;
556 }
557 if ( (ENOTCONN == err) ||
558 (EPIPE == err) )
559 {
560 return MHD_ERR_CONNRESET_;
561 }
562 return MHD_ERR_BADF_; /* Fail hard */
563#endif /* HAVE_SOLARIS_SENDFILE */
564 } 561 }
562 if ( (ENOTCONN == err) ||
563 (EPIPE == err) )
564 {
565 return MHD_ERR_CONNRESET_;
566 }
567 return MHD_ERR_BADF_; /* Fail hard */
568#endif /* HAVE_SOLARIS_SENDFILE */
569 }
565#ifdef EPOLL_SUPPORT 570#ifdef EPOLL_SUPPORT
566 else if (send_size > (size_t)ret) 571 else if (send_size > (size_t) ret)
567 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 572 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
568#endif /* EPOLL_SUPPORT */ 573#endif /* EPOLL_SUPPORT */
569#elif defined(HAVE_FREEBSD_SENDFILE) 574#elif defined(HAVE_FREEBSD_SENDFILE)
570#ifdef SF_FLAGS 575#ifdef SF_FLAGS
571 flags = used_thr_p_c ? 576 flags = used_thr_p_c ?
572 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_; 577 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
573#endif /* SF_FLAGS */ 578#endif /* SF_FLAGS */
574 if (0 != sendfile (file_fd, 579 if (0 != sendfile (file_fd,
575 connection->socket_fd, 580 connection->socket_fd,
@@ -578,63 +583,63 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
578 NULL, 583 NULL,
579 &sent_bytes, 584 &sent_bytes,
580 flags)) 585 flags))
586 {
587 const int err = MHD_socket_get_error_ ();
588 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) ||
589 MHD_SCKT_ERR_IS_EINTR_ (err) ||
590 (EBUSY == err) )
581 { 591 {
582 const int err = MHD_socket_get_error_(); 592 mhd_assert (SSIZE_MAX >= sent_bytes);
583 if (MHD_SCKT_ERR_IS_EAGAIN_(err) || 593 if (0 != sent_bytes)
584 MHD_SCKT_ERR_IS_EINTR_(err) || 594 return (ssize_t) sent_bytes;
585 EBUSY == err) 595
586 {
587 mhd_assert (SSIZE_MAX >= sent_bytes);
588 if (0 != sent_bytes)
589 return (ssize_t)sent_bytes;
590
591 return MHD_ERR_AGAIN_;
592 }
593 /* Some unrecoverable error. Possibly file FD is not suitable
594 * for sendfile(). Retry with standard send(). */
595 connection->resp_sender = MHD_resp_sender_std;
596 return MHD_ERR_AGAIN_; 596 return MHD_ERR_AGAIN_;
597 } 597 }
598 /* Some unrecoverable error. Possibly file FD is not suitable
599 * for sendfile(). Retry with standard send(). */
600 connection->resp_sender = MHD_resp_sender_std;
601 return MHD_ERR_AGAIN_;
602 }
598 mhd_assert (0 < sent_bytes); 603 mhd_assert (0 < sent_bytes);
599 mhd_assert (SSIZE_MAX >= sent_bytes); 604 mhd_assert (SSIZE_MAX >= sent_bytes);
600 ret = (ssize_t)sent_bytes; 605 ret = (ssize_t) sent_bytes;
601#elif defined(HAVE_DARWIN_SENDFILE) 606#elif defined(HAVE_DARWIN_SENDFILE)
602 len = (off_t)send_size; /* chunk always fit */ 607 len = (off_t) send_size; /* chunk always fit */
603 if (0 != sendfile (file_fd, 608 if (0 != sendfile (file_fd,
604 connection->socket_fd, 609 connection->socket_fd,
605 (off_t) offsetu64, 610 (off_t) offsetu64,
606 &len, 611 &len,
607 NULL, 612 NULL,
608 0)) 613 0))
614 {
615 const int err = MHD_socket_get_error_ ();
616 if (MHD_SCKT_ERR_IS_EAGAIN_ (err) ||
617 MHD_SCKT_ERR_IS_EINTR_ (err))
609 { 618 {
610 const int err = MHD_socket_get_error_(); 619 mhd_assert (0 <= len);
611 if (MHD_SCKT_ERR_IS_EAGAIN_(err) || 620 mhd_assert (SSIZE_MAX >= len);
612 MHD_SCKT_ERR_IS_EINTR_(err)) 621 mhd_assert (send_size >= (size_t) len);
613 { 622 if (0 != len)
614 mhd_assert (0 <= len); 623 return (ssize_t) len;
615 mhd_assert (SSIZE_MAX >= len); 624
616 mhd_assert (send_size >= (size_t)len); 625 return MHD_ERR_AGAIN_;
617 if (0 != len) 626 }
618 return (ssize_t)len; 627 if ((ENOTCONN == err) ||
619 628 (EPIPE == err) )
620 return MHD_ERR_AGAIN_; 629 return MHD_ERR_CONNRESET_;
621 } 630 if ((ENOTSUP == err) ||
622 if (ENOTCONN == err || 631 (EOPNOTSUPP == err) )
623 EPIPE == err) 632 { /* This file FD is not suitable for sendfile().
624 return MHD_ERR_CONNRESET_;
625 if (ENOTSUP == err ||
626 EOPNOTSUPP == err)
627 { /* This file FD is not suitable for sendfile().
628 * Retry with standard send(). */ 633 * Retry with standard send(). */
629 connection->resp_sender = MHD_resp_sender_std; 634 connection->resp_sender = MHD_resp_sender_std;
630 return MHD_ERR_AGAIN_; 635 return MHD_ERR_AGAIN_;
631 }
632 return MHD_ERR_BADF_; /* Return hard error. */
633 } 636 }
637 return MHD_ERR_BADF_; /* Return hard error. */
638 }
634 mhd_assert (0 <= len); 639 mhd_assert (0 <= len);
635 mhd_assert (SSIZE_MAX >= len); 640 mhd_assert (SSIZE_MAX >= len);
636 mhd_assert (send_size >= (size_t)len); 641 mhd_assert (send_size >= (size_t) len);
637 ret = (ssize_t)len; 642 ret = (ssize_t) len;
638#endif /* HAVE_FREEBSD_SENDFILE */ 643#endif /* HAVE_FREEBSD_SENDFILE */
639 644
640 /* Make sure we send the data without delay ONLY if we 645 /* Make sure we send the data without delay ONLY if we
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h
index a766c8c0..3c484f79 100644
--- a/src/microhttpd/mhd_send.h
+++ b/src/microhttpd/mhd_send.h
@@ -56,9 +56,9 @@
56 */ 56 */
57enum MHD_SendSocketOptions 57enum MHD_SendSocketOptions
58{ 58{
59 /** 59 /**
60 * definitely no corking (use NODELAY, or explicitly disable cork) 60 * definitely no corking (use NODELAY, or explicitly disable cork)
61 */ 61 */
62 MHD_SSO_NO_CORK = 0, 62 MHD_SSO_NO_CORK = 0,
63 /** 63 /**
64 * should enable corking (use MSG_MORE, or explicitly enable cork) 64 * should enable corking (use MSG_MORE, or explicitly enable cork)
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index 08b01c20..3099357b 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -37,8 +37,8 @@
37#include <errno.h> 37#include <errno.h>
38#include <stdbool.h> 38#include <stdbool.h>
39 39
40#if !defined(MHD_POSIX_SOCKETS) && !defined(MHD_WINSOCK_SOCKETS) 40#if ! defined(MHD_POSIX_SOCKETS) && ! defined(MHD_WINSOCK_SOCKETS)
41# if !defined(_WIN32) || defined(__CYGWIN__) 41# if ! defined(_WIN32) || defined(__CYGWIN__)
42# define MHD_POSIX_SOCKETS 1 42# define MHD_POSIX_SOCKETS 1
43# else /* defined(_WIN32) && !defined(__CYGWIN__) */ 43# else /* defined(_WIN32) && !defined(__CYGWIN__) */
44# define MHD_WINSOCK_SOCKETS 1 44# define MHD_WINSOCK_SOCKETS 1
@@ -93,7 +93,7 @@
93# include <sys/epoll.h> 93# include <sys/epoll.h>
94# endif 94# endif
95# ifdef HAVE_NETINET_TCP_H 95# ifdef HAVE_NETINET_TCP_H
96 /* for TCP_FASTOPEN and TCP_CORK */ 96/* for TCP_FASTOPEN and TCP_CORK */
97# include <netinet/tcp.h> 97# include <netinet/tcp.h>
98# endif 98# endif
99# ifdef HAVE_STRING_H 99# ifdef HAVE_STRING_H
@@ -112,10 +112,10 @@
112#endif 112#endif
113 113
114#include <stddef.h> 114#include <stddef.h>
115#if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) 115#if defined(_MSC_FULL_VER) && ! defined (_SSIZE_T_DEFINED)
116# include <stdint.h> 116# include <stdint.h>
117# define _SSIZE_T_DEFINED 117# define _SSIZE_T_DEFINED
118 typedef intptr_t ssize_t; 118typedef intptr_t ssize_t;
119#endif /* !_SSIZE_T_DEFINED */ 119#endif /* !_SSIZE_T_DEFINED */
120 120
121#include "mhd_limits.h" 121#include "mhd_limits.h"
@@ -124,7 +124,7 @@
124# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE 124# define _MHD_SYS_DEFAULT_FD_SETSIZE FD_SETSIZE
125#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 125#else /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
126# include "sysfdsetsize.h" 126# include "sysfdsetsize.h"
127# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value() 127# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value ()
128#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 128#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
129 129
130#ifndef MHD_PANIC 130#ifndef MHD_PANIC
@@ -132,8 +132,9 @@
132# include <stdlib.h> 132# include <stdlib.h>
133/* Simple implementation of MHD_PANIC, to be used outside lib */ 133/* Simple implementation of MHD_PANIC, to be used outside lib */
134# define MHD_PANIC(msg) do { fprintf (stderr, \ 134# define MHD_PANIC(msg) do { fprintf (stderr, \
135 "Abnormal termination at %d line in file %s: %s\n", \ 135 "Abnormal termination at %d line in file %s: %s\n", \
136 (int)__LINE__, __FILE__, msg); abort();} while(0) 136 (int) __LINE__, __FILE__, msg); abort (); \
137} while (0)
137#endif /* ! MHD_PANIC */ 138#endif /* ! MHD_PANIC */
138 139
139#ifndef MHD_SOCKET_DEFINED 140#ifndef MHD_SOCKET_DEFINED
@@ -141,10 +142,10 @@
141 * MHD_socket is type for socket FDs 142 * MHD_socket is type for socket FDs
142 */ 143 */
143# if defined(MHD_POSIX_SOCKETS) 144# if defined(MHD_POSIX_SOCKETS)
144 typedef int MHD_socket; 145typedef int MHD_socket;
145# define MHD_INVALID_SOCKET (-1) 146# define MHD_INVALID_SOCKET (-1)
146# elif defined(MHD_WINSOCK_SOCKETS) 147# elif defined(MHD_WINSOCK_SOCKETS)
147 typedef SOCKET MHD_socket; 148typedef SOCKET MHD_socket;
148# define MHD_INVALID_SOCKET (INVALID_SOCKET) 149# define MHD_INVALID_SOCKET (INVALID_SOCKET)
149# endif /* MHD_WINSOCK_SOCKETS */ 150# endif /* MHD_WINSOCK_SOCKETS */
150 151
@@ -175,17 +176,18 @@
175# define MAYBE_MSG_NOSIGNAL 0 176# define MAYBE_MSG_NOSIGNAL 0
176#endif /* ! MSG_NOSIGNAL */ 177#endif /* ! MSG_NOSIGNAL */
177 178
178#if !defined(SHUT_WR) && defined(SD_SEND) 179#if ! defined(SHUT_WR) && defined(SD_SEND)
179# define SHUT_WR SD_SEND 180# define SHUT_WR SD_SEND
180#endif 181#endif
181#if !defined(SHUT_RD) && defined(SD_RECEIVE) 182#if ! defined(SHUT_RD) && defined(SD_RECEIVE)
182# define SHUT_RD SD_RECEIVE 183# define SHUT_RD SD_RECEIVE
183#endif 184#endif
184#if !defined(SHUT_RDWR) && defined(SD_BOTH) 185#if ! defined(SHUT_RDWR) && defined(SD_BOTH)
185# define SHUT_RDWR SD_BOTH 186# define SHUT_RDWR SD_BOTH
186#endif 187#endif
187 188
188#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE)) 189#if HAVE_ACCEPT4 + 0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || \
190 defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE))
189# define USE_ACCEPT4 1 191# define USE_ACCEPT4 1
190#endif 192#endif
191 193
@@ -218,25 +220,25 @@
218 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt() 220 * MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt()
219 */ 221 */
220#ifdef MHD_POSIX_SOCKETS 222#ifdef MHD_POSIX_SOCKETS
221 typedef int MHD_SCKT_OPT_BOOL_; 223typedef int MHD_SCKT_OPT_BOOL_;
222#else /* MHD_WINSOCK_SOCKETS */ 224#else /* MHD_WINSOCK_SOCKETS */
223 typedef BOOL MHD_SCKT_OPT_BOOL_; 225typedef BOOL MHD_SCKT_OPT_BOOL_;
224#endif /* MHD_WINSOCK_SOCKETS */ 226#endif /* MHD_WINSOCK_SOCKETS */
225 227
226/** 228/**
227 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv 229 * MHD_SCKT_SEND_SIZE_ is type used to specify size for send and recv
228 * functions 230 * functions
229 */ 231 */
230#if !defined(MHD_WINSOCK_SOCKETS) 232#if ! defined(MHD_WINSOCK_SOCKETS)
231 typedef size_t MHD_SCKT_SEND_SIZE_; 233typedef size_t MHD_SCKT_SEND_SIZE_;
232#else 234#else
233 typedef int MHD_SCKT_SEND_SIZE_; 235typedef int MHD_SCKT_SEND_SIZE_;
234#endif 236#endif
235 237
236/** 238/**
237 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value. 239 * MHD_SCKT_SEND_MAX_SIZE_ is maximum send()/recv() size value.
238 */ 240 */
239#if !defined(MHD_WINSOCK_SOCKETS) 241#if ! defined(MHD_WINSOCK_SOCKETS)
240# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX 242# define MHD_SCKT_SEND_MAX_SIZE_ SSIZE_MAX
241#else 243#else
242# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX 244# define MHD_SCKT_SEND_MAX_SIZE_ INT_MAX
@@ -252,10 +254,10 @@
252 * counted as success, only EBADF counts as an error!), 254 * counted as success, only EBADF counts as an error!),
253 * boolean false otherwise. 255 * boolean false otherwise.
254 */ 256 */
255#if !defined(MHD_WINSOCK_SOCKETS) 257#if ! defined(MHD_WINSOCK_SOCKETS)
256# define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno)) 258# define MHD_socket_close_(fd) ((0 == close ((fd))) || (EBADF != errno))
257#else 259#else
258# define MHD_socket_close_(fd) (0 == closesocket((fd))) 260# define MHD_socket_close_(fd) (0 == closesocket ((fd)))
259#endif 261#endif
260 262
261/** 263/**
@@ -264,9 +266,9 @@
264 * @param fd socket to close 266 * @param fd socket to close
265 */ 267 */
266#define MHD_socket_close_chk_(fd) do { \ 268#define MHD_socket_close_chk_(fd) do { \
267 if (!MHD_socket_close_(fd)) \ 269 if (! MHD_socket_close_ (fd)) \
268 MHD_PANIC(_("Close socket failed.\n")); \ 270 MHD_PANIC (_ ("Close socket failed.\n")); \
269 } while(0) 271} while (0)
270 272
271 273
272/** 274/**
@@ -277,7 +279,8 @@
277 * @return ssize_t type value 279 * @return ssize_t type value
278 */ 280 */
279#define MHD_send_(s,b,l) \ 281#define MHD_send_(s,b,l) \
280 ((ssize_t)send((s),(const void*)(b),(MHD_SCKT_SEND_SIZE_)(l), MAYBE_MSG_NOSIGNAL)) 282 ((ssize_t) send ((s),(const void*) (b),(MHD_SCKT_SEND_SIZE_) (l), \
283 MAYBE_MSG_NOSIGNAL))
281 284
282 285
283/** 286/**
@@ -288,7 +291,7 @@
288 * @return ssize_t type value 291 * @return ssize_t type value
289 */ 292 */
290#define MHD_recv_(s,b,l) \ 293#define MHD_recv_(s,b,l) \
291 ((ssize_t)recv((s),(void*)(b),(MHD_SCKT_SEND_SIZE_)(l), 0)) 294 ((ssize_t) recv ((s),(void*) (b),(MHD_SCKT_SEND_SIZE_) (l), 0))
292 295
293 296
294/** 297/**
@@ -301,11 +304,18 @@
301 * boolean false otherwise. 304 * boolean false otherwise.
302 */ 305 */
303#if defined(MHD_POSIX_SOCKETS) 306#if defined(MHD_POSIX_SOCKETS)
304# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < ((MHD_socket)setsize)) 307# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < \
308 ((MHD_socket) \
309 setsize))
305#elif defined(MHD_WINSOCK_SOCKETS) 310#elif defined(MHD_WINSOCK_SOCKETS)
306# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*)(pset)==(void*)0) || \ 311# define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( ((void*) (pset)== \
307 (((fd_set*)(pset))->fd_count < ((unsigned)setsize)) || \ 312 (void*) 0) || \
308 (FD_ISSET((fd),(pset))) ) 313 (((fd_set*) (pset)) \
314 ->fd_count < \
315 ((unsigned) \
316 setsize)) || \
317 (FD_ISSET ((fd), \
318 (pset))) )
309#endif 319#endif
310 320
311/** 321/**
@@ -316,7 +326,9 @@
316 * @return boolean true if FD can be added to fd_set, 326 * @return boolean true if FD can be added to fd_set,
317 * boolean false otherwise. 327 * boolean false otherwise.
318 */ 328 */
319#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE) 329#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) MHD_SCKT_FD_FITS_FDSET_SETSIZE_ ((fd), \
330 (pset), \
331 FD_SETSIZE)
320 332
321/** 333/**
322 * Add FD to fd_set with specified FD_SETSIZE. 334 * Add FD to fd_set with specified FD_SETSIZE.
@@ -327,34 +339,35 @@
327 * system definition of FD_SET() is not used. 339 * system definition of FD_SET() is not used.
328 */ 340 */
329#if defined(MHD_POSIX_SOCKETS) 341#if defined(MHD_POSIX_SOCKETS)
330# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET((fd),(pset)) 342# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) FD_SET ((fd), \
343 (pset))
331#elif defined(MHD_WINSOCK_SOCKETS) 344#elif defined(MHD_WINSOCK_SOCKETS)
332# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \ 345# define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) \
333 do { \ 346 do { \
334 u_int _i_ = 0; \ 347 u_int _i_ = 0; \
335 fd_set* const _s_ = (fd_set*)(pset); \ 348 fd_set*const _s_ = (fd_set*) (pset); \
336 while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) {++_i_;} \ 349 while ((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array [_i_])) {++_i_;} \
337 if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = (fd);} \ 350 if ((_i_ == _s_->fd_count)) {_s_->fd_array [_s_->fd_count ++] = (fd);} \
338 } while(0) 351 } while (0)
339#endif 352#endif
340 353
341 /* MHD_SYS_select_ is wrapper macro for system select() function */ 354/* MHD_SYS_select_ is wrapper macro for system select() function */
342#if !defined(MHD_WINSOCK_SOCKETS) 355#if ! defined(MHD_WINSOCK_SOCKETS)
343# define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) 356# define MHD_SYS_select_(n,r,w,e,t) select ((n),(r),(w),(e),(t))
344#else 357#else
345# define MHD_SYS_select_(n,r,w,e,t) \ 358# define MHD_SYS_select_(n,r,w,e,t) \
346( ( (((void*)(r) == (void*)0) || ((fd_set*)(r))->fd_count == 0) && \ 359 ( ( (((void*) (r) == (void*) 0) || ((fd_set*) (r))->fd_count == 0) && \
347 (((void*)(w) == (void*)0) || ((fd_set*)(w))->fd_count == 0) && \ 360 (((void*) (w) == (void*) 0) || ((fd_set*) (w))->fd_count == 0) && \
348 (((void*)(e) == (void*)0) || ((fd_set*)(e))->fd_count == 0) ) ? \ 361 (((void*) (e) == (void*) 0) || ((fd_set*) (e))->fd_count == 0) ) ? \
349 ( ((void*)(t) == (void*)0) ? 0 : \ 362 ( ((void*) (t) == (void*) 0) ? 0 : \
350 (Sleep(((struct timeval*)(t))->tv_sec * 1000 + \ 363 (Sleep (((struct timeval*) (t))->tv_sec * 1000 \
351 ((struct timeval*)(t))->tv_usec / 1000), 0) ) : \ 364 + ((struct timeval*) (t))->tv_usec / 1000), 0) ) : \
352 (select((int)0,(r),(w),(e),(t))) ) 365 (select ((int) 0,(r),(w),(e),(t))) )
353#endif 366#endif
354 367
355#if defined(HAVE_POLL) 368#if defined(HAVE_POLL)
356/* MHD_sys_poll_ is wrapper macro for system poll() function */ 369/* MHD_sys_poll_ is wrapper macro for system poll() function */
357# if !defined(MHD_WINSOCK_SOCKETS) 370# if ! defined(MHD_WINSOCK_SOCKETS)
358# define MHD_sys_poll_ poll 371# define MHD_sys_poll_ poll
359# else /* MHD_WINSOCK_SOCKETS */ 372# else /* MHD_WINSOCK_SOCKETS */
360# define MHD_sys_poll_ WSAPoll 373# define MHD_sys_poll_ WSAPoll
@@ -383,16 +396,19 @@
383# elif defined(__linux__) 396# elif defined(__linux__)
384# define MHD_POLL_EVENTS_ERR_DISC POLLPRI 397# define MHD_POLL_EVENTS_ERR_DISC POLLPRI
385# else /* ! __linux__ */ 398# else /* ! __linux__ */
386# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO) 399# define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO \
400 | MHD_POLLRDBAND_OR_ZERO)
387# endif /* ! __linux__ */ 401# endif /* ! __linux__ */
388/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect. 402/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect.
389 * Note: Out-of-band data is treated as error. */ 403 * Note: Out-of-band data is treated as error. */
390# define MHD_POLL_REVENTS_ERR_DISC \ 404# define MHD_POLL_REVENTS_ERR_DISC \
391 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR | POLLHUP) 405 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
406 | POLLERR | POLLHUP)
392/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors. 407/* MHD_POLL_REVENTS_ERRROR is 'revents' mask for errors.
393 * Note: Out-of-band data is treated as error. */ 408 * Note: Out-of-band data is treated as error. */
394# define MHD_POLL_REVENTS_ERRROR \ 409# define MHD_POLL_REVENTS_ERRROR \
395 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | POLLERR) 410 (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO \
411 | POLLERR)
396#endif /* HAVE_POLL */ 412#endif /* HAVE_POLL */
397 413
398#define MHD_SCKT_MISSING_ERR_CODE_ 31450 414#define MHD_SCKT_MISSING_ERR_CODE_ 31450
@@ -526,30 +542,30 @@
526#if defined(MHD_POSIX_SOCKETS) 542#if defined(MHD_POSIX_SOCKETS)
527# define MHD_socket_get_error_() (errno) 543# define MHD_socket_get_error_() (errno)
528#elif defined(MHD_WINSOCK_SOCKETS) 544#elif defined(MHD_WINSOCK_SOCKETS)
529# define MHD_socket_get_error_() WSAGetLastError() 545# define MHD_socket_get_error_() WSAGetLastError ()
530#endif 546#endif
531 547
532#ifdef MHD_WINSOCK_SOCKETS 548#ifdef MHD_WINSOCK_SOCKETS
533 /* POSIX-W32 sockets compatibility functions */ 549/* POSIX-W32 sockets compatibility functions */
534 550
535/** 551/**
536 * Return pointer to string description of specified WinSock error 552 * Return pointer to string description of specified WinSock error
537 * @param err the WinSock error code. 553 * @param err the WinSock error code.
538 * @return pointer to string description of specified WinSock error. 554 * @return pointer to string description of specified WinSock error.
539 */ 555 */
540 const char* MHD_W32_strerror_winsock_(int err); 556const char*MHD_W32_strerror_winsock_ (int err);
541#endif /* MHD_WINSOCK_SOCKETS */ 557#endif /* MHD_WINSOCK_SOCKETS */
542 558
543/* MHD_socket_last_strerr_ is description string of specified socket error code */ 559/* MHD_socket_last_strerr_ is description string of specified socket error code */
544#if defined(MHD_POSIX_SOCKETS) 560#if defined(MHD_POSIX_SOCKETS)
545# define MHD_socket_strerr_(err) strerror((err)) 561# define MHD_socket_strerr_(err) strerror ((err))
546#elif defined(MHD_WINSOCK_SOCKETS) 562#elif defined(MHD_WINSOCK_SOCKETS)
547# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err)) 563# define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_ ((err))
548#endif 564#endif
549 565
550/* MHD_socket_last_strerr_ is description string of last errno (non-W32) / 566/* MHD_socket_last_strerr_ is description string of last errno (non-W32) /
551 * description string of last socket error (W32) */ 567 * description string of last socket error (W32) */
552#define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_()) 568#define MHD_socket_last_strerr_() MHD_socket_strerr_ (MHD_socket_get_error_ ())
553 569
554/** 570/**
555 * MHD_socket_fset_error_() set socket system native error code. 571 * MHD_socket_fset_error_() set socket system native error code.
@@ -557,7 +573,7 @@
557#if defined(MHD_POSIX_SOCKETS) 573#if defined(MHD_POSIX_SOCKETS)
558# define MHD_socket_fset_error_(err) (errno = (err)) 574# define MHD_socket_fset_error_(err) (errno = (err))
559#elif defined(MHD_WINSOCK_SOCKETS) 575#elif defined(MHD_WINSOCK_SOCKETS)
560# define MHD_socket_fset_error_(err) (WSASetLastError((err))) 576# define MHD_socket_fset_error_(err) (WSASetLastError ((err)))
561#endif 577#endif
562 578
563/** 579/**
@@ -569,7 +585,8 @@
569 * and error was not set. 585 * and error was not set.
570 */ 586 */
571#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ 587#define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \
572 (MHD_socket_fset_error_((err)), !0) : 0 ) 588 (MHD_socket_fset_error_ ((err)), ! 0) : \
589 0)
573 590
574/** 591/**
575 * MHD_socket_set_error_() set socket system native error code to 592 * MHD_socket_set_error_() set socket system native error code to
@@ -582,7 +599,8 @@
582 (errno = ENOSYS) : (errno = (err)) ) 599 (errno = ENOSYS) : (errno = (err)) )
583# elif defined(EOPNOTSUPP) 600# elif defined(EOPNOTSUPP)
584# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 601# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
585 (errno = EOPNOTSUPP) : (errno = (err)) ) 602 (errno = EOPNOTSUPP) : (errno = \
603 (err)) )
586# elif defined (EFAULT) 604# elif defined (EFAULT)
587# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 605# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
588 (errno = EFAULT) : (errno = (err)) ) 606 (errno = EFAULT) : (errno = (err)) )
@@ -590,13 +608,14 @@
590# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 608# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
591 (errno = EINVAL) : (errno = (err)) ) 609 (errno = EINVAL) : (errno = (err)) )
592# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ 610# else /* !EOPNOTSUPP && !EFAULT && !EINVAL */
593# warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. 611# warning \
612 No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system.
594# define MHD_socket_set_error_(err) (errno = (err)) 613# define MHD_socket_set_error_(err) (errno = (err))
595# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ 614# endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/
596#elif defined(MHD_WINSOCK_SOCKETS) 615#elif defined(MHD_WINSOCK_SOCKETS)
597# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ 616# define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \
598 (WSASetLastError((WSAEOPNOTSUPP))) : \ 617 (WSASetLastError ((WSAEOPNOTSUPP))) : \
599 (WSASetLastError((err))) ) 618 (WSASetLastError ((err))) )
600#endif 619#endif
601 620
602/** 621/**
@@ -620,7 +639,8 @@
620 * last socket error equals to MHD_SCKT_E*_ @a code; 639 * last socket error equals to MHD_SCKT_E*_ @a code;
621 * boolean false otherwise 640 * boolean false otherwise
622 */ 641 */
623#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code)) 642#define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_ (MHD_socket_get_error_ (), \
643 (code))
624 644
625/* Specific error code checks */ 645/* Specific error code checks */
626 646
@@ -630,7 +650,7 @@
630 * @return boolean true if @a err is equal to sockets' EINTR code; 650 * @return boolean true if @a err is equal to sockets' EINTR code;
631 * boolean false otherwise. 651 * boolean false otherwise.
632 */ 652 */
633#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_) 653#define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EINTR_)
634 654
635/** 655/**
636 * Check whether given socket error is equal to system's 656 * Check whether given socket error is equal to system's
@@ -639,10 +659,12 @@
639 * boolean false otherwise. 659 * boolean false otherwise.
640 */ 660 */
641#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ 661#if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_
642# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) 662# define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_ ((err),MHD_SCKT_EAGAIN_)
643#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 663#else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
644# define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \ 664# define MHD_SCKT_ERR_IS_EAGAIN_(err) (MHD_SCKT_ERR_IS_ ((err), \
645 MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) ) 665 MHD_SCKT_EAGAIN_) || \
666 MHD_SCKT_ERR_IS_ ((err), \
667 MHD_SCKT_EWOULDBLOCK_) )
646#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ 668#endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */
647 669
648/** 670/**
@@ -650,10 +672,17 @@
650 * @return boolean true if @a err is any kind of "low resource" error, 672 * @return boolean true if @a err is any kind of "low resource" error,
651 * boolean false otherwise. 673 * boolean false otherwise.
652 */ 674 */
653#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \ 675#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) (MHD_SCKT_ERR_IS_ ((err), \
654 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \ 676 MHD_SCKT_EMFILE_) \
655 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \ 677 || \
656 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) ) 678 MHD_SCKT_ERR_IS_ ((err), \
679 MHD_SCKT_ENFILE_) \
680 || \
681 MHD_SCKT_ERR_IS_ ((err), \
682 MHD_SCKT_ENOMEM_) \
683 || \
684 MHD_SCKT_ERR_IS_ ((err), \
685 MHD_SCKT_ENOBUFS_) )
657 686
658/** 687/**
659 * Check whether is given socket error is type of "incoming connection 688 * Check whether is given socket error is type of "incoming connection
@@ -662,9 +691,11 @@
662 * boolean false otherwise. 691 * boolean false otherwise.
663 */ 692 */
664#if defined(MHD_POSIX_SOCKETS) 693#if defined(MHD_POSIX_SOCKETS)
665# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_) 694# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
695 MHD_SCKT_ECONNABORTED_)
666#elif defined(MHD_WINSOCK_SOCKETS) 696#elif defined(MHD_WINSOCK_SOCKETS)
667# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) 697# define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_ ((err), \
698 MHD_SCKT_ECONNRESET_)
668#endif 699#endif
669 700
670/** 701/**
@@ -673,8 +704,11 @@
673 * @return boolean true is @a err match described socket error code, 704 * @return boolean true is @a err match described socket error code,
674 * boolean false otherwise. 705 * boolean false otherwise.
675 */ 706 */
676#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \ 707#define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) (MHD_SCKT_ERR_IS_ ((err), \
677 MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)) 708 MHD_SCKT_ECONNRESET_) \
709 || \
710 MHD_SCKT_ERR_IS_ ((err), \
711 MHD_SCKT_ECONNABORTED_))
678 712
679/* Specific error code set */ 713/* Specific error code set */
680 714
@@ -683,12 +717,16 @@
683 * available on platform. 717 * available on platform.
684 */ 718 */
685#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ 719#if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_
686# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 720# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
721 MHD_SCKT_ENOMEM_)
687#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ 722#elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_
688# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_) 723# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
724 MHD_SCKT_ENOBUFS_)
689#else 725#else
690# warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. 726# warning \
691# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) 727 No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system.
728# define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_ ( \
729 MHD_SCKT_ENOMEM_)
692#endif 730#endif
693 731
694/* Socket functions */ 732/* Socket functions */
@@ -700,22 +738,26 @@
700#endif /* AF_UNIX */ 738#endif /* AF_UNIX */
701 739
702#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL) 740#if defined(MHD_POSIX_SOCKETS) && defined(MHD_SCKT_LOCAL)
703# define MHD_socket_pair_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM, 0, (fdarr))) 741# define MHD_socket_pair_(fdarr) (! socketpair (MHD_SCKT_LOCAL, SOCK_STREAM, 0, \
742 (fdarr)))
704# if defined(HAVE_SOCK_NONBLOCK) 743# if defined(HAVE_SOCK_NONBLOCK)
705# define MHD_socket_pair_nblk_(fdarr) (!socketpair(MHD_SCKT_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr))) 744# define MHD_socket_pair_nblk_(fdarr) (! socketpair (MHD_SCKT_LOCAL, \
745 SOCK_STREAM \
746 | SOCK_NONBLOCK, 0, \
747 (fdarr)))
706# endif /* HAVE_SOCK_NONBLOCK*/ 748# endif /* HAVE_SOCK_NONBLOCK*/
707#elif defined(MHD_WINSOCK_SOCKETS) 749#elif defined(MHD_WINSOCK_SOCKETS)
708 /** 750/**
709 * Create pair of mutually connected TCP/IP sockets on loopback address 751 * Create pair of mutually connected TCP/IP sockets on loopback address
710 * @param sockets_pair array to receive resulted sockets 752 * @param sockets_pair array to receive resulted sockets
711 * @param non_blk if set to non-zero value, sockets created in non-blocking mode 753 * @param non_blk if set to non-zero value, sockets created in non-blocking mode
712 * otherwise sockets will be in blocking mode 754 * otherwise sockets will be in blocking mode
713 * @return non-zero if succeeded, zero otherwise 755 * @return non-zero if succeeded, zero otherwise
714 */ 756 */
715 int MHD_W32_socket_pair_(SOCKET sockets_pair[2], int non_blk); 757int MHD_W32_socket_pair_ (SOCKET sockets_pair[2], int non_blk);
716 758
717# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_((fdarr), 0) 759# define MHD_socket_pair_(fdarr) MHD_W32_socket_pair_ ((fdarr), 0)
718# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_((fdarr), 1) 760# define MHD_socket_pair_nblk_(fdarr) MHD_W32_socket_pair_ ((fdarr), 1)
719#endif 761#endif
720 762
721/** 763/**
@@ -804,7 +846,7 @@ MHD_socket_buffering_reset_ (MHD_socket sock);
804 846
805 847
806#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) 848#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
807 static const int _MHD_socket_int_one = 1; 849static const int _MHD_socket_int_one = 1;
808/** 850/**
809 * Change socket options to no signal on remote disconnect. 851 * Change socket options to no signal on remote disconnect.
810 * 852 *
@@ -812,7 +854,8 @@ MHD_socket_buffering_reset_ (MHD_socket sock);
812 * @return non-zero if succeeded, zero otherwise 854 * @return non-zero if succeeded, zero otherwise
813 */ 855 */
814# define MHD_socket_nosignal_(sock) \ 856# define MHD_socket_nosignal_(sock) \
815 (!setsockopt((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one,sizeof(_MHD_socket_int_one))) 857 (! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one, \
858 sizeof(_MHD_socket_int_one)))
816#endif /* SOL_SOCKET && SO_NOSIGPIPE */ 859#endif /* SOL_SOCKET && SO_NOSIGPIPE */
817 860
818/** 861/**
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 36a935a2..80f0b82e 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -117,8 +117,8 @@ _MHD_static_inline bool
117isasciixdigit (char c) 117isasciixdigit (char c)
118{ 118{
119 return isasciidigit (c) || 119 return isasciidigit (c) ||
120 ( (c >= 'A') && (c <= 'F') ) || 120 ( (c >= 'A') && (c <= 'F') ) ||
121 ( (c >= 'a') && (c <= 'f') ); 121 ( (c >= 'a') && (c <= 'f') );
122} 122}
123 123
124 124
@@ -181,7 +181,7 @@ _MHD_static_inline int
181todigitvalue (char c) 181todigitvalue (char c)
182{ 182{
183 if (isasciidigit (c)) 183 if (isasciidigit (c))
184 return (unsigned char)(c - '0'); 184 return (unsigned char) (c - '0');
185 185
186 return -1; 186 return -1;
187} 187}
@@ -198,11 +198,11 @@ _MHD_static_inline int
198toxdigitvalue (char c) 198toxdigitvalue (char c)
199{ 199{
200 if (isasciidigit (c)) 200 if (isasciidigit (c))
201 return (unsigned char)(c - '0'); 201 return (unsigned char) (c - '0');
202 if ( (c >= 'A') && (c <= 'F') ) 202 if ( (c >= 'A') && (c <= 'F') )
203 return (unsigned char)(c - 'A' + 10); 203 return (unsigned char) (c - 'A' + 10);
204 if ( (c >= 'a') && (c <= 'f') ) 204 if ( (c >= 'a') && (c <= 'f') )
205 return (unsigned char)(c - 'a' + 10); 205 return (unsigned char) (c - 'a' + 10);
206 206
207 return -1; 207 return -1;
208} 208}
@@ -216,7 +216,7 @@ toxdigitvalue (char c)
216 * @return boolean true if character is lower case letter, 216 * @return boolean true if character is lower case letter,
217 * boolean false otherwise 217 * boolean false otherwise
218 */ 218 */
219#define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z') 219#define isasciilower(c) (((char) (c)) >= 'a' && ((char) (c)) <= 'z')
220 220
221 221
222/** 222/**
@@ -226,7 +226,7 @@ toxdigitvalue (char c)
226 * @return boolean true if character is upper case letter, 226 * @return boolean true if character is upper case letter,
227 * boolean false otherwise 227 * boolean false otherwise
228 */ 228 */
229#define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z') 229#define isasciiupper(c) (((char) (c)) >= 'A' && ((char) (c)) <= 'Z')
230 230
231 231
232/** 232/**
@@ -236,7 +236,7 @@ toxdigitvalue (char c)
236 * @return boolean true if character is letter, boolean false 236 * @return boolean true if character is letter, boolean false
237 * otherwise 237 * otherwise
238 */ 238 */
239#define isasciialpha(c) (isasciilower(c) || isasciiupper(c)) 239#define isasciialpha(c) (isasciilower (c) || isasciiupper (c))
240 240
241 241
242/** 242/**
@@ -246,7 +246,7 @@ toxdigitvalue (char c)
246 * @return boolean true if character is decimal digit, boolean false 246 * @return boolean true if character is decimal digit, boolean false
247 * otherwise 247 * otherwise
248 */ 248 */
249#define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9') 249#define isasciidigit(c) (((char) (c)) >= '0' && ((char) (c)) <= '9')
250 250
251 251
252/** 252/**
@@ -256,9 +256,9 @@ toxdigitvalue (char c)
256 * @return boolean true if character is hexadecimal digit, 256 * @return boolean true if character is hexadecimal digit,
257 * boolean false otherwise 257 * boolean false otherwise
258 */ 258 */
259#define isasciixdigit(c) (isasciidigit((c)) || \ 259#define isasciixdigit(c) (isasciidigit ((c)) || \
260 (((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \ 260 (((char) (c)) >= 'A' && ((char) (c)) <= 'F') || \
261 (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ) 261 (((char) (c)) >= 'a' && ((char) (c)) <= 'f') )
262 262
263 263
264/** 264/**
@@ -268,7 +268,7 @@ toxdigitvalue (char c)
268 * @return boolean true if character is decimal digit or letter, 268 * @return boolean true if character is decimal digit or letter,
269 * boolean false otherwise 269 * boolean false otherwise
270 */ 270 */
271#define isasciialnum(c) (isasciialpha(c) || isasciidigit(c)) 271#define isasciialnum(c) (isasciialpha (c) || isasciidigit (c))
272 272
273 273
274/** 274/**
@@ -280,7 +280,8 @@ toxdigitvalue (char c)
280 * @param c character to convert 280 * @param c character to convert
281 * @return converted to lower case character 281 * @return converted to lower case character
282 */ 282 */
283#define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c))) 283#define toasciilower(c) ((isasciiupper (c)) ? (((char) (c)) - 'A' + 'a') : \
284 ((char) (c)))
284 285
285 286
286/** 287/**
@@ -292,7 +293,8 @@ toxdigitvalue (char c)
292 * @param c character to convert 293 * @param c character to convert
293 * @return converted to upper case character 294 * @return converted to upper case character
294 */ 295 */
295#define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c))) 296#define toasciiupper(c) ((isasciilower (c)) ? (((char) (c)) - 'a' + 'A') : \
297 ((char) (c)))
296 298
297 299
298/** 300/**
@@ -301,7 +303,8 @@ toxdigitvalue (char c)
301 * @param c character to convert 303 * @param c character to convert
302 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 304 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
303 */ 305 */
304#define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1)) 306#define todigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \
307 (int) (-1))
305 308
306 309
307/** 310/**
@@ -309,11 +312,12 @@ toxdigitvalue (char c)
309 * @param c character to convert 312 * @param c character to convert
310 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 313 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
311 */ 314 */
312#define toxdigitvalue(c) ( isasciidigit(c) ? (int)(((char)(c)) - '0') : \ 315#define toxdigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \
313 ( (((char)(c)) >= 'A' && ((char)(c)) <= 'F') ? \ 316 ( (((char) (c)) >= 'A' && ((char) (c)) <= 'F') ? \
314 (int)(((unsigned char)(c)) - 'A' + 10) : \ 317 (int) (((unsigned char) (c)) - 'A' + 10) : \
315 ( (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ? \ 318 ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \
316 (int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) ))) 319 (int) (((unsigned char) (c)) - 'a' + 10) : \
320 (int) (-1) )))
317#endif /* !INLINE_FUNC */ 321#endif /* !INLINE_FUNC */
318 322
319 323
@@ -326,19 +330,19 @@ toxdigitvalue (char c)
326 * @return non-zero if two strings are equal, zero otherwise. 330 * @return non-zero if two strings are equal, zero otherwise.
327 */ 331 */
328int 332int
329MHD_str_equal_caseless_ (const char * str1, 333MHD_str_equal_caseless_ (const char *str1,
330 const char * str2) 334 const char *str2)
331{ 335{
332 while (0 != (*str1)) 336 while (0 != (*str1))
333 { 337 {
334 const char c1 = *str1; 338 const char c1 = *str1;
335 const char c2 = *str2; 339 const char c2 = *str2;
336 if ( (c1 != c2) && 340 if ( (c1 != c2) &&
337 (toasciilower (c1) != toasciilower (c2)) ) 341 (toasciilower (c1) != toasciilower (c2)) )
338 return 0; 342 return 0;
339 str1++; 343 str1++;
340 str2++; 344 str2++;
341 } 345 }
342 return 0 == (*str2); 346 return 0 == (*str2);
343} 347}
344#endif /* ! MHD_FAVOR_SMALL_CODE */ 348#endif /* ! MHD_FAVOR_SMALL_CODE */
@@ -356,23 +360,23 @@ MHD_str_equal_caseless_ (const char * str1,
356 * @return non-zero if two strings are equal, zero otherwise. 360 * @return non-zero if two strings are equal, zero otherwise.
357 */ 361 */
358int 362int
359MHD_str_equal_caseless_n_ (const char * const str1, 363MHD_str_equal_caseless_n_ (const char *const str1,
360 const char * const str2, 364 const char *const str2,
361 size_t maxlen) 365 size_t maxlen)
362{ 366{
363 size_t i; 367 size_t i;
364 368
365 for (i = 0; i < maxlen; ++i) 369 for (i = 0; i < maxlen; ++i)
366 { 370 {
367 const char c1 = str1[i]; 371 const char c1 = str1[i];
368 const char c2 = str2[i]; 372 const char c2 = str2[i];
369 if (0 == c2) 373 if (0 == c2)
370 return 0 == c1; 374 return 0 == c1;
371 if ( (c1 != c2) && 375 if ( (c1 != c2) &&
372 (toasciilower (c1) != toasciilower (c2)) ) 376 (toasciilower (c1) != toasciilower (c2)) )
373 return 0; 377 return 0;
374 } 378 }
375 return !0; 379 return ! 0;
376} 380}
377 381
378 382
@@ -386,21 +390,21 @@ MHD_str_equal_caseless_n_ (const char * const str1,
386 * @return non-zero if two strings are equal, zero otherwise. 390 * @return non-zero if two strings are equal, zero otherwise.
387 */ 391 */
388bool 392bool
389MHD_str_equal_caseless_bin_n_ (const char * const str1, 393MHD_str_equal_caseless_bin_n_ (const char *const str1,
390 const char * const str2, 394 const char *const str2,
391 size_t len) 395 size_t len)
392{ 396{
393 size_t i; 397 size_t i;
394 398
395 for (i = 0; i < len; ++i) 399 for (i = 0; i < len; ++i)
396 { 400 {
397 const char c1 = str1[i]; 401 const char c1 = str1[i];
398 const char c2 = str2[i]; 402 const char c2 = str2[i];
399 if ( (c1 != c2) && 403 if ( (c1 != c2) &&
400 (toasciilower (c1) != toasciilower (c2)) ) 404 (toasciilower (c1) != toasciilower (c2)) )
401 return 0; 405 return 0;
402 } 406 }
403 return !0; 407 return ! 0;
404} 408}
405 409
406 410
@@ -419,46 +423,49 @@ MHD_str_equal_caseless_bin_n_ (const char * const str1,
419 * @return non-zero if two strings are equal, zero otherwise. 423 * @return non-zero if two strings are equal, zero otherwise.
420 */ 424 */
421bool 425bool
422MHD_str_has_token_caseless_ (const char * str, 426MHD_str_has_token_caseless_ (const char *str,
423 const char * const token, 427 const char *const token,
424 size_t token_len) 428 size_t token_len)
425{ 429{
426 if (0 == token_len) 430 if (0 == token_len)
427 return false; 431 return false;
428 432
429 while (0 != *str) 433 while (0 != *str)
434 {
435 size_t i;
436 /* Skip all whitespaces and empty tokens. */
437 while (' ' == *str || '\t' == *str || ',' == *str)
438 str++;
439
440 /* Check for token match. */
441 i = 0;
442 while (1)
430 { 443 {
431 size_t i; 444 const char sc = *(str++);
432 /* Skip all whitespaces and empty tokens. */ 445 const char tc = token[i++];
433 while (' ' == *str || '\t' == *str || ',' == *str) str++; 446
434 447 if (0 == sc)
435 /* Check for token match. */ 448 return false;
436 i = 0; 449 if ( (sc != tc) &&
437 while (1) 450 (toasciilower (sc) != toasciilower (tc)) )
438 { 451 break;
439 const char sc = *(str++); 452 if (i >= token_len)
440 const char tc = token[i++]; 453 {
441 454 /* Check whether substring match token fully or
442 if (0 == sc) 455 * has additional unmatched chars at tail. */
443 return false; 456 while (' ' == *str || '\t' == *str)
444 if ( (sc != tc) && 457 str++;
445 (toasciilower (sc) != toasciilower (tc)) ) 458 /* End of (sub)string? */
446 break; 459 if ((0 == *str) ||(',' == *str) )
447 if (i >= token_len) 460 return true;
448 { 461 /* Unmatched chars at end of substring. */
449 /* Check whether substring match token fully or 462 break;
450 * has additional unmatched chars at tail. */ 463 }
451 while (' ' == *str || '\t' == *str) str++;
452 /* End of (sub)string? */
453 if (0 == *str || ',' == *str)
454 return true;
455 /* Unmatched chars at end of substring. */
456 break;
457 }
458 }
459 /* Find next substring. */
460 while (0 != *str && ',' != *str) str++;
461 } 464 }
465 /* Find next substring. */
466 while (0 != *str && ',' != *str)
467 str++;
468 }
462 return false; 469 return false;
463} 470}
464 471
@@ -479,25 +486,25 @@ size_t
479MHD_str_to_uint64_ (const char *str, 486MHD_str_to_uint64_ (const char *str,
480 uint64_t *out_val) 487 uint64_t *out_val)
481{ 488{
482 const char * const start = str; 489 const char *const start = str;
483 uint64_t res; 490 uint64_t res;
484 491
485 if (!str || !out_val || !isasciidigit(str[0])) 492 if (! str || ! out_val || ! isasciidigit (str[0]))
486 return 0; 493 return 0;
487 494
488 res = 0; 495 res = 0;
489 do 496 do
490 { 497 {
491 const int digit = (unsigned char)(*str) - '0'; 498 const int digit = (unsigned char) (*str) - '0';
492 if ( (res > (UINT64_MAX / 10)) || 499 if ( (res > (UINT64_MAX / 10)) ||
493 ( (res == (UINT64_MAX / 10)) && 500 ( (res == (UINT64_MAX / 10)) &&
494 ((uint64_t)digit > (UINT64_MAX % 10)) ) ) 501 ((uint64_t) digit > (UINT64_MAX % 10)) ) )
495 return 0; 502 return 0;
496 503
497 res *= 10; 504 res *= 10;
498 res += digit; 505 res += digit;
499 str++; 506 str++;
500 } while (isasciidigit (*str)); 507 } while (isasciidigit (*str));
501 508
502 *out_val = res; 509 *out_val = res;
503 return str - start; 510 return str - start;
@@ -518,34 +525,34 @@ MHD_str_to_uint64_ (const char *str,
518 * then possible to store in uint64_t or @a out_val is NULL 525 * then possible to store in uint64_t or @a out_val is NULL
519 */ 526 */
520size_t 527size_t
521MHD_str_to_uint64_n_ (const char * str, 528MHD_str_to_uint64_n_ (const char *str,
522 size_t maxlen, 529 size_t maxlen,
523 uint64_t *out_val) 530 uint64_t *out_val)
524{ 531{
525 uint64_t res; 532 uint64_t res;
526 size_t i; 533 size_t i;
527 534
528 if (!str || !maxlen || !out_val || !isasciidigit (str[0])) 535 if (! str || ! maxlen || ! out_val || ! isasciidigit (str[0]))
529 return 0; 536 return 0;
530 537
531 res = 0; 538 res = 0;
532 i = 0; 539 i = 0;
533 do 540 do
534 { 541 {
535 const int digit = (unsigned char)str[i] - '0'; 542 const int digit = (unsigned char) str[i] - '0';
536 543
537 if ( (res > (UINT64_MAX / 10)) || 544 if ( (res > (UINT64_MAX / 10)) ||
538 ( (res == (UINT64_MAX / 10)) && 545 ( (res == (UINT64_MAX / 10)) &&
539 ((uint64_t)digit > (UINT64_MAX % 10)) ) ) 546 ((uint64_t) digit > (UINT64_MAX % 10)) ) )
540 return 0; 547 return 0;
541 548
542 res *= 10; 549 res *= 10;
543 res += digit; 550 res += digit;
544 i++; 551 i++;
545 } while ( (i < maxlen) && 552 } while ( (i < maxlen) &&
546 isasciidigit (str[i]) ); 553 isasciidigit (str[i]) );
547 554
548 *out_val= res; 555 *out_val = res;
549 return i; 556 return i;
550} 557}
551 558
@@ -561,31 +568,32 @@ MHD_str_to_uint64_n_ (const char * str,
561 * then possible to store in uint32_t or @a out_val is NULL 568 * then possible to store in uint32_t or @a out_val is NULL
562 */ 569 */
563size_t 570size_t
564MHD_strx_to_uint32_ (const char * str, 571MHD_strx_to_uint32_ (const char *str,
565 uint32_t *out_val) 572 uint32_t *out_val)
566{ 573{
567 const char * const start = str; 574 const char *const start = str;
568 uint32_t res; 575 uint32_t res;
569 int digit; 576 int digit;
570 577
571 if (!str || !out_val) 578 if (! str || ! out_val)
572 return 0; 579 return 0;
573 580
574 res = 0; 581 res = 0;
575 digit = toxdigitvalue (*str); 582 digit = toxdigitvalue (*str);
576 while (digit >= 0) 583 while (digit >= 0)
584 {
585 if ( (res < (UINT32_MAX / 16)) ||
586 ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit <= (UINT32_MAX
587 % 16)) ) )
577 { 588 {
578 if ( (res < (UINT32_MAX / 16)) || 589 res *= 16;
579 (res == (UINT32_MAX / 16) && (uint32_t)digit <= (UINT32_MAX % 16)) ) 590 res += digit;
580 {
581 res *= 16;
582 res += digit;
583 }
584 else
585 return 0;
586 str++;
587 digit = toxdigitvalue (*str);
588 } 591 }
592 else
593 return 0;
594 str++;
595 digit = toxdigitvalue (*str);
596 }
589 597
590 if (str - start > 0) 598 if (str - start > 0)
591 *out_val = res; 599 *out_val = res;
@@ -614,21 +622,22 @@ MHD_strx_to_uint32_n_ (const char *str,
614 size_t i; 622 size_t i;
615 uint32_t res; 623 uint32_t res;
616 int digit; 624 int digit;
617 if (!str || !out_val) 625 if (! str || ! out_val)
618 return 0; 626 return 0;
619 627
620 res = 0; 628 res = 0;
621 i = 0; 629 i = 0;
622 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 630 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
623 { 631 {
624 if ( (res > (UINT32_MAX / 16)) || 632 if ( (res > (UINT32_MAX / 16)) ||
625 (res == (UINT32_MAX / 16) && (uint32_t)digit > (UINT32_MAX % 16)) ) 633 ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit > (UINT32_MAX
626 return 0; 634 % 16)) ) )
635 return 0;
627 636
628 res *= 16; 637 res *= 16;
629 res += digit; 638 res += digit;
630 i++; 639 i++;
631 } 640 }
632 641
633 if (i) 642 if (i)
634 *out_val = res; 643 *out_val = res;
@@ -650,27 +659,28 @@ size_t
650MHD_strx_to_uint64_ (const char *str, 659MHD_strx_to_uint64_ (const char *str,
651 uint64_t *out_val) 660 uint64_t *out_val)
652{ 661{
653 const char * const start = str; 662 const char *const start = str;
654 uint64_t res; 663 uint64_t res;
655 int digit; 664 int digit;
656 if (!str || !out_val) 665 if (! str || ! out_val)
657 return 0; 666 return 0;
658 667
659 res = 0; 668 res = 0;
660 digit = toxdigitvalue (*str); 669 digit = toxdigitvalue (*str);
661 while (digit >= 0) 670 while (digit >= 0)
671 {
672 if ( (res < (UINT64_MAX / 16)) ||
673 ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit <= (UINT64_MAX
674 % 16)) ) )
662 { 675 {
663 if ( (res < (UINT64_MAX / 16)) || 676 res *= 16;
664 (res == (UINT64_MAX / 16) && (uint64_t)digit <= (UINT64_MAX % 16)) ) 677 res += digit;
665 {
666 res *= 16;
667 res += digit;
668 }
669 else
670 return 0;
671 str++;
672 digit = toxdigitvalue (*str);
673 } 678 }
679 else
680 return 0;
681 str++;
682 digit = toxdigitvalue (*str);
683 }
674 684
675 if (str - start > 0) 685 if (str - start > 0)
676 *out_val = res; 686 *out_val = res;
@@ -692,28 +702,29 @@ MHD_strx_to_uint64_ (const char *str,
692 * then possible to store in uint64_t or @a out_val is NULL 702 * then possible to store in uint64_t or @a out_val is NULL
693 */ 703 */
694size_t 704size_t
695MHD_strx_to_uint64_n_ (const char * str, 705MHD_strx_to_uint64_n_ (const char *str,
696 size_t maxlen, 706 size_t maxlen,
697 uint64_t *out_val) 707 uint64_t *out_val)
698{ 708{
699 size_t i; 709 size_t i;
700 uint64_t res; 710 uint64_t res;
701 int digit; 711 int digit;
702 if (!str || !out_val) 712 if (! str || ! out_val)
703 return 0; 713 return 0;
704 714
705 res = 0; 715 res = 0;
706 i = 0; 716 i = 0;
707 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 717 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
708 { 718 {
709 if ( (res > (UINT64_MAX / 16)) || 719 if ( (res > (UINT64_MAX / 16)) ||
710 (res == (UINT64_MAX / 16) && (uint64_t)digit > (UINT64_MAX % 16)) ) 720 ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit > (UINT64_MAX
711 return 0; 721 % 16)) ) )
722 return 0;
712 723
713 res *= 16; 724 res *= 16;
714 res += digit; 725 res += digit;
715 i++; 726 i++;
716 } 727 }
717 728
718 if (i) 729 if (i)
719 *out_val = res; 730 *out_val = res;
@@ -742,7 +753,7 @@ MHD_strx_to_uint64_n_ (const char * str,
742size_t 753size_t
743MHD_str_to_uvalue_n_ (const char *str, 754MHD_str_to_uvalue_n_ (const char *str,
744 size_t maxlen, 755 size_t maxlen,
745 void * out_val, 756 void *out_val,
746 size_t val_size, 757 size_t val_size,
747 uint64_t max_val, 758 uint64_t max_val,
748 int base) 759 int base)
@@ -754,34 +765,34 @@ MHD_str_to_uvalue_n_ (const char *str,
754 const uint64_t max_v_mod_b = max_val % base; 765 const uint64_t max_v_mod_b = max_val % base;
755 /* 'digit->value' must be function, not macro */ 766 /* 'digit->value' must be function, not macro */
756 int (*const dfunc)(char) = (base == 16) ? 767 int (*const dfunc)(char) = (base == 16) ?
757 toxdigitvalue : todigitvalue; 768 toxdigitvalue : todigitvalue;
758 769
759 if ( !str || !out_val || 770 if ( ! str || ! out_val ||
760 (base != 16 && base != 10) ) 771 ((base != 16)&&(base != 10)) )
761 return 0; 772 return 0;
762 773
763 res = 0; 774 res = 0;
764 i = 0; 775 i = 0;
765 while (maxlen > i && 0 <= (digit = dfunc (str[i]))) 776 while (maxlen > i && 0 <= (digit = dfunc (str[i])))
766 { 777 {
767 if ( ((max_v_div_b) < res) || 778 if ( ((max_v_div_b) < res) ||
768 ((max_v_div_b) == res && (max_v_mod_b) < (uint64_t)digit) ) 779 (( (max_v_div_b) == res) &&( (max_v_mod_b) < (uint64_t) digit) ) )
769 return 0; 780 return 0;
770 781
771 res *= base; 782 res *= base;
772 res += digit; 783 res += digit;
773 i++; 784 i++;
774 } 785 }
775 786
776 if (i) 787 if (i)
777 { 788 {
778 if (8 == val_size) 789 if (8 == val_size)
779 *(uint64_t*)out_val = res; 790 *(uint64_t*) out_val = res;
780 else if (4 == val_size) 791 else if (4 == val_size)
781 *(uint32_t*)out_val = (uint32_t)res; 792 *(uint32_t*) out_val = (uint32_t) res;
782 else 793 else
783 return 0; 794 return 0;
784 } 795 }
785 return i; 796 return i;
786} 797}
787#endif /* MHD_FAVOR_SMALL_CODE */ 798#endif /* MHD_FAVOR_SMALL_CODE */
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index 5c0e0fdc..dd379f52 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -42,7 +42,7 @@
42/** 42/**
43 * Determine length of static string / macro strings at compile time. 43 * Determine length of static string / macro strings at compile time.
44 */ 44 */
45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
46#endif /* ! MHD_STATICSTR_LEN_ */ 46#endif /* ! MHD_STATICSTR_LEN_ */
47 47
48/* 48/*
@@ -58,11 +58,12 @@
58 * @return non-zero if two strings are equal, zero otherwise. 58 * @return non-zero if two strings are equal, zero otherwise.
59 */ 59 */
60int 60int
61MHD_str_equal_caseless_ (const char * str1, 61MHD_str_equal_caseless_ (const char *str1,
62 const char * str2); 62 const char *str2);
63#else /* MHD_FAVOR_SMALL_CODE */ 63#else /* MHD_FAVOR_SMALL_CODE */
64/* Reuse MHD_str_equal_caseless_n_() to reduce size */ 64/* Reuse MHD_str_equal_caseless_n_() to reduce size */
65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_((s1),(s2), SIZE_MAX) 65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
66 SIZE_MAX)
66#endif /* MHD_FAVOR_SMALL_CODE */ 67#endif /* MHD_FAVOR_SMALL_CODE */
67 68
68 69
@@ -77,9 +78,9 @@ MHD_str_equal_caseless_ (const char * str1,
77 * @return non-zero if two strings are equal, zero otherwise. 78 * @return non-zero if two strings are equal, zero otherwise.
78 */ 79 */
79int 80int
80MHD_str_equal_caseless_n_ (const char * const str1, 81MHD_str_equal_caseless_n_ (const char *const str1,
81 const char * const str2, 82 const char *const str2,
82 size_t maxlen); 83 size_t maxlen);
83 84
84 85
85/** 86/**
@@ -92,9 +93,9 @@ MHD_str_equal_caseless_n_ (const char * const str1,
92 * @return non-zero if two strings are equal, zero otherwise. 93 * @return non-zero if two strings are equal, zero otherwise.
93 */ 94 */
94bool 95bool
95MHD_str_equal_caseless_bin_n_ (const char * const str1, 96MHD_str_equal_caseless_bin_n_ (const char *const str1,
96 const char * const str2, 97 const char *const str2,
97 size_t len); 98 size_t len);
98 99
99 100
100/** 101/**
@@ -111,8 +112,8 @@ MHD_str_equal_caseless_bin_n_ (const char * const str1,
111 * @return non-zero if two strings are equal, zero otherwise. 112 * @return non-zero if two strings are equal, zero otherwise.
112 */ 113 */
113bool 114bool
114MHD_str_has_token_caseless_ (const char * str, 115MHD_str_has_token_caseless_ (const char *str,
115 const char * const token, 116 const char *const token,
116 size_t token_len); 117 size_t token_len);
117 118
118/** 119/**
@@ -126,7 +127,7 @@ MHD_str_has_token_caseless_ (const char * str,
126 * @return non-zero if two strings are equal, zero otherwise. 127 * @return non-zero if two strings are equal, zero otherwise.
127 */ 128 */
128#define MHD_str_has_s_token_caseless_(str,tkn) \ 129#define MHD_str_has_s_token_caseless_(str,tkn) \
129 MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn)) 130 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
130 131
131#ifndef MHD_FAVOR_SMALL_CODE 132#ifndef MHD_FAVOR_SMALL_CODE
132/* Use individual function for each case to improve speed */ 133/* Use individual function for each case to improve speed */
@@ -141,13 +142,13 @@ MHD_str_has_token_caseless_ (const char * str,
141 * then possible to store in uint64_t or @a out_val is NULL 142 * then possible to store in uint64_t or @a out_val is NULL
142 */ 143 */
143size_t 144size_t
144MHD_str_to_uint64_ (const char * str, 145MHD_str_to_uint64_ (const char *str,
145 uint64_t * out_val); 146 uint64_t *out_val);
146 147
147/** 148/**
148 * Convert not more then @a maxlen decimal US-ASCII digits in string to 149 * Convert not more then @a maxlen decimal US-ASCII digits in string to
149 * number in uint64_t. 150 * number in uint64_t.
150 * Conversion stopped at first non-digit character or after @a maxlen 151 * Conversion stopped at first non-digit character or after @a maxlen
151 * digits. 152 * digits.
152 * @param str string to convert 153 * @param str string to convert
153 * @param maxlen maximum number of characters to process 154 * @param maxlen maximum number of characters to process
@@ -157,9 +158,9 @@ MHD_str_to_uint64_ (const char * str,
157 * then possible to store in uint64_t or @a out_val is NULL 158 * then possible to store in uint64_t or @a out_val is NULL
158 */ 159 */
159size_t 160size_t
160MHD_str_to_uint64_n_ (const char * str, 161MHD_str_to_uint64_n_ (const char *str,
161 size_t maxlen, 162 size_t maxlen,
162 uint64_t * out_val); 163 uint64_t *out_val);
163 164
164 165
165/** 166/**
@@ -167,19 +168,19 @@ MHD_str_to_uint64_n_ (const char * str,
167 * Conversion stopped at first non-digit character. 168 * Conversion stopped at first non-digit character.
168 * @param str string to convert 169 * @param str string to convert
169 * @param out_val pointer to uint32_t to store result of conversion 170 * @param out_val pointer to uint32_t to store result of conversion
170 * @return non-zero number of characters processed on succeed, 171 * @return non-zero number of characters processed on succeed,
171 * zero if no digit is found, resulting value is larger 172 * zero if no digit is found, resulting value is larger
172 * then possible to store in uint32_t or @a out_val is NULL 173 * then possible to store in uint32_t or @a out_val is NULL
173 */ 174 */
174size_t 175size_t
175MHD_strx_to_uint32_ (const char * str, 176MHD_strx_to_uint32_ (const char *str,
176 uint32_t * out_val); 177 uint32_t *out_val);
177 178
178 179
179/** 180/**
180 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 181 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
181 * to number in uint32_t. 182 * to number in uint32_t.
182 * Conversion stopped at first non-digit character or after @a maxlen 183 * Conversion stopped at first non-digit character or after @a maxlen
183 * digits. 184 * digits.
184 * @param str string to convert 185 * @param str string to convert
185 * @param maxlen maximum number of characters to process 186 * @param maxlen maximum number of characters to process
@@ -189,9 +190,9 @@ MHD_strx_to_uint32_ (const char * str,
189 * then possible to store in uint32_t or @a out_val is NULL 190 * then possible to store in uint32_t or @a out_val is NULL
190 */ 191 */
191size_t 192size_t
192MHD_strx_to_uint32_n_ (const char * str, 193MHD_strx_to_uint32_n_ (const char *str,
193 size_t maxlen, 194 size_t maxlen,
194 uint32_t * out_val); 195 uint32_t *out_val);
195 196
196 197
197/** 198/**
@@ -199,19 +200,19 @@ MHD_strx_to_uint32_n_ (const char * str,
199 * Conversion stopped at first non-digit character. 200 * Conversion stopped at first non-digit character.
200 * @param str string to convert 201 * @param str string to convert
201 * @param out_val pointer to uint64_t to store result of conversion 202 * @param out_val pointer to uint64_t to store result of conversion
202 * @return non-zero number of characters processed on succeed, 203 * @return non-zero number of characters processed on succeed,
203 * zero if no digit is found, resulting value is larger 204 * zero if no digit is found, resulting value is larger
204 * then possible to store in uint64_t or @a out_val is NULL 205 * then possible to store in uint64_t or @a out_val is NULL
205 */ 206 */
206size_t 207size_t
207MHD_strx_to_uint64_ (const char * str, 208MHD_strx_to_uint64_ (const char *str,
208 uint64_t * out_val); 209 uint64_t *out_val);
209 210
210 211
211/** 212/**
212 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 213 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
213 * to number in uint64_t. 214 * to number in uint64_t.
214 * Conversion stopped at first non-digit character or after @a maxlen 215 * Conversion stopped at first non-digit character or after @a maxlen
215 * digits. 216 * digits.
216 * @param str string to convert 217 * @param str string to convert
217 * @param maxlen maximum number of characters to process 218 * @param maxlen maximum number of characters to process
@@ -221,9 +222,9 @@ MHD_strx_to_uint64_ (const char * str,
221 * then possible to store in uint64_t or @a out_val is NULL 222 * then possible to store in uint64_t or @a out_val is NULL
222 */ 223 */
223size_t 224size_t
224MHD_strx_to_uint64_n_ (const char * str, 225MHD_strx_to_uint64_n_ (const char *str,
225 size_t maxlen, 226 size_t maxlen,
226 uint64_t * out_val); 227 uint64_t *out_val);
227 228
228#else /* MHD_FAVOR_SMALL_CODE */ 229#else /* MHD_FAVOR_SMALL_CODE */
229/* Use one universal function and macros to reduce size */ 230/* Use one universal function and macros to reduce size */
@@ -231,7 +232,7 @@ MHD_strx_to_uint64_n_ (const char * str,
231/** 232/**
232 * Generic function for converting not more then @a maxlen 233 * Generic function for converting not more then @a maxlen
233 * hexadecimal or decimal US-ASCII digits in string to number. 234 * hexadecimal or decimal US-ASCII digits in string to number.
234 * Conversion stopped at first non-digit character or after @a maxlen 235 * Conversion stopped at first non-digit character or after @a maxlen
235 * digits. 236 * digits.
236 * To be used only within macro. 237 * To be used only within macro.
237 * @param str the string to convert 238 * @param str the string to convert
@@ -245,36 +246,44 @@ MHD_strx_to_uint64_n_ (const char * str,
245 * then @ max_val or @a out_val is NULL 246 * then @ max_val or @a out_val is NULL
246 */ 247 */
247size_t 248size_t
248MHD_str_to_uvalue_n_ (const char * str, 249MHD_str_to_uvalue_n_ (const char *str,
249 size_t maxlen, 250 size_t maxlen,
250 void * out_val, 251 void *out_val,
251 size_t val_size, 252 size_t val_size,
252 uint64_t max_val, 253 uint64_t max_val,
253 int base); 254 int base);
254 255
255#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 256#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
256 sizeof(uint64_t),UINT64_MAX,10) 257 sizeof(uint64_t), \
258 UINT64_MAX,10)
257 259
258#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 260#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
259 sizeof(uint64_t),UINT64_MAX,10) 261 sizeof(uint64_t), \
262 UINT64_MAX,10)
260 263
261#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 264#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
262 sizeof(size_t),SIZE_MAX,16) 265 sizeof(size_t),SIZE_MAX, \
266 16)
263 267
264#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 268#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
265 sizeof(size_t),SIZE_MAX,16) 269 sizeof(size_t), \
270 SIZE_MAX,16)
266 271
267#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 272#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
268 sizeof(uint32_t),UINT32_MAX,16) 273 sizeof(uint32_t), \
274 UINT32_MAX,16)
269 275
270#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 276#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
271 sizeof(uint32_t),UINT32_MAX,16) 277 sizeof(uint32_t), \
278 UINT32_MAX,16)
272 279
273#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 280#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
274 sizeof(uint64_t),UINT64_MAX,16) 281 sizeof(uint64_t), \
282 UINT64_MAX,16)
275 283
276#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 284#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
277 sizeof(uint64_t),UINT64_MAX,16) 285 sizeof(uint64_t), \
286 UINT64_MAX,16)
278 287
279#endif /* MHD_FAVOR_SMALL_CODE */ 288#endif /* MHD_FAVOR_SMALL_CODE */
280 289
diff --git a/src/microhttpd/mhd_threads.h b/src/microhttpd/mhd_threads.h
index 6d69b9ed..79520d53 100644
--- a/src/microhttpd/mhd_threads.h
+++ b/src/microhttpd/mhd_threads.h
@@ -58,23 +58,26 @@
58 58
59#ifndef MHD_NO_THREAD_NAMES 59#ifndef MHD_NO_THREAD_NAMES
60# if defined(MHD_USE_POSIX_THREADS) 60# if defined(MHD_USE_POSIX_THREADS)
61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \ 61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
62 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \ 62 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \
63 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 63 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \
64 defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \
65 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
66 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
64# define MHD_USE_THREAD_NAME_ 67# define MHD_USE_THREAD_NAME_
65# endif /* HAVE_PTHREAD_SETNAME_NP */ 68# endif /* HAVE_PTHREAD_SETNAME_NP */
66# elif defined(MHD_USE_W32_THREADS) 69# elif defined(MHD_USE_W32_THREADS)
67# ifdef _MSC_FULL_VER 70# ifdef _MSC_FULL_VER
68 /* Thread names only available with VC compiler */ 71/* Thread names only available with VC compiler */
69# define MHD_USE_THREAD_NAME_ 72# define MHD_USE_THREAD_NAME_
70# endif /* _MSC_FULL_VER */ 73# endif /* _MSC_FULL_VER */
71# endif 74# endif
72#endif 75#endif
73 76
74#if defined(MHD_USE_POSIX_THREADS) 77#if defined(MHD_USE_POSIX_THREADS)
75 typedef pthread_t MHD_thread_handle_; 78typedef pthread_t MHD_thread_handle_;
76#elif defined(MHD_USE_W32_THREADS) 79#elif defined(MHD_USE_W32_THREADS)
77 typedef HANDLE MHD_thread_handle_; 80typedef HANDLE MHD_thread_handle_;
78#endif 81#endif
79 82
80#if defined(MHD_USE_POSIX_THREADS) 83#if defined(MHD_USE_POSIX_THREADS)
@@ -86,9 +89,9 @@
86#endif 89#endif
87 90
88#if defined(MHD_USE_POSIX_THREADS) 91#if defined(MHD_USE_POSIX_THREADS)
89 typedef pthread_t MHD_thread_ID_; 92typedef pthread_t MHD_thread_ID_;
90#elif defined(MHD_USE_W32_THREADS) 93#elif defined(MHD_USE_W32_THREADS)
91 typedef DWORD MHD_thread_ID_; 94typedef DWORD MHD_thread_ID_;
92#endif 95#endif
93 96
94/* Depending on implementation, pthread_create() MAY set thread ID into 97/* Depending on implementation, pthread_create() MAY set thread ID into
@@ -100,27 +103,27 @@
100 * to save some resources. */ 103 * to save some resources. */
101#if defined(MHD_USE_POSIX_THREADS) 104#if defined(MHD_USE_POSIX_THREADS)
102# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD 105# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD
103 union _MHD_thread_handle_ID_ 106union _MHD_thread_handle_ID_
104 { 107{
105 MHD_thread_handle_ handle; /**< To be used in other threads */ 108 MHD_thread_handle_ handle; /**< To be used in other threads */
106 MHD_thread_ID_ ID; /**< To be used in thread itself */ 109 MHD_thread_ID_ ID; /**< To be used in thread itself */
107 }; 110};
108 typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 111typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
109# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 112# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
110 struct _MHD_thread_handle_ID_ 113struct _MHD_thread_handle_ID_
111 { 114{
112 MHD_thread_handle_ handle; /**< To be used in other threads */ 115 MHD_thread_handle_ handle; /**< To be used in other threads */
113 MHD_thread_ID_ ID; /**< To be used in thread itself */ 116 MHD_thread_ID_ ID; /**< To be used in thread itself */
114 }; 117};
115 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 118typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
116# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 119# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
117#elif defined(MHD_USE_W32_THREADS) 120#elif defined(MHD_USE_W32_THREADS)
118 struct _MHD_thread_handle_ID_ 121struct _MHD_thread_handle_ID_
119 { 122{
120 MHD_thread_handle_ handle; /**< To be used in other threads */ 123 MHD_thread_handle_ handle; /**< To be used in other threads */
121 MHD_thread_ID_ ID; /**< To be used in thread itself */ 124 MHD_thread_ID_ ID; /**< To be used in thread itself */
122 }; 125};
123 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 126typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
124#endif 127#endif
125 128
126#if defined(MHD_USE_POSIX_THREADS) 129#if defined(MHD_USE_POSIX_THREADS)
@@ -129,14 +132,17 @@
129 * @param thread handle to watch 132 * @param thread handle to watch
130 * @return nonzero on success, zero otherwise 133 * @return nonzero on success, zero otherwise
131 */ 134 */
132#define MHD_join_thread_(thread) (!pthread_join((thread), NULL)) 135#define MHD_join_thread_(thread) (! pthread_join ((thread), NULL))
133#elif defined(MHD_USE_W32_THREADS) 136#elif defined(MHD_USE_W32_THREADS)
134/** 137/**
135 * Wait until specified thread is ended and free thread handle on success. 138 * Wait until specified thread is ended and free thread handle on success.
136 * @param thread handle to watch 139 * @param thread handle to watch
137 * @return nonzero on success, zero otherwise 140 * @return nonzero on success, zero otherwise
138 */ 141 */
139#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0) 142#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject ( \
143 (thread), INFINITE) ? (CloseHandle ( \
144 (thread)), ! 0) : \
145 0)
140#endif 146#endif
141 147
142#if defined(MHD_USE_POSIX_THREADS) 148#if defined(MHD_USE_POSIX_THREADS)
@@ -145,14 +151,14 @@
145 * @param ID thread ID to match 151 * @param ID thread ID to match
146 * @return nonzero on match, zero otherwise 152 * @return nonzero on match, zero otherwise
147 */ 153 */
148#define MHD_thread_ID_match_current_(ID) (pthread_equal((ID), pthread_self())) 154#define MHD_thread_ID_match_current_(ID) (pthread_equal ((ID), pthread_self ()))
149#elif defined(MHD_USE_W32_THREADS) 155#elif defined(MHD_USE_W32_THREADS)
150/** 156/**
151 * Check whether provided thread ID match current thread. 157 * Check whether provided thread ID match current thread.
152 * @param ID thread ID to match 158 * @param ID thread ID to match
153 * @return nonzero on match, zero otherwise 159 * @return nonzero on match, zero otherwise
154 */ 160 */
155#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId() == (ID)) 161#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId () == (ID))
156#endif 162#endif
157 163
158#if defined(MHD_USE_POSIX_THREADS) 164#if defined(MHD_USE_POSIX_THREADS)
@@ -161,20 +167,22 @@
161 * Initialise thread ID. 167 * Initialise thread ID.
162 * @param thread_handle_ID_ptr pointer to thread handle-ID 168 * @param thread_handle_ID_ptr pointer to thread handle-ID
163 */ 169 */
164#define MHD_thread_init_(thread_handle_ID_ptr) (void)0 170#define MHD_thread_init_(thread_handle_ID_ptr) (void) 0
165# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 171# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
166/** 172/**
167 * Initialise thread ID. 173 * Initialise thread ID.
168 * @param thread_handle_ID_ptr pointer to thread handle-ID 174 * @param thread_handle_ID_ptr pointer to thread handle-ID
169 */ 175 */
170#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=pthread_self()) 176#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
177 pthread_self ())
171# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 178# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
172#elif defined(MHD_USE_W32_THREADS) 179#elif defined(MHD_USE_W32_THREADS)
173/** 180/**
174 * Initialise thread ID. 181 * Initialise thread ID.
175 * @param thread_handle_ID_ptr pointer to thread handle-ID 182 * @param thread_handle_ID_ptr pointer to thread handle-ID
176 */ 183 */
177#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=GetCurrentThreadId()) 184#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
185 GetCurrentThreadId ())
178#endif 186#endif
179 187
180/** 188/**
@@ -205,7 +213,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
205 void *arg); 213 void *arg);
206 214
207#ifndef MHD_USE_THREAD_NAME_ 215#ifndef MHD_USE_THREAD_NAME_
208#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_((t),(s),(r),(a)) 216#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_ ((t),(s),(r),(a))
209#else /* MHD_USE_THREAD_NAME_ */ 217#else /* MHD_USE_THREAD_NAME_ */
210/** 218/**
211 * Create a named thread and set the attributes according to our options. 219 * Create a named thread and set the attributes according to our options.
@@ -219,7 +227,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
219 */ 227 */
220int 228int
221MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, 229MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
222 const char* thread_name, 230 const char*thread_name,
223 size_t stack_size, 231 size_t stack_size,
224 MHD_THREAD_START_ROUTINE_ start_routine, 232 MHD_THREAD_START_ROUTINE_ start_routine,
225 void *arg); 233 void *arg);
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index e9d40ef7..8b6a33ea 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -291,44 +291,48 @@ MHD_create_post_processor (struct MHD_Connection *connection,
291 if (MHD_NO == MHD_lookup_connection_value_n (connection, 291 if (MHD_NO == MHD_lookup_connection_value_n (connection,
292 MHD_HEADER_KIND, 292 MHD_HEADER_KIND,
293 MHD_HTTP_HEADER_CONTENT_TYPE, 293 MHD_HTTP_HEADER_CONTENT_TYPE,
294 MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONTENT_TYPE), 294 MHD_STATICSTR_LEN_ (
295 MHD_HTTP_HEADER_CONTENT_TYPE),
295 &encoding, 296 &encoding,
296 NULL)) 297 NULL))
297 return NULL; 298 return NULL;
298 boundary = NULL; 299 boundary = NULL;
299 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, 300 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
300 encoding, 301 encoding,
301 MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 302 MHD_STATICSTR_LEN_ (
303 MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
304 {
305 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
306 encoding,
307 MHD_STATICSTR_LEN_ (
308 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
309 return NULL;
310 boundary =
311 &encoding[MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
312 /* Q: should this be "strcasestr"? */
313 boundary = strstr (boundary, "boundary=");
314 if (NULL == boundary)
315 return NULL; /* failed to determine boundary */
316 boundary += MHD_STATICSTR_LEN_ ("boundary=");
317 blen = strlen (boundary);
318 if ( (blen == 0) ||
319 (blen * 2 + 2 > buffer_size) )
320 return NULL; /* (will be) out of memory or invalid boundary */
321 if ( (boundary[0] == '"') &&
322 (boundary[blen - 1] == '"') )
302 { 323 {
303 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, 324 /* remove enclosing quotes */
304 encoding, 325 ++boundary;
305 MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 326 blen -= 2;
306 return NULL;
307 boundary =
308 &encoding[MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
309 /* Q: should this be "strcasestr"? */
310 boundary = strstr (boundary, "boundary=");
311 if (NULL == boundary)
312 return NULL; /* failed to determine boundary */
313 boundary += MHD_STATICSTR_LEN_ ("boundary=");
314 blen = strlen (boundary);
315 if ( (blen == 0) ||
316 (blen * 2 + 2 > buffer_size) )
317 return NULL; /* (will be) out of memory or invalid boundary */
318 if ( (boundary[0] == '"') &&
319 (boundary[blen - 1] == '"') )
320 {
321 /* remove enclosing quotes */
322 ++boundary;
323 blen -= 2;
324 }
325 } 327 }
328 }
326 else 329 else
327 blen = 0; 330 blen = 0;
328 buffer_size += 4; /* round up to get nice block sizes despite boundary search */ 331 buffer_size += 4; /* round up to get nice block sizes despite boundary search */
329 332
330 /* add +1 to ensure we ALWAYS have a zero-termination at the end */ 333 /* add +1 to ensure we ALWAYS have a zero-termination at the end */
331 if (NULL == (ret = MHD_calloc_ (1, sizeof (struct MHD_PostProcessor) + buffer_size + 1))) 334 if (NULL == (ret = MHD_calloc_ (1, sizeof (struct MHD_PostProcessor)
335 + buffer_size + 1)))
332 return NULL; 336 return NULL;
333 ret->connection = connection; 337 ret->connection = connection;
334 ret->ikvi = iter; 338 ret->ikvi = iter;
@@ -354,7 +358,7 @@ MHD_create_post_processor (struct MHD_Connection *connection,
354static int 358static int
355post_process_urlencoded (struct MHD_PostProcessor *pp, 359post_process_urlencoded (struct MHD_PostProcessor *pp,
356 const char *post_data, 360 const char *post_data,
357 size_t post_data_len) 361 size_t post_data_len)
358{ 362{
359 size_t equals; 363 size_t equals;
360 size_t amper; 364 size_t amper;
@@ -368,149 +372,149 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
368 buf = (char *) &pp[1]; 372 buf = (char *) &pp[1];
369 poff = 0; 373 poff = 0;
370 while (poff < post_data_len) 374 while (poff < post_data_len)
375 {
376 switch (pp->state)
371 { 377 {
372 switch (pp->state) 378 case PP_Error:
379 return MHD_NO;
380 case PP_Done:
381 /* did not expect to receive more data */
382 pp->state = PP_Error;
383 return MHD_NO;
384 case PP_Init:
385 equals = 0;
386 while ((equals + poff < post_data_len) &&
387 (post_data[equals + poff] != '='))
388 equals++;
389 if (equals + pp->buffer_pos > pp->buffer_size)
390 {
391 pp->state = PP_Error; /* out of memory */
392 return MHD_NO;
393 }
394 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
395 pp->buffer_pos += equals;
396 if (equals + poff == post_data_len)
397 return MHD_YES; /* no '=' yet */
398 buf[pp->buffer_pos] = '\0'; /* 0-terminate key */
399 pp->buffer_pos = 0; /* reset for next key */
400 MHD_unescape_plus (buf);
401 MHD_http_unescape (buf);
402 poff += equals + 1;
403 pp->state = PP_ProcessValue;
404 pp->value_offset = 0;
405 break;
406 case PP_ProcessValue:
407 /* obtain rest of value from previous iteration */
408 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
409 xoff = pp->xbuf_pos;
410 pp->xbuf_pos = 0;
411
412 /* find last position in input buffer that is part of the value */
413 amper = 0;
414 while ((amper + poff < post_data_len) &&
415 (amper < XBUF_SIZE) &&
416 (post_data[amper + poff] != '&') &&
417 (post_data[amper + poff] != '\n') &&
418 (post_data[amper + poff] != '\r'))
419 amper++;
420 end_of_value_found = ((amper + poff < post_data_len) &&
421 ((post_data[amper + poff] == '&') ||
422 (post_data[amper + poff] == '\n') ||
423 (post_data[amper + poff] == '\r')));
424 /* compute delta, the maximum number of bytes that we will be able to
425 process right now (either amper-limited of xbuf-size limited) */
426 delta = amper;
427 if (delta > XBUF_SIZE - xoff)
428 delta = XBUF_SIZE - xoff;
429
430 /* move input into processing buffer */
431 memcpy (&xbuf[xoff], &post_data[poff], delta);
432 xoff += delta;
433 poff += delta;
434
435 /* find if escape sequence is at the end of the processing buffer;
436 if so, exclude those from processing (reduce delta to point at
437 end of processed region) */
438 delta = xoff;
439 if ((delta > 0) &&
440 ('%' == xbuf[delta - 1]))
441 delta--;
442 else if ((delta > 1) &&
443 ('%' == xbuf[delta - 2]))
444 delta -= 2;
445
446 /* if we have an incomplete escape sequence, save it to
447 pp->xbuf for later */
448 if (delta < xoff)
449 {
450 memcpy (pp->xbuf,
451 &xbuf[delta],
452 xoff - delta);
453 pp->xbuf_pos = xoff - delta;
454 xoff = delta;
455 }
456
457 /* If we have nothing to do (delta == 0) and
458 not just because the value is empty (are
459 waiting for more data), go for next iteration */
460 if ( (0 == xoff) &&
461 (poff == post_data_len))
462 continue;
463
464 /* unescape */
465 xbuf[xoff] = '\0'; /* 0-terminate in preparation */
466 MHD_unescape_plus (xbuf);
467 xoff = MHD_http_unescape (xbuf);
468 /* finally: call application! */
469 pp->must_ikvi = MHD_NO;
470 if (MHD_NO == pp->ikvi (pp->cls,
471 MHD_POSTDATA_KIND,
472 (const char *) &pp[1], /* key */
473 NULL,
474 NULL,
475 NULL,
476 xbuf,
477 pp->value_offset,
478 xoff))
479 {
480 pp->state = PP_Error;
481 return MHD_NO;
482 }
483 pp->value_offset += xoff;
484
485 /* are we done with the value? */
486 if (end_of_value_found)
487 {
488 /* we found the end of the value! */
489 if ( ('\n' == post_data[poff]) ||
490 ('\r' == post_data[poff]) )
373 { 491 {
374 case PP_Error: 492 pp->state = PP_ExpectNewLine;
375 return MHD_NO; 493 }
376 case PP_Done: 494 else if ('&' == post_data[poff])
377 /* did not expect to receive more data */ 495 {
378 pp->state = PP_Error; 496 poff++; /* skip '&' */
379 return MHD_NO; 497 pp->state = PP_Init;
380 case PP_Init:
381 equals = 0;
382 while ((equals + poff < post_data_len) &&
383 (post_data[equals + poff] != '='))
384 equals++;
385 if (equals + pp->buffer_pos > pp->buffer_size)
386 {
387 pp->state = PP_Error; /* out of memory */
388 return MHD_NO;
389 }
390 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
391 pp->buffer_pos += equals;
392 if (equals + poff == post_data_len)
393 return MHD_YES; /* no '=' yet */
394 buf[pp->buffer_pos] = '\0'; /* 0-terminate key */
395 pp->buffer_pos = 0; /* reset for next key */
396 MHD_unescape_plus (buf);
397 MHD_http_unescape (buf);
398 poff += equals + 1;
399 pp->state = PP_ProcessValue;
400 pp->value_offset = 0;
401 break;
402 case PP_ProcessValue:
403 /* obtain rest of value from previous iteration */
404 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
405 xoff = pp->xbuf_pos;
406 pp->xbuf_pos = 0;
407
408 /* find last position in input buffer that is part of the value */
409 amper = 0;
410 while ((amper + poff < post_data_len) &&
411 (amper < XBUF_SIZE) &&
412 (post_data[amper + poff] != '&') &&
413 (post_data[amper + poff] != '\n') &&
414 (post_data[amper + poff] != '\r'))
415 amper++;
416 end_of_value_found = ((amper + poff < post_data_len) &&
417 ((post_data[amper + poff] == '&') ||
418 (post_data[amper + poff] == '\n') ||
419 (post_data[amper + poff] == '\r')));
420 /* compute delta, the maximum number of bytes that we will be able to
421 process right now (either amper-limited of xbuf-size limited) */
422 delta = amper;
423 if (delta > XBUF_SIZE - xoff)
424 delta = XBUF_SIZE - xoff;
425
426 /* move input into processing buffer */
427 memcpy (&xbuf[xoff], &post_data[poff], delta);
428 xoff += delta;
429 poff += delta;
430
431 /* find if escape sequence is at the end of the processing buffer;
432 if so, exclude those from processing (reduce delta to point at
433 end of processed region) */
434 delta = xoff;
435 if ((delta > 0) &&
436 ('%' == xbuf[delta - 1]))
437 delta--;
438 else if ((delta > 1) &&
439 ('%' == xbuf[delta - 2]))
440 delta -= 2;
441
442 /* if we have an incomplete escape sequence, save it to
443 pp->xbuf for later */
444 if (delta < xoff)
445 {
446 memcpy (pp->xbuf,
447 &xbuf[delta],
448 xoff - delta);
449 pp->xbuf_pos = xoff - delta;
450 xoff = delta;
451 }
452
453 /* If we have nothing to do (delta == 0) and
454 not just because the value is empty (are
455 waiting for more data), go for next iteration */
456 if ( (0 == xoff) &&
457 (poff == post_data_len))
458 continue;
459
460 /* unescape */
461 xbuf[xoff] = '\0'; /* 0-terminate in preparation */
462 MHD_unescape_plus (xbuf);
463 xoff = MHD_http_unescape (xbuf);
464 /* finally: call application! */
465 pp->must_ikvi = MHD_NO;
466 if (MHD_NO == pp->ikvi (pp->cls,
467 MHD_POSTDATA_KIND,
468 (const char *) &pp[1], /* key */
469 NULL,
470 NULL,
471 NULL,
472 xbuf,
473 pp->value_offset,
474 xoff))
475 {
476 pp->state = PP_Error;
477 return MHD_NO;
478 }
479 pp->value_offset += xoff;
480
481 /* are we done with the value? */
482 if (end_of_value_found)
483 {
484 /* we found the end of the value! */
485 if ( ('\n' == post_data[poff]) ||
486 ('\r' == post_data[poff]) )
487 {
488 pp->state = PP_ExpectNewLine;
489 }
490 else if ('&' == post_data[poff])
491 {
492 poff++; /* skip '&' */
493 pp->state = PP_Init;
494 }
495 }
496 break;
497 case PP_ExpectNewLine:
498 if ( ('\n' == post_data[poff]) ||
499 ('\r' == post_data[poff]) )
500 {
501 poff++;
502 /* we are done, report error if we receive any more... */
503 pp->state = PP_Done;
504 return MHD_YES;
505 }
506 return MHD_NO;
507 default:
508 mhd_panic (mhd_panic_cls,
509 __FILE__,
510 __LINE__,
511 NULL); /* should never happen! */
512 } 498 }
499 }
500 break;
501 case PP_ExpectNewLine:
502 if ( ('\n' == post_data[poff]) ||
503 ('\r' == post_data[poff]) )
504 {
505 poff++;
506 /* we are done, report error if we receive any more... */
507 pp->state = PP_Done;
508 return MHD_YES;
509 }
510 return MHD_NO;
511 default:
512 mhd_panic (mhd_panic_cls,
513 __FILE__,
514 __LINE__,
515 NULL); /* should never happen! */
513 } 516 }
517 }
514 return MHD_YES; 518 return MHD_YES;
515} 519}
516 520
@@ -534,16 +538,16 @@ try_match_header (const char *prefix,
534 if (NULL != *suffix) 538 if (NULL != *suffix)
535 return MHD_NO; 539 return MHD_NO;
536 while (0 != *line) 540 while (0 != *line)
541 {
542 if (MHD_str_equal_caseless_n_ (prefix,
543 line,
544 prefix_len))
537 { 545 {
538 if (MHD_str_equal_caseless_n_ (prefix, 546 *suffix = strdup (&line[prefix_len]);
539 line, 547 return MHD_YES;
540 prefix_len))
541 {
542 *suffix = strdup (&line[prefix_len]);
543 return MHD_YES;
544 }
545 ++line;
546 } 548 }
549 ++line;
550 }
547 return MHD_NO; 551 return MHD_NO;
548} 552}
549 553
@@ -573,40 +577,39 @@ find_boundary (struct MHD_PostProcessor *pp,
573 const char *dash; 577 const char *dash;
574 578
575 if (pp->buffer_pos < 2 + blen) 579 if (pp->buffer_pos < 2 + blen)
576 { 580 {
577 if (pp->buffer_pos == pp->buffer_size) 581 if (pp->buffer_pos == pp->buffer_size)
578 pp->state = PP_Error; /* out of memory */ 582 pp->state = PP_Error; /* out of memory */
579 /* ++(*ioffptr); */ 583 /* ++(*ioffptr); */
580 return MHD_NO; /* not enough data */ 584 return MHD_NO; /* not enough data */
581 } 585 }
582 if ( (0 != memcmp ("--", 586 if ( (0 != memcmp ("--",
583 buf, 587 buf,
584 2)) || 588 2)) ||
585 (0 != memcmp (&buf[2], 589 (0 != memcmp (&buf[2],
586 boundary, 590 boundary,
587 blen))) 591 blen)))
592 {
593 if (pp->state != PP_Init)
588 { 594 {
589 if (pp->state != PP_Init) 595 /* garbage not allowed */
590 { 596 pp->state = PP_Error;
591 /* garbage not allowed */ 597 }
592 pp->state = PP_Error; 598 else
593 } 599 {
600 /* skip over garbage (RFC 2046, 5.1.1) */
601 dash = memchr (buf,
602 '-',
603 pp->buffer_pos);
604 if (NULL == dash)
605 (*ioffptr) += pp->buffer_pos; /* skip entire buffer */
606 else if (dash == buf)
607 (*ioffptr)++; /* at least skip one byte */
594 else 608 else
595 { 609 (*ioffptr) += dash - buf; /* skip to first possible boundary */
596 /* skip over garbage (RFC 2046, 5.1.1) */
597 dash = memchr (buf,
598 '-',
599 pp->buffer_pos);
600 if (NULL == dash)
601 (*ioffptr) += pp->buffer_pos; /* skip entire buffer */
602 else
603 if (dash == buf)
604 (*ioffptr)++; /* at least skip one byte */
605 else
606 (*ioffptr) += dash - buf; /* skip to first possible boundary */
607 }
608 return MHD_NO; /* expected boundary */
609 } 610 }
611 return MHD_NO; /* expected boundary */
612 }
610 /* remove boundary from buffer */ 613 /* remove boundary from buffer */
611 (*ioffptr) += 2 + blen; 614 (*ioffptr) += 2 + blen;
612 /* next: start with headers */ 615 /* next: start with headers */
@@ -625,8 +628,8 @@ find_boundary (struct MHD_PostProcessor *pp,
625 */ 628 */
626static void 629static void
627try_get_value (const char *buf, 630try_get_value (const char *buf,
628 const char *key, 631 const char *key,
629 char **destination) 632 char **destination)
630{ 633{
631 const char *spos; 634 const char *spos;
632 const char *bpos; 635 const char *bpos;
@@ -639,30 +642,30 @@ try_get_value (const char *buf,
639 bpos = buf; 642 bpos = buf;
640 klen = strlen (key); 643 klen = strlen (key);
641 while (NULL != (spos = strstr (bpos, key))) 644 while (NULL != (spos = strstr (bpos, key)))
645 {
646 if ( (spos[klen] != '=') ||
647 ( (spos != buf) &&
648 (spos[-1] != ' ') ) )
642 { 649 {
643 if ( (spos[klen] != '=') || 650 /* no match */
644 ( (spos != buf) && 651 bpos = spos + 1;
645 (spos[-1] != ' ') ) ) 652 continue;
646 {
647 /* no match */
648 bpos = spos + 1;
649 continue;
650 }
651 if (spos[klen + 1] != '"')
652 return; /* not quoted */
653 if (NULL == (endv = strchr (&spos[klen + 2],
654 '\"')))
655 return; /* no end-quote */
656 vlen = endv - spos - klen - 1;
657 *destination = malloc (vlen);
658 if (NULL == *destination)
659 return; /* out of memory */
660 (*destination)[vlen - 1] = '\0';
661 memcpy (*destination,
662 &spos[klen + 2],
663 vlen - 1);
664 return; /* success */
665 } 653 }
654 if (spos[klen + 1] != '"')
655 return; /* not quoted */
656 if (NULL == (endv = strchr (&spos[klen + 2],
657 '\"')))
658 return; /* no end-quote */
659 vlen = endv - spos - klen - 1;
660 *destination = malloc (vlen);
661 if (NULL == *destination)
662 return; /* out of memory */
663 (*destination)[vlen - 1] = '\0';
664 memcpy (*destination,
665 &spos[klen + 2],
666 vlen - 1);
667 return; /* success */
668 }
666} 669}
667 670
668 671
@@ -695,19 +698,19 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
695 (buf[newline] != '\n') ) 698 (buf[newline] != '\n') )
696 newline++; 699 newline++;
697 if (newline == pp->buffer_size) 700 if (newline == pp->buffer_size)
698 { 701 {
699 pp->state = PP_Error; 702 pp->state = PP_Error;
700 return MHD_NO; /* out of memory */ 703 return MHD_NO; /* out of memory */
701 } 704 }
702 if (newline == pp->buffer_pos) 705 if (newline == pp->buffer_pos)
703 return MHD_NO; /* will need more data */ 706 return MHD_NO; /* will need more data */
704 if (0 == newline) 707 if (0 == newline)
705 { 708 {
706 /* empty line - end of headers */ 709 /* empty line - end of headers */
707 pp->skip_rn = RN_Full; 710 pp->skip_rn = RN_Full;
708 pp->state = next_state; 711 pp->state = next_state;
709 return MHD_YES; 712 return MHD_YES;
710 } 713 }
711 /* got an actual header */ 714 /* got an actual header */
712 if (buf[newline] == '\r') 715 if (buf[newline] == '\r')
713 pp->skip_rn = RN_OptN; 716 pp->skip_rn = RN_OptN;
@@ -715,25 +718,25 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
715 if (MHD_str_equal_caseless_n_ ("Content-disposition: ", 718 if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
716 buf, 719 buf,
717 MHD_STATICSTR_LEN_ ("Content-disposition: "))) 720 MHD_STATICSTR_LEN_ ("Content-disposition: ")))
718 { 721 {
719 try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")], 722 try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")],
720 "name", 723 "name",
721 &pp->content_name); 724 &pp->content_name);
722 try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")], 725 try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")],
723 "filename", 726 "filename",
724 &pp->content_filename); 727 &pp->content_filename);
725 } 728 }
726 else 729 else
727 { 730 {
728 try_match_header ("Content-type: ", 731 try_match_header ("Content-type: ",
729 MHD_STATICSTR_LEN_("Content-type: "), 732 MHD_STATICSTR_LEN_ ("Content-type: "),
730 buf, 733 buf,
731 &pp->content_type); 734 &pp->content_type);
732 try_match_header ("Content-Transfer-Encoding: ", 735 try_match_header ("Content-Transfer-Encoding: ",
733 MHD_STATICSTR_LEN_("Content-Transfer-Encoding: "), 736 MHD_STATICSTR_LEN_ ("Content-Transfer-Encoding: "),
734 buf, 737 buf,
735 &pp->content_transfer_encoding); 738 &pp->content_transfer_encoding);
736 } 739 }
737 (*ioffptr) += newline + 1; 740 (*ioffptr) += newline + 1;
738 return MHD_YES; 741 return MHD_YES;
739} 742}
@@ -771,79 +774,79 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
771 (\r\n--+boundary) is part of the value */ 774 (\r\n--+boundary) is part of the value */
772 newline = 0; 775 newline = 0;
773 while (1) 776 while (1)
777 {
778 while (newline + 4 < pp->buffer_pos)
774 { 779 {
775 while (newline + 4 < pp->buffer_pos) 780 r = memchr (&buf[newline],
776 { 781 '\r',
777 r = memchr (&buf[newline], 782 pp->buffer_pos - newline - 4);
778 '\r', 783 if (NULL == r)
779 pp->buffer_pos - newline - 4); 784 {
780 if (NULL == r) 785 newline = pp->buffer_pos - 4;
781 { 786 break;
782 newline = pp->buffer_pos - 4; 787 }
783 break; 788 newline = r - buf;
784 } 789 if (0 == memcmp ("\r\n--",
785 newline = r - buf; 790 &buf[newline],
786 if (0 == memcmp ("\r\n--", 791 4))
787 &buf[newline], 792 break;
788 4)) 793 newline++;
789 break; 794 }
790 newline++; 795 if (newline + blen + 4 <= pp->buffer_pos)
791 } 796 {
792 if (newline + blen + 4 <= pp->buffer_pos) 797 /* can check boundary */
793 { 798 if (0 != memcmp (&buf[newline + 4],
794 /* can check boundary */ 799 boundary,
795 if (0 != memcmp (&buf[newline + 4], 800 blen))
796 boundary, 801 {
797 blen)) 802 /* no boundary, "\r\n--" is part of content, skip */
798 { 803 newline += 4;
799 /* no boundary, "\r\n--" is part of content, skip */ 804 continue;
800 newline += 4; 805 }
801 continue;
802 }
803 else
804 {
805 /* boundary found, process until newline then
806 skip boundary and go back to init */
807 pp->skip_rn = RN_Dash;
808 pp->state = next_state;
809 pp->dash_state = next_dash_state;
810 (*ioffptr) += blen + 4; /* skip boundary as well */
811 buf[newline] = '\0';
812 break;
813 }
814 }
815 else 806 else
816 { 807 {
817 /* cannot check for boundary, process content that 808 /* boundary found, process until newline then
818 we have and check again later; except, if we have 809 skip boundary and go back to init */
819 no content, abort (out of memory) */ 810 pp->skip_rn = RN_Dash;
820 if ( (0 == newline) && 811 pp->state = next_state;
821 (pp->buffer_pos == pp->buffer_size) ) 812 pp->dash_state = next_dash_state;
822 { 813 (*ioffptr) += blen + 4; /* skip boundary as well */
823 pp->state = PP_Error; 814 buf[newline] = '\0';
824 return MHD_NO; 815 break;
825 } 816 }
826 break;
827 }
828 } 817 }
818 else
819 {
820 /* cannot check for boundary, process content that
821 we have and check again later; except, if we have
822 no content, abort (out of memory) */
823 if ( (0 == newline) &&
824 (pp->buffer_pos == pp->buffer_size) )
825 {
826 pp->state = PP_Error;
827 return MHD_NO;
828 }
829 break;
830 }
831 }
829 /* newline is either at beginning of boundary or 832 /* newline is either at beginning of boundary or
830 at least at the last character that we are sure 833 at least at the last character that we are sure
831 is not part of the boundary */ 834 is not part of the boundary */
832 if ( ( (MHD_YES == pp->must_ikvi) || 835 if ( ( (MHD_YES == pp->must_ikvi) ||
833 (0 != newline) ) && 836 (0 != newline) ) &&
834 (MHD_NO == pp->ikvi (pp->cls, 837 (MHD_NO == pp->ikvi (pp->cls,
835 MHD_POSTDATA_KIND, 838 MHD_POSTDATA_KIND,
836 pp->content_name, 839 pp->content_name,
837 pp->content_filename, 840 pp->content_filename,
838 pp->content_type, 841 pp->content_type,
839 pp->content_transfer_encoding, 842 pp->content_transfer_encoding,
840 buf, 843 buf,
841 pp->value_offset, 844 pp->value_offset,
842 newline)) ) 845 newline)) )
843 { 846 {
844 pp->state = PP_Error; 847 pp->state = PP_Error;
845 return MHD_NO; 848 return MHD_NO;
846 } 849 }
847 pp->must_ikvi = MHD_NO; 850 pp->must_ikvi = MHD_NO;
848 pp->value_offset += newline; 851 pp->value_offset += newline;
849 (*ioffptr) += newline; 852 (*ioffptr) += newline;
@@ -860,28 +863,28 @@ free_unmarked (struct MHD_PostProcessor *pp)
860{ 863{
861 if ( (NULL != pp->content_name) && 864 if ( (NULL != pp->content_name) &&
862 (0 == (pp->have & NE_content_name)) ) 865 (0 == (pp->have & NE_content_name)) )
863 { 866 {
864 free (pp->content_name); 867 free (pp->content_name);
865 pp->content_name = NULL; 868 pp->content_name = NULL;
866 } 869 }
867 if ( (NULL != pp->content_type) && 870 if ( (NULL != pp->content_type) &&
868 (0 == (pp->have & NE_content_type)) ) 871 (0 == (pp->have & NE_content_type)) )
869 { 872 {
870 free (pp->content_type); 873 free (pp->content_type);
871 pp->content_type = NULL; 874 pp->content_type = NULL;
872 } 875 }
873 if ( (NULL != pp->content_filename) && 876 if ( (NULL != pp->content_filename) &&
874 (0 == (pp->have & NE_content_filename)) ) 877 (0 == (pp->have & NE_content_filename)) )
875 { 878 {
876 free (pp->content_filename); 879 free (pp->content_filename);
877 pp->content_filename = NULL; 880 pp->content_filename = NULL;
878 } 881 }
879 if ( (NULL != pp->content_transfer_encoding) && 882 if ( (NULL != pp->content_transfer_encoding) &&
880 (0 == (pp->have & NE_content_transfer_encoding)) ) 883 (0 == (pp->have & NE_content_transfer_encoding)) )
881 { 884 {
882 free (pp->content_transfer_encoding); 885 free (pp->content_transfer_encoding);
883 pp->content_transfer_encoding = NULL; 886 pp->content_transfer_encoding = NULL;
884 } 887 }
885} 888}
886 889
887 890
@@ -896,7 +899,7 @@ free_unmarked (struct MHD_PostProcessor *pp)
896static int 899static int
897post_process_multipart (struct MHD_PostProcessor *pp, 900post_process_multipart (struct MHD_PostProcessor *pp,
898 const char *post_data, 901 const char *post_data,
899 size_t post_data_len) 902 size_t post_data_len)
900{ 903{
901 char *buf; 904 char *buf;
902 size_t max; 905 size_t max;
@@ -911,294 +914,294 @@ post_process_multipart (struct MHD_PostProcessor *pp,
911 while ( (poff < post_data_len) || 914 while ( (poff < post_data_len) ||
912 ( (pp->buffer_pos > 0) && 915 ( (pp->buffer_pos > 0) &&
913 (0 != state_changed) ) ) 916 (0 != state_changed) ) )
917 {
918 /* first, move as much input data
919 as possible to our internal buffer */
920 max = pp->buffer_size - pp->buffer_pos;
921 if (max > post_data_len - poff)
922 max = post_data_len - poff;
923 memcpy (&buf[pp->buffer_pos],
924 &post_data[poff],
925 max);
926 poff += max;
927 pp->buffer_pos += max;
928 if ( (0 == max) &&
929 (0 == state_changed) &&
930 (poff < post_data_len) )
914 { 931 {
915 /* first, move as much input data 932 pp->state = PP_Error;
916 as possible to our internal buffer */ 933 return MHD_NO; /* out of memory */
917 max = pp->buffer_size - pp->buffer_pos; 934 }
918 if (max > post_data_len - poff) 935 state_changed = 0;
919 max = post_data_len - poff;
920 memcpy (&buf[pp->buffer_pos],
921 &post_data[poff],
922 max);
923 poff += max;
924 pp->buffer_pos += max;
925 if ( (0 == max) &&
926 (0 == state_changed) &&
927 (poff < post_data_len) )
928 {
929 pp->state = PP_Error;
930 return MHD_NO; /* out of memory */
931 }
932 state_changed = 0;
933 936
934 /* first state machine for '\r'-'\n' and '--' handling */ 937 /* first state machine for '\r'-'\n' and '--' handling */
935 switch (pp->skip_rn) 938 switch (pp->skip_rn)
939 {
940 case RN_Inactive:
941 break;
942 case RN_OptN:
943 if (buf[0] == '\n')
944 {
945 ioff++;
946 pp->skip_rn = RN_Inactive;
947 goto AGAIN;
948 }
949 /* fall-through! */
950 case RN_Dash:
951 if (buf[0] == '-')
952 {
953 ioff++;
954 pp->skip_rn = RN_Dash2;
955 goto AGAIN;
956 }
957 pp->skip_rn = RN_Full;
958 /* fall-through! */
959 case RN_Full:
960 if (buf[0] == '\r')
961 {
962 if ( (pp->buffer_pos > 1) &&
963 ('\n' == buf[1]) )
936 { 964 {
937 case RN_Inactive:
938 break;
939 case RN_OptN:
940 if (buf[0] == '\n')
941 {
942 ioff++;
943 pp->skip_rn = RN_Inactive;
944 goto AGAIN;
945 }
946 /* fall-through! */
947 case RN_Dash:
948 if (buf[0] == '-')
949 {
950 ioff++;
951 pp->skip_rn = RN_Dash2;
952 goto AGAIN;
953 }
954 pp->skip_rn = RN_Full;
955 /* fall-through! */
956 case RN_Full:
957 if (buf[0] == '\r')
958 {
959 if ( (pp->buffer_pos > 1) &&
960 ('\n' == buf[1]) )
961 {
962 pp->skip_rn = RN_Inactive;
963 ioff += 2;
964 }
965 else
966 {
967 pp->skip_rn = RN_OptN;
968 ioff++;
969 }
970 goto AGAIN;
971 }
972 if (buf[0] == '\n')
973 {
974 ioff++;
975 pp->skip_rn = RN_Inactive;
976 goto AGAIN;
977 }
978 pp->skip_rn = RN_Inactive; 965 pp->skip_rn = RN_Inactive;
979 pp->state = PP_Error; 966 ioff += 2;
980 return MHD_NO; /* no '\r\n' */
981 case RN_Dash2:
982 if (buf[0] == '-')
983 {
984 ioff++;
985 pp->skip_rn = RN_Full;
986 pp->state = pp->dash_state;
987 goto AGAIN;
988 }
989 pp->state = PP_Error;
990 break;
991 } 967 }
992 968 else
993 /* main state engine */
994 switch (pp->state)
995 { 969 {
996 case PP_Error: 970 pp->skip_rn = RN_OptN;
971 ioff++;
972 }
973 goto AGAIN;
974 }
975 if (buf[0] == '\n')
976 {
977 ioff++;
978 pp->skip_rn = RN_Inactive;
979 goto AGAIN;
980 }
981 pp->skip_rn = RN_Inactive;
982 pp->state = PP_Error;
983 return MHD_NO; /* no '\r\n' */
984 case RN_Dash2:
985 if (buf[0] == '-')
986 {
987 ioff++;
988 pp->skip_rn = RN_Full;
989 pp->state = pp->dash_state;
990 goto AGAIN;
991 }
992 pp->state = PP_Error;
993 break;
994 }
995
996 /* main state engine */
997 switch (pp->state)
998 {
999 case PP_Error:
1000 return MHD_NO;
1001 case PP_Done:
1002 /* did not expect to receive more data */
1003 pp->state = PP_Error;
1004 return MHD_NO;
1005 case PP_Init:
1006 /**
1007 * Per RFC2046 5.1.1 NOTE TO IMPLEMENTORS, consume anything
1008 * prior to the first multipart boundary:
1009 *
1010 * > There appears to be room for additional information prior
1011 * > to the first boundary delimiter line and following the
1012 * > final boundary delimiter line. These areas should
1013 * > generally be left blank, and implementations must ignore
1014 * > anything that appears before the first boundary delimiter
1015 * > line or after the last one.
1016 */
1017 (void) find_boundary (pp,
1018 pp->boundary,
1019 pp->blen,
1020 &ioff,
1021 PP_ProcessEntryHeaders,
1022 PP_Done);
1023 break;
1024 case PP_NextBoundary:
1025 if (MHD_NO == find_boundary (pp,
1026 pp->boundary,
1027 pp->blen,
1028 &ioff,
1029 PP_ProcessEntryHeaders,
1030 PP_Done))
1031 {
1032 if (pp->state == PP_Error)
997 return MHD_NO; 1033 return MHD_NO;
998 case PP_Done: 1034 goto END;
999 /* did not expect to receive more data */ 1035 }
1036 break;
1037 case PP_ProcessEntryHeaders:
1038 pp->must_ikvi = MHD_YES;
1039 if (MHD_NO ==
1040 process_multipart_headers (pp,
1041 &ioff,
1042 PP_PerformCheckMultipart))
1043 {
1044 if (pp->state == PP_Error)
1045 return MHD_NO;
1046 else
1047 goto END;
1048 }
1049 state_changed = 1;
1050 break;
1051 case PP_PerformCheckMultipart:
1052 if ( (NULL != pp->content_type) &&
1053 (MHD_str_equal_caseless_n_ (pp->content_type,
1054 "multipart/mixed",
1055 MHD_STATICSTR_LEN_ ("multipart/mixed"))))
1056 {
1057 pp->nested_boundary = strstr (pp->content_type,
1058 "boundary=");
1059 if (NULL == pp->nested_boundary)
1060 {
1000 pp->state = PP_Error; 1061 pp->state = PP_Error;
1001 return MHD_NO; 1062 return MHD_NO;
1002 case PP_Init:
1003 /**
1004 * Per RFC2046 5.1.1 NOTE TO IMPLEMENTORS, consume anything
1005 * prior to the first multipart boundary:
1006 *
1007 * > There appears to be room for additional information prior
1008 * > to the first boundary delimiter line and following the
1009 * > final boundary delimiter line. These areas should
1010 * > generally be left blank, and implementations must ignore
1011 * > anything that appears before the first boundary delimiter
1012 * > line or after the last one.
1013 */
1014 (void) find_boundary (pp,
1015 pp->boundary,
1016 pp->blen,
1017 &ioff,
1018 PP_ProcessEntryHeaders,
1019 PP_Done);
1020 break;
1021 case PP_NextBoundary:
1022 if (MHD_NO == find_boundary (pp,
1023 pp->boundary,
1024 pp->blen,
1025 &ioff,
1026 PP_ProcessEntryHeaders,
1027 PP_Done))
1028 {
1029 if (pp->state == PP_Error)
1030 return MHD_NO;
1031 goto END;
1032 }
1033 break;
1034 case PP_ProcessEntryHeaders:
1035 pp->must_ikvi = MHD_YES;
1036 if (MHD_NO ==
1037 process_multipart_headers (pp,
1038 &ioff,
1039 PP_PerformCheckMultipart))
1040 {
1041 if (pp->state == PP_Error)
1042 return MHD_NO;
1043 else
1044 goto END;
1045 }
1046 state_changed = 1;
1047 break;
1048 case PP_PerformCheckMultipart:
1049 if ( (NULL != pp->content_type) &&
1050 (MHD_str_equal_caseless_n_ (pp->content_type,
1051 "multipart/mixed",
1052 MHD_STATICSTR_LEN_ ("multipart/mixed"))))
1053 {
1054 pp->nested_boundary = strstr (pp->content_type,
1055 "boundary=");
1056 if (NULL == pp->nested_boundary)
1057 {
1058 pp->state = PP_Error;
1059 return MHD_NO;
1060 }
1061 pp->nested_boundary =
1062 strdup (&pp->nested_boundary[MHD_STATICSTR_LEN_ ("boundary=")]);
1063 if (NULL == pp->nested_boundary)
1064 {
1065 /* out of memory */
1066 pp->state = PP_Error;
1067 return MHD_NO;
1068 }
1069 /* free old content type, we will need that field
1070 for the content type of the nested elements */
1071 free (pp->content_type);
1072 pp->content_type = NULL;
1073 pp->nlen = strlen (pp->nested_boundary);
1074 pp->state = PP_Nested_Init;
1075 state_changed = 1;
1076 break;
1077 }
1078 pp->state = PP_ProcessValueToBoundary;
1079 pp->value_offset = 0;
1080 state_changed = 1;
1081 break;
1082 case PP_ProcessValueToBoundary:
1083 if (MHD_NO == process_value_to_boundary (pp,
1084 &ioff,
1085 pp->boundary,
1086 pp->blen,
1087 PP_PerformCleanup,
1088 PP_Done))
1089 {
1090 if (pp->state == PP_Error)
1091 return MHD_NO;
1092 break;
1093 }
1094 break;
1095 case PP_PerformCleanup:
1096 /* clean up state of one multipart form-data element! */
1097 pp->have = NE_none;
1098 free_unmarked (pp);
1099 if (NULL != pp->nested_boundary)
1100 {
1101 free (pp->nested_boundary);
1102 pp->nested_boundary = NULL;
1103 }
1104 pp->state = PP_ProcessEntryHeaders;
1105 state_changed = 1;
1106 break;
1107 case PP_Nested_Init:
1108 if (NULL == pp->nested_boundary)
1109 {
1110 pp->state = PP_Error;
1111 return MHD_NO;
1112 }
1113 if (MHD_NO == find_boundary (pp,
1114 pp->nested_boundary,
1115 pp->nlen,
1116 &ioff,
1117 PP_Nested_PerformMarking,
1118 PP_NextBoundary /* or PP_Error? */ ))
1119 {
1120 if (pp->state == PP_Error)
1121 return MHD_NO;
1122 goto END;
1123 }
1124 break;
1125 case PP_Nested_PerformMarking:
1126 /* remember what headers were given
1127 globally */
1128 pp->have = NE_none;
1129 if (NULL != pp->content_name)
1130 pp->have |= NE_content_name;
1131 if (NULL != pp->content_type)
1132 pp->have |= NE_content_type;
1133 if (NULL != pp->content_filename)
1134 pp->have |= NE_content_filename;
1135 if (NULL != pp->content_transfer_encoding)
1136 pp->have |= NE_content_transfer_encoding;
1137 pp->state = PP_Nested_ProcessEntryHeaders;
1138 state_changed = 1;
1139 break;
1140 case PP_Nested_ProcessEntryHeaders:
1141 pp->value_offset = 0;
1142 if (MHD_NO ==
1143 process_multipart_headers (pp,
1144 &ioff,
1145 PP_Nested_ProcessValueToBoundary))
1146 {
1147 if (pp->state == PP_Error)
1148 return MHD_NO;
1149 else
1150 goto END;
1151 }
1152 state_changed = 1;
1153 break;
1154 case PP_Nested_ProcessValueToBoundary:
1155 if (MHD_NO == process_value_to_boundary (pp,
1156 &ioff,
1157 pp->nested_boundary,
1158 pp->nlen,
1159 PP_Nested_PerformCleanup,
1160 PP_NextBoundary))
1161 {
1162 if (pp->state == PP_Error)
1163 return MHD_NO;
1164 break;
1165 }
1166 break;
1167 case PP_Nested_PerformCleanup:
1168 free_unmarked (pp);
1169 pp->state = PP_Nested_ProcessEntryHeaders;
1170 state_changed = 1;
1171 break;
1172 default:
1173 mhd_panic (mhd_panic_cls,
1174 __FILE__,
1175 __LINE__,
1176 NULL); /* should never happen! */
1177 } 1063 }
1178 AGAIN: 1064 pp->nested_boundary =
1179 if (ioff > 0) 1065 strdup (&pp->nested_boundary[MHD_STATICSTR_LEN_ ("boundary=")]);
1066 if (NULL == pp->nested_boundary)
1180 { 1067 {
1181 memmove (buf, 1068 /* out of memory */
1182 &buf[ioff], 1069 pp->state = PP_Error;
1183 pp->buffer_pos - ioff); 1070 return MHD_NO;
1184 pp->buffer_pos -= ioff;
1185 ioff = 0;
1186 state_changed = 1;
1187 } 1071 }
1072 /* free old content type, we will need that field
1073 for the content type of the nested elements */
1074 free (pp->content_type);
1075 pp->content_type = NULL;
1076 pp->nlen = strlen (pp->nested_boundary);
1077 pp->state = PP_Nested_Init;
1078 state_changed = 1;
1079 break;
1080 }
1081 pp->state = PP_ProcessValueToBoundary;
1082 pp->value_offset = 0;
1083 state_changed = 1;
1084 break;
1085 case PP_ProcessValueToBoundary:
1086 if (MHD_NO == process_value_to_boundary (pp,
1087 &ioff,
1088 pp->boundary,
1089 pp->blen,
1090 PP_PerformCleanup,
1091 PP_Done))
1092 {
1093 if (pp->state == PP_Error)
1094 return MHD_NO;
1095 break;
1096 }
1097 break;
1098 case PP_PerformCleanup:
1099 /* clean up state of one multipart form-data element! */
1100 pp->have = NE_none;
1101 free_unmarked (pp);
1102 if (NULL != pp->nested_boundary)
1103 {
1104 free (pp->nested_boundary);
1105 pp->nested_boundary = NULL;
1106 }
1107 pp->state = PP_ProcessEntryHeaders;
1108 state_changed = 1;
1109 break;
1110 case PP_Nested_Init:
1111 if (NULL == pp->nested_boundary)
1112 {
1113 pp->state = PP_Error;
1114 return MHD_NO;
1115 }
1116 if (MHD_NO == find_boundary (pp,
1117 pp->nested_boundary,
1118 pp->nlen,
1119 &ioff,
1120 PP_Nested_PerformMarking,
1121 PP_NextBoundary /* or PP_Error? */))
1122 {
1123 if (pp->state == PP_Error)
1124 return MHD_NO;
1125 goto END;
1126 }
1127 break;
1128 case PP_Nested_PerformMarking:
1129 /* remember what headers were given
1130 globally */
1131 pp->have = NE_none;
1132 if (NULL != pp->content_name)
1133 pp->have |= NE_content_name;
1134 if (NULL != pp->content_type)
1135 pp->have |= NE_content_type;
1136 if (NULL != pp->content_filename)
1137 pp->have |= NE_content_filename;
1138 if (NULL != pp->content_transfer_encoding)
1139 pp->have |= NE_content_transfer_encoding;
1140 pp->state = PP_Nested_ProcessEntryHeaders;
1141 state_changed = 1;
1142 break;
1143 case PP_Nested_ProcessEntryHeaders:
1144 pp->value_offset = 0;
1145 if (MHD_NO ==
1146 process_multipart_headers (pp,
1147 &ioff,
1148 PP_Nested_ProcessValueToBoundary))
1149 {
1150 if (pp->state == PP_Error)
1151 return MHD_NO;
1152 else
1153 goto END;
1154 }
1155 state_changed = 1;
1156 break;
1157 case PP_Nested_ProcessValueToBoundary:
1158 if (MHD_NO == process_value_to_boundary (pp,
1159 &ioff,
1160 pp->nested_boundary,
1161 pp->nlen,
1162 PP_Nested_PerformCleanup,
1163 PP_NextBoundary))
1164 {
1165 if (pp->state == PP_Error)
1166 return MHD_NO;
1167 break;
1168 }
1169 break;
1170 case PP_Nested_PerformCleanup:
1171 free_unmarked (pp);
1172 pp->state = PP_Nested_ProcessEntryHeaders;
1173 state_changed = 1;
1174 break;
1175 default:
1176 mhd_panic (mhd_panic_cls,
1177 __FILE__,
1178 __LINE__,
1179 NULL); /* should never happen! */
1188 } 1180 }
1189END: 1181AGAIN:
1190 if (0 != ioff) 1182 if (ioff > 0)
1191 { 1183 {
1192 memmove (buf, 1184 memmove (buf,
1193 &buf[ioff], 1185 &buf[ioff],
1194 pp->buffer_pos - ioff); 1186 pp->buffer_pos - ioff);
1195 pp->buffer_pos -= ioff; 1187 pp->buffer_pos -= ioff;
1188 ioff = 0;
1189 state_changed = 1;
1196 } 1190 }
1191 }
1192END:
1193 if (0 != ioff)
1194 {
1195 memmove (buf,
1196 &buf[ioff],
1197 pp->buffer_pos - ioff);
1198 pp->buffer_pos -= ioff;
1199 }
1197 if (poff < post_data_len) 1200 if (poff < post_data_len)
1198 { 1201 {
1199 pp->state = PP_Error; 1202 pp->state = PP_Error;
1200 return MHD_NO; /* serious error */ 1203 return MHD_NO; /* serious error */
1201 } 1204 }
1202 return MHD_YES; 1205 return MHD_YES;
1203} 1206}
1204 1207
@@ -1227,13 +1230,15 @@ MHD_post_process (struct MHD_PostProcessor *pp,
1227 return MHD_NO; 1230 return MHD_NO;
1228 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, 1231 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
1229 pp->encoding, 1232 pp->encoding,
1230 MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 1233 MHD_STATICSTR_LEN_ (
1234 MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
1231 return post_process_urlencoded (pp, 1235 return post_process_urlencoded (pp,
1232 post_data, 1236 post_data,
1233 post_data_len); 1237 post_data_len);
1234 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, 1238 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
1235 pp->encoding, 1239 pp->encoding,
1236 MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 1240 MHD_STATICSTR_LEN_ (
1241 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
1237 return post_process_multipart (pp, 1242 return post_process_multipart (pp,
1238 post_data, 1243 post_data,
1239 post_data_len); 1244 post_data_len);
diff --git a/src/microhttpd/reason_phrase.c b/src/microhttpd/reason_phrase.c
index d6fe8330..7891854a 100644
--- a/src/microhttpd/reason_phrase.c
+++ b/src/microhttpd/reason_phrase.c
@@ -28,7 +28,7 @@
28#include "microhttpd.h" 28#include "microhttpd.h"
29 29
30#ifndef NULL 30#ifndef NULL
31#define NULL ((void*)0) 31#define NULL ((void*) 0)
32#endif 32#endif
33 33
34static const char *const invalid_hundred[] = { 34static const char *const invalid_hundred[] = {
@@ -36,121 +36,121 @@ static const char *const invalid_hundred[] = {
36}; 36};
37 37
38static const char *const one_hundred[] = { 38static const char *const one_hundred[] = {
39 /* 100 */ "Continue" /* RFC7231, Section 6.2.1 */, 39 /* 100 */ "Continue" /* RFC7231, Section 6.2.1 */,
40 /* 101 */ "Switching Protocols" /* RFC7231, Section 6.2.2 */, 40 /* 101 */ "Switching Protocols" /* RFC7231, Section 6.2.2 */,
41 /* 102 */ "Processing" /* RFC2518 */, 41 /* 102 */ "Processing" /* RFC2518 */,
42 /* 103 */ "Early Hints" /* RFC8297 */ 42 /* 103 */ "Early Hints" /* RFC8297 */
43}; 43};
44 44
45static const char *const two_hundred[] = { 45static const char *const two_hundred[] = {
46 /* 200 */ "OK" /* RFC7231, Section 6.3.1 */, 46 /* 200 */ "OK" /* RFC7231, Section 6.3.1 */,
47 /* 201 */ "Created" /* RFC7231, Section 6.3.2 */, 47 /* 201 */ "Created" /* RFC7231, Section 6.3.2 */,
48 /* 202 */ "Accepted" /* RFC7231, Section 6.3.3 */, 48 /* 202 */ "Accepted" /* RFC7231, Section 6.3.3 */,
49 /* 203 */ "Non-Authoritative Information" /* RFC7231, Section 6.3.4 */, 49 /* 203 */ "Non-Authoritative Information" /* RFC7231, Section 6.3.4 */,
50 /* 204 */ "No Content" /* RFC7231, Section 6.3.5 */, 50 /* 204 */ "No Content" /* RFC7231, Section 6.3.5 */,
51 /* 205 */ "Reset Content" /* RFC7231, Section 6.3.6 */, 51 /* 205 */ "Reset Content" /* RFC7231, Section 6.3.6 */,
52 /* 206 */ "Partial Content" /* RFC7233, Section 4.1 */, 52 /* 206 */ "Partial Content" /* RFC7233, Section 4.1 */,
53 /* 207 */ "Multi-Status" /* RFC4918 */, 53 /* 207 */ "Multi-Status" /* RFC4918 */,
54 /* 208 */ "Already Reported" /* RFC5842 */, 54 /* 208 */ "Already Reported" /* RFC5842 */,
55 /* 209 */ "Unknown" /* Not used */, 55 /* 209 */ "Unknown" /* Not used */,
56 /* 210 */ "Unknown" /* Not used */, 56 /* 210 */ "Unknown" /* Not used */,
57 /* 211 */ "Unknown" /* Not used */, 57 /* 211 */ "Unknown" /* Not used */,
58 /* 212 */ "Unknown" /* Not used */, 58 /* 212 */ "Unknown" /* Not used */,
59 /* 213 */ "Unknown" /* Not used */, 59 /* 213 */ "Unknown" /* Not used */,
60 /* 214 */ "Unknown" /* Not used */, 60 /* 214 */ "Unknown" /* Not used */,
61 /* 215 */ "Unknown" /* Not used */, 61 /* 215 */ "Unknown" /* Not used */,
62 /* 216 */ "Unknown" /* Not used */, 62 /* 216 */ "Unknown" /* Not used */,
63 /* 217 */ "Unknown" /* Not used */, 63 /* 217 */ "Unknown" /* Not used */,
64 /* 218 */ "Unknown" /* Not used */, 64 /* 218 */ "Unknown" /* Not used */,
65 /* 219 */ "Unknown" /* Not used */, 65 /* 219 */ "Unknown" /* Not used */,
66 /* 220 */ "Unknown" /* Not used */, 66 /* 220 */ "Unknown" /* Not used */,
67 /* 221 */ "Unknown" /* Not used */, 67 /* 221 */ "Unknown" /* Not used */,
68 /* 222 */ "Unknown" /* Not used */, 68 /* 222 */ "Unknown" /* Not used */,
69 /* 223 */ "Unknown" /* Not used */, 69 /* 223 */ "Unknown" /* Not used */,
70 /* 224 */ "Unknown" /* Not used */, 70 /* 224 */ "Unknown" /* Not used */,
71 /* 225 */ "Unknown" /* Not used */, 71 /* 225 */ "Unknown" /* Not used */,
72 /* 226 */ "IM Used" /* RFC3229 */ 72 /* 226 */ "IM Used" /* RFC3229 */
73}; 73};
74 74
75static const char *const three_hundred[] = { 75static const char *const three_hundred[] = {
76 /* 300 */ "Multiple Choices" /* RFC7231, Section 6.4.1 */, 76 /* 300 */ "Multiple Choices" /* RFC7231, Section 6.4.1 */,
77 /* 301 */ "Moved Permanently" /* RFC7231, Section 6.4.2 */, 77 /* 301 */ "Moved Permanently" /* RFC7231, Section 6.4.2 */,
78 /* 302 */ "Found" /* RFC7231, Section 6.4.3 */, 78 /* 302 */ "Found" /* RFC7231, Section 6.4.3 */,
79 /* 303 */ "See Other" /* RFC7231, Section 6.4.4 */, 79 /* 303 */ "See Other" /* RFC7231, Section 6.4.4 */,
80 /* 304 */ "Not Modified" /* RFC7232, Section 4.1 */, 80 /* 304 */ "Not Modified" /* RFC7232, Section 4.1 */,
81 /* 305 */ "Use Proxy" /* RFC7231, Section 6.4.5 */, 81 /* 305 */ "Use Proxy" /* RFC7231, Section 6.4.5 */,
82 /* 306 */ "Switch Proxy" /* Not used! RFC7231, Section 6.4.6 */, 82 /* 306 */ "Switch Proxy" /* Not used! RFC7231, Section 6.4.6 */,
83 /* 307 */ "Temporary Redirect" /* RFC7231, Section 6.4.7 */, 83 /* 307 */ "Temporary Redirect" /* RFC7231, Section 6.4.7 */,
84 /* 308 */ "Permanent Redirect" /* RFC7538 */ 84 /* 308 */ "Permanent Redirect" /* RFC7538 */
85}; 85};
86 86
87static const char *const four_hundred[] = { 87static const char *const four_hundred[] = {
88 /* 400 */ "Bad Request" /* RFC7231, Section 6.5.1 */, 88 /* 400 */ "Bad Request" /* RFC7231, Section 6.5.1 */,
89 /* 401 */ "Unauthorized" /* RFC7235, Section 3.1 */, 89 /* 401 */ "Unauthorized" /* RFC7235, Section 3.1 */,
90 /* 402 */ "Payment Required" /* RFC7231, Section 6.5.2 */, 90 /* 402 */ "Payment Required" /* RFC7231, Section 6.5.2 */,
91 /* 403 */ "Forbidden" /* RFC7231, Section 6.5.3 */, 91 /* 403 */ "Forbidden" /* RFC7231, Section 6.5.3 */,
92 /* 404 */ "Not Found" /* RFC7231, Section 6.5.4 */, 92 /* 404 */ "Not Found" /* RFC7231, Section 6.5.4 */,
93 /* 405 */ "Method Not Allowed" /* RFC7231, Section 6.5.5 */, 93 /* 405 */ "Method Not Allowed" /* RFC7231, Section 6.5.5 */,
94 /* 406 */ "Not Acceptable" /* RFC7231, Section 6.5.6 */, 94 /* 406 */ "Not Acceptable" /* RFC7231, Section 6.5.6 */,
95 /* 407 */ "Proxy Authentication Required" /* RFC7235, Section 3.2 */, 95 /* 407 */ "Proxy Authentication Required" /* RFC7235, Section 3.2 */,
96 /* 408 */ "Request Timeout" /* RFC7231, Section 6.5.7 */, 96 /* 408 */ "Request Timeout" /* RFC7231, Section 6.5.7 */,
97 /* 409 */ "Conflict" /* RFC7231, Section 6.5.8 */, 97 /* 409 */ "Conflict" /* RFC7231, Section 6.5.8 */,
98 /* 410 */ "Gone" /* RFC7231, Section 6.5.9 */, 98 /* 410 */ "Gone" /* RFC7231, Section 6.5.9 */,
99 /* 411 */ "Length Required" /* RFC7231, Section 6.5.10 */, 99 /* 411 */ "Length Required" /* RFC7231, Section 6.5.10 */,
100 /* 412 */ "Precondition Failed" /* RFC7232, Section 4.2; RFC8144, Section 3.2 */, 100 /* 412 */ "Precondition Failed" /* RFC7232, Section 4.2; RFC8144, Section 3.2 */,
101 /* 413 */ "Payload Too Large" /* RFC7231, Section 6.5.11 */, 101 /* 413 */ "Payload Too Large" /* RFC7231, Section 6.5.11 */,
102 /* 414 */ "URI Too Long" /* RFC7231, Section 6.5.12 */, 102 /* 414 */ "URI Too Long" /* RFC7231, Section 6.5.12 */,
103 /* 415 */ "Unsupported Media Type" /* RFC7231, Section 6.5.13; RFC7694, Section 3 */, 103 /* 415 */ "Unsupported Media Type" /* RFC7231, Section 6.5.13; RFC7694, Section 3 */,
104 /* 416 */ "Range Not Satisfiable" /* RFC7233, Section 4.4 */, 104 /* 416 */ "Range Not Satisfiable" /* RFC7233, Section 4.4 */,
105 /* 417 */ "Expectation Failed" /* RFC7231, Section 6.5.14 */, 105 /* 417 */ "Expectation Failed" /* RFC7231, Section 6.5.14 */,
106 /* 418 */ "Unknown" /* Not used */, 106 /* 418 */ "Unknown" /* Not used */,
107 /* 419 */ "Unknown" /* Not used */, 107 /* 419 */ "Unknown" /* Not used */,
108 /* 420 */ "Unknown" /* Not used */, 108 /* 420 */ "Unknown" /* Not used */,
109 /* 421 */ "Misdirected Request" /* RFC7540, Section 9.1.2 */, 109 /* 421 */ "Misdirected Request" /* RFC7540, Section 9.1.2 */,
110 /* 422 */ "Unprocessable Entity" /* RFC4918 */, 110 /* 422 */ "Unprocessable Entity" /* RFC4918 */,
111 /* 423 */ "Locked" /* RFC4918 */, 111 /* 423 */ "Locked" /* RFC4918 */,
112 /* 424 */ "Failed Dependency" /* RFC4918 */, 112 /* 424 */ "Failed Dependency" /* RFC4918 */,
113 /* 425 */ "Too Early" /* RFC8470 */, 113 /* 425 */ "Too Early" /* RFC8470 */,
114 /* 426 */ "Upgrade Required" /* RFC7231, Section 6.5.15 */, 114 /* 426 */ "Upgrade Required" /* RFC7231, Section 6.5.15 */,
115 /* 427 */ "Unknown" /* Not used */, 115 /* 427 */ "Unknown" /* Not used */,
116 /* 428 */ "Precondition Required" /* RFC6585 */, 116 /* 428 */ "Precondition Required" /* RFC6585 */,
117 /* 429 */ "Too Many Requests" /* RFC6585 */, 117 /* 429 */ "Too Many Requests" /* RFC6585 */,
118 /* 430 */ "Unknown" /* Not used */, 118 /* 430 */ "Unknown" /* Not used */,
119 /* 431 */ "Request Header Fields Too Large" /* RFC6585 */, 119 /* 431 */ "Request Header Fields Too Large" /* RFC6585 */,
120 /* 432 */ "Unknown" /* Not used */, 120 /* 432 */ "Unknown" /* Not used */,
121 /* 433 */ "Unknown" /* Not used */, 121 /* 433 */ "Unknown" /* Not used */,
122 /* 434 */ "Unknown" /* Not used */, 122 /* 434 */ "Unknown" /* Not used */,
123 /* 435 */ "Unknown" /* Not used */, 123 /* 435 */ "Unknown" /* Not used */,
124 /* 436 */ "Unknown" /* Not used */, 124 /* 436 */ "Unknown" /* Not used */,
125 /* 437 */ "Unknown" /* Not used */, 125 /* 437 */ "Unknown" /* Not used */,
126 /* 438 */ "Unknown" /* Not used */, 126 /* 438 */ "Unknown" /* Not used */,
127 /* 439 */ "Unknown" /* Not used */, 127 /* 439 */ "Unknown" /* Not used */,
128 /* 440 */ "Unknown" /* Not used */, 128 /* 440 */ "Unknown" /* Not used */,
129 /* 441 */ "Unknown" /* Not used */, 129 /* 441 */ "Unknown" /* Not used */,
130 /* 442 */ "Unknown" /* Not used */, 130 /* 442 */ "Unknown" /* Not used */,
131 /* 443 */ "Unknown" /* Not used */, 131 /* 443 */ "Unknown" /* Not used */,
132 /* 444 */ "Unknown" /* Not used */, 132 /* 444 */ "Unknown" /* Not used */,
133 /* 445 */ "Unknown" /* Not used */, 133 /* 445 */ "Unknown" /* Not used */,
134 /* 446 */ "Unknown" /* Not used */, 134 /* 446 */ "Unknown" /* Not used */,
135 /* 447 */ "Unknown" /* Not used */, 135 /* 447 */ "Unknown" /* Not used */,
136 /* 448 */ "Unknown" /* Not used */, 136 /* 448 */ "Unknown" /* Not used */,
137 /* 449 */ "Reply With" /* MS IIS extension */, 137 /* 449 */ "Reply With" /* MS IIS extension */,
138 /* 450 */ "Blocked by Windows Parental Controls" /* MS extension */, 138 /* 450 */ "Blocked by Windows Parental Controls" /* MS extension */,
139 /* 451 */ "Unavailable For Legal Reasons" /* RFC7725 */ 139 /* 451 */ "Unavailable For Legal Reasons" /* RFC7725 */
140}; 140};
141 141
142static const char *const five_hundred[] = { 142static const char *const five_hundred[] = {
143 /* 500 */ "Internal Server Error" /* RFC7231, Section 6.6.1 */, 143 /* 500 */ "Internal Server Error" /* RFC7231, Section 6.6.1 */,
144 /* 501 */ "Not Implemented" /* RFC7231, Section 6.6.2 */, 144 /* 501 */ "Not Implemented" /* RFC7231, Section 6.6.2 */,
145 /* 502 */ "Bad Gateway" /* RFC7231, Section 6.6.3 */, 145 /* 502 */ "Bad Gateway" /* RFC7231, Section 6.6.3 */,
146 /* 503 */ "Service Unavailable" /* RFC7231, Section 6.6.4 */, 146 /* 503 */ "Service Unavailable" /* RFC7231, Section 6.6.4 */,
147 /* 504 */ "Gateway Timeout" /* RFC7231, Section 6.6.5 */, 147 /* 504 */ "Gateway Timeout" /* RFC7231, Section 6.6.5 */,
148 /* 505 */ "HTTP Version Not Supported" /* RFC7231, Section 6.6.6 */, 148 /* 505 */ "HTTP Version Not Supported" /* RFC7231, Section 6.6.6 */,
149 /* 506 */ "Variant Also Negotiates" /* RFC2295 */, 149 /* 506 */ "Variant Also Negotiates" /* RFC2295 */,
150 /* 507 */ "Insufficient Storage" /* RFC4918 */, 150 /* 507 */ "Insufficient Storage" /* RFC4918 */,
151 /* 508 */ "Loop Detected" /* RFC5842 */, 151 /* 508 */ "Loop Detected" /* RFC5842 */,
152 /* 509 */ "Bandwidth Limit Exceeded" /* Apache extension */, 152 /* 509 */ "Bandwidth Limit Exceeded" /* Apache extension */,
153 /* 510 */ "Not Extended" /* RFC2774 */, 153 /* 510 */ "Not Extended" /* RFC2774 */,
154 /* 511 */ "Network Authentication Required" /* RFC6585 */ 154 /* 511 */ "Network Authentication Required" /* RFC6585 */
155}; 155};
156 156
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 65ea7b09..112a622a 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -101,17 +101,17 @@ add_response_entry (struct MHD_Response *response,
101 if (NULL == (hdr = malloc (sizeof (struct MHD_HTTP_Header)))) 101 if (NULL == (hdr = malloc (sizeof (struct MHD_HTTP_Header))))
102 return MHD_NO; 102 return MHD_NO;
103 if (NULL == (hdr->header = strdup (header))) 103 if (NULL == (hdr->header = strdup (header)))
104 { 104 {
105 free (hdr); 105 free (hdr);
106 return MHD_NO; 106 return MHD_NO;
107 } 107 }
108 hdr->header_size = strlen (header); 108 hdr->header_size = strlen (header);
109 if (NULL == (hdr->value = strdup (content))) 109 if (NULL == (hdr->value = strdup (content)))
110 { 110 {
111 free (hdr->header); 111 free (hdr->header);
112 free (hdr); 112 free (hdr);
113 return MHD_NO; 113 return MHD_NO;
114 } 114 }
115 hdr->value_size = strlen (content); 115 hdr->value_size = strlen (content);
116 hdr->kind = kind; 116 hdr->kind = kind;
117 hdr->next = response->first_header; 117 hdr->next = response->first_header;
@@ -140,25 +140,25 @@ MHD_add_response_header (struct MHD_Response *response,
140 "identity")) && 140 "identity")) &&
141 (! MHD_str_equal_caseless_ (content, 141 (! MHD_str_equal_caseless_ (content,
142 "chunked")) ) 142 "chunked")) )
143 { 143 {
144 /* Setting transfer encodings other than "identity" or 144 /* Setting transfer encodings other than "identity" or
145 "chunked" is not allowed. Note that MHD will set the 145 "chunked" is not allowed. Note that MHD will set the
146 correct transfer encoding if required automatically. */ 146 correct transfer encoding if required automatically. */
147 /* NOTE: for compressed bodies, use the "Content-encoding" header */ 147 /* NOTE: for compressed bodies, use the "Content-encoding" header */
148 return MHD_NO; 148 return MHD_NO;
149 } 149 }
150 if (MHD_str_equal_caseless_ (header, 150 if (MHD_str_equal_caseless_ (header,
151 MHD_HTTP_HEADER_CONTENT_LENGTH)) 151 MHD_HTTP_HEADER_CONTENT_LENGTH))
152 { 152 {
153 /* MHD will set Content-length if allowed and possible, 153 /* MHD will set Content-length if allowed and possible,
154 reject attempt by application */ 154 reject attempt by application */
155 return MHD_NO; 155 return MHD_NO;
156 } 156 }
157 157
158 return add_response_entry (response, 158 return add_response_entry (response,
159 MHD_HEADER_KIND, 159 MHD_HEADER_KIND,
160 header, 160 header,
161 content); 161 content);
162} 162}
163 163
164 164
@@ -177,9 +177,9 @@ MHD_add_response_footer (struct MHD_Response *response,
177 const char *content) 177 const char *content)
178{ 178{
179 return add_response_entry (response, 179 return add_response_entry (response,
180 MHD_FOOTER_KIND, 180 MHD_FOOTER_KIND,
181 footer, 181 footer,
182 content); 182 content);
183} 183}
184 184
185 185
@@ -203,35 +203,35 @@ MHD_del_response_header (struct MHD_Response *response,
203 size_t content_len; 203 size_t content_len;
204 204
205 if ( (NULL == header) || 205 if ( (NULL == header) ||
206 (NULL == content) ) 206 (NULL == content) )
207 return MHD_NO; 207 return MHD_NO;
208 header_len = strlen (header); 208 header_len = strlen (header);
209 content_len = strlen (content); 209 content_len = strlen (content);
210 prev = NULL; 210 prev = NULL;
211 pos = response->first_header; 211 pos = response->first_header;
212 while (NULL != pos) 212 while (NULL != pos)
213 {
214 if ((header_len == pos->header_size) &&
215 (content_len == pos->value_size) &&
216 (0 == memcmp (header,
217 pos->header,
218 header_len)) &&
219 (0 == memcmp (content,
220 pos->value,
221 content_len)))
213 { 222 {
214 if ((header_len == pos->header_size) && 223 free (pos->header);
215 (content_len == pos->value_size) && 224 free (pos->value);
216 (0 == memcmp (header, 225 if (NULL == prev)
217 pos->header, 226 response->first_header = pos->next;
218 header_len)) && 227 else
219 (0 == memcmp (content, 228 prev->next = pos->next;
220 pos->value, 229 free (pos);
221 content_len))) 230 return MHD_YES;
222 {
223 free (pos->header);
224 free (pos->value);
225 if (NULL == prev)
226 response->first_header = pos->next;
227 else
228 prev->next = pos->next;
229 free (pos);
230 return MHD_YES;
231 }
232 prev = pos;
233 pos = pos->next;
234 } 231 }
232 prev = pos;
233 pos = pos->next;
234 }
235 return MHD_NO; 235 return MHD_NO;
236} 236}
237 237
@@ -257,15 +257,15 @@ MHD_get_response_headers (struct MHD_Response *response,
257 for (pos = response->first_header; 257 for (pos = response->first_header;
258 NULL != pos; 258 NULL != pos;
259 pos = pos->next) 259 pos = pos->next)
260 { 260 {
261 numHeaders++; 261 numHeaders++;
262 if ((NULL != iterator) && 262 if ((NULL != iterator) &&
263 (MHD_YES != iterator (iterator_cls, 263 (MHD_YES != iterator (iterator_cls,
264 pos->kind, 264 pos->kind,
265 pos->header, 265 pos->header,
266 pos->value))) 266 pos->value)))
267 break; 267 break;
268 } 268 }
269 return numHeaders; 269 return numHeaders;
270} 270}
271 271
@@ -292,11 +292,11 @@ MHD_get_response_header (struct MHD_Response *response,
292 for (pos = response->first_header; 292 for (pos = response->first_header;
293 NULL != pos; 293 NULL != pos;
294 pos = pos->next) 294 pos = pos->next)
295 { 295 {
296 if ((pos->header_size == key_size) && 296 if ((pos->header_size == key_size) &&
297 (MHD_str_equal_caseless_bin_n_ (pos->header, key, pos->header_size))) 297 (MHD_str_equal_caseless_bin_n_ (pos->header, key, pos->header_size)))
298 return pos->value; 298 return pos->value;
299 } 299 }
300 return NULL; 300 return NULL;
301} 301}
302 302
@@ -333,22 +333,22 @@ MHD_check_response_header_token_ci (const struct MHD_Response *response,
333 return false; 333 return false;
334 334
335 /* Token must not contain binary zero! */ 335 /* Token must not contain binary zero! */
336 mhd_assert(strlen(token) == token_len); 336 mhd_assert (strlen (token) == token_len);
337 337
338 for (pos = response->first_header; 338 for (pos = response->first_header;
339 NULL != pos; 339 NULL != pos;
340 pos = pos->next) 340 pos = pos->next)
341 { 341 {
342 if ( (pos->kind == MHD_HEADER_KIND) && 342 if ( (pos->kind == MHD_HEADER_KIND) &&
343 (key_len == pos->header_size) && 343 (key_len == pos->header_size) &&
344 MHD_str_equal_caseless_bin_n_ (pos->header, 344 MHD_str_equal_caseless_bin_n_ (pos->header,
345 key, 345 key,
346 key_len) && 346 key_len) &&
347 MHD_str_has_token_caseless_ (pos->value, 347 MHD_str_has_token_caseless_ (pos->value,
348 token, 348 token,
349 token_len) ) 349 token_len) )
350 return true; 350 return true;
351 } 351 }
352 return false; 352 return false;
353} 353}
354 354
@@ -380,7 +380,8 @@ MHD_create_response_from_callback (uint64_t size,
380 380
381 if ((NULL == crc) || (0 == block_size)) 381 if ((NULL == crc) || (0 == block_size))
382 return NULL; 382 return NULL;
383 if (NULL == (response = MHD_calloc_ (1, sizeof (struct MHD_Response) + block_size))) 383 if (NULL == (response = MHD_calloc_ (1, sizeof (struct MHD_Response)
384 + block_size)))
384 return NULL; 385 return NULL;
385 response->fd = -1; 386 response->fd = -1;
386 response->data = (void *) &response[1]; 387 response->data = (void *) &response[1];
@@ -452,28 +453,28 @@ file_reader (void *cls,
452 size_t max) 453 size_t max)
453{ 454{
454 struct MHD_Response *response = cls; 455 struct MHD_Response *response = cls;
455#if !defined(_WIN32) || defined(__CYGWIN__) 456#if ! defined(_WIN32) || defined(__CYGWIN__)
456 ssize_t n; 457 ssize_t n;
457#else /* _WIN32 && !__CYGWIN__ */ 458#else /* _WIN32 && !__CYGWIN__ */
458 const HANDLE fh = (HANDLE) _get_osfhandle (response->fd); 459 const HANDLE fh = (HANDLE) _get_osfhandle (response->fd);
459#endif /* _WIN32 && !__CYGWIN__ */ 460#endif /* _WIN32 && !__CYGWIN__ */
460 const int64_t offset64 = (int64_t)(pos + response->fd_off); 461 const int64_t offset64 = (int64_t) (pos + response->fd_off);
461 462
462 if (offset64 < 0) 463 if (offset64 < 0)
463 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 464 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
464 465
465#if !defined(_WIN32) || defined(__CYGWIN__) 466#if ! defined(_WIN32) || defined(__CYGWIN__)
466 if (max > SSIZE_MAX) 467 if (max > SSIZE_MAX)
467 max = SSIZE_MAX; /* Clamp to maximum return value. */ 468 max = SSIZE_MAX; /* Clamp to maximum return value. */
468 469
469#if defined(HAVE_PREAD64) 470#if defined(HAVE_PREAD64)
470 n = pread64(response->fd, buf, max, offset64); 471 n = pread64 (response->fd, buf, max, offset64);
471#elif defined(HAVE_PREAD) 472#elif defined(HAVE_PREAD)
472 if ( (sizeof(off_t) < sizeof (uint64_t)) && 473 if ( (sizeof(off_t) < sizeof (uint64_t)) &&
473 (offset64 > (uint64_t)INT32_MAX) ) 474 (offset64 > (uint64_t) INT32_MAX) )
474 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read at required position is not possible. */ 475 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read at required position is not possible. */
475 476
476 n = pread(response->fd, buf, max, (off_t) offset64); 477 n = pread (response->fd, buf, max, (off_t) offset64);
477#else /* ! HAVE_PREAD */ 478#else /* ! HAVE_PREAD */
478#if defined(HAVE_LSEEK64) 479#if defined(HAVE_LSEEK64)
479 if (lseek64 (response->fd, 480 if (lseek64 (response->fd,
@@ -482,7 +483,7 @@ file_reader (void *cls,
482 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */ 483 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */
483#else /* ! HAVE_LSEEK64 */ 484#else /* ! HAVE_LSEEK64 */
484 if ( (sizeof(off_t) < sizeof (uint64_t)) && 485 if ( (sizeof(off_t) < sizeof (uint64_t)) &&
485 (offset64 > (uint64_t)INT32_MAX) ) 486 (offset64 > (uint64_t) INT32_MAX) )
486 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 487 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
487 488
488 if (lseek (response->fd, 489 if (lseek (response->fd,
@@ -504,21 +505,21 @@ file_reader (void *cls,
504 if (INVALID_HANDLE_VALUE == fh) 505 if (INVALID_HANDLE_VALUE == fh)
505 return MHD_CONTENT_READER_END_WITH_ERROR; /* Value of 'response->fd' is not valid. */ 506 return MHD_CONTENT_READER_END_WITH_ERROR; /* Value of 'response->fd' is not valid. */
506 else 507 else
507 { 508 {
508 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0}; /* Initialize to zero. */ 509 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0}; /* Initialize to zero. */
509 ULARGE_INTEGER pos_uli; 510 ULARGE_INTEGER pos_uli;
510 DWORD toRead = (max > INT32_MAX) ? INT32_MAX : (DWORD) max; 511 DWORD toRead = (max > INT32_MAX) ? INT32_MAX : (DWORD) max;
511 DWORD resRead; 512 DWORD resRead;
512 513
513 pos_uli.QuadPart = (uint64_t) offset64; /* Simple transformation 64bit -> 2x32bit. */ 514 pos_uli.QuadPart = (uint64_t) offset64; /* Simple transformation 64bit -> 2x32bit. */
514 f_ol.Offset = pos_uli.LowPart; 515 f_ol.Offset = pos_uli.LowPart;
515 f_ol.OffsetHigh = pos_uli.HighPart; 516 f_ol.OffsetHigh = pos_uli.HighPart;
516 if (! ReadFile(fh, (void*)buf, toRead, &resRead, &f_ol)) 517 if (! ReadFile (fh, (void*) buf, toRead, &resRead, &f_ol))
517 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read error. */ 518 return MHD_CONTENT_READER_END_WITH_ERROR; /* Read error. */
518 if (0 == resRead) 519 if (0 == resRead)
519 return MHD_CONTENT_READER_END_OF_STREAM; 520 return MHD_CONTENT_READER_END_OF_STREAM;
520 return (ssize_t) resRead; 521 return (ssize_t) resRead;
521 } 522 }
522#endif /* _WIN32 && !__CYGWIN__ */ 523#endif /* _WIN32 && !__CYGWIN__ */
523} 524}
524 525
@@ -590,16 +591,16 @@ MHD_create_response_from_fd_at_offset64 (uint64_t size,
590{ 591{
591 struct MHD_Response *response; 592 struct MHD_Response *response;
592 593
593#if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 594#if ! defined(HAVE___LSEEKI64) && ! defined(HAVE_LSEEK64)
594 if ( (sizeof(uint64_t) > sizeof(off_t)) && 595 if ( (sizeof(uint64_t) > sizeof(off_t)) &&
595 ( (size > (uint64_t)INT32_MAX) || 596 ( (size > (uint64_t) INT32_MAX) ||
596 (offset > (uint64_t)INT32_MAX) || 597 (offset > (uint64_t) INT32_MAX) ||
597 ((size + offset) >= (uint64_t)INT32_MAX) ) ) 598 ((size + offset) >= (uint64_t) INT32_MAX) ) )
598 return NULL; 599 return NULL;
599#endif 600#endif
600 if ( ((int64_t)size < 0) || 601 if ( ((int64_t) size < 0) ||
601 ((int64_t)offset < 0) || 602 ((int64_t) offset < 0) ||
602 ((int64_t)(size + offset) < 0) ) 603 ((int64_t) (size + offset) < 0) )
603 return NULL; 604 return NULL;
604 605
605 response = MHD_create_response_from_callback (size, 606 response = MHD_create_response_from_callback (size,
@@ -688,30 +689,30 @@ MHD_create_response_from_data (size_t size,
688 response->fd = -1; 689 response->fd = -1;
689#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 690#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
690 if (! MHD_mutex_init_ (&response->mutex)) 691 if (! MHD_mutex_init_ (&response->mutex))
691 { 692 {
692 free (response); 693 free (response);
693 return NULL; 694 return NULL;
694 } 695 }
695#endif 696#endif
696 if ((must_copy) && (size > 0)) 697 if ((must_copy) && (size > 0))
698 {
699 if (NULL == (tmp = malloc (size)))
697 { 700 {
698 if (NULL == (tmp = malloc (size)))
699 {
700#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 701#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
701 MHD_mutex_destroy_chk_ (&response->mutex); 702 MHD_mutex_destroy_chk_ (&response->mutex);
702#endif 703#endif
703 free (response); 704 free (response);
704 return NULL; 705 return NULL;
705 }
706 memcpy (tmp, data, size);
707 must_free = MHD_YES;
708 data = tmp;
709 } 706 }
707 memcpy (tmp, data, size);
708 must_free = MHD_YES;
709 data = tmp;
710 }
710 if (must_free) 711 if (must_free)
711 { 712 {
712 response->crfc = &free; 713 response->crfc = &free;
713 response->crc_cls = data; 714 response->crc_cls = data;
714 } 715 }
715 response->reference_count = 1; 716 response->reference_count = 1;
716 response->total_size = size; 717 response->total_size = size;
717 response->data = data; 718 response->data = data;
@@ -736,9 +737,9 @@ MHD_create_response_from_buffer (size_t size,
736 enum MHD_ResponseMemoryMode mode) 737 enum MHD_ResponseMemoryMode mode)
737{ 738{
738 return MHD_create_response_from_data (size, 739 return MHD_create_response_from_data (size,
739 buffer, 740 buffer,
740 mode == MHD_RESPMEM_MUST_FREE, 741 mode == MHD_RESPMEM_MUST_FREE,
741 mode == MHD_RESPMEM_MUST_COPY); 742 mode == MHD_RESPMEM_MUST_COPY);
742} 743}
743 744
744 745
@@ -755,7 +756,8 @@ MHD_create_response_from_buffer (size_t size,
755_MHD_EXTERN struct MHD_Response * 756_MHD_EXTERN struct MHD_Response *
756MHD_create_response_from_buffer_with_free_callback (size_t size, 757MHD_create_response_from_buffer_with_free_callback (size_t size,
757 void *buffer, 758 void *buffer,
758 MHD_ContentReaderFreeCallback crfc) 759 MHD_ContentReaderFreeCallback
760 crfc)
759{ 761{
760 struct MHD_Response *r; 762 struct MHD_Response *r;
761 763
@@ -811,12 +813,12 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
811 /* transition to special 'closed' state for start of cleanup */ 813 /* transition to special 'closed' state for start of cleanup */
812#ifdef HTTPS_SUPPORT 814#ifdef HTTPS_SUPPORT
813 if (0 != (daemon->options & MHD_USE_TLS) ) 815 if (0 != (daemon->options & MHD_USE_TLS) )
814 { 816 {
815 /* signal that app is done by shutdown() of 'app' socket */ 817 /* signal that app is done by shutdown() of 'app' socket */
816 /* Application will not use anyway this socket after this command. */ 818 /* Application will not use anyway this socket after this command. */
817 shutdown (urh->app.socket, 819 shutdown (urh->app.socket,
818 SHUT_RDWR); 820 SHUT_RDWR);
819 } 821 }
820#endif /* HTTPS_SUPPORT */ 822#endif /* HTTPS_SUPPORT */
821 mhd_assert (MHD_CONNECTION_UPGRADE == connection->state); 823 mhd_assert (MHD_CONNECTION_UPGRADE == connection->state);
822 urh->was_closed = true; 824 urh->was_closed = true;
@@ -830,42 +832,42 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
830 return MHD_YES; 832 return MHD_YES;
831#ifdef HTTPS_SUPPORT 833#ifdef HTTPS_SUPPORT
832 if (0 != (daemon->options & MHD_USE_TLS) ) 834 if (0 != (daemon->options & MHD_USE_TLS) )
833 { 835 {
834 gnutls_record_cork (connection->tls_session); 836 gnutls_record_cork (connection->tls_session);
835 connection->sk_cork_on = true; 837 connection->sk_cork_on = true;
836 return MHD_YES; 838 return MHD_YES;
837 } 839 }
838 else 840 else
839#else 841#else
840 { 842 {
841 if (0 == 843 if (0 ==
842 MHD_socket_cork_ (connection->socket_fd, 844 MHD_socket_cork_ (connection->socket_fd,
843 true)) 845 true))
844 connection->sk_cork_on = true; 846 connection->sk_cork_on = true;
845 } 847 }
846#endif 848#endif
847 case MHD_UPGRADE_ACTION_CORK_OFF: 849 case MHD_UPGRADE_ACTION_CORK_OFF:
848 if (! connection->sk_cork_on) 850 if (! connection->sk_cork_on)
849 return MHD_YES; 851 return MHD_YES;
850#ifdef HTTPS_SUPPORT 852#ifdef HTTPS_SUPPORT
851 if (0 != (daemon->options & MHD_USE_TLS) ) 853 if (0 != (daemon->options & MHD_USE_TLS) )
852 { 854 {
853 gnutls_record_uncork (connection->tls_session, 0); 855 gnutls_record_uncork (connection->tls_session, 0);
854 connection->sk_cork_on = false; 856 connection->sk_cork_on = false;
855 return MHD_YES; 857 return MHD_YES;
856 } 858 }
857 else 859 else
858#else 860#else
859 { 861 {
860 if (0 == 862 if (0 ==
861 MHD_socket_cork_ (connection->socket_fd, 863 MHD_socket_cork_ (connection->socket_fd,
862 false)) 864 false))
863 connection->sk_cork_on = false; 865 connection->sk_cork_on = false;
864 } 866 }
865#endif 867#endif
866 default: 868 default:
867 /* we don't understand this one */ 869 /* we don't understand this one */
868 return MHD_NO; 870 return MHD_NO;
869 } 871 }
870} 872}
871 873
@@ -897,13 +899,14 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
897 if (NULL == 899 if (NULL ==
898 MHD_get_response_header (response, 900 MHD_get_response_header (response,
899 MHD_HTTP_HEADER_UPGRADE)) 901 MHD_HTTP_HEADER_UPGRADE))
900 { 902 {
901#ifdef HAVE_MESSAGES 903#ifdef HAVE_MESSAGES
902 MHD_DLOG (daemon, 904 MHD_DLOG (daemon,
903 _("Invalid response for upgrade: application failed to set the 'Upgrade' header!\n")); 905 _ (
906 "Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
904#endif 907#endif
905 return MHD_NO; 908 return MHD_NO;
906 } 909 }
907 910
908 urh = MHD_calloc_ (1, sizeof (struct MHD_UpgradeResponseHandle)); 911 urh = MHD_calloc_ (1, sizeof (struct MHD_UpgradeResponseHandle));
909 if (NULL == urh) 912 if (NULL == urh)
@@ -918,77 +921,77 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
918 size_t avail; 921 size_t avail;
919 char *buf; 922 char *buf;
920 MHD_socket sv[2]; 923 MHD_socket sv[2];
921#if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_) 924#if defined(MHD_socket_nosignal_) || ! defined(MHD_socket_pair_nblk_)
922 int res1; 925 int res1;
923 int res2; 926 int res2;
924#endif /* MHD_socket_nosignal_ || !MHD_socket_pair_nblk_ */ 927#endif /* MHD_socket_nosignal_ || !MHD_socket_pair_nblk_ */
925 928
926#ifdef MHD_socket_pair_nblk_ 929#ifdef MHD_socket_pair_nblk_
927 if (! MHD_socket_pair_nblk_ (sv)) 930 if (! MHD_socket_pair_nblk_ (sv))
928 { 931 {
929 free (urh); 932 free (urh);
930 return MHD_NO; 933 return MHD_NO;
931 } 934 }
932#else /* !MHD_socket_pair_nblk_ */ 935#else /* !MHD_socket_pair_nblk_ */
933 if (! MHD_socket_pair_ (sv)) 936 if (! MHD_socket_pair_ (sv))
934 { 937 {
935 free (urh); 938 free (urh);
936 return MHD_NO; 939 return MHD_NO;
937 } 940 }
938 res1 = MHD_socket_nonblocking_(sv[0]); 941 res1 = MHD_socket_nonblocking_ (sv[0]);
939 res2 = MHD_socket_nonblocking_(sv[1]); 942 res2 = MHD_socket_nonblocking_ (sv[1]);
940 if ( (! res1) || (! res2) ) 943 if ( (! res1) || (! res2) )
941 { 944 {
942#ifdef HAVE_MESSAGES 945#ifdef HAVE_MESSAGES
943 MHD_DLOG (daemon, 946 MHD_DLOG (daemon,
944 _("Failed to make loopback sockets non-blocking.\n")); 947 _ ("Failed to make loopback sockets non-blocking.\n"));
945#endif 948#endif
946 if (! res2) 949 if (! res2)
947 { 950 {
948 /* Socketpair cannot be used. */ 951 /* Socketpair cannot be used. */
949 MHD_socket_close_chk_ (sv[0]); 952 MHD_socket_close_chk_ (sv[0]);
950 MHD_socket_close_chk_ (sv[1]); 953 MHD_socket_close_chk_ (sv[1]);
951 free (urh); 954 free (urh);
952 return MHD_NO; 955 return MHD_NO;
953 }
954 } 956 }
957 }
955#endif /* !MHD_socket_pair_nblk_ */ 958#endif /* !MHD_socket_pair_nblk_ */
956#ifdef MHD_socket_nosignal_ 959#ifdef MHD_socket_nosignal_
957 res1 = MHD_socket_nosignal_(sv[0]); 960 res1 = MHD_socket_nosignal_ (sv[0]);
958 res2 = MHD_socket_nosignal_(sv[1]); 961 res2 = MHD_socket_nosignal_ (sv[1]);
959 if ( (! res1) || (! res2) ) 962 if ( (! res1) || (! res2) )
960 { 963 {
961#ifdef HAVE_MESSAGES 964#ifdef HAVE_MESSAGES
962 MHD_DLOG (daemon, 965 MHD_DLOG (daemon,
963 _("Failed to set SO_NOSIGPIPE on loopback sockets.\n")); 966 _ ("Failed to set SO_NOSIGPIPE on loopback sockets.\n"));
964#endif 967#endif
965#ifndef MSG_NOSIGNAL 968#ifndef MSG_NOSIGNAL
966 if (!res2) 969 if (! res2)
967 { 970 {
968 /* Socketpair cannot be used. */ 971 /* Socketpair cannot be used. */
969 MHD_socket_close_chk_ (sv[0]); 972 MHD_socket_close_chk_ (sv[0]);
970 MHD_socket_close_chk_ (sv[1]); 973 MHD_socket_close_chk_ (sv[1]);
971 free (urh); 974 free (urh);
972 return MHD_NO; 975 return MHD_NO;
973 }
974#endif /* ! MSG_NOSIGNAL */
975 } 976 }
977#endif /* ! MSG_NOSIGNAL */
978 }
976#endif /* MHD_socket_nosignal_ */ 979#endif /* MHD_socket_nosignal_ */
977 if ( (! MHD_SCKT_FD_FITS_FDSET_ (sv[1], 980 if ( (! MHD_SCKT_FD_FITS_FDSET_ (sv[1],
978 NULL)) && 981 NULL)) &&
979 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) ) 982 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) )
980 { 983 {
981#ifdef HAVE_MESSAGES 984#ifdef HAVE_MESSAGES
982 MHD_DLOG (daemon, 985 MHD_DLOG (daemon,
983 _("Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"), 986 _ ("Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
984 (int) sv[1], 987 (int) sv[1],
985 (int) FD_SETSIZE); 988 (int) FD_SETSIZE);
986#endif 989#endif
987 MHD_socket_close_chk_ (sv[0]); 990 MHD_socket_close_chk_ (sv[0]);
988 MHD_socket_close_chk_ (sv[1]); 991 MHD_socket_close_chk_ (sv[1]);
989 free (urh); 992 free (urh);
990 return MHD_NO; 993 return MHD_NO;
991 } 994 }
992 urh->app.socket = sv[0]; 995 urh->app.socket = sv[0];
993 urh->app.urh = urh; 996 urh->app.urh = urh;
994 urh->app.celi = MHD_EPOLL_STATE_UNREADY; 997 urh->app.celi = MHD_EPOLL_STATE_UNREADY;
@@ -998,22 +1001,22 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
998 pool = connection->pool; 1001 pool = connection->pool;
999 avail = MHD_pool_get_free (pool); 1002 avail = MHD_pool_get_free (pool);
1000 if (avail < RESERVE_EBUF_SIZE) 1003 if (avail < RESERVE_EBUF_SIZE)
1001 { 1004 {
1002 /* connection's pool is totally at the limit, 1005 /* connection's pool is totally at the limit,
1003 use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */ 1006 use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */
1004 avail = RESERVE_EBUF_SIZE; 1007 avail = RESERVE_EBUF_SIZE;
1005 buf = urh->e_buf; 1008 buf = urh->e_buf;
1006 } 1009 }
1007 else 1010 else
1008 { 1011 {
1009 /* Normal case: grab all remaining memory from the 1012 /* Normal case: grab all remaining memory from the
1010 connection's pool for the IO buffers; the connection 1013 connection's pool for the IO buffers; the connection
1011 certainly won't need it anymore as we've upgraded 1014 certainly won't need it anymore as we've upgraded
1012 to another protocol. */ 1015 to another protocol. */
1013 buf = MHD_pool_allocate (pool, 1016 buf = MHD_pool_allocate (pool,
1014 avail, 1017 avail,
1015 false); 1018 false);
1016 } 1019 }
1017 /* use half the buffer for inbound, half for outbound */ 1020 /* use half the buffer for inbound, half for outbound */
1018 urh->in_buffer_size = avail / 2; 1021 urh->in_buffer_size = avail / 2;
1019 urh->out_buffer_size = avail - urh->in_buffer_size; 1022 urh->out_buffer_size = avail - urh->in_buffer_size;
@@ -1022,81 +1025,81 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
1022#ifdef EPOLL_SUPPORT 1025#ifdef EPOLL_SUPPORT
1023 /* Launch IO processing by the event loop */ 1026 /* Launch IO processing by the event loop */
1024 if (0 != (daemon->options & MHD_USE_EPOLL)) 1027 if (0 != (daemon->options & MHD_USE_EPOLL))
1028 {
1029 /* We're running with epoll(), need to add the sockets
1030 to the event set of the daemon's `epoll_upgrade_fd` */
1031 struct epoll_event event;
1032
1033 mhd_assert (-1 != daemon->epoll_upgrade_fd);
1034 /* First, add network socket */
1035 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
1036 event.data.ptr = &urh->app;
1037 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1038 EPOLL_CTL_ADD,
1039 connection->socket_fd,
1040 &event))
1025 { 1041 {
1026 /* We're running with epoll(), need to add the sockets 1042#ifdef HAVE_MESSAGES
1027 to the event set of the daemon's `epoll_upgrade_fd` */ 1043 MHD_DLOG (daemon,
1028 struct epoll_event event; 1044 _ ("Call to epoll_ctl failed: %s\n"),
1045 MHD_socket_last_strerr_ ());
1046#endif
1047 MHD_socket_close_chk_ (sv[0]);
1048 MHD_socket_close_chk_ (sv[1]);
1049 free (urh);
1050 return MHD_NO;
1051 }
1029 1052
1030 mhd_assert (-1 != daemon->epoll_upgrade_fd); 1053 /* Second, add our end of the UNIX socketpair() */
1031 /* First, add network socket */ 1054 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
1032 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET; 1055 event.data.ptr = &urh->mhd;
1056 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1057 EPOLL_CTL_ADD,
1058 urh->mhd.socket,
1059 &event))
1060 {
1061 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
1033 event.data.ptr = &urh->app; 1062 event.data.ptr = &urh->app;
1034 if (0 != epoll_ctl (daemon->epoll_upgrade_fd, 1063 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1035 EPOLL_CTL_ADD, 1064 EPOLL_CTL_DEL,
1036 connection->socket_fd, 1065 connection->socket_fd,
1037 &event)) 1066 &event))
1038 { 1067 MHD_PANIC (_ ("Error cleaning up while handling epoll error"));
1039#ifdef HAVE_MESSAGES 1068#ifdef HAVE_MESSAGES
1040 MHD_DLOG (daemon, 1069 MHD_DLOG (daemon,
1041 _("Call to epoll_ctl failed: %s\n"), 1070 _ ("Call to epoll_ctl failed: %s\n"),
1042 MHD_socket_last_strerr_ ()); 1071 MHD_socket_last_strerr_ ());
1043#endif
1044 MHD_socket_close_chk_ (sv[0]);
1045 MHD_socket_close_chk_ (sv[1]);
1046 free (urh);
1047 return MHD_NO;
1048 }
1049
1050 /* Second, add our end of the UNIX socketpair() */
1051 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
1052 event.data.ptr = &urh->mhd;
1053 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1054 EPOLL_CTL_ADD,
1055 urh->mhd.socket,
1056 &event))
1057 {
1058 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
1059 event.data.ptr = &urh->app;
1060 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1061 EPOLL_CTL_DEL,
1062 connection->socket_fd,
1063 &event))
1064 MHD_PANIC (_("Error cleaning up while handling epoll error"));
1065#ifdef HAVE_MESSAGES
1066 MHD_DLOG (daemon,
1067 _("Call to epoll_ctl failed: %s\n"),
1068 MHD_socket_last_strerr_ ());
1069#endif 1072#endif
1070 MHD_socket_close_chk_ (sv[0]); 1073 MHD_socket_close_chk_ (sv[0]);
1071 MHD_socket_close_chk_ (sv[1]); 1074 MHD_socket_close_chk_ (sv[1]);
1072 free (urh); 1075 free (urh);
1073 return MHD_NO; 1076 return MHD_NO;
1074 }
1075 EDLL_insert (daemon->eready_urh_head,
1076 daemon->eready_urh_tail,
1077 urh);
1078 urh->in_eready_list = true;
1079 } 1077 }
1078 EDLL_insert (daemon->eready_urh_head,
1079 daemon->eready_urh_tail,
1080 urh);
1081 urh->in_eready_list = true;
1082 }
1080#endif /* EPOLL_SUPPORT */ 1083#endif /* EPOLL_SUPPORT */
1081 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) 1084 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION) )
1082 { 1085 {
1083 /* This takes care of further processing for most event loops: 1086 /* This takes care of further processing for most event loops:
1084 simply add to DLL for bi-direcitonal processing */ 1087 simply add to DLL for bi-direcitonal processing */
1085 DLL_insert (daemon->urh_head, 1088 DLL_insert (daemon->urh_head,
1086 daemon->urh_tail, 1089 daemon->urh_tail,
1087 urh); 1090 urh);
1088 } 1091 }
1089 /* In thread-per-connection mode, thread will switch to forwarding once 1092 /* In thread-per-connection mode, thread will switch to forwarding once
1090 * connection.urh is not NULL and connection.state == MHD_CONNECTION_UPGRADE. 1093 * connection.urh is not NULL and connection.state == MHD_CONNECTION_UPGRADE.
1091 */ 1094 */
1092 } 1095 }
1093 else 1096 else
1094 { 1097 {
1095 urh->app.socket = MHD_INVALID_SOCKET; 1098 urh->app.socket = MHD_INVALID_SOCKET;
1096 urh->mhd.socket = MHD_INVALID_SOCKET; 1099 urh->mhd.socket = MHD_INVALID_SOCKET;
1097 /* Non-TLS connection do not hold any additional resources. */ 1100 /* Non-TLS connection do not hold any additional resources. */
1098 urh->clean_ready = true; 1101 urh->clean_ready = true;
1099 } 1102 }
1100#else /* ! HTTPS_SUPPORT */ 1103#else /* ! HTTPS_SUPPORT */
1101 urh->clean_ready = true; 1104 urh->clean_ready = true;
1102#endif /* ! HTTPS_SUPPORT */ 1105#endif /* ! HTTPS_SUPPORT */
@@ -1154,7 +1157,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
1154 */ 1157 */
1155_MHD_EXTERN struct MHD_Response * 1158_MHD_EXTERN struct MHD_Response *
1156MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, 1159MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
1157 void *upgrade_handler_cls) 1160 void *upgrade_handler_cls)
1158{ 1161{
1159 struct MHD_Response *response; 1162 struct MHD_Response *response;
1160 1163
@@ -1165,10 +1168,10 @@ MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
1165 return NULL; 1168 return NULL;
1166#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1169#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1167 if (! MHD_mutex_init_ (&response->mutex)) 1170 if (! MHD_mutex_init_ (&response->mutex))
1168 { 1171 {
1169 free (response); 1172 free (response);
1170 return NULL; 1173 return NULL;
1171 } 1174 }
1172#endif 1175#endif
1173 response->upgrade_handler = upgrade_handler; 1176 response->upgrade_handler = upgrade_handler;
1174 response->upgrade_handler_cls = upgrade_handler_cls; 1177 response->upgrade_handler_cls = upgrade_handler_cls;
@@ -1178,10 +1181,10 @@ MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
1178 MHD_add_response_header (response, 1181 MHD_add_response_header (response,
1179 MHD_HTTP_HEADER_CONNECTION, 1182 MHD_HTTP_HEADER_CONNECTION,
1180 "Upgrade")) 1183 "Upgrade"))
1181 { 1184 {
1182 MHD_destroy_response (response); 1185 MHD_destroy_response (response);
1183 return NULL; 1186 return NULL;
1184 } 1187 }
1185 return response; 1188 return response;
1186} 1189}
1187#endif /* UPGRADE_SUPPORT */ 1190#endif /* UPGRADE_SUPPORT */
@@ -1207,12 +1210,12 @@ MHD_destroy_response (struct MHD_Response *response)
1207 MHD_mutex_lock_chk_ (&response->mutex); 1210 MHD_mutex_lock_chk_ (&response->mutex);
1208#endif 1211#endif
1209 if (0 != --(response->reference_count)) 1212 if (0 != --(response->reference_count))
1210 { 1213 {
1211#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1214#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1212 MHD_mutex_unlock_chk_ (&response->mutex); 1215 MHD_mutex_unlock_chk_ (&response->mutex);
1213#endif 1216#endif
1214 return; 1217 return;
1215 } 1218 }
1216#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1219#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1217 MHD_mutex_unlock_chk_ (&response->mutex); 1220 MHD_mutex_unlock_chk_ (&response->mutex);
1218 MHD_mutex_destroy_chk_ (&response->mutex); 1221 MHD_mutex_destroy_chk_ (&response->mutex);
@@ -1220,13 +1223,13 @@ MHD_destroy_response (struct MHD_Response *response)
1220 if (NULL != response->crfc) 1223 if (NULL != response->crfc)
1221 response->crfc (response->crc_cls); 1224 response->crfc (response->crc_cls);
1222 while (NULL != response->first_header) 1225 while (NULL != response->first_header)
1223 { 1226 {
1224 pos = response->first_header; 1227 pos = response->first_header;
1225 response->first_header = pos->next; 1228 response->first_header = pos->next;
1226 free (pos->header); 1229 free (pos->header);
1227 free (pos->value); 1230 free (pos->value);
1228 free (pos); 1231 free (pos);
1229 } 1232 }
1230 free (response); 1233 free (response);
1231} 1234}
1232 1235
diff --git a/src/microhttpd/sha256.c b/src/microhttpd/sha256.c
index b47a773b..846a43b7 100644
--- a/src/microhttpd/sha256.c
+++ b/src/microhttpd/sha256.c
@@ -104,10 +104,12 @@ sha256_transform (uint32_t H[_SHA256_DIGEST_LENGTH],
104 104
105 /* Four 'Sigma' macro functions. 105 /* Four 'Sigma' macro functions.
106 See FIPS PUB 180-4 formulae 4.4, 4.5, 4.6, 4.7. */ 106 See FIPS PUB 180-4 formulae 4.4, 4.5, 4.6, 4.7. */
107#define SIG0(x) ( _MHD_ROTR32((x),2) ^ _MHD_ROTR32((x),13) ^ _MHD_ROTR32((x),22) ) 107#define SIG0(x) (_MHD_ROTR32 ((x),2) ^ _MHD_ROTR32 ((x),13) ^ _MHD_ROTR32 ((x), \
108#define SIG1(x) ( _MHD_ROTR32((x),6) ^ _MHD_ROTR32((x),11) ^ _MHD_ROTR32((x),25) ) 108 22) )
109#define sig0(x) ( _MHD_ROTR32((x),7) ^ _MHD_ROTR32((x),18) ^ ((x) >> 3) ) 109#define SIG1(x) (_MHD_ROTR32 ((x),6) ^ _MHD_ROTR32 ((x),11) ^ _MHD_ROTR32 ((x), \
110#define sig1(x) ( _MHD_ROTR32((x),17) ^ _MHD_ROTR32((x),19) ^ ((x) >> 10) ) 110 25) )
111#define sig0(x) (_MHD_ROTR32 ((x),7) ^ _MHD_ROTR32 ((x),18) ^ ((x) >> 3) )
112#define sig1(x) (_MHD_ROTR32 ((x),17) ^ _MHD_ROTR32 ((x),19) ^ ((x) >> 10) )
111 113
112 /* Single step of SHA-256 computation, 114 /* Single step of SHA-256 computation,
113 see FIPS PUB 180-4 paragraph 6.2.2 step 3. 115 see FIPS PUB 180-4 paragraph 6.2.2 step 3.
@@ -122,99 +124,115 @@ sha256_transform (uint32_t H[_SHA256_DIGEST_LENGTH],
122 * Note: 'wt' must be used exactly one time in this macro as it change other data as well 124 * Note: 'wt' must be used exactly one time in this macro as it change other data as well
123 every time when used. */ 125 every time when used. */
124#define SHA2STEP32(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ 126#define SHA2STEP32(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \
125 (vD) += ((vH) += SIG1((vE)) + Ch((vE),(vF),(vG)) + (kt) + (wt)); \ 127 (vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \
126 (vH) += SIG0((vA)) + Maj((vA),(vB),(vC)); } while (0) 128 (vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0)
127 129
128 /* Get value of W(t) from input data buffer, 130 /* Get value of W(t) from input data buffer,
129 See FIPS PUB 180-4 paragraph 6.2. 131 See FIPS PUB 180-4 paragraph 6.2.
130 Input data must be read in big-endian bytes order, 132 Input data must be read in big-endian bytes order,
131 see FIPS PUB 180-4 paragraph 3.1.2. */ 133 see FIPS PUB 180-4 paragraph 3.1.2. */
132#define GET_W_FROM_DATA(buf,t) \ 134#define GET_W_FROM_DATA(buf,t) \
133 _MHD_GET_32BIT_BE(((const uint8_t*)(buf)) + (t) * SHA256_BYTES_IN_WORD) 135 _MHD_GET_32BIT_BE (((const uint8_t*) (buf)) + (t) * SHA256_BYTES_IN_WORD)
134 136
135 /* During first 16 steps, before making any calculations on each step, 137 /* During first 16 steps, before making any calculations on each step,
136 the W element is read from input data buffer as big-endian value and 138 the W element is read from input data buffer as big-endian value and
137 stored in array of W elements. */ 139 stored in array of W elements. */
138 /* Note: instead of using K constants as array, all K values are specified 140 /* Note: instead of using K constants as array, all K values are specified
139 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for K values. */ 141 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for K values. */
140 SHA2STEP32(a, b, c, d, e, f, g, h, 0x428a2f98UL, W[0] = GET_W_FROM_DATA(data,0)); 142 SHA2STEP32 (a, b, c, d, e, f, g, h, 0x428a2f98UL, W[0] = GET_W_FROM_DATA (
141 SHA2STEP32(h, a, b, c, d, e, f, g, 0x71374491UL, W[1] = GET_W_FROM_DATA(data,1)); 143 data,0));
142 SHA2STEP32(g, h, a, b, c, d, e, f, 0xb5c0fbcfUL, W[2] = GET_W_FROM_DATA(data,2)); 144 SHA2STEP32 (h, a, b, c, d, e, f, g, 0x71374491UL, W[1] = GET_W_FROM_DATA (
143 SHA2STEP32(f, g, h, a, b, c, d, e, 0xe9b5dba5UL, W[3] = GET_W_FROM_DATA(data,3)); 145 data,1));
144 SHA2STEP32(e, f, g, h, a, b, c, d, 0x3956c25bUL, W[4] = GET_W_FROM_DATA(data,4)); 146 SHA2STEP32 (g, h, a, b, c, d, e, f, 0xb5c0fbcfUL, W[2] = GET_W_FROM_DATA (
145 SHA2STEP32(d, e, f, g, h, a, b, c, 0x59f111f1UL, W[5] = GET_W_FROM_DATA(data,5)); 147 data,2));
146 SHA2STEP32(c, d, e, f, g, h, a, b, 0x923f82a4UL, W[6] = GET_W_FROM_DATA(data,6)); 148 SHA2STEP32 (f, g, h, a, b, c, d, e, 0xe9b5dba5UL, W[3] = GET_W_FROM_DATA (
147 SHA2STEP32(b, c, d, e, f, g, h, a, 0xab1c5ed5UL, W[7] = GET_W_FROM_DATA(data,7)); 149 data,3));
148 SHA2STEP32(a, b, c, d, e, f, g, h, 0xd807aa98UL, W[8] = GET_W_FROM_DATA(data,8)); 150 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x3956c25bUL, W[4] = GET_W_FROM_DATA (
149 SHA2STEP32(h, a, b, c, d, e, f, g, 0x12835b01UL, W[9] = GET_W_FROM_DATA(data,9)); 151 data,4));
150 SHA2STEP32(g, h, a, b, c, d, e, f, 0x243185beUL, W[10] = GET_W_FROM_DATA(data,10)); 152 SHA2STEP32 (d, e, f, g, h, a, b, c, 0x59f111f1UL, W[5] = GET_W_FROM_DATA (
151 SHA2STEP32(f, g, h, a, b, c, d, e, 0x550c7dc3UL, W[11] = GET_W_FROM_DATA(data,11)); 153 data,5));
152 SHA2STEP32(e, f, g, h, a, b, c, d, 0x72be5d74UL, W[12] = GET_W_FROM_DATA(data,12)); 154 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x923f82a4UL, W[6] = GET_W_FROM_DATA (
153 SHA2STEP32(d, e, f, g, h, a, b, c, 0x80deb1feUL, W[13] = GET_W_FROM_DATA(data,13)); 155 data,6));
154 SHA2STEP32(c, d, e, f, g, h, a, b, 0x9bdc06a7UL, W[14] = GET_W_FROM_DATA(data,14)); 156 SHA2STEP32 (b, c, d, e, f, g, h, a, 0xab1c5ed5UL, W[7] = GET_W_FROM_DATA (
155 SHA2STEP32(b, c, d, e, f, g, h, a, 0xc19bf174UL, W[15] = GET_W_FROM_DATA(data,15)); 157 data,7));
158 SHA2STEP32 (a, b, c, d, e, f, g, h, 0xd807aa98UL, W[8] = GET_W_FROM_DATA (
159 data,8));
160 SHA2STEP32 (h, a, b, c, d, e, f, g, 0x12835b01UL, W[9] = GET_W_FROM_DATA (
161 data,9));
162 SHA2STEP32 (g, h, a, b, c, d, e, f, 0x243185beUL, W[10] = GET_W_FROM_DATA (
163 data,10));
164 SHA2STEP32 (f, g, h, a, b, c, d, e, 0x550c7dc3UL, W[11] = GET_W_FROM_DATA (
165 data,11));
166 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x72be5d74UL, W[12] = GET_W_FROM_DATA (
167 data,12));
168 SHA2STEP32 (d, e, f, g, h, a, b, c, 0x80deb1feUL, W[13] = GET_W_FROM_DATA (
169 data,13));
170 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x9bdc06a7UL, W[14] = GET_W_FROM_DATA (
171 data,14));
172 SHA2STEP32 (b, c, d, e, f, g, h, a, 0xc19bf174UL, W[15] = GET_W_FROM_DATA (
173 data,15));
156 174
157 /* 'W' generation and assignment for 16 <= t <= 63. 175 /* 'W' generation and assignment for 16 <= t <= 63.
158 See FIPS PUB 180-4 paragraph 6.2.2. 176 See FIPS PUB 180-4 paragraph 6.2.2.
159 As only last 16 'W' are used in calculations, it is possible to 177 As only last 16 'W' are used in calculations, it is possible to
160 use 16 elements array of W as cyclic buffer. 178 use 16 elements array of W as cyclic buffer.
161 * Note: ((t-16)&0xf) have same value as (t&0xf) */ 179 * Note: ((t-16)&0xf) have same value as (t&0xf) */
162#define Wgen(w,t) ( (w)[(t-16)&0xf] + sig1((w)[((t)-2)&0xf]) + \ 180#define Wgen(w,t) ( (w)[(t - 16) & 0xf] + sig1 ((w)[((t) - 2) & 0xf]) \
163 (w)[((t)-7)&0xf] + sig0((w)[((t)-15)&0xf]) ) 181 + (w)[((t) - 7) & 0xf] + sig0 ((w)[((t) - 15) & 0xf]) )
164 182
165 /* During last 48 steps, before making any calculations on each step, 183 /* During last 48 steps, before making any calculations on each step,
166 W element is generated from W elements of cyclic buffer and generated value 184 W element is generated from W elements of cyclic buffer and generated value
167 stored back in cyclic buffer. */ 185 stored back in cyclic buffer. */
168 /* Note: instead of using K constants as array, all K values are specified 186 /* Note: instead of using K constants as array, all K values are specified
169 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for K values. */ 187 individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for K values. */
170 SHA2STEP32(a, b, c, d, e, f, g, h, 0xe49b69c1UL, W[16&0xf] = Wgen(W,16)); 188 SHA2STEP32 (a, b, c, d, e, f, g, h, 0xe49b69c1UL, W[16 & 0xf] = Wgen (W,16));
171 SHA2STEP32(h, a, b, c, d, e, f, g, 0xefbe4786UL, W[17&0xf] = Wgen(W,17)); 189 SHA2STEP32 (h, a, b, c, d, e, f, g, 0xefbe4786UL, W[17 & 0xf] = Wgen (W,17));
172 SHA2STEP32(g, h, a, b, c, d, e, f, 0x0fc19dc6UL, W[18&0xf] = Wgen(W,18)); 190 SHA2STEP32 (g, h, a, b, c, d, e, f, 0x0fc19dc6UL, W[18 & 0xf] = Wgen (W,18));
173 SHA2STEP32(f, g, h, a, b, c, d, e, 0x240ca1ccUL, W[19&0xf] = Wgen(W,19)); 191 SHA2STEP32 (f, g, h, a, b, c, d, e, 0x240ca1ccUL, W[19 & 0xf] = Wgen (W,19));
174 SHA2STEP32(e, f, g, h, a, b, c, d, 0x2de92c6fUL, W[20&0xf] = Wgen(W,20)); 192 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x2de92c6fUL, W[20 & 0xf] = Wgen (W,20));
175 SHA2STEP32(d, e, f, g, h, a, b, c, 0x4a7484aaUL, W[21&0xf] = Wgen(W,21)); 193 SHA2STEP32 (d, e, f, g, h, a, b, c, 0x4a7484aaUL, W[21 & 0xf] = Wgen (W,21));
176 SHA2STEP32(c, d, e, f, g, h, a, b, 0x5cb0a9dcUL, W[22&0xf] = Wgen(W,22)); 194 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x5cb0a9dcUL, W[22 & 0xf] = Wgen (W,22));
177 SHA2STEP32(b, c, d, e, f, g, h, a, 0x76f988daUL, W[23&0xf] = Wgen(W,23)); 195 SHA2STEP32 (b, c, d, e, f, g, h, a, 0x76f988daUL, W[23 & 0xf] = Wgen (W,23));
178 SHA2STEP32(a, b, c, d, e, f, g, h, 0x983e5152UL, W[24&0xf] = Wgen(W,24)); 196 SHA2STEP32 (a, b, c, d, e, f, g, h, 0x983e5152UL, W[24 & 0xf] = Wgen (W,24));
179 SHA2STEP32(h, a, b, c, d, e, f, g, 0xa831c66dUL, W[25&0xf] = Wgen(W,25)); 197 SHA2STEP32 (h, a, b, c, d, e, f, g, 0xa831c66dUL, W[25 & 0xf] = Wgen (W,25));
180 SHA2STEP32(g, h, a, b, c, d, e, f, 0xb00327c8UL, W[26&0xf] = Wgen(W,26)); 198 SHA2STEP32 (g, h, a, b, c, d, e, f, 0xb00327c8UL, W[26 & 0xf] = Wgen (W,26));
181 SHA2STEP32(f, g, h, a, b, c, d, e, 0xbf597fc7UL, W[27&0xf] = Wgen(W,27)); 199 SHA2STEP32 (f, g, h, a, b, c, d, e, 0xbf597fc7UL, W[27 & 0xf] = Wgen (W,27));
182 SHA2STEP32(e, f, g, h, a, b, c, d, 0xc6e00bf3UL, W[28&0xf] = Wgen(W,28)); 200 SHA2STEP32 (e, f, g, h, a, b, c, d, 0xc6e00bf3UL, W[28 & 0xf] = Wgen (W,28));
183 SHA2STEP32(d, e, f, g, h, a, b, c, 0xd5a79147UL, W[29&0xf] = Wgen(W,29)); 201 SHA2STEP32 (d, e, f, g, h, a, b, c, 0xd5a79147UL, W[29 & 0xf] = Wgen (W,29));
184 SHA2STEP32(c, d, e, f, g, h, a, b, 0x06ca6351UL, W[30&0xf] = Wgen(W,30)); 202 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x06ca6351UL, W[30 & 0xf] = Wgen (W,30));
185 SHA2STEP32(b, c, d, e, f, g, h, a, 0x14292967UL, W[31&0xf] = Wgen(W,31)); 203 SHA2STEP32 (b, c, d, e, f, g, h, a, 0x14292967UL, W[31 & 0xf] = Wgen (W,31));
186 SHA2STEP32(a, b, c, d, e, f, g, h, 0x27b70a85UL, W[32&0xf] = Wgen(W,32)); 204 SHA2STEP32 (a, b, c, d, e, f, g, h, 0x27b70a85UL, W[32 & 0xf] = Wgen (W,32));
187 SHA2STEP32(h, a, b, c, d, e, f, g, 0x2e1b2138UL, W[33&0xf] = Wgen(W,33)); 205 SHA2STEP32 (h, a, b, c, d, e, f, g, 0x2e1b2138UL, W[33 & 0xf] = Wgen (W,33));
188 SHA2STEP32(g, h, a, b, c, d, e, f, 0x4d2c6dfcUL, W[34&0xf] = Wgen(W,34)); 206 SHA2STEP32 (g, h, a, b, c, d, e, f, 0x4d2c6dfcUL, W[34 & 0xf] = Wgen (W,34));
189 SHA2STEP32(f, g, h, a, b, c, d, e, 0x53380d13UL, W[35&0xf] = Wgen(W,35)); 207 SHA2STEP32 (f, g, h, a, b, c, d, e, 0x53380d13UL, W[35 & 0xf] = Wgen (W,35));
190 SHA2STEP32(e, f, g, h, a, b, c, d, 0x650a7354UL, W[36&0xf] = Wgen(W,36)); 208 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x650a7354UL, W[36 & 0xf] = Wgen (W,36));
191 SHA2STEP32(d, e, f, g, h, a, b, c, 0x766a0abbUL, W[37&0xf] = Wgen(W,37)); 209 SHA2STEP32 (d, e, f, g, h, a, b, c, 0x766a0abbUL, W[37 & 0xf] = Wgen (W,37));
192 SHA2STEP32(c, d, e, f, g, h, a, b, 0x81c2c92eUL, W[38&0xf] = Wgen(W,38)); 210 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x81c2c92eUL, W[38 & 0xf] = Wgen (W,38));
193 SHA2STEP32(b, c, d, e, f, g, h, a, 0x92722c85UL, W[39&0xf] = Wgen(W,39)); 211 SHA2STEP32 (b, c, d, e, f, g, h, a, 0x92722c85UL, W[39 & 0xf] = Wgen (W,39));
194 SHA2STEP32(a, b, c, d, e, f, g, h, 0xa2bfe8a1UL, W[40&0xf] = Wgen(W,40)); 212 SHA2STEP32 (a, b, c, d, e, f, g, h, 0xa2bfe8a1UL, W[40 & 0xf] = Wgen (W,40));
195 SHA2STEP32(h, a, b, c, d, e, f, g, 0xa81a664bUL, W[41&0xf] = Wgen(W,41)); 213 SHA2STEP32 (h, a, b, c, d, e, f, g, 0xa81a664bUL, W[41 & 0xf] = Wgen (W,41));
196 SHA2STEP32(g, h, a, b, c, d, e, f, 0xc24b8b70UL, W[42&0xf] = Wgen(W,42)); 214 SHA2STEP32 (g, h, a, b, c, d, e, f, 0xc24b8b70UL, W[42 & 0xf] = Wgen (W,42));
197 SHA2STEP32(f, g, h, a, b, c, d, e, 0xc76c51a3UL, W[43&0xf] = Wgen(W,43)); 215 SHA2STEP32 (f, g, h, a, b, c, d, e, 0xc76c51a3UL, W[43 & 0xf] = Wgen (W,43));
198 SHA2STEP32(e, f, g, h, a, b, c, d, 0xd192e819UL, W[44&0xf] = Wgen(W,44)); 216 SHA2STEP32 (e, f, g, h, a, b, c, d, 0xd192e819UL, W[44 & 0xf] = Wgen (W,44));
199 SHA2STEP32(d, e, f, g, h, a, b, c, 0xd6990624UL, W[45&0xf] = Wgen(W,45)); 217 SHA2STEP32 (d, e, f, g, h, a, b, c, 0xd6990624UL, W[45 & 0xf] = Wgen (W,45));
200 SHA2STEP32(c, d, e, f, g, h, a, b, 0xf40e3585UL, W[46&0xf] = Wgen(W,46)); 218 SHA2STEP32 (c, d, e, f, g, h, a, b, 0xf40e3585UL, W[46 & 0xf] = Wgen (W,46));
201 SHA2STEP32(b, c, d, e, f, g, h, a, 0x106aa070UL, W[47&0xf] = Wgen(W,47)); 219 SHA2STEP32 (b, c, d, e, f, g, h, a, 0x106aa070UL, W[47 & 0xf] = Wgen (W,47));
202 SHA2STEP32(a, b, c, d, e, f, g, h, 0x19a4c116UL, W[48&0xf] = Wgen(W,48)); 220 SHA2STEP32 (a, b, c, d, e, f, g, h, 0x19a4c116UL, W[48 & 0xf] = Wgen (W,48));
203 SHA2STEP32(h, a, b, c, d, e, f, g, 0x1e376c08UL, W[49&0xf] = Wgen(W,49)); 221 SHA2STEP32 (h, a, b, c, d, e, f, g, 0x1e376c08UL, W[49 & 0xf] = Wgen (W,49));
204 SHA2STEP32(g, h, a, b, c, d, e, f, 0x2748774cUL, W[50&0xf] = Wgen(W,50)); 222 SHA2STEP32 (g, h, a, b, c, d, e, f, 0x2748774cUL, W[50 & 0xf] = Wgen (W,50));
205 SHA2STEP32(f, g, h, a, b, c, d, e, 0x34b0bcb5UL, W[51&0xf] = Wgen(W,51)); 223 SHA2STEP32 (f, g, h, a, b, c, d, e, 0x34b0bcb5UL, W[51 & 0xf] = Wgen (W,51));
206 SHA2STEP32(e, f, g, h, a, b, c, d, 0x391c0cb3UL, W[52&0xf] = Wgen(W,52)); 224 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x391c0cb3UL, W[52 & 0xf] = Wgen (W,52));
207 SHA2STEP32(d, e, f, g, h, a, b, c, 0x4ed8aa4aUL, W[53&0xf] = Wgen(W,53)); 225 SHA2STEP32 (d, e, f, g, h, a, b, c, 0x4ed8aa4aUL, W[53 & 0xf] = Wgen (W,53));
208 SHA2STEP32(c, d, e, f, g, h, a, b, 0x5b9cca4fUL, W[54&0xf] = Wgen(W,54)); 226 SHA2STEP32 (c, d, e, f, g, h, a, b, 0x5b9cca4fUL, W[54 & 0xf] = Wgen (W,54));
209 SHA2STEP32(b, c, d, e, f, g, h, a, 0x682e6ff3UL, W[55&0xf] = Wgen(W,55)); 227 SHA2STEP32 (b, c, d, e, f, g, h, a, 0x682e6ff3UL, W[55 & 0xf] = Wgen (W,55));
210 SHA2STEP32(a, b, c, d, e, f, g, h, 0x748f82eeUL, W[56&0xf] = Wgen(W,56)); 228 SHA2STEP32 (a, b, c, d, e, f, g, h, 0x748f82eeUL, W[56 & 0xf] = Wgen (W,56));
211 SHA2STEP32(h, a, b, c, d, e, f, g, 0x78a5636fUL, W[57&0xf] = Wgen(W,57)); 229 SHA2STEP32 (h, a, b, c, d, e, f, g, 0x78a5636fUL, W[57 & 0xf] = Wgen (W,57));
212 SHA2STEP32(g, h, a, b, c, d, e, f, 0x84c87814UL, W[58&0xf] = Wgen(W,58)); 230 SHA2STEP32 (g, h, a, b, c, d, e, f, 0x84c87814UL, W[58 & 0xf] = Wgen (W,58));
213 SHA2STEP32(f, g, h, a, b, c, d, e, 0x8cc70208UL, W[59&0xf] = Wgen(W,59)); 231 SHA2STEP32 (f, g, h, a, b, c, d, e, 0x8cc70208UL, W[59 & 0xf] = Wgen (W,59));
214 SHA2STEP32(e, f, g, h, a, b, c, d, 0x90befffaUL, W[60&0xf] = Wgen(W,60)); 232 SHA2STEP32 (e, f, g, h, a, b, c, d, 0x90befffaUL, W[60 & 0xf] = Wgen (W,60));
215 SHA2STEP32(d, e, f, g, h, a, b, c, 0xa4506cebUL, W[61&0xf] = Wgen(W,61)); 233 SHA2STEP32 (d, e, f, g, h, a, b, c, 0xa4506cebUL, W[61 & 0xf] = Wgen (W,61));
216 SHA2STEP32(c, d, e, f, g, h, a, b, 0xbef9a3f7UL, W[62&0xf] = Wgen(W,62)); 234 SHA2STEP32 (c, d, e, f, g, h, a, b, 0xbef9a3f7UL, W[62 & 0xf] = Wgen (W,62));
217 SHA2STEP32(b, c, d, e, f, g, h, a, 0xc67178f2UL, W[63&0xf] = Wgen(W,63)); 235 SHA2STEP32 (b, c, d, e, f, g, h, a, 0xc67178f2UL, W[63 & 0xf] = Wgen (W,63));
218 236
219 /* Compute intermediate hash. 237 /* Compute intermediate hash.
220 See FIPS PUB 180-4 paragraph 4.2.2 step 4. */ 238 See FIPS PUB 180-4 paragraph 4.2.2 step 4. */
@@ -237,51 +255,51 @@ sha256_transform (uint32_t H[_SHA256_DIGEST_LENGTH],
237 */ 255 */
238void 256void
239MHD_SHA256_update (void *ctx_, 257MHD_SHA256_update (void *ctx_,
240 const uint8_t *data, 258 const uint8_t *data,
241 size_t length) 259 size_t length)
242{ 260{
243 struct sha256_ctx *const ctx = ctx_; 261 struct sha256_ctx *const ctx = ctx_;
244 unsigned bytes_have; /**< Number of bytes in buffer */ 262 unsigned bytes_have; /**< Number of bytes in buffer */
245 263
246 mhd_assert((data != NULL) || (length == 0)); 264 mhd_assert ((data != NULL) || (length == 0));
247 265
248 if (0 == length) 266 if (0 == length)
249 return; /* Do nothing */ 267 return; /* Do nothing */
250 268
251 /* Note: (count & (SHA256_BLOCK_SIZE-1)) 269 /* Note: (count & (SHA256_BLOCK_SIZE-1))
252 equal (count % SHA256_BLOCK_SIZE) for this block size. */ 270 equal (count % SHA256_BLOCK_SIZE) for this block size. */
253 bytes_have = (unsigned)(ctx->count & (SHA256_BLOCK_SIZE-1)); 271 bytes_have = (unsigned) (ctx->count & (SHA256_BLOCK_SIZE - 1));
254 ctx->count += length; 272 ctx->count += length;
255 273
256 if (0 != bytes_have) 274 if (0 != bytes_have)
257 { 275 {
258 unsigned bytes_left = SHA256_BLOCK_SIZE - bytes_have; 276 unsigned bytes_left = SHA256_BLOCK_SIZE - bytes_have;
259 if (length >= bytes_left) 277 if (length >= bytes_left)
260 { /* Combine new data with data in buffer and 278 { /* Combine new data with data in buffer and
261 process full block. */ 279 process full block. */
262 memcpy (ctx->buffer + bytes_have, 280 memcpy (ctx->buffer + bytes_have,
263 data, 281 data,
264 bytes_left); 282 bytes_left);
265 data += bytes_left; 283 data += bytes_left;
266 length -= bytes_left; 284 length -= bytes_left;
267 sha256_transform (ctx->H, ctx->buffer); 285 sha256_transform (ctx->H, ctx->buffer);
268 bytes_have = 0; 286 bytes_have = 0;
269 }
270 } 287 }
288 }
271 289
272 while (SHA256_BLOCK_SIZE <= length) 290 while (SHA256_BLOCK_SIZE <= length)
273 { /* Process any full blocks of new data directly, 291 { /* Process any full blocks of new data directly,
274 without copying to buffer. */ 292 without copying to buffer. */
275 sha256_transform (ctx->H, data); 293 sha256_transform (ctx->H, data);
276 data += SHA256_BLOCK_SIZE; 294 data += SHA256_BLOCK_SIZE;
277 length -= SHA256_BLOCK_SIZE; 295 length -= SHA256_BLOCK_SIZE;
278 } 296 }
279 297
280 if (0 != length) 298 if (0 != length)
281 { /* Copy incomplete block of new data (if any) 299 { /* Copy incomplete block of new data (if any)
282 to buffer. */ 300 to buffer. */
283 memcpy (ctx->buffer + bytes_have, data, length); 301 memcpy (ctx->buffer + bytes_have, data, length);
284 } 302 }
285} 303}
286 304
287 305
@@ -308,7 +326,7 @@ sha256_finish (void *ctx_,
308 num_bits = ctx->count << 3; 326 num_bits = ctx->count << 3;
309 /* Note: (count & (SHA256_BLOCK_SIZE-1)) 327 /* Note: (count & (SHA256_BLOCK_SIZE-1))
310 equal (count % SHA256_BLOCK_SIZE) for this block size. */ 328 equal (count % SHA256_BLOCK_SIZE) for this block size. */
311 bytes_have = (unsigned)(ctx->count & (SHA256_BLOCK_SIZE-1)); 329 bytes_have = (unsigned) (ctx->count & (SHA256_BLOCK_SIZE - 1));
312 330
313 /* Input data must be padded with bit "1" and with length of data in bits. 331 /* Input data must be padded with bit "1" and with length of data in bits.
314 See FIPS PUB 180-4 paragraph 5.1.1. */ 332 See FIPS PUB 180-4 paragraph 5.1.1. */
@@ -319,33 +337,35 @@ sha256_finish (void *ctx_,
319 ctx->buffer[bytes_have++] = 0x80; 337 ctx->buffer[bytes_have++] = 0x80;
320 338
321 if (SHA256_BLOCK_SIZE - bytes_have < SHA256_SIZE_OF_LEN_ADD) 339 if (SHA256_BLOCK_SIZE - bytes_have < SHA256_SIZE_OF_LEN_ADD)
322 { /* No space in current block to put total length of message. 340 { /* No space in current block to put total length of message.
323 Pad current block with zeros and process it. */ 341 Pad current block with zeros and process it. */
324 while (bytes_have < SHA256_BLOCK_SIZE) ctx->buffer[bytes_have++] = 0; 342 while (bytes_have < SHA256_BLOCK_SIZE)
325 /* Process full block. */ 343 ctx->buffer[bytes_have++] = 0;
326 sha256_transform (ctx->H, ctx->buffer); 344 /* Process full block. */
327 /* Start new block. */ 345 sha256_transform (ctx->H, ctx->buffer);
328 bytes_have = 0; 346 /* Start new block. */
329 } 347 bytes_have = 0;
348 }
330 349
331 /* Pad the rest of the buffer with zeros. */ 350 /* Pad the rest of the buffer with zeros. */
332 memset(ctx->buffer + bytes_have, 0, 351 memset (ctx->buffer + bytes_have, 0,
333 SHA256_BLOCK_SIZE - SHA256_SIZE_OF_LEN_ADD - bytes_have); 352 SHA256_BLOCK_SIZE - SHA256_SIZE_OF_LEN_ADD - bytes_have);
334 /* Put number of bits in processed message as big-endian value. */ 353 /* Put number of bits in processed message as big-endian value. */
335 _MHD_PUT_64BIT_BE(ctx->buffer + SHA256_BLOCK_SIZE - SHA256_SIZE_OF_LEN_ADD, num_bits); 354 _MHD_PUT_64BIT_BE (ctx->buffer + SHA256_BLOCK_SIZE - SHA256_SIZE_OF_LEN_ADD,
355 num_bits);
336 /* Process full final block. */ 356 /* Process full final block. */
337 sha256_transform (ctx->H, ctx->buffer); 357 sha256_transform (ctx->H, ctx->buffer);
338 358
339 /* Put final hash/digest in BE mode */ 359 /* Put final hash/digest in BE mode */
340 _MHD_PUT_32BIT_BE(digest + 0 * SHA256_BYTES_IN_WORD, ctx->H[0]); 360 _MHD_PUT_32BIT_BE (digest + 0 * SHA256_BYTES_IN_WORD, ctx->H[0]);
341 _MHD_PUT_32BIT_BE(digest + 1 * SHA256_BYTES_IN_WORD, ctx->H[1]); 361 _MHD_PUT_32BIT_BE (digest + 1 * SHA256_BYTES_IN_WORD, ctx->H[1]);
342 _MHD_PUT_32BIT_BE(digest + 2 * SHA256_BYTES_IN_WORD, ctx->H[2]); 362 _MHD_PUT_32BIT_BE (digest + 2 * SHA256_BYTES_IN_WORD, ctx->H[2]);
343 _MHD_PUT_32BIT_BE(digest + 3 * SHA256_BYTES_IN_WORD, ctx->H[3]); 363 _MHD_PUT_32BIT_BE (digest + 3 * SHA256_BYTES_IN_WORD, ctx->H[3]);
344 _MHD_PUT_32BIT_BE(digest + 4 * SHA256_BYTES_IN_WORD, ctx->H[4]); 364 _MHD_PUT_32BIT_BE (digest + 4 * SHA256_BYTES_IN_WORD, ctx->H[4]);
345 _MHD_PUT_32BIT_BE(digest + 5 * SHA256_BYTES_IN_WORD, ctx->H[5]); 365 _MHD_PUT_32BIT_BE (digest + 5 * SHA256_BYTES_IN_WORD, ctx->H[5]);
346 _MHD_PUT_32BIT_BE(digest + 6 * SHA256_BYTES_IN_WORD, ctx->H[6]); 366 _MHD_PUT_32BIT_BE (digest + 6 * SHA256_BYTES_IN_WORD, ctx->H[6]);
347 _MHD_PUT_32BIT_BE(digest + 7 * SHA256_BYTES_IN_WORD, ctx->H[7]); 367 _MHD_PUT_32BIT_BE (digest + 7 * SHA256_BYTES_IN_WORD, ctx->H[7]);
348 368
349 /* Erase potentially sensitive data. */ 369 /* Erase potentially sensitive data. */
350 memset(ctx, 0, sizeof(struct sha256_ctx)); 370 memset (ctx, 0, sizeof(struct sha256_ctx));
351} 371}
diff --git a/src/microhttpd/sha256.h b/src/microhttpd/sha256.h
index 319277ff..f4c84e2c 100644
--- a/src/microhttpd/sha256.h
+++ b/src/microhttpd/sha256.h
@@ -76,8 +76,8 @@ MHD_SHA256_init (void *ctx_);
76 */ 76 */
77void 77void
78MHD_SHA256_update (void *ctx_, 78MHD_SHA256_update (void *ctx_,
79 const uint8_t *data, 79 const uint8_t *data,
80 size_t length); 80 size_t length);
81 81
82 82
83/** 83/**
diff --git a/src/microhttpd/sysfdsetsize.c b/src/microhttpd/sysfdsetsize.c
index fe7fba75..4929b3d2 100644
--- a/src/microhttpd/sysfdsetsize.c
+++ b/src/microhttpd/sysfdsetsize.c
@@ -56,7 +56,7 @@
56#include <sys/socket.h> 56#include <sys/socket.h>
57#endif /* HAVE_SYS_SOCKET_H */ 57#endif /* HAVE_SYS_SOCKET_H */
58 58
59#if defined(_WIN32) && !defined(__CYGWIN__) 59#if defined(_WIN32) && ! defined(__CYGWIN__)
60#ifndef WIN32_LEAN_AND_MEAN 60#ifndef WIN32_LEAN_AND_MEAN
61#define WIN32_LEAN_AND_MEAN 1 61#define WIN32_LEAN_AND_MEAN 1
62#endif /* !WIN32_LEAN_AND_MEAN */ 62#endif /* !WIN32_LEAN_AND_MEAN */
diff --git a/src/microhttpd/test_daemon.c b/src/microhttpd/test_daemon.c
index af59b86d..4f600ef0 100644
--- a/src/microhttpd/test_daemon.c
+++ b/src/microhttpd/test_daemon.c
@@ -57,7 +57,7 @@ apc_nothing (void *cls,
57 const struct sockaddr *addr, 57 const struct sockaddr *addr,
58 socklen_t addrlen) 58 socklen_t addrlen)
59{ 59{
60 (void)cls; (void)addr; (void)addrlen; /* Unused. Silent compiler warning. */ 60 (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */
61 61
62 return MHD_NO; 62 return MHD_NO;
63} 63}
@@ -68,7 +68,7 @@ apc_all (void *cls,
68 const struct sockaddr *addr, 68 const struct sockaddr *addr,
69 socklen_t addrlen) 69 socklen_t addrlen)
70{ 70{
71 (void)cls; (void)addr; (void)addrlen; /* Unused. Silent compiler warning. */ 71 (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */
72 72
73 return MHD_YES; 73 return MHD_YES;
74} 74}
@@ -83,9 +83,9 @@ ahc_nothing (void *cls,
83 const char *upload_data, size_t *upload_data_size, 83 const char *upload_data, size_t *upload_data_size,
84 void **unused) 84 void **unused)
85{ 85{
86 (void)cls;(void)connection;(void)url; /* Unused. Silent compiler warning. */ 86 (void) cls; (void) connection; (void) url; /* Unused. Silent compiler warning. */
87 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 87 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
88 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 88 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
89 89
90 return MHD_NO; 90 return MHD_NO;
91} 91}
@@ -136,25 +136,25 @@ testExternalRun ()
136 } 136 }
137 i = 0; 137 i = 0;
138 while (i < 15) 138 while (i < 15)
139 {
140 maxfd = 0;
141 FD_ZERO (&rs);
142 if (MHD_YES != MHD_get_fdset (d, &rs, &rs, &rs, &maxfd))
143 {
144 MHD_stop_daemon (d);
145 fprintf (stderr,
146 "Failed in MHD_get_fdset()\n");
147 return 256;
148 }
149 if (MHD_run (d) == MHD_NO)
139 { 150 {
140 maxfd = 0; 151 MHD_stop_daemon (d);
141 FD_ZERO (&rs); 152 fprintf (stderr,
142 if (MHD_YES != MHD_get_fdset (d, &rs, &rs, &rs, &maxfd)) 153 "Failed in MHD_run()\n");
143 { 154 return 8;
144 MHD_stop_daemon (d);
145 fprintf (stderr,
146 "Failed in MHD_get_fdset()\n");
147 return 256;
148 }
149 if (MHD_run (d) == MHD_NO)
150 {
151 MHD_stop_daemon (d);
152 fprintf (stderr,
153 "Failed in MHD_run()\n");
154 return 8;
155 }
156 i++;
157 } 155 }
156 i++;
157 }
158 MHD_stop_daemon (d); 158 MHD_stop_daemon (d);
159 return 0; 159 return 0;
160} 160}
@@ -179,11 +179,11 @@ testThread ()
179 exit (77); 179 exit (77);
180 } 180 }
181 if (MHD_run (d) != MHD_NO) 181 if (MHD_run (d) != MHD_NO)
182 { 182 {
183 fprintf (stderr, 183 fprintf (stderr,
184 "Failed in MHD_run()\n"); 184 "Failed in MHD_run()\n");
185 return 32; 185 return 32;
186 } 186 }
187 MHD_stop_daemon (d); 187 MHD_stop_daemon (d);
188 return 0; 188 return 0;
189} 189}
@@ -194,7 +194,8 @@ testMultithread ()
194{ 194{
195 struct MHD_Daemon *d; 195 struct MHD_Daemon *d;
196 196
197 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION, 197 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_INTERNAL_POLLING_THREAD
198 | MHD_USE_THREAD_PER_CONNECTION,
198 0, 199 0,
199 &apc_all, NULL, 200 &apc_all, NULL,
200 &ahc_nothing, NULL, 201 &ahc_nothing, NULL,
@@ -208,11 +209,11 @@ testMultithread ()
208 exit (77); 209 exit (77);
209 } 210 }
210 if (MHD_run (d) != MHD_NO) 211 if (MHD_run (d) != MHD_NO)
211 { 212 {
212 fprintf (stderr, 213 fprintf (stderr,
213 "Failed in MHD_run()\n"); 214 "Failed in MHD_run()\n");
214 return 128; 215 return 128;
215 } 216 }
216 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
217 return 0; 218 return 0;
218} 219}
@@ -223,7 +224,7 @@ main (int argc,
223 char *const *argv) 224 char *const *argv)
224{ 225{
225 int errorCount = 0; 226 int errorCount = 0;
226 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 227 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
227 228
228 errorCount += testStartError (); 229 errorCount += testStartError ();
229 errorCount += testStartStop (); 230 errorCount += testStartStop ();
diff --git a/src/microhttpd/test_helpers.h b/src/microhttpd/test_helpers.h
index 4f015ef2..d47f7168 100644
--- a/src/microhttpd/test_helpers.h
+++ b/src/microhttpd/test_helpers.h
@@ -39,29 +39,29 @@
39 * name. 39 * name.
40 */ 40 */
41static int 41static int
42has_in_name(const char *prog_name, const char *marker) 42has_in_name (const char *prog_name, const char *marker)
43{ 43{
44 size_t name_pos; 44 size_t name_pos;
45 size_t pos; 45 size_t pos;
46 46
47 if (!prog_name || !marker || !prog_name[0] || !marker[0]) 47 if (! prog_name || ! marker || ! prog_name[0] || ! marker[0])
48 return 0; 48 return 0;
49 49
50 pos = 0; 50 pos = 0;
51 name_pos = 0; 51 name_pos = 0;
52 while (prog_name[pos]) 52 while (prog_name[pos])
53 { 53 {
54 if ('/' == prog_name[pos]) 54 if ('/' == prog_name[pos])
55 name_pos = pos + 1; 55 name_pos = pos + 1;
56#if defined(_WIN32) || defined(__CYGWIN__) 56#if defined(_WIN32) || defined(__CYGWIN__)
57 else if ('\\' == prog_name[pos]) 57 else if ('\\' == prog_name[pos])
58 name_pos = pos + 1; 58 name_pos = pos + 1;
59#endif /* _WIN32 || __CYGWIN__ */ 59#endif /* _WIN32 || __CYGWIN__ */
60 pos++; 60 pos++;
61 } 61 }
62 if (name_pos == pos) 62 if (name_pos == pos)
63 return 0; 63 return 0;
64 return strstr(prog_name + name_pos, marker) != (char*)0; 64 return strstr (prog_name + name_pos, marker) != (char*) 0;
65} 65}
66 66
67/** 67/**
@@ -75,17 +75,17 @@ has_in_name(const char *prog_name, const char *marker)
75 * non-zero if one of strings in @a argv is equal to @a param. 75 * non-zero if one of strings in @a argv is equal to @a param.
76 */ 76 */
77static int 77static int
78has_param(int argc, char * const argv[], const char * param) 78has_param (int argc, char *const argv[], const char *param)
79{ 79{
80 int i; 80 int i;
81 if (!argv || !param || !param[0]) 81 if (! argv || ! param || ! param[0])
82 return 0; 82 return 0;
83 83
84 for(i = 1; i < argc; i++) 84 for (i = 1; i < argc; i++)
85 { 85 {
86 if(argv[i] && strcmp(argv[i], param) == 0) 86 if (argv[i] &&(strcmp (argv[i], param) == 0) )
87 return !0; 87 return ! 0;
88 } 88 }
89 89
90 return 0; 90 return 0;
91} 91}
diff --git a/src/microhttpd/test_http_reasons.c b/src/microhttpd/test_http_reasons.c
index 62721439..4d0484ad 100644
--- a/src/microhttpd/test_http_reasons.c
+++ b/src/microhttpd/test_http_reasons.c
@@ -28,105 +28,111 @@
28#include "microhttpd.h" 28#include "microhttpd.h"
29#include "mhd_str.h" 29#include "mhd_str.h"
30 30
31static int expect_result(int code, const char* expected) 31static int expect_result (int code, const char*expected)
32{ 32{
33 const char* const reason = MHD_get_reason_phrase_for(code); 33 const char*const reason = MHD_get_reason_phrase_for (code);
34 if (MHD_str_equal_caseless_(reason, expected)) 34 if (MHD_str_equal_caseless_ (reason, expected))
35 return 0; 35 return 0;
36 fprintf(stderr, "Incorrect reason returned for code %d:\n Returned: \"%s\" \tExpected: \"%s\"\n", 36 fprintf (stderr,
37 code, reason, expected); 37 "Incorrect reason returned for code %d:\n Returned: \"%s\" \tExpected: \"%s\"\n",
38 code, reason, expected);
38 return 1; 39 return 1;
39} 40}
40 41
41static int expect_absent(int code) 42static int expect_absent (int code)
42{ 43{
43 return expect_result(code, "unknown"); 44 return expect_result (code, "unknown");
44} 45}
45 46
46static int test_absent_codes(void) 47static int test_absent_codes (void)
47{ 48{
48 int errcount = 0; 49 int errcount = 0;
49 errcount += expect_absent(0); 50 errcount += expect_absent (0);
50 errcount += expect_absent(1); 51 errcount += expect_absent (1);
51 errcount += expect_absent(50); 52 errcount += expect_absent (50);
52 errcount += expect_absent(99); 53 errcount += expect_absent (99);
53 errcount += expect_absent(600); 54 errcount += expect_absent (600);
54 errcount += expect_absent(601); 55 errcount += expect_absent (601);
55 errcount += expect_absent(900); 56 errcount += expect_absent (900);
56 errcount += expect_absent(10000); 57 errcount += expect_absent (10000);
57 return errcount; 58 return errcount;
58} 59}
59 60
60static int test_1xx(void) 61static int test_1xx (void)
61{ 62{
62 int errcount = 0; 63 int errcount = 0;
63 errcount += expect_result(MHD_HTTP_CONTINUE, "continue"); 64 errcount += expect_result (MHD_HTTP_CONTINUE, "continue");
64 errcount += expect_result(MHD_HTTP_PROCESSING, "processing"); 65 errcount += expect_result (MHD_HTTP_PROCESSING, "processing");
65 errcount += expect_absent(110); 66 errcount += expect_absent (110);
66 errcount += expect_absent(190); 67 errcount += expect_absent (190);
67 return errcount; 68 return errcount;
68} 69}
69 70
70static int test_2xx(void) 71static int test_2xx (void)
71{ 72{
72 int errcount = 0; 73 int errcount = 0;
73 errcount += expect_result(MHD_HTTP_OK, "ok"); 74 errcount += expect_result (MHD_HTTP_OK, "ok");
74 errcount += expect_result(MHD_HTTP_ALREADY_REPORTED, "already reported"); 75 errcount += expect_result (MHD_HTTP_ALREADY_REPORTED, "already reported");
75 errcount += expect_absent(217); 76 errcount += expect_absent (217);
76 errcount += expect_result(MHD_HTTP_IM_USED, "im used"); 77 errcount += expect_result (MHD_HTTP_IM_USED, "im used");
77 errcount += expect_absent(230); 78 errcount += expect_absent (230);
78 errcount += expect_absent(295); 79 errcount += expect_absent (295);
79 return errcount; 80 return errcount;
80} 81}
81 82
82static int test_3xx(void) 83static int test_3xx (void)
83{ 84{
84 int errcount = 0; 85 int errcount = 0;
85 errcount += expect_result(MHD_HTTP_MULTIPLE_CHOICES, "multiple choices"); 86 errcount += expect_result (MHD_HTTP_MULTIPLE_CHOICES, "multiple choices");
86 errcount += expect_result(MHD_HTTP_SEE_OTHER, "see other"); 87 errcount += expect_result (MHD_HTTP_SEE_OTHER, "see other");
87 errcount += expect_result(MHD_HTTP_PERMANENT_REDIRECT, "permanent redirect"); 88 errcount += expect_result (MHD_HTTP_PERMANENT_REDIRECT, "permanent redirect");
88 errcount += expect_absent(311); 89 errcount += expect_absent (311);
89 errcount += expect_absent(399); 90 errcount += expect_absent (399);
90 return errcount; 91 return errcount;
91} 92}
92 93
93static int test_4xx(void) 94static int test_4xx (void)
94{ 95{
95 int errcount = 0; 96 int errcount = 0;
96 errcount += expect_result(MHD_HTTP_BAD_REQUEST, "bad request"); 97 errcount += expect_result (MHD_HTTP_BAD_REQUEST, "bad request");
97 errcount += expect_result(MHD_HTTP_NOT_FOUND, "not found"); 98 errcount += expect_result (MHD_HTTP_NOT_FOUND, "not found");
98 errcount += expect_result(MHD_HTTP_URI_TOO_LONG, "uri too long"); 99 errcount += expect_result (MHD_HTTP_URI_TOO_LONG, "uri too long");
99 errcount += expect_result(MHD_HTTP_EXPECTATION_FAILED, "expectation failed"); 100 errcount += expect_result (MHD_HTTP_EXPECTATION_FAILED, "expectation failed");
100 errcount += expect_result(MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, "request header fields too large"); 101 errcount += expect_result (MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
101 errcount += expect_absent(441); 102 "request header fields too large");
102 errcount += expect_result(MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, "unavailable for legal reasons"); 103 errcount += expect_absent (441);
103 errcount += expect_absent(470); 104 errcount += expect_result (MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
104 errcount += expect_absent(493); 105 "unavailable for legal reasons");
106 errcount += expect_absent (470);
107 errcount += expect_absent (493);
105 return errcount; 108 return errcount;
106} 109}
107 110
108static int test_5xx(void) 111static int test_5xx (void)
109{ 112{
110 int errcount = 0; 113 int errcount = 0;
111 errcount += expect_result(MHD_HTTP_INTERNAL_SERVER_ERROR, "internal server error"); 114 errcount += expect_result (MHD_HTTP_INTERNAL_SERVER_ERROR,
112 errcount += expect_result(MHD_HTTP_BAD_GATEWAY, "bad gateway"); 115 "internal server error");
113 errcount += expect_result(MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED, "http version not supported"); 116 errcount += expect_result (MHD_HTTP_BAD_GATEWAY, "bad gateway");
114 errcount += expect_result(MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED, "network authentication required"); 117 errcount += expect_result (MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED,
115 errcount += expect_absent(520); 118 "http version not supported");
116 errcount += expect_absent(597); 119 errcount += expect_result (MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED,
120 "network authentication required");
121 errcount += expect_absent (520);
122 errcount += expect_absent (597);
117 return errcount; 123 return errcount;
118} 124}
119 125
120int main(int argc, char * argv[]) 126int main (int argc, char *argv[])
121{ 127{
122 int errcount = 0; 128 int errcount = 0;
123 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 129 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
124 130
125 errcount += test_absent_codes(); 131 errcount += test_absent_codes ();
126 errcount += test_1xx(); 132 errcount += test_1xx ();
127 errcount += test_2xx(); 133 errcount += test_2xx ();
128 errcount += test_3xx(); 134 errcount += test_3xx ();
129 errcount += test_4xx(); 135 errcount += test_4xx ();
130 errcount += test_5xx(); 136 errcount += test_5xx ();
131 return errcount == 0 ? 0 : 1; 137 return errcount == 0 ? 0 : 1;
132} 138}
diff --git a/src/microhttpd/test_options.c b/src/microhttpd/test_options.c
index 3198c731..be033ae8 100644
--- a/src/microhttpd/test_options.c
+++ b/src/microhttpd/test_options.c
@@ -44,33 +44,33 @@ ahc_echo (void *cls,
44 const char *upload_data, size_t *upload_data_size, 44 const char *upload_data, size_t *upload_data_size,
45 void **unused) 45 void **unused)
46{ 46{
47 (void)cls; 47 (void) cls;
48 (void)connection; 48 (void) connection;
49 (void)url; 49 (void) url;
50 (void)method; 50 (void) method;
51 (void)version; 51 (void) version;
52 (void)upload_data; 52 (void) upload_data;
53 (void)upload_data_size; 53 (void) upload_data_size;
54 (void)unused; 54 (void) unused;
55 55
56 return 0; 56 return 0;
57} 57}
58 58
59static int 59static int
60test_wrap_loc (char *test_name, int (*test) (void)) 60test_wrap_loc (char *test_name, int (*test)(void))
61{ 61{
62 int ret; 62 int ret;
63 63
64 fprintf (stdout, "running test: %s ", test_name); 64 fprintf (stdout, "running test: %s ", test_name);
65 ret = test (); 65 ret = test ();
66 if (ret == 0) 66 if (ret == 0)
67 { 67 {
68 fprintf (stdout, "[pass]\n"); 68 fprintf (stdout, "[pass]\n");
69 } 69 }
70 else 70 else
71 { 71 {
72 fprintf (stdout, "[fail]\n"); 72 fprintf (stdout, "[fail]\n");
73 } 73 }
74 return ret; 74 return ret;
75} 75}
76 76
@@ -127,7 +127,7 @@ int
127main (int argc, char *const *argv) 127main (int argc, char *const *argv)
128{ 128{
129 unsigned int errorCount = 0; 129 unsigned int errorCount = 0;
130 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 130 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
131 131
132 errorCount += test_wrap_loc ("ip addr option", &test_ip_addr_option); 132 errorCount += test_wrap_loc ("ip addr option", &test_ip_addr_option);
133 133
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index acbb5b02..e1a167e7 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -48,13 +48,15 @@ const char *want[] = {
48 "x", NULL, NULL, NULL, "5", 48 "x", NULL, NULL, NULL, "5",
49#define URL_END (URL_START + 10) 49#define URL_END (URL_START + 10)
50 NULL, NULL, NULL, NULL, NULL, 50 NULL, NULL, NULL, NULL, NULL,
51#define FORM_DATA "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJoe Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata\r\n--AaB03x--\r\n" 51#define FORM_DATA \
52 "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJoe Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata\r\n--AaB03x--\r\n"
52#define FORM_START (URL_END + 5) 53#define FORM_START (URL_END + 5)
53 "field1", NULL, NULL, NULL, "Joe Blow", 54 "field1", NULL, NULL, NULL, "Joe Blow",
54 "pics", "file1.txt", "text/plain", "binary", "filedata", 55 "pics", "file1.txt", "text/plain", "binary", "filedata",
55#define FORM_END (FORM_START + 10) 56#define FORM_END (FORM_START + 10)
56 NULL, NULL, NULL, NULL, NULL, 57 NULL, NULL, NULL, NULL, NULL,
57#define FORM_NESTED_DATA "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJane Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"\r\nContent-type: multipart/mixed, boundary=BbC04y\r\n\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\n\r\nfiledata1\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file2.gif\"\r\nContent-type: image/gif\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata2\r\n--BbC04y--\r\n--AaB03x--" 58#define FORM_NESTED_DATA \
59 "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJane Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"\r\nContent-type: multipart/mixed, boundary=BbC04y\r\n\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\n\r\nfiledata1\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file2.gif\"\r\nContent-type: image/gif\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata2\r\n--BbC04y--\r\n--AaB03x--"
58#define FORM_NESTED_START (FORM_END + 5) 60#define FORM_NESTED_START (FORM_END + 5)
59 "field1", NULL, NULL, NULL, "Jane Blow", 61 "field1", NULL, NULL, NULL, "Jane Blow",
60 "pics", "file1.txt", "text/plain", NULL, "filedata1", 62 "pics", "file1.txt", "text/plain", NULL, "filedata1",
@@ -91,7 +93,7 @@ value_checker (void *cls,
91{ 93{
92 int *want_off = cls; 94 int *want_off = cls;
93 int idx = *want_off; 95 int idx = *want_off;
94 (void)kind; /* Unused. Silent compiler warning. */ 96 (void) kind; /* Unused. Silent compiler warning. */
95 97
96 98
97#if 0 99#if 0
@@ -110,10 +112,10 @@ value_checker (void *cls,
110 (mismatch (content_type, want[idx + 2])) || 112 (mismatch (content_type, want[idx + 2])) ||
111 (mismatch (transfer_encoding, want[idx + 3])) || 113 (mismatch (transfer_encoding, want[idx + 3])) ||
112 (0 != memcmp (data, &want[idx + 4][off], size))) 114 (0 != memcmp (data, &want[idx + 4][off], size)))
113 { 115 {
114 *want_off = -1; 116 *want_off = -1;
115 return MHD_NO; 117 return MHD_NO;
116 } 118 }
117 if (off + size == strlen (want[idx + 4])) 119 if (off + size == strlen (want[idx + 4]))
118 *want_off = idx + 5; 120 *want_off = idx + 5;
119 return MHD_YES; 121 return MHD_YES;
@@ -137,19 +139,20 @@ test_urlencoding (void)
137 connection.headers_received = &header; 139 connection.headers_received = &header;
138 header.header = MHD_HTTP_HEADER_CONTENT_TYPE; 140 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
139 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; 141 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
140 header.header_size = MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONTENT_TYPE); 142 header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
141 header.value_size = MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_FORM_URLENCODED); 143 header.value_size = MHD_STATICSTR_LEN_ (
144 MHD_HTTP_POST_ENCODING_FORM_URLENCODED);
142 header.kind = MHD_HEADER_KIND; 145 header.kind = MHD_HEADER_KIND;
143 pp = MHD_create_post_processor (&connection, 146 pp = MHD_create_post_processor (&connection,
144 1024, &value_checker, &want_off); 147 1024, &value_checker, &want_off);
145 i = 0; 148 i = 0;
146 size = strlen (URL_DATA); 149 size = strlen (URL_DATA);
147 while (i < size) 150 while (i < size)
148 { 151 {
149 delta = 1 + MHD_random_ () % (size - i); 152 delta = 1 + MHD_random_ () % (size - i);
150 MHD_post_process (pp, &URL_DATA[i], delta); 153 MHD_post_process (pp, &URL_DATA[i], delta);
151 i += delta; 154 i += delta;
152 } 155 }
153 MHD_destroy_post_processor (pp); 156 MHD_destroy_post_processor (pp);
154 if (want_off != URL_END) 157 if (want_off != URL_END)
155 return 1; 158 return 1;
@@ -183,8 +186,9 @@ test_multipart_garbage (void)
183 header.header = MHD_HTTP_HEADER_CONTENT_TYPE; 186 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
184 header.value = 187 header.value =
185 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; 188 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
186 header.header_size = MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONTENT_TYPE); 189 header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
187 header.value_size = MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"); 190 header.value_size = MHD_STATICSTR_LEN_ (
191 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x");
188 header.kind = MHD_HEADER_KIND; 192 header.kind = MHD_HEADER_KIND;
189 pp = MHD_create_post_processor (&connection, 193 pp = MHD_create_post_processor (&connection,
190 1024, &value_checker, &want_off); 194 1024, &value_checker, &want_off);
@@ -258,11 +262,11 @@ test_multipart (void)
258 i = 0; 262 i = 0;
259 size = strlen (FORM_DATA); 263 size = strlen (FORM_DATA);
260 while (i < size) 264 while (i < size)
261 { 265 {
262 delta = 1 + MHD_random_ () % (size - i); 266 delta = 1 + MHD_random_ () % (size - i);
263 MHD_post_process (pp, &FORM_DATA[i], delta); 267 MHD_post_process (pp, &FORM_DATA[i], delta);
264 i += delta; 268 i += delta;
265 } 269 }
266 MHD_destroy_post_processor (pp); 270 MHD_destroy_post_processor (pp);
267 if (want_off != FORM_END) 271 if (want_off != FORM_END)
268 return 2; 272 return 2;
@@ -295,11 +299,11 @@ test_nested_multipart (void)
295 i = 0; 299 i = 0;
296 size = strlen (FORM_NESTED_DATA); 300 size = strlen (FORM_NESTED_DATA);
297 while (i < size) 301 while (i < size)
298 { 302 {
299 delta = 1 + MHD_random_ () % (size - i); 303 delta = 1 + MHD_random_ () % (size - i);
300 MHD_post_process (pp, &FORM_NESTED_DATA[i], delta); 304 MHD_post_process (pp, &FORM_NESTED_DATA[i], delta);
301 i += delta; 305 i += delta;
302 } 306 }
303 MHD_destroy_post_processor (pp); 307 MHD_destroy_post_processor (pp);
304 if (want_off != FORM_NESTED_END) 308 if (want_off != FORM_NESTED_END)
305 return 4; 309 return 4;
@@ -331,11 +335,11 @@ test_empty_value (void)
331 i = 0; 335 i = 0;
332 size = strlen (URL_EMPTY_VALUE_DATA); 336 size = strlen (URL_EMPTY_VALUE_DATA);
333 while (i < size) 337 while (i < size)
334 { 338 {
335 delta = 1 + MHD_random_ () % (size - i); 339 delta = 1 + MHD_random_ () % (size - i);
336 MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta); 340 MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta);
337 i += delta; 341 i += delta;
338 } 342 }
339 MHD_destroy_post_processor (pp); 343 MHD_destroy_post_processor (pp);
340 if (want_off != URL_EMPTY_VALUE_END) 344 if (want_off != URL_EMPTY_VALUE_END)
341 return 8; 345 return 8;
@@ -349,7 +353,7 @@ int
349main (int argc, char *const *argv) 353main (int argc, char *const *argv)
350{ 354{
351 unsigned int errorCount = 0; 355 unsigned int errorCount = 0;
352 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 356 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
353 357
354 errorCount += test_multipart_splits (); 358 errorCount += test_multipart_splits ();
355 errorCount += test_multipart_garbage (); 359 errorCount += test_multipart_garbage ();
diff --git a/src/microhttpd/test_postprocessor_amp.c b/src/microhttpd/test_postprocessor_amp.c
index 6c0ebff4..e2ea4a54 100644
--- a/src/microhttpd/test_postprocessor_amp.c
+++ b/src/microhttpd/test_postprocessor_amp.c
@@ -7,18 +7,18 @@
7 7
8uint64_t num_errors; 8uint64_t num_errors;
9 9
10int check_post(void *cls, enum MHD_ValueKind kind, const char* key, 10int check_post (void *cls, enum MHD_ValueKind kind, const char*key,
11 const char* filename, const char* content_type, 11 const char*filename, const char*content_type,
12 const char* content_encoding, const char* data, 12 const char*content_encoding, const char*data,
13 uint64_t off, size_t size) 13 uint64_t off, size_t size)
14{ 14{
15 (void)cls; (void)kind; (void)filename; (void)content_type; /* Unused. Silent compiler warning. */ 15 (void) cls; (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
16 (void)content_encoding; (void)data; (void)off; (void)size; /* Unused. Silent compiler warning. */ 16 (void) content_encoding; (void) data; (void) off; (void) size; /* Unused. Silent compiler warning. */
17 if ((0 != strcmp(key, "a")) && (0 != strcmp(key, "b"))) 17 if ((0 != strcmp (key, "a")) && (0 != strcmp (key, "b")))
18 { 18 {
19 printf("ERROR: got unexpected '%s'\n", key); 19 printf ("ERROR: got unexpected '%s'\n", key);
20 num_errors++; 20 num_errors++;
21 } 21 }
22 22
23 return MHD_YES; 23 return MHD_YES;
24} 24}
@@ -30,7 +30,7 @@ main (int argc, char *const *argv)
30 struct MHD_Connection connection; 30 struct MHD_Connection connection;
31 struct MHD_HTTP_Header header; 31 struct MHD_HTTP_Header header;
32 struct MHD_PostProcessor *pp; 32 struct MHD_PostProcessor *pp;
33 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 33 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
34 34
35 num_errors = 0; 35 num_errors = 0;
36 memset (&connection, 0, sizeof (struct MHD_Connection)); 36 memset (&connection, 0, sizeof (struct MHD_Connection));
@@ -47,12 +47,12 @@ main (int argc, char *const *argv)
47 if (NULL == pp) 47 if (NULL == pp)
48 return 1; 48 return 1;
49 49
50 const char* post = "a=xx+xx+xxx+xxxxx+xxxx+xxxxxxxx+xxx+xxxxxx+xxx+xxx+xxxxxxx+xxxxx%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++--%3E%0A++++++++++++++%3Cxxxxx+xxxxx%3D%22xxx%25%22%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xxxxx%3D%22xxxxx%22%3E%0A+++++++++++++++++++%3Cxxxxx+xxxxx%3D%22xxx%25%22%3E%0A+++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++++++++++++++%3Cxx+xxxxx%3D%22xxxx%22%3E%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%22%3Exxxxx%3A%3C%2Fx%3E%0A%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%22%3Exxx%3A%3C%2Fx%3E%0A%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%3B+xxxx-xxxxxx%3A+xxxx%3B%22%3Exxxxx+xxxxx%3A%3C%2Fx%3E%0A+++++++++++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++++++%3C%2Fxxxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxxx.xx%3C%2Fxxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A++++++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxx.xx%3C%2Fxxxx%3E%0A+++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3Bxxxx-xxxxxx%3A+xxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxxx.xx%3C%2Fxxxx%3E%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++%3C%2Fxxxxx%3E%0A+++++++%3C%21--%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++xxx+xx+xxxxx+xxxxxxx+xxxxxxx%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++--%3E%0A+++%3C%2Fxxx%3E%0A%0A%0A%0A+++%3Cxxx+xxxxx%3D%22xxxxxxxxx%22+xx%3D%22xxxxxxxxx%22%3E%3C%2Fxxx%3E%0A%0A+++%3Cxxx+xx%3D%22xxxx%22+xxxxx%3D%22xxxx%22%3E%0A+++++++%3Cxxxxx+xxxxx%3D%22xxxxxxxxx%22%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xx%3D%22xxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xx%3D%22xxxxxxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxxxxxx%22%3E%3C%2Fxx%3E%0A+++++++++++++++%3Cxx+xx%3D%22xxxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xx%3D%22xxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++%3C%2Fxxxxx%3E%0A+++%3C%2Fxxx%3E%0A%3C%2Fxxx%3E%0A%0A%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A%0A%3C%2Fxxxx%3E%0A%3C%2Fxxxx%3E+&b=value"; 50 const char*post =
51 "a=xx+xx+xxx+xxxxx+xxxx+xxxxxxxx+xxx+xxxxxx+xxx+xxx+xxxxxxx+xxxxx%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++--%3E%0A++++++++++++++%3Cxxxxx+xxxxx%3D%22xxx%25%22%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xxxxx%3D%22xxxxx%22%3E%0A+++++++++++++++++++%3Cxxxxx+xxxxx%3D%22xxx%25%22%3E%0A+++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++++++++++++++%3Cxx+xxxxx%3D%22xxxx%22%3E%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%22%3Exxxxx%3A%3C%2Fx%3E%0A%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%22%3Exxx%3A%3C%2Fx%3E%0A%0A+++++++++++++++++++++++++++++++%3Cx+xxxxx%3D%22xxxx-xxxxx%3Axxxxx%3B+xxxx-xxxxxx%3A+xxxx%3B%22%3Exxxxx+xxxxx%3A%3C%2Fx%3E%0A+++++++++++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++++++%3C%2Fxxxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxxx.xx%3C%2Fxxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A++++++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxx.xx%3C%2Fxxxx%3E%0A+++++++++++++++++++%3C%2Fxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A++++++++++++++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxx%3D%22xxxx-xxxxx%3A+xxxxx%3Bxxxx-xxxxxx%3A+xxxx%3B+xxxxx%3A+xxxx%22%3E%26xxxxx%3B+%3Cxxxx%0A+++++++++++++++++++++++xxxxx%3D%22xxxxxxxxxxxxxxx%22%3Exxxx.xx%3C%2Fxxxx%3E%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++%3C%2Fxxxxx%3E%0A+++++++%3C%21--%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++xxx+xx+xxxxx+xxxxxxx+xxxxxxx%0A+++++++xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%0A+++++++--%3E%0A+++%3C%2Fxxx%3E%0A%0A%0A%0A+++%3Cxxx+xxxxx%3D%22xxxxxxxxx%22+xx%3D%22xxxxxxxxx%22%3E%3C%2Fxxx%3E%0A%0A+++%3Cxxx+xx%3D%22xxxx%22+xxxxx%3D%22xxxx%22%3E%0A+++++++%3Cxxxxx+xxxxx%3D%22xxxxxxxxx%22%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xx%3D%22xxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xx%3D%22xxxxxxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxxxxxx%22%3E%3C%2Fxx%3E%0A+++++++++++++++%3Cxx+xx%3D%22xxxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++++++%3Cxx%3E%0A+++++++++++++++%3Cxx+xxxxxxx%3D%22x%22+xx%3D%22xxxxxxxxxxxxx%22+xxxxx%3D%22xxxxxxxxxxxxx%22%3E%0A+++++++++++++++++++%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A+++++++++++++++%3C%2Fxx%3E%0A+++++++++++%3C%2Fxx%3E%0A+++++++%3C%2Fxxxxx%3E%0A+++%3C%2Fxxx%3E%0A%3C%2Fxxx%3E%0A%0A%3Cxxx+xx%3D%22xxxxxx%22%3E%3C%2Fxxx%3E%0A%0A%3C%2Fxxxx%3E%0A%3C%2Fxxxx%3E+&b=value";
51 52
52 if (MHD_YES != MHD_post_process (pp, post, strlen(post))) 53 if (MHD_YES != MHD_post_process (pp, post, strlen (post)))
53 num_errors++; 54 num_errors++;
54 MHD_destroy_post_processor (pp); 55 MHD_destroy_post_processor (pp);
55 56
56 return num_errors == 0 ? 0 : 2; 57 return num_errors == 0 ? 0 : 2;
57} 58}
58
diff --git a/src/microhttpd/test_postprocessor_large.c b/src/microhttpd/test_postprocessor_large.c
index 3421f734..68e5f671 100644
--- a/src/microhttpd/test_postprocessor_large.c
+++ b/src/microhttpd/test_postprocessor_large.c
@@ -43,8 +43,8 @@ value_checker (void *cls,
43 const char *data, uint64_t off, size_t size) 43 const char *data, uint64_t off, size_t size)
44{ 44{
45 unsigned int *pos = cls; 45 unsigned int *pos = cls;
46 (void)kind; (void)key; (void)filename; (void)content_type; /* Unused. Silent compiler warning. */ 46 (void) kind; (void) key; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
47 (void)transfer_encoding; (void)data; (void)off; /* Unused. Silent compiler warning. */ 47 (void) transfer_encoding; (void) data; (void) off; /* Unused. Silent compiler warning. */
48#if 0 48#if 0
49 fprintf (stderr, 49 fprintf (stderr,
50 "VC: %llu %u `%s' `%s' `%s' `%s' `%.*s'\n", 50 "VC: %llu %u `%s' `%s' `%s' `%s' `%.*s'\n",
@@ -87,11 +87,11 @@ test_simple_large ()
87 i = 0; 87 i = 0;
88 size = strlen (data); 88 size = strlen (data);
89 while (i < size) 89 while (i < size)
90 { 90 {
91 delta = 1 + MHD_random_ () % (size - i); 91 delta = 1 + MHD_random_ () % (size - i);
92 MHD_post_process (pp, &data[i], delta); 92 MHD_post_process (pp, &data[i], delta);
93 i += delta; 93 i += delta;
94 } 94 }
95 MHD_destroy_post_processor (pp); 95 MHD_destroy_post_processor (pp);
96 if (pos != sizeof (data) - 5) /* minus 0-termination and 'key=' */ 96 if (pos != sizeof (data) - 5) /* minus 0-termination and 'key=' */
97 return 1; 97 return 1;
@@ -102,7 +102,7 @@ int
102main (int argc, char *const *argv) 102main (int argc, char *const *argv)
103{ 103{
104 unsigned int errorCount = 0; 104 unsigned int errorCount = 0;
105 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 105 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
106 106
107 errorCount += test_simple_large (); 107 errorCount += test_simple_large ();
108 if (errorCount != 0) 108 if (errorCount != 0)
diff --git a/src/microhttpd/test_shutdown_select.c b/src/microhttpd/test_shutdown_select.c
index a334f63f..ae88658d 100644
--- a/src/microhttpd/test_shutdown_select.c
+++ b/src/microhttpd/test_shutdown_select.c
@@ -50,7 +50,7 @@
50#if defined(MHD_WINSOCK_SOCKETS) 50#if defined(MHD_WINSOCK_SOCKETS)
51#include <winsock2.h> 51#include <winsock2.h>
52#include <windows.h> 52#include <windows.h>
53#define sock_errno (WSAGetLastError()) 53#define sock_errno (WSAGetLastError ())
54#elif defined(MHD_POSIX_SOCKETS) 54#elif defined(MHD_POSIX_SOCKETS)
55#ifdef HAVE_SYS_TYPES_H 55#ifdef HAVE_SYS_TYPES_H
56#include <sys/types.h> 56#include <sys/types.h>
@@ -83,7 +83,7 @@
83#define SOMAXCONN 511 83#define SOMAXCONN 511
84#endif /* ! SOMAXCONN */ 84#endif /* ! SOMAXCONN */
85 85
86#if !defined(SHUT_RDWR) && defined(SD_BOTH) 86#if ! defined(SHUT_RDWR) && defined(SD_BOTH)
87#define SHUT_RDWR SD_BOTH 87#define SHUT_RDWR SD_BOTH
88#endif 88#endif
89 89
@@ -91,34 +91,34 @@ static bool check_err;
91 91
92 92
93static bool 93static bool
94has_in_name(const char *prog_name, const char *marker) 94has_in_name (const char *prog_name, const char *marker)
95{ 95{
96 size_t name_pos; 96 size_t name_pos;
97 size_t pos; 97 size_t pos;
98 98
99 if (!prog_name || !marker) 99 if (! prog_name || ! marker)
100 return 0; 100 return 0;
101 101
102 pos = 0; 102 pos = 0;
103 name_pos = 0; 103 name_pos = 0;
104 while (prog_name[pos]) 104 while (prog_name[pos])
105 { 105 {
106 if ('/' == prog_name[pos]) 106 if ('/' == prog_name[pos])
107 name_pos = pos + 1; 107 name_pos = pos + 1;
108#if defined(_WIN32) || defined(__CYGWIN__) 108#if defined(_WIN32) || defined(__CYGWIN__)
109 else if ('\\' == prog_name[pos]) 109 else if ('\\' == prog_name[pos])
110 name_pos = pos + 1; 110 name_pos = pos + 1;
111#endif /* _WIN32 || __CYGWIN__ */ 111#endif /* _WIN32 || __CYGWIN__ */
112 pos++; 112 pos++;
113 } 113 }
114 if (name_pos == pos) 114 if (name_pos == pos)
115 return true; 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
120static MHD_socket 120static MHD_socket
121start_socket_listen(int domain) 121start_socket_listen (int domain)
122{ 122{
123/* Create sockets similarly to daemon.c */ 123/* Create sockets similarly to daemon.c */
124 MHD_socket fd; 124 MHD_socket fd;
@@ -143,23 +143,23 @@ start_socket_listen(int domain)
143 cloexec_set = 0; 143 cloexec_set = 0;
144#endif /* !SOCK_CLOEXEC */ 144#endif /* !SOCK_CLOEXEC */
145 if ( (MHD_INVALID_SOCKET == fd) && (cloexec_set) ) 145 if ( (MHD_INVALID_SOCKET == fd) && (cloexec_set) )
146 { 146 {
147 fd = socket (domain, SOCK_STREAM, 0); 147 fd = socket (domain, SOCK_STREAM, 0);
148 cloexec_set = 0; 148 cloexec_set = 0;
149 } 149 }
150 if (MHD_INVALID_SOCKET == fd) 150 if (MHD_INVALID_SOCKET == fd)
151 { 151 {
152 fprintf (stderr, "Can't create socket: %u\n", 152 fprintf (stderr, "Can't create socket: %u\n",
153 (unsigned)sock_errno); 153 (unsigned) sock_errno);
154 return MHD_INVALID_SOCKET; 154 return MHD_INVALID_SOCKET;
155 } 155 }
156 156
157 if (!cloexec_set) 157 if (! cloexec_set)
158 { 158 {
159#ifdef MHD_WINSOCK_SOCKETS 159#ifdef MHD_WINSOCK_SOCKETS
160 if (!SetHandleInformation ((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) 160 if (! SetHandleInformation ((HANDLE) fd, HANDLE_FLAG_INHERIT, 0))
161 fprintf (stderr, "Failed to make socket non-inheritable: %u\n", 161 fprintf (stderr, "Failed to make socket non-inheritable: %u\n",
162 (unsigned int)GetLastError ()); 162 (unsigned int) GetLastError ());
163#else /* MHD_POSIX_SOCKETS */ 163#else /* MHD_POSIX_SOCKETS */
164 flags = fcntl (fd, F_GETFD); 164 flags = fcntl (fd, F_GETFD);
165 if ( ( (-1 == flags) || 165 if ( ( (-1 == flags) ||
@@ -168,7 +168,7 @@ start_socket_listen(int domain)
168 fprintf (stderr, "Failed to make socket non-inheritable: %s\n", 168 fprintf (stderr, "Failed to make socket non-inheritable: %s\n",
169 MHD_socket_last_strerr_ ()); 169 MHD_socket_last_strerr_ ());
170#endif /* MHD_POSIX_SOCKETS */ 170#endif /* MHD_POSIX_SOCKETS */
171 } 171 }
172 172
173 memset (&sock_addr, 0, sizeof (struct sockaddr_in)); 173 memset (&sock_addr, 0, sizeof (struct sockaddr_in));
174 sock_addr.sin_family = AF_INET; 174 sock_addr.sin_family = AF_INET;
@@ -179,73 +179,73 @@ start_socket_listen(int domain)
179 addrlen = sizeof (struct sockaddr_in); 179 addrlen = sizeof (struct sockaddr_in);
180 180
181 if (bind (fd, (const struct sockaddr*) &sock_addr, addrlen) < 0) 181 if (bind (fd, (const struct sockaddr*) &sock_addr, addrlen) < 0)
182 { 182 {
183 fprintf (stderr, "Failed to bind socket: %u\n", 183 fprintf (stderr, "Failed to bind socket: %u\n",
184 (unsigned)sock_errno); 184 (unsigned) sock_errno);
185 MHD_socket_close_chk_ (fd); 185 MHD_socket_close_chk_ (fd);
186 return MHD_INVALID_SOCKET; 186 return MHD_INVALID_SOCKET;
187 } 187 }
188 188
189#ifdef MHD_WINSOCK_SOCKETS 189#ifdef MHD_WINSOCK_SOCKETS
190 if (0 != ioctlsocket (fd, FIONBIO, &flags)) 190 if (0 != ioctlsocket (fd, FIONBIO, &flags))
191 { 191 {
192 fprintf (stderr, "Failed to make socket non-blocking: %u\n", 192 fprintf (stderr, "Failed to make socket non-blocking: %u\n",
193 (unsigned)sock_errno); 193 (unsigned) sock_errno);
194 MHD_socket_close_chk_ (fd); 194 MHD_socket_close_chk_ (fd);
195 return MHD_INVALID_SOCKET; 195 return MHD_INVALID_SOCKET;
196 } 196 }
197#else /* MHD_POSIX_SOCKETS */ 197#else /* MHD_POSIX_SOCKETS */
198 flags = fcntl (fd, F_GETFL); 198 flags = fcntl (fd, F_GETFL);
199 if ( ( (-1 == flags) || 199 if ( ( (-1 == flags) ||
200 ( (flags != (flags | O_NONBLOCK)) && 200 ( (flags != (flags | O_NONBLOCK)) &&
201 (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) ) ) ) 201 (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) ) ) )
202 { 202 {
203 fprintf (stderr, "Failed to make socket non-blocking: %s\n", 203 fprintf (stderr, "Failed to make socket non-blocking: %s\n",
204 MHD_socket_last_strerr_ ()); 204 MHD_socket_last_strerr_ ());
205 MHD_socket_close_chk_ (fd); 205 MHD_socket_close_chk_ (fd);
206 return MHD_INVALID_SOCKET; 206 return MHD_INVALID_SOCKET;
207 } 207 }
208#endif /* MHD_POSIX_SOCKETS */ 208#endif /* MHD_POSIX_SOCKETS */
209 209
210 if (listen(fd, SOMAXCONN) < 0) 210 if (listen (fd, SOMAXCONN) < 0)
211 { 211 {
212 fprintf (stderr, "Failed to listen on socket: %u\n", 212 fprintf (stderr, "Failed to listen on socket: %u\n",
213 (unsigned)sock_errno); 213 (unsigned) sock_errno);
214 MHD_socket_close_chk_ (fd); 214 MHD_socket_close_chk_ (fd);
215 return MHD_INVALID_SOCKET; 215 return MHD_INVALID_SOCKET;
216 } 216 }
217 217
218 return fd; 218 return fd;
219} 219}
220 220
221 221
222MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ 222MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
223select_thread(void* data) 223select_thread (void*data)
224{ 224{
225 /* use select() like in daemon.c */ 225 /* use select() like in daemon.c */
226 MHD_socket listen_sock = *((MHD_socket*)data); 226 MHD_socket listen_sock = *((MHD_socket*) data);
227 fd_set rs, ws; 227 fd_set rs, ws;
228 struct timeval timeout; 228 struct timeval timeout;
229 229
230 FD_ZERO(&rs); 230 FD_ZERO (&rs);
231 FD_ZERO(&ws); 231 FD_ZERO (&ws);
232 FD_SET(listen_sock, &rs); 232 FD_SET (listen_sock, &rs);
233 timeout.tv_usec = 0; 233 timeout.tv_usec = 0;
234 timeout.tv_sec = 7; 234 timeout.tv_sec = 7;
235 235
236 check_err = (0 > MHD_SYS_select_(listen_sock + 1, &rs, &ws, NULL, &timeout)); 236 check_err = (0 > MHD_SYS_select_ (listen_sock + 1, &rs, &ws, NULL, &timeout));
237 237
238 return (MHD_THRD_RTRN_TYPE_)0; 238 return (MHD_THRD_RTRN_TYPE_) 0;
239} 239}
240 240
241 241
242#ifdef HAVE_POLL 242#ifdef HAVE_POLL
243MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ 243MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
244poll_thread(void* data) 244poll_thread (void*data)
245{ 245{
246 /* use poll() like in daemon.c */ 246 /* use poll() like in daemon.c */
247 struct pollfd p[1]; 247 struct pollfd p[1];
248 MHD_socket listen_sock = *((MHD_socket*)data); 248 MHD_socket listen_sock = *((MHD_socket*) data);
249 249
250 p[0].fd = listen_sock; 250 p[0].fd = listen_sock;
251 p[0].events = POLLIN; 251 p[0].events = POLLIN;
@@ -253,22 +253,22 @@ poll_thread(void* data)
253 253
254 check_err = (0 > MHD_sys_poll_ (p, 1, 7000)); 254 check_err = (0 > MHD_sys_poll_ (p, 1, 7000));
255 255
256 return (MHD_THRD_RTRN_TYPE_)0; 256 return (MHD_THRD_RTRN_TYPE_) 0;
257} 257}
258#endif /* HAVE_POLL */ 258#endif /* HAVE_POLL */
259 259
260 260
261static void 261static void
262local_sleep(unsigned seconds) 262local_sleep (unsigned seconds)
263{ 263{
264#if defined(_WIN32) && !defined(__CYGWIN__) 264#if defined(_WIN32) && ! defined(__CYGWIN__)
265 Sleep(seconds * 1000); 265 Sleep (seconds * 1000);
266#else 266#else
267 unsigned seconds_left = seconds; 267 unsigned seconds_left = seconds;
268 do 268 do
269 { 269 {
270 seconds_left = sleep(seconds_left); 270 seconds_left = sleep (seconds_left);
271 } while (seconds_left > 0); 271 } while (seconds_left > 0);
272#endif 272#endif
273} 273}
274 274
@@ -279,7 +279,7 @@ main (int argc, char *const *argv)
279 int i; 279 int i;
280 time_t start_t, end_t; 280 time_t start_t, end_t;
281 int result = 0; 281 int result = 0;
282 MHD_THRD_RTRN_TYPE_ (MHD_THRD_CALL_SPEC_ *test_func)(void* data); 282 MHD_THRD_RTRN_TYPE_ (MHD_THRD_CALL_SPEC_ * test_func)(void*data);
283#ifdef MHD_WINSOCK_SOCKETS 283#ifdef MHD_WINSOCK_SOCKETS
284 WORD ver_req; 284 WORD ver_req;
285 WSADATA wsa_data; 285 WSADATA wsa_data;
@@ -287,101 +287,102 @@ main (int argc, char *const *argv)
287#endif /* MHD_WINSOCK_SOCKETS */ 287#endif /* MHD_WINSOCK_SOCKETS */
288 bool test_poll; 288 bool test_poll;
289 bool must_ignore; 289 bool must_ignore;
290 (void)argc; /* Unused. Silent compiler warning. */ 290 (void) argc; /* Unused. Silent compiler warning. */
291 291
292 test_poll = has_in_name(argv[0], "_poll"); 292 test_poll = has_in_name (argv[0], "_poll");
293 must_ignore = has_in_name(argv[0], "_ignore"); 293 must_ignore = has_in_name (argv[0], "_ignore");
294 if (! test_poll) 294 if (! test_poll)
295 test_func = &select_thread; 295 test_func = &select_thread;
296 else 296 else
297 { 297 {
298#ifndef HAVE_POLL 298#ifndef HAVE_POLL
299 return 77; 299 return 77;
300#else /* ! HAVE_POLL */ 300#else /* ! HAVE_POLL */
301 test_func = &poll_thread; 301 test_func = &poll_thread;
302#endif /* ! HAVE_POLL */ 302#endif /* ! HAVE_POLL */
303 } 303 }
304 304
305#ifdef MHD_WINSOCK_SOCKETS 305#ifdef MHD_WINSOCK_SOCKETS
306 ver_req = MAKEWORD(2, 2); 306 ver_req = MAKEWORD (2, 2);
307 307
308 err = WSAStartup(ver_req, &wsa_data); 308 err = WSAStartup (ver_req, &wsa_data);
309 if (err != 0 || MAKEWORD(2, 2) != wsa_data.wVersion) 309 if ((err != 0)||(MAKEWORD (2, 2) != wsa_data.wVersion))
310 { 310 {
311 printf("WSAStartup() failed\n"); 311 printf ("WSAStartup() failed\n");
312 WSACleanup(); 312 WSACleanup ();
313 return 99; 313 return 99;
314 } 314 }
315#endif /* MHD_WINSOCK_SOCKETS */ 315#endif /* MHD_WINSOCK_SOCKETS */
316 316
317 /* try several times to ensure that accidental incoming connection 317 /* try several times to ensure that accidental incoming connection
318 * didn't interfere with test results 318 * didn't interfere with test results
319 */ 319 */
320 for (i = 0; i < 5 && result == 0; i++) 320 for (i = 0; i < 5 && result == 0; i++)
321 { 321 {
322 MHD_thread_handle_ sel_thrd; 322 MHD_thread_handle_ sel_thrd;
323 /* fprintf(stdout, "Creating, binding and listening socket...\n"); */ 323 /* fprintf(stdout, "Creating, binding and listening socket...\n"); */
324 MHD_socket listen_socket = start_socket_listen (AF_INET); 324 MHD_socket listen_socket = start_socket_listen (AF_INET);
325 if (MHD_INVALID_SOCKET == listen_socket) 325 if (MHD_INVALID_SOCKET == listen_socket)
326 return 99; 326 return 99;
327 327
328 check_err = true; 328 check_err = true;
329 /* fprintf (stdout, "Starting select() thread...\n"); */ 329 /* fprintf (stdout, "Starting select() thread...\n"); */
330#if defined(MHD_USE_POSIX_THREADS) 330#if defined(MHD_USE_POSIX_THREADS)
331 if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket)) 331 if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket))
332 { 332 {
333 MHD_socket_close_chk_ (listen_socket); 333 MHD_socket_close_chk_ (listen_socket);
334 fprintf (stderr, "Can't start thread\n"); 334 fprintf (stderr, "Can't start thread\n");
335 return 99; 335 return 99;
336 } 336 }
337#elif defined(MHD_USE_W32_THREADS) 337#elif defined(MHD_USE_W32_THREADS)
338 sel_thrd = (HANDLE)_beginthreadex (NULL, 0, test_func, &listen_socket, 0, NULL); 338 sel_thrd = (HANDLE) _beginthreadex (NULL, 0, test_func, &listen_socket, 0,
339 if (0 == (sel_thrd)) 339 NULL);
340 { 340 if (0 == (sel_thrd))
341 MHD_socket_close_chk_ (listen_socket); 341 {
342 fprintf (stderr, "Can't start select() thread\n"); 342 MHD_socket_close_chk_ (listen_socket);
343 return 99; 343 fprintf (stderr, "Can't start select() thread\n");
344 } 344 return 99;
345 }
345#else 346#else
346#error No threading lib available 347#error No threading lib available
347#endif 348#endif
348 /* fprintf (stdout, "Waiting...\n"); */ 349 /* fprintf (stdout, "Waiting...\n"); */
349 local_sleep(1); /* make sure that select() is started */ 350 local_sleep (1); /* make sure that select() is started */
350 351
351 /* fprintf (stdout, "Shutting down socket...\n"); */ 352 /* fprintf (stdout, "Shutting down socket...\n"); */
352 start_t = time (NULL); 353 start_t = time (NULL);
353 shutdown (listen_socket, SHUT_RDWR); 354 shutdown (listen_socket, SHUT_RDWR);
354 355
355 /* fprintf (stdout, "Waiting for thread to finish...\n"); */ 356 /* fprintf (stdout, "Waiting for thread to finish...\n"); */
356 if (!MHD_join_thread_(sel_thrd)) 357 if (! MHD_join_thread_ (sel_thrd))
357 { 358 {
358 MHD_socket_close_chk_(listen_socket); 359 MHD_socket_close_chk_ (listen_socket);
359 fprintf (stderr, "Can't join select() thread\n"); 360 fprintf (stderr, "Can't join select() thread\n");
360 return 99; 361 return 99;
361 } 362 }
362 if (check_err) 363 if (check_err)
363 { 364 {
364 MHD_socket_close_chk_(listen_socket); 365 MHD_socket_close_chk_ (listen_socket);
365 fprintf (stderr, "Error in waiting thread\n"); 366 fprintf (stderr, "Error in waiting thread\n");
366 return 99; 367 return 99;
367 } 368 }
368 end_t = time (NULL); 369 end_t = time (NULL);
369 /* fprintf (stdout, "Thread finished.\n"); */ 370 /* fprintf (stdout, "Thread finished.\n"); */
370 MHD_socket_close_chk_(listen_socket); 371 MHD_socket_close_chk_ (listen_socket);
371 372
372 if (start_t == (time_t)-1 || end_t == (time_t)-1) 373 if ((start_t == (time_t) -1) ||(end_t == (time_t) -1) )
373 { 374 {
374 MHD_socket_close_chk_(listen_socket); 375 MHD_socket_close_chk_ (listen_socket);
375 fprintf (stderr, "Can't get current time\n"); 376 fprintf (stderr, "Can't get current time\n");
376 return 99; 377 return 99;
377 }
378 if (end_t - start_t > 3)
379 result++;
380 } 378 }
379 if (end_t - start_t > 3)
380 result++;
381 }
381 382
382#ifdef MHD_WINSOCK_SOCKETS 383#ifdef MHD_WINSOCK_SOCKETS
383 WSACleanup(); 384 WSACleanup ();
384#endif /* MHD_WINSOCK_SOCKETS */ 385#endif /* MHD_WINSOCK_SOCKETS */
385 386
386 return must_ignore ? (!result) : (result); 387 return must_ignore ? (! result) : (result);
387} 388}
diff --git a/src/microhttpd/test_start_stop.c b/src/microhttpd/test_start_stop.c
index d27291b8..541cc5c5 100644
--- a/src/microhttpd/test_start_stop.c
+++ b/src/microhttpd/test_start_stop.c
@@ -27,10 +27,10 @@
27#include "platform.h" 27#include "platform.h"
28#include <microhttpd.h> 28#include <microhttpd.h>
29 29
30#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 30#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
31#undef CPU_COUNT 31#undef CPU_COUNT
32#endif 32#endif
33#if !defined(CPU_COUNT) 33#if ! defined(CPU_COUNT)
34#define CPU_COUNT 2 34#define CPU_COUNT 2
35#endif 35#endif
36 36
@@ -44,9 +44,9 @@ ahc_echo (void *cls,
44 const char *upload_data, size_t *upload_data_size, 44 const char *upload_data, size_t *upload_data_size,
45 void **unused) 45 void **unused)
46{ 46{
47 (void)cls;(void)connection;(void)url; /* Unused. Silent compiler warning. */ 47 (void) cls; (void) connection; (void) url; /* Unused. Silent compiler warning. */
48 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 48 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
49 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 49 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
50 50
51 return MHD_NO; 51 return MHD_NO;
52} 52}
@@ -58,7 +58,8 @@ testInternalGet (int poll_flag)
58{ 58{
59 struct MHD_Daemon *d; 59 struct MHD_Daemon *d;
60 60
61 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 61 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
62 | poll_flag,
62 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 63 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
63 if (d == NULL) 64 if (d == NULL)
64 return 1; 65 return 1;
@@ -71,7 +72,9 @@ testMultithreadedGet (int poll_flag)
71{ 72{
72 struct MHD_Daemon *d; 73 struct MHD_Daemon *d;
73 74
74 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 75 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
76 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
77 | poll_flag,
75 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 78 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
76 if (d == NULL) 79 if (d == NULL)
77 return 2; 80 return 2;
@@ -85,7 +88,8 @@ testMultithreadedPoolGet (int poll_flag)
85{ 88{
86 struct MHD_Daemon *d; 89 struct MHD_Daemon *d;
87 90
88 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 91 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
92 | poll_flag,
89 0, NULL, NULL, &ahc_echo, "GET", 93 0, NULL, NULL, &ahc_echo, "GET",
90 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); 94 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
91 if (d == NULL) 95 if (d == NULL)
@@ -103,8 +107,8 @@ testExternalGet ()
103 107
104 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 108 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
105 0, NULL, NULL, 109 0, NULL, NULL,
106 &ahc_echo, "GET", 110 &ahc_echo, "GET",
107 MHD_OPTION_END); 111 MHD_OPTION_END);
108 if (NULL == d) 112 if (NULL == d)
109 return 8; 113 return 8;
110 MHD_stop_daemon (d); 114 MHD_stop_daemon (d);
@@ -127,21 +131,21 @@ main (int argc,
127#endif 131#endif
128 errorCount += testExternalGet (); 132 errorCount += testExternalGet ();
129#if defined (MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 133#if defined (MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
130 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) 134 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
131 { 135 {
132 errorCount += testInternalGet(MHD_USE_POLL); 136 errorCount += testInternalGet (MHD_USE_POLL);
133 errorCount += testMultithreadedGet(MHD_USE_POLL); 137 errorCount += testMultithreadedGet (MHD_USE_POLL);
134 errorCount += testMultithreadedPoolGet(MHD_USE_POLL); 138 errorCount += testMultithreadedPoolGet (MHD_USE_POLL);
135 } 139 }
136 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) 140 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
137 { 141 {
138 errorCount += testInternalGet(MHD_USE_EPOLL); 142 errorCount += testInternalGet (MHD_USE_EPOLL);
139 errorCount += testMultithreadedPoolGet(MHD_USE_EPOLL); 143 errorCount += testMultithreadedPoolGet (MHD_USE_EPOLL);
140 } 144 }
141#endif 145#endif
142 if (0 != errorCount) 146 if (0 != errorCount)
143 fprintf (stderr, 147 fprintf (stderr,
144 "Error (code: %u)\n", 148 "Error (code: %u)\n",
145 errorCount); 149 errorCount);
146 return errorCount != 0; /* 0 == pass */ 150 return errorCount != 0; /* 0 == pass */
147} 151}
diff --git a/src/microhttpd/test_str.c b/src/microhttpd/test_str.c
index 12e12a85..8739a23a 100644
--- a/src/microhttpd/test_str.c
+++ b/src/microhttpd/test_str.c
@@ -46,235 +46,237 @@ static int verbose = 0; /* verbose level (0-3)*/
46 * Functions must not depend of current current locale, 46 * Functions must not depend of current current locale,
47 * so result must be the same in any locale. 47 * so result must be the same in any locale.
48 */ 48 */
49static const char * const locale_names[] = { 49static const char *const locale_names[] = {
50 "C", 50 "C",
51 "", /* System default locale */ 51 "", /* System default locale */
52#if defined(_WIN32) && !defined(__CYGWIN__) 52#if defined(_WIN32) && ! defined(__CYGWIN__)
53 ".OCP", /* W32 system default OEM code page */ 53 ".OCP", /* W32 system default OEM code page */
54 ".ACP", /* W32 system default ANSI code page */ 54 ".ACP", /* W32 system default ANSI code page */
55 ".65001", /* UTF-8 */ 55 ".65001", /* UTF-8 */
56 ".437", 56 ".437",
57 ".850", 57 ".850",
58 ".857", 58 ".857",
59 ".866", 59 ".866",
60 ".1250", 60 ".1250",
61 ".1251", 61 ".1251",
62 ".1252", 62 ".1252",
63 ".1254", 63 ".1254",
64 ".20866", /* number for KOI8-R */ 64 ".20866", /* number for KOI8-R */
65 ".28591", /* number for ISO-8859-1 */ 65 ".28591", /* number for ISO-8859-1 */
66 ".28595", /* number for ISO-8859-5 */ 66 ".28595", /* number for ISO-8859-5 */
67 ".28599", /* number for ISO-8859-9 */ 67 ".28599", /* number for ISO-8859-9 */
68 ".28605", /* number for ISO-8859-15 */ 68 ".28605", /* number for ISO-8859-15 */
69 "en", 69 "en",
70 "english", 70 "english",
71 "en-US", 71 "en-US",
72 "English-US", 72 "English-US",
73 "en-US.437", 73 "en-US.437",
74 "English_United States.437", 74 "English_United States.437",
75 "en-US.1252", 75 "en-US.1252",
76 "English_United States.1252", 76 "English_United States.1252",
77 "English_United States.28591", 77 "English_United States.28591",
78 "English_United States.65001", 78 "English_United States.65001",
79 "fra", 79 "fra",
80 "french", 80 "french",
81 "fr-FR", 81 "fr-FR",
82 "French_France", 82 "French_France",
83 "fr-FR.850", 83 "fr-FR.850",
84 "french_france.850", 84 "french_france.850",
85 "fr-FR.1252", 85 "fr-FR.1252",
86 "French_france.1252", 86 "French_france.1252",
87 "French_france.28605", 87 "French_france.28605",
88 "French_France.65001", 88 "French_France.65001",
89 "de", 89 "de",
90 "de-DE", 90 "de-DE",
91 "de-DE.850", 91 "de-DE.850",
92 "German_Germany.850", 92 "German_Germany.850",
93 "German_Germany.1250", 93 "German_Germany.1250",
94 "de-DE.1252", 94 "de-DE.1252",
95 "German_Germany.1252", 95 "German_Germany.1252",
96 "German_Germany.28605", 96 "German_Germany.28605",
97 "German_Germany.65001", 97 "German_Germany.65001",
98 "tr", 98 "tr",
99 "trk", 99 "trk",
100 "turkish", 100 "turkish",
101 "tr-TR", 101 "tr-TR",
102 "tr-TR.1254", 102 "tr-TR.1254",
103 "Turkish_Turkey.1254", 103 "Turkish_Turkey.1254",
104 "tr-TR.857", 104 "tr-TR.857",
105 "Turkish_Turkey.857", 105 "Turkish_Turkey.857",
106 "Turkish_Turkey.28599", 106 "Turkish_Turkey.28599",
107 "Turkish_Turkey.65001", 107 "Turkish_Turkey.65001",
108 "ru", 108 "ru",
109 "ru-RU", 109 "ru-RU",
110 "Russian", 110 "Russian",
111 "ru-RU.866", 111 "ru-RU.866",
112 "Russian_Russia.866", 112 "Russian_Russia.866",
113 "ru-RU.1251", 113 "ru-RU.1251",
114 "Russian_Russia.1251", 114 "Russian_Russia.1251",
115 "Russian_Russia.20866", 115 "Russian_Russia.20866",
116 "Russian_Russia.28595", 116 "Russian_Russia.28595",
117 "Russian_Russia.65001", 117 "Russian_Russia.65001",
118 "zh-Hans", 118 "zh-Hans",
119 "zh-Hans.936", 119 "zh-Hans.936",
120 "chinese-simplified" 120 "chinese-simplified"
121#else /* ! _WIN32 || __CYGWIN__ */ 121#else /* ! _WIN32 || __CYGWIN__ */
122 "C.UTF-8", 122 "C.UTF-8",
123 "POSIX", 123 "POSIX",
124 "en", 124 "en",
125 "en_US", 125 "en_US",
126 "en_US.ISO-8859-1", 126 "en_US.ISO-8859-1",
127 "en_US.ISO_8859-1", 127 "en_US.ISO_8859-1",
128 "en_US.ISO8859-1", 128 "en_US.ISO8859-1",
129 "en_US.iso88591", 129 "en_US.iso88591",
130 "en_US.ISO-8859-15", 130 "en_US.ISO-8859-15",
131 "en_US.DIS_8859-15", 131 "en_US.DIS_8859-15",
132 "en_US.ISO8859-15", 132 "en_US.ISO8859-15",
133 "en_US.iso885915", 133 "en_US.iso885915",
134 "en_US.1252", 134 "en_US.1252",
135 "en_US.CP1252", 135 "en_US.CP1252",
136 "en_US.UTF-8", 136 "en_US.UTF-8",
137 "en_US.utf8", 137 "en_US.utf8",
138 "fr", 138 "fr",
139 "fr_FR", 139 "fr_FR",
140 "fr_FR.850", 140 "fr_FR.850",
141 "fr_FR.IBM850", 141 "fr_FR.IBM850",
142 "fr_FR.1252", 142 "fr_FR.1252",
143 "fr_FR.CP1252", 143 "fr_FR.CP1252",
144 "fr_FR.ISO-8859-1", 144 "fr_FR.ISO-8859-1",
145 "fr_FR.ISO_8859-1", 145 "fr_FR.ISO_8859-1",
146 "fr_FR.ISO8859-1", 146 "fr_FR.ISO8859-1",
147 "fr_FR.iso88591", 147 "fr_FR.iso88591",
148 "fr_FR.ISO-8859-15", 148 "fr_FR.ISO-8859-15",
149 "fr_FR.DIS_8859-15", 149 "fr_FR.DIS_8859-15",
150 "fr_FR.ISO8859-15", 150 "fr_FR.ISO8859-15",
151 "fr_FR.iso8859-15", 151 "fr_FR.iso8859-15",
152 "fr_FR.UTF-8", 152 "fr_FR.UTF-8",
153 "fr_FR.utf8", 153 "fr_FR.utf8",
154 "de", 154 "de",
155 "de_DE", 155 "de_DE",
156 "de_DE.850", 156 "de_DE.850",
157 "de_DE.IBM850", 157 "de_DE.IBM850",
158 "de_DE.1250", 158 "de_DE.1250",
159 "de_DE.CP1250", 159 "de_DE.CP1250",
160 "de_DE.1252", 160 "de_DE.1252",
161 "de_DE.CP1252", 161 "de_DE.CP1252",
162 "de_DE.ISO-8859-1", 162 "de_DE.ISO-8859-1",
163 "de_DE.ISO_8859-1", 163 "de_DE.ISO_8859-1",
164 "de_DE.ISO8859-1", 164 "de_DE.ISO8859-1",
165 "de_DE.iso88591", 165 "de_DE.iso88591",
166 "de_DE.ISO-8859-15", 166 "de_DE.ISO-8859-15",
167 "de_DE.DIS_8859-15", 167 "de_DE.DIS_8859-15",
168 "de_DE.ISO8859-15", 168 "de_DE.ISO8859-15",
169 "de_DE.iso885915", 169 "de_DE.iso885915",
170 "de_DE.UTF-8", 170 "de_DE.UTF-8",
171 "de_DE.utf8", 171 "de_DE.utf8",
172 "tr", 172 "tr",
173 "tr_TR", 173 "tr_TR",
174 "tr_TR.1254", 174 "tr_TR.1254",
175 "tr_TR.CP1254", 175 "tr_TR.CP1254",
176 "tr_TR.857", 176 "tr_TR.857",
177 "tr_TR.IBM857", 177 "tr_TR.IBM857",
178 "tr_TR.ISO-8859-9", 178 "tr_TR.ISO-8859-9",
179 "tr_TR.ISO8859-9", 179 "tr_TR.ISO8859-9",
180 "tr_TR.iso88599", 180 "tr_TR.iso88599",
181 "tr_TR.UTF-8", 181 "tr_TR.UTF-8",
182 "tr_TR.utf8", 182 "tr_TR.utf8",
183 "ru", 183 "ru",
184 "ru_RU", 184 "ru_RU",
185 "ru_RU.1251", 185 "ru_RU.1251",
186 "ru_RU.CP1251", 186 "ru_RU.CP1251",
187 "ru_RU.866", 187 "ru_RU.866",
188 "ru_RU.IBM866", 188 "ru_RU.IBM866",
189 "ru_RU.KOI8-R", 189 "ru_RU.KOI8-R",
190 "ru_RU.koi8-r", 190 "ru_RU.koi8-r",
191 "ru_RU.KOI8-RU", 191 "ru_RU.KOI8-RU",
192 "ru_RU.ISO-8859-5", 192 "ru_RU.ISO-8859-5",
193 "ru_RU.ISO_8859-5", 193 "ru_RU.ISO_8859-5",
194 "ru_RU.ISO8859-5", 194 "ru_RU.ISO8859-5",
195 "ru_RU.iso88595", 195 "ru_RU.iso88595",
196 "ru_RU.UTF-8", 196 "ru_RU.UTF-8",
197 "zh_CN", 197 "zh_CN",
198 "zh_CN.GB2312", 198 "zh_CN.GB2312",
199 "zh_CN.UTF-8", 199 "zh_CN.UTF-8",
200#endif /* ! _WIN32 || __CYGWIN__ */ 200#endif /* ! _WIN32 || __CYGWIN__ */
201}; 201};
202 202
203static const unsigned int locale_name_count = sizeof(locale_names) / sizeof(locale_names[0]); 203static const unsigned int locale_name_count = sizeof(locale_names)
204 / sizeof(locale_names[0]);
204 205
205 206
206/* 207/*
207 * Helper functions 208 * Helper functions
208 */ 209 */
209 210
210int set_test_locale(unsigned int num) 211int set_test_locale (unsigned int num)
211{ 212{
212 if (num >= locale_name_count) 213 if (num >= locale_name_count)
213 return -1; 214 return -1;
214 if (verbose > 2) 215 if (verbose > 2)
215 printf("Setting locale \"%s\":", locale_names[num]); 216 printf ("Setting locale \"%s\":", locale_names[num]);
216 if (setlocale(LC_ALL, locale_names[num])) 217 if (setlocale (LC_ALL, locale_names[num]))
217 { 218 {
218 if (verbose > 2) 219 if (verbose > 2)
219 printf(" succeed.\n"); 220 printf (" succeed.\n");
220 return 1; 221 return 1;
221 } 222 }
222 if (verbose > 2) 223 if (verbose > 2)
223 printf(" failed.\n"); 224 printf (" failed.\n");
224 return 0; 225 return 0;
225} 226}
226 227
227const char * get_current_locale_str(void) 228const char *get_current_locale_str (void)
228{ 229{
229 char const * loc_str = setlocale(LC_ALL, NULL); 230 char const *loc_str = setlocale (LC_ALL, NULL);
230 return loc_str ? loc_str : "unknown"; 231 return loc_str ? loc_str : "unknown";
231} 232}
232 233
233static char tmp_bufs[4][4*1024]; /* should be enough for testing */ 234static char tmp_bufs[4][4 * 1024]; /* should be enough for testing */
234static size_t buf_idx = 0; 235static size_t buf_idx = 0;
235 236
236/* print non-printable chars as char codes */ 237/* print non-printable chars as char codes */
237char * n_prnt(const char * str) 238char *n_prnt (const char *str)
238{ 239{
239 static char * buf; /* should be enough for testing */ 240 static char *buf; /* should be enough for testing */
240 static const size_t buf_size = sizeof(tmp_bufs[0]); 241 static const size_t buf_size = sizeof(tmp_bufs[0]);
241 const unsigned char * p = (const unsigned char*)str; 242 const unsigned char *p = (const unsigned char*) str;
242 size_t w_pos = 0; 243 size_t w_pos = 0;
243 if (++buf_idx > 3) 244 if (++buf_idx > 3)
244 buf_idx = 0; 245 buf_idx = 0;
245 buf = tmp_bufs[buf_idx]; 246 buf = tmp_bufs[buf_idx];
246 247
247 while(*p && w_pos + 1 < buf_size) 248 while (*p && w_pos + 1 < buf_size)
249 {
250 const unsigned char c = *p;
251 if ((c == '\\') ||(c == '"') )
248 { 252 {
249 const unsigned char c = *p; 253 if (w_pos + 2 >= buf_size)
250 if (c == '\\' || c == '"') 254 break;
251 { 255 buf[w_pos++] = '\\';
252 if (w_pos + 2 >= buf_size) 256 buf[w_pos++] = c;
253 break;
254 buf[w_pos++] = '\\';
255 buf[w_pos++] = c;
256 }
257 else if (c >= 0x20 && c <= 0x7E)
258 buf[w_pos++] = c;
259 else
260 {
261 if (w_pos + 4 >= buf_size)
262 break;
263 if (snprintf(buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned int)c) != 4)
264 break;
265 w_pos += 4;
266 }
267 p++;
268 } 257 }
258 else if ((c >= 0x20) &&(c <= 0x7E) )
259 buf[w_pos++] = c;
260 else
261 {
262 if (w_pos + 4 >= buf_size)
263 break;
264 if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned
265 int) c) != 4)
266 break;
267 w_pos += 4;
268 }
269 p++;
270 }
269 if (*p) 271 if (*p)
270 { /* not full string is printed */ 272 { /* not full string is printed */
271 /* enough space for "..." ? */ 273 /* enough space for "..." ? */
272 if (w_pos + 3 > buf_size) 274 if (w_pos + 3 > buf_size)
273 w_pos = buf_size - 4; 275 w_pos = buf_size - 4;
274 buf[w_pos++] = '.'; 276 buf[w_pos++] = '.';
275 buf[w_pos++] = '.'; 277 buf[w_pos++] = '.';
276 buf[w_pos++] = '.'; 278 buf[w_pos++] = '.';
277 } 279 }
278 buf[w_pos] = 0; 280 buf[w_pos] = 0;
279 return buf; 281 return buf;
280} 282}
@@ -282,7 +284,7 @@ char * n_prnt(const char * str)
282 284
283struct str_with_len 285struct str_with_len
284{ 286{
285 const char * const str; 287 const char *const str;
286 const size_t len; 288 const size_t len;
287}; 289};
288 290
@@ -299,118 +301,129 @@ struct two_eq_strs
299}; 301};
300 302
301static const struct two_eq_strs eq_strings[] = { 303static const struct two_eq_strs eq_strings[] = {
302 {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`.")}, 304 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN (
303 {D_STR_W_LEN("Simple string."), D_STR_W_LEN("Simple string.")}, 305 "1234567890!@~%&$@#{}[]\\/!?`.")},
304 {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("SIMPLE STRING.")}, 306 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple string.")},
305 {D_STR_W_LEN("simple string."), D_STR_W_LEN("simple string.")}, 307 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("SIMPLE STRING.")},
306 {D_STR_W_LEN("simple string."), D_STR_W_LEN("Simple String.")}, 308 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string.")},
307 {D_STR_W_LEN("sImPlE StRiNg."), D_STR_W_LEN("SiMpLe sTrInG.")}, 309 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("Simple String.")},
308 {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("simple string.")}, 310 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SiMpLe sTrInG.")},
309 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz")}, 311 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.")},
310 {D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 312 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN (
311 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 313 "abcdefghijklmnopqrstuvwxyz")},
312 {D_STR_W_LEN("zyxwvutsrqponMLKJIHGFEDCBA"), D_STR_W_LEN("ZYXWVUTSRQPONmlkjihgfedcba")}, 314 {D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), D_STR_W_LEN (
313 315 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")},
314 {D_STR_W_LEN("Cha\x8cne pour le test."), 316 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN (
315 D_STR_W_LEN("Cha\x8cne pour le test.")}, /* "Chaîne pour le test." in CP850 */ 317 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")},
316 {D_STR_W_LEN("cha\x8cne pOur Le TEst."), 318 {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"), D_STR_W_LEN (
317 D_STR_W_LEN("Cha\x8cne poUr Le teST.")}, 319 "ZYXWVUTSRQPONmlkjihgfedcba")},
318 {D_STR_W_LEN("Cha\xeene pour le test."), 320
319 D_STR_W_LEN("Cha\xeene pour le test.")}, /* "Chaîne pour le test." in CP1252/ISO-8859-1/ISO-8859-15 */ 321 {D_STR_W_LEN ("Cha\x8cne pour le test."),
320 {D_STR_W_LEN("CHa\xeene POUR le test."), 322 D_STR_W_LEN ("Cha\x8cne pour le test.")}, /* "Chaîne pour le test." in CP850 */
321 D_STR_W_LEN("Cha\xeeNe pour lE TEST.")}, 323 {D_STR_W_LEN ("cha\x8cne pOur Le TEst."),
322 {D_STR_W_LEN("Cha\xc3\xaene pour le Test."), 324 D_STR_W_LEN ("Cha\x8cne poUr Le teST.")},
323 D_STR_W_LEN("Cha\xc3\xaene pour le Test.")}, /* "Chaîne pour le test." in UTF-8 */ 325 {D_STR_W_LEN ("Cha\xeene pour le test."),
324 {D_STR_W_LEN("ChA\xc3\xaene pouR lE TesT."), 326 D_STR_W_LEN ("Cha\xeene pour le test.")}, /* "Chaîne pour le test." in CP1252/ISO-8859-1/ISO-8859-15 */
325 D_STR_W_LEN("Cha\xc3\xaeNe Pour le teSt.")}, 327 {D_STR_W_LEN ("CHa\xeene POUR le test."),
326 328 D_STR_W_LEN ("Cha\xeeNe pour lE TEST.")},
327 {D_STR_W_LEN(".Beispiel Zeichenfolge"), 329 {D_STR_W_LEN ("Cha\xc3\xaene pour le Test."),
328 D_STR_W_LEN(".Beispiel Zeichenfolge")}, 330 D_STR_W_LEN ("Cha\xc3\xaene pour le Test.")}, /* "Chaîne pour le test." in UTF-8 */
329 {D_STR_W_LEN(".bEisPiel ZEIchenfoLgE"), 331 {D_STR_W_LEN ("ChA\xc3\xaene pouR lE TesT."),
330 D_STR_W_LEN(".BEiSpiEl zeIcheNfolge")}, 332 D_STR_W_LEN ("Cha\xc3\xaeNe Pour le teSt.")},
331 333
332 {D_STR_W_LEN("Do\xa7rulama \x87izgi!"), 334 {D_STR_W_LEN (".Beispiel Zeichenfolge"),
333 D_STR_W_LEN("Do\xa7rulama \x87izgi!")}, /* "Doğrulama çizgi!" in CP857 */ 335 D_STR_W_LEN (".Beispiel Zeichenfolge")},
334 {D_STR_W_LEN("Do\xa7rulama \x87IzgI!"), /* Spelling intentionally incorrect here */ 336 {D_STR_W_LEN (".bEisPiel ZEIchenfoLgE"),
335 D_STR_W_LEN("Do\xa7rulama \x87izgi!")}, /* Note: 'i' is not caseless equal to 'I' in Turkish */ 337 D_STR_W_LEN (".BEiSpiEl zeIcheNfolge")},
336 {D_STR_W_LEN("Do\xf0rulama \xe7izgi!"), 338
337 D_STR_W_LEN("Do\xf0rulama \xe7izgi!")}, /* "Doğrulama çizgi!" in CP1254/ISO-8859-9 */ 339 {D_STR_W_LEN ("Do\xa7rulama \x87izgi!"),
338 {D_STR_W_LEN("Do\xf0rulamA \xe7Izgi!"), 340 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* "Doğrulama çizgi!" in CP857 */
339 D_STR_W_LEN("do\xf0rulama \xe7izgi!")}, 341 {D_STR_W_LEN ("Do\xa7rulama \x87IzgI!"), /* Spelling intentionally incorrect here */
340 {D_STR_W_LEN("Do\xc4\x9frulama \xc3\xa7izgi!"), 342 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* Note: 'i' is not caseless equal to 'I' in Turkish */
341 D_STR_W_LEN("Do\xc4\x9frulama \xc3\xa7izgi!")}, /* "Doğrulama çizgi!" in UTF-8 */ 343 {D_STR_W_LEN ("Do\xf0rulama \xe7izgi!"),
342 {D_STR_W_LEN("do\xc4\x9fruLAMA \xc3\xa7Izgi!"), /* Spelling intentionally incorrect here */ 344 D_STR_W_LEN ("Do\xf0rulama \xe7izgi!")}, /* "Doğrulama çizgi!" in CP1254/ISO-8859-9 */
343 D_STR_W_LEN("DO\xc4\x9frulama \xc3\xa7izgI!")}, /* Spelling intentionally incorrect here */ 345 {D_STR_W_LEN ("Do\xf0rulamA \xe7Izgi!"),
344 346 D_STR_W_LEN ("do\xf0rulama \xe7izgi!")},
345 {D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), 347 {D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!"),
346 D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0.")}, /* "Тестовая Строка." in CP866 */ 348 D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!")}, /* "Doğrulama çizgi!" in UTF-8 */
347 {D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), 349 {D_STR_W_LEN ("do\xc4\x9fruLAMA \xc3\xa7Izgi!"), /* Spelling intentionally incorrect here */
348 D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0.")}, /* "Тестовая Строка." in CP1251 */ 350 D_STR_W_LEN ("DO\xc4\x9frulama \xc3\xa7izgI!")}, /* Spelling intentionally incorrect here */
349 {D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), 351
350 D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1.")}, /* "Тестовая Строка." in KOI8-R */ 352 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."),
351 {D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), 353 D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0.")}, /* "Тестовая Строка." in CP866 */
352 D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0.")}, /* "Тестовая Строка." in ISO-8859-5 */ 354 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."),
353 {D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 355 D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0.")}, /* "Тестовая Строка." in CP1251 */
354 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), 356 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."),
355 D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 357 D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1.")}, /* "Тестовая Строка." in KOI8-R */
356 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0.")}, /* "Тестовая Строка." in UTF-8 */ 358 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."),
357 359 D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0.")}, /* "Тестовая Строка." in ISO-8859-5 */
358 {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 360 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1"
359 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 361 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."),
360 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 362 D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1"
361 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 363 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0.")}, /* "Тестовая Строка." in UTF-8 */
362 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 364
363 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 365 {D_STR_W_LEN (
364 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 366 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
365 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 367 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]"
366 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), 368 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90"
367 D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 369 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4"
368 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 370 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8"
369 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 371 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"
370 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 372 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
371 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 373 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4"
372 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 374 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"),
373 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 375 D_STR_W_LEN (
374 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 376 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
375 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")}, /* Full sequence without a-z */ 377 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]"
376 {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 378 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90"
377 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 379 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4"
378 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 380 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8"
379 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 381 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"
380 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 382 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
381 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 383 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4"
382 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 384 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")}, /* Full sequence without a-z */
383 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 385 {D_STR_W_LEN (
384 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 386 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
385 "\xfc\xfd\xfe\xff"), 387 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB"
386 D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 388 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83"
387 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 389 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97"
388 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 390 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab"
389 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 391 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
390 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 392 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
391 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 393 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7"
392 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 394 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb"
393 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 395 "\xfc\xfd\xfe\xff"),
394 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 396 D_STR_W_LEN (
395 "\xfc\xfd\xfe\xff")}, /* Full sequence */ 397 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
396 {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 398 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB"
397 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 399 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83"
398 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 400 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97"
399 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 401 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab"
400 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 402 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
401 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 403 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
402 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 404 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7"
403 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 405 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb"
404 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), 406 "\xfc\xfd\xfe\xff")}, /* Full sequence */
405 D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 407 {D_STR_W_LEN (
406 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ab" 408 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
407 "cdefghijklmnopqrstuvwxyz[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 409 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB"
408 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 410 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89"
409 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 411 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d"
410 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 412 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1"
411 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 413 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5"
412 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 414 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9"
413 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")} /* Full with A/a match */ 415 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed"
416 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"),
417 D_STR_W_LEN (
418 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
419 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ab"
420 "cdefghijklmnopqrstuvwxyz[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89"
421 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d"
422 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1"
423 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5"
424 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9"
425 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed"
426 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")} /* Full with A/a match */
414}; 427};
415 428
416struct two_neq_strs 429struct two_neq_strs
@@ -421,367 +434,419 @@ struct two_neq_strs
421}; 434};
422 435
423static const struct two_neq_strs neq_strings[] = { 436static const struct two_neq_strs neq_strings[] = {
424 {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`"), 27}, 437 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN (
425 {D_STR_W_LEN(".1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`"), 0}, 438 "1234567890!@~%&$@#{}[]\\/!?`"), 27},
426 {D_STR_W_LEN("Simple string."), D_STR_W_LEN("Simple ctring."), 7}, 439 {D_STR_W_LEN (".1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN (
427 {D_STR_W_LEN("simple string."), D_STR_W_LEN("simple string"), 13}, 440 "1234567890!@~%&$@#{}[]\\/!?`"), 0},
428 {D_STR_W_LEN("simple strings"), D_STR_W_LEN("Simple String."), 13}, 441 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple ctring."), 7},
429 {D_STR_W_LEN("sImPlE StRiNg."), D_STR_W_LEN("SYMpLe sTrInG."), 1}, 442 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string"), 13},
430 {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("simple string.2"), 14}, 443 {D_STR_W_LEN ("simple strings"), D_STR_W_LEN ("Simple String."), 13},
431 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz,"), D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz."), 26}, 444 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SYMpLe sTrInG."), 1},
432 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz!"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ?"), 26}, 445 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.2"), 14},
433 {D_STR_W_LEN("zyxwvutsrqponwMLKJIHGFEDCBA"), D_STR_W_LEN("ZYXWVUTSRQPON%mlkjihgfedcba"), 13}, 446 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz,"), D_STR_W_LEN (
434 447 "abcdefghijklmnopqrstuvwxyz."), 26},
435 {D_STR_W_LEN("S\xbdur veulent plus d'\xbdufs."), /* "Sœur veulent plus d'œufs." in ISO-8859-15 */ 448 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz!"), D_STR_W_LEN (
436 D_STR_W_LEN("S\xbcUR VEULENT PLUS D'\xbcUFS."), 1},/* "SŒUR VEULENT PLUS D'ŒUFS." in ISO-8859-15 */ 449 "ABCDEFGHIJKLMNOPQRSTUVWXYZ?"), 26},
437 {D_STR_W_LEN("S\x9cur veulent plus d'\x9cufs."), /* "Sœur veulent plus d'œufs." in CP1252 */ 450 {D_STR_W_LEN ("zyxwvutsrqponwMLKJIHGFEDCBA"), D_STR_W_LEN (
438 D_STR_W_LEN("S\x8cUR VEULENT PLUS D'\x8cUFS."), 1},/* "SŒUR VEULENT PLUS D'ŒUFS." in CP1252 */ 451 "ZYXWVUTSRQPON%mlkjihgfedcba"), 13},
439 {D_STR_W_LEN("S\xc5\x93ur veulent plus d'\xc5\x93ufs."), /* "Sœur veulent plus d'œufs." in UTF-8 */ 452
440 D_STR_W_LEN("S\xc5\x92UR VEULENT PLUS D'\xc5\x92UFS."), 2},/* "SŒUR VEULENT PLUS D'ŒUFS." in UTF-8 */ 453 {D_STR_W_LEN ("S\xbdur veulent plus d'\xbdufs."), /* "Sœur veulent plus d'œufs." in ISO-8859-15 */
441 454 D_STR_W_LEN ("S\xbcUR VEULENT PLUS D'\xbcUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in ISO-8859-15 */
442 {D_STR_W_LEN("Um ein sch\x94nes M\x84" "dchen zu k\x81ssen."), /* "Um ein schönes Mädchen zu küssen." in CP850 */ 455 {D_STR_W_LEN ("S\x9cur veulent plus d'\x9cufs."), /* "Sœur veulent plus d'œufs." in CP1252 */
443 D_STR_W_LEN("UM EIN SCH\x99NES M\x8e" "DCHEN ZU K\x9aSSEN."), 10},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in CP850 */ 456 D_STR_W_LEN ("S\x8cUR VEULENT PLUS D'\x8cUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in CP1252 */
444 {D_STR_W_LEN("Um ein sch\xf6nes M\xe4" "dchen zu k\xfcssen."), /* "Um ein schönes Mädchen zu küssen." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ 457 {D_STR_W_LEN ("S\xc5\x93ur veulent plus d'\xc5\x93ufs."), /* "Sœur veulent plus d'œufs." in UTF-8 */
445 D_STR_W_LEN("UM EIN SCH\xd6NES M\xc4" "DCHEN ZU K\xdcSSEN."), 10},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ 458 D_STR_W_LEN ("S\xc5\x92UR VEULENT PLUS D'\xc5\x92UFS."), 2}, /* "SŒUR VEULENT PLUS D'ŒUFS." in UTF-8 */
446 {D_STR_W_LEN("Um ein sch\xc3\xb6nes M\xc3\xa4" "dchen zu k\xc3\xbcssen."), /* "Um ein schönes Mädchen zu küssen." in UTF-8 */ 459
447 D_STR_W_LEN("UM EIN SCH\xc3\x96NES M\xc3\x84" "DCHEN ZU K\xc3\x9cSSEN."), 11},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in UTF-8 */ 460 {D_STR_W_LEN ("Um ein sch\x94nes M\x84" "dchen zu k\x81ssen."), /* "Um ein schönes Mädchen zu küssen." in CP850 */
448 461 D_STR_W_LEN ("UM EIN SCH\x99NES M\x8e" "DCHEN ZU K\x9aSSEN."), 10}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in CP850 */
449 {D_STR_W_LEN("\x98stanbul"), /* "İstanbul" in CP857 */ 462 {D_STR_W_LEN ("Um ein sch\xf6nes M\xe4" "dchen zu k\xfcssen."), /* "Um ein schönes Mädchen zu küssen." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */
450 D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in CP857 */ 463 D_STR_W_LEN ("UM EIN SCH\xd6NES M\xc4" "DCHEN ZU K\xdcSSEN."), 10}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */
451 {D_STR_W_LEN("\xddstanbul"), /* "İstanbul" in ISO-8859-9/CP1254 */ 464 {D_STR_W_LEN ("Um ein sch\xc3\xb6nes M\xc3\xa4" "dchen zu k\xc3\xbcssen."), /* "Um ein schönes Mädchen zu küssen." in UTF-8 */
452 D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in ISO-8859-9/CP1254 */ 465 D_STR_W_LEN ("UM EIN SCH\xc3\x96NES M\xc3\x84" "DCHEN ZU K\xc3\x9cSSEN."),
453 {D_STR_W_LEN("\xc4\xb0stanbul"), /* "İstanbul" in UTF-8 */ 466 11}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in UTF-8 */
454 D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in UTF-8 */ 467
455 {D_STR_W_LEN("Diyarbak\x8dr"), /* "Diyarbakır" in CP857 */ 468 {D_STR_W_LEN ("\x98stanbul"), /* "İstanbul" in CP857 */
456 D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in CP857 */ 469 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in CP857 */
457 {D_STR_W_LEN("Diyarbak\xfdr"), /* "Diyarbakır" in ISO-8859-9/CP1254 */ 470 {D_STR_W_LEN ("\xddstanbul"), /* "İstanbul" in ISO-8859-9/CP1254 */
458 D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in ISO-8859-9/CP1254 */ 471 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in ISO-8859-9/CP1254 */
459 {D_STR_W_LEN("Diyarbak\xc4\xb1r"), /* "Diyarbakır" in UTF-8 */ 472 {D_STR_W_LEN ("\xc4\xb0stanbul"), /* "İstanbul" in UTF-8 */
460 D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in UTF-8 */ 473 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in UTF-8 */
461 474 {D_STR_W_LEN ("Diyarbak\x8dr"), /* "Diyarbakır" in CP857 */
462 {D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), /* "Тестовая Строка." in CP866 */ 475 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in CP857 */
463 D_STR_W_LEN("\x92\x85\x91\x92\x8e\x82\x80\x9f \x91\x92\x90\x8e\x8a\x80."), 1}, /* "ТЕСТОВАЯ СТРОКА." in CP866 */ 476 {D_STR_W_LEN ("Diyarbak\xfdr"), /* "Diyarbakır" in ISO-8859-9/CP1254 */
464 {D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), /* "Тестовая Строка." in CP1251 */ 477 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in ISO-8859-9/CP1254 */
465 D_STR_W_LEN("\xd2\xc5\xd1\xd2\xce\xc2\xc0\xdf \xd1\xd2\xd0\xce\xca\xc0."), 1}, /* "ТЕСТОВАЯ СТРОКА." in CP1251 */ 478 {D_STR_W_LEN ("Diyarbak\xc4\xb1r"), /* "Diyarbakır" in UTF-8 */
466 {D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), /* "Тестовая Строка." in KOI8-R */ 479 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in UTF-8 */
467 D_STR_W_LEN("\xf4\xe5\xf3\xf4\xef\xf7\xe1\xf1 \xf3\xf4\xf2\xef\xeb\xe1."), 1}, /* "ТЕСТОВАЯ СТРОКА." in KOI8-R */ 480
468 {D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), /* "Тестовая Строка." in ISO-8859-5 */ 481 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), /* "Тестовая Строка." in CP866 */
469 D_STR_W_LEN("\xc2\xb5\xc1\xc2\xbe\xb2\xb0\xcf \xc1\xc2\xc0\xbe\xba\xb0."), 1}, /* "ТЕСТОВАЯ СТРОКА." in ISO-8859-5 */ 482 D_STR_W_LEN ("\x92\x85\x91\x92\x8e\x82\x80\x9f \x91\x92\x90\x8e\x8a\x80."),
470 {D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 483 1}, /* "ТЕСТОВАЯ СТРОКА." in CP866 */
471 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), /* "Тестовая Строка." in UTF-8 */ 484 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), /* "Тестовая Строка." in CP1251 */
472 D_STR_W_LEN("\xd0\xa2\xd0\x95\xd0\xa1\xd0\xa2\xd0\x9e\xd0\x92\xd0\x90\xd0" 485 D_STR_W_LEN ("\xd2\xc5\xd1\xd2\xce\xc2\xc0\xdf \xd1\xd2\xd0\xce\xca\xc0."),
473 "\xaf \xd0\xa1\xd0\xa2\xd0\xa0\xd0\x9e\xd0\x9a\xd0\x90."), 3} /* "ТЕСТОВАЯ СТРОКА." in UTF-8 */ 486 1}, /* "ТЕСТОВАЯ СТРОКА." in CP1251 */
487 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), /* "Тестовая Строка." in KOI8-R */
488 D_STR_W_LEN ("\xf4\xe5\xf3\xf4\xef\xf7\xe1\xf1 \xf3\xf4\xf2\xef\xeb\xe1."),
489 1}, /* "ТЕСТОВАЯ СТРОКА." in KOI8-R */
490 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), /* "Тестовая Строка." in ISO-8859-5 */
491 D_STR_W_LEN ("\xc2\xb5\xc1\xc2\xbe\xb2\xb0\xcf \xc1\xc2\xc0\xbe\xba\xb0."),
492 1}, /* "ТЕСТОВАЯ СТРОКА." in ISO-8859-5 */
493 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1"
494 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), /* "Тестовая Строка." in UTF-8 */
495 D_STR_W_LEN ("\xd0\xa2\xd0\x95\xd0\xa1\xd0\xa2\xd0\x9e\xd0\x92\xd0\x90\xd0"
496 "\xaf \xd0\xa1\xd0\xa2\xd0\xa0\xd0\x9e\xd0\x9a\xd0\x90."), 3} /* "ТЕСТОВАЯ СТРОКА." in UTF-8 */
474}; 497};
475 498
476 499
477int check_eq_strings(void) 500int check_eq_strings (void)
478{ 501{
479 size_t t_failed = 0; 502 size_t t_failed = 0;
480 size_t i, j; 503 size_t i, j;
481 static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]); 504 static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]);
482 int c_failed[n_checks]; 505 int c_failed[n_checks];
483 506
484 memset(c_failed, 0, sizeof(c_failed)); 507 memset (c_failed, 0, sizeof(c_failed));
485 508
486 for(j = 0; j < locale_name_count; j++) 509 for (j = 0; j < locale_name_count; j++)
510 {
511 set_test_locale (j); /* setlocale() can be slow! */
512 for (i = 0; i < n_checks; i++)
487 { 513 {
488 set_test_locale(j); /* setlocale() can be slow! */ 514 const struct two_eq_strs *const t = eq_strings + i;
489 for(i = 0; i < n_checks; i++) 515 if (c_failed[i])
490 { 516 continue; /* skip already failed checks */
491 const struct two_eq_strs * const t = eq_strings + i; 517 if (! MHD_str_equal_caseless_ (t->s1.str, t->s2.str))
492 if (c_failed[i]) 518 {
493 continue; /* skip already failed checks */ 519 t_failed++;
494 if (!MHD_str_equal_caseless_(t->s1.str, t->s2.str)) 520 c_failed[i] = ! 0;
495 { 521 fprintf (stderr,
496 t_failed++; 522 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero."
497 c_failed[i] = !0; 523 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str),
498 fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." 524 get_current_locale_str ());
499 " Locale: %s\n", n_prnt(t->s1.str), n_prnt(t->s2.str), get_current_locale_str()); 525 }
500 } 526 else if (! MHD_str_equal_caseless_ (t->s2.str, t->s1.str))
501 else if (!MHD_str_equal_caseless_(t->s2.str, t->s1.str)) 527 {
502 { 528 t_failed++;
503 t_failed++; 529 c_failed[i] = ! 0;
504 c_failed[i] = !0; 530 fprintf (stderr,
505 fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." 531 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero."
506 " Locale: %s\n", n_prnt(t->s2.str), n_prnt(t->s1.str), get_current_locale_str()); 532 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str),
507 } 533 get_current_locale_str ());
508 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) 534 }
509 printf("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") != 0 && \\\n" 535 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
510 " MHD_str_equal_caseless_(\"%s\", \"%s\") != 0\n", n_prnt(t->s1.str), n_prnt(t->s2.str), 536 printf ("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") != 0 && \\\n"
511 n_prnt(t->s2.str), n_prnt(t->s1.str)); 537 " MHD_str_equal_caseless_(\"%s\", \"%s\") != 0\n",
512 } 538 n_prnt (t->s1.str), n_prnt (t->s2.str),
539 n_prnt (t->s2.str), n_prnt (t->s1.str));
513 } 540 }
541 }
514 return t_failed; 542 return t_failed;
515} 543}
516 544
517int check_neq_strings(void) 545int check_neq_strings (void)
518{ 546{
519 size_t t_failed = 0; 547 size_t t_failed = 0;
520 size_t i, j; 548 size_t i, j;
521 static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]); 549 static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]);
522 int c_failed[n_checks]; 550 int c_failed[n_checks];
523 551
524 memset(c_failed, 0, sizeof(c_failed)); 552 memset (c_failed, 0, sizeof(c_failed));
525 553
526 for(j = 0; j < locale_name_count; j++) 554 for (j = 0; j < locale_name_count; j++)
555 {
556 set_test_locale (j); /* setlocale() can be slow! */
557 for (i = 0; i < n_checks; i++)
527 { 558 {
528 set_test_locale(j); /* setlocale() can be slow! */ 559 const struct two_neq_strs *const t = neq_strings + i;
529 for(i = 0; i < n_checks; i++) 560 if (c_failed[i])
530 { 561 continue; /* skip already failed checks */
531 const struct two_neq_strs * const t = neq_strings + i; 562 if (MHD_str_equal_caseless_ (t->s1.str, t->s2.str))
532 if (c_failed[i]) 563 {
533 continue; /* skip already failed checks */ 564 t_failed++;
534 if (MHD_str_equal_caseless_(t->s1.str, t->s2.str)) 565 c_failed[i] = ! 0;
535 { 566 fprintf (stderr,
536 t_failed++; 567 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero."
537 c_failed[i] = !0; 568 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str),
538 fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." 569 get_current_locale_str ());
539 " Locale: %s\n", n_prnt(t->s1.str), n_prnt(t->s2.str), get_current_locale_str()); 570 }
540 } 571 else if (MHD_str_equal_caseless_ (t->s2.str, t->s1.str))
541 else if (MHD_str_equal_caseless_(t->s2.str, t->s1.str)) 572 {
542 { 573 t_failed++;
543 t_failed++; 574 c_failed[i] = ! 0;
544 c_failed[i] = !0; 575 fprintf (stderr,
545 fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." 576 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero."
546 " Locale: %s\n", n_prnt(t->s2.str), n_prnt(t->s1.str), get_current_locale_str()); 577 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str),
547 } 578 get_current_locale_str ());
548 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) 579 }
549 printf("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") == 0 && \\\n" 580 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
550 " MHD_str_equal_caseless_(\"%s\", \"%s\") == 0\n", n_prnt(t->s1.str), n_prnt(t->s2.str), 581 printf ("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") == 0 && \\\n"
551 n_prnt(t->s2.str), n_prnt(t->s1.str)); 582 " MHD_str_equal_caseless_(\"%s\", \"%s\") == 0\n",
552 } 583 n_prnt (t->s1.str), n_prnt (t->s2.str),
584 n_prnt (t->s2.str), n_prnt (t->s1.str));
553 } 585 }
586 }
554 return t_failed; 587 return t_failed;
555} 588}
556 589
557int check_eq_strings_n(void) 590int check_eq_strings_n (void)
558{ 591{
559 size_t t_failed = 0; 592 size_t t_failed = 0;
560 size_t i, j, k; 593 size_t i, j, k;
561 static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]); 594 static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]);
562 int c_failed[n_checks]; 595 int c_failed[n_checks];
563 596
564 memset(c_failed, 0, sizeof(c_failed)); 597 memset (c_failed, 0, sizeof(c_failed));
565 598
566 for(j = 0; j < locale_name_count; j++) 599 for (j = 0; j < locale_name_count; j++)
600 {
601 set_test_locale (j); /* setlocale() can be slow! */
602 for (i = 0; i < n_checks; i++)
567 { 603 {
568 set_test_locale(j); /* setlocale() can be slow! */ 604 size_t m_len;
569 for(i = 0; i < n_checks; i++) 605 const struct two_eq_strs *const t = eq_strings + i;
606 m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len;
607 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++)
608 {
609 if (! MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k))
570 { 610 {
571 size_t m_len; 611 t_failed++;
572 const struct two_eq_strs * const t = eq_strings + i; 612 c_failed[i] = ! 0;
573 m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len; 613 fprintf (stderr,
574 for(k = 0; k <= m_len + 1 && !c_failed[i]; k++) 614 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
575 { 615 " while expected non-zero. Locale: %s\n",
576 if (!MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k)) 616 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k,
577 { 617 get_current_locale_str ());
578 t_failed++;
579 c_failed[i] = !0;
580 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
581 " while expected non-zero. Locale: %s\n",
582 n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str());
583 }
584 else if (!MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k))
585 {
586 t_failed++;
587 c_failed[i] = !0;
588 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
589 " while expected non-zero. Locale: %s\n",
590 n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str());
591 }
592 }
593 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
594 printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n"
595 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n",
596 n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) m_len + 1);
597 } 618 }
619 else if (! MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k))
620 {
621 t_failed++;
622 c_failed[i] = ! 0;
623 fprintf (stderr,
624 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
625 " while expected non-zero. Locale: %s\n",
626 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k,
627 get_current_locale_str ());
628 }
629 }
630 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
631 printf (
632 "PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n"
633 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n",
634 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str),
635 n_prnt (t->s1.str), (unsigned int) m_len + 1);
598 } 636 }
637 }
599 return t_failed; 638 return t_failed;
600} 639}
601 640
602int check_neq_strings_n(void) 641int check_neq_strings_n (void)
603{ 642{
604 size_t t_failed = 0; 643 size_t t_failed = 0;
605 size_t i, j, k; 644 size_t i, j, k;
606 static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]); 645 static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]);
607 int c_failed[n_checks]; 646 int c_failed[n_checks];
608 647
609 memset(c_failed, 0, sizeof(c_failed)); 648 memset (c_failed, 0, sizeof(c_failed));
610 649
611 for(j = 0; j < locale_name_count; j++) 650 for (j = 0; j < locale_name_count; j++)
651 {
652 set_test_locale (j); /* setlocale() can be slow! */
653 for (i = 0; i < n_checks; i++)
612 { 654 {
613 set_test_locale(j); /* setlocale() can be slow! */ 655 size_t m_len;
614 for(i = 0; i < n_checks; i++) 656 const struct two_neq_strs *const t = neq_strings + i;
657 m_len = t->s1.len > t->s2.len ? t->s1.len : t->s2.len;
658 if (t->dif_pos >= m_len)
659 {
660 fprintf (stderr,
661 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than "
662 "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned
663 int) t->
664 dif_pos,
665 (unsigned int) t->s1.len, (unsigned int) t->s2.len);
666 return -1;
667 }
668 if (t->dif_pos > t->s1.len)
669 {
670 fprintf (stderr,
671 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or "
672 "equal to s1.len (%u).\n", (unsigned int) i, (unsigned
673 int) t->dif_pos,
674 (unsigned int) t->s1.len);
675 return -1;
676 }
677 if (t->dif_pos > t->s2.len)
678 {
679 fprintf (stderr,
680 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or "
681 "equal to s2.len (%u).\n", (unsigned int) i, (unsigned
682 int) t->dif_pos,
683 (unsigned int) t->s2.len);
684 return -1;
685 }
686 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++)
687 {
688 if (k <= t->dif_pos)
689 {
690 if (! MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k))
691 {
692 t_failed++;
693 c_failed[i] = ! 0;
694 fprintf (stderr,
695 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
696 " while expected non-zero. Locale: %s\n",
697 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k,
698 get_current_locale_str ());
699 }
700 else if (! MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k))
701 {
702 t_failed++;
703 c_failed[i] = ! 0;
704 fprintf (stderr,
705 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
706 " while expected non-zero. Locale: %s\n",
707 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k,
708 get_current_locale_str ());
709 }
710 }
711 else
615 { 712 {
616 size_t m_len; 713 if (MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k))
617 const struct two_neq_strs * const t = neq_strings + i; 714 {
618 m_len = t->s1.len > t->s2.len ? t->s1.len : t->s2.len; 715 t_failed++;
619 if (t->dif_pos >= m_len) 716 c_failed[i] = ! 0;
620 { 717 fprintf (stderr,
621 fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than " 718 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero,"
622 "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos, 719 " while expected zero. Locale: %s\n",
623 (unsigned int) t->s1.len, (unsigned int) t->s2.len); 720 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k,
624 return -1; 721 get_current_locale_str ());
625 } 722 }
626 if (t->dif_pos > t->s1.len) 723 else if (MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k))
627 { 724 {
628 fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 725 t_failed++;
629 "equal to s1.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos, 726 c_failed[i] = ! 0;
630 (unsigned int) t->s1.len); 727 fprintf (stderr,
631 return -1; 728 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero,"
632 } 729 " while expected zero. Locale: %s\n",
633 if (t->dif_pos > t->s2.len) 730 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k,
634 { 731 get_current_locale_str ());
635 fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 732 }
636 "equal to s2.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos,
637 (unsigned int) t->s2.len);
638 return -1;
639 }
640 for(k = 0; k <= m_len + 1 && !c_failed[i]; k++)
641 {
642 if (k <= t->dif_pos)
643 {
644 if (!MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k))
645 {
646 t_failed++;
647 c_failed[i] = !0;
648 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
649 " while expected non-zero. Locale: %s\n",
650 n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str());
651 }
652 else if (!MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k))
653 {
654 t_failed++;
655 c_failed[i] = !0;
656 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero,"
657 " while expected non-zero. Locale: %s\n",
658 n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str());
659 }
660 }
661 else
662 {
663 if (MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k))
664 {
665 t_failed++;
666 c_failed[i] = !0;
667 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero,"
668 " while expected zero. Locale: %s\n",
669 n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str());
670 }
671 else if (MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k))
672 {
673 t_failed++;
674 c_failed[i] = !0;
675 fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero,"
676 " while expected zero. Locale: %s\n",
677 n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str());
678 }
679 }
680 }
681 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
682 {
683 printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n"
684 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n",
685 n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str),
686 (unsigned int) t->dif_pos);
687
688 printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0 && \\\n"
689 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0, where N is %u..%u\n",
690 n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str),
691 (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1);
692 }
693 } 733 }
734 }
735 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
736 {
737 printf (
738 "PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n"
739 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n",
740 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str),
741 n_prnt (t->s1.str),
742 (unsigned int) t->dif_pos);
743
744 printf (
745 "PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0 && \\\n"
746 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0, where N is %u..%u\n",
747 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str),
748 n_prnt (t->s1.str),
749 (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1);
750 }
694 } 751 }
752 }
695 return t_failed; 753 return t_failed;
696} 754}
697 755
698/* 756/*
699 * Run eq/neq strings tests 757 * Run eq/neq strings tests
700 */ 758 */
701int run_eq_neq_str_tests(void) 759int run_eq_neq_str_tests (void)
702{ 760{
703 int str_equal_caseless_fails = 0; 761 int str_equal_caseless_fails = 0;
704 int str_equal_caseless_n_fails = 0; 762 int str_equal_caseless_n_fails = 0;
705 int res; 763 int res;
706 764
707 res = check_eq_strings(); 765 res = check_eq_strings ();
708 if (res != 0) 766 if (res != 0)
767 {
768 if (res < 0)
709 { 769 {
710 if (res < 0) 770 fprintf (stderr, "ERROR: test internal error in check_eq_strings().\n");
711 { 771 return 99;
712 fprintf(stderr, "ERROR: test internal error in check_eq_strings().\n");
713 return 99;
714 }
715 str_equal_caseless_fails += res;
716 fprintf(stderr, "FAILED: testcase check_eq_strings() failed.\n\n");
717 } 772 }
773 str_equal_caseless_fails += res;
774 fprintf (stderr, "FAILED: testcase check_eq_strings() failed.\n\n");
775 }
718 else if (verbose > 1) 776 else if (verbose > 1)
719 printf("PASSED: testcase check_eq_strings() successfully passed.\n\n"); 777 printf ("PASSED: testcase check_eq_strings() successfully passed.\n\n");
720 778
721 res = check_neq_strings(); 779 res = check_neq_strings ();
722 if (res != 0) 780 if (res != 0)
781 {
782 if (res < 0)
723 { 783 {
724 if (res < 0) 784 fprintf (stderr, "ERROR: test internal error in check_neq_strings().\n");
725 { 785 return 99;
726 fprintf(stderr, "ERROR: test internal error in check_neq_strings().\n");
727 return 99;
728 }
729 str_equal_caseless_fails += res;
730 fprintf(stderr, "FAILED: testcase check_neq_strings() failed.\n\n");
731 } 786 }
787 str_equal_caseless_fails += res;
788 fprintf (stderr, "FAILED: testcase check_neq_strings() failed.\n\n");
789 }
732 else if (verbose > 1) 790 else if (verbose > 1)
733 printf("PASSED: testcase check_neq_strings() successfully passed.\n\n"); 791 printf ("PASSED: testcase check_neq_strings() successfully passed.\n\n");
734 792
735 if (str_equal_caseless_fails) 793 if (str_equal_caseless_fails)
736 fprintf(stderr, "FAILED: function MHD_str_equal_caseless_() failed %d time%s.\n\n", 794 fprintf (stderr,
737 str_equal_caseless_fails, str_equal_caseless_fails == 1 ? "" : "s"); 795 "FAILED: function MHD_str_equal_caseless_() failed %d time%s.\n\n",
796 str_equal_caseless_fails, str_equal_caseless_fails == 1 ? "" :
797 "s");
738 else if (verbose > 0) 798 else if (verbose > 0)
739 printf("PASSED: function MHD_str_equal_caseless_() successfully passed all checks.\n\n"); 799 printf (
800 "PASSED: function MHD_str_equal_caseless_() successfully passed all checks.\n\n");
740 801
741 res = check_eq_strings_n(); 802 res = check_eq_strings_n ();
742 if (res != 0) 803 if (res != 0)
804 {
805 if (res < 0)
743 { 806 {
744 if (res < 0) 807 fprintf (stderr, "ERROR: test internal error in check_eq_strings_n().\n");
745 { 808 return 99;
746 fprintf(stderr, "ERROR: test internal error in check_eq_strings_n().\n");
747 return 99;
748 }
749 str_equal_caseless_n_fails += res;
750 fprintf(stderr, "FAILED: testcase check_eq_strings_n() failed.\n\n");
751 } 809 }
810 str_equal_caseless_n_fails += res;
811 fprintf (stderr, "FAILED: testcase check_eq_strings_n() failed.\n\n");
812 }
752 else if (verbose > 1) 813 else if (verbose > 1)
753 printf("PASSED: testcase check_eq_strings_n() successfully passed.\n\n"); 814 printf ("PASSED: testcase check_eq_strings_n() successfully passed.\n\n");
754 815
755 res = check_neq_strings_n(); 816 res = check_neq_strings_n ();
756 if (res != 0) 817 if (res != 0)
818 {
819 if (res < 0)
757 { 820 {
758 if (res < 0) 821 fprintf (stderr,
759 { 822 "ERROR: test internal error in check_neq_strings_n().\n");
760 fprintf(stderr, "ERROR: test internal error in check_neq_strings_n().\n"); 823 return 99;
761 return 99;
762 }
763 str_equal_caseless_n_fails += res;
764 fprintf(stderr, "FAILED: testcase check_neq_strings_n() failed.\n\n");
765 } 824 }
825 str_equal_caseless_n_fails += res;
826 fprintf (stderr, "FAILED: testcase check_neq_strings_n() failed.\n\n");
827 }
766 else if (verbose > 1) 828 else if (verbose > 1)
767 printf("PASSED: testcase check_neq_strings_n() successfully passed.\n\n"); 829 printf ("PASSED: testcase check_neq_strings_n() successfully passed.\n\n");
768 830
769 if (str_equal_caseless_n_fails) 831 if (str_equal_caseless_n_fails)
770 fprintf(stderr, "FAILED: function MHD_str_equal_caseless_n_() failed %d time%s.\n\n", 832 fprintf (stderr,
771 str_equal_caseless_n_fails, str_equal_caseless_n_fails == 1 ? "" : "s"); 833 "FAILED: function MHD_str_equal_caseless_n_() failed %d time%s.\n\n",
834 str_equal_caseless_n_fails, str_equal_caseless_n_fails == 1 ? "" :
835 "s");
772 else if (verbose > 0) 836 else if (verbose > 0)
773 printf("PASSED: function MHD_str_equal_caseless_n_() successfully passed all checks.\n\n"); 837 printf (
838 "PASSED: function MHD_str_equal_caseless_n_() successfully passed all checks.\n\n");
774 839
775 if (str_equal_caseless_fails || str_equal_caseless_n_fails) 840 if (str_equal_caseless_fails || str_equal_caseless_n_fails)
776 { 841 {
777 if (verbose > 0) 842 if (verbose > 0)
778 printf("At least one test failed.\n"); 843 printf ("At least one test failed.\n");
779 844
780 return 1; 845 return 1;
781 } 846 }
782 847
783 if (verbose > 0) 848 if (verbose > 0)
784 printf("All tests passed successfully.\n"); 849 printf ("All tests passed successfully.\n");
785 850
786 return 0; 851 return 0;
787} 852}
@@ -790,7 +855,8 @@ int run_eq_neq_str_tests(void)
790 * Digits in string -> value tests 855 * Digits in string -> value tests
791 */ 856 */
792 857
793struct str_with_value { 858struct str_with_value
859{
794 const struct str_with_len str; 860 const struct str_with_len str;
795 const size_t num_of_digt; 861 const size_t num_of_digt;
796 const uint64_t val; 862 const uint64_t val;
@@ -798,1646 +864,1930 @@ struct str_with_value {
798 864
799/* valid string for conversion to unsigned integer value */ 865/* valid string for conversion to unsigned integer value */
800static const struct str_with_value dstrs_w_values[] = { 866static const struct str_with_value dstrs_w_values[] = {
801 /* simplest strings */ 867 /* simplest strings */
802 {D_STR_W_LEN("1"), 1, 1}, 868 {D_STR_W_LEN ("1"), 1, 1},
803 {D_STR_W_LEN("0"), 1, 0}, 869 {D_STR_W_LEN ("0"), 1, 0},
804 {D_STR_W_LEN("10000"), 5, 10000}, 870 {D_STR_W_LEN ("10000"), 5, 10000},
805 871
806 /* all digits */ 872 /* all digits */
807 {D_STR_W_LEN("1234"), 4, 1234}, 873 {D_STR_W_LEN ("1234"), 4, 1234},
808 {D_STR_W_LEN("4567"), 4, 4567}, 874 {D_STR_W_LEN ("4567"), 4, 4567},
809 {D_STR_W_LEN("7890"), 4, 7890}, 875 {D_STR_W_LEN ("7890"), 4, 7890},
810 {D_STR_W_LEN("8021"), 4, 8021}, 876 {D_STR_W_LEN ("8021"), 4, 8021},
811 {D_STR_W_LEN("9754"), 4, 9754}, 877 {D_STR_W_LEN ("9754"), 4, 9754},
812 {D_STR_W_LEN("6392"), 4, 6392}, 878 {D_STR_W_LEN ("6392"), 4, 6392},
813 879
814 /* various prefixes */ 880 /* various prefixes */
815 {D_STR_W_LEN("00000000"), 8, 0}, 881 {D_STR_W_LEN ("00000000"), 8, 0},
816 {D_STR_W_LEN("0755"), 4, 755}, /* not to be interpreted as octal value! */ 882 {D_STR_W_LEN ("0755"), 4, 755}, /* not to be interpreted as octal value! */
817 {D_STR_W_LEN("002"), 3, 2}, 883 {D_STR_W_LEN ("002"), 3, 2},
818 {D_STR_W_LEN("0001"), 4, 1}, 884 {D_STR_W_LEN ("0001"), 4, 1},
819 {D_STR_W_LEN("00000000000000000000000031295483"), 32, 31295483}, 885 {D_STR_W_LEN ("00000000000000000000000031295483"), 32, 31295483},
820 886
821 /* numbers below and above limits */ 887 /* numbers below and above limits */
822 {D_STR_W_LEN("127"), 3, 127}, /* 0x7F, SCHAR_MAX */ 888 {D_STR_W_LEN ("127"), 3, 127}, /* 0x7F, SCHAR_MAX */
823 {D_STR_W_LEN("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */ 889 {D_STR_W_LEN ("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */
824 {D_STR_W_LEN("255"), 3, 255}, /* 0xFF, UCHAR_MAX */ 890 {D_STR_W_LEN ("255"), 3, 255}, /* 0xFF, UCHAR_MAX */
825 {D_STR_W_LEN("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 891 {D_STR_W_LEN ("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */
826 {D_STR_W_LEN("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */ 892 {D_STR_W_LEN ("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */
827 {D_STR_W_LEN("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */ 893 {D_STR_W_LEN ("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */
828 {D_STR_W_LEN("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */ 894 {D_STR_W_LEN ("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */
829 {D_STR_W_LEN("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 895 {D_STR_W_LEN ("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */
830 {D_STR_W_LEN("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 896 {D_STR_W_LEN ("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
831 {D_STR_W_LEN("2147483648"), 10, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */ 897 {D_STR_W_LEN ("2147483648"), 10, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */
832 {D_STR_W_LEN("4294967295"), 10, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 898 {D_STR_W_LEN ("4294967295"), 10, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
833 {D_STR_W_LEN("4294967296"), 10, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 899 {D_STR_W_LEN ("4294967296"), 10, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */
834 {D_STR_W_LEN("9223372036854775807"), 19, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 900 {D_STR_W_LEN ("9223372036854775807"), 19, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
835 {D_STR_W_LEN("9223372036854775808"), 19, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 901 {D_STR_W_LEN ("9223372036854775808"), 19, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */
836 {D_STR_W_LEN("18446744073709551615"), 20, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 902 {D_STR_W_LEN ("18446744073709551615"), 20, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
837 903
838 /* random numbers */ 904 /* random numbers */
839 {D_STR_W_LEN("10186753"), 8, 10186753}, 905 {D_STR_W_LEN ("10186753"), 8, 10186753},
840 {D_STR_W_LEN("144402566"), 9, 144402566}, 906 {D_STR_W_LEN ("144402566"), 9, 144402566},
841 {D_STR_W_LEN("151903144"), 9, 151903144}, 907 {D_STR_W_LEN ("151903144"), 9, 151903144},
842 {D_STR_W_LEN("139264621"), 9, 139264621}, 908 {D_STR_W_LEN ("139264621"), 9, 139264621},
843 {D_STR_W_LEN("730348"), 6, 730348}, 909 {D_STR_W_LEN ("730348"), 6, 730348},
844 {D_STR_W_LEN("21584377"), 8, 21584377}, 910 {D_STR_W_LEN ("21584377"), 8, 21584377},
845 {D_STR_W_LEN("709"), 3, 709}, 911 {D_STR_W_LEN ("709"), 3, 709},
846 {D_STR_W_LEN("54"), 2, 54}, 912 {D_STR_W_LEN ("54"), 2, 54},
847 {D_STR_W_LEN("8452"), 4, 8452}, 913 {D_STR_W_LEN ("8452"), 4, 8452},
848 {D_STR_W_LEN("17745098750013624977"), 20, UINT64_C(17745098750013624977)}, 914 {D_STR_W_LEN ("17745098750013624977"), 20, UINT64_C (17745098750013624977)},
849 {D_STR_W_LEN("06786878769931678000"), 20, UINT64_C(6786878769931678000)}, 915 {D_STR_W_LEN ("06786878769931678000"), 20, UINT64_C (6786878769931678000)},
850 916
851 /* non-digit suffixes */ 917 /* non-digit suffixes */
852 {D_STR_W_LEN("1234oa"), 4, 1234}, 918 {D_STR_W_LEN ("1234oa"), 4, 1234},
853 {D_STR_W_LEN("20h"), 2, 20}, /* not to be interpreted as hex value! */ 919 {D_STR_W_LEN ("20h"), 2, 20}, /* not to be interpreted as hex value! */
854 {D_STR_W_LEN("0x1F"), 1, 0}, /* not to be interpreted as hex value! */ 920 {D_STR_W_LEN ("0x1F"), 1, 0}, /* not to be interpreted as hex value! */
855 {D_STR_W_LEN("0564`~}"), 4, 564}, 921 {D_STR_W_LEN ("0564`~}"), 4, 564},
856 {D_STR_W_LEN("7240146.724"), 7, 7240146}, 922 {D_STR_W_LEN ("7240146.724"), 7, 7240146},
857 {D_STR_W_LEN("2,9"), 1, 2}, 923 {D_STR_W_LEN ("2,9"), 1, 2},
858 {D_STR_W_LEN("200+1"), 3, 200}, 924 {D_STR_W_LEN ("200+1"), 3, 200},
859 {D_STR_W_LEN("1a"), 1, 1}, 925 {D_STR_W_LEN ("1a"), 1, 1},
860 {D_STR_W_LEN("2E"), 1, 2}, 926 {D_STR_W_LEN ("2E"), 1, 2},
861 {D_STR_W_LEN("6c"), 1, 6}, 927 {D_STR_W_LEN ("6c"), 1, 6},
862 {D_STR_W_LEN("8F"), 1, 8}, 928 {D_STR_W_LEN ("8F"), 1, 8},
863 {D_STR_W_LEN("287416997! And the not too long string."), 9, 287416997} 929 {D_STR_W_LEN ("287416997! And the not too long string."), 9, 287416997}
864}; 930};
865 931
866/* strings that should overflow uint64_t */ 932/* strings that should overflow uint64_t */
867const struct str_with_len str_ovflw[] = { 933const struct str_with_len str_ovflw[] = {
868 D_STR_W_LEN("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 934 D_STR_W_LEN ("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */
869 D_STR_W_LEN("18446744073709551620"), 935 D_STR_W_LEN ("18446744073709551620"),
870 D_STR_W_LEN("18446744083709551615"), 936 D_STR_W_LEN ("18446744083709551615"),
871 D_STR_W_LEN("19234761020556472143"), 937 D_STR_W_LEN ("19234761020556472143"),
872 D_STR_W_LEN("184467440737095516150"), 938 D_STR_W_LEN ("184467440737095516150"),
873 D_STR_W_LEN("1844674407370955161500"), 939 D_STR_W_LEN ("1844674407370955161500"),
874 D_STR_W_LEN("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 940 D_STR_W_LEN ("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */
875 D_STR_W_LEN("20000000000000000000"), 941 D_STR_W_LEN ("20000000000000000000"),
876 D_STR_W_LEN("020000000000000000000"), 942 D_STR_W_LEN ("020000000000000000000"),
877 D_STR_W_LEN("0020000000000000000000"), 943 D_STR_W_LEN ("0020000000000000000000"),
878 D_STR_W_LEN("100000000000000000000"), 944 D_STR_W_LEN ("100000000000000000000"),
879 D_STR_W_LEN("434532891232591226417"), 945 D_STR_W_LEN ("434532891232591226417"),
880 D_STR_W_LEN("99999999999999999999"), 946 D_STR_W_LEN ("99999999999999999999"),
881 D_STR_W_LEN("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */ 947 D_STR_W_LEN ("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */
882 D_STR_W_LEN("20000000000000000000 suffix"), 948 D_STR_W_LEN ("20000000000000000000 suffix"),
883 D_STR_W_LEN("020000000000000000000x") 949 D_STR_W_LEN ("020000000000000000000x")
884}; 950};
885 951
886/* strings that should not be convertible to numeric value */ 952/* strings that should not be convertible to numeric value */
887const struct str_with_len str_no_num[] = { 953const struct str_with_len str_no_num[] = {
888 D_STR_W_LEN("zero"), 954 D_STR_W_LEN ("zero"),
889 D_STR_W_LEN("one"), 955 D_STR_W_LEN ("one"),
890 D_STR_W_LEN("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */ 956 D_STR_W_LEN ("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */
891 D_STR_W_LEN("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */ 957 D_STR_W_LEN ("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */
892 D_STR_W_LEN("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */ 958 D_STR_W_LEN ("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */
893 D_STR_W_LEN("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */ 959 D_STR_W_LEN ("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */
894 D_STR_W_LEN("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */ 960 D_STR_W_LEN ("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */
895 D_STR_W_LEN("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */ 961 D_STR_W_LEN ("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */
896 D_STR_W_LEN("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */ 962 D_STR_W_LEN ("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */
897 D_STR_W_LEN("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */ 963 D_STR_W_LEN ("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */
898}; 964};
899 965
900/* valid hex string for conversion to unsigned integer value */ 966/* valid hex string for conversion to unsigned integer value */
901static const struct str_with_value xdstrs_w_values[] = { 967static const struct str_with_value xdstrs_w_values[] = {
902 /* simplest strings */ 968 /* simplest strings */
903 {D_STR_W_LEN("1"), 1, 0x1}, 969 {D_STR_W_LEN ("1"), 1, 0x1},
904 {D_STR_W_LEN("0"), 1, 0x0}, 970 {D_STR_W_LEN ("0"), 1, 0x0},
905 {D_STR_W_LEN("10000"), 5, 0x10000}, 971 {D_STR_W_LEN ("10000"), 5, 0x10000},
906 972
907 /* all digits */ 973 /* all digits */
908 {D_STR_W_LEN("1234"), 4, 0x1234}, 974 {D_STR_W_LEN ("1234"), 4, 0x1234},
909 {D_STR_W_LEN("4567"), 4, 0x4567}, 975 {D_STR_W_LEN ("4567"), 4, 0x4567},
910 {D_STR_W_LEN("7890"), 4, 0x7890}, 976 {D_STR_W_LEN ("7890"), 4, 0x7890},
911 {D_STR_W_LEN("8021"), 4, 0x8021}, 977 {D_STR_W_LEN ("8021"), 4, 0x8021},
912 {D_STR_W_LEN("9754"), 4, 0x9754}, 978 {D_STR_W_LEN ("9754"), 4, 0x9754},
913 {D_STR_W_LEN("6392"), 4, 0x6392}, 979 {D_STR_W_LEN ("6392"), 4, 0x6392},
914 {D_STR_W_LEN("abcd"), 4, 0xABCD}, 980 {D_STR_W_LEN ("abcd"), 4, 0xABCD},
915 {D_STR_W_LEN("cdef"), 4, 0xCDEF}, 981 {D_STR_W_LEN ("cdef"), 4, 0xCDEF},
916 {D_STR_W_LEN("FEAB"), 4, 0xFEAB}, 982 {D_STR_W_LEN ("FEAB"), 4, 0xFEAB},
917 {D_STR_W_LEN("BCED"), 4, 0xBCED}, 983 {D_STR_W_LEN ("BCED"), 4, 0xBCED},
918 {D_STR_W_LEN("bCeD"), 4, 0xBCED}, 984 {D_STR_W_LEN ("bCeD"), 4, 0xBCED},
919 {D_STR_W_LEN("1A5F"), 4, 0x1A5F}, 985 {D_STR_W_LEN ("1A5F"), 4, 0x1A5F},
920 {D_STR_W_LEN("12AB"), 4, 0x12AB}, 986 {D_STR_W_LEN ("12AB"), 4, 0x12AB},
921 {D_STR_W_LEN("CD34"), 4, 0xCD34}, 987 {D_STR_W_LEN ("CD34"), 4, 0xCD34},
922 {D_STR_W_LEN("56EF"), 4, 0x56EF}, 988 {D_STR_W_LEN ("56EF"), 4, 0x56EF},
923 {D_STR_W_LEN("7a9f"), 4, 0x7A9F}, 989 {D_STR_W_LEN ("7a9f"), 4, 0x7A9F},
924 990
925 /* various prefixes */ 991 /* various prefixes */
926 {D_STR_W_LEN("00000000"), 8, 0x0}, 992 {D_STR_W_LEN ("00000000"), 8, 0x0},
927 {D_STR_W_LEN("0755"), 4, 0x755}, /* not to be interpreted as octal value! */ 993 {D_STR_W_LEN ("0755"), 4, 0x755}, /* not to be interpreted as octal value! */
928 {D_STR_W_LEN("002"), 3, 0x2}, 994 {D_STR_W_LEN ("002"), 3, 0x2},
929 {D_STR_W_LEN("0001"), 4, 0x1}, 995 {D_STR_W_LEN ("0001"), 4, 0x1},
930 {D_STR_W_LEN("00a"), 3, 0xA}, 996 {D_STR_W_LEN ("00a"), 3, 0xA},
931 {D_STR_W_LEN("0F"), 2, 0xF}, 997 {D_STR_W_LEN ("0F"), 2, 0xF},
932 {D_STR_W_LEN("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3}, 998 {D_STR_W_LEN ("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3},
933 999
934 /* numbers below and above limits */ 1000 /* numbers below and above limits */
935 {D_STR_W_LEN("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */ 1001 {D_STR_W_LEN ("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */
936 {D_STR_W_LEN("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */ 1002 {D_STR_W_LEN ("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */
937 {D_STR_W_LEN("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */ 1003 {D_STR_W_LEN ("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */
938 {D_STR_W_LEN("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1004 {D_STR_W_LEN ("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */
939 {D_STR_W_LEN("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1005 {D_STR_W_LEN ("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */
940 {D_STR_W_LEN("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1006 {D_STR_W_LEN ("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */
941 {D_STR_W_LEN("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1007 {D_STR_W_LEN ("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */
942 {D_STR_W_LEN("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 1008 {D_STR_W_LEN ("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */
943 {D_STR_W_LEN("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1009 {D_STR_W_LEN ("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */
944 {D_STR_W_LEN("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1010 {D_STR_W_LEN ("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */
945 {D_STR_W_LEN("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1011 {D_STR_W_LEN ("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */
946 {D_STR_W_LEN("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */ 1012 {D_STR_W_LEN ("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */
947 {D_STR_W_LEN("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1013 {D_STR_W_LEN ("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
948 {D_STR_W_LEN("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1014 {D_STR_W_LEN ("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
949 {D_STR_W_LEN("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1015 {D_STR_W_LEN ("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
950 {D_STR_W_LEN("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 1016 {D_STR_W_LEN ("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */
951 {D_STR_W_LEN("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1017 {D_STR_W_LEN ("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
952 {D_STR_W_LEN("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1018 {D_STR_W_LEN ("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
953 {D_STR_W_LEN("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1019 {D_STR_W_LEN ("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
954 {D_STR_W_LEN("80000000"), 8, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */ 1020 {D_STR_W_LEN ("80000000"), 8, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */
955 {D_STR_W_LEN("FFFFFFFF"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1021 {D_STR_W_LEN ("FFFFFFFF"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
956 {D_STR_W_LEN("ffffffff"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1022 {D_STR_W_LEN ("ffffffff"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
957 {D_STR_W_LEN("FfFfFfFf"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1023 {D_STR_W_LEN ("FfFfFfFf"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
958 {D_STR_W_LEN("100000000"), 9, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 1024 {D_STR_W_LEN ("100000000"), 9, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */
959 {D_STR_W_LEN("7fffffffffffffff"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1025 {D_STR_W_LEN ("7fffffffffffffff"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
960 {D_STR_W_LEN("7FFFFFFFFFFFFFFF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1026 {D_STR_W_LEN ("7FFFFFFFFFFFFFFF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
961 {D_STR_W_LEN("7FfffFFFFffFFffF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1027 {D_STR_W_LEN ("7FfffFFFFffFFffF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
962 {D_STR_W_LEN("8000000000000000"), 16, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 1028 {D_STR_W_LEN ("8000000000000000"), 16, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */
963 {D_STR_W_LEN("ffffffffffffffff"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1029 {D_STR_W_LEN ("ffffffffffffffff"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
964 {D_STR_W_LEN("FFFFFFFFFFFFFFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1030 {D_STR_W_LEN ("FFFFFFFFFFFFFFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
965 {D_STR_W_LEN("FffFffFFffFFfFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1031 {D_STR_W_LEN ("FffFffFFffFFfFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
966 1032
967 /* random numbers */ 1033 /* random numbers */
968 {D_STR_W_LEN("10186753"), 8, 0x10186753}, 1034 {D_STR_W_LEN ("10186753"), 8, 0x10186753},
969 {D_STR_W_LEN("144402566"), 9, 0x144402566}, 1035 {D_STR_W_LEN ("144402566"), 9, 0x144402566},
970 {D_STR_W_LEN("151903144"), 9, 0x151903144}, 1036 {D_STR_W_LEN ("151903144"), 9, 0x151903144},
971 {D_STR_W_LEN("139264621"), 9, 0x139264621}, 1037 {D_STR_W_LEN ("139264621"), 9, 0x139264621},
972 {D_STR_W_LEN("730348"), 6, 0x730348}, 1038 {D_STR_W_LEN ("730348"), 6, 0x730348},
973 {D_STR_W_LEN("21584377"), 8, 0x21584377}, 1039 {D_STR_W_LEN ("21584377"), 8, 0x21584377},
974 {D_STR_W_LEN("709"), 3, 0x709}, 1040 {D_STR_W_LEN ("709"), 3, 0x709},
975 {D_STR_W_LEN("54"), 2, 0x54}, 1041 {D_STR_W_LEN ("54"), 2, 0x54},
976 {D_STR_W_LEN("8452"), 4, 0x8452}, 1042 {D_STR_W_LEN ("8452"), 4, 0x8452},
977 {D_STR_W_LEN("22353EC6"), 8, 0x22353EC6}, 1043 {D_STR_W_LEN ("22353EC6"), 8, 0x22353EC6},
978 {D_STR_W_LEN("307F1655"), 8, 0x307F1655}, 1044 {D_STR_W_LEN ("307F1655"), 8, 0x307F1655},
979 {D_STR_W_LEN("1FCB7226"), 8, 0x1FCB7226}, 1045 {D_STR_W_LEN ("1FCB7226"), 8, 0x1FCB7226},
980 {D_STR_W_LEN("82480560"), 8, 0x82480560}, 1046 {D_STR_W_LEN ("82480560"), 8, 0x82480560},
981 {D_STR_W_LEN("7386D95"), 7, 0x7386D95}, 1047 {D_STR_W_LEN ("7386D95"), 7, 0x7386D95},
982 {D_STR_W_LEN("EC3AB"), 5, 0xEC3AB}, 1048 {D_STR_W_LEN ("EC3AB"), 5, 0xEC3AB},
983 {D_STR_W_LEN("6DD05"), 5, 0x6DD05}, 1049 {D_STR_W_LEN ("6DD05"), 5, 0x6DD05},
984 {D_STR_W_LEN("C5DF"), 4, 0xC5DF}, 1050 {D_STR_W_LEN ("C5DF"), 4, 0xC5DF},
985 {D_STR_W_LEN("6CE"), 3, 0x6CE}, 1051 {D_STR_W_LEN ("6CE"), 3, 0x6CE},
986 {D_STR_W_LEN("CE6"), 3, 0xCE6}, 1052 {D_STR_W_LEN ("CE6"), 3, 0xCE6},
987 {D_STR_W_LEN("ce6"), 3, 0xCE6}, 1053 {D_STR_W_LEN ("ce6"), 3, 0xCE6},
988 {D_STR_W_LEN("F27"), 3, 0xF27}, 1054 {D_STR_W_LEN ("F27"), 3, 0xF27},
989 {D_STR_W_LEN("8497D54277D7E1"), 14, UINT64_C(37321639124785121)}, 1055 {D_STR_W_LEN ("8497D54277D7E1"), 14, UINT64_C (37321639124785121)},
990 {D_STR_W_LEN("8497d54277d7e1"), 14, UINT64_C(37321639124785121)}, 1056 {D_STR_W_LEN ("8497d54277d7e1"), 14, UINT64_C (37321639124785121)},
991 {D_STR_W_LEN("8497d54277d7E1"), 14, UINT64_C(37321639124785121)}, 1057 {D_STR_W_LEN ("8497d54277d7E1"), 14, UINT64_C (37321639124785121)},
992 {D_STR_W_LEN("8C8112D0A06"), 11, UINT64_C(9655374645766)}, 1058 {D_STR_W_LEN ("8C8112D0A06"), 11, UINT64_C (9655374645766)},
993 {D_STR_W_LEN("8c8112d0a06"), 11, UINT64_C(9655374645766)}, 1059 {D_STR_W_LEN ("8c8112d0a06"), 11, UINT64_C (9655374645766)},
994 {D_STR_W_LEN("8c8112d0A06"), 11, UINT64_C(9655374645766)}, 1060 {D_STR_W_LEN ("8c8112d0A06"), 11, UINT64_C (9655374645766)},
995 {D_STR_W_LEN("1774509875001362"), 16, UINT64_C(1690064375898968930)}, 1061 {D_STR_W_LEN ("1774509875001362"), 16, UINT64_C (1690064375898968930)},
996 {D_STR_W_LEN("0678687876998000"), 16, UINT64_C(466237428027981824)}, 1062 {D_STR_W_LEN ("0678687876998000"), 16, UINT64_C (466237428027981824)},
997 1063
998 /* non-digit suffixes */ 1064 /* non-digit suffixes */
999 {D_STR_W_LEN("1234oa"), 4, 0x1234}, 1065 {D_STR_W_LEN ("1234oa"), 4, 0x1234},
1000 {D_STR_W_LEN("20h"), 2, 0x20}, 1066 {D_STR_W_LEN ("20h"), 2, 0x20},
1001 {D_STR_W_LEN("2CH"), 2, 0x2C}, 1067 {D_STR_W_LEN ("2CH"), 2, 0x2C},
1002 {D_STR_W_LEN("2ch"), 2, 0x2C}, 1068 {D_STR_W_LEN ("2ch"), 2, 0x2C},
1003 {D_STR_W_LEN("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */ 1069 {D_STR_W_LEN ("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */
1004 {D_STR_W_LEN("0564`~}"), 4, 0x564}, 1070 {D_STR_W_LEN ("0564`~}"), 4, 0x564},
1005 {D_STR_W_LEN("0A64`~}"), 4, 0xA64}, 1071 {D_STR_W_LEN ("0A64`~}"), 4, 0xA64},
1006 {D_STR_W_LEN("056c`~}"), 4, 0X56C}, 1072 {D_STR_W_LEN ("056c`~}"), 4, 0X56C},
1007 {D_STR_W_LEN("7240146.724"), 7, 0x7240146}, 1073 {D_STR_W_LEN ("7240146.724"), 7, 0x7240146},
1008 {D_STR_W_LEN("7E4c1AB.724"), 7, 0X7E4C1AB}, 1074 {D_STR_W_LEN ("7E4c1AB.724"), 7, 0X7E4C1AB},
1009 {D_STR_W_LEN("F24B1B6.724"), 7, 0xF24B1B6}, 1075 {D_STR_W_LEN ("F24B1B6.724"), 7, 0xF24B1B6},
1010 {D_STR_W_LEN("2,9"), 1, 0x2}, 1076 {D_STR_W_LEN ("2,9"), 1, 0x2},
1011 {D_STR_W_LEN("a,9"), 1, 0xA}, 1077 {D_STR_W_LEN ("a,9"), 1, 0xA},
1012 {D_STR_W_LEN("200+1"), 3, 0x200}, 1078 {D_STR_W_LEN ("200+1"), 3, 0x200},
1013 {D_STR_W_LEN("2cc+1"), 3, 0x2CC}, 1079 {D_STR_W_LEN ("2cc+1"), 3, 0x2CC},
1014 {D_STR_W_LEN("2cC+1"), 3, 0x2CC}, 1080 {D_STR_W_LEN ("2cC+1"), 3, 0x2CC},
1015 {D_STR_W_LEN("27416997! And the not too long string."), 8, 0x27416997}, 1081 {D_STR_W_LEN ("27416997! And the not too long string."), 8, 0x27416997},
1016 {D_STR_W_LEN("27555416997! And the not too long string."), 11, 0x27555416997}, 1082 {D_STR_W_LEN ("27555416997! And the not too long string."), 11,
1017 {D_STR_W_LEN("416997And the not too long string."), 7, 0x416997A}, 1083 0x27555416997},
1018 {D_STR_W_LEN("0F4C3Dabstract addition to make string even longer"), 8, 0xF4C3DAB} 1084 {D_STR_W_LEN ("416997And the not too long string."), 7, 0x416997A},
1085 {D_STR_W_LEN ("0F4C3Dabstract addition to make string even longer"), 8,
1086 0xF4C3DAB}
1019}; 1087};
1020 1088
1021/* hex strings that should overflow uint64_t */ 1089/* hex strings that should overflow uint64_t */
1022const struct str_with_len strx_ovflw[] = { 1090const struct str_with_len strx_ovflw[] = {
1023 D_STR_W_LEN("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1091 D_STR_W_LEN ("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
1024 D_STR_W_LEN("10000000000000001"), 1092 D_STR_W_LEN ("10000000000000001"),
1025 D_STR_W_LEN("10000000000000002"), 1093 D_STR_W_LEN ("10000000000000002"),
1026 D_STR_W_LEN("1000000000000000A"), 1094 D_STR_W_LEN ("1000000000000000A"),
1027 D_STR_W_LEN("11000000000000000"), 1095 D_STR_W_LEN ("11000000000000000"),
1028 D_STR_W_LEN("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1096 D_STR_W_LEN ("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
1029 D_STR_W_LEN("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1097 D_STR_W_LEN ("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
1030 D_STR_W_LEN("20000000000000000000"), 1098 D_STR_W_LEN ("20000000000000000000"),
1031 D_STR_W_LEN("020000000000000000000"), 1099 D_STR_W_LEN ("020000000000000000000"),
1032 D_STR_W_LEN("0020000000000000000000"), 1100 D_STR_W_LEN ("0020000000000000000000"),
1033 D_STR_W_LEN("20000000000000000"), 1101 D_STR_W_LEN ("20000000000000000"),
1034 D_STR_W_LEN("A0000000000000000"), 1102 D_STR_W_LEN ("A0000000000000000"),
1035 D_STR_W_LEN("F0000000000000000"), 1103 D_STR_W_LEN ("F0000000000000000"),
1036 D_STR_W_LEN("a0000000000000000"), 1104 D_STR_W_LEN ("a0000000000000000"),
1037 D_STR_W_LEN("11111111111111111"), 1105 D_STR_W_LEN ("11111111111111111"),
1038 D_STR_W_LEN("CcCcCCccCCccCCccC"), 1106 D_STR_W_LEN ("CcCcCCccCCccCCccC"),
1039 D_STR_W_LEN("f0000000000000000"), 1107 D_STR_W_LEN ("f0000000000000000"),
1040 D_STR_W_LEN("100000000000000000000"), 1108 D_STR_W_LEN ("100000000000000000000"),
1041 D_STR_W_LEN("434532891232591226417"), 1109 D_STR_W_LEN ("434532891232591226417"),
1042 D_STR_W_LEN("10000000000000000a"), 1110 D_STR_W_LEN ("10000000000000000a"),
1043 D_STR_W_LEN("10000000000000000E"), 1111 D_STR_W_LEN ("10000000000000000E"),
1044 D_STR_W_LEN("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */ 1112 D_STR_W_LEN ("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */
1045 D_STR_W_LEN("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */ 1113 D_STR_W_LEN ("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */
1046 D_STR_W_LEN("99999999999999999999"), 1114 D_STR_W_LEN ("99999999999999999999"),
1047 D_STR_W_LEN("18446744073709551616abcd"), 1115 D_STR_W_LEN ("18446744073709551616abcd"),
1048 D_STR_W_LEN("20000000000000000000 suffix"), 1116 D_STR_W_LEN ("20000000000000000000 suffix"),
1049 D_STR_W_LEN("020000000000000000000x") 1117 D_STR_W_LEN ("020000000000000000000x")
1050}; 1118};
1051 1119
1052 1120
1053int check_str_to_uint64_valid(void) 1121int check_str_to_uint64_valid (void)
1054{ 1122{
1055 size_t t_failed = 0; 1123 size_t t_failed = 0;
1056 size_t i, j; 1124 size_t i, j;
1057 static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]); 1125 static const size_t n_checks = sizeof(dstrs_w_values)
1126 / sizeof(dstrs_w_values[0]);
1058 int c_failed[n_checks]; 1127 int c_failed[n_checks];
1059 1128
1060 memset(c_failed, 0, sizeof(c_failed)); 1129 memset (c_failed, 0, sizeof(c_failed));
1061 1130
1062 for(j = 0; j < locale_name_count; j++) 1131 for (j = 0; j < locale_name_count; j++)
1132 {
1133 set_test_locale (j); /* setlocale() can be slow! */
1134 for (i = 0; i < n_checks; i++)
1063 { 1135 {
1064 set_test_locale(j); /* setlocale() can be slow! */ 1136 uint64_t rv;
1065 for(i = 0; i < n_checks; i++) 1137 size_t rs;
1066 { 1138 const struct str_with_value *const t = dstrs_w_values + i;
1067 uint64_t rv; 1139
1068 size_t rs; 1140 if (c_failed[i])
1069 const struct str_with_value * const t = dstrs_w_values + i; 1141 continue; /* skip already failed checks */
1070 1142
1071 if (c_failed[i]) 1143 if (t->str.len < t->num_of_digt)
1072 continue; /* skip already failed checks */ 1144 {
1073 1145 fprintf (stderr,
1074 if (t->str.len < t->num_of_digt) 1146 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1075 { 1147 " to be less or equal to str.len (%u).\n",
1076 fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1148 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
1077 " to be less or equal to str.len (%u).\n", 1149 int) t->str.
1078 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); 1150 len);
1079 return -1; 1151 return -1;
1080 } 1152 }
1081 rv = 9435223; /* some random value */ 1153 rv = 9435223; /* some random value */
1082 rs = MHD_str_to_uint64_(t->str.str, &rv); 1154 rs = MHD_str_to_uint64_ (t->str.str, &rv);
1083 if (rs != t->num_of_digt) 1155 if (rs != t->num_of_digt)
1084 { 1156 {
1085 t_failed++; 1157 t_failed++;
1086 c_failed[i] = !0; 1158 c_failed[i] = ! 0;
1087 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting %d." 1159 fprintf (stderr,
1088 " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); 1160 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %"
1089 } 1161 PRIuPTR
1090 if (rv != t->val) 1162 ", while expecting %d."
1091 { 1163 " Locale: %s\n", n_prnt (t->str.str), rv, (intptr_t) rs,
1092 t_failed++; 1164 (int) t->num_of_digt, get_current_locale_str ());
1093 c_failed[i] = !0; 1165 }
1094 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") converted string to value %" PRIu64 "," 1166 if (rv != t->val)
1095 " while expecting result %" PRIu64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv, 1167 {
1096 t->val, get_current_locale_str()); 1168 t_failed++;
1097 } 1169 c_failed[i] = ! 0;
1098 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) 1170 fprintf (stderr,
1099 printf("PASSED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") == %" PRIuPTR "\n", 1171 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64
1100 n_prnt(t->str.str), rv, rs); 1172 ") converted string to value %"
1101 } 1173 PRIu64 ","
1174 " while expecting result %" PRIu64 ". Locale: %s\n", n_prnt (
1175 t->str.str), rv, rv,
1176 t->val, get_current_locale_str ());
1177 }
1178 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1179 printf (
1180 "PASSED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") == %" PRIuPTR "\n",
1181 n_prnt (t->str.str), rv, rs);
1102 } 1182 }
1183 }
1103 return t_failed; 1184 return t_failed;
1104} 1185}
1105 1186
1106 1187
1107int check_str_to_uint64_all_chars(void) 1188int check_str_to_uint64_all_chars (void)
1108{ 1189{
1109 static const size_t n_checks = 256; /* from 0 to 255 */ 1190 static const size_t n_checks = 256; /* from 0 to 255 */
1110 int c_failed[n_checks]; 1191 int c_failed[n_checks];
1111 size_t t_failed = 0; 1192 size_t t_failed = 0;
1112 size_t j; 1193 size_t j;
1113 1194
1114 memset(c_failed, 0, sizeof(c_failed)); 1195 memset (c_failed, 0, sizeof(c_failed));
1115 1196
1116 for(j = 0; j < locale_name_count; j++) 1197 for (j = 0; j < locale_name_count; j++)
1117 { 1198 {
1118 unsigned int c; 1199 unsigned int c;
1119 uint64_t test_val; 1200 uint64_t test_val;
1120 1201
1121 set_test_locale(j); /* setlocale() can be slow! */ 1202 set_test_locale (j); /* setlocale() can be slow! */
1122 for(c = 0; c < n_checks; c++) 1203 for (c = 0; c < n_checks; c++)
1204 {
1205 static const uint64_t rnd_val = 24941852;
1206 size_t rs;
1207 if ((c >= '0') &&(c <= '9') )
1208 continue; /* skip digits */
1209 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
1210 rnd_val)
1211 {
1212 char test_str[] = "0123";
1213 uint64_t rv = test_val;
1214
1215 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1216 rs = MHD_str_to_uint64_ (test_str, &rv);
1217 if (rs != 0)
1218 {
1219 t_failed++;
1220 c_failed[c] = ! 0;
1221 fprintf (stderr,
1222 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64
1223 ") returned %" PRIuPTR
1224 ", while expecting zero."
1225 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs,
1226 get_current_locale_str ());
1227 }
1228 else if (rv != test_val)
1123 { 1229 {
1124 static const uint64_t rnd_val = 24941852; 1230 t_failed++;
1125 size_t rs; 1231 c_failed[c] = ! 0;
1126 if (c >= '0' && c <= '9') 1232 fprintf (stderr,
1127 continue; /* skip digits */ 1233 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1128 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 1234 " (before call: %" PRIu64 ", after call %" PRIu64
1129 { 1235 "). Locale: %s\n",
1130 char test_str[] = "0123"; 1236 n_prnt (test_str), test_val, rv, get_current_locale_str ());
1131 uint64_t rv = test_val;
1132
1133 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1134 rs = MHD_str_to_uint64_(test_str, &rv);
1135 if (rs != 0)
1136 {
1137 t_failed++;
1138 c_failed[c] = !0;
1139 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
1140 " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str());
1141 }
1142 else if (rv != test_val)
1143 {
1144 t_failed++;
1145 c_failed[c] = !0;
1146 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1147 " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
1148 n_prnt(test_str), test_val, rv, get_current_locale_str());
1149 }
1150 }
1151 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
1152 {
1153 char test_str[] = "0123";
1154 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1155
1156 printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1157 n_prnt(test_str));
1158 }
1159 } 1237 }
1238 }
1239 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
1240 {
1241 char test_str[] = "0123";
1242 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1243
1244 printf (
1245 "PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1246 n_prnt (test_str));
1247 }
1160 } 1248 }
1249 }
1161 return t_failed; 1250 return t_failed;
1162} 1251}
1163 1252
1164 1253
1165int check_str_to_uint64_overflow(void) 1254int check_str_to_uint64_overflow (void)
1166{ 1255{
1167 size_t t_failed = 0; 1256 size_t t_failed = 0;
1168 size_t i, j; 1257 size_t i, j;
1169 static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]); 1258 static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]);
1170 int c_failed[n_checks]; 1259 int c_failed[n_checks];
1171 1260
1172 memset(c_failed, 0, sizeof(c_failed)); 1261 memset (c_failed, 0, sizeof(c_failed));
1173 1262
1174 for(j = 0; j < locale_name_count; j++) 1263 for (j = 0; j < locale_name_count; j++)
1264 {
1265 set_test_locale (j); /* setlocale() can be slow! */
1266 for (i = 0; i < n_checks; i++)
1175 { 1267 {
1176 set_test_locale(j); /* setlocale() can be slow! */ 1268 size_t rs;
1177 for(i = 0; i < n_checks; i++) 1269 const struct str_with_len *const t = str_ovflw + i;
1270 static const uint64_t rnd_val = 2;
1271 uint64_t test_val;
1272
1273 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1274 rnd_val)
1275 {
1276 uint64_t rv = test_val;
1277
1278 rs = MHD_str_to_uint64_ (t->str, &rv);
1279 if (rs != 0)
1178 { 1280 {
1179 size_t rs; 1281 t_failed++;
1180 const struct str_with_len * const t = str_ovflw + i; 1282 c_failed[i] = ! 0;
1181 static const uint64_t rnd_val = 2; 1283 fprintf (stderr,
1182 uint64_t test_val; 1284 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64
1183 1285 ") returned %" PRIuPTR
1184 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 1286 ", while expecting zero."
1185 { 1287 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs,
1186 uint64_t rv = test_val; 1288 get_current_locale_str ());
1187
1188 rs = MHD_str_to_uint64_(t->str, &rv);
1189 if (rs != 0)
1190 {
1191 t_failed++;
1192 c_failed[i] = !0;
1193 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
1194 " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
1195 }
1196 else if (rv != test_val)
1197 {
1198 t_failed++;
1199 c_failed[i] = !0;
1200 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1201 " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
1202 n_prnt(t->str), test_val, rv, get_current_locale_str());
1203 }
1204 }
1205 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1206 printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1207 n_prnt(t->str));
1208 } 1289 }
1290 else if (rv != test_val)
1291 {
1292 t_failed++;
1293 c_failed[i] = ! 0;
1294 fprintf (stderr,
1295 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1296 " (before call: %" PRIu64 ", after call %" PRIu64
1297 "). Locale: %s\n",
1298 n_prnt (t->str), test_val, rv, get_current_locale_str ());
1299 }
1300 }
1301 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1302 printf (
1303 "PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1304 n_prnt (t->str));
1209 } 1305 }
1306 }
1210 return t_failed; 1307 return t_failed;
1211} 1308}
1212 1309
1213 1310
1214int check_str_to_uint64_no_val(void) 1311int check_str_to_uint64_no_val (void)
1215{ 1312{
1216 size_t t_failed = 0; 1313 size_t t_failed = 0;
1217 size_t i, j; 1314 size_t i, j;
1218 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 1315 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
1219 int c_failed[n_checks]; 1316 int c_failed[n_checks];
1220 1317
1221 memset(c_failed, 0, sizeof(c_failed)); 1318 memset (c_failed, 0, sizeof(c_failed));
1222 1319
1223 for(j = 0; j < locale_name_count; j++) 1320 for (j = 0; j < locale_name_count; j++)
1321 {
1322 set_test_locale (j); /* setlocale() can be slow! */
1323 for (i = 0; i < n_checks; i++)
1224 { 1324 {
1225 set_test_locale(j); /* setlocale() can be slow! */ 1325 size_t rs;
1226 for(i = 0; i < n_checks; i++) 1326 const struct str_with_len *const t = str_no_num + i;
1327 static const uint64_t rnd_val = 74218431;
1328 uint64_t test_val;
1329
1330 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1331 rnd_val)
1332 {
1333 uint64_t rv = test_val;
1334
1335 rs = MHD_str_to_uint64_ (t->str, &rv);
1336 if (rs != 0)
1227 { 1337 {
1228 size_t rs; 1338 t_failed++;
1229 const struct str_with_len * const t = str_no_num + i; 1339 c_failed[i] = ! 0;
1230 static const uint64_t rnd_val = 74218431; 1340 fprintf (stderr,
1231 uint64_t test_val; 1341 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64
1232 1342 ") returned %" PRIuPTR
1233 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 1343 ", while expecting zero."
1234 { 1344 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs,
1235 uint64_t rv = test_val; 1345 get_current_locale_str ());
1236
1237 rs = MHD_str_to_uint64_(t->str, &rv);
1238 if (rs != 0)
1239 {
1240 t_failed++;
1241 c_failed[i] = !0;
1242 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
1243 " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
1244 }
1245 else if (rv != test_val)
1246 {
1247 t_failed++;
1248 c_failed[i] = !0;
1249 fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1250 " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
1251 n_prnt(t->str), test_val, rv, get_current_locale_str());
1252 }
1253 }
1254 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1255 printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1256 n_prnt(t->str));
1257 } 1346 }
1347 else if (rv != test_val)
1348 {
1349 t_failed++;
1350 c_failed[i] = ! 0;
1351 fprintf (stderr,
1352 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
1353 " (before call: %" PRIu64 ", after call %" PRIu64
1354 "). Locale: %s\n",
1355 n_prnt (t->str), test_val, rv, get_current_locale_str ());
1356 }
1357 }
1358 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1359 printf (
1360 "PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1361 n_prnt (t->str));
1258 } 1362 }
1363 }
1259 return t_failed; 1364 return t_failed;
1260} 1365}
1261 1366
1262 1367
1263int check_str_to_uint64_n_valid(void) 1368int check_str_to_uint64_n_valid (void)
1264{ 1369{
1265 size_t t_failed = 0; 1370 size_t t_failed = 0;
1266 size_t i, j; 1371 size_t i, j;
1267 static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]); 1372 static const size_t n_checks = sizeof(dstrs_w_values)
1373 / sizeof(dstrs_w_values[0]);
1268 int c_failed[n_checks]; 1374 int c_failed[n_checks];
1269 1375
1270 memset(c_failed, 0, sizeof(c_failed)); 1376 memset (c_failed, 0, sizeof(c_failed));
1271 1377
1272 for(j = 0; j < locale_name_count; j++) 1378 for (j = 0; j < locale_name_count; j++)
1379 {
1380 set_test_locale (j); /* setlocale() can be slow! */
1381 for (i = 0; i < n_checks; i++)
1273 { 1382 {
1274 set_test_locale(j); /* setlocale() can be slow! */ 1383 uint64_t rv = 1235572; /* some random value */
1275 for(i = 0; i < n_checks; i++) 1384 size_t rs = 0;
1385 size_t len;
1386 const struct str_with_value *const t = dstrs_w_values + i;
1387
1388 if (t->str.len < t->num_of_digt)
1389 {
1390 fprintf (stderr,
1391 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1392 " to be less or equal to str.len (%u).\n",
1393 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
1394 int) t->str.
1395 len);
1396 return -1;
1397 }
1398 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++)
1399 {
1400 rs = MHD_str_to_uint64_n_ (t->str.str, len, &rv);
1401 if (rs != t->num_of_digt)
1276 { 1402 {
1277 uint64_t rv = 1235572; /* some random value */ 1403 t_failed++;
1278 size_t rs = 0; 1404 c_failed[i] = ! 0;
1279 size_t len; 1405 fprintf (stderr,
1280 const struct str_with_value * const t = dstrs_w_values + i; 1406 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%"
1281 1407 PRIu64 ")"
1282 if (t->str.len < t->num_of_digt) 1408 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
1283 { 1409 n_prnt (t->str.str), (intptr_t) len, rv, (intptr_t) rs,
1284 fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1410 (int) t->num_of_digt, get_current_locale_str ());
1285 " to be less or equal to str.len (%u).\n",
1286 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
1287 return -1;
1288 }
1289 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
1290 {
1291 rs = MHD_str_to_uint64_n_(t->str.str, len, &rv);
1292 if (rs != t->num_of_digt)
1293 {
1294 t_failed++;
1295 c_failed[i] = !0;
1296 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
1297 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
1298 n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs,
1299 (int)t->num_of_digt, get_current_locale_str());
1300 }
1301 if (rv != t->val)
1302 {
1303 t_failed++;
1304 c_failed[i] = !0;
1305 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
1306 " converted string to value %" PRIu64 ", while expecting result %" PRIu64
1307 ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv,
1308 t->val, get_current_locale_str());
1309 }
1310 }
1311 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1312 printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->%" PRIu64 ")"
1313 " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
1314 (intptr_t)t->str.len + 1, rv, rs);
1315 } 1411 }
1412 if (rv != t->val)
1413 {
1414 t_failed++;
1415 c_failed[i] = ! 0;
1416 fprintf (stderr,
1417 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%"
1418 PRIu64 ")"
1419 " converted string to value %" PRIu64
1420 ", while expecting result %" PRIu64
1421 ". Locale: %s\n", n_prnt (t->str.str), (intptr_t) len, rv,
1422 rv,
1423 t->val, get_current_locale_str ());
1424 }
1425 }
1426 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1427 printf (
1428 "PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->%"
1429 PRIu64 ")"
1430 " == %" PRIuPTR "\n", n_prnt (t->str.str),
1431 (intptr_t) t->num_of_digt,
1432 (intptr_t) t->str.len + 1, rv, rs);
1316 } 1433 }
1434 }
1317 return t_failed; 1435 return t_failed;
1318} 1436}
1319 1437
1320 1438
1321int check_str_to_uint64_n_all_chars(void) 1439int check_str_to_uint64_n_all_chars (void)
1322{ 1440{
1323 static const size_t n_checks = 256; /* from 0 to 255 */ 1441 static const size_t n_checks = 256; /* from 0 to 255 */
1324 int c_failed[n_checks]; 1442 int c_failed[n_checks];
1325 size_t t_failed = 0; 1443 size_t t_failed = 0;
1326 size_t j; 1444 size_t j;
1327 1445
1328 memset(c_failed, 0, sizeof(c_failed)); 1446 memset (c_failed, 0, sizeof(c_failed));
1447
1448 for (j = 0; j < locale_name_count; j++)
1449 {
1450 unsigned int c;
1451 uint64_t test_val;
1329 1452
1330 for(j = 0; j < locale_name_count; j++) 1453 set_test_locale (j); /* setlocale() can be slow! */
1454 for (c = 0; c < n_checks; c++)
1331 { 1455 {
1332 unsigned int c; 1456 static const uint64_t rnd_val = 98372558;
1333 uint64_t test_val; 1457 size_t rs;
1458 size_t len;
1334 1459
1335 set_test_locale(j); /* setlocale() can be slow! */ 1460 if ((c >= '0') &&(c <= '9') )
1336 for(c = 0; c < n_checks; c++) 1461 continue; /* skip digits */
1462
1463 for (len = 0; len <= 5; len++)
1464 {
1465 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
1466 rnd_val)
1337 { 1467 {
1338 static const uint64_t rnd_val = 98372558; 1468 char test_str[] = "0123";
1339 size_t rs; 1469 uint64_t rv = test_val;
1340 size_t len; 1470
1341 1471 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1342 if (c >= '0' && c <= '9') 1472 rs = MHD_str_to_uint64_n_ (test_str, len, &rv);
1343 continue; /* skip digits */ 1473 if (rs != 0)
1344 1474 {
1345 for (len = 0; len <= 5; len++) 1475 t_failed++;
1346 { 1476 c_failed[c] = ! 0;
1347 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 1477 fprintf (stderr,
1348 { 1478 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%"
1349 char test_str[] = "0123"; 1479 PRIu64 ")"
1350 uint64_t rv = test_val; 1480 " returned %" PRIuPTR
1351 1481 ", while expecting zero. Locale: %s\n",
1352 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ 1482 n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs,
1353 rs = MHD_str_to_uint64_n_(test_str, len, &rv); 1483 get_current_locale_str ());
1354 if (rs != 0) 1484 }
1355 { 1485 else if (rv != test_val)
1356 t_failed++; 1486 {
1357 c_failed[c] = !0; 1487 t_failed++;
1358 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" 1488 c_failed[c] = ! 0;
1359 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 1489 fprintf (stderr,
1360 n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 1490 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR
1361 } 1491 ", &ret_val)"
1362 else if (rv != test_val) 1492 " modified value of ret_val (before call: %" PRIu64
1363 { 1493 ", after call %" PRIu64 ")."
1364 t_failed++; 1494 " Locale: %s\n",
1365 c_failed[c] = !0; 1495 n_prnt (test_str), (uintptr_t) len, test_val, rv,
1366 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 1496 get_current_locale_str ());
1367 " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." 1497 }
1368 " Locale: %s\n",
1369 n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str());
1370 }
1371 }
1372 }
1373 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
1374 {
1375 char test_str[] = "0123";
1376 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1377
1378 printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
1379 n_prnt(test_str));
1380 }
1381 } 1498 }
1499 }
1500 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
1501 {
1502 char test_str[] = "0123";
1503 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1504
1505 printf (
1506 "PASSED: MHD_str_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
1507 n_prnt (test_str));
1508 }
1382 } 1509 }
1510 }
1383 return t_failed; 1511 return t_failed;
1384} 1512}
1385 1513
1386 1514
1387int check_str_to_uint64_n_overflow(void) 1515int check_str_to_uint64_n_overflow (void)
1388{ 1516{
1389 size_t t_failed = 0; 1517 size_t t_failed = 0;
1390 size_t i, j; 1518 size_t i, j;
1391 static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]); 1519 static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]);
1392 int c_failed[n_checks]; 1520 int c_failed[n_checks];
1393 1521
1394 memset(c_failed, 0, sizeof(c_failed)); 1522 memset (c_failed, 0, sizeof(c_failed));
1395 1523
1396 for(j = 0; j < locale_name_count; j++) 1524 for (j = 0; j < locale_name_count; j++)
1525 {
1526 set_test_locale (j); /* setlocale() can be slow! */
1527 for (i = 0; i < n_checks; i++)
1397 { 1528 {
1398 set_test_locale(j); /* setlocale() can be slow! */ 1529 size_t rs;
1399 for(i = 0; i < n_checks; i++) 1530 const struct str_with_len *const t = str_ovflw + i;
1531 static const uint64_t rnd_val = 3;
1532 size_t len;
1533
1534 for (len = t->len; len <= t->len + 1; len++)
1535 {
1536 uint64_t test_val;
1537 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1538 rnd_val)
1400 { 1539 {
1401 size_t rs; 1540 uint64_t rv = test_val;
1402 const struct str_with_len * const t = str_ovflw + i; 1541
1403 static const uint64_t rnd_val = 3; 1542 rs = MHD_str_to_uint64_n_ (t->str, len, &rv);
1404 size_t len; 1543 if (rs != 0)
1405 1544 {
1406 for (len = t->len; len <= t->len + 1; len++) 1545 t_failed++;
1407 { 1546 c_failed[i] = ! 0;
1408 uint64_t test_val; 1547 fprintf (stderr,
1409 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 1548 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%"
1410 { 1549 PRIu64 ")"
1411 uint64_t rv = test_val; 1550 " returned %" PRIuPTR
1412 1551 ", while expecting zero. Locale: %s\n",
1413 rs = MHD_str_to_uint64_n_(t->str, len, &rv); 1552 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs,
1414 if (rs != 0) 1553 get_current_locale_str ());
1415 { 1554 }
1416 t_failed++; 1555 else if (rv != test_val)
1417 c_failed[i] = !0; 1556 {
1418 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" 1557 t_failed++;
1419 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 1558 c_failed[i] = ! 0;
1420 n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 1559 fprintf (stderr,
1421 } 1560 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR
1422 else if (rv != test_val) 1561 ", &ret_val)"
1423 { 1562 " modified value of ret_val (before call: %" PRIu64
1424 t_failed++; 1563 ", after call %" PRIu64 ")."
1425 c_failed[i] = !0; 1564 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len,
1426 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 1565 test_val, rv,
1427 " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." 1566 get_current_locale_str ());
1428 " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, 1567 }
1429 get_current_locale_str());
1430 }
1431 }
1432 }
1433 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1434 printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
1435 " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len,
1436 (uintptr_t)t->len + 1);
1437 } 1568 }
1569 }
1570 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1571 printf (
1572 "PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR
1573 ", &ret_val) == 0,"
1574 " value of ret_val is unmodified\n", n_prnt (t->str),
1575 (uintptr_t) t->len,
1576 (uintptr_t) t->len + 1);
1438 } 1577 }
1578 }
1439 return t_failed; 1579 return t_failed;
1440} 1580}
1441 1581
1442 1582
1443int check_str_to_uint64_n_no_val(void) 1583int check_str_to_uint64_n_no_val (void)
1444{ 1584{
1445 size_t t_failed = 0; 1585 size_t t_failed = 0;
1446 size_t i, j; 1586 size_t i, j;
1447 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 1587 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
1448 int c_failed[n_checks]; 1588 int c_failed[n_checks];
1449 1589
1450 memset(c_failed, 0, sizeof(c_failed)); 1590 memset (c_failed, 0, sizeof(c_failed));
1451 1591
1452 for(j = 0; j < locale_name_count; j++) 1592 for (j = 0; j < locale_name_count; j++)
1593 {
1594 set_test_locale (j); /* setlocale() can be slow! */
1595 for (i = 0; i < n_checks; i++)
1453 { 1596 {
1454 set_test_locale(j); /* setlocale() can be slow! */ 1597 size_t rs;
1455 for(i = 0; i < n_checks; i++) 1598 const struct str_with_len *const t = str_no_num + i;
1599 static const uint64_t rnd_val = 43255654342;
1600 size_t len;
1601
1602 for (len = 0; len <= t->len + 1; len++)
1603 {
1604 uint64_t test_val;
1605 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1606 rnd_val)
1456 { 1607 {
1457 size_t rs; 1608 uint64_t rv = test_val;
1458 const struct str_with_len * const t = str_no_num + i; 1609
1459 static const uint64_t rnd_val = 43255654342; 1610 rs = MHD_str_to_uint64_n_ (t->str, len, &rv);
1460 size_t len; 1611 if (rs != 0)
1461 1612 {
1462 for (len = 0; len <= t->len + 1; len++) 1613 t_failed++;
1463 { 1614 c_failed[i] = ! 0;
1464 uint64_t test_val; 1615 fprintf (stderr,
1465 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 1616 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%"
1466 { 1617 PRIu64 ")"
1467 uint64_t rv = test_val; 1618 " returned %" PRIuPTR
1468 1619 ", while expecting zero. Locale: %s\n",
1469 rs = MHD_str_to_uint64_n_(t->str, len, &rv); 1620 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs,
1470 if (rs != 0) 1621 get_current_locale_str ());
1471 { 1622 }
1472 t_failed++; 1623 else if (rv != test_val)
1473 c_failed[i] = !0; 1624 {
1474 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" 1625 t_failed++;
1475 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 1626 c_failed[i] = ! 0;
1476 n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 1627 fprintf (stderr,
1477 } 1628 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR
1478 else if (rv != test_val) 1629 ", &ret_val)"
1479 { 1630 " modified value of ret_val (before call: %" PRIu64
1480 t_failed++; 1631 ", after call %" PRIu64 ")."
1481 c_failed[i] = !0; 1632 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len,
1482 fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 1633 test_val, rv,
1483 " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." 1634 get_current_locale_str ());
1484 " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, 1635 }
1485 get_current_locale_str());
1486 }
1487 }
1488 }
1489 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1490 printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
1491 " value of ret_val is unmodified\n", n_prnt(t->str),
1492 (uintptr_t)t->len + 1);
1493 } 1636 }
1637 }
1638 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1639 printf (
1640 "PASSED: MHD_str_to_uint64_n_(\"%s\", 0..%" PRIuPTR
1641 ", &ret_val) == 0,"
1642 " value of ret_val is unmodified\n", n_prnt (t->str),
1643 (uintptr_t) t->len + 1);
1494 } 1644 }
1645 }
1495 return t_failed; 1646 return t_failed;
1496} 1647}
1497 1648
1498 1649
1499int check_strx_to_uint32_valid(void) 1650int check_strx_to_uint32_valid (void)
1500{ 1651{
1501 size_t t_failed = 0; 1652 size_t t_failed = 0;
1502 size_t i, j; 1653 size_t i, j;
1503 static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 1654 static const size_t n_checks = sizeof(xdstrs_w_values)
1655 / sizeof(xdstrs_w_values[0]);
1504 int c_failed[n_checks]; 1656 int c_failed[n_checks];
1505 1657
1506 memset(c_failed, 0, sizeof(c_failed)); 1658 memset (c_failed, 0, sizeof(c_failed));
1507 1659
1508 for(j = 0; j < locale_name_count; j++) 1660 for (j = 0; j < locale_name_count; j++)
1661 {
1662 set_test_locale (j); /* setlocale() can be slow! */
1663 for (i = 0; i < n_checks; i++)
1509 { 1664 {
1510 set_test_locale(j); /* setlocale() can be slow! */ 1665 uint32_t rv;
1511 for(i = 0; i < n_checks; i++) 1666 size_t rs;
1512 { 1667 const struct str_with_value *const t = xdstrs_w_values + i;
1513 uint32_t rv; 1668
1514 size_t rs; 1669 if (t->val > UINT32_MAX)
1515 const struct str_with_value * const t = xdstrs_w_values + i; 1670 continue; /* number is too high for this function */
1516 1671
1517 if (t->val > UINT32_MAX) 1672 if (c_failed[i])
1518 continue; /* number is too high for this function */ 1673 continue; /* skip already failed checks */
1519 1674
1520 if (c_failed[i]) 1675 if (t->str.len < t->num_of_digt)
1521 continue; /* skip already failed checks */ 1676 {
1522 1677 fprintf (stderr,
1523 if (t->str.len < t->num_of_digt) 1678 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1524 { 1679 " to be less or equal to str.len (%u).\n",
1525 fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1680 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
1526 " to be less or equal to str.len (%u).\n", 1681 int) t->str.
1527 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); 1682 len);
1528 return -1; 1683 return -1;
1529 } 1684 }
1530 rv = 1458532; /* some random value */ 1685 rv = 1458532; /* some random value */
1531 rs = MHD_strx_to_uint32_(t->str.str, &rv); 1686 rs = MHD_strx_to_uint32_ (t->str.str, &rv);
1532 if (rs != t->num_of_digt) 1687 if (rs != t->num_of_digt)
1533 { 1688 {
1534 t_failed++; 1689 t_failed++;
1535 c_failed[i] = !0; 1690 c_failed[i] = ! 0;
1536 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." 1691 fprintf (stderr,
1537 " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); 1692 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64
1538 } 1693 ") returned %"
1539 if (rv != t->val) 1694 PRIuPTR ", while expecting %d."
1540 { 1695 " Locale: %s\n", n_prnt (t->str.str), (uint64_t) rv,
1541 t_failed++; 1696 (intptr_t) rs, (int) t->num_of_digt,
1542 c_failed[i] = !0; 1697 get_current_locale_str ());
1543 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," 1698 }
1544 " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv, 1699 if (rv != t->val)
1545 t->val, get_current_locale_str()); 1700 {
1546 } 1701 t_failed++;
1547 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) 1702 c_failed[i] = ! 0;
1548 printf("PASSED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", 1703 fprintf (stderr,
1549 n_prnt(t->str.str), (uint64_t)rv, rs); 1704 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64
1550 } 1705 ") converted string to value 0x%"
1706 PRIX64 ","
1707 " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt (
1708 t->str.str), (uint64_t) rv, (uint64_t) rv,
1709 t->val, get_current_locale_str ());
1710 }
1711 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1712 printf (
1713 "PASSED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR
1714 "\n",
1715 n_prnt (t->str.str), (uint64_t) rv, rs);
1551 } 1716 }
1717 }
1552 return t_failed; 1718 return t_failed;
1553} 1719}
1554 1720
1555 1721
1556int check_strx_to_uint32_all_chars(void) 1722int check_strx_to_uint32_all_chars (void)
1557{ 1723{
1558 static const size_t n_checks = 256; /* from 0 to 255 */ 1724 static const size_t n_checks = 256; /* from 0 to 255 */
1559 int c_failed[n_checks]; 1725 int c_failed[n_checks];
1560 size_t t_failed = 0; 1726 size_t t_failed = 0;
1561 size_t j; 1727 size_t j;
1562 1728
1563 memset(c_failed, 0, sizeof(c_failed)); 1729 memset (c_failed, 0, sizeof(c_failed));
1564 1730
1565 for(j = 0; j < locale_name_count; j++) 1731 for (j = 0; j < locale_name_count; j++)
1566 { 1732 {
1567 unsigned int c; 1733 unsigned int c;
1568 uint32_t test_val; 1734 uint32_t test_val;
1569 1735
1570 set_test_locale(j); /* setlocale() can be slow! */ 1736 set_test_locale (j); /* setlocale() can be slow! */
1571 for(c = 0; c < n_checks; c++) 1737 for (c = 0; c < n_checks; c++)
1738 {
1739 static const uint32_t rnd_val = 234234;
1740 size_t rs;
1741 if (((c >= '0') &&(c <= '9') ) || ((c >= 'A') &&(c <= 'F') ) ||((c >=
1742 'a') &&
1743 (c <=
1744 'f') ))
1745 continue; /* skip xdigits */
1746 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
1747 rnd_val)
1748 {
1749 char test_str[] = "0123";
1750 uint32_t rv = test_val;
1751
1752 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1753 rs = MHD_strx_to_uint32_ (test_str, &rv);
1754 if (rs != 0)
1572 { 1755 {
1573 static const uint32_t rnd_val = 234234; 1756 t_failed++;
1574 size_t rs; 1757 c_failed[c] = ! 0;
1575 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f')) 1758 fprintf (stderr,
1576 continue; /* skip xdigits */ 1759 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64
1577 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 1760 ") returned %"
1578 { 1761 PRIuPTR ", while expecting zero."
1579 char test_str[] = "0123"; 1762 " Locale: %s\n", n_prnt (test_str), (uint64_t) rv,
1580 uint32_t rv = test_val; 1763 (uintptr_t) rs, get_current_locale_str ());
1581
1582 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1583 rs = MHD_strx_to_uint32_(test_str, &rv);
1584 if (rs != 0)
1585 {
1586 t_failed++;
1587 c_failed[c] = !0;
1588 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
1589 " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
1590 }
1591 else if (rv != test_val)
1592 {
1593 t_failed++;
1594 c_failed[c] = !0;
1595 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1596 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
1597 n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
1598 }
1599 }
1600 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
1601 {
1602 char test_str[] = "0123";
1603 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1604
1605 printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1606 n_prnt(test_str));
1607 }
1608 } 1764 }
1765 else if (rv != test_val)
1766 {
1767 t_failed++;
1768 c_failed[c] = ! 0;
1769 fprintf (stderr,
1770 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1771 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
1772 "). Locale: %s\n",
1773 n_prnt (test_str), (uint64_t) test_val, (uint64_t) rv,
1774 get_current_locale_str ());
1775 }
1776 }
1777 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
1778 {
1779 char test_str[] = "0123";
1780 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1781
1782 printf (
1783 "PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1784 n_prnt (test_str));
1785 }
1609 } 1786 }
1787 }
1610 return t_failed; 1788 return t_failed;
1611} 1789}
1612 1790
1613 1791
1614int check_strx_to_uint32_overflow(void) 1792int check_strx_to_uint32_overflow (void)
1615{ 1793{
1616 size_t t_failed = 0; 1794 size_t t_failed = 0;
1617 size_t i, j; 1795 size_t i, j;
1618 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 1796 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
1619 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + 1797 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0])
1620 sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 1798 + sizeof(xdstrs_w_values)
1799 / sizeof(xdstrs_w_values[0]);
1621 int c_failed[n_checks]; 1800 int c_failed[n_checks];
1622 1801
1623 memset(c_failed, 0, sizeof(c_failed)); 1802 memset (c_failed, 0, sizeof(c_failed));
1624 1803
1625 for(j = 0; j < locale_name_count; j++) 1804 for (j = 0; j < locale_name_count; j++)
1805 {
1806 set_test_locale (j); /* setlocale() can be slow! */
1807 for (i = 0; i < n_checks; i++)
1626 { 1808 {
1627 set_test_locale(j); /* setlocale() can be slow! */ 1809 size_t rs;
1628 for(i = 0; i < n_checks; i++) 1810 static const uint32_t rnd_val = 74218431;
1811 uint32_t test_val;
1812 const char *str;
1813 if (i < n_checks1)
1814 {
1815 const struct str_with_len *const t = strx_ovflw + i;
1816 str = t->str;
1817 }
1818 else
1819 {
1820 const struct str_with_value *const t = xdstrs_w_values + (i
1821 - n_checks1);
1822 if (t->val <= UINT32_MAX)
1823 continue; /* check only strings that should overflow uint32_t */
1824 str = t->str.str;
1825 }
1826
1827
1828 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1829 rnd_val)
1830 {
1831 uint32_t rv = test_val;
1832
1833 rs = MHD_strx_to_uint32_ (str, &rv);
1834 if (rs != 0)
1629 { 1835 {
1630 size_t rs; 1836 t_failed++;
1631 static const uint32_t rnd_val = 74218431; 1837 c_failed[i] = ! 0;
1632 uint32_t test_val; 1838 fprintf (stderr,
1633 const char * str; 1839 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64
1634 if (i < n_checks1) 1840 ") returned %"
1635 { 1841 PRIuPTR ", while expecting zero."
1636 const struct str_with_len * const t = strx_ovflw + i; 1842 " Locale: %s\n", n_prnt (str), (uint64_t) rv, (uintptr_t) rs,
1637 str = t->str; 1843 get_current_locale_str ());
1638 }
1639 else
1640 {
1641 const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
1642 if (t->val <= UINT32_MAX)
1643 continue; /* check only strings that should overflow uint32_t */
1644 str = t->str.str;
1645 }
1646
1647
1648 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
1649 {
1650 uint32_t rv = test_val;
1651
1652 rs = MHD_strx_to_uint32_(str, &rv);
1653 if (rs != 0)
1654 {
1655 t_failed++;
1656 c_failed[i] = !0;
1657 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
1658 " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
1659 }
1660 else if (rv != test_val)
1661 {
1662 t_failed++;
1663 c_failed[i] = !0;
1664 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1665 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
1666 n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
1667 }
1668 }
1669 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1670 printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1671 n_prnt(str));
1672 } 1844 }
1845 else if (rv != test_val)
1846 {
1847 t_failed++;
1848 c_failed[i] = ! 0;
1849 fprintf (stderr,
1850 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1851 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
1852 "). Locale: %s\n",
1853 n_prnt (str), (uint64_t) test_val, (uint64_t) rv,
1854 get_current_locale_str ());
1855 }
1856 }
1857 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1858 printf (
1859 "PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1860 n_prnt (str));
1673 } 1861 }
1862 }
1674 return t_failed; 1863 return t_failed;
1675} 1864}
1676 1865
1677 1866
1678int check_strx_to_uint32_no_val(void) 1867int check_strx_to_uint32_no_val (void)
1679{ 1868{
1680 size_t t_failed = 0; 1869 size_t t_failed = 0;
1681 size_t i, j; 1870 size_t i, j;
1682 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 1871 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
1683 int c_failed[n_checks]; 1872 int c_failed[n_checks];
1684 1873
1685 memset(c_failed, 0, sizeof(c_failed)); 1874 memset (c_failed, 0, sizeof(c_failed));
1686 1875
1687 for(j = 0; j < locale_name_count; j++) 1876 for (j = 0; j < locale_name_count; j++)
1877 {
1878 set_test_locale (j); /* setlocale() can be slow! */
1879 for (i = 0; i < n_checks; i++)
1688 { 1880 {
1689 set_test_locale(j); /* setlocale() can be slow! */ 1881 size_t rs;
1690 for(i = 0; i < n_checks; i++) 1882 const struct str_with_len *const t = str_no_num + i;
1883 static const uint32_t rnd_val = 74218431;
1884 uint32_t test_val;
1885
1886 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
1887 rnd_val)
1888 {
1889 uint32_t rv = test_val;
1890
1891 rs = MHD_strx_to_uint32_ (t->str, &rv);
1892 if (rs != 0)
1691 { 1893 {
1692 size_t rs; 1894 t_failed++;
1693 const struct str_with_len * const t = str_no_num + i; 1895 c_failed[i] = ! 0;
1694 static const uint32_t rnd_val = 74218431; 1896 fprintf (stderr,
1695 uint32_t test_val; 1897 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64
1696 1898 ") returned %"
1697 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 1899 PRIuPTR ", while expecting zero."
1698 { 1900 " Locale: %s\n", n_prnt (t->str), (uint64_t) rv,
1699 uint32_t rv = test_val; 1901 (uintptr_t) rs, get_current_locale_str ());
1700
1701 rs = MHD_strx_to_uint32_(t->str, &rv);
1702 if (rs != 0)
1703 {
1704 t_failed++;
1705 c_failed[i] = !0;
1706 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
1707 " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
1708 }
1709 else if (rv != test_val)
1710 {
1711 t_failed++;
1712 c_failed[i] = !0;
1713 fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1714 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
1715 n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
1716 }
1717 }
1718 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1719 printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1720 n_prnt(t->str));
1721 } 1902 }
1903 else if (rv != test_val)
1904 {
1905 t_failed++;
1906 c_failed[i] = ! 0;
1907 fprintf (stderr,
1908 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
1909 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
1910 "). Locale: %s\n",
1911 n_prnt (t->str), (uint64_t) test_val, (uint64_t) rv,
1912 get_current_locale_str ());
1913 }
1914 }
1915 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1916 printf (
1917 "PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
1918 n_prnt (t->str));
1722 } 1919 }
1920 }
1723 return t_failed; 1921 return t_failed;
1724} 1922}
1725 1923
1726 1924
1727int check_strx_to_uint32_n_valid(void) 1925int check_strx_to_uint32_n_valid (void)
1728{ 1926{
1729 size_t t_failed = 0; 1927 size_t t_failed = 0;
1730 size_t i, j; 1928 size_t i, j;
1731 static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 1929 static const size_t n_checks = sizeof(xdstrs_w_values)
1930 / sizeof(xdstrs_w_values[0]);
1732 int c_failed[n_checks]; 1931 int c_failed[n_checks];
1733 1932
1734 memset(c_failed, 0, sizeof(c_failed)); 1933 memset (c_failed, 0, sizeof(c_failed));
1735 1934
1736 for(j = 0; j < locale_name_count; j++) 1935 for (j = 0; j < locale_name_count; j++)
1936 {
1937 set_test_locale (j); /* setlocale() can be slow! */
1938 for (i = 0; i < n_checks; i++)
1737 { 1939 {
1738 set_test_locale(j); /* setlocale() can be slow! */ 1940 uint32_t rv = 2352932; /* some random value */
1739 for(i = 0; i < n_checks; i++) 1941 size_t rs = 0;
1942 size_t len;
1943 const struct str_with_value *const t = xdstrs_w_values + i;
1944
1945 if (t->val > UINT32_MAX)
1946 continue; /* number is too high for this function */
1947
1948 if (t->str.len < t->num_of_digt)
1949 {
1950 fprintf (stderr,
1951 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1952 " to be less or equal to str.len (%u).\n",
1953 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
1954 int) t->str.
1955 len);
1956 return -1;
1957 }
1958 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++)
1959 {
1960 rs = MHD_strx_to_uint32_n_ (t->str.str, len, &rv);
1961 if (rs != t->num_of_digt)
1740 { 1962 {
1741 uint32_t rv = 2352932; /* some random value */ 1963 t_failed++;
1742 size_t rs = 0; 1964 c_failed[i] = ! 0;
1743 size_t len; 1965 fprintf (stderr,
1744 const struct str_with_value * const t = xdstrs_w_values + i; 1966 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%"
1745 1967 PRIX64 ")"
1746 if (t->val > UINT32_MAX) 1968 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
1747 continue; /* number is too high for this function */ 1969 n_prnt (t->str.str), (intptr_t) len, (uint64_t) rv,
1748 1970 (intptr_t) rs,
1749 if (t->str.len < t->num_of_digt) 1971 (int) t->num_of_digt, get_current_locale_str ());
1750 {
1751 fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1752 " to be less or equal to str.len (%u).\n",
1753 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
1754 return -1;
1755 }
1756 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
1757 {
1758 rs = MHD_strx_to_uint32_n_(t->str.str, len, &rv);
1759 if (rs != t->num_of_digt)
1760 {
1761 t_failed++;
1762 c_failed[i] = !0;
1763 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
1764 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
1765 n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs,
1766 (int)t->num_of_digt, get_current_locale_str());
1767 }
1768 if (rv != t->val)
1769 {
1770 t_failed++;
1771 c_failed[i] = !0;
1772 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
1773 " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
1774 ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv,
1775 t->val, get_current_locale_str());
1776 }
1777 }
1778 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1779 printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
1780 " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
1781 (intptr_t)t->str.len + 1, (uint64_t)rv, rs);
1782 } 1972 }
1973 if (rv != t->val)
1974 {
1975 t_failed++;
1976 c_failed[i] = ! 0;
1977 fprintf (stderr,
1978 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%"
1979 PRIX64 ")"
1980 " converted string to value 0x%" PRIX64
1981 ", while expecting result 0x%" PRIX64
1982 ". Locale: %s\n", n_prnt (t->str.str), (intptr_t) len,
1983 (uint64_t) rv, (uint64_t) rv,
1984 t->val, get_current_locale_str ());
1985 }
1986 }
1987 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
1988 printf (
1989 "PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR
1990 ", ->0x%"
1991 PRIX64 ")"
1992 " == %" PRIuPTR "\n", n_prnt (t->str.str),
1993 (intptr_t) t->num_of_digt,
1994 (intptr_t) t->str.len + 1, (uint64_t) rv, rs);
1783 } 1995 }
1996 }
1784 return t_failed; 1997 return t_failed;
1785} 1998}
1786 1999
1787 2000
1788int check_strx_to_uint32_n_all_chars(void) 2001int check_strx_to_uint32_n_all_chars (void)
1789{ 2002{
1790 static const size_t n_checks = 256; /* from 0 to 255 */ 2003 static const size_t n_checks = 256; /* from 0 to 255 */
1791 int c_failed[n_checks]; 2004 int c_failed[n_checks];
1792 size_t t_failed = 0; 2005 size_t t_failed = 0;
1793 size_t j; 2006 size_t j;
1794 2007
1795 memset(c_failed, 0, sizeof(c_failed)); 2008 memset (c_failed, 0, sizeof(c_failed));
1796 2009
1797 for(j = 0; j < locale_name_count; j++) 2010 for (j = 0; j < locale_name_count; j++)
1798 { 2011 {
1799 unsigned int c; 2012 unsigned int c;
1800 uint32_t test_val; 2013 uint32_t test_val;
1801 2014
1802 set_test_locale(j); /* setlocale() can be slow! */ 2015 set_test_locale (j); /* setlocale() can be slow! */
1803 for(c = 0; c < n_checks; c++) 2016 for (c = 0; c < n_checks; c++)
2017 {
2018 static const uint32_t rnd_val = 98372558;
2019 size_t rs;
2020 size_t len;
2021
2022 if (((c >= '0') &&(c <= '9') ) || ((c >= 'A') &&(c <= 'F') ) || ((c >=
2023 'a') &&
2024 (c <=
2025 'f') ))
2026 continue; /* skip xdigits */
2027
2028 for (len = 0; len <= 5; len++)
2029 {
2030 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
2031 rnd_val)
1804 { 2032 {
1805 static const uint32_t rnd_val = 98372558; 2033 char test_str[] = "0123";
1806 size_t rs; 2034 uint32_t rv = test_val;
1807 size_t len; 2035
1808 2036 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
1809 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) 2037 rs = MHD_strx_to_uint32_n_ (test_str, len, &rv);
1810 continue; /* skip xdigits */ 2038 if (rs != 0)
1811 2039 {
1812 for (len = 0; len <= 5; len++) 2040 t_failed++;
1813 { 2041 c_failed[c] = ! 0;
1814 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 2042 fprintf (stderr,
1815 { 2043 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%"
1816 char test_str[] = "0123"; 2044 PRIX64
1817 uint32_t rv = test_val; 2045 ")"
1818 2046 " returned %" PRIuPTR
1819 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ 2047 ", while expecting zero. Locale: %s\n",
1820 rs = MHD_strx_to_uint32_n_(test_str, len, &rv); 2048 n_prnt (test_str), (uintptr_t) len, (uint64_t) rv,
1821 if (rs != 0) 2049 (uintptr_t) rs, get_current_locale_str ());
1822 { 2050 }
1823 t_failed++; 2051 else if (rv != test_val)
1824 c_failed[c] = !0; 2052 {
1825 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" 2053 t_failed++;
1826 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 2054 c_failed[c] = ! 0;
1827 n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); 2055 fprintf (stderr,
1828 } 2056 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR
1829 else if (rv != test_val) 2057 ", &ret_val)"
1830 { 2058 " modified value of ret_val (before call: 0x%" PRIX64
1831 t_failed++; 2059 ", after call 0x%" PRIX64 ")."
1832 c_failed[c] = !0; 2060 " Locale: %s\n",
1833 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)" 2061 n_prnt (test_str), (uintptr_t) len, (uint64_t) test_val,
1834 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." 2062 (uint64_t) rv, get_current_locale_str ());
1835 " Locale: %s\n", 2063 }
1836 n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
1837 }
1838 }
1839 }
1840 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
1841 {
1842 char test_str[] = "0123";
1843 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
1844
1845 printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
1846 n_prnt(test_str));
1847 }
1848 } 2064 }
2065 }
2066 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
2067 {
2068 char test_str[] = "0123";
2069 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
2070
2071 printf (
2072 "PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
2073 n_prnt (test_str));
2074 }
1849 } 2075 }
2076 }
1850 return t_failed; 2077 return t_failed;
1851} 2078}
1852 2079
1853 2080
1854int check_strx_to_uint32_n_overflow(void) 2081int check_strx_to_uint32_n_overflow (void)
1855{ 2082{
1856 size_t t_failed = 0; 2083 size_t t_failed = 0;
1857 size_t i, j; 2084 size_t i, j;
1858 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 2085 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
1859 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + 2086 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0])
1860 sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 2087 + sizeof(xdstrs_w_values)
2088 / sizeof(xdstrs_w_values[0]);
1861 int c_failed[n_checks]; 2089 int c_failed[n_checks];
1862 2090
1863 memset(c_failed, 0, sizeof(c_failed)); 2091 memset (c_failed, 0, sizeof(c_failed));
1864 2092
1865 for(j = 0; j < locale_name_count; j++) 2093 for (j = 0; j < locale_name_count; j++)
2094 {
2095 set_test_locale (j); /* setlocale() can be slow! */
2096 for (i = 0; i < n_checks; i++)
1866 { 2097 {
1867 set_test_locale(j); /* setlocale() can be slow! */ 2098 size_t rs;
1868 for(i = 0; i < n_checks; i++) 2099 static const uint32_t rnd_val = 4;
2100 size_t len;
2101 const char *str;
2102 size_t min_len, max_len;
2103 if (i < n_checks1)
2104 {
2105 const struct str_with_len *const t = strx_ovflw + i;
2106 str = t->str;
2107 min_len = t->len;
2108 max_len = t->len + 1;
2109 }
2110 else
2111 {
2112 const struct str_with_value *const t = xdstrs_w_values + (i
2113 - n_checks1);
2114 if (t->val <= UINT32_MAX)
2115 continue; /* check only strings that should overflow uint32_t */
2116
2117 if (t->str.len < t->num_of_digt)
1869 { 2118 {
1870 size_t rs; 2119 fprintf (stderr,
1871 static const uint32_t rnd_val = 4; 2120 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1872 size_t len; 2121 " to be less or equal to str.len (%u).\n",
1873 const char * str; 2122 (unsigned int) (i - n_checks1), (unsigned
1874 size_t min_len, max_len; 2123 int) t->num_of_digt,
1875 if (i < n_checks1) 2124 (unsigned int) t->str.len);
1876 { 2125 return -1;
1877 const struct str_with_len * const t = strx_ovflw + i;
1878 str = t->str;
1879 min_len = t->len;
1880 max_len = t->len + 1;
1881 }
1882 else
1883 {
1884 const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
1885 if (t->val <= UINT32_MAX)
1886 continue; /* check only strings that should overflow uint32_t */
1887
1888 if (t->str.len < t->num_of_digt)
1889 {
1890 fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
1891 " to be less or equal to str.len (%u).\n",
1892 (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt,
1893 (unsigned int) t->str.len);
1894 return -1;
1895 }
1896 str = t->str.str;
1897 min_len = t->num_of_digt;
1898 max_len = t->str.len + 1;
1899 }
1900
1901 for (len = min_len; len <= max_len; len++)
1902 {
1903 uint32_t test_val;
1904 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
1905 {
1906 uint32_t rv = test_val;
1907
1908 rs = MHD_strx_to_uint32_n_(str, len, &rv);
1909 if (rs != 0)
1910 {
1911 t_failed++;
1912 c_failed[i] = !0;
1913 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
1914 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
1915 n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
1916 }
1917 else if (rv != test_val)
1918 {
1919 t_failed++;
1920 c_failed[i] = !0;
1921 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)"
1922 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
1923 " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
1924 get_current_locale_str());
1925 }
1926 }
1927 }
1928 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1929 printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
1930 " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len,
1931 (uintptr_t)max_len);
1932 } 2126 }
2127 str = t->str.str;
2128 min_len = t->num_of_digt;
2129 max_len = t->str.len + 1;
2130 }
2131
2132 for (len = min_len; len <= max_len; len++)
2133 {
2134 uint32_t test_val;
2135 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2136 rnd_val)
2137 {
2138 uint32_t rv = test_val;
2139
2140 rs = MHD_strx_to_uint32_n_ (str, len, &rv);
2141 if (rs != 0)
2142 {
2143 t_failed++;
2144 c_failed[i] = ! 0;
2145 fprintf (stderr,
2146 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%"
2147 PRIX64
2148 ")"
2149 " returned %" PRIuPTR
2150 ", while expecting zero. Locale: %s\n",
2151 n_prnt (str), (uintptr_t) len, (uint64_t) rv,
2152 (uintptr_t) rs, get_current_locale_str ());
2153 }
2154 else if (rv != test_val)
2155 {
2156 t_failed++;
2157 c_failed[i] = ! 0;
2158 fprintf (stderr,
2159 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR
2160 ", &ret_val)"
2161 " modified value of ret_val (before call: 0x%" PRIX64
2162 ", after call 0x%" PRIX64 ")."
2163 " Locale: %s\n", n_prnt (str), (uintptr_t) len,
2164 (uint64_t) test_val, (uint64_t) rv,
2165 get_current_locale_str ());
2166 }
2167 }
2168 }
2169 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2170 printf (
2171 "PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR
2172 ", &ret_val) == 0,"
2173 " value of ret_val is unmodified\n", n_prnt (str),
2174 (uintptr_t) min_len,
2175 (uintptr_t) max_len);
1933 } 2176 }
2177 }
1934 return t_failed; 2178 return t_failed;
1935} 2179}
1936 2180
1937 2181
1938int check_strx_to_uint32_n_no_val(void) 2182int check_strx_to_uint32_n_no_val (void)
1939{ 2183{
1940 size_t t_failed = 0; 2184 size_t t_failed = 0;
1941 size_t i, j; 2185 size_t i, j;
1942 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 2186 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
1943 int c_failed[n_checks]; 2187 int c_failed[n_checks];
1944 2188
1945 memset(c_failed, 0, sizeof(c_failed)); 2189 memset (c_failed, 0, sizeof(c_failed));
1946 2190
1947 for(j = 0; j < locale_name_count; j++) 2191 for (j = 0; j < locale_name_count; j++)
2192 {
2193 set_test_locale (j); /* setlocale() can be slow! */
2194 for (i = 0; i < n_checks; i++)
1948 { 2195 {
1949 set_test_locale(j); /* setlocale() can be slow! */ 2196 size_t rs;
1950 for(i = 0; i < n_checks; i++) 2197 const struct str_with_len *const t = str_no_num + i;
2198 static const uint32_t rnd_val = 3214314212UL;
2199 size_t len;
2200
2201 for (len = 0; len <= t->len + 1; len++)
2202 {
2203 uint32_t test_val;
2204 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2205 rnd_val)
1951 { 2206 {
1952 size_t rs; 2207 uint32_t rv = test_val;
1953 const struct str_with_len * const t = str_no_num + i; 2208
1954 static const uint32_t rnd_val = 3214314212UL; 2209 rs = MHD_strx_to_uint32_n_ (t->str, len, &rv);
1955 size_t len; 2210 if (rs != 0)
1956 2211 {
1957 for (len = 0; len <= t->len + 1; len++) 2212 t_failed++;
1958 { 2213 c_failed[i] = ! 0;
1959 uint32_t test_val; 2214 fprintf (stderr,
1960 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 2215 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%"
1961 { 2216 PRIX64
1962 uint32_t rv = test_val; 2217 ")"
1963 2218 " returned %" PRIuPTR
1964 rs = MHD_strx_to_uint32_n_(t->str, len, &rv); 2219 ", while expecting zero. Locale: %s\n",
1965 if (rs != 0) 2220 n_prnt (t->str), (uintptr_t) len, (uint64_t) rv,
1966 { 2221 (uintptr_t) rs, get_current_locale_str ());
1967 t_failed++; 2222 }
1968 c_failed[i] = !0; 2223 else if (rv != test_val)
1969 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" 2224 {
1970 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 2225 t_failed++;
1971 n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); 2226 c_failed[i] = ! 0;
1972 } 2227 fprintf (stderr,
1973 else if (rv != test_val) 2228 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR
1974 { 2229 ", &ret_val)"
1975 t_failed++; 2230 " modified value of ret_val (before call: 0x%" PRIX64
1976 c_failed[i] = !0; 2231 ", after call 0x%" PRIX64 ")."
1977 fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)" 2232 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len,
1978 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." 2233 (uint64_t) test_val, (uint64_t) rv,
1979 " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, 2234 get_current_locale_str ());
1980 get_current_locale_str()); 2235 }
1981 }
1982 }
1983 }
1984 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
1985 printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
1986 " value of ret_val is unmodified\n", n_prnt(t->str),
1987 (uintptr_t)t->len + 1);
1988 } 2236 }
2237 }
2238 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2239 printf (
2240 "PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..%" PRIuPTR
2241 ", &ret_val) == 0,"
2242 " value of ret_val is unmodified\n", n_prnt (t->str),
2243 (uintptr_t) t->len + 1);
1989 } 2244 }
2245 }
1990 return t_failed; 2246 return t_failed;
1991} 2247}
1992 2248
1993 2249
1994int check_strx_to_uint64_valid(void) 2250int check_strx_to_uint64_valid (void)
1995{ 2251{
1996 size_t t_failed = 0; 2252 size_t t_failed = 0;
1997 size_t i, j; 2253 size_t i, j;
1998 static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 2254 static const size_t n_checks = sizeof(xdstrs_w_values)
2255 / sizeof(xdstrs_w_values[0]);
1999 int c_failed[n_checks]; 2256 int c_failed[n_checks];
2000 2257
2001 memset(c_failed, 0, sizeof(c_failed)); 2258 memset (c_failed, 0, sizeof(c_failed));
2002 2259
2003 for(j = 0; j < locale_name_count; j++) 2260 for (j = 0; j < locale_name_count; j++)
2261 {
2262 set_test_locale (j); /* setlocale() can be slow! */
2263 for (i = 0; i < n_checks; i++)
2004 { 2264 {
2005 set_test_locale(j); /* setlocale() can be slow! */ 2265 uint64_t rv;
2006 for(i = 0; i < n_checks; i++) 2266 size_t rs;
2007 { 2267 const struct str_with_value *const t = xdstrs_w_values + i;
2008 uint64_t rv; 2268
2009 size_t rs; 2269 if (c_failed[i])
2010 const struct str_with_value * const t = xdstrs_w_values + i; 2270 continue; /* skip already failed checks */
2011 2271
2012 if (c_failed[i]) 2272 if (t->str.len < t->num_of_digt)
2013 continue; /* skip already failed checks */ 2273 {
2014 2274 fprintf (stderr,
2015 if (t->str.len < t->num_of_digt) 2275 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
2016 { 2276 " to be less or equal to str.len (%u).\n",
2017 fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2277 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
2018 " to be less or equal to str.len (%u).\n", 2278 int) t->str.
2019 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); 2279 len);
2020 return -1; 2280 return -1;
2021 } 2281 }
2022 rv = 1458532; /* some random value */ 2282 rv = 1458532; /* some random value */
2023 rs = MHD_strx_to_uint64_(t->str.str, &rv); 2283 rs = MHD_strx_to_uint64_ (t->str.str, &rv);
2024 if (rs != t->num_of_digt) 2284 if (rs != t->num_of_digt)
2025 { 2285 {
2026 t_failed++; 2286 t_failed++;
2027 c_failed[i] = !0; 2287 c_failed[i] = ! 0;
2028 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." 2288 fprintf (stderr,
2029 " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); 2289 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64
2030 } 2290 ") returned %"
2031 if (rv != t->val) 2291 PRIuPTR ", while expecting %d."
2032 { 2292 " Locale: %s\n", n_prnt (t->str.str), rv, (intptr_t) rs,
2033 t_failed++; 2293 (int) t->num_of_digt, get_current_locale_str ());
2034 c_failed[i] = !0; 2294 }
2035 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," 2295 if (rv != t->val)
2036 " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv, 2296 {
2037 t->val, get_current_locale_str()); 2297 t_failed++;
2038 } 2298 c_failed[i] = ! 0;
2039 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) 2299 fprintf (stderr,
2040 printf("PASSED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", 2300 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64
2041 n_prnt(t->str.str), rv, rs); 2301 ") converted string to value 0x%"
2042 } 2302 PRIX64 ","
2303 " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt (
2304 t->str.str), rv, rv,
2305 t->val, get_current_locale_str ());
2306 }
2307 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2308 printf (
2309 "PASSED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR
2310 "\n",
2311 n_prnt (t->str.str), rv, rs);
2043 } 2312 }
2313 }
2044 return t_failed; 2314 return t_failed;
2045} 2315}
2046 2316
2047 2317
2048int check_strx_to_uint64_all_chars(void) 2318int check_strx_to_uint64_all_chars (void)
2049{ 2319{
2050 static const size_t n_checks = 256; /* from 0 to 255 */ 2320 static const size_t n_checks = 256; /* from 0 to 255 */
2051 int c_failed[n_checks]; 2321 int c_failed[n_checks];
2052 size_t t_failed = 0; 2322 size_t t_failed = 0;
2053 size_t j; 2323 size_t j;
2054 2324
2055 memset(c_failed, 0, sizeof(c_failed)); 2325 memset (c_failed, 0, sizeof(c_failed));
2056 2326
2057 for(j = 0; j < locale_name_count; j++) 2327 for (j = 0; j < locale_name_count; j++)
2058 { 2328 {
2059 unsigned int c; 2329 unsigned int c;
2060 uint64_t test_val; 2330 uint64_t test_val;
2061 2331
2062 set_test_locale(j); /* setlocale() can be slow! */ 2332 set_test_locale (j); /* setlocale() can be slow! */
2063 for(c = 0; c < n_checks; c++) 2333 for (c = 0; c < n_checks; c++)
2334 {
2335 static const uint64_t rnd_val = 234234;
2336 size_t rs;
2337 if (((c >= '0') &&(c <= '9') ) || ((c >= 'A') &&(c <= 'F') ) || ((c >=
2338 'a') &&
2339 (c <=
2340 'f') ))
2341 continue; /* skip xdigits */
2342 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
2343 rnd_val)
2344 {
2345 char test_str[] = "0123";
2346 uint64_t rv = test_val;
2347
2348 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
2349 rs = MHD_strx_to_uint64_ (test_str, &rv);
2350 if (rs != 0)
2064 { 2351 {
2065 static const uint64_t rnd_val = 234234; 2352 t_failed++;
2066 size_t rs; 2353 c_failed[c] = ! 0;
2067 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) 2354 fprintf (stderr,
2068 continue; /* skip xdigits */ 2355 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64
2069 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 2356 ") returned %"
2070 { 2357 PRIuPTR ", while expecting zero."
2071 char test_str[] = "0123"; 2358 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs,
2072 uint64_t rv = test_val; 2359 get_current_locale_str ());
2073
2074 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
2075 rs = MHD_strx_to_uint64_(test_str, &rv);
2076 if (rs != 0)
2077 {
2078 t_failed++;
2079 c_failed[c] = !0;
2080 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
2081 " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str());
2082 }
2083 else if (rv != test_val)
2084 {
2085 t_failed++;
2086 c_failed[c] = !0;
2087 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2088 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
2089 n_prnt(test_str), test_val, rv, get_current_locale_str());
2090 }
2091 }
2092 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
2093 {
2094 char test_str[] = "0123";
2095 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
2096
2097 printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2098 n_prnt(test_str));
2099 }
2100 } 2360 }
2361 else if (rv != test_val)
2362 {
2363 t_failed++;
2364 c_failed[c] = ! 0;
2365 fprintf (stderr,
2366 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2367 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
2368 "). Locale: %s\n",
2369 n_prnt (test_str), test_val, rv, get_current_locale_str ());
2370 }
2371 }
2372 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
2373 {
2374 char test_str[] = "0123";
2375 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
2376
2377 printf (
2378 "PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2379 n_prnt (test_str));
2380 }
2101 } 2381 }
2382 }
2102 return t_failed; 2383 return t_failed;
2103} 2384}
2104 2385
2105 2386
2106int check_strx_to_uint64_overflow(void) 2387int check_strx_to_uint64_overflow (void)
2107{ 2388{
2108 size_t t_failed = 0; 2389 size_t t_failed = 0;
2109 size_t i, j; 2390 size_t i, j;
2110 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 2391 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
2111 int c_failed[n_checks]; 2392 int c_failed[n_checks];
2112 2393
2113 memset(c_failed, 0, sizeof(c_failed)); 2394 memset (c_failed, 0, sizeof(c_failed));
2114 2395
2115 for(j = 0; j < locale_name_count; j++) 2396 for (j = 0; j < locale_name_count; j++)
2397 {
2398 set_test_locale (j); /* setlocale() can be slow! */
2399 for (i = 0; i < n_checks; i++)
2116 { 2400 {
2117 set_test_locale(j); /* setlocale() can be slow! */ 2401 size_t rs;
2118 for(i = 0; i < n_checks; i++) 2402 const struct str_with_len *const t = strx_ovflw + i;
2403 static const uint64_t rnd_val = 74218431;
2404 uint64_t test_val;
2405
2406 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2407 rnd_val)
2408 {
2409 uint64_t rv = test_val;
2410
2411 rs = MHD_strx_to_uint64_ (t->str, &rv);
2412 if (rs != 0)
2119 { 2413 {
2120 size_t rs; 2414 t_failed++;
2121 const struct str_with_len * const t = strx_ovflw + i; 2415 c_failed[i] = ! 0;
2122 static const uint64_t rnd_val = 74218431; 2416 fprintf (stderr,
2123 uint64_t test_val; 2417 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64
2124 2418 ") returned %"
2125 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 2419 PRIuPTR ", while expecting zero."
2126 { 2420 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs,
2127 uint64_t rv = test_val; 2421 get_current_locale_str ());
2128
2129 rs = MHD_strx_to_uint64_(t->str, &rv);
2130 if (rs != 0)
2131 {
2132 t_failed++;
2133 c_failed[i] = !0;
2134 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
2135 " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
2136 }
2137 else if (rv != test_val)
2138 {
2139 t_failed++;
2140 c_failed[i] = !0;
2141 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2142 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
2143 n_prnt(t->str), test_val, rv, get_current_locale_str());
2144 }
2145 }
2146 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
2147 printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2148 n_prnt(t->str));
2149 } 2422 }
2423 else if (rv != test_val)
2424 {
2425 t_failed++;
2426 c_failed[i] = ! 0;
2427 fprintf (stderr,
2428 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2429 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
2430 "). Locale: %s\n",
2431 n_prnt (t->str), test_val, rv, get_current_locale_str ());
2432 }
2433 }
2434 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2435 printf (
2436 "PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2437 n_prnt (t->str));
2150 } 2438 }
2439 }
2151 return t_failed; 2440 return t_failed;
2152} 2441}
2153 2442
2154 2443
2155int check_strx_to_uint64_no_val(void) 2444int check_strx_to_uint64_no_val (void)
2156{ 2445{
2157 size_t t_failed = 0; 2446 size_t t_failed = 0;
2158 size_t i, j; 2447 size_t i, j;
2159 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 2448 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
2160 int c_failed[n_checks]; 2449 int c_failed[n_checks];
2161 2450
2162 memset(c_failed, 0, sizeof(c_failed)); 2451 memset (c_failed, 0, sizeof(c_failed));
2163 2452
2164 for(j = 0; j < locale_name_count; j++) 2453 for (j = 0; j < locale_name_count; j++)
2454 {
2455 set_test_locale (j); /* setlocale() can be slow! */
2456 for (i = 0; i < n_checks; i++)
2165 { 2457 {
2166 set_test_locale(j); /* setlocale() can be slow! */ 2458 size_t rs;
2167 for(i = 0; i < n_checks; i++) 2459 const struct str_with_len *const t = str_no_num + i;
2460 static const uint64_t rnd_val = 74218431;
2461 uint64_t test_val;
2462
2463 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2464 rnd_val)
2465 {
2466 uint64_t rv = test_val;
2467
2468 rs = MHD_strx_to_uint64_ (t->str, &rv);
2469 if (rs != 0)
2470 {
2471 t_failed++;
2472 c_failed[i] = ! 0;
2473 fprintf (stderr,
2474 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64
2475 ") returned %"
2476 PRIuPTR ", while expecting zero."
2477 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs,
2478 get_current_locale_str ());
2479 }
2480 else if (rv != test_val)
2168 { 2481 {
2169 size_t rs; 2482 t_failed++;
2170 const struct str_with_len * const t = str_no_num + i; 2483 c_failed[i] = ! 0;
2171 static const uint64_t rnd_val = 74218431; 2484 fprintf (stderr,
2172 uint64_t test_val; 2485 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2173 2486 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64
2174 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 2487 "). Locale: %s\n",
2175 { 2488 n_prnt (t->str), test_val, rv, get_current_locale_str ());
2176 uint64_t rv = test_val;
2177
2178 rs = MHD_strx_to_uint64_(t->str, &rv);
2179 if (rs != 0)
2180 {
2181 t_failed++;
2182 c_failed[i] = !0;
2183 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
2184 " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
2185 }
2186 else if (rv != test_val)
2187 {
2188 t_failed++;
2189 c_failed[i] = !0;
2190 fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
2191 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
2192 n_prnt(t->str), test_val, rv, get_current_locale_str());
2193 }
2194 }
2195 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
2196 printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2197 n_prnt(t->str));
2198 } 2489 }
2490 }
2491 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2492 printf (
2493 "PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
2494 n_prnt (t->str));
2199 } 2495 }
2496 }
2200 return t_failed; 2497 return t_failed;
2201} 2498}
2202 2499
2203 2500
2204int check_strx_to_uint64_n_valid(void) 2501int check_strx_to_uint64_n_valid (void)
2205{ 2502{
2206 size_t t_failed = 0; 2503 size_t t_failed = 0;
2207 size_t i, j; 2504 size_t i, j;
2208 static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); 2505 static const size_t n_checks = sizeof(xdstrs_w_values)
2506 / sizeof(xdstrs_w_values[0]);
2209 int c_failed[n_checks]; 2507 int c_failed[n_checks];
2210 2508
2211 memset(c_failed, 0, sizeof(c_failed)); 2509 memset (c_failed, 0, sizeof(c_failed));
2212 2510
2213 for(j = 0; j < locale_name_count; j++) 2511 for (j = 0; j < locale_name_count; j++)
2512 {
2513 set_test_locale (j); /* setlocale() can be slow! */
2514 for (i = 0; i < n_checks; i++)
2214 { 2515 {
2215 set_test_locale(j); /* setlocale() can be slow! */ 2516 uint64_t rv = 2352932; /* some random value */
2216 for(i = 0; i < n_checks; i++) 2517 size_t rs = 0;
2518 size_t len;
2519 const struct str_with_value *const t = xdstrs_w_values + i;
2520
2521 if (t->str.len < t->num_of_digt)
2522 {
2523 fprintf (stderr,
2524 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
2525 " to be less or equal to str.len (%u).\n",
2526 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned
2527 int) t->str.
2528 len);
2529 return -1;
2530 }
2531 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++)
2532 {
2533 rs = MHD_strx_to_uint64_n_ (t->str.str, len, &rv);
2534 if (rs != t->num_of_digt)
2217 { 2535 {
2218 uint64_t rv = 2352932; /* some random value */ 2536 t_failed++;
2219 size_t rs = 0; 2537 c_failed[i] = ! 0;
2220 size_t len; 2538 fprintf (stderr,
2221 const struct str_with_value * const t = xdstrs_w_values + i; 2539 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%"
2222 2540 PRIX64 ")"
2223 if (t->str.len < t->num_of_digt) 2541 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
2224 { 2542 n_prnt (t->str.str), (intptr_t) len, rv, (intptr_t) rs,
2225 fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2543 (int) t->num_of_digt, get_current_locale_str ());
2226 " to be less or equal to str.len (%u).\n",
2227 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
2228 return -1;
2229 }
2230 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
2231 {
2232 rs = MHD_strx_to_uint64_n_(t->str.str, len, &rv);
2233 if (rs != t->num_of_digt)
2234 {
2235 t_failed++;
2236 c_failed[i] = !0;
2237 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
2238 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
2239 n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs,
2240 (int)t->num_of_digt, get_current_locale_str());
2241 }
2242 if (rv != t->val)
2243 {
2244 t_failed++;
2245 c_failed[i] = !0;
2246 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
2247 " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
2248 ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv,
2249 t->val, get_current_locale_str());
2250 }
2251 }
2252 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
2253 printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
2254 " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
2255 (intptr_t)t->str.len + 1, rv, rs);
2256 } 2544 }
2545 if (rv != t->val)
2546 {
2547 t_failed++;
2548 c_failed[i] = ! 0;
2549 fprintf (stderr,
2550 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%"
2551 PRIX64 ")"
2552 " converted string to value 0x%" PRIX64
2553 ", while expecting result 0x%" PRIX64
2554 ". Locale: %s\n", n_prnt (t->str.str), (intptr_t) len, rv,
2555 rv,
2556 t->val, get_current_locale_str ());
2557 }
2558 }
2559 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2560 printf (
2561 "PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR
2562 ", ->0x%"
2563 PRIX64 ")"
2564 " == %" PRIuPTR "\n", n_prnt (t->str.str),
2565 (intptr_t) t->num_of_digt,
2566 (intptr_t) t->str.len + 1, rv, rs);
2257 } 2567 }
2568 }
2258 return t_failed; 2569 return t_failed;
2259} 2570}
2260 2571
2261 2572
2262int check_strx_to_uint64_n_all_chars(void) 2573int check_strx_to_uint64_n_all_chars (void)
2263{ 2574{
2264 static const size_t n_checks = 256; /* from 0 to 255 */ 2575 static const size_t n_checks = 256; /* from 0 to 255 */
2265 int c_failed[n_checks]; 2576 int c_failed[n_checks];
2266 size_t t_failed = 0; 2577 size_t t_failed = 0;
2267 size_t j; 2578 size_t j;
2268 2579
2269 memset(c_failed, 0, sizeof(c_failed)); 2580 memset (c_failed, 0, sizeof(c_failed));
2270 2581
2271 for(j = 0; j < locale_name_count; j++) 2582 for (j = 0; j < locale_name_count; j++)
2272 { 2583 {
2273 unsigned int c; 2584 unsigned int c;
2274 uint64_t test_val; 2585 uint64_t test_val;
2275 2586
2276 set_test_locale(j); /* setlocale() can be slow! */ 2587 set_test_locale (j); /* setlocale() can be slow! */
2277 for(c = 0; c < n_checks; c++) 2588 for (c = 0; c < n_checks; c++)
2589 {
2590 static const uint64_t rnd_val = 98372558;
2591 size_t rs;
2592 size_t len;
2593
2594 if (((c >= '0') &&(c <= '9') ) || ((c >= 'A') &&(c <= 'F') ) || ((c >=
2595 'a') &&
2596 (c <=
2597 'f') ))
2598 continue; /* skip xdigits */
2599
2600 for (len = 0; len <= 5; len++)
2601 {
2602 for (test_val = 0; test_val <= rnd_val&& ! c_failed[c]; test_val +=
2603 rnd_val)
2278 { 2604 {
2279 static const uint64_t rnd_val = 98372558; 2605 char test_str[] = "0123";
2280 size_t rs; 2606 uint64_t rv = test_val;
2281 size_t len; 2607
2282 2608 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
2283 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) 2609 rs = MHD_strx_to_uint64_n_ (test_str, len, &rv);
2284 continue; /* skip xdigits */ 2610 if (rs != 0)
2285 2611 {
2286 for (len = 0; len <= 5; len++) 2612 t_failed++;
2287 { 2613 c_failed[c] = ! 0;
2288 for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) 2614 fprintf (stderr,
2289 { 2615 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%"
2290 char test_str[] = "0123"; 2616 PRIX64
2291 uint64_t rv = test_val; 2617 ")"
2292 2618 " returned %" PRIuPTR
2293 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ 2619 ", while expecting zero. Locale: %s\n",
2294 rs = MHD_strx_to_uint64_n_(test_str, len, &rv); 2620 n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs,
2295 if (rs != 0) 2621 get_current_locale_str ());
2296 { 2622 }
2297 t_failed++; 2623 else if (rv != test_val)
2298 c_failed[c] = !0; 2624 {
2299 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" 2625 t_failed++;
2300 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 2626 c_failed[c] = ! 0;
2301 n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 2627 fprintf (stderr,
2302 } 2628 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR
2303 else if (rv != test_val) 2629 ", &ret_val)"
2304 { 2630 " modified value of ret_val (before call: 0x%" PRIX64
2305 t_failed++; 2631 ", after call 0x%" PRIX64 ")."
2306 c_failed[c] = !0; 2632 " Locale: %s\n",
2307 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 2633 n_prnt (test_str), (uintptr_t) len, test_val, rv,
2308 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." 2634 get_current_locale_str ());
2309 " Locale: %s\n", 2635 }
2310 n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str());
2311 }
2312 }
2313 }
2314 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
2315 {
2316 char test_str[] = "0123";
2317 test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
2318
2319 printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
2320 n_prnt(test_str));
2321 }
2322 } 2636 }
2637 }
2638 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[c])
2639 {
2640 char test_str[] = "0123";
2641 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */
2642
2643 printf (
2644 "PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
2645 n_prnt (test_str));
2646 }
2323 } 2647 }
2648 }
2324 return t_failed; 2649 return t_failed;
2325} 2650}
2326 2651
2327 2652
2328int check_strx_to_uint64_n_overflow(void) 2653int check_strx_to_uint64_n_overflow (void)
2329{ 2654{
2330 size_t t_failed = 0; 2655 size_t t_failed = 0;
2331 size_t i, j; 2656 size_t i, j;
2332 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 2657 static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
2333 int c_failed[n_checks]; 2658 int c_failed[n_checks];
2334 2659
2335 memset(c_failed, 0, sizeof(c_failed)); 2660 memset (c_failed, 0, sizeof(c_failed));
2336 2661
2337 for(j = 0; j < locale_name_count; j++) 2662 for (j = 0; j < locale_name_count; j++)
2663 {
2664 set_test_locale (j); /* setlocale() can be slow! */
2665 for (i = 0; i < n_checks; i++)
2338 { 2666 {
2339 set_test_locale(j); /* setlocale() can be slow! */ 2667 size_t rs;
2340 for(i = 0; i < n_checks; i++) 2668 const struct str_with_len *const t = strx_ovflw + i;
2669 static const uint64_t rnd_val = 4;
2670 size_t len;
2671
2672 for (len = t->len; len <= t->len + 1; len++)
2673 {
2674 uint64_t test_val;
2675 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2676 rnd_val)
2341 { 2677 {
2342 size_t rs; 2678 uint64_t rv = test_val;
2343 const struct str_with_len * const t = strx_ovflw + i; 2679
2344 static const uint64_t rnd_val = 4; 2680 rs = MHD_strx_to_uint64_n_ (t->str, len, &rv);
2345 size_t len; 2681 if (rs != 0)
2346 2682 {
2347 for (len = t->len; len <= t->len + 1; len++) 2683 t_failed++;
2348 { 2684 c_failed[i] = ! 0;
2349 uint64_t test_val; 2685 fprintf (stderr,
2350 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 2686 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%"
2351 { 2687 PRIX64
2352 uint64_t rv = test_val; 2688 ")"
2353 2689 " returned %" PRIuPTR
2354 rs = MHD_strx_to_uint64_n_(t->str, len, &rv); 2690 ", while expecting zero. Locale: %s\n",
2355 if (rs != 0) 2691 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs,
2356 { 2692 get_current_locale_str ());
2357 t_failed++; 2693 }
2358 c_failed[i] = !0; 2694 else if (rv != test_val)
2359 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" 2695 {
2360 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 2696 t_failed++;
2361 n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 2697 c_failed[i] = ! 0;
2362 } 2698 fprintf (stderr,
2363 else if (rv != test_val) 2699 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR
2364 { 2700 ", &ret_val)"
2365 t_failed++; 2701 " modified value of ret_val (before call: 0x%" PRIX64
2366 c_failed[i] = !0; 2702 ", after call 0x%" PRIX64 ")."
2367 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 2703 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len,
2368 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." 2704 test_val, rv,
2369 " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, 2705 get_current_locale_str ());
2370 get_current_locale_str()); 2706 }
2371 }
2372 }
2373 }
2374 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
2375 printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
2376 " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len,
2377 (uintptr_t)t->len + 1);
2378 } 2707 }
2708 }
2709 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2710 printf (
2711 "PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR
2712 ", &ret_val) == 0,"
2713 " value of ret_val is unmodified\n", n_prnt (t->str),
2714 (uintptr_t) t->len,
2715 (uintptr_t) t->len + 1);
2379 } 2716 }
2717 }
2380 return t_failed; 2718 return t_failed;
2381} 2719}
2382 2720
2383 2721
2384int check_strx_to_uint64_n_no_val(void) 2722int check_strx_to_uint64_n_no_val (void)
2385{ 2723{
2386 size_t t_failed = 0; 2724 size_t t_failed = 0;
2387 size_t i, j; 2725 size_t i, j;
2388 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); 2726 static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
2389 int c_failed[n_checks]; 2727 int c_failed[n_checks];
2390 2728
2391 memset(c_failed, 0, sizeof(c_failed)); 2729 memset (c_failed, 0, sizeof(c_failed));
2392 2730
2393 for(j = 0; j < locale_name_count; j++) 2731 for (j = 0; j < locale_name_count; j++)
2732 {
2733 set_test_locale (j); /* setlocale() can be slow! */
2734 for (i = 0; i < n_checks; i++)
2394 { 2735 {
2395 set_test_locale(j); /* setlocale() can be slow! */ 2736 size_t rs;
2396 for(i = 0; i < n_checks; i++) 2737 const struct str_with_len *const t = str_no_num + i;
2738 static const uint64_t rnd_val = 3214314212UL;
2739 size_t len;
2740
2741 for (len = 0; len <= t->len + 1; len++)
2742 {
2743 uint64_t test_val;
2744 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val +=
2745 rnd_val)
2397 { 2746 {
2398 size_t rs; 2747 uint64_t rv = test_val;
2399 const struct str_with_len * const t = str_no_num + i; 2748
2400 static const uint64_t rnd_val = 3214314212UL; 2749 rs = MHD_strx_to_uint64_n_ (t->str, len, &rv);
2401 size_t len; 2750 if (rs != 0)
2402 2751 {
2403 for (len = 0; len <= t->len + 1; len++) 2752 t_failed++;
2404 { 2753 c_failed[i] = ! 0;
2405 uint64_t test_val; 2754 fprintf (stderr,
2406 for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) 2755 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%"
2407 { 2756 PRIX64
2408 uint64_t rv = test_val; 2757 ")"
2409 2758 " returned %" PRIuPTR
2410 rs = MHD_strx_to_uint64_n_(t->str, len, &rv); 2759 ", while expecting zero. Locale: %s\n",
2411 if (rs != 0) 2760 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs,
2412 { 2761 get_current_locale_str ());
2413 t_failed++; 2762 }
2414 c_failed[i] = !0; 2763 else if (rv != test_val)
2415 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" 2764 {
2416 " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", 2765 t_failed++;
2417 n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); 2766 c_failed[i] = ! 0;
2418 } 2767 fprintf (stderr,
2419 else if (rv != test_val) 2768 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR
2420 { 2769 ", &ret_val)"
2421 t_failed++; 2770 " modified value of ret_val (before call: 0x%" PRIX64
2422 c_failed[i] = !0; 2771 ", after call 0x%" PRIX64 ")."
2423 fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" 2772 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len,
2424 " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." 2773 test_val, rv,
2425 " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, 2774 get_current_locale_str ());
2426 get_current_locale_str()); 2775 }
2427 }
2428 }
2429 }
2430 if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
2431 printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
2432 " value of ret_val is unmodified\n", n_prnt(t->str),
2433 (uintptr_t)t->len + 1);
2434 } 2776 }
2777 }
2778 if ((verbose > 1) &&(j == locale_name_count - 1) && ! c_failed[i])
2779 printf (
2780 "PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..%" PRIuPTR
2781 ", &ret_val) == 0,"
2782 " value of ret_val is unmodified\n", n_prnt (t->str),
2783 (uintptr_t) t->len + 1);
2435 } 2784 }
2785 }
2436 return t_failed; 2786 return t_failed;
2437} 2787}
2438 2788
2439 2789
2440int run_str_to_X_tests(void) 2790int run_str_to_X_tests (void)
2441{ 2791{
2442 int str_to_uint64_fails = 0; 2792 int str_to_uint64_fails = 0;
2443 int str_to_uint64_n_fails = 0; 2793 int str_to_uint64_n_fails = 0;
@@ -2447,406 +2797,491 @@ int run_str_to_X_tests(void)
2447 int strx_to_uint64_n_fails = 0; 2797 int strx_to_uint64_n_fails = 0;
2448 int res; 2798 int res;
2449 2799
2450 res = check_str_to_uint64_valid(); 2800 res = check_str_to_uint64_valid ();
2451 if (res != 0) 2801 if (res != 0)
2802 {
2803 if (res < 0)
2452 { 2804 {
2453 if (res < 0) 2805 fprintf (stderr,
2454 { 2806 "ERROR: test internal error in check_str_to_uint64_valid().\n");
2455 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_valid().\n"); 2807 return 99;
2456 return 99;
2457 }
2458 str_to_uint64_fails += res;
2459 fprintf(stderr, "FAILED: testcase check_str_to_uint64_valid() failed.\n\n");
2460 } 2808 }
2809 str_to_uint64_fails += res;
2810 fprintf (stderr,
2811 "FAILED: testcase check_str_to_uint64_valid() failed.\n\n");
2812 }
2461 else if (verbose > 1) 2813 else if (verbose > 1)
2462 printf("PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n"); 2814 printf (
2815 "PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n");
2463 2816
2464 res = check_str_to_uint64_all_chars(); 2817 res = check_str_to_uint64_all_chars ();
2465 if (res != 0) 2818 if (res != 0)
2819 {
2820 if (res < 0)
2466 { 2821 {
2467 if (res < 0) 2822 fprintf (stderr,
2468 { 2823 "ERROR: test internal error in check_str_to_uint64_all_chars().\n");
2469 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_all_chars().\n"); 2824 return 99;
2470 return 99;
2471 }
2472 str_to_uint64_fails += res;
2473 fprintf(stderr, "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n");
2474 } 2825 }
2826 str_to_uint64_fails += res;
2827 fprintf (stderr,
2828 "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n");
2829 }
2475 else if (verbose > 1) 2830 else if (verbose > 1)
2476 printf("PASSED: testcase check_str_to_uint64_all_chars() successfully passed.\n\n"); 2831 printf (
2832 "PASSED: testcase check_str_to_uint64_all_chars() successfully passed.\n\n");
2477 2833
2478 res = check_str_to_uint64_overflow(); 2834 res = check_str_to_uint64_overflow ();
2479 if (res != 0) 2835 if (res != 0)
2836 {
2837 if (res < 0)
2480 { 2838 {
2481 if (res < 0) 2839 fprintf (stderr,
2482 { 2840 "ERROR: test internal error in check_str_to_uint64_overflow().\n");
2483 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_overflow().\n"); 2841 return 99;
2484 return 99;
2485 }
2486 str_to_uint64_fails += res;
2487 fprintf(stderr, "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n");
2488 } 2842 }
2843 str_to_uint64_fails += res;
2844 fprintf (stderr,
2845 "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n");
2846 }
2489 else if (verbose > 1) 2847 else if (verbose > 1)
2490 printf("PASSED: testcase check_str_to_uint64_overflow() successfully passed.\n\n"); 2848 printf (
2849 "PASSED: testcase check_str_to_uint64_overflow() successfully passed.\n\n");
2491 2850
2492 res = check_str_to_uint64_no_val(); 2851 res = check_str_to_uint64_no_val ();
2493 if (res != 0) 2852 if (res != 0)
2853 {
2854 if (res < 0)
2494 { 2855 {
2495 if (res < 0) 2856 fprintf (stderr,
2496 { 2857 "ERROR: test internal error in check_str_to_uint64_no_val().\n");
2497 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_no_val().\n"); 2858 return 99;
2498 return 99;
2499 }
2500 str_to_uint64_fails += res;
2501 fprintf(stderr, "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n");
2502 } 2859 }
2860 str_to_uint64_fails += res;
2861 fprintf (stderr,
2862 "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n");
2863 }
2503 else if (verbose > 1) 2864 else if (verbose > 1)
2504 printf("PASSED: testcase check_str_to_uint64_no_val() successfully passed.\n\n"); 2865 printf (
2866 "PASSED: testcase check_str_to_uint64_no_val() successfully passed.\n\n");
2505 2867
2506 if (str_to_uint64_fails) 2868 if (str_to_uint64_fails)
2507 fprintf(stderr, "FAILED: function MHD_str_to_uint64_() failed %d time%s.\n\n", 2869 fprintf (stderr,
2508 str_to_uint64_fails, str_to_uint64_fails == 1 ? "" : "s"); 2870 "FAILED: function MHD_str_to_uint64_() failed %d time%s.\n\n",
2871 str_to_uint64_fails, str_to_uint64_fails == 1 ? "" : "s");
2509 else if (verbose > 0) 2872 else if (verbose > 0)
2510 printf("PASSED: function MHD_str_to_uint64_() successfully passed all checks.\n\n"); 2873 printf (
2874 "PASSED: function MHD_str_to_uint64_() successfully passed all checks.\n\n");
2511 2875
2512 res = check_str_to_uint64_n_valid(); 2876 res = check_str_to_uint64_n_valid ();
2513 if (res != 0) 2877 if (res != 0)
2878 {
2879 if (res < 0)
2514 { 2880 {
2515 if (res < 0) 2881 fprintf (stderr,
2516 { 2882 "ERROR: test internal error in check_str_to_uint64_n_valid().\n");
2517 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_valid().\n"); 2883 return 99;
2518 return 99;
2519 }
2520 str_to_uint64_n_fails += res;
2521 fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n");
2522 } 2884 }
2885 str_to_uint64_n_fails += res;
2886 fprintf (stderr,
2887 "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n");
2888 }
2523 else if (verbose > 1) 2889 else if (verbose > 1)
2524 printf("PASSED: testcase check_str_to_uint64_n_valid() successfully passed.\n\n"); 2890 printf (
2891 "PASSED: testcase check_str_to_uint64_n_valid() successfully passed.\n\n");
2525 2892
2526 res = check_str_to_uint64_n_all_chars(); 2893 res = check_str_to_uint64_n_all_chars ();
2527 if (res != 0) 2894 if (res != 0)
2895 {
2896 if (res < 0)
2528 { 2897 {
2529 if (res < 0) 2898 fprintf (stderr,
2530 { 2899 "ERROR: test internal error in check_str_to_uint64_n_all_chars().\n");
2531 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_all_chars().\n"); 2900 return 99;
2532 return 99;
2533 }
2534 str_to_uint64_n_fails += res;
2535 fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n");
2536 } 2901 }
2902 str_to_uint64_n_fails += res;
2903 fprintf (stderr,
2904 "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n");
2905 }
2537 else if (verbose > 1) 2906 else if (verbose > 1)
2538 printf("PASSED: testcase check_str_to_uint64_n_all_chars() successfully passed.\n\n"); 2907 printf (
2908 "PASSED: testcase check_str_to_uint64_n_all_chars() successfully passed.\n\n");
2539 2909
2540 res = check_str_to_uint64_n_overflow(); 2910 res = check_str_to_uint64_n_overflow ();
2541 if (res != 0) 2911 if (res != 0)
2912 {
2913 if (res < 0)
2542 { 2914 {
2543 if (res < 0) 2915 fprintf (stderr,
2544 { 2916 "ERROR: test internal error in check_str_to_uint64_n_overflow().\n");
2545 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_overflow().\n"); 2917 return 99;
2546 return 99;
2547 }
2548 str_to_uint64_n_fails += res;
2549 fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n");
2550 } 2918 }
2919 str_to_uint64_n_fails += res;
2920 fprintf (stderr,
2921 "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n");
2922 }
2551 else if (verbose > 1) 2923 else if (verbose > 1)
2552 printf("PASSED: testcase check_str_to_uint64_n_overflow() successfully passed.\n\n"); 2924 printf (
2925 "PASSED: testcase check_str_to_uint64_n_overflow() successfully passed.\n\n");
2553 2926
2554 res = check_str_to_uint64_n_no_val(); 2927 res = check_str_to_uint64_n_no_val ();
2555 if (res != 0) 2928 if (res != 0)
2929 {
2930 if (res < 0)
2556 { 2931 {
2557 if (res < 0) 2932 fprintf (stderr,
2558 { 2933 "ERROR: test internal error in check_str_to_uint64_n_no_val().\n");
2559 fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_no_val().\n"); 2934 return 99;
2560 return 99;
2561 }
2562 str_to_uint64_n_fails += res;
2563 fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n");
2564 } 2935 }
2936 str_to_uint64_n_fails += res;
2937 fprintf (stderr,
2938 "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n");
2939 }
2565 else if (verbose > 1) 2940 else if (verbose > 1)
2566 printf("PASSED: testcase check_str_to_uint64_n_no_val() successfully passed.\n\n"); 2941 printf (
2942 "PASSED: testcase check_str_to_uint64_n_no_val() successfully passed.\n\n");
2567 2943
2568 if (str_to_uint64_n_fails) 2944 if (str_to_uint64_n_fails)
2569 fprintf(stderr, "FAILED: function MHD_str_to_uint64_n_() failed %d time%s.\n\n", 2945 fprintf (stderr,
2570 str_to_uint64_n_fails, str_to_uint64_n_fails == 1 ? "" : "s"); 2946 "FAILED: function MHD_str_to_uint64_n_() failed %d time%s.\n\n",
2947 str_to_uint64_n_fails, str_to_uint64_n_fails == 1 ? "" : "s");
2571 else if (verbose > 0) 2948 else if (verbose > 0)
2572 printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n"); 2949 printf (
2950 "PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n");
2573 2951
2574 res = check_strx_to_uint32_valid(); 2952 res = check_strx_to_uint32_valid ();
2575 if (res != 0) 2953 if (res != 0)
2954 {
2955 if (res < 0)
2576 { 2956 {
2577 if (res < 0) 2957 fprintf (stderr,
2578 { 2958 "ERROR: test internal error in check_strx_to_uint32_valid().\n");
2579 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_valid().\n"); 2959 return 99;
2580 return 99;
2581 }
2582 strx_to_uint32_fails += res;
2583 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n");
2584 } 2960 }
2961 strx_to_uint32_fails += res;
2962 fprintf (stderr,
2963 "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n");
2964 }
2585 else if (verbose > 1) 2965 else if (verbose > 1)
2586 printf("PASSED: testcase check_strx_to_uint32_valid() successfully passed.\n\n"); 2966 printf (
2967 "PASSED: testcase check_strx_to_uint32_valid() successfully passed.\n\n");
2587 2968
2588 res = check_strx_to_uint32_all_chars(); 2969 res = check_strx_to_uint32_all_chars ();
2589 if (res != 0) 2970 if (res != 0)
2971 {
2972 if (res < 0)
2590 { 2973 {
2591 if (res < 0) 2974 fprintf (stderr,
2592 { 2975 "ERROR: test internal error in check_strx_to_uint32_all_chars().\n");
2593 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_all_chars().\n"); 2976 return 99;
2594 return 99;
2595 }
2596 strx_to_uint32_fails += res;
2597 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n");
2598 } 2977 }
2978 strx_to_uint32_fails += res;
2979 fprintf (stderr,
2980 "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n");
2981 }
2599 else if (verbose > 1) 2982 else if (verbose > 1)
2600 printf("PASSED: testcase check_strx_to_uint32_all_chars() successfully passed.\n\n"); 2983 printf (
2984 "PASSED: testcase check_strx_to_uint32_all_chars() successfully passed.\n\n");
2601 2985
2602 res = check_strx_to_uint32_overflow(); 2986 res = check_strx_to_uint32_overflow ();
2603 if (res != 0) 2987 if (res != 0)
2988 {
2989 if (res < 0)
2604 { 2990 {
2605 if (res < 0) 2991 fprintf (stderr,
2606 { 2992 "ERROR: test internal error in check_strx_to_uint32_overflow().\n");
2607 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_overflow().\n"); 2993 return 99;
2608 return 99;
2609 }
2610 strx_to_uint32_fails += res;
2611 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n");
2612 } 2994 }
2995 strx_to_uint32_fails += res;
2996 fprintf (stderr,
2997 "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n");
2998 }
2613 else if (verbose > 1) 2999 else if (verbose > 1)
2614 printf("PASSED: testcase check_strx_to_uint32_overflow() successfully passed.\n\n"); 3000 printf (
3001 "PASSED: testcase check_strx_to_uint32_overflow() successfully passed.\n\n");
2615 3002
2616 res = check_strx_to_uint32_no_val(); 3003 res = check_strx_to_uint32_no_val ();
2617 if (res != 0) 3004 if (res != 0)
3005 {
3006 if (res < 0)
2618 { 3007 {
2619 if (res < 0) 3008 fprintf (stderr,
2620 { 3009 "ERROR: test internal error in check_strx_to_uint32_no_val().\n");
2621 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_no_val().\n"); 3010 return 99;
2622 return 99;
2623 }
2624 strx_to_uint32_fails += res;
2625 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n");
2626 } 3011 }
3012 strx_to_uint32_fails += res;
3013 fprintf (stderr,
3014 "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n");
3015 }
2627 else if (verbose > 1) 3016 else if (verbose > 1)
2628 printf("PASSED: testcase check_strx_to_uint32_no_val() successfully passed.\n\n"); 3017 printf (
3018 "PASSED: testcase check_strx_to_uint32_no_val() successfully passed.\n\n");
2629 3019
2630 if (strx_to_uint32_fails) 3020 if (strx_to_uint32_fails)
2631 fprintf(stderr, "FAILED: function MHD_strx_to_uint32_() failed %d time%s.\n\n", 3021 fprintf (stderr,
2632 strx_to_uint32_fails, strx_to_uint32_fails == 1 ? "" : "s"); 3022 "FAILED: function MHD_strx_to_uint32_() failed %d time%s.\n\n",
3023 strx_to_uint32_fails, strx_to_uint32_fails == 1 ? "" : "s");
2633 else if (verbose > 0) 3024 else if (verbose > 0)
2634 printf("PASSED: function MHD_strx_to_uint32_() successfully passed all checks.\n\n"); 3025 printf (
3026 "PASSED: function MHD_strx_to_uint32_() successfully passed all checks.\n\n");
2635 3027
2636 res = check_strx_to_uint32_n_valid(); 3028 res = check_strx_to_uint32_n_valid ();
2637 if (res != 0) 3029 if (res != 0)
3030 {
3031 if (res < 0)
2638 { 3032 {
2639 if (res < 0) 3033 fprintf (stderr,
2640 { 3034 "ERROR: test internal error in check_strx_to_uint32_n_valid().\n");
2641 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_valid().\n"); 3035 return 99;
2642 return 99;
2643 }
2644 strx_to_uint32_n_fails += res;
2645 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n");
2646 } 3036 }
3037 strx_to_uint32_n_fails += res;
3038 fprintf (stderr,
3039 "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n");
3040 }
2647 else if (verbose > 1) 3041 else if (verbose > 1)
2648 printf("PASSED: testcase check_strx_to_uint32_n_valid() successfully passed.\n\n"); 3042 printf (
3043 "PASSED: testcase check_strx_to_uint32_n_valid() successfully passed.\n\n");
2649 3044
2650 res = check_strx_to_uint32_n_all_chars(); 3045 res = check_strx_to_uint32_n_all_chars ();
2651 if (res != 0) 3046 if (res != 0)
3047 {
3048 if (res < 0)
2652 { 3049 {
2653 if (res < 0) 3050 fprintf (stderr,
2654 { 3051 "ERROR: test internal error in check_strx_to_uint32_n_all_chars().\n");
2655 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_all_chars().\n"); 3052 return 99;
2656 return 99;
2657 }
2658 strx_to_uint32_n_fails += res;
2659 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n");
2660 } 3053 }
3054 strx_to_uint32_n_fails += res;
3055 fprintf (stderr,
3056 "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n");
3057 }
2661 else if (verbose > 1) 3058 else if (verbose > 1)
2662 printf("PASSED: testcase check_strx_to_uint32_n_all_chars() successfully passed.\n\n"); 3059 printf (
3060 "PASSED: testcase check_strx_to_uint32_n_all_chars() successfully passed.\n\n");
2663 3061
2664 res = check_strx_to_uint32_n_overflow(); 3062 res = check_strx_to_uint32_n_overflow ();
2665 if (res != 0) 3063 if (res != 0)
3064 {
3065 if (res < 0)
2666 { 3066 {
2667 if (res < 0) 3067 fprintf (stderr,
2668 { 3068 "ERROR: test internal error in check_strx_to_uint32_n_overflow().\n");
2669 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_overflow().\n"); 3069 return 99;
2670 return 99;
2671 }
2672 strx_to_uint32_n_fails += res;
2673 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n");
2674 } 3070 }
3071 strx_to_uint32_n_fails += res;
3072 fprintf (stderr,
3073 "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n");
3074 }
2675 else if (verbose > 1) 3075 else if (verbose > 1)
2676 printf("PASSED: testcase check_strx_to_uint32_n_overflow() successfully passed.\n\n"); 3076 printf (
3077 "PASSED: testcase check_strx_to_uint32_n_overflow() successfully passed.\n\n");
2677 3078
2678 res = check_strx_to_uint32_n_no_val(); 3079 res = check_strx_to_uint32_n_no_val ();
2679 if (res != 0) 3080 if (res != 0)
3081 {
3082 if (res < 0)
2680 { 3083 {
2681 if (res < 0) 3084 fprintf (stderr,
2682 { 3085 "ERROR: test internal error in check_strx_to_uint32_n_no_val().\n");
2683 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_no_val().\n"); 3086 return 99;
2684 return 99;
2685 }
2686 strx_to_uint32_n_fails += res;
2687 fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n");
2688 } 3087 }
3088 strx_to_uint32_n_fails += res;
3089 fprintf (stderr,
3090 "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n");
3091 }
2689 else if (verbose > 1) 3092 else if (verbose > 1)
2690 printf("PASSED: testcase check_strx_to_uint32_n_no_val() successfully passed.\n\n"); 3093 printf (
3094 "PASSED: testcase check_strx_to_uint32_n_no_val() successfully passed.\n\n");
2691 3095
2692 if (strx_to_uint32_n_fails) 3096 if (strx_to_uint32_n_fails)
2693 fprintf(stderr, "FAILED: function MHD_strx_to_uint32_n_() failed %d time%s.\n\n", 3097 fprintf (stderr,
2694 strx_to_uint32_n_fails, strx_to_uint32_n_fails == 1 ? "" : "s"); 3098 "FAILED: function MHD_strx_to_uint32_n_() failed %d time%s.\n\n",
3099 strx_to_uint32_n_fails, strx_to_uint32_n_fails == 1 ? "" : "s");
2695 else if (verbose > 0) 3100 else if (verbose > 0)
2696 printf("PASSED: function MHD_strx_to_uint32_n_() successfully passed all checks.\n\n"); 3101 printf (
3102 "PASSED: function MHD_strx_to_uint32_n_() successfully passed all checks.\n\n");
2697 3103
2698 res = check_strx_to_uint64_valid(); 3104 res = check_strx_to_uint64_valid ();
2699 if (res != 0) 3105 if (res != 0)
3106 {
3107 if (res < 0)
2700 { 3108 {
2701 if (res < 0) 3109 fprintf (stderr,
2702 { 3110 "ERROR: test internal error in check_strx_to_uint64_valid().\n");
2703 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_valid().\n"); 3111 return 99;
2704 return 99;
2705 }
2706 strx_to_uint64_fails += res;
2707 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n");
2708 } 3112 }
3113 strx_to_uint64_fails += res;
3114 fprintf (stderr,
3115 "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n");
3116 }
2709 else if (verbose > 1) 3117 else if (verbose > 1)
2710 printf("PASSED: testcase check_strx_to_uint64_valid() successfully passed.\n\n"); 3118 printf (
3119 "PASSED: testcase check_strx_to_uint64_valid() successfully passed.\n\n");
2711 3120
2712 res = check_strx_to_uint64_all_chars(); 3121 res = check_strx_to_uint64_all_chars ();
2713 if (res != 0) 3122 if (res != 0)
3123 {
3124 if (res < 0)
2714 { 3125 {
2715 if (res < 0) 3126 fprintf (stderr,
2716 { 3127 "ERROR: test internal error in check_strx_to_uint64_all_chars().\n");
2717 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_all_chars().\n"); 3128 return 99;
2718 return 99;
2719 }
2720 strx_to_uint64_fails += res;
2721 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n");
2722 } 3129 }
3130 strx_to_uint64_fails += res;
3131 fprintf (stderr,
3132 "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n");
3133 }
2723 else if (verbose > 1) 3134 else if (verbose > 1)
2724 printf("PASSED: testcase check_strx_to_uint64_all_chars() successfully passed.\n\n"); 3135 printf (
3136 "PASSED: testcase check_strx_to_uint64_all_chars() successfully passed.\n\n");
2725 3137
2726 res = check_strx_to_uint64_overflow(); 3138 res = check_strx_to_uint64_overflow ();
2727 if (res != 0) 3139 if (res != 0)
3140 {
3141 if (res < 0)
2728 { 3142 {
2729 if (res < 0) 3143 fprintf (stderr,
2730 { 3144 "ERROR: test internal error in check_strx_to_uint64_overflow().\n");
2731 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_overflow().\n"); 3145 return 99;
2732 return 99;
2733 }
2734 strx_to_uint64_fails += res;
2735 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n");
2736 } 3146 }
3147 strx_to_uint64_fails += res;
3148 fprintf (stderr,
3149 "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n");
3150 }
2737 else if (verbose > 1) 3151 else if (verbose > 1)
2738 printf("PASSED: testcase check_strx_to_uint64_overflow() successfully passed.\n\n"); 3152 printf (
3153 "PASSED: testcase check_strx_to_uint64_overflow() successfully passed.\n\n");
2739 3154
2740 res = check_strx_to_uint64_no_val(); 3155 res = check_strx_to_uint64_no_val ();
2741 if (res != 0) 3156 if (res != 0)
3157 {
3158 if (res < 0)
2742 { 3159 {
2743 if (res < 0) 3160 fprintf (stderr,
2744 { 3161 "ERROR: test internal error in check_strx_to_uint64_no_val().\n");
2745 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_no_val().\n"); 3162 return 99;
2746 return 99;
2747 }
2748 strx_to_uint64_fails += res;
2749 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n");
2750 } 3163 }
3164 strx_to_uint64_fails += res;
3165 fprintf (stderr,
3166 "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n");
3167 }
2751 else if (verbose > 1) 3168 else if (verbose > 1)
2752 printf("PASSED: testcase check_strx_to_uint64_no_val() successfully passed.\n\n"); 3169 printf (
3170 "PASSED: testcase check_strx_to_uint64_no_val() successfully passed.\n\n");
2753 3171
2754 if (strx_to_uint64_fails) 3172 if (strx_to_uint64_fails)
2755 fprintf(stderr, "FAILED: function MHD_strx_to_uint64_() failed %d time%s.\n\n", 3173 fprintf (stderr,
2756 strx_to_uint64_fails, strx_to_uint64_fails == 1 ? "" : "s"); 3174 "FAILED: function MHD_strx_to_uint64_() failed %d time%s.\n\n",
3175 strx_to_uint64_fails, strx_to_uint64_fails == 1 ? "" : "s");
2757 else if (verbose > 0) 3176 else if (verbose > 0)
2758 printf("PASSED: function MHD_strx_to_uint64_() successfully passed all checks.\n\n"); 3177 printf (
3178 "PASSED: function MHD_strx_to_uint64_() successfully passed all checks.\n\n");
2759 3179
2760 res = check_strx_to_uint64_n_valid(); 3180 res = check_strx_to_uint64_n_valid ();
2761 if (res != 0) 3181 if (res != 0)
3182 {
3183 if (res < 0)
2762 { 3184 {
2763 if (res < 0) 3185 fprintf (stderr,
2764 { 3186 "ERROR: test internal error in check_strx_to_uint64_n_valid().\n");
2765 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_valid().\n"); 3187 return 99;
2766 return 99;
2767 }
2768 strx_to_uint64_n_fails += res;
2769 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n");
2770 } 3188 }
3189 strx_to_uint64_n_fails += res;
3190 fprintf (stderr,
3191 "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n");
3192 }
2771 else if (verbose > 1) 3193 else if (verbose > 1)
2772 printf("PASSED: testcase check_strx_to_uint64_n_valid() successfully passed.\n\n"); 3194 printf (
3195 "PASSED: testcase check_strx_to_uint64_n_valid() successfully passed.\n\n");
2773 3196
2774 res = check_strx_to_uint64_n_all_chars(); 3197 res = check_strx_to_uint64_n_all_chars ();
2775 if (res != 0) 3198 if (res != 0)
3199 {
3200 if (res < 0)
2776 { 3201 {
2777 if (res < 0) 3202 fprintf (stderr,
2778 { 3203 "ERROR: test internal error in check_strx_to_uint64_n_all_chars().\n");
2779 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_all_chars().\n"); 3204 return 99;
2780 return 99;
2781 }
2782 strx_to_uint64_n_fails += res;
2783 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n");
2784 } 3205 }
3206 strx_to_uint64_n_fails += res;
3207 fprintf (stderr,
3208 "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n");
3209 }
2785 else if (verbose > 1) 3210 else if (verbose > 1)
2786 printf("PASSED: testcase check_strx_to_uint64_n_all_chars() successfully passed.\n\n"); 3211 printf (
3212 "PASSED: testcase check_strx_to_uint64_n_all_chars() successfully passed.\n\n");
2787 3213
2788 res = check_strx_to_uint64_n_overflow(); 3214 res = check_strx_to_uint64_n_overflow ();
2789 if (res != 0) 3215 if (res != 0)
3216 {
3217 if (res < 0)
2790 { 3218 {
2791 if (res < 0) 3219 fprintf (stderr,
2792 { 3220 "ERROR: test internal error in check_strx_to_uint64_n_overflow().\n");
2793 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_overflow().\n"); 3221 return 99;
2794 return 99;
2795 }
2796 strx_to_uint64_n_fails += res;
2797 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n");
2798 } 3222 }
3223 strx_to_uint64_n_fails += res;
3224 fprintf (stderr,
3225 "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n");
3226 }
2799 else if (verbose > 1) 3227 else if (verbose > 1)
2800 printf("PASSED: testcase check_strx_to_uint64_n_overflow() successfully passed.\n\n"); 3228 printf (
3229 "PASSED: testcase check_strx_to_uint64_n_overflow() successfully passed.\n\n");
2801 3230
2802 res = check_strx_to_uint64_n_no_val(); 3231 res = check_strx_to_uint64_n_no_val ();
2803 if (res != 0) 3232 if (res != 0)
3233 {
3234 if (res < 0)
2804 { 3235 {
2805 if (res < 0) 3236 fprintf (stderr,
2806 { 3237 "ERROR: test internal error in check_strx_to_uint64_n_no_val().\n");
2807 fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_no_val().\n"); 3238 return 99;
2808 return 99;
2809 }
2810 strx_to_uint64_n_fails += res;
2811 fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n");
2812 } 3239 }
3240 strx_to_uint64_n_fails += res;
3241 fprintf (stderr,
3242 "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n");
3243 }
2813 else if (verbose > 1) 3244 else if (verbose > 1)
2814 printf("PASSED: testcase check_strx_to_uint64_n_no_val() successfully passed.\n\n"); 3245 printf (
3246 "PASSED: testcase check_strx_to_uint64_n_no_val() successfully passed.\n\n");
2815 3247
2816 if (strx_to_uint64_n_fails) 3248 if (strx_to_uint64_n_fails)
2817 fprintf(stderr, "FAILED: function MHD_strx_to_uint64_n_() failed %d time%s.\n\n", 3249 fprintf (stderr,
2818 strx_to_uint64_n_fails, strx_to_uint64_n_fails == 1 ? "" : "s"); 3250 "FAILED: function MHD_strx_to_uint64_n_() failed %d time%s.\n\n",
3251 strx_to_uint64_n_fails, strx_to_uint64_n_fails == 1 ? "" : "s");
2819 else if (verbose > 0) 3252 else if (verbose > 0)
2820 printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n"); 3253 printf (
3254 "PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n");
2821 3255
2822 if (str_to_uint64_fails || str_to_uint64_n_fails || 3256 if (str_to_uint64_fails || str_to_uint64_n_fails ||
2823 strx_to_uint32_fails || strx_to_uint32_n_fails || 3257 strx_to_uint32_fails || strx_to_uint32_n_fails ||
2824 strx_to_uint64_fails || strx_to_uint64_n_fails) 3258 strx_to_uint64_fails || strx_to_uint64_n_fails)
2825 { 3259 {
2826 if (verbose > 0) 3260 if (verbose > 0)
2827 printf("At least one test failed.\n"); 3261 printf ("At least one test failed.\n");
2828 3262
2829 return 1; 3263 return 1;
2830 } 3264 }
2831 3265
2832 if (verbose > 0) 3266 if (verbose > 0)
2833 printf("All tests passed successfully.\n"); 3267 printf ("All tests passed successfully.\n");
2834 3268
2835 return 0; 3269 return 0;
2836} 3270}
2837 3271
2838 3272
2839int main(int argc, char * argv[]) 3273int main (int argc, char *argv[])
2840{ 3274{
2841 if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose") || has_param(argc, argv, "--verbose1")) 3275 if (has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose") ||
3276 has_param (argc, argv, "--verbose1"))
2842 verbose = 1; 3277 verbose = 1;
2843 if (has_param(argc, argv, "-vv") || has_param(argc, argv, "--verbose2")) 3278 if (has_param (argc, argv, "-vv") || has_param (argc, argv, "--verbose2"))
2844 verbose = 2; 3279 verbose = 2;
2845 if (has_param(argc, argv, "-vvv") || has_param(argc, argv, "--verbose3")) 3280 if (has_param (argc, argv, "-vvv") || has_param (argc, argv, "--verbose3"))
2846 verbose = 3; 3281 verbose = 3;
2847 3282
2848 if (has_in_name(argv[0], "_to_value")) 3283 if (has_in_name (argv[0], "_to_value"))
2849 return run_str_to_X_tests(); 3284 return run_str_to_X_tests ();
2850 3285
2851 return run_eq_neq_str_tests(); 3286 return run_eq_neq_str_tests ();
2852} 3287}
diff --git a/src/microhttpd/test_str_token.c b/src/microhttpd/test_str_token.c
index 15f3f406..0baca53d 100644
--- a/src/microhttpd/test_str_token.c
+++ b/src/microhttpd/test_str_token.c
@@ -29,90 +29,93 @@
29 29
30 30
31static int 31static int
32expect_found_n(const char *str, const char *token, size_t token_len) 32expect_found_n (const char *str, const char *token, size_t token_len)
33{ 33{
34 if (!MHD_str_has_token_caseless_(str, token, token_len)) 34 if (! MHD_str_has_token_caseless_ (str, token, token_len))
35 { 35 {
36 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return false\n", 36 fprintf (stderr,
37 str, token, (unsigned long) token_len); 37 "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return false\n",
38 return 1; 38 str, token, (unsigned long) token_len);
39 } 39 return 1;
40 }
40 return 0; 41 return 0;
41} 42}
42 43
43#define expect_found(s,t) expect_found_n((s),(t),MHD_STATICSTR_LEN_(t)) 44#define expect_found(s,t) expect_found_n ((s),(t),MHD_STATICSTR_LEN_ (t))
44 45
45static int 46static int
46expect_not_found_n(const char *str, const char *token, size_t token_len) 47expect_not_found_n (const char *str, const char *token, size_t token_len)
47{ 48{
48 if (MHD_str_has_token_caseless_(str, token, token_len)) 49 if (MHD_str_has_token_caseless_ (str, token, token_len))
49 { 50 {
50 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return true\n", 51 fprintf (stderr,
51 str, token, (unsigned long) token_len); 52 "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return true\n",
52 return 1; 53 str, token, (unsigned long) token_len);
53 } 54 return 1;
55 }
54 return 0; 56 return 0;
55} 57}
56 58
57#define expect_not_found(s,t) expect_not_found_n((s),(t),MHD_STATICSTR_LEN_(t)) 59#define expect_not_found(s,t) expect_not_found_n ((s),(t),MHD_STATICSTR_LEN_ ( \
60 t))
58 61
59int check_match(void) 62int check_match (void)
60{ 63{
61 int errcount = 0; 64 int errcount = 0;
62 errcount += expect_found("string", "string"); 65 errcount += expect_found ("string", "string");
63 errcount += expect_found("String", "string"); 66 errcount += expect_found ("String", "string");
64 errcount += expect_found("string", "String"); 67 errcount += expect_found ("string", "String");
65 errcount += expect_found("strinG", "String"); 68 errcount += expect_found ("strinG", "String");
66 errcount += expect_found("\t strinG", "String"); 69 errcount += expect_found ("\t strinG", "String");
67 errcount += expect_found("strinG\t ", "String"); 70 errcount += expect_found ("strinG\t ", "String");
68 errcount += expect_found(" \t tOkEn ", "toKEN"); 71 errcount += expect_found (" \t tOkEn ", "toKEN");
69 errcount += expect_found("not token\t, tOkEn ", "toKEN"); 72 errcount += expect_found ("not token\t, tOkEn ", "toKEN");
70 errcount += expect_found("not token,\t tOkEn, more token", "toKEN"); 73 errcount += expect_found ("not token,\t tOkEn, more token", "toKEN");
71 errcount += expect_found("not token,\t tOkEn\t, more token", "toKEN"); 74 errcount += expect_found ("not token,\t tOkEn\t, more token", "toKEN");
72 errcount += expect_found(",,,,,,test,,,,", "TESt"); 75 errcount += expect_found (",,,,,,test,,,,", "TESt");
73 errcount += expect_found(",,,,,\t,test,,,,", "TESt"); 76 errcount += expect_found (",,,,,\t,test,,,,", "TESt");
74 errcount += expect_found(",,,,,,test, ,,,", "TESt"); 77 errcount += expect_found (",,,,,,test, ,,,", "TESt");
75 errcount += expect_found(",,,,,, test,,,,", "TESt"); 78 errcount += expect_found (",,,,,, test,,,,", "TESt");
76 errcount += expect_found(",,,,,, test not,test,,", "TESt"); 79 errcount += expect_found (",,,,,, test not,test,,", "TESt");
77 errcount += expect_found(",,,,,, test not,,test,,", "TESt"); 80 errcount += expect_found (",,,,,, test not,,test,,", "TESt");
78 errcount += expect_found(",,,,,, test not ,test,,", "TESt"); 81 errcount += expect_found (",,,,,, test not ,test,,", "TESt");
79 errcount += expect_found(",,,,,, test", "TESt"); 82 errcount += expect_found (",,,,,, test", "TESt");
80 errcount += expect_found(",,,,,, test ", "TESt"); 83 errcount += expect_found (",,,,,, test ", "TESt");
81 errcount += expect_found("no test,,,,,, test ", "TESt"); 84 errcount += expect_found ("no test,,,,,, test ", "TESt");
82 return errcount; 85 return errcount;
83} 86}
84 87
85int check_not_match(void) 88int check_not_match (void)
86{ 89{
87 int errcount = 0; 90 int errcount = 0;
88 errcount += expect_not_found("strin", "string"); 91 errcount += expect_not_found ("strin", "string");
89 errcount += expect_not_found("Stringer", "string"); 92 errcount += expect_not_found ("Stringer", "string");
90 errcount += expect_not_found("sstring", "String"); 93 errcount += expect_not_found ("sstring", "String");
91 errcount += expect_not_found("string", "Strin"); 94 errcount += expect_not_found ("string", "Strin");
92 errcount += expect_not_found("\t( strinG", "String"); 95 errcount += expect_not_found ("\t( strinG", "String");
93 errcount += expect_not_found(")strinG\t ", "String"); 96 errcount += expect_not_found (")strinG\t ", "String");
94 errcount += expect_not_found(" \t tOkEn t ", "toKEN"); 97 errcount += expect_not_found (" \t tOkEn t ", "toKEN");
95 errcount += expect_not_found("not token\t, tOkEner ", "toKEN"); 98 errcount += expect_not_found ("not token\t, tOkEner ", "toKEN");
96 errcount += expect_not_found("not token,\t tOkEns, more token", "toKEN"); 99 errcount += expect_not_found ("not token,\t tOkEns, more token", "toKEN");
97 errcount += expect_not_found("not token,\t tOkEns\t, more token", "toKEN"); 100 errcount += expect_not_found ("not token,\t tOkEns\t, more token", "toKEN");
98 errcount += expect_not_found(",,,,,,testing,,,,", "TESt"); 101 errcount += expect_not_found (",,,,,,testing,,,,", "TESt");
99 errcount += expect_not_found(",,,,,\t,test,,,,", "TESting"); 102 errcount += expect_not_found (",,,,,\t,test,,,,", "TESting");
100 errcount += expect_not_found("tests,,,,,,quest, ,,,", "TESt"); 103 errcount += expect_not_found ("tests,,,,,,quest, ,,,", "TESt");
101 errcount += expect_not_found(",,,,,, testы,,,,", "TESt"); 104 errcount += expect_not_found (",,,,,, testы,,,,", "TESt");
102 errcount += expect_not_found(",,,,,, test not,хtest,,", "TESt"); 105 errcount += expect_not_found (",,,,,, test not,хtest,,", "TESt");
103 errcount += expect_not_found("testing,,,,,, test not,,test2,,", "TESt"); 106 errcount += expect_not_found ("testing,,,,,, test not,,test2,,", "TESt");
104 errcount += expect_not_found(",testi,,,,, test not ,test,,", "TESting"); 107 errcount += expect_not_found (",testi,,,,, test not ,test,,", "TESting");
105 errcount += expect_not_found(",,,,,,2 test", "TESt"); 108 errcount += expect_not_found (",,,,,,2 test", "TESt");
106 errcount += expect_not_found(",,,,,,test test ", "test"); 109 errcount += expect_not_found (",,,,,,test test ", "test");
107 errcount += expect_not_found("no test,,,,,, test test", "test"); 110 errcount += expect_not_found ("no test,,,,,, test test", "test");
108 return errcount; 111 return errcount;
109} 112}
110 113
111int main(int argc, char * argv[]) 114int main (int argc, char *argv[])
112{ 115{
113 int errcount = 0; 116 int errcount = 0;
114 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 117 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
115 errcount += check_match(); 118 errcount += check_match ();
116 errcount += check_not_match(); 119 errcount += check_not_match ();
117 return errcount == 0 ? 0 : 1; 120 return errcount == 0 ? 0 : 1;
118} 121}
diff --git a/src/microhttpd/tsearch.c b/src/microhttpd/tsearch.c
index fe5fcd5b..e43d758f 100644
--- a/src/microhttpd/tsearch.c
+++ b/src/microhttpd/tsearch.c
@@ -13,7 +13,7 @@
13#include <stdlib.h> 13#include <stdlib.h>
14 14
15 15
16typedef struct node 16typedef struct node
17{ 17{
18 const void *key; 18 const void *key;
19 struct node *llink; 19 struct node *llink;
@@ -24,35 +24,35 @@ typedef struct node
24/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ 24/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */
25/* find or insert datum into search tree */ 25/* find or insert datum into search tree */
26void * 26void *
27tsearch (const void *vkey, /* key to be located */ 27tsearch (const void *vkey, /* key to be located */
28 void **vrootp, /* address of tree root */ 28 void **vrootp, /* address of tree root */
29 int (*compar)(const void *, const void *)) 29 int (*compar)(const void *, const void *))
30{ 30{
31 node_t *q; 31 node_t *q;
32 node_t **rootp = (node_t **)vrootp; 32 node_t **rootp = (node_t **) vrootp;
33 33
34 if (NULL == rootp) 34 if (NULL == rootp)
35 return NULL; 35 return NULL;
36 36
37 while (*rootp != NULL) 37 while (*rootp != NULL)
38 { /* Knuth's T1: */ 38 { /* Knuth's T1: */
39 int r; 39 int r;
40 40
41 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 41 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
42 return *rootp; /* we found it! */ 42 return *rootp; /* we found it! */
43 43
44 rootp = (r < 0) ? 44 rootp = (r < 0) ?
45 &(*rootp)->llink : /* T3: follow left branch */ 45 &(*rootp)->llink : /* T3: follow left branch */
46 &(*rootp)->rlink; /* T4: follow right branch */ 46 &(*rootp)->rlink; /* T4: follow right branch */
47 } 47 }
48 48
49 q = malloc (sizeof(node_t)); /* T5: key not found */ 49 q = malloc (sizeof(node_t)); /* T5: key not found */
50 if (q) 50 if (q)
51 { /* make new node */ 51 { /* make new node */
52 *rootp = q; /* link new node to old */ 52 *rootp = q; /* link new node to old */
53 q->key = vkey; /* initialize new node */ 53 q->key = vkey; /* initialize new node */
54 q->llink = q->rlink = NULL; 54 q->llink = q->rlink = NULL;
55 } 55 }
56 return q; 56 return q;
57} 57}
58 58
@@ -61,24 +61,24 @@ tsearch (const void *vkey, /* key to be located */
61/* find a node, or return NULL */ 61/* find a node, or return NULL */
62void * 62void *
63tfind (const void *vkey, /* key to be found */ 63tfind (const void *vkey, /* key to be found */
64 void * const *vrootp, /* address of the tree root */ 64 void *const *vrootp, /* address of the tree root */
65 int (*compar)(const void *, const void *)) 65 int (*compar)(const void *, const void *))
66{ 66{
67 node_t * const *rootp = (node_t * const*)vrootp; 67 node_t *const *rootp = (node_t *const*) vrootp;
68 68
69 if (NULL == rootp) 69 if (NULL == rootp)
70 return NULL; 70 return NULL;
71 71
72 while (*rootp != NULL) 72 while (*rootp != NULL)
73 { /* T1: */ 73 { /* T1: */
74 int r; 74 int r;
75 75
76 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 76 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
77 return *rootp; /* key found */ 77 return *rootp; /* key found */
78 rootp = (r < 0) ? 78 rootp = (r < 0) ?
79 &(*rootp)->llink : /* T3: follow left branch */ 79 &(*rootp)->llink : /* T3: follow left branch */
80 &(*rootp)->rlink; /* T4: follow right branch */ 80 &(*rootp)->rlink; /* T4: follow right branch */
81 } 81 }
82 return NULL; 82 return NULL;
83} 83}
84 84
@@ -92,51 +92,51 @@ tfind (const void *vkey, /* key to be found */
92 * compar: function to carry out node comparisons 92 * compar: function to carry out node comparisons
93 */ 93 */
94void * 94void *
95tdelete (const void * __restrict vkey, 95tdelete (const void *__restrict vkey,
96 void ** __restrict vrootp, 96 void **__restrict vrootp,
97 int (*compar)(const void *, const void *)) 97 int (*compar)(const void *, const void *))
98{ 98{
99 node_t **rootp = (node_t **)vrootp; 99 node_t **rootp = (node_t **) vrootp;
100 node_t *p; 100 node_t *p;
101 node_t *q; 101 node_t *q;
102 node_t *r; 102 node_t *r;
103 int cmp; 103 int cmp;
104 104
105 if (rootp == NULL || (p = *rootp) == NULL) 105 if ((rootp == NULL)||((p = *rootp) == NULL))
106 return NULL; 106 return NULL;
107 107
108 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) 108 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0)
109 { 109 {
110 p = *rootp; 110 p = *rootp;
111 rootp = (cmp < 0) ? 111 rootp = (cmp < 0) ?
112 &(*rootp)->llink : /* follow llink branch */ 112 &(*rootp)->llink : /* follow llink branch */
113 &(*rootp)->rlink; /* follow rlink branch */ 113 &(*rootp)->rlink; /* follow rlink branch */
114 if (*rootp == NULL) 114 if (*rootp == NULL)
115 return NULL; /* key not found */ 115 return NULL; /* key not found */
116 } 116 }
117 r = (*rootp)->rlink; /* D1: */ 117 r = (*rootp)->rlink; /* D1: */
118 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ 118 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
119 { 119 {
120 q = r;
121 }
122 else if (r != NULL)
123 { /* Right link is NULL? */
124 if (r->llink == NULL)
125 { /* D2: Find successor */
126 r->llink = q;
120 q = r; 127 q = r;
121 } 128 }
122 else if (r != NULL) 129 else
123 { /* Right link is NULL? */ 130 { /* D3: Find NULL link */
124 if (r->llink == NULL) 131 for (q = r->llink; q->llink != NULL; q = r->llink)
125 { /* D2: Find successor */ 132 r = q;
126 r->llink = q; 133 r->llink = q->rlink;
127 q = r; 134 q->llink = (*rootp)->llink;
128 } 135 q->rlink = (*rootp)->rlink;
129 else
130 { /* D3: Find NULL link */
131 for (q = r->llink; q->llink != NULL; q = r->llink)
132 r = q;
133 r->llink = q->rlink;
134 q->llink = (*rootp)->llink;
135 q->rlink = (*rootp)->rlink;
136 }
137 } 136 }
138 free(*rootp); /* D4: Free node */ 137 }
139 *rootp = q; /* link parent to new node */ 138 free (*rootp); /* D4: Free node */
139 *rootp = q; /* link parent to new node */
140 return p; 140 return p;
141} 141}
142 142
diff --git a/src/microhttpd/tsearch.h b/src/microhttpd/tsearch.h
index aa186495..0cfe16a7 100644
--- a/src/microhttpd/tsearch.h
+++ b/src/microhttpd/tsearch.h
@@ -14,22 +14,22 @@ extern "C" {
14#endif /* __cplusplus */ 14#endif /* __cplusplus */
15 15
16 16
17void * 17void *
18tdelete (const void * __restrict, 18 tdelete (const void *__restrict,
19 void ** __restrict, 19 void **__restrict,
20 int (*)(const void *, const void *)); 20 int (*)(const void *, const void *));
21 21
22 22
23void * 23void *
24tfind (const void *, 24 tfind (const void *,
25 void * const *, 25 void *const *,
26 int (*)(const void *, const void *)); 26 int (*)(const void *, const void *));
27 27
28 28
29void * 29void *
30tsearch (const void *, 30 tsearch (const void *,
31 void **, 31 void **,
32 int (*)(const void *, const void *)); 32 int (*)(const void *, const void *));
33 33
34#if defined(__cplusplus) 34#if defined(__cplusplus)
35}; 35};
diff --git a/src/testcurl/curl_version_check.c b/src/testcurl/curl_version_check.c
index dff143f8..d1134f42 100644
--- a/src/testcurl/curl_version_check.c
+++ b/src/testcurl/curl_version_check.c
@@ -39,11 +39,11 @@ parse_version_number (const char **s)
39 char num[17]; 39 char num[17];
40 40
41 while (i < 16 && ((**s >= '0') & (**s <= '9'))) 41 while (i < 16 && ((**s >= '0') & (**s <= '9')))
42 { 42 {
43 num[i] = **s; 43 num[i] = **s;
44 (*s)++; 44 (*s)++;
45 i++; 45 i++;
46 } 46 }
47 47
48 num[i] = '\0'; 48 num[i] = '\0';
49 49
@@ -53,7 +53,7 @@ parse_version_number (const char **s)
53const char * 53const char *
54parse_version_string (const char *s, int *major, int *minor, int *micro) 54parse_version_string (const char *s, int *major, int *minor, int *micro)
55{ 55{
56 if (!s) 56 if (! s)
57 return NULL; 57 return NULL;
58 *major = parse_version_number (&s); 58 *major = parse_version_number (&s);
59 if (*s != '.') 59 if (*s != '.')
@@ -69,9 +69,9 @@ parse_version_string (const char *s, int *major, int *minor, int *micro)
69 69
70#ifdef HTTPS_SUPPORT 70#ifdef HTTPS_SUPPORT
71int 71int
72curl_uses_nss_ssl() 72curl_uses_nss_ssl ()
73{ 73{
74 return (strstr(curl_version(), " NSS/") != NULL) ? 0 : -1; 74 return (strstr (curl_version (), " NSS/") != NULL) ? 0 : -1;
75} 75}
76#endif /* HTTPS_SUPPORT */ 76#endif /* HTTPS_SUPPORT */
77 77
@@ -105,23 +105,25 @@ curl_check_version (const char *req_version)
105 return -1; 105 return -1;
106 curl_ver++; 106 curl_ver++;
107 /* Parse version numbers */ 107 /* Parse version numbers */
108 if ( (NULL == parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro)) || 108 if ( (NULL == parse_version_string (req_version, &rq_major, &rq_minor,
109 (NULL == parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro)) ) 109 &rq_micro)) ||
110 (NULL == parse_version_string (curl_ver, &loc_major, &loc_minor,
111 &loc_micro)) )
110 return -1; 112 return -1;
111 113
112 /* Compare version numbers. */ 114 /* Compare version numbers. */
113 if ((loc_major > rq_major 115 if (((loc_major > rq_major)
114 || (loc_major == rq_major && loc_minor > rq_minor) 116 || ((loc_major == rq_major)&&(loc_minor > rq_minor))
115 || (loc_major == rq_major && loc_minor == rq_minor 117 || ((loc_major == rq_major)&&(loc_minor == rq_minor)
116 && loc_micro > rq_micro) || (loc_major == rq_major 118 &&(loc_micro > rq_micro)) || ((loc_major == rq_major)
117 && loc_minor == rq_minor 119 &&(loc_minor == rq_minor)
118 && loc_micro == rq_micro)) == 0) 120 &&(loc_micro == rq_micro) )) == 0)
119 { 121 {
120 fprintf (stderr, 122 fprintf (stderr,
121 "Error: running curl test depends on local libcurl version > %s\n", 123 "Error: running curl test depends on local libcurl version > %s\n",
122 req_version); 124 req_version);
123 return -1; 125 return -1;
124 } 126 }
125 127
126 /* 128 /*
127 * enforce required gnutls/openssl version. 129 * enforce required gnutls/openssl version.
@@ -133,44 +135,46 @@ curl_check_version (const char *req_version)
133 return -1; 135 return -1;
134 ssl_ver++; 136 ssl_ver++;
135 if (strncmp ("GnuTLS", ssl_ver, strlen ("GNUtls")) == 0) 137 if (strncmp ("GnuTLS", ssl_ver, strlen ("GNUtls")) == 0)
136 { 138 {
137 ssl_ver = strchr (ssl_ver, '/'); 139 ssl_ver = strchr (ssl_ver, '/');
138 req_ssl_ver = MHD_REQ_CURL_GNUTLS_VERSION; 140 req_ssl_ver = MHD_REQ_CURL_GNUTLS_VERSION;
139 } 141 }
140 else if (strncmp ("OpenSSL", ssl_ver, strlen ("OpenSSL")) == 0) 142 else if (strncmp ("OpenSSL", ssl_ver, strlen ("OpenSSL")) == 0)
141 { 143 {
142 ssl_ver = strchr (ssl_ver, '/'); 144 ssl_ver = strchr (ssl_ver, '/');
143 req_ssl_ver = MHD_REQ_CURL_OPENSSL_VERSION; 145 req_ssl_ver = MHD_REQ_CURL_OPENSSL_VERSION;
144 } 146 }
145 else if (strncmp ("NSS", ssl_ver, strlen ("NSS")) == 0) 147 else if (strncmp ("NSS", ssl_ver, strlen ("NSS")) == 0)
146 { 148 {
147 ssl_ver = strchr (ssl_ver, '/'); 149 ssl_ver = strchr (ssl_ver, '/');
148 req_ssl_ver = MHD_REQ_CURL_NSS_VERSION; 150 req_ssl_ver = MHD_REQ_CURL_NSS_VERSION;
149 } 151 }
150 else 152 else
151 { 153 {
152 fprintf (stderr, "Error: unrecognized curl ssl library\n"); 154 fprintf (stderr, "Error: unrecognized curl ssl library\n");
153 return -1; 155 return -1;
154 } 156 }
155 if (ssl_ver == NULL) 157 if (ssl_ver == NULL)
156 return -1; 158 return -1;
157 ssl_ver++; 159 ssl_ver++;
158 if ( (NULL == parse_version_string (req_ssl_ver, &rq_major, &rq_minor, &rq_micro)) || 160 if ( (NULL == parse_version_string (req_ssl_ver, &rq_major, &rq_minor,
159 (NULL == parse_version_string (ssl_ver, &loc_major, &loc_minor, &loc_micro)) ) 161 &rq_micro)) ||
162 (NULL == parse_version_string (ssl_ver, &loc_major, &loc_minor,
163 &loc_micro)) )
160 return -1; 164 return -1;
161 165
162 if ((loc_major > rq_major 166 if (((loc_major > rq_major)
163 || (loc_major == rq_major && loc_minor > rq_minor) 167 || ((loc_major == rq_major)&&(loc_minor > rq_minor))
164 || (loc_major == rq_major && loc_minor == rq_minor 168 || ((loc_major == rq_major)&&(loc_minor == rq_minor)
165 && loc_micro > rq_micro) || (loc_major == rq_major 169 &&(loc_micro > rq_micro)) || ((loc_major == rq_major)
166 && loc_minor == rq_minor 170 &&(loc_minor == rq_minor)
167 && loc_micro == rq_micro)) == 0) 171 &&(loc_micro == rq_micro) )) == 0)
168 { 172 {
169 fprintf (stderr, 173 fprintf (stderr,
170 "Error: running curl test depends on local libcurl SSL version > %s\n", 174 "Error: running curl test depends on local libcurl SSL version > %s\n",
171 req_ssl_ver); 175 req_ssl_ver);
172 return -1; 176 return -1;
173 } 177 }
174#endif /* HTTPS_SUPPORT */ 178#endif /* HTTPS_SUPPORT */
175 return 0; 179 return 0;
176} 180}
diff --git a/src/testcurl/gauger.h b/src/testcurl/gauger.h
index 6698f5d5..d00839c1 100644
--- a/src/testcurl/gauger.h
+++ b/src/testcurl/gauger.h
@@ -17,64 +17,64 @@
17#include <stdio.h> 17#include <stdio.h>
18#include <sys/wait.h> 18#include <sys/wait.h>
19 19
20#define GAUGER(category, counter, value, unit)\ 20#define GAUGER(category, counter, value, unit) \
21{\ 21 { \
22 const char * __gauger_v[10]; \ 22 const char *__gauger_v[10]; \
23 char __gauger_s[32];\ 23 char __gauger_s[32]; \
24 pid_t __gauger_p;\ 24 pid_t __gauger_p; \
25 if(!(__gauger_p=fork())){\ 25 if (! (__gauger_p = fork ())) { \
26 if(!fork()){ \ 26 if (! fork ()) { \
27 sprintf(__gauger_s,"%Lf", (long double) (value));\ 27 sprintf (__gauger_s,"%Lf", (long double) (value)); \
28 __gauger_v[0] = "gauger";\ 28 __gauger_v[0] = "gauger"; \
29 __gauger_v[1] = "-n";\ 29 __gauger_v[1] = "-n"; \
30 __gauger_v[2] = counter; \ 30 __gauger_v[2] = counter; \
31 __gauger_v[3] = "-d";\ 31 __gauger_v[3] = "-d"; \
32 __gauger_v[4] = __gauger_s;\ 32 __gauger_v[4] = __gauger_s; \
33 __gauger_v[5] = "-u";\ 33 __gauger_v[5] = "-u"; \
34 __gauger_v[6] = unit; \ 34 __gauger_v[6] = unit; \
35 __gauger_v[7] = "-c";\ 35 __gauger_v[7] = "-c"; \
36 __gauger_v[8] = category; \ 36 __gauger_v[8] = category; \
37 __gauger_v[9] = (char *)NULL;\ 37 __gauger_v[9] = (char *) NULL; \
38 execvp("gauger", (char*const*) __gauger_v); \ 38 execvp ("gauger", (char*const*) __gauger_v); \
39 _exit(1);\ 39 _exit (1); \
40 }else{\ 40 }else{ \
41 _exit(0);\ 41 _exit (0); \
42 }\ 42 } \
43 }else{\ 43 }else{ \
44 waitpid(__gauger_p,NULL,0);\ 44 waitpid (__gauger_p,NULL,0); \
45 }\ 45 } \
46} 46 }
47 47
48#define GAUGER_ID(category, counter, value, unit, id)\ 48#define GAUGER_ID(category, counter, value, unit, id) \
49{\ 49 { \
50 char* __gauger_v[12];\ 50 char*__gauger_v[12]; \
51 char __gauger_s[32];\ 51 char __gauger_s[32]; \
52 pid_t __gauger_p;\ 52 pid_t __gauger_p; \
53 if(!(__gauger_p=fork())){\ 53 if (! (__gauger_p = fork ())) { \
54 if(!fork()){\ 54 if (! fork ()) { \
55 sprintf(__gauger_s,"%Lf", (long double) (value));\ 55 sprintf (__gauger_s,"%Lf", (long double) (value)); \
56 __gauger_v[0] = "gauger";\ 56 __gauger_v[0] = "gauger"; \
57 __gauger_v[1] = "-n";\ 57 __gauger_v[1] = "-n"; \
58 __gauger_v[2] = counter;\ 58 __gauger_v[2] = counter; \
59 __gauger_v[3] = "-d";\ 59 __gauger_v[3] = "-d"; \
60 __gauger_v[4] = __gauger_s;\ 60 __gauger_v[4] = __gauger_s; \
61 __gauger_v[5] = "-u";\ 61 __gauger_v[5] = "-u"; \
62 __gauger_v[6] = unit;\ 62 __gauger_v[6] = unit; \
63 __gauger_v[7] = "-i";\ 63 __gauger_v[7] = "-i"; \
64 __gauger_v[8] = id;\ 64 __gauger_v[8] = id; \
65 __gauger_v[9] = "-c";\ 65 __gauger_v[9] = "-c"; \
66 __gauger_v[10] = category;\ 66 __gauger_v[10] = category; \
67 __gauger_v[11] = (char *)NULL;\ 67 __gauger_v[11] = (char *) NULL; \
68 execvp("gauger",__gauger_v);\ 68 execvp ("gauger",__gauger_v); \
69 perror("gauger");\ 69 perror ("gauger"); \
70 _exit(1);\ 70 _exit (1); \
71 }else{\ 71 }else{ \
72 _exit(0);\ 72 _exit (0); \
73 }\ 73 } \
74 }else{\ 74 }else{ \
75 waitpid(__gauger_p,NULL,0);\ 75 waitpid (__gauger_p,NULL,0); \
76 }\ 76 } \
77} 77 }
78 78
79#else 79#else
80 80
diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c
index f53a70ec..41026896 100644
--- a/src/testcurl/https/test_empty_response.c
+++ b/src/testcurl/https/test_empty_response.c
@@ -49,11 +49,11 @@ ahc_echo (void *cls,
49{ 49{
50 struct MHD_Response *response; 50 struct MHD_Response *response;
51 int ret; 51 int ret;
52 (void)cls;(void)url;(void)method;(void)version; /* Unused. Silent compiler warning. */ 52 (void) cls; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */
53 (void)upload_data;(void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 53 (void) upload_data; (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
54 54
55 response = MHD_create_response_from_buffer (0, NULL, 55 response = MHD_create_response_from_buffer (0, NULL,
56 MHD_RESPMEM_PERSISTENT); 56 MHD_RESPMEM_PERSISTENT);
57 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 57 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
58 MHD_destroy_response (response); 58 MHD_destroy_response (response);
59 return ret; 59 return ret;
@@ -88,31 +88,34 @@ testInternalSelectGet ()
88 cbc.buf = buf; 88 cbc.buf = buf;
89 cbc.size = 2048; 89 cbc.size = 2048;
90 cbc.pos = 0; 90 cbc.pos = 0;
91 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS | MHD_USE_INTERNAL_POLLING_THREAD, 91 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS
92 | MHD_USE_INTERNAL_POLLING_THREAD,
92 port, NULL, NULL, &ahc_echo, "GET", 93 port, NULL, NULL, &ahc_echo, "GET",
93 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 94 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
94 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 95 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
95 MHD_OPTION_END); 96 MHD_OPTION_END);
96 if (d == NULL) 97 if (d == NULL)
97 return 256; 98 return 256;
98 99
99 if (0 == port) 100 if (0 == port)
101 {
102 const union MHD_DaemonInfo *dinfo;
103 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
104 if ((NULL == dinfo) ||(0 == dinfo->port) )
100 { 105 {
101 const union MHD_DaemonInfo *dinfo; 106 MHD_stop_daemon (d); return 32;
102 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
103 if (NULL == dinfo || 0 == dinfo->port)
104 { MHD_stop_daemon (d); return 32; }
105 port = (int)dinfo->port;
106 } 107 }
108 port = (int) dinfo->port;
109 }
107 char *aes256_sha = "AES256-SHA"; 110 char *aes256_sha = "AES256-SHA";
108 if (curl_uses_nss_ssl() == 0) 111 if (curl_uses_nss_ssl () == 0)
109 { 112 {
110 aes256_sha = "rsa_aes_256_sha"; 113 aes256_sha = "rsa_aes_256_sha";
111 } 114 }
112 115
113 c = curl_easy_init (); 116 c = curl_easy_init ();
114 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world"); 117 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world");
115 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 118 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
116 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 119 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
117 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 120 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
118 /* TLS options */ 121 /* TLS options */
@@ -135,80 +138,83 @@ testInternalSelectGet ()
135 138
136 multi = curl_multi_init (); 139 multi = curl_multi_init ();
137 if (multi == NULL) 140 if (multi == NULL)
138 { 141 {
139 curl_easy_cleanup (c); 142 curl_easy_cleanup (c);
140 MHD_stop_daemon (d); 143 MHD_stop_daemon (d);
141 return 512; 144 return 512;
142 } 145 }
143 mret = curl_multi_add_handle (multi, c); 146 mret = curl_multi_add_handle (multi, c);
144 if (mret != CURLM_OK) 147 if (mret != CURLM_OK)
148 {
149 curl_multi_cleanup (multi);
150 curl_easy_cleanup (c);
151 MHD_stop_daemon (d);
152 return 1024;
153 }
154 start = time (NULL);
155 while ((time (NULL) - start < 5) && (multi != NULL))
156 {
157 maxposixs = -1;
158 FD_ZERO (&rs);
159 FD_ZERO (&ws);
160 FD_ZERO (&es);
161 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
162 if (mret != CURLM_OK)
145 { 163 {
164 curl_multi_remove_handle (multi, c);
146 curl_multi_cleanup (multi); 165 curl_multi_cleanup (multi);
147 curl_easy_cleanup (c); 166 curl_easy_cleanup (c);
148 MHD_stop_daemon (d); 167 MHD_stop_daemon (d);
149 return 1024; 168 return 2048;
150 } 169 }
151 start = time (NULL); 170 tv.tv_sec = 0;
152 while ((time (NULL) - start < 5) && (multi != NULL)) 171 tv.tv_usec = 1000;
172 if (-1 != maxposixs)
153 { 173 {
154 maxposixs = -1; 174 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
155 FD_ZERO (&rs); 175 {
156 FD_ZERO (&ws);
157 FD_ZERO (&es);
158 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
159 if (mret != CURLM_OK)
160 {
161 curl_multi_remove_handle (multi, c);
162 curl_multi_cleanup (multi);
163 curl_easy_cleanup (c);
164 MHD_stop_daemon (d);
165 return 2048;
166 }
167 tv.tv_sec = 0;
168 tv.tv_usec = 1000;
169 if (-1 != maxposixs)
170 {
171 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
172 {
173#ifdef MHD_POSIX_SOCKETS 176#ifdef MHD_POSIX_SOCKETS
174 if (EINTR != errno) 177 if (EINTR != errno)
175 abort (); 178 abort ();
176#else 179#else
177 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 180 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
178 abort (); 181 ws.
179 Sleep (1000); 182 fd_count)
183 ||(0 != es.fd_count) )
184 abort ();
185 Sleep (1000);
180#endif 186#endif
181 } 187 }
182 }
183 else
184 (void)sleep (1);
185 curl_multi_perform (multi, &running);
186 if (running == 0)
187 {
188 msg = curl_multi_info_read (multi, &running);
189 if (msg == NULL)
190 break;
191 if (msg->msg == CURLMSG_DONE)
192 {
193 if (msg->data.result != CURLE_OK)
194 printf ("%s failed at %s:%d: `%s'\n",
195 "curl_multi_perform",
196 __FILE__,
197 __LINE__, curl_easy_strerror (msg->data.result));
198 curl_multi_remove_handle (multi, c);
199 curl_multi_cleanup (multi);
200 curl_easy_cleanup (c);
201 c = NULL;
202 multi = NULL;
203 }
204 }
205 } 188 }
206 if (multi != NULL) 189 else
190 (void) sleep (1);
191 curl_multi_perform (multi, &running);
192 if (running == 0)
207 { 193 {
208 curl_multi_remove_handle (multi, c); 194 msg = curl_multi_info_read (multi, &running);
209 curl_easy_cleanup (c); 195 if (msg == NULL)
210 curl_multi_cleanup (multi); 196 break;
197 if (msg->msg == CURLMSG_DONE)
198 {
199 if (msg->data.result != CURLE_OK)
200 printf ("%s failed at %s:%d: `%s'\n",
201 "curl_multi_perform",
202 __FILE__,
203 __LINE__, curl_easy_strerror (msg->data.result));
204 curl_multi_remove_handle (multi, c);
205 curl_multi_cleanup (multi);
206 curl_easy_cleanup (c);
207 c = NULL;
208 multi = NULL;
209 }
211 } 210 }
211 }
212 if (multi != NULL)
213 {
214 curl_multi_remove_handle (multi, c);
215 curl_easy_cleanup (c);
216 curl_multi_cleanup (multi);
217 }
212 MHD_stop_daemon (d); 218 MHD_stop_daemon (d);
213 if (cbc.pos != 0) 219 if (cbc.pos != 0)
214 return 8192; 220 return 8192;
@@ -220,16 +226,16 @@ int
220main (int argc, char *const *argv) 226main (int argc, char *const *argv)
221{ 227{
222 unsigned int errorCount = 0; 228 unsigned int errorCount = 0;
223 (void)argc; /* Unused. Silent compiler warning. */ 229 (void) argc; /* Unused. Silent compiler warning. */
224 230
225 if (!testsuite_curl_global_init ()) 231 if (! testsuite_curl_global_init ())
226 return 99; 232 return 99;
227 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 233 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
228 { 234 {
229 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 235 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
230 curl_global_cleanup (); 236 curl_global_cleanup ();
231 return 77; 237 return 77;
232 } 238 }
233 if (0 != (errorCount = testInternalSelectGet ())) 239 if (0 != (errorCount = testInternalSelectGet ()))
234 fprintf (stderr, "Failed test: %s, error: %u.\n", argv[0], errorCount); 240 fprintf (stderr, "Failed test: %s, error: %u.\n", argv[0], errorCount);
235 curl_global_cleanup (); 241 curl_global_cleanup ();
diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c
index 61c25643..17248bf7 100644
--- a/src/testcurl/https/test_https_get.c
+++ b/src/testcurl/https/test_https_get.c
@@ -39,9 +39,9 @@ extern const char srv_signed_key_pem[];
39 39
40/* perform a HTTP GET request via SSL/TLS */ 40/* perform a HTTP GET request via SSL/TLS */
41static int 41static int
42test_secure_get (FILE * test_fd, 42test_secure_get (FILE *test_fd,
43 const char *cipher_suite, 43 const char *cipher_suite,
44 int proto_version) 44 int proto_version)
45{ 45{
46 int ret; 46 int ret;
47 struct MHD_Daemon *d; 47 struct MHD_Daemon *d;
@@ -52,26 +52,29 @@ test_secure_get (FILE * test_fd,
52 else 52 else
53 port = 3041; 53 port = 3041;
54 54
55 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 55 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
56 MHD_USE_ERROR_LOG, port, 56 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
57 | MHD_USE_ERROR_LOG, port,
57 NULL, NULL, &http_ahc, NULL, 58 NULL, NULL, &http_ahc, NULL,
58 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 59 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
59 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 60 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
60 MHD_OPTION_END); 61 MHD_OPTION_END);
61 62
62 if (d == NULL) 63 if (d == NULL)
63 { 64 {
64 fprintf (stderr, MHD_E_SERVER_INIT); 65 fprintf (stderr, MHD_E_SERVER_INIT);
65 return -1; 66 return -1;
66 } 67 }
67 if (0 == port) 68 if (0 == port)
69 {
70 const union MHD_DaemonInfo *dinfo;
71 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
72 if ((NULL == dinfo) ||(0 == dinfo->port) )
68 { 73 {
69 const union MHD_DaemonInfo *dinfo; 74 MHD_stop_daemon (d); return -1;
70 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
71 if (NULL == dinfo || 0 == dinfo->port)
72 { MHD_stop_daemon (d); return -1; }
73 port = (int)dinfo->port;
74 } 75 }
76 port = (int) dinfo->port;
77 }
75 78
76 ret = test_https_transfer (test_fd, port, cipher_suite, proto_version); 79 ret = test_https_transfer (test_fd, port, cipher_suite, proto_version);
77 80
@@ -85,7 +88,7 @@ main (int argc, char *const *argv)
85{ 88{
86 unsigned int errorCount = 0; 89 unsigned int errorCount = 0;
87 const char *aes256_sha_tlsv1 = "AES256-SHA"; 90 const char *aes256_sha_tlsv1 = "AES256-SHA";
88 (void)argc; /* Unused. Silent compiler warning. */ 91 (void) argc; /* Unused. Silent compiler warning. */
89 92
90#ifdef MHD_HTTPS_REQUIRE_GRYPT 93#ifdef MHD_HTTPS_REQUIRE_GRYPT
91 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 94 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -93,19 +96,19 @@ main (int argc, char *const *argv)
93 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 96 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
94#endif 97#endif
95#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 98#endif /* MHD_HTTPS_REQUIRE_GRYPT */
96 if (!testsuite_curl_global_init ()) 99 if (! testsuite_curl_global_init ())
97 return 99; 100 return 99;
98 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 101 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
99 { 102 {
100 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 103 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
101 curl_global_cleanup (); 104 curl_global_cleanup ();
102 return 77; 105 return 77;
103 } 106 }
104 107
105 if (curl_uses_nss_ssl() == 0) 108 if (curl_uses_nss_ssl () == 0)
106 { 109 {
107 aes256_sha_tlsv1 = "rsa_aes_256_sha"; 110 aes256_sha_tlsv1 = "rsa_aes_256_sha";
108 } 111 }
109 112
110 errorCount += 113 errorCount +=
111 test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); 114 test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1);
diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c
index 27c23173..e4040874 100644
--- a/src/testcurl/https/test_https_get_parallel.c
+++ b/src/testcurl/https/test_https_get_parallel.c
@@ -36,10 +36,10 @@
36#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 36#endif /* MHD_HTTPS_REQUIRE_GRYPT */
37#include "tls_test_common.h" 37#include "tls_test_common.h"
38 38
39#if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 39#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 4
40#undef CPU_COUNT 40#undef CPU_COUNT
41#endif 41#endif
42#if !defined(CPU_COUNT) 42#if ! defined(CPU_COUNT)
43#define CPU_COUNT 4 43#define CPU_COUNT 4
44#endif 44#endif
45 45
@@ -83,8 +83,8 @@ test_single_client (void *cls, int port, const char *cipher_suite,
83{ 83{
84 void *client_thread_ret; 84 void *client_thread_ret;
85 struct https_test_data client_args = 85 struct https_test_data client_args =
86 { NULL, port, cipher_suite, curl_proto_version }; 86 { NULL, port, cipher_suite, curl_proto_version };
87 (void)cls; /* Unused. Silent compiler warning. */ 87 (void) cls; /* Unused. Silent compiler warning. */
88 88
89 client_thread_ret = https_transfer_thread_adapter (&client_args); 89 client_thread_ret = https_transfer_thread_adapter (&client_args);
90 if (client_thread_ret != NULL) 90 if (client_thread_ret != NULL)
@@ -101,7 +101,7 @@ test_single_client (void *cls, int port, const char *cipher_suite,
101 * TODO : make client_count a parameter - numver of curl client threads to spawn 101 * TODO : make client_count a parameter - numver of curl client threads to spawn
102 */ 102 */
103static int 103static int
104test_parallel_clients (void * cls, int port, const char *cipher_suite, 104test_parallel_clients (void *cls, int port, const char *cipher_suite,
105 int curl_proto_version) 105 int curl_proto_version)
106{ 106{
107 int i; 107 int i;
@@ -109,26 +109,26 @@ test_parallel_clients (void * cls, int port, const char *cipher_suite,
109 void *client_thread_ret; 109 void *client_thread_ret;
110 pthread_t client_arr[client_count]; 110 pthread_t client_arr[client_count];
111 struct https_test_data client_args = 111 struct https_test_data client_args =
112 { NULL, port, cipher_suite, curl_proto_version }; 112 { NULL, port, cipher_suite, curl_proto_version };
113 (void)cls; /* Unused. Silent compiler warning. */ 113 (void) cls; /* Unused. Silent compiler warning. */
114 114
115 for (i = 0; i < client_count; ++i) 115 for (i = 0; i < client_count; ++i)
116 {
117 if (pthread_create (&client_arr[i], NULL,
118 &https_transfer_thread_adapter, &client_args) != 0)
116 { 119 {
117 if (pthread_create (&client_arr[i], NULL, 120 fprintf (stderr, "Error: failed to spawn test client threads.\n");
118 &https_transfer_thread_adapter, &client_args) != 0) 121 return -1;
119 {
120 fprintf (stderr, "Error: failed to spawn test client threads.\n");
121 return -1;
122 }
123 } 122 }
123 }
124 124
125 /* check all client requests fulfilled correctly */ 125 /* check all client requests fulfilled correctly */
126 for (i = 0; i < client_count; ++i) 126 for (i = 0; i < client_count; ++i)
127 { 127 {
128 if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || 128 if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
129 (client_thread_ret != NULL)) 129 (client_thread_ret != NULL))
130 return -1; 130 return -1;
131 } 131 }
132 132
133 return 0; 133 return 0;
134} 134}
@@ -136,11 +136,11 @@ test_parallel_clients (void * cls, int port, const char *cipher_suite,
136 136
137int 137int
138main (int argc, char *const *argv) 138main (int argc, char *const *argv)
139{ 139{
140 unsigned int errorCount = 0; 140 unsigned int errorCount = 0;
141 const char *aes256_sha = "AES256-SHA"; 141 const char *aes256_sha = "AES256-SHA";
142 int port; 142 int port;
143 (void)argc; /* Unused. Silent compiler warning. */ 143 (void) argc; /* Unused. Silent compiler warning. */
144 144
145 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 145 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
146 port = 0; 146 port = 0;
@@ -150,21 +150,23 @@ main (int argc, char *const *argv)
150 /* initialize random seed used by curl clients */ 150 /* initialize random seed used by curl clients */
151 unsigned int iseed = (unsigned int) time (NULL); 151 unsigned int iseed = (unsigned int) time (NULL);
152 srand (iseed); 152 srand (iseed);
153 if (!testsuite_curl_global_init ()) 153 if (! testsuite_curl_global_init ())
154 return 99; 154 return 99;
155 155
156 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 156 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
157 { 157 {
158 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 158 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
159 return 77; 159 return 77;
160 } 160 }
161 if (curl_uses_nss_ssl() == 0) 161 if (curl_uses_nss_ssl () == 0)
162 aes256_sha = "rsa_aes_256_sha"; 162 aes256_sha = "rsa_aes_256_sha";
163#ifdef EPOLL_SUPPORT 163#ifdef EPOLL_SUPPORT
164 errorCount += 164 errorCount +=
165 test_wrap ("single threaded daemon, single client, epoll", &test_single_client, 165 test_wrap ("single threaded daemon, single client, epoll",
166 &test_single_client,
166 NULL, port, 167 NULL, port,
167 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, 168 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
169 | MHD_USE_ERROR_LOG | MHD_USE_EPOLL,
168 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 170 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
169 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 171 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
170 srv_self_signed_cert_pem, MHD_OPTION_END); 172 srv_self_signed_cert_pem, MHD_OPTION_END);
@@ -172,7 +174,8 @@ main (int argc, char *const *argv)
172 errorCount += 174 errorCount +=
173 test_wrap ("single threaded daemon, single client", &test_single_client, 175 test_wrap ("single threaded daemon, single client", &test_single_client,
174 NULL, port, 176 NULL, port,
175 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, 177 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
178 | MHD_USE_ERROR_LOG,
176 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 179 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
177 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 180 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
178 srv_self_signed_cert_pem, MHD_OPTION_END); 181 srv_self_signed_cert_pem, MHD_OPTION_END);
@@ -180,7 +183,8 @@ main (int argc, char *const *argv)
180 errorCount += 183 errorCount +=
181 test_wrap ("single threaded daemon, parallel clients, epoll", 184 test_wrap ("single threaded daemon, parallel clients, epoll",
182 &test_parallel_clients, NULL, port, 185 &test_parallel_clients, NULL, port,
183 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, 186 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
187 | MHD_USE_ERROR_LOG | MHD_USE_EPOLL,
184 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 188 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
185 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 189 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
186 srv_self_signed_cert_pem, MHD_OPTION_END); 190 srv_self_signed_cert_pem, MHD_OPTION_END);
@@ -188,7 +192,8 @@ main (int argc, char *const *argv)
188 errorCount += 192 errorCount +=
189 test_wrap ("single threaded daemon, parallel clients", 193 test_wrap ("single threaded daemon, parallel clients",
190 &test_parallel_clients, NULL, port, 194 &test_parallel_clients, NULL, port,
191 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, 195 MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
196 | MHD_USE_ERROR_LOG,
192 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 197 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
193 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 198 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
194 srv_self_signed_cert_pem, MHD_OPTION_END); 199 srv_self_signed_cert_pem, MHD_OPTION_END);
diff --git a/src/testcurl/https/test_https_get_parallel_threads.c b/src/testcurl/https/test_https_get_parallel_threads.c
index c9fc8ffc..8ca976c2 100644
--- a/src/testcurl/https/test_https_get_parallel_threads.c
+++ b/src/testcurl/https/test_https_get_parallel_threads.c
@@ -38,10 +38,10 @@
38#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 38#endif /* MHD_HTTPS_REQUIRE_GRYPT */
39#include "tls_test_common.h" 39#include "tls_test_common.h"
40 40
41#if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 41#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 4
42#undef CPU_COUNT 42#undef CPU_COUNT
43#endif 43#endif
44#if !defined(CPU_COUNT) 44#if ! defined(CPU_COUNT)
45#define CPU_COUNT 4 45#define CPU_COUNT 4
46#endif 46#endif
47 47
@@ -83,8 +83,8 @@ test_single_client (void *cls, int port, const char *cipher_suite,
83{ 83{
84 void *client_thread_ret; 84 void *client_thread_ret;
85 struct https_test_data client_args = 85 struct https_test_data client_args =
86 { NULL, port, cipher_suite, curl_proto_version }; 86 { NULL, port, cipher_suite, curl_proto_version };
87 (void)cls; /* Unused. Silent compiler warning. */ 87 (void) cls; /* Unused. Silent compiler warning. */
88 88
89 client_thread_ret = https_transfer_thread_adapter (&client_args); 89 client_thread_ret = https_transfer_thread_adapter (&client_args);
90 if (client_thread_ret != NULL) 90 if (client_thread_ret != NULL)
@@ -109,27 +109,27 @@ test_parallel_clients (void *cls, int port, const char *cipher_suite,
109 void *client_thread_ret; 109 void *client_thread_ret;
110 pthread_t client_arr[client_count]; 110 pthread_t client_arr[client_count];
111 struct https_test_data client_args = 111 struct https_test_data client_args =
112 { NULL, port, cipher_suite, curl_proto_version }; 112 { NULL, port, cipher_suite, curl_proto_version };
113 (void)cls; /* Unused. Silent compiler warning. */ 113 (void) cls; /* Unused. Silent compiler warning. */
114 114
115 for (i = 0; i < client_count; ++i) 115 for (i = 0; i < client_count; ++i)
116 {
117 if (pthread_create (&client_arr[i], NULL,
118 &https_transfer_thread_adapter, &client_args) != 0)
116 { 119 {
117 if (pthread_create (&client_arr[i], NULL, 120 fprintf (stderr, "Error: failed to spawn test client threads.\n");
118 &https_transfer_thread_adapter, &client_args) != 0)
119 {
120 fprintf (stderr, "Error: failed to spawn test client threads.\n");
121 121
122 return -1; 122 return -1;
123 }
124 } 123 }
124 }
125 125
126 /* check all client requests fulfilled correctly */ 126 /* check all client requests fulfilled correctly */
127 for (i = 0; i < client_count; ++i) 127 for (i = 0; i < client_count; ++i)
128 { 128 {
129 if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || 129 if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
130 (client_thread_ret != NULL)) 130 (client_thread_ret != NULL))
131 return -1; 131 return -1;
132 } 132 }
133 133
134 return 0; 134 return 0;
135} 135}
@@ -141,7 +141,7 @@ main (int argc, char *const *argv)
141 unsigned int errorCount = 0; 141 unsigned int errorCount = 0;
142 const char *ssl_version; 142 const char *ssl_version;
143 int port; 143 int port;
144 (void)argc; /* Unused. Silent compiler warning. */ 144 (void) argc; /* Unused. Silent compiler warning. */
145 145
146 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 146 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
147 port = 0; 147 port = 0;
@@ -157,32 +157,33 @@ main (int argc, char *const *argv)
157#endif 157#endif
158#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 158#endif /* MHD_HTTPS_REQUIRE_GRYPT */
159 srand (iseed); 159 srand (iseed);
160 if (!testsuite_curl_global_init ()) 160 if (! testsuite_curl_global_init ())
161 return 99; 161 return 99;
162 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; 162 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version;
163 if (NULL == ssl_version) 163 if (NULL == ssl_version)
164 { 164 {
165 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 165 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
166 curl_global_cleanup (); 166 curl_global_cleanup ();
167 return 77; 167 return 77;
168 } 168 }
169 if (0 != strncmp (ssl_version, "GnuTLS", 6)) 169 if (0 != strncmp (ssl_version, "GnuTLS", 6))
170 { 170 {
171 fprintf (stderr, "This test can be run only with libcurl-gnutls.\n"); 171 fprintf (stderr, "This test can be run only with libcurl-gnutls.\n");
172 curl_global_cleanup (); 172 curl_global_cleanup ();
173 return 77; 173 return 77;
174 } 174 }
175 175
176 char *aes256_sha = "AES256-SHA"; 176 char *aes256_sha = "AES256-SHA";
177 if (curl_uses_nss_ssl() == 0) 177 if (curl_uses_nss_ssl () == 0)
178 { 178 {
179 aes256_sha = "rsa_aes_256_sha"; 179 aes256_sha = "rsa_aes_256_sha";
180 } 180 }
181 181
182 errorCount += 182 errorCount +=
183 test_wrap ("multi threaded daemon, single client", &test_single_client, 183 test_wrap ("multi threaded daemon, single client", &test_single_client,
184 NULL, port, 184 NULL, port,
185 MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 185 MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION
186 | MHD_USE_INTERNAL_POLLING_THREAD,
186 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 187 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
187 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 188 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
188 srv_self_signed_cert_pem, MHD_OPTION_END); 189 srv_self_signed_cert_pem, MHD_OPTION_END);
@@ -190,7 +191,8 @@ main (int argc, char *const *argv)
190 errorCount += 191 errorCount +=
191 test_wrap ("multi threaded daemon, parallel client", 192 test_wrap ("multi threaded daemon, parallel client",
192 &test_parallel_clients, NULL, port, 193 &test_parallel_clients, NULL, port,
193 MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 194 MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION
195 | MHD_USE_INTERNAL_POLLING_THREAD,
194 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, 196 aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
195 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, 197 srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
196 srv_self_signed_cert_pem, MHD_OPTION_END); 198 srv_self_signed_cert_pem, MHD_OPTION_END);
diff --git a/src/testcurl/https/test_https_get_select.c b/src/testcurl/https/test_https_get_select.c
index 94b4a051..ce74c1d7 100644
--- a/src/testcurl/https/test_https_get_select.c
+++ b/src/testcurl/https/test_https_get_select.c
@@ -52,19 +52,19 @@ ahc_echo (void *cls,
52 const char *me = cls; 52 const char *me = cls;
53 struct MHD_Response *response; 53 struct MHD_Response *response;
54 int ret; 54 int ret;
55 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 55 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
56 56
57 if (0 != strcmp (me, method)) 57 if (0 != strcmp (me, method))
58 return MHD_NO; /* unexpected method */ 58 return MHD_NO; /* unexpected method */
59 if (&ptr != *unused) 59 if (&ptr != *unused)
60 { 60 {
61 *unused = &ptr; 61 *unused = &ptr;
62 return MHD_YES; 62 return MHD_YES;
63 } 63 }
64 *unused = NULL; 64 *unused = NULL;
65 response = MHD_create_response_from_buffer (strlen (url), 65 response = MHD_create_response_from_buffer (strlen (url),
66 (void *) url, 66 (void *) url,
67 MHD_RESPMEM_MUST_COPY); 67 MHD_RESPMEM_MUST_COPY);
68 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 68 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
69 MHD_destroy_response (response); 69 MHD_destroy_response (response);
70 if (ret == MHD_NO) 70 if (ret == MHD_NO)
@@ -111,24 +111,26 @@ testExternalGet (int flags)
111 port, NULL, NULL, &ahc_echo, "GET", 111 port, NULL, NULL, &ahc_echo, "GET",
112 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 112 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
113 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 113 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
114 MHD_OPTION_END); 114 MHD_OPTION_END);
115 if (d == NULL) 115 if (d == NULL)
116 return 256; 116 return 256;
117 if (0 == port) 117 if (0 == port)
118 {
119 const union MHD_DaemonInfo *dinfo;
120 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
121 if ((NULL == dinfo) ||(0 == dinfo->port) )
118 { 122 {
119 const union MHD_DaemonInfo *dinfo; 123 MHD_stop_daemon (d); return 32;
120 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
121 if (NULL == dinfo || 0 == dinfo->port)
122 { MHD_stop_daemon (d); return 32; }
123 port = (int)dinfo->port;
124 } 124 }
125 port = (int) dinfo->port;
126 }
125 127
126 if (curl_uses_nss_ssl() == 0) 128 if (curl_uses_nss_ssl () == 0)
127 aes256_sha = "rsa_aes_256_sha"; 129 aes256_sha = "rsa_aes_256_sha";
128 130
129 c = curl_easy_init (); 131 c = curl_easy_init ();
130 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world"); 132 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world");
131 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 133 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
132 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 134 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
133 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 135 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
134 /* TLS options */ 136 /* TLS options */
@@ -151,90 +153,93 @@ testExternalGet (int flags)
151 153
152 multi = curl_multi_init (); 154 multi = curl_multi_init ();
153 if (multi == NULL) 155 if (multi == NULL)
156 {
157 curl_easy_cleanup (c);
158 MHD_stop_daemon (d);
159 return 512;
160 }
161 mret = curl_multi_add_handle (multi, c);
162 if (mret != CURLM_OK)
163 {
164 curl_multi_cleanup (multi);
165 curl_easy_cleanup (c);
166 MHD_stop_daemon (d);
167 return 1024;
168 }
169 start = time (NULL);
170 while ((time (NULL) - start < 5) && (multi != NULL))
171 {
172 maxsock = MHD_INVALID_SOCKET;
173 maxposixs = -1;
174 FD_ZERO (&rs);
175 FD_ZERO (&ws);
176 FD_ZERO (&es);
177 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
178 if (mret != CURLM_OK)
154 { 179 {
180 curl_multi_remove_handle (multi, c);
181 curl_multi_cleanup (multi);
155 curl_easy_cleanup (c); 182 curl_easy_cleanup (c);
156 MHD_stop_daemon (d); 183 MHD_stop_daemon (d);
157 return 512; 184 return 2048;
158 } 185 }
159 mret = curl_multi_add_handle (multi, c); 186 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
160 if (mret != CURLM_OK)
161 { 187 {
188 curl_multi_remove_handle (multi, c);
162 curl_multi_cleanup (multi); 189 curl_multi_cleanup (multi);
163 curl_easy_cleanup (c); 190 curl_easy_cleanup (c);
164 MHD_stop_daemon (d); 191 MHD_stop_daemon (d);
165 return 1024; 192 return 4096;
166 } 193 }
167 start = time (NULL); 194 tv.tv_sec = 0;
168 while ((time (NULL) - start < 5) && (multi != NULL)) 195 tv.tv_usec = 1000;
196 if (-1 != maxposixs)
169 { 197 {
170 maxsock = MHD_INVALID_SOCKET; 198 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
171 maxposixs = -1; 199 {
172 FD_ZERO (&rs);
173 FD_ZERO (&ws);
174 FD_ZERO (&es);
175 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
176 if (mret != CURLM_OK)
177 {
178 curl_multi_remove_handle (multi, c);
179 curl_multi_cleanup (multi);
180 curl_easy_cleanup (c);
181 MHD_stop_daemon (d);
182 return 2048;
183 }
184 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
185 {
186 curl_multi_remove_handle (multi, c);
187 curl_multi_cleanup (multi);
188 curl_easy_cleanup (c);
189 MHD_stop_daemon (d);
190 return 4096;
191 }
192 tv.tv_sec = 0;
193 tv.tv_usec = 1000;
194 if (-1 != maxposixs)
195 {
196 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
197 {
198#ifdef MHD_POSIX_SOCKETS 200#ifdef MHD_POSIX_SOCKETS
199 if (EINTR != errno) 201 if (EINTR != errno)
200 abort (); 202 abort ();
201#else 203#else
202 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 204 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
203 abort (); 205 ws.
204 Sleep (1000); 206 fd_count)
207 ||(0 != es.fd_count) )
208 abort ();
209 Sleep (1000);
205#endif 210#endif
206 } 211 }
207 }
208 else
209 (void)sleep (1);
210 curl_multi_perform (multi, &running);
211 if (running == 0)
212 {
213 msg = curl_multi_info_read (multi, &running);
214 if (msg == NULL)
215 break;
216 if (msg->msg == CURLMSG_DONE)
217 {
218 if (msg->data.result != CURLE_OK)
219 printf ("%s failed at %s:%d: `%s'\n",
220 "curl_multi_perform",
221 __FILE__,
222 __LINE__, curl_easy_strerror (msg->data.result));
223 curl_multi_remove_handle (multi, c);
224 curl_multi_cleanup (multi);
225 curl_easy_cleanup (c);
226 c = NULL;
227 multi = NULL;
228 }
229 }
230 MHD_run (d);
231 } 212 }
232 if (multi != NULL) 213 else
214 (void) sleep (1);
215 curl_multi_perform (multi, &running);
216 if (running == 0)
233 { 217 {
234 curl_multi_remove_handle (multi, c); 218 msg = curl_multi_info_read (multi, &running);
235 curl_easy_cleanup (c); 219 if (msg == NULL)
236 curl_multi_cleanup (multi); 220 break;
221 if (msg->msg == CURLMSG_DONE)
222 {
223 if (msg->data.result != CURLE_OK)
224 printf ("%s failed at %s:%d: `%s'\n",
225 "curl_multi_perform",
226 __FILE__,
227 __LINE__, curl_easy_strerror (msg->data.result));
228 curl_multi_remove_handle (multi, c);
229 curl_multi_cleanup (multi);
230 curl_easy_cleanup (c);
231 c = NULL;
232 multi = NULL;
233 }
237 } 234 }
235 MHD_run (d);
236 }
237 if (multi != NULL)
238 {
239 curl_multi_remove_handle (multi, c);
240 curl_easy_cleanup (c);
241 curl_multi_cleanup (multi);
242 }
238 MHD_stop_daemon (d); 243 MHD_stop_daemon (d);
239 if (cbc.pos != strlen ("/hello_world")) 244 if (cbc.pos != strlen ("/hello_world"))
240 return 8192; 245 return 8192;
@@ -248,17 +253,17 @@ int
248main (int argc, char *const *argv) 253main (int argc, char *const *argv)
249{ 254{
250 unsigned int errorCount = 0; 255 unsigned int errorCount = 0;
251 (void)argc; /* Unused. Silent compiler warning. */ 256 (void) argc; /* Unused. Silent compiler warning. */
252 257
253 oneone = 0; 258 oneone = 0;
254 if (!testsuite_curl_global_init ()) 259 if (! testsuite_curl_global_init ())
255 return 99; 260 return 99;
256 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 261 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
257 { 262 {
258 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 263 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
259 curl_global_cleanup (); 264 curl_global_cleanup ();
260 return 77; 265 return 77;
261 } 266 }
262 267
263#ifdef EPOLL_SUPPORT 268#ifdef EPOLL_SUPPORT
264 errorCount += testExternalGet (MHD_USE_EPOLL); 269 errorCount += testExternalGet (MHD_USE_EPOLL);
diff --git a/src/testcurl/https/test_https_multi_daemon.c b/src/testcurl/https/test_https_multi_daemon.c
index 130fa9df..de153ff6 100644
--- a/src/testcurl/https/test_https_multi_daemon.c
+++ b/src/testcurl/https/test_https_multi_daemon.c
@@ -43,70 +43,74 @@ extern const char srv_self_signed_cert_pem[];
43 */ 43 */
44static int 44static int
45test_concurent_daemon_pair (void *cls, 45test_concurent_daemon_pair (void *cls,
46 const char *cipher_suite, 46 const char *cipher_suite,
47 int proto_version) 47 int proto_version)
48{ 48{
49 int ret; 49 int ret;
50 struct MHD_Daemon *d1; 50 struct MHD_Daemon *d1;
51 struct MHD_Daemon *d2; 51 struct MHD_Daemon *d2;
52 int port1, port2; 52 int port1, port2;
53 (void)cls; /* Unused. Silent compiler warning. */ 53 (void) cls; /* Unused. Silent compiler warning. */
54 54
55 55
56 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 56 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
57 port1 = port2 = 0; 57 port1 = port2 = 0;
58 else 58 else
59 { 59 {
60 port1 = 3050; 60 port1 = 3050;
61 port2 = 3051; 61 port2 = 3051;
62 } 62 }
63 63
64 d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 64 d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
65 MHD_USE_ERROR_LOG, port1, 65 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
66 | MHD_USE_ERROR_LOG, port1,
66 NULL, NULL, &http_ahc, NULL, 67 NULL, NULL, &http_ahc, NULL,
67 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 68 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
68 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 69 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
69 MHD_OPTION_END); 70 MHD_OPTION_END);
70 71
71 if (d1 == NULL) 72 if (d1 == NULL)
72 { 73 {
73 fprintf (stderr, MHD_E_SERVER_INIT); 74 fprintf (stderr, MHD_E_SERVER_INIT);
74 return -1; 75 return -1;
75 } 76 }
76 if (0 == port1) 77 if (0 == port1)
78 {
79 const union MHD_DaemonInfo *dinfo;
80 dinfo = MHD_get_daemon_info (d1, MHD_DAEMON_INFO_BIND_PORT);
81 if ((NULL == dinfo) ||(0 == dinfo->port) )
77 { 82 {
78 const union MHD_DaemonInfo *dinfo; 83 MHD_stop_daemon (d1); return -1;
79 dinfo = MHD_get_daemon_info (d1, MHD_DAEMON_INFO_BIND_PORT);
80 if (NULL == dinfo || 0 == dinfo->port)
81 { MHD_stop_daemon (d1); return -1; }
82 port1 = (int)dinfo->port;
83 } 84 }
85 port1 = (int) dinfo->port;
86 }
84 87
85 d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 88 d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
86 MHD_USE_ERROR_LOG, port2, 89 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
90 | MHD_USE_ERROR_LOG, port2,
87 NULL, NULL, &http_ahc, NULL, 91 NULL, NULL, &http_ahc, NULL,
88 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 92 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
89 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 93 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
90 MHD_OPTION_END); 94 MHD_OPTION_END);
91 95
92 if (d2 == NULL) 96 if (d2 == NULL)
97 {
98 MHD_stop_daemon (d1);
99 fprintf (stderr, MHD_E_SERVER_INIT);
100 return -1;
101 }
102 if (0 == port2)
103 {
104 const union MHD_DaemonInfo *dinfo;
105 dinfo = MHD_get_daemon_info (d2, MHD_DAEMON_INFO_BIND_PORT);
106 if ((NULL == dinfo) ||(0 == dinfo->port) )
93 { 107 {
94 MHD_stop_daemon (d1); 108 MHD_stop_daemon (d1);
95 fprintf (stderr, MHD_E_SERVER_INIT); 109 MHD_stop_daemon (d2);
96 return -1; 110 return -1;
97 } 111 }
98 if (0 == port2) 112 port2 = (int) dinfo->port;
99 { 113 }
100 const union MHD_DaemonInfo *dinfo;
101 dinfo = MHD_get_daemon_info (d2, MHD_DAEMON_INFO_BIND_PORT);
102 if (NULL == dinfo || 0 == dinfo->port)
103 {
104 MHD_stop_daemon (d1);
105 MHD_stop_daemon (d2);
106 return -1;
107 }
108 port2 = (int)dinfo->port;
109 }
110 114
111 ret = 115 ret =
112 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0); 116 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0);
@@ -128,7 +132,7 @@ main (int argc, char *const *argv)
128 unsigned int errorCount = 0; 132 unsigned int errorCount = 0;
129 FILE *cert; 133 FILE *cert;
130 const char *aes256_sha = "AES256-SHA"; 134 const char *aes256_sha = "AES256-SHA";
131 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 135 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
132 136
133#ifdef MHD_HTTPS_REQUIRE_GRYPT 137#ifdef MHD_HTTPS_REQUIRE_GRYPT
134 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 138 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -136,25 +140,25 @@ main (int argc, char *const *argv)
136 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 140 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
137#endif 141#endif
138#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 142#endif /* MHD_HTTPS_REQUIRE_GRYPT */
139 if (!testsuite_curl_global_init ()) 143 if (! testsuite_curl_global_init ())
140 return 99; 144 return 99;
141 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 145 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
142 { 146 {
143 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 147 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
144 curl_global_cleanup (); 148 curl_global_cleanup ();
145 return 77; 149 return 77;
146 } 150 }
147 if ((cert = setup_ca_cert ()) == NULL) 151 if ((cert = setup_ca_cert ()) == NULL)
148 { 152 {
149 fprintf (stderr, MHD_E_TEST_FILE_CREAT); 153 fprintf (stderr, MHD_E_TEST_FILE_CREAT);
150 curl_global_cleanup (); 154 curl_global_cleanup ();
151 return 99; 155 return 99;
152 } 156 }
153 157
154 if (curl_uses_nss_ssl() == 0) 158 if (curl_uses_nss_ssl () == 0)
155 { 159 {
156 aes256_sha = "rsa_aes_256_sha"; 160 aes256_sha = "rsa_aes_256_sha";
157 } 161 }
158 162
159 errorCount += 163 errorCount +=
160 test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); 164 test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_TLSv1);
@@ -165,7 +169,7 @@ main (int argc, char *const *argv)
165 fclose (cert); 169 fclose (cert);
166 if (0 != remove (ca_cert_file_name)) 170 if (0 != remove (ca_cert_file_name))
167 fprintf (stderr, 171 fprintf (stderr,
168 "Failed to remove `%s'\n", 172 "Failed to remove `%s'\n",
169 ca_cert_file_name); 173 ca_cert_file_name);
170 return errorCount != 0 ? 1 : 0; 174 return errorCount != 0 ? 1 : 0;
171} 175}
diff --git a/src/testcurl/https/test_https_session_info.c b/src/testcurl/https/test_https_session_info.c
index 45f13981..b692af15 100644
--- a/src/testcurl/https/test_https_session_info.c
+++ b/src/testcurl/https/test_https_session_info.c
@@ -49,41 +49,41 @@ query_session_ahc (void *cls, struct MHD_Connection *connection,
49{ 49{
50 struct MHD_Response *response; 50 struct MHD_Response *response;
51 int ret; 51 int ret;
52 (void)cls;(void)url;(void)method;(void)version; /* Unused. Silent compiler warning. */ 52 (void) cls; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */
53 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 53 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
54 54
55 if (NULL == *ptr) 55 if (NULL == *ptr)
56 { 56 {
57 *ptr = (void*)&query_session_ahc; 57 *ptr = (void*) &query_session_ahc;
58 return MHD_YES; 58 return MHD_YES;
59 } 59 }
60 60
61 if (GNUTLS_TLS1_1 != 61 if (GNUTLS_TLS1_1 !=
62 (ret = MHD_get_connection_info 62 (ret = MHD_get_connection_info
63 (connection, 63 (connection,
64 MHD_CONNECTION_INFO_PROTOCOL)->protocol)) 64 MHD_CONNECTION_INFO_PROTOCOL)->protocol))
65 {
66 if (GNUTLS_TLS1_2 == ret)
67 {
68 /* as usual, TLS implementations sometimes don't
69 quite do what was asked, just mildly complain... */
70 fprintf (stderr,
71 "Warning: requested TLS 1.1, got TLS 1.2\n");
72 }
73 else
65 { 74 {
66 if (GNUTLS_TLS1_2 == ret) 75 /* really different version... */
67 { 76 fprintf (stderr,
68 /* as usual, TLS implementations sometimes don't 77 "Error: requested protocol mismatch (wanted %d, got %d)\n",
69 quite do what was asked, just mildly complain... */ 78 GNUTLS_TLS1_1,
70 fprintf (stderr, 79 ret);
71 "Warning: requested TLS 1.1, got TLS 1.2\n"); 80 return -1;
72 }
73 else
74 {
75 /* really different version... */
76 fprintf (stderr,
77 "Error: requested protocol mismatch (wanted %d, got %d)\n",
78 GNUTLS_TLS1_1,
79 ret);
80 return -1;
81 }
82 } 81 }
82 }
83 83
84 response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), 84 response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE),
85 (void *) EMPTY_PAGE, 85 (void *) EMPTY_PAGE,
86 MHD_RESPMEM_PERSISTENT); 86 MHD_RESPMEM_PERSISTENT);
87 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 87 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
88 MHD_destroy_response (response); 88 MHD_destroy_response (response);
89 return ret; 89 return ret;
@@ -114,37 +114,38 @@ test_query_session ()
114 cbc.pos = 0; 114 cbc.pos = 0;
115 115
116 /* setup test */ 116 /* setup test */
117 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 117 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
118 MHD_USE_ERROR_LOG, port, 118 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
119 | MHD_USE_ERROR_LOG, port,
119 NULL, NULL, &query_session_ahc, NULL, 120 NULL, NULL, &query_session_ahc, NULL,
120 MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128", 121 MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128",
121 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 122 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
122 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 123 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
123 MHD_OPTION_END); 124 MHD_OPTION_END);
124 125
125 if (d == NULL) 126 if (d == NULL)
126 { 127 {
127 free (cbc.buf); 128 free (cbc.buf);
128 return 2; 129 return 2;
129 } 130 }
130 if (0 == port) 131 if (0 == port)
132 {
133 const union MHD_DaemonInfo *dinfo;
134 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
135 if ((NULL == dinfo) ||(0 == dinfo->port) )
131 { 136 {
132 const union MHD_DaemonInfo *dinfo; 137 MHD_stop_daemon (d);
133 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); 138 free (cbc.buf);
134 if (NULL == dinfo || 0 == dinfo->port) 139 return 32;
135 {
136 MHD_stop_daemon (d);
137 free (cbc.buf);
138 return 32;
139 }
140 port = (int)dinfo->port;
141 } 140 }
141 port = (int) dinfo->port;
142 }
142 143
143 const char *aes256_sha = "AES256-SHA"; 144 const char *aes256_sha = "AES256-SHA";
144 if (curl_uses_nss_ssl() == 0) 145 if (curl_uses_nss_ssl () == 0)
145 { 146 {
146 aes256_sha = "rsa_aes_256_sha"; 147 aes256_sha = "rsa_aes_256_sha";
147 } 148 }
148 149
149 gen_test_file_url (url, 150 gen_test_file_url (url,
150 sizeof (url), 151 sizeof (url),
@@ -172,15 +173,15 @@ test_query_session ()
172 * crashes on my system! */ 173 * crashes on my system! */
173 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 174 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
174 if (CURLE_OK != (errornum = curl_easy_perform (c))) 175 if (CURLE_OK != (errornum = curl_easy_perform (c)))
175 { 176 {
176 fprintf (stderr, "curl_easy_perform failed: `%s'\n", 177 fprintf (stderr, "curl_easy_perform failed: `%s'\n",
177 curl_easy_strerror (errornum)); 178 curl_easy_strerror (errornum));
178 179
179 MHD_stop_daemon (d); 180 MHD_stop_daemon (d);
180 curl_easy_cleanup (c); 181 curl_easy_cleanup (c);
181 free (cbc.buf); 182 free (cbc.buf);
182 return -1; 183 return -1;
183 } 184 }
184 185
185 curl_easy_cleanup (c); 186 curl_easy_cleanup (c);
186 MHD_stop_daemon (d); 187 MHD_stop_daemon (d);
@@ -195,7 +196,7 @@ main (int argc, char *const *argv)
195#if LIBCURL_VERSION_NUM >= 0x072200 196#if LIBCURL_VERSION_NUM >= 0x072200
196 unsigned int errorCount = 0; 197 unsigned int errorCount = 0;
197 const char *ssl_version; 198 const char *ssl_version;
198 (void)argc; /* Unused. Silent compiler warning. */ 199 (void) argc; /* Unused. Silent compiler warning. */
199 200
200#ifdef MHD_HTTPS_REQUIRE_GRYPT 201#ifdef MHD_HTTPS_REQUIRE_GRYPT
201 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 202 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -203,7 +204,7 @@ main (int argc, char *const *argv)
203 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 204 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
204#endif 205#endif
205#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 206#endif /* MHD_HTTPS_REQUIRE_GRYPT */
206 if (!testsuite_curl_global_init ()) 207 if (! testsuite_curl_global_init ())
207 return 99; 208 return 99;
208 209
209 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; 210 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version;
diff --git a/src/testcurl/https/test_https_sni.c b/src/testcurl/https/test_https_sni.c
index 8af1472b..16576656 100644
--- a/src/testcurl/https/test_https_sni.c
+++ b/src/testcurl/https/test_https_sni.c
@@ -60,9 +60,9 @@ static struct Hosts *hosts;
60 * (This code is largely taken from GnuTLS). 60 * (This code is largely taken from GnuTLS).
61 */ 61 */
62static void 62static void
63load_keys(const char *hostname, 63load_keys (const char *hostname,
64 const char *CERT_FILE, 64 const char *CERT_FILE,
65 const char *KEY_FILE) 65 const char *KEY_FILE)
66{ 66{
67 int ret; 67 int ret;
68 gnutls_datum_t data; 68 gnutls_datum_t data;
@@ -77,32 +77,32 @@ load_keys(const char *hostname,
77 77
78 ret = gnutls_load_file (CERT_FILE, &data); 78 ret = gnutls_load_file (CERT_FILE, &data);
79 if (ret < 0) 79 if (ret < 0)
80 { 80 {
81 fprintf (stderr, 81 fprintf (stderr,
82 "*** Error loading certificate file %s.\n", 82 "*** Error loading certificate file %s.\n",
83 CERT_FILE); 83 CERT_FILE);
84 exit (1); 84 exit (1);
85 } 85 }
86 ret = 86 ret =
87 gnutls_pcert_import_x509_raw (&host->pcrt, &data, GNUTLS_X509_FMT_PEM, 87 gnutls_pcert_import_x509_raw (&host->pcrt, &data, GNUTLS_X509_FMT_PEM,
88 0); 88 0);
89 if (ret < 0) 89 if (ret < 0)
90 { 90 {
91 fprintf (stderr, 91 fprintf (stderr,
92 "*** Error loading certificate file: %s\n", 92 "*** Error loading certificate file: %s\n",
93 gnutls_strerror (ret)); 93 gnutls_strerror (ret));
94 exit (1); 94 exit (1);
95 } 95 }
96 gnutls_free (data.data); 96 gnutls_free (data.data);
97 97
98 ret = gnutls_load_file (KEY_FILE, &data); 98 ret = gnutls_load_file (KEY_FILE, &data);
99 if (ret < 0) 99 if (ret < 0)
100 { 100 {
101 fprintf (stderr, 101 fprintf (stderr,
102 "*** Error loading key file %s.\n", 102 "*** Error loading key file %s.\n",
103 KEY_FILE); 103 KEY_FILE);
104 exit (1); 104 exit (1);
105 } 105 }
106 106
107 gnutls_privkey_init (&host->key); 107 gnutls_privkey_init (&host->key);
108 ret = 108 ret =
@@ -110,12 +110,12 @@ load_keys(const char *hostname,
110 &data, GNUTLS_X509_FMT_PEM, 110 &data, GNUTLS_X509_FMT_PEM,
111 NULL, 0); 111 NULL, 0);
112 if (ret < 0) 112 if (ret < 0)
113 { 113 {
114 fprintf (stderr, 114 fprintf (stderr,
115 "*** Error loading key file: %s\n", 115 "*** Error loading key file: %s\n",
116 gnutls_strerror (ret)); 116 gnutls_strerror (ret));
117 exit (1); 117 exit (1);
118 } 118 }
119 gnutls_free (data.data); 119 gnutls_free (data.data);
120} 120}
121 121
@@ -133,19 +133,19 @@ load_keys(const char *hostname,
133 */ 133 */
134static int 134static int
135sni_callback (gnutls_session_t session, 135sni_callback (gnutls_session_t session,
136 const gnutls_datum_t* req_ca_dn, 136 const gnutls_datum_t*req_ca_dn,
137 int nreqs, 137 int nreqs,
138 const gnutls_pk_algorithm_t* pk_algos, 138 const gnutls_pk_algorithm_t*pk_algos,
139 int pk_algos_length, 139 int pk_algos_length,
140 gnutls_pcert_st** pcert, 140 gnutls_pcert_st**pcert,
141 unsigned int *pcert_length, 141 unsigned int *pcert_length,
142 gnutls_privkey_t * pkey) 142 gnutls_privkey_t *pkey)
143{ 143{
144 char name[256]; 144 char name[256];
145 size_t name_len; 145 size_t name_len;
146 struct Hosts *host; 146 struct Hosts *host;
147 unsigned int type; 147 unsigned int type;
148 (void)req_ca_dn;(void)nreqs;(void)pk_algos;(void)pk_algos_length; /* Unused. Silent compiler warning. */ 148 (void) req_ca_dn; (void) nreqs; (void) pk_algos; (void) pk_algos_length; /* Unused. Silent compiler warning. */
149 149
150 name_len = sizeof (name); 150 name_len = sizeof (name);
151 if (GNUTLS_E_SUCCESS != 151 if (GNUTLS_E_SUCCESS !=
@@ -159,13 +159,13 @@ sni_callback (gnutls_session_t session,
159 if (0 == strncmp (name, host->hostname, name_len)) 159 if (0 == strncmp (name, host->hostname, name_len))
160 break; 160 break;
161 if (NULL == host) 161 if (NULL == host)
162 { 162 {
163 fprintf (stderr, 163 fprintf (stderr,
164 "Need certificate for %.*s\n", 164 "Need certificate for %.*s\n",
165 (int) name_len, 165 (int) name_len,
166 name); 166 name);
167 return -1; 167 return -1;
168 } 168 }
169#if 0 169#if 0
170 fprintf (stderr, 170 fprintf (stderr,
171 "Returning certificate for %.*s\n", 171 "Returning certificate for %.*s\n",
@@ -192,10 +192,10 @@ do_get (const char *url, int port)
192 192
193 len = strlen (test_data); 193 len = strlen (test_data);
194 if (NULL == (cbc.buf = malloc (sizeof (char) * len))) 194 if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
195 { 195 {
196 fprintf (stderr, MHD_E_MEM); 196 fprintf (stderr, MHD_E_MEM);
197 return -1; 197 return -1;
198 } 198 }
199 cbc.size = len; 199 cbc.size = len;
200 cbc.pos = 0; 200 cbc.pos = 0;
201 201
@@ -204,7 +204,7 @@ do_get (const char *url, int port)
204 curl_easy_setopt (c, CURLOPT_VERBOSE, 1L); 204 curl_easy_setopt (c, CURLOPT_VERBOSE, 1L);
205#endif 205#endif
206 curl_easy_setopt (c, CURLOPT_URL, url); 206 curl_easy_setopt (c, CURLOPT_URL, url);
207 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 207 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
208 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 208 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
209 curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L); 209 curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
210 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L); 210 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
@@ -215,9 +215,9 @@ do_get (const char *url, int port)
215 /* TODO merge into send_curl_req */ 215 /* TODO merge into send_curl_req */
216 curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0L); 216 curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0L);
217 curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 2L); 217 curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 2L);
218 sprintf(buf, "host1:%d:127.0.0.1", port); 218 sprintf (buf, "host1:%d:127.0.0.1", port);
219 dns_info = curl_slist_append (NULL, buf); 219 dns_info = curl_slist_append (NULL, buf);
220 sprintf(buf, "host2:%d:127.0.0.1", port); 220 sprintf (buf, "host2:%d:127.0.0.1", port);
221 dns_info = curl_slist_append (dns_info, buf); 221 dns_info = curl_slist_append (dns_info, buf);
222 curl_easy_setopt (c, CURLOPT_RESOLVE, dns_info); 222 curl_easy_setopt (c, CURLOPT_RESOLVE, dns_info);
223 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 223 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -227,23 +227,23 @@ do_get (const char *url, int port)
227 crashes on my system! */ 227 crashes on my system! */
228 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 228 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
229 if (CURLE_OK != (errornum = curl_easy_perform (c))) 229 if (CURLE_OK != (errornum = curl_easy_perform (c)))
230 { 230 {
231 fprintf (stderr, "curl_easy_perform failed: `%s'\n", 231 fprintf (stderr, "curl_easy_perform failed: `%s'\n",
232 curl_easy_strerror (errornum)); 232 curl_easy_strerror (errornum));
233 curl_easy_cleanup (c); 233 curl_easy_cleanup (c);
234 free (cbc.buf); 234 free (cbc.buf);
235 curl_slist_free_all (dns_info); 235 curl_slist_free_all (dns_info);
236 return errornum; 236 return errornum;
237 } 237 }
238 238
239 curl_easy_cleanup (c); 239 curl_easy_cleanup (c);
240 curl_slist_free_all (dns_info); 240 curl_slist_free_all (dns_info);
241 if (memcmp (cbc.buf, test_data, len) != 0) 241 if (memcmp (cbc.buf, test_data, len) != 0)
242 { 242 {
243 fprintf (stderr, "Error: local file & received file differ.\n"); 243 fprintf (stderr, "Error: local file & received file differ.\n");
244 free (cbc.buf); 244 free (cbc.buf);
245 return -1; 245 return -1;
246 } 246 }
247 247
248 free (cbc.buf); 248 free (cbc.buf);
249 return 0; 249 return 0;
@@ -256,7 +256,7 @@ main (int argc, char *const *argv)
256 unsigned int error_count = 0; 256 unsigned int error_count = 0;
257 struct MHD_Daemon *d; 257 struct MHD_Daemon *d;
258 int port; 258 int port;
259 (void)argc; /* Unused. Silent compiler warning. */ 259 (void) argc; /* Unused. Silent compiler warning. */
260 260
261 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 261 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
262 port = 0; 262 port = 0;
@@ -269,36 +269,40 @@ main (int argc, char *const *argv)
269 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 269 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
270#endif 270#endif
271#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 271#endif /* MHD_HTTPS_REQUIRE_GRYPT */
272 if (!testsuite_curl_global_init ()) 272 if (! testsuite_curl_global_init ())
273 return 99; 273 return 99;
274 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 274 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
275 { 275 {
276 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 276 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
277 curl_global_cleanup (); 277 curl_global_cleanup ();
278 return 77; 278 return 77;
279 } 279 }
280 280
281 load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key"); 281 load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key");
282 load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key"); 282 load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key");
283 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, 283 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
284 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
285 | MHD_USE_ERROR_LOG,
284 port, 286 port,
285 NULL, NULL, 287 NULL, NULL,
286 &http_ahc, NULL, 288 &http_ahc, NULL,
287 MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback, 289 MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback,
288 MHD_OPTION_END); 290 MHD_OPTION_END);
289 if (d == NULL) 291 if (d == NULL)
290 { 292 {
291 fprintf (stderr, MHD_E_SERVER_INIT); 293 fprintf (stderr, MHD_E_SERVER_INIT);
292 return -1; 294 return -1;
293 } 295 }
294 if (0 == port) 296 if (0 == port)
297 {
298 const union MHD_DaemonInfo *dinfo;
299 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
300 if ((NULL == dinfo) ||(0 == dinfo->port) )
295 { 301 {
296 const union MHD_DaemonInfo *dinfo; 302 MHD_stop_daemon (d); return -1;
297 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
298 if (NULL == dinfo || 0 == dinfo->port)
299 { MHD_stop_daemon (d); return -1; }
300 port = (int)dinfo->port;
301 } 303 }
304 port = (int) dinfo->port;
305 }
302 if (0 != do_get ("https://host1/", port)) 306 if (0 != do_get ("https://host1/", port))
303 error_count++; 307 error_count++;
304 if (0 != do_get ("https://host2/", port)) 308 if (0 != do_get ("https://host2/", port))
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c
index e46923eb..d2f4d92c 100644
--- a/src/testcurl/https/test_https_time_out.c
+++ b/src/testcurl/https/test_https_time_out.c
@@ -55,10 +55,10 @@ test_tls_session_time_out (gnutls_session_t session, int port)
55 55
56 sd = socket (AF_INET, SOCK_STREAM, 0); 56 sd = socket (AF_INET, SOCK_STREAM, 0);
57 if (sd == MHD_INVALID_SOCKET) 57 if (sd == MHD_INVALID_SOCKET)
58 { 58 {
59 fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); 59 fprintf (stderr, "Failed to create socket: %s\n", strerror (errno));
60 return -1; 60 return -1;
61 } 61 }
62 62
63 memset (&sa, '\0', sizeof (struct sockaddr_in)); 63 memset (&sa, '\0', sizeof (struct sockaddr_in));
64 sa.sin_family = AF_INET; 64 sa.sin_family = AF_INET;
@@ -70,30 +70,30 @@ test_tls_session_time_out (gnutls_session_t session, int port)
70 ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); 70 ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in));
71 71
72 if (ret < 0) 72 if (ret < 0)
73 { 73 {
74 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); 74 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
75 MHD_socket_close_chk_ (sd); 75 MHD_socket_close_chk_ (sd);
76 return -1; 76 return -1;
77 } 77 }
78 78
79 ret = gnutls_handshake (session); 79 ret = gnutls_handshake (session);
80 if (ret < 0) 80 if (ret < 0)
81 { 81 {
82 fprintf (stderr, "Handshake failed\n"); 82 fprintf (stderr, "Handshake failed\n");
83 MHD_socket_close_chk_ (sd); 83 MHD_socket_close_chk_ (sd);
84 return -1; 84 return -1;
85 } 85 }
86 86
87 (void)sleep (TIME_OUT + 1); 87 (void) sleep (TIME_OUT + 1);
88 88
89 /* check that server has closed the connection */ 89 /* check that server has closed the connection */
90 /* TODO better RST trigger */ 90 /* TODO better RST trigger */
91 if (send (sd, "", 1, 0) == 0) 91 if (send (sd, "", 1, 0) == 0)
92 { 92 {
93 fprintf (stderr, "Connection failed to time-out\n"); 93 fprintf (stderr, "Connection failed to time-out\n");
94 MHD_socket_close_chk_ (sd); 94 MHD_socket_close_chk_ (sd);
95 return -1; 95 return -1;
96 } 96 }
97 97
98 MHD_socket_close_chk_ (sd); 98 MHD_socket_close_chk_ (sd);
99 return 0; 99 return 0;
@@ -110,7 +110,7 @@ main (int argc, char *const *argv)
110 gnutls_datum_t cert; 110 gnutls_datum_t cert;
111 gnutls_certificate_credentials_t xcred; 111 gnutls_certificate_credentials_t xcred;
112 int port; 112 int port;
113 (void)argc; /* Unused. Silent compiler warning. */ 113 (void) argc; /* Unused. Silent compiler warning. */
114 114
115 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 115 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
116 port = 0; 116 port = 0;
@@ -126,8 +126,9 @@ main (int argc, char *const *argv)
126 gnutls_global_init (); 126 gnutls_global_init ();
127 gnutls_global_set_log_level (11); 127 gnutls_global_set_log_level (11);
128 128
129 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 129 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
130 MHD_USE_ERROR_LOG, port, 130 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
131 | MHD_USE_ERROR_LOG, port,
131 NULL, NULL, &http_dummy_ahc, NULL, 132 NULL, NULL, &http_dummy_ahc, NULL,
132 MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT, 133 MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
133 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 134 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -135,24 +136,26 @@ main (int argc, char *const *argv)
135 MHD_OPTION_END); 136 MHD_OPTION_END);
136 137
137 if (NULL == d) 138 if (NULL == d)
138 { 139 {
139 fprintf (stderr, MHD_E_SERVER_INIT); 140 fprintf (stderr, MHD_E_SERVER_INIT);
140 return -1; 141 return -1;
141 } 142 }
142 if (0 == port) 143 if (0 == port)
144 {
145 const union MHD_DaemonInfo *dinfo;
146 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
147 if ((NULL == dinfo) ||(0 == dinfo->port) )
143 { 148 {
144 const union MHD_DaemonInfo *dinfo; 149 MHD_stop_daemon (d); return -1;
145 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
146 if (NULL == dinfo || 0 == dinfo->port)
147 { MHD_stop_daemon (d); return -1; }
148 port = (int)dinfo->port;
149 } 150 }
151 port = (int) dinfo->port;
152 }
150 153
151 if (0 != setup_session (&session, &key, &cert, &xcred)) 154 if (0 != setup_session (&session, &key, &cert, &xcred))
152 { 155 {
153 fprintf (stderr, "failed to setup session\n"); 156 fprintf (stderr, "failed to setup session\n");
154 return 1; 157 return 1;
155 } 158 }
156 errorCount += test_tls_session_time_out (session, port); 159 errorCount += test_tls_session_time_out (session, port);
157 teardown_session (session, &key, &cert, xcred); 160 teardown_session (session, &key, &cert, xcred);
158 161
diff --git a/src/testcurl/https/test_tls_authentication.c b/src/testcurl/https/test_tls_authentication.c
index 2ed8f14c..51fb5331 100644
--- a/src/testcurl/https/test_tls_authentication.c
+++ b/src/testcurl/https/test_tls_authentication.c
@@ -41,38 +41,41 @@ extern const char srv_signed_key_pem[];
41 41
42/* perform a HTTP GET request via SSL/TLS */ 42/* perform a HTTP GET request via SSL/TLS */
43static int 43static int
44test_secure_get (void * cls, char *cipher_suite, int proto_version) 44test_secure_get (void *cls, char *cipher_suite, int proto_version)
45{ 45{
46 int ret; 46 int ret;
47 struct MHD_Daemon *d; 47 struct MHD_Daemon *d;
48 int port; 48 int port;
49 (void)cls; /* Unused. Silent compiler warning. */ 49 (void) cls; /* Unused. Silent compiler warning. */
50 50
51 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 51 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
52 port = 0; 52 port = 0;
53 else 53 else
54 port = 3070; 54 port = 3070;
55 55
56 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 56 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
57 MHD_USE_ERROR_LOG, port, 57 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
58 | MHD_USE_ERROR_LOG, port,
58 NULL, NULL, &http_ahc, NULL, 59 NULL, NULL, &http_ahc, NULL,
59 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 60 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
60 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 61 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
61 MHD_OPTION_END); 62 MHD_OPTION_END);
62 63
63 if (d == NULL) 64 if (d == NULL)
64 { 65 {
65 fprintf (stderr, MHD_E_SERVER_INIT); 66 fprintf (stderr, MHD_E_SERVER_INIT);
66 return -1; 67 return -1;
67 } 68 }
68 if (0 == port) 69 if (0 == port)
70 {
71 const union MHD_DaemonInfo *dinfo;
72 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
73 if ((NULL == dinfo) ||(0 == dinfo->port) )
69 { 74 {
70 const union MHD_DaemonInfo *dinfo; 75 MHD_stop_daemon (d); return -1;
71 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
72 if (NULL == dinfo || 0 == dinfo->port)
73 { MHD_stop_daemon (d); return -1; }
74 port = (int)dinfo->port;
75 } 76 }
77 port = (int) dinfo->port;
78 }
76 79
77 ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 0); 80 ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 0);
78 81
@@ -87,8 +90,8 @@ main (int argc, char *const *argv)
87 unsigned int errorCount = 0; 90 unsigned int errorCount = 0;
88 char *aes256_sha = "AES256-SHA"; 91 char *aes256_sha = "AES256-SHA";
89 FILE *crt; 92 FILE *crt;
90 (void)argc; 93 (void) argc;
91 (void)argv; /* Unused. Silent compiler warning. */ 94 (void) argv; /* Unused. Silent compiler warning. */
92 95
93#ifdef MHD_HTTPS_REQUIRE_GRYPT 96#ifdef MHD_HTTPS_REQUIRE_GRYPT
94 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 97 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -96,26 +99,26 @@ main (int argc, char *const *argv)
96 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 99 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
97#endif 100#endif
98#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 101#endif /* MHD_HTTPS_REQUIRE_GRYPT */
99 if (!testsuite_curl_global_init ()) 102 if (! testsuite_curl_global_init ())
100 return 99; 103 return 99;
101 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 104 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
102 { 105 {
103 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 106 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
104 curl_global_cleanup (); 107 curl_global_cleanup ();
105 return 77; 108 return 77;
106 } 109 }
107 110
108 if (NULL == (crt = setup_ca_cert ())) 111 if (NULL == (crt = setup_ca_cert ()))
109 { 112 {
110 fprintf (stderr, MHD_E_TEST_FILE_CREAT); 113 fprintf (stderr, MHD_E_TEST_FILE_CREAT);
111 curl_global_cleanup (); 114 curl_global_cleanup ();
112 return 99; 115 return 99;
113 } 116 }
114 fclose (crt); 117 fclose (crt);
115 if (curl_uses_nss_ssl() == 0) 118 if (curl_uses_nss_ssl () == 0)
116 { 119 {
117 aes256_sha = "rsa_aes_256_sha"; 120 aes256_sha = "rsa_aes_256_sha";
118 } 121 }
119 122
120 errorCount += 123 errorCount +=
121 test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); 124 test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1);
@@ -125,7 +128,7 @@ main (int argc, char *const *argv)
125 curl_global_cleanup (); 128 curl_global_cleanup ();
126 if (0 != remove (ca_cert_file_name)) 129 if (0 != remove (ca_cert_file_name))
127 fprintf (stderr, 130 fprintf (stderr,
128 "Failed to remove `%s'\n", 131 "Failed to remove `%s'\n",
129 ca_cert_file_name); 132 ca_cert_file_name);
130 return errorCount != 0 ? 1 : 0; 133 return errorCount != 0 ? 1 : 0;
131} 134}
diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c
index 08cde939..f5095359 100644
--- a/src/testcurl/https/test_tls_extensions.c
+++ b/src/testcurl/https/test_tls_extensions.c
@@ -69,20 +69,20 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
69 sd = -1; 69 sd = -1;
70 memset (&cbc, 0, sizeof (struct CBC)); 70 memset (&cbc, 0, sizeof (struct CBC));
71 if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) 71 if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
72 { 72 {
73 fprintf (stderr, MHD_E_MEM); 73 fprintf (stderr, MHD_E_MEM);
74 ret = -1; 74 ret = -1;
75 goto cleanup; 75 goto cleanup;
76 } 76 }
77 cbc.size = 256; 77 cbc.size = 256;
78 78
79 sd = socket (AF_INET, SOCK_STREAM, 0); 79 sd = socket (AF_INET, SOCK_STREAM, 0);
80 if (sd == -1) 80 if (sd == -1)
81 { 81 {
82 fprintf(stderr, "Failed to create socket: %s\n", strerror(errno)); 82 fprintf (stderr, "Failed to create socket: %s\n", strerror (errno));
83 free (cbc.buf); 83 free (cbc.buf);
84 return -1; 84 return -1;
85 } 85 }
86 memset (&sa, '\0', sizeof (struct sockaddr_in)); 86 memset (&sa, '\0', sizeof (struct sockaddr_in));
87 sa.sin_family = AF_INET; 87 sa.sin_family = AF_INET;
88 sa.sin_port = htons (port); 88 sa.sin_port = htons (port);
@@ -101,10 +101,10 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
101 101
102 data = MHD_gnutls_malloc (datalen); 102 data = MHD_gnutls_malloc (datalen);
103 if (data == NULL) 103 if (data == NULL)
104 { 104 {
105 free (cbc.buf); 105 free (cbc.buf);
106 return -1; 106 return -1;
107 } 107 }
108 hver = MHD_gtls_version_max (session); 108 hver = MHD_gtls_version_max (session);
109 data[pos++] = MHD_gtls_version_get_major (hver); 109 data[pos++] = MHD_gtls_version_get_major (hver);
110 data[pos++] = MHD_gtls_version_get_minor (hver); 110 data[pos++] = MHD_gtls_version_get_minor (hver);
@@ -119,7 +119,8 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
119 /* generate session client random */ 119 /* generate session client random */
120 memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE); 120 memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE);
121 gnutls_write_uint32 (time (NULL), rnd); 121 gnutls_write_uint32 (time (NULL), rnd);
122 if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4)) abort (); 122 if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4))
123 abort ();
123 memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE); 124 memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE);
124 memcpy (&data[pos], rnd, TLS_RANDOM_SIZE); 125 memcpy (&data[pos], rnd, TLS_RANDOM_SIZE);
125 pos += TLS_RANDOM_SIZE; 126 pos += TLS_RANDOM_SIZE;
@@ -148,37 +149,37 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
148 gnutls_write_uint16 (exten_data_len, &data[pos]); 149 gnutls_write_uint16 (exten_data_len, &data[pos]);
149 pos += 2; 150 pos += 2;
150 for (i = 0; i < ext_count; ++i) 151 for (i = 0; i < ext_count; ++i)
151 { 152 {
152 /* write extension type */ 153 /* write extension type */
153 gnutls_write_uint16 (exten_t, &data[pos]); 154 gnutls_write_uint16 (exten_t, &data[pos]);
154 pos += 2; 155 pos += 2;
155 gnutls_write_uint16 (ext_length, &data[pos]); 156 gnutls_write_uint16 (ext_length, &data[pos]);
156 pos += 2; 157 pos += 2;
157 /* we might want to generate random data here */ 158 /* we might want to generate random data here */
158 memset (&data[pos], 0, ext_length); 159 memset (&data[pos], 0, ext_length);
159 pos += ext_length; 160 pos += ext_length;
160 } 161 }
161 162
162 if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0) 163 if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0)
163 { 164 {
164 fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT); 165 fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT);
165 ret = -1; 166 ret = -1;
166 goto cleanup; 167 goto cleanup;
167 } 168 }
168 169
169 gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd); 170 gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd);
170 171
171 if (gen_test_file_url (url, 172 if (gen_test_file_url (url,
172 sizeof (url), 173 sizeof (url),
173 port)) 174 port))
174 { 175 {
175 ret = -1; 176 ret = -1;
176 goto cleanup; 177 goto cleanup;
177 } 178 }
178 179
179 /* this should crash the server */ 180 /* this should crash the server */
180 ret = gnutls_send_handshake (session, data, datalen, 181 ret = gnutls_send_handshake (session, data, datalen,
181 GNUTLS_HANDSHAKE_CLIENT_HELLO); 182 GNUTLS_HANDSHAKE_CLIENT_HELLO);
182 183
183 /* advance to STATE2 */ 184 /* advance to STATE2 */
184 session->internals.handshake_state = STATE2; 185 session->internals.handshake_state = STATE2;
@@ -190,10 +191,10 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t,
190 /* make sure daemon is still functioning */ 191 /* make sure daemon is still functioning */
191 if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA", 192 if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA",
192 MHD_GNUTLS_PROTOCOL_TLS1_2)) 193 MHD_GNUTLS_PROTOCOL_TLS1_2))
193 { 194 {
194 ret = -1; 195 ret = -1;
195 goto cleanup; 196 goto cleanup;
196 } 197 }
197 198
198cleanup: 199cleanup:
199 if (-1 != sd) 200 if (-1 != sd)
@@ -233,34 +234,37 @@ main (int argc, char *const *argv)
233 MHD_gtls_global_set_log_level (11); 234 MHD_gtls_global_set_log_level (11);
234 235
235 if ((test_fd = setup_test_file ()) == NULL) 236 if ((test_fd = setup_test_file ()) == NULL)
236 { 237 {
237 fprintf (stderr, MHD_E_TEST_FILE_CREAT); 238 fprintf (stderr, MHD_E_TEST_FILE_CREAT);
238 return -1; 239 return -1;
239 } 240 }
240 241
241 if (!testsuite_curl_global_init ()) 242 if (! testsuite_curl_global_init ())
242 return 99; 243 return 99;
243 244
244 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 245 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
245 MHD_USE_ERROR_LOG, port, 246 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
247 | MHD_USE_ERROR_LOG, port,
246 NULL, NULL, &http_ahc, NULL, 248 NULL, NULL, &http_ahc, NULL,
247 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 249 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
248 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 250 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
249 MHD_OPTION_END); 251 MHD_OPTION_END);
250 252
251 if (d == NULL) 253 if (d == NULL)
252 { 254 {
253 fprintf (stderr, "%s\n", MHD_E_SERVER_INIT); 255 fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
254 return -1; 256 return -1;
255 } 257 }
256 if (0 == port) 258 if (0 == port)
259 {
260 const union MHD_DaemonInfo *dinfo;
261 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
262 if ((NULL == dinfo) ||(0 == dinfo->port) )
257 { 263 {
258 const union MHD_DaemonInfo *dinfo; 264 MHD_stop_daemon (d); return -1;
259 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
260 if (NULL == dinfo || 0 == dinfo->port)
261 { MHD_stop_daemon (d); return -1; }
262 port = (int)dinfo->port;
263 } 265 }
266 port = (int) dinfo->port;
267 }
264 268
265 i = 0; 269 i = 0;
266 setup_session (&session, &key, &cert, &xcred); 270 setup_session (&session, &key, &cert, &xcred);
@@ -269,21 +273,21 @@ main (int argc, char *const *argv)
269#if 1 273#if 1
270 i = 0; 274 i = 0;
271 while (ext_arr[i] != -1) 275 while (ext_arr[i] != -1)
272 { 276 {
273 setup_session (&session, &key, &cert, &xcred); 277 setup_session (&session, &key, &cert, &xcred);
274 errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16); 278 errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16);
275 teardown_session (session, &key, &cert, xcred); 279 teardown_session (session, &key, &cert, xcred);
276 280
277 setup_session (&session, &key, &cert, &xcred); 281 setup_session (&session, &key, &cert, &xcred);
278 errorCount += test_hello_extension (session, port, ext_arr[i], 3, 8); 282 errorCount += test_hello_extension (session, port, ext_arr[i], 3, 8);
279 teardown_session (session, &key, &cert, xcred); 283 teardown_session (session, &key, &cert, xcred);
280 284
281 /* this test specifically tests the issue raised in CVE-2008-1948 */ 285 /* this test specifically tests the issue raised in CVE-2008-1948 */
282 setup_session (&session, &key, &cert, &xcred); 286 setup_session (&session, &key, &cert, &xcred);
283 errorCount += test_hello_extension (session, port, ext_arr[i], 6, 0); 287 errorCount += test_hello_extension (session, port, ext_arr[i], 6, 0);
284 teardown_session (session, &key, &cert, xcred); 288 teardown_session (session, &key, &cert, xcred);
285 i++; 289 i++;
286 } 290 }
287#endif 291#endif
288 292
289 print_test_result (errorCount, argv[0]); 293 print_test_result (errorCount, argv[0]);
diff --git a/src/testcurl/https/test_tls_options.c b/src/testcurl/https/test_tls_options.c
index 703ae92a..f94834b5 100644
--- a/src/testcurl/https/test_tls_options.c
+++ b/src/testcurl/https/test_tls_options.c
@@ -43,17 +43,17 @@ int curl_check_version (const char *req_version, ...);
43 * 43 *
44 */ 44 */
45static int 45static int
46test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite, 46test_unmatching_ssl_version (void *cls, int port, const char *cipher_suite,
47 int curl_req_ssl_version) 47 int curl_req_ssl_version)
48{ 48{
49 struct CBC cbc; 49 struct CBC cbc;
50 (void)cls; /* Unused. Silent compiler warning. */ 50 (void) cls; /* Unused. Silent compiler warning. */
51 if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) 51 if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
52 { 52 {
53 fprintf (stderr, "Error: failed to allocate: %s\n", 53 fprintf (stderr, "Error: failed to allocate: %s\n",
54 strerror (errno)); 54 strerror (errno));
55 return -1; 55 return -1;
56 } 56 }
57 cbc.size = 256; 57 cbc.size = 256;
58 cbc.pos = 0; 58 cbc.pos = 0;
59 59
@@ -61,21 +61,22 @@ test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite,
61 if (gen_test_file_url (url, 61 if (gen_test_file_url (url,
62 sizeof (url), 62 sizeof (url),
63 port)) 63 port))
64 { 64 {
65 free (cbc.buf); 65 free (cbc.buf);
66 fprintf (stderr, 66 fprintf (stderr,
67 "Internal error in gen_test_file_url\n"); 67 "Internal error in gen_test_file_url\n");
68 return -1; 68 return -1;
69 } 69 }
70 70
71 /* assert daemon *rejected* request */ 71 /* assert daemon *rejected* request */
72 if (CURLE_OK == 72 if (CURLE_OK ==
73 send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version)) 73 send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version))
74 { 74 {
75 free (cbc.buf); 75 free (cbc.buf);
76 fprintf (stderr, "cURL failed to reject request despite SSL version mismatch!\n"); 76 fprintf (stderr,
77 return -1; 77 "cURL failed to reject request despite SSL version mismatch!\n");
78 } 78 return -1;
79 }
79 80
80 free (cbc.buf); 81 free (cbc.buf);
81 return 0; 82 return 0;
@@ -89,9 +90,10 @@ main (int argc, char *const *argv)
89 unsigned int errorCount = 0; 90 unsigned int errorCount = 0;
90 const char *ssl_version; 91 const char *ssl_version;
91 int daemon_flags = 92 int daemon_flags =
92 MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG; 93 MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD
94 | MHD_USE_TLS | MHD_USE_ERROR_LOG;
93 int port; 95 int port;
94 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 96 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
95 97
96 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 98 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
97 port = 0; 99 port = 0;
@@ -105,10 +107,10 @@ main (int argc, char *const *argv)
105 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 107 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
106#endif 108#endif
107#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 109#endif /* MHD_HTTPS_REQUIRE_GRYPT */
108 if (curl_check_version (MHD_REQ_CURL_VERSION)) 110 if (curl_check_version (MHD_REQ_CURL_VERSION))
109 { 111 {
110 return 77; 112 return 77;
111 } 113 }
112 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; 114 ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version;
113 if (NULL == ssl_version) 115 if (NULL == ssl_version)
114 { 116 {
@@ -121,46 +123,48 @@ main (int argc, char *const *argv)
121 return 77; 123 return 77;
122 } 124 }
123 125
124 if (!testsuite_curl_global_init ()) 126 if (! testsuite_curl_global_init ())
125 return 99; 127 return 99;
126 128
127 const char *aes128_sha = "AES128-SHA"; 129 const char *aes128_sha = "AES128-SHA";
128 const char *aes256_sha = "AES256-SHA"; 130 const char *aes256_sha = "AES256-SHA";
129 if (curl_uses_nss_ssl() == 0) 131 if (curl_uses_nss_ssl () == 0)
130 { 132 {
131 aes128_sha = "rsa_aes_128_sha"; 133 aes128_sha = "rsa_aes_128_sha";
132 aes256_sha = "rsa_aes_256_sha"; 134 aes256_sha = "rsa_aes_256_sha";
133 } 135 }
134 136
135 137
136 if (0 != 138 if (0 !=
137 test_wrap ("TLS1.0-AES-SHA1", 139 test_wrap ("TLS1.0-AES-SHA1",
138 &test_https_transfer, NULL, port, daemon_flags, 140 &test_https_transfer, NULL, port, daemon_flags,
139 aes128_sha, 141 aes128_sha,
140 CURL_SSLVERSION_TLSv1, 142 CURL_SSLVERSION_TLSv1,
141 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 143 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
142 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 144 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
143 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL", 145 MHD_OPTION_HTTPS_PRIORITIES,
144 MHD_OPTION_END)) 146 "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
145 { 147 MHD_OPTION_END))
146 fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n"); 148 {
147 errorCount++; 149 fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n");
148 } 150 errorCount++;
151 }
149 fprintf (stderr, 152 fprintf (stderr,
150 "The following handshake should fail (and print an error message)...\n"); 153 "The following handshake should fail (and print an error message)...\n");
151 if (0 != 154 if (0 !=
152 test_wrap ("TLS1.0 vs SSL3", 155 test_wrap ("TLS1.0 vs SSL3",
153 &test_unmatching_ssl_version, NULL, port, daemon_flags, 156 &test_unmatching_ssl_version, NULL, port, daemon_flags,
154 aes256_sha, 157 aes256_sha,
155 CURL_SSLVERSION_SSLv3, 158 CURL_SSLVERSION_SSLv3,
156 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 159 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
157 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 160 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
158 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL", 161 MHD_OPTION_HTTPS_PRIORITIES,
159 MHD_OPTION_END)) 162 "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
160 { 163 MHD_OPTION_END))
161 fprintf (stderr, "TLS1.0 vs SSL3 test failed\n"); 164 {
162 errorCount++; 165 fprintf (stderr, "TLS1.0 vs SSL3 test failed\n");
163 } 166 errorCount++;
167 }
164 curl_global_cleanup (); 168 curl_global_cleanup ();
165 169
166 return errorCount != 0 ? 1 : 0; 170 return errorCount != 0 ? 1 : 0;
diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c
index 367bed00..eb7cb14c 100644
--- a/src/testcurl/https/tls_test_common.c
+++ b/src/testcurl/https/tls_test_common.c
@@ -33,26 +33,26 @@ setup_ca_cert ()
33 FILE *cert_fd; 33 FILE *cert_fd;
34 34
35 if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+"))) 35 if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+")))
36 { 36 {
37 fprintf (stderr, "Error: failed to open `%s': %s\n", 37 fprintf (stderr, "Error: failed to open `%s': %s\n",
38 ca_cert_file_name, strerror (errno)); 38 ca_cert_file_name, strerror (errno));
39 return NULL; 39 return NULL;
40 } 40 }
41 if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem) + 1, cert_fd) 41 if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem) + 1, cert_fd)
42 != strlen (ca_cert_pem) + 1) 42 != strlen (ca_cert_pem) + 1)
43 { 43 {
44 fprintf (stderr, "Error: failed to write `%s. %s'\n", 44 fprintf (stderr, "Error: failed to write `%s. %s'\n",
45 ca_cert_file_name, strerror (errno)); 45 ca_cert_file_name, strerror (errno));
46 fclose (cert_fd); 46 fclose (cert_fd);
47 return NULL; 47 return NULL;
48 } 48 }
49 if (fflush (cert_fd)) 49 if (fflush (cert_fd))
50 { 50 {
51 fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n", 51 fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n",
52 strerror (errno)); 52 strerror (errno));
53 fclose (cert_fd); 53 fclose (cert_fd);
54 return NULL; 54 return NULL;
55 } 55 }
56 return cert_fd; 56 return cert_fd;
57} 57}
58 58
@@ -62,23 +62,23 @@ setup_ca_cert ()
62 */ 62 */
63int 63int
64test_daemon_get (void *cls, 64test_daemon_get (void *cls,
65 const char *cipher_suite, int proto_version, 65 const char *cipher_suite, int proto_version,
66 int port, 66 int port,
67 int ver_peer) 67 int ver_peer)
68{ 68{
69 CURL *c; 69 CURL *c;
70 struct CBC cbc; 70 struct CBC cbc;
71 CURLcode errornum; 71 CURLcode errornum;
72 char url[255]; 72 char url[255];
73 size_t len; 73 size_t len;
74 (void)cls; /* Unused. Silent compiler warning. */ 74 (void) cls; /* Unused. Silent compiler warning. */
75 75
76 len = strlen (test_data); 76 len = strlen (test_data);
77 if (NULL == (cbc.buf = malloc (sizeof (char) * len))) 77 if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
78 { 78 {
79 fprintf (stderr, MHD_E_MEM); 79 fprintf (stderr, MHD_E_MEM);
80 return -1; 80 return -1;
81 } 81 }
82 cbc.size = len; 82 cbc.size = len;
83 cbc.pos = 0; 83 cbc.pos = 0;
84 84
@@ -115,22 +115,22 @@ test_daemon_get (void *cls,
115 crashes on my system! */ 115 crashes on my system! */
116 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 116 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
117 if (CURLE_OK != (errornum = curl_easy_perform (c))) 117 if (CURLE_OK != (errornum = curl_easy_perform (c)))
118 { 118 {
119 fprintf (stderr, "curl_easy_perform failed: `%s'\n", 119 fprintf (stderr, "curl_easy_perform failed: `%s'\n",
120 curl_easy_strerror (errornum)); 120 curl_easy_strerror (errornum));
121 curl_easy_cleanup (c); 121 curl_easy_cleanup (c);
122 free (cbc.buf); 122 free (cbc.buf);
123 return errornum; 123 return errornum;
124 } 124 }
125 125
126 curl_easy_cleanup (c); 126 curl_easy_cleanup (c);
127 127
128 if (memcmp (cbc.buf, test_data, len) != 0) 128 if (memcmp (cbc.buf, test_data, len) != 0)
129 { 129 {
130 fprintf (stderr, "Error: local file & received file differ.\n"); 130 fprintf (stderr, "Error: local file & received file differ.\n");
131 free (cbc.buf); 131 free (cbc.buf);
132 return -1; 132 return -1;
133 } 133 }
134 134
135 free (cbc.buf); 135 free (cbc.buf);
136 return 0; 136 return 0;
@@ -141,7 +141,9 @@ void
141print_test_result (int test_outcome, char *test_name) 141print_test_result (int test_outcome, char *test_name)
142{ 142{
143 if (test_outcome != 0) 143 if (test_outcome != 0)
144 fprintf (stderr, "running test: %s [fail: %u]\n", test_name, (unsigned int)test_outcome); 144 fprintf (stderr, "running test: %s [fail: %u]\n", test_name, (unsigned
145 int)
146 test_outcome);
145#if 0 147#if 0
146 else 148 else
147 fprintf (stdout, "running test: %s [pass]\n", test_name); 149 fprintf (stdout, "running test: %s [pass]\n", test_name);
@@ -171,21 +173,21 @@ http_ahc (void *cls, struct MHD_Connection *connection,
171 static int aptr; 173 static int aptr;
172 struct MHD_Response *response; 174 struct MHD_Response *response;
173 int ret; 175 int ret;
174 (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ 176 (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */
175 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 177 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
176 178
177 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 179 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
178 return MHD_NO; /* unexpected method */ 180 return MHD_NO; /* unexpected method */
179 if (&aptr != *ptr) 181 if (&aptr != *ptr)
180 { 182 {
181 /* do never respond on first call */ 183 /* do never respond on first call */
182 *ptr = &aptr; 184 *ptr = &aptr;
183 return MHD_YES; 185 return MHD_YES;
184 } 186 }
185 *ptr = NULL; /* reset when done */ 187 *ptr = NULL; /* reset when done */
186 response = MHD_create_response_from_buffer (strlen (test_data), 188 response = MHD_create_response_from_buffer (strlen (test_data),
187 (void *) test_data, 189 (void *) test_data,
188 MHD_RESPMEM_PERSISTENT); 190 MHD_RESPMEM_PERSISTENT);
189 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 191 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
190 MHD_destroy_response (response); 192 MHD_destroy_response (response);
191 return ret; 193 return ret;
@@ -198,9 +200,9 @@ http_dummy_ahc (void *cls, struct MHD_Connection *connection,
198 const char *upload_data, size_t *upload_data_size, 200 const char *upload_data, size_t *upload_data_size,
199 void **ptr) 201 void **ptr)
200{ 202{
201 (void)cls;(void)connection;(void)url;(void)method;(void)version; /* Unused. Silent compiler warning. */ 203 (void) cls; (void) connection; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */
202 (void)upload_data;(void)upload_data_size;(void)ptr; /* Unused. Silent compiler warning. */ 204 (void) upload_data; (void) upload_data_size; (void) ptr; /* Unused. Silent compiler warning. */
203 return 0; 205 return 0;
204} 206}
205 207
206/** 208/**
@@ -213,7 +215,7 @@ http_dummy_ahc (void *cls, struct MHD_Connection *connection,
213 */ 215 */
214/* TODO have test wrap consider a NULL cbc */ 216/* TODO have test wrap consider a NULL cbc */
215int 217int
216send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite, 218send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite,
217 int proto_version) 219 int proto_version)
218{ 220{
219 CURL *c; 221 CURL *c;
@@ -228,10 +230,10 @@ send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite,
228 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 60L); 230 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 60L);
229 231
230 if (cbc != NULL) 232 if (cbc != NULL)
231 { 233 {
232 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 234 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
233 curl_easy_setopt (c, CURLOPT_FILE, cbc); 235 curl_easy_setopt (c, CURLOPT_FILE, cbc);
234 } 236 }
235 237
236 /* TLS options */ 238 /* TLS options */
237 curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version); 239 curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version);
@@ -248,12 +250,12 @@ send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite,
248 crashes on my system! */ 250 crashes on my system! */
249 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 251 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
250 if (CURLE_OK != (errornum = curl_easy_perform (c))) 252 if (CURLE_OK != (errornum = curl_easy_perform (c)))
251 { 253 {
252 fprintf (stderr, "curl_easy_perform failed: `%s'\n", 254 fprintf (stderr, "curl_easy_perform failed: `%s'\n",
253 curl_easy_strerror (errornum)); 255 curl_easy_strerror (errornum));
254 curl_easy_cleanup (c); 256 curl_easy_cleanup (c);
255 return errornum; 257 return errornum;
256 } 258 }
257 curl_easy_cleanup (c); 259 curl_easy_cleanup (c);
258 260
259 return CURLE_OK; 261 return CURLE_OK;
@@ -286,27 +288,27 @@ gen_test_file_url (char *url,
286 size_t i; 288 size_t i;
287#endif /* ! WINDOWS */ 289#endif /* ! WINDOWS */
288 if (NULL == (doc_path = malloc (doc_path_len))) 290 if (NULL == (doc_path = malloc (doc_path_len)))
289 { 291 {
290 fprintf (stderr, MHD_E_MEM); 292 fprintf (stderr, MHD_E_MEM);
291 return -1; 293 return -1;
292 } 294 }
293 if (NULL == getcwd (doc_path, doc_path_len)) 295 if (NULL == getcwd (doc_path, doc_path_len))
294 { 296 {
295 fprintf (stderr, 297 fprintf (stderr,
296 "Error: failed to get working directory. %s\n", 298 "Error: failed to get working directory. %s\n",
297 strerror (errno)); 299 strerror (errno));
298 free (doc_path); 300 free (doc_path);
299 return -1; 301 return -1;
300 } 302 }
301#ifdef WINDOWS 303#ifdef WINDOWS
302 for (i = 0; i < doc_path_len; i++) 304 for (i = 0; i < doc_path_len; i++)
303 { 305 {
304 if (doc_path[i] == 0) 306 if (doc_path[i] == 0)
305 break; 307 break;
306 if (doc_path[i] == '\\') 308 if (doc_path[i] == '\\')
307 { 309 {
308 doc_path[i] = '/'; 310 doc_path[i] = '/';
309 } 311 }
310 if (doc_path[i] != ':') 312 if (doc_path[i] != ':')
311 continue; 313 continue;
312 if (i == 0) 314 if (i == 0)
@@ -322,7 +324,7 @@ gen_test_file_url (char *url,
322 "https://127.0.0.1", 324 "https://127.0.0.1",
323 port, 325 port,
324 doc_path, 326 doc_path,
325 "urlpath") >= (long long)url_len) 327 "urlpath") >= (long long) url_len)
326 ret = -1; 328 ret = -1;
327 329
328 free (doc_path); 330 free (doc_path);
@@ -343,41 +345,41 @@ test_https_transfer (void *cls,
343 int ret = 0; 345 int ret = 0;
344 struct CBC cbc; 346 struct CBC cbc;
345 char url[255]; 347 char url[255];
346 (void)cls; /* Unused. Silent compiler warning. */ 348 (void) cls; /* Unused. Silent compiler warning. */
347 349
348 len = strlen (test_data); 350 len = strlen (test_data);
349 if (NULL == (cbc.buf = malloc (sizeof (char) * len))) 351 if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
350 { 352 {
351 fprintf (stderr, MHD_E_MEM); 353 fprintf (stderr, MHD_E_MEM);
352 return -1; 354 return -1;
353 } 355 }
354 cbc.size = len; 356 cbc.size = len;
355 cbc.pos = 0; 357 cbc.pos = 0;
356 358
357 if (gen_test_file_url (url, 359 if (gen_test_file_url (url,
358 sizeof (url), 360 sizeof (url),
359 port)) 361 port))
360 { 362 {
361 ret = -1; 363 ret = -1;
362 goto cleanup; 364 goto cleanup;
363 } 365 }
364 366
365 if (CURLE_OK != 367 if (CURLE_OK !=
366 send_curl_req (url, &cbc, cipher_suite, proto_version)) 368 send_curl_req (url, &cbc, cipher_suite, proto_version))
367 { 369 {
368 ret = -1; 370 ret = -1;
369 goto cleanup; 371 goto cleanup;
370 } 372 }
371 373
372 /* compare test file & daemon responce */ 374 /* compare test file & daemon responce */
373 if ( (len != strlen (test_data)) || 375 if ( (len != strlen (test_data)) ||
374 (memcmp (cbc.buf, 376 (memcmp (cbc.buf,
375 test_data, 377 test_data,
376 len) != 0) ) 378 len) != 0) )
377 { 379 {
378 fprintf (stderr, "Error: local file & received file differ.\n"); 380 fprintf (stderr, "Error: local file & received file differ.\n");
379 ret = -1; 381 ret = -1;
380 } 382 }
381cleanup: 383cleanup:
382 free (cbc.buf); 384 free (cbc.buf);
383 return ret; 385 return ret;
@@ -392,28 +394,29 @@ cleanup:
392 * @return port number on success or zero on failure 394 * @return port number on success or zero on failure
393 */ 395 */
394int 396int
395setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list) 397setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list
398 arg_list)
396{ 399{
397 *d = MHD_start_daemon_va (daemon_flags, port, 400 *d = MHD_start_daemon_va (daemon_flags, port,
398 NULL, NULL, &http_ahc, NULL, arg_list); 401 NULL, NULL, &http_ahc, NULL, arg_list);
399 402
400 if (*d == NULL) 403 if (*d == NULL)
401 { 404 {
402 fprintf (stderr, MHD_E_SERVER_INIT); 405 fprintf (stderr, MHD_E_SERVER_INIT);
403 return 0; 406 return 0;
404 } 407 }
405 408
406 if (0 == port) 409 if (0 == port)
410 {
411 const union MHD_DaemonInfo *dinfo;
412 dinfo = MHD_get_daemon_info (*d, MHD_DAEMON_INFO_BIND_PORT);
413 if ((NULL == dinfo) ||(0 == dinfo->port) )
407 { 414 {
408 const union MHD_DaemonInfo *dinfo; 415 MHD_stop_daemon (*d);
409 dinfo = MHD_get_daemon_info (*d, MHD_DAEMON_INFO_BIND_PORT); 416 return 0;
410 if (NULL == dinfo || 0 == dinfo->port)
411 {
412 MHD_stop_daemon (*d);
413 return 0;
414 }
415 port = (int)dinfo->port;
416 } 417 }
418 port = (int) dinfo->port;
419 }
417 420
418 return port; 421 return port;
419} 422}
@@ -425,10 +428,10 @@ teardown_testcase (struct MHD_Daemon *d)
425} 428}
426 429
427int 430int
428setup_session (gnutls_session_t * session, 431setup_session (gnutls_session_t *session,
429 gnutls_datum_t * key, 432 gnutls_datum_t *key,
430 gnutls_datum_t * cert, 433 gnutls_datum_t *cert,
431 gnutls_certificate_credentials_t * xcred) 434 gnutls_certificate_credentials_t *xcred)
432{ 435{
433 int ret; 436 int ret;
434 const char *err_pos; 437 const char *err_pos;
@@ -437,42 +440,42 @@ setup_session (gnutls_session_t * session,
437 key->size = strlen (srv_key_pem) + 1; 440 key->size = strlen (srv_key_pem) + 1;
438 key->data = malloc (key->size); 441 key->data = malloc (key->size);
439 if (NULL == key->data) 442 if (NULL == key->data)
440 { 443 {
441 gnutls_certificate_free_credentials (*xcred); 444 gnutls_certificate_free_credentials (*xcred);
442 return -1; 445 return -1;
443 } 446 }
444 memcpy (key->data, srv_key_pem, key->size); 447 memcpy (key->data, srv_key_pem, key->size);
445 cert->size = strlen (srv_self_signed_cert_pem) + 1; 448 cert->size = strlen (srv_self_signed_cert_pem) + 1;
446 cert->data = malloc (cert->size); 449 cert->data = malloc (cert->size);
447 if (NULL == cert->data) 450 if (NULL == cert->data)
448 { 451 {
449 gnutls_certificate_free_credentials (*xcred); 452 gnutls_certificate_free_credentials (*xcred);
450 free (key->data); 453 free (key->data);
451 return -1; 454 return -1;
452 } 455 }
453 memcpy (cert->data, srv_self_signed_cert_pem, cert->size); 456 memcpy (cert->data, srv_self_signed_cert_pem, cert->size);
454 gnutls_certificate_set_x509_key_mem (*xcred, cert, key, 457 gnutls_certificate_set_x509_key_mem (*xcred, cert, key,
455 GNUTLS_X509_FMT_PEM); 458 GNUTLS_X509_FMT_PEM);
456 gnutls_init (session, GNUTLS_CLIENT); 459 gnutls_init (session, GNUTLS_CLIENT);
457 ret = gnutls_priority_set_direct (*session, 460 ret = gnutls_priority_set_direct (*session,
458 "NORMAL", &err_pos); 461 "NORMAL", &err_pos);
459 if (ret < 0) 462 if (ret < 0)
460 { 463 {
461 gnutls_deinit (*session); 464 gnutls_deinit (*session);
462 gnutls_certificate_free_credentials (*xcred); 465 gnutls_certificate_free_credentials (*xcred);
463 free (key->data); 466 free (key->data);
464 return -1; 467 return -1;
465 } 468 }
466 gnutls_credentials_set (*session, 469 gnutls_credentials_set (*session,
467 GNUTLS_CRD_CERTIFICATE, 470 GNUTLS_CRD_CERTIFICATE,
468 *xcred); 471 *xcred);
469 return 0; 472 return 0;
470} 473}
471 474
472int 475int
473teardown_session (gnutls_session_t session, 476teardown_session (gnutls_session_t session,
474 gnutls_datum_t * key, 477 gnutls_datum_t *key,
475 gnutls_datum_t * cert, 478 gnutls_datum_t *cert,
476 gnutls_certificate_credentials_t xcred) 479 gnutls_certificate_credentials_t xcred)
477{ 480{
478 free (key->data); 481 free (key->data);
@@ -489,37 +492,37 @@ teardown_session (gnutls_session_t session,
489/* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */ 492/* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */
490int 493int
491test_wrap (const char *test_name, int 494test_wrap (const char *test_name, int
492 (*test_function) (void * cls, int port, const char *cipher_suite, 495 (*test_function)(void *cls, int port, const char *cipher_suite,
493 int proto_version), void * cls, 496 int proto_version), void *cls,
494 int port, 497 int port,
495 int daemon_flags, const char *cipher_suite, int proto_version, ...) 498 int daemon_flags, const char *cipher_suite, int proto_version, ...)
496{ 499{
497 int ret; 500 int ret;
498 va_list arg_list; 501 va_list arg_list;
499 struct MHD_Daemon *d; 502 struct MHD_Daemon *d;
500 (void)cls; /* Unused. Silent compiler warning. */ 503 (void) cls; /* Unused. Silent compiler warning. */
501 504
502 va_start (arg_list, proto_version); 505 va_start (arg_list, proto_version);
503 port = setup_testcase (&d, port, daemon_flags, arg_list); 506 port = setup_testcase (&d, port, daemon_flags, arg_list);
504 if (0 == port) 507 if (0 == port)
505 { 508 {
506 va_end (arg_list); 509 va_end (arg_list);
507 fprintf (stderr, "Failed to setup testcase %s\n", test_name); 510 fprintf (stderr, "Failed to setup testcase %s\n", test_name);
508 return -1; 511 return -1;
509 } 512 }
510#if 0 513#if 0
511 fprintf (stdout, "running test: %s ", test_name); 514 fprintf (stdout, "running test: %s ", test_name);
512#endif 515#endif
513 ret = test_function (NULL, port, cipher_suite, proto_version); 516 ret = test_function (NULL, port, cipher_suite, proto_version);
514#if 0 517#if 0
515 if (ret == 0) 518 if (ret == 0)
516 { 519 {
517 fprintf (stdout, "[pass]\n"); 520 fprintf (stdout, "[pass]\n");
518 } 521 }
519 else 522 else
520 { 523 {
521 fprintf (stdout, "[fail]\n"); 524 fprintf (stdout, "[fail]\n");
522 } 525 }
523#endif 526#endif
524 teardown_testcase (d); 527 teardown_testcase (d);
525 va_end (arg_list); 528 va_end (arg_list);
@@ -532,17 +535,19 @@ testsuite_curl_global_init (void)
532{ 535{
533 CURLcode res; 536 CURLcode res;
534#if LIBCURL_VERSION_NUM >= 0x073800 537#if LIBCURL_VERSION_NUM >= 0x073800
535 if (CURLSSLSET_OK != curl_global_sslset(CURLSSLBACKEND_GNUTLS, NULL, NULL)) 538 if (CURLSSLSET_OK != curl_global_sslset (CURLSSLBACKEND_GNUTLS, NULL, NULL))
536 { 539 {
537 if (CURLSSLSET_TOO_LATE == curl_global_sslset(CURLSSLBACKEND_OPENSSL, NULL, NULL)) 540 if (CURLSSLSET_TOO_LATE == curl_global_sslset (CURLSSLBACKEND_OPENSSL, NULL,
538 fprintf (stderr, "WARNING: libcurl was already initialised.\n"); 541 NULL))
539 } 542 fprintf (stderr, "WARNING: libcurl was already initialised.\n");
543 }
540#endif /* LIBCURL_VERSION_NUM >= 0x07380 */ 544#endif /* LIBCURL_VERSION_NUM >= 0x07380 */
541 res = curl_global_init (CURL_GLOBAL_ALL); 545 res = curl_global_init (CURL_GLOBAL_ALL);
542 if (CURLE_OK != res) 546 if (CURLE_OK != res)
543 { 547 {
544 fprintf (stderr, "libcurl initialisation error: %s\n", curl_easy_strerror(res)); 548 fprintf (stderr, "libcurl initialisation error: %s\n", curl_easy_strerror (
545 return 0; 549 res));
546 } 550 return 0;
551 }
547 return 1; 552 return 1;
548} 553}
diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h
index 490239ef..36f5ffa5 100644
--- a/src/testcurl/https/tls_test_common.h
+++ b/src/testcurl/https/tls_test_common.h
@@ -35,15 +35,18 @@
35#define test_data "Hello World\n" 35#define test_data "Hello World\n"
36#define ca_cert_file_name "tmp_ca_cert.pem" 36#define ca_cert_file_name "tmp_ca_cert.pem"
37 37
38#define EMPTY_PAGE "<html><head><title>Empty page</title></head><body>Empty page</body></html>" 38#define EMPTY_PAGE \
39#define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>" 39 "<html><head><title>Empty page</title></head><body>Empty page</body></html>"
40#define PAGE_NOT_FOUND \
41 "<html><head><title>File not found</title></head><body>File not found</body></html>"
40 42
41#define MHD_E_MEM "Error: memory error\n" 43#define MHD_E_MEM "Error: memory error\n"
42#define MHD_E_SERVER_INIT "Error: failed to start server\n" 44#define MHD_E_SERVER_INIT "Error: failed to start server\n"
43#define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n" 45#define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n"
44#define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n" 46#define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n"
45#define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n" 47#define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n"
46#define MHD_E_FAILED_TO_CONNECT "Error: server connection could not be established\n" 48#define MHD_E_FAILED_TO_CONNECT \
49 "Error: server connection could not be established\n"
47 50
48/* TODO rm if unused */ 51/* TODO rm if unused */
49struct https_test_data 52struct https_test_data
@@ -82,8 +85,8 @@ setup_ca_cert (void);
82 * perform cURL request for file 85 * perform cURL request for file
83 */ 86 */
84int 87int
85test_daemon_get (void * cls, 88test_daemon_get (void *cls,
86 const char *cipher_suite, int proto_version, 89 const char *cipher_suite, int proto_version,
87 int port, int ver_peer); 90 int port, int ver_peer);
88 91
89void 92void
@@ -122,31 +125,33 @@ send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite,
122 int proto_version); 125 int proto_version);
123 126
124int 127int
125test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_version); 128test_https_transfer (void *cls, int port, const char *cipher_suite, int
129 proto_version);
126 130
127int 131int
128setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list); 132setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list
133 arg_list);
129 134
130void 135void
131teardown_testcase (struct MHD_Daemon *d); 136teardown_testcase (struct MHD_Daemon *d);
132 137
133 138
134int 139int
135setup_session (gnutls_session_t * session, 140setup_session (gnutls_session_t *session,
136 gnutls_datum_t * key, 141 gnutls_datum_t *key,
137 gnutls_datum_t * cert, 142 gnutls_datum_t *cert,
138 gnutls_certificate_credentials_t * xcred); 143 gnutls_certificate_credentials_t *xcred);
139 144
140int 145int
141teardown_session (gnutls_session_t session, 146teardown_session (gnutls_session_t session,
142 gnutls_datum_t * key, 147 gnutls_datum_t *key,
143 gnutls_datum_t * cert, 148 gnutls_datum_t *cert,
144 gnutls_certificate_credentials_t xcred); 149 gnutls_certificate_credentials_t xcred);
145 150
146int 151int
147test_wrap (const char *test_name, int 152test_wrap (const char *test_name, int
148 (*test_function) (void * cls, int port, const char *cipher_suite, 153 (*test_function)(void *cls, int port, const char *cipher_suite,
149 int proto_version), void * cls, 154 int proto_version), void *cls,
150 int port, 155 int port,
151 int daemon_flags, const char *cipher_suite, int proto_version, ...); 156 int daemon_flags, const char *cipher_suite, int proto_version, ...);
152 157
diff --git a/src/testcurl/https/tls_test_keys.h b/src/testcurl/https/tls_test_keys.h
index b6e37eec..76f6f06f 100644
--- a/src/testcurl/https/tls_test_keys.h
+++ b/src/testcurl/https/tls_test_keys.h
@@ -24,150 +24,150 @@
24 24
25/* Certificate Authority key */ 25/* Certificate Authority key */
26const char ca_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 26const char ca_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
27 "MIIEowIBAAKCAQEA0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9J\n" 27 "MIIEowIBAAKCAQEA0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9J\n"
28 "rlxyLGfa6qVX7CFVNmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/E\n" 28 "rlxyLGfa6qVX7CFVNmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/E\n"
29 "h7n5VgwBX8NsP4eZNmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+3\n" 29 "h7n5VgwBX8NsP4eZNmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+3\n"
30 "32oqc4D/wJbV1AwwvC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn\n" 30 "32oqc4D/wJbV1AwwvC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn\n"
31 "4a4jIdf4FoPp9s0EieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEe\n" 31 "4a4jIdf4FoPp9s0EieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEe\n"
32 "o+jan9XK0dE88AIImGzgoBnlic/Rr7J8OWA+iwIDAQABAoIBAEICZqXkUdpsw2F6\n" 32 "o+jan9XK0dE88AIImGzgoBnlic/Rr7J8OWA+iwIDAQABAoIBAEICZqXkUdpsw2F6\n"
33 "qPMOergNPO3lrKg6ZO8hBs6j2fj3tcPuzljK5sqJDboxNejZ9Zo+rmnXf3Oj5fgL\n" 33 "qPMOergNPO3lrKg6ZO8hBs6j2fj3tcPuzljK5sqJDboxNejZ9Zo+rmnXf3Oj5fgL\n"
34 "6UcYMYEsm4W/QRA3uEJ1fzeQnT7Ty9KNprlHaSzquCLEGlIWJSo3xu0vFlWjJUcL\n" 34 "6UcYMYEsm4W/QRA3uEJ1fzeQnT7Ty9KNprlHaSzquCLEGlIWJSo3xu0vFlWjJUcL\n"
35 "fwemfaOhD/OVUeEU6s5FOngwy6pZUsOajs3fNRtwBGuuXjniKZZlpSf2Wqu3xpHZ\n" 35 "fwemfaOhD/OVUeEU6s5FOngwy6pZUsOajs3fNRtwBGuuXjniKZZlpSf2Wqu3xpHZ\n"
36 "31OF1V0ycUCGPPFtpmUCtnZhS9L8QBTkNtfTIdXv6SfoBRFm0oXb0uL5HGft6yc7\n" 36 "31OF1V0ycUCGPPFtpmUCtnZhS9L8QBTkNtfTIdXv6SfoBRFm0oXb0uL5HGft6yc7\n"
37 "eYRXIscllQciqG3ymJ/y9o0E3A0YsBVauQyi7OEk+Kg8uoYOBkZCIY69hoN2Znlk\n" 37 "eYRXIscllQciqG3ymJ/y9o0E3A0YsBVauQyi7OEk+Kg8uoYOBkZCIY69hoN2Znlk\n"
38 "OY5S5Z0CgYEA3j8pRAJzvc827KcX4vJf05HYD4aCyaI80fNmx1DgXfglTSGLQ361\n" 38 "OY5S5Z0CgYEA3j8pRAJzvc827KcX4vJf05HYD4aCyaI80fNmx1DgXfglTSGLQ361\n"
39 "6i05YW8WtIvgkma3wF+jJOckBCW/7iq8wAX7Kz75WKGRyyTEb0wSfjx0G8grxX4d\n" 39 "6i05YW8WtIvgkma3wF+jJOckBCW/7iq8wAX7Kz75WKGRyyTEb0wSfjx0G8grxX4d\n"
40 "7sTIAAOnQj5WT6E/bkqxQZAYnVtIPxKtSlwts0H/bjPVYwSFchHK7t8CgYEA7+ks\n" 40 "7sTIAAOnQj5WT6E/bkqxQZAYnVtIPxKtSlwts0H/bjPVYwSFchHK7t8CgYEA7+ks\n"
41 "C0EMjF8CDeCfvbOUGiiqAvU3G20LEC3WlJM3AU+J9Jzp6AMkgaIA8J5oNdsbFBn4\n" 41 "C0EMjF8CDeCfvbOUGiiqAvU3G20LEC3WlJM3AU+J9Jzp6AMkgaIA8J5oNdsbFBn4\n"
42 "N12JPOO+7WRUk6Av8bsh4faE36ThnHohgAL8guRU7jIXvsFyO5yiY7/o/0lES0/V\n" 42 "N12JPOO+7WRUk6Av8bsh4faE36ThnHohgAL8guRU7jIXvsFyO5yiY7/o/0lES0/V\n"
43 "6xkh/Epj4MReuCGkiD9ifCVAo+dhHskeE9qbYdUCgYA4yBpa7eV0UUTPIcHQkew5\n" 43 "6xkh/Epj4MReuCGkiD9ifCVAo+dhHskeE9qbYdUCgYA4yBpa7eV0UUTPIcHQkew5\n"
44 "ucFh9hPkQDcZzP4tXlR0rbmaAz/5dp4zvmoyopdCeZpezS+VTtn3y7Y/+QUYbILc\n" 44 "ucFh9hPkQDcZzP4tXlR0rbmaAz/5dp4zvmoyopdCeZpezS+VTtn3y7Y/+QUYbILc\n"
45 "7KpHWkeKhX0iUbp+VQlEh12C25mTU62CG3SdzFEnc5XJsoDqRNsUzSP80B2dP8BW\n" 45 "7KpHWkeKhX0iUbp+VQlEh12C25mTU62CG3SdzFEnc5XJsoDqRNsUzSP80B2dP8BW\n"
46 "h0aFzg7csRGLwtP1WOZoMQKBgQCrgsKd+Q8Dexh421DXyX3jhZalLrEKxlXWZy60\n" 46 "h0aFzg7csRGLwtP1WOZoMQKBgQCrgsKd+Q8Dexh421DXyX3jhZalLrEKxlXWZy60\n"
47 "YNo98aLqYRNHbpe2pR6O5nARsGYXZMlyq0flY9um0sc0Epyz79g1NoufZrxzpUw1\n" 47 "YNo98aLqYRNHbpe2pR6O5nARsGYXZMlyq0flY9um0sc0Epyz79g1NoufZrxzpUw1\n"
48 "u+zRlnKxJtaa5KjJvRzKuvPTLYnJXXXM8Na/Cl+E3F3qvQJm9QlvPyKLCmsAGz+J\n" 48 "u+zRlnKxJtaa5KjJvRzKuvPTLYnJXXXM8Na/Cl+E3F3qvQJm9QlvPyKLCmsAGz+J\n"
49 "agsTUQKBgC0wqqJ6b1tbrAD8AVeeAn/IiP1rxYpc3x2s6ikFO2FMHXHC9wgrRPOc\n" 49 "agsTUQKBgC0wqqJ6b1tbrAD8AVeeAn/IiP1rxYpc3x2s6ikFO2FMHXHC9wgrRPOc\n"
50 "mkokV+DrUOv3I/7jG8wQA/FmBUPy562a1bObIKzg6CPXzrN68AmNnOIVU+H8fdxI\n" 50 "mkokV+DrUOv3I/7jG8wQA/FmBUPy562a1bObIKzg6CPXzrN68AmNnOIVU+H8fdxI\n"
51 "iGyfT8WNpcRmtN11v34qXHwOWGQhpyyk2yNa8VIBSpkShq/EseZ1\n" 51 "iGyfT8WNpcRmtN11v34qXHwOWGQhpyyk2yNa8VIBSpkShq/EseZ1\n"
52 "-----END RSA PRIVATE KEY-----\n"; 52 "-----END RSA PRIVATE KEY-----\n";
53 53
54/* Certificate Authority cert */ 54/* Certificate Authority cert */
55const char ca_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 55const char ca_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
56 "MIIC6DCCAdKgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 56 "MIIC6DCCAdKgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
57 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 57 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n"
58 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" 58 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n"
59 "0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9JrlxyLGfa6qVX7CFV\n" 59 "0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9JrlxyLGfa6qVX7CFV\n"
60 "NmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/Eh7n5VgwBX8NsP4eZ\n" 60 "NmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/Eh7n5VgwBX8NsP4eZ\n"
61 "Nmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+332oqc4D/wJbV1Aww\n" 61 "Nmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+332oqc4D/wJbV1Aww\n"
62 "vC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn4a4jIdf4FoPp9s0E\n" 62 "vC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn4a4jIdf4FoPp9s0E\n"
63 "ieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEeo+jan9XK0dE88AII\n" 63 "ieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEeo+jan9XK0dE88AII\n"
64 "mGzgoBnlic/Rr7J8OWA+iwIDAQABo0MwQTAPBgNVHRMBAf8EBTADAQH/MA8GA1Ud\n" 64 "mGzgoBnlic/Rr7J8OWA+iwIDAQABo0MwQTAPBgNVHRMBAf8EBTADAQH/MA8GA1Ud\n"
65 "DwEB/wQFAwMHBAAwHQYDVR0OBBYEFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsGCSqG\n" 65 "DwEB/wQFAwMHBAAwHQYDVR0OBBYEFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsGCSqG\n"
66 "SIb3DQEBBQOCAQEAebD5m+vZkVXa8y+QZ5GtsiR9gpH+LKtdWBjk1kmfSgvQI/xA\n" 66 "SIb3DQEBBQOCAQEAebD5m+vZkVXa8y+QZ5GtsiR9gpH+LKtdWBjk1kmfSgvQI/xA\n"
67 "aDCV/9BhdNGIBOTYGkln8urWd7g2Mj3TwKEAfNTUFpAsrBAlSSLTGYCSt72S2NsS\n" 67 "aDCV/9BhdNGIBOTYGkln8urWd7g2Mj3TwKEAfNTUFpAsrBAlSSLTGYCSt72S2NsS\n"
68 "L/qUxmj1W6X95UHXCo49mSZx3LlaY3mz1L87gq/kK0XpzA3g2uF25jt84RvshsXy\n" 68 "L/qUxmj1W6X95UHXCo49mSZx3LlaY3mz1L87gq/kK0XpzA3g2uF25jt84RvshsXy\n"
69 "clOc+eRrVETqFZqer96WB7kzFTv+qmROQKmW8X4a2A5r5Jl4vRwOz5/rEeB9Qs0K\n" 69 "clOc+eRrVETqFZqer96WB7kzFTv+qmROQKmW8X4a2A5r5Jl4vRwOz5/rEeB9Qs0K\n"
70 "rmK8+5HgvWd80WB8BtfFtZfoY/hHVM8nLD3ELVJrOKiTeIACunQFyT5lV0QkdmSA\n" 70 "rmK8+5HgvWd80WB8BtfFtZfoY/hHVM8nLD3ELVJrOKiTeIACunQFyT5lV0QkdmSA\n"
71 "CGInU7jzs8nu+s2avf6j+eVZUbVJ+dFMApTJgg==\n" 71 "CGInU7jzs8nu+s2avf6j+eVZUbVJ+dFMApTJgg==\n"
72 "-----END CERTIFICATE-----\n"; 72 "-----END CERTIFICATE-----\n";
73 73
74/* test server CA signed certificates */ 74/* test server CA signed certificates */
75const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 75const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
76 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 76 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
77 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 77 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n"
78 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" 78 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n"
79 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n" 79 "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n"
80 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n" 80 "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n"
81 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n" 81 "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n"
82 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n" 82 "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n"
83 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n" 83 "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n"
84 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" 84 "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n"
85 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n" 85 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n"
86 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n" 86 "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n"
87 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n" 87 "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n"
88 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n" 88 "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n"
89 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n" 89 "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n"
90 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n" 90 "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n"
91 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n" 91 "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n"
92 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n" 92 "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n"
93 "-----END CERTIFICATE-----\n"; 93 "-----END CERTIFICATE-----\n";
94 94
95/* test server key */ 95/* test server key */
96const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 96const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
97 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" 97 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n"
98 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" 98 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n"
99 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" 99 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n"
100 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" 100 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n"
101 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" 101 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n"
102 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n" 102 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n"
103 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n" 103 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n"
104 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n" 104 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n"
105 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n" 105 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n"
106 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n" 106 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n"
107 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n" 107 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n"
108 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n" 108 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n"
109 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n" 109 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n"
110 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n" 110 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n"
111 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n" 111 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n"
112 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n" 112 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n"
113 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n" 113 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n"
114 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n" 114 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n"
115 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n" 115 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n"
116 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n" 116 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n"
117 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n" 117 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n"
118 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" 118 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n"
119 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" 119 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n"
120 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" 120 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n"
121 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" 121 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n"
122 "-----END RSA PRIVATE KEY-----\n"; 122 "-----END RSA PRIVATE KEY-----\n";
123 123
124/* test server self signed certificates */ 124/* test server self signed certificates */
125const char srv_self_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 125const char srv_self_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
126 "MIIC+jCCAeSgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 126 "MIIC+jCCAeSgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
127 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 127 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n"
128 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" 128 "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n"
129 "tDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5kPqO1I7Cggzw68Y5\n" 129 "tDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5kPqO1I7Cggzw68Y5\n"
130 "jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qjMpnoGQ/2xmsNG/is\n" 130 "jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qjMpnoGQ/2xmsNG/is\n"
131 "i+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtdkrWxPKwYTgnDEN6D\n" 131 "i+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtdkrWxPKwYTgnDEN6D\n"
132 "JL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFvKRuiU35tU7h7CPbL\n" 132 "JL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFvKRuiU35tU7h7CPbL\n"
133 "4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh1IhbklSh/Z6FA/e8\n" 133 "4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh1IhbklSh/Z6FA/e8\n"
134 "hj0yVo2tdllXuJGVs3PIEwIDAQABo1UwUzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" 134 "hj0yVo2tdllXuJGVs3PIEwIDAQABo1UwUzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n"
135 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFDfU7pAv9LYn\n" 135 "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFDfU7pAv9LYn\n"
136 "n7jb4WHl4+Vgi2FnMAsGCSqGSIb3DQEBBQOCAQEAkaembPQMmv6OOjbIod8zTatr\n" 136 "n7jb4WHl4+Vgi2FnMAsGCSqGSIb3DQEBBQOCAQEAkaembPQMmv6OOjbIod8zTatr\n"
137 "x5Bwkwp3TOE1NRyy2OytzFIYRUkNrZYlcmrxcbNNycIK41CNVXbriFCF8gcmIq9y\n" 137 "x5Bwkwp3TOE1NRyy2OytzFIYRUkNrZYlcmrxcbNNycIK41CNVXbriFCF8gcmIq9y\n"
138 "vaKZn8Gcy+vGggv+1BP9IAPBGKRwSi0wmq9JoGE8hx+qqTpRSdfbM/cps/09hicO\n" 138 "vaKZn8Gcy+vGggv+1BP9IAPBGKRwSi0wmq9JoGE8hx+qqTpRSdfbM/cps/09hicO\n"
139 "0EIR7kWEbvnpMBcMKYOtYE9Gce7rdSMWVAsKc174xn8vW6TxCUvmWFv5DPg5HG1v\n" 139 "0EIR7kWEbvnpMBcMKYOtYE9Gce7rdSMWVAsKc174xn8vW6TxCUvmWFv5DPg5HG1v\n"
140 "y1SUX73qafRo+W6FN4UC/DHfwRhF8RSKEnVbmgDVCs6GHdKBjU2qRgYyj6nWZqK1\n" 140 "y1SUX73qafRo+W6FN4UC/DHfwRhF8RSKEnVbmgDVCs6GHdKBjU2qRgYyj6nWZqK1\n"
141 "XFUTWgia+Fl3D9vlsXaFcSZKA0Bq1eojl0B0AfeYAxTFwPWXscKvt/bXZfH8bg==\n" 141 "XFUTWgia+Fl3D9vlsXaFcSZKA0Bq1eojl0B0AfeYAxTFwPWXscKvt/bXZfH8bg==\n"
142 "-----END CERTIFICATE-----\n"; 142 "-----END CERTIFICATE-----\n";
143 143
144/* test server key */ 144/* test server key */
145const char srv_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 145const char srv_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
146 "MIIEpAIBAAKCAQEAtDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5\n" 146 "MIIEpAIBAAKCAQEAtDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5\n"
147 "kPqO1I7Cggzw68Y5jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qj\n" 147 "kPqO1I7Cggzw68Y5jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qj\n"
148 "MpnoGQ/2xmsNG/isi+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtd\n" 148 "MpnoGQ/2xmsNG/isi+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtd\n"
149 "krWxPKwYTgnDEN6DJL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFv\n" 149 "krWxPKwYTgnDEN6DJL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFv\n"
150 "KRuiU35tU7h7CPbL4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh\n" 150 "KRuiU35tU7h7CPbL4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh\n"
151 "1IhbklSh/Z6FA/e8hj0yVo2tdllXuJGVs3PIEwIDAQABAoIBAAEtcg+LFLGtoxjq\n" 151 "1IhbklSh/Z6FA/e8hj0yVo2tdllXuJGVs3PIEwIDAQABAoIBAAEtcg+LFLGtoxjq\n"
152 "b+tFttBJfbRcfdG6ocYqBGmUXF+MgFs573DHX3sHNOQxlaNHtSgIclF1eYgNZFFt\n" 152 "b+tFttBJfbRcfdG6ocYqBGmUXF+MgFs573DHX3sHNOQxlaNHtSgIclF1eYgNZFFt\n"
153 "VLIoBFTzfEQXoFosPUDoEuqVMeXLttmD7P2jwL780XJLZ4Xj6GY07npq1iGBcEZf\n" 153 "VLIoBFTzfEQXoFosPUDoEuqVMeXLttmD7P2jwL780XJLZ4Xj6GY07npq1iGBcEZf\n"
154 "yCcdoyGkr9jgc5Auyis8DStGg/jfUBC4NBvF0GnuuNPAdYRPKUpKw9EatI+FdMjy\n" 154 "yCcdoyGkr9jgc5Auyis8DStGg/jfUBC4NBvF0GnuuNPAdYRPKUpKw9EatI+FdMjy\n"
155 "BuroD90fhdkK8EwMEVb9P17bdIc1MCIZFpUE9YHjVdK/oxCUhQ8KRfdbI4JU5Zh3\n" 155 "BuroD90fhdkK8EwMEVb9P17bdIc1MCIZFpUE9YHjVdK/oxCUhQ8KRfdbI4JU5Zh3\n"
156 "UtO6Jm2wFuP3VmeVpPvE/C2rxI70pyl6HMSiFGNc0rhJYCQ+yhohWj7nZ67H4vLx\n" 156 "UtO6Jm2wFuP3VmeVpPvE/C2rxI70pyl6HMSiFGNc0rhJYCQ+yhohWj7nZ67H4vLx\n"
157 "plv5LxkCgYEAz7ewou8oFafDAMNoxaqKudvUg+lxXewdLDKaYBF5ACi9uAPCJ+v7\n" 157 "plv5LxkCgYEAz7ewou8oFafDAMNoxaqKudvUg+lxXewdLDKaYBF5ACi9uAPCJ+v7\n"
158 "M5c/fvPFn/XHzo7xaXbtTAH3Z5xzBs+80OsvL+e1Ut4xR+ELRkybknh/s2wQeABk\n" 158 "M5c/fvPFn/XHzo7xaXbtTAH3Z5xzBs+80OsvL+e1Ut4xR+ELRkybknh/s2wQeABk\n"
159 "Kb0vA59ukQGj12LV5phZMaVoXe6KJ7hZnN62d3K6m1wGE/k58i4pPLUCgYEA3hN8\n" 159 "Kb0vA59ukQGj12LV5phZMaVoXe6KJ7hZnN62d3K6m1wGE/k58i4pPLUCgYEA3hN8\n"
160 "G95zW7g0jVdSr+KUeVmephph9yh8Yb+3I3ojwOIv6d45TopGx8pFZlnBAMZf1ZQx\n" 160 "G95zW7g0jVdSr+KUeVmephph9yh8Yb+3I3ojwOIv6d45TopGx8pFZlnBAMZf1ZQx\n"
161 "DIhzJNnaqZy/4w7RNaOGWnPA/5f+MIoHBiLGEEmfHC3lt087Yp9OuwDUHwpETYdV\n" 161 "DIhzJNnaqZy/4w7RNaOGWnPA/5f+MIoHBiLGEEmfHC3lt087Yp9OuwDUHwpETYdV\n"
162 "o+KBCvVh60Et3bZUgF/1k/3YXxn8J5dsmJsjNqcCgYBLflyRa1BrRnTGMz9CEDCp\n" 162 "o+KBCvVh60Et3bZUgF/1k/3YXxn8J5dsmJsjNqcCgYBLflyRa1BrRnTGMz9CEDCp\n"
163 "Si9b3h1Y4Hbd2GppHhCXMTd6yMrpDYhYANGQB3M9Juv+s88j4JhwNoq/uonH4Pqk\n" 163 "Si9b3h1Y4Hbd2GppHhCXMTd6yMrpDYhYANGQB3M9Juv+s88j4JhwNoq/uonH4Pqk\n"
164 "B8Y3qAQr4RuSH0WkwDUOsALhqBX4N1QwI1USAQEDbNAqeP5698X7GD3tXcQSmZrg\n" 164 "B8Y3qAQr4RuSH0WkwDUOsALhqBX4N1QwI1USAQEDbNAqeP5698X7GD3tXcQSmZrg\n"
165 "O8WfdjBCRNjkq4EW9xX/vQKBgQDONtmwJ0iHiu2BseyeVo/4fzfKlgUSNQ4K1rOA\n" 165 "O8WfdjBCRNjkq4EW9xX/vQKBgQDONtmwJ0iHiu2BseyeVo/4fzfKlgUSNQ4K1rOA\n"
166 "xhIdMeu8Bxa/z7caHsGC4SVPSuYCtbE2Kh6BwapChcPJXCD45fgEViiJLuJiwEj1\n" 166 "xhIdMeu8Bxa/z7caHsGC4SVPSuYCtbE2Kh6BwapChcPJXCD45fgEViiJLuJiwEj1\n"
167 "caTpyvNsf1IoffJvCe9ZxtMyX549P8ZOgC3Dt0hN5CBrGLwu2Ox5l+YrqT10pi+5\n" 167 "caTpyvNsf1IoffJvCe9ZxtMyX549P8ZOgC3Dt0hN5CBrGLwu2Ox5l+YrqT10pi+5\n"
168 "JZX1UQKBgQCrcXrdkkDAc/a4+PxNRpJRLcU4fhv8/lr+UWItE8eUe7bd25bTQfQm\n" 168 "JZX1UQKBgQCrcXrdkkDAc/a4+PxNRpJRLcU4fhv8/lr+UWItE8eUe7bd25bTQfQm\n"
169 "VpNKc/kAJ66PjIED6fy3ADhd2y4naT2a24uAgQ/M494J68qLnGh6K4JU/09uxR2v\n" 169 "VpNKc/kAJ66PjIED6fy3ADhd2y4naT2a24uAgQ/M494J68qLnGh6K4JU/09uxR2v\n"
170 "1i2q/4FNLdFFk1XP4iNnTHRLZ+NYr2p5Y9RcvQfTjOauz8Ahav0lyg==\n" 170 "1i2q/4FNLdFFk1XP4iNnTHRLZ+NYr2p5Y9RcvQfTjOauz8Ahav0lyg==\n"
171 "-----END RSA PRIVATE KEY-----\n"; 171 "-----END RSA PRIVATE KEY-----\n";
172 172
173#endif 173#endif
diff --git a/src/testcurl/mhd_has_in_name.h b/src/testcurl/mhd_has_in_name.h
index 50f32cca..aff15e15 100644
--- a/src/testcurl/mhd_has_in_name.h
+++ b/src/testcurl/mhd_has_in_name.h
@@ -39,27 +39,27 @@
39 * name. 39 * name.
40 */ 40 */
41static int 41static int
42has_in_name(const char *prog_name, const char *marker) 42has_in_name (const char *prog_name, const char *marker)
43{ 43{
44 size_t name_pos; 44 size_t name_pos;
45 size_t pos; 45 size_t pos;
46 46
47 if (!prog_name || !marker || !prog_name[0] || !marker[0]) 47 if (! prog_name || ! marker || ! prog_name[0] || ! marker[0])
48 return 0; 48 return 0;
49 49
50 pos = 0; 50 pos = 0;
51 name_pos = 0; 51 name_pos = 0;
52 while (prog_name[pos]) 52 while (prog_name[pos])
53 { 53 {
54 if ('/' == prog_name[pos]) 54 if ('/' == prog_name[pos])
55 name_pos = pos + 1; 55 name_pos = pos + 1;
56#if defined(_WIN32) || defined(__CYGWIN__) 56#if defined(_WIN32) || defined(__CYGWIN__)
57 else if ('\\' == prog_name[pos]) 57 else if ('\\' == prog_name[pos])
58 name_pos = pos + 1; 58 name_pos = pos + 1;
59#endif /* _WIN32 || __CYGWIN__ */ 59#endif /* _WIN32 || __CYGWIN__ */
60 pos++; 60 pos++;
61 } 61 }
62 if (name_pos == pos) 62 if (name_pos == pos)
63 return 0; 63 return 0;
64 return strstr(prog_name + name_pos, marker) != (char*)0; 64 return strstr (prog_name + name_pos, marker) != (char*) 0;
65} 65}
diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c
index a0af70cd..112046d5 100644
--- a/src/testcurl/perf_get.c
+++ b/src/testcurl/perf_get.c
@@ -51,10 +51,10 @@
51#include <sys/socket.h> 51#include <sys/socket.h>
52#endif 52#endif
53 53
54#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 54#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
55#undef CPU_COUNT 55#undef CPU_COUNT
56#endif 56#endif
57#if !defined(CPU_COUNT) 57#if ! defined(CPU_COUNT)
58#define CPU_COUNT 2 58#define CPU_COUNT 2
59#endif 59#endif
60 60
@@ -91,8 +91,8 @@ now ()
91 struct timeval tv; 91 struct timeval tv;
92 92
93 gettimeofday (&tv, NULL); 93 gettimeofday (&tv, NULL);
94 return (((unsigned long long) tv.tv_sec * 1000LL) + 94 return (((unsigned long long) tv.tv_sec * 1000LL)
95 ((unsigned long long) tv.tv_usec / 1000LL)); 95 + ((unsigned long long) tv.tv_usec / 1000LL));
96} 96}
97 97
98 98
@@ -100,7 +100,7 @@ now ()
100 * Start the timer. 100 * Start the timer.
101 */ 101 */
102static void 102static void
103start_timer() 103start_timer ()
104{ 104{
105 start_time = now (); 105 start_time = now ();
106} 106}
@@ -114,17 +114,17 @@ start_timer()
114static void 114static void
115stop (const char *desc) 115stop (const char *desc)
116{ 116{
117 double rps = ((double) (ROUNDS * 1000)) / ((double) (now() - start_time)); 117 double rps = ((double) (ROUNDS * 1000)) / ((double) (now () - start_time));
118 118
119 fprintf (stderr, 119 fprintf (stderr,
120 "Sequential GETs using %s: %f %s\n", 120 "Sequential GETs using %s: %f %s\n",
121 desc, 121 desc,
122 rps, 122 rps,
123 "requests/s"); 123 "requests/s");
124 GAUGER (desc, 124 GAUGER (desc,
125 "Sequential GETs", 125 "Sequential GETs",
126 rps, 126 rps,
127 "requests/s"); 127 "requests/s");
128} 128}
129 129
130 130
@@ -138,8 +138,8 @@ struct CBC
138 138
139static size_t 139static size_t
140copyBuffer (void *ptr, 140copyBuffer (void *ptr,
141 size_t size, size_t nmemb, 141 size_t size, size_t nmemb,
142 void *ctx) 142 void *ctx)
143{ 143{
144 struct CBC *cbc = ctx; 144 struct CBC *cbc = ctx;
145 145
@@ -162,16 +162,16 @@ ahc_echo (void *cls,
162 static int ptr; 162 static int ptr;
163 const char *me = cls; 163 const char *me = cls;
164 int ret; 164 int ret;
165 (void)url;(void)version; /* Unused. Silent compiler warning. */ 165 (void) url; (void) version; /* Unused. Silent compiler warning. */
166 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 166 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
167 167
168 if (0 != strcmp (me, method)) 168 if (0 != strcmp (me, method))
169 return MHD_NO; /* unexpected method */ 169 return MHD_NO; /* unexpected method */
170 if (&ptr != *unused) 170 if (&ptr != *unused)
171 { 171 {
172 *unused = &ptr; 172 *unused = &ptr;
173 return MHD_YES; 173 return MHD_YES;
174 } 174 }
175 *unused = NULL; 175 *unused = NULL;
176 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 176 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
177 if (ret == MHD_NO) 177 if (ret == MHD_NO)
@@ -191,60 +191,64 @@ testInternalGet (int port, int poll_flag)
191 unsigned int i; 191 unsigned int i;
192 char url[64]; 192 char url[64];
193 193
194 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 194 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
195 port = 0; 195 port = 0;
196 196
197 cbc.buf = buf; 197 cbc.buf = buf;
198 cbc.size = 2048; 198 cbc.size = 2048;
199 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 199 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
200 | poll_flag,
200 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 201 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
201 if (d == NULL) 202 if (d == NULL)
202 return 1; 203 return 1;
203 if (0 == port) 204 if (0 == port)
205 {
206 const union MHD_DaemonInfo *dinfo;
207 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
208 if ((NULL == dinfo) ||(0 == dinfo->port) )
204 { 209 {
205 const union MHD_DaemonInfo *dinfo; 210 MHD_stop_daemon (d); return 32;
206 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
207 if (NULL == dinfo || 0 == dinfo->port)
208 { MHD_stop_daemon (d); return 32; }
209 port = (int)dinfo->port;
210 } 211 }
212 port = (int) dinfo->port;
213 }
211 snprintf (url, 214 snprintf (url,
212 sizeof (url), 215 sizeof (url),
213 "http://127.0.0.1:%d/hello_world", 216 "http://127.0.0.1:%d/hello_world",
214 port); 217 port);
215 start_timer (); 218 start_timer ();
216 for (i=0;i<ROUNDS;i++) 219 for (i = 0; i<ROUNDS; i++)
220 {
221 cbc.pos = 0;
222 c = curl_easy_init ();
223 curl_easy_setopt (c, CURLOPT_URL, url);
224 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
225 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
226 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
227 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
228 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
229 if (oneone)
230 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
231 else
232 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
233 /* NOTE: use of CONNECTTIMEOUT without also
234 setting NOSIGNAL results in really weird
235 crashes on my system!*/
236 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
237 if (CURLE_OK != (errornum = curl_easy_perform (c)))
217 { 238 {
218 cbc.pos = 0; 239 fprintf (stderr,
219 c = curl_easy_init (); 240 "curl_easy_perform failed: `%s'\n",
220 curl_easy_setopt (c, CURLOPT_URL, url); 241 curl_easy_strerror (errornum));
221 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
222 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
223 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
224 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
225 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
226 if (oneone)
227 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
228 else
229 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
230 /* NOTE: use of CONNECTTIMEOUT without also
231 setting NOSIGNAL results in really weird
232 crashes on my system!*/
233 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
234 if (CURLE_OK != (errornum = curl_easy_perform (c)))
235 {
236 fprintf (stderr,
237 "curl_easy_perform failed: `%s'\n",
238 curl_easy_strerror (errornum));
239 curl_easy_cleanup (c);
240 MHD_stop_daemon (d);
241 return 2;
242 }
243 curl_easy_cleanup (c); 242 curl_easy_cleanup (c);
243 MHD_stop_daemon (d);
244 return 2;
244 } 245 }
246 curl_easy_cleanup (c);
247 }
245 stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" : 248 stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" :
246 poll_flag == MHD_USE_POLL ? "internal thread with poll()" : 249 poll_flag == MHD_USE_POLL ? "internal thread with poll()" :
247 poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" : "internal thread with select()"); 250 poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" :
251 "internal thread with select()");
248 MHD_stop_daemon (d); 252 MHD_stop_daemon (d);
249 if (cbc.pos != strlen ("/hello_world")) 253 if (cbc.pos != strlen ("/hello_world"))
250 return 4; 254 return 4;
@@ -265,61 +269,68 @@ testMultithreadedGet (int port, int poll_flag)
265 unsigned int i; 269 unsigned int i;
266 char url[64]; 270 char url[64];
267 271
268 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 272 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
269 port = 0; 273 port = 0;
270 274
271 cbc.buf = buf; 275 cbc.buf = buf;
272 cbc.size = 2048; 276 cbc.size = 2048;
273 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 277 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
278 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
279 | poll_flag,
274 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 280 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
275 if (d == NULL) 281 if (d == NULL)
276 return 16; 282 return 16;
277 if (0 == port) 283 if (0 == port)
284 {
285 const union MHD_DaemonInfo *dinfo;
286 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
287 if ((NULL == dinfo) ||(0 == dinfo->port) )
278 { 288 {
279 const union MHD_DaemonInfo *dinfo; 289 MHD_stop_daemon (d); return 32;
280 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
281 if (NULL == dinfo || 0 == dinfo->port)
282 { MHD_stop_daemon (d); return 32; }
283 port = (int)dinfo->port;
284 } 290 }
291 port = (int) dinfo->port;
292 }
285 snprintf (url, 293 snprintf (url,
286 sizeof (url), 294 sizeof (url),
287 "http://127.0.0.1:%d/hello_world", 295 "http://127.0.0.1:%d/hello_world",
288 port); 296 port);
289 start_timer (); 297 start_timer ();
290 for (i=0;i<ROUNDS;i++) 298 for (i = 0; i<ROUNDS; i++)
299 {
300 cbc.pos = 0;
301 c = curl_easy_init ();
302 curl_easy_setopt (c, CURLOPT_URL, url);
303 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
304 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
305 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
306 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
307 if (oneone)
308 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
309 else
310 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
311 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
312 /* NOTE: use of CONNECTTIMEOUT without also
313 setting NOSIGNAL results in really weird
314 crashes on my system! */
315 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
316 if (CURLE_OK != (errornum = curl_easy_perform (c)))
291 { 317 {
292 cbc.pos = 0; 318 fprintf (stderr,
293 c = curl_easy_init (); 319 "curl_easy_perform failed: `%s'\n",
294 curl_easy_setopt (c, CURLOPT_URL, url); 320 curl_easy_strerror (errornum));
295 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
296 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
297 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
298 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
299 if (oneone)
300 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
301 else
302 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
303 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
304 /* NOTE: use of CONNECTTIMEOUT without also
305 setting NOSIGNAL results in really weird
306 crashes on my system! */
307 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
308 if (CURLE_OK != (errornum = curl_easy_perform (c)))
309 {
310 fprintf (stderr,
311 "curl_easy_perform failed: `%s'\n",
312 curl_easy_strerror (errornum));
313 curl_easy_cleanup (c);
314 MHD_stop_daemon (d);
315 return 32;
316 }
317 curl_easy_cleanup (c); 321 curl_easy_cleanup (c);
322 MHD_stop_daemon (d);
323 return 32;
318 } 324 }
319 stop ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto' and thread per connection" : 325 curl_easy_cleanup (c);
320 (poll_flag & MHD_USE_POLL) ? "internal thread with poll() and thread per connection" : 326 }
321 (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll and thread per connection" : 327 stop ((poll_flag & MHD_USE_AUTO) ?
322 "internal thread with select() and thread per connection"); 328 "internal thread with 'auto' and thread per connection" :
329 (poll_flag & MHD_USE_POLL) ?
330 "internal thread with poll() and thread per connection" :
331 (poll_flag & MHD_USE_EPOLL) ?
332 "internal thread with epoll and thread per connection" :
333 "internal thread with select() and thread per connection");
323 MHD_stop_daemon (d); 334 MHD_stop_daemon (d);
324 if (cbc.pos != strlen ("/hello_world")) 335 if (cbc.pos != strlen ("/hello_world"))
325 return 64; 336 return 64;
@@ -339,61 +350,65 @@ testMultithreadedPoolGet (int port, int poll_flag)
339 unsigned int i; 350 unsigned int i;
340 char url[64]; 351 char url[64];
341 352
342 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 353 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
343 port = 0; 354 port = 0;
344 355
345 cbc.buf = buf; 356 cbc.buf = buf;
346 cbc.size = 2048; 357 cbc.size = 2048;
347 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 358 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
359 | poll_flag,
348 port, NULL, NULL, &ahc_echo, "GET", 360 port, NULL, NULL, &ahc_echo, "GET",
349 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); 361 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
350 if (d == NULL) 362 if (d == NULL)
351 return 16; 363 return 16;
352 if (0 == port) 364 if (0 == port)
365 {
366 const union MHD_DaemonInfo *dinfo;
367 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
368 if ((NULL == dinfo) ||(0 == dinfo->port) )
353 { 369 {
354 const union MHD_DaemonInfo *dinfo; 370 MHD_stop_daemon (d); return 32;
355 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
356 if (NULL == dinfo || 0 == dinfo->port)
357 { MHD_stop_daemon (d); return 32; }
358 port = (int)dinfo->port;
359 } 371 }
372 port = (int) dinfo->port;
373 }
360 snprintf (url, 374 snprintf (url,
361 sizeof (url), 375 sizeof (url),
362 "http://127.0.0.1:%d/hello_world", 376 "http://127.0.0.1:%d/hello_world",
363 port); 377 port);
364 start_timer (); 378 start_timer ();
365 for (i=0;i<ROUNDS;i++) 379 for (i = 0; i<ROUNDS; i++)
380 {
381 cbc.pos = 0;
382 c = curl_easy_init ();
383 curl_easy_setopt (c, CURLOPT_URL, url);
384 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
385 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
386 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
387 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
388 if (oneone)
389 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
390 else
391 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
392 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
393 /* NOTE: use of CONNECTTIMEOUT without also
394 setting NOSIGNAL results in really weird
395 crashes on my system!*/
396 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
397 if (CURLE_OK != (errornum = curl_easy_perform (c)))
366 { 398 {
367 cbc.pos = 0; 399 fprintf (stderr,
368 c = curl_easy_init (); 400 "curl_easy_perform failed: `%s'\n",
369 curl_easy_setopt (c, CURLOPT_URL, url); 401 curl_easy_strerror (errornum));
370 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
371 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
372 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
373 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
374 if (oneone)
375 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
376 else
377 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
378 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
379 /* NOTE: use of CONNECTTIMEOUT without also
380 setting NOSIGNAL results in really weird
381 crashes on my system!*/
382 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
383 if (CURLE_OK != (errornum = curl_easy_perform (c)))
384 {
385 fprintf (stderr,
386 "curl_easy_perform failed: `%s'\n",
387 curl_easy_strerror (errornum));
388 curl_easy_cleanup (c);
389 MHD_stop_daemon (d);
390 return 32;
391 }
392 curl_easy_cleanup (c); 402 curl_easy_cleanup (c);
403 MHD_stop_daemon (d);
404 return 32;
393 } 405 }
406 curl_easy_cleanup (c);
407 }
394 stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : 408 stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" :
395 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : 409 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" :
396 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" : "internal thread pool with select()"); 410 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" :
411 "internal thread pool with select()");
397 MHD_stop_daemon (d); 412 MHD_stop_daemon (d);
398 if (cbc.pos != strlen ("/hello_world")) 413 if (cbc.pos != strlen ("/hello_world"))
399 return 64; 414 return 64;
@@ -427,7 +442,7 @@ testExternalGet (int port)
427 unsigned int i; 442 unsigned int i;
428 char url[64]; 443 char url[64];
429 444
430 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 445 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
431 port = 0; 446 port = 0;
432 447
433 multi = NULL; 448 multi = NULL;
@@ -440,13 +455,15 @@ testExternalGet (int port)
440 if (NULL == d) 455 if (NULL == d)
441 return 256; 456 return 256;
442 if (0 == port) 457 if (0 == port)
458 {
459 const union MHD_DaemonInfo *dinfo;
460 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
461 if ((NULL == dinfo) ||(0 == dinfo->port) )
443 { 462 {
444 const union MHD_DaemonInfo *dinfo; 463 MHD_stop_daemon (d); return 32;
445 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
446 if (NULL == dinfo || 0 == dinfo->port)
447 { MHD_stop_daemon (d); return 32; }
448 port = (int)dinfo->port;
449 } 464 }
465 port = (int) dinfo->port;
466 }
450 snprintf (url, 467 snprintf (url,
451 sizeof (url), 468 sizeof (url),
452 "http://127.0.0.1:%d/hello_world", 469 "http://127.0.0.1:%d/hello_world",
@@ -454,116 +471,119 @@ testExternalGet (int port)
454 start_timer (); 471 start_timer ();
455 multi = curl_multi_init (); 472 multi = curl_multi_init ();
456 if (multi == NULL) 473 if (multi == NULL)
474 {
475 MHD_stop_daemon (d);
476 return 512;
477 }
478 for (i = 0; i<ROUNDS; i++)
479 {
480 cbc.pos = 0;
481 c = curl_easy_init ();
482 curl_easy_setopt (c, CURLOPT_URL, url);
483 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
484 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
485 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
486 if (oneone)
487 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
488 else
489 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
490 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
491 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
492 /* NOTE: use of CONNECTTIMEOUT without also
493 setting NOSIGNAL results in really weird
494 crashes on my system! */
495 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
496 mret = curl_multi_add_handle (multi, c);
497 if (mret != CURLM_OK)
457 { 498 {
499 curl_multi_cleanup (multi);
500 curl_easy_cleanup (c);
458 MHD_stop_daemon (d); 501 MHD_stop_daemon (d);
459 return 512; 502 return 1024;
460 } 503 }
461 for (i=0;i<ROUNDS;i++) 504 start = time (NULL);
505 while ((time (NULL) - start < 5) && (c != NULL))
462 { 506 {
463 cbc.pos = 0; 507 maxsock = MHD_INVALID_SOCKET;
464 c = curl_easy_init (); 508 maxposixs = -1;
465 curl_easy_setopt (c, CURLOPT_URL, url); 509 FD_ZERO (&rs);
466 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 510 FD_ZERO (&ws);
467 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 511 FD_ZERO (&es);
468 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 512 curl_multi_perform (multi, &running);
469 if (oneone) 513 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
470 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
471 else
472 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
473 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
474 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
475 /* NOTE: use of CONNECTTIMEOUT without also
476 setting NOSIGNAL results in really weird
477 crashes on my system! */
478 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
479 mret = curl_multi_add_handle (multi, c);
480 if (mret != CURLM_OK) 514 if (mret != CURLM_OK)
481 { 515 {
482 curl_multi_cleanup (multi); 516 curl_multi_remove_handle (multi, c);
483 curl_easy_cleanup (c); 517 curl_multi_cleanup (multi);
484 MHD_stop_daemon (d); 518 curl_easy_cleanup (c);
485 return 1024; 519 MHD_stop_daemon (d);
486 } 520 return 2048;
487 start = time (NULL); 521 }
488 while ((time (NULL) - start < 5) && (c != NULL)) 522 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
489 { 523 {
490 maxsock = MHD_INVALID_SOCKET; 524 curl_multi_remove_handle (multi, c);
491 maxposixs = -1; 525 curl_multi_cleanup (multi);
492 FD_ZERO (&rs); 526 curl_easy_cleanup (c);
493 FD_ZERO (&ws); 527 MHD_stop_daemon (d);
494 FD_ZERO (&es); 528 return 4096;
495 curl_multi_perform (multi, &running); 529 }
496 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); 530 tv.tv_sec = 0;
497 if (mret != CURLM_OK) 531 tv.tv_usec = 1000;
498 { 532 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
499 curl_multi_remove_handle (multi, c); 533 {
500 curl_multi_cleanup (multi);
501 curl_easy_cleanup (c);
502 MHD_stop_daemon (d);
503 return 2048;
504 }
505 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
506 {
507 curl_multi_remove_handle (multi, c);
508 curl_multi_cleanup (multi);
509 curl_easy_cleanup (c);
510 MHD_stop_daemon (d);
511 return 4096;
512 }
513 tv.tv_sec = 0;
514 tv.tv_usec = 1000;
515 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
516 {
517#ifdef MHD_POSIX_SOCKETS 534#ifdef MHD_POSIX_SOCKETS
518 if (EINTR != errno) 535 if (EINTR != errno)
519 abort (); 536 abort ();
520#else 537#else
521 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 538 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
522 abort (); 539 ws.
523 Sleep (1000); 540 fd_count)
541 ||(0 != es.fd_count) )
542 abort ();
543 Sleep (1000);
524#endif 544#endif
525 } 545 }
526 curl_multi_perform (multi, &running); 546 curl_multi_perform (multi, &running);
527 if (running == 0) 547 if (running == 0)
528 { 548 {
529 msg = curl_multi_info_read (multi, &running); 549 msg = curl_multi_info_read (multi, &running);
530 if (msg == NULL) 550 if (msg == NULL)
531 break; 551 break;
532 if (msg->msg == CURLMSG_DONE) 552 if (msg->msg == CURLMSG_DONE)
533 { 553 {
534 if (msg->data.result != CURLE_OK) 554 if (msg->data.result != CURLE_OK)
535 printf ("%s failed at %s:%d: `%s'\n", 555 printf ("%s failed at %s:%d: `%s'\n",
536 "curl_multi_perform", 556 "curl_multi_perform",
537 __FILE__, 557 __FILE__,
538 __LINE__, curl_easy_strerror (msg->data.result)); 558 __LINE__, curl_easy_strerror (msg->data.result));
539 curl_multi_remove_handle (multi, c); 559 curl_multi_remove_handle (multi, c);
540 curl_easy_cleanup (c); 560 curl_easy_cleanup (c);
541 c = NULL; 561 c = NULL;
542 } 562 }
543 } 563 }
544 /* two possibilities here; as select sets are 564 /* two possibilities here; as select sets are
545 tiny, this makes virtually no difference 565 tiny, this makes virtually no difference
546 in actual runtime right now, even though the 566 in actual runtime right now, even though the
547 number of select calls is virtually cut in half 567 number of select calls is virtually cut in half
548 (and 'select' is the most expensive of our system 568 (and 'select' is the most expensive of our system
549 calls according to 'strace') */ 569 calls according to 'strace') */
550 if (0) 570 if (0)
551 MHD_run (d); 571 MHD_run (d);
552 else 572 else
553 MHD_run_from_select (d, &rs, &ws, &es); 573 MHD_run_from_select (d, &rs, &ws, &es);
554 }
555 if (NULL != c)
556 {
557 curl_multi_remove_handle (multi, c);
558 curl_easy_cleanup (c);
559 fprintf (stderr, "Timeout!?\n");
560 }
561 } 574 }
562 stop ("external select"); 575 if (NULL != c)
563 if (multi != NULL)
564 { 576 {
565 curl_multi_cleanup (multi); 577 curl_multi_remove_handle (multi, c);
578 curl_easy_cleanup (c);
579 fprintf (stderr, "Timeout!?\n");
566 } 580 }
581 }
582 stop ("external select");
583 if (multi != NULL)
584 {
585 curl_multi_cleanup (multi);
586 }
567 MHD_stop_daemon (d); 587 MHD_stop_daemon (d);
568 if (cbc.pos != strlen ("/hello_world")) 588 if (cbc.pos != strlen ("/hello_world"))
569 return 8192; 589 return 8192;
@@ -578,9 +598,9 @@ main (int argc, char *const *argv)
578{ 598{
579 unsigned int errorCount = 0; 599 unsigned int errorCount = 0;
580 int port = 1130; 600 int port = 1130;
581 (void)argc; /* Unused. Silent compiler warning. */ 601 (void) argc; /* Unused. Silent compiler warning. */
582 602
583 if (NULL == argv || 0 == argv[0]) 603 if ((NULL == argv)||(0 == argv[0]))
584 return 99; 604 return 99;
585 oneone = has_in_name (argv[0], "11"); 605 oneone = has_in_name (argv[0], "11");
586 if (oneone) 606 if (oneone)
@@ -588,29 +608,29 @@ main (int argc, char *const *argv)
588 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 608 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
589 return 2; 609 return 2;
590 response = MHD_create_response_from_buffer (strlen ("/hello_world"), 610 response = MHD_create_response_from_buffer (strlen ("/hello_world"),
591 "/hello_world", 611 "/hello_world",
592 MHD_RESPMEM_MUST_COPY); 612 MHD_RESPMEM_MUST_COPY);
593 errorCount += testExternalGet (port++); 613 errorCount += testExternalGet (port++);
594 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 614 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
615 {
616 errorCount += testInternalGet (port++, MHD_USE_AUTO);
617 errorCount += testMultithreadedGet (port++, MHD_USE_AUTO);
618 errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO);
619 errorCount += testInternalGet (port++, 0);
620 errorCount += testMultithreadedGet (port++, 0);
621 errorCount += testMultithreadedPoolGet (port++, 0);
622 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
623 {
624 errorCount += testInternalGet (port++, MHD_USE_POLL);
625 errorCount += testMultithreadedGet (port++, MHD_USE_POLL);
626 errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL);
627 }
628 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
595 { 629 {
596 errorCount += testInternalGet (port++, MHD_USE_AUTO); 630 errorCount += testInternalGet (port++, MHD_USE_EPOLL);
597 errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); 631 errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL);
598 errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO);
599 errorCount += testInternalGet (port++, 0);
600 errorCount += testMultithreadedGet (port++, 0);
601 errorCount += testMultithreadedPoolGet (port++, 0);
602 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
603 {
604 errorCount += testInternalGet(port++, MHD_USE_POLL);
605 errorCount += testMultithreadedGet(port++, MHD_USE_POLL);
606 errorCount += testMultithreadedPoolGet(port++, MHD_USE_POLL);
607 }
608 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
609 {
610 errorCount += testInternalGet(port++, MHD_USE_EPOLL);
611 errorCount += testMultithreadedPoolGet(port++, MHD_USE_EPOLL);
612 }
613 } 632 }
633 }
614 MHD_destroy_response (response); 634 MHD_destroy_response (response);
615 if (errorCount != 0) 635 if (errorCount != 0)
616 fprintf (stderr, "Error (code: %u)\n", errorCount); 636 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c
index 336a1d1e..b4cd6d8d 100644
--- a/src/testcurl/perf_get_concurrent.c
+++ b/src/testcurl/perf_get_concurrent.c
@@ -43,10 +43,10 @@
43#include "gauger.h" 43#include "gauger.h"
44#include "mhd_has_in_name.h" 44#include "mhd_has_in_name.h"
45 45
46#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 46#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
47#undef CPU_COUNT 47#undef CPU_COUNT
48#endif 48#endif
49#if !defined(CPU_COUNT) 49#if ! defined(CPU_COUNT)
50#define CPU_COUNT 2 50#define CPU_COUNT 2
51#endif 51#endif
52 52
@@ -98,8 +98,8 @@ now ()
98 struct timeval tv; 98 struct timeval tv;
99 99
100 gettimeofday (&tv, NULL); 100 gettimeofday (&tv, NULL);
101 return (((unsigned long long) tv.tv_sec * 1000LL) + 101 return (((unsigned long long) tv.tv_sec * 1000LL)
102 ((unsigned long long) tv.tv_usec / 1000LL)); 102 + ((unsigned long long) tv.tv_usec / 1000LL));
103} 103}
104 104
105 105
@@ -107,7 +107,7 @@ now ()
107 * Start the timer. 107 * Start the timer.
108 */ 108 */
109static void 109static void
110start_timer() 110start_timer ()
111{ 111{
112 start_time = now (); 112 start_time = now ();
113} 113}
@@ -121,26 +121,27 @@ start_timer()
121static void 121static void
122stop (const char *desc) 122stop (const char *desc)
123{ 123{
124 double rps = ((double) (PAR * ROUNDS * 1000)) / ((double) (now() - start_time)); 124 double rps = ((double) (PAR * ROUNDS * 1000)) / ((double) (now ()
125 - start_time));
125 126
126 fprintf (stderr, 127 fprintf (stderr,
127 "Parallel GETs using %s: %f %s\n", 128 "Parallel GETs using %s: %f %s\n",
128 desc, 129 desc,
129 rps, 130 rps,
130 "requests/s"); 131 "requests/s");
131 GAUGER (desc, 132 GAUGER (desc,
132 "Parallel GETs", 133 "Parallel GETs",
133 rps, 134 rps,
134 "requests/s"); 135 "requests/s");
135} 136}
136 137
137 138
138static size_t 139static size_t
139copyBuffer (void *ptr, 140copyBuffer (void *ptr,
140 size_t size, size_t nmemb, 141 size_t size, size_t nmemb,
141 void *ctx) 142 void *ctx)
142{ 143{
143 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 144 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
144 return size * nmemb; 145 return size * nmemb;
145} 146}
146 147
@@ -157,16 +158,16 @@ ahc_echo (void *cls,
157 static int ptr; 158 static int ptr;
158 const char *me = cls; 159 const char *me = cls;
159 int ret; 160 int ret;
160 (void)url;(void)version; /* Unused. Silent compiler warning. */ 161 (void) url; (void) version; /* Unused. Silent compiler warning. */
161 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 162 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
162 163
163 if (0 != strcmp (me, method)) 164 if (0 != strcmp (me, method))
164 return MHD_NO; /* unexpected method */ 165 return MHD_NO; /* unexpected method */
165 if (&ptr != *unused) 166 if (&ptr != *unused)
166 { 167 {
167 *unused = &ptr; 168 *unused = &ptr;
168 return MHD_YES; 169 return MHD_YES;
169 } 170 }
170 *unused = NULL; 171 *unused = NULL;
171 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 172 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
172 if (ret == MHD_NO) 173 if (ret == MHD_NO)
@@ -181,7 +182,7 @@ thread_gets (void *param)
181 CURL *c; 182 CURL *c;
182 CURLcode errornum; 183 CURLcode errornum;
183 unsigned int i; 184 unsigned int i;
184 char * const url = (char*) param; 185 char *const url = (char*) param;
185 186
186 c = curl_easy_init (); 187 c = curl_easy_init ();
187 curl_easy_setopt (c, CURLOPT_URL, url); 188 curl_easy_setopt (c, CURLOPT_URL, url);
@@ -198,17 +199,17 @@ thread_gets (void *param)
198 setting NOSIGNAL results in really weird 199 setting NOSIGNAL results in really weird
199 crashes on my system! */ 200 crashes on my system! */
200 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 201 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
201 for (i=0;i<ROUNDS;i++) 202 for (i = 0; i<ROUNDS; i++)
203 {
204 if (CURLE_OK != (errornum = curl_easy_perform (c)))
202 { 205 {
203 if (CURLE_OK != (errornum = curl_easy_perform (c))) 206 fprintf (stderr,
204 { 207 "curl_easy_perform failed: `%s'\n",
205 fprintf (stderr, 208 curl_easy_strerror (errornum));
206 "curl_easy_perform failed: `%s'\n", 209 curl_easy_cleanup (c);
207 curl_easy_strerror (errornum)); 210 return "curl error";
208 curl_easy_cleanup (c);
209 return "curl error";
210 }
211 } 211 }
212 }
212 curl_easy_cleanup (c); 213 curl_easy_cleanup (c);
213 214
214 return NULL; 215 return NULL;
@@ -216,34 +217,34 @@ thread_gets (void *param)
216 217
217 218
218static void * 219static void *
219do_gets (void * param) 220do_gets (void *param)
220{ 221{
221 int j; 222 int j;
222 pthread_t par[PAR]; 223 pthread_t par[PAR];
223 char url[64]; 224 char url[64];
224 int port = (int)(intptr_t)param; 225 int port = (int) (intptr_t) param;
225 char *err = NULL; 226 char *err = NULL;
226 227
227 snprintf (url, 228 snprintf (url,
228 sizeof (url), 229 sizeof (url),
229 "http://127.0.0.1:%d/hello_world", 230 "http://127.0.0.1:%d/hello_world",
230 port); 231 port);
231 for (j=0;j<PAR;j++) 232 for (j = 0; j<PAR; j++)
232 { 233 {
233 if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) 234 if (0 != pthread_create (&par[j], NULL, &thread_gets, (void*) url))
234 {
235 for (j--; j >= 0; j--)
236 pthread_join(par[j], NULL);
237 return "pthread_create error";
238 }
239 }
240 for (j=0;j<PAR;j++)
241 { 235 {
242 char *ret_val; 236 for (j--; j >= 0; j--)
243 if (0 != pthread_join(par[j], (void**)&ret_val) || 237 pthread_join (par[j], NULL);
244 NULL != ret_val) 238 return "pthread_create error";
245 err = ret_val;
246 } 239 }
240 }
241 for (j = 0; j<PAR; j++)
242 {
243 char *ret_val;
244 if ((0 != pthread_join (par[j], (void**) &ret_val)) ||
245 (NULL != ret_val) )
246 err = ret_val;
247 }
247 signal_done = 1; 248 signal_done = 1;
248 return err; 249 return err;
249} 250}
@@ -253,38 +254,45 @@ static int
253testInternalGet (int port, int poll_flag) 254testInternalGet (int port, int poll_flag)
254{ 255{
255 struct MHD_Daemon *d; 256 struct MHD_Daemon *d;
256 const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto'" : 257 const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ?
257 (poll_flag & MHD_USE_POLL) ? "internal thread with poll()" : 258 "internal thread with 'auto'" :
258 (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll" : "internal thread with select()"); 259 (poll_flag & MHD_USE_POLL) ?
259 const char * ret_val; 260 "internal thread with poll()" :
260 261 (poll_flag & MHD_USE_EPOLL) ?
261 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 262 "internal thread with epoll" :
263 "internal thread with select()");
264 const char *ret_val;
265
266 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
262 port = 0; 267 port = 0;
263 268
264 signal_done = 0; 269 signal_done = 0;
265 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 270 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
271 | poll_flag,
266 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 272 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
267 if (d == NULL) 273 if (d == NULL)
268 return 1; 274 return 1;
269 if (0 == port) 275 if (0 == port)
276 {
277 const union MHD_DaemonInfo *dinfo;
278 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
279 if ((NULL == dinfo) ||(0 == dinfo->port) )
270 { 280 {
271 const union MHD_DaemonInfo *dinfo; 281 MHD_stop_daemon (d); return 32;
272 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
273 if (NULL == dinfo || 0 == dinfo->port)
274 { MHD_stop_daemon (d); return 32; }
275 port = (int)dinfo->port;
276 } 282 }
283 port = (int) dinfo->port;
284 }
277 start_timer (); 285 start_timer ();
278 ret_val = do_gets ((void*)(intptr_t)port); 286 ret_val = do_gets ((void*) (intptr_t) port);
279 if (!ret_val) 287 if (! ret_val)
280 stop (test_desc); 288 stop (test_desc);
281 MHD_stop_daemon (d); 289 MHD_stop_daemon (d);
282 if (ret_val) 290 if (ret_val)
283 { 291 {
284 fprintf (stderr, 292 fprintf (stderr,
285 "Error performing %s test: %s\n", test_desc, ret_val); 293 "Error performing %s test: %s\n", test_desc, ret_val);
286 return 4; 294 return 4;
287 } 295 }
288 return 0; 296 return 0;
289} 297}
290 298
@@ -293,39 +301,49 @@ static int
293testMultithreadedGet (int port, int poll_flag) 301testMultithreadedGet (int port, int poll_flag)
294{ 302{
295 struct MHD_Daemon *d; 303 struct MHD_Daemon *d;
296 const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto' and thread per connection" : 304 const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ?
297 (poll_flag & MHD_USE_POLL) ? "internal thread with poll() and thread per connection" : 305 "internal thread with 'auto' and thread per connection"
298 (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll and thread per connection" 306 :
299 : "internal thread with select() and thread per connection"); 307 (poll_flag & MHD_USE_POLL) ?
300 const char * ret_val; 308 "internal thread with poll() and thread per connection"
301 309 :
302 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 310 (poll_flag & MHD_USE_EPOLL) ?
311 "internal thread with epoll and thread per connection"
312 :
313 "internal thread with select() and thread per connection");
314 const char *ret_val;
315
316 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
303 port = 0; 317 port = 0;
304 318
305 signal_done = 0; 319 signal_done = 0;
306 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 320 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
321 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
322 | poll_flag,
307 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 323 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
308 if (d == NULL) 324 if (d == NULL)
309 return 16; 325 return 16;
310 if (0 == port) 326 if (0 == port)
327 {
328 const union MHD_DaemonInfo *dinfo;
329 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
330 if ((NULL == dinfo) ||(0 == dinfo->port) )
311 { 331 {
312 const union MHD_DaemonInfo *dinfo; 332 MHD_stop_daemon (d); return 32;
313 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
314 if (NULL == dinfo || 0 == dinfo->port)
315 { MHD_stop_daemon (d); return 32; }
316 port = (int)dinfo->port;
317 } 333 }
334 port = (int) dinfo->port;
335 }
318 start_timer (); 336 start_timer ();
319 ret_val = do_gets ((void*)(intptr_t)port); 337 ret_val = do_gets ((void*) (intptr_t) port);
320 if (!ret_val) 338 if (! ret_val)
321 stop (test_desc); 339 stop (test_desc);
322 MHD_stop_daemon (d); 340 MHD_stop_daemon (d);
323 if (ret_val) 341 if (ret_val)
324 { 342 {
325 fprintf (stderr, 343 fprintf (stderr,
326 "Error performing %s test: %s\n", test_desc, ret_val); 344 "Error performing %s test: %s\n", test_desc, ret_val);
327 return 4; 345 return 4;
328 } 346 }
329 return 0; 347 return 0;
330} 348}
331 349
@@ -334,39 +352,46 @@ static int
334testMultithreadedPoolGet (int port, int poll_flag) 352testMultithreadedPoolGet (int port, int poll_flag)
335{ 353{
336 struct MHD_Daemon *d; 354 struct MHD_Daemon *d;
337 const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : 355 const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ?
338 (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : 356 "internal thread pool with 'auto'" :
339 (poll_flag & MHD_USE_EPOLL) ? "internal thread poll with epoll" : "internal thread pool with select()"); 357 (poll_flag & MHD_USE_POLL) ?
340 const char * ret_val; 358 "internal thread pool with poll()" :
341 359 (poll_flag & MHD_USE_EPOLL) ?
342 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 360 "internal thread poll with epoll" :
361 "internal thread pool with select()");
362 const char *ret_val;
363
364 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
343 port = 0; 365 port = 0;
344 366
345 signal_done = 0 ; 367 signal_done = 0;
346 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 368 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
369 | poll_flag,
347 port, NULL, NULL, &ahc_echo, "GET", 370 port, NULL, NULL, &ahc_echo, "GET",
348 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); 371 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
349 if (d == NULL) 372 if (d == NULL)
350 return 16; 373 return 16;
351 if (0 == port) 374 if (0 == port)
375 {
376 const union MHD_DaemonInfo *dinfo;
377 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
378 if ((NULL == dinfo) ||(0 == dinfo->port) )
352 { 379 {
353 const union MHD_DaemonInfo *dinfo; 380 MHD_stop_daemon (d); return 32;
354 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
355 if (NULL == dinfo || 0 == dinfo->port)
356 { MHD_stop_daemon (d); return 32; }
357 port = (int)dinfo->port;
358 } 381 }
382 port = (int) dinfo->port;
383 }
359 start_timer (); 384 start_timer ();
360 ret_val = do_gets ((void*)(intptr_t)port); 385 ret_val = do_gets ((void*) (intptr_t) port);
361 if (!ret_val) 386 if (! ret_val)
362 stop (test_desc); 387 stop (test_desc);
363 MHD_stop_daemon (d); 388 MHD_stop_daemon (d);
364 if (ret_val) 389 if (ret_val)
365 { 390 {
366 fprintf (stderr, 391 fprintf (stderr,
367 "Error performing %s test: %s\n", test_desc, ret_val); 392 "Error performing %s test: %s\n", test_desc, ret_val);
368 return 4; 393 return 4;
369 } 394 }
370 return 0; 395 return 0;
371} 396}
372 397
@@ -386,7 +411,7 @@ testExternalGet (int port)
386 char *ret_val; 411 char *ret_val;
387 int ret = 0; 412 int ret = 0;
388 413
389 if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) 414 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
390 port = 0; 415 port = 0;
391 416
392 signal_done = 0; 417 signal_done = 0;
@@ -395,66 +420,71 @@ testExternalGet (int port)
395 if (d == NULL) 420 if (d == NULL)
396 return 256; 421 return 256;
397 if (0 == port) 422 if (0 == port)
423 {
424 const union MHD_DaemonInfo *dinfo;
425 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
426 if ((NULL == dinfo) ||(0 == dinfo->port) )
398 { 427 {
399 const union MHD_DaemonInfo *dinfo; 428 MHD_stop_daemon (d); return 32;
400 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
401 if (NULL == dinfo || 0 == dinfo->port)
402 { MHD_stop_daemon (d); return 32; }
403 port = (int)dinfo->port;
404 } 429 }
430 port = (int) dinfo->port;
431 }
405 if (0 != pthread_create (&pid, NULL, 432 if (0 != pthread_create (&pid, NULL,
406 &do_gets, (void*)(intptr_t)port)) 433 &do_gets, (void*) (intptr_t) port))
407 { 434 {
408 MHD_stop_daemon(d); 435 MHD_stop_daemon (d);
409 return 512; 436 return 512;
410 } 437 }
411 start_timer (); 438 start_timer ();
412 439
413 while (0 == signal_done) 440 while (0 == signal_done)
441 {
442 max = 0;
443 FD_ZERO (&rs);
444 FD_ZERO (&ws);
445 FD_ZERO (&es);
446 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
447 {
448 MHD_stop_daemon (d);
449 return 4096;
450 }
451 tret = MHD_get_timeout (d, &tt);
452 if (MHD_YES != tret)
453 tt = 1;
454 tv.tv_sec = tt / 1000;
455 tv.tv_usec = 1000 * (tt % 1000);
456 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
414 { 457 {
415 max = 0;
416 FD_ZERO (&rs);
417 FD_ZERO (&ws);
418 FD_ZERO (&es);
419 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
420 {
421 MHD_stop_daemon (d);
422 return 4096;
423 }
424 tret = MHD_get_timeout (d, &tt);
425 if (MHD_YES != tret) tt = 1;
426 tv.tv_sec = tt / 1000;
427 tv.tv_usec = 1000 * (tt % 1000);
428 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
429 {
430#ifdef MHD_POSIX_SOCKETS 458#ifdef MHD_POSIX_SOCKETS
431 if (EINTR == errno) 459 if (EINTR == errno)
432 continue; 460 continue;
433 fprintf (stderr, 461 fprintf (stderr,
434 "select failed: %s\n", 462 "select failed: %s\n",
435 strerror (errno)); 463 strerror (errno));
436#else 464#else
437 if (WSAEINVAL == WSAGetLastError() && 0 == rs.fd_count && 0 == ws.fd_count && 0 == es.fd_count) 465 if ((WSAEINVAL == WSAGetLastError ()) &&(0 == rs.fd_count) &&(0 ==
438 { 466 ws.fd_count)
439 Sleep (1000); 467 &&(0 == es.fd_count) )
440 continue; 468 {
441 } 469 Sleep (1000);
470 continue;
471 }
442#endif 472#endif
443 ret |= 1024; 473 ret |= 1024;
444 break; 474 break;
445 }
446 MHD_run_from_select(d, &rs, &ws, &es);
447 } 475 }
476 MHD_run_from_select (d, &rs, &ws, &es);
477 }
448 478
449 stop ("external select"); 479 stop ("external select");
450 MHD_stop_daemon (d); 480 MHD_stop_daemon (d);
451 if (0 != pthread_join(pid, (void**)&ret_val) || 481 if ((0 != pthread_join (pid, (void**) &ret_val))||
452 NULL != ret_val) 482 (NULL != ret_val) )
453 { 483 {
454 fprintf (stderr, 484 fprintf (stderr,
455 "%s\n", ret_val); 485 "%s\n", ret_val);
456 ret |= 8; 486 ret |= 8;
457 } 487 }
458 if (ret) 488 if (ret)
459 fprintf (stderr, "Error performing test.\n"); 489 fprintf (stderr, "Error performing test.\n");
460 return 0; 490 return 0;
@@ -466,9 +496,9 @@ main (int argc, char *const *argv)
466{ 496{
467 unsigned int errorCount = 0; 497 unsigned int errorCount = 0;
468 int port = 1100; 498 int port = 1100;
469 (void)argc; /* Unused. Silent compiler warning. */ 499 (void) argc; /* Unused. Silent compiler warning. */
470 500
471 if (NULL == argv || 0 == argv[0]) 501 if ((NULL == argv)||(0 == argv[0]))
472 return 99; 502 return 99;
473 oneone = has_in_name (argv[0], "11"); 503 oneone = has_in_name (argv[0], "11");
474 if (oneone) 504 if (oneone)
@@ -476,8 +506,8 @@ main (int argc, char *const *argv)
476 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 506 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
477 return 2; 507 return 2;
478 response = MHD_create_response_from_buffer (strlen ("/hello_world"), 508 response = MHD_create_response_from_buffer (strlen ("/hello_world"),
479 "/hello_world", 509 "/hello_world",
480 MHD_RESPMEM_MUST_COPY); 510 MHD_RESPMEM_MUST_COPY);
481 errorCount += testInternalGet (port++, 0); 511 errorCount += testInternalGet (port++, 0);
482 errorCount += testMultithreadedGet (port++, 0); 512 errorCount += testMultithreadedGet (port++, 0);
483 errorCount += testMultithreadedPoolGet (port++, 0); 513 errorCount += testMultithreadedPoolGet (port++, 0);
@@ -485,17 +515,17 @@ main (int argc, char *const *argv)
485 errorCount += testInternalGet (port++, MHD_USE_AUTO); 515 errorCount += testInternalGet (port++, MHD_USE_AUTO);
486 errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); 516 errorCount += testMultithreadedGet (port++, MHD_USE_AUTO);
487 errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); 517 errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO);
488 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) 518 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
489 { 519 {
490 errorCount += testInternalGet (port++, MHD_USE_POLL); 520 errorCount += testInternalGet (port++, MHD_USE_POLL);
491 errorCount += testMultithreadedGet (port++, MHD_USE_POLL); 521 errorCount += testMultithreadedGet (port++, MHD_USE_POLL);
492 errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL); 522 errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL);
493 } 523 }
494 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) 524 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
495 { 525 {
496 errorCount += testInternalGet (port++, MHD_USE_EPOLL); 526 errorCount += testInternalGet (port++, MHD_USE_EPOLL);
497 errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL); 527 errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL);
498 } 528 }
499 MHD_destroy_response (response); 529 MHD_destroy_response (response);
500 if (errorCount != 0) 530 if (errorCount != 0)
501 fprintf (stderr, "Error (code: %u)\n", errorCount); 531 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c
index 5b1062fe..a0480932 100644
--- a/src/testcurl/test_callback.c
+++ b/src/testcurl/test_callback.c
@@ -35,56 +35,56 @@ struct callback_closure
35 35
36 36
37static ssize_t 37static ssize_t
38called_twice(void *cls, uint64_t pos, char *buf, size_t max) 38called_twice (void *cls, uint64_t pos, char *buf, size_t max)
39{ 39{
40 struct callback_closure *cls2 = cls; 40 struct callback_closure *cls2 = cls;
41 41
42 (void) pos; /* Unused. Silence compiler warning. */ 42 (void) pos; /* Unused. Silence compiler warning. */
43 (void) max; 43 (void) max;
44 if (cls2->called == 0) 44 if (cls2->called == 0)
45 { 45 {
46 memcpy(buf, "test", 5); 46 memcpy (buf, "test", 5);
47 cls2->called = 1; 47 cls2->called = 1;
48 return strlen(buf); 48 return strlen (buf);
49 } 49 }
50 if (cls2->called == 1) 50 if (cls2->called == 1)
51 { 51 {
52 cls2->called = 2; 52 cls2->called = 2;
53 return MHD_CONTENT_READER_END_OF_STREAM; 53 return MHD_CONTENT_READER_END_OF_STREAM;
54 } 54 }
55 fprintf(stderr, 55 fprintf (stderr,
56 "Handler called after returning END_OF_STREAM!\n"); 56 "Handler called after returning END_OF_STREAM!\n");
57 return MHD_CONTENT_READER_END_WITH_ERROR; 57 return MHD_CONTENT_READER_END_WITH_ERROR;
58} 58}
59 59
60 60
61static int 61static int
62callback(void *cls, 62callback (void *cls,
63 struct MHD_Connection *connection, 63 struct MHD_Connection *connection,
64 const char *url, 64 const char *url,
65 const char *method, 65 const char *method,
66 const char *version, 66 const char *version,
67 const char *upload_data, 67 const char *upload_data,
68 size_t *upload_data_size, 68 size_t *upload_data_size,
69 void **con_cls) 69 void **con_cls)
70{ 70{
71 struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure)); 71 struct callback_closure *cbc = calloc (1, sizeof(struct callback_closure));
72 struct MHD_Response *r; 72 struct MHD_Response *r;
73 int ret; 73 int ret;
74 74
75 (void)cls; 75 (void) cls;
76 (void)url; /* Unused. Silent compiler warning. */ 76 (void) url; /* Unused. Silent compiler warning. */
77 (void)method; 77 (void) method;
78 (void)version; 78 (void) version;
79 (void)upload_data; /* Unused. Silent compiler warning. */ 79 (void) upload_data; /* Unused. Silent compiler warning. */
80 (void)upload_data_size; 80 (void) upload_data_size;
81 (void)con_cls; /* Unused. Silent compiler warning. */ 81 (void) con_cls; /* Unused. Silent compiler warning. */
82 82
83 if (NULL == cbc) 83 if (NULL == cbc)
84 return MHD_NO; 84 return MHD_NO;
85 r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, 85 r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
86 &called_twice, cbc, 86 &called_twice, cbc,
87 &free); 87 &free);
88 if (NULL == r) 88 if (NULL == r)
89 { 89 {
90 free (cbc); 90 free (cbc);
@@ -104,13 +104,13 @@ discard_buffer (void *ptr,
104 size_t nmemb, 104 size_t nmemb,
105 void *ctx) 105 void *ctx)
106{ 106{
107 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 107 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
108 return size * nmemb; 108 return size * nmemb;
109} 109}
110 110
111 111
112int 112int
113main(int argc, char **argv) 113main (int argc, char **argv)
114{ 114{
115 struct MHD_Daemon *d; 115 struct MHD_Daemon *d;
116 fd_set rs; 116 fd_set rs;
@@ -130,33 +130,35 @@ main(int argc, char **argv)
130 struct timeval tv; 130 struct timeval tv;
131 int extra; 131 int extra;
132 int port; 132 int port;
133 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 133 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
134 134
135 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 135 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
136 port = 0; 136 port = 0;
137 else 137 else
138 port = 1140; 138 port = 1140;
139 139
140 d = MHD_start_daemon(0, 140 d = MHD_start_daemon (0,
141 port, 141 port,
142 NULL, 142 NULL,
143 NULL, 143 NULL,
144 &callback, 144 &callback,
145 NULL, 145 NULL,
146 MHD_OPTION_END); 146 MHD_OPTION_END);
147 if (d == NULL) 147 if (d == NULL)
148 return 32; 148 return 32;
149 if (0 == port) 149 if (0 == port)
150 {
151 const union MHD_DaemonInfo *dinfo;
152 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
153 if ((NULL == dinfo) ||(0 == dinfo->port) )
150 { 154 {
151 const union MHD_DaemonInfo *dinfo; 155 MHD_stop_daemon (d); return 48;
152 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
153 if (NULL == dinfo || 0 == dinfo->port)
154 { MHD_stop_daemon (d); return 48; }
155 port = (int)dinfo->port;
156 } 156 }
157 port = (int) dinfo->port;
158 }
157 c = curl_easy_init (); 159 c = curl_easy_init ();
158 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); 160 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
159 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 161 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
160 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &discard_buffer); 162 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &discard_buffer);
161 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 163 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
162 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 164 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
@@ -165,87 +167,89 @@ main(int argc, char **argv)
165 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 167 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
166 multi = curl_multi_init (); 168 multi = curl_multi_init ();
167 if (multi == NULL) 169 if (multi == NULL)
168 { 170 {
169 curl_easy_cleanup (c); 171 curl_easy_cleanup (c);
170 MHD_stop_daemon (d); 172 MHD_stop_daemon (d);
171 return 1; 173 return 1;
172 } 174 }
173 mret = curl_multi_add_handle (multi, c); 175 mret = curl_multi_add_handle (multi, c);
174 if (mret != CURLM_OK) 176 if (mret != CURLM_OK)
177 {
178 curl_multi_cleanup (multi);
179 curl_easy_cleanup (c);
180 MHD_stop_daemon (d);
181 return 2;
182 }
183 extra = 10;
184 while ( (c != NULL) || (--extra > 0) )
185 {
186 maxsock = MHD_INVALID_SOCKET;
187 maxposixs = -1;
188 FD_ZERO (&ws);
189 FD_ZERO (&rs);
190 FD_ZERO (&es);
191 curl_multi_perform (multi, &running);
192 if (NULL != multi)
193 {
194 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
195 if (mret != CURLM_OK)
196 {
197 curl_multi_remove_handle (multi, c);
198 curl_multi_cleanup (multi);
199 curl_easy_cleanup (c);
200 MHD_stop_daemon (d);
201 return 3;
202 }
203 }
204 if (MHD_YES !=
205 MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
175 { 206 {
207 curl_multi_remove_handle (multi, c);
176 curl_multi_cleanup (multi); 208 curl_multi_cleanup (multi);
177 curl_easy_cleanup (c); 209 curl_easy_cleanup (c);
178 MHD_stop_daemon (d); 210 MHD_stop_daemon (d);
179 return 2; 211 return 4;
180 } 212 }
181 extra = 10; 213 tv.tv_sec = 0;
182 while ( (c != NULL) || (--extra > 0) ) 214 tv.tv_usec = 1000;
215 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
216 {
217#ifdef MHD_POSIX_SOCKETS
218 if (EINTR != errno)
219 abort ();
220#else
221 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
222 ws.fd_count)
223 ||(0 != es.fd_count) )
224 abort ();
225 Sleep (1000);
226#endif
227 }
228 if (NULL != multi)
183 { 229 {
184 maxsock = MHD_INVALID_SOCKET;
185 maxposixs = -1;
186 FD_ZERO(&ws);
187 FD_ZERO(&rs);
188 FD_ZERO(&es);
189 curl_multi_perform (multi, &running); 230 curl_multi_perform (multi, &running);
190 if (NULL != multi) 231 if (running == 0)
191 { 232 {
192 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); 233 msg = curl_multi_info_read (multi, &running);
193 if (mret != CURLM_OK) 234 if (msg == NULL)
194 { 235 break;
195 curl_multi_remove_handle (multi, c); 236 if (msg->msg == CURLMSG_DONE)
196 curl_multi_cleanup (multi); 237 {
197 curl_easy_cleanup (c); 238 if (msg->data.result != CURLE_OK)
198 MHD_stop_daemon (d); 239 printf ("%s failed at %s:%d: `%s'\n",
199 return 3; 240 "curl_multi_perform",
200 } 241 __FILE__,
201 } 242 __LINE__, curl_easy_strerror (msg->data.result));
202 if (MHD_YES !=
203 MHD_get_fdset(d, &rs, &ws, &es, &maxsock))
204 {
205 curl_multi_remove_handle (multi, c); 243 curl_multi_remove_handle (multi, c);
206 curl_multi_cleanup (multi); 244 curl_multi_cleanup (multi);
207 curl_easy_cleanup (c); 245 curl_easy_cleanup (c);
208 MHD_stop_daemon (d); 246 c = NULL;
209 return 4; 247 multi = NULL;
210 }
211 tv.tv_sec = 0;
212 tv.tv_usec = 1000;
213 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
214 {
215#ifdef MHD_POSIX_SOCKETS
216 if (EINTR != errno)
217 abort ();
218#else
219 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count)
220 abort ();
221 Sleep (1000);
222#endif
223 } 248 }
224 if (NULL != multi) 249 }
225 {
226 curl_multi_perform (multi, &running);
227 if (running == 0)
228 {
229 msg = curl_multi_info_read (multi, &running);
230 if (msg == NULL)
231 break;
232 if (msg->msg == CURLMSG_DONE)
233 {
234 if (msg->data.result != CURLE_OK)
235 printf ("%s failed at %s:%d: `%s'\n",
236 "curl_multi_perform",
237 __FILE__,
238 __LINE__, curl_easy_strerror (msg->data.result));
239 curl_multi_remove_handle (multi, c);
240 curl_multi_cleanup (multi);
241 curl_easy_cleanup (c);
242 c = NULL;
243 multi = NULL;
244 }
245 }
246 }
247 MHD_run(d);
248 } 250 }
249 MHD_stop_daemon(d); 251 MHD_run (d);
252 }
253 MHD_stop_daemon (d);
250 return 0; 254 return 0;
251} 255}
diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c
index 71202add..02f4fffd 100644
--- a/src/testcurl/test_concurrent_stop.c
+++ b/src/testcurl/test_concurrent_stop.c
@@ -33,10 +33,10 @@
33#include <pthread.h> 33#include <pthread.h>
34#include "gauger.h" 34#include "gauger.h"
35 35
36#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 36#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
37#undef CPU_COUNT 37#undef CPU_COUNT
38#endif 38#endif
39#if !defined(CPU_COUNT) 39#if ! defined(CPU_COUNT)
40#define CPU_COUNT 2 40#define CPU_COUNT 2
41#endif 41#endif
42 42
@@ -81,50 +81,52 @@ thread_watchdog (void *param)
81 81
82 seconds_passed = 0; 82 seconds_passed = 0;
83 while (watchdog_continue) /* Poor threads sync, but works for testing. */ 83 while (watchdog_continue) /* Poor threads sync, but works for testing. */
84 {
85 if (0 == sleep (1)) /* Poor accuracy, but enough for testing. */
86 seconds_passed++;
87 if (timeout_val < seconds_passed)
84 { 88 {
85 if (0 == sleep (1)) /* Poor accuracy, but enough for testing. */ 89 fprintf (stderr, "%s timeout expired.\n", watchdog_obj ? watchdog_obj :
86 seconds_passed++; 90 "Watchdog");
87 if (timeout_val < seconds_passed) 91 fflush (stderr);
88 { 92 _exit (16);
89 fprintf (stderr, "%s timeout expired.\n", watchdog_obj ? watchdog_obj : "Watchdog");
90 fflush (stderr);
91 _exit(16);
92 }
93 } 93 }
94 }
94 return NULL; 95 return NULL;
95} 96}
96 97
97pthread_t watchdog_tid; 98pthread_t watchdog_tid;
98 99
99static void 100static void
100start_watchdog(int timeout, const char *obj_name) 101start_watchdog (int timeout, const char *obj_name)
101{ 102{
102 watchdog_continue = 1; 103 watchdog_continue = 1;
103 watchdog_obj = obj_name; 104 watchdog_obj = obj_name;
104 if (0 != pthread_create(&watchdog_tid, NULL, &thread_watchdog, (void*)(intptr_t)timeout)) 105 if (0 != pthread_create (&watchdog_tid, NULL, &thread_watchdog,
105 { 106 (void*) (intptr_t) timeout))
106 fprintf(stderr, "Failed to start watchdog.\n"); 107 {
107 _exit (99); 108 fprintf (stderr, "Failed to start watchdog.\n");
108 } 109 _exit (99);
110 }
109} 111}
110 112
111static void 113static void
112stop_watchdog(void) 114stop_watchdog (void)
113{ 115{
114 watchdog_continue = 0; 116 watchdog_continue = 0;
115 if (0 != pthread_join (watchdog_tid, NULL)) 117 if (0 != pthread_join (watchdog_tid, NULL))
116 { 118 {
117 fprintf(stderr, "Failed to stop watchdog.\n"); 119 fprintf (stderr, "Failed to stop watchdog.\n");
118 _exit (99); 120 _exit (99);
119 } 121 }
120} 122}
121 123
122static size_t 124static size_t
123copyBuffer (void *ptr, 125copyBuffer (void *ptr,
124 size_t size, size_t nmemb, 126 size_t size, size_t nmemb,
125 void *ctx) 127 void *ctx)
126{ 128{
127 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 129 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
128 return size * nmemb; 130 return size * nmemb;
129} 131}
130 132
@@ -142,16 +144,16 @@ ahc_echo (void *cls,
142 static int ptr; 144 static int ptr;
143 const char *me = cls; 145 const char *me = cls;
144 int ret; 146 int ret;
145 (void)url;(void)version; /* Unused. Silent compiler warning. */ 147 (void) url; (void) version; /* Unused. Silent compiler warning. */
146 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 148 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
147 149
148 if (0 != strcmp (me, method)) 150 if (0 != strcmp (me, method))
149 return MHD_NO; /* unexpected method */ 151 return MHD_NO; /* unexpected method */
150 if (&ptr != *unused) 152 if (&ptr != *unused)
151 { 153 {
152 *unused = &ptr; 154 *unused = &ptr;
153 return MHD_YES; 155 return MHD_YES;
154 } 156 }
155 *unused = NULL; 157 *unused = NULL;
156 ret = MHD_queue_response (connection, 158 ret = MHD_queue_response (connection,
157 MHD_HTTP_OK, 159 MHD_HTTP_OK,
@@ -166,15 +168,15 @@ thread_gets (void *param)
166{ 168{
167 CURL *c; 169 CURL *c;
168 CURLcode errornum; 170 CURLcode errornum;
169 char * const url = (char*) param; 171 char *const url = (char*) param;
170 172
171 c = NULL; 173 c = NULL;
172 c = curl_easy_init (); 174 c = curl_easy_init ();
173 if (NULL == c) 175 if (NULL == c)
174 { 176 {
175 fprintf(stderr, "curl_easy_init failed.\n"); 177 fprintf (stderr, "curl_easy_init failed.\n");
176 _exit(99); 178 _exit (99);
177 } 179 }
178 curl_easy_setopt (c, CURLOPT_URL, url); 180 curl_easy_setopt (c, CURLOPT_URL, url);
179 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 181 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
180 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); 182 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
@@ -190,62 +192,62 @@ thread_gets (void *param)
190 crashes on my system! */ 192 crashes on my system! */
191 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 193 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
192 while (continue_requesting) 194 while (continue_requesting)
195 {
196 errornum = curl_easy_perform (c);
197 if (CURLE_OK != errornum)
193 { 198 {
194 errornum = curl_easy_perform (c); 199 curl_easy_cleanup (c);
195 if (CURLE_OK != errornum) 200 return NULL;
196 {
197 curl_easy_cleanup (c);
198 return NULL;
199 }
200 } 201 }
202 }
201 curl_easy_cleanup (c); 203 curl_easy_cleanup (c);
202 return NULL; 204 return NULL;
203} 205}
204 206
205static void * 207static void *
206do_gets (void * param) 208do_gets (void *param)
207{ 209{
208 int j; 210 int j;
209 pthread_t par[PAR]; 211 pthread_t par[PAR];
210 char url[64]; 212 char url[64];
211 int port = (int)(intptr_t)param; 213 int port = (int) (intptr_t) param;
212 214
213 snprintf (url, 215 snprintf (url,
214 sizeof (url), 216 sizeof (url),
215 "http://127.0.0.1:%d/hello_world", 217 "http://127.0.0.1:%d/hello_world",
216 port); 218 port);
217 219
218 for (j=0;j<PAR;j++) 220 for (j = 0; j<PAR; j++)
219 { 221 {
220 if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) 222 if (0 != pthread_create (&par[j], NULL, &thread_gets, (void*) url))
221 {
222 fprintf(stderr, "pthread_create failed.\n");
223 continue_requesting = 0;
224 for (j--; j >= 0; j--)
225 {
226 pthread_join(par[j], NULL);
227 }
228 _exit(99);
229 }
230 }
231 (void)sleep (1);
232 for (j=0;j<PAR;j++)
233 { 223 {
234 pthread_join(par[j], NULL); 224 fprintf (stderr, "pthread_create failed.\n");
225 continue_requesting = 0;
226 for (j--; j >= 0; j--)
227 {
228 pthread_join (par[j], NULL);
229 }
230 _exit (99);
235 } 231 }
232 }
233 (void) sleep (1);
234 for (j = 0; j<PAR; j++)
235 {
236 pthread_join (par[j], NULL);
237 }
236 return NULL; 238 return NULL;
237} 239}
238 240
239 241
240pthread_t start_gets(int port) 242pthread_t start_gets (int port)
241{ 243{
242 pthread_t tid; 244 pthread_t tid;
243 continue_requesting = 1; 245 continue_requesting = 1;
244 if (0 != pthread_create(&tid, NULL, &do_gets, (void*)(intptr_t)port)) 246 if (0 != pthread_create (&tid, NULL, &do_gets, (void*) (intptr_t) port))
245 { 247 {
246 fprintf(stderr, "pthread_create failed.\n"); 248 fprintf (stderr, "pthread_create failed.\n");
247 _exit(99); 249 _exit (99);
248 } 250 }
249 return tid; 251 return tid;
250} 252}
251 253
@@ -257,7 +259,9 @@ testMultithreadedGet (int port,
257 struct MHD_Daemon *d; 259 struct MHD_Daemon *d;
258 pthread_t p; 260 pthread_t p;
259 261
260 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 262 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
263 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
264 | poll_flag,
261 port, 265 port,
262 NULL, NULL, 266 NULL, NULL,
263 &ahc_echo, "GET", 267 &ahc_echo, "GET",
@@ -265,18 +269,20 @@ testMultithreadedGet (int port,
265 if (d == NULL) 269 if (d == NULL)
266 return 16; 270 return 16;
267 if (0 == port) 271 if (0 == port)
272 {
273 const union MHD_DaemonInfo *dinfo;
274 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
275 if ((NULL == dinfo) ||(0 == dinfo->port) )
268 { 276 {
269 const union MHD_DaemonInfo *dinfo; 277 MHD_stop_daemon (d); return 32;
270 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
271 if (NULL == dinfo || 0 == dinfo->port)
272 { MHD_stop_daemon (d); return 32; }
273 port = (int)dinfo->port;
274 } 278 }
279 port = (int) dinfo->port;
280 }
275 p = start_gets (port); 281 p = start_gets (port);
276 (void)sleep (1); 282 (void) sleep (1);
277 start_watchdog(10, "daemon_stop() in testMultithreadedGet"); 283 start_watchdog (10, "daemon_stop() in testMultithreadedGet");
278 MHD_stop_daemon (d); 284 MHD_stop_daemon (d);
279 stop_watchdog(); 285 stop_watchdog ();
280 continue_requesting = 0; 286 continue_requesting = 0;
281 pthread_join (p, NULL); 287 pthread_join (p, NULL);
282 return 0; 288 return 0;
@@ -290,7 +296,8 @@ testMultithreadedPoolGet (int port,
290 struct MHD_Daemon *d; 296 struct MHD_Daemon *d;
291 pthread_t p; 297 pthread_t p;
292 298
293 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 299 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
300 | poll_flag,
294 port, 301 port,
295 NULL, NULL, 302 NULL, NULL,
296 &ahc_echo, "GET", 303 &ahc_echo, "GET",
@@ -299,18 +306,20 @@ testMultithreadedPoolGet (int port,
299 if (d == NULL) 306 if (d == NULL)
300 return 16; 307 return 16;
301 if (0 == port) 308 if (0 == port)
309 {
310 const union MHD_DaemonInfo *dinfo;
311 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
312 if ((NULL == dinfo) ||(0 == dinfo->port) )
302 { 313 {
303 const union MHD_DaemonInfo *dinfo; 314 MHD_stop_daemon (d); return 32;
304 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
305 if (NULL == dinfo || 0 == dinfo->port)
306 { MHD_stop_daemon (d); return 32; }
307 port = (int)dinfo->port;
308 } 315 }
316 port = (int) dinfo->port;
317 }
309 p = start_gets (port); 318 p = start_gets (port);
310 (void)sleep (1); 319 (void) sleep (1);
311 start_watchdog(10, "daemon_stop() in testMultithreadedPoolGet"); 320 start_watchdog (10, "daemon_stop() in testMultithreadedPoolGet");
312 MHD_stop_daemon (d); 321 MHD_stop_daemon (d);
313 stop_watchdog(); 322 stop_watchdog ();
314 continue_requesting = 0; 323 continue_requesting = 0;
315 pthread_join (p, NULL); 324 pthread_join (p, NULL);
316 return 0; 325 return 0;
@@ -322,8 +331,8 @@ main (int argc, char *const *argv)
322{ 331{
323 unsigned int errorCount = 0; 332 unsigned int errorCount = 0;
324 int port; 333 int port;
325 (void)argc; /* Unused. Silent compiler warning. */ 334 (void) argc; /* Unused. Silent compiler warning. */
326 (void)argv; /* Unused. Silent compiler warning. */ 335 (void) argv; /* Unused. Silent compiler warning. */
327 336
328 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 337 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
329 port = 0; 338 port = 0;
@@ -333,15 +342,16 @@ main (int argc, char *const *argv)
333 /* Do reuse connection, otherwise all available local ports may exhausted. */ 342 /* Do reuse connection, otherwise all available local ports may exhausted. */
334 oneone = 1; 343 oneone = 1;
335 344
336 if (0 != port && oneone) 345 if ((0 != port)&& oneone)
337 port += 5; 346 port += 5;
338 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 347 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
339 return 2; 348 return 2;
340 response = MHD_create_response_from_buffer (strlen ("/hello_world"), 349 response = MHD_create_response_from_buffer (strlen ("/hello_world"),
341 "/hello_world", 350 "/hello_world",
342 MHD_RESPMEM_MUST_COPY); 351 MHD_RESPMEM_MUST_COPY);
343 errorCount += testMultithreadedGet (port, 0); 352 errorCount += testMultithreadedGet (port, 0);
344 if (0 != port) port++; 353 if (0 != port)
354 port++;
345 errorCount += testMultithreadedPoolGet (port, 0); 355 errorCount += testMultithreadedPoolGet (port, 0);
346 MHD_destroy_response (response); 356 MHD_destroy_response (response);
347 if (errorCount != 0) 357 if (errorCount != 0)
diff --git a/src/testcurl/test_delete.c b/src/testcurl/test_delete.c
index 35e9dc62..a3d14661 100644
--- a/src/testcurl/test_delete.c
+++ b/src/testcurl/test_delete.c
@@ -37,10 +37,10 @@
37#include <unistd.h> 37#include <unistd.h>
38#endif 38#endif
39 39
40#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 40#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
41#undef CPU_COUNT 41#undef CPU_COUNT
42#endif 42#endif
43#if !defined(CPU_COUNT) 43#if ! defined(CPU_COUNT)
44#define CPU_COUNT 2 44#define CPU_COUNT 2
45#endif 45#endif
46 46
@@ -91,28 +91,28 @@ ahc_echo (void *cls,
91 int *done = cls; 91 int *done = cls;
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 94 (void) version; (void) unused; /* Unused. Silent compiler warning. */
95 95
96 if (0 != strcasecmp ("DELETE", method)) 96 if (0 != strcasecmp ("DELETE", method))
97 return MHD_NO; /* unexpected method */ 97 return MHD_NO; /* unexpected method */
98 if ((*done) == 0) 98 if ((*done) == 0)
99 {
100 if (*upload_data_size != 8)
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
99 { 103 {
100 if (*upload_data_size != 8) 104 *upload_data_size = 0;
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
103 {
104 *upload_data_size = 0;
105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 } 105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 }
114 response = MHD_create_response_from_buffer (strlen (url), (void*) url, 114 response = MHD_create_response_from_buffer (strlen (url), (void*) url,
115 MHD_RESPMEM_MUST_COPY); 115 MHD_RESPMEM_MUST_COPY);
116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
117 MHD_destroy_response (response); 117 MHD_destroy_response (response);
118 return ret; 118 return ret;
@@ -145,16 +145,18 @@ testInternalDelete ()
145 if (d == NULL) 145 if (d == NULL)
146 return 1; 146 return 1;
147 if (0 == port) 147 if (0 == port)
148 {
149 const union MHD_DaemonInfo *dinfo;
150 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
151 if ((NULL == dinfo) ||(0 == dinfo->port) )
148 { 152 {
149 const union MHD_DaemonInfo *dinfo; 153 MHD_stop_daemon (d); return 32;
150 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
151 if (NULL == dinfo || 0 == dinfo->port)
152 { MHD_stop_daemon (d); return 32; }
153 port = (int)dinfo->port;
154 } 154 }
155 port = (int) dinfo->port;
156 }
155 c = curl_easy_init (); 157 c = curl_easy_init ();
156 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 158 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
157 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 159 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 160 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 161 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
160 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 162 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -174,14 +176,14 @@ testInternalDelete ()
174 * crashes on my system! */ 176 * crashes on my system! */
175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 177 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
176 if (CURLE_OK != (errornum = curl_easy_perform (c))) 178 if (CURLE_OK != (errornum = curl_easy_perform (c)))
177 { 179 {
178 fprintf (stderr, 180 fprintf (stderr,
179 "curl_easy_perform failed: `%s'\n", 181 "curl_easy_perform failed: `%s'\n",
180 curl_easy_strerror (errornum)); 182 curl_easy_strerror (errornum));
181 curl_easy_cleanup (c); 183 curl_easy_cleanup (c);
182 MHD_stop_daemon (d); 184 MHD_stop_daemon (d);
183 return 2; 185 return 2;
184 } 186 }
185 curl_easy_cleanup (c); 187 curl_easy_cleanup (c);
186 MHD_stop_daemon (d); 188 MHD_stop_daemon (d);
187 if (cbc.pos != strlen ("/hello_world")) 189 if (cbc.pos != strlen ("/hello_world"))
@@ -212,22 +214,25 @@ testMultithreadedDelete ()
212 cbc.buf = buf; 214 cbc.buf = buf;
213 cbc.size = 2048; 215 cbc.size = 2048;
214 cbc.pos = 0; 216 cbc.pos = 0;
215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 217 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
218 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
216 port, 219 port,
217 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 220 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
218 if (d == NULL) 221 if (d == NULL)
219 return 16; 222 return 16;
220 if (0 == port) 223 if (0 == port)
224 {
225 const union MHD_DaemonInfo *dinfo;
226 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
227 if ((NULL == dinfo) ||(0 == dinfo->port) )
221 { 228 {
222 const union MHD_DaemonInfo *dinfo; 229 MHD_stop_daemon (d); return 32;
223 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
224 if (NULL == dinfo || 0 == dinfo->port)
225 { MHD_stop_daemon (d); return 32; }
226 port = (int)dinfo->port;
227 } 230 }
231 port = (int) dinfo->port;
232 }
228 c = curl_easy_init (); 233 c = curl_easy_init ();
229 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 234 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
230 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 235 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 236 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 237 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
233 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 238 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -247,14 +252,14 @@ testMultithreadedDelete ()
247 * crashes on my system! */ 252 * crashes on my system! */
248 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 253 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
249 if (CURLE_OK != (errornum = curl_easy_perform (c))) 254 if (CURLE_OK != (errornum = curl_easy_perform (c)))
250 { 255 {
251 fprintf (stderr, 256 fprintf (stderr,
252 "curl_easy_perform failed: `%s'\n", 257 "curl_easy_perform failed: `%s'\n",
253 curl_easy_strerror (errornum)); 258 curl_easy_strerror (errornum));
254 curl_easy_cleanup (c); 259 curl_easy_cleanup (c);
255 MHD_stop_daemon (d); 260 MHD_stop_daemon (d);
256 return 32; 261 return 32;
257 } 262 }
258 curl_easy_cleanup (c); 263 curl_easy_cleanup (c);
259 MHD_stop_daemon (d); 264 MHD_stop_daemon (d);
260 if (cbc.pos != strlen ("/hello_world")) 265 if (cbc.pos != strlen ("/hello_world"))
@@ -292,16 +297,18 @@ testMultithreadedPoolDelete ()
292 if (d == NULL) 297 if (d == NULL)
293 return 16; 298 return 16;
294 if (0 == port) 299 if (0 == port)
300 {
301 const union MHD_DaemonInfo *dinfo;
302 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
303 if ((NULL == dinfo) ||(0 == dinfo->port) )
295 { 304 {
296 const union MHD_DaemonInfo *dinfo; 305 MHD_stop_daemon (d); return 32;
297 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
298 if (NULL == dinfo || 0 == dinfo->port)
299 { MHD_stop_daemon (d); return 32; }
300 port = (int)dinfo->port;
301 } 306 }
307 port = (int) dinfo->port;
308 }
302 c = curl_easy_init (); 309 c = curl_easy_init ();
303 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 310 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
304 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 311 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
305 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 312 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
306 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 313 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
307 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 314 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -321,14 +328,14 @@ testMultithreadedPoolDelete ()
321 * crashes on my system! */ 328 * crashes on my system! */
322 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 329 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
323 if (CURLE_OK != (errornum = curl_easy_perform (c))) 330 if (CURLE_OK != (errornum = curl_easy_perform (c)))
324 { 331 {
325 fprintf (stderr, 332 fprintf (stderr,
326 "curl_easy_perform failed: `%s'\n", 333 "curl_easy_perform failed: `%s'\n",
327 curl_easy_strerror (errornum)); 334 curl_easy_strerror (errornum));
328 curl_easy_cleanup (c); 335 curl_easy_cleanup (c);
329 MHD_stop_daemon (d); 336 MHD_stop_daemon (d);
330 return 32; 337 return 32;
331 } 338 }
332 curl_easy_cleanup (c); 339 curl_easy_cleanup (c);
333 MHD_stop_daemon (d); 340 MHD_stop_daemon (d);
334 if (cbc.pos != strlen ("/hello_world")) 341 if (cbc.pos != strlen ("/hello_world"))
@@ -381,16 +388,18 @@ testExternalDelete ()
381 if (d == NULL) 388 if (d == NULL)
382 return 256; 389 return 256;
383 if (0 == port) 390 if (0 == port)
391 {
392 const union MHD_DaemonInfo *dinfo;
393 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
394 if ((NULL == dinfo) ||(0 == dinfo->port) )
384 { 395 {
385 const union MHD_DaemonInfo *dinfo; 396 MHD_stop_daemon (d); return 32;
386 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
387 if (NULL == dinfo || 0 == dinfo->port)
388 { MHD_stop_daemon (d); return 32; }
389 port = (int)dinfo->port;
390 } 397 }
398 port = (int) dinfo->port;
399 }
391 c = curl_easy_init (); 400 c = curl_easy_init ();
392 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 401 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
393 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 402 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
394 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 403 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
395 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 404 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
396 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 405 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -413,86 +422,88 @@ testExternalDelete ()
413 422
414 multi = curl_multi_init (); 423 multi = curl_multi_init ();
415 if (multi == NULL) 424 if (multi == NULL)
425 {
426 curl_easy_cleanup (c);
427 MHD_stop_daemon (d);
428 return 512;
429 }
430 mret = curl_multi_add_handle (multi, c);
431 if (mret != CURLM_OK)
432 {
433 curl_multi_cleanup (multi);
434 curl_easy_cleanup (c);
435 MHD_stop_daemon (d);
436 return 1024;
437 }
438 start = time (NULL);
439 while ((time (NULL) - start < 5) && (multi != NULL))
440 {
441 maxsock = MHD_INVALID_SOCKET;
442 maxposixs = -1;
443 FD_ZERO (&rs);
444 FD_ZERO (&ws);
445 FD_ZERO (&es);
446 curl_multi_perform (multi, &running);
447 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
448 if (mret != CURLM_OK)
416 { 449 {
450 curl_multi_remove_handle (multi, c);
451 curl_multi_cleanup (multi);
417 curl_easy_cleanup (c); 452 curl_easy_cleanup (c);
418 MHD_stop_daemon (d); 453 MHD_stop_daemon (d);
419 return 512; 454 return 2048;
420 } 455 }
421 mret = curl_multi_add_handle (multi, c); 456 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
422 if (mret != CURLM_OK)
423 { 457 {
458 curl_multi_remove_handle (multi, c);
424 curl_multi_cleanup (multi); 459 curl_multi_cleanup (multi);
425 curl_easy_cleanup (c); 460 curl_easy_cleanup (c);
426 MHD_stop_daemon (d); 461 MHD_stop_daemon (d);
427 return 1024; 462 return 4096;
428 } 463 }
429 start = time (NULL); 464 tv.tv_sec = 0;
430 while ((time (NULL) - start < 5) && (multi != NULL)) 465 tv.tv_usec = 1000;
466 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
431 { 467 {
432 maxsock = MHD_INVALID_SOCKET;
433 maxposixs = -1;
434 FD_ZERO (&rs);
435 FD_ZERO (&ws);
436 FD_ZERO (&es);
437 curl_multi_perform (multi, &running);
438 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
439 if (mret != CURLM_OK)
440 {
441 curl_multi_remove_handle (multi, c);
442 curl_multi_cleanup (multi);
443 curl_easy_cleanup (c);
444 MHD_stop_daemon (d);
445 return 2048;
446 }
447 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
448 {
449 curl_multi_remove_handle (multi, c);
450 curl_multi_cleanup (multi);
451 curl_easy_cleanup (c);
452 MHD_stop_daemon (d);
453 return 4096;
454 }
455 tv.tv_sec = 0;
456 tv.tv_usec = 1000;
457 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
458 {
459#ifdef MHD_POSIX_SOCKETS 468#ifdef MHD_POSIX_SOCKETS
460 if (EINTR != errno) 469 if (EINTR != errno)
461 abort (); 470 abort ();
462#else 471#else
463 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 472 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
464 abort (); 473 ws.fd_count)
465 Sleep (1000); 474 ||(0 != es.fd_count) )
475 abort ();
476 Sleep (1000);
466#endif 477#endif
467 }
468 curl_multi_perform (multi, &running);
469 if (running == 0)
470 {
471 msg = curl_multi_info_read (multi, &running);
472 if (msg == NULL)
473 break;
474 if (msg->msg == CURLMSG_DONE)
475 {
476 if (msg->data.result != CURLE_OK)
477 printf ("%s failed at %s:%d: `%s'\n",
478 "curl_multi_perform",
479 __FILE__,
480 __LINE__, curl_easy_strerror (msg->data.result));
481 curl_multi_remove_handle (multi, c);
482 curl_multi_cleanup (multi);
483 curl_easy_cleanup (c);
484 c = NULL;
485 multi = NULL;
486 }
487 }
488 MHD_run (d);
489 } 478 }
490 if (multi != NULL) 479 curl_multi_perform (multi, &running);
480 if (running == 0)
491 { 481 {
492 curl_multi_remove_handle (multi, c); 482 msg = curl_multi_info_read (multi, &running);
493 curl_easy_cleanup (c); 483 if (msg == NULL)
494 curl_multi_cleanup (multi); 484 break;
485 if (msg->msg == CURLMSG_DONE)
486 {
487 if (msg->data.result != CURLE_OK)
488 printf ("%s failed at %s:%d: `%s'\n",
489 "curl_multi_perform",
490 __FILE__,
491 __LINE__, curl_easy_strerror (msg->data.result));
492 curl_multi_remove_handle (multi, c);
493 curl_multi_cleanup (multi);
494 curl_easy_cleanup (c);
495 c = NULL;
496 multi = NULL;
497 }
495 } 498 }
499 MHD_run (d);
500 }
501 if (multi != NULL)
502 {
503 curl_multi_remove_handle (multi, c);
504 curl_easy_cleanup (c);
505 curl_multi_cleanup (multi);
506 }
496 MHD_stop_daemon (d); 507 MHD_stop_daemon (d);
497 if (cbc.pos != strlen ("/hello_world")) 508 if (cbc.pos != strlen ("/hello_world"))
498 return 8192; 509 return 8192;
@@ -507,19 +518,19 @@ int
507main (int argc, char *const *argv) 518main (int argc, char *const *argv)
508{ 519{
509 unsigned int errorCount = 0; 520 unsigned int errorCount = 0;
510 (void)argc; /* Unused. Silent compiler warning. */ 521 (void) argc; /* Unused. Silent compiler warning. */
511 522
512 if (NULL == argv || 0 == argv[0]) 523 if ((NULL == argv)||(0 == argv[0]))
513 return 99; 524 return 99;
514 oneone = has_in_name (argv[0], "11"); 525 oneone = has_in_name (argv[0], "11");
515 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 526 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
516 return 2; 527 return 2;
517 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 528 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
518 { 529 {
519 errorCount += testInternalDelete (); 530 errorCount += testInternalDelete ();
520 errorCount += testMultithreadedDelete (); 531 errorCount += testMultithreadedDelete ();
521 errorCount += testMultithreadedPoolDelete (); 532 errorCount += testMultithreadedPoolDelete ();
522 } 533 }
523 errorCount += testExternalDelete (); 534 errorCount += testExternalDelete ();
524 if (errorCount != 0) 535 if (errorCount != 0)
525 fprintf (stderr, "Error (code: %u)\n", errorCount); 536 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index b0a39bf7..4de006b7 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -44,9 +44,11 @@
44#include <wincrypt.h> 44#include <wincrypt.h>
45#endif 45#endif
46 46
47#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" 47#define PAGE \
48 "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
48 49
49#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" 50#define DENIED \
51 "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
50 52
51#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" 53#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
52 54
@@ -89,48 +91,49 @@ ahc_echo (void *cls,
89 const char *password = "testpass"; 91 const char *password = "testpass";
90 const char *realm = "test@example.com"; 92 const char *realm = "test@example.com";
91 int ret; 93 int ret;
92 (void)cls;(void)url; /* Unused. Silent compiler warning. */ 94 (void) cls; (void) url; /* Unused. Silent compiler warning. */
93 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 95 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
94 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 96 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
95 97
96 username = MHD_digest_auth_get_username (connection); 98 username = MHD_digest_auth_get_username (connection);
97 if ( (username == NULL) || 99 if ( (username == NULL) ||
98 (0 != strcmp (username, "testuser")) ) 100 (0 != strcmp (username, "testuser")) )
99 { 101 {
100 response = MHD_create_response_from_buffer (strlen (DENIED), 102 response = MHD_create_response_from_buffer (strlen (DENIED),
101 DENIED, 103 DENIED,
102 MHD_RESPMEM_PERSISTENT); 104 MHD_RESPMEM_PERSISTENT);
103 ret = MHD_queue_auth_fail_response (connection, 105 ret = MHD_queue_auth_fail_response (connection,
104 realm, 106 realm,
105 MY_OPAQUE, 107 MY_OPAQUE,
106 response, 108 response,
107 MHD_NO); 109 MHD_NO);
108 MHD_destroy_response(response); 110 MHD_destroy_response (response);
109 return ret; 111 return ret;
110 } 112 }
111 ret = MHD_digest_auth_check (connection, 113 ret = MHD_digest_auth_check (connection,
112 realm, 114 realm,
113 username, 115 username,
114 password, 116 password,
115 300); 117 300);
116 free (username); 118 free (username);
117 if ( (ret == MHD_INVALID_NONCE) || 119 if ( (ret == MHD_INVALID_NONCE) ||
118 (ret == MHD_NO) ) 120 (ret == MHD_NO) )
119 { 121 {
120 response = MHD_create_response_from_buffer (strlen (DENIED), 122 response = MHD_create_response_from_buffer (strlen (DENIED),
121 DENIED, 123 DENIED,
122 MHD_RESPMEM_PERSISTENT); 124 MHD_RESPMEM_PERSISTENT);
123 if (NULL == response) 125 if (NULL == response)
124 return MHD_NO; 126 return MHD_NO;
125 ret = MHD_queue_auth_fail_response (connection, 127 ret = MHD_queue_auth_fail_response (connection,
126 realm, 128 realm,
127 MY_OPAQUE, 129 MY_OPAQUE,
128 response, 130 response,
129 (MHD_INVALID_NONCE == ret) ? MHD_YES : MHD_NO); 131 (MHD_INVALID_NONCE == ret) ? MHD_YES :
130 MHD_destroy_response(response); 132 MHD_NO);
131 return ret; 133 MHD_destroy_response (response);
132 } 134 return ret;
133 response = MHD_create_response_from_buffer (strlen(PAGE), 135 }
136 response = MHD_create_response_from_buffer (strlen (PAGE),
134 PAGE, 137 PAGE,
135 MHD_RESPMEM_PERSISTENT); 138 MHD_RESPMEM_PERSISTENT);
136 ret = MHD_queue_response (connection, 139 ret = MHD_queue_response (connection,
@@ -170,30 +173,30 @@ testDigestAuth ()
170 fd = open ("/dev/urandom", 173 fd = open ("/dev/urandom",
171 O_RDONLY); 174 O_RDONLY);
172 if (-1 == fd) 175 if (-1 == fd)
176 {
177 fprintf (stderr,
178 "Failed to open `%s': %s\n",
179 "/dev/urandom",
180 strerror (errno));
181 return 1;
182 }
183 while (off < 8)
184 {
185 len = read (fd,
186 rnd,
187 8);
188 if (len == (size_t) -1)
173 { 189 {
174 fprintf (stderr, 190 fprintf (stderr,
175 "Failed to open `%s': %s\n", 191 "Failed to read `%s': %s\n",
176 "/dev/urandom", 192 "/dev/urandom",
177 strerror(errno)); 193 strerror (errno));
194 (void) close (fd);
178 return 1; 195 return 1;
179 } 196 }
180 while (off < 8) 197 off += len;
181 { 198 }
182 len = read (fd, 199 (void) close (fd);
183 rnd,
184 8);
185 if (len == (size_t)-1)
186 {
187 fprintf (stderr,
188 "Failed to read `%s': %s\n",
189 "/dev/urandom",
190 strerror(errno));
191 (void) close(fd);
192 return 1;
193 }
194 off += len;
195 }
196 (void) close(fd);
197#else 200#else
198 { 201 {
199 HCRYPTPROV cc; 202 HCRYPTPROV cc;
@@ -211,7 +214,7 @@ testDigestAuth ()
211 GetLastError ()); 214 GetLastError ());
212 return 1; 215 return 1;
213 } 216 }
214 b = CryptGenRandom (cc, 8, (BYTE*)rnd); 217 b = CryptGenRandom (cc, 8, (BYTE*) rnd);
215 if (b == 0) 218 if (b == 0)
216 { 219 {
217 fprintf (stderr, 220 fprintf (stderr,
@@ -226,25 +229,25 @@ testDigestAuth ()
226 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 229 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
227 port, NULL, NULL, 230 port, NULL, NULL,
228 &ahc_echo, PAGE, 231 &ahc_echo, PAGE,
229 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, 232 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
230 MHD_OPTION_NONCE_NC_SIZE, 300, 233 MHD_OPTION_NONCE_NC_SIZE, 300,
231 MHD_OPTION_END); 234 MHD_OPTION_END);
232 if (d == NULL) 235 if (d == NULL)
233 return 1; 236 return 1;
234 if (0 == port) 237 if (0 == port)
235 { 238 {
236 const union MHD_DaemonInfo *dinfo; 239 const union MHD_DaemonInfo *dinfo;
237 240
238 dinfo = MHD_get_daemon_info (d, 241 dinfo = MHD_get_daemon_info (d,
239 MHD_DAEMON_INFO_BIND_PORT); 242 MHD_DAEMON_INFO_BIND_PORT);
240 if ( (NULL == dinfo) || 243 if ( (NULL == dinfo) ||
241 (0 == dinfo->port) ) 244 (0 == dinfo->port) )
242 { 245 {
243 MHD_stop_daemon (d); 246 MHD_stop_daemon (d);
244 return 32; 247 return 32;
245 }
246 port = (int)dinfo->port;
247 } 248 }
249 port = (int) dinfo->port;
250 }
248 snprintf (url, 251 snprintf (url,
249 sizeof (url), 252 sizeof (url),
250 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", 253 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue",
@@ -264,14 +267,14 @@ testDigestAuth ()
264 crashes on my system!*/ 267 crashes on my system!*/
265 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 268 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
266 if (CURLE_OK != (errornum = curl_easy_perform (c))) 269 if (CURLE_OK != (errornum = curl_easy_perform (c)))
267 { 270 {
268 fprintf (stderr, 271 fprintf (stderr,
269 "curl_easy_perform failed: `%s'\n", 272 "curl_easy_perform failed: `%s'\n",
270 curl_easy_strerror (errornum)); 273 curl_easy_strerror (errornum));
271 curl_easy_cleanup (c); 274 curl_easy_cleanup (c);
272 MHD_stop_daemon (d); 275 MHD_stop_daemon (d);
273 return 2; 276 return 2;
274 } 277 }
275 curl_easy_cleanup (c); 278 curl_easy_cleanup (c);
276 MHD_stop_daemon (d); 279 MHD_stop_daemon (d);
277 if (cbc.pos != strlen (PAGE)) 280 if (cbc.pos != strlen (PAGE))
@@ -286,7 +289,7 @@ int
286main (int argc, char *const *argv) 289main (int argc, char *const *argv)
287{ 290{
288 unsigned int errorCount = 0; 291 unsigned int errorCount = 0;
289 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 292 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
290 293
291#ifdef MHD_HTTPS_REQUIRE_GRYPT 294#ifdef MHD_HTTPS_REQUIRE_GRYPT
292#ifdef HAVE_GCRYPT_H 295#ifdef HAVE_GCRYPT_H
@@ -296,7 +299,7 @@ main (int argc, char *const *argv)
296#endif 299#endif
297#endif 300#endif
298#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 301#endif /* MHD_HTTPS_REQUIRE_GRYPT */
299if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 302 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
300 return 2; 303 return 2;
301 errorCount += testDigestAuth (); 304 errorCount += testDigestAuth ();
302 if (errorCount != 0) 305 if (errorCount != 0)
diff --git a/src/testcurl/test_digestauth_sha256.c b/src/testcurl/test_digestauth_sha256.c
index c3430283..3482d14d 100644
--- a/src/testcurl/test_digestauth_sha256.c
+++ b/src/testcurl/test_digestauth_sha256.c
@@ -45,9 +45,11 @@
45#include <wincrypt.h> 45#include <wincrypt.h>
46#endif 46#endif
47 47
48#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" 48#define PAGE \
49 "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
49 50
50#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" 51#define DENIED \
52 "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
51 53
52#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" 54#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
53 55
@@ -90,26 +92,26 @@ ahc_echo (void *cls,
90 const char *password = "testpass"; 92 const char *password = "testpass";
91 const char *realm = "test@example.com"; 93 const char *realm = "test@example.com";
92 int ret; 94 int ret;
93 (void)cls;(void)url; /* Unused. Silent compiler warning. */ 95 (void) cls; (void) url; /* Unused. Silent compiler warning. */
94 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 96 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
95 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 97 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
96 98
97 username = MHD_digest_auth_get_username (connection); 99 username = MHD_digest_auth_get_username (connection);
98 if ( (username == NULL) || 100 if ( (username == NULL) ||
99 (0 != strcmp (username, "testuser")) ) 101 (0 != strcmp (username, "testuser")) )
100 { 102 {
101 response = MHD_create_response_from_buffer (strlen (DENIED), 103 response = MHD_create_response_from_buffer (strlen (DENIED),
102 DENIED, 104 DENIED,
103 MHD_RESPMEM_PERSISTENT); 105 MHD_RESPMEM_PERSISTENT);
104 ret = MHD_queue_auth_fail_response2 (connection, 106 ret = MHD_queue_auth_fail_response2 (connection,
105 realm, 107 realm,
106 MY_OPAQUE, 108 MY_OPAQUE,
107 response, 109 response,
108 MHD_NO, 110 MHD_NO,
109 MHD_DIGEST_ALG_SHA256); 111 MHD_DIGEST_ALG_SHA256);
110 MHD_destroy_response(response); 112 MHD_destroy_response (response);
111 return ret; 113 return ret;
112 } 114 }
113 ret = MHD_digest_auth_check2 (connection, 115 ret = MHD_digest_auth_check2 (connection,
114 realm, 116 realm,
115 username, 117 username,
@@ -119,22 +121,23 @@ ahc_echo (void *cls,
119 free (username); 121 free (username);
120 if ( (ret == MHD_INVALID_NONCE) || 122 if ( (ret == MHD_INVALID_NONCE) ||
121 (ret == MHD_NO) ) 123 (ret == MHD_NO) )
122 { 124 {
123 response = MHD_create_response_from_buffer (strlen (DENIED), 125 response = MHD_create_response_from_buffer (strlen (DENIED),
124 DENIED, 126 DENIED,
125 MHD_RESPMEM_PERSISTENT); 127 MHD_RESPMEM_PERSISTENT);
126 if (NULL == response) 128 if (NULL == response)
127 return MHD_NO; 129 return MHD_NO;
128 ret = MHD_queue_auth_fail_response2 (connection, 130 ret = MHD_queue_auth_fail_response2 (connection,
129 realm, 131 realm,
130 MY_OPAQUE, 132 MY_OPAQUE,
131 response, 133 response,
132 (MHD_INVALID_NONCE == ret) ? MHD_YES : MHD_NO, 134 (MHD_INVALID_NONCE == ret) ? MHD_YES :
133 MHD_DIGEST_ALG_SHA256); 135 MHD_NO,
134 MHD_destroy_response(response); 136 MHD_DIGEST_ALG_SHA256);
135 return ret; 137 MHD_destroy_response (response);
136 } 138 return ret;
137 response = MHD_create_response_from_buffer (strlen(PAGE), 139 }
140 response = MHD_create_response_from_buffer (strlen (PAGE),
138 PAGE, 141 PAGE,
139 MHD_RESPMEM_PERSISTENT); 142 MHD_RESPMEM_PERSISTENT);
140 ret = MHD_queue_response (connection, 143 ret = MHD_queue_response (connection,
@@ -174,30 +177,30 @@ testDigestAuth ()
174 fd = open ("/dev/urandom", 177 fd = open ("/dev/urandom",
175 O_RDONLY); 178 O_RDONLY);
176 if (-1 == fd) 179 if (-1 == fd)
180 {
181 fprintf (stderr,
182 "Failed to open `%s': %s\n",
183 "/dev/urandom",
184 strerror (errno));
185 return 1;
186 }
187 while (off < 8)
188 {
189 len = read (fd,
190 rnd,
191 8);
192 if (len == (size_t) -1)
177 { 193 {
178 fprintf (stderr, 194 fprintf (stderr,
179 "Failed to open `%s': %s\n", 195 "Failed to read `%s': %s\n",
180 "/dev/urandom", 196 "/dev/urandom",
181 strerror(errno)); 197 strerror (errno));
198 (void) close (fd);
182 return 1; 199 return 1;
183 } 200 }
184 while (off < 8) 201 off += len;
185 { 202 }
186 len = read (fd, 203 (void) close (fd);
187 rnd,
188 8);
189 if (len == (size_t)-1)
190 {
191 fprintf (stderr,
192 "Failed to read `%s': %s\n",
193 "/dev/urandom",
194 strerror(errno));
195 (void) close(fd);
196 return 1;
197 }
198 off += len;
199 }
200 (void) close(fd);
201#else 204#else
202 { 205 {
203 HCRYPTPROV cc; 206 HCRYPTPROV cc;
@@ -215,7 +218,7 @@ testDigestAuth ()
215 GetLastError ()); 218 GetLastError ());
216 return 1; 219 return 1;
217 } 220 }
218 b = CryptGenRandom (cc, 8, (BYTE*)rnd); 221 b = CryptGenRandom (cc, 8, (BYTE*) rnd);
219 if (b == 0) 222 if (b == 0)
220 { 223 {
221 fprintf (stderr, 224 fprintf (stderr,
@@ -230,25 +233,25 @@ testDigestAuth ()
230 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 233 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
231 port, NULL, NULL, 234 port, NULL, NULL,
232 &ahc_echo, PAGE, 235 &ahc_echo, PAGE,
233 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, 236 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
234 MHD_OPTION_NONCE_NC_SIZE, 300, 237 MHD_OPTION_NONCE_NC_SIZE, 300,
235 MHD_OPTION_END); 238 MHD_OPTION_END);
236 if (d == NULL) 239 if (d == NULL)
237 return 1; 240 return 1;
238 if (0 == port) 241 if (0 == port)
239 { 242 {
240 const union MHD_DaemonInfo *dinfo; 243 const union MHD_DaemonInfo *dinfo;
241 244
242 dinfo = MHD_get_daemon_info (d, 245 dinfo = MHD_get_daemon_info (d,
243 MHD_DAEMON_INFO_BIND_PORT); 246 MHD_DAEMON_INFO_BIND_PORT);
244 if ( (NULL == dinfo) || 247 if ( (NULL == dinfo) ||
245 (0 == dinfo->port) ) 248 (0 == dinfo->port) )
246 { 249 {
247 MHD_stop_daemon (d); 250 MHD_stop_daemon (d);
248 return 32; 251 return 32;
249 }
250 port = (int)dinfo->port;
251 } 252 }
253 port = (int) dinfo->port;
254 }
252 snprintf (url, 255 snprintf (url,
253 sizeof (url), 256 sizeof (url),
254 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", 257 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue",
@@ -268,14 +271,14 @@ testDigestAuth ()
268 crashes on my system!*/ 271 crashes on my system!*/
269 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 272 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
270 if (CURLE_OK != (errornum = curl_easy_perform (c))) 273 if (CURLE_OK != (errornum = curl_easy_perform (c)))
271 { 274 {
272 fprintf (stderr, 275 fprintf (stderr,
273 "curl_easy_perform failed: `%s'\n", 276 "curl_easy_perform failed: `%s'\n",
274 curl_easy_strerror (errornum)); 277 curl_easy_strerror (errornum));
275 curl_easy_cleanup (c); 278 curl_easy_cleanup (c);
276 MHD_stop_daemon (d); 279 MHD_stop_daemon (d);
277 return 2; 280 return 2;
278 } 281 }
279 curl_easy_cleanup (c); 282 curl_easy_cleanup (c);
280 MHD_stop_daemon (d); 283 MHD_stop_daemon (d);
281 if (cbc.pos != strlen (PAGE)) 284 if (cbc.pos != strlen (PAGE))
@@ -291,7 +294,7 @@ main (int argc, char *const *argv)
291{ 294{
292 unsigned int errorCount = 0; 295 unsigned int errorCount = 0;
293 curl_version_info_data *d = curl_version_info (CURLVERSION_NOW); 296 curl_version_info_data *d = curl_version_info (CURLVERSION_NOW);
294 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 297 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
295 298
296 /* curl added SHA256 support in 7.57 = 7.0x39 */ 299 /* curl added SHA256 support in 7.57 = 7.0x39 */
297 if (d->version_num < 0x073900) 300 if (d->version_num < 0x073900)
@@ -304,7 +307,7 @@ main (int argc, char *const *argv)
304#endif 307#endif
305#endif 308#endif
306#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 309#endif /* MHD_HTTPS_REQUIRE_GRYPT */
307if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 310 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
308 return 2; 311 return 2;
309 errorCount += testDigestAuth (); 312 errorCount += testDigestAuth ();
310 if (errorCount != 0) 313 if (errorCount != 0)
diff --git a/src/testcurl/test_digestauth_with_arguments.c b/src/testcurl/test_digestauth_with_arguments.c
index 3f2852c0..5bacdc76 100644
--- a/src/testcurl/test_digestauth_with_arguments.c
+++ b/src/testcurl/test_digestauth_with_arguments.c
@@ -43,9 +43,11 @@
43#include <wincrypt.h> 43#include <wincrypt.h>
44#endif 44#endif
45 45
46#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" 46#define PAGE \
47 "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
47 48
48#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" 49#define DENIED \
50 "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
49 51
50#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" 52#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
51 53
@@ -82,48 +84,49 @@ ahc_echo (void *cls,
82 const char *password = "testpass"; 84 const char *password = "testpass";
83 const char *realm = "test@example.com"; 85 const char *realm = "test@example.com";
84 int ret; 86 int ret;
85 (void)cls;(void)url; /* Unused. Silent compiler warning. */ 87 (void) cls; (void) url; /* Unused. Silent compiler warning. */
86 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 88 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
87 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 89 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
88 90
89 username = MHD_digest_auth_get_username(connection); 91 username = MHD_digest_auth_get_username (connection);
90 if ( (username == NULL) || 92 if ( (username == NULL) ||
91 (0 != strcmp (username, "testuser")) ) 93 (0 != strcmp (username, "testuser")) )
92 { 94 {
93 response = MHD_create_response_from_buffer(strlen (DENIED), 95 response = MHD_create_response_from_buffer (strlen (DENIED),
94 DENIED, 96 DENIED,
95 MHD_RESPMEM_PERSISTENT); 97 MHD_RESPMEM_PERSISTENT);
96 ret = MHD_queue_auth_fail_response(connection, realm, 98 ret = MHD_queue_auth_fail_response (connection, realm,
97 MY_OPAQUE, 99 MY_OPAQUE,
98 response, 100 response,
99 MHD_NO); 101 MHD_NO);
100 MHD_destroy_response(response); 102 MHD_destroy_response (response);
101 return ret; 103 return ret;
102 } 104 }
103 ret = MHD_digest_auth_check(connection, realm, 105 ret = MHD_digest_auth_check (connection, realm,
104 username, 106 username,
105 password, 107 password,
106 300); 108 300);
107 free(username); 109 free (username);
108 if ( (ret == MHD_INVALID_NONCE) || 110 if ( (ret == MHD_INVALID_NONCE) ||
109 (ret == MHD_NO) ) 111 (ret == MHD_NO) )
110 { 112 {
111 response = MHD_create_response_from_buffer(strlen (DENIED), 113 response = MHD_create_response_from_buffer (strlen (DENIED),
112 DENIED, 114 DENIED,
113 MHD_RESPMEM_PERSISTENT); 115 MHD_RESPMEM_PERSISTENT);
114 if (NULL == response) 116 if (NULL == response)
115 return MHD_NO; 117 return MHD_NO;
116 ret = MHD_queue_auth_fail_response(connection, realm, 118 ret = MHD_queue_auth_fail_response (connection, realm,
117 MY_OPAQUE, 119 MY_OPAQUE,
118 response, 120 response,
119 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); 121 (ret == MHD_INVALID_NONCE) ? MHD_YES :
120 MHD_destroy_response(response); 122 MHD_NO);
121 return ret; 123 MHD_destroy_response (response);
122 } 124 return ret;
123 response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, 125 }
124 MHD_RESPMEM_PERSISTENT); 126 response = MHD_create_response_from_buffer (strlen (PAGE), PAGE,
125 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 127 MHD_RESPMEM_PERSISTENT);
126 MHD_destroy_response(response); 128 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
129 MHD_destroy_response (response);
127 return ret; 130 return ret;
128} 131}
129 132
@@ -154,45 +157,46 @@ testDigestAuth ()
154 cbc.size = 2048; 157 cbc.size = 2048;
155 cbc.pos = 0; 158 cbc.pos = 0;
156#ifndef WINDOWS 159#ifndef WINDOWS
157 fd = open("/dev/urandom", O_RDONLY); 160 fd = open ("/dev/urandom", O_RDONLY);
158 if (-1 == fd) 161 if (-1 == fd)
159 { 162 {
160 fprintf(stderr, "Failed to open `%s': %s\n", 163 fprintf (stderr, "Failed to open `%s': %s\n",
161 "/dev/urandom", 164 "/dev/urandom",
162 strerror(errno)); 165 strerror (errno));
163 return 1; 166 return 1;
164 } 167 }
165 while (off < 8) 168 while (off < 8)
169 {
170 len = read (fd, rnd, 8);
171 if (len == (size_t) -1)
166 { 172 {
167 len = read(fd, rnd, 8); 173 fprintf (stderr,
168 if (len == (size_t)-1) 174 "Failed to read `%s': %s\n",
169 { 175 "/dev/urandom",
170 fprintf(stderr, 176 strerror (errno));
171 "Failed to read `%s': %s\n", 177 (void) close (fd);
172 "/dev/urandom", 178 return 1;
173 strerror(errno));
174 (void) close(fd);
175 return 1;
176 }
177 off += len;
178 } 179 }
179 (void) close(fd); 180 off += len;
181 }
182 (void) close (fd);
180#else 183#else
181 { 184 {
182 HCRYPTPROV cc; 185 HCRYPTPROV cc;
183 BOOL b; 186 BOOL b;
184 b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); 187 b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL,
188 CRYPT_VERIFYCONTEXT);
185 if (b == 0) 189 if (b == 0)
186 { 190 {
187 fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", 191 fprintf (stderr, "Failed to acquire crypto provider context: %lu\n",
188 GetLastError ()); 192 GetLastError ());
189 return 1; 193 return 1;
190 } 194 }
191 b = CryptGenRandom (cc, 8, (BYTE*)rnd); 195 b = CryptGenRandom (cc, 8, (BYTE*) rnd);
192 if (b == 0) 196 if (b == 0)
193 { 197 {
194 fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", 198 fprintf (stderr, "Failed to generate 8 random bytes: %lu\n",
195 GetLastError ()); 199 GetLastError ());
196 } 200 }
197 CryptReleaseContext (cc, 0); 201 CryptReleaseContext (cc, 0);
198 if (b == 0) 202 if (b == 0)
@@ -201,19 +205,21 @@ testDigestAuth ()
201#endif 205#endif
202 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 206 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
203 port, NULL, NULL, &ahc_echo, PAGE, 207 port, NULL, NULL, &ahc_echo, PAGE,
204 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, 208 MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
205 MHD_OPTION_NONCE_NC_SIZE, 300, 209 MHD_OPTION_NONCE_NC_SIZE, 300,
206 MHD_OPTION_END); 210 MHD_OPTION_END);
207 if (d == NULL) 211 if (d == NULL)
208 return 1; 212 return 1;
209 if (0 == port) 213 if (0 == port)
214 {
215 const union MHD_DaemonInfo *dinfo;
216 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
217 if ((NULL == dinfo) ||(0 == dinfo->port) )
210 { 218 {
211 const union MHD_DaemonInfo *dinfo; 219 MHD_stop_daemon (d); return 32;
212 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
213 if (NULL == dinfo || 0 == dinfo->port)
214 { MHD_stop_daemon (d); return 32; }
215 port = (int)dinfo->port;
216 } 220 }
221 port = (int) dinfo->port;
222 }
217 snprintf (url, 223 snprintf (url,
218 sizeof (url), 224 sizeof (url),
219 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", 225 "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue",
@@ -233,14 +239,14 @@ testDigestAuth ()
233 crashes on my system!*/ 239 crashes on my system!*/
234 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 240 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
235 if (CURLE_OK != (errornum = curl_easy_perform (c))) 241 if (CURLE_OK != (errornum = curl_easy_perform (c)))
236 { 242 {
237 fprintf (stderr, 243 fprintf (stderr,
238 "curl_easy_perform failed: `%s'\n", 244 "curl_easy_perform failed: `%s'\n",
239 curl_easy_strerror (errornum)); 245 curl_easy_strerror (errornum));
240 curl_easy_cleanup (c); 246 curl_easy_cleanup (c);
241 MHD_stop_daemon (d); 247 MHD_stop_daemon (d);
242 return 2; 248 return 2;
243 } 249 }
244 curl_easy_cleanup (c); 250 curl_easy_cleanup (c);
245 MHD_stop_daemon (d); 251 MHD_stop_daemon (d);
246 if (cbc.pos != strlen (PAGE)) 252 if (cbc.pos != strlen (PAGE))
@@ -255,7 +261,7 @@ int
255main (int argc, char *const *argv) 261main (int argc, char *const *argv)
256{ 262{
257 unsigned int errorCount = 0; 263 unsigned int errorCount = 0;
258 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 264 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
259 265
260#ifdef MHD_HTTPS_REQUIRE_GRYPT 266#ifdef MHD_HTTPS_REQUIRE_GRYPT
261#ifdef HAVE_GCRYPT_H 267#ifdef HAVE_GCRYPT_H
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c
index 567b0787..dee5a9c1 100644
--- a/src/testcurl/test_get.c
+++ b/src/testcurl/test_get.c
@@ -48,10 +48,10 @@
48#include <sys/socket.h> 48#include <sys/socket.h>
49#endif 49#endif
50 50
51#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 51#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
52#undef CPU_COUNT 52#undef CPU_COUNT
53#endif 53#endif
54#if !defined(CPU_COUNT) 54#if ! defined(CPU_COUNT)
55#define CPU_COUNT 2 55#define CPU_COUNT 2
56#endif 56#endif
57 57
@@ -88,12 +88,12 @@ log_cb (void *cls,
88 (void) con; 88 (void) con;
89 if (0 != strcmp (uri, 89 if (0 != strcmp (uri,
90 EXPECTED_URI_PATH)) 90 EXPECTED_URI_PATH))
91 { 91 {
92 fprintf (stderr, 92 fprintf (stderr,
93 "Wrong URI: `%s'\n", 93 "Wrong URI: `%s'\n",
94 uri); 94 uri);
95 _exit (22); 95 _exit (22);
96 } 96 }
97 return NULL; 97 return NULL;
98} 98}
99 99
@@ -119,10 +119,10 @@ ahc_echo (void *cls,
119 if (0 != strcasecmp (me, method)) 119 if (0 != strcasecmp (me, method))
120 return MHD_NO; /* unexpected method */ 120 return MHD_NO; /* unexpected method */
121 if (&ptr != *unused) 121 if (&ptr != *unused)
122 { 122 {
123 *unused = &ptr; 123 *unused = &ptr;
124 return MHD_YES; 124 return MHD_YES;
125 } 125 }
126 *unused = NULL; 126 *unused = NULL;
127 v = MHD_lookup_connection_value (connection, 127 v = MHD_lookup_connection_value (connection,
128 MHD_GET_ARGUMENT_KIND, 128 MHD_GET_ARGUMENT_KIND,
@@ -130,11 +130,11 @@ ahc_echo (void *cls,
130 if ( (NULL == v) || 130 if ( (NULL == v) ||
131 (0 != strcmp ("&", 131 (0 != strcmp ("&",
132 v)) ) 132 v)) )
133 { 133 {
134 fprintf (stderr, "Found while looking for 'a=&': 'a=%s'\n", 134 fprintf (stderr, "Found while looking for 'a=&': 'a=%s'\n",
135 NULL == v ? "NULL" : v); 135 NULL == v ? "NULL" : v);
136 _exit (17); 136 _exit (17);
137 } 137 }
138 v = NULL; 138 v = NULL;
139 if (MHD_YES != MHD_lookup_connection_value_n (connection, 139 if (MHD_YES != MHD_lookup_connection_value_n (connection,
140 MHD_GET_ARGUMENT_KIND, 140 MHD_GET_ARGUMENT_KIND,
@@ -142,30 +142,30 @@ ahc_echo (void *cls,
142 1, 142 1,
143 &v, 143 &v,
144 NULL)) 144 NULL))
145 { 145 {
146 fprintf (stderr, "Not found 'b' GET argument.\n"); 146 fprintf (stderr, "Not found 'b' GET argument.\n");
147 _exit (18); 147 _exit (18);
148 } 148 }
149 if ( (NULL == v) || 149 if ( (NULL == v) ||
150 (0 != strcmp ("c", 150 (0 != strcmp ("c",
151 v)) ) 151 v)) )
152 { 152 {
153 fprintf (stderr, "Found while looking for 'b=c': 'b=%s'\n", 153 fprintf (stderr, "Found while looking for 'b=c': 'b=%s'\n",
154 NULL == v ? "NULL" : v); 154 NULL == v ? "NULL" : v);
155 _exit (19); 155 _exit (19);
156 } 156 }
157 response = MHD_create_response_from_buffer (strlen (url), 157 response = MHD_create_response_from_buffer (strlen (url),
158 (void *) url, 158 (void *) url,
159 MHD_RESPMEM_MUST_COPY); 159 MHD_RESPMEM_MUST_COPY);
160 ret = MHD_queue_response (connection, 160 ret = MHD_queue_response (connection,
161 MHD_HTTP_OK, 161 MHD_HTTP_OK,
162 response); 162 response);
163 MHD_destroy_response (response); 163 MHD_destroy_response (response);
164 if (ret == MHD_NO) 164 if (ret == MHD_NO)
165 { 165 {
166 fprintf (stderr, "Failed to queue response.\n"); 166 fprintf (stderr, "Failed to queue response.\n");
167 _exit (19); 167 _exit (19);
168 } 168 }
169 return ret; 169 return ret;
170} 170}
171 171
@@ -181,16 +181,17 @@ testInternalGet (int poll_flag)
181 181
182 if ( (0 == global_port) && 182 if ( (0 == global_port) &&
183 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) 183 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
184 { 184 {
185 global_port = 1220; 185 global_port = 1220;
186 if (oneone) 186 if (oneone)
187 global_port += 20; 187 global_port += 20;
188 } 188 }
189 189
190 cbc.buf = buf; 190 cbc.buf = buf;
191 cbc.size = 2048; 191 cbc.size = 2048;
192 cbc.pos = 0; 192 cbc.pos = 0;
193 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 193 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
194 | poll_flag,
194 global_port, NULL, NULL, 195 global_port, NULL, NULL,
195 &ahc_echo, "GET", 196 &ahc_echo, "GET",
196 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 197 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
@@ -198,16 +199,18 @@ testInternalGet (int poll_flag)
198 if (d == NULL) 199 if (d == NULL)
199 return 1; 200 return 1;
200 if (0 == global_port) 201 if (0 == global_port)
202 {
203 const union MHD_DaemonInfo *dinfo;
204 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
205 if ((NULL == dinfo) ||(0 == dinfo->port) )
201 { 206 {
202 const union MHD_DaemonInfo *dinfo; 207 MHD_stop_daemon (d); return 32;
203 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
204 if (NULL == dinfo || 0 == dinfo->port)
205 { MHD_stop_daemon (d); return 32; }
206 global_port = (int)dinfo->port;
207 } 208 }
209 global_port = (int) dinfo->port;
210 }
208 c = curl_easy_init (); 211 c = curl_easy_init ();
209 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); 212 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH);
210 curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); 213 curl_easy_setopt (c, CURLOPT_PORT, (long) global_port);
211 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 214 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
212 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 215 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
213 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 216 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -222,14 +225,14 @@ testInternalGet (int poll_flag)
222 crashes on my system!*/ 225 crashes on my system!*/
223 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 226 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
224 if (CURLE_OK != (errornum = curl_easy_perform (c))) 227 if (CURLE_OK != (errornum = curl_easy_perform (c)))
225 { 228 {
226 fprintf (stderr, 229 fprintf (stderr,
227 "curl_easy_perform failed: `%s'\n", 230 "curl_easy_perform failed: `%s'\n",
228 curl_easy_strerror (errornum)); 231 curl_easy_strerror (errornum));
229 curl_easy_cleanup (c); 232 curl_easy_cleanup (c);
230 MHD_stop_daemon (d); 233 MHD_stop_daemon (d);
231 return 2; 234 return 2;
232 } 235 }
233 curl_easy_cleanup (c); 236 curl_easy_cleanup (c);
234 MHD_stop_daemon (d); 237 MHD_stop_daemon (d);
235 if (cbc.pos != strlen ("/hello_world")) 238 if (cbc.pos != strlen ("/hello_world"))
@@ -251,16 +254,18 @@ testMultithreadedGet (int poll_flag)
251 254
252 if ( (0 == global_port) && 255 if ( (0 == global_port) &&
253 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) 256 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
254 { 257 {
255 global_port = 1221; 258 global_port = 1221;
256 if (oneone) 259 if (oneone)
257 global_port += 20; 260 global_port += 20;
258 } 261 }
259 262
260 cbc.buf = buf; 263 cbc.buf = buf;
261 cbc.size = 2048; 264 cbc.size = 2048;
262 cbc.pos = 0; 265 cbc.pos = 0;
263 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 266 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
267 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
268 | poll_flag,
264 global_port, NULL, NULL, 269 global_port, NULL, NULL,
265 &ahc_echo, "GET", 270 &ahc_echo, "GET",
266 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 271 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
@@ -268,16 +273,18 @@ testMultithreadedGet (int poll_flag)
268 if (d == NULL) 273 if (d == NULL)
269 return 16; 274 return 16;
270 if (0 == global_port) 275 if (0 == global_port)
276 {
277 const union MHD_DaemonInfo *dinfo;
278 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
279 if ((NULL == dinfo) ||(0 == dinfo->port) )
271 { 280 {
272 const union MHD_DaemonInfo *dinfo; 281 MHD_stop_daemon (d); return 32;
273 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
274 if (NULL == dinfo || 0 == dinfo->port)
275 { MHD_stop_daemon (d); return 32; }
276 global_port = (int)dinfo->port;
277 } 282 }
283 global_port = (int) dinfo->port;
284 }
278 c = curl_easy_init (); 285 c = curl_easy_init ();
279 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); 286 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH);
280 curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); 287 curl_easy_setopt (c, CURLOPT_PORT, (long) global_port);
281 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 288 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
282 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 289 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
283 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 290 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -292,14 +299,14 @@ testMultithreadedGet (int poll_flag)
292 crashes on my system! */ 299 crashes on my system! */
293 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 300 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
294 if (CURLE_OK != (errornum = curl_easy_perform (c))) 301 if (CURLE_OK != (errornum = curl_easy_perform (c)))
295 { 302 {
296 fprintf (stderr, 303 fprintf (stderr,
297 "curl_easy_perform failed: `%s'\n", 304 "curl_easy_perform failed: `%s'\n",
298 curl_easy_strerror (errornum)); 305 curl_easy_strerror (errornum));
299 curl_easy_cleanup (c); 306 curl_easy_cleanup (c);
300 MHD_stop_daemon (d); 307 MHD_stop_daemon (d);
301 return 32; 308 return 32;
302 } 309 }
303 curl_easy_cleanup (c); 310 curl_easy_cleanup (c);
304 MHD_stop_daemon (d); 311 MHD_stop_daemon (d);
305 if (cbc.pos != strlen ("/hello_world")) 312 if (cbc.pos != strlen ("/hello_world"))
@@ -321,16 +328,17 @@ testMultithreadedPoolGet (int poll_flag)
321 328
322 if ( (0 == global_port) && 329 if ( (0 == global_port) &&
323 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) 330 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
324 { 331 {
325 global_port = 1222; 332 global_port = 1222;
326 if (oneone) 333 if (oneone)
327 global_port += 20; 334 global_port += 20;
328 } 335 }
329 336
330 cbc.buf = buf; 337 cbc.buf = buf;
331 cbc.size = 2048; 338 cbc.size = 2048;
332 cbc.pos = 0; 339 cbc.pos = 0;
333 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 340 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
341 | poll_flag,
334 global_port, NULL, NULL, 342 global_port, NULL, NULL,
335 &ahc_echo, "GET", 343 &ahc_echo, "GET",
336 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, 344 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT,
@@ -339,16 +347,18 @@ testMultithreadedPoolGet (int poll_flag)
339 if (d == NULL) 347 if (d == NULL)
340 return 16; 348 return 16;
341 if (0 == global_port) 349 if (0 == global_port)
350 {
351 const union MHD_DaemonInfo *dinfo;
352 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
353 if ((NULL == dinfo) ||(0 == dinfo->port) )
342 { 354 {
343 const union MHD_DaemonInfo *dinfo; 355 MHD_stop_daemon (d); return 32;
344 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
345 if (NULL == dinfo || 0 == dinfo->port)
346 { MHD_stop_daemon (d); return 32; }
347 global_port = (int)dinfo->port;
348 } 356 }
357 global_port = (int) dinfo->port;
358 }
349 c = curl_easy_init (); 359 c = curl_easy_init ();
350 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); 360 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH);
351 curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); 361 curl_easy_setopt (c, CURLOPT_PORT, (long) global_port);
352 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 362 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
353 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 363 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
354 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 364 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -363,14 +373,14 @@ testMultithreadedPoolGet (int poll_flag)
363 crashes on my system!*/ 373 crashes on my system!*/
364 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 374 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
365 if (CURLE_OK != (errornum = curl_easy_perform (c))) 375 if (CURLE_OK != (errornum = curl_easy_perform (c)))
366 { 376 {
367 fprintf (stderr, 377 fprintf (stderr,
368 "curl_easy_perform failed: `%s'\n", 378 "curl_easy_perform failed: `%s'\n",
369 curl_easy_strerror (errornum)); 379 curl_easy_strerror (errornum));
370 curl_easy_cleanup (c); 380 curl_easy_cleanup (c);
371 MHD_stop_daemon (d); 381 MHD_stop_daemon (d);
372 return 32; 382 return 32;
373 } 383 }
374 curl_easy_cleanup (c); 384 curl_easy_cleanup (c);
375 MHD_stop_daemon (d); 385 MHD_stop_daemon (d);
376 if (cbc.pos != strlen ("/hello_world")) 386 if (cbc.pos != strlen ("/hello_world"))
@@ -394,7 +404,7 @@ testExternalGet ()
394 fd_set ws; 404 fd_set ws;
395 fd_set es; 405 fd_set es;
396 MHD_socket maxsock; 406 MHD_socket maxsock;
397 int maxposixs; 407 int maxposixs;
398 int running; 408 int running;
399 struct CURLMsg *msg; 409 struct CURLMsg *msg;
400 time_t start; 410 time_t start;
@@ -402,11 +412,11 @@ testExternalGet ()
402 412
403 if ( (0 == global_port) && 413 if ( (0 == global_port) &&
404 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) 414 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
405 { 415 {
406 global_port = 1223; 416 global_port = 1223;
407 if (oneone) 417 if (oneone)
408 global_port += 20; 418 global_port += 20;
409 } 419 }
410 420
411 multi = NULL; 421 multi = NULL;
412 cbc.buf = buf; 422 cbc.buf = buf;
@@ -420,16 +430,18 @@ testExternalGet ()
420 if (d == NULL) 430 if (d == NULL)
421 return 256; 431 return 256;
422 if (0 == global_port) 432 if (0 == global_port)
433 {
434 const union MHD_DaemonInfo *dinfo;
435 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
436 if ((NULL == dinfo) ||(0 == dinfo->port) )
423 { 437 {
424 const union MHD_DaemonInfo *dinfo; 438 MHD_stop_daemon (d); return 32;
425 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
426 if (NULL == dinfo || 0 == dinfo->port)
427 { MHD_stop_daemon (d); return 32; }
428 global_port = (int)dinfo->port;
429 } 439 }
440 global_port = (int) dinfo->port;
441 }
430 c = curl_easy_init (); 442 c = curl_easy_init ();
431 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); 443 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH);
432 curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); 444 curl_easy_setopt (c, CURLOPT_PORT, (long) global_port);
433 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 445 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
434 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 446 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
435 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 447 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -447,90 +459,92 @@ testExternalGet ()
447 459
448 multi = curl_multi_init (); 460 multi = curl_multi_init ();
449 if (multi == NULL) 461 if (multi == NULL)
462 {
463 curl_easy_cleanup (c);
464 MHD_stop_daemon (d);
465 return 512;
466 }
467 mret = curl_multi_add_handle (multi, c);
468 if (mret != CURLM_OK)
469 {
470 curl_multi_cleanup (multi);
471 curl_easy_cleanup (c);
472 MHD_stop_daemon (d);
473 return 1024;
474 }
475 start = time (NULL);
476 while ((time (NULL) - start < 5) && (multi != NULL))
477 {
478 maxsock = MHD_INVALID_SOCKET;
479 maxposixs = -1;
480 FD_ZERO (&rs);
481 FD_ZERO (&ws);
482 FD_ZERO (&es);
483 curl_multi_perform (multi, &running);
484 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
485 if (mret != CURLM_OK)
450 { 486 {
487 curl_multi_remove_handle (multi, c);
488 curl_multi_cleanup (multi);
451 curl_easy_cleanup (c); 489 curl_easy_cleanup (c);
452 MHD_stop_daemon (d); 490 MHD_stop_daemon (d);
453 return 512; 491 return 2048;
454 } 492 }
455 mret = curl_multi_add_handle (multi, c); 493 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
456 if (mret != CURLM_OK)
457 { 494 {
495 curl_multi_remove_handle (multi, c);
458 curl_multi_cleanup (multi); 496 curl_multi_cleanup (multi);
459 curl_easy_cleanup (c); 497 curl_easy_cleanup (c);
460 MHD_stop_daemon (d); 498 MHD_stop_daemon (d);
461 return 1024; 499 return 4096;
462 } 500 }
463 start = time (NULL); 501 tv.tv_sec = 0;
464 while ((time (NULL) - start < 5) && (multi != NULL)) 502 tv.tv_usec = 1000;
465 {
466 maxsock = MHD_INVALID_SOCKET;
467 maxposixs = -1;
468 FD_ZERO (&rs);
469 FD_ZERO (&ws);
470 FD_ZERO (&es);
471 curl_multi_perform (multi, &running);
472 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
473 if (mret != CURLM_OK)
474 {
475 curl_multi_remove_handle (multi, c);
476 curl_multi_cleanup (multi);
477 curl_easy_cleanup (c);
478 MHD_stop_daemon (d);
479 return 2048;
480 }
481 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
482 {
483 curl_multi_remove_handle (multi, c);
484 curl_multi_cleanup (multi);
485 curl_easy_cleanup (c);
486 MHD_stop_daemon (d);
487 return 4096;
488 }
489 tv.tv_sec = 0;
490 tv.tv_usec = 1000;
491#ifdef MHD_POSIX_SOCKETS 503#ifdef MHD_POSIX_SOCKETS
492 if (maxsock > maxposixs) 504 if (maxsock > maxposixs)
493 maxposixs = maxsock; 505 maxposixs = maxsock;
494#endif /* MHD_POSIX_SOCKETS */ 506#endif /* MHD_POSIX_SOCKETS */
495 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) 507 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
496 { 508 {
497#ifdef MHD_POSIX_SOCKETS 509#ifdef MHD_POSIX_SOCKETS
498 if (EINTR != errno) 510 if (EINTR != errno)
499 abort (); 511 abort ();
500#else 512#else
501 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 513 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
502 _exit (99); 514 ws.fd_count)
503 Sleep (1000); 515 ||(0 != es.fd_count) )
516 _exit (99);
517 Sleep (1000);
504#endif 518#endif
505 }
506 curl_multi_perform (multi, &running);
507 if (running == 0)
508 {
509 msg = curl_multi_info_read (multi, &running);
510 if (msg == NULL)
511 break;
512 if (msg->msg == CURLMSG_DONE)
513 {
514 if (msg->data.result != CURLE_OK)
515 printf ("%s failed at %s:%d: `%s'\n",
516 "curl_multi_perform",
517 __FILE__,
518 __LINE__, curl_easy_strerror (msg->data.result));
519 curl_multi_remove_handle (multi, c);
520 curl_multi_cleanup (multi);
521 curl_easy_cleanup (c);
522 c = NULL;
523 multi = NULL;
524 }
525 }
526 MHD_run (d);
527 } 519 }
528 if (multi != NULL) 520 curl_multi_perform (multi, &running);
521 if (running == 0)
529 { 522 {
530 curl_multi_remove_handle (multi, c); 523 msg = curl_multi_info_read (multi, &running);
531 curl_easy_cleanup (c); 524 if (msg == NULL)
532 curl_multi_cleanup (multi); 525 break;
526 if (msg->msg == CURLMSG_DONE)
527 {
528 if (msg->data.result != CURLE_OK)
529 printf ("%s failed at %s:%d: `%s'\n",
530 "curl_multi_perform",
531 __FILE__,
532 __LINE__, curl_easy_strerror (msg->data.result));
533 curl_multi_remove_handle (multi, c);
534 curl_multi_cleanup (multi);
535 curl_easy_cleanup (c);
536 c = NULL;
537 multi = NULL;
538 }
533 } 539 }
540 MHD_run (d);
541 }
542 if (multi != NULL)
543 {
544 curl_multi_remove_handle (multi, c);
545 curl_easy_cleanup (c);
546 curl_multi_cleanup (multi);
547 }
534 MHD_stop_daemon (d); 548 MHD_stop_daemon (d);
535 if (cbc.pos != strlen ("/hello_world")) 549 if (cbc.pos != strlen ("/hello_world"))
536 return 8192; 550 return 8192;
@@ -553,7 +567,7 @@ testUnknownPortGet (int poll_flag)
553 567
554 struct sockaddr_in addr; 568 struct sockaddr_in addr;
555 socklen_t addr_len = sizeof(addr); 569 socklen_t addr_len = sizeof(addr);
556 memset(&addr, 0, sizeof(addr)); 570 memset (&addr, 0, sizeof(addr));
557 addr.sin_family = AF_INET; 571 addr.sin_family = AF_INET;
558 addr.sin_port = 0; 572 addr.sin_port = 0;
559 addr.sin_addr.s_addr = INADDR_ANY; 573 addr.sin_addr.s_addr = INADDR_ANY;
@@ -561,38 +575,41 @@ testUnknownPortGet (int poll_flag)
561 cbc.buf = buf; 575 cbc.buf = buf;
562 cbc.size = 2048; 576 cbc.size = 2048;
563 cbc.pos = 0; 577 cbc.pos = 0;
564 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 578 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
579 | poll_flag,
565 0, NULL, NULL, &ahc_echo, "GET", 580 0, NULL, NULL, &ahc_echo, "GET",
566 MHD_OPTION_SOCK_ADDR, &addr, 581 MHD_OPTION_SOCK_ADDR, &addr,
567 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 582 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
568 MHD_OPTION_END); 583 MHD_OPTION_END);
569 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 584 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
570 { 585 {
571 di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); 586 di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD);
572 if (di == NULL) 587 if (di == NULL)
573 return 65536; 588 return 65536;
574 589
575 if (0 != getsockname(di->listen_fd, (struct sockaddr *) &addr, &addr_len)) 590 if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len))
576 return 131072; 591 return 131072;
577 592
578 if (addr.sin_family != AF_INET) 593 if (addr.sin_family != AF_INET)
579 return 26214; 594 return 26214;
580 port = (int)ntohs(addr.sin_port); 595 port = (int) ntohs (addr.sin_port);
581 } 596 }
582 else 597 else
598 {
599 const union MHD_DaemonInfo *dinfo;
600 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
601 if ((NULL == dinfo) ||(0 == dinfo->port) )
583 { 602 {
584 const union MHD_DaemonInfo *dinfo; 603 MHD_stop_daemon (d); return 32;
585 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
586 if (NULL == dinfo || 0 == dinfo->port)
587 { MHD_stop_daemon (d); return 32; }
588 port = (int)dinfo->port;
589 } 604 }
605 port = (int) dinfo->port;
606 }
590 607
591 snprintf(buf, 608 snprintf (buf,
592 sizeof(buf), 609 sizeof(buf),
593 "http://127.0.0.1:%d%s", 610 "http://127.0.0.1:%d%s",
594 port, 611 port,
595 EXPECTED_URI_PATH); 612 EXPECTED_URI_PATH);
596 613
597 c = curl_easy_init (); 614 c = curl_easy_init ();
598 curl_easy_setopt (c, CURLOPT_URL, buf); 615 curl_easy_setopt (c, CURLOPT_URL, buf);
@@ -610,14 +627,14 @@ testUnknownPortGet (int poll_flag)
610 crashes on my system! */ 627 crashes on my system! */
611 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 628 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
612 if (CURLE_OK != (errornum = curl_easy_perform (c))) 629 if (CURLE_OK != (errornum = curl_easy_perform (c)))
613 { 630 {
614 fprintf (stderr, 631 fprintf (stderr,
615 "curl_easy_perform failed: `%s'\n", 632 "curl_easy_perform failed: `%s'\n",
616 curl_easy_strerror (errornum)); 633 curl_easy_strerror (errornum));
617 curl_easy_cleanup (c); 634 curl_easy_cleanup (c);
618 MHD_stop_daemon (d); 635 MHD_stop_daemon (d);
619 return 524288; 636 return 524288;
620 } 637 }
621 curl_easy_cleanup (c); 638 curl_easy_cleanup (c);
622 MHD_stop_daemon (d); 639 MHD_stop_daemon (d);
623 if (cbc.pos != strlen ("/hello_world")) 640 if (cbc.pos != strlen ("/hello_world"))
@@ -631,115 +648,120 @@ testUnknownPortGet (int poll_flag)
631static int 648static int
632testStopRace (int poll_flag) 649testStopRace (int poll_flag)
633{ 650{
634 struct sockaddr_in sin; 651 struct sockaddr_in sin;
635 MHD_socket fd; 652 MHD_socket fd;
636 struct MHD_Daemon *d; 653 struct MHD_Daemon *d;
637
638 if ( (0 == global_port) &&
639 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
640 {
641 global_port = 1224;
642 if (oneone)
643 global_port += 20;
644 }
645
646 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
647 global_port, NULL, NULL,
648 &ahc_echo, "GET",
649 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
650 MHD_OPTION_END);
651 if (d == NULL)
652 return 16;
653 if (0 == global_port)
654 {
655 const union MHD_DaemonInfo *dinfo;
656 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
657 if (NULL == dinfo || 0 == dinfo->port)
658 { MHD_stop_daemon (d); return 32; }
659 global_port = (int)dinfo->port;
660 }
661 654
662 fd = socket (PF_INET, SOCK_STREAM, 0); 655 if ( (0 == global_port) &&
663 if (fd == MHD_INVALID_SOCKET) 656 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
657 {
658 global_port = 1224;
659 if (oneone)
660 global_port += 20;
661 }
662
663 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
664 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
665 | poll_flag,
666 global_port, NULL, NULL,
667 &ahc_echo, "GET",
668 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
669 MHD_OPTION_END);
670 if (d == NULL)
671 return 16;
672 if (0 == global_port)
673 {
674 const union MHD_DaemonInfo *dinfo;
675 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
676 if ((NULL == dinfo) ||(0 == dinfo->port) )
664 { 677 {
665 fprintf(stderr, "socket error\n"); 678 MHD_stop_daemon (d); return 32;
666 return 256;
667 } 679 }
680 global_port = (int) dinfo->port;
681 }
668 682
669 memset(&sin, 0, sizeof(sin)); 683 fd = socket (PF_INET, SOCK_STREAM, 0);
670 sin.sin_family = AF_INET; 684 if (fd == MHD_INVALID_SOCKET)
671 sin.sin_port = htons(global_port); 685 {
672 sin.sin_addr.s_addr = htonl(0x7f000001); 686 fprintf (stderr, "socket error\n");
687 return 256;
688 }
673 689
674 if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) 690 memset (&sin, 0, sizeof(sin));
675 { 691 sin.sin_family = AF_INET;
676 fprintf(stderr, "connect error\n"); 692 sin.sin_port = htons (global_port);
677 MHD_socket_close_chk_ (fd); 693 sin.sin_addr.s_addr = htonl (0x7f000001);
678 return 512;
679 }
680 694
681 /* printf("Waiting\n"); */ 695 if (connect (fd, (struct sockaddr *) (&sin), sizeof(sin)) < 0)
682 /* Let the thread get going. */ 696 {
683 usleep(500000); 697 fprintf (stderr, "connect error\n");
698 MHD_socket_close_chk_ (fd);
699 return 512;
700 }
684 701
685 /* printf("Stopping daemon\n"); */ 702 /* printf("Waiting\n"); */
686 MHD_stop_daemon (d); 703 /* Let the thread get going. */
704 usleep (500000);
687 705
688 MHD_socket_close_chk_ (fd); 706 /* printf("Stopping daemon\n"); */
707 MHD_stop_daemon (d);
708
709 MHD_socket_close_chk_ (fd);
689 710
690 /* printf("good\n"); */ 711 /* printf("good\n"); */
691 return 0; 712 return 0;
692} 713}
693 714
694 715
695static int 716static int
696ahc_empty (void *cls, 717ahc_empty (void *cls,
697 struct MHD_Connection *connection, 718 struct MHD_Connection *connection,
698 const char *url, 719 const char *url,
699 const char *method, 720 const char *method,
700 const char *version, 721 const char *version,
701 const char *upload_data, size_t *upload_data_size, 722 const char *upload_data, size_t *upload_data_size,
702 void **unused) 723 void **unused)
703{ 724{
704 static int ptr; 725 static int ptr;
705 struct MHD_Response *response; 726 struct MHD_Response *response;
706 int ret; 727 int ret;
707 (void)cls;(void)url;(void)url;(void)version; /* Unused. Silent compiler warning. */ 728 (void) cls; (void) url; (void) url; (void) version; /* Unused. Silent compiler warning. */
708 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 729 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
709 730
710 if (0 != strcasecmp ("GET", method)) 731 if (0 != strcasecmp ("GET", method))
711 return MHD_NO; /* unexpected method */ 732 return MHD_NO; /* unexpected method */
712 if (&ptr != *unused) 733 if (&ptr != *unused)
713 { 734 {
714 *unused = &ptr; 735 *unused = &ptr;
715 return MHD_YES; 736 return MHD_YES;
716 } 737 }
717 *unused = NULL; 738 *unused = NULL;
718 response = MHD_create_response_from_buffer (0, 739 response = MHD_create_response_from_buffer (0,
719 NULL, 740 NULL,
720 MHD_RESPMEM_PERSISTENT); 741 MHD_RESPMEM_PERSISTENT);
721 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 742 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
722 MHD_destroy_response (response); 743 MHD_destroy_response (response);
723 if (ret == MHD_NO) 744 if (ret == MHD_NO)
724 { 745 {
725 fprintf (stderr, "Failed to queue response.\n"); 746 fprintf (stderr, "Failed to queue response.\n");
726 _exit (20); 747 _exit (20);
727 } 748 }
728 return ret; 749 return ret;
729} 750}
730 751
731 752
732static int 753static int
733curlExcessFound(CURL *c, curl_infotype type, char *data, size_t size, void *cls) 754curlExcessFound (CURL *c, curl_infotype type, char *data, size_t size,
755 void *cls)
734{ 756{
735 static const char *excess_found = "Excess found"; 757 static const char *excess_found = "Excess found";
736 const size_t str_size = strlen (excess_found); 758 const size_t str_size = strlen (excess_found);
737 (void)c; /* Unused. Silent compiler warning. */ 759 (void) c; /* Unused. Silent compiler warning. */
738 760
739 if (CURLINFO_TEXT == type 761 if ((CURLINFO_TEXT == type)
740 && size >= str_size 762 &&(size >= str_size)
741 && 0 == strncmp(excess_found, data, str_size)) 763 &&(0 == strncmp (excess_found, data, str_size)))
742 *(int *)cls = 1; 764 *(int *) cls = 1;
743 return 0; 765 return 0;
744} 766}
745 767
@@ -756,16 +778,17 @@ testEmptyGet (int poll_flag)
756 778
757 if ( (0 == global_port) && 779 if ( (0 == global_port) &&
758 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) 780 (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) )
759 { 781 {
760 global_port = 1225; 782 global_port = 1225;
761 if (oneone) 783 if (oneone)
762 global_port += 20; 784 global_port += 20;
763 } 785 }
764 786
765 cbc.buf = buf; 787 cbc.buf = buf;
766 cbc.size = 2048; 788 cbc.size = 2048;
767 cbc.pos = 0; 789 cbc.pos = 0;
768 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 790 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
791 | poll_flag,
769 global_port, NULL, NULL, 792 global_port, NULL, NULL,
770 &ahc_empty, NULL, 793 &ahc_empty, NULL,
771 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 794 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
@@ -773,16 +796,18 @@ testEmptyGet (int poll_flag)
773 if (d == NULL) 796 if (d == NULL)
774 return 4194304; 797 return 4194304;
775 if (0 == global_port) 798 if (0 == global_port)
799 {
800 const union MHD_DaemonInfo *dinfo;
801 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
802 if ((NULL == dinfo) ||(0 == dinfo->port) )
776 { 803 {
777 const union MHD_DaemonInfo *dinfo; 804 MHD_stop_daemon (d); return 32;
778 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
779 if (NULL == dinfo || 0 == dinfo->port)
780 { MHD_stop_daemon (d); return 32; }
781 global_port = (int)dinfo->port;
782 } 805 }
806 global_port = (int) dinfo->port;
807 }
783 c = curl_easy_init (); 808 c = curl_easy_init ();
784 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); 809 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH);
785 curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); 810 curl_easy_setopt (c, CURLOPT_PORT, (long) global_port);
786 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 811 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
787 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 812 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
788 curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); 813 curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound);
@@ -800,14 +825,14 @@ testEmptyGet (int poll_flag)
800 crashes on my system!*/ 825 crashes on my system!*/
801 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 826 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
802 if (CURLE_OK != (errornum = curl_easy_perform (c))) 827 if (CURLE_OK != (errornum = curl_easy_perform (c)))
803 { 828 {
804 fprintf (stderr, 829 fprintf (stderr,
805 "curl_easy_perform failed: `%s'\n", 830 "curl_easy_perform failed: `%s'\n",
806 curl_easy_strerror (errornum)); 831 curl_easy_strerror (errornum));
807 curl_easy_cleanup (c); 832 curl_easy_cleanup (c);
808 MHD_stop_daemon (d); 833 MHD_stop_daemon (d);
809 return 8388608; 834 return 8388608;
810 } 835 }
811 curl_easy_cleanup (c); 836 curl_easy_cleanup (c);
812 MHD_stop_daemon (d); 837 MHD_stop_daemon (d);
813 if (cbc.pos != 0) 838 if (cbc.pos != 0)
@@ -825,7 +850,7 @@ main (int argc, char *const *argv)
825 unsigned int test_result = 0; 850 unsigned int test_result = 0;
826 int verbose = 0; 851 int verbose = 0;
827 852
828 if (NULL == argv || 0 == argv[0]) 853 if ((NULL == argv)||(0 == argv[0]))
829 return 99; 854 return 99;
830 oneone = has_in_name (argv[0], "11"); 855 oneone = has_in_name (argv[0], "11");
831 verbose = has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose"); 856 verbose = has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose");
@@ -838,115 +863,128 @@ main (int argc, char *const *argv)
838 else if (verbose) 863 else if (verbose)
839 printf ("PASSED: testExternalGet ().\n"); 864 printf ("PASSED: testExternalGet ().\n");
840 errorCount += test_result; 865 errorCount += test_result;
841 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 866 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
842 { 867 {
843 test_result += testInternalGet (0); 868 test_result += testInternalGet (0);
869 if (test_result)
870 fprintf (stderr, "FAILED: testInternalGet (0) - %u.\n", test_result);
871 else if (verbose)
872 printf ("PASSED: testInternalGet (0).\n");
873 errorCount += test_result;
874 test_result += testMultithreadedGet (0);
875 if (test_result)
876 fprintf (stderr, "FAILED: testMultithreadedGet (0) - %u.\n", test_result);
877 else if (verbose)
878 printf ("PASSED: testMultithreadedGet (0).\n");
879 errorCount += test_result;
880 test_result += testMultithreadedPoolGet (0);
881 if (test_result)
882 fprintf (stderr, "FAILED: testMultithreadedPoolGet (0) - %u.\n",
883 test_result);
884 else if (verbose)
885 printf ("PASSED: testMultithreadedPoolGet (0).\n");
886 errorCount += test_result;
887 test_result += testUnknownPortGet (0);
888 if (test_result)
889 fprintf (stderr, "FAILED: testUnknownPortGet (0) - %u.\n", test_result);
890 else if (verbose)
891 printf ("PASSED: testUnknownPortGet (0).\n");
892 errorCount += test_result;
893 test_result += testStopRace (0);
894 if (test_result)
895 fprintf (stderr, "FAILED: testStopRace (0) - %u.\n", test_result);
896 else if (verbose)
897 printf ("PASSED: testStopRace (0).\n");
898 errorCount += test_result;
899 test_result += testEmptyGet (0);
900 if (test_result)
901 fprintf (stderr, "FAILED: testEmptyGet (0) - %u.\n", test_result);
902 else if (verbose)
903 printf ("PASSED: testEmptyGet (0).\n");
904 errorCount += test_result;
905 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
906 {
907 test_result += testInternalGet (MHD_USE_POLL);
908 if (test_result)
909 fprintf (stderr, "FAILED: testInternalGet (MHD_USE_POLL) - %u.\n",
910 test_result);
911 else if (verbose)
912 printf ("PASSED: testInternalGet (MHD_USE_POLL).\n");
913 errorCount += test_result;
914 test_result += testMultithreadedGet (MHD_USE_POLL);
915 if (test_result)
916 fprintf (stderr, "FAILED: testMultithreadedGet (MHD_USE_POLL) - %u.\n",
917 test_result);
918 else if (verbose)
919 printf ("PASSED: testMultithreadedGet (MHD_USE_POLL).\n");
920 errorCount += test_result;
921 test_result += testMultithreadedPoolGet (MHD_USE_POLL);
844 if (test_result) 922 if (test_result)
845 fprintf (stderr, "FAILED: testInternalGet (0) - %u.\n", test_result); 923 fprintf (stderr,
924 "FAILED: testMultithreadedPoolGet (MHD_USE_POLL) - %u.\n",
925 test_result);
846 else if (verbose) 926 else if (verbose)
847 printf ("PASSED: testInternalGet (0).\n"); 927 printf ("PASSED: testMultithreadedPoolGet (MHD_USE_POLL).\n");
848 errorCount += test_result; 928 errorCount += test_result;
849 test_result += testMultithreadedGet (0); 929 test_result += testUnknownPortGet (MHD_USE_POLL);
850 if (test_result) 930 if (test_result)
851 fprintf (stderr, "FAILED: testMultithreadedGet (0) - %u.\n", test_result); 931 fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_POLL) - %u.\n",
932 test_result);
852 else if (verbose) 933 else if (verbose)
853 printf ("PASSED: testMultithreadedGet (0).\n"); 934 printf ("PASSED: testUnknownPortGet (MHD_USE_POLL).\n");
854 errorCount += test_result; 935 errorCount += test_result;
855 test_result += testMultithreadedPoolGet (0); 936 test_result += testStopRace (MHD_USE_POLL);
937 if (test_result)
938 fprintf (stderr, "FAILED: testStopRace (MHD_USE_POLL) - %u.\n",
939 test_result);
940 else if (verbose)
941 printf ("PASSED: testStopRace (MHD_USE_POLL).\n");
942 errorCount += test_result;
943 test_result += testEmptyGet (MHD_USE_POLL);
944 if (test_result)
945 fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_POLL) - %u.\n",
946 test_result);
947 else if (verbose)
948 printf ("PASSED: testEmptyGet (MHD_USE_POLL).\n");
949 errorCount += test_result;
950 }
951 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
952 {
953 test_result += testInternalGet (MHD_USE_EPOLL);
856 if (test_result) 954 if (test_result)
857 fprintf (stderr, "FAILED: testMultithreadedPoolGet (0) - %u.\n", test_result); 955 fprintf (stderr, "FAILED: testInternalGet (MHD_USE_EPOLL) - %u.\n",
956 test_result);
858 else if (verbose) 957 else if (verbose)
859 printf ("PASSED: testMultithreadedPoolGet (0).\n"); 958 printf ("PASSED: testInternalGet (MHD_USE_EPOLL).\n");
860 errorCount += test_result; 959 errorCount += test_result;
861 test_result += testUnknownPortGet (0); 960 test_result += testMultithreadedPoolGet (MHD_USE_EPOLL);
862 if (test_result) 961 if (test_result)
863 fprintf (stderr, "FAILED: testUnknownPortGet (0) - %u.\n", test_result); 962 fprintf (stderr,
963 "FAILED: testMultithreadedPoolGet (MHD_USE_EPOLL) - %u.\n",
964 test_result);
864 else if (verbose) 965 else if (verbose)
865 printf ("PASSED: testUnknownPortGet (0).\n"); 966 printf ("PASSED: testMultithreadedPoolGet (MHD_USE_EPOLL).\n");
866 errorCount += test_result; 967 errorCount += test_result;
867 test_result += testStopRace (0); 968 test_result += testUnknownPortGet (MHD_USE_EPOLL);
868 if (test_result) 969 if (test_result)
869 fprintf (stderr, "FAILED: testStopRace (0) - %u.\n", test_result); 970 fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_EPOLL) - %u.\n",
971 test_result);
870 else if (verbose) 972 else if (verbose)
871 printf ("PASSED: testStopRace (0).\n"); 973 printf ("PASSED: testUnknownPortGet (MHD_USE_EPOLL).\n");
872 errorCount += test_result; 974 errorCount += test_result;
873 test_result += testEmptyGet (0); 975 test_result += testEmptyGet (MHD_USE_EPOLL);
874 if (test_result) 976 if (test_result)
875 fprintf (stderr, "FAILED: testEmptyGet (0) - %u.\n", test_result); 977 fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_EPOLL) - %u.\n",
978 test_result);
876 else if (verbose) 979 else if (verbose)
877 printf ("PASSED: testEmptyGet (0).\n"); 980 printf ("PASSED: testEmptyGet (MHD_USE_EPOLL).\n");
878 errorCount += test_result; 981 errorCount += test_result;
879 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
880 {
881 test_result += testInternalGet(MHD_USE_POLL);
882 if (test_result)
883 fprintf (stderr, "FAILED: testInternalGet (MHD_USE_POLL) - %u.\n", test_result);
884 else if (verbose)
885 printf ("PASSED: testInternalGet (MHD_USE_POLL).\n");
886 errorCount += test_result;
887 test_result += testMultithreadedGet(MHD_USE_POLL);
888 if (test_result)
889 fprintf (stderr, "FAILED: testMultithreadedGet (MHD_USE_POLL) - %u.\n", test_result);
890 else if (verbose)
891 printf ("PASSED: testMultithreadedGet (MHD_USE_POLL).\n");
892 errorCount += test_result;
893 test_result += testMultithreadedPoolGet(MHD_USE_POLL);
894 if (test_result)
895 fprintf (stderr, "FAILED: testMultithreadedPoolGet (MHD_USE_POLL) - %u.\n", test_result);
896 else if (verbose)
897 printf ("PASSED: testMultithreadedPoolGet (MHD_USE_POLL).\n");
898 errorCount += test_result;
899 test_result += testUnknownPortGet(MHD_USE_POLL);
900 if (test_result)
901 fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_POLL) - %u.\n", test_result);
902 else if (verbose)
903 printf ("PASSED: testUnknownPortGet (MHD_USE_POLL).\n");
904 errorCount += test_result;
905 test_result += testStopRace(MHD_USE_POLL);
906 if (test_result)
907 fprintf (stderr, "FAILED: testStopRace (MHD_USE_POLL) - %u.\n", test_result);
908 else if (verbose)
909 printf ("PASSED: testStopRace (MHD_USE_POLL).\n");
910 errorCount += test_result;
911 test_result += testEmptyGet(MHD_USE_POLL);
912 if (test_result)
913 fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_POLL) - %u.\n", test_result);
914 else if (verbose)
915 printf ("PASSED: testEmptyGet (MHD_USE_POLL).\n");
916 errorCount += test_result;
917 }
918 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
919 {
920 test_result += testInternalGet(MHD_USE_EPOLL);
921 if (test_result)
922 fprintf (stderr, "FAILED: testInternalGet (MHD_USE_EPOLL) - %u.\n", test_result);
923 else if (verbose)
924 printf ("PASSED: testInternalGet (MHD_USE_EPOLL).\n");
925 errorCount += test_result;
926 test_result += testMultithreadedPoolGet(MHD_USE_EPOLL);
927 if (test_result)
928 fprintf (stderr, "FAILED: testMultithreadedPoolGet (MHD_USE_EPOLL) - %u.\n", test_result);
929 else if (verbose)
930 printf ("PASSED: testMultithreadedPoolGet (MHD_USE_EPOLL).\n");
931 errorCount += test_result;
932 test_result += testUnknownPortGet(MHD_USE_EPOLL);
933 if (test_result)
934 fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_EPOLL) - %u.\n", test_result);
935 else if (verbose)
936 printf ("PASSED: testUnknownPortGet (MHD_USE_EPOLL).\n");
937 errorCount += test_result;
938 test_result += testEmptyGet(MHD_USE_EPOLL);
939 if (test_result)
940 fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_EPOLL) - %u.\n", test_result);
941 else if (verbose)
942 printf ("PASSED: testEmptyGet (MHD_USE_EPOLL).\n");
943 errorCount += test_result;
944 }
945 } 982 }
983 }
946 if (0 != errorCount) 984 if (0 != errorCount)
947 fprintf (stderr, 985 fprintf (stderr,
948 "Error (code: %u)\n", 986 "Error (code: %u)\n",
949 errorCount); 987 errorCount);
950 else if (verbose) 988 else if (verbose)
951 printf ("All tests passed.\n"); 989 printf ("All tests passed.\n");
952 curl_global_cleanup (); 990 curl_global_cleanup ();
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index c7be5c83..9916a902 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -40,10 +40,10 @@
40#include <unistd.h> 40#include <unistd.h>
41#endif 41#endif
42 42
43#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 43#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
44#undef CPU_COUNT 44#undef CPU_COUNT
45#endif 45#endif
46#if !defined(CPU_COUNT) 46#if ! defined(CPU_COUNT)
47#define CPU_COUNT 2 47#define CPU_COUNT 2
48#endif 48#endif
49 49
@@ -120,19 +120,19 @@ ahc_echo (void *cls,
120 struct MHD_Response **responseptr; 120 struct MHD_Response **responseptr;
121 int ret; 121 int ret;
122 122
123 (void)url; 123 (void) url;
124 (void)version; /* Unused. Silent compiler warning. */ 124 (void) version; /* Unused. Silent compiler warning. */
125 (void)upload_data; 125 (void) upload_data;
126 (void)upload_data_size; /* Unused. Silent compiler warning. */ 126 (void) upload_data_size; /* Unused. Silent compiler warning. */
127 127
128 if (0 != strcmp (me, method)) 128 if (0 != strcmp (me, method))
129 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
130 if (&aptr != *ptr) 130 if (&aptr != *ptr)
131 { 131 {
132 /* do never respond on first call */ 132 /* do never respond on first call */
133 *ptr = &aptr; 133 *ptr = &aptr;
134 return MHD_YES; 134 return MHD_YES;
135 } 135 }
136 responseptr = malloc (sizeof (struct MHD_Response *)); 136 responseptr = malloc (sizeof (struct MHD_Response *));
137 if (NULL == responseptr) 137 if (NULL == responseptr)
138 return MHD_NO; 138 return MHD_NO;
@@ -165,16 +165,16 @@ validate (struct CBC cbc, int ebase)
165 return ebase; 165 return ebase;
166 166
167 for (i = 0; i < 10; i++) 167 for (i = 0; i < 10; i++)
168 {
169 memset (buf, 'A' + i, 128);
170 if (0 != memcmp (buf, &cbc.buf[i * 128], 128))
168 { 171 {
169 memset (buf, 'A' + i, 128); 172 fprintf (stderr,
170 if (0 != memcmp (buf, &cbc.buf[i * 128], 128)) 173 "Got `%.*s'\nWant `%.*s'\n",
171 { 174 128, buf, 128, &cbc.buf[i * 128]);
172 fprintf (stderr, 175 return ebase * 2;
173 "Got `%.*s'\nWant `%.*s'\n",
174 128, buf, 128, &cbc.buf[i * 128]);
175 return ebase * 2;
176 }
177 } 176 }
177 }
178 return 0; 178 return 0;
179} 179}
180 180
@@ -201,16 +201,18 @@ testInternalGet ()
201 if (d == NULL) 201 if (d == NULL)
202 return 1; 202 return 1;
203 if (0 == port) 203 if (0 == port)
204 {
205 const union MHD_DaemonInfo *dinfo;
206 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
207 if ((NULL == dinfo) ||(0 == dinfo->port) )
204 { 208 {
205 const union MHD_DaemonInfo *dinfo; 209 MHD_stop_daemon (d); return 32;
206 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
207 if (NULL == dinfo || 0 == dinfo->port)
208 { MHD_stop_daemon (d); return 32; }
209 port = (int)dinfo->port;
210 } 210 }
211 port = (int) dinfo->port;
212 }
211 c = curl_easy_init (); 213 c = curl_easy_init ();
212 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 214 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
213 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 215 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
214 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 216 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
215 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 217 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
216 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 218 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -222,14 +224,14 @@ testInternalGet ()
222 * crashes on my system! */ 224 * crashes on my system! */
223 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 225 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
224 if (CURLE_OK != (errornum = curl_easy_perform (c))) 226 if (CURLE_OK != (errornum = curl_easy_perform (c)))
225 { 227 {
226 fprintf (stderr, 228 fprintf (stderr,
227 "curl_easy_perform failed: `%s'\n", 229 "curl_easy_perform failed: `%s'\n",
228 curl_easy_strerror (errornum)); 230 curl_easy_strerror (errornum));
229 curl_easy_cleanup (c); 231 curl_easy_cleanup (c);
230 MHD_stop_daemon (d); 232 MHD_stop_daemon (d);
231 return 2; 233 return 2;
232 } 234 }
233 curl_easy_cleanup (c); 235 curl_easy_cleanup (c);
234 MHD_stop_daemon (d); 236 MHD_stop_daemon (d);
235 return validate (cbc, 4); 237 return validate (cbc, 4);
@@ -253,21 +255,24 @@ testMultithreadedGet ()
253 cbc.buf = buf; 255 cbc.buf = buf;
254 cbc.size = 2048; 256 cbc.size = 2048;
255 cbc.pos = 0; 257 cbc.pos = 0;
256 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 258 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
259 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
257 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 260 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
258 if (d == NULL) 261 if (d == NULL)
259 return 16; 262 return 16;
260 if (0 == port) 263 if (0 == port)
264 {
265 const union MHD_DaemonInfo *dinfo;
266 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
267 if ((NULL == dinfo) ||(0 == dinfo->port) )
261 { 268 {
262 const union MHD_DaemonInfo *dinfo; 269 MHD_stop_daemon (d); return 32;
263 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
264 if (NULL == dinfo || 0 == dinfo->port)
265 { MHD_stop_daemon (d); return 32; }
266 port = (int)dinfo->port;
267 } 270 }
271 port = (int) dinfo->port;
272 }
268 c = curl_easy_init (); 273 c = curl_easy_init ();
269 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 274 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
270 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 275 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
271 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 276 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
272 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 277 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
273 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 278 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -279,14 +284,14 @@ testMultithreadedGet ()
279 * crashes on my system! */ 284 * crashes on my system! */
280 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 285 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
281 if (CURLE_OK != (errornum = curl_easy_perform (c))) 286 if (CURLE_OK != (errornum = curl_easy_perform (c)))
282 { 287 {
283 fprintf (stderr, 288 fprintf (stderr,
284 "curl_easy_perform failed: `%s'\n", 289 "curl_easy_perform failed: `%s'\n",
285 curl_easy_strerror (errornum)); 290 curl_easy_strerror (errornum));
286 curl_easy_cleanup (c); 291 curl_easy_cleanup (c);
287 MHD_stop_daemon (d); 292 MHD_stop_daemon (d);
288 return 32; 293 return 32;
289 } 294 }
290 curl_easy_cleanup (c); 295 curl_easy_cleanup (c);
291 MHD_stop_daemon (d); 296 MHD_stop_daemon (d);
292 return validate (cbc, 64); 297 return validate (cbc, 64);
@@ -316,16 +321,18 @@ testMultithreadedPoolGet ()
316 if (d == NULL) 321 if (d == NULL)
317 return 16; 322 return 16;
318 if (0 == port) 323 if (0 == port)
324 {
325 const union MHD_DaemonInfo *dinfo;
326 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
327 if ((NULL == dinfo) ||(0 == dinfo->port) )
319 { 328 {
320 const union MHD_DaemonInfo *dinfo; 329 MHD_stop_daemon (d); return 32;
321 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
322 if (NULL == dinfo || 0 == dinfo->port)
323 { MHD_stop_daemon (d); return 32; }
324 port = (int)dinfo->port;
325 } 330 }
331 port = (int) dinfo->port;
332 }
326 c = curl_easy_init (); 333 c = curl_easy_init ();
327 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 334 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
328 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 335 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
329 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 336 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
330 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 337 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
331 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 338 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -337,14 +344,14 @@ testMultithreadedPoolGet ()
337 * crashes on my system! */ 344 * crashes on my system! */
338 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 345 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
339 if (CURLE_OK != (errornum = curl_easy_perform (c))) 346 if (CURLE_OK != (errornum = curl_easy_perform (c)))
340 { 347 {
341 fprintf (stderr, 348 fprintf (stderr,
342 "curl_easy_perform failed: `%s'\n", 349 "curl_easy_perform failed: `%s'\n",
343 curl_easy_strerror (errornum)); 350 curl_easy_strerror (errornum));
344 curl_easy_cleanup (c); 351 curl_easy_cleanup (c);
345 MHD_stop_daemon (d); 352 MHD_stop_daemon (d);
346 return 32; 353 return 32;
347 } 354 }
348 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
349 MHD_stop_daemon (d); 356 MHD_stop_daemon (d);
350 return validate (cbc, 64); 357 return validate (cbc, 64);
@@ -388,16 +395,18 @@ testExternalGet ()
388 if (d == NULL) 395 if (d == NULL)
389 return 256; 396 return 256;
390 if (0 == port) 397 if (0 == port)
398 {
399 const union MHD_DaemonInfo *dinfo;
400 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
401 if ((NULL == dinfo) ||(0 == dinfo->port) )
391 { 402 {
392 const union MHD_DaemonInfo *dinfo; 403 MHD_stop_daemon (d); return 32;
393 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
394 if (NULL == dinfo || 0 == dinfo->port)
395 { MHD_stop_daemon (d); return 32; }
396 port = (int)dinfo->port;
397 } 404 }
405 port = (int) dinfo->port;
406 }
398 c = curl_easy_init (); 407 c = curl_easy_init ();
399 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 408 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
400 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 409 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
401 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 410 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
402 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 411 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
403 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 412 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -412,86 +421,88 @@ testExternalGet ()
412 421
413 multi = curl_multi_init (); 422 multi = curl_multi_init ();
414 if (multi == NULL) 423 if (multi == NULL)
424 {
425 curl_easy_cleanup (c);
426 MHD_stop_daemon (d);
427 return 512;
428 }
429 mret = curl_multi_add_handle (multi, c);
430 if (mret != CURLM_OK)
431 {
432 curl_multi_cleanup (multi);
433 curl_easy_cleanup (c);
434 MHD_stop_daemon (d);
435 return 1024;
436 }
437 start = time (NULL);
438 while ((time (NULL) - start < 5) && (multi != NULL))
439 {
440 maxsock = MHD_INVALID_SOCKET;
441 maxposixs = -1;
442 FD_ZERO (&rs);
443 FD_ZERO (&ws);
444 FD_ZERO (&es);
445 curl_multi_perform (multi, &running);
446 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
447 if (mret != CURLM_OK)
415 { 448 {
449 curl_multi_remove_handle (multi, c);
450 curl_multi_cleanup (multi);
416 curl_easy_cleanup (c); 451 curl_easy_cleanup (c);
417 MHD_stop_daemon (d); 452 MHD_stop_daemon (d);
418 return 512; 453 return 2048;
419 } 454 }
420 mret = curl_multi_add_handle (multi, c); 455 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
421 if (mret != CURLM_OK)
422 { 456 {
457 curl_multi_remove_handle (multi, c);
423 curl_multi_cleanup (multi); 458 curl_multi_cleanup (multi);
424 curl_easy_cleanup (c); 459 curl_easy_cleanup (c);
425 MHD_stop_daemon (d); 460 MHD_stop_daemon (d);
426 return 1024; 461 return 4096;
427 } 462 }
428 start = time (NULL); 463 tv.tv_sec = 0;
429 while ((time (NULL) - start < 5) && (multi != NULL)) 464 tv.tv_usec = 1000;
465 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
430 { 466 {
431 maxsock = MHD_INVALID_SOCKET;
432 maxposixs = -1;
433 FD_ZERO (&rs);
434 FD_ZERO (&ws);
435 FD_ZERO (&es);
436 curl_multi_perform (multi, &running);
437 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
438 if (mret != CURLM_OK)
439 {
440 curl_multi_remove_handle (multi, c);
441 curl_multi_cleanup (multi);
442 curl_easy_cleanup (c);
443 MHD_stop_daemon (d);
444 return 2048;
445 }
446 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
447 {
448 curl_multi_remove_handle (multi, c);
449 curl_multi_cleanup (multi);
450 curl_easy_cleanup (c);
451 MHD_stop_daemon (d);
452 return 4096;
453 }
454 tv.tv_sec = 0;
455 tv.tv_usec = 1000;
456 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
457 {
458#ifdef MHD_POSIX_SOCKETS 467#ifdef MHD_POSIX_SOCKETS
459 if (EINTR != errno) 468 if (EINTR != errno)
460 abort (); 469 abort ();
461#else 470#else
462 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 471 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
463 abort (); 472 ws.fd_count)
464 Sleep (1000); 473 ||(0 != es.fd_count) )
474 abort ();
475 Sleep (1000);
465#endif 476#endif
466 }
467 curl_multi_perform (multi, &running);
468 if (running == 0)
469 {
470 msg = curl_multi_info_read (multi, &running);
471 if (msg == NULL)
472 break;
473 if (msg->msg == CURLMSG_DONE)
474 {
475 if (msg->data.result != CURLE_OK)
476 printf ("%s failed at %s:%d: `%s'\n",
477 "curl_multi_perform",
478 __FILE__,
479 __LINE__, curl_easy_strerror (msg->data.result));
480 curl_multi_remove_handle (multi, c);
481 curl_multi_cleanup (multi);
482 curl_easy_cleanup (c);
483 c = NULL;
484 multi = NULL;
485 }
486 }
487 MHD_run (d);
488 } 477 }
489 if (multi != NULL) 478 curl_multi_perform (multi, &running);
479 if (running == 0)
490 { 480 {
491 curl_multi_remove_handle (multi, c); 481 msg = curl_multi_info_read (multi, &running);
492 curl_easy_cleanup (c); 482 if (msg == NULL)
493 curl_multi_cleanup (multi); 483 break;
484 if (msg->msg == CURLMSG_DONE)
485 {
486 if (msg->data.result != CURLE_OK)
487 printf ("%s failed at %s:%d: `%s'\n",
488 "curl_multi_perform",
489 __FILE__,
490 __LINE__, curl_easy_strerror (msg->data.result));
491 curl_multi_remove_handle (multi, c);
492 curl_multi_cleanup (multi);
493 curl_easy_cleanup (c);
494 c = NULL;
495 multi = NULL;
496 }
494 } 497 }
498 MHD_run (d);
499 }
500 if (multi != NULL)
501 {
502 curl_multi_remove_handle (multi, c);
503 curl_easy_cleanup (c);
504 curl_multi_cleanup (multi);
505 }
495 MHD_stop_daemon (d); 506 MHD_stop_daemon (d);
496 return validate (cbc, 8192); 507 return validate (cbc, 8192);
497} 508}
@@ -502,16 +513,16 @@ int
502main (int argc, char *const *argv) 513main (int argc, char *const *argv)
503{ 514{
504 unsigned int errorCount = 0; 515 unsigned int errorCount = 0;
505 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 516 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
506 517
507 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 518 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
508 return 2; 519 return 2;
509 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 520 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
510 { 521 {
511 errorCount += testInternalGet (); 522 errorCount += testInternalGet ();
512 errorCount += testMultithreadedGet (); 523 errorCount += testMultithreadedGet ();
513 errorCount += testMultithreadedPoolGet (); 524 errorCount += testMultithreadedPoolGet ();
514 } 525 }
515 errorCount += testExternalGet (); 526 errorCount += testExternalGet ();
516 if (errorCount != 0) 527 if (errorCount != 0)
517 fprintf (stderr, "Error (code: %u)\n", errorCount); 528 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c
index 66653a93..04fe3204 100644
--- a/src/testcurl/test_get_response_cleanup.c
+++ b/src/testcurl/test_get_response_cleanup.c
@@ -53,10 +53,10 @@
53 53
54#include "mhd_has_in_name.h" 54#include "mhd_has_in_name.h"
55 55
56#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 56#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
57#undef CPU_COUNT 57#undef CPU_COUNT
58#endif 58#endif
59#if !defined(CPU_COUNT) 59#if ! defined(CPU_COUNT)
60#define CPU_COUNT 2 60#define CPU_COUNT 2
61#endif 61#endif
62 62
@@ -72,13 +72,13 @@ fork_curl (const char *url)
72{ 72{
73 pid_t ret; 73 pid_t ret;
74 74
75 ret = fork(); 75 ret = fork ();
76 if (ret != 0) 76 if (ret != 0)
77 return ret; 77 return ret;
78 execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL); 78 execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL);
79 fprintf (stderr, 79 fprintf (stderr,
80 "Failed to exec curl: %s\n", 80 "Failed to exec curl: %s\n",
81 strerror (errno)); 81 strerror (errno));
82 _exit (-1); 82 _exit (-1);
83} 83}
84 84
@@ -88,7 +88,7 @@ kill_curl (pid_t pid)
88{ 88{
89 int status; 89 int status;
90 90
91 //fprintf (stderr, "Killing curl\n"); 91 // fprintf (stderr, "Killing curl\n");
92 kill (pid, SIGTERM); 92 kill (pid, SIGTERM);
93 waitpid (pid, &status, 0); 93 waitpid (pid, &status, 0);
94} 94}
@@ -97,7 +97,7 @@ kill_curl (pid_t pid)
97static ssize_t 97static ssize_t
98push_callback (void *cls, uint64_t pos, char *buf, size_t max) 98push_callback (void *cls, uint64_t pos, char *buf, size_t max)
99{ 99{
100 (void)cls;(void)pos; /* Unused. Silent compiler warning. */ 100 (void) cls; (void) pos; /* Unused. Silent compiler warning. */
101 101
102 if (max == 0) 102 if (max == 0)
103 return 0; 103 return 0;
@@ -111,7 +111,7 @@ push_free_callback (void *cls)
111{ 111{
112 int *ok = cls; 112 int *ok = cls;
113 113
114 //fprintf (stderr, "Cleanup callback called!\n"); 114 // fprintf (stderr, "Cleanup callback called!\n");
115 *ok = 0; 115 *ok = 0;
116} 116}
117 117
@@ -129,23 +129,23 @@ ahc_echo (void *cls,
129 const char *me = cls; 129 const char *me = cls;
130 struct MHD_Response *response; 130 struct MHD_Response *response;
131 int ret; 131 int ret;
132 (void)url;(void)version; /* Unused. Silent compiler warning. */ 132 (void) url; (void) version; /* Unused. Silent compiler warning. */
133 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 133 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
134 134
135 //fprintf (stderr, "In CB: %s!\n", method); 135 // fprintf (stderr, "In CB: %s!\n", method);
136 if (0 != strcmp (me, method)) 136 if (0 != strcmp (me, method))
137 return MHD_NO; /* unexpected method */ 137 return MHD_NO; /* unexpected method */
138 if (&ptr != *unused) 138 if (&ptr != *unused)
139 { 139 {
140 *unused = &ptr; 140 *unused = &ptr;
141 return MHD_YES; 141 return MHD_YES;
142 } 142 }
143 *unused = NULL; 143 *unused = NULL;
144 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 144 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
145 32 * 1024, 145 32 * 1024,
146 &push_callback, 146 &push_callback,
147 &ok, 147 &ok,
148 &push_free_callback); 148 &push_free_callback);
149 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 149 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
150 MHD_destroy_response (response); 150 MHD_destroy_response (response);
151 if (ret == MHD_NO) 151 if (ret == MHD_NO)
@@ -165,11 +165,11 @@ testInternalGet ()
165 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 165 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
166 port = 0; 166 port = 0;
167 else 167 else
168 { 168 {
169 port = 1180; 169 port = 1180;
170 if (oneone) 170 if (oneone)
171 port += 10; 171 port += 10;
172 } 172 }
173 173
174 ok = 1; 174 ok = 1;
175 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 175 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -177,21 +177,23 @@ testInternalGet ()
177 if (d == NULL) 177 if (d == NULL)
178 return 1; 178 return 1;
179 if (0 == port) 179 if (0 == port)
180 {
181 const union MHD_DaemonInfo *dinfo;
182 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
183 if ((NULL == dinfo) ||(0 == dinfo->port) )
180 { 184 {
181 const union MHD_DaemonInfo *dinfo; 185 MHD_stop_daemon (d); return 32;
182 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
183 if (NULL == dinfo || 0 == dinfo->port)
184 { MHD_stop_daemon (d); return 32; }
185 port = (int)dinfo->port;
186 } 186 }
187 port = (int) dinfo->port;
188 }
187 snprintf (url, 189 snprintf (url,
188 sizeof (url), 190 sizeof (url),
189 "http://127.0.0.1:%d/", 191 "http://127.0.0.1:%d/",
190 port); 192 port);
191 curl = fork_curl (url); 193 curl = fork_curl (url);
192 (void)sleep (1); 194 (void) sleep (1);
193 kill_curl (curl); 195 kill_curl (curl);
194 (void)sleep (1); 196 (void) sleep (1);
195 /* fprintf (stderr, "Stopping daemon!\n"); */ 197 /* fprintf (stderr, "Stopping daemon!\n"); */
196 MHD_stop_daemon (d); 198 MHD_stop_daemon (d);
197 if (ok != 0) 199 if (ok != 0)
@@ -211,47 +213,50 @@ testMultithreadedGet ()
211 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 213 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
212 port = 0; 214 port = 0;
213 else 215 else
214 { 216 {
215 port = 1181; 217 port = 1181;
216 if (oneone) 218 if (oneone)
217 port += 10; 219 port += 10;
218 } 220 }
219 221
220 ok = 1; 222 ok = 1;
221 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 223 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
224 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
222 port, NULL, NULL, &ahc_echo, "GET", 225 port, NULL, NULL, &ahc_echo, "GET",
223 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2, 226 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2,
224 MHD_OPTION_END); 227 MHD_OPTION_END);
225 if (d == NULL) 228 if (d == NULL)
226 return 16; 229 return 16;
227 if (0 == port) 230 if (0 == port)
231 {
232 const union MHD_DaemonInfo *dinfo;
233 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
234 if ((NULL == dinfo) ||(0 == dinfo->port) )
228 { 235 {
229 const union MHD_DaemonInfo *dinfo; 236 MHD_stop_daemon (d); return 32;
230 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
231 if (NULL == dinfo || 0 == dinfo->port)
232 { MHD_stop_daemon (d); return 32; }
233 port = (int)dinfo->port;
234 } 237 }
238 port = (int) dinfo->port;
239 }
235 snprintf (url, 240 snprintf (url,
236 sizeof (url), 241 sizeof (url),
237 "http://127.0.0.1:%d/", 242 "http://127.0.0.1:%d/",
238 port); 243 port);
239 //fprintf (stderr, "Forking cURL!\n"); 244 // fprintf (stderr, "Forking cURL!\n");
240 curl = fork_curl (url); 245 curl = fork_curl (url);
241 (void)sleep (1); 246 (void) sleep (1);
242 kill_curl (curl); 247 kill_curl (curl);
243 (void)sleep (1); 248 (void) sleep (1);
244 curl = fork_curl (url); 249 curl = fork_curl (url);
245 (void)sleep (1); 250 (void) sleep (1);
246 if (ok != 0) 251 if (ok != 0)
247 { 252 {
248 kill_curl (curl); 253 kill_curl (curl);
249 MHD_stop_daemon (d); 254 MHD_stop_daemon (d);
250 return 64; 255 return 64;
251 } 256 }
252 kill_curl (curl); 257 kill_curl (curl);
253 (void)sleep (1); 258 (void) sleep (1);
254 //fprintf (stderr, "Stopping daemon!\n"); 259 // fprintf (stderr, "Stopping daemon!\n");
255 MHD_stop_daemon (d); 260 MHD_stop_daemon (d);
256 if (ok != 0) 261 if (ok != 0)
257 return 32; 262 return 32;
@@ -271,11 +276,11 @@ testMultithreadedPoolGet ()
271 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 276 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
272 port = 0; 277 port = 0;
273 else 278 else
274 { 279 {
275 port = 1182; 280 port = 1182;
276 if (oneone) 281 if (oneone)
277 port += 10; 282 port += 10;
278 } 283 }
279 284
280 ok = 1; 285 ok = 1;
281 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 286 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -284,22 +289,24 @@ testMultithreadedPoolGet ()
284 if (d == NULL) 289 if (d == NULL)
285 return 64; 290 return 64;
286 if (0 == port) 291 if (0 == port)
292 {
293 const union MHD_DaemonInfo *dinfo;
294 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
295 if ((NULL == dinfo) ||(0 == dinfo->port) )
287 { 296 {
288 const union MHD_DaemonInfo *dinfo; 297 MHD_stop_daemon (d); return 32;
289 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
290 if (NULL == dinfo || 0 == dinfo->port)
291 { MHD_stop_daemon (d); return 32; }
292 port = (int)dinfo->port;
293 } 298 }
299 port = (int) dinfo->port;
300 }
294 snprintf (url, 301 snprintf (url,
295 sizeof (url), 302 sizeof (url),
296 "http://127.0.0.1:%d/", 303 "http://127.0.0.1:%d/",
297 port); 304 port);
298 curl = fork_curl (url); 305 curl = fork_curl (url);
299 (void)sleep (1); 306 (void) sleep (1);
300 kill_curl (curl); 307 kill_curl (curl);
301 (void)sleep (1); 308 (void) sleep (1);
302 //fprintf (stderr, "Stopping daemon!\n"); 309 // fprintf (stderr, "Stopping daemon!\n");
303 MHD_stop_daemon (d); 310 MHD_stop_daemon (d);
304 if (ok != 0) 311 if (ok != 0)
305 return 128; 312 return 128;
@@ -324,11 +331,11 @@ testExternalGet ()
324 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 331 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
325 port = 0; 332 port = 0;
326 else 333 else
327 { 334 {
328 port = 1183; 335 port = 1183;
329 if (oneone) 336 if (oneone)
330 port += 10; 337 port += 10;
331 } 338 }
332 339
333 ok = 1; 340 ok = 1;
334 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 341 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
@@ -336,13 +343,15 @@ testExternalGet ()
336 if (d == NULL) 343 if (d == NULL)
337 return 256; 344 return 256;
338 if (0 == port) 345 if (0 == port)
346 {
347 const union MHD_DaemonInfo *dinfo;
348 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
349 if ((NULL == dinfo) ||(0 == dinfo->port) )
339 { 350 {
340 const union MHD_DaemonInfo *dinfo; 351 MHD_stop_daemon (d); return 32;
341 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
342 if (NULL == dinfo || 0 == dinfo->port)
343 { MHD_stop_daemon (d); return 32; }
344 port = (int)dinfo->port;
345 } 352 }
353 port = (int) dinfo->port;
354 }
346 snprintf (url, 355 snprintf (url,
347 sizeof (url), 356 sizeof (url),
348 "http://127.0.0.1:%d/", 357 "http://127.0.0.1:%d/",
@@ -351,47 +360,47 @@ testExternalGet ()
351 360
352 start = time (NULL); 361 start = time (NULL);
353 while ((time (NULL) - start < 2)) 362 while ((time (NULL) - start < 2))
363 {
364 max = 0;
365 FD_ZERO (&rs);
366 FD_ZERO (&ws);
367 FD_ZERO (&es);
368 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
369 {
370 MHD_stop_daemon (d);
371 return 4096;
372 }
373 tv.tv_sec = 0;
374 tv.tv_usec = 1000;
375 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
354 { 376 {
355 max = 0; 377 if (EINTR != errno)
356 FD_ZERO (&rs); 378 abort ();
357 FD_ZERO (&ws);
358 FD_ZERO (&es);
359 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
360 {
361 MHD_stop_daemon (d);
362 return 4096;
363 }
364 tv.tv_sec = 0;
365 tv.tv_usec = 1000;
366 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
367 {
368 if (EINTR != errno)
369 abort ();
370 }
371 MHD_run (d);
372 } 379 }
380 MHD_run (d);
381 }
373 kill_curl (curl); 382 kill_curl (curl);
374 start = time (NULL); 383 start = time (NULL);
375 while ((time (NULL) - start < 2)) 384 while ((time (NULL) - start < 2))
385 {
386 max = 0;
387 FD_ZERO (&rs);
388 FD_ZERO (&ws);
389 FD_ZERO (&es);
390 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
391 {
392 MHD_stop_daemon (d);
393 return 4096;
394 }
395 tv.tv_sec = 0;
396 tv.tv_usec = 1000;
397 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
376 { 398 {
377 max = 0; 399 if (EINTR != errno)
378 FD_ZERO (&rs); 400 abort ();
379 FD_ZERO (&ws);
380 FD_ZERO (&es);
381 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
382 {
383 MHD_stop_daemon (d);
384 return 4096;
385 }
386 tv.tv_sec = 0;
387 tv.tv_usec = 1000;
388 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
389 {
390 if (EINTR != errno)
391 abort ();
392 }
393 MHD_run (d);
394 } 401 }
402 MHD_run (d);
403 }
395 /* fprintf (stderr, "Stopping daemon!\n"); */ 404 /* fprintf (stderr, "Stopping daemon!\n"); */
396 MHD_stop_daemon (d); 405 MHD_stop_daemon (d);
397 if (ok != 0) 406 if (ok != 0)
@@ -404,28 +413,28 @@ int
404main (int argc, char *const *argv) 413main (int argc, char *const *argv)
405{ 414{
406 unsigned int errorCount = 0; 415 unsigned int errorCount = 0;
407 (void)argc; /* Unused. Silent compiler warning. */ 416 (void) argc; /* Unused. Silent compiler warning. */
408 417
409#ifndef _WIN32 418#ifndef _WIN32
410 /* Solaris has no way to disable SIGPIPE on socket disconnect. */ 419 /* Solaris has no way to disable SIGPIPE on socket disconnect. */
411 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE)) 420 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE))
412 { 421 {
413 struct sigaction act; 422 struct sigaction act;
414 423
415 act.sa_handler = SIG_IGN; 424 act.sa_handler = SIG_IGN;
416 sigaction(SIGPIPE, &act, NULL); 425 sigaction (SIGPIPE, &act, NULL);
417 } 426 }
418#endif /* _WIN32 */ 427#endif /* _WIN32 */
419 428
420 if (NULL == argv || 0 == argv[0]) 429 if ((NULL == argv)||(0 == argv[0]))
421 return 99; 430 return 99;
422 oneone = has_in_name (argv[0], "11"); 431 oneone = has_in_name (argv[0], "11");
423 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 432 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
424 { 433 {
425 errorCount += testInternalGet (); 434 errorCount += testInternalGet ();
426 errorCount += testMultithreadedGet (); 435 errorCount += testMultithreadedGet ();
427 errorCount += testMultithreadedPoolGet (); 436 errorCount += testMultithreadedPoolGet ();
428 } 437 }
429 errorCount += testExternalGet (); 438 errorCount += testExternalGet ();
430 if (errorCount != 0) 439 if (errorCount != 0)
431 fprintf (stderr, "Error (code: %u)\n", errorCount); 440 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c
index 3e68647b..7651ff56 100644
--- a/src/testcurl/test_get_sendfile.c
+++ b/src/testcurl/test_get_sendfile.c
@@ -40,14 +40,15 @@
40#include <unistd.h> 40#include <unistd.h>
41#endif 41#endif
42 42
43#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 43#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
44#undef CPU_COUNT 44#undef CPU_COUNT
45#endif 45#endif
46#if !defined(CPU_COUNT) 46#if ! defined(CPU_COUNT)
47#define CPU_COUNT 2 47#define CPU_COUNT 2
48#endif 48#endif
49 49
50#define TESTSTR "This is the content of the test file we are sending using sendfile (if available)" 50#define TESTSTR \
51 "This is the content of the test file we are sending using sendfile (if available)"
51 52
52static char *sourcefile; 53static char *sourcefile;
53 54
@@ -88,25 +89,25 @@ ahc_echo (void *cls,
88 struct MHD_Response *response; 89 struct MHD_Response *response;
89 int ret; 90 int ret;
90 int fd; 91 int fd;
91 (void)url;(void)version; /* Unused. Silent compiler warning. */ 92 (void) url; (void) version; /* Unused. Silent compiler warning. */
92 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 93 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
93 94
94 if (0 != strcmp (me, method)) 95 if (0 != strcmp (me, method))
95 return MHD_NO; /* unexpected method */ 96 return MHD_NO; /* unexpected method */
96 if (&ptr != *unused) 97 if (&ptr != *unused)
97 { 98 {
98 *unused = &ptr; 99 *unused = &ptr;
99 return MHD_YES; 100 return MHD_YES;
100 } 101 }
101 *unused = NULL; 102 *unused = NULL;
102 fd = open (sourcefile, O_RDONLY); 103 fd = open (sourcefile, O_RDONLY);
103 if (fd == -1) 104 if (fd == -1)
104 { 105 {
105 fprintf (stderr, "Failed to open `%s': %s\n", 106 fprintf (stderr, "Failed to open `%s': %s\n",
106 sourcefile, 107 sourcefile,
107 strerror (errno)); 108 strerror (errno));
108 exit (1); 109 exit (1);
109 } 110 }
110 response = MHD_create_response_from_fd (strlen (TESTSTR), fd); 111 response = MHD_create_response_from_fd (strlen (TESTSTR), fd);
111 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
112 MHD_destroy_response (response); 113 MHD_destroy_response (response);
@@ -129,11 +130,11 @@ testInternalGet ()
129 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 130 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
130 port = 0; 131 port = 0;
131 else 132 else
132 { 133 {
133 port = 1200; 134 port = 1200;
134 if (oneone) 135 if (oneone)
135 port += 10; 136 port += 10;
136 } 137 }
137 138
138 cbc.buf = buf; 139 cbc.buf = buf;
139 cbc.size = 2048; 140 cbc.size = 2048;
@@ -143,16 +144,18 @@ testInternalGet ()
143 if (d == NULL) 144 if (d == NULL)
144 return 1; 145 return 1;
145 if (0 == port) 146 if (0 == port)
147 {
148 const union MHD_DaemonInfo *dinfo;
149 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
150 if ((NULL == dinfo) ||(0 == dinfo->port) )
146 { 151 {
147 const union MHD_DaemonInfo *dinfo; 152 MHD_stop_daemon (d); return 32;
148 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
149 if (NULL == dinfo || 0 == dinfo->port)
150 { MHD_stop_daemon (d); return 32; }
151 port = (int)dinfo->port;
152 } 153 }
154 port = (int) dinfo->port;
155 }
153 c = curl_easy_init (); 156 c = curl_easy_init ();
154 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); 157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
155 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 158 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
156 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 159 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
157 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 160 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
158 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 161 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -167,14 +170,14 @@ testInternalGet ()
167 crashes on my system!*/ 170 crashes on my system!*/
168 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 171 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
169 if (CURLE_OK != (errornum = curl_easy_perform (c))) 172 if (CURLE_OK != (errornum = curl_easy_perform (c)))
170 { 173 {
171 fprintf (stderr, 174 fprintf (stderr,
172 "curl_easy_perform failed: `%s'\n", 175 "curl_easy_perform failed: `%s'\n",
173 curl_easy_strerror (errornum)); 176 curl_easy_strerror (errornum));
174 curl_easy_cleanup (c); 177 curl_easy_cleanup (c);
175 MHD_stop_daemon (d); 178 MHD_stop_daemon (d);
176 return 2; 179 return 2;
177 } 180 }
178 curl_easy_cleanup (c); 181 curl_easy_cleanup (c);
179 MHD_stop_daemon (d); 182 MHD_stop_daemon (d);
180 if (cbc.pos != strlen (TESTSTR)) 183 if (cbc.pos != strlen (TESTSTR))
@@ -198,30 +201,33 @@ testMultithreadedGet ()
198 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 201 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
199 port = 0; 202 port = 0;
200 else 203 else
201 { 204 {
202 port = 1201; 205 port = 1201;
203 if (oneone) 206 if (oneone)
204 port += 10; 207 port += 10;
205 } 208 }
206 209
207 cbc.buf = buf; 210 cbc.buf = buf;
208 cbc.size = 2048; 211 cbc.size = 2048;
209 cbc.pos = 0; 212 cbc.pos = 0;
210 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 213 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
214 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
211 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 215 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
212 if (d == NULL) 216 if (d == NULL)
213 return 16; 217 return 16;
214 if (0 == port) 218 if (0 == port)
219 {
220 const union MHD_DaemonInfo *dinfo;
221 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
222 if ((NULL == dinfo) ||(0 == dinfo->port) )
215 { 223 {
216 const union MHD_DaemonInfo *dinfo; 224 MHD_stop_daemon (d); return 32;
217 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
218 if (NULL == dinfo || 0 == dinfo->port)
219 { MHD_stop_daemon (d); return 32; }
220 port = (int)dinfo->port;
221 } 225 }
226 port = (int) dinfo->port;
227 }
222 c = curl_easy_init (); 228 c = curl_easy_init ();
223 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); 229 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
224 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 230 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
225 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
226 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
227 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 233 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -236,14 +242,14 @@ testMultithreadedGet ()
236 crashes on my system! */ 242 crashes on my system! */
237 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 243 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
238 if (CURLE_OK != (errornum = curl_easy_perform (c))) 244 if (CURLE_OK != (errornum = curl_easy_perform (c)))
239 { 245 {
240 fprintf (stderr, 246 fprintf (stderr,
241 "curl_easy_perform failed: `%s'\n", 247 "curl_easy_perform failed: `%s'\n",
242 curl_easy_strerror (errornum)); 248 curl_easy_strerror (errornum));
243 curl_easy_cleanup (c); 249 curl_easy_cleanup (c);
244 MHD_stop_daemon (d); 250 MHD_stop_daemon (d);
245 return 32; 251 return 32;
246 } 252 }
247 curl_easy_cleanup (c); 253 curl_easy_cleanup (c);
248 MHD_stop_daemon (d); 254 MHD_stop_daemon (d);
249 if (cbc.pos != strlen (TESTSTR)) 255 if (cbc.pos != strlen (TESTSTR))
@@ -267,11 +273,11 @@ testMultithreadedPoolGet ()
267 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 273 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
268 port = 0; 274 port = 0;
269 else 275 else
270 { 276 {
271 port = 1202; 277 port = 1202;
272 if (oneone) 278 if (oneone)
273 port += 10; 279 port += 10;
274 } 280 }
275 281
276 cbc.buf = buf; 282 cbc.buf = buf;
277 cbc.size = 2048; 283 cbc.size = 2048;
@@ -282,16 +288,18 @@ testMultithreadedPoolGet ()
282 if (d == NULL) 288 if (d == NULL)
283 return 16; 289 return 16;
284 if (0 == port) 290 if (0 == port)
291 {
292 const union MHD_DaemonInfo *dinfo;
293 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
294 if ((NULL == dinfo) ||(0 == dinfo->port) )
285 { 295 {
286 const union MHD_DaemonInfo *dinfo; 296 MHD_stop_daemon (d); return 32;
287 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
288 if (NULL == dinfo || 0 == dinfo->port)
289 { MHD_stop_daemon (d); return 32; }
290 port = (int)dinfo->port;
291 } 297 }
298 port = (int) dinfo->port;
299 }
292 c = curl_easy_init (); 300 c = curl_easy_init ();
293 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); 301 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
294 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 302 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
295 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 303 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
296 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 304 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
297 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 305 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -306,14 +314,14 @@ testMultithreadedPoolGet ()
306 crashes on my system!*/ 314 crashes on my system!*/
307 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 315 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
308 if (CURLE_OK != (errornum = curl_easy_perform (c))) 316 if (CURLE_OK != (errornum = curl_easy_perform (c)))
309 { 317 {
310 fprintf (stderr, 318 fprintf (stderr,
311 "curl_easy_perform failed: `%s'\n", 319 "curl_easy_perform failed: `%s'\n",
312 curl_easy_strerror (errornum)); 320 curl_easy_strerror (errornum));
313 curl_easy_cleanup (c); 321 curl_easy_cleanup (c);
314 MHD_stop_daemon (d); 322 MHD_stop_daemon (d);
315 return 32; 323 return 32;
316 } 324 }
317 curl_easy_cleanup (c); 325 curl_easy_cleanup (c);
318 MHD_stop_daemon (d); 326 MHD_stop_daemon (d);
319 if (cbc.pos != strlen (TESTSTR)) 327 if (cbc.pos != strlen (TESTSTR))
@@ -351,11 +359,11 @@ testExternalGet ()
351 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 359 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
352 port = 0; 360 port = 0;
353 else 361 else
354 { 362 {
355 port = 1203; 363 port = 1203;
356 if (oneone) 364 if (oneone)
357 port += 10; 365 port += 10;
358 } 366 }
359 367
360 multi = NULL; 368 multi = NULL;
361 cbc.buf = buf; 369 cbc.buf = buf;
@@ -366,16 +374,18 @@ testExternalGet ()
366 if (d == NULL) 374 if (d == NULL)
367 return 256; 375 return 256;
368 if (0 == port) 376 if (0 == port)
377 {
378 const union MHD_DaemonInfo *dinfo;
379 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
380 if ((NULL == dinfo) ||(0 == dinfo->port) )
369 { 381 {
370 const union MHD_DaemonInfo *dinfo; 382 MHD_stop_daemon (d); return 32;
371 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
372 if (NULL == dinfo || 0 == dinfo->port)
373 { MHD_stop_daemon (d); return 32; }
374 port = (int)dinfo->port;
375 } 383 }
384 port = (int) dinfo->port;
385 }
376 c = curl_easy_init (); 386 c = curl_easy_init ();
377 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); 387 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
378 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 388 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
379 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 389 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
380 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 390 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
381 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 391 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -393,86 +403,88 @@ testExternalGet ()
393 403
394 multi = curl_multi_init (); 404 multi = curl_multi_init ();
395 if (multi == NULL) 405 if (multi == NULL)
406 {
407 curl_easy_cleanup (c);
408 MHD_stop_daemon (d);
409 return 512;
410 }
411 mret = curl_multi_add_handle (multi, c);
412 if (mret != CURLM_OK)
413 {
414 curl_multi_cleanup (multi);
415 curl_easy_cleanup (c);
416 MHD_stop_daemon (d);
417 return 1024;
418 }
419 start = time (NULL);
420 while ((time (NULL) - start < 5) && (multi != NULL))
421 {
422 maxsock = MHD_INVALID_SOCKET;
423 maxposixs = -1;
424 FD_ZERO (&rs);
425 FD_ZERO (&ws);
426 FD_ZERO (&es);
427 curl_multi_perform (multi, &running);
428 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
429 if (mret != CURLM_OK)
396 { 430 {
431 curl_multi_remove_handle (multi, c);
432 curl_multi_cleanup (multi);
397 curl_easy_cleanup (c); 433 curl_easy_cleanup (c);
398 MHD_stop_daemon (d); 434 MHD_stop_daemon (d);
399 return 512; 435 return 2048;
400 } 436 }
401 mret = curl_multi_add_handle (multi, c); 437 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
402 if (mret != CURLM_OK)
403 { 438 {
439 curl_multi_remove_handle (multi, c);
404 curl_multi_cleanup (multi); 440 curl_multi_cleanup (multi);
405 curl_easy_cleanup (c); 441 curl_easy_cleanup (c);
406 MHD_stop_daemon (d); 442 MHD_stop_daemon (d);
407 return 1024; 443 return 4096;
408 } 444 }
409 start = time (NULL); 445 tv.tv_sec = 0;
410 while ((time (NULL) - start < 5) && (multi != NULL)) 446 tv.tv_usec = 1000;
447 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
411 { 448 {
412 maxsock = MHD_INVALID_SOCKET;
413 maxposixs = -1;
414 FD_ZERO (&rs);
415 FD_ZERO (&ws);
416 FD_ZERO (&es);
417 curl_multi_perform (multi, &running);
418 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
419 if (mret != CURLM_OK)
420 {
421 curl_multi_remove_handle (multi, c);
422 curl_multi_cleanup (multi);
423 curl_easy_cleanup (c);
424 MHD_stop_daemon (d);
425 return 2048;
426 }
427 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
428 {
429 curl_multi_remove_handle (multi, c);
430 curl_multi_cleanup (multi);
431 curl_easy_cleanup (c);
432 MHD_stop_daemon (d);
433 return 4096;
434 }
435 tv.tv_sec = 0;
436 tv.tv_usec = 1000;
437 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
438 {
439#ifdef MHD_POSIX_SOCKETS 449#ifdef MHD_POSIX_SOCKETS
440 if (EINTR != errno) 450 if (EINTR != errno)
441 abort (); 451 abort ();
442#else 452#else
443 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 453 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
444 abort (); 454 ws.fd_count)
445 Sleep (1000); 455 ||(0 != es.fd_count) )
456 abort ();
457 Sleep (1000);
446#endif 458#endif
447 }
448 curl_multi_perform (multi, &running);
449 if (running == 0)
450 {
451 msg = curl_multi_info_read (multi, &running);
452 if (msg == NULL)
453 break;
454 if (msg->msg == CURLMSG_DONE)
455 {
456 if (msg->data.result != CURLE_OK)
457 printf ("%s failed at %s:%d: `%s'\n",
458 "curl_multi_perform",
459 __FILE__,
460 __LINE__, curl_easy_strerror (msg->data.result));
461 curl_multi_remove_handle (multi, c);
462 curl_multi_cleanup (multi);
463 curl_easy_cleanup (c);
464 c = NULL;
465 multi = NULL;
466 }
467 }
468 MHD_run (d);
469 } 459 }
470 if (multi != NULL) 460 curl_multi_perform (multi, &running);
461 if (running == 0)
471 { 462 {
472 curl_multi_remove_handle (multi, c); 463 msg = curl_multi_info_read (multi, &running);
473 curl_easy_cleanup (c); 464 if (msg == NULL)
474 curl_multi_cleanup (multi); 465 break;
466 if (msg->msg == CURLMSG_DONE)
467 {
468 if (msg->data.result != CURLE_OK)
469 printf ("%s failed at %s:%d: `%s'\n",
470 "curl_multi_perform",
471 __FILE__,
472 __LINE__, curl_easy_strerror (msg->data.result));
473 curl_multi_remove_handle (multi, c);
474 curl_multi_cleanup (multi);
475 curl_easy_cleanup (c);
476 c = NULL;
477 multi = NULL;
478 }
475 } 479 }
480 MHD_run (d);
481 }
482 if (multi != NULL)
483 {
484 curl_multi_remove_handle (multi, c);
485 curl_easy_cleanup (c);
486 curl_multi_cleanup (multi);
487 }
476 MHD_stop_daemon (d); 488 MHD_stop_daemon (d);
477 if (cbc.pos != strlen (TESTSTR)) 489 if (cbc.pos != strlen (TESTSTR))
478 return 8192; 490 return 8192;
@@ -495,7 +507,7 @@ testUnknownPortGet ()
495 507
496 struct sockaddr_in addr; 508 struct sockaddr_in addr;
497 socklen_t addr_len = sizeof(addr); 509 socklen_t addr_len = sizeof(addr);
498 memset(&addr, 0, sizeof(addr)); 510 memset (&addr, 0, sizeof(addr));
499 addr.sin_family = AF_INET; 511 addr.sin_family = AF_INET;
500 addr.sin_port = 0; 512 addr.sin_port = 0;
501 addr.sin_addr.s_addr = INADDR_ANY; 513 addr.sin_addr.s_addr = INADDR_ANY;
@@ -511,29 +523,31 @@ testUnknownPortGet ()
511 return 32768; 523 return 32768;
512 524
513 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 525 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
514 { 526 {
515 di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); 527 di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD);
516 if (di == NULL) 528 if (di == NULL)
517 return 65536; 529 return 65536;
518 530
519 if (0 != getsockname(di->listen_fd, (struct sockaddr *) &addr, &addr_len)) 531 if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len))
520 return 131072; 532 return 131072;
521 533
522 if (addr.sin_family != AF_INET) 534 if (addr.sin_family != AF_INET)
523 return 26214; 535 return 26214;
524 port = (int)ntohs(addr.sin_port); 536 port = (int) ntohs (addr.sin_port);
525 } 537 }
526 else 538 else
539 {
540 const union MHD_DaemonInfo *dinfo;
541 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
542 if ((NULL == dinfo) ||(0 == dinfo->port) )
527 { 543 {
528 const union MHD_DaemonInfo *dinfo; 544 MHD_stop_daemon (d); return 32;
529 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
530 if (NULL == dinfo || 0 == dinfo->port)
531 { MHD_stop_daemon (d); return 32; }
532 port = (int)dinfo->port;
533 } 545 }
546 port = (int) dinfo->port;
547 }
534 548
535 snprintf(buf, sizeof(buf), "http://127.0.0.1:%d/", 549 snprintf (buf, sizeof(buf), "http://127.0.0.1:%d/",
536 port); 550 port);
537 551
538 c = curl_easy_init (); 552 c = curl_easy_init ();
539 curl_easy_setopt (c, CURLOPT_URL, buf); 553 curl_easy_setopt (c, CURLOPT_URL, buf);
@@ -551,14 +565,14 @@ testUnknownPortGet ()
551 crashes on my system! */ 565 crashes on my system! */
552 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 566 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
553 if (CURLE_OK != (errornum = curl_easy_perform (c))) 567 if (CURLE_OK != (errornum = curl_easy_perform (c)))
554 { 568 {
555 fprintf (stderr, 569 fprintf (stderr,
556 "curl_easy_perform failed: `%s'\n", 570 "curl_easy_perform failed: `%s'\n",
557 curl_easy_strerror (errornum)); 571 curl_easy_strerror (errornum));
558 curl_easy_cleanup (c); 572 curl_easy_cleanup (c);
559 MHD_stop_daemon (d); 573 MHD_stop_daemon (d);
560 return 524288; 574 return 524288;
561 } 575 }
562 curl_easy_cleanup (c); 576 curl_easy_cleanup (c);
563 MHD_stop_daemon (d); 577 MHD_stop_daemon (d);
564 if (cbc.pos != strlen (TESTSTR)) 578 if (cbc.pos != strlen (TESTSTR))
@@ -575,9 +589,9 @@ main (int argc, char *const *argv)
575 unsigned int errorCount = 0; 589 unsigned int errorCount = 0;
576 const char *tmp; 590 const char *tmp;
577 FILE *f; 591 FILE *f;
578 (void)argc; /* Unused. Silent compiler warning. */ 592 (void) argc; /* Unused. Silent compiler warning. */
579 593
580 if (NULL == argv || 0 == argv[0]) 594 if ((NULL == argv)||(0 == argv[0]))
581 return 99; 595 return 99;
582 oneone = has_in_name (argv[0], "11"); 596 oneone = has_in_name (argv[0], "11");
583 597
@@ -594,24 +608,24 @@ main (int argc, char *const *argv)
594 oneone ? "11" : ""); 608 oneone ? "11" : "");
595 f = fopen (sourcefile, "w"); 609 f = fopen (sourcefile, "w");
596 if (NULL == f) 610 if (NULL == f)
597 { 611 {
598 fprintf (stderr, "failed to write test file\n"); 612 fprintf (stderr, "failed to write test file\n");
599 free (sourcefile); 613 free (sourcefile);
600 return 1; 614 return 1;
601 } 615 }
602 if (1 != 616 if (1 !=
603 fwrite (TESTSTR, strlen (TESTSTR), 1, f)) 617 fwrite (TESTSTR, strlen (TESTSTR), 1, f))
604 abort (); 618 abort ();
605 fclose (f); 619 fclose (f);
606 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 620 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
607 return 2; 621 return 2;
608 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 622 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
609 { 623 {
610 errorCount += testInternalGet (); 624 errorCount += testInternalGet ();
611 errorCount += testMultithreadedGet (); 625 errorCount += testMultithreadedGet ();
612 errorCount += testMultithreadedPoolGet (); 626 errorCount += testMultithreadedPoolGet ();
613 errorCount += testUnknownPortGet (); 627 errorCount += testUnknownPortGet ();
614 } 628 }
615 errorCount += testExternalGet (); 629 errorCount += testExternalGet ();
616 if (errorCount != 0) 630 if (errorCount != 0)
617 fprintf (stderr, "Error (code: %u)\n", errorCount); 631 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c
index 35ae6645..82d2923f 100644
--- a/src/testcurl/test_iplimit.c
+++ b/src/testcurl/test_iplimit.c
@@ -45,10 +45,10 @@
45#include <windows.h> 45#include <windows.h>
46#endif 46#endif
47 47
48#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 48#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
49#undef CPU_COUNT 49#undef CPU_COUNT
50#endif 50#endif
51#if !defined(CPU_COUNT) 51#if ! defined(CPU_COUNT)
52#define CPU_COUNT 2 52#define CPU_COUNT 2
53#endif 53#endif
54 54
@@ -86,19 +86,19 @@ ahc_echo (void *cls,
86 const char *me = cls; 86 const char *me = cls;
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 89 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
90 90
91 if (0 != strcmp (me, method)) 91 if (0 != strcmp (me, method))
92 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
93 if (&ptr != *unused) 93 if (&ptr != *unused)
94 { 94 {
95 *unused = &ptr; 95 *unused = &ptr;
96 return MHD_YES; 96 return MHD_YES;
97 } 97 }
98 *unused = NULL; 98 *unused = NULL;
99 response = MHD_create_response_from_buffer (strlen (url), 99 response = MHD_create_response_from_buffer (strlen (url),
100 (void *) url, 100 (void *) url,
101 MHD_RESPMEM_MUST_COPY); 101 MHD_RESPMEM_MUST_COPY);
102 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 102 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
103 MHD_destroy_response (response); 103 MHD_destroy_response (response);
104 if (ret == MHD_NO) 104 if (ret == MHD_NO)
@@ -119,14 +119,14 @@ testMultithreadedGet ()
119 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 119 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
120 port = 0; 120 port = 0;
121 else 121 else
122 { 122 {
123 port = 1260; 123 port = 1260;
124 if (oneone) 124 if (oneone)
125 port += 5; 125 port += 5;
126 } 126 }
127 127
128 /* Test only valid for HTTP/1.1 (uses persistent connections) */ 128 /* Test only valid for HTTP/1.1 (uses persistent connections) */
129 if (!oneone) 129 if (! oneone)
130 return 0; 130 return 0;
131 131
132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -137,83 +137,85 @@ testMultithreadedGet ()
137 if (d == NULL) 137 if (d == NULL)
138 return 16; 138 return 16;
139 if (0 == port) 139 if (0 == port)
140 {
141 const union MHD_DaemonInfo *dinfo;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if ((NULL == dinfo) ||(0 == dinfo->port) )
140 { 144 {
141 const union MHD_DaemonInfo *dinfo; 145 MHD_stop_daemon (d); return 32;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if (NULL == dinfo || 0 == dinfo->port)
144 { MHD_stop_daemon (d); return 32; }
145 port = (int)dinfo->port;
146 } 146 }
147 port = (int) dinfo->port;
148 }
147 149
148 for (k = 0; k < 3; ++k) 150 for (k = 0; k < 3; ++k)
151 {
152 struct CBC cbc[3];
153 CURL *cenv[3];
154 int i;
155
156 success = 0;
157 failure = 0;
158 for (i = 0; i < 3; ++i)
159 {
160 CURL *c;
161 CURLcode errornum;
162
163 cenv[i] = c = curl_easy_init ();
164 cbc[i].buf = buf;
165 cbc[i].size = 2048;
166 cbc[i].pos = 0;
167
168 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
169 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
170 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
171 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
172 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
173 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
174 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
175 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
176 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
177 /* NOTE: use of CONNECTTIMEOUT without also
178 * setting NOSIGNAL results in really weird
179 * crashes on my system! */
180 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
181
182 errornum = curl_easy_perform (c);
183 if (CURLE_OK == errornum)
184 success++;
185 else
186 failure++;
187 }
188
189 /* Cleanup the environments */
190 for (i = 0; i < 3; ++i)
191 curl_easy_cleanup (cenv[i]);
192 if ( (2 != success) ||
193 (1 != failure) )
149 { 194 {
150 struct CBC cbc[3]; 195 fprintf (stderr,
151 CURL *cenv[3]; 196 "Unexpected number of success (%u) or failure (%u)\n",
152 int i; 197 success,
153 198 failure);
154 success = 0; 199 MHD_stop_daemon (d);
155 failure = 0; 200 return 32;
156 for (i = 0; i < 3; ++i) 201 }
157 { 202
158 CURL *c; 203 (void) sleep (2);
159 CURLcode errornum; 204
160 205 for (i = 0; i < 2; ++i)
161 cenv[i] = c = curl_easy_init (); 206 {
162 cbc[i].buf = buf; 207 if (cbc[i].pos != strlen ("/hello_world"))
163 cbc[i].size = 2048;
164 cbc[i].pos = 0;
165
166 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
167 curl_easy_setopt (c, CURLOPT_PORT, (long)port);
168 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
169 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
171 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
172 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
174 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
175 /* NOTE: use of CONNECTTIMEOUT without also
176 * setting NOSIGNAL results in really weird
177 * crashes on my system! */
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
179
180 errornum = curl_easy_perform (c);
181 if (CURLE_OK == errornum)
182 success++;
183 else
184 failure++;
185 }
186
187 /* Cleanup the environments */
188 for (i = 0; i < 3; ++i)
189 curl_easy_cleanup (cenv[i]);
190 if ( (2 != success) ||
191 (1 != failure) )
192 { 208 {
193 fprintf (stderr,
194 "Unexpected number of success (%u) or failure (%u)\n",
195 success,
196 failure);
197 MHD_stop_daemon (d); 209 MHD_stop_daemon (d);
198 return 32; 210 return 64;
211 }
212 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
213 {
214 MHD_stop_daemon (d);
215 return 128;
199 } 216 }
200
201 (void)sleep(2);
202
203 for (i = 0; i < 2; ++i)
204 {
205 if (cbc[i].pos != strlen ("/hello_world"))
206 {
207 MHD_stop_daemon (d);
208 return 64;
209 }
210 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
211 {
212 MHD_stop_daemon (d);
213 return 128;
214 }
215 }
216 } 217 }
218 }
217 MHD_stop_daemon (d); 219 MHD_stop_daemon (d);
218 return 0; 220 return 0;
219} 221}
@@ -228,14 +230,14 @@ testMultithreadedPoolGet ()
228 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 230 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
229 port = 0; 231 port = 0;
230 else 232 else
231 { 233 {
232 port = 1261; 234 port = 1261;
233 if (oneone) 235 if (oneone)
234 port += 5; 236 port += 5;
235 } 237 }
236 238
237 /* Test only valid for HTTP/1.1 (uses persistent connections) */ 239 /* Test only valid for HTTP/1.1 (uses persistent connections) */
238 if (!oneone) 240 if (! oneone)
239 return 0; 241 return 0;
240 242
241 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 243 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -246,90 +248,92 @@ testMultithreadedPoolGet ()
246 if (d == NULL) 248 if (d == NULL)
247 return 16; 249 return 16;
248 if (0 == port) 250 if (0 == port)
251 {
252 const union MHD_DaemonInfo *dinfo;
253 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
254 if ((NULL == dinfo) ||(0 == dinfo->port) )
249 { 255 {
250 const union MHD_DaemonInfo *dinfo; 256 MHD_stop_daemon (d); return 32;
251 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
252 if (NULL == dinfo || 0 == dinfo->port)
253 { MHD_stop_daemon (d); return 32; }
254 port = (int)dinfo->port;
255 } 257 }
258 port = (int) dinfo->port;
259 }
256 260
257 for (k = 0; k < 3; ++k) 261 for (k = 0; k < 3; ++k)
262 {
263 struct CBC cbc[3];
264 CURL *cenv[3];
265 int i;
266
267 for (i = 0; i < 3; ++i)
258 { 268 {
259 struct CBC cbc[3]; 269 CURL *c;
260 CURL *cenv[3]; 270 CURLcode errornum;
261 int i; 271
262 272 cenv[i] = c = curl_easy_init ();
263 for (i = 0; i < 3; ++i) 273 cbc[i].buf = buf;
264 { 274 cbc[i].size = 2048;
265 CURL *c; 275 cbc[i].pos = 0;
266 CURLcode errornum; 276
267 277 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
268 cenv[i] = c = curl_easy_init (); 278 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
269 cbc[i].buf = buf; 279 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
270 cbc[i].size = 2048; 280 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
271 cbc[i].pos = 0; 281 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
272 282 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
273 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 283 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
274 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 284 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
275 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 285 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
276 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); 286 /* NOTE: use of CONNECTTIMEOUT without also
277 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 287 * setting NOSIGNAL results in really weird
278 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 288 * crashes on my system! */
279 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); 289 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
280 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 290
281 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 291 errornum = curl_easy_perform (c);
282 /* NOTE: use of CONNECTTIMEOUT without also 292 if ( ( (CURLE_OK != errornum) && (i < 2) ) ||
283 * setting NOSIGNAL results in really weird 293 ( (CURLE_OK == errornum) && (i == 2) ) )
284 * crashes on my system! */ 294 {
285 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 295 int j;
286 296
287 errornum = curl_easy_perform (c); 297 /* First 2 should succeed */
288 if ( ( (CURLE_OK != errornum) && (i < 2) ) || 298 if (i < 2)
289 ( (CURLE_OK == errornum) && (i == 2) ) ) 299 fprintf (stderr,
290 { 300 "curl_easy_perform failed: `%s'\n",
291 int j; 301 curl_easy_strerror (errornum));
292 302
293 /* First 2 should succeed */ 303 /* Last request should have failed */
294 if (i < 2) 304 else
295 fprintf (stderr, 305 fprintf (stderr,
296 "curl_easy_perform failed: `%s'\n", 306 "No error on IP address over limit\n");
297 curl_easy_strerror (errornum)); 307
298 308 for (j = 0; j < i; ++j)
299 /* Last request should have failed */ 309 curl_easy_cleanup (cenv[j]);
300 else 310 MHD_stop_daemon (d);
301 fprintf (stderr, 311 return 32;
302 "No error on IP address over limit\n"); 312 }
303 313 }
304 for (j = 0; j < i; ++j) 314
305 curl_easy_cleanup (cenv[j]); 315 /* Cleanup the environments */
306 MHD_stop_daemon (d); 316 for (i = 0; i < 3; ++i)
307 return 32; 317 curl_easy_cleanup (cenv[i]);
308 }
309 }
310
311 /* Cleanup the environments */
312 for (i = 0; i < 3; ++i)
313 curl_easy_cleanup (cenv[i]);
314
315 (void)sleep(2);
316
317 for (i = 0; i < 2; ++i)
318 {
319 if (cbc[i].pos != strlen ("/hello_world"))
320 {
321 MHD_stop_daemon (d);
322 return 64;
323 }
324 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
325 {
326 MHD_stop_daemon (d);
327 return 128;
328 }
329 }
330 318
319 (void) sleep (2);
331 320
321 for (i = 0; i < 2; ++i)
322 {
323 if (cbc[i].pos != strlen ("/hello_world"))
324 {
325 MHD_stop_daemon (d);
326 return 64;
327 }
328 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
329 {
330 MHD_stop_daemon (d);
331 return 128;
332 }
332 } 333 }
334
335
336 }
333 MHD_stop_daemon (d); 337 MHD_stop_daemon (d);
334 return 0; 338 return 0;
335} 339}
@@ -338,9 +342,9 @@ int
338main (int argc, char *const *argv) 342main (int argc, char *const *argv)
339{ 343{
340 unsigned int errorCount = 0; 344 unsigned int errorCount = 0;
341 (void)argc; /* Unused. Silent compiler warning. */ 345 (void) argc; /* Unused. Silent compiler warning. */
342 346
343 if (NULL == argv || 0 == argv[0]) 347 if ((NULL == argv)||(0 == argv[0]))
344 return 99; 348 return 99;
345 oneone = has_in_name (argv[0], "11"); 349 oneone = has_in_name (argv[0], "11");
346 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 350 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c
index 4495cfd6..0b7256ae 100644
--- a/src/testcurl/test_large_put.c
+++ b/src/testcurl/test_large_put.c
@@ -38,10 +38,10 @@
38 38
39#include "test_helpers.h" 39#include "test_helpers.h"
40 40
41#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 41#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
42#undef CPU_COUNT 42#undef CPU_COUNT
43#endif 43#endif
44#if !defined(CPU_COUNT) 44#if ! defined(CPU_COUNT)
45#define CPU_COUNT 2 45#define CPU_COUNT 2
46#endif 46#endif
47 47
@@ -61,34 +61,35 @@ struct CBC
61}; 61};
62 62
63char* 63char*
64alloc_init(size_t buf_size) 64alloc_init (size_t buf_size)
65{ 65{
66 static const char template[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz"; 66 static const char template[] =
67 "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz";
67 static const size_t templ_size = sizeof(template) / sizeof(char) - 1; 68 static const size_t templ_size = sizeof(template) / sizeof(char) - 1;
68 char *buf; 69 char *buf;
69 char *fill_ptr; 70 char *fill_ptr;
70 size_t to_fill; 71 size_t to_fill;
71 72
72 buf = malloc(buf_size); 73 buf = malloc (buf_size);
73 if (NULL == buf) 74 if (NULL == buf)
74 return NULL; 75 return NULL;
75 76
76 fill_ptr = buf; 77 fill_ptr = buf;
77 to_fill = buf_size; 78 to_fill = buf_size;
78 while (to_fill > 0) 79 while (to_fill > 0)
79 { 80 {
80 const size_t to_copy = to_fill > templ_size ? templ_size : to_fill; 81 const size_t to_copy = to_fill > templ_size ? templ_size : to_fill;
81 memcpy (fill_ptr, template, to_copy); 82 memcpy (fill_ptr, template, to_copy);
82 fill_ptr += to_copy; 83 fill_ptr += to_copy;
83 to_fill -= to_copy; 84 to_fill -= to_copy;
84 } 85 }
85 return buf; 86 return buf;
86} 87}
87 88
88static size_t 89static size_t
89putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) 90putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
90{ 91{
91 size_t *pos = (size_t *)ptr; 92 size_t *pos = (size_t *) ptr;
92 size_t wrt; 93 size_t wrt;
93 94
94 wrt = size * nmemb; 95 wrt = size * nmemb;
@@ -127,46 +128,46 @@ ahc_echo (void *cls,
127 struct MHD_Response *response; 128 struct MHD_Response *response;
128 int ret; 129 int ret;
129 static size_t processed; 130 static size_t processed;
130 (void)version; /* Unused. Silent compiler warning. */ 131 (void) version; /* Unused. Silent compiler warning. */
131 132
132 if (0 != strcmp ("PUT", method)) 133 if (0 != strcmp ("PUT", method))
133 return MHD_NO; /* unexpected method */ 134 return MHD_NO; /* unexpected method */
134 if ((*done) == 0) 135 if ((*done) == 0)
136 {
137 size_t *pproc;
138 if (NULL == *pparam)
139 {
140 processed = 0;
141 *pparam = &processed; /* Safe as long as only one parallel request served. */
142 }
143 pproc = (size_t*) *pparam;
144
145 if (0 == *upload_data_size)
146 return MHD_YES; /* No data to process. */
147
148 if (*pproc + *upload_data_size > PUT_SIZE)
149 {
150 fprintf (stderr, "Incoming data larger than expected.\n");
151 return MHD_NO;
152 }
153 if ( (! incr_read) && (*upload_data_size != PUT_SIZE) )
154 return MHD_YES; /* Wait until whole request is received. */
155
156 if (0 != memcmp (upload_data, put_buffer + (*pproc), *upload_data_size))
135 { 157 {
136 size_t *pproc; 158 fprintf (stderr, "Incoming data does not match sent data.\n");
137 if (NULL == *pparam) 159 return MHD_NO;
138 {
139 processed = 0;
140 *pparam = &processed; /* Safe as long as only one parallel request served. */
141 }
142 pproc = (size_t*) *pparam;
143
144 if (0 == *upload_data_size)
145 return MHD_YES; /* No data to process. */
146
147 if (*pproc + *upload_data_size > PUT_SIZE)
148 {
149 fprintf (stderr, "Incoming data larger than expected.\n");
150 return MHD_NO;
151 }
152 if ( (!incr_read) && (*upload_data_size != PUT_SIZE) )
153 return MHD_YES; /* Wait until whole request is received. */
154
155 if (0 != memcmp(upload_data, put_buffer + (*pproc), *upload_data_size))
156 {
157 fprintf (stderr, "Incoming data does not match sent data.\n");
158 return MHD_NO;
159 }
160 *pproc += *upload_data_size;
161 *upload_data_size = 0; /* Current block of data is fully processed. */
162
163 if (PUT_SIZE == *pproc)
164 *done = 1; /* Whole request is processed. */
165 return MHD_YES;
166 } 160 }
161 *pproc += *upload_data_size;
162 *upload_data_size = 0; /* Current block of data is fully processed. */
163
164 if (PUT_SIZE == *pproc)
165 *done = 1; /* Whole request is processed. */
166 return MHD_YES;
167 }
167 response = MHD_create_response_from_buffer (strlen (url), 168 response = MHD_create_response_from_buffer (strlen (url),
168 (void *) url, 169 (void *) url,
169 MHD_RESPMEM_MUST_COPY); 170 MHD_RESPMEM_MUST_COPY);
170 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 171 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
171 MHD_destroy_response (response); 172 MHD_destroy_response (response);
172 return ret; 173 return ret;
@@ -188,35 +189,39 @@ testPutInternalThread (unsigned int add_flag)
188 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 189 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
189 port = 0; 190 port = 0;
190 else 191 else
191 { 192 {
192 port = 1270; 193 port = 1270;
193 if (oneone) 194 if (oneone)
194 port += 10; 195 port += 10;
195 if (incr_read) 196 if (incr_read)
196 port += 20; 197 port += 20;
197 } 198 }
198 199
199 cbc.buf = buf; 200 cbc.buf = buf;
200 cbc.size = 2048; 201 cbc.size = 2048;
201 cbc.pos = 0; 202 cbc.pos = 0;
202 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, 203 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
204 | add_flag,
203 port, 205 port,
204 NULL, NULL, &ahc_echo, &done_flag, 206 NULL, NULL, &ahc_echo, &done_flag,
205 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4 / 3)), 207 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
206 MHD_OPTION_END); 208 (size_t) (incr_read ? 1024 : (PUT_SIZE * 4 / 3)),
209 MHD_OPTION_END);
207 if (d == NULL) 210 if (d == NULL)
208 return 1; 211 return 1;
209 if (0 == port) 212 if (0 == port)
213 {
214 const union MHD_DaemonInfo *dinfo;
215 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
216 if ((NULL == dinfo) ||(0 == dinfo->port) )
210 { 217 {
211 const union MHD_DaemonInfo *dinfo; 218 MHD_stop_daemon (d); return 32;
212 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
213 if (NULL == dinfo || 0 == dinfo->port)
214 { MHD_stop_daemon (d); return 32; }
215 port = (int)dinfo->port;
216 } 219 }
220 port = (int) dinfo->port;
221 }
217 c = curl_easy_init (); 222 c = curl_easy_init ();
218 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 223 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
219 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 224 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
220 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 225 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
221 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 226 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
222 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 227 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -235,14 +240,14 @@ testPutInternalThread (unsigned int add_flag)
235 * crashes on my system! */ 240 * crashes on my system! */
236 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 241 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
237 if (CURLE_OK != (errornum = curl_easy_perform (c))) 242 if (CURLE_OK != (errornum = curl_easy_perform (c)))
238 { 243 {
239 fprintf (stderr, 244 fprintf (stderr,
240 "curl_easy_perform failed: `%s'\n", 245 "curl_easy_perform failed: `%s'\n",
241 curl_easy_strerror (errornum)); 246 curl_easy_strerror (errornum));
242 curl_easy_cleanup (c); 247 curl_easy_cleanup (c);
243 MHD_stop_daemon (d); 248 MHD_stop_daemon (d);
244 return 2; 249 return 2;
245 } 250 }
246 curl_easy_cleanup (c); 251 curl_easy_cleanup (c);
247 MHD_stop_daemon (d); 252 MHD_stop_daemon (d);
248 if (cbc.pos != strlen ("/hello_world")) 253 if (cbc.pos != strlen ("/hello_world"))
@@ -267,36 +272,40 @@ testPutThreadPerConn (unsigned int add_flag)
267 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 272 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
268 port = 0; 273 port = 0;
269 else 274 else
270 { 275 {
271 port = 1271; 276 port = 1271;
272 if (oneone) 277 if (oneone)
273 port += 10; 278 port += 10;
274 if (incr_read) 279 if (incr_read)
275 port += 20; 280 port += 20;
276 } 281 }
277 282
278 cbc.buf = buf; 283 cbc.buf = buf;
279 cbc.size = 2048; 284 cbc.size = 2048;
280 cbc.pos = 0; 285 cbc.pos = 0;
281 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | 286 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
282 MHD_USE_ERROR_LOG | add_flag, 287 | MHD_USE_INTERNAL_POLLING_THREAD
288 | MHD_USE_ERROR_LOG | add_flag,
283 port, 289 port,
284 NULL, NULL, &ahc_echo, &done_flag, 290 NULL, NULL, &ahc_echo, &done_flag,
285 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), 291 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
286 MHD_OPTION_END); 292 (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)),
293 MHD_OPTION_END);
287 if (d == NULL) 294 if (d == NULL)
288 return 16; 295 return 16;
289 if (0 == port) 296 if (0 == port)
297 {
298 const union MHD_DaemonInfo *dinfo;
299 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
300 if ((NULL == dinfo) ||(0 == dinfo->port) )
290 { 301 {
291 const union MHD_DaemonInfo *dinfo; 302 MHD_stop_daemon (d); return 32;
292 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
293 if (NULL == dinfo || 0 == dinfo->port)
294 { MHD_stop_daemon (d); return 32; }
295 port = (int)dinfo->port;
296 } 303 }
304 port = (int) dinfo->port;
305 }
297 c = curl_easy_init (); 306 c = curl_easy_init ();
298 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 307 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
299 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 308 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
300 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 309 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
301 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 310 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
302 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 311 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -315,21 +324,21 @@ testPutThreadPerConn (unsigned int add_flag)
315 * crashes on my system! */ 324 * crashes on my system! */
316 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 325 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
317 if (CURLE_OK != (errornum = curl_easy_perform (c))) 326 if (CURLE_OK != (errornum = curl_easy_perform (c)))
318 { 327 {
319 fprintf (stderr, 328 fprintf (stderr,
320 "curl_easy_perform failed: `%s'\n", 329 "curl_easy_perform failed: `%s'\n",
321 curl_easy_strerror (errornum)); 330 curl_easy_strerror (errornum));
322 curl_easy_cleanup (c); 331 curl_easy_cleanup (c);
323 MHD_stop_daemon (d); 332 MHD_stop_daemon (d);
324 return 32; 333 return 32;
325 } 334 }
326 curl_easy_cleanup (c); 335 curl_easy_cleanup (c);
327 MHD_stop_daemon (d); 336 MHD_stop_daemon (d);
328 if (cbc.pos != strlen ("/hello_world")) 337 if (cbc.pos != strlen ("/hello_world"))
329 { 338 {
330 fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); 339 fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf);
331 return 64; 340 return 64;
332 } 341 }
333 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 342 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
334 return 128; 343 return 128;
335 return 0; 344 return 0;
@@ -350,36 +359,40 @@ testPutThreadPool (unsigned int add_flag)
350 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 359 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
351 port = 0; 360 port = 0;
352 else 361 else
353 { 362 {
354 port = 1272; 363 port = 1272;
355 if (oneone) 364 if (oneone)
356 port += 10; 365 port += 10;
357 if (incr_read) 366 if (incr_read)
358 port += 20; 367 port += 20;
359 } 368 }
360 369
361 cbc.buf = buf; 370 cbc.buf = buf;
362 cbc.size = 2048; 371 cbc.size = 2048;
363 cbc.pos = 0; 372 cbc.pos = 0;
364 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, 373 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
374 | add_flag,
365 port, 375 port,
366 NULL, NULL, &ahc_echo, &done_flag, 376 NULL, NULL, &ahc_echo, &done_flag,
367 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, 377 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT,
368 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), 378 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
369 MHD_OPTION_END); 379 (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)),
380 MHD_OPTION_END);
370 if (d == NULL) 381 if (d == NULL)
371 return 16; 382 return 16;
372 if (0 == port) 383 if (0 == port)
384 {
385 const union MHD_DaemonInfo *dinfo;
386 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
387 if ((NULL == dinfo) ||(0 == dinfo->port) )
373 { 388 {
374 const union MHD_DaemonInfo *dinfo; 389 MHD_stop_daemon (d); return 32;
375 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
376 if (NULL == dinfo || 0 == dinfo->port)
377 { MHD_stop_daemon (d); return 32; }
378 port = (int)dinfo->port;
379 } 390 }
391 port = (int) dinfo->port;
392 }
380 c = curl_easy_init (); 393 c = curl_easy_init ();
381 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 394 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
382 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 395 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
383 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 396 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
384 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 397 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
385 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 398 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -398,21 +411,21 @@ testPutThreadPool (unsigned int add_flag)
398 * crashes on my system! */ 411 * crashes on my system! */
399 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 412 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
400 if (CURLE_OK != (errornum = curl_easy_perform (c))) 413 if (CURLE_OK != (errornum = curl_easy_perform (c)))
401 { 414 {
402 fprintf (stderr, 415 fprintf (stderr,
403 "curl_easy_perform failed: `%s'\n", 416 "curl_easy_perform failed: `%s'\n",
404 curl_easy_strerror (errornum)); 417 curl_easy_strerror (errornum));
405 curl_easy_cleanup (c); 418 curl_easy_cleanup (c);
406 MHD_stop_daemon (d); 419 MHD_stop_daemon (d);
407 return 32; 420 return 32;
408 } 421 }
409 curl_easy_cleanup (c); 422 curl_easy_cleanup (c);
410 MHD_stop_daemon (d); 423 MHD_stop_daemon (d);
411 if (cbc.pos != strlen ("/hello_world")) 424 if (cbc.pos != strlen ("/hello_world"))
412 { 425 {
413 fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); 426 fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf);
414 return 64; 427 return 64;
415 } 428 }
416 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 429 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
417 return 128; 430 return 128;
418 return 0; 431 return 0;
@@ -447,13 +460,13 @@ testPutExternal (void)
447 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 460 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
448 port = 0; 461 port = 0;
449 else 462 else
450 { 463 {
451 port = 1273; 464 port = 1273;
452 if (oneone) 465 if (oneone)
453 port += 10; 466 port += 10;
454 if (incr_read) 467 if (incr_read)
455 port += 20; 468 port += 20;
456 } 469 }
457 470
458 cbc.buf = buf; 471 cbc.buf = buf;
459 cbc.size = 2048; 472 cbc.size = 2048;
@@ -462,21 +475,24 @@ testPutExternal (void)
462 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 475 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
463 port, 476 port,
464 NULL, NULL, &ahc_echo, &done_flag, 477 NULL, NULL, &ahc_echo, &done_flag,
465 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), 478 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
479 (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)),
466 MHD_OPTION_END); 480 MHD_OPTION_END);
467 if (d == NULL) 481 if (d == NULL)
468 return 256; 482 return 256;
469 if (0 == port) 483 if (0 == port)
484 {
485 const union MHD_DaemonInfo *dinfo;
486 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
487 if ((NULL == dinfo) ||(0 == dinfo->port) )
470 { 488 {
471 const union MHD_DaemonInfo *dinfo; 489 MHD_stop_daemon (d); return 32;
472 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
473 if (NULL == dinfo || 0 == dinfo->port)
474 { MHD_stop_daemon (d); return 32; }
475 port = (int)dinfo->port;
476 } 490 }
491 port = (int) dinfo->port;
492 }
477 c = curl_easy_init (); 493 c = curl_easy_init ();
478 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 494 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
479 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 495 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
480 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 496 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
481 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 497 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
482 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 498 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -498,92 +514,94 @@ testPutExternal (void)
498 514
499 multi = curl_multi_init (); 515 multi = curl_multi_init ();
500 if (multi == NULL) 516 if (multi == NULL)
517 {
518 curl_easy_cleanup (c);
519 MHD_stop_daemon (d);
520 return 512;
521 }
522 mret = curl_multi_add_handle (multi, c);
523 if (mret != CURLM_OK)
524 {
525 curl_multi_cleanup (multi);
526 curl_easy_cleanup (c);
527 MHD_stop_daemon (d);
528 return 1024;
529 }
530 start = time (NULL);
531 while ((time (NULL) - start < 5) && (multi != NULL))
532 {
533 maxsock = MHD_INVALID_SOCKET;
534 maxposixs = -1;
535 FD_ZERO (&rs);
536 FD_ZERO (&ws);
537 FD_ZERO (&es);
538 curl_multi_perform (multi, &running);
539 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
540 if (mret != CURLM_OK)
501 { 541 {
542 curl_multi_remove_handle (multi, c);
543 curl_multi_cleanup (multi);
502 curl_easy_cleanup (c); 544 curl_easy_cleanup (c);
503 MHD_stop_daemon (d); 545 MHD_stop_daemon (d);
504 return 512; 546 return 2048;
505 } 547 }
506 mret = curl_multi_add_handle (multi, c); 548 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
507 if (mret != CURLM_OK)
508 { 549 {
550 curl_multi_remove_handle (multi, c);
509 curl_multi_cleanup (multi); 551 curl_multi_cleanup (multi);
510 curl_easy_cleanup (c); 552 curl_easy_cleanup (c);
511 MHD_stop_daemon (d); 553 MHD_stop_daemon (d);
512 return 1024; 554 return 4096;
513 } 555 }
514 start = time (NULL); 556 tv.tv_sec = 0;
515 while ((time (NULL) - start < 5) && (multi != NULL)) 557 tv.tv_usec = 1000;
558 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
516 { 559 {
517 maxsock = MHD_INVALID_SOCKET;
518 maxposixs = -1;
519 FD_ZERO (&rs);
520 FD_ZERO (&ws);
521 FD_ZERO (&es);
522 curl_multi_perform (multi, &running);
523 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
524 if (mret != CURLM_OK)
525 {
526 curl_multi_remove_handle (multi, c);
527 curl_multi_cleanup (multi);
528 curl_easy_cleanup (c);
529 MHD_stop_daemon (d);
530 return 2048;
531 }
532 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
533 {
534 curl_multi_remove_handle (multi, c);
535 curl_multi_cleanup (multi);
536 curl_easy_cleanup (c);
537 MHD_stop_daemon (d);
538 return 4096;
539 }
540 tv.tv_sec = 0;
541 tv.tv_usec = 1000;
542 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
543 {
544#ifdef MHD_POSIX_SOCKETS 560#ifdef MHD_POSIX_SOCKETS
545 if (EINTR != errno) 561 if (EINTR != errno)
546 abort (); 562 abort ();
547#else 563#else
548 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 564 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
549 abort (); 565 ws.fd_count)
550 Sleep (1000); 566 ||(0 != es.fd_count) )
567 abort ();
568 Sleep (1000);
551#endif 569#endif
552 }
553 curl_multi_perform (multi, &running);
554 if (running == 0)
555 {
556 msg = curl_multi_info_read (multi, &running);
557 if (msg == NULL)
558 break;
559 if (msg->msg == CURLMSG_DONE)
560 {
561 if (msg->data.result != CURLE_OK)
562 printf ("%s failed at %s:%d: `%s'\n",
563 "curl_multi_perform",
564 __FILE__,
565 __LINE__, curl_easy_strerror (msg->data.result));
566 curl_multi_remove_handle (multi, c);
567 curl_multi_cleanup (multi);
568 curl_easy_cleanup (c);
569 c = NULL;
570 multi = NULL;
571 }
572 }
573 MHD_run (d);
574 } 570 }
575 if (multi != NULL) 571 curl_multi_perform (multi, &running);
572 if (running == 0)
576 { 573 {
577 curl_multi_remove_handle (multi, c); 574 msg = curl_multi_info_read (multi, &running);
578 curl_easy_cleanup (c); 575 if (msg == NULL)
579 curl_multi_cleanup (multi); 576 break;
577 if (msg->msg == CURLMSG_DONE)
578 {
579 if (msg->data.result != CURLE_OK)
580 printf ("%s failed at %s:%d: `%s'\n",
581 "curl_multi_perform",
582 __FILE__,
583 __LINE__, curl_easy_strerror (msg->data.result));
584 curl_multi_remove_handle (multi, c);
585 curl_multi_cleanup (multi);
586 curl_easy_cleanup (c);
587 c = NULL;
588 multi = NULL;
589 }
580 } 590 }
591 MHD_run (d);
592 }
593 if (multi != NULL)
594 {
595 curl_multi_remove_handle (multi, c);
596 curl_easy_cleanup (c);
597 curl_multi_cleanup (multi);
598 }
581 MHD_stop_daemon (d); 599 MHD_stop_daemon (d);
582 if (cbc.pos != strlen ("/hello_world")) 600 if (cbc.pos != strlen ("/hello_world"))
583 { 601 {
584 fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); 602 fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf);
585 return 8192; 603 return 8192;
586 } 604 }
587 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 605 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
588 return 16384; 606 return 16384;
589 return 0; 607 return 0;
@@ -597,59 +615,67 @@ main (int argc, char *const *argv)
597 unsigned int errorCount = 0; 615 unsigned int errorCount = 0;
598 unsigned int lastErr; 616 unsigned int lastErr;
599 617
600 oneone = has_in_name(argv[0], "11"); 618 oneone = has_in_name (argv[0], "11");
601 incr_read = has_in_name(argv[0], "_inc"); 619 incr_read = has_in_name (argv[0], "_inc");
602 verbose = has_param(argc, argv, "-v"); 620 verbose = has_param (argc, argv, "-v");
603 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 621 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
604 return 99; 622 return 99;
605 put_buffer = alloc_init (PUT_SIZE); 623 put_buffer = alloc_init (PUT_SIZE);
606 if (NULL == put_buffer) 624 if (NULL == put_buffer)
607 return 99; 625 return 99;
608 lastErr = testPutExternal (); 626 lastErr = testPutExternal ();
609 if (verbose && 0 != lastErr) 627 if (verbose &&(0 != lastErr))
610 fprintf (stderr, "Error during testing with external select().\n"); 628 fprintf (stderr, "Error during testing with external select().\n");
611 errorCount += lastErr; 629 errorCount += lastErr;
612 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 630 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
631 {
632 lastErr = testPutInternalThread (0);
633 if (verbose &&(0 != lastErr) )
634 fprintf (stderr,
635 "Error during testing with internal thread with select().\n");
636 errorCount += lastErr;
637 lastErr = testPutThreadPerConn (0);
638 if (verbose &&(0 != lastErr) )
639 fprintf (stderr,
640 "Error during testing with internal thread per connection with select().\n");
641 errorCount += lastErr;
642 lastErr = testPutThreadPool (0);
643 if (verbose &&(0 != lastErr) )
644 fprintf (stderr,
645 "Error during testing with thread pool per connection with select().\n");
646 errorCount += lastErr;
647 if (MHD_is_feature_supported (MHD_FEATURE_POLL))
613 { 648 {
614 lastErr = testPutInternalThread (0); 649 lastErr = testPutInternalThread (MHD_USE_POLL);
615 if (verbose && 0 != lastErr) 650 if (verbose &&(0 != lastErr) )
616 fprintf (stderr, "Error during testing with internal thread with select().\n"); 651 fprintf (stderr,
652 "Error during testing with internal thread with poll().\n");
617 errorCount += lastErr; 653 errorCount += lastErr;
618 lastErr = testPutThreadPerConn (0); 654 lastErr = testPutThreadPerConn (MHD_USE_POLL);
619 if (verbose && 0 != lastErr) 655 if (verbose &&(0 != lastErr) )
620 fprintf (stderr, "Error during testing with internal thread per connection with select().\n"); 656 fprintf (stderr,
657 "Error during testing with internal thread per connection with poll().\n");
658 errorCount += lastErr;
659 lastErr = testPutThreadPool (MHD_USE_POLL);
660 if (verbose &&(0 != lastErr) )
661 fprintf (stderr,
662 "Error during testing with thread pool per connection with poll().\n");
663 errorCount += lastErr;
664 }
665 if (MHD_is_feature_supported (MHD_FEATURE_EPOLL))
666 {
667 lastErr = testPutInternalThread (MHD_USE_EPOLL);
668 if (verbose &&(0 != lastErr) )
669 fprintf (stderr,
670 "Error during testing with internal thread with epoll.\n");
621 errorCount += lastErr; 671 errorCount += lastErr;
622 lastErr = testPutThreadPool (0); 672 lastErr = testPutThreadPool (MHD_USE_EPOLL);
623 if (verbose && 0 != lastErr) 673 if (verbose &&(0 != lastErr) )
624 fprintf (stderr, "Error during testing with thread pool per connection with select().\n"); 674 fprintf (stderr,
675 "Error during testing with thread pool per connection with epoll.\n");
625 errorCount += lastErr; 676 errorCount += lastErr;
626 if (MHD_is_feature_supported(MHD_FEATURE_POLL))
627 {
628 lastErr = testPutInternalThread (MHD_USE_POLL);
629 if (verbose && 0 != lastErr)
630 fprintf (stderr, "Error during testing with internal thread with poll().\n");
631 errorCount += lastErr;
632 lastErr = testPutThreadPerConn (MHD_USE_POLL);
633 if (verbose && 0 != lastErr)
634 fprintf (stderr, "Error during testing with internal thread per connection with poll().\n");
635 errorCount += lastErr;
636 lastErr = testPutThreadPool (MHD_USE_POLL);
637 if (verbose && 0 != lastErr)
638 fprintf (stderr, "Error during testing with thread pool per connection with poll().\n");
639 errorCount += lastErr;
640 }
641 if (MHD_is_feature_supported(MHD_FEATURE_EPOLL))
642 {
643 lastErr = testPutInternalThread (MHD_USE_EPOLL);
644 if (verbose && 0 != lastErr)
645 fprintf (stderr, "Error during testing with internal thread with epoll.\n");
646 errorCount += lastErr;
647 lastErr = testPutThreadPool (MHD_USE_EPOLL);
648 if (verbose && 0 != lastErr)
649 fprintf (stderr, "Error during testing with thread pool per connection with epoll.\n");
650 errorCount += lastErr;
651 }
652 } 677 }
678 }
653 free (put_buffer); 679 free (put_buffer);
654 if (errorCount != 0) 680 if (errorCount != 0)
655 fprintf (stderr, "Error (code: %u)\n", errorCount); 681 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_long_header.c b/src/testcurl/test_long_header.c
index dc76a136..01d62d11 100644
--- a/src/testcurl/test_long_header.c
+++ b/src/testcurl/test_long_header.c
@@ -42,14 +42,14 @@
42 * half of this value, so the actual value does not have 42 * half of this value, so the actual value does not have
43 * to be big at all... 43 * to be big at all...
44 */ 44 */
45#define VERY_LONG (1024*8) 45#define VERY_LONG (1024 * 8)
46 46
47static int oneone; 47static int oneone;
48 48
49static int 49static int
50apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) 50apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen)
51{ 51{
52 (void)cls;(void)addr;(void)addrlen; /* Unused. Silent compiler warning. */ 52 (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */
53 return MHD_YES; 53 return MHD_YES;
54} 54}
55 55
@@ -63,7 +63,7 @@ struct CBC
63static size_t 63static size_t
64copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 64copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
65{ 65{
66 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 66 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
67 return size * nmemb; 67 return size * nmemb;
68} 68}
69 69
@@ -79,14 +79,14 @@ ahc_echo (void *cls,
79 const char *me = cls; 79 const char *me = cls;
80 struct MHD_Response *response; 80 struct MHD_Response *response;
81 int ret; 81 int ret;
82 (void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 82 (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
83 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 83 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
84 84
85 if (0 != strcmp (me, method)) 85 if (0 != strcmp (me, method))
86 return MHD_NO; /* unexpected method */ 86 return MHD_NO; /* unexpected method */
87 response = MHD_create_response_from_buffer (strlen (url), 87 response = MHD_create_response_from_buffer (strlen (url),
88 (void *) url, 88 (void *) url,
89 MHD_RESPMEM_MUST_COPY); 89 MHD_RESPMEM_MUST_COPY);
90 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 90 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
91 MHD_destroy_response (response); 91 MHD_destroy_response (response);
92 return ret; 92 return ret;
@@ -107,44 +107,47 @@ testLongUrlGet (size_t buff_size)
107 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 107 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
108 port = 0; 108 port = 0;
109 else 109 else
110 { 110 {
111 port = 1330 + buff_size % 20; 111 port = 1330 + buff_size % 20;
112 if (oneone) 112 if (oneone)
113 port += 5; 113 port += 5;
114 } 114 }
115 cbc.buf = buf; 115 cbc.buf = buf;
116 cbc.size = 2048; 116 cbc.size = 2048;
117 cbc.pos = 0; 117 cbc.pos = 0;
118 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 118 d = MHD_start_daemon (
119 port, 119 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
120 &apc_all, 120 port,
121 NULL, 121 &apc_all,
122 &ahc_echo, 122 NULL,
123 "GET", 123 &ahc_echo,
124 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 124 "GET",
125 (size_t) buff_size, MHD_OPTION_END); 125 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
126 (size_t) buff_size, MHD_OPTION_END);
126 if (d == NULL) 127 if (d == NULL)
127 return 1; 128 return 1;
128 if (0 == port) 129 if (0 == port)
130 {
131 const union MHD_DaemonInfo *dinfo;
132 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
133 if ((NULL == dinfo) ||(0 == dinfo->port) )
129 { 134 {
130 const union MHD_DaemonInfo *dinfo; 135 MHD_stop_daemon (d); return 32;
131 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
132 if (NULL == dinfo || 0 == dinfo->port)
133 { MHD_stop_daemon (d); return 32; }
134 port = (int)dinfo->port;
135 } 136 }
137 port = (int) dinfo->port;
138 }
136 c = curl_easy_init (); 139 c = curl_easy_init ();
137 url = malloc (VERY_LONG); 140 url = malloc (VERY_LONG);
138 if (url == NULL) 141 if (url == NULL)
139 { 142 {
140 MHD_stop_daemon (d); 143 MHD_stop_daemon (d);
141 return 1; 144 return 1;
142 } 145 }
143 memset (url, 'a', VERY_LONG); 146 memset (url, 'a', VERY_LONG);
144 url[VERY_LONG - 1] = '\0'; 147 url[VERY_LONG - 1] = '\0';
145 memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/")); 148 memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/"));
146 curl_easy_setopt (c, CURLOPT_URL, url); 149 curl_easy_setopt (c, CURLOPT_URL, url);
147 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 150 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
148 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 151 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
149 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 152 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
150 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 153 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -159,19 +162,19 @@ testLongUrlGet (size_t buff_size)
159 crashes on my system! */ 162 crashes on my system! */
160 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 163 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
161 if (CURLE_OK == curl_easy_perform (c)) 164 if (CURLE_OK == curl_easy_perform (c))
162 { 165 {
163 curl_easy_cleanup (c); 166 curl_easy_cleanup (c);
164 MHD_stop_daemon (d); 167 MHD_stop_daemon (d);
165 free (url); 168 free (url);
166 return 2; 169 return 2;
167 } 170 }
168 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) 171 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
169 { 172 {
170 curl_easy_cleanup (c); 173 curl_easy_cleanup (c);
171 MHD_stop_daemon (d); 174 MHD_stop_daemon (d);
172 free (url); 175 free (url);
173 return 4; 176 return 4;
174 } 177 }
175 curl_easy_cleanup (c); 178 curl_easy_cleanup (c);
176 MHD_stop_daemon (d); 179 MHD_stop_daemon (d);
177 free (url); 180 free (url);
@@ -196,40 +199,43 @@ testLongHeaderGet (size_t buff_size)
196 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 199 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
197 port = 0; 200 port = 0;
198 else 201 else
199 { 202 {
200 port = 1331 + buff_size % 20; 203 port = 1331 + buff_size % 20;
201 if (oneone) 204 if (oneone)
202 port += 5; 205 port += 5;
203 } 206 }
204 207
205 cbc.buf = buf; 208 cbc.buf = buf;
206 cbc.size = 2048; 209 cbc.size = 2048;
207 cbc.pos = 0; 210 cbc.pos = 0;
208 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 211 d = MHD_start_daemon (
209 port, 212 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
210 &apc_all, 213 port,
211 NULL, 214 &apc_all,
212 &ahc_echo, 215 NULL,
213 "GET", 216 &ahc_echo,
214 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 217 "GET",
215 (size_t) buff_size, MHD_OPTION_END); 218 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
219 (size_t) buff_size, MHD_OPTION_END);
216 if (d == NULL) 220 if (d == NULL)
217 return 16; 221 return 16;
218 if (0 == port) 222 if (0 == port)
223 {
224 const union MHD_DaemonInfo *dinfo;
225 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
226 if ((NULL == dinfo) ||(0 == dinfo->port) )
219 { 227 {
220 const union MHD_DaemonInfo *dinfo; 228 MHD_stop_daemon (d); return 32;
221 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
222 if (NULL == dinfo || 0 == dinfo->port)
223 { MHD_stop_daemon (d); return 32; }
224 port = (int)dinfo->port;
225 } 229 }
230 port = (int) dinfo->port;
231 }
226 c = curl_easy_init (); 232 c = curl_easy_init ();
227 url = malloc (VERY_LONG); 233 url = malloc (VERY_LONG);
228 if (url == NULL) 234 if (url == NULL)
229 { 235 {
230 MHD_stop_daemon (d); 236 MHD_stop_daemon (d);
231 return 16; 237 return 16;
232 } 238 }
233 memset (url, 'a', VERY_LONG); 239 memset (url, 'a', VERY_LONG);
234 url[VERY_LONG - 1] = '\0'; 240 url[VERY_LONG - 1] = '\0';
235 url[VERY_LONG / 2] = ':'; 241 url[VERY_LONG / 2] = ':';
@@ -238,7 +244,7 @@ testLongHeaderGet (size_t buff_size)
238 244
239 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); 245 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
240 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 246 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
241 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 247 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
242 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
243 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
244 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 250 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -253,21 +259,21 @@ testLongHeaderGet (size_t buff_size)
253 crashes on my system! */ 259 crashes on my system! */
254 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 260 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
255 if (CURLE_OK == curl_easy_perform (c)) 261 if (CURLE_OK == curl_easy_perform (c))
256 { 262 {
257 curl_easy_cleanup (c); 263 curl_easy_cleanup (c);
258 MHD_stop_daemon (d); 264 MHD_stop_daemon (d);
259 curl_slist_free_all (header); 265 curl_slist_free_all (header);
260 free (url); 266 free (url);
261 return 32; 267 return 32;
262 } 268 }
263 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) 269 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
264 { 270 {
265 curl_slist_free_all (header); 271 curl_slist_free_all (header);
266 curl_easy_cleanup (c); 272 curl_easy_cleanup (c);
267 MHD_stop_daemon (d); 273 MHD_stop_daemon (d);
268 free (url); 274 free (url);
269 return 64; 275 return 64;
270 } 276 }
271 curl_slist_free_all (header); 277 curl_slist_free_all (header);
272 curl_easy_cleanup (c); 278 curl_easy_cleanup (c);
273 MHD_stop_daemon (d); 279 MHD_stop_daemon (d);
@@ -281,9 +287,9 @@ int
281main (int argc, char *const *argv) 287main (int argc, char *const *argv)
282{ 288{
283 unsigned int errorCount = 0; 289 unsigned int errorCount = 0;
284 (void)argc; /* Unused. Silent compiler warning. */ 290 (void) argc; /* Unused. Silent compiler warning. */
285 291
286 if (NULL == argv || 0 == argv[0]) 292 if ((NULL == argv)||(0 == argv[0]))
287 return 99; 293 return 99;
288 oneone = has_in_name (argv[0], "11"); 294 oneone = has_in_name (argv[0], "11");
289 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 295 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
diff --git a/src/testcurl/test_parse_cookies.c b/src/testcurl/test_parse_cookies.c
index c09846d8..da33ea3f 100644
--- a/src/testcurl/test_parse_cookies.c
+++ b/src/testcurl/test_parse_cookies.c
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
4 Copyright (C) 2007 Christian Grothoff 3 Copyright (C) 2007 Christian Grothoff
@@ -73,15 +72,15 @@ ahc_echo (void *cls,
73 struct MHD_Response *response; 72 struct MHD_Response *response;
74 int ret; 73 int ret;
75 const char *hdr; 74 const char *hdr;
76 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 75 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
77 76
78 if (0 != strcmp (me, method)) 77 if (0 != strcmp (me, method))
79 return MHD_NO; /* unexpected method */ 78 return MHD_NO; /* unexpected method */
80 if (&ptr != *unused) 79 if (&ptr != *unused)
81 { 80 {
82 *unused = &ptr; 81 *unused = &ptr;
83 return MHD_YES; 82 return MHD_YES;
84 } 83 }
85 *unused = NULL; 84 *unused = NULL;
86 85
87 hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1"); 86 hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1");
@@ -97,8 +96,8 @@ ahc_echo (void *cls,
97 if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces"))) 96 if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces")))
98 abort (); 97 abort ();
99 response = MHD_create_response_from_buffer (strlen (url), 98 response = MHD_create_response_from_buffer (strlen (url),
100 (void *) url, 99 (void *) url,
101 MHD_RESPMEM_PERSISTENT); 100 MHD_RESPMEM_PERSISTENT);
102 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 101 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
103 MHD_destroy_response (response); 102 MHD_destroy_response (response);
104 if (ret == MHD_NO) 103 if (ret == MHD_NO)
@@ -133,11 +132,11 @@ testExternalGet ()
133 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 132 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
134 port = 0; 133 port = 0;
135 else 134 else
136 { 135 {
137 port = 1340; 136 port = 1340;
138 if (oneone) 137 if (oneone)
139 port += 5; 138 port += 5;
140 } 139 }
141 140
142 multi = NULL; 141 multi = NULL;
143 cbc.buf = buf; 142 cbc.buf = buf;
@@ -148,16 +147,18 @@ testExternalGet ()
148 if (d == NULL) 147 if (d == NULL)
149 return 256; 148 return 256;
150 if (0 == port) 149 if (0 == port)
150 {
151 const union MHD_DaemonInfo *dinfo;
152 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
153 if ((NULL == dinfo) ||(0 == dinfo->port) )
151 { 154 {
152 const union MHD_DaemonInfo *dinfo; 155 MHD_stop_daemon (d); return 32;
153 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
154 if (NULL == dinfo || 0 == dinfo->port)
155 { MHD_stop_daemon (d); return 32; }
156 port = (int)dinfo->port;
157 } 156 }
157 port = (int) dinfo->port;
158 }
158 c = curl_easy_init (); 159 c = curl_easy_init ();
159 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 160 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
160 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 161 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
161 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 162 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
162 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 163 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
163 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 164 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -180,86 +181,88 @@ testExternalGet ()
180 181
181 multi = curl_multi_init (); 182 multi = curl_multi_init ();
182 if (multi == NULL) 183 if (multi == NULL)
184 {
185 curl_easy_cleanup (c);
186 MHD_stop_daemon (d);
187 return 512;
188 }
189 mret = curl_multi_add_handle (multi, c);
190 if (mret != CURLM_OK)
191 {
192 curl_multi_cleanup (multi);
193 curl_easy_cleanup (c);
194 MHD_stop_daemon (d);
195 return 1024;
196 }
197 start = time (NULL);
198 while ((time (NULL) - start < 5) && (multi != NULL))
199 {
200 maxsock = MHD_INVALID_SOCKET;
201 maxposixs = -1;
202 FD_ZERO (&rs);
203 FD_ZERO (&ws);
204 FD_ZERO (&es);
205 curl_multi_perform (multi, &running);
206 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
207 if (mret != CURLM_OK)
183 { 208 {
209 curl_multi_remove_handle (multi, c);
210 curl_multi_cleanup (multi);
184 curl_easy_cleanup (c); 211 curl_easy_cleanup (c);
185 MHD_stop_daemon (d); 212 MHD_stop_daemon (d);
186 return 512; 213 return 2048;
187 } 214 }
188 mret = curl_multi_add_handle (multi, c); 215 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
189 if (mret != CURLM_OK)
190 { 216 {
217 curl_multi_remove_handle (multi, c);
191 curl_multi_cleanup (multi); 218 curl_multi_cleanup (multi);
192 curl_easy_cleanup (c); 219 curl_easy_cleanup (c);
193 MHD_stop_daemon (d); 220 MHD_stop_daemon (d);
194 return 1024; 221 return 4096;
195 } 222 }
196 start = time (NULL); 223 tv.tv_sec = 0;
197 while ((time (NULL) - start < 5) && (multi != NULL)) 224 tv.tv_usec = 1000;
225 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
198 { 226 {
199 maxsock = MHD_INVALID_SOCKET;
200 maxposixs = -1;
201 FD_ZERO (&rs);
202 FD_ZERO (&ws);
203 FD_ZERO (&es);
204 curl_multi_perform (multi, &running);
205 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
206 if (mret != CURLM_OK)
207 {
208 curl_multi_remove_handle (multi, c);
209 curl_multi_cleanup (multi);
210 curl_easy_cleanup (c);
211 MHD_stop_daemon (d);
212 return 2048;
213 }
214 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
215 {
216 curl_multi_remove_handle (multi, c);
217 curl_multi_cleanup (multi);
218 curl_easy_cleanup (c);
219 MHD_stop_daemon (d);
220 return 4096;
221 }
222 tv.tv_sec = 0;
223 tv.tv_usec = 1000;
224 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
225 {
226#ifdef MHD_POSIX_SOCKETS 227#ifdef MHD_POSIX_SOCKETS
227 if (EINTR != errno) 228 if (EINTR != errno)
228 abort (); 229 abort ();
229#else 230#else
230 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 231 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
231 abort (); 232 ws.fd_count)
232 Sleep (1000); 233 ||(0 != es.fd_count) )
234 abort ();
235 Sleep (1000);
233#endif 236#endif
234 }
235 curl_multi_perform (multi, &running);
236 if (running == 0)
237 {
238 msg = curl_multi_info_read (multi, &running);
239 if (msg == NULL)
240 break;
241 if (msg->msg == CURLMSG_DONE)
242 {
243 if (msg->data.result != CURLE_OK)
244 printf ("%s failed at %s:%d: `%s'\n",
245 "curl_multi_perform",
246 __FILE__,
247 __LINE__, curl_easy_strerror (msg->data.result));
248 curl_multi_remove_handle (multi, c);
249 curl_multi_cleanup (multi);
250 curl_easy_cleanup (c);
251 c = NULL;
252 multi = NULL;
253 }
254 }
255 MHD_run (d);
256 } 237 }
257 if (multi != NULL) 238 curl_multi_perform (multi, &running);
239 if (running == 0)
258 { 240 {
259 curl_multi_remove_handle (multi, c); 241 msg = curl_multi_info_read (multi, &running);
260 curl_easy_cleanup (c); 242 if (msg == NULL)
261 curl_multi_cleanup (multi); 243 break;
244 if (msg->msg == CURLMSG_DONE)
245 {
246 if (msg->data.result != CURLE_OK)
247 printf ("%s failed at %s:%d: `%s'\n",
248 "curl_multi_perform",
249 __FILE__,
250 __LINE__, curl_easy_strerror (msg->data.result));
251 curl_multi_remove_handle (multi, c);
252 curl_multi_cleanup (multi);
253 curl_easy_cleanup (c);
254 c = NULL;
255 multi = NULL;
256 }
262 } 257 }
258 MHD_run (d);
259 }
260 if (multi != NULL)
261 {
262 curl_multi_remove_handle (multi, c);
263 curl_easy_cleanup (c);
264 curl_multi_cleanup (multi);
265 }
263 MHD_stop_daemon (d); 266 MHD_stop_daemon (d);
264 if (cbc.pos != strlen ("/hello_world")) 267 if (cbc.pos != strlen ("/hello_world"))
265 return 8192; 268 return 8192;
@@ -273,9 +276,9 @@ int
273main (int argc, char *const *argv) 276main (int argc, char *const *argv)
274{ 277{
275 unsigned int errorCount = 0; 278 unsigned int errorCount = 0;
276 (void)argc; /* Unused. Silent compiler warning. */ 279 (void) argc; /* Unused. Silent compiler warning. */
277 280
278 if (NULL == argv || 0 == argv[0]) 281 if ((NULL == argv)||(0 == argv[0]))
279 return 99; 282 return 99;
280 oneone = has_in_name (argv[0], "11"); 283 oneone = has_in_name (argv[0], "11");
281 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 284 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c
index 03452a2f..b665139a 100644
--- a/src/testcurl/test_post.c
+++ b/src/testcurl/test_post.c
@@ -45,10 +45,10 @@
45 45
46#include "mhd_has_in_name.h" 46#include "mhd_has_in_name.h"
47 47
48#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 48#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
49#undef CPU_COUNT 49#undef CPU_COUNT
50#endif 50#endif
51#if !defined(CPU_COUNT) 51#if ! defined(CPU_COUNT)
52#define CPU_COUNT 2 52#define CPU_COUNT 2
53#endif 53#endif
54 54
@@ -66,12 +66,12 @@ struct CBC
66 66
67static void 67static void
68completed_cb (void *cls, 68completed_cb (void *cls,
69 struct MHD_Connection *connection, 69 struct MHD_Connection *connection,
70 void **con_cls, 70 void **con_cls,
71 enum MHD_RequestTerminationCode toe) 71 enum MHD_RequestTerminationCode toe)
72{ 72{
73 struct MHD_PostProcessor *pp = *con_cls; 73 struct MHD_PostProcessor *pp = *con_cls;
74 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 74 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
75 75
76 if (NULL != pp) 76 if (NULL != pp)
77 MHD_destroy_post_processor (pp); 77 MHD_destroy_post_processor (pp);
@@ -107,8 +107,8 @@ post_iterator (void *cls,
107 const char *value, uint64_t off, size_t size) 107 const char *value, uint64_t off, size_t size)
108{ 108{
109 int *eok = cls; 109 int *eok = cls;
110 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 110 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
111 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 111 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
112 112
113 if ((0 == strcasecmp (key, "name")) && 113 if ((0 == strcasecmp (key, "name")) &&
114 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) 114 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
@@ -133,32 +133,32 @@ ahc_echo (void *cls,
133 struct MHD_Response *response; 133 struct MHD_Response *response;
134 struct MHD_PostProcessor *pp; 134 struct MHD_PostProcessor *pp;
135 int ret; 135 int ret;
136 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 136 (void) cls; (void) version; /* Unused. Silent compiler warning. */
137 137
138 if (0 != strcasecmp ("POST", method)) 138 if (0 != strcasecmp ("POST", method))
139 { 139 {
140 printf ("METHOD: %s\n", method); 140 printf ("METHOD: %s\n", method);
141 return MHD_NO; /* unexpected method */ 141 return MHD_NO; /* unexpected method */
142 } 142 }
143 pp = *unused; 143 pp = *unused;
144 if (pp == NULL) 144 if (pp == NULL)
145 { 145 {
146 eok = 0; 146 eok = 0;
147 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 147 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
148 *unused = pp; 148 *unused = pp;
149 } 149 }
150 MHD_post_process (pp, upload_data, *upload_data_size); 150 MHD_post_process (pp, upload_data, *upload_data_size);
151 if ((eok == 3) && (0 == *upload_data_size)) 151 if ((eok == 3) && (0 == *upload_data_size))
152 { 152 {
153 response = MHD_create_response_from_buffer (strlen (url), 153 response = MHD_create_response_from_buffer (strlen (url),
154 (void *) url, 154 (void *) url,
155 MHD_RESPMEM_MUST_COPY); 155 MHD_RESPMEM_MUST_COPY);
156 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 156 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
157 MHD_destroy_response (response); 157 MHD_destroy_response (response);
158 MHD_destroy_post_processor (pp); 158 MHD_destroy_post_processor (pp);
159 *unused = NULL; 159 *unused = NULL;
160 return ret; 160 return ret;
161 } 161 }
162 *upload_data_size = 0; 162 *upload_data_size = 0;
163 return MHD_YES; 163 return MHD_YES;
164} 164}
@@ -177,32 +177,34 @@ testInternalPost ()
177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
178 port = 0; 178 port = 0;
179 else 179 else
180 { 180 {
181 port = 1370; 181 port = 1370;
182 if (oneone) 182 if (oneone)
183 port += 10; 183 port += 10;
184 } 184 }
185 185
186 cbc.buf = buf; 186 cbc.buf = buf;
187 cbc.size = 2048; 187 cbc.size = 2048;
188 cbc.pos = 0; 188 cbc.pos = 0;
189 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 189 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
190 port, NULL, NULL, &ahc_echo, NULL, 190 port, NULL, NULL, &ahc_echo, NULL,
191 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 191 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
192 MHD_OPTION_END); 192 MHD_OPTION_END);
193 if (d == NULL) 193 if (d == NULL)
194 return 1; 194 return 1;
195 if (0 == port) 195 if (0 == port)
196 {
197 const union MHD_DaemonInfo *dinfo;
198 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
199 if ((NULL == dinfo) ||(0 == dinfo->port) )
196 { 200 {
197 const union MHD_DaemonInfo *dinfo; 201 MHD_stop_daemon (d); return 32;
198 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
199 if (NULL == dinfo || 0 == dinfo->port)
200 { MHD_stop_daemon (d); return 32; }
201 port = (int)dinfo->port;
202 } 202 }
203 port = (int) dinfo->port;
204 }
203 c = curl_easy_init (); 205 c = curl_easy_init ();
204 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 206 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
205 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 207 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
206 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 208 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
207 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 209 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
208 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 210 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
@@ -220,14 +222,14 @@ testInternalPost ()
220 * crashes on my system! */ 222 * crashes on my system! */
221 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 223 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
222 if (CURLE_OK != (errornum = curl_easy_perform (c))) 224 if (CURLE_OK != (errornum = curl_easy_perform (c)))
223 { 225 {
224 fprintf (stderr, 226 fprintf (stderr,
225 "curl_easy_perform failed: `%s'\n", 227 "curl_easy_perform failed: `%s'\n",
226 curl_easy_strerror (errornum)); 228 curl_easy_strerror (errornum));
227 curl_easy_cleanup (c); 229 curl_easy_cleanup (c);
228 MHD_stop_daemon (d); 230 MHD_stop_daemon (d);
229 return 2; 231 return 2;
230 } 232 }
231 curl_easy_cleanup (c); 233 curl_easy_cleanup (c);
232 MHD_stop_daemon (d); 234 MHD_stop_daemon (d);
233 if (cbc.pos != strlen ("/hello_world")) 235 if (cbc.pos != strlen ("/hello_world"))
@@ -250,32 +252,35 @@ testMultithreadedPost ()
250 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 252 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
251 port = 0; 253 port = 0;
252 else 254 else
253 { 255 {
254 port = 1371; 256 port = 1371;
255 if (oneone) 257 if (oneone)
256 port += 10; 258 port += 10;
257 } 259 }
258 260
259 cbc.buf = buf; 261 cbc.buf = buf;
260 cbc.size = 2048; 262 cbc.size = 2048;
261 cbc.pos = 0; 263 cbc.pos = 0;
262 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 264 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
265 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
263 port, NULL, NULL, &ahc_echo, NULL, 266 port, NULL, NULL, &ahc_echo, NULL,
264 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 267 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
265 MHD_OPTION_END); 268 MHD_OPTION_END);
266 if (d == NULL) 269 if (d == NULL)
267 return 16; 270 return 16;
268 if (0 == port) 271 if (0 == port)
272 {
273 const union MHD_DaemonInfo *dinfo;
274 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
275 if ((NULL == dinfo) ||(0 == dinfo->port) )
269 { 276 {
270 const union MHD_DaemonInfo *dinfo; 277 MHD_stop_daemon (d); return 32;
271 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
272 if (NULL == dinfo || 0 == dinfo->port)
273 { MHD_stop_daemon (d); return 32; }
274 port = (int)dinfo->port;
275 } 278 }
279 port = (int) dinfo->port;
280 }
276 c = curl_easy_init (); 281 c = curl_easy_init ();
277 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 282 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
278 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 283 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
279 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 284 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
280 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 285 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
281 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 286 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
@@ -293,14 +298,14 @@ testMultithreadedPost ()
293 * crashes on my system! */ 298 * crashes on my system! */
294 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 299 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
295 if (CURLE_OK != (errornum = curl_easy_perform (c))) 300 if (CURLE_OK != (errornum = curl_easy_perform (c)))
296 { 301 {
297 fprintf (stderr, 302 fprintf (stderr,
298 "curl_easy_perform failed: `%s'\n", 303 "curl_easy_perform failed: `%s'\n",
299 curl_easy_strerror (errornum)); 304 curl_easy_strerror (errornum));
300 curl_easy_cleanup (c); 305 curl_easy_cleanup (c);
301 MHD_stop_daemon (d); 306 MHD_stop_daemon (d);
302 return 32; 307 return 32;
303 } 308 }
304 curl_easy_cleanup (c); 309 curl_easy_cleanup (c);
305 MHD_stop_daemon (d); 310 MHD_stop_daemon (d);
306 if (cbc.pos != strlen ("/hello_world")) 311 if (cbc.pos != strlen ("/hello_world"))
@@ -323,11 +328,11 @@ testMultithreadedPoolPost ()
323 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 328 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
324 port = 0; 329 port = 0;
325 else 330 else
326 { 331 {
327 port = 1372; 332 port = 1372;
328 if (oneone) 333 if (oneone)
329 port += 10; 334 port += 10;
330 } 335 }
331 336
332 cbc.buf = buf; 337 cbc.buf = buf;
333 cbc.size = 2048; 338 cbc.size = 2048;
@@ -335,21 +340,23 @@ testMultithreadedPoolPost ()
335 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 340 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
336 port, NULL, NULL, &ahc_echo, NULL, 341 port, NULL, NULL, &ahc_echo, NULL,
337 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, 342 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT,
338 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 343 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
339 MHD_OPTION_END); 344 MHD_OPTION_END);
340 if (d == NULL) 345 if (d == NULL)
341 return 16; 346 return 16;
342 if (0 == port) 347 if (0 == port)
348 {
349 const union MHD_DaemonInfo *dinfo;
350 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
351 if ((NULL == dinfo) ||(0 == dinfo->port) )
343 { 352 {
344 const union MHD_DaemonInfo *dinfo; 353 MHD_stop_daemon (d); return 32;
345 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
346 if (NULL == dinfo || 0 == dinfo->port)
347 { MHD_stop_daemon (d); return 32; }
348 port = (int)dinfo->port;
349 } 354 }
355 port = (int) dinfo->port;
356 }
350 c = curl_easy_init (); 357 c = curl_easy_init ();
351 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 358 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
352 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 359 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
353 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 360 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
354 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 361 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
355 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 362 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
@@ -367,14 +374,14 @@ testMultithreadedPoolPost ()
367 * crashes on my system! */ 374 * crashes on my system! */
368 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 375 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
369 if (CURLE_OK != (errornum = curl_easy_perform (c))) 376 if (CURLE_OK != (errornum = curl_easy_perform (c)))
370 { 377 {
371 fprintf (stderr, 378 fprintf (stderr,
372 "curl_easy_perform failed: `%s'\n", 379 "curl_easy_perform failed: `%s'\n",
373 curl_easy_strerror (errornum)); 380 curl_easy_strerror (errornum));
374 curl_easy_cleanup (c); 381 curl_easy_cleanup (c);
375 MHD_stop_daemon (d); 382 MHD_stop_daemon (d);
376 return 32; 383 return 32;
377 } 384 }
378 curl_easy_cleanup (c); 385 curl_easy_cleanup (c);
379 MHD_stop_daemon (d); 386 MHD_stop_daemon (d);
380 if (cbc.pos != strlen ("/hello_world")) 387 if (cbc.pos != strlen ("/hello_world"))
@@ -411,11 +418,11 @@ testExternalPost ()
411 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 418 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
412 port = 0; 419 port = 0;
413 else 420 else
414 { 421 {
415 port = 1373; 422 port = 1373;
416 if (oneone) 423 if (oneone)
417 port += 10; 424 port += 10;
418 } 425 }
419 426
420 multi = NULL; 427 multi = NULL;
421 cbc.buf = buf; 428 cbc.buf = buf;
@@ -423,21 +430,23 @@ testExternalPost ()
423 cbc.pos = 0; 430 cbc.pos = 0;
424 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 431 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
425 port, NULL, NULL, &ahc_echo, NULL, 432 port, NULL, NULL, &ahc_echo, NULL,
426 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 433 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
427 MHD_OPTION_END); 434 MHD_OPTION_END);
428 if (d == NULL) 435 if (d == NULL)
429 return 256; 436 return 256;
430 if (0 == port) 437 if (0 == port)
438 {
439 const union MHD_DaemonInfo *dinfo;
440 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
441 if ((NULL == dinfo) ||(0 == dinfo->port) )
431 { 442 {
432 const union MHD_DaemonInfo *dinfo; 443 MHD_stop_daemon (d); return 32;
433 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
434 if (NULL == dinfo || 0 == dinfo->port)
435 { MHD_stop_daemon (d); return 32; }
436 port = (int)dinfo->port;
437 } 444 }
445 port = (int) dinfo->port;
446 }
438 c = curl_easy_init (); 447 c = curl_easy_init ();
439 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 448 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
440 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 449 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
441 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 450 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
442 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 451 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
443 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 452 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
@@ -458,85 +467,88 @@ testExternalPost ()
458 467
459 multi = curl_multi_init (); 468 multi = curl_multi_init ();
460 if (multi == NULL) 469 if (multi == NULL)
470 {
471 curl_easy_cleanup (c);
472 MHD_stop_daemon (d);
473 return 512;
474 }
475 mret = curl_multi_add_handle (multi, c);
476 if (mret != CURLM_OK)
477 {
478 curl_multi_cleanup (multi);
479 curl_easy_cleanup (c);
480 MHD_stop_daemon (d);
481 return 1024;
482 }
483 start = time (NULL);
484 while ((time (NULL) - start < 5) && (multi != NULL))
485 {
486 maxsock = MHD_INVALID_SOCKET;
487 maxposixs = -1;
488 FD_ZERO (&rs);
489 FD_ZERO (&ws);
490 FD_ZERO (&es);
491 curl_multi_perform (multi, &running);
492 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
493 if (mret != CURLM_OK)
461 { 494 {
495 curl_multi_remove_handle (multi, c);
496 curl_multi_cleanup (multi);
462 curl_easy_cleanup (c); 497 curl_easy_cleanup (c);
463 MHD_stop_daemon (d); 498 MHD_stop_daemon (d);
464 return 512; 499 return 2048;
465 } 500 }
466 mret = curl_multi_add_handle (multi, c); 501 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
467 if (mret != CURLM_OK)
468 { 502 {
503 curl_multi_remove_handle (multi, c);
469 curl_multi_cleanup (multi); 504 curl_multi_cleanup (multi);
470 curl_easy_cleanup (c); 505 curl_easy_cleanup (c);
471 MHD_stop_daemon (d); 506 MHD_stop_daemon (d);
472 return 1024; 507 return 4096;
473 } 508 }
474 start = time (NULL); 509 tv.tv_sec = 0;
475 while ((time (NULL) - start < 5) && (multi != NULL)) 510 tv.tv_usec = 1000;
511 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
476 { 512 {
477 maxsock = MHD_INVALID_SOCKET;
478 maxposixs = -1;
479 FD_ZERO (&rs);
480 FD_ZERO (&ws);
481 FD_ZERO (&es);
482 curl_multi_perform (multi, &running);
483 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
484 if (mret != CURLM_OK)
485 {
486 curl_multi_remove_handle (multi, c);
487 curl_multi_cleanup (multi);
488 curl_easy_cleanup (c);
489 MHD_stop_daemon (d);
490 return 2048;
491 }
492 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
493 {
494 curl_multi_remove_handle (multi, c);
495 curl_multi_cleanup (multi);
496 curl_easy_cleanup (c);
497 MHD_stop_daemon (d);
498 return 4096;
499 }
500 tv.tv_sec = 0;
501 tv.tv_usec = 1000;
502 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
503 {
504#ifdef MHD_POSIX_SOCKETS 513#ifdef MHD_POSIX_SOCKETS
505 if (EINTR != errno) 514 if (EINTR != errno)
506 abort (); 515 abort ();
507#else 516#else
508 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 517 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
509 abort (); 518 ws.fd_count)
510 Sleep (1000); 519 ||(0 != es.fd_count) )
520 abort ();
521 Sleep (1000);
511#endif 522#endif
512 }
513 curl_multi_perform (multi, &running);
514 if (running == 0)
515 {
516 msg = curl_multi_info_read (multi, &running);
517 if (msg == NULL)
518 break;
519 if (msg->msg == CURLMSG_DONE)
520 {
521 if (msg->data.result != CURLE_OK)
522 printf ("%s failed at %s:%d: `%s'\n",
523 "curl_multi_perform",
524 __FILE__,
525 __LINE__, curl_easy_strerror (msg->data.result));
526 curl_multi_remove_handle (multi, c);
527 curl_multi_cleanup (multi);
528 curl_easy_cleanup (c);
529 c = NULL;
530 multi = NULL;
531 }
532 } MHD_run (d);
533 } 523 }
534 if (multi != NULL) 524 curl_multi_perform (multi, &running);
525 if (running == 0)
535 { 526 {
536 curl_multi_remove_handle (multi, c); 527 msg = curl_multi_info_read (multi, &running);
537 curl_easy_cleanup (c); 528 if (msg == NULL)
538 curl_multi_cleanup (multi); 529 break;
530 if (msg->msg == CURLMSG_DONE)
531 {
532 if (msg->data.result != CURLE_OK)
533 printf ("%s failed at %s:%d: `%s'\n",
534 "curl_multi_perform",
535 __FILE__,
536 __LINE__, curl_easy_strerror (msg->data.result));
537 curl_multi_remove_handle (multi, c);
538 curl_multi_cleanup (multi);
539 curl_easy_cleanup (c);
540 c = NULL;
541 multi = NULL;
542 }
539 } 543 }
544 MHD_run (d);
545 }
546 if (multi != NULL)
547 {
548 curl_multi_remove_handle (multi, c);
549 curl_easy_cleanup (c);
550 curl_multi_cleanup (multi);
551 }
540 MHD_stop_daemon (d); 552 MHD_stop_daemon (d);
541 if (cbc.pos != strlen ("/hello_world")) 553 if (cbc.pos != strlen ("/hello_world"))
542 return 8192; 554 return 8192;
@@ -548,43 +560,43 @@ testExternalPost ()
548 560
549static int 561static int
550ahc_cancel (void *cls, 562ahc_cancel (void *cls,
551 struct MHD_Connection *connection, 563 struct MHD_Connection *connection,
552 const char *url, 564 const char *url,
553 const char *method, 565 const char *method,
554 const char *version, 566 const char *version,
555 const char *upload_data, size_t *upload_data_size, 567 const char *upload_data, size_t *upload_data_size,
556 void **unused) 568 void **unused)
557{ 569{
558 struct MHD_Response *response; 570 struct MHD_Response *response;
559 int ret; 571 int ret;
560 (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ 572 (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */
561 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 573 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
562 574
563 if (0 != strcasecmp ("POST", method)) 575 if (0 != strcasecmp ("POST", method))
564 { 576 {
565 fprintf (stderr, 577 fprintf (stderr,
566 "Unexpected method `%s'\n", method); 578 "Unexpected method `%s'\n", method);
567 return MHD_NO; 579 return MHD_NO;
568 } 580 }
569 581
570 if (*unused == NULL) 582 if (*unused == NULL)
571 { 583 {
572 *unused = "wibble"; 584 *unused = "wibble";
573 /* We don't want the body. Send a 500. */ 585 /* We don't want the body. Send a 500. */
574 response = MHD_create_response_from_buffer (0, NULL, 586 response = MHD_create_response_from_buffer (0, NULL,
575 MHD_RESPMEM_PERSISTENT); 587 MHD_RESPMEM_PERSISTENT);
576 ret = MHD_queue_response(connection, 500, response); 588 ret = MHD_queue_response (connection, 500, response);
577 if (ret != MHD_YES) 589 if (ret != MHD_YES)
578 fprintf(stderr, "Failed to queue response\n"); 590 fprintf (stderr, "Failed to queue response\n");
579 MHD_destroy_response(response); 591 MHD_destroy_response (response);
580 return ret; 592 return ret;
581 } 593 }
582 else 594 else
583 { 595 {
584 fprintf(stderr, 596 fprintf (stderr,
585 "In ahc_cancel again. This should not happen.\n"); 597 "In ahc_cancel again. This should not happen.\n");
586 return MHD_NO; 598 return MHD_NO;
587 } 599 }
588} 600}
589 601
590struct CRBC 602struct CRBC
@@ -596,7 +608,7 @@ struct CRBC
596 608
597 609
598static size_t 610static size_t
599readBuffer(void *p, size_t size, size_t nmemb, void *opaque) 611readBuffer (void *p, size_t size, size_t nmemb, void *opaque)
600{ 612{
601 struct CRBC *data = opaque; 613 struct CRBC *data = opaque;
602 size_t required = size * nmemb; 614 size_t required = size * nmemb;
@@ -605,18 +617,18 @@ readBuffer(void *p, size_t size, size_t nmemb, void *opaque)
605 if (required > left) 617 if (required > left)
606 required = left; 618 required = left;
607 619
608 memcpy(p, data->buffer + data->pos, required); 620 memcpy (p, data->buffer + data->pos, required);
609 data->pos += required; 621 data->pos += required;
610 622
611 return required/size; 623 return required / size;
612} 624}
613 625
614 626
615static size_t 627static size_t
616slowReadBuffer(void *p, size_t size, size_t nmemb, void *opaque) 628slowReadBuffer (void *p, size_t size, size_t nmemb, void *opaque)
617{ 629{
618 (void)sleep(1); 630 (void) sleep (1);
619 return readBuffer(p, size, nmemb, opaque); 631 return readBuffer (p, size, nmemb, opaque);
620} 632}
621 633
622 634
@@ -628,7 +640,7 @@ slowReadBuffer(void *p, size_t size, size_t nmemb, void *opaque)
628 640
629 641
630static int 642static int
631testMultithreadedPostCancelPart(int flags) 643testMultithreadedPostCancelPart (int flags)
632{ 644{
633 struct MHD_Daemon *d; 645 struct MHD_Daemon *d;
634 CURL *c; 646 CURL *c;
@@ -645,44 +657,48 @@ testMultithreadedPostCancelPart(int flags)
645 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 657 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
646 port = 0; 658 port = 0;
647 else 659 else
648 { 660 {
649 port = 1374; 661 port = 1374;
650 if (oneone) 662 if (oneone)
651 port += 10; 663 port += 10;
652 } 664 }
653 665
654 /* Don't test features that aren't available with HTTP/1.0 in 666 /* Don't test features that aren't available with HTTP/1.0 in
655 * HTTP/1.0 mode. */ 667 * HTTP/1.0 mode. */
656 if (!oneone && (flags & (FLAG_EXPECT_CONTINUE | FLAG_CHUNKED))) 668 if (! oneone && (flags & (FLAG_EXPECT_CONTINUE | FLAG_CHUNKED)))
657 return 0; 669 return 0;
658 670
659 cbc.buf = buf; 671 cbc.buf = buf;
660 cbc.size = 2048; 672 cbc.size = 2048;
661 cbc.pos = 0; 673 cbc.pos = 0;
662 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 674 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
675 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
663 port, NULL, NULL, &ahc_cancel, NULL, 676 port, NULL, NULL, &ahc_cancel, NULL,
664 MHD_OPTION_END); 677 MHD_OPTION_END);
665 if (d == NULL) 678 if (d == NULL)
666 return 32768; 679 return 32768;
667 if (0 == port) 680 if (0 == port)
681 {
682 const union MHD_DaemonInfo *dinfo;
683 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
684 if ((NULL == dinfo) ||(0 == dinfo->port) )
668 { 685 {
669 const union MHD_DaemonInfo *dinfo; 686 MHD_stop_daemon (d); return 32;
670 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
671 if (NULL == dinfo || 0 == dinfo->port)
672 { MHD_stop_daemon (d); return 32; }
673 port = (int)dinfo->port;
674 } 687 }
688 port = (int) dinfo->port;
689 }
675 690
676 crbc.buffer = "Test content"; 691 crbc.buffer = "Test content";
677 crbc.size = strlen(crbc.buffer); 692 crbc.size = strlen (crbc.buffer);
678 crbc.pos = 0; 693 crbc.pos = 0;
679 694
680 c = curl_easy_init (); 695 c = curl_easy_init ();
681 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 696 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
682 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 697 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
683 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 698 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
684 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 699 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
685 curl_easy_setopt (c, CURLOPT_READFUNCTION, (flags & FLAG_SLOW_READ) ? &slowReadBuffer : &readBuffer); 700 curl_easy_setopt (c, CURLOPT_READFUNCTION, (flags & FLAG_SLOW_READ) ?
701 &slowReadBuffer : &readBuffer);
686 curl_easy_setopt (c, CURLOPT_READDATA, &crbc); 702 curl_easy_setopt (c, CURLOPT_READDATA, &crbc);
687 curl_easy_setopt (c, CURLOPT_POSTFIELDS, NULL); 703 curl_easy_setopt (c, CURLOPT_POSTFIELDS, NULL);
688 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, crbc.size); 704 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, crbc.size);
@@ -700,68 +716,72 @@ testMultithreadedPostCancelPart(int flags)
700 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 716 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
701 717
702 if (flags & FLAG_CHUNKED) 718 if (flags & FLAG_CHUNKED)
703 headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); 719 headers = curl_slist_append (headers, "Transfer-Encoding: chunked");
704 if (!(flags & FLAG_FORM_DATA)) 720 if (! (flags & FLAG_FORM_DATA))
705 headers = curl_slist_append(headers, "Content-Type: application/octet-stream"); 721 headers = curl_slist_append (headers,
722 "Content-Type: application/octet-stream");
706 if (flags & FLAG_EXPECT_CONTINUE) 723 if (flags & FLAG_EXPECT_CONTINUE)
707 headers = curl_slist_append(headers, "Expect: 100-Continue"); 724 headers = curl_slist_append (headers, "Expect: 100-Continue");
708 curl_easy_setopt(c, CURLOPT_HTTPHEADER, headers); 725 curl_easy_setopt (c, CURLOPT_HTTPHEADER, headers);
709 726
710 if (CURLE_HTTP_RETURNED_ERROR != (errornum = curl_easy_perform (c))) 727 if (CURLE_HTTP_RETURNED_ERROR != (errornum = curl_easy_perform (c)))
711 { 728 {
712#ifdef _WIN32 729#ifdef _WIN32
713 curl_version_info_data *curlverd = curl_version_info(CURLVERSION_NOW); 730 curl_version_info_data *curlverd = curl_version_info (CURLVERSION_NOW);
714 if (0 != (flags & FLAG_SLOW_READ) && CURLE_RECV_ERROR == errornum && 731 if ((0 != (flags & FLAG_SLOW_READ)) &&(CURLE_RECV_ERROR == errornum) &&
715 (curlverd == NULL || curlverd->ares_num < 0x073100) ) 732 ((curlverd == NULL) ||(curlverd->ares_num < 0x073100) ) )
716 { /* libcurl up to version 7.49.0 didn't have workaround for WinSock bug */ 733 { /* libcurl up to version 7.49.0 didn't have workaround for WinSock bug */
717 fprintf (stderr, "Ignored curl_easy_perform expected failure on W32 with \"slow read\".\n"); 734 fprintf (stderr,
718 result = 0; 735 "Ignored curl_easy_perform expected failure on W32 with \"slow read\".\n");
719 } 736 result = 0;
720 else 737 }
738 else
721#else /* ! _WIN32 */ 739#else /* ! _WIN32 */
722 if(1) 740 if (1)
723#endif /* ! _WIN32 */ 741#endif /* ! _WIN32 */
724 {
725 fprintf (stderr,
726 "flibbet curl_easy_perform didn't fail as expected: `%s' %d\n",
727 curl_easy_strerror (errornum), errornum);
728 result = 65536;
729 }
730 curl_easy_cleanup (c);
731 MHD_stop_daemon (d);
732 curl_slist_free_all(headers);
733 return result;
734 }
735
736 if (CURLE_OK != (cc = curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &response_code)))
737 { 742 {
738 fprintf(stderr, "curl_easy_getinfo failed: '%s'\n", curl_easy_strerror(errornum)); 743 fprintf (stderr,
744 "flibbet curl_easy_perform didn't fail as expected: `%s' %d\n",
745 curl_easy_strerror (errornum), errornum);
739 result = 65536; 746 result = 65536;
740 } 747 }
741 748 curl_easy_cleanup (c);
742 if (!result && (response_code != 500)) 749 MHD_stop_daemon (d);
743 { 750 curl_slist_free_all (headers);
744 fprintf(stderr, "Unexpected response code: %ld\n", response_code); 751 return result;
745 result = 131072; 752 }
746 } 753
747 754 if (CURLE_OK != (cc = curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE,
748 if (!result && (cbc.pos != 0)) 755 &response_code)))
756 {
757 fprintf (stderr, "curl_easy_getinfo failed: '%s'\n", curl_easy_strerror (
758 errornum));
759 result = 65536;
760 }
761
762 if (! result && (response_code != 500))
763 {
764 fprintf (stderr, "Unexpected response code: %ld\n", response_code);
765 result = 131072;
766 }
767
768 if (! result && (cbc.pos != 0))
749 result = 262144; 769 result = 262144;
750 770
751 curl_easy_cleanup (c); 771 curl_easy_cleanup (c);
752 MHD_stop_daemon (d); 772 MHD_stop_daemon (d);
753 curl_slist_free_all(headers); 773 curl_slist_free_all (headers);
754 return result; 774 return result;
755} 775}
756 776
757 777
758static int 778static int
759testMultithreadedPostCancel() 779testMultithreadedPostCancel ()
760{ 780{
761 int result = 0; 781 int result = 0;
762 int flags; 782 int flags;
763 for(flags = 0; flags < FLAG_COUNT; ++flags) 783 for (flags = 0; flags < FLAG_COUNT; ++flags)
764 result |= testMultithreadedPostCancelPart(flags); 784 result |= testMultithreadedPostCancelPart (flags);
765 return result; 785 return result;
766} 786}
767 787
@@ -770,20 +790,20 @@ int
770main (int argc, char *const *argv) 790main (int argc, char *const *argv)
771{ 791{
772 unsigned int errorCount = 0; 792 unsigned int errorCount = 0;
773 (void)argc; /* Unused. Silent compiler warning. */ 793 (void) argc; /* Unused. Silent compiler warning. */
774 794
775 if (NULL == argv || 0 == argv[0]) 795 if ((NULL == argv)||(0 == argv[0]))
776 return 99; 796 return 99;
777 oneone = has_in_name (argv[0], "11"); 797 oneone = has_in_name (argv[0], "11");
778 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 798 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
779 return 2; 799 return 2;
780 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 800 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
781 { 801 {
782 errorCount += testMultithreadedPostCancel (); 802 errorCount += testMultithreadedPostCancel ();
783 errorCount += testInternalPost (); 803 errorCount += testInternalPost ();
784 errorCount += testMultithreadedPost (); 804 errorCount += testMultithreadedPost ();
785 errorCount += testMultithreadedPoolPost (); 805 errorCount += testMultithreadedPoolPost ();
786 } 806 }
787 errorCount += testExternalPost (); 807 errorCount += testExternalPost ();
788 if (errorCount != 0) 808 if (errorCount != 0)
789 fprintf (stderr, "Error (code: %u)\n", errorCount); 809 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c
index 6da54a95..558228a2 100644
--- a/src/testcurl/test_post_loop.c
+++ b/src/testcurl/test_post_loop.c
@@ -38,14 +38,15 @@
38#include <unistd.h> 38#include <unistd.h>
39#endif 39#endif
40 40
41#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 41#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
42#undef CPU_COUNT 42#undef CPU_COUNT
43#endif 43#endif
44#if !defined(CPU_COUNT) 44#if ! defined(CPU_COUNT)
45#define CPU_COUNT 2 45#define CPU_COUNT 2
46#endif 46#endif
47 47
48#define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" 48#define POST_DATA \
49 "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n"
49 50
50#define LOOPCOUNT 1000 51#define LOOPCOUNT 1000
51 52
@@ -82,25 +83,25 @@ ahc_echo (void *cls,
82 static int marker; 83 static int marker;
83 struct MHD_Response *response; 84 struct MHD_Response *response;
84 int ret; 85 int ret;
85 (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ 86 (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */
86 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 87 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
87 88
88 if (0 != strcmp ("POST", method)) 89 if (0 != strcmp ("POST", method))
89 { 90 {
90 printf ("METHOD: %s\n", method); 91 printf ("METHOD: %s\n", method);
91 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
92 } 93 }
93 if ((*mptr != NULL) && (0 == *upload_data_size)) 94 if ((*mptr != NULL) && (0 == *upload_data_size))
94 { 95 {
95 if (*mptr != &marker) 96 if (*mptr != &marker)
96 abort (); 97 abort ();
97 response = MHD_create_response_from_buffer (2, "OK", 98 response = MHD_create_response_from_buffer (2, "OK",
98 MHD_RESPMEM_PERSISTENT); 99 MHD_RESPMEM_PERSISTENT);
99 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 100 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
100 MHD_destroy_response (response); 101 MHD_destroy_response (response);
101 *mptr = NULL; 102 *mptr = NULL;
102 return ret; 103 return ret;
103 } 104 }
104 if (strlen (POST_DATA) != *upload_data_size) 105 if (strlen (POST_DATA) != *upload_data_size)
105 return MHD_YES; 106 return MHD_YES;
106 *upload_data_size = 0; 107 *upload_data_size = 0;
@@ -124,11 +125,11 @@ testInternalPost ()
124 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 125 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
125 port = 0; 126 port = 0;
126 else 127 else
127 { 128 {
128 port = 1350; 129 port = 1350;
129 if (oneone) 130 if (oneone)
130 port += 10; 131 port += 10;
131 } 132 }
132 133
133 cbc.buf = buf; 134 cbc.buf = buf;
134 cbc.size = 2048; 135 cbc.size = 2048;
@@ -137,58 +138,60 @@ testInternalPost ()
137 if (d == NULL) 138 if (d == NULL)
138 return 1; 139 return 1;
139 if (0 == port) 140 if (0 == port)
141 {
142 const union MHD_DaemonInfo *dinfo;
143 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
144 if ((NULL == dinfo) ||(0 == dinfo->port) )
140 { 145 {
141 const union MHD_DaemonInfo *dinfo; 146 MHD_stop_daemon (d); return 32;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if (NULL == dinfo || 0 == dinfo->port)
144 { MHD_stop_daemon (d); return 32; }
145 port = (int)dinfo->port;
146 } 147 }
148 port = (int) dinfo->port;
149 }
147 for (i = 0; i < LOOPCOUNT; i++) 150 for (i = 0; i < LOOPCOUNT; i++)
151 {
152 if (99 == i % 100)
153 fprintf (stderr, ".");
154 c = curl_easy_init ();
155 cbc.pos = 0;
156 buf[0] = '\0';
157 snprintf (url,
158 sizeof (url),
159 "http://127.0.0.1:%d/hw%d",
160 port,
161 i);
162 curl_easy_setopt (c, CURLOPT_URL, url);
163 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
164 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
165 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
166 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
167 curl_easy_setopt (c, CURLOPT_POST, 1L);
168 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
169 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
170 if (oneone)
171 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
172 else
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
174 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
175 /* NOTE: use of CONNECTTIMEOUT without also
176 * setting NOSIGNAL results in really weird
177 * crashes on my system! */
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
179 if (CURLE_OK != (errornum = curl_easy_perform (c)))
148 { 180 {
149 if (99 == i % 100) 181 fprintf (stderr,
150 fprintf (stderr, "."); 182 "curl_easy_perform failed: `%s'\n",
151 c = curl_easy_init (); 183 curl_easy_strerror (errornum));
152 cbc.pos = 0;
153 buf[0] = '\0';
154 snprintf (url,
155 sizeof (url),
156 "http://127.0.0.1:%d/hw%d",
157 port,
158 i);
159 curl_easy_setopt (c, CURLOPT_URL, url);
160 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
161 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
162 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
163 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
164 curl_easy_setopt (c, CURLOPT_POST, 1L);
165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
166 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
167 if (oneone)
168 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
169 else
170 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
171 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
172 /* NOTE: use of CONNECTTIMEOUT without also
173 * setting NOSIGNAL results in really weird
174 * crashes on my system! */
175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
176 if (CURLE_OK != (errornum = curl_easy_perform (c)))
177 {
178 fprintf (stderr,
179 "curl_easy_perform failed: `%s'\n",
180 curl_easy_strerror (errornum));
181 curl_easy_cleanup (c);
182 MHD_stop_daemon (d);
183 return 2;
184 }
185 curl_easy_cleanup (c); 184 curl_easy_cleanup (c);
186 if ((buf[0] != 'O') || (buf[1] != 'K')) 185 MHD_stop_daemon (d);
187 { 186 return 2;
188 MHD_stop_daemon (d); 187 }
189 return 4; 188 curl_easy_cleanup (c);
190 } 189 if ((buf[0] != 'O') || (buf[1] != 'K'))
190 {
191 MHD_stop_daemon (d);
192 return 4;
191 } 193 }
194 }
192 MHD_stop_daemon (d); 195 MHD_stop_daemon (d);
193 if (LOOPCOUNT >= 99) 196 if (LOOPCOUNT >= 99)
194 fprintf (stderr, "\n"); 197 fprintf (stderr, "\n");
@@ -210,73 +213,76 @@ testMultithreadedPost ()
210 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 213 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
211 port = 0; 214 port = 0;
212 else 215 else
213 { 216 {
214 port = 1351; 217 port = 1351;
215 if (oneone) 218 if (oneone)
216 port += 10; 219 port += 10;
217 } 220 }
218 221
219 cbc.buf = buf; 222 cbc.buf = buf;
220 cbc.size = 2048; 223 cbc.size = 2048;
221 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 224 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
225 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
222 port, NULL, NULL, 226 port, NULL, NULL,
223 &ahc_echo, NULL, 227 &ahc_echo, NULL,
224 MHD_OPTION_END); 228 MHD_OPTION_END);
225 if (d == NULL) 229 if (d == NULL)
226 return 16; 230 return 16;
227 if (0 == port) 231 if (0 == port)
232 {
233 const union MHD_DaemonInfo *dinfo;
234 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
235 if ((NULL == dinfo) ||(0 == dinfo->port) )
228 { 236 {
229 const union MHD_DaemonInfo *dinfo; 237 MHD_stop_daemon (d); return 32;
230 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
231 if (NULL == dinfo || 0 == dinfo->port)
232 { MHD_stop_daemon (d); return 32; }
233 port = (int)dinfo->port;
234 } 238 }
239 port = (int) dinfo->port;
240 }
235 for (i = 0; i < LOOPCOUNT; i++) 241 for (i = 0; i < LOOPCOUNT; i++)
242 {
243 if (99 == i % 100)
244 fprintf (stderr, ".");
245 c = curl_easy_init ();
246 cbc.pos = 0;
247 buf[0] = '\0';
248 snprintf (url,
249 sizeof (url),
250 "http://127.0.0.1:%d/hw%d",
251 port,
252 i);
253 curl_easy_setopt (c, CURLOPT_URL, url);
254 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
255 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
256 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
257 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
258 curl_easy_setopt (c, CURLOPT_POST, 1L);
259 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
260 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
261 if (oneone)
262 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
263 else
264 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
265 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
266 /* NOTE: use of CONNECTTIMEOUT without also
267 * setting NOSIGNAL results in really weird
268 * crashes on my system! */
269 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
270 if (CURLE_OK != (errornum = curl_easy_perform (c)))
236 { 271 {
237 if (99 == i % 100) 272 fprintf (stderr,
238 fprintf (stderr, "."); 273 "curl_easy_perform failed: `%s'\n",
239 c = curl_easy_init (); 274 curl_easy_strerror (errornum));
240 cbc.pos = 0;
241 buf[0] = '\0';
242 snprintf (url,
243 sizeof (url),
244 "http://127.0.0.1:%d/hw%d",
245 port,
246 i);
247 curl_easy_setopt (c, CURLOPT_URL, url);
248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
250 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
251 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
252 curl_easy_setopt (c, CURLOPT_POST, 1L);
253 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
254 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
255 if (oneone)
256 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
257 else
258 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
259 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
260 /* NOTE: use of CONNECTTIMEOUT without also
261 * setting NOSIGNAL results in really weird
262 * crashes on my system! */
263 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
264 if (CURLE_OK != (errornum = curl_easy_perform (c)))
265 {
266 fprintf (stderr,
267 "curl_easy_perform failed: `%s'\n",
268 curl_easy_strerror (errornum));
269 curl_easy_cleanup (c);
270 MHD_stop_daemon (d);
271 return 32;
272 }
273 curl_easy_cleanup (c); 275 curl_easy_cleanup (c);
274 if ((buf[0] != 'O') || (buf[1] != 'K')) 276 MHD_stop_daemon (d);
275 { 277 return 32;
276 MHD_stop_daemon (d); 278 }
277 return 64; 279 curl_easy_cleanup (c);
278 } 280 if ((buf[0] != 'O') || (buf[1] != 'K'))
281 {
282 MHD_stop_daemon (d);
283 return 64;
279 } 284 }
285 }
280 MHD_stop_daemon (d); 286 MHD_stop_daemon (d);
281 if (LOOPCOUNT >= 99) 287 if (LOOPCOUNT >= 99)
282 fprintf (stderr, "\n"); 288 fprintf (stderr, "\n");
@@ -298,11 +304,11 @@ testMultithreadedPoolPost ()
298 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 304 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
299 port = 0; 305 port = 0;
300 else 306 else
301 { 307 {
302 port = 1352; 308 port = 1352;
303 if (oneone) 309 if (oneone)
304 port += 10; 310 port += 10;
305 } 311 }
306 312
307 cbc.buf = buf; 313 cbc.buf = buf;
308 cbc.size = 2048; 314 cbc.size = 2048;
@@ -312,58 +318,60 @@ testMultithreadedPoolPost ()
312 if (d == NULL) 318 if (d == NULL)
313 return 16; 319 return 16;
314 if (0 == port) 320 if (0 == port)
321 {
322 const union MHD_DaemonInfo *dinfo;
323 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
324 if ((NULL == dinfo) ||(0 == dinfo->port) )
315 { 325 {
316 const union MHD_DaemonInfo *dinfo; 326 MHD_stop_daemon (d); return 32;
317 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
318 if (NULL == dinfo || 0 == dinfo->port)
319 { MHD_stop_daemon (d); return 32; }
320 port = (int)dinfo->port;
321 } 327 }
328 port = (int) dinfo->port;
329 }
322 for (i = 0; i < LOOPCOUNT; i++) 330 for (i = 0; i < LOOPCOUNT; i++)
331 {
332 if (99 == i % 100)
333 fprintf (stderr, ".");
334 c = curl_easy_init ();
335 cbc.pos = 0;
336 buf[0] = '\0';
337 snprintf (url,
338 sizeof (url),
339 "http://127.0.0.1:%d/hw%d",
340 port,
341 i);
342 curl_easy_setopt (c, CURLOPT_URL, url);
343 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
344 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
345 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
346 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
347 curl_easy_setopt (c, CURLOPT_POST, 1L);
348 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
349 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
350 if (oneone)
351 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
352 else
353 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
354 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
355 /* NOTE: use of CONNECTTIMEOUT without also
356 * setting NOSIGNAL results in really weird
357 * crashes on my system! */
358 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
359 if (CURLE_OK != (errornum = curl_easy_perform (c)))
323 { 360 {
324 if (99 == i % 100) 361 fprintf (stderr,
325 fprintf (stderr, "."); 362 "curl_easy_perform failed: `%s'\n",
326 c = curl_easy_init (); 363 curl_easy_strerror (errornum));
327 cbc.pos = 0;
328 buf[0] = '\0';
329 snprintf (url,
330 sizeof (url),
331 "http://127.0.0.1:%d/hw%d",
332 port,
333 i);
334 curl_easy_setopt (c, CURLOPT_URL, url);
335 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
336 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
337 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
338 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
339 curl_easy_setopt (c, CURLOPT_POST, 1L);
340 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
341 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
342 if (oneone)
343 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
344 else
345 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
346 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
347 /* NOTE: use of CONNECTTIMEOUT without also
348 * setting NOSIGNAL results in really weird
349 * crashes on my system! */
350 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
351 if (CURLE_OK != (errornum = curl_easy_perform (c)))
352 {
353 fprintf (stderr,
354 "curl_easy_perform failed: `%s'\n",
355 curl_easy_strerror (errornum));
356 curl_easy_cleanup (c);
357 MHD_stop_daemon (d);
358 return 32;
359 }
360 curl_easy_cleanup (c); 364 curl_easy_cleanup (c);
361 if ((buf[0] != 'O') || (buf[1] != 'K')) 365 MHD_stop_daemon (d);
362 { 366 return 32;
363 MHD_stop_daemon (d); 367 }
364 return 64; 368 curl_easy_cleanup (c);
365 } 369 if ((buf[0] != 'O') || (buf[1] != 'K'))
370 {
371 MHD_stop_daemon (d);
372 return 64;
366 } 373 }
374 }
367 MHD_stop_daemon (d); 375 MHD_stop_daemon (d);
368 if (LOOPCOUNT >= 99) 376 if (LOOPCOUNT >= 99)
369 fprintf (stderr, "\n"); 377 fprintf (stderr, "\n");
@@ -401,11 +409,11 @@ testExternalPost ()
401 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 409 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
402 port = 0; 410 port = 0;
403 else 411 else
404 { 412 {
405 port = 1353; 413 port = 1353;
406 if (oneone) 414 if (oneone)
407 port += 10; 415 port += 10;
408 } 416 }
409 417
410 multi = NULL; 418 multi = NULL;
411 cbc.buf = buf; 419 cbc.buf = buf;
@@ -416,134 +424,138 @@ testExternalPost ()
416 if (d == NULL) 424 if (d == NULL)
417 return 256; 425 return 256;
418 if (0 == port) 426 if (0 == port)
427 {
428 const union MHD_DaemonInfo *dinfo;
429 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
430 if ((NULL == dinfo) ||(0 == dinfo->port) )
419 { 431 {
420 const union MHD_DaemonInfo *dinfo; 432 MHD_stop_daemon (d); return 32;
421 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
422 if (NULL == dinfo || 0 == dinfo->port)
423 { MHD_stop_daemon (d); return 32; }
424 port = (int)dinfo->port;
425 } 433 }
434 port = (int) dinfo->port;
435 }
426 multi = curl_multi_init (); 436 multi = curl_multi_init ();
427 if (multi == NULL) 437 if (multi == NULL)
438 {
439 MHD_stop_daemon (d);
440 return 512;
441 }
442 for (i = 0; i < LOOPCOUNT; i++)
443 {
444 if (99 == i % 100)
445 fprintf (stderr, ".");
446 c = curl_easy_init ();
447 cbc.pos = 0;
448 buf[0] = '\0';
449 snprintf (url,
450 sizeof (url),
451 "http://127.0.0.1:%d/hw%d",
452 port,
453 i);
454 curl_easy_setopt (c, CURLOPT_URL, url);
455 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
456 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
457 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
458 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
459 curl_easy_setopt (c, CURLOPT_POST, 1L);
460 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
461 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
462 if (oneone)
463 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
464 else
465 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
466 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
467 /* NOTE: use of CONNECTTIMEOUT without also
468 * setting NOSIGNAL results in really weird
469 * crashes on my system! */
470 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
471 mret = curl_multi_add_handle (multi, c);
472 if (mret != CURLM_OK)
428 { 473 {
474 curl_multi_cleanup (multi);
475 curl_easy_cleanup (c);
429 MHD_stop_daemon (d); 476 MHD_stop_daemon (d);
430 return 512; 477 return 1024;
431 } 478 }
432 for (i = 0; i < LOOPCOUNT; i++) 479 start = time (NULL);
480 while ((time (NULL) - start < 5) && (multi != NULL))
433 { 481 {
434 if (99 == i % 100) 482 maxsock = MHD_INVALID_SOCKET;
435 fprintf (stderr, "."); 483 maxposixs = -1;
436 c = curl_easy_init (); 484 FD_ZERO (&rs);
437 cbc.pos = 0; 485 FD_ZERO (&ws);
438 buf[0] = '\0'; 486 FD_ZERO (&es);
439 snprintf (url, 487 while (CURLM_CALL_MULTI_PERFORM ==
440 sizeof (url), 488 curl_multi_perform (multi, &running))
441 "http://127.0.0.1:%d/hw%d", 489 ;
442 port, 490 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
443 i);
444 curl_easy_setopt (c, CURLOPT_URL, url);
445 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
446 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
447 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
448 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
449 curl_easy_setopt (c, CURLOPT_POST, 1L);
450 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
451 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
452 if (oneone)
453 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
454 else
455 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
456 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
457 /* NOTE: use of CONNECTTIMEOUT without also
458 * setting NOSIGNAL results in really weird
459 * crashes on my system! */
460 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
461 mret = curl_multi_add_handle (multi, c);
462 if (mret != CURLM_OK) 491 if (mret != CURLM_OK)
492 {
493 curl_multi_remove_handle (multi, c);
494 curl_multi_cleanup (multi);
495 curl_easy_cleanup (c);
496 MHD_stop_daemon (d);
497 return 2048;
498 }
499 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
500 {
501 curl_multi_remove_handle (multi, c);
502 curl_multi_cleanup (multi);
503 curl_easy_cleanup (c);
504 MHD_stop_daemon (d);
505 return 4096;
506 }
507 if (MHD_NO == MHD_get_timeout (d, &timeout))
508 timeout = 100; /* 100ms == INFTY -- CURL bug... */
509 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
510 (ctimeout < (long long) timeout) && (ctimeout >= 0))
511 timeout = ctimeout;
512 if ( (c == NULL) || (running == 0) )
513 timeout = 0; /* terminate quickly... */
514 tv.tv_sec = timeout / 1000;
515 tv.tv_usec = (timeout % 1000) * 1000;
516 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
517 {
518 if (EINTR == errno)
519 continue;
520 fprintf (stderr,
521 "select failed: %s\n",
522 strerror (errno));
523 break;
524 }
525 while (CURLM_CALL_MULTI_PERFORM ==
526 curl_multi_perform (multi, &running))
527 ;
528 if (running == 0)
529 {
530 msg = curl_multi_info_read (multi, &running);
531 if (msg == NULL)
532 break;
533 if (msg->msg == CURLMSG_DONE)
463 { 534 {
464 curl_multi_cleanup (multi); 535 if (msg->data.result != CURLE_OK)
465 curl_easy_cleanup (c); 536 printf ("%s failed at %s:%d: `%s'\n",
466 MHD_stop_daemon (d); 537 "curl_multi_perform",
467 return 1024; 538 __FILE__,
468 } 539 __LINE__, curl_easy_strerror (msg->data.result));
469 start = time (NULL);
470 while ((time (NULL) - start < 5) && (multi != NULL))
471 {
472 maxsock = MHD_INVALID_SOCKET;
473 maxposixs = -1;
474 FD_ZERO (&rs);
475 FD_ZERO (&ws);
476 FD_ZERO (&es);
477 while (CURLM_CALL_MULTI_PERFORM ==
478 curl_multi_perform (multi, &running));
479 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
480 if (mret != CURLM_OK)
481 {
482 curl_multi_remove_handle (multi, c);
483 curl_multi_cleanup (multi);
484 curl_easy_cleanup (c);
485 MHD_stop_daemon (d);
486 return 2048;
487 }
488 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
489 {
490 curl_multi_remove_handle (multi, c);
491 curl_multi_cleanup (multi);
492 curl_easy_cleanup (c);
493 MHD_stop_daemon (d);
494 return 4096;
495 }
496 if (MHD_NO == MHD_get_timeout (d, &timeout))
497 timeout = 100; /* 100ms == INFTY -- CURL bug... */
498 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
499 (ctimeout < (long long)timeout) && (ctimeout >= 0))
500 timeout = ctimeout;
501 if ( (c == NULL) || (running == 0) )
502 timeout = 0; /* terminate quickly... */
503 tv.tv_sec = timeout / 1000;
504 tv.tv_usec = (timeout % 1000) * 1000;
505 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
506 {
507 if (EINTR == errno)
508 continue;
509 fprintf (stderr,
510 "select failed: %s\n",
511 strerror (errno));
512 break;
513 }
514 while (CURLM_CALL_MULTI_PERFORM ==
515 curl_multi_perform (multi, &running));
516 if (running == 0)
517 {
518 msg = curl_multi_info_read (multi, &running);
519 if (msg == NULL)
520 break;
521 if (msg->msg == CURLMSG_DONE)
522 {
523 if (msg->data.result != CURLE_OK)
524 printf ("%s failed at %s:%d: `%s'\n",
525 "curl_multi_perform",
526 __FILE__,
527 __LINE__, curl_easy_strerror (msg->data.result));
528 curl_multi_remove_handle (multi, c);
529 curl_easy_cleanup (c);
530 c = NULL;
531 }
532 }
533 MHD_run (d);
534 }
535 if (c != NULL)
536 {
537 curl_multi_remove_handle (multi, c); 540 curl_multi_remove_handle (multi, c);
538 curl_easy_cleanup (c); 541 curl_easy_cleanup (c);
542 c = NULL;
539 } 543 }
540 if ((buf[0] != 'O') || (buf[1] != 'K')) 544 }
541 { 545 MHD_run (d);
542 curl_multi_cleanup (multi);
543 MHD_stop_daemon (d);
544 return 8192;
545 }
546 } 546 }
547 if (c != NULL)
548 {
549 curl_multi_remove_handle (multi, c);
550 curl_easy_cleanup (c);
551 }
552 if ((buf[0] != 'O') || (buf[1] != 'K'))
553 {
554 curl_multi_cleanup (multi);
555 MHD_stop_daemon (d);
556 return 8192;
557 }
558 }
547 curl_multi_cleanup (multi); 559 curl_multi_cleanup (multi);
548 MHD_stop_daemon (d); 560 MHD_stop_daemon (d);
549 if (LOOPCOUNT >= 99) 561 if (LOOPCOUNT >= 99)
@@ -569,8 +581,8 @@ now ()
569 struct timeval tv; 581 struct timeval tv;
570 582
571 gettimeofday (&tv, NULL); 583 gettimeofday (&tv, NULL);
572 return (((unsigned long long) tv.tv_sec * 1000LL) + 584 return (((unsigned long long) tv.tv_sec * 1000LL)
573 ((unsigned long long) tv.tv_usec / 1000LL)); 585 + ((unsigned long long) tv.tv_usec / 1000LL));
574} 586}
575 587
576 588
@@ -578,56 +590,64 @@ int
578main (int argc, char *const *argv) 590main (int argc, char *const *argv)
579{ 591{
580 unsigned int errorCount = 0; 592 unsigned int errorCount = 0;
581 (void)argc; /* Unused. Silent compiler warning. */ 593 (void) argc; /* Unused. Silent compiler warning. */
582 594
583 if (NULL == argv || 0 == argv[0]) 595 if ((NULL == argv)||(0 == argv[0]))
584 return 99; 596 return 99;
585 oneone = has_in_name (argv[0], "11"); 597 oneone = has_in_name (argv[0], "11");
586 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 598 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
587 return 2; 599 return 2;
588 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 600 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
589 { 601 {
590 start_time = now(); 602 start_time = now ();
591 errorCount += testInternalPost (); 603 errorCount += testInternalPost ();
592 fprintf (stderr, 604 fprintf (stderr,
593 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 605 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
594 "internal select", 606 "%s: Sequential POSTs (http/1.0) %f/s\n",
595 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 607 "internal select",
596 GAUGER ("internal select", 608 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
597 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 609 GAUGER ("internal select",
598 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 610 oneone ? "Sequential POSTs (http/1.1)" :
599 "requests/s"); 611 "Sequential POSTs (http/1.0)",
600 start_time = now(); 612 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
601 errorCount += testMultithreadedPost (); 613 "requests/s");
602 fprintf (stderr, 614 start_time = now ();
603 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 615 errorCount += testMultithreadedPost ();
604 "multithreaded post", 616 fprintf (stderr,
605 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 617 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
606 GAUGER ("Multithreaded select", 618 "%s: Sequential POSTs (http/1.0) %f/s\n",
607 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 619 "multithreaded post",
608 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 620 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
609 "requests/s"); 621 GAUGER ("Multithreaded select",
610 start_time = now(); 622 oneone ? "Sequential POSTs (http/1.1)" :
611 errorCount += testMultithreadedPoolPost (); 623 "Sequential POSTs (http/1.0)",
612 fprintf (stderr, 624 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
613 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 625 "requests/s");
614 "thread with pool", 626 start_time = now ();
615 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 627 errorCount += testMultithreadedPoolPost ();
616 GAUGER ("thread with pool", 628 fprintf (stderr,
617 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 629 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
618 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 630 "%s: Sequential POSTs (http/1.0) %f/s\n",
619 "requests/s"); 631 "thread with pool",
620 } 632 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
621 start_time = now(); 633 GAUGER ("thread with pool",
634 oneone ? "Sequential POSTs (http/1.1)" :
635 "Sequential POSTs (http/1.0)",
636 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
637 "requests/s");
638 }
639 start_time = now ();
622 errorCount += testExternalPost (); 640 errorCount += testExternalPost ();
623 fprintf (stderr, 641 fprintf (stderr,
624 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 642 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
625 "external select", 643 "%s: Sequential POSTs (http/1.0) %f/s\n",
626 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 644 "external select",
645 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
627 GAUGER ("external select", 646 GAUGER ("external select",
628 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 647 oneone ? "Sequential POSTs (http/1.1)" :
629 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 648 "Sequential POSTs (http/1.0)",
630 "requests/s"); 649 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
650 "requests/s");
631 if (errorCount != 0) 651 if (errorCount != 0)
632 fprintf (stderr, "Error (code: %u)\n", errorCount); 652 fprintf (stderr, "Error (code: %u)\n", errorCount);
633 curl_global_cleanup (); 653 curl_global_cleanup ();
diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c
index 723bde0f..c4fbd5d5 100644
--- a/src/testcurl/test_postform.c
+++ b/src/testcurl/test_postform.c
@@ -43,10 +43,10 @@
43 43
44#include "mhd_has_in_name.h" 44#include "mhd_has_in_name.h"
45 45
46#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 46#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
47#undef CPU_COUNT 47#undef CPU_COUNT
48#endif 48#endif
49#if !defined(CPU_COUNT) 49#if ! defined(CPU_COUNT)
50#define CPU_COUNT 2 50#define CPU_COUNT 2
51#endif 51#endif
52 52
@@ -62,12 +62,12 @@ struct CBC
62 62
63static void 63static void
64completed_cb (void *cls, 64completed_cb (void *cls,
65 struct MHD_Connection *connection, 65 struct MHD_Connection *connection,
66 void **con_cls, 66 void **con_cls,
67 enum MHD_RequestTerminationCode toe) 67 enum MHD_RequestTerminationCode toe)
68{ 68{
69 struct MHD_PostProcessor *pp = *con_cls; 69 struct MHD_PostProcessor *pp = *con_cls;
70 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 70 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
71 71
72 if (NULL != pp) 72 if (NULL != pp)
73 MHD_destroy_post_processor (pp); 73 MHD_destroy_post_processor (pp);
@@ -103,8 +103,8 @@ post_iterator (void *cls,
103 const char *value, uint64_t off, size_t size) 103 const char *value, uint64_t off, size_t size)
104{ 104{
105 int *eok = cls; 105 int *eok = cls;
106 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 106 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
107 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 107 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
108 108
109#if 0 109#if 0
110 fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); 110 fprintf (stderr, "PI sees %s-%.*s\n", key, size, value);
@@ -132,34 +132,34 @@ ahc_echo (void *cls,
132 struct MHD_Response *response; 132 struct MHD_Response *response;
133 struct MHD_PostProcessor *pp; 133 struct MHD_PostProcessor *pp;
134 int ret; 134 int ret;
135 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 135 (void) cls; (void) version; /* Unused. Silent compiler warning. */
136 136
137 if (0 != strcmp ("POST", method)) 137 if (0 != strcmp ("POST", method))
138 { 138 {
139 printf ("METHOD: %s\n", method); 139 printf ("METHOD: %s\n", method);
140 return MHD_NO; /* unexpected method */ 140 return MHD_NO; /* unexpected method */
141 } 141 }
142 pp = *unused; 142 pp = *unused;
143 if (pp == NULL) 143 if (pp == NULL)
144 { 144 {
145 eok = 0; 145 eok = 0;
146 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 146 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
147 if (pp == NULL) 147 if (pp == NULL)
148 abort (); 148 abort ();
149 *unused = pp; 149 *unused = pp;
150 } 150 }
151 MHD_post_process (pp, upload_data, *upload_data_size); 151 MHD_post_process (pp, upload_data, *upload_data_size);
152 if ((eok == 3) && (0 == *upload_data_size)) 152 if ((eok == 3) && (0 == *upload_data_size))
153 { 153 {
154 response = MHD_create_response_from_buffer (strlen (url), 154 response = MHD_create_response_from_buffer (strlen (url),
155 (void *) url, 155 (void *) url,
156 MHD_RESPMEM_MUST_COPY); 156 MHD_RESPMEM_MUST_COPY);
157 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 157 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
158 MHD_destroy_response (response); 158 MHD_destroy_response (response);
159 MHD_destroy_post_processor (pp); 159 MHD_destroy_post_processor (pp);
160 *unused = NULL; 160 *unused = NULL;
161 return ret; 161 return ret;
162 } 162 }
163 *upload_data_size = 0; 163 *upload_data_size = 0;
164 return MHD_YES; 164 return MHD_YES;
165} 165}
@@ -192,32 +192,34 @@ testInternalPost ()
192 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 192 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
193 port = 0; 193 port = 0;
194 else 194 else
195 { 195 {
196 port = 1390; 196 port = 1390;
197 if (oneone) 197 if (oneone)
198 port += 10; 198 port += 10;
199 } 199 }
200 200
201 cbc.buf = buf; 201 cbc.buf = buf;
202 cbc.size = 2048; 202 cbc.size = 2048;
203 cbc.pos = 0; 203 cbc.pos = 0;
204 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 204 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
205 port, NULL, NULL, &ahc_echo, NULL, 205 port, NULL, NULL, &ahc_echo, NULL,
206 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 206 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
207 MHD_OPTION_END); 207 MHD_OPTION_END);
208 if (d == NULL) 208 if (d == NULL)
209 return 1; 209 return 1;
210 if (0 == port) 210 if (0 == port)
211 {
212 const union MHD_DaemonInfo *dinfo;
213 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
214 if ((NULL == dinfo) ||(0 == dinfo->port) )
211 { 215 {
212 const union MHD_DaemonInfo *dinfo; 216 MHD_stop_daemon (d); return 32;
213 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
214 if (NULL == dinfo || 0 == dinfo->port)
215 { MHD_stop_daemon (d); return 32; }
216 port = (int)dinfo->port;
217 } 217 }
218 port = (int) dinfo->port;
219 }
218 c = curl_easy_init (); 220 c = curl_easy_init ();
219 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 221 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
220 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 222 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
221 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 223 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
222 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 224 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
223 pd = make_form (); 225 pd = make_form ();
@@ -234,15 +236,15 @@ testInternalPost ()
234 * crashes on my system! */ 236 * crashes on my system! */
235 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 237 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
236 if (CURLE_OK != (errornum = curl_easy_perform (c))) 238 if (CURLE_OK != (errornum = curl_easy_perform (c)))
237 { 239 {
238 fprintf (stderr, 240 fprintf (stderr,
239 "curl_easy_perform failed: `%s'\n", 241 "curl_easy_perform failed: `%s'\n",
240 curl_easy_strerror (errornum)); 242 curl_easy_strerror (errornum));
241 curl_easy_cleanup (c); 243 curl_easy_cleanup (c);
242 curl_formfree (pd); 244 curl_formfree (pd);
243 MHD_stop_daemon (d); 245 MHD_stop_daemon (d);
244 return 2; 246 return 2;
245 } 247 }
246 curl_easy_cleanup (c); 248 curl_easy_cleanup (c);
247 curl_formfree (pd); 249 curl_formfree (pd);
248 MHD_stop_daemon (d); 250 MHD_stop_daemon (d);
@@ -267,32 +269,35 @@ testMultithreadedPost ()
267 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 269 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
268 port = 0; 270 port = 0;
269 else 271 else
270 { 272 {
271 port = 1390; 273 port = 1390;
272 if (oneone) 274 if (oneone)
273 port += 10; 275 port += 10;
274 } 276 }
275 277
276 cbc.buf = buf; 278 cbc.buf = buf;
277 cbc.size = 2048; 279 cbc.size = 2048;
278 cbc.pos = 0; 280 cbc.pos = 0;
279 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 281 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
282 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
280 port, NULL, NULL, &ahc_echo, NULL, 283 port, NULL, NULL, &ahc_echo, NULL,
281 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 284 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
282 MHD_OPTION_END); 285 MHD_OPTION_END);
283 if (d == NULL) 286 if (d == NULL)
284 return 16; 287 return 16;
285 if (0 == port) 288 if (0 == port)
289 {
290 const union MHD_DaemonInfo *dinfo;
291 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
292 if ((NULL == dinfo) ||(0 == dinfo->port) )
286 { 293 {
287 const union MHD_DaemonInfo *dinfo; 294 MHD_stop_daemon (d); return 32;
288 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
289 if (NULL == dinfo || 0 == dinfo->port)
290 { MHD_stop_daemon (d); return 32; }
291 port = (int)dinfo->port;
292 } 295 }
296 port = (int) dinfo->port;
297 }
293 c = curl_easy_init (); 298 c = curl_easy_init ();
294 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 299 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
295 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 300 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
296 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 301 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
297 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 302 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
298 pd = make_form (); 303 pd = make_form ();
@@ -309,15 +314,15 @@ testMultithreadedPost ()
309 * crashes on my system! */ 314 * crashes on my system! */
310 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 315 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
311 if (CURLE_OK != (errornum = curl_easy_perform (c))) 316 if (CURLE_OK != (errornum = curl_easy_perform (c)))
312 { 317 {
313 fprintf (stderr, 318 fprintf (stderr,
314 "curl_easy_perform failed: `%s'\n", 319 "curl_easy_perform failed: `%s'\n",
315 curl_easy_strerror (errornum)); 320 curl_easy_strerror (errornum));
316 curl_easy_cleanup (c); 321 curl_easy_cleanup (c);
317 curl_formfree (pd); 322 curl_formfree (pd);
318 MHD_stop_daemon (d); 323 MHD_stop_daemon (d);
319 return 32; 324 return 32;
320 } 325 }
321 curl_easy_cleanup (c); 326 curl_easy_cleanup (c);
322 curl_formfree (pd); 327 curl_formfree (pd);
323 MHD_stop_daemon (d); 328 MHD_stop_daemon (d);
@@ -342,11 +347,11 @@ testMultithreadedPoolPost ()
342 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 347 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
343 port = 0; 348 port = 0;
344 else 349 else
345 { 350 {
346 port = 1391; 351 port = 1391;
347 if (oneone) 352 if (oneone)
348 port += 10; 353 port += 10;
349 } 354 }
350 355
351 cbc.buf = buf; 356 cbc.buf = buf;
352 cbc.size = 2048; 357 cbc.size = 2048;
@@ -354,21 +359,23 @@ testMultithreadedPoolPost ()
354 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 359 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
355 port, NULL, NULL, &ahc_echo, NULL, 360 port, NULL, NULL, &ahc_echo, NULL,
356 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, 361 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT,
357 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 362 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
358 MHD_OPTION_END); 363 MHD_OPTION_END);
359 if (d == NULL) 364 if (d == NULL)
360 return 16; 365 return 16;
361 if (0 == port) 366 if (0 == port)
367 {
368 const union MHD_DaemonInfo *dinfo;
369 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
370 if ((NULL == dinfo) ||(0 == dinfo->port) )
362 { 371 {
363 const union MHD_DaemonInfo *dinfo; 372 MHD_stop_daemon (d); return 32;
364 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
365 if (NULL == dinfo || 0 == dinfo->port)
366 { MHD_stop_daemon (d); return 32; }
367 port = (int)dinfo->port;
368 } 373 }
374 port = (int) dinfo->port;
375 }
369 c = curl_easy_init (); 376 c = curl_easy_init ();
370 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 377 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
371 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 378 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
372 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 379 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
373 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 380 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
374 pd = make_form (); 381 pd = make_form ();
@@ -385,15 +392,15 @@ testMultithreadedPoolPost ()
385 * crashes on my system! */ 392 * crashes on my system! */
386 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 393 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
387 if (CURLE_OK != (errornum = curl_easy_perform (c))) 394 if (CURLE_OK != (errornum = curl_easy_perform (c)))
388 { 395 {
389 fprintf (stderr, 396 fprintf (stderr,
390 "curl_easy_perform failed: `%s'\n", 397 "curl_easy_perform failed: `%s'\n",
391 curl_easy_strerror (errornum)); 398 curl_easy_strerror (errornum));
392 curl_easy_cleanup (c); 399 curl_easy_cleanup (c);
393 curl_formfree (pd); 400 curl_formfree (pd);
394 MHD_stop_daemon (d); 401 MHD_stop_daemon (d);
395 return 32; 402 return 32;
396 } 403 }
397 curl_easy_cleanup (c); 404 curl_easy_cleanup (c);
398 curl_formfree (pd); 405 curl_formfree (pd);
399 MHD_stop_daemon (d); 406 MHD_stop_daemon (d);
@@ -432,11 +439,11 @@ testExternalPost ()
432 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 439 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
433 port = 0; 440 port = 0;
434 else 441 else
435 { 442 {
436 port = 1392; 443 port = 1392;
437 if (oneone) 444 if (oneone)
438 port += 10; 445 port += 10;
439 } 446 }
440 447
441 multi = NULL; 448 multi = NULL;
442 cbc.buf = buf; 449 cbc.buf = buf;
@@ -444,21 +451,23 @@ testExternalPost ()
444 cbc.pos = 0; 451 cbc.pos = 0;
445 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 452 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
446 port, NULL, NULL, &ahc_echo, NULL, 453 port, NULL, NULL, &ahc_echo, NULL,
447 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 454 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
448 MHD_OPTION_END); 455 MHD_OPTION_END);
449 if (d == NULL) 456 if (d == NULL)
450 return 256; 457 return 256;
451 if (0 == port) 458 if (0 == port)
459 {
460 const union MHD_DaemonInfo *dinfo;
461 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
462 if ((NULL == dinfo) ||(0 == dinfo->port) )
452 { 463 {
453 const union MHD_DaemonInfo *dinfo; 464 MHD_stop_daemon (d); return 32;
454 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
455 if (NULL == dinfo || 0 == dinfo->port)
456 { MHD_stop_daemon (d); return 32; }
457 port = (int)dinfo->port;
458 } 465 }
466 port = (int) dinfo->port;
467 }
459 c = curl_easy_init (); 468 c = curl_easy_init ();
460 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 469 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
461 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 470 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
462 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 471 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
463 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 472 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
464 pd = make_form (); 473 pd = make_form ();
@@ -478,91 +487,93 @@ testExternalPost ()
478 487
479 multi = curl_multi_init (); 488 multi = curl_multi_init ();
480 if (multi == NULL) 489 if (multi == NULL)
490 {
491 curl_easy_cleanup (c);
492 curl_formfree (pd);
493 MHD_stop_daemon (d);
494 return 512;
495 }
496 mret = curl_multi_add_handle (multi, c);
497 if (mret != CURLM_OK)
498 {
499 curl_multi_cleanup (multi);
500 curl_formfree (pd);
501 curl_easy_cleanup (c);
502 MHD_stop_daemon (d);
503 return 1024;
504 }
505 start = time (NULL);
506 while ((time (NULL) - start < 5) && (multi != NULL))
507 {
508 maxsock = MHD_INVALID_SOCKET;
509 maxposixs = -1;
510 FD_ZERO (&rs);
511 FD_ZERO (&ws);
512 FD_ZERO (&es);
513 curl_multi_perform (multi, &running);
514 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
515 if (mret != CURLM_OK)
481 { 516 {
517 curl_multi_remove_handle (multi, c);
518 curl_multi_cleanup (multi);
482 curl_easy_cleanup (c); 519 curl_easy_cleanup (c);
483 curl_formfree (pd);
484 MHD_stop_daemon (d); 520 MHD_stop_daemon (d);
485 return 512; 521 curl_formfree (pd);
522 return 2048;
486 } 523 }
487 mret = curl_multi_add_handle (multi, c); 524 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
488 if (mret != CURLM_OK)
489 { 525 {
526 curl_multi_remove_handle (multi, c);
490 curl_multi_cleanup (multi); 527 curl_multi_cleanup (multi);
491 curl_formfree (pd);
492 curl_easy_cleanup (c); 528 curl_easy_cleanup (c);
529 curl_formfree (pd);
493 MHD_stop_daemon (d); 530 MHD_stop_daemon (d);
494 return 1024; 531 return 4096;
495 } 532 }
496 start = time (NULL); 533 tv.tv_sec = 0;
497 while ((time (NULL) - start < 5) && (multi != NULL)) 534 tv.tv_usec = 1000;
535 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
498 { 536 {
499 maxsock = MHD_INVALID_SOCKET;
500 maxposixs = -1;
501 FD_ZERO (&rs);
502 FD_ZERO (&ws);
503 FD_ZERO (&es);
504 curl_multi_perform (multi, &running);
505 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
506 if (mret != CURLM_OK)
507 {
508 curl_multi_remove_handle (multi, c);
509 curl_multi_cleanup (multi);
510 curl_easy_cleanup (c);
511 MHD_stop_daemon (d);
512 curl_formfree (pd);
513 return 2048;
514 }
515 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
516 {
517 curl_multi_remove_handle (multi, c);
518 curl_multi_cleanup (multi);
519 curl_easy_cleanup (c);
520 curl_formfree (pd);
521 MHD_stop_daemon (d);
522 return 4096;
523 }
524 tv.tv_sec = 0;
525 tv.tv_usec = 1000;
526 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
527 {
528#ifdef MHD_POSIX_SOCKETS 537#ifdef MHD_POSIX_SOCKETS
529 if (EINTR != errno) 538 if (EINTR != errno)
530 abort (); 539 abort ();
531#else 540#else
532 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 541 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
533 abort (); 542 ws.fd_count)
534 Sleep (1000); 543 ||(0 != es.fd_count) )
544 abort ();
545 Sleep (1000);
535#endif 546#endif
536 }
537 curl_multi_perform (multi, &running);
538 if (running == 0)
539 {
540 msg = curl_multi_info_read (multi, &running);
541 if (msg == NULL)
542 break;
543 if (msg->msg == CURLMSG_DONE)
544 {
545 if (msg->data.result != CURLE_OK)
546 printf ("%s failed at %s:%d: `%s'\n",
547 "curl_multi_perform",
548 __FILE__,
549 __LINE__,
550 curl_easy_strerror (msg->data.result));
551 curl_multi_remove_handle (multi, c);
552 curl_multi_cleanup (multi);
553 curl_easy_cleanup (c);
554 c = NULL;
555 multi = NULL;
556 }
557 }
558 MHD_run (d);
559 } 547 }
560 if (multi != NULL) 548 curl_multi_perform (multi, &running);
549 if (running == 0)
561 { 550 {
562 curl_multi_remove_handle (multi, c); 551 msg = curl_multi_info_read (multi, &running);
563 curl_easy_cleanup (c); 552 if (msg == NULL)
564 curl_multi_cleanup (multi); 553 break;
554 if (msg->msg == CURLMSG_DONE)
555 {
556 if (msg->data.result != CURLE_OK)
557 printf ("%s failed at %s:%d: `%s'\n",
558 "curl_multi_perform",
559 __FILE__,
560 __LINE__,
561 curl_easy_strerror (msg->data.result));
562 curl_multi_remove_handle (multi, c);
563 curl_multi_cleanup (multi);
564 curl_easy_cleanup (c);
565 c = NULL;
566 multi = NULL;
567 }
565 } 568 }
569 MHD_run (d);
570 }
571 if (multi != NULL)
572 {
573 curl_multi_remove_handle (multi, c);
574 curl_easy_cleanup (c);
575 curl_multi_cleanup (multi);
576 }
566 curl_formfree (pd); 577 curl_formfree (pd);
567 MHD_stop_daemon (d); 578 MHD_stop_daemon (d);
568 if (cbc.pos != strlen ("/hello_world")) 579 if (cbc.pos != strlen ("/hello_world"))
@@ -577,7 +588,7 @@ int
577main (int argc, char *const *argv) 588main (int argc, char *const *argv)
578{ 589{
579 unsigned int errorCount = 0; 590 unsigned int errorCount = 0;
580 (void)argc; /* Unused. Silent compiler warning. */ 591 (void) argc; /* Unused. Silent compiler warning. */
581 592
582#ifdef MHD_HTTPS_REQUIRE_GRYPT 593#ifdef MHD_HTTPS_REQUIRE_GRYPT
583#ifdef HAVE_GCRYPT_H 594#ifdef HAVE_GCRYPT_H
@@ -587,17 +598,17 @@ main (int argc, char *const *argv)
587#endif 598#endif
588#endif 599#endif
589#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 600#endif /* MHD_HTTPS_REQUIRE_GRYPT */
590 if (NULL == argv || 0 == argv[0]) 601 if ((NULL == argv)||(0 == argv[0]))
591 return 99; 602 return 99;
592 oneone = has_in_name (argv[0], "11"); 603 oneone = has_in_name (argv[0], "11");
593 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 604 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
594 return 2; 605 return 2;
595 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 606 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
596 { 607 {
597 errorCount += testInternalPost (); 608 errorCount += testInternalPost ();
598 errorCount += testMultithreadedPost (); 609 errorCount += testMultithreadedPost ();
599 errorCount += testMultithreadedPoolPost (); 610 errorCount += testMultithreadedPoolPost ();
600 } 611 }
601 errorCount += testExternalPost (); 612 errorCount += testExternalPost ();
602 if (errorCount != 0) 613 if (errorCount != 0)
603 fprintf (stderr, "Error (code: %u)\n", errorCount); 614 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_process_arguments.c b/src/testcurl/test_process_arguments.c
index 0817836d..3094a97f 100644
--- a/src/testcurl/test_process_arguments.c
+++ b/src/testcurl/test_process_arguments.c
@@ -74,15 +74,15 @@ ahc_echo (void *cls,
74 struct MHD_Response *response; 74 struct MHD_Response *response;
75 int ret; 75 int ret;
76 const char *hdr; 76 const char *hdr;
77 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 77 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
78 78
79 if (0 != strcmp (me, method)) 79 if (0 != strcmp (me, method))
80 return MHD_NO; /* unexpected method */ 80 return MHD_NO; /* unexpected method */
81 if (&ptr != *unused) 81 if (&ptr != *unused)
82 { 82 {
83 *unused = &ptr; 83 *unused = &ptr;
84 return MHD_YES; 84 return MHD_YES;
85 } 85 }
86 *unused = NULL; 86 *unused = NULL;
87 hdr = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "k"); 87 hdr = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "k");
88 if ((hdr == NULL) || (0 != strcmp (hdr, "v x"))) 88 if ((hdr == NULL) || (0 != strcmp (hdr, "v x")))
@@ -96,12 +96,12 @@ ahc_echo (void *cls,
96 if ((hdr == NULL) || (0 != strcmp (hdr, "\240bar"))) 96 if ((hdr == NULL) || (0 != strcmp (hdr, "\240bar")))
97 abort (); 97 abort ();
98 if (3 != MHD_get_connection_values (connection, 98 if (3 != MHD_get_connection_values (connection,
99 MHD_GET_ARGUMENT_KIND, 99 MHD_GET_ARGUMENT_KIND,
100 NULL, NULL)) 100 NULL, NULL))
101 abort (); 101 abort ();
102 response = MHD_create_response_from_buffer (strlen (url), 102 response = MHD_create_response_from_buffer (strlen (url),
103 (void *) url, 103 (void *) url,
104 MHD_RESPMEM_MUST_COPY); 104 MHD_RESPMEM_MUST_COPY);
105 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 105 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
106 MHD_destroy_response (response); 106 MHD_destroy_response (response);
107 if (ret == MHD_NO) 107 if (ret == MHD_NO)
@@ -137,11 +137,11 @@ testExternalGet ()
137 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 137 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
138 port = 0; 138 port = 0;
139 else 139 else
140 { 140 {
141 port = 1410; 141 port = 1410;
142 if (oneone) 142 if (oneone)
143 port += 5; 143 port += 5;
144 } 144 }
145 145
146 multi = NULL; 146 multi = NULL;
147 cbc.buf = buf; 147 cbc.buf = buf;
@@ -152,17 +152,19 @@ testExternalGet ()
152 if (d == NULL) 152 if (d == NULL)
153 return 256; 153 return 256;
154 if (0 == port) 154 if (0 == port)
155 {
156 const union MHD_DaemonInfo *dinfo;
157 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
158 if ((NULL == dinfo) ||(0 == dinfo->port) )
155 { 159 {
156 const union MHD_DaemonInfo *dinfo; 160 MHD_stop_daemon (d); return 32;
157 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
158 if (NULL == dinfo || 0 == dinfo->port)
159 { MHD_stop_daemon (d); return 32; }
160 port = (int)dinfo->port;
161 } 161 }
162 port = (int) dinfo->port;
163 }
162 c = curl_easy_init (); 164 c = curl_easy_init ();
163 curl_easy_setopt (c, CURLOPT_URL, 165 curl_easy_setopt (c, CURLOPT_URL,
164 "http://127.0.0.1/hello+world?k=v+x&hash=%23foo&space=%A0bar"); 166 "http://127.0.0.1/hello+world?k=v+x&hash=%23foo&space=%A0bar");
165 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 167 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
166 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 168 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
167 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 169 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
168 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -180,86 +182,88 @@ testExternalGet ()
180 182
181 multi = curl_multi_init (); 183 multi = curl_multi_init ();
182 if (multi == NULL) 184 if (multi == NULL)
185 {
186 curl_easy_cleanup (c);
187 MHD_stop_daemon (d);
188 return 512;
189 }
190 mret = curl_multi_add_handle (multi, c);
191 if (mret != CURLM_OK)
192 {
193 curl_multi_cleanup (multi);
194 curl_easy_cleanup (c);
195 MHD_stop_daemon (d);
196 return 1024;
197 }
198 start = time (NULL);
199 while ((time (NULL) - start < 5) && (multi != NULL))
200 {
201 maxsock = MHD_INVALID_SOCKET;
202 maxposixs = -1;
203 FD_ZERO (&rs);
204 FD_ZERO (&ws);
205 FD_ZERO (&es);
206 curl_multi_perform (multi, &running);
207 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
208 if (mret != CURLM_OK)
183 { 209 {
210 curl_multi_remove_handle (multi, c);
211 curl_multi_cleanup (multi);
184 curl_easy_cleanup (c); 212 curl_easy_cleanup (c);
185 MHD_stop_daemon (d); 213 MHD_stop_daemon (d);
186 return 512; 214 return 2048;
187 } 215 }
188 mret = curl_multi_add_handle (multi, c); 216 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
189 if (mret != CURLM_OK)
190 { 217 {
218 curl_multi_remove_handle (multi, c);
191 curl_multi_cleanup (multi); 219 curl_multi_cleanup (multi);
192 curl_easy_cleanup (c); 220 curl_easy_cleanup (c);
193 MHD_stop_daemon (d); 221 MHD_stop_daemon (d);
194 return 1024; 222 return 4096;
195 } 223 }
196 start = time (NULL); 224 tv.tv_sec = 0;
197 while ((time (NULL) - start < 5) && (multi != NULL)) 225 tv.tv_usec = 1000;
226 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
198 { 227 {
199 maxsock = MHD_INVALID_SOCKET;
200 maxposixs = -1;
201 FD_ZERO (&rs);
202 FD_ZERO (&ws);
203 FD_ZERO (&es);
204 curl_multi_perform (multi, &running);
205 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
206 if (mret != CURLM_OK)
207 {
208 curl_multi_remove_handle (multi, c);
209 curl_multi_cleanup (multi);
210 curl_easy_cleanup (c);
211 MHD_stop_daemon (d);
212 return 2048;
213 }
214 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
215 {
216 curl_multi_remove_handle (multi, c);
217 curl_multi_cleanup (multi);
218 curl_easy_cleanup (c);
219 MHD_stop_daemon (d);
220 return 4096;
221 }
222 tv.tv_sec = 0;
223 tv.tv_usec = 1000;
224 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
225 {
226#ifdef MHD_POSIX_SOCKETS 228#ifdef MHD_POSIX_SOCKETS
227 if (EINTR != errno) 229 if (EINTR != errno)
228 abort (); 230 abort ();
229#else 231#else
230 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 232 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
231 abort (); 233 ws.fd_count)
232 Sleep (1000); 234 ||(0 != es.fd_count) )
235 abort ();
236 Sleep (1000);
233#endif 237#endif
234 }
235 curl_multi_perform (multi, &running);
236 if (running == 0)
237 {
238 msg = curl_multi_info_read (multi, &running);
239 if (msg == NULL)
240 break;
241 if (msg->msg == CURLMSG_DONE)
242 {
243 if (msg->data.result != CURLE_OK)
244 printf ("%s failed at %s:%d: `%s'\n",
245 "curl_multi_perform",
246 __FILE__,
247 __LINE__, curl_easy_strerror (msg->data.result));
248 curl_multi_remove_handle (multi, c);
249 curl_multi_cleanup (multi);
250 curl_easy_cleanup (c);
251 c = NULL;
252 multi = NULL;
253 }
254 }
255 MHD_run (d);
256 } 238 }
257 if (multi != NULL) 239 curl_multi_perform (multi, &running);
240 if (running == 0)
258 { 241 {
259 curl_multi_remove_handle (multi, c); 242 msg = curl_multi_info_read (multi, &running);
260 curl_easy_cleanup (c); 243 if (msg == NULL)
261 curl_multi_cleanup (multi); 244 break;
245 if (msg->msg == CURLMSG_DONE)
246 {
247 if (msg->data.result != CURLE_OK)
248 printf ("%s failed at %s:%d: `%s'\n",
249 "curl_multi_perform",
250 __FILE__,
251 __LINE__, curl_easy_strerror (msg->data.result));
252 curl_multi_remove_handle (multi, c);
253 curl_multi_cleanup (multi);
254 curl_easy_cleanup (c);
255 c = NULL;
256 multi = NULL;
257 }
262 } 258 }
259 MHD_run (d);
260 }
261 if (multi != NULL)
262 {
263 curl_multi_remove_handle (multi, c);
264 curl_easy_cleanup (c);
265 curl_multi_cleanup (multi);
266 }
263 MHD_stop_daemon (d); 267 MHD_stop_daemon (d);
264 if (cbc.pos != strlen ("/hello+world")) 268 if (cbc.pos != strlen ("/hello+world"))
265 return 8192; 269 return 8192;
@@ -273,9 +277,9 @@ int
273main (int argc, char *const *argv) 277main (int argc, char *const *argv)
274{ 278{
275 unsigned int errorCount = 0; 279 unsigned int errorCount = 0;
276 (void)argc; /* Unused. Silent compiler warning. */ 280 (void) argc; /* Unused. Silent compiler warning. */
277 281
278 if (NULL == argv || 0 == argv[0]) 282 if ((NULL == argv)||(0 == argv[0]))
279 return 99; 283 return 99;
280 oneone = has_in_name (argv[0], "11"); 284 oneone = has_in_name (argv[0], "11");
281 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 285 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c
index a1237c78..a2d7485b 100644
--- a/src/testcurl/test_process_headers.c
+++ b/src/testcurl/test_process_headers.c
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
4 Copyright (C) 2007 Christian Grothoff 3 Copyright (C) 2007 Christian Grothoff
@@ -38,10 +37,10 @@
38#include <unistd.h> 37#include <unistd.h>
39#endif 38#endif
40 39
41#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 40#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
42#undef CPU_COUNT 41#undef CPU_COUNT
43#endif 42#endif
44#if !defined(CPU_COUNT) 43#if ! defined(CPU_COUNT)
45#define CPU_COUNT 2 44#define CPU_COUNT 2
46#endif 45#endif
47 46
@@ -70,11 +69,12 @@ static int
70kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) 69kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
71{ 70{
72 if ((0 == strcmp (key, MHD_HTTP_HEADER_HOST)) && 71 if ((0 == strcmp (key, MHD_HTTP_HEADER_HOST)) &&
73 (0 == strncmp (value, "127.0.0.1", strlen("127.0.0.1"))) && (kind == MHD_HEADER_KIND)) 72 (0 == strncmp (value, "127.0.0.1", strlen ("127.0.0.1"))) && (kind ==
74 { 73 MHD_HEADER_KIND))
75 *((int *) cls) = 1; 74 {
76 return MHD_NO; 75 *((int *) cls) = 1;
77 } 76 return MHD_NO;
77 }
78 return MHD_YES; 78 return MHD_YES;
79} 79}
80 80
@@ -92,15 +92,15 @@ ahc_echo (void *cls,
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 const char *hdr; 94 const char *hdr;
95 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 95 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
96 96
97 if (0 != strcmp (me, method)) 97 if (0 != strcmp (me, method))
98 return MHD_NO; /* unexpected method */ 98 return MHD_NO; /* unexpected method */
99 if (&ptr != *unused) 99 if (&ptr != *unused)
100 { 100 {
101 *unused = &ptr; 101 *unused = &ptr;
102 return MHD_YES; 102 return MHD_YES;
103 } 103 }
104 *unused = NULL; 104 *unused = NULL;
105 ret = 0; 105 ret = 0;
106 MHD_get_connection_values (connection, MHD_HEADER_KIND, &kv_cb, &ret); 106 MHD_get_connection_values (connection, MHD_HEADER_KIND, &kv_cb, &ret);
@@ -115,7 +115,7 @@ ahc_echo (void *cls,
115 abort (); 115 abort ();
116 hdr = MHD_lookup_connection_value (connection, 116 hdr = MHD_lookup_connection_value (connection,
117 MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST); 117 MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST);
118 if ((hdr == NULL) || (0 != strncmp (hdr, "127.0.0.1", strlen("127.0.0.1")))) 118 if ((hdr == NULL) || (0 != strncmp (hdr, "127.0.0.1", strlen ("127.0.0.1"))))
119 abort (); 119 abort ();
120 MHD_set_connection_value (connection, 120 MHD_set_connection_value (connection,
121 MHD_HEADER_KIND, "FakeHeader", "NowPresent"); 121 MHD_HEADER_KIND, "FakeHeader", "NowPresent");
@@ -125,8 +125,8 @@ ahc_echo (void *cls,
125 abort (); 125 abort ();
126 126
127 response = MHD_create_response_from_buffer (strlen (url), 127 response = MHD_create_response_from_buffer (strlen (url),
128 (void *) url, 128 (void *) url,
129 MHD_RESPMEM_MUST_COPY); 129 MHD_RESPMEM_MUST_COPY);
130 if (NULL == response) 130 if (NULL == response)
131 abort (); 131 abort ();
132 MHD_add_response_header (response, "MyHeader", "MyValue"); 132 MHD_add_response_header (response, "MyHeader", "MyValue");
@@ -162,11 +162,11 @@ testInternalGet ()
162 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 162 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
163 port = 0; 163 port = 0;
164 else 164 else
165 { 165 {
166 port = 1420; 166 port = 1420;
167 if (oneone) 167 if (oneone)
168 port += 10; 168 port += 10;
169 } 169 }
170 170
171 cbc.buf = buf; 171 cbc.buf = buf;
172 cbc.size = 2048; 172 cbc.size = 2048;
@@ -176,16 +176,18 @@ testInternalGet ()
176 if (d == NULL) 176 if (d == NULL)
177 return 1; 177 return 1;
178 if (0 == port) 178 if (0 == port)
179 {
180 const union MHD_DaemonInfo *dinfo;
181 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
182 if ((NULL == dinfo) ||(0 == dinfo->port) )
179 { 183 {
180 const union MHD_DaemonInfo *dinfo; 184 MHD_stop_daemon (d); return 32;
181 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
182 if (NULL == dinfo || 0 == dinfo->port)
183 { MHD_stop_daemon (d); return 32; }
184 port = (int)dinfo->port;
185 } 185 }
186 port = (int) dinfo->port;
187 }
186 c = curl_easy_init (); 188 c = curl_easy_init ();
187 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 189 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
188 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 190 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
189 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 191 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
190 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 192 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
191 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 193 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -200,14 +202,14 @@ testInternalGet ()
200 crashes on my system! */ 202 crashes on my system! */
201 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 203 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
202 if (CURLE_OK != (errornum = curl_easy_perform (c))) 204 if (CURLE_OK != (errornum = curl_easy_perform (c)))
203 { 205 {
204 fprintf (stderr, 206 fprintf (stderr,
205 "curl_easy_perform failed: `%s'\n", 207 "curl_easy_perform failed: `%s'\n",
206 curl_easy_strerror (errornum)); 208 curl_easy_strerror (errornum));
207 curl_easy_cleanup (c); 209 curl_easy_cleanup (c);
208 MHD_stop_daemon (d); 210 MHD_stop_daemon (d);
209 return 2; 211 return 2;
210 } 212 }
211 curl_easy_cleanup (c); 213 curl_easy_cleanup (c);
212 MHD_stop_daemon (d); 214 MHD_stop_daemon (d);
213 if (cbc.pos != strlen ("/hello_world")) 215 if (cbc.pos != strlen ("/hello_world"))
@@ -230,30 +232,33 @@ testMultithreadedGet ()
230 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 232 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
231 port = 0; 233 port = 0;
232 else 234 else
233 { 235 {
234 port = 1421; 236 port = 1421;
235 if (oneone) 237 if (oneone)
236 port += 10; 238 port += 10;
237 } 239 }
238 240
239 cbc.buf = buf; 241 cbc.buf = buf;
240 cbc.size = 2048; 242 cbc.size = 2048;
241 cbc.pos = 0; 243 cbc.pos = 0;
242 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 244 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
245 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
243 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 246 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
244 if (d == NULL) 247 if (d == NULL)
245 return 16; 248 return 16;
246 if (0 == port) 249 if (0 == port)
250 {
251 const union MHD_DaemonInfo *dinfo;
252 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
253 if ((NULL == dinfo) ||(0 == dinfo->port) )
247 { 254 {
248 const union MHD_DaemonInfo *dinfo; 255 MHD_stop_daemon (d); return 32;
249 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
250 if (NULL == dinfo || 0 == dinfo->port)
251 { MHD_stop_daemon (d); return 32; }
252 port = (int)dinfo->port;
253 } 256 }
257 port = (int) dinfo->port;
258 }
254 c = curl_easy_init (); 259 c = curl_easy_init ();
255 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 260 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
256 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 261 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
257 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 262 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
258 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 263 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
259 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 264 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -268,14 +273,14 @@ testMultithreadedGet ()
268 crashes on my system! */ 273 crashes on my system! */
269 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 274 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
270 if (CURLE_OK != (errornum = curl_easy_perform (c))) 275 if (CURLE_OK != (errornum = curl_easy_perform (c)))
271 { 276 {
272 fprintf (stderr, 277 fprintf (stderr,
273 "curl_easy_perform failed: `%s'\n", 278 "curl_easy_perform failed: `%s'\n",
274 curl_easy_strerror (errornum)); 279 curl_easy_strerror (errornum));
275 curl_easy_cleanup (c); 280 curl_easy_cleanup (c);
276 MHD_stop_daemon (d); 281 MHD_stop_daemon (d);
277 return 32; 282 return 32;
278 } 283 }
279 curl_easy_cleanup (c); 284 curl_easy_cleanup (c);
280 MHD_stop_daemon (d); 285 MHD_stop_daemon (d);
281 if (cbc.pos != strlen ("/hello_world")) 286 if (cbc.pos != strlen ("/hello_world"))
@@ -298,11 +303,11 @@ testMultithreadedPoolGet ()
298 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 303 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
299 port = 0; 304 port = 0;
300 else 305 else
301 { 306 {
302 port = 1422; 307 port = 1422;
303 if (oneone) 308 if (oneone)
304 port += 10; 309 port += 10;
305 } 310 }
306 311
307 cbc.buf = buf; 312 cbc.buf = buf;
308 cbc.size = 2048; 313 cbc.size = 2048;
@@ -313,16 +318,18 @@ testMultithreadedPoolGet ()
313 if (d == NULL) 318 if (d == NULL)
314 return 16; 319 return 16;
315 if (0 == port) 320 if (0 == port)
321 {
322 const union MHD_DaemonInfo *dinfo;
323 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
324 if ((NULL == dinfo) ||(0 == dinfo->port) )
316 { 325 {
317 const union MHD_DaemonInfo *dinfo; 326 MHD_stop_daemon (d); return 32;
318 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
319 if (NULL == dinfo || 0 == dinfo->port)
320 { MHD_stop_daemon (d); return 32; }
321 port = (int)dinfo->port;
322 } 327 }
328 port = (int) dinfo->port;
329 }
323 c = curl_easy_init (); 330 c = curl_easy_init ();
324 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 331 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
325 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 332 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
326 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 333 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
327 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 334 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
328 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 335 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -337,14 +344,14 @@ testMultithreadedPoolGet ()
337 crashes on my system! */ 344 crashes on my system! */
338 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 345 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
339 if (CURLE_OK != (errornum = curl_easy_perform (c))) 346 if (CURLE_OK != (errornum = curl_easy_perform (c)))
340 { 347 {
341 fprintf (stderr, 348 fprintf (stderr,
342 "curl_easy_perform failed: `%s'\n", 349 "curl_easy_perform failed: `%s'\n",
343 curl_easy_strerror (errornum)); 350 curl_easy_strerror (errornum));
344 curl_easy_cleanup (c); 351 curl_easy_cleanup (c);
345 MHD_stop_daemon (d); 352 MHD_stop_daemon (d);
346 return 32; 353 return 32;
347 } 354 }
348 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
349 MHD_stop_daemon (d); 356 MHD_stop_daemon (d);
350 if (cbc.pos != strlen ("/hello_world")) 357 if (cbc.pos != strlen ("/hello_world"))
@@ -381,11 +388,11 @@ testExternalGet ()
381 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 388 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
382 port = 0; 389 port = 0;
383 else 390 else
384 { 391 {
385 port = 1423; 392 port = 1423;
386 if (oneone) 393 if (oneone)
387 port += 10; 394 port += 10;
388 } 395 }
389 396
390 multi = NULL; 397 multi = NULL;
391 cbc.buf = buf; 398 cbc.buf = buf;
@@ -396,16 +403,18 @@ testExternalGet ()
396 if (d == NULL) 403 if (d == NULL)
397 return 256; 404 return 256;
398 if (0 == port) 405 if (0 == port)
406 {
407 const union MHD_DaemonInfo *dinfo;
408 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
409 if ((NULL == dinfo) ||(0 == dinfo->port) )
399 { 410 {
400 const union MHD_DaemonInfo *dinfo; 411 MHD_stop_daemon (d); return 32;
401 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
402 if (NULL == dinfo || 0 == dinfo->port)
403 { MHD_stop_daemon (d); return 32; }
404 port = (int)dinfo->port;
405 } 412 }
413 port = (int) dinfo->port;
414 }
406 c = curl_easy_init (); 415 c = curl_easy_init ();
407 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 416 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
408 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 417 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
409 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 418 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
410 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 419 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
411 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 420 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -423,86 +432,88 @@ testExternalGet ()
423 432
424 multi = curl_multi_init (); 433 multi = curl_multi_init ();
425 if (multi == NULL) 434 if (multi == NULL)
435 {
436 curl_easy_cleanup (c);
437 MHD_stop_daemon (d);
438 return 512;
439 }
440 mret = curl_multi_add_handle (multi, c);
441 if (mret != CURLM_OK)
442 {
443 curl_multi_cleanup (multi);
444 curl_easy_cleanup (c);
445 MHD_stop_daemon (d);
446 return 1024;
447 }
448 start = time (NULL);
449 while ((time (NULL) - start < 5) && (multi != NULL))
450 {
451 maxsock = MHD_INVALID_SOCKET;
452 maxposixs = -1;
453 FD_ZERO (&rs);
454 FD_ZERO (&ws);
455 FD_ZERO (&es);
456 curl_multi_perform (multi, &running);
457 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
458 if (mret != CURLM_OK)
426 { 459 {
460 curl_multi_remove_handle (multi, c);
461 curl_multi_cleanup (multi);
427 curl_easy_cleanup (c); 462 curl_easy_cleanup (c);
428 MHD_stop_daemon (d); 463 MHD_stop_daemon (d);
429 return 512; 464 return 2048;
430 } 465 }
431 mret = curl_multi_add_handle (multi, c); 466 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
432 if (mret != CURLM_OK)
433 { 467 {
468 curl_multi_remove_handle (multi, c);
434 curl_multi_cleanup (multi); 469 curl_multi_cleanup (multi);
435 curl_easy_cleanup (c); 470 curl_easy_cleanup (c);
436 MHD_stop_daemon (d); 471 MHD_stop_daemon (d);
437 return 1024; 472 return 4096;
438 } 473 }
439 start = time (NULL); 474 tv.tv_sec = 0;
440 while ((time (NULL) - start < 5) && (multi != NULL)) 475 tv.tv_usec = 1000;
476 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
441 { 477 {
442 maxsock = MHD_INVALID_SOCKET;
443 maxposixs = -1;
444 FD_ZERO (&rs);
445 FD_ZERO (&ws);
446 FD_ZERO (&es);
447 curl_multi_perform (multi, &running);
448 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
449 if (mret != CURLM_OK)
450 {
451 curl_multi_remove_handle (multi, c);
452 curl_multi_cleanup (multi);
453 curl_easy_cleanup (c);
454 MHD_stop_daemon (d);
455 return 2048;
456 }
457 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
458 {
459 curl_multi_remove_handle (multi, c);
460 curl_multi_cleanup (multi);
461 curl_easy_cleanup (c);
462 MHD_stop_daemon (d);
463 return 4096;
464 }
465 tv.tv_sec = 0;
466 tv.tv_usec = 1000;
467 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
468 {
469#ifdef MHD_POSIX_SOCKETS 478#ifdef MHD_POSIX_SOCKETS
470 if (EINTR != errno) 479 if (EINTR != errno)
471 abort (); 480 abort ();
472#else 481#else
473 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 482 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
474 abort (); 483 ws.fd_count)
475 Sleep (1000); 484 ||(0 != es.fd_count) )
485 abort ();
486 Sleep (1000);
476#endif 487#endif
477 }
478 curl_multi_perform (multi, &running);
479 if (running == 0)
480 {
481 msg = curl_multi_info_read (multi, &running);
482 if (msg == NULL)
483 break;
484 if (msg->msg == CURLMSG_DONE)
485 {
486 if (msg->data.result != CURLE_OK)
487 printf ("%s failed at %s:%d: `%s'\n",
488 "curl_multi_perform",
489 __FILE__,
490 __LINE__, curl_easy_strerror (msg->data.result));
491 curl_multi_remove_handle (multi, c);
492 curl_multi_cleanup (multi);
493 curl_easy_cleanup (c);
494 c = NULL;
495 multi = NULL;
496 }
497 }
498 MHD_run (d);
499 } 488 }
500 if (multi != NULL) 489 curl_multi_perform (multi, &running);
490 if (running == 0)
501 { 491 {
502 curl_multi_remove_handle (multi, c); 492 msg = curl_multi_info_read (multi, &running);
503 curl_easy_cleanup (c); 493 if (msg == NULL)
504 curl_multi_cleanup (multi); 494 break;
495 if (msg->msg == CURLMSG_DONE)
496 {
497 if (msg->data.result != CURLE_OK)
498 printf ("%s failed at %s:%d: `%s'\n",
499 "curl_multi_perform",
500 __FILE__,
501 __LINE__, curl_easy_strerror (msg->data.result));
502 curl_multi_remove_handle (multi, c);
503 curl_multi_cleanup (multi);
504 curl_easy_cleanup (c);
505 c = NULL;
506 multi = NULL;
507 }
505 } 508 }
509 MHD_run (d);
510 }
511 if (multi != NULL)
512 {
513 curl_multi_remove_handle (multi, c);
514 curl_easy_cleanup (c);
515 curl_multi_cleanup (multi);
516 }
506 MHD_stop_daemon (d); 517 MHD_stop_daemon (d);
507 if (cbc.pos != strlen ("/hello_world")) 518 if (cbc.pos != strlen ("/hello_world"))
508 return 8192; 519 return 8192;
@@ -517,17 +528,17 @@ int
517main (int argc, char *const *argv) 528main (int argc, char *const *argv)
518{ 529{
519 unsigned int errorCount = 0; 530 unsigned int errorCount = 0;
520 (void)argc; /* Unused. Silent compiler warning. */ 531 (void) argc; /* Unused. Silent compiler warning. */
521 532
522 if (NULL == argv || 0 == argv[0]) 533 if ((NULL == argv)||(0 == argv[0]))
523 return 99; 534 return 99;
524 oneone = has_in_name (argv[0], "11"); 535 oneone = has_in_name (argv[0], "11");
525 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 536 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
526 { 537 {
527 errorCount += testInternalGet (); 538 errorCount += testInternalGet ();
528 errorCount += testMultithreadedGet (); 539 errorCount += testMultithreadedGet ();
529 errorCount += testMultithreadedPoolGet (); 540 errorCount += testMultithreadedPoolGet ();
530 } 541 }
531 errorCount += testExternalGet (); 542 errorCount += testExternalGet ();
532 if (errorCount != 0) 543 if (errorCount != 0)
533 fprintf (stderr, "Error (code: %u)\n", errorCount); 544 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_put.c b/src/testcurl/test_put.c
index fd56e2b2..df399268 100644
--- a/src/testcurl/test_put.c
+++ b/src/testcurl/test_put.c
@@ -37,10 +37,10 @@
37#include <unistd.h> 37#include <unistd.h>
38#endif 38#endif
39 39
40#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 40#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
41#undef CPU_COUNT 41#undef CPU_COUNT
42#endif 42#endif
43#if !defined(CPU_COUNT) 43#if ! defined(CPU_COUNT)
44#define CPU_COUNT 2 44#define CPU_COUNT 2
45#endif 45#endif
46 46
@@ -91,28 +91,28 @@ ahc_echo (void *cls,
91 int *done = cls; 91 int *done = cls;
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 94 (void) version; (void) unused; /* Unused. Silent compiler warning. */
95 95
96 if (0 != strcasecmp ("PUT", method)) 96 if (0 != strcasecmp ("PUT", method))
97 return MHD_NO; /* unexpected method */ 97 return MHD_NO; /* unexpected method */
98 if ((*done) == 0) 98 if ((*done) == 0)
99 {
100 if (*upload_data_size != 8)
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
99 { 103 {
100 if (*upload_data_size != 8) 104 *upload_data_size = 0;
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
103 {
104 *upload_data_size = 0;
105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 } 105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 }
114 response = MHD_create_response_from_buffer (strlen (url), (void*) url, 114 response = MHD_create_response_from_buffer (strlen (url), (void*) url,
115 MHD_RESPMEM_MUST_COPY); 115 MHD_RESPMEM_MUST_COPY);
116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
117 MHD_destroy_response (response); 117 MHD_destroy_response (response);
118 return ret; 118 return ret;
@@ -134,11 +134,11 @@ testInternalPut ()
134 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 134 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
135 port = 0; 135 port = 0;
136 else 136 else
137 { 137 {
138 port = 1450; 138 port = 1450;
139 if (oneone) 139 if (oneone)
140 port += 10; 140 port += 10;
141 } 141 }
142 142
143 cbc.buf = buf; 143 cbc.buf = buf;
144 cbc.size = 2048; 144 cbc.size = 2048;
@@ -149,16 +149,18 @@ testInternalPut ()
149 if (d == NULL) 149 if (d == NULL)
150 return 1; 150 return 1;
151 if (0 == port) 151 if (0 == port)
152 {
153 const union MHD_DaemonInfo *dinfo;
154 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
155 if ((NULL == dinfo) ||(0 == dinfo->port) )
152 { 156 {
153 const union MHD_DaemonInfo *dinfo; 157 MHD_stop_daemon (d); return 32;
154 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
155 if (NULL == dinfo || 0 == dinfo->port)
156 { MHD_stop_daemon (d); return 32; }
157 port = (int)dinfo->port;
158 } 158 }
159 port = (int) dinfo->port;
160 }
159 c = curl_easy_init (); 161 c = curl_easy_init ();
160 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 162 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
161 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 163 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
162 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 164 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
163 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 165 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
164 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 166 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -177,14 +179,14 @@ testInternalPut ()
177 * crashes on my system! */ 179 * crashes on my system! */
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 180 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
179 if (CURLE_OK != (errornum = curl_easy_perform (c))) 181 if (CURLE_OK != (errornum = curl_easy_perform (c)))
180 { 182 {
181 fprintf (stderr, 183 fprintf (stderr,
182 "curl_easy_perform failed: `%s'\n", 184 "curl_easy_perform failed: `%s'\n",
183 curl_easy_strerror (errornum)); 185 curl_easy_strerror (errornum));
184 curl_easy_cleanup (c); 186 curl_easy_cleanup (c);
185 MHD_stop_daemon (d); 187 MHD_stop_daemon (d);
186 return 2; 188 return 2;
187 } 189 }
188 curl_easy_cleanup (c); 190 curl_easy_cleanup (c);
189 MHD_stop_daemon (d); 191 MHD_stop_daemon (d);
190 if (cbc.pos != strlen ("/hello_world")) 192 if (cbc.pos != strlen ("/hello_world"))
@@ -209,31 +211,34 @@ testMultithreadedPut ()
209 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 211 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
210 port = 0; 212 port = 0;
211 else 213 else
212 { 214 {
213 port = 1451; 215 port = 1451;
214 if (oneone) 216 if (oneone)
215 port += 10; 217 port += 10;
216 } 218 }
217 219
218 cbc.buf = buf; 220 cbc.buf = buf;
219 cbc.size = 2048; 221 cbc.size = 2048;
220 cbc.pos = 0; 222 cbc.pos = 0;
221 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 223 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
224 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
222 port, 225 port,
223 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 226 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
224 if (d == NULL) 227 if (d == NULL)
225 return 16; 228 return 16;
226 if (0 == port) 229 if (0 == port)
230 {
231 const union MHD_DaemonInfo *dinfo;
232 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
233 if ((NULL == dinfo) ||(0 == dinfo->port) )
227 { 234 {
228 const union MHD_DaemonInfo *dinfo; 235 MHD_stop_daemon (d); return 32;
229 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
230 if (NULL == dinfo || 0 == dinfo->port)
231 { MHD_stop_daemon (d); return 32; }
232 port = (int)dinfo->port;
233 } 236 }
237 port = (int) dinfo->port;
238 }
234 c = curl_easy_init (); 239 c = curl_easy_init ();
235 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 240 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
236 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 241 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
237 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 242 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
238 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 243 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
239 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 244 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -252,14 +257,14 @@ testMultithreadedPut ()
252 * crashes on my system! */ 257 * crashes on my system! */
253 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 258 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
254 if (CURLE_OK != (errornum = curl_easy_perform (c))) 259 if (CURLE_OK != (errornum = curl_easy_perform (c)))
255 { 260 {
256 fprintf (stderr, 261 fprintf (stderr,
257 "curl_easy_perform failed: `%s'\n", 262 "curl_easy_perform failed: `%s'\n",
258 curl_easy_strerror (errornum)); 263 curl_easy_strerror (errornum));
259 curl_easy_cleanup (c); 264 curl_easy_cleanup (c);
260 MHD_stop_daemon (d); 265 MHD_stop_daemon (d);
261 return 32; 266 return 32;
262 } 267 }
263 curl_easy_cleanup (c); 268 curl_easy_cleanup (c);
264 MHD_stop_daemon (d); 269 MHD_stop_daemon (d);
265 if (cbc.pos != strlen ("/hello_world")) 270 if (cbc.pos != strlen ("/hello_world"))
@@ -285,11 +290,11 @@ testMultithreadedPoolPut ()
285 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 290 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
286 port = 0; 291 port = 0;
287 else 292 else
288 { 293 {
289 port = 1452; 294 port = 1452;
290 if (oneone) 295 if (oneone)
291 port += 10; 296 port += 10;
292 } 297 }
293 298
294 cbc.buf = buf; 299 cbc.buf = buf;
295 cbc.size = 2048; 300 cbc.size = 2048;
@@ -301,16 +306,18 @@ testMultithreadedPoolPut ()
301 if (d == NULL) 306 if (d == NULL)
302 return 16; 307 return 16;
303 if (0 == port) 308 if (0 == port)
309 {
310 const union MHD_DaemonInfo *dinfo;
311 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
312 if ((NULL == dinfo) ||(0 == dinfo->port) )
304 { 313 {
305 const union MHD_DaemonInfo *dinfo; 314 MHD_stop_daemon (d); return 32;
306 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
307 if (NULL == dinfo || 0 == dinfo->port)
308 { MHD_stop_daemon (d); return 32; }
309 port = (int)dinfo->port;
310 } 315 }
316 port = (int) dinfo->port;
317 }
311 c = curl_easy_init (); 318 c = curl_easy_init ();
312 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 319 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
313 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 320 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
314 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 321 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
315 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 322 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
316 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 323 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -329,14 +336,14 @@ testMultithreadedPoolPut ()
329 * crashes on my system! */ 336 * crashes on my system! */
330 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 337 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
331 if (CURLE_OK != (errornum = curl_easy_perform (c))) 338 if (CURLE_OK != (errornum = curl_easy_perform (c)))
332 { 339 {
333 fprintf (stderr, 340 fprintf (stderr,
334 "curl_easy_perform failed: `%s'\n", 341 "curl_easy_perform failed: `%s'\n",
335 curl_easy_strerror (errornum)); 342 curl_easy_strerror (errornum));
336 curl_easy_cleanup (c); 343 curl_easy_cleanup (c);
337 MHD_stop_daemon (d); 344 MHD_stop_daemon (d);
338 return 32; 345 return 32;
339 } 346 }
340 curl_easy_cleanup (c); 347 curl_easy_cleanup (c);
341 MHD_stop_daemon (d); 348 MHD_stop_daemon (d);
342 if (cbc.pos != strlen ("/hello_world")) 349 if (cbc.pos != strlen ("/hello_world"))
@@ -373,11 +380,11 @@ testExternalPut ()
373 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 380 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
374 port = 0; 381 port = 0;
375 else 382 else
376 { 383 {
377 port = 1453; 384 port = 1453;
378 if (oneone) 385 if (oneone)
379 port += 10; 386 port += 10;
380 } 387 }
381 388
382 multi = NULL; 389 multi = NULL;
383 cbc.buf = buf; 390 cbc.buf = buf;
@@ -389,17 +396,19 @@ testExternalPut ()
389 if (d == NULL) 396 if (d == NULL)
390 return 256; 397 return 256;
391 if (0 == port) 398 if (0 == port)
399 {
400 const union MHD_DaemonInfo *dinfo;
401 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
402 if ((NULL == dinfo) ||(0 == dinfo->port) )
392 { 403 {
393 const union MHD_DaemonInfo *dinfo; 404 MHD_stop_daemon (d); return 32;
394 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
395 if (NULL == dinfo || 0 == dinfo->port)
396 { MHD_stop_daemon (d); return 32; }
397 port = (int)dinfo->port;
398 } 405 }
406 port = (int) dinfo->port;
407 }
399 c = curl_easy_init (); 408 c = curl_easy_init ();
400 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 409 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
401 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 410 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
402curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 411 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
403 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 412 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
404 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 413 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
405 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 414 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
@@ -420,90 +429,92 @@ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
420 429
421 multi = curl_multi_init (); 430 multi = curl_multi_init ();
422 if (multi == NULL) 431 if (multi == NULL)
432 {
433 curl_easy_cleanup (c);
434 MHD_stop_daemon (d);
435 return 512;
436 }
437 mret = curl_multi_add_handle (multi, c);
438 if (mret != CURLM_OK)
439 {
440 curl_multi_cleanup (multi);
441 curl_easy_cleanup (c);
442 MHD_stop_daemon (d);
443 return 1024;
444 }
445 start = time (NULL);
446 while ((time (NULL) - start < 5) && (multi != NULL))
447 {
448 maxsock = MHD_INVALID_SOCKET;
449 maxposixs = -1;
450 FD_ZERO (&rs);
451 FD_ZERO (&ws);
452 FD_ZERO (&es);
453 curl_multi_perform (multi, &running);
454 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
455 if (mret != CURLM_OK)
423 { 456 {
457 curl_multi_remove_handle (multi, c);
458 curl_multi_cleanup (multi);
424 curl_easy_cleanup (c); 459 curl_easy_cleanup (c);
425 MHD_stop_daemon (d); 460 MHD_stop_daemon (d);
426 return 512; 461 return 2048;
427 } 462 }
428 mret = curl_multi_add_handle (multi, c); 463 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
429 if (mret != CURLM_OK)
430 { 464 {
465 curl_multi_remove_handle (multi, c);
431 curl_multi_cleanup (multi); 466 curl_multi_cleanup (multi);
432 curl_easy_cleanup (c); 467 curl_easy_cleanup (c);
433 MHD_stop_daemon (d); 468 MHD_stop_daemon (d);
434 return 1024; 469 return 4096;
435 } 470 }
436 start = time (NULL);
437 while ((time (NULL) - start < 5) && (multi != NULL))
438 {
439 maxsock = MHD_INVALID_SOCKET;
440 maxposixs = -1;
441 FD_ZERO (&rs);
442 FD_ZERO (&ws);
443 FD_ZERO (&es);
444 curl_multi_perform (multi, &running);
445 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
446 if (mret != CURLM_OK)
447 {
448 curl_multi_remove_handle (multi, c);
449 curl_multi_cleanup (multi);
450 curl_easy_cleanup (c);
451 MHD_stop_daemon (d);
452 return 2048;
453 }
454 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
455 {
456 curl_multi_remove_handle (multi, c);
457 curl_multi_cleanup (multi);
458 curl_easy_cleanup (c);
459 MHD_stop_daemon (d);
460 return 4096;
461 }
462#ifdef MHD_POSIX_SOCKETS 471#ifdef MHD_POSIX_SOCKETS
463 if (maxsock > maxposixs) 472 if (maxsock > maxposixs)
464 maxposixs = maxsock; 473 maxposixs = maxsock;
465#endif /* MHD_POSIX_SOCKETS */ 474#endif /* MHD_POSIX_SOCKETS */
466 tv.tv_sec = 0; 475 tv.tv_sec = 0;
467 tv.tv_usec = 1000; 476 tv.tv_usec = 1000;
468 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) 477 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
469 { 478 {
470#ifdef MHD_POSIX_SOCKETS 479#ifdef MHD_POSIX_SOCKETS
471 if (EINTR != errno) 480 if (EINTR != errno)
472 abort (); 481 abort ();
473#else 482#else
474 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 483 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
475 _exit (99); 484 ws.fd_count)
476 Sleep (1000); 485 ||(0 != es.fd_count) )
486 _exit (99);
487 Sleep (1000);
477#endif 488#endif
478 }
479 curl_multi_perform (multi, &running);
480 if (running == 0)
481 {
482 msg = curl_multi_info_read (multi, &running);
483 if (msg == NULL)
484 break;
485 if (msg->msg == CURLMSG_DONE)
486 {
487 if (msg->data.result != CURLE_OK)
488 printf ("%s failed at %s:%d: `%s'\n",
489 "curl_multi_perform",
490 __FILE__,
491 __LINE__, curl_easy_strerror (msg->data.result));
492 curl_multi_remove_handle (multi, c);
493 curl_multi_cleanup (multi);
494 curl_easy_cleanup (c);
495 c = NULL;
496 multi = NULL;
497 }
498 }
499 MHD_run (d);
500 } 489 }
501 if (multi != NULL) 490 curl_multi_perform (multi, &running);
491 if (running == 0)
502 { 492 {
503 curl_multi_remove_handle (multi, c); 493 msg = curl_multi_info_read (multi, &running);
504 curl_easy_cleanup (c); 494 if (msg == NULL)
505 curl_multi_cleanup (multi); 495 break;
496 if (msg->msg == CURLMSG_DONE)
497 {
498 if (msg->data.result != CURLE_OK)
499 printf ("%s failed at %s:%d: `%s'\n",
500 "curl_multi_perform",
501 __FILE__,
502 __LINE__, curl_easy_strerror (msg->data.result));
503 curl_multi_remove_handle (multi, c);
504 curl_multi_cleanup (multi);
505 curl_easy_cleanup (c);
506 c = NULL;
507 multi = NULL;
508 }
506 } 509 }
510 MHD_run (d);
511 }
512 if (multi != NULL)
513 {
514 curl_multi_remove_handle (multi, c);
515 curl_easy_cleanup (c);
516 curl_multi_cleanup (multi);
517 }
507 MHD_stop_daemon (d); 518 MHD_stop_daemon (d);
508 if (cbc.pos != strlen ("/hello_world")) 519 if (cbc.pos != strlen ("/hello_world"))
509 return 8192; 520 return 8192;
@@ -518,19 +529,19 @@ int
518main (int argc, char *const *argv) 529main (int argc, char *const *argv)
519{ 530{
520 unsigned int errorCount = 0; 531 unsigned int errorCount = 0;
521 (void)argc; /* Unused. Silent compiler warning. */ 532 (void) argc; /* Unused. Silent compiler warning. */
522 533
523 if (NULL == argv || 0 == argv[0]) 534 if ((NULL == argv)||(0 == argv[0]))
524 return 99; 535 return 99;
525 oneone = has_in_name (argv[0], "11"); 536 oneone = has_in_name (argv[0], "11");
526 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 537 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
527 return 2; 538 return 2;
528 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 539 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
529 { 540 {
530 errorCount += testInternalPut (); 541 errorCount += testInternalPut ();
531 errorCount += testMultithreadedPut (); 542 errorCount += testMultithreadedPut ();
532 errorCount += testMultithreadedPoolPut (); 543 errorCount += testMultithreadedPoolPut ();
533 } 544 }
534 errorCount += testExternalPut (); 545 errorCount += testExternalPut ();
535 if (errorCount != 0) 546 if (errorCount != 0)
536 fprintf (stderr, "Error (code: %u)\n", errorCount); 547 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c
index 9f875a40..6374f4a7 100644
--- a/src/testcurl/test_put_chunked.c
+++ b/src/testcurl/test_put_chunked.c
@@ -37,10 +37,10 @@
37#include <unistd.h> 37#include <unistd.h>
38#endif 38#endif
39 39
40#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 40#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
41#undef CPU_COUNT 41#undef CPU_COUNT
42#endif 42#endif
43#if !defined(CPU_COUNT) 43#if ! defined(CPU_COUNT)
44#define CPU_COUNT 2 44#define CPU_COUNT 2
45#endif 45#endif
46 46
@@ -92,38 +92,38 @@ ahc_echo (void *cls,
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 int have; 94 int have;
95 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 95 (void) version; (void) unused; /* Unused. Silent compiler warning. */
96 96
97 if (0 != strcmp ("PUT", method)) 97 if (0 != strcmp ("PUT", method))
98 return MHD_NO; /* unexpected method */ 98 return MHD_NO; /* unexpected method */
99 if ((*done) < 8) 99 if ((*done) < 8)
100 {
101 have = *upload_data_size;
102 if (have + *done > 8)
100 { 103 {
101 have = *upload_data_size; 104 printf ("Invalid upload data `%8s'!\n", upload_data);
102 if (have + *done > 8) 105 return MHD_NO;
103 { 106 }
104 printf ("Invalid upload data `%8s'!\n", upload_data); 107 if (0 == have)
105 return MHD_NO;
106 }
107 if (0 == have)
108 return MHD_YES;
109 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
110 {
111 *done += have;
112 *upload_data_size = 0;
113 }
114 else
115 {
116 printf ("Invalid upload data `%8s'!\n", upload_data);
117 return MHD_NO;
118 }
119#if 0
120 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
121#endif
122 return MHD_YES; 108 return MHD_YES;
109 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
110 {
111 *done += have;
112 *upload_data_size = 0;
113 }
114 else
115 {
116 printf ("Invalid upload data `%8s'!\n", upload_data);
117 return MHD_NO;
123 } 118 }
119#if 0
120 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
121#endif
122 return MHD_YES;
123 }
124 response = MHD_create_response_from_buffer (strlen (url), 124 response = MHD_create_response_from_buffer (strlen (url),
125 (void *) url, 125 (void *) url,
126 MHD_RESPMEM_MUST_COPY); 126 MHD_RESPMEM_MUST_COPY);
127 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 127 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
128 MHD_destroy_response (response); 128 MHD_destroy_response (response);
129 return ret; 129 return ret;
@@ -156,16 +156,18 @@ testInternalPut ()
156 if (d == NULL) 156 if (d == NULL)
157 return 1; 157 return 1;
158 if (0 == port) 158 if (0 == port)
159 {
160 const union MHD_DaemonInfo *dinfo;
161 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
162 if ((NULL == dinfo) ||(0 == dinfo->port) )
159 { 163 {
160 const union MHD_DaemonInfo *dinfo; 164 MHD_stop_daemon (d); return 32;
161 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
162 if (NULL == dinfo || 0 == dinfo->port)
163 { MHD_stop_daemon (d); return 32; }
164 port = (int)dinfo->port;
165 } 165 }
166 port = (int) dinfo->port;
167 }
166 c = curl_easy_init (); 168 c = curl_easy_init ();
167 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 169 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
168 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 170 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
169 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 171 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
170 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 172 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
171 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 173 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -184,14 +186,14 @@ testInternalPut ()
184 * crashes on my system! */ 186 * crashes on my system! */
185 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 187 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
186 if (CURLE_OK != (errornum = curl_easy_perform (c))) 188 if (CURLE_OK != (errornum = curl_easy_perform (c)))
187 { 189 {
188 fprintf (stderr, 190 fprintf (stderr,
189 "curl_easy_perform failed: `%s'\n", 191 "curl_easy_perform failed: `%s'\n",
190 curl_easy_strerror (errornum)); 192 curl_easy_strerror (errornum));
191 curl_easy_cleanup (c); 193 curl_easy_cleanup (c);
192 MHD_stop_daemon (d); 194 MHD_stop_daemon (d);
193 return 2; 195 return 2;
194 } 196 }
195 curl_easy_cleanup (c); 197 curl_easy_cleanup (c);
196 MHD_stop_daemon (d); 198 MHD_stop_daemon (d);
197 if (cbc.pos != strlen ("/hello_world")) 199 if (cbc.pos != strlen ("/hello_world"))
@@ -221,22 +223,25 @@ testMultithreadedPut ()
221 cbc.buf = buf; 223 cbc.buf = buf;
222 cbc.size = 2048; 224 cbc.size = 2048;
223 cbc.pos = 0; 225 cbc.pos = 0;
224 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 226 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
227 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
225 port, 228 port,
226 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 229 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
227 if (d == NULL) 230 if (d == NULL)
228 return 16; 231 return 16;
229 if (0 == port) 232 if (0 == port)
233 {
234 const union MHD_DaemonInfo *dinfo;
235 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
236 if ((NULL == dinfo) ||(0 == dinfo->port) )
230 { 237 {
231 const union MHD_DaemonInfo *dinfo; 238 MHD_stop_daemon (d); return 32;
232 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
233 if (NULL == dinfo || 0 == dinfo->port)
234 { MHD_stop_daemon (d); return 32; }
235 port = (int)dinfo->port;
236 } 239 }
240 port = (int) dinfo->port;
241 }
237 c = curl_easy_init (); 242 c = curl_easy_init ();
238 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 243 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
239 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 244 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
240 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 245 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
241 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 246 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
242 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 247 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -255,14 +260,14 @@ testMultithreadedPut ()
255 * crashes on my system! */ 260 * crashes on my system! */
256 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 261 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
257 if (CURLE_OK != (errornum = curl_easy_perform (c))) 262 if (CURLE_OK != (errornum = curl_easy_perform (c)))
258 { 263 {
259 fprintf (stderr, 264 fprintf (stderr,
260 "curl_easy_perform failed: `%s'\n", 265 "curl_easy_perform failed: `%s'\n",
261 curl_easy_strerror (errornum)); 266 curl_easy_strerror (errornum));
262 curl_easy_cleanup (c); 267 curl_easy_cleanup (c);
263 MHD_stop_daemon (d); 268 MHD_stop_daemon (d);
264 return 32; 269 return 32;
265 } 270 }
266 curl_easy_cleanup (c); 271 curl_easy_cleanup (c);
267 MHD_stop_daemon (d); 272 MHD_stop_daemon (d);
268 if (cbc.pos != strlen ("/hello_world")) 273 if (cbc.pos != strlen ("/hello_world"))
@@ -300,16 +305,18 @@ testMultithreadedPoolPut ()
300 if (d == NULL) 305 if (d == NULL)
301 return 16; 306 return 16;
302 if (0 == port) 307 if (0 == port)
308 {
309 const union MHD_DaemonInfo *dinfo;
310 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
311 if ((NULL == dinfo) ||(0 == dinfo->port) )
303 { 312 {
304 const union MHD_DaemonInfo *dinfo; 313 MHD_stop_daemon (d); return 32;
305 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
306 if (NULL == dinfo || 0 == dinfo->port)
307 { MHD_stop_daemon (d); return 32; }
308 port = (int)dinfo->port;
309 } 314 }
315 port = (int) dinfo->port;
316 }
310 c = curl_easy_init (); 317 c = curl_easy_init ();
311 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 318 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
312 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 319 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
313 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 320 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
314 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 321 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
315 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 322 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -328,14 +335,14 @@ testMultithreadedPoolPut ()
328 * crashes on my system! */ 335 * crashes on my system! */
329 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 336 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
330 if (CURLE_OK != (errornum = curl_easy_perform (c))) 337 if (CURLE_OK != (errornum = curl_easy_perform (c)))
331 { 338 {
332 fprintf (stderr, 339 fprintf (stderr,
333 "curl_easy_perform failed: `%s'\n", 340 "curl_easy_perform failed: `%s'\n",
334 curl_easy_strerror (errornum)); 341 curl_easy_strerror (errornum));
335 curl_easy_cleanup (c); 342 curl_easy_cleanup (c);
336 MHD_stop_daemon (d); 343 MHD_stop_daemon (d);
337 return 32; 344 return 32;
338 } 345 }
339 curl_easy_cleanup (c); 346 curl_easy_cleanup (c);
340 MHD_stop_daemon (d); 347 MHD_stop_daemon (d);
341 if (cbc.pos != strlen ("/hello_world")) 348 if (cbc.pos != strlen ("/hello_world"))
@@ -388,16 +395,18 @@ testExternalPut ()
388 if (d == NULL) 395 if (d == NULL)
389 return 256; 396 return 256;
390 if (0 == port) 397 if (0 == port)
398 {
399 const union MHD_DaemonInfo *dinfo;
400 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
401 if ((NULL == dinfo) ||(0 == dinfo->port) )
391 { 402 {
392 const union MHD_DaemonInfo *dinfo; 403 MHD_stop_daemon (d); return 32;
393 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
394 if (NULL == dinfo || 0 == dinfo->port)
395 { MHD_stop_daemon (d); return 32; }
396 port = (int)dinfo->port;
397 } 404 }
405 port = (int) dinfo->port;
406 }
398 c = curl_easy_init (); 407 c = curl_easy_init ();
399 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 408 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
400 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 409 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
401 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 410 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
402 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 411 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
403 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 412 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -419,87 +428,89 @@ testExternalPut ()
419 428
420 multi = curl_multi_init (); 429 multi = curl_multi_init ();
421 if (multi == NULL) 430 if (multi == NULL)
431 {
432 curl_easy_cleanup (c);
433 MHD_stop_daemon (d);
434 return 512;
435 }
436 mret = curl_multi_add_handle (multi, c);
437 if (mret != CURLM_OK)
438 {
439 curl_multi_cleanup (multi);
440 curl_easy_cleanup (c);
441 MHD_stop_daemon (d);
442 return 1024;
443 }
444 start = time (NULL);
445 while ((time (NULL) - start < 5) && (multi != NULL))
446 {
447 maxsock = MHD_INVALID_SOCKET;
448 maxposixs = -1;
449 FD_ZERO (&rs);
450 FD_ZERO (&ws);
451 FD_ZERO (&es);
452 curl_multi_perform (multi, &running);
453 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
454 if (mret != CURLM_OK)
422 { 455 {
456 curl_multi_remove_handle (multi, c);
457 curl_multi_cleanup (multi);
423 curl_easy_cleanup (c); 458 curl_easy_cleanup (c);
424 MHD_stop_daemon (d); 459 MHD_stop_daemon (d);
425 return 512; 460 return 2048;
426 } 461 }
427 mret = curl_multi_add_handle (multi, c); 462 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
428 if (mret != CURLM_OK)
429 { 463 {
464 curl_multi_remove_handle (multi, c);
430 curl_multi_cleanup (multi); 465 curl_multi_cleanup (multi);
431 curl_easy_cleanup (c); 466 curl_easy_cleanup (c);
432 MHD_stop_daemon (d); 467 MHD_stop_daemon (d);
433 return 1024; 468 return 4096;
434 } 469 }
435 start = time (NULL); 470 tv.tv_sec = 0;
436 while ((time (NULL) - start < 5) && (multi != NULL)) 471 tv.tv_usec = 1000;
472 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
437 { 473 {
438 maxsock = MHD_INVALID_SOCKET;
439 maxposixs = -1;
440 FD_ZERO (&rs);
441 FD_ZERO (&ws);
442 FD_ZERO (&es);
443 curl_multi_perform (multi, &running);
444 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
445 if (mret != CURLM_OK)
446 {
447 curl_multi_remove_handle (multi, c);
448 curl_multi_cleanup (multi);
449 curl_easy_cleanup (c);
450 MHD_stop_daemon (d);
451 return 2048;
452 }
453 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
454 {
455 curl_multi_remove_handle (multi, c);
456 curl_multi_cleanup (multi);
457 curl_easy_cleanup (c);
458 MHD_stop_daemon (d);
459 return 4096;
460 }
461 tv.tv_sec = 0;
462 tv.tv_usec = 1000;
463 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
464 {
465#ifdef MHD_POSIX_SOCKETS 474#ifdef MHD_POSIX_SOCKETS
466 if (EINTR != errno) 475 if (EINTR != errno)
467 abort (); 476 abort ();
468#else 477#else
469 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 478 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
470 abort (); 479 ws.fd_count)
471 Sleep (1000); 480 ||(0 != es.fd_count) )
481 abort ();
482 Sleep (1000);
472#endif 483#endif
473 }
474 curl_multi_perform (multi, &running);
475 if (running == 0)
476 {
477 msg = curl_multi_info_read (multi, &running);
478 if (msg == NULL)
479 break;
480 if (msg->msg == CURLMSG_DONE)
481 {
482 if (msg->data.result != CURLE_OK)
483 printf ("%s failed at %s:%d: `%s'\n",
484 "curl_multi_perform",
485 __FILE__,
486 __LINE__,
487 curl_easy_strerror (msg->data.result));
488 curl_multi_remove_handle (multi, c);
489 curl_multi_cleanup (multi);
490 curl_easy_cleanup (c);
491 c = NULL;
492 multi = NULL;
493 }
494 }
495 MHD_run (d);
496 } 484 }
497 if (multi != NULL) 485 curl_multi_perform (multi, &running);
486 if (running == 0)
498 { 487 {
499 curl_multi_remove_handle (multi, c); 488 msg = curl_multi_info_read (multi, &running);
500 curl_easy_cleanup (c); 489 if (msg == NULL)
501 curl_multi_cleanup (multi); 490 break;
491 if (msg->msg == CURLMSG_DONE)
492 {
493 if (msg->data.result != CURLE_OK)
494 printf ("%s failed at %s:%d: `%s'\n",
495 "curl_multi_perform",
496 __FILE__,
497 __LINE__,
498 curl_easy_strerror (msg->data.result));
499 curl_multi_remove_handle (multi, c);
500 curl_multi_cleanup (multi);
501 curl_easy_cleanup (c);
502 c = NULL;
503 multi = NULL;
504 }
502 } 505 }
506 MHD_run (d);
507 }
508 if (multi != NULL)
509 {
510 curl_multi_remove_handle (multi, c);
511 curl_easy_cleanup (c);
512 curl_multi_cleanup (multi);
513 }
503 MHD_stop_daemon (d); 514 MHD_stop_daemon (d);
504 if (cbc.pos != strlen ("/hello_world")) 515 if (cbc.pos != strlen ("/hello_world"))
505 return 8192; 516 return 8192;
@@ -514,16 +525,16 @@ int
514main (int argc, char *const *argv) 525main (int argc, char *const *argv)
515{ 526{
516 unsigned int errorCount = 0; 527 unsigned int errorCount = 0;
517 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 528 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
518 529
519 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 530 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
520 return 2; 531 return 2;
521 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 532 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
522 { 533 {
523 errorCount += testInternalPut (); 534 errorCount += testInternalPut ();
524 errorCount += testMultithreadedPut (); 535 errorCount += testMultithreadedPut ();
525 errorCount += testMultithreadedPoolPut (); 536 errorCount += testMultithreadedPoolPut ();
526 } 537 }
527 errorCount += testExternalPut (); 538 errorCount += testExternalPut ();
528 if (errorCount != 0) 539 if (errorCount != 0)
529 fprintf (stderr, "Error (code: %u)\n", errorCount); 540 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index 69b07618..c42880ce 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -40,10 +40,10 @@
40#include <sys/socket.h> 40#include <sys/socket.h>
41#endif 41#endif
42 42
43#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 43#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
44#undef CPU_COUNT 44#undef CPU_COUNT
45#endif 45#endif
46#if !defined(CPU_COUNT) 46#if ! defined(CPU_COUNT)
47#define CPU_COUNT 2 47#define CPU_COUNT 2
48#endif 48#endif
49 49
@@ -83,19 +83,19 @@ ahc_echo (void *cls,
83 const char *me = cls; 83 const char *me = cls;
84 struct MHD_Response *response; 84 struct MHD_Response *response;
85 int ret; 85 int ret;
86 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 86 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
87 87
88 if (0 != strcmp (me, method)) 88 if (0 != strcmp (me, method))
89 return MHD_NO; /* unexpected method */ 89 return MHD_NO; /* unexpected method */
90 if (&ptr != *unused) 90 if (&ptr != *unused)
91 { 91 {
92 *unused = &ptr; 92 *unused = &ptr;
93 return MHD_YES; 93 return MHD_YES;
94 } 94 }
95 *unused = NULL; 95 *unused = NULL;
96 response = MHD_create_response_from_buffer (strlen (url), 96 response = MHD_create_response_from_buffer (strlen (url),
97 (void *) url, 97 (void *) url,
98 MHD_RESPMEM_MUST_COPY); 98 MHD_RESPMEM_MUST_COPY);
99 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 99 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
100 MHD_destroy_response (response); 100 MHD_destroy_response (response);
101 if (ret == MHD_NO) 101 if (ret == MHD_NO)
@@ -106,16 +106,16 @@ ahc_echo (void *cls,
106 106
107static void 107static void
108request_completed (void *cls, struct MHD_Connection *connection, 108request_completed (void *cls, struct MHD_Connection *connection,
109 void **con_cls, enum MHD_RequestTerminationCode code) 109 void **con_cls, enum MHD_RequestTerminationCode code)
110{ 110{
111 (void)connection;(void)con_cls;(void)code; /* Unused. Silent compiler warning. */ 111 (void) connection; (void) con_cls; (void) code; /* Unused. Silent compiler warning. */
112 int *done = (int *)cls; 112 int *done = (int *) cls;
113 *done = 1; 113 *done = 1;
114} 114}
115 115
116 116
117static void * 117static void *
118ServeOneRequest(void *param) 118ServeOneRequest (void *param)
119{ 119{
120 struct MHD_Daemon *d; 120 struct MHD_Daemon *d;
121 fd_set rs; 121 fd_set rs;
@@ -138,38 +138,40 @@ ServeOneRequest(void *param)
138 138
139 start = time (NULL); 139 start = time (NULL);
140 while ((time (NULL) - start < 5) && done == 0) 140 while ((time (NULL) - start < 5) && done == 0)
141 {
142 max = 0;
143 FD_ZERO (&rs);
144 FD_ZERO (&ws);
145 FD_ZERO (&es);
146 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
147 {
148 MHD_stop_daemon (d);
149 MHD_socket_close_chk_ (fd);
150 return "MHD_get_fdset() failed";
151 }
152 tv.tv_sec = 0;
153 tv.tv_usec = 1000;
154 if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv))
141 { 155 {
142 max = 0;
143 FD_ZERO (&rs);
144 FD_ZERO (&ws);
145 FD_ZERO (&es);
146 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
147 {
148 MHD_stop_daemon (d);
149 MHD_socket_close_chk_(fd);
150 return "MHD_get_fdset() failed";
151 }
152 tv.tv_sec = 0;
153 tv.tv_usec = 1000;
154 if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv))
155 {
156#ifdef MHD_POSIX_SOCKETS 156#ifdef MHD_POSIX_SOCKETS
157 if (EINTR != errno) 157 if (EINTR != errno)
158 abort (); 158 abort ();
159#else 159#else
160 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 160 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
161 abort (); 161 ws.fd_count)
162 Sleep (1000); 162 ||(0 != es.fd_count) )
163 abort ();
164 Sleep (1000);
163#endif 165#endif
164 }
165 MHD_run (d);
166 } 166 }
167 MHD_run (d);
168 }
167 fd = MHD_quiesce_daemon (d); 169 fd = MHD_quiesce_daemon (d);
168 if (MHD_INVALID_SOCKET == fd) 170 if (MHD_INVALID_SOCKET == fd)
169 { 171 {
170 MHD_stop_daemon (d); 172 MHD_stop_daemon (d);
171 return "MHD_quiesce_daemon() failed in ServeOneRequest()"; 173 return "MHD_quiesce_daemon() failed in ServeOneRequest()";
172 } 174 }
173 MHD_stop_daemon (d); 175 MHD_stop_daemon (d);
174 return done ? NULL : "Requests was not served by ServeOneRequest()"; 176 return done ? NULL : "Requests was not served by ServeOneRequest()";
175} 177}
@@ -182,7 +184,7 @@ setupCURL (void *cbc)
182 184
183 c = curl_easy_init (); 185 c = curl_easy_init ();
184 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 186 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
185 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 187 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
186 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 188 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
187 curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc); 189 curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc);
188 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 190 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -218,44 +220,51 @@ testGet (int type, int pool_count, int poll_flag)
218 cbc.buf = buf; 220 cbc.buf = buf;
219 cbc.size = 2048; 221 cbc.size = 2048;
220 cbc.pos = 0; 222 cbc.pos = 0;
221 if (pool_count > 0) { 223 if (pool_count > 0)
224 {
222 d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, 225 d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag,
223 port, NULL, NULL, &ahc_echo, "GET", 226 port, NULL, NULL, &ahc_echo, "GET",
224 MHD_OPTION_THREAD_POOL_SIZE, pool_count, MHD_OPTION_END); 227 MHD_OPTION_THREAD_POOL_SIZE, pool_count,
228 MHD_OPTION_END);
225 229
226 } else { 230 }
231 else {
227 d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, 232 d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag,
228 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 233 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
229 } 234 }
230 if (d == NULL) 235 if (d == NULL)
231 return 1; 236 return 1;
232 if (0 == port) 237 if (0 == port)
238 {
239 const union MHD_DaemonInfo *dinfo;
240 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
241 if ((NULL == dinfo) ||(0 == dinfo->port) )
233 { 242 {
234 const union MHD_DaemonInfo *dinfo; 243 MHD_stop_daemon (d); return 32;
235 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
236 if (NULL == dinfo || 0 == dinfo->port)
237 { MHD_stop_daemon (d); return 32; }
238 port = (int)dinfo->port;
239 } 244 }
245 port = (int) dinfo->port;
246 }
240 247
241 c = setupCURL(&cbc); 248 c = setupCURL (&cbc);
242 249
243 if (CURLE_OK != (errornum = curl_easy_perform (c))) 250 if (CURLE_OK != (errornum = curl_easy_perform (c)))
244 { 251 {
245 fprintf (stderr, 252 fprintf (stderr,
246 "curl_easy_perform failed: `%s'\n", 253 "curl_easy_perform failed: `%s'\n",
247 curl_easy_strerror (errornum)); 254 curl_easy_strerror (errornum));
248 curl_easy_cleanup (c); 255 curl_easy_cleanup (c);
249 MHD_stop_daemon (d); 256 MHD_stop_daemon (d);
250 return 2; 257 return 2;
251 } 258 }
252 259
253 if (cbc.pos != strlen ("/hello_world")) { 260 if (cbc.pos != strlen ("/hello_world"))
261 {
254 curl_easy_cleanup (c); 262 curl_easy_cleanup (c);
255 MHD_stop_daemon (d); 263 MHD_stop_daemon (d);
256 return 4; 264 return 4;
257 } 265 }
258 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) { 266 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
267 {
259 curl_easy_cleanup (c); 268 curl_easy_cleanup (c);
260 MHD_stop_daemon (d); 269 MHD_stop_daemon (d);
261 return 8; 270 return 8;
@@ -263,78 +272,79 @@ testGet (int type, int pool_count, int poll_flag)
263 272
264 fd = MHD_quiesce_daemon (d); 273 fd = MHD_quiesce_daemon (d);
265 if (MHD_INVALID_SOCKET == fd) 274 if (MHD_INVALID_SOCKET == fd)
266 { 275 {
267 fprintf (stderr, 276 fprintf (stderr,
268 "MHD_quiesce_daemon failed.\n"); 277 "MHD_quiesce_daemon failed.\n");
269 curl_easy_cleanup (c); 278 curl_easy_cleanup (c);
270 MHD_stop_daemon (d); 279 MHD_stop_daemon (d);
271 return 2; 280 return 2;
272 } 281 }
273 if (0 != pthread_create(&thrd, NULL, &ServeOneRequest, (void*)(intptr_t) fd)) 282 if (0 != pthread_create (&thrd, NULL, &ServeOneRequest,
274 { 283 (void*) (intptr_t) fd))
275 fprintf (stderr, "pthread_create failed\n"); 284 {
276 curl_easy_cleanup (c); 285 fprintf (stderr, "pthread_create failed\n");
277 MHD_stop_daemon (d); 286 curl_easy_cleanup (c);
278 return 16; 287 MHD_stop_daemon (d);
279 } 288 return 16;
289 }
280 290
281 cbc.pos = 0; 291 cbc.pos = 0;
282 if (CURLE_OK != (errornum = curl_easy_perform (c))) 292 if (CURLE_OK != (errornum = curl_easy_perform (c)))
283 { 293 {
284 fprintf (stderr, 294 fprintf (stderr,
285 "curl_easy_perform failed: `%s'\n", 295 "curl_easy_perform failed: `%s'\n",
286 curl_easy_strerror (errornum)); 296 curl_easy_strerror (errornum));
287 curl_easy_cleanup (c); 297 curl_easy_cleanup (c);
288 MHD_stop_daemon (d); 298 MHD_stop_daemon (d);
289 return 2; 299 return 2;
290 } 300 }
291 301
292 if (0 != pthread_join(thrd, (void**)&thrdRet)) 302 if (0 != pthread_join (thrd, (void**) &thrdRet))
293 { 303 {
294 fprintf (stderr, "pthread_join failed\n"); 304 fprintf (stderr, "pthread_join failed\n");
295 curl_easy_cleanup (c); 305 curl_easy_cleanup (c);
296 MHD_stop_daemon (d); 306 MHD_stop_daemon (d);
297 return 16; 307 return 16;
298 } 308 }
299 if (NULL != thrdRet) 309 if (NULL != thrdRet)
300 { 310 {
301 fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet); 311 fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet);
302 curl_easy_cleanup (c); 312 curl_easy_cleanup (c);
303 MHD_stop_daemon (d); 313 MHD_stop_daemon (d);
304 return 16; 314 return 16;
305 } 315 }
306 316
307 if (cbc.pos != strlen ("/hello_world")) 317 if (cbc.pos != strlen ("/hello_world"))
308 { 318 {
309 fprintf(stderr, "%s\n", cbc.buf); 319 fprintf (stderr, "%s\n", cbc.buf);
310 curl_easy_cleanup (c); 320 curl_easy_cleanup (c);
311 MHD_stop_daemon (d); 321 MHD_stop_daemon (d);
312 MHD_socket_close_chk_(fd); 322 MHD_socket_close_chk_ (fd);
313 return 4; 323 return 4;
314 } 324 }
315 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 325 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
316 { 326 {
317 fprintf(stderr, "%s\n", cbc.buf); 327 fprintf (stderr, "%s\n", cbc.buf);
318 curl_easy_cleanup (c); 328 curl_easy_cleanup (c);
319 MHD_stop_daemon (d); 329 MHD_stop_daemon (d);
320 MHD_socket_close_chk_(fd); 330 MHD_socket_close_chk_ (fd);
321 return 8; 331 return 8;
322 } 332 }
323 333
324 /* at this point, the forked server quit, and the new 334 /* at this point, the forked server quit, and the new
325 * server has quiesced, so new requests should fail 335 * server has quiesced, so new requests should fail
326 */ 336 */
327 if (CURLE_OK == (errornum = curl_easy_perform (c))) 337 if (CURLE_OK == (errornum = curl_easy_perform (c)))
328 { 338 {
329 fprintf (stderr, "curl_easy_perform should fail\n"); 339 fprintf (stderr, "curl_easy_perform should fail\n");
330 curl_easy_cleanup (c); 340 curl_easy_cleanup (c);
331 MHD_stop_daemon (d); 341 MHD_stop_daemon (d);
332 MHD_socket_close_chk_(fd); 342 MHD_socket_close_chk_ (fd);
333 return 2; 343 return 2;
334 } 344 }
335 curl_easy_cleanup (c); 345 curl_easy_cleanup (c);
336 MHD_stop_daemon (d); 346 MHD_stop_daemon (d);
337 MHD_socket_close_chk_(fd); 347 MHD_socket_close_chk_ (fd);
338 348
339 return 0; 349 return 0;
340} 350}
@@ -382,136 +392,141 @@ testExternalGet ()
382 if (d == NULL) 392 if (d == NULL)
383 return 256; 393 return 256;
384 if (0 == port) 394 if (0 == port)
395 {
396 const union MHD_DaemonInfo *dinfo;
397 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
398 if ((NULL == dinfo) ||(0 == dinfo->port) )
385 { 399 {
386 const union MHD_DaemonInfo *dinfo; 400 MHD_stop_daemon (d); return 32;
387 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
388 if (NULL == dinfo || 0 == dinfo->port)
389 { MHD_stop_daemon (d); return 32; }
390 port = (int)dinfo->port;
391 } 401 }
392 c = setupCURL(&cbc); 402 port = (int) dinfo->port;
403 }
404 c = setupCURL (&cbc);
393 405
394 multi = curl_multi_init (); 406 multi = curl_multi_init ();
395 if (multi == NULL) 407 if (multi == NULL)
396 { 408 {
397 curl_easy_cleanup (c); 409 curl_easy_cleanup (c);
398 MHD_stop_daemon (d); 410 MHD_stop_daemon (d);
399 return 512; 411 return 512;
400 } 412 }
401 mret = curl_multi_add_handle (multi, c); 413 mret = curl_multi_add_handle (multi, c);
402 if (mret != CURLM_OK) 414 if (mret != CURLM_OK)
403 { 415 {
404 curl_multi_cleanup (multi); 416 curl_multi_cleanup (multi);
405 curl_easy_cleanup (c); 417 curl_easy_cleanup (c);
406 MHD_stop_daemon (d); 418 MHD_stop_daemon (d);
407 return 1024; 419 return 1024;
408 } 420 }
409 421
410 for (i = 0; i < 2; i++) 422 for (i = 0; i < 2; i++)
423 {
424 start = time (NULL);
425 while ( (time (NULL) - start < 5) &&
426 (NULL != multi) )
411 { 427 {
412 start = time (NULL); 428 maxsock = MHD_INVALID_SOCKET;
413 while ( (time (NULL) - start < 5) && 429 maxposixs = -1;
414 (NULL != multi) ) 430 FD_ZERO (&rs);
415 { 431 FD_ZERO (&ws);
416 maxsock = MHD_INVALID_SOCKET; 432 FD_ZERO (&es);
417 maxposixs = -1; 433 curl_multi_perform (multi, &running);
418 FD_ZERO (&rs); 434 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
419 FD_ZERO (&ws); 435 if (mret != CURLM_OK)
420 FD_ZERO (&es); 436 {
421 curl_multi_perform (multi, &running); 437 curl_multi_remove_handle (multi, c);
422 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); 438 curl_multi_cleanup (multi);
423 if (mret != CURLM_OK) 439 curl_easy_cleanup (c);
424 { 440 MHD_stop_daemon (d);
425 curl_multi_remove_handle (multi, c); 441 return 2048;
426 curl_multi_cleanup (multi); 442 }
427 curl_easy_cleanup (c); 443 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
428 MHD_stop_daemon (d); 444 {
429 return 2048; 445 curl_multi_remove_handle (multi, c);
430 } 446 curl_multi_cleanup (multi);
431 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) 447 curl_easy_cleanup (c);
432 { 448 MHD_stop_daemon (d);
433 curl_multi_remove_handle (multi, c); 449 return 4096;
434 curl_multi_cleanup (multi); 450 }
435 curl_easy_cleanup (c); 451 tv.tv_sec = 0;
436 MHD_stop_daemon (d); 452 tv.tv_usec = 1000;
437 return 4096; 453 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
438 } 454 {
439 tv.tv_sec = 0;
440 tv.tv_usec = 1000;
441 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
442 {
443#ifdef MHD_POSIX_SOCKETS 455#ifdef MHD_POSIX_SOCKETS
444 if (EINTR != errno) 456 if (EINTR != errno)
445 abort (); 457 abort ();
446#else 458#else
447 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 459 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
448 abort (); 460 ws.
449 Sleep (1000); 461 fd_count)
462 ||(0 != es.fd_count) )
463 abort ();
464 Sleep (1000);
450#endif 465#endif
451 } 466 }
452 curl_multi_perform (multi, &running); 467 curl_multi_perform (multi, &running);
453 if (0 == running) 468 if (0 == running)
454 { 469 {
455 msg = curl_multi_info_read (multi, &running); 470 msg = curl_multi_info_read (multi, &running);
456 if (NULL == msg) 471 if (NULL == msg)
457 break; 472 break;
458 if (msg->msg == CURLMSG_DONE) 473 if (msg->msg == CURLMSG_DONE)
459 {
460 if (i == 0 && msg->data.result != CURLE_OK)
461 printf ("%s failed at %s:%d: `%s'\n",
462 "curl_multi_perform",
463 __FILE__,
464 __LINE__,
465 curl_easy_strerror (msg->data.result));
466 else if ( (i == 1) &&
467 (msg->data.result == CURLE_OK) )
468 printf ("%s should have failed at %s:%d\n",
469 "curl_multi_perform",
470 __FILE__,
471 __LINE__);
472 curl_multi_remove_handle (multi, c);
473 curl_multi_cleanup (multi);
474 curl_easy_cleanup (c);
475 c = NULL;
476 multi = NULL;
477 }
478 }
479 MHD_run (d);
480 }
481
482 if (0 == i)
483 { 474 {
484 /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ 475 if ((i == 0) &&(msg->data.result != CURLE_OK) )
485 fd = MHD_quiesce_daemon(d); 476 printf ("%s failed at %s:%d: `%s'\n",
486 if (MHD_INVALID_SOCKET == fd) 477 "curl_multi_perform",
487 { 478 __FILE__,
488 fprintf (stderr, 479 __LINE__,
489 "MHD_quiesce_daemon failed.\n"); 480 curl_easy_strerror (msg->data.result));
490 curl_multi_remove_handle (multi, c); 481 else if ( (i == 1) &&
491 curl_multi_cleanup (multi); 482 (msg->data.result == CURLE_OK) )
492 curl_easy_cleanup (c); 483 printf ("%s should have failed at %s:%d\n",
493 MHD_stop_daemon (d); 484 "curl_multi_perform",
494 return 2; 485 __FILE__,
495 } 486 __LINE__);
496 c = setupCURL (&cbc); 487 curl_multi_remove_handle (multi, c);
497 multi = curl_multi_init (); 488 curl_multi_cleanup (multi);
498 mret = curl_multi_add_handle (multi, c); 489 curl_easy_cleanup (c);
499 if (mret != CURLM_OK) 490 c = NULL;
500 { 491 multi = NULL;
501 curl_multi_remove_handle (multi, c);
502 curl_multi_cleanup (multi);
503 curl_easy_cleanup (c);
504 MHD_stop_daemon (d);
505 return 32768;
506 }
507 } 492 }
493 }
494 MHD_run (d);
508 } 495 }
509 if (NULL != multi) 496
497 if (0 == i)
510 { 498 {
511 curl_multi_remove_handle (multi, c); 499 /* quiesce the daemon on the 1st iteration, so the 2nd should fail */
512 curl_easy_cleanup (c); 500 fd = MHD_quiesce_daemon (d);
513 curl_multi_cleanup (multi); 501 if (MHD_INVALID_SOCKET == fd)
502 {
503 fprintf (stderr,
504 "MHD_quiesce_daemon failed.\n");
505 curl_multi_remove_handle (multi, c);
506 curl_multi_cleanup (multi);
507 curl_easy_cleanup (c);
508 MHD_stop_daemon (d);
509 return 2;
510 }
511 c = setupCURL (&cbc);
512 multi = curl_multi_init ();
513 mret = curl_multi_add_handle (multi, c);
514 if (mret != CURLM_OK)
515 {
516 curl_multi_remove_handle (multi, c);
517 curl_multi_cleanup (multi);
518 curl_easy_cleanup (c);
519 MHD_stop_daemon (d);
520 return 32768;
521 }
514 } 522 }
523 }
524 if (NULL != multi)
525 {
526 curl_multi_remove_handle (multi, c);
527 curl_easy_cleanup (c);
528 curl_multi_cleanup (multi);
529 }
515 MHD_stop_daemon (d); 530 MHD_stop_daemon (d);
516 MHD_socket_close_chk_ (fd); 531 MHD_socket_close_chk_ (fd);
517 if (cbc.pos != strlen ("/hello_world")) 532 if (cbc.pos != strlen ("/hello_world"))
@@ -526,32 +541,37 @@ int
526main (int argc, char *const *argv) 541main (int argc, char *const *argv)
527{ 542{
528 unsigned int errorCount = 0; 543 unsigned int errorCount = 0;
529 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 544 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
530 545
531 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 546 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
532 return 2; 547 return 2;
533 errorCount += testExternalGet (); 548 errorCount += testExternalGet ();
534 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 549 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
550 {
551 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0);
552 errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION
553 | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0);
554 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0);
555 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
535 { 556 {
536 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); 557 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL);
537 errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); 558 errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION
538 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0); 559 | MHD_USE_INTERNAL_POLLING_THREAD, 0,
539 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) 560 MHD_USE_POLL);
540 { 561 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT,
541 errorCount += testGet(MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); 562 MHD_USE_POLL);
542 errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL);
543 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_POLL);
544 }
545 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
546 {
547 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL);
548 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_EPOLL);
549 }
550 } 563 }
564 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
565 {
566 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL);
567 errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT,
568 MHD_USE_EPOLL);
569 }
570 }
551 if (0 != errorCount) 571 if (0 != errorCount)
552 fprintf (stderr, 572 fprintf (stderr,
553 "Error (code: %u)\n", 573 "Error (code: %u)\n",
554 errorCount); 574 errorCount);
555 curl_global_cleanup (); 575 curl_global_cleanup ();
556 return errorCount != 0; /* 0 == pass */ 576 return errorCount != 0; /* 0 == pass */
557} 577}
diff --git a/src/testcurl/test_quiesce_stream.c b/src/testcurl/test_quiesce_stream.c
index bccb5890..821f1102 100644
--- a/src/testcurl/test_quiesce_stream.c
+++ b/src/testcurl/test_quiesce_stream.c
@@ -35,7 +35,7 @@
35#include <unistd.h> 35#include <unistd.h>
36#elif defined(_WIN32) 36#elif defined(_WIN32)
37#include <windows.h> 37#include <windows.h>
38#define sleep(s) (Sleep((s)*1000), 0) 38#define sleep(s) (Sleep ((s) * 1000), 0)
39#endif /* _WIN32 */ 39#endif /* _WIN32 */
40 40
41 41
@@ -48,8 +48,8 @@ http_PanicCallback (void *cls,
48 unsigned int line, 48 unsigned int line,
49 const char *reason) 49 const char *reason)
50{ 50{
51 (void)cls; /* Unused. Silent compiler warning. */ 51 (void) cls; /* Unused. Silent compiler warning. */
52 fprintf( stderr, 52 fprintf (stderr,
53 "PANIC: exit process: %s at %s:%u\n", 53 "PANIC: exit process: %s at %s:%u\n",
54 reason, 54 reason,
55 file, 55 file,
@@ -81,11 +81,11 @@ suspend_connection (struct MHD_Connection *connection)
81 &resume_connection, 81 &resume_connection,
82 connection); 82 connection);
83 if (0 != status) 83 if (0 != status)
84 { 84 {
85 fprintf (stderr, 85 fprintf (stderr,
86 "Could not create thead\n"); 86 "Could not create thead\n");
87 exit( EXIT_FAILURE ); 87 exit (EXIT_FAILURE);
88 } 88 }
89 pthread_detach (thread_id); 89 pthread_detach (thread_id);
90} 90}
91 91
@@ -103,17 +103,18 @@ http_ContentReaderCallback (void *cls,
103 char *buf, 103 char *buf,
104 size_t max) 104 size_t max)
105{ 105{
106 static const char alphabet[] = "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 106 static const char alphabet[] =
107 "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
107 struct ContentReaderUserdata *userdata = cls; 108 struct ContentReaderUserdata *userdata = cls;
108 (void)pos;(void)max; /* Unused. Silent compiler warning. */ 109 (void) pos; (void) max; /* Unused. Silent compiler warning. */
109 110
110 if( userdata->bytes_written >= 1024) 111 if ( userdata->bytes_written >= 1024)
111 { 112 {
112 fprintf( stderr, 113 fprintf (stderr,
113 "finish: %d\n", 114 "finish: %d\n",
114 request_counter); 115 request_counter);
115 return MHD_CONTENT_READER_END_OF_STREAM; 116 return MHD_CONTENT_READER_END_OF_STREAM;
116 } 117 }
117 userdata->bytes_written++; 118 userdata->bytes_written++;
118 buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)]; 119 buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)];
119 suspend_connection (userdata->connection); 120 suspend_connection (userdata->connection);
@@ -139,21 +140,22 @@ http_AccessHandlerCallback (void *cls,
139 const char *version, 140 const char *version,
140 const char *upload_data, 141 const char *upload_data,
141 size_t *upload_data_size, 142 size_t *upload_data_size,
142 void **con_cls ) 143 void **con_cls)
143{ 144{
144 int ret; 145 int ret;
145 (void)cls;(void)url; /* Unused. Silent compiler warning. */ 146 (void) cls; (void) url; /* Unused. Silent compiler warning. */
146 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 147 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
147 (void)upload_data_size; /* Unused. Silent compiler warning. */ 148 (void) upload_data_size; /* Unused. Silent compiler warning. */
148 149
149 /* Never respond on first call */ 150 /* Never respond on first call */
150 if (NULL == *con_cls) 151 if (NULL == *con_cls)
151 { 152 {
152 fprintf (stderr, 153 fprintf (stderr,
153 "start: %d\n", 154 "start: %d\n",
154 ++request_counter); 155 ++request_counter);
155 156
156 struct ContentReaderUserdata *userdata = malloc (sizeof(struct ContentReaderUserdata)); 157 struct ContentReaderUserdata *userdata = malloc (sizeof(struct
158 ContentReaderUserdata));
157 159
158 if (NULL == userdata) 160 if (NULL == userdata)
159 return MHD_NO; 161 return MHD_NO;
@@ -181,7 +183,7 @@ http_AccessHandlerCallback (void *cls,
181 183
182 184
183int 185int
184main(void) 186main (void)
185{ 187{
186 int port; 188 int port;
187 char command_line[1024]; 189 char command_line[1024];
@@ -198,9 +200,9 @@ main(void)
198 /* Flags */ 200 /* Flags */
199 unsigned int daemon_flags 201 unsigned int daemon_flags
200 = MHD_USE_INTERNAL_POLLING_THREAD 202 = MHD_USE_INTERNAL_POLLING_THREAD
201 | MHD_USE_AUTO 203 | MHD_USE_AUTO
202 | MHD_ALLOW_SUSPEND_RESUME 204 | MHD_ALLOW_SUSPEND_RESUME
203 | MHD_USE_ITC; 205 | MHD_USE_ITC;
204 206
205 /* Create daemon */ 207 /* Create daemon */
206 struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags, 208 struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags,
@@ -213,33 +215,35 @@ main(void)
213 if (NULL == daemon) 215 if (NULL == daemon)
214 return 1; 216 return 1;
215 if (0 == port) 217 if (0 == port)
218 {
219 const union MHD_DaemonInfo *dinfo;
220 dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT);
221 if ((NULL == dinfo) ||(0 == dinfo->port) )
216 { 222 {
217 const union MHD_DaemonInfo *dinfo; 223 MHD_stop_daemon (daemon); return 32;
218 dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT);
219 if (NULL == dinfo || 0 == dinfo->port)
220 { MHD_stop_daemon (daemon); return 32; }
221 port = (int)dinfo->port;
222 } 224 }
225 port = (int) dinfo->port;
226 }
223 snprintf (command_line, 227 snprintf (command_line,
224 sizeof (command_line), 228 sizeof (command_line),
225 "curl -s http://127.0.0.1:%d", 229 "curl -s http://127.0.0.1:%d",
226 port); 230 port);
227 231
228 if (0 != system (command_line)) 232 if (0 != system (command_line))
229 { 233 {
230 MHD_stop_daemon (daemon); 234 MHD_stop_daemon (daemon);
231 return 1; 235 return 1;
232 } 236 }
233 /* wait for a request */ 237 /* wait for a request */
234 while (0 == request_counter) 238 while (0 == request_counter)
235 (void)sleep (1); 239 (void) sleep (1);
236 240
237 fprintf (stderr, 241 fprintf (stderr,
238 "quiesce\n"); 242 "quiesce\n");
239 MHD_quiesce_daemon (daemon); 243 MHD_quiesce_daemon (daemon);
240 244
241 /* wait a second */ 245 /* wait a second */
242 (void)sleep (1); 246 (void) sleep (1);
243 247
244 fprintf (stderr, 248 fprintf (stderr,
245 "stopping daemon\n"); 249 "stopping daemon\n");
diff --git a/src/testcurl/test_termination.c b/src/testcurl/test_termination.c
index 5be74303..cd99e0af 100644
--- a/src/testcurl/test_termination.c
+++ b/src/testcurl/test_termination.c
@@ -53,29 +53,29 @@ connection_handler (void *cls,
53 const char *url, 53 const char *url,
54 const char *method, 54 const char *method,
55 const char *version, 55 const char *version,
56 const char *upload_data, size_t * upload_data_size, 56 const char *upload_data, size_t *upload_data_size,
57 void **ptr) 57 void **ptr)
58{ 58{
59 static int i; 59 static int i;
60 (void)cls;(void)url; /* Unused. Silent compiler warning. */ 60 (void) cls; (void) url; /* Unused. Silent compiler warning. */
61 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 61 (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
62 (void)upload_data_size; /* Unused. Silent compiler warning. */ 62 (void) upload_data_size; /* Unused. Silent compiler warning. */
63 63
64 if (*ptr == NULL) 64 if (*ptr == NULL)
65 { 65 {
66 *ptr = &i; 66 *ptr = &i;
67 return MHD_YES; 67 return MHD_YES;
68 } 68 }
69 69
70 if (*upload_data_size != 0) 70 if (*upload_data_size != 0)
71 { 71 {
72 (*upload_data_size) = 0; 72 (*upload_data_size) = 0;
73 return MHD_YES; 73 return MHD_YES;
74 } 74 }
75 75
76 struct MHD_Response *response = 76 struct MHD_Response *response =
77 MHD_create_response_from_buffer (strlen ("Response"), "Response", 77 MHD_create_response_from_buffer (strlen ("Response"), "Response",
78 MHD_RESPMEM_PERSISTENT); 78 MHD_RESPMEM_PERSISTENT);
79 int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 79 int ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
80 MHD_destroy_response (response); 80 MHD_destroy_response (response);
81 81
@@ -85,7 +85,7 @@ connection_handler (void *cls,
85static size_t 85static size_t
86write_data (void *ptr, size_t size, size_t nmemb, void *stream) 86write_data (void *ptr, size_t size, size_t nmemb, void *stream)
87{ 87{
88 (void)ptr;(void)stream; /* Unused. Silent compiler warning. */ 88 (void) ptr; (void) stream; /* Unused. Silent compiler warning. */
89 return size * nmemb; 89 return size * nmemb;
90} 90}
91 91
@@ -103,24 +103,28 @@ main (void)
103 port = 1490; 103 port = 1490;
104 104
105 105
106 daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 106 daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
107 | MHD_USE_INTERNAL_POLLING_THREAD
108 | MHD_USE_ERROR_LOG,
107 port, 109 port,
108 NULL, 110 NULL,
109 NULL, connection_handler, NULL, MHD_OPTION_END); 111 NULL, connection_handler, NULL, MHD_OPTION_END);
110 112
111 if (daemon == NULL) 113 if (daemon == NULL)
112 { 114 {
113 fprintf (stderr, "Daemon cannot be started!"); 115 fprintf (stderr, "Daemon cannot be started!");
114 exit (1); 116 exit (1);
115 } 117 }
116 if (0 == port) 118 if (0 == port)
119 {
120 const union MHD_DaemonInfo *dinfo;
121 dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT);
122 if ((NULL == dinfo) ||(0 == dinfo->port) )
117 { 123 {
118 const union MHD_DaemonInfo *dinfo; 124 MHD_stop_daemon (daemon); return 32;
119 dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT);
120 if (NULL == dinfo || 0 == dinfo->port)
121 { MHD_stop_daemon (daemon); return 32; }
122 port = (int)dinfo->port;
123 } 125 }
126 port = (int) dinfo->port;
127 }
124 128
125 curl = curl_easy_init (); 129 curl = curl_easy_init ();
126 /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */ 130 /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */
@@ -133,12 +137,12 @@ main (void)
133 137
134 CURLcode success = curl_easy_perform (curl); 138 CURLcode success = curl_easy_perform (curl);
135 if (success != 0) 139 if (success != 0)
136 { 140 {
137 fprintf (stderr, "CURL Error"); 141 fprintf (stderr, "CURL Error");
138 exit (1); 142 exit (1);
139 } 143 }
140 /* CPU used to go crazy here */ 144 /* CPU used to go crazy here */
141 (void)sleep (1); 145 (void) sleep (1);
142 146
143 curl_easy_cleanup (curl); 147 curl_easy_cleanup (curl);
144 MHD_stop_daemon (daemon); 148 MHD_stop_daemon (daemon);
diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c
index d87bb368..a17b0fb8 100644
--- a/src/testcurl/test_timeout.c
+++ b/src/testcurl/test_timeout.c
@@ -51,37 +51,37 @@ struct CBC
51}; 51};
52 52
53 53
54static void 54static void
55termination_cb (void *cls, 55termination_cb (void *cls,
56 struct MHD_Connection *connection, 56 struct MHD_Connection *connection,
57 void **con_cls, 57 void **con_cls,
58 enum MHD_RequestTerminationCode toe) 58 enum MHD_RequestTerminationCode toe)
59{ 59{
60 int *test = cls; 60 int *test = cls;
61 (void)connection;(void)con_cls; /* Unused. Silent compiler warning. */ 61 (void) connection; (void) con_cls; /* Unused. Silent compiler warning. */
62 62
63 switch (toe) 63 switch (toe)
64 {
65 case MHD_REQUEST_TERMINATED_COMPLETED_OK:
66 if (test == &withoutTimeout)
64 { 67 {
65 case MHD_REQUEST_TERMINATED_COMPLETED_OK : 68 withoutTimeout = 0;
66 if (test == &withoutTimeout)
67 {
68 withoutTimeout = 0;
69 }
70 break;
71 case MHD_REQUEST_TERMINATED_WITH_ERROR :
72 case MHD_REQUEST_TERMINATED_READ_ERROR :
73 break;
74 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED :
75 if (test == &withTimeout)
76 {
77 withTimeout = 0;
78 }
79 break;
80 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN:
81 break;
82 case MHD_REQUEST_TERMINATED_CLIENT_ABORT:
83 break;
84 } 69 }
70 break;
71 case MHD_REQUEST_TERMINATED_WITH_ERROR:
72 case MHD_REQUEST_TERMINATED_READ_ERROR:
73 break;
74 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED:
75 if (test == &withTimeout)
76 {
77 withTimeout = 0;
78 }
79 break;
80 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN:
81 break;
82 case MHD_REQUEST_TERMINATED_CLIENT_ABORT:
83 break;
84 }
85} 85}
86 86
87 87
@@ -93,7 +93,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
93 93
94 wrt = size * nmemb; 94 wrt = size * nmemb;
95 if (wrt > 8 - (*pos)) 95 if (wrt > 8 - (*pos))
96 wrt = 8 - (*pos); 96 wrt = 8 - (*pos);
97 memcpy (stream, &("Hello123"[*pos]), wrt); 97 memcpy (stream, &("Hello123"[*pos]), wrt);
98 (*pos) += wrt; 98 (*pos) += wrt;
99 return wrt; 99 return wrt;
@@ -103,7 +103,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
103static size_t 103static size_t
104putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr) 104putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr)
105{ 105{
106 (void)stream;(void)size;(void)nmemb;(void)ptr; /* Unused. Silent compiler warning. */ 106 (void) stream; (void) size; (void) nmemb; (void) ptr; /* Unused. Silent compiler warning. */
107 return 0; 107 return 0;
108} 108}
109 109
@@ -133,29 +133,29 @@ ahc_echo (void *cls,
133 int *done = cls; 133 int *done = cls;
134 struct MHD_Response *response; 134 struct MHD_Response *response;
135 int ret; 135 int ret;
136 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 136 (void) version; (void) unused; /* Unused. Silent compiler warning. */
137 137
138 if (0 != strcmp ("PUT", method)) 138 if (0 != strcmp ("PUT", method))
139 return MHD_NO; /* unexpected method */ 139 return MHD_NO; /* unexpected method */
140 if ((*done) == 0) 140 if ((*done) == 0)
141 {
142 if (*upload_data_size != 8)
143 return MHD_YES; /* not yet ready */
144 if (0 == memcmp (upload_data, "Hello123", 8))
145 {
146 *upload_data_size = 0;
147 }
148 else
141 { 149 {
142 if (*upload_data_size != 8) 150 printf ("Invalid upload data `%8s'!\n", upload_data);
143 return MHD_YES; /* not yet ready */ 151 return MHD_NO;
144 if (0 == memcmp (upload_data, "Hello123", 8))
145 {
146 *upload_data_size = 0;
147 }
148 else
149 {
150 printf ("Invalid upload data `%8s'!\n", upload_data);
151 return MHD_NO;
152 }
153 *done = 1;
154 return MHD_YES;
155 } 152 }
153 *done = 1;
154 return MHD_YES;
155 }
156 response = MHD_create_response_from_buffer (strlen (url), 156 response = MHD_create_response_from_buffer (strlen (url),
157 (void *) url, 157 (void *) url,
158 MHD_RESPMEM_MUST_COPY); 158 MHD_RESPMEM_MUST_COPY);
159 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 159 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
160 MHD_destroy_response (response); 160 MHD_destroy_response (response);
161 return ret; 161 return ret;
@@ -177,11 +177,11 @@ testWithoutTimeout ()
177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
178 port = 0; 178 port = 0;
179 else 179 else
180 { 180 {
181 port = 1500; 181 port = 1500;
182 if (oneone) 182 if (oneone)
183 port += 5; 183 port += 5;
184 } 184 }
185 185
186 cbc.buf = buf; 186 cbc.buf = buf;
187 cbc.size = 2048; 187 cbc.size = 2048;
@@ -190,21 +190,24 @@ testWithoutTimeout ()
190 port, 190 port,
191 NULL, NULL, &ahc_echo, &done_flag, 191 NULL, NULL, &ahc_echo, &done_flag,
192 MHD_OPTION_CONNECTION_TIMEOUT, 2, 192 MHD_OPTION_CONNECTION_TIMEOUT, 2,
193 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withTimeout, 193 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
194 &withTimeout,
194 MHD_OPTION_END); 195 MHD_OPTION_END);
195 if (d == NULL) 196 if (d == NULL)
196 return 1; 197 return 1;
197 if (0 == port) 198 if (0 == port)
199 {
200 const union MHD_DaemonInfo *dinfo;
201 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
202 if ((NULL == dinfo) ||(0 == dinfo->port) )
198 { 203 {
199 const union MHD_DaemonInfo *dinfo; 204 MHD_stop_daemon (d); return 32;
200 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
201 if (NULL == dinfo || 0 == dinfo->port)
202 { MHD_stop_daemon (d); return 32; }
203 port = (int)dinfo->port;
204 } 205 }
206 port = (int) dinfo->port;
207 }
205 c = curl_easy_init (); 208 c = curl_easy_init ();
206 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 209 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
207 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 210 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
208 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 211 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
209 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 212 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
210 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 213 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -223,11 +226,11 @@ testWithoutTimeout ()
223 * crashes on my system! */ 226 * crashes on my system! */
224 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 227 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
225 if (CURLE_OK != (errornum = curl_easy_perform (c))) 228 if (CURLE_OK != (errornum = curl_easy_perform (c)))
226 { 229 {
227 curl_easy_cleanup (c); 230 curl_easy_cleanup (c);
228 MHD_stop_daemon (d); 231 MHD_stop_daemon (d);
229 return 2; 232 return 2;
230 } 233 }
231 curl_easy_cleanup (c); 234 curl_easy_cleanup (c);
232 MHD_stop_daemon (d); 235 MHD_stop_daemon (d);
233 if (cbc.pos != strlen ("/hello_world")) 236 if (cbc.pos != strlen ("/hello_world"))
@@ -251,11 +254,11 @@ testWithTimeout ()
251 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 254 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
252 port = 0; 255 port = 0;
253 else 256 else
254 { 257 {
255 port = 1501; 258 port = 1501;
256 if (oneone) 259 if (oneone)
257 port += 5; 260 port += 5;
258 } 261 }
259 262
260 cbc.buf = buf; 263 cbc.buf = buf;
261 cbc.size = 2048; 264 cbc.size = 2048;
@@ -264,21 +267,24 @@ testWithTimeout ()
264 port, 267 port,
265 NULL, NULL, &ahc_echo, &done_flag, 268 NULL, NULL, &ahc_echo, &done_flag,
266 MHD_OPTION_CONNECTION_TIMEOUT, 2, 269 MHD_OPTION_CONNECTION_TIMEOUT, 2,
267 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withoutTimeout, 270 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
271 &withoutTimeout,
268 MHD_OPTION_END); 272 MHD_OPTION_END);
269 if (d == NULL) 273 if (d == NULL)
270 return 16; 274 return 16;
271 if (0 == port) 275 if (0 == port)
276 {
277 const union MHD_DaemonInfo *dinfo;
278 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
279 if ((NULL == dinfo) ||(0 == dinfo->port) )
272 { 280 {
273 const union MHD_DaemonInfo *dinfo; 281 MHD_stop_daemon (d); return 32;
274 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
275 if (NULL == dinfo || 0 == dinfo->port)
276 { MHD_stop_daemon (d); return 32; }
277 port = (int)dinfo->port;
278 } 282 }
283 port = (int) dinfo->port;
284 }
279 c = curl_easy_init (); 285 c = curl_easy_init ();
280 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 286 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
281 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 287 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
282 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 288 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
283 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 289 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
284 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail); 290 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail);
@@ -297,16 +303,16 @@ testWithTimeout ()
297 * crashes on my system! */ 303 * crashes on my system! */
298 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 304 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
299 if (CURLE_OK != (errornum = curl_easy_perform (c))) 305 if (CURLE_OK != (errornum = curl_easy_perform (c)))
300 { 306 {
301 curl_easy_cleanup (c); 307 curl_easy_cleanup (c);
302 MHD_stop_daemon (d); 308 MHD_stop_daemon (d);
303 if (errornum == CURLE_GOT_NOTHING) 309 if (errornum == CURLE_GOT_NOTHING)
304 /* mhd had the timeout */ 310 /* mhd had the timeout */
305 return 0; 311 return 0;
306 else 312 else
307 /* curl had the timeout first */ 313 /* curl had the timeout first */
308 return 32; 314 return 32;
309 } 315 }
310 curl_easy_cleanup (c); 316 curl_easy_cleanup (c);
311 MHD_stop_daemon (d); 317 MHD_stop_daemon (d);
312 return 64; 318 return 64;
@@ -317,9 +323,9 @@ int
317main (int argc, char *const *argv) 323main (int argc, char *const *argv)
318{ 324{
319 unsigned int errorCount = 0; 325 unsigned int errorCount = 0;
320 (void)argc; /* Unused. Silent compiler warning. */ 326 (void) argc; /* Unused. Silent compiler warning. */
321 327
322 if (NULL == argv || 0 == argv[0]) 328 if ((NULL == argv)||(0 == argv[0]))
323 return 99; 329 return 99;
324 oneone = has_in_name (argv[0], "11"); 330 oneone = has_in_name (argv[0], "11");
325 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 331 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
@@ -327,9 +333,9 @@ main (int argc, char *const *argv)
327 errorCount += testWithoutTimeout (); 333 errorCount += testWithoutTimeout ();
328 errorCount += testWithTimeout (); 334 errorCount += testWithTimeout ();
329 if (errorCount != 0) 335 if (errorCount != 0)
330 fprintf (stderr, 336 fprintf (stderr,
331 "Error during test execution (code: %u)\n", 337 "Error during test execution (code: %u)\n",
332 errorCount); 338 errorCount);
333 curl_global_cleanup (); 339 curl_global_cleanup ();
334 if ((withTimeout == 0) && (withoutTimeout == 0)) 340 if ((withTimeout == 0) && (withoutTimeout == 0))
335 return 0; 341 return 0;
diff --git a/src/testcurl/test_urlparse.c b/src/testcurl/test_urlparse.c
index d7c133ae..f1bab3d1 100644
--- a/src/testcurl/test_urlparse.c
+++ b/src/testcurl/test_urlparse.c
@@ -68,13 +68,13 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
68 return size * nmemb; 68 return size * nmemb;
69} 69}
70 70
71static int 71static int
72test_values (void *cls, 72test_values (void *cls,
73 enum MHD_ValueKind kind, 73 enum MHD_ValueKind kind,
74 const char *key, 74 const char *key,
75 const char *value) 75 const char *value)
76{ 76{
77 (void)cls;(void)kind; /* Unused. Silent compiler warning. */ 77 (void) cls; (void) kind; /* Unused. Silent compiler warning. */
78 if ( (0 == strcmp (key, "a")) && 78 if ( (0 == strcmp (key, "a")) &&
79 (0 == strcmp (value, "b")) ) 79 (0 == strcmp (value, "b")) )
80 matches += 1; 80 matches += 1;
@@ -100,23 +100,23 @@ ahc_echo (void *cls,
100 const char *me = cls; 100 const char *me = cls;
101 struct MHD_Response *response; 101 struct MHD_Response *response;
102 int ret; 102 int ret;
103 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 103 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
104 104
105 if (0 != strcmp (me, method)) 105 if (0 != strcmp (me, method))
106 return MHD_NO; /* unexpected method */ 106 return MHD_NO; /* unexpected method */
107 if (&ptr != *unused) 107 if (&ptr != *unused)
108 { 108 {
109 *unused = &ptr; 109 *unused = &ptr;
110 return MHD_YES; 110 return MHD_YES;
111 } 111 }
112 MHD_get_connection_values (connection, 112 MHD_get_connection_values (connection,
113 MHD_GET_ARGUMENT_KIND, 113 MHD_GET_ARGUMENT_KIND,
114 &test_values, 114 &test_values,
115 NULL); 115 NULL);
116 *unused = NULL; 116 *unused = NULL;
117 response = MHD_create_response_from_buffer (strlen (url), 117 response = MHD_create_response_from_buffer (strlen (url),
118 (void *) url, 118 (void *) url,
119 MHD_RESPMEM_MUST_COPY); 119 MHD_RESPMEM_MUST_COPY);
120 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 120 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
121 MHD_destroy_response (response); 121 MHD_destroy_response (response);
122 if (ret == MHD_NO) 122 if (ret == MHD_NO)
@@ -138,30 +138,33 @@ testInternalGet (int poll_flag)
138 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 138 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
139 port = 0; 139 port = 0;
140 else 140 else
141 { 141 {
142 port = 1510; 142 port = 1510;
143 if (oneone) 143 if (oneone)
144 port += 5; 144 port += 5;
145 } 145 }
146 146
147 cbc.buf = buf; 147 cbc.buf = buf;
148 cbc.size = 2048; 148 cbc.size = 2048;
149 cbc.pos = 0; 149 cbc.pos = 0;
150 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, 150 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
151 | poll_flag,
151 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 152 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
152 if (d == NULL) 153 if (d == NULL)
153 return 1; 154 return 1;
154 if (0 == port) 155 if (0 == port)
156 {
157 const union MHD_DaemonInfo *dinfo;
158 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
159 if ((NULL == dinfo) ||(0 == dinfo->port) )
155 { 160 {
156 const union MHD_DaemonInfo *dinfo; 161 MHD_stop_daemon (d); return 32;
157 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
158 if (NULL == dinfo || 0 == dinfo->port)
159 { MHD_stop_daemon (d); return 32; }
160 port = (int)dinfo->port;
161 } 162 }
163 port = (int) dinfo->port;
164 }
162 c = curl_easy_init (); 165 c = curl_easy_init ();
163 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world?a=b&c=&d"); 166 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world?a=b&c=&d");
164 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 167 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
165 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 168 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
166 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 169 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
167 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -176,14 +179,14 @@ testInternalGet (int poll_flag)
176 crashes on my system!*/ 179 crashes on my system!*/
177 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 180 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
178 if (CURLE_OK != (errornum = curl_easy_perform (c))) 181 if (CURLE_OK != (errornum = curl_easy_perform (c)))
179 { 182 {
180 fprintf (stderr, 183 fprintf (stderr,
181 "curl_easy_perform failed: `%s'\n", 184 "curl_easy_perform failed: `%s'\n",
182 curl_easy_strerror (errornum)); 185 curl_easy_strerror (errornum));
183 curl_easy_cleanup (c); 186 curl_easy_cleanup (c);
184 MHD_stop_daemon (d); 187 MHD_stop_daemon (d);
185 return 2; 188 return 2;
186 } 189 }
187 curl_easy_cleanup (c); 190 curl_easy_cleanup (c);
188 MHD_stop_daemon (d); 191 MHD_stop_daemon (d);
189 if (cbc.pos != strlen ("/hello_world")) 192 if (cbc.pos != strlen ("/hello_world"))
@@ -200,9 +203,9 @@ int
200main (int argc, char *const *argv) 203main (int argc, char *const *argv)
201{ 204{
202 unsigned int errorCount = 0; 205 unsigned int errorCount = 0;
203 (void)argc; /* Unused. Silent compiler warning. */ 206 (void) argc; /* Unused. Silent compiler warning. */
204 207
205 if (NULL == argv || 0 == argv[0]) 208 if ((NULL == argv)||(0 == argv[0]))
206 return 99; 209 return 99;
207 oneone = has_in_name (argv[0], "11"); 210 oneone = has_in_name (argv[0], "11");
208 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 211 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
index 72089a6d..07cbf464 100644
--- a/src/testzzuf/socat.c
+++ b/src/testzzuf/socat.c
@@ -67,27 +67,27 @@ zzuf_socat_start ()
67 }; 67 };
68 zzuf_pid = fork (); 68 zzuf_pid = fork ();
69 if (zzuf_pid == -1) 69 if (zzuf_pid == -1)
70 { 70 {
71 fprintf (stderr, "fork failed: %s\n", strerror (errno)); 71 fprintf (stderr, "fork failed: %s\n", strerror (errno));
72 exit (1); 72 exit (1);
73 } 73 }
74 if (zzuf_pid != 0) 74 if (zzuf_pid != 0)
75 {
76 (void) sleep (1); /* allow zzuf and socat to start */
77 status = 0;
78 if (0 < waitpid (zzuf_pid, &status, WNOHANG))
75 { 79 {
76 (void)sleep (1); /* allow zzuf and socat to start */ 80 if (WIFEXITED (status))
77 status = 0; 81 fprintf (stderr,
78 if (0 < waitpid (zzuf_pid, &status, WNOHANG)) 82 "zzuf died with status code %d!\n",
79 { 83 WEXITSTATUS (status));
80 if (WIFEXITED (status)) 84 if (WIFSIGNALED (status))
81 fprintf (stderr, 85 fprintf (stderr,
82 "zzuf died with status code %d!\n", 86 "zzuf died from signal %d!\n", WTERMSIG (status));
83 WEXITSTATUS (status)); 87 exit (1);
84 if (WIFSIGNALED (status))
85 fprintf (stderr,
86 "zzuf died from signal %d!\n", WTERMSIG (status));
87 exit (1);
88 }
89 return;
90 } 88 }
89 return;
90 }
91 setpgid (0, 0); 91 setpgid (0, 0);
92 execvp ("zzuf", args); 92 execvp ("zzuf", args);
93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno)); 93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
@@ -100,13 +100,13 @@ zzuf_socat_stop ()
100{ 100{
101 int status; 101 int status;
102 if (zzuf_pid != 0) 102 if (zzuf_pid != 0)
103 { 103 {
104 if (0 != killpg (zzuf_pid, SIGINT)) 104 if (0 != killpg (zzuf_pid, SIGINT))
105 fprintf (stderr, "Failed to killpg: %s\n", strerror (errno)); 105 fprintf (stderr, "Failed to killpg: %s\n", strerror (errno));
106 kill (zzuf_pid, SIGINT); 106 kill (zzuf_pid, SIGINT);
107 waitpid (zzuf_pid, &status, 0); 107 waitpid (zzuf_pid, &status, 0);
108 (void)sleep (1); /* allow socat to also die in peace */ 108 (void) sleep (1); /* allow socat to also die in peace */
109 } 109 }
110} 110}
111 111
112/* end of socat.c */ 112/* end of socat.c */
diff --git a/src/testzzuf/test_get.c b/src/testzzuf/test_get.c
index 08954226..cfa70b13 100644
--- a/src/testzzuf/test_get.c
+++ b/src/testzzuf/test_get.c
@@ -72,19 +72,19 @@ ahc_echo (void *cls,
72 const char *me = cls; 72 const char *me = cls;
73 struct MHD_Response *response; 73 struct MHD_Response *response;
74 int ret; 74 int ret;
75 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 75 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
76 76
77 if (0 != strcmp (me, method)) 77 if (0 != strcmp (me, method))
78 return MHD_NO; /* unexpected method */ 78 return MHD_NO; /* unexpected method */
79 if (&ptr != *unused) 79 if (&ptr != *unused)
80 { 80 {
81 *unused = &ptr; 81 *unused = &ptr;
82 return MHD_YES; 82 return MHD_YES;
83 } 83 }
84 *unused = NULL; 84 *unused = NULL;
85 response = MHD_create_response_from_buffer (strlen (url), 85 response = MHD_create_response_from_buffer (strlen (url),
86 (void *) url, 86 (void *) url,
87 MHD_RESPMEM_MUST_COPY); 87 MHD_RESPMEM_MUST_COPY);
88 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 88 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
89 MHD_destroy_response (response); 89 MHD_destroy_response (response);
90 if (ret == MHD_NO) 90 if (ret == MHD_NO)
@@ -105,32 +105,33 @@ testInternalGet ()
105 cbc.buf = buf; 105 cbc.buf = buf;
106 cbc.size = 2048; 106 cbc.size = 2048;
107 cbc.pos = 0; 107 cbc.pos = 0;
108 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 108 d = MHD_start_daemon (
109 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 109 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
110 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
110 if (d == NULL) 111 if (d == NULL)
111 return 1; 112 return 1;
112 zzuf_socat_start (); 113 zzuf_socat_start ();
113 for (i = 0; i < LOOP_COUNT; i++) 114 for (i = 0; i < LOOP_COUNT; i++)
114 { 115 {
115 fprintf (stderr, "."); 116 fprintf (stderr, ".");
116 c = curl_easy_init (); 117 c = curl_easy_init ();
117 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 118 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
118 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 119 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
119 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 120 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
120 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 121 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
121 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 122 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
122 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 123 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
123 if (oneone) 124 if (oneone)
124 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 125 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
125 else 126 else
126 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 127 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
127 /* NOTE: use of CONNECTTIMEOUT without also 128 /* NOTE: use of CONNECTTIMEOUT without also
128 * setting NOSIGNAL results in really weird 129 * setting NOSIGNAL results in really weird
129 * crashes on my system! */ 130 * crashes on my system! */
130 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 131 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
131 curl_easy_perform (c); 132 curl_easy_perform (c);
132 curl_easy_cleanup (c); 133 curl_easy_cleanup (c);
133 } 134 }
134 fprintf (stderr, "\n"); 135 fprintf (stderr, "\n");
135 zzuf_socat_stop (); 136 zzuf_socat_stop ();
136 MHD_stop_daemon (d); 137 MHD_stop_daemon (d);
@@ -149,32 +150,33 @@ testMultithreadedGet ()
149 cbc.buf = buf; 150 cbc.buf = buf;
150 cbc.size = 2048; 151 cbc.size = 2048;
151 cbc.pos = 0; 152 cbc.pos = 0;
152 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 153 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
154 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
153 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 155 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
154 if (d == NULL) 156 if (d == NULL)
155 return 16; 157 return 16;
156 zzuf_socat_start (); 158 zzuf_socat_start ();
157 for (i = 0; i < LOOP_COUNT; i++) 159 for (i = 0; i < LOOP_COUNT; i++)
158 { 160 {
159 fprintf (stderr, "."); 161 fprintf (stderr, ".");
160 c = curl_easy_init (); 162 c = curl_easy_init ();
161 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 163 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
162 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 164 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
163 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 165 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
164 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 166 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
165 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 167 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
166 if (oneone) 168 if (oneone)
167 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
168 else 170 else
169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 171 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
170 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 172 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
171 /* NOTE: use of CONNECTTIMEOUT without also 173 /* NOTE: use of CONNECTTIMEOUT without also
172 * setting NOSIGNAL results in really weird 174 * setting NOSIGNAL results in really weird
173 * crashes on my system! */ 175 * crashes on my system! */
174 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 176 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
175 curl_easy_perform (c); 177 curl_easy_perform (c);
176 curl_easy_cleanup (c); 178 curl_easy_cleanup (c);
177 } 179 }
178 fprintf (stderr, "\n"); 180 fprintf (stderr, "\n");
179 zzuf_socat_stop (); 181 zzuf_socat_stop ();
180 MHD_stop_daemon (d); 182 MHD_stop_daemon (d);
@@ -204,90 +206,90 @@ testExternalGet ()
204 cbc.buf = buf; 206 cbc.buf = buf;
205 cbc.size = 2048; 207 cbc.size = 2048;
206 cbc.pos = 0; 208 cbc.pos = 0;
207 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 209 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
208 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 210 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
209 if (d == NULL) 211 if (d == NULL)
210 return 256; 212 return 256;
211 multi = curl_multi_init (); 213 multi = curl_multi_init ();
212 if (multi == NULL) 214 if (multi == NULL)
215 {
216 MHD_stop_daemon (d);
217 return 512;
218 }
219 zzuf_socat_start ();
220 for (i = 0; i < LOOP_COUNT; i++)
221 {
222 fprintf (stderr, ".");
223 c = curl_easy_init ();
224 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
225 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
226 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
227 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
228 if (oneone)
229 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
230 else
231 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
232 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
233 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
234 /* NOTE: use of CONNECTTIMEOUT without also
235 * setting NOSIGNAL results in really weird
236 * crashes on my system! */
237 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
238 mret = curl_multi_add_handle (multi, c);
239 if (mret != CURLM_OK)
213 { 240 {
241 curl_multi_cleanup (multi);
242 curl_easy_cleanup (c);
243 zzuf_socat_stop ();
214 MHD_stop_daemon (d); 244 MHD_stop_daemon (d);
215 return 512; 245 return 1024;
216 } 246 }
217 zzuf_socat_start (); 247 start = time (NULL);
218 for (i = 0; i < LOOP_COUNT; i++) 248 while ((time (NULL) - start < 5) && (c != NULL))
219 { 249 {
220 fprintf (stderr, "."); 250 max = 0;
221 c = curl_easy_init (); 251 FD_ZERO (&rs);
222 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 252 FD_ZERO (&ws);
223 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 253 FD_ZERO (&es);
224 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 254 curl_multi_perform (multi, &running);
225 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 255 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
226 if (oneone)
227 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
228 else
229 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
230 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
231 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
232 /* NOTE: use of CONNECTTIMEOUT without also
233 * setting NOSIGNAL results in really weird
234 * crashes on my system! */
235 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
236 mret = curl_multi_add_handle (multi, c);
237 if (mret != CURLM_OK) 256 if (mret != CURLM_OK)
238 { 257 {
239 curl_multi_cleanup (multi); 258 curl_multi_remove_handle (multi, c);
240 curl_easy_cleanup (c); 259 curl_multi_cleanup (multi);
241 zzuf_socat_stop (); 260 curl_easy_cleanup (c);
242 MHD_stop_daemon (d); 261 zzuf_socat_stop ();
243 return 1024; 262 MHD_stop_daemon (d);
244 } 263 return 2048;
245 start = time (NULL); 264 }
246 while ((time (NULL) - start < 5) && (c != NULL)) 265 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
247 { 266 {
248 max = 0; 267 curl_multi_remove_handle (multi, c);
249 FD_ZERO (&rs); 268 curl_multi_cleanup (multi);
250 FD_ZERO (&ws); 269 curl_easy_cleanup (c);
251 FD_ZERO (&es); 270 zzuf_socat_stop ();
252 curl_multi_perform (multi, &running); 271 MHD_stop_daemon (d);
253 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 272 return 4096;
254 if (mret != CURLM_OK) 273 }
255 { 274 tv.tv_sec = 0;
256 curl_multi_remove_handle (multi, c); 275 tv.tv_usec = 1000;
257 curl_multi_cleanup (multi); 276 select (max + 1, &rs, &ws, &es, &tv);
258 curl_easy_cleanup (c); 277 curl_multi_perform (multi, &running);
259 zzuf_socat_stop (); 278 if (running == 0)
260 MHD_stop_daemon (d); 279 {
261 return 2048; 280 curl_multi_info_read (multi, &running);
262 } 281 curl_multi_remove_handle (multi, c);
263 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 282 curl_easy_cleanup (c);
264 { 283 c = NULL;
265 curl_multi_remove_handle (multi, c); 284 }
266 curl_multi_cleanup (multi); 285 MHD_run (d);
267 curl_easy_cleanup (c);
268 zzuf_socat_stop ();
269 MHD_stop_daemon (d);
270 return 4096;
271 }
272 tv.tv_sec = 0;
273 tv.tv_usec = 1000;
274 select (max + 1, &rs, &ws, &es, &tv);
275 curl_multi_perform (multi, &running);
276 if (running == 0)
277 {
278 curl_multi_info_read (multi, &running);
279 curl_multi_remove_handle (multi, c);
280 curl_easy_cleanup (c);
281 c = NULL;
282 }
283 MHD_run (d);
284 }
285 if (c != NULL)
286 {
287 curl_multi_remove_handle (multi, c);
288 curl_easy_cleanup (c);
289 }
290 } 286 }
287 if (c != NULL)
288 {
289 curl_multi_remove_handle (multi, c);
290 curl_easy_cleanup (c);
291 }
292 }
291 fprintf (stderr, "\n"); 293 fprintf (stderr, "\n");
292 curl_multi_cleanup (multi); 294 curl_multi_cleanup (multi);
293 zzuf_socat_stop (); 295 zzuf_socat_stop ();
@@ -300,17 +302,17 @@ int
300main (int argc, char *const *argv) 302main (int argc, char *const *argv)
301{ 303{
302 unsigned int errorCount = 0; 304 unsigned int errorCount = 0;
303 (void)argc; /* Unused. Silent compiler warning. */ 305 (void) argc; /* Unused. Silent compiler warning. */
304 306
305 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 307 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
306 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 308 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
307 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 309 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
308 return 2; 310 return 2;
309 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 311 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
310 { 312 {
311 errorCount += testInternalGet (); 313 errorCount += testInternalGet ();
312 errorCount += testMultithreadedGet (); 314 errorCount += testMultithreadedGet ();
313 } 315 }
314 errorCount += testExternalGet (); 316 errorCount += testExternalGet ();
315 if (errorCount != 0) 317 if (errorCount != 0)
316 fprintf (stderr, "Error (code: %u)\n", errorCount); 318 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c
index 2a16202b..facad587 100644
--- a/src/testzzuf/test_get_chunked.c
+++ b/src/testzzuf/test_get_chunked.c
@@ -67,10 +67,10 @@ crc (void *cls, uint64_t pos, char *buf, size_t max)
67 struct MHD_Response **responseptr = cls; 67 struct MHD_Response **responseptr = cls;
68 68
69 if (pos == 128 * 10) 69 if (pos == 128 * 10)
70 { 70 {
71 MHD_add_response_header (*responseptr, "Footer", "working"); 71 MHD_add_response_header (*responseptr, "Footer", "working");
72 return MHD_CONTENT_READER_END_OF_STREAM; 72 return MHD_CONTENT_READER_END_OF_STREAM;
73 } 73 }
74 if (max < 128) 74 if (max < 128)
75 abort (); /* should not happen in this testcase... */ 75 abort (); /* should not happen in this testcase... */
76 memset (buf, 'A' + (pos / 128), 128); 76 memset (buf, 'A' + (pos / 128), 128);
@@ -108,11 +108,11 @@ ahc_echo (void *cls,
108 if (0 != strcmp (me, method)) 108 if (0 != strcmp (me, method))
109 return MHD_NO; /* unexpected method */ 109 return MHD_NO; /* unexpected method */
110 if (&aptr != *ptr) 110 if (&aptr != *ptr)
111 { 111 {
112 /* do never respond on first call */ 112 /* do never respond on first call */
113 *ptr = &aptr; 113 *ptr = &aptr;
114 return MHD_YES; 114 return MHD_YES;
115 } 115 }
116 responseptr = malloc (sizeof (struct MHD_Response *)); 116 responseptr = malloc (sizeof (struct MHD_Response *));
117 if (NULL == responseptr) 117 if (NULL == responseptr)
118 return MHD_NO; 118 return MHD_NO;
@@ -144,29 +144,30 @@ testInternalGet ()
144 cbc.buf = buf; 144 cbc.buf = buf;
145 cbc.size = 2048; 145 cbc.size = 2048;
146 cbc.pos = 0; 146 cbc.pos = 0;
147 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 147 d = MHD_start_daemon (
148 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 148 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
149 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
149 if (d == NULL) 150 if (d == NULL)
150 return 1; 151 return 1;
151 zzuf_socat_start (); 152 zzuf_socat_start ();
152 for (i = 0; i < LOOP_COUNT; i++) 153 for (i = 0; i < LOOP_COUNT; i++)
153 { 154 {
154 fprintf (stderr, "."); 155 fprintf (stderr, ".");
155 c = curl_easy_init (); 156 c = curl_easy_init ();
156 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
157 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
158 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
159 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 160 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
160 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 161 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 162 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
162 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 163 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
163 /* NOTE: use of CONNECTTIMEOUT without also 164 /* NOTE: use of CONNECTTIMEOUT without also
164 * setting NOSIGNAL results in really weird 165 * setting NOSIGNAL results in really weird
165 * crashes on my system! */ 166 * crashes on my system! */
166 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 167 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
167 curl_easy_perform (c); 168 curl_easy_perform (c);
168 curl_easy_cleanup (c); 169 curl_easy_cleanup (c);
169 } 170 }
170 fprintf (stderr, "\n"); 171 fprintf (stderr, "\n");
171 zzuf_socat_stop (); 172 zzuf_socat_stop ();
172 MHD_stop_daemon (d); 173 MHD_stop_daemon (d);
@@ -185,29 +186,30 @@ testMultithreadedGet ()
185 cbc.buf = buf; 186 cbc.buf = buf;
186 cbc.size = 2048; 187 cbc.size = 2048;
187 cbc.pos = 0; 188 cbc.pos = 0;
188 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
190 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
189 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 191 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
190 if (d == NULL) 192 if (d == NULL)
191 return 16; 193 return 16;
192 zzuf_socat_start (); 194 zzuf_socat_start ();
193 for (i = 0; i < LOOP_COUNT; i++) 195 for (i = 0; i < LOOP_COUNT; i++)
194 { 196 {
195 fprintf (stderr, "."); 197 fprintf (stderr, ".");
196 c = curl_easy_init (); 198 c = curl_easy_init ();
197 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 199 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
198 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 200 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
199 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 201 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 202 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 203 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
204 /* NOTE: use of CONNECTTIMEOUT without also 206 /* NOTE: use of CONNECTTIMEOUT without also
205 * setting NOSIGNAL results in really weird 207 * setting NOSIGNAL results in really weird
206 * crashes on my system! */ 208 * crashes on my system! */
207 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
208 curl_easy_perform (c); 210 curl_easy_perform (c);
209 curl_easy_cleanup (c); 211 curl_easy_cleanup (c);
210 } 212 }
211 fprintf (stderr, "\n"); 213 fprintf (stderr, "\n");
212 zzuf_socat_stop (); 214 zzuf_socat_stop ();
213 MHD_stop_daemon (d); 215 MHD_stop_daemon (d);
@@ -237,87 +239,87 @@ testExternalGet ()
237 cbc.buf = buf; 239 cbc.buf = buf;
238 cbc.size = 2048; 240 cbc.size = 2048;
239 cbc.pos = 0; 241 cbc.pos = 0;
240 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 242 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
241 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 243 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
242 if (d == NULL) 244 if (d == NULL)
243 return 256; 245 return 256;
244 multi = curl_multi_init (); 246 multi = curl_multi_init ();
245 if (multi == NULL) 247 if (multi == NULL)
248 {
249 MHD_stop_daemon (d);
250 return 512;
251 }
252 zzuf_socat_start ();
253 for (i = 0; i < LOOP_COUNT; i++)
254 {
255 fprintf (stderr, ".");
256 c = curl_easy_init ();
257 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
258 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
259 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
260 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
261 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
262 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
263 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
264 /* NOTE: use of CONNECTTIMEOUT without also
265 * setting NOSIGNAL results in really weird
266 * crashes on my system! */
267 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
268 mret = curl_multi_add_handle (multi, c);
269 if (mret != CURLM_OK)
246 { 270 {
271 curl_multi_cleanup (multi);
272 curl_easy_cleanup (c);
273 zzuf_socat_stop ();
247 MHD_stop_daemon (d); 274 MHD_stop_daemon (d);
248 return 512; 275 return 1024;
249 } 276 }
250 zzuf_socat_start (); 277 start = time (NULL);
251 for (i = 0; i < LOOP_COUNT; i++) 278 while ((time (NULL) - start < 5) && (c != NULL))
252 { 279 {
253 fprintf (stderr, "."); 280 max = 0;
254 c = curl_easy_init (); 281 FD_ZERO (&rs);
255 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 282 FD_ZERO (&ws);
256 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 283 FD_ZERO (&es);
257 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 284 curl_multi_perform (multi, &running);
258 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 285 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
259 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
260 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
261 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
262 /* NOTE: use of CONNECTTIMEOUT without also
263 * setting NOSIGNAL results in really weird
264 * crashes on my system! */
265 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
266 mret = curl_multi_add_handle (multi, c);
267 if (mret != CURLM_OK) 286 if (mret != CURLM_OK)
268 { 287 {
269 curl_multi_cleanup (multi); 288 curl_multi_remove_handle (multi, c);
270 curl_easy_cleanup (c); 289 curl_multi_cleanup (multi);
271 zzuf_socat_stop (); 290 curl_easy_cleanup (c);
272 MHD_stop_daemon (d); 291 zzuf_socat_stop ();
273 return 1024; 292 MHD_stop_daemon (d);
274 } 293 return 2048;
275 start = time (NULL); 294 }
276 while ((time (NULL) - start < 5) && (c != NULL)) 295 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
277 { 296 {
278 max = 0; 297 curl_multi_remove_handle (multi, c);
279 FD_ZERO (&rs); 298 curl_multi_cleanup (multi);
280 FD_ZERO (&ws); 299 curl_easy_cleanup (c);
281 FD_ZERO (&es); 300 zzuf_socat_stop ();
282 curl_multi_perform (multi, &running); 301 MHD_stop_daemon (d);
283 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 302 return 4096;
284 if (mret != CURLM_OK) 303 }
285 { 304 tv.tv_sec = 0;
286 curl_multi_remove_handle (multi, c); 305 tv.tv_usec = 1000;
287 curl_multi_cleanup (multi); 306 select (max + 1, &rs, &ws, &es, &tv);
288 curl_easy_cleanup (c); 307 curl_multi_perform (multi, &running);
289 zzuf_socat_stop (); 308 if (running == 0)
290 MHD_stop_daemon (d); 309 {
291 return 2048; 310 curl_multi_info_read (multi, &running);
292 } 311 curl_multi_remove_handle (multi, c);
293 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 312 curl_easy_cleanup (c);
294 { 313 c = NULL;
295 curl_multi_remove_handle (multi, c); 314 }
296 curl_multi_cleanup (multi); 315 MHD_run (d);
297 curl_easy_cleanup (c);
298 zzuf_socat_stop ();
299 MHD_stop_daemon (d);
300 return 4096;
301 }
302 tv.tv_sec = 0;
303 tv.tv_usec = 1000;
304 select (max + 1, &rs, &ws, &es, &tv);
305 curl_multi_perform (multi, &running);
306 if (running == 0)
307 {
308 curl_multi_info_read (multi, &running);
309 curl_multi_remove_handle (multi, c);
310 curl_easy_cleanup (c);
311 c = NULL;
312 }
313 MHD_run (d);
314 }
315 if (c != NULL)
316 {
317 curl_multi_remove_handle (multi, c);
318 curl_easy_cleanup (c);
319 }
320 } 316 }
317 if (c != NULL)
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_easy_cleanup (c);
321 }
322 }
321 fprintf (stderr, "\n"); 323 fprintf (stderr, "\n");
322 curl_multi_cleanup (multi); 324 curl_multi_cleanup (multi);
323 zzuf_socat_stop (); 325 zzuf_socat_stop ();
@@ -331,15 +333,15 @@ int
331main (int argc, char *const *argv) 333main (int argc, char *const *argv)
332{ 334{
333 unsigned int errorCount = 0; 335 unsigned int errorCount = 0;
334 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 336 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
335 337
336 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 338 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
337 return 2; 339 return 2;
338 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 340 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
339 { 341 {
340 errorCount += testInternalGet (); 342 errorCount += testInternalGet ();
341 errorCount += testMultithreadedGet (); 343 errorCount += testMultithreadedGet ();
342 } 344 }
343 errorCount += testExternalGet (); 345 errorCount += testExternalGet ();
344 if (errorCount != 0) 346 if (errorCount != 0)
345 fprintf (stderr, "Error (code: %u)\n", errorCount); 347 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_long_header.c b/src/testzzuf/test_long_header.c
index 12a396bb..5ffaf272 100644
--- a/src/testzzuf/test_long_header.c
+++ b/src/testzzuf/test_long_header.c
@@ -43,14 +43,14 @@
43 * half of this value, so the actual value does not have 43 * half of this value, so the actual value does not have
44 * to be big at all... 44 * to be big at all...
45 */ 45 */
46#define VERY_LONG (1024*10) 46#define VERY_LONG (1024 * 10)
47 47
48static int oneone; 48static int oneone;
49 49
50static int 50static int
51apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) 51apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen)
52{ 52{
53 (void)cls;(void)addr;(void)addrlen; /* Unused. Silent compiler warning. */ 53 (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */
54 return MHD_YES; 54 return MHD_YES;
55} 55}
56 56
@@ -64,7 +64,7 @@ struct CBC
64static size_t 64static size_t
65copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 65copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
66{ 66{
67 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 67 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
68 return size * nmemb; 68 return size * nmemb;
69} 69}
70 70
@@ -80,14 +80,14 @@ ahc_echo (void *cls,
80 const char *me = cls; 80 const char *me = cls;
81 struct MHD_Response *response; 81 struct MHD_Response *response;
82 int ret; 82 int ret;
83 (void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 83 (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
84 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 84 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
85 85
86 if (0 != strcmp (me, method)) 86 if (0 != strcmp (me, method))
87 return MHD_NO; /* unexpected method */ 87 return MHD_NO; /* unexpected method */
88 response = MHD_create_response_from_buffer (strlen (url), 88 response = MHD_create_response_from_buffer (strlen (url),
89 (void *) url, 89 (void *) url,
90 MHD_RESPMEM_MUST_COPY); 90 MHD_RESPMEM_MUST_COPY);
91 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 91 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
92 MHD_destroy_response (response); 92 MHD_destroy_response (response);
93 return ret; 93 return ret;
@@ -107,46 +107,47 @@ testLongUrlGet ()
107 cbc.buf = buf; 107 cbc.buf = buf;
108 cbc.size = 2048; 108 cbc.size = 2048;
109 cbc.pos = 0; 109 cbc.pos = 0;
110 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 110 d = MHD_start_daemon (
111 11080, 111 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
112 &apc_all, 112 11080,
113 NULL, 113 &apc_all,
114 &ahc_echo, 114 NULL,
115 "GET", 115 &ahc_echo,
116 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 116 "GET",
117 (size_t) (VERY_LONG / 2), MHD_OPTION_END); 117 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
118 (size_t) (VERY_LONG / 2), MHD_OPTION_END);
118 119
119 if (d == NULL) 120 if (d == NULL)
120 return 1; 121 return 1;
121 zzuf_socat_start (); 122 zzuf_socat_start ();
122 for (i = 0; i < LOOP_COUNT; i++) 123 for (i = 0; i < LOOP_COUNT; i++)
123 { 124 {
124 fprintf (stderr, "."); 125 fprintf (stderr, ".");
125 126
126 c = curl_easy_init (); 127 c = curl_easy_init ();
127 url = malloc (VERY_LONG); 128 url = malloc (VERY_LONG);
128 memset (url, 'a', VERY_LONG); 129 memset (url, 'a', VERY_LONG);
129 url[VERY_LONG - 1] = '\0'; 130 url[VERY_LONG - 1] = '\0';
130 memcpy (url, "http://127.0.0.1:11081/", 131 memcpy (url, "http://127.0.0.1:11081/",
131 strlen ("http://127.0.0.1:11081/")); 132 strlen ("http://127.0.0.1:11081/"));
132 curl_easy_setopt (c, CURLOPT_URL, url); 133 curl_easy_setopt (c, CURLOPT_URL, url);
133 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 134 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
134 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 135 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
135 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 136 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
136 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 137 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
137 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 138 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
138 if (oneone) 139 if (oneone)
139 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 140 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
140 else 141 else
141 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 142 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
142 /* NOTE: use of CONNECTTIMEOUT without also 143 /* NOTE: use of CONNECTTIMEOUT without also
143 * setting NOSIGNAL results in really weird 144 * setting NOSIGNAL results in really weird
144 * crashes on my system! */ 145 * crashes on my system! */
145 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 146 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
146 curl_easy_perform (c); 147 curl_easy_perform (c);
147 curl_easy_cleanup (c); 148 curl_easy_cleanup (c);
148 free (url); 149 free (url);
149 } 150 }
150 fprintf (stderr, "\n"); 151 fprintf (stderr, "\n");
151 zzuf_socat_stop (); 152 zzuf_socat_stop ();
152 153
@@ -169,49 +170,50 @@ testLongHeaderGet ()
169 cbc.buf = buf; 170 cbc.buf = buf;
170 cbc.size = 2048; 171 cbc.size = 2048;
171 cbc.pos = 0; 172 cbc.pos = 0;
172 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 173 d = MHD_start_daemon (
173 11080, 174 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
174 &apc_all, 175 11080,
175 NULL, 176 &apc_all,
176 &ahc_echo, 177 NULL,
177 "GET", 178 &ahc_echo,
178 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 179 "GET",
179 (size_t) (VERY_LONG / 2), MHD_OPTION_END); 180 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
181 (size_t) (VERY_LONG / 2), MHD_OPTION_END);
180 if (d == NULL) 182 if (d == NULL)
181 return 16; 183 return 16;
182 zzuf_socat_start (); 184 zzuf_socat_start ();
183 for (i = 0; i < LOOP_COUNT; i++) 185 for (i = 0; i < LOOP_COUNT; i++)
184 { 186 {
185 fprintf (stderr, "."); 187 fprintf (stderr, ".");
186 c = curl_easy_init (); 188 c = curl_easy_init ();
187 url = malloc (VERY_LONG); 189 url = malloc (VERY_LONG);
188 memset (url, 'a', VERY_LONG); 190 memset (url, 'a', VERY_LONG);
189 url[VERY_LONG - 1] = '\0'; 191 url[VERY_LONG - 1] = '\0';
190 url[VERY_LONG / 2] = ':'; 192 url[VERY_LONG / 2] = ':';
191 url[VERY_LONG / 2 + 1] = ' '; 193 url[VERY_LONG / 2 + 1] = ' ';
192 header = curl_slist_append (header, url); 194 header = curl_slist_append (header, url);
193 195
194 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); 196 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 197 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 198 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 199 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
198 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
199 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
200 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 202 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
201 if (oneone) 203 if (oneone)
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 else 205 else
204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 206 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
205 /* NOTE: use of CONNECTTIMEOUT without also 207 /* NOTE: use of CONNECTTIMEOUT without also
206 * setting NOSIGNAL results in really weird 208 * setting NOSIGNAL results in really weird
207 * crashes on my system! */ 209 * crashes on my system! */
208 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
209 curl_easy_perform (c); 211 curl_easy_perform (c);
210 curl_slist_free_all (header); 212 curl_slist_free_all (header);
211 header = NULL; 213 header = NULL;
212 curl_easy_cleanup (c); 214 curl_easy_cleanup (c);
213 free (url); 215 free (url);
214 } 216 }
215 fprintf (stderr, "\n"); 217 fprintf (stderr, "\n");
216 zzuf_socat_stop (); 218 zzuf_socat_stop ();
217 219
diff --git a/src/testzzuf/test_post.c b/src/testzzuf/test_post.c
index 03b8e5a8..90da5e02 100644
--- a/src/testzzuf/test_post.c
+++ b/src/testzzuf/test_post.c
@@ -53,12 +53,12 @@ struct CBC
53 53
54static void 54static void
55completed_cb (void *cls, 55completed_cb (void *cls,
56 struct MHD_Connection *connection, 56 struct MHD_Connection *connection,
57 void **con_cls, 57 void **con_cls,
58 enum MHD_RequestTerminationCode toe) 58 enum MHD_RequestTerminationCode toe)
59{ 59{
60 struct MHD_PostProcessor *pp = *con_cls; 60 struct MHD_PostProcessor *pp = *con_cls;
61 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 61 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
62 62
63 if (NULL != pp) 63 if (NULL != pp)
64 MHD_destroy_post_processor (pp); 64 MHD_destroy_post_processor (pp);
@@ -94,8 +94,8 @@ post_iterator (void *cls,
94 const char *value, uint64_t off, size_t size) 94 const char *value, uint64_t off, size_t size)
95{ 95{
96 int *eok = cls; 96 int *eok = cls;
97 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 97 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
98 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 98 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
99 99
100 if ((0 == strcmp (key, "name")) && 100 if ((0 == strcmp (key, "name")) &&
101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) 101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
@@ -119,31 +119,31 @@ ahc_echo (void *cls,
119 struct MHD_Response *response; 119 struct MHD_Response *response;
120 struct MHD_PostProcessor *pp; 120 struct MHD_PostProcessor *pp;
121 int ret; 121 int ret;
122 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 122 (void) cls; (void) version; /* Unused. Silent compiler warning. */
123 123
124 if (0 != strcmp ("POST", method)) 124 if (0 != strcmp ("POST", method))
125 { 125 {
126 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
127 } 127 }
128 pp = *unused; 128 pp = *unused;
129 if (pp == NULL) 129 if (pp == NULL)
130 { 130 {
131 eok = 0; 131 eok = 0;
132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
133 *unused = pp; 133 *unused = pp;
134 } 134 }
135 MHD_post_process (pp, upload_data, *upload_data_size); 135 MHD_post_process (pp, upload_data, *upload_data_size);
136 if ((eok == 3) && (0 == *upload_data_size)) 136 if ((eok == 3) && (0 == *upload_data_size))
137 { 137 {
138 response = MHD_create_response_from_buffer (strlen (url), 138 response = MHD_create_response_from_buffer (strlen (url),
139 (void *) url, 139 (void *) url,
140 MHD_RESPMEM_MUST_COPY); 140 MHD_RESPMEM_MUST_COPY);
141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
142 MHD_destroy_response (response); 142 MHD_destroy_response (response);
143 MHD_destroy_post_processor (pp); 143 MHD_destroy_post_processor (pp);
144 *unused = NULL; 144 *unused = NULL;
145 return ret; 145 return ret;
146 } 146 }
147 *upload_data_size = 0; 147 *upload_data_size = 0;
148 return MHD_YES; 148 return MHD_YES;
149} 149}
@@ -161,38 +161,39 @@ testInternalPost ()
161 cbc.buf = buf; 161 cbc.buf = buf;
162 cbc.size = 2048; 162 cbc.size = 2048;
163 cbc.pos = 0; 163 cbc.pos = 0;
164 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 164 d = MHD_start_daemon (
165 11080, NULL, NULL, &ahc_echo, NULL, 165 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
166 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 166 11080, NULL, NULL, &ahc_echo, NULL,
167 MHD_OPTION_END); 167 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
168 MHD_OPTION_END);
168 if (d == NULL) 169 if (d == NULL)
169 return 1; 170 return 1;
170 zzuf_socat_start (); 171 zzuf_socat_start ();
171 for (i = 0; i < LOOP_COUNT; i++) 172 for (i = 0; i < LOOP_COUNT; i++)
172 { 173 {
173 fprintf (stderr, "."); 174 fprintf (stderr, ".");
174 175
175 c = curl_easy_init (); 176 c = curl_easy_init ();
176 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 177 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
177 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 178 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
178 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 179 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
179 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 180 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
180 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 181 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
181 curl_easy_setopt (c, CURLOPT_POST, 1L); 182 curl_easy_setopt (c, CURLOPT_POST, 1L);
182 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 183 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
183 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 184 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
184 if (oneone) 185 if (oneone)
185 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 186 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
186 else 187 else
187 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 188 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
188 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 189 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
189 /* NOTE: use of CONNECTTIMEOUT without also 190 /* NOTE: use of CONNECTTIMEOUT without also
190 * setting NOSIGNAL results in really weird 191 * setting NOSIGNAL results in really weird
191 * crashes on my system! */ 192 * crashes on my system! */
192 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 193 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
193 curl_easy_perform (c); 194 curl_easy_perform (c);
194 curl_easy_cleanup (c); 195 curl_easy_cleanup (c);
195 } 196 }
196 fprintf (stderr, "\n"); 197 fprintf (stderr, "\n");
197 zzuf_socat_stop (); 198 zzuf_socat_stop ();
198 MHD_stop_daemon (d); 199 MHD_stop_daemon (d);
@@ -212,39 +213,40 @@ testMultithreadedPost ()
212 cbc.buf = buf; 213 cbc.buf = buf;
213 cbc.size = 2048; 214 cbc.size = 2048;
214 cbc.pos = 0; 215 cbc.pos = 0;
215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 216 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
216 11080, NULL, NULL, &ahc_echo, NULL, 217 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
217 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 218 11080, NULL, NULL, &ahc_echo, NULL,
218 MHD_OPTION_END); 219 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
220 MHD_OPTION_END);
219 if (d == NULL) 221 if (d == NULL)
220 return 16; 222 return 16;
221 223
222 zzuf_socat_start (); 224 zzuf_socat_start ();
223 for (i = 0; i < LOOP_COUNT; i++) 225 for (i = 0; i < LOOP_COUNT; i++)
224 { 226 {
225 fprintf (stderr, "."); 227 fprintf (stderr, ".");
226 228
227 c = curl_easy_init (); 229 c = curl_easy_init ();
228 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 230 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
229 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
230 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
231 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 233 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
232 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 234 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
233 curl_easy_setopt (c, CURLOPT_POST, 1L); 235 curl_easy_setopt (c, CURLOPT_POST, 1L);
234 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 236 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
235 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 237 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
236 if (oneone) 238 if (oneone)
237 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
238 else 240 else
239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 241 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
240 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 242 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
241 /* NOTE: use of CONNECTTIMEOUT without also 243 /* NOTE: use of CONNECTTIMEOUT without also
242 * setting NOSIGNAL results in really weird 244 * setting NOSIGNAL results in really weird
243 * crashes on my system! */ 245 * crashes on my system! */
244 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 246 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
245 curl_easy_perform (c); 247 curl_easy_perform (c);
246 curl_easy_cleanup (c); 248 curl_easy_cleanup (c);
247 } 249 }
248 fprintf (stderr, "\n"); 250 fprintf (stderr, "\n");
249 zzuf_socat_stop (); 251 zzuf_socat_stop ();
250 252
@@ -275,101 +277,101 @@ testExternalPost ()
275 cbc.buf = buf; 277 cbc.buf = buf;
276 cbc.size = 2048; 278 cbc.size = 2048;
277 cbc.pos = 0; 279 cbc.pos = 0;
278 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 280 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
279 1082, NULL, NULL, &ahc_echo, NULL, 281 1082, NULL, NULL, &ahc_echo, NULL,
280 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 282 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
281 MHD_OPTION_END); 283 MHD_OPTION_END);
282 if (d == NULL) 284 if (d == NULL)
283 return 256; 285 return 256;
284 multi = curl_multi_init (); 286 multi = curl_multi_init ();
285 if (multi == NULL) 287 if (multi == NULL)
286 { 288 {
287 MHD_stop_daemon (d); 289 MHD_stop_daemon (d);
288 return 512; 290 return 512;
289 } 291 }
290 292
291 zzuf_socat_start (); 293 zzuf_socat_start ();
292 for (i = 0; i < LOOP_COUNT; i++) 294 for (i = 0; i < LOOP_COUNT; i++)
295 {
296 fprintf (stderr, ".");
297
298
299 c = curl_easy_init ();
300 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
301 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
302 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
303 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
304 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
305 curl_easy_setopt (c, CURLOPT_POST, 1L);
306 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
307 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
308 if (oneone)
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
310 else
311 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
312 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
313 /* NOTE: use of CONNECTTIMEOUT without also
314 * setting NOSIGNAL results in really weird
315 * crashes on my system! */
316 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
317
318
319 mret = curl_multi_add_handle (multi, c);
320 if (mret != CURLM_OK)
293 { 321 {
294 fprintf (stderr, "."); 322 curl_multi_cleanup (multi);
295 323 curl_easy_cleanup (c);
296 324 zzuf_socat_stop ();
297 c = curl_easy_init (); 325 MHD_stop_daemon (d);
298 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 326 return 1024;
299 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 327 }
300 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 328 start = time (NULL);
301 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 329 while ((time (NULL) - start < 5) && (c != NULL))
302 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 330 {
303 curl_easy_setopt (c, CURLOPT_POST, 1L); 331 max = 0;
304 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 332 FD_ZERO (&rs);
305 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 333 FD_ZERO (&ws);
306 if (oneone) 334 FD_ZERO (&es);
307 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 335 curl_multi_perform (multi, &running);
308 else 336 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
310 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
311 /* NOTE: use of CONNECTTIMEOUT without also
312 * setting NOSIGNAL results in really weird
313 * crashes on my system! */
314 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
315
316
317 mret = curl_multi_add_handle (multi, c);
318 if (mret != CURLM_OK) 337 if (mret != CURLM_OK)
319 { 338 {
320 curl_multi_cleanup (multi); 339 curl_multi_remove_handle (multi, c);
321 curl_easy_cleanup (c); 340 curl_multi_cleanup (multi);
322 zzuf_socat_stop (); 341 curl_easy_cleanup (c);
323 MHD_stop_daemon (d); 342 zzuf_socat_stop ();
324 return 1024; 343 MHD_stop_daemon (d);
325 } 344 return 2048;
326 start = time (NULL); 345 }
327 while ((time (NULL) - start < 5) && (c != NULL)) 346 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
328 { 347 {
329 max = 0; 348 curl_multi_remove_handle (multi, c);
330 FD_ZERO (&rs); 349 curl_multi_cleanup (multi);
331 FD_ZERO (&ws); 350 curl_easy_cleanup (c);
332 FD_ZERO (&es); 351 zzuf_socat_stop ();
333 curl_multi_perform (multi, &running); 352 MHD_stop_daemon (d);
334 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 353 return 4096;
335 if (mret != CURLM_OK) 354 }
336 { 355 tv.tv_sec = 0;
337 curl_multi_remove_handle (multi, c); 356 tv.tv_usec = 1000;
338 curl_multi_cleanup (multi); 357 select (max + 1, &rs, &ws, &es, &tv);
339 curl_easy_cleanup (c); 358 curl_multi_perform (multi, &running);
340 zzuf_socat_stop (); 359 if (running == 0)
341 MHD_stop_daemon (d); 360 {
342 return 2048; 361 curl_multi_info_read (multi, &running);
343 } 362 curl_multi_remove_handle (multi, c);
344 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 363 curl_easy_cleanup (c);
345 { 364 c = NULL;
346 curl_multi_remove_handle (multi, c); 365 }
347 curl_multi_cleanup (multi); 366 MHD_run (d);
348 curl_easy_cleanup (c);
349 zzuf_socat_stop ();
350 MHD_stop_daemon (d);
351 return 4096;
352 }
353 tv.tv_sec = 0;
354 tv.tv_usec = 1000;
355 select (max + 1, &rs, &ws, &es, &tv);
356 curl_multi_perform (multi, &running);
357 if (running == 0)
358 {
359 curl_multi_info_read (multi, &running);
360 curl_multi_remove_handle (multi, c);
361 curl_easy_cleanup (c);
362 c = NULL;
363 }
364 MHD_run (d);
365 }
366 if (c != NULL)
367 {
368 curl_multi_remove_handle (multi, c);
369 curl_easy_cleanup (c);
370 }
371
372 } 367 }
368 if (c != NULL)
369 {
370 curl_multi_remove_handle (multi, c);
371 curl_easy_cleanup (c);
372 }
373
374 }
373 fprintf (stderr, "\n"); 375 fprintf (stderr, "\n");
374 curl_multi_cleanup (multi); 376 curl_multi_cleanup (multi);
375 zzuf_socat_stop (); 377 zzuf_socat_stop ();
@@ -383,17 +385,17 @@ int
383main (int argc, char *const *argv) 385main (int argc, char *const *argv)
384{ 386{
385 unsigned int errorCount = 0; 387 unsigned int errorCount = 0;
386 (void)argc; /* Unused. Silent compiler warning. */ 388 (void) argc; /* Unused. Silent compiler warning. */
387 389
388 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 390 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
389 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 391 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
390 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 392 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
391 return 2; 393 return 2;
392 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 394 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
393 { 395 {
394 errorCount += testInternalPost (); 396 errorCount += testInternalPost ();
395 errorCount += testMultithreadedPost (); 397 errorCount += testMultithreadedPost ();
396 } 398 }
397 errorCount += testExternalPost (); 399 errorCount += testExternalPost ();
398 if (errorCount != 0) 400 if (errorCount != 0)
399 fprintf (stderr, "Error (code: %u)\n", errorCount); 401 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c
index cbe55b5d..d7c2fad3 100644
--- a/src/testzzuf/test_post_form.c
+++ b/src/testzzuf/test_post_form.c
@@ -51,12 +51,12 @@ struct CBC
51 51
52static void 52static void
53completed_cb (void *cls, 53completed_cb (void *cls,
54 struct MHD_Connection *connection, 54 struct MHD_Connection *connection,
55 void **con_cls, 55 void **con_cls,
56 enum MHD_RequestTerminationCode toe) 56 enum MHD_RequestTerminationCode toe)
57{ 57{
58 struct MHD_PostProcessor *pp = *con_cls; 58 struct MHD_PostProcessor *pp = *con_cls;
59 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 59 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
60 60
61 if (NULL != pp) 61 if (NULL != pp)
62 MHD_destroy_post_processor (pp); 62 MHD_destroy_post_processor (pp);
@@ -91,8 +91,8 @@ post_iterator (void *cls,
91 const char *value, uint64_t off, size_t size) 91 const char *value, uint64_t off, size_t size)
92{ 92{
93 int *eok = cls; 93 int *eok = cls;
94 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 94 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
95 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 95 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
96 96
97 if (key == NULL) 97 if (key == NULL)
98 return MHD_YES; 98 return MHD_YES;
@@ -122,33 +122,33 @@ ahc_echo (void *cls,
122 struct MHD_Response *response; 122 struct MHD_Response *response;
123 struct MHD_PostProcessor *pp; 123 struct MHD_PostProcessor *pp;
124 int ret; 124 int ret;
125 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 125 (void) cls; (void) version; /* Unused. Silent compiler warning. */
126 126
127 if (0 != strcmp ("POST", method)) 127 if (0 != strcmp ("POST", method))
128 { 128 {
129 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
130 } 130 }
131 pp = *unused; 131 pp = *unused;
132 if (pp == NULL) 132 if (pp == NULL)
133 { 133 {
134 eok = 0; 134 eok = 0;
135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
136 if (pp == NULL) 136 if (pp == NULL)
137 return MHD_NO; 137 return MHD_NO;
138 *unused = pp; 138 *unused = pp;
139 } 139 }
140 MHD_post_process (pp, upload_data, *upload_data_size); 140 MHD_post_process (pp, upload_data, *upload_data_size);
141 if ((eok == 3) && (0 == *upload_data_size)) 141 if ((eok == 3) && (0 == *upload_data_size))
142 { 142 {
143 response = MHD_create_response_from_buffer (strlen (url), 143 response = MHD_create_response_from_buffer (strlen (url),
144 (void *) url, 144 (void *) url,
145 MHD_RESPMEM_MUST_COPY); 145 MHD_RESPMEM_MUST_COPY);
146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
147 MHD_destroy_response (response); 147 MHD_destroy_response (response);
148 MHD_destroy_post_processor (pp); 148 MHD_destroy_post_processor (pp);
149 *unused = NULL; 149 *unused = NULL;
150 return ret; 150 return ret;
151 } 151 }
152 *upload_data_size = 0; 152 *upload_data_size = 0;
153 return MHD_YES; 153 return MHD_YES;
154} 154}
@@ -180,37 +180,38 @@ testInternalPost ()
180 cbc.buf = buf; 180 cbc.buf = buf;
181 cbc.size = 2048; 181 cbc.size = 2048;
182 cbc.pos = 0; 182 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 183 d = MHD_start_daemon (
184 11080, NULL, NULL, &ahc_echo, NULL, 184 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
185 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 185 11080, NULL, NULL, &ahc_echo, NULL,
186 MHD_OPTION_END); 186 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
187 MHD_OPTION_END);
187 if (d == NULL) 188 if (d == NULL)
188 return 1; 189 return 1;
189 zzuf_socat_start (); 190 zzuf_socat_start ();
190 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
191 { 192 {
192 fprintf (stderr, "."); 193 fprintf (stderr, ".");
193 c = curl_easy_init (); 194 c = curl_easy_init ();
194 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
195 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
196 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
197 pd = make_form (); 198 pd = make_form ();
198 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 199 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
199 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
200 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
201 if (oneone) 202 if (oneone)
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 else 204 else
204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
206 /* NOTE: use of CONNECTTIMEOUT without also 207 /* NOTE: use of CONNECTTIMEOUT without also
207 * setting NOSIGNAL results in really weird 208 * setting NOSIGNAL results in really weird
208 * crashes on my system! */ 209 * crashes on my system! */
209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
210 curl_easy_perform (c); 211 curl_easy_perform (c);
211 curl_easy_cleanup (c); 212 curl_easy_cleanup (c);
212 curl_formfree (pd); 213 curl_formfree (pd);
213 } 214 }
214 fprintf (stderr, "\n"); 215 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 216 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
@@ -231,37 +232,38 @@ testMultithreadedPost ()
231 cbc.buf = buf; 232 cbc.buf = buf;
232 cbc.size = 2048; 233 cbc.size = 2048;
233 cbc.pos = 0; 234 cbc.pos = 0;
234 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 235 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
236 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
235 11080, NULL, NULL, &ahc_echo, NULL, 237 11080, NULL, NULL, &ahc_echo, NULL,
236 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 238 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
237 MHD_OPTION_END); 239 MHD_OPTION_END);
238 if (d == NULL) 240 if (d == NULL)
239 return 16; 241 return 16;
240 zzuf_socat_start (); 242 zzuf_socat_start ();
241 for (i = 0; i < LOOP_COUNT; i++) 243 for (i = 0; i < LOOP_COUNT; i++)
242 { 244 {
243 fprintf (stderr, "."); 245 fprintf (stderr, ".");
244 c = curl_easy_init (); 246 c = curl_easy_init ();
245 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 247 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
246 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
247 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
248 pd = make_form (); 250 pd = make_form ();
249 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 251 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
250 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 252 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
251 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 253 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
252 if (oneone) 254 if (oneone)
253 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
254 else 256 else
255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 257 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
256 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 258 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
257 /* NOTE: use of CONNECTTIMEOUT without also 259 /* NOTE: use of CONNECTTIMEOUT without also
258 * setting NOSIGNAL results in really weird 260 * setting NOSIGNAL results in really weird
259 * crashes on my system! */ 261 * crashes on my system! */
260 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 262 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
261 curl_easy_perform (c); 263 curl_easy_perform (c);
262 curl_easy_cleanup (c); 264 curl_easy_cleanup (c);
263 curl_formfree (pd); 265 curl_formfree (pd);
264 } 266 }
265 fprintf (stderr, "\n"); 267 fprintf (stderr, "\n");
266 zzuf_socat_stop (); 268 zzuf_socat_stop ();
267 MHD_stop_daemon (d); 269 MHD_stop_daemon (d);
@@ -292,100 +294,100 @@ testExternalPost ()
292 cbc.buf = buf; 294 cbc.buf = buf;
293 cbc.size = 2048; 295 cbc.size = 2048;
294 cbc.pos = 0; 296 cbc.pos = 0;
295 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 297 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
296 1082, NULL, NULL, &ahc_echo, NULL, 298 1082, NULL, NULL, &ahc_echo, NULL,
297 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 299 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
298 MHD_OPTION_END); 300 MHD_OPTION_END);
299 if (d == NULL) 301 if (d == NULL)
300 return 256; 302 return 256;
301 multi = curl_multi_init (); 303 multi = curl_multi_init ();
302 if (multi == NULL) 304 if (multi == NULL)
305 {
306 MHD_stop_daemon (d);
307 return 512;
308 }
309 zzuf_socat_start ();
310 for (i = 0; i < LOOP_COUNT; i++)
311 {
312 fprintf (stderr, ".");
313
314 c = curl_easy_init ();
315 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
316 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
317 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
318 pd = make_form ();
319 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
320 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
321 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
322 if (oneone)
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
324 else
325 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
326 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
327 /* NOTE: use of CONNECTTIMEOUT without also
328 * setting NOSIGNAL results in really weird
329 * crashes on my system! */
330 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
331
332 mret = curl_multi_add_handle (multi, c);
333 if (mret != CURLM_OK)
303 { 334 {
335 curl_multi_cleanup (multi);
336 curl_formfree (pd);
337 curl_easy_cleanup (c);
338 zzuf_socat_stop ();
304 MHD_stop_daemon (d); 339 MHD_stop_daemon (d);
305 return 512; 340 return 1024;
306 } 341 }
307 zzuf_socat_start (); 342 start = time (NULL);
308 for (i = 0; i < LOOP_COUNT; i++) 343 while ((time (NULL) - start < 5) && (c != NULL))
309 { 344 {
310 fprintf (stderr, "."); 345 max = 0;
311 346 FD_ZERO (&rs);
312 c = curl_easy_init (); 347 FD_ZERO (&ws);
313 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 348 FD_ZERO (&es);
314 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 349 curl_multi_perform (multi, &running);
315 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 350 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
316 pd = make_form ();
317 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
318 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
319 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
320 if (oneone)
321 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
322 else
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
324 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
325 /* NOTE: use of CONNECTTIMEOUT without also
326 * setting NOSIGNAL results in really weird
327 * crashes on my system! */
328 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
329
330 mret = curl_multi_add_handle (multi, c);
331 if (mret != CURLM_OK) 351 if (mret != CURLM_OK)
332 { 352 {
333 curl_multi_cleanup (multi); 353 curl_multi_remove_handle (multi, c);
334 curl_formfree (pd); 354 curl_multi_cleanup (multi);
335 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
336 zzuf_socat_stop (); 356 zzuf_socat_stop ();
337 MHD_stop_daemon (d); 357 MHD_stop_daemon (d);
338 return 1024; 358 curl_formfree (pd);
339 } 359 return 2048;
340 start = time (NULL); 360 }
341 while ((time (NULL) - start < 5) && (c != NULL)) 361 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
342 { 362 {
343 max = 0; 363 curl_multi_remove_handle (multi, c);
344 FD_ZERO (&rs); 364 curl_multi_cleanup (multi);
345 FD_ZERO (&ws); 365 curl_easy_cleanup (c);
346 FD_ZERO (&es); 366 curl_formfree (pd);
347 curl_multi_perform (multi, &running); 367 zzuf_socat_stop ();
348 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 368 MHD_stop_daemon (d);
349 if (mret != CURLM_OK) 369 return 4096;
350 { 370 }
351 curl_multi_remove_handle (multi, c); 371 tv.tv_sec = 0;
352 curl_multi_cleanup (multi); 372 tv.tv_usec = 1000;
353 curl_easy_cleanup (c); 373 select (max + 1, &rs, &ws, &es, &tv);
354 zzuf_socat_stop (); 374 curl_multi_perform (multi, &running);
355 MHD_stop_daemon (d); 375 if (running == 0)
356 curl_formfree (pd); 376 {
357 return 2048; 377 curl_multi_info_read (multi, &running);
358 } 378 curl_multi_remove_handle (multi, c);
359 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 379 curl_easy_cleanup (c);
360 { 380 c = NULL;
361 curl_multi_remove_handle (multi, c); 381 }
362 curl_multi_cleanup (multi); 382 MHD_run (d);
363 curl_easy_cleanup (c);
364 curl_formfree (pd);
365 zzuf_socat_stop ();
366 MHD_stop_daemon (d);
367 return 4096;
368 }
369 tv.tv_sec = 0;
370 tv.tv_usec = 1000;
371 select (max + 1, &rs, &ws, &es, &tv);
372 curl_multi_perform (multi, &running);
373 if (running == 0)
374 {
375 curl_multi_info_read (multi, &running);
376 curl_multi_remove_handle (multi, c);
377 curl_easy_cleanup (c);
378 c = NULL;
379 }
380 MHD_run (d);
381 }
382 if (c != NULL)
383 {
384 curl_multi_remove_handle (multi, c);
385 curl_easy_cleanup (c);
386 }
387 curl_formfree (pd);
388 } 383 }
384 if (c != NULL)
385 {
386 curl_multi_remove_handle (multi, c);
387 curl_easy_cleanup (c);
388 }
389 curl_formfree (pd);
390 }
389 fprintf (stderr, "\n"); 391 fprintf (stderr, "\n");
390 zzuf_socat_stop (); 392 zzuf_socat_stop ();
391 curl_multi_cleanup (multi); 393 curl_multi_cleanup (multi);
@@ -399,17 +401,17 @@ int
399main (int argc, char *const *argv) 401main (int argc, char *const *argv)
400{ 402{
401 unsigned int errorCount = 0; 403 unsigned int errorCount = 0;
402 (void)argc; /* Unused. Silent compiler warning. */ 404 (void) argc; /* Unused. Silent compiler warning. */
403 405
404 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 406 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
405 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 407 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
406 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 408 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
407 return 2; 409 return 2;
408 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 410 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
409 { 411 {
410 errorCount += testInternalPost (); 412 errorCount += testInternalPost ();
411 errorCount += testMultithreadedPost (); 413 errorCount += testMultithreadedPost ();
412 } 414 }
413 errorCount += testExternalPost (); 415 errorCount += testExternalPost ();
414 if (errorCount != 0) 416 if (errorCount != 0)
415 fprintf (stderr, "Error (code: %u)\n", errorCount); 417 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put.c b/src/testzzuf/test_put.c
index 5a237ddd..605f4804 100644
--- a/src/testzzuf/test_put.c
+++ b/src/testzzuf/test_put.c
@@ -86,29 +86,29 @@ ahc_echo (void *cls,
86 int *done = cls; 86 int *done = cls;
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 89 (void) version; (void) unused; /* Unused. Silent compiler warning. */
90 90
91 if (0 != strcmp ("PUT", method)) 91 if (0 != strcmp ("PUT", method))
92 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
93 if ((*done) == 0) 93 if ((*done) == 0)
94 {
95 if (*upload_data_size != 8)
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
94 { 98 {
95 if (*upload_data_size != 8) 99 *upload_data_size = 0;
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
98 {
99 *upload_data_size = 0;
100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 } 100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 }
109 response = MHD_create_response_from_buffer (strlen (url), 109 response = MHD_create_response_from_buffer (strlen (url),
110 (void *) url, 110 (void *) url,
111 MHD_RESPMEM_MUST_COPY); 111 MHD_RESPMEM_MUST_COPY);
112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
113 MHD_destroy_response (response); 113 MHD_destroy_response (response);
114 return ret; 114 return ret;
@@ -129,37 +129,38 @@ testInternalPut ()
129 cbc.buf = buf; 129 cbc.buf = buf;
130 cbc.size = 2048; 130 cbc.size = 2048;
131 cbc.pos = 0; 131 cbc.pos = 0;
132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 132 d = MHD_start_daemon (
133 11080, 133 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
134 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 134 11080,
135 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
135 if (d == NULL) 136 if (d == NULL)
136 return 1; 137 return 1;
137 zzuf_socat_start (); 138 zzuf_socat_start ();
138 for (i = 0; i < LOOP_COUNT; i++) 139 for (i = 0; i < LOOP_COUNT; i++)
139 { 140 {
140 fprintf (stderr, "."); 141 fprintf (stderr, ".");
141 c = curl_easy_init (); 142 c = curl_easy_init ();
142 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 143 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
143 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 144 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
144 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 145 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
145 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 146 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
146 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 147 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
147 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 148 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
148 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 149 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
149 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 150 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
150 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 151 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
151 if (oneone) 152 if (oneone)
152 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 153 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
153 else 154 else
154 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 155 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
155 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 156 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
156 /* NOTE: use of CONNECTTIMEOUT without also 157 /* NOTE: use of CONNECTTIMEOUT without also
157 * setting NOSIGNAL results in really weird 158 * setting NOSIGNAL results in really weird
158 * crashes on my system! */ 159 * crashes on my system! */
159 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 160 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
160 curl_easy_perform (c); 161 curl_easy_perform (c);
161 curl_easy_cleanup (c); 162 curl_easy_cleanup (c);
162 } 163 }
163 fprintf (stderr, "\n"); 164 fprintf (stderr, "\n");
164 zzuf_socat_stop (); 165 zzuf_socat_stop ();
165 MHD_stop_daemon (d); 166 MHD_stop_daemon (d);
@@ -180,37 +181,38 @@ testMultithreadedPut ()
180 cbc.buf = buf; 181 cbc.buf = buf;
181 cbc.size = 2048; 182 cbc.size = 2048;
182 cbc.pos = 0; 183 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 184 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
185 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
184 11080, 186 11080,
185 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 187 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
186 if (d == NULL) 188 if (d == NULL)
187 return 16; 189 return 16;
188 zzuf_socat_start (); 190 zzuf_socat_start ();
189 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
190 { 192 {
191 fprintf (stderr, "."); 193 fprintf (stderr, ".");
192 c = curl_easy_init (); 194 c = curl_easy_init ();
193 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
194 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
195 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
196 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 198 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
197 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 199 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
198 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 200 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
199 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 201 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 202 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 203 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
202 if (oneone) 204 if (oneone)
203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
204 else 206 else
205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 207 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 208 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
207 /* NOTE: use of CONNECTTIMEOUT without also 209 /* NOTE: use of CONNECTTIMEOUT without also
208 * setting NOSIGNAL results in really weird 210 * setting NOSIGNAL results in really weird
209 * crashes on my system! */ 211 * crashes on my system! */
210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 212 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
211 curl_easy_perform (c); 213 curl_easy_perform (c);
212 curl_easy_cleanup (c); 214 curl_easy_cleanup (c);
213 } 215 }
214 fprintf (stderr, "\n"); 216 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 217 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 218 MHD_stop_daemon (d);
@@ -242,99 +244,99 @@ testExternalPut ()
242 cbc.buf = buf; 244 cbc.buf = buf;
243 cbc.size = 2048; 245 cbc.size = 2048;
244 cbc.pos = 0; 246 cbc.pos = 0;
245 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 247 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
246 11080, 248 11080,
247 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 249 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
248 if (d == NULL) 250 if (d == NULL)
249 return 256; 251 return 256;
250 multi = curl_multi_init (); 252 multi = curl_multi_init ();
251 if (multi == NULL) 253 if (multi == NULL)
252 { 254 {
253 MHD_stop_daemon (d); 255 MHD_stop_daemon (d);
254 return 512; 256 return 512;
255 } 257 }
256 zzuf_socat_start (); 258 zzuf_socat_start ();
257 for (i = 0; i < LOOP_COUNT; i++) 259 for (i = 0; i < LOOP_COUNT; i++)
258 { 260 {
259 fprintf (stderr, "."); 261 fprintf (stderr, ".");
260 262
261 c = curl_easy_init (); 263 c = curl_easy_init ();
262 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 264 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
263 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 265 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
264 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 266 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
265 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 267 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
266 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 268 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
267 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 269 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
268 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 270 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
269 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 271 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
270 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 272 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
271 if (oneone) 273 if (oneone)
272 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
273 else 275 else
274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 276 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
275 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 277 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
276 /* NOTE: use of CONNECTTIMEOUT without also 278 /* NOTE: use of CONNECTTIMEOUT without also
277 * setting NOSIGNAL results in really weird 279 * setting NOSIGNAL results in really weird
278 * crashes on my system! */ 280 * crashes on my system! */
279 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 281 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
280 282
281 283
282 284
283 mret = curl_multi_add_handle (multi, c); 285 mret = curl_multi_add_handle (multi, c);
286 if (mret != CURLM_OK)
287 {
288 curl_multi_cleanup (multi);
289 curl_easy_cleanup (c);
290 zzuf_socat_stop ();
291 MHD_stop_daemon (d);
292 return 1024;
293 }
294 start = time (NULL);
295 while ((time (NULL) - start < 5) && (c != NULL))
296 {
297 max = 0;
298 FD_ZERO (&rs);
299 FD_ZERO (&ws);
300 FD_ZERO (&es);
301 curl_multi_perform (multi, &running);
302 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
284 if (mret != CURLM_OK) 303 if (mret != CURLM_OK)
285 { 304 {
286 curl_multi_cleanup (multi); 305 curl_multi_remove_handle (multi, c);
287 curl_easy_cleanup (c); 306 curl_multi_cleanup (multi);
288 zzuf_socat_stop (); 307 curl_easy_cleanup (c);
289 MHD_stop_daemon (d); 308 zzuf_socat_stop ();
290 return 1024; 309 MHD_stop_daemon (d);
291 } 310 return 2048;
292 start = time (NULL); 311 }
293 while ((time (NULL) - start < 5) && (c != NULL)) 312 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
294 { 313 {
295 max = 0; 314 curl_multi_remove_handle (multi, c);
296 FD_ZERO (&rs); 315 curl_multi_cleanup (multi);
297 FD_ZERO (&ws); 316 curl_easy_cleanup (c);
298 FD_ZERO (&es); 317 zzuf_socat_stop ();
299 curl_multi_perform (multi, &running); 318 MHD_stop_daemon (d);
300 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 319 return 4096;
301 if (mret != CURLM_OK) 320 }
302 { 321 tv.tv_sec = 0;
303 curl_multi_remove_handle (multi, c); 322 tv.tv_usec = 1000;
304 curl_multi_cleanup (multi); 323 select (max + 1, &rs, &ws, &es, &tv);
305 curl_easy_cleanup (c); 324 curl_multi_perform (multi, &running);
306 zzuf_socat_stop (); 325 if (running == 0)
307 MHD_stop_daemon (d); 326 {
308 return 2048; 327 curl_multi_info_read (multi, &running);
309 } 328 curl_multi_remove_handle (multi, c);
310 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 329 curl_easy_cleanup (c);
311 { 330 c = NULL;
312 curl_multi_remove_handle (multi, c); 331 }
313 curl_multi_cleanup (multi); 332 MHD_run (d);
314 curl_easy_cleanup (c); 333 }
315 zzuf_socat_stop (); 334 if (c != NULL)
316 MHD_stop_daemon (d); 335 {
317 return 4096; 336 curl_multi_remove_handle (multi, c);
318 } 337 curl_easy_cleanup (c);
319 tv.tv_sec = 0;
320 tv.tv_usec = 1000;
321 select (max + 1, &rs, &ws, &es, &tv);
322 curl_multi_perform (multi, &running);
323 if (running == 0)
324 {
325 curl_multi_info_read (multi, &running);
326 curl_multi_remove_handle (multi, c);
327 curl_easy_cleanup (c);
328 c = NULL;
329 }
330 MHD_run (d);
331 }
332 if (c != NULL)
333 {
334 curl_multi_remove_handle (multi, c);
335 curl_easy_cleanup (c);
336 }
337 } 338 }
339 }
338 fprintf (stderr, "\n"); 340 fprintf (stderr, "\n");
339 curl_multi_cleanup (multi); 341 curl_multi_cleanup (multi);
340 zzuf_socat_stop (); 342 zzuf_socat_stop ();
@@ -347,17 +349,17 @@ int
347main (int argc, char *const *argv) 349main (int argc, char *const *argv)
348{ 350{
349 unsigned int errorCount = 0; 351 unsigned int errorCount = 0;
350 (void)argc; /* Unused. Silent compiler warning. */ 352 (void) argc; /* Unused. Silent compiler warning. */
351 353
352 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 354 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
353 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 355 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
354 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 356 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
355 return 2; 357 return 2;
356 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 358 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
357 { 359 {
358 errorCount += testInternalPut (); 360 errorCount += testInternalPut ();
359 errorCount += testMultithreadedPut (); 361 errorCount += testMultithreadedPut ();
360 } 362 }
361 errorCount += testExternalPut (); 363 errorCount += testExternalPut ();
362 if (errorCount != 0) 364 if (errorCount != 0)
363 fprintf (stderr, "Error (code: %u)\n", errorCount); 365 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put_chunked.c b/src/testzzuf/test_put_chunked.c
index d016d84e..f66e1ff9 100644
--- a/src/testzzuf/test_put_chunked.c
+++ b/src/testzzuf/test_put_chunked.c
@@ -87,34 +87,34 @@ ahc_echo (void *cls,
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 int have; 89 int have;
90 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 90 (void) version; (void) unused; /* Unused. Silent compiler warning. */
91 91
92 if (0 != strcmp ("PUT", method)) 92 if (0 != strcmp ("PUT", method))
93 return MHD_NO; /* unexpected method */ 93 return MHD_NO; /* unexpected method */
94 if ((*done) < 8) 94 if ((*done) < 8)
95 {
96 have = *upload_data_size;
97 if (have + *done > 8)
95 { 98 {
96 have = *upload_data_size; 99 return MHD_NO;
97 if (have + *done > 8) 100 }
98 { 101 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
99 return MHD_NO; 102 {
100 } 103 *done += have;
101 if (0 == memcmp (upload_data, &"Hello123"[*done], have)) 104 *upload_data_size = 0;
102 { 105 }
103 *done += have; 106 else
104 *upload_data_size = 0; 107 {
105 } 108 return MHD_NO;
106 else 109 }
107 {
108 return MHD_NO;
109 }
110#if 0 110#if 0
111 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); 111 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
112#endif 112#endif
113 return MHD_YES; 113 return MHD_YES;
114 } 114 }
115 response = MHD_create_response_from_buffer (strlen (url), 115 response = MHD_create_response_from_buffer (strlen (url),
116 (void *) url, 116 (void *) url,
117 MHD_RESPMEM_MUST_COPY); 117 MHD_RESPMEM_MUST_COPY);
118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
119 MHD_destroy_response (response); 119 MHD_destroy_response (response);
120 return ret; 120 return ret;
@@ -142,30 +142,30 @@ testInternalPut ()
142 return 1; 142 return 1;
143 zzuf_socat_start (); 143 zzuf_socat_start ();
144 for (i = 0; i < LOOP_COUNT; i++) 144 for (i = 0; i < LOOP_COUNT; i++)
145 { 145 {
146 fprintf (stderr, "."); 146 fprintf (stderr, ".");
147 c = curl_easy_init (); 147 c = curl_easy_init ();
148 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world"); 148 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world");
149 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 149 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
150 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 150 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
151 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 151 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
152 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 152 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
153 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 153 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
154 /* by not giving the file size, we force chunking! */ 154 /* by not giving the file size, we force chunking! */
155 /* 155 /*
156 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 156 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
157 */ 157 */
158 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 158 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
159 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 159 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
160 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 160 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
162 /* NOTE: use of CONNECTTIMEOUT without also 162 /* NOTE: use of CONNECTTIMEOUT without also
163 * setting NOSIGNAL results in really weird 163 * setting NOSIGNAL results in really weird
164 * crashes on my system! */ 164 * crashes on my system! */
165 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 165 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
166 curl_easy_perform (c); 166 curl_easy_perform (c);
167 curl_easy_cleanup (c); 167 curl_easy_cleanup (c);
168 } 168 }
169 fprintf (stderr, "\n"); 169 fprintf (stderr, "\n");
170 zzuf_socat_stop (); 170 zzuf_socat_stop ();
171 MHD_stop_daemon (d); 171 MHD_stop_daemon (d);
@@ -186,7 +186,8 @@ testMultithreadedPut ()
186 cbc.buf = buf; 186 cbc.buf = buf;
187 cbc.size = 2048; 187 cbc.size = 2048;
188 cbc.pos = 0; 188 cbc.pos = 0;
189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
190 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
190 11081, 191 11081,
191 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 192 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
192 if (d == NULL) 193 if (d == NULL)
@@ -211,14 +212,14 @@ testMultithreadedPut ()
211 * crashes on my system! */ 212 * crashes on my system! */
212 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 213 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
213 if (CURLE_OK != (errornum = curl_easy_perform (c))) 214 if (CURLE_OK != (errornum = curl_easy_perform (c)))
214 { 215 {
215 fprintf (stderr, 216 fprintf (stderr,
216 "curl_easy_perform failed: `%s'\n", 217 "curl_easy_perform failed: `%s'\n",
217 curl_easy_strerror (errornum)); 218 curl_easy_strerror (errornum));
218 curl_easy_cleanup (c); 219 curl_easy_cleanup (c);
219 MHD_stop_daemon (d); 220 MHD_stop_daemon (d);
220 return 32; 221 return 32;
221 } 222 }
222 curl_easy_cleanup (c); 223 curl_easy_cleanup (c);
223 MHD_stop_daemon (d); 224 MHD_stop_daemon (d);
224 if (cbc.pos != strlen ("/hello_world")) 225 if (cbc.pos != strlen ("/hello_world"))
@@ -262,90 +263,90 @@ testExternalPut ()
262 263
263 multi = curl_multi_init (); 264 multi = curl_multi_init ();
264 if (multi == NULL) 265 if (multi == NULL)
265 { 266 {
266 MHD_stop_daemon (d); 267 MHD_stop_daemon (d);
267 return 512; 268 return 512;
268 } 269 }
269 zzuf_socat_start (); 270 zzuf_socat_start ();
270 for (i = 0; i < LOOP_COUNT; i++) 271 for (i = 0; i < LOOP_COUNT; i++)
271 { 272 {
272 fprintf (stderr, "."); 273 fprintf (stderr, ".");
273 c = curl_easy_init (); 274 c = curl_easy_init ();
274 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world"); 275 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world");
275 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 276 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
276 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 277 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
277 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 278 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
278 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 279 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
279 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 280 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
280 /* by not giving the file size, we force chunking! */ 281 /* by not giving the file size, we force chunking! */
281 /* 282 /*
282 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 283 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
283 */ 284 */
284 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 285 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
285 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 286 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
286 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 287 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
287 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 288 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
288 /* NOTE: use of CONNECTTIMEOUT without also 289 /* NOTE: use of CONNECTTIMEOUT without also
289 * setting NOSIGNAL results in really weird 290 * setting NOSIGNAL results in really weird
290 * crashes on my system! */ 291 * crashes on my system! */
291 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 292 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
292 293
293 294
294 mret = curl_multi_add_handle (multi, c); 295 mret = curl_multi_add_handle (multi, c);
296 if (mret != CURLM_OK)
297 {
298 curl_multi_cleanup (multi);
299 curl_easy_cleanup (c);
300 zzuf_socat_stop ();
301 MHD_stop_daemon (d);
302 return 1024;
303 }
304 start = time (NULL);
305 while ((time (NULL) - start < 5) && (c != NULL))
306 {
307 max = 0;
308 FD_ZERO (&rs);
309 FD_ZERO (&ws);
310 FD_ZERO (&es);
311 curl_multi_perform (multi, &running);
312 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
295 if (mret != CURLM_OK) 313 if (mret != CURLM_OK)
296 { 314 {
297 curl_multi_cleanup (multi); 315 curl_multi_remove_handle (multi, c);
298 curl_easy_cleanup (c); 316 curl_multi_cleanup (multi);
299 zzuf_socat_stop (); 317 curl_easy_cleanup (c);
300 MHD_stop_daemon (d); 318 zzuf_socat_stop ();
301 return 1024; 319 MHD_stop_daemon (d);
302 } 320 return 2048;
303 start = time (NULL); 321 }
304 while ((time (NULL) - start < 5) && (c != NULL)) 322 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
305 { 323 {
306 max = 0; 324 curl_multi_remove_handle (multi, c);
307 FD_ZERO (&rs); 325 curl_multi_cleanup (multi);
308 FD_ZERO (&ws); 326 curl_easy_cleanup (c);
309 FD_ZERO (&es); 327 zzuf_socat_stop ();
310 curl_multi_perform (multi, &running); 328 MHD_stop_daemon (d);
311 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 329 return 4096;
312 if (mret != CURLM_OK) 330 }
313 { 331 tv.tv_sec = 0;
314 curl_multi_remove_handle (multi, c); 332 tv.tv_usec = 1000;
315 curl_multi_cleanup (multi); 333 select (max + 1, &rs, &ws, &es, &tv);
316 curl_easy_cleanup (c); 334 curl_multi_perform (multi, &running);
317 zzuf_socat_stop (); 335 if (running == 0)
318 MHD_stop_daemon (d); 336 {
319 return 2048; 337 curl_multi_info_read (multi, &running);
320 } 338 curl_multi_remove_handle (multi, c);
321 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 339 curl_easy_cleanup (c);
322 { 340 c = NULL;
323 curl_multi_remove_handle (multi, c); 341 }
324 curl_multi_cleanup (multi); 342 MHD_run (d);
325 curl_easy_cleanup (c); 343 }
326 zzuf_socat_stop (); 344 if (c != NULL)
327 MHD_stop_daemon (d); 345 {
328 return 4096; 346 curl_multi_remove_handle (multi, c);
329 } 347 curl_easy_cleanup (c);
330 tv.tv_sec = 0;
331 tv.tv_usec = 1000;
332 select (max + 1, &rs, &ws, &es, &tv);
333 curl_multi_perform (multi, &running);
334 if (running == 0)
335 {
336 curl_multi_info_read (multi, &running);
337 curl_multi_remove_handle (multi, c);
338 curl_easy_cleanup (c);
339 c = NULL;
340 }
341 MHD_run (d);
342 }
343 if (c != NULL)
344 {
345 curl_multi_remove_handle (multi, c);
346 curl_easy_cleanup (c);
347 }
348 } 348 }
349 }
349 fprintf (stderr, "\n"); 350 fprintf (stderr, "\n");
350 curl_multi_cleanup (multi); 351 curl_multi_cleanup (multi);
351 zzuf_socat_stop (); 352 zzuf_socat_stop ();
@@ -359,15 +360,15 @@ int
359main (int argc, char *const *argv) 360main (int argc, char *const *argv)
360{ 361{
361 unsigned int errorCount = 0; 362 unsigned int errorCount = 0;
362 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 363 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
363 364
364 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 365 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
365 return 2; 366 return 2;
366 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 367 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
367 { 368 {
368 errorCount += testInternalPut (); 369 errorCount += testInternalPut ();
369 errorCount += testMultithreadedPut (); 370 errorCount += testMultithreadedPut ();
370 } 371 }
371 errorCount += testExternalPut (); 372 errorCount += testExternalPut ();
372 if (errorCount != 0) 373 if (errorCount != 0)
373 fprintf (stderr, "Error (code: %u)\n", errorCount); 374 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put_large.c b/src/testzzuf/test_put_large.c
index 815ce77d..1186f583 100644
--- a/src/testzzuf/test_put_large.c
+++ b/src/testzzuf/test_put_large.c
@@ -94,35 +94,35 @@ ahc_echo (void *cls,
94 int *done = cls; 94 int *done = cls;
95 struct MHD_Response *response; 95 struct MHD_Response *response;
96 int ret; 96 int ret;
97 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 97 (void) version; (void) unused; /* Unused. Silent compiler warning. */
98 98
99 if (0 != strcmp ("PUT", method)) 99 if (0 != strcmp ("PUT", method))
100 return MHD_NO; /* unexpected method */ 100 return MHD_NO; /* unexpected method */
101 if ((*done) == 0) 101 if ((*done) == 0)
102 {
103 if (*upload_data_size != PUT_SIZE)
102 { 104 {
103 if (*upload_data_size != PUT_SIZE)
104 {
105#if 0 105#if 0
106 fprintf (stderr, 106 fprintf (stderr,
107 "Waiting for more data (%u/%u)...\n", 107 "Waiting for more data (%u/%u)...\n",
108 *upload_data_size, PUT_SIZE); 108 *upload_data_size, PUT_SIZE);
109#endif 109#endif
110 return MHD_YES; /* not yet ready */ 110 return MHD_YES; /* not yet ready */
111 }
112 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE))
113 {
114 *upload_data_size = 0;
115 }
116 else
117 {
118 return MHD_NO;
119 }
120 *done = 1;
121 return MHD_YES;
122 } 111 }
112 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE))
113 {
114 *upload_data_size = 0;
115 }
116 else
117 {
118 return MHD_NO;
119 }
120 *done = 1;
121 return MHD_YES;
122 }
123 response = MHD_create_response_from_buffer (strlen (url), 123 response = MHD_create_response_from_buffer (strlen (url),
124 (void *) url, 124 (void *) url,
125 MHD_RESPMEM_MUST_COPY); 125 MHD_RESPMEM_MUST_COPY);
126 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 126 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
127 MHD_destroy_response (response); 127 MHD_destroy_response (response);
128 return ret; 128 return ret;
@@ -143,38 +143,39 @@ testInternalPut ()
143 cbc.buf = buf; 143 cbc.buf = buf;
144 cbc.size = 2048; 144 cbc.size = 2048;
145 cbc.pos = 0; 145 cbc.pos = 0;
146 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 146 d = MHD_start_daemon (
147 11080, 147 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
148 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 148 11080,
149 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
149 if (d == NULL) 150 if (d == NULL)
150 return 1; 151 return 1;
151 zzuf_socat_start (); 152 zzuf_socat_start ();
152 for (i = 0; i < LOOP_COUNT; i++) 153 for (i = 0; i < LOOP_COUNT; i++)
153 { 154 {
154 fprintf (stderr, "."); 155 fprintf (stderr, ".");
155 156
156 c = curl_easy_init (); 157 c = curl_easy_init ();
157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 158 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 159 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 160 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
160 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 161 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
161 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 162 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
162 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 163 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
163 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE); 164 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
164 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
165 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 166 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
166 if (oneone) 167 if (oneone)
167 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 168 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
168 else 169 else
169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 170 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
170 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 171 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
171 /* NOTE: use of CONNECTTIMEOUT without also 172 /* NOTE: use of CONNECTTIMEOUT without also
172 * setting NOSIGNAL results in really weird 173 * setting NOSIGNAL results in really weird
173 * crashes on my system! */ 174 * crashes on my system! */
174 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
175 curl_easy_perform (c); 176 curl_easy_perform (c);
176 curl_easy_cleanup (c); 177 curl_easy_cleanup (c);
177 } 178 }
178 fprintf (stderr, "\n"); 179 fprintf (stderr, "\n");
179 zzuf_socat_stop (); 180 zzuf_socat_stop ();
180 MHD_stop_daemon (d); 181 MHD_stop_daemon (d);
@@ -195,38 +196,39 @@ testMultithreadedPut ()
195 cbc.buf = buf; 196 cbc.buf = buf;
196 cbc.size = 2048; 197 cbc.size = 2048;
197 cbc.pos = 0; 198 cbc.pos = 0;
198 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 199 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
200 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
199 11080, 201 11080,
200 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 202 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
201 if (d == NULL) 203 if (d == NULL)
202 return 16; 204 return 16;
203 zzuf_socat_start (); 205 zzuf_socat_start ();
204 for (i = 0; i < LOOP_COUNT; i++) 206 for (i = 0; i < LOOP_COUNT; i++)
205 { 207 {
206 fprintf (stderr, "."); 208 fprintf (stderr, ".");
207 209
208 c = curl_easy_init (); 210 c = curl_easy_init ();
209 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 211 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
210 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 212 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
211 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 213 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
212 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 214 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
213 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 215 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
214 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 216 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
215 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE); 217 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
216 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 218 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
217 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 219 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
218 if (oneone) 220 if (oneone)
219 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 221 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
220 else 222 else
221 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 223 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
222 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 224 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
223 /* NOTE: use of CONNECTTIMEOUT without also 225 /* NOTE: use of CONNECTTIMEOUT without also
224 * setting NOSIGNAL results in really weird 226 * setting NOSIGNAL results in really weird
225 * crashes on my system! */ 227 * crashes on my system! */
226 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 228 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
227 curl_easy_perform (c); 229 curl_easy_perform (c);
228 curl_easy_cleanup (c); 230 curl_easy_cleanup (c);
229 } 231 }
230 fprintf (stderr, "\n"); 232 fprintf (stderr, "\n");
231 zzuf_socat_stop (); 233 zzuf_socat_stop ();
232 MHD_stop_daemon (d); 234 MHD_stop_daemon (d);
@@ -267,92 +269,92 @@ testExternalPut ()
267 return 256; 269 return 256;
268 multi = curl_multi_init (); 270 multi = curl_multi_init ();
269 if (multi == NULL) 271 if (multi == NULL)
272 {
273 MHD_stop_daemon (d);
274 return 512;
275 }
276 zzuf_socat_start ();
277 for (i = 0; i < LOOP_COUNT; i++)
278 {
279 fprintf (stderr, ".");
280
281 c = curl_easy_init ();
282 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
283 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
284 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
285 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
286 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
287 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
288 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
289 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
290 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
291 if (oneone)
292 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
293 else
294 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
295 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
296 /* NOTE: use of CONNECTTIMEOUT without also
297 * setting NOSIGNAL results in really weird
298 * crashes on my system! */
299 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
300
301
302
303 mret = curl_multi_add_handle (multi, c);
304 if (mret != CURLM_OK)
270 { 305 {
306 curl_multi_cleanup (multi);
307 curl_easy_cleanup (c);
308 zzuf_socat_stop ();
271 MHD_stop_daemon (d); 309 MHD_stop_daemon (d);
272 return 512; 310 return 1024;
273 } 311 }
274 zzuf_socat_start (); 312 start = time (NULL);
275 for (i = 0; i < LOOP_COUNT; i++) 313 while ((time (NULL) - start < 5) && (c != NULL))
276 { 314 {
277 fprintf (stderr, "."); 315 max = 0;
278 316 FD_ZERO (&rs);
279 c = curl_easy_init (); 317 FD_ZERO (&ws);
280 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 318 FD_ZERO (&es);
281 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 319 curl_multi_perform (multi, &running);
282 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 320 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
283 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
284 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
285 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
286 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
287 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
288 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
289 if (oneone)
290 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
291 else
292 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
293 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
294 /* NOTE: use of CONNECTTIMEOUT without also
295 * setting NOSIGNAL results in really weird
296 * crashes on my system! */
297 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
298
299
300
301 mret = curl_multi_add_handle (multi, c);
302 if (mret != CURLM_OK) 321 if (mret != CURLM_OK)
303 { 322 {
304 curl_multi_cleanup (multi); 323 curl_multi_remove_handle (multi, c);
305 curl_easy_cleanup (c); 324 curl_multi_cleanup (multi);
306 zzuf_socat_stop (); 325 curl_easy_cleanup (c);
307 MHD_stop_daemon (d); 326 zzuf_socat_stop ();
308 return 1024; 327 MHD_stop_daemon (d);
309 } 328 return 2048;
310 start = time (NULL); 329 }
311 while ((time (NULL) - start < 5) && (c != NULL)) 330 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
312 { 331 {
313 max = 0; 332 curl_multi_remove_handle (multi, c);
314 FD_ZERO (&rs); 333 curl_multi_cleanup (multi);
315 FD_ZERO (&ws); 334 curl_easy_cleanup (c);
316 FD_ZERO (&es); 335 zzuf_socat_stop ();
317 curl_multi_perform (multi, &running); 336 MHD_stop_daemon (d);
318 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 337 return 4096;
319 if (mret != CURLM_OK) 338 }
320 { 339 tv.tv_sec = 0;
321 curl_multi_remove_handle (multi, c); 340 tv.tv_usec = 1000;
322 curl_multi_cleanup (multi); 341 select (max + 1, &rs, &ws, &es, &tv);
323 curl_easy_cleanup (c); 342 curl_multi_perform (multi, &running);
324 zzuf_socat_stop (); 343 if (running == 0)
325 MHD_stop_daemon (d); 344 {
326 return 2048; 345 curl_multi_info_read (multi, &running);
327 } 346 curl_multi_remove_handle (multi, c);
328 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 347 curl_easy_cleanup (c);
329 { 348 c = NULL;
330 curl_multi_remove_handle (multi, c); 349 }
331 curl_multi_cleanup (multi); 350 MHD_run (d);
332 curl_easy_cleanup (c);
333 zzuf_socat_stop ();
334 MHD_stop_daemon (d);
335 return 4096;
336 }
337 tv.tv_sec = 0;
338 tv.tv_usec = 1000;
339 select (max + 1, &rs, &ws, &es, &tv);
340 curl_multi_perform (multi, &running);
341 if (running == 0)
342 {
343 curl_multi_info_read (multi, &running);
344 curl_multi_remove_handle (multi, c);
345 curl_easy_cleanup (c);
346 c = NULL;
347 }
348 MHD_run (d);
349 }
350 if (c != NULL)
351 {
352 curl_multi_remove_handle (multi, c);
353 curl_easy_cleanup (c);
354 }
355 } 351 }
352 if (c != NULL)
353 {
354 curl_multi_remove_handle (multi, c);
355 curl_easy_cleanup (c);
356 }
357 }
356 fprintf (stderr, "\n"); 358 fprintf (stderr, "\n");
357 zzuf_socat_stop (); 359 zzuf_socat_stop ();
358 curl_multi_cleanup (multi); 360 curl_multi_cleanup (multi);
@@ -365,19 +367,19 @@ int
365main (int argc, char *const *argv) 367main (int argc, char *const *argv)
366{ 368{
367 unsigned int errorCount = 0; 369 unsigned int errorCount = 0;
368 (void)argc; /* Unused. Silent compiler warning. */ 370 (void) argc; /* Unused. Silent compiler warning. */
369 371
370 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 372 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
371 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 373 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
372 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 374 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
373 return 2; 375 return 2;
374 put_buffer = malloc (PUT_SIZE); 376 put_buffer = malloc (PUT_SIZE);
375 memset (put_buffer, 1, PUT_SIZE); 377 memset (put_buffer, 1, PUT_SIZE);
376 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 378 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
377 { 379 {
378 errorCount += testInternalPut (); 380 errorCount += testInternalPut ();
379 errorCount += testMultithreadedPut (); 381 errorCount += testMultithreadedPut ();
380 } 382 }
381 errorCount += testExternalPut (); 383 errorCount += testExternalPut ();
382 free (put_buffer); 384 free (put_buffer);
383 if (errorCount != 0) 385 if (errorCount != 0)