aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon/EXPORT.sym1
-rw-r--r--src/daemon/connection.c7
-rw-r--r--src/daemon/connection_https.c2
-rw-r--r--src/daemon/connection_https.h2
-rw-r--r--src/daemon/daemon.c30
-rw-r--r--src/daemon/internal.h34
-rw-r--r--src/daemon/response.c22
-rw-r--r--src/include/microhttpd.h2
-rw-r--r--src/testcurl/Makefile.am14
-rw-r--r--src/testcurl/daemontest_get_sendfile.c463
-rw-r--r--src/testcurl/https/mhds_get_test.c36
-rw-r--r--src/testcurl/https/tls_daemon_options_test.c44
12 files changed, 572 insertions, 85 deletions
diff --git a/src/daemon/EXPORT.sym b/src/daemon/EXPORT.sym
index 32096ad6..53bd960b 100644
--- a/src/daemon/EXPORT.sym
+++ b/src/daemon/EXPORT.sym
@@ -10,6 +10,7 @@ MHD_lookup_connection_value
10MHD_queue_response 10MHD_queue_response
11MHD_create_response_from_callback 11MHD_create_response_from_callback
12MHD_create_response_from_data 12MHD_create_response_from_data
13MHD_create_response_from_fd
13MHD_destroy_response 14MHD_destroy_response
14MHD_add_response_header 15MHD_add_response_header
15MHD_del_response_header 16MHD_del_response_header
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index dab19472..a56106a4 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2008 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -336,7 +336,10 @@ try_ready_normal_body (struct MHD_Connection *connection)
336#if LINUX 336#if LINUX
337 if ( (response->fd != -1) && 337 if ( (response->fd != -1) &&
338 (0 == (connection->daemon->options & MHD_USE_SSL)) ) 338 (0 == (connection->daemon->options & MHD_USE_SSL)) )
339 return MHD_YES; /* will use sendfile */ 339 {
340 /* will use sendfile, no need to bother response crc */
341 return MHD_YES;
342 }
340#endif 343#endif
341 ret = response->crc (response->crc_cls, 344 ret = response->crc (response->crc_cls,
342 connection->response_write_position, 345 connection->response_write_position,
diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c
index b00da807..e24da021 100644
--- a/src/daemon/connection_https.c
+++ b/src/daemon/connection_https.c
@@ -198,7 +198,7 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection)
198 * the processing of this secure connection. 198 * the processing of this secure connection.
199 */ 199 */
200void 200void
201MHD_set_https_calbacks (struct MHD_Connection *connection) 201MHD_set_https_callbacks (struct MHD_Connection *connection)
202{ 202{
203 connection->read_handler = &MHD_tls_connection_handle_read; 203 connection->read_handler = &MHD_tls_connection_handle_read;
204 connection->write_handler = &MHD_tls_connection_handle_write; 204 connection->write_handler = &MHD_tls_connection_handle_write;
diff --git a/src/daemon/connection_https.h b/src/daemon/connection_https.h
index ef6f5dc6..8a5cf380 100644
--- a/src/daemon/connection_https.h
+++ b/src/daemon/connection_https.h
@@ -29,7 +29,7 @@
29#include "internal.h" 29#include "internal.h"
30 30
31#if HTTPS_SUPPORT 31#if HTTPS_SUPPORT
32void MHD_set_https_calbacks (struct MHD_Connection *connection); 32void MHD_set_https_callbacks (struct MHD_Connection *connection);
33#endif 33#endif
34 34
35#endif 35#endif
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f704382d..73a0f163 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2008, 2009 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -387,8 +387,8 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
387 cert.size = strlen (daemon->https_mem_cert); 387 cert.size = strlen (daemon->https_mem_cert);
388 388
389 return gnutls_certificate_set_x509_key_mem (daemon->x509_cred, 389 return gnutls_certificate_set_x509_key_mem (daemon->x509_cred,
390 &cert, &key, 390 &cert, &key,
391 GNUTLS_X509_FMT_PEM); 391 GNUTLS_X509_FMT_PEM);
392 } 392 }
393#if HAVE_MESSAGES 393#if HAVE_MESSAGES
394 MHD_DLOG (daemon, "You need to specify a certificate and key location\n"); 394 MHD_DLOG (daemon, "You need to specify a certificate and key location\n");
@@ -625,21 +625,28 @@ send_param_adapter (struct MHD_Connection *connection,
625#if LINUX 625#if LINUX
626 int fd; 626 int fd;
627 off_t offset; 627 off_t offset;
628 int ret;
628#endif 629#endif
629 if (connection->socket_fd == -1) 630 if (connection->socket_fd == -1)
630 return -1; 631 return -1;
631 if (0 != (connection->daemon->options & MHD_USE_SSL)) 632 if (0 != (connection->daemon->options & MHD_USE_SSL))
632 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL); 633 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL);
633#if LINUX 634#if LINUX
634 if ( (NULL != connection->response) && 635 if ( (connection->write_buffer_append_offset ==
636 connection->write_buffer_send_offset) &&
637 (NULL != connection->response) &&
635 (-1 != (fd = connection->response->fd)) ) 638 (-1 != (fd = connection->response->fd)) )
636 { 639 {
637 /* can use sendfile */ 640 /* can use sendfile */
638 offset = (off_t) connection->response_write_position; 641 offset = (off_t) connection->response_write_position;
639 return sendfile (connection->socket_fd, 642 ret = sendfile (connection->socket_fd,
640 fd, 643 fd,
641 &offset, 644 &offset,
642 i); 645 connection->response->total_size - offset);
646 if ( (ret == -1) &&
647 (errno == EINTR) )
648 return 0;
649 return ret;
643 } 650 }
644#endif 651#endif
645 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT); 652 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT);
@@ -819,7 +826,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
819 connection->recv_cls = &recv_tls_adapter; 826 connection->recv_cls = &recv_tls_adapter;
820 connection->send_cls = &send_tls_adapter; 827 connection->send_cls = &send_tls_adapter;
821 connection->state = MHD_TLS_CONNECTION_INIT; 828 connection->state = MHD_TLS_CONNECTION_INIT;
822 MHD_set_https_calbacks (connection); 829 MHD_set_https_callbacks (connection);
823 gnutls_init (&connection->tls_session, GNUTLS_SERVER); 830 gnutls_init (&connection->tls_session, GNUTLS_SERVER);
824 gnutls_priority_set (connection->tls_session, 831 gnutls_priority_set (connection->tls_session,
825 daemon->priority_cache); 832 daemon->priority_cache);
@@ -1664,7 +1671,10 @@ MHD_start_daemon_va (unsigned int options,
1664 return NULL; 1671 return NULL;
1665 } 1672 }
1666 } 1673 }
1667 1674 else
1675 {
1676 socket_fd = retVal->socket_fd;
1677 }
1668#ifndef WINDOWS 1678#ifndef WINDOWS
1669 if ( (socket_fd >= FD_SETSIZE) && 1679 if ( (socket_fd >= FD_SETSIZE) &&
1670 (0 == (options & MHD_USE_POLL)) ) 1680 (0 == (options & MHD_USE_POLL)) )
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index a026eeef..f3f47ce0 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -1,21 +1,21 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version. 8 version 2.1 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details. 13 Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU Lesser General Public 15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software 16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 18*/
19 19
20/** 20/**
21 * @file internal.h 21 * @file internal.h
diff --git a/src/daemon/response.c b/src/daemon/response.c
index 0f5501ee..f1379301 100644
--- a/src/daemon/response.c
+++ b/src/daemon/response.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2009 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -210,7 +210,7 @@ MHD_create_response_from_callback (uint64_t size,
210 * Given a file descriptor, read data from the file 210 * Given a file descriptor, read data from the file
211 * to generate the response. 211 * to generate the response.
212 * 212 *
213 * @param cls pointer to the file descriptor 213 * @param cls pointer to the response
214 * @param pos offset in the file to access 214 * @param pos offset in the file to access
215 * @param buf where to write the data 215 * @param buf where to write the data
216 * @param max number of bytes to write at most 216 * @param max number of bytes to write at most
@@ -219,10 +219,14 @@ MHD_create_response_from_callback (uint64_t size,
219static int 219static int
220file_reader (void *cls, uint64_t pos, char *buf, int max) 220file_reader (void *cls, uint64_t pos, char *buf, int max)
221{ 221{
222 int *fd = cls; 222 struct MHD_Response *response = cls;
223 int ret;
223 224
224 (void) lseek (*fd, pos, SEEK_SET); 225 pthread_mutex_lock (&response->mutex);
225 return read (*fd, buf, max); 226 (void) lseek (response->fd, pos, SEEK_SET);
227 ret = read (response->fd, buf, max);
228 pthread_mutex_unlock (&response->mutex);
229 return ret;
226} 230}
227 231
228 232
@@ -235,9 +239,9 @@ file_reader (void *cls, uint64_t pos, char *buf, int max)
235static void 239static void
236free_callback (void *cls) 240free_callback (void *cls)
237{ 241{
238 int *fd = cls; 242 struct MHD_Response *response = cls;
239 close (*fd); 243 (void) close (response->fd);
240 *fd = -1; 244 response->fd = -1;
241} 245}
242 246
243 247
@@ -262,7 +266,7 @@ struct MHD_Response *MHD_create_response_from_fd (size_t size,
262 if (ret == NULL) 266 if (ret == NULL)
263 return NULL; 267 return NULL;
264 ret->fd = fd; 268 ret->fd = fd;
265 ret->crc_cls = &ret->fd; 269 ret->crc_cls = ret;
266 return ret; 270 return ret;
267} 271}
268 272
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 65f2aa89..67071999 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -81,7 +81,7 @@ extern "C"
81/** 81/**
82 * Current version of the library. 82 * Current version of the library.
83 */ 83 */
84#define MHD_VERSION 0x00040600 84#define MHD_VERSION 0x00090000
85 85
86/** 86/**
87 * MHD-internal return code for "YES". 87 * MHD-internal return code for "YES".
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am
index 1e9fe19d..c7124a19 100644
--- a/src/testcurl/Makefile.am
+++ b/src/testcurl/Makefile.am
@@ -16,6 +16,7 @@ $(LIBCURL_CPPFLAGS)
16 16
17check_PROGRAMS = \ 17check_PROGRAMS = \
18 daemontest_get \ 18 daemontest_get \
19 daemontest_get_sendfile \
19 daemontest_post \ 20 daemontest_post \
20 daemontest_postform \ 21 daemontest_postform \
21 daemontest_post_loop \ 22 daemontest_post_loop \
@@ -25,6 +26,7 @@ check_PROGRAMS = \
25 daemontest_parse_cookies \ 26 daemontest_parse_cookies \
26 daemontest_large_put \ 27 daemontest_large_put \
27 daemontest_get11 \ 28 daemontest_get11 \
29 daemontest_get_sendfile11 \
28 daemontest_post11 \ 30 daemontest_post11 \
29 daemontest_postform11 \ 31 daemontest_postform11 \
30 daemontest_post_loop11 \ 32 daemontest_post_loop11 \
@@ -57,6 +59,12 @@ daemontest_get_LDADD = \
57 $(top_builddir)/src/daemon/libmicrohttpd.la \ 59 $(top_builddir)/src/daemon/libmicrohttpd.la \
58 @LIBCURL@ 60 @LIBCURL@
59 61
62daemontest_get_sendfile_SOURCES = \
63 daemontest_get_sendfile.c
64daemontest_get_sendfile_LDADD = \
65 $(top_builddir)/src/daemon/libmicrohttpd.la \
66 @LIBCURL@
67
60daemontest_get_chunked_SOURCES = \ 68daemontest_get_chunked_SOURCES = \
61 daemontest_get_chunked.c 69 daemontest_get_chunked.c
62daemontest_get_chunked_LDADD = \ 70daemontest_get_chunked_LDADD = \
@@ -117,6 +125,12 @@ daemontest_get11_LDADD = \
117 $(top_builddir)/src/daemon/libmicrohttpd.la \ 125 $(top_builddir)/src/daemon/libmicrohttpd.la \
118 @LIBCURL@ 126 @LIBCURL@
119 127
128daemontest_get_sendfile11_SOURCES = \
129 daemontest_get_sendfile.c
130daemontest_get_sendfile11_LDADD = \
131 $(top_builddir)/src/daemon/libmicrohttpd.la \
132 @LIBCURL@
133
120daemontest_post11_SOURCES = \ 134daemontest_post11_SOURCES = \
121 daemontest_post.c 135 daemontest_post.c
122daemontest_post11_LDADD = \ 136daemontest_post11_LDADD = \
diff --git a/src/testcurl/daemontest_get_sendfile.c b/src/testcurl/daemontest_get_sendfile.c
new file mode 100644
index 00000000..8116c3c9
--- /dev/null
+++ b/src/testcurl/daemontest_get_sendfile.c
@@ -0,0 +1,463 @@
1/* DO NOT CHANGE THIS LINE */
2/*
3 This file is part of libmicrohttpd
4 (C) 2007, 2009 Christian Grothoff
5
6 libmicrohttpd is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
10
11 libmicrohttpd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with libmicrohttpd; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/**
23 * @file daemontest_get_sendfile.c
24 * @brief Testcase for libmicrohttpd response from FD
25 * @author Christian Grothoff
26 */
27
28#include "MHD_config.h"
29#include "platform.h"
30#include <curl/curl.h>
31#include <microhttpd.h>
32#include <stdlib.h>
33#include <string.h>
34#include <time.h>
35#include <sys/socket.h>
36#include <sys/types.h>
37#include <fcntl.h>
38
39#ifndef WINDOWS
40#include <unistd.h>
41#endif
42
43#define TESTSTR "/* DO NOT CHANGE THIS LINE */"
44
45static int oneone;
46
47struct CBC
48{
49 char *buf;
50 size_t pos;
51 size_t size;
52};
53
54static size_t
55copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
56{
57 struct CBC *cbc = ctx;
58
59 if (cbc->pos + size * nmemb > cbc->size)
60 return 0; /* overflow */
61 memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
62 cbc->pos += size * nmemb;
63 return size * nmemb;
64}
65
66
67static int
68ahc_echo (void *cls,
69 struct MHD_Connection *connection,
70 const char *url,
71 const char *method,
72 const char *version,
73 const char *upload_data, size_t *upload_data_size,
74 void **unused)
75{
76 static int ptr;
77 const char *me = cls;
78 struct MHD_Response *response;
79 int ret;
80 int fd;
81
82 if (0 != strcmp (me, method))
83 return MHD_NO; /* unexpected method */
84 if (&ptr != *unused)
85 {
86 *unused = &ptr;
87 return MHD_YES;
88 }
89 *unused = NULL;
90 fd = open ("daemontest_get_sendfile.c", O_RDONLY);
91 if (fd == -1)
92 abort ();
93 response = MHD_create_response_from_fd (strlen (TESTSTR), fd);
94 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
95 MHD_destroy_response (response);
96 if (ret == MHD_NO)
97 abort ();
98 return ret;
99}
100
101
102static int
103testInternalGet ()
104{
105 struct MHD_Daemon *d;
106 CURL *c;
107 char buf[2048];
108 struct CBC cbc;
109 CURLcode errornum;
110
111 cbc.buf = buf;
112 cbc.size = 2048;
113 cbc.pos = 0;
114 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
115 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
116 if (d == NULL)
117 return 1;
118 c = curl_easy_init ();
119 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/");
120 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
121 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
122 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
123 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
124 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
125 if (oneone)
126 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
127 else
128 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
129 /* NOTE: use of CONNECTTIMEOUT without also
130 setting NOSIGNAL results in really weird
131 crashes on my system!*/
132 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
133 if (CURLE_OK != (errornum = curl_easy_perform (c)))
134 {
135 fprintf (stderr,
136 "curl_easy_perform failed: `%s'\n",
137 curl_easy_strerror (errornum));
138 curl_easy_cleanup (c);
139 MHD_stop_daemon (d);
140 return 2;
141 }
142 curl_easy_cleanup (c);
143 MHD_stop_daemon (d);
144 if (cbc.pos != strlen (TESTSTR))
145 return 4;
146 if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
147 return 8;
148 return 0;
149}
150
151static int
152testMultithreadedGet ()
153{
154 struct MHD_Daemon *d;
155 CURL *c;
156 char buf[2048];
157 struct CBC cbc;
158 CURLcode errornum;
159
160 cbc.buf = buf;
161 cbc.size = 2048;
162 cbc.pos = 0;
163 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
164 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
165 if (d == NULL)
166 return 16;
167 c = curl_easy_init ();
168 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/");
169 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
170 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
171 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
172 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
173 if (oneone)
174 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
175 else
176 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
177 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
178 /* NOTE: use of CONNECTTIMEOUT without also
179 setting NOSIGNAL results in really weird
180 crashes on my system! */
181 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
182 if (CURLE_OK != (errornum = curl_easy_perform (c)))
183 {
184 fprintf (stderr,
185 "curl_easy_perform failed: `%s'\n",
186 curl_easy_strerror (errornum));
187 curl_easy_cleanup (c);
188 MHD_stop_daemon (d);
189 return 32;
190 }
191 curl_easy_cleanup (c);
192 MHD_stop_daemon (d);
193 if (cbc.pos != strlen (TESTSTR))
194 return 64;
195 if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
196 return 128;
197 return 0;
198}
199
200static int
201testMultithreadedPoolGet ()
202{
203 struct MHD_Daemon *d;
204 CURL *c;
205 char buf[2048];
206 struct CBC cbc;
207 CURLcode errornum;
208
209 cbc.buf = buf;
210 cbc.size = 2048;
211 cbc.pos = 0;
212 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
213 1081, NULL, NULL, &ahc_echo, "GET",
214 MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END);
215 if (d == NULL)
216 return 16;
217 c = curl_easy_init ();
218 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/");
219 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
220 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
221 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
222 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
223 if (oneone)
224 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
225 else
226 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
227 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
228 /* NOTE: use of CONNECTTIMEOUT without also
229 setting NOSIGNAL results in really weird
230 crashes on my system!*/
231 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
232 if (CURLE_OK != (errornum = curl_easy_perform (c)))
233 {
234 fprintf (stderr,
235 "curl_easy_perform failed: `%s'\n",
236 curl_easy_strerror (errornum));
237 curl_easy_cleanup (c);
238 MHD_stop_daemon (d);
239 return 32;
240 }
241 curl_easy_cleanup (c);
242 MHD_stop_daemon (d);
243 if (cbc.pos != strlen (TESTSTR))
244 return 64;
245 if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
246 return 128;
247 return 0;
248}
249
250static int
251testExternalGet ()
252{
253 struct MHD_Daemon *d;
254 CURL *c;
255 char buf[2048];
256 struct CBC cbc;
257 CURLM *multi;
258 CURLMcode mret;
259 fd_set rs;
260 fd_set ws;
261 fd_set es;
262 int max;
263 int running;
264 struct CURLMsg *msg;
265 time_t start;
266 struct timeval tv;
267
268 multi = NULL;
269 cbc.buf = buf;
270 cbc.size = 2048;
271 cbc.pos = 0;
272 d = MHD_start_daemon (MHD_USE_DEBUG,
273 1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
274 if (d == NULL)
275 return 256;
276 c = curl_easy_init ();
277 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/");
278 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
279 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
280 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
281 if (oneone)
282 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
283 else
284 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
285 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
286 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
287 /* NOTE: use of CONNECTTIMEOUT without also
288 setting NOSIGNAL results in really weird
289 crashes on my system! */
290 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
291
292
293 multi = curl_multi_init ();
294 if (multi == NULL)
295 {
296 curl_easy_cleanup (c);
297 MHD_stop_daemon (d);
298 return 512;
299 }
300 mret = curl_multi_add_handle (multi, c);
301 if (mret != CURLM_OK)
302 {
303 curl_multi_cleanup (multi);
304 curl_easy_cleanup (c);
305 MHD_stop_daemon (d);
306 return 1024;
307 }
308 start = time (NULL);
309 while ((time (NULL) - start < 5) && (multi != NULL))
310 {
311 max = 0;
312 FD_ZERO (&rs);
313 FD_ZERO (&ws);
314 FD_ZERO (&es);
315 curl_multi_perform (multi, &running);
316 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
317 if (mret != CURLM_OK)
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_multi_cleanup (multi);
321 curl_easy_cleanup (c);
322 MHD_stop_daemon (d);
323 return 2048;
324 }
325 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
326 {
327 curl_multi_remove_handle (multi, c);
328 curl_multi_cleanup (multi);
329 curl_easy_cleanup (c);
330 MHD_stop_daemon (d);
331 return 4096;
332 }
333 tv.tv_sec = 0;
334 tv.tv_usec = 1000;
335 select (max + 1, &rs, &ws, &es, &tv);
336 curl_multi_perform (multi, &running);
337 if (running == 0)
338 {
339 msg = curl_multi_info_read (multi, &running);
340 if (msg == NULL)
341 break;
342 if (msg->msg == CURLMSG_DONE)
343 {
344 if (msg->data.result != CURLE_OK)
345 printf ("%s failed at %s:%d: `%s'\n",
346 "curl_multi_perform",
347 __FILE__,
348 __LINE__, curl_easy_strerror (msg->data.result));
349 curl_multi_remove_handle (multi, c);
350 curl_multi_cleanup (multi);
351 curl_easy_cleanup (c);
352 c = NULL;
353 multi = NULL;
354 }
355 }
356 MHD_run (d);
357 }
358 if (multi != NULL)
359 {
360 curl_multi_remove_handle (multi, c);
361 curl_easy_cleanup (c);
362 curl_multi_cleanup (multi);
363 }
364 MHD_stop_daemon (d);
365 if (cbc.pos != strlen (TESTSTR))
366 return 8192;
367 if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
368 return 16384;
369 return 0;
370}
371
372static int
373testUnknownPortGet ()
374{
375 struct MHD_Daemon *d;
376 const union MHD_DaemonInfo *di;
377 CURL *c;
378 char buf[2048];
379 struct CBC cbc;
380 CURLcode errornum;
381
382 struct sockaddr_in addr;
383 socklen_t addr_len = sizeof(addr);
384 memset(&addr, 0, sizeof(addr));
385 addr.sin_family = AF_INET;
386 addr.sin_port = 0;
387 addr.sin_addr.s_addr = INADDR_ANY;
388
389 cbc.buf = buf;
390 cbc.size = 2048;
391 cbc.pos = 0;
392 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
393 1, NULL, NULL, &ahc_echo, "GET",
394 MHD_OPTION_SOCK_ADDR, &addr,
395 MHD_OPTION_END);
396 if (d == NULL)
397 return 32768;
398
399 di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD);
400 if (di == NULL)
401 return 65536;
402
403 if (0 != getsockname(di->listen_fd, &addr, &addr_len))
404 return 131072;
405
406 if (addr.sin_family != AF_INET)
407 return 26214;
408
409 snprintf(buf, sizeof(buf), "http://localhost:%hu/",
410 ntohs(addr.sin_port));
411
412 c = curl_easy_init ();
413 curl_easy_setopt (c, CURLOPT_URL, buf);
414 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
415 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
416 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
417 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
418 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
419 if (oneone)
420 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
421 else
422 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
423 /* NOTE: use of CONNECTTIMEOUT without also
424 setting NOSIGNAL results in really weird
425 crashes on my system! */
426 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
427 if (CURLE_OK != (errornum = curl_easy_perform (c)))
428 {
429 fprintf (stderr,
430 "curl_easy_perform failed: `%s'\n",
431 curl_easy_strerror (errornum));
432 curl_easy_cleanup (c);
433 MHD_stop_daemon (d);
434 return 524288;
435 }
436 curl_easy_cleanup (c);
437 MHD_stop_daemon (d);
438 if (cbc.pos != strlen (TESTSTR))
439 return 1048576;
440 if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
441 return 2097152;
442 return 0;
443}
444
445
446int
447main (int argc, char *const *argv)
448{
449 unsigned int errorCount = 0;
450
451 oneone = NULL != strstr (argv[0], "11");
452 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
453 return 2;
454 errorCount += testInternalGet ();
455 errorCount += testMultithreadedGet ();
456 errorCount += testMultithreadedPoolGet ();
457 errorCount += testExternalGet ();
458 errorCount += testUnknownPortGet ();
459 if (errorCount != 0)
460 fprintf (stderr, "Error (code: %u)\n", errorCount);
461 curl_global_cleanup ();
462 return errorCount != 0; /* 0 == pass */
463}
diff --git a/src/testcurl/https/mhds_get_test.c b/src/testcurl/https/mhds_get_test.c
index eef3f2b2..7fdf1a4e 100644
--- a/src/testcurl/https/mhds_get_test.c
+++ b/src/testcurl/https/mhds_get_test.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your 7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 libmicrohttpd is distributed in the hope that it will be useful, but 10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the 16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19*/
20 20
21/** 21/**
22 * @file mhds_get_test.c 22 * @file mhds_get_test.c
diff --git a/src/testcurl/https/tls_daemon_options_test.c b/src/testcurl/https/tls_daemon_options_test.c
index 2d859428..3e269122 100644
--- a/src/testcurl/https/tls_daemon_options_test.c
+++ b/src/testcurl/https/tls_daemon_options_test.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2010 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your 7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 libmicrohttpd is distributed in the hope that it will be useful, but 10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the 16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19*/
20 20
21/** 21/**
22 * @file tls_daemon_options_test.c 22 * @file tls_daemon_options_test.c
@@ -103,7 +103,6 @@ main (int argc, char *const *argv)
103 fprintf (stderr, "Error: %s\n", strerror (errno)); 103 fprintf (stderr, "Error: %s\n", strerror (errno));
104 return -1; 104 return -1;
105 } 105 }
106#if 0
107 errorCount += 106 errorCount +=
108 test_wrap ("TLS1.0-AES-SHA1", 107 test_wrap ("TLS1.0-AES-SHA1",
109 &test_https_transfer, test_fd, daemon_flags, 108 &test_https_transfer, test_fd, daemon_flags,
@@ -113,8 +112,6 @@ main (int argc, char *const *argv)
113 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 112 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
114 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL", 113 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
115 MHD_OPTION_END); 114 MHD_OPTION_END);
116#endif
117#if 0
118 errorCount += 115 errorCount +=
119 test_wrap ("TLS1.0-AES-SHA1", 116 test_wrap ("TLS1.0-AES-SHA1",
120 &test_https_transfer, test_fd, daemon_flags, 117 &test_https_transfer, test_fd, daemon_flags,
@@ -134,8 +131,6 @@ main (int argc, char *const *argv)
134 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 131 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
135 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-SSL3.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL", 132 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-SSL3.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
136 MHD_OPTION_END); 133 MHD_OPTION_END);
137#endif
138
139#if 0 134#if 0
140 /* manual inspection of the handshake suggests that CURL will 135 /* manual inspection of the handshake suggests that CURL will
141 request TLSv1, we send back "SSL3" and CURL takes it *despite* 136 request TLSv1, we send back "SSL3" and CURL takes it *despite*
@@ -152,7 +147,6 @@ main (int argc, char *const *argv)
152 MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END); 147 MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
153#endif 148#endif
154 149
155#if 1
156 errorCount += 150 errorCount +=
157 test_wrap ("TLS1.0 vs SSL3", 151 test_wrap ("TLS1.0 vs SSL3",
158 &test_unmatching_ssl_version, test_fd, daemon_flags, 152 &test_unmatching_ssl_version, test_fd, daemon_flags,
@@ -162,8 +156,6 @@ main (int argc, char *const *argv)
162 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 156 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
163 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL", 157 MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
164 MHD_OPTION_END); 158 MHD_OPTION_END);
165#endif
166
167 curl_global_cleanup (); 159 curl_global_cleanup ();
168 fclose (test_fd); 160 fclose (test_fd);
169 remove (TEST_FILE_NAME); 161 remove (TEST_FILE_NAME);