diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-02-14 04:19:04 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-02-14 04:19:04 +0100 |
commit | bf5c5c10f480a01da85ac47ef288f2c2bfea3444 (patch) | |
tree | 1aa826f517cb2e4240b10bbdb94ba008074e3644 | |
parent | 48dd53c7eb6a0ec3f47c23511bcf94d3f6f52e24 (diff) | |
download | libmicrohttpd-bf5c5c10f480a01da85ac47ef288f2c2bfea3444.tar.gz libmicrohttpd-bf5c5c10f480a01da85ac47ef288f2c2bfea3444.zip |
fixing misc build issues, mostly in the new src/lib/
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/include/microhttpd2.h | 669 | ||||
-rw-r--r-- | src/include/microhttpd_tls.h | 2 | ||||
-rw-r--r-- | src/lib/action_continue.c | 6 | ||||
-rw-r--r-- | src/lib/action_from_response.c | 35 | ||||
-rw-r--r-- | src/lib/action_process_upload.c | 10 | ||||
-rw-r--r-- | src/lib/action_suspend.c | 7 | ||||
-rw-r--r-- | src/lib/connection_options.c | 1 | ||||
-rw-r--r-- | src/lib/daemon_options.c | 63 | ||||
-rw-r--r-- | src/lib/daemon_start.c | 8 | ||||
-rw-r--r-- | src/lib/init.c | 2 | ||||
-rw-r--r-- | src/lib/internal.c | 51 | ||||
-rw-r--r-- | src/lib/internal.h | 160 | ||||
-rw-r--r-- | src/lib/request.c | 1 | ||||
-rw-r--r-- | src/lib/response.c | 4 | ||||
-rw-r--r-- | src/lib/response_from_buffer.c | 10 | ||||
-rw-r--r-- | src/lib/response_from_fd.c | 4 | ||||
-rw-r--r-- | src/lib/version.c | 4 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 4 |
19 files changed, 923 insertions, 119 deletions
@@ -43,3 +43,4 @@ po/configure.acT | |||
43 | po/Makevars.template | 43 | po/Makevars.template |
44 | po/POTFILES | 44 | po/POTFILES |
45 | po/configargs.stamp | 45 | po/configargs.stamp |
46 | **~ | ||
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index c69d8731..4302d8ae 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -74,6 +74,57 @@ | |||
74 | #define MICROHTTPD2_H | 74 | #define MICROHTTPD2_H |
75 | 75 | ||
76 | 76 | ||
77 | #ifdef __cplusplus | ||
78 | extern "C" | ||
79 | { | ||
80 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
81 | } | ||
82 | #endif | ||
83 | #endif | ||
84 | |||
85 | /* While we generally would like users to use a configure-driven | ||
86 | build process which detects which headers are present and | ||
87 | hence works on any platform, we use "standard" includes here | ||
88 | to build out-of-the-box for beginning users on common systems. | ||
89 | |||
90 | If generic headers don't work on your platform, include headers | ||
91 | which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', | ||
92 | 'uint16_t', 'uint32_t', 'uint64_t', 'off_t', 'struct sockaddr', | ||
93 | 'socklen_t', 'fd_set' and "#define MHD_PLATFORM_H" before | ||
94 | including "microhttpd.h". Then the following "standard" | ||
95 | includes won't be used (which might be a good idea, especially | ||
96 | on platforms where they do not exist). | ||
97 | */ | ||
98 | #ifndef MHD_PLATFORM_H | ||
99 | #include <stdarg.h> | ||
100 | #include <stdint.h> | ||
101 | #include <sys/types.h> | ||
102 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
103 | #include <ws2tcpip.h> | ||
104 | #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED) | ||
105 | #define _SSIZE_T_DEFINED | ||
106 | typedef intptr_t ssize_t; | ||
107 | #endif /* !_SSIZE_T_DEFINED */ | ||
108 | #else | ||
109 | #include <unistd.h> | ||
110 | #include <sys/time.h> | ||
111 | #include <sys/socket.h> | ||
112 | #endif | ||
113 | #endif | ||
114 | |||
115 | #if defined(__CYGWIN__) && !defined(_SYS_TYPES_FD_SET) | ||
116 | /* Do not define __USE_W32_SOCKETS under Cygwin! */ | ||
117 | #error Cygwin with winsock fd_set is not supported | ||
118 | #endif | ||
119 | |||
120 | /** | ||
121 | * Current version of the library. | ||
122 | * 0x01093001 = 1.9.30-1. | ||
123 | */ | ||
124 | #define MHD_VERSION 0x01000000 | ||
125 | |||
126 | |||
127 | |||
77 | /** | 128 | /** |
78 | * Representation of 'bool' in the public API as stdbool.h may not | 129 | * Representation of 'bool' in the public API as stdbool.h may not |
79 | * always be available. | 130 | * always be available. |
@@ -96,6 +147,144 @@ enum MHD_Bool | |||
96 | 147 | ||
97 | 148 | ||
98 | /** | 149 | /** |
150 | * Constant used to indicate unknown size (use when | ||
151 | * creating a response). | ||
152 | */ | ||
153 | #ifdef UINT64_MAX | ||
154 | #define MHD_SIZE_UNKNOWN UINT64_MAX | ||
155 | #else | ||
156 | #define MHD_SIZE_UNKNOWN ((uint64_t) -1LL) | ||
157 | #endif | ||
158 | |||
159 | #ifdef SIZE_MAX | ||
160 | #define MHD_CONTENT_READER_END_OF_STREAM SIZE_MAX | ||
161 | #define MHD_CONTENT_READER_END_WITH_ERROR (SIZE_MAX - 1) | ||
162 | #else | ||
163 | #define MHD_CONTENT_READER_END_OF_STREAM ((size_t) -1LL) | ||
164 | #define MHD_CONTENT_READER_END_WITH_ERROR (((size_t) -1LL) - 1) | ||
165 | #endif | ||
166 | |||
167 | #ifndef _MHD_EXTERN | ||
168 | #if defined(_WIN32) && defined(MHD_W32LIB) | ||
169 | #define _MHD_EXTERN extern | ||
170 | #elif defined (_WIN32) && defined(MHD_W32DLL) | ||
171 | /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */ | ||
172 | #define _MHD_EXTERN __declspec(dllimport) | ||
173 | #else | ||
174 | #define _MHD_EXTERN extern | ||
175 | #endif | ||
176 | #endif | ||
177 | |||
178 | #ifndef MHD_SOCKET_DEFINED | ||
179 | /** | ||
180 | * MHD_socket is type for socket FDs | ||
181 | */ | ||
182 | #if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) | ||
183 | #define MHD_POSIX_SOCKETS 1 | ||
184 | typedef int MHD_socket; | ||
185 | #define MHD_INVALID_SOCKET (-1) | ||
186 | #else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */ | ||
187 | #define MHD_WINSOCK_SOCKETS 1 | ||
188 | #include <winsock2.h> | ||
189 | typedef SOCKET MHD_socket; | ||
190 | #define MHD_INVALID_SOCKET (INVALID_SOCKET) | ||
191 | #endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */ | ||
192 | #define MHD_SOCKET_DEFINED 1 | ||
193 | #endif /* MHD_SOCKET_DEFINED */ | ||
194 | |||
195 | /** | ||
196 | * Define MHD_NO_DEPRECATION before including "microhttpd.h" to disable deprecation messages | ||
197 | */ | ||
198 | #ifdef MHD_NO_DEPRECATION | ||
199 | #define _MHD_DEPR_MACRO(msg) | ||
200 | #define _MHD_NO_DEPR_IN_MACRO 1 | ||
201 | #define _MHD_DEPR_IN_MACRO(msg) | ||
202 | #define _MHD_NO_DEPR_FUNC 1 | ||
203 | #define _MHD_DEPR_FUNC(msg) | ||
204 | #endif /* MHD_NO_DEPRECATION */ | ||
205 | |||
206 | #ifndef _MHD_DEPR_MACRO | ||
207 | #if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1500 | ||
208 | /* VS 2008 or later */ | ||
209 | /* Stringify macros */ | ||
210 | #define _MHD_INSTRMACRO(a) #a | ||
211 | #define _MHD_STRMACRO(a) _MHD_INSTRMACRO(a) | ||
212 | /* deprecation message */ | ||
213 | #define _MHD_DEPR_MACRO(msg) __pragma(message(__FILE__ "(" _MHD_STRMACRO(__LINE__)"): warning: " msg)) | ||
214 | #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) | ||
215 | #elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__) | ||
216 | /* clang or GCC since 3.0 */ | ||
217 | #define _MHD_GCC_PRAG(x) _Pragma (#x) | ||
218 | #if (defined(__clang__) && (__clang_major__+0 >= 5 || \ | ||
219 | (!defined(__apple_build_version__) && (__clang_major__+0 > 3 || (__clang_major__+0 == 3 && __clang_minor__ >= 3))))) || \ | ||
220 | __GNUC__+0 > 4 || (__GNUC__+0 == 4 && __GNUC_MINOR__+0 >= 8) | ||
221 | /* clang >= 3.3 (or XCode's clang >= 5.0) or | ||
222 | GCC >= 4.8 */ | ||
223 | #define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(GCC warning msg) | ||
224 | #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) | ||
225 | #else /* older clang or GCC */ | ||
226 | /* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */ | ||
227 | #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 */ | ||
229 | /* clang handles inline pragmas better than GCC */ | ||
230 | #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO(msg) | ||
231 | #endif /* clang >= 2.9 */ | ||
232 | #endif /* older clang or GCC */ | ||
233 | /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */ | ||
234 | #endif /* clang || GCC >= 3.0 */ | ||
235 | #endif /* !_MHD_DEPR_MACRO */ | ||
236 | |||
237 | #ifndef _MHD_DEPR_MACRO | ||
238 | #define _MHD_DEPR_MACRO(msg) | ||
239 | #endif /* !_MHD_DEPR_MACRO */ | ||
240 | |||
241 | #ifndef _MHD_DEPR_IN_MACRO | ||
242 | #define _MHD_NO_DEPR_IN_MACRO 1 | ||
243 | #define _MHD_DEPR_IN_MACRO(msg) | ||
244 | #endif /* !_MHD_DEPR_IN_MACRO */ | ||
245 | |||
246 | #ifndef _MHD_DEPR_FUNC | ||
247 | #if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1400 | ||
248 | /* VS 2005 or later */ | ||
249 | #define _MHD_DEPR_FUNC(msg) __declspec(deprecated(msg)) | ||
250 | #elif defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1310 | ||
251 | /* VS .NET 2003 deprecation do not support custom messages */ | ||
252 | #define _MHD_DEPR_FUNC(msg) __declspec(deprecated) | ||
253 | #elif (__GNUC__+0 >= 5) || (defined (__clang__) && \ | ||
254 | (__clang_major__+0 > 2 || (__clang_major__+0 == 2 && __clang_minor__ >= 9))) /* FIXME: earlier versions not tested */ | ||
255 | /* GCC >= 5.0 or clang >= 2.9 */ | ||
256 | #define _MHD_DEPR_FUNC(msg) __attribute__((deprecated(msg))) | ||
257 | #elif defined (__clang__) || __GNUC__+0 > 3 || (__GNUC__+0 == 3 && __GNUC_MINOR__+0 >= 1) | ||
258 | /* 3.1 <= GCC < 5.0 or clang < 2.9 */ | ||
259 | /* old GCC-style deprecation do not support custom messages */ | ||
260 | #define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__)) | ||
261 | /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */ | ||
262 | #endif /* clang < 2.9 || GCC >= 3.1 */ | ||
263 | #endif /* !_MHD_DEPR_FUNC */ | ||
264 | |||
265 | #ifndef _MHD_DEPR_FUNC | ||
266 | #define _MHD_NO_DEPR_FUNC 1 | ||
267 | #define _MHD_DEPR_FUNC(msg) | ||
268 | #endif /* !_MHD_DEPR_FUNC */ | ||
269 | |||
270 | /** | ||
271 | * Not all architectures and `printf()`'s support the `long long` type. | ||
272 | * This gives the ability to replace `long long` with just a `long`, | ||
273 | * standard `int` or a `short`. | ||
274 | */ | ||
275 | #ifndef MHD_UNSIGNED_LONG_LONG | ||
276 | #define MHD_UNSIGNED_LONG_LONG unsigned long long | ||
277 | #endif | ||
278 | /** | ||
279 | * Format string for printing a variable of type #MHD_LONG_LONG. | ||
280 | * You should only redefine this if you also define #MHD_LONG_LONG. | ||
281 | */ | ||
282 | #ifndef MHD_UNSIGNED_LONG_LONG_PRINTF | ||
283 | #define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu" | ||
284 | #endif | ||
285 | |||
286 | |||
287 | /** | ||
99 | * @brief Handle for a connection / HTTP request. | 288 | * @brief Handle for a connection / HTTP request. |
100 | * | 289 | * |
101 | * With HTTP/1.1, multiple requests can be run over the same | 290 | * With HTTP/1.1, multiple requests can be run over the same |
@@ -112,6 +301,14 @@ struct MHD_Request; | |||
112 | 301 | ||
113 | 302 | ||
114 | /** | 303 | /** |
304 | * A connection corresponds to the network/stream abstraction. | ||
305 | * A single network (i.e. TCP) stream may be used for multiple | ||
306 | * requests, which in HTTP/1.1 must be processed sequentially. | ||
307 | */ | ||
308 | struct MHD_Connection; | ||
309 | |||
310 | |||
311 | /** | ||
115 | * Return values for reporting errors, also used | 312 | * Return values for reporting errors, also used |
116 | * for logging. | 313 | * for logging. |
117 | * | 314 | * |
@@ -164,7 +361,7 @@ enum MHD_StatusCode | |||
164 | * The application requested a TLS cipher suite which is not | 361 | * The application requested a TLS cipher suite which is not |
165 | * supported by the selected backend. | 362 | * supported by the selected backend. |
166 | */ | 363 | */ |
167 | MHD_SC_TLS_CIPHERS_INVALID = 50002 | 364 | MHD_SC_TLS_CIPHERS_INVALID = 50002, |
168 | 365 | ||
169 | /** | 366 | /** |
170 | * The application attempted to setup TLS paramters before | 367 | * The application attempted to setup TLS paramters before |
@@ -301,6 +498,19 @@ enum MHD_StatusCode | |||
301 | MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE = 50027, | 498 | MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE = 50027, |
302 | 499 | ||
303 | /** | 500 | /** |
501 | * There was an attempt to upgrade a connection on | ||
502 | * a daemon where upgrades are disallowed. | ||
503 | */ | ||
504 | MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED = 50028, | ||
505 | |||
506 | /** | ||
507 | * Queueing a response failed because the respective | ||
508 | * daemon is already too deep inside of the shutdown | ||
509 | * activity and the reponse cannot be sent any longer. | ||
510 | */ | ||
511 | MHD_SC_DAEMON_ALREADY_SHUTDOWN = 50029, | ||
512 | |||
513 | /** | ||
304 | * We failed to initialize the main thread for listening. | 514 | * We failed to initialize the main thread for listening. |
305 | */ | 515 | */ |
306 | MHD_SC_THREAD_MAIN_LAUNCH_FAILURE = 50030, | 516 | MHD_SC_THREAD_MAIN_LAUNCH_FAILURE = 50030, |
@@ -1069,8 +1279,9 @@ MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, | |||
1069 | * | 1279 | * |
1070 | * @param daemon daemon to configure callback for | 1280 | * @param daemon daemon to configure callback for |
1071 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. | 1281 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. |
1282 | * @return #MHD_SC_OK on success | ||
1072 | */ | 1283 | */ |
1073 | _MHD_EXTERN void | 1284 | _MHD_EXTERN enum MHD_StatusCode |
1074 | MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, | 1285 | MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, |
1075 | void *cb); | 1286 | void *cb); |
1076 | 1287 | ||
@@ -1174,9 +1385,9 @@ MHD_daemon_accept_policy (struct MHD_Daemon *daemon, | |||
1174 | * @return value to set for the "request_context" of @a request | 1385 | * @return value to set for the "request_context" of @a request |
1175 | */ | 1386 | */ |
1176 | typedef void * | 1387 | typedef void * |
1177 | (MHD_EarlyUriLogCallback)(void *cls, | 1388 | (*MHD_EarlyUriLogCallback)(void *cls, |
1178 | const char *uri, | 1389 | const char *uri, |
1179 | struct MHD_Request *request); | 1390 | struct MHD_Request *request); |
1180 | 1391 | ||
1181 | 1392 | ||
1182 | /** | 1393 | /** |
@@ -1195,6 +1406,29 @@ MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, | |||
1195 | 1406 | ||
1196 | 1407 | ||
1197 | /** | 1408 | /** |
1409 | * The `enum MHD_ConnectionNotificationCode` specifies types | ||
1410 | * of connection notifications. | ||
1411 | * @ingroup request | ||
1412 | */ | ||
1413 | enum MHD_ConnectionNotificationCode | ||
1414 | { | ||
1415 | |||
1416 | /** | ||
1417 | * A new connection has been started. | ||
1418 | * @ingroup request | ||
1419 | */ | ||
1420 | MHD_CONNECTION_NOTIFY_STARTED = 0, | ||
1421 | |||
1422 | /** | ||
1423 | * A connection is closed. | ||
1424 | * @ingroup request | ||
1425 | */ | ||
1426 | MHD_CONNECTION_NOTIFY_CLOSED = 1 | ||
1427 | |||
1428 | }; | ||
1429 | |||
1430 | |||
1431 | /** | ||
1198 | * Signature of the callback used by MHD to notify the | 1432 | * Signature of the callback used by MHD to notify the |
1199 | * application about started/stopped connections | 1433 | * application about started/stopped connections |
1200 | * | 1434 | * |
@@ -1214,9 +1448,9 @@ MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, | |||
1214 | * @ingroup request | 1448 | * @ingroup request |
1215 | */ | 1449 | */ |
1216 | typedef void | 1450 | typedef void |
1217 | (*MHD_ConnectionCompletedCallback) (void *cls, | 1451 | (*MHD_NotifyConnectionCallback) (void *cls, |
1218 | struct MHD_Connection *connection, | 1452 | struct MHD_Connection *connection, |
1219 | enum MHD_ConnectionNotificationCode toe); | 1453 | enum MHD_ConnectionNotificationCode toe); |
1220 | 1454 | ||
1221 | 1455 | ||
1222 | /** | 1456 | /** |
@@ -1310,9 +1544,9 @@ MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, | |||
1310 | * @return number of characters in @a s (excluding 0-terminator) | 1544 | * @return number of characters in @a s (excluding 0-terminator) |
1311 | */ | 1545 | */ |
1312 | typedef size_t | 1546 | typedef size_t |
1313 | MHD_UnescapeCallback (void *cls, | 1547 | (*MHD_UnescapeCallback) (void *cls, |
1314 | struct MHD_Request *req, | 1548 | struct MHD_Request *req, |
1315 | char *s); | 1549 | char *s); |
1316 | 1550 | ||
1317 | 1551 | ||
1318 | /** | 1552 | /** |
@@ -1377,6 +1611,69 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, | |||
1377 | 1611 | ||
1378 | /* **************** Request handling functions ***************** */ | 1612 | /* **************** Request handling functions ***************** */ |
1379 | 1613 | ||
1614 | |||
1615 | /** | ||
1616 | * The `enum MHD_ValueKind` specifies the source of | ||
1617 | * the key-value pairs in the HTTP protocol. | ||
1618 | */ | ||
1619 | enum MHD_ValueKind | ||
1620 | { | ||
1621 | |||
1622 | /** | ||
1623 | * HTTP header (request/response). | ||
1624 | */ | ||
1625 | MHD_HEADER_KIND = 1, | ||
1626 | |||
1627 | /** | ||
1628 | * Cookies. Note that the original HTTP header containing | ||
1629 | * the cookie(s) will still be available and intact. | ||
1630 | */ | ||
1631 | MHD_COOKIE_KIND = 2, | ||
1632 | |||
1633 | /** | ||
1634 | * POST data. This is available only if a content encoding | ||
1635 | * supported by MHD is used (currently only URL encoding), | ||
1636 | * and only if the posted content fits within the available | ||
1637 | * memory pool. Note that in that case, the upload data | ||
1638 | * given to the #MHD_AccessHandlerCallback will be | ||
1639 | * empty (since it has already been processed). | ||
1640 | */ | ||
1641 | MHD_POSTDATA_KIND = 4, | ||
1642 | |||
1643 | /** | ||
1644 | * GET (URI) arguments. | ||
1645 | */ | ||
1646 | MHD_GET_ARGUMENT_KIND = 8, | ||
1647 | |||
1648 | /** | ||
1649 | * HTTP footer (only for HTTP 1.1 chunked encodings). | ||
1650 | */ | ||
1651 | MHD_FOOTER_KIND = 16 | ||
1652 | }; | ||
1653 | |||
1654 | |||
1655 | |||
1656 | /** | ||
1657 | * Iterator over key-value pairs. This iterator can be used to | ||
1658 | * iterate over all of the cookies, headers, or POST-data fields of a | ||
1659 | * request, and also to iterate over the headers that have been added | ||
1660 | * to a response. | ||
1661 | * | ||
1662 | * @param cls closure | ||
1663 | * @param kind kind of the header we are looking at | ||
1664 | * @param key key for the value, can be an empty string | ||
1665 | * @param value corresponding value, can be NULL | ||
1666 | * @return #MHD_YES to continue iterating, | ||
1667 | * #MHD_NO to abort the iteration | ||
1668 | * @ingroup request | ||
1669 | */ | ||
1670 | typedef int | ||
1671 | (*MHD_KeyValueIterator) (void *cls, | ||
1672 | enum MHD_ValueKind kind, | ||
1673 | const char *key, | ||
1674 | const char *value); | ||
1675 | |||
1676 | |||
1380 | /** | 1677 | /** |
1381 | * Get all of the headers from the request. | 1678 | * Get all of the headers from the request. |
1382 | * | 1679 | * |
@@ -1596,6 +1893,14 @@ MHD_request_resume (struct MHD_Request *request); | |||
1596 | 1893 | ||
1597 | 1894 | ||
1598 | /** | 1895 | /** |
1896 | * Data transmitted in response to an HTTP request. | ||
1897 | * Usually the final action taken in response to | ||
1898 | * receiving a request. | ||
1899 | */ | ||
1900 | struct MHD_Response; | ||
1901 | |||
1902 | |||
1903 | /** | ||
1599 | * Converts a @a response to an action. If @a consume | 1904 | * Converts a @a response to an action. If @a consume |
1600 | * is set, the reference to the @a response is consumed | 1905 | * is set, the reference to the @a response is consumed |
1601 | * by the conversion. If @a consume is #MHD_NO, then | 1906 | * by the conversion. If @a consume is #MHD_NO, then |
@@ -1614,7 +1919,7 @@ MHD_request_resume (struct MHD_Request *request); | |||
1614 | */ | 1919 | */ |
1615 | _MHD_EXTERN struct MHD_Action * | 1920 | _MHD_EXTERN struct MHD_Action * |
1616 | MHD_action_from_response (struct MHD_Response *response, | 1921 | MHD_action_from_response (struct MHD_Response *response, |
1617 | enum MHD_bool destroy_after_use); | 1922 | enum MHD_Bool destroy_after_use); |
1618 | 1923 | ||
1619 | 1924 | ||
1620 | /** | 1925 | /** |
@@ -1628,9 +1933,67 @@ _MHD_EXTERN void | |||
1628 | MHD_response_option_v10_only (struct MHD_Response *response); | 1933 | MHD_response_option_v10_only (struct MHD_Response *response); |
1629 | 1934 | ||
1630 | 1935 | ||
1936 | /** | ||
1937 | * The `enum MHD_RequestTerminationCode` specifies reasons | ||
1938 | * why a request has been terminated (or completed). | ||
1939 | * @ingroup request | ||
1940 | */ | ||
1941 | enum MHD_RequestTerminationCode | ||
1942 | { | ||
1943 | |||
1944 | /** | ||
1945 | * We finished sending the response. | ||
1946 | * @ingroup request | ||
1947 | */ | ||
1948 | MHD_REQUEST_TERMINATED_COMPLETED_OK = 0, | ||
1949 | |||
1950 | /** | ||
1951 | * Error handling the connection (resources | ||
1952 | * exhausted, other side closed connection, | ||
1953 | * application error accepting request, etc.) | ||
1954 | * @ingroup request | ||
1955 | */ | ||
1956 | MHD_REQUEST_TERMINATED_WITH_ERROR = 1, | ||
1957 | |||
1958 | /** | ||
1959 | * No activity on the connection for the number | ||
1960 | * of seconds specified using | ||
1961 | * #MHD_OPTION_CONNECTION_TIMEOUT. | ||
1962 | * @ingroup request | ||
1963 | */ | ||
1964 | MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2, | ||
1965 | |||
1966 | /** | ||
1967 | * We had to close the session since MHD was being | ||
1968 | * shut down. | ||
1969 | * @ingroup request | ||
1970 | */ | ||
1971 | MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3, | ||
1972 | |||
1973 | /** | ||
1974 | * We tried to read additional data, but the other side closed the | ||
1975 | * connection. This error is similar to | ||
1976 | * #MHD_REQUEST_TERMINATED_WITH_ERROR, but specific to the case where | ||
1977 | * the connection died because the other side did not send expected | ||
1978 | * data. | ||
1979 | * @ingroup request | ||
1980 | */ | ||
1981 | MHD_REQUEST_TERMINATED_READ_ERROR = 4, | ||
1982 | |||
1983 | /** | ||
1984 | * The client terminated the connection by closing the socket | ||
1985 | * for writing (TCP half-closed); MHD aborted sending the | ||
1986 | * response according to RFC 2616, section 8.1.4. | ||
1987 | * @ingroup request | ||
1988 | */ | ||
1989 | MHD_REQUEST_TERMINATED_CLIENT_ABORT = 5 | ||
1990 | |||
1991 | }; | ||
1992 | |||
1993 | |||
1631 | /** | 1994 | /** |
1632 | * Signature of the callback used by MHD to notify the | 1995 | * Signature of the callback used by MHD to notify the application |
1633 | * application about completed requests. | 1996 | * about completed requests. |
1634 | * | 1997 | * |
1635 | * @param cls client-defined closure | 1998 | * @param cls client-defined closure |
1636 | * @param toe reason for request termination | 1999 | * @param toe reason for request termination |
@@ -1660,6 +2023,69 @@ MHD_response_option_termination_callback (struct MHD_Response *response, | |||
1660 | 2023 | ||
1661 | 2024 | ||
1662 | /** | 2025 | /** |
2026 | * Callback used by libmicrohttpd in order to obtain content. The | ||
2027 | * callback is to copy at most @a max bytes of content into @a buf. The | ||
2028 | * total number of bytes that has been placed into @a buf should be | ||
2029 | * returned. | ||
2030 | * | ||
2031 | * Note that returning zero will cause libmicrohttpd to try again. | ||
2032 | * Thus, returning zero should only be used in conjunction | ||
2033 | * with MHD_suspend_connection() to avoid busy waiting. | ||
2034 | * | ||
2035 | * @param cls extra argument to the callback | ||
2036 | * @param pos position in the datastream to access; | ||
2037 | * note that if a `struct MHD_Response` object is re-used, | ||
2038 | * it is possible for the same content reader to | ||
2039 | * be queried multiple times for the same data; | ||
2040 | * however, if a `struct MHD_Response` is not re-used, | ||
2041 | * libmicrohttpd guarantees that "pos" will be | ||
2042 | * the sum of all non-negative return values | ||
2043 | * obtained from the content reader so far. | ||
2044 | * @param buf where to copy the data | ||
2045 | * @param max maximum number of bytes to copy to @a buf (size of @a buf) | ||
2046 | * @return number of bytes written to @a buf; | ||
2047 | * 0 is legal unless we are running in internal select mode (since | ||
2048 | * this would cause busy-waiting); 0 in external select mode | ||
2049 | * will cause this function to be called again once the external | ||
2050 | * select calls MHD again; | ||
2051 | * #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular | ||
2052 | * end of transmission (with chunked encoding, MHD will then | ||
2053 | * terminate the chunk and send any HTTP footers that might be | ||
2054 | * present; without chunked encoding and given an unknown | ||
2055 | * response size, MHD will simply close the connection; note | ||
2056 | * that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically | ||
2057 | * legal if a response size was specified, MHD accepts this | ||
2058 | * and treats it just as #MHD_CONTENT_READER_END_WITH_ERROR; | ||
2059 | * #MHD_CONTENT_READER_END_WITH_ERROR (-2) to indicate a server | ||
2060 | * error generating the response; this will cause MHD to simply | ||
2061 | * close the connection immediately. If a response size was | ||
2062 | * given or if chunked encoding is in use, this will indicate | ||
2063 | * an error to the client. Note, however, that if the client | ||
2064 | * does not know a response size and chunked encoding is not in | ||
2065 | * use, then clients will not be able to tell the difference between | ||
2066 | * #MHD_CONTENT_READER_END_WITH_ERROR and #MHD_CONTENT_READER_END_OF_STREAM. | ||
2067 | * This is not a limitation of MHD but rather of the HTTP protocol. | ||
2068 | */ | ||
2069 | typedef ssize_t | ||
2070 | (*MHD_ContentReaderCallback) (void *cls, | ||
2071 | uint64_t pos, | ||
2072 | char *buf, | ||
2073 | size_t max); | ||
2074 | |||
2075 | |||
2076 | /** | ||
2077 | * This method is called by libmicrohttpd if we are done with a | ||
2078 | * content reader. It should be used to free resources associated | ||
2079 | * with the content reader. | ||
2080 | * | ||
2081 | * @param cls closure | ||
2082 | * @ingroup response | ||
2083 | */ | ||
2084 | typedef void | ||
2085 | (*MHD_ContentReaderFreeCallback) (void *cls); | ||
2086 | |||
2087 | |||
2088 | /** | ||
1663 | * Create a response action. The response object can be extended with | 2089 | * Create a response action. The response object can be extended with |
1664 | * header information and then be used any number of times. | 2090 | * header information and then be used any number of times. |
1665 | * | 2091 | * |
@@ -2505,4 +2931,219 @@ MHD_daemon_get_information_sz (struct MHD_Daemon *daemon, | |||
2505 | MHD_daemon_get_information_sz((daemon), (info_type), (return_value), sizeof(union MHD_DaemonInformation)); | 2931 | MHD_daemon_get_information_sz((daemon), (info_type), (return_value), sizeof(union MHD_DaemonInformation)); |
2506 | 2932 | ||
2507 | 2933 | ||
2934 | /** | ||
2935 | * Callback for serious error condition. The default action is to print | ||
2936 | * an error message and `abort()`. | ||
2937 | * | ||
2938 | * @param cls user specified value | ||
2939 | * @param file where the error occured | ||
2940 | * @param line where the error occured | ||
2941 | * @param reason error detail, may be NULL | ||
2942 | * @ingroup logging | ||
2943 | */ | ||
2944 | typedef void | ||
2945 | (*MHD_PanicCallback) (void *cls, | ||
2946 | const char *file, | ||
2947 | unsigned int line, | ||
2948 | const char *reason); | ||
2949 | |||
2950 | |||
2951 | /** | ||
2952 | * Sets the global error handler to a different implementation. @a cb | ||
2953 | * will only be called in the case of typically fatal, serious | ||
2954 | * internal consistency issues. These issues should only arise in the | ||
2955 | * case of serious memory corruption or similar problems with the | ||
2956 | * architecture. While @a cb is allowed to return and MHD will then | ||
2957 | * try to continue, this is never safe. | ||
2958 | * | ||
2959 | * The default implementation that is used if no panic function is set | ||
2960 | * simply prints an error message and calls `abort()`. Alternative | ||
2961 | * implementations might call `exit()` or other similar functions. | ||
2962 | * | ||
2963 | * @param cb new error handler | ||
2964 | * @param cls passed to @a cb | ||
2965 | * @ingroup logging | ||
2966 | */ | ||
2967 | _MHD_EXTERN void | ||
2968 | MHD_set_panic_func (MHD_PanicCallback cb, | ||
2969 | void *cls); | ||
2970 | |||
2971 | |||
2972 | |||
2973 | /** | ||
2974 | * Types of information about MHD features, | ||
2975 | * used by #MHD_is_feature_supported(). | ||
2976 | */ | ||
2977 | enum MHD_Feature | ||
2978 | { | ||
2979 | /** | ||
2980 | * Get whether messages are supported. If supported then in debug | ||
2981 | * mode messages can be printed to stderr or to external logger. | ||
2982 | */ | ||
2983 | MHD_FEATURE_MESSAGES = 1, | ||
2984 | |||
2985 | /** | ||
2986 | * Get whether HTTPS is supported. If supported then flag | ||
2987 | * #MHD_USE_TLS and options #MHD_OPTION_HTTPS_MEM_KEY, | ||
2988 | * #MHD_OPTION_HTTPS_MEM_CERT, #MHD_OPTION_HTTPS_MEM_TRUST, | ||
2989 | * #MHD_OPTION_HTTPS_MEM_DHPARAMS, #MHD_OPTION_HTTPS_CRED_TYPE, | ||
2990 | * #MHD_OPTION_HTTPS_PRIORITIES can be used. | ||
2991 | */ | ||
2992 | MHD_FEATURE_TLS = 2, | ||
2993 | |||
2994 | /** | ||
2995 | * Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is | ||
2996 | * supported. | ||
2997 | */ | ||
2998 | MHD_FEATURE_HTTPS_CERT_CALLBACK = 3, | ||
2999 | |||
3000 | /** | ||
3001 | * Get whether IPv6 is supported. If supported then flag | ||
3002 | * #MHD_USE_IPv6 can be used. | ||
3003 | */ | ||
3004 | MHD_FEATURE_IPv6 = 4, | ||
3005 | |||
3006 | /** | ||
3007 | * Get whether IPv6 without IPv4 is supported. If not supported | ||
3008 | * then IPv4 is always enabled in IPv6 sockets and | ||
3009 | * flag #MHD_USE_DUAL_STACK if always used when #MHD_USE_IPv6 is | ||
3010 | * specified. | ||
3011 | */ | ||
3012 | MHD_FEATURE_IPv6_ONLY = 5, | ||
3013 | |||
3014 | /** | ||
3015 | * Get whether `poll()` is supported. If supported then flag | ||
3016 | * #MHD_USE_POLL can be used. | ||
3017 | */ | ||
3018 | MHD_FEATURE_POLL = 6, | ||
3019 | |||
3020 | /** | ||
3021 | * Get whether `epoll()` is supported. If supported then Flags | ||
3022 | * #MHD_USE_EPOLL and | ||
3023 | * #MHD_USE_EPOLL_INTERNAL_THREAD can be used. | ||
3024 | */ | ||
3025 | MHD_FEATURE_EPOLL = 7, | ||
3026 | |||
3027 | /** | ||
3028 | * Get whether shutdown on listen socket to signal other | ||
3029 | * threads is supported. If not supported flag | ||
3030 | * #MHD_USE_ITC is automatically forced. | ||
3031 | */ | ||
3032 | MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET = 8, | ||
3033 | |||
3034 | /** | ||
3035 | * Get whether socketpair is used internally instead of pipe to | ||
3036 | * signal other threads. | ||
3037 | */ | ||
3038 | MHD_FEATURE_SOCKETPAIR = 9, | ||
3039 | |||
3040 | /** | ||
3041 | * Get whether TCP Fast Open is supported. If supported then | ||
3042 | * flag #MHD_USE_TCP_FASTOPEN and option | ||
3043 | * #MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used. | ||
3044 | */ | ||
3045 | MHD_FEATURE_TCP_FASTOPEN = 10, | ||
3046 | |||
3047 | /** | ||
3048 | * Get whether HTTP Basic authorization is supported. If supported | ||
3049 | * then functions #MHD_basic_auth_get_username_password and | ||
3050 | * #MHD_queue_basic_auth_fail_response can be used. | ||
3051 | */ | ||
3052 | MHD_FEATURE_BASIC_AUTH = 11, | ||
3053 | |||
3054 | /** | ||
3055 | * Get whether HTTP Digest authorization is supported. If | ||
3056 | * supported then options #MHD_OPTION_DIGEST_AUTH_RANDOM, | ||
3057 | * #MHD_OPTION_NONCE_NC_SIZE and | ||
3058 | * #MHD_digest_auth_check() can be used. | ||
3059 | */ | ||
3060 | MHD_FEATURE_DIGEST_AUTH = 12, | ||
3061 | |||
3062 | /** | ||
3063 | * Get whether postprocessor is supported. If supported then | ||
3064 | * functions #MHD_create_post_processor(), #MHD_post_process() and | ||
3065 | * #MHD_destroy_post_processor() can | ||
3066 | * be used. | ||
3067 | */ | ||
3068 | MHD_FEATURE_POSTPROCESSOR = 13, | ||
3069 | |||
3070 | /** | ||
3071 | * Get whether password encrypted private key for HTTPS daemon is | ||
3072 | * supported. If supported then option | ||
3073 | * ::MHD_OPTION_HTTPS_KEY_PASSWORD can be used. | ||
3074 | */ | ||
3075 | MHD_FEATURE_HTTPS_KEY_PASSWORD = 14, | ||
3076 | |||
3077 | /** | ||
3078 | * Get whether reading files beyond 2 GiB boundary is supported. | ||
3079 | * If supported then #MHD_create_response_from_fd(), | ||
3080 | * #MHD_create_response_from_fd64 #MHD_create_response_from_fd_at_offset() | ||
3081 | * and #MHD_create_response_from_fd_at_offset64() can be used with sizes and | ||
3082 | * offsets larger than 2 GiB. If not supported value of size+offset is | ||
3083 | * limited to 2 GiB. | ||
3084 | */ | ||
3085 | MHD_FEATURE_LARGE_FILE = 15, | ||
3086 | |||
3087 | /** | ||
3088 | * Get whether MHD set names on generated threads. | ||
3089 | */ | ||
3090 | MHD_FEATURE_THREAD_NAMES = 16, | ||
3091 | |||
3092 | /** | ||
3093 | * Get whether HTTP "Upgrade" is supported. | ||
3094 | * If supported then #MHD_ALLOW_UPGRADE, #MHD_upgrade_action() and | ||
3095 | * #MHD_create_response_for_upgrade() can be used. | ||
3096 | */ | ||
3097 | MHD_FEATURE_UPGRADE = 17, | ||
3098 | |||
3099 | /** | ||
3100 | * Get whether it's safe to use same FD for multiple calls of | ||
3101 | * #MHD_create_response_from_fd() and whether it's safe to use single | ||
3102 | * response generated by #MHD_create_response_from_fd() with multiple | ||
3103 | * connections at same time. | ||
3104 | * If #MHD_is_feature_supported() return #MHD_NO for this feature then | ||
3105 | * usage of responses with same file FD in multiple parallel threads may | ||
3106 | * results in incorrect data sent to remote client. | ||
3107 | * It's always safe to use same file FD in multiple responses if MHD | ||
3108 | * is run in any single thread mode. | ||
3109 | */ | ||
3110 | MHD_FEATURE_RESPONSES_SHARED_FD = 18, | ||
3111 | |||
3112 | /** | ||
3113 | * Get whether MHD support automatic detection of bind port number. | ||
3114 | * @sa #MHD_DAEMON_INFO_BIND_PORT | ||
3115 | */ | ||
3116 | MHD_FEATURE_AUTODETECT_BIND_PORT = 19, | ||
3117 | |||
3118 | /** | ||
3119 | * Get whether MHD support SIGPIPE suppression. | ||
3120 | * If SIGPIPE suppression is not supported, application must handle | ||
3121 | * SIGPIPE signal by itself. | ||
3122 | */ | ||
3123 | MHD_FEATURE_AUTOSUPPRESS_SIGPIPE = 20, | ||
3124 | |||
3125 | /** | ||
3126 | * Get whether MHD use system's sendfile() function to send | ||
3127 | * file-FD based responses over non-TLS connections. | ||
3128 | * @note Since v0.9.56 | ||
3129 | */ | ||
3130 | MHD_FEATURE_SENDFILE = 21 | ||
3131 | }; | ||
3132 | |||
3133 | |||
3134 | /** | ||
3135 | * Get information about supported MHD features. | ||
3136 | * Indicate that MHD was compiled with or without support for | ||
3137 | * particular feature. Some features require additional support | ||
3138 | * by kernel. Kernel support is not checked by this function. | ||
3139 | * | ||
3140 | * @param feature type of requested information | ||
3141 | * @return #MHD_YES if feature is supported by MHD, #MHD_NO if | ||
3142 | * feature is not supported or feature is unknown. | ||
3143 | * @ingroup specialized | ||
3144 | */ | ||
3145 | _MHD_EXTERN enum MHD_Bool | ||
3146 | MHD_is_feature_supported (enum MHD_Feature feature); | ||
3147 | |||
3148 | |||
2508 | #endif | 3149 | #endif |
diff --git a/src/include/microhttpd_tls.h b/src/include/microhttpd_tls.h index cbb50aa2..4f5b0e72 100644 --- a/src/include/microhttpd_tls.h +++ b/src/include/microhttpd_tls.h | |||
@@ -87,7 +87,7 @@ struct MHD_TLS_Plugin | |||
87 | * @return NULL on errors (in particular, invalid cipher suite) | 87 | * @return NULL on errors (in particular, invalid cipher suite) |
88 | */ | 88 | */ |
89 | typedef struct MHD_TLS_Plugin * | 89 | typedef struct MHD_TLS_Plugin * |
90 | MHD_TLS_PluginInit (const char *ciphers); | 90 | (*MHD_TLS_PluginInit) (const char *ciphers); |
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
diff --git a/src/lib/action_continue.c b/src/lib/action_continue.c index 0367f536..84d98d9e 100644 --- a/src/lib/action_continue.c +++ b/src/lib/action_continue.c | |||
@@ -31,13 +31,15 @@ | |||
31 | * | 31 | * |
32 | * @param cls NULL | 32 | * @param cls NULL |
33 | * @param request the request to apply the action to | 33 | * @param request the request to apply the action to |
34 | * @return #MHD_SC_OK on success | ||
34 | */ | 35 | */ |
35 | static void | 36 | static enum MHD_StatusCode |
36 | cont_action (void *cls, | 37 | cont_action (void *cls, |
37 | struct MHD_Request *request) | 38 | struct MHD_Request *request) |
38 | { | 39 | { |
39 | /* not sure yet, but this function body may | 40 | /* not sure yet, but this function body may |
40 | just legitimately stay empty... */ | 41 | just legitimately stay empty... */ |
42 | return MHD_SC_OK; | ||
41 | } | 43 | } |
42 | 44 | ||
43 | 45 | ||
@@ -49,7 +51,7 @@ cont_action (void *cls, | |||
49 | struct MHD_Action * | 51 | struct MHD_Action * |
50 | MHD_action_continue (void) | 52 | MHD_action_continue (void) |
51 | { | 53 | { |
52 | static MHD_Action acont = { | 54 | static struct MHD_Action acont = { |
53 | .action = &cont_action, | 55 | .action = &cont_action, |
54 | .action_cls = NULL | 56 | .action_cls = NULL |
55 | }; | 57 | }; |
diff --git a/src/lib/action_from_response.c b/src/lib/action_from_response.c index 3c13cf42..883fcb98 100644 --- a/src/lib/action_from_response.c +++ b/src/lib/action_from_response.c | |||
@@ -31,27 +31,30 @@ | |||
31 | * | 31 | * |
32 | * @param cls the `struct MHD_Response` | 32 | * @param cls the `struct MHD_Response` |
33 | * @param request the request we are processing | 33 | * @param request the request we are processing |
34 | * @return #MHD_SC_OK on success | ||
34 | */ | 35 | */ |
35 | static void | 36 | static enum MHD_StatusCode |
36 | response_action (void *cls, | 37 | response_action (void *cls, |
37 | struct MHD_Request *request) | 38 | struct MHD_Request *request) |
38 | { | 39 | { |
39 | struct MHD_Response *response = cls; | 40 | struct MHD_Response *response = cls; |
40 | struct MHD_Daemon *daemon = response->daemon; | 41 | struct MHD_Daemon *daemon = request->daemon; |
41 | 42 | ||
43 | /* If daemon was shut down in parallel, | ||
44 | * response will be aborted now or on later stage. */ | ||
42 | if (daemon->shutdown) | 45 | if (daemon->shutdown) |
43 | return MHD_YES; /* If daemon was shut down in parallel, | 46 | return MHD_SC_DAEMON_ALREADY_SHUTDOWN; |
44 | * response will be aborted now or on later stage. */ | ||
45 | 47 | ||
46 | #ifdef UPGRADE_SUPPORT | 48 | #ifdef UPGRADE_SUPPORT |
47 | if ( (NULL != response->upgrade_handler) && | 49 | if ( (NULL != response->upgrade_handler) && |
48 | (0 == (daemon->options & MHD_ALLOW_UPGRADE)) ) | 50 | daemon->disallow_upgrade ) |
49 | { | 51 | { |
50 | #ifdef HAVE_MESSAGES | 52 | #ifdef HAVE_MESSAGES |
51 | MHD_DLOG (daemon, | 53 | MHD_DLOG (daemon, |
54 | MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED, | ||
52 | _("Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n")); | 55 | _("Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n")); |
53 | #endif | 56 | #endif |
54 | return MHD_NO; | 57 | return MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED; |
55 | } | 58 | } |
56 | #endif /* UPGRADE_SUPPORT */ | 59 | #endif /* UPGRADE_SUPPORT */ |
57 | request->response = response; | 60 | request->response = response; |
@@ -66,9 +69,7 @@ response_action (void *cls, | |||
66 | request->resp_sender = MHD_resp_sender_sendfile; | 69 | request->resp_sender = MHD_resp_sender_sendfile; |
67 | #endif /* _MHD_HAVE_SENDFILE */ | 70 | #endif /* _MHD_HAVE_SENDFILE */ |
68 | 71 | ||
69 | if ( ( (NULL != request->method) && | 72 | if ( (MHD_METHOD_HEAD == request->method) || |
70 | (MHD_str_equal_caseless_ (request->method, | ||
71 | MHD_HTTP_METHOD_HEAD)) ) || | ||
72 | (MHD_HTTP_OK > response->status_code) || | 73 | (MHD_HTTP_OK > response->status_code) || |
73 | (MHD_HTTP_NO_CONTENT == response->status_code) || | 74 | (MHD_HTTP_NO_CONTENT == response->status_code) || |
74 | (MHD_HTTP_NOT_MODIFIED == response->status_code) ) | 75 | (MHD_HTTP_NOT_MODIFIED == response->status_code) ) |
@@ -79,19 +80,17 @@ response_action (void *cls, | |||
79 | request->response_write_position = response->total_size; | 80 | request->response_write_position = response->total_size; |
80 | } | 81 | } |
81 | if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && | 82 | if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && |
82 | (NULL != connection->method) && | 83 | (MHD_METHOD_POST == request->method) || |
83 | ( (MHD_str_equal_caseless_ (request->method, | 84 | (MHD_METHOD_PUT == request->method) ) |
84 | MHD_HTTP_METHOD_POST)) || | ||
85 | (MHD_str_equal_caseless_ (request->method, | ||
86 | MHD_HTTP_METHOD_PUT))) ) | ||
87 | { | 85 | { |
88 | /* response was queued "early", refuse to read body / footers or | 86 | /* response was queued "early", refuse to read body / footers or |
89 | further requests! */ | 87 | further requests! */ |
90 | connection->read_closed = true; | 88 | request->connection->read_closed = true; |
91 | request->state = MHD_CONNECTION_FOOTERS_RECEIVED; | 89 | request->state = MHD_REQUEST_FOOTERS_RECEIVED; |
92 | } | 90 | } |
93 | if (! request->in_idle) | 91 | if (! request->in_idle) |
94 | (void) MHD_connection_handle_idle (connection); | 92 | (void) MHD_connection_handle_idle (request->connection); |
93 | return MHD_SC_OK; | ||
95 | } | 94 | } |
96 | 95 | ||
97 | 96 | ||
@@ -114,7 +113,7 @@ response_action (void *cls, | |||
114 | */ | 113 | */ |
115 | _MHD_EXTERN struct MHD_Action * | 114 | _MHD_EXTERN struct MHD_Action * |
116 | MHD_action_from_response (struct MHD_Response *response, | 115 | MHD_action_from_response (struct MHD_Response *response, |
117 | enum MHD_bool destroy_after_use) | 116 | enum MHD_Bool destroy_after_use) |
118 | { | 117 | { |
119 | response->action.action = &response_action; | 118 | response->action.action = &response_action; |
120 | response->action.action_cls = response; | 119 | response->action.action_cls = response; |
diff --git a/src/lib/action_process_upload.c b/src/lib/action_process_upload.c index d67b60a1..33221486 100644 --- a/src/lib/action_process_upload.c +++ b/src/lib/action_process_upload.c | |||
@@ -51,8 +51,9 @@ struct UploadAction | |||
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 | */ | 55 | */ |
55 | static void | 56 | static enum MHD_StatusCode |
56 | upload_action (void *cls, | 57 | upload_action (void *cls, |
57 | struct MHD_Request *request) | 58 | struct MHD_Request *request) |
58 | { | 59 | { |
@@ -60,6 +61,7 @@ upload_action (void *cls, | |||
60 | 61 | ||
61 | (void) ua; | 62 | (void) ua; |
62 | // FIXME: implement! | 63 | // FIXME: implement! |
64 | return -1; | ||
63 | } | 65 | } |
64 | 66 | ||
65 | 67 | ||
@@ -79,11 +81,11 @@ MHD_action_process_upload (MHD_UploadCallback uc, | |||
79 | 81 | ||
80 | if (NULL == (ua = malloc (sizeof (struct UploadAction)))) | 82 | if (NULL == (ua = malloc (sizeof (struct UploadAction)))) |
81 | return NULL; | 83 | return NULL; |
82 | ua->action = &upload_action; | 84 | ua->action.action = &upload_action; |
83 | ua->action_cls = ua; | 85 | ua->action.action_cls = ua; |
84 | ua->uc = uc; | 86 | ua->uc = uc; |
85 | ua->uc_cls = uc_cls; | 87 | ua->uc_cls = uc_cls; |
86 | return ua; | 88 | return &ua->action; |
87 | } | 89 | } |
88 | 90 | ||
89 | 91 | ||
diff --git a/src/lib/action_suspend.c b/src/lib/action_suspend.c index 8327992d..b54fe419 100644 --- a/src/lib/action_suspend.c +++ b/src/lib/action_suspend.c | |||
@@ -31,11 +31,13 @@ | |||
31 | * | 31 | * |
32 | * @param cls NULL | 32 | * @param cls NULL |
33 | * @param request the request to apply the action to | 33 | * @param request the request to apply the action to |
34 | * @return #MHD_SC_OK on success | ||
34 | */ | 35 | */ |
35 | static void | 36 | static enum MHD_StatusCode |
36 | suspend_action (void *cls, | 37 | suspend_action (void *cls, |
37 | struct MHD_Request *request) | 38 | struct MHD_Request *request) |
38 | { | 39 | { |
40 | struct MHD_Connection *connection = request->connection; | ||
39 | struct MHD_Daemon *daemon = connection->daemon; | 41 | struct MHD_Daemon *daemon = connection->daemon; |
40 | 42 | ||
41 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 43 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
@@ -44,7 +46,7 @@ suspend_action (void *cls, | |||
44 | /* suspending again while we didn't even complete resuming yet */ | 46 | /* suspending again while we didn't even complete resuming yet */ |
45 | connection->resuming = false; | 47 | connection->resuming = false; |
46 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 48 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
47 | return; | 49 | return MHD_SC_OK; |
48 | } | 50 | } |
49 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 51 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
50 | { | 52 | { |
@@ -88,6 +90,7 @@ suspend_action (void *cls, | |||
88 | } | 90 | } |
89 | #endif | 91 | #endif |
90 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 92 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
93 | return MHD_SC_OK; | ||
91 | } | 94 | } |
92 | 95 | ||
93 | 96 | ||
diff --git a/src/lib/connection_options.c b/src/lib/connection_options.c index 24301ddf..118da122 100644 --- a/src/lib/connection_options.c +++ b/src/lib/connection_options.c | |||
@@ -46,6 +46,7 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, | |||
46 | connection->connection_timeout = (time_t) timeout_s; | 46 | connection->connection_timeout = (time_t) timeout_s; |
47 | return; | 47 | return; |
48 | } | 48 | } |
49 | |||
49 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 50 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
50 | if (! connection->suspended) | 51 | if (! connection->suspended) |
51 | { | 52 | { |
diff --git a/src/lib/daemon_options.c b/src/lib/daemon_options.c index 3adee960..db0be522 100644 --- a/src/lib/daemon_options.c +++ b/src/lib/daemon_options.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | #include "internal.h" | 25 | #include "internal.h" |
26 | #include <dlfcn.h> | ||
26 | 27 | ||
27 | 28 | ||
28 | /** | 29 | /** |
@@ -150,7 +151,7 @@ MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon, | |||
150 | unsigned int queue_length) | 151 | unsigned int queue_length) |
151 | { | 152 | { |
152 | daemon->fast_open_method = fom; | 153 | daemon->fast_open_method = fom; |
153 | daemon->fast_open_queue_length = queue_length; | 154 | daemon->fo_queue_length = queue_length; |
154 | switch (fom) | 155 | switch (fom) |
155 | { | 156 | { |
156 | case MHD_FOM_DISABLE: | 157 | case MHD_FOM_DISABLE: |
@@ -204,7 +205,6 @@ MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon, | |||
204 | const struct sockaddr *sa, | 205 | const struct sockaddr *sa, |
205 | size_t sa_len) | 206 | size_t sa_len) |
206 | { | 207 | { |
207 | daemon->sa_given = true; | ||
208 | memcpy (&daemon->listen_sa, | 208 | memcpy (&daemon->listen_sa, |
209 | sa, | 209 | sa, |
210 | sa_len); | 210 | sa_len); |
@@ -338,37 +338,37 @@ MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon, | |||
338 | const char *ciphers) | 338 | const char *ciphers) |
339 | { | 339 | { |
340 | #ifndef HTTPS_SUPPORT | 340 | #ifndef HTTPS_SUPPORT |
341 | return MHD_TLS_DISABLED; | 341 | return MHD_SC_TLS_DISABLED; |
342 | #else | 342 | #else |
343 | char filename[1024]; | 343 | char filename[1024]; |
344 | int res; | 344 | int res; |
345 | MHD_TLS_PluginInit init; | 345 | MHD_TLS_PluginInit init; |
346 | 346 | ||
347 | /* todo: .dll on W32? */ | 347 | /* todo: .dll on W32? */ |
348 | res = MHD_snprintf (filename, | 348 | res = MHD_snprintf_ (filename, |
349 | sizeof (filename), | 349 | sizeof (filename), |
350 | "%s/libmicrohttpd_tls_%s.so", | 350 | "%s/libmicrohttpd_tls_%s.so", |
351 | MHD_PLUGIN_INSTALL_PREFIX, | 351 | MHD_PLUGIN_INSTALL_PREFIX, |
352 | tls_backend); | 352 | tls_backend); |
353 | if (0 >= res) | 353 | if (0 >= res) |
354 | return MHD_BACKEND_UNSUPPORTED; /* string too long? */ | 354 | return MHD_SC_TLS_BACKEND_UNSUPPORTED; /* string too long? */ |
355 | if (NULL == | 355 | if (NULL == |
356 | (daemon->tls_backend_lib = dlopen (filename, | 356 | (daemon->tls_backend_lib = dlopen (filename, |
357 | RTLD_NOW | RTLD_LOCAL))) | 357 | RTLD_NOW | RTLD_LOCAL))) |
358 | return MHD_BACKEND_UNSUPPORTED; /* plugin not found */ | 358 | return MHD_SC_BACKEND_UNSUPPORTED; /* plugin not found */ |
359 | if (NULL == (init = dlsym (daemon->tls_backend_lib, | 359 | if (NULL == (init = dlsym (daemon->tls_backend_lib, |
360 | "MHD_TLS_init_" MHD_TLS_ABI_VERSION_STR))) | 360 | "MHD_TLS_init_" MHD_TLS_ABI_VERSION_STR))) |
361 | 361 | ||
362 | { | 362 | { |
363 | dlclose (daemon->tls_backend_lib); | 363 | dlclose (daemon->tls_backend_lib); |
364 | daemon->tls_backend_lib = NULL; | 364 | daemon->tls_backend_lib = NULL; |
365 | return MHD_BACKEND_UNSUPPORTED; /* possibly wrong version installed */ | 365 | return MHD_SC_BACKEND_UNSUPPORTED; /* possibly wrong version installed */ |
366 | } | 366 | } |
367 | if (NULL == (daemon->tls_backend = init (ciphers))) | 367 | if (NULL == (daemon->tls_api = init (ciphers))) |
368 | { | 368 | { |
369 | dlclose (daemon->tls_backend_lib); | 369 | dlclose (daemon->tls_backend_lib); |
370 | daemon->tls_backend_lib = NULL; | 370 | daemon->tls_backend_lib = NULL; |
371 | return MHD_CIPHERS_INVALID; /* possibly wrong version installed */ | 371 | return MHD_SC_CIPHERS_INVALID; /* possibly wrong version installed */ |
372 | } | 372 | } |
373 | return MHD_SC_OK; | 373 | return MHD_SC_OK; |
374 | #endif | 374 | #endif |
@@ -396,8 +396,8 @@ MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, | |||
396 | { | 396 | { |
397 | struct MHD_TLS_Plugin *plugin; | 397 | struct MHD_TLS_Plugin *plugin; |
398 | 398 | ||
399 | if (NULL == (plugin = daemon->tls_backend)) | 399 | if (NULL == (plugin = daemon->tls_api)) |
400 | return MHD_TLS_BACKEND_UNINITIALIZED; | 400 | return MHD_SC_TLS_BACKEND_UNINITIALIZED; |
401 | return plugin->init_kcp (plugin->cls, | 401 | return plugin->init_kcp (plugin->cls, |
402 | mem_key, | 402 | mem_key, |
403 | mem_cert, | 403 | mem_cert, |
@@ -420,8 +420,8 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon, | |||
420 | { | 420 | { |
421 | struct MHD_TLS_Plugin *plugin; | 421 | struct MHD_TLS_Plugin *plugin; |
422 | 422 | ||
423 | if (NULL == (plugin = daemon->tls_backend)) | 423 | if (NULL == (plugin = daemon->tls_api)) |
424 | return MHD_TLS_BACKEND_UNINITIALIZED; | 424 | return MHD_SC_TLS_BACKEND_UNINITIALIZED; |
425 | return plugin->init_dhparams (plugin->cls, | 425 | return plugin->init_dhparams (plugin->cls, |
426 | dh); | 426 | dh); |
427 | } | 427 | } |
@@ -442,8 +442,8 @@ MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon, | |||
442 | { | 442 | { |
443 | struct MHD_TLS_Plugin *plugin; | 443 | struct MHD_TLS_Plugin *plugin; |
444 | 444 | ||
445 | if (NULL == (plugin = daemon->tls_backend)) | 445 | if (NULL == (plugin = daemon->tls_api)) |
446 | return MHD_TLS_BACKEND_UNINITIALIZED; | 446 | return MHD_SC_TLS_BACKEND_UNINITIALIZED; |
447 | return plugin->init_mem_trust (plugin->cls, | 447 | return plugin->init_mem_trust (plugin->cls, |
448 | mem_trust); | 448 | mem_trust); |
449 | } | 449 | } |
@@ -462,9 +462,9 @@ MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, | |||
462 | { | 462 | { |
463 | struct MHD_TLS_Plugin *plugin; | 463 | struct MHD_TLS_Plugin *plugin; |
464 | 464 | ||
465 | if (NULL == (plugin = daemon->tls_backend)) | 465 | if (NULL == (plugin = daemon->tls_api)) |
466 | return MHD_TLS_BACKEND_UNINITIALIZED; | 466 | return MHD_SC_TLS_BACKEND_UNINITIALIZED; |
467 | return MHD_TLS_BACKEND_OPERATION_UNSUPPORTED; | 467 | return MHD_SC_TLS_BACKEND_OPERATION_UNSUPPORTED; |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
@@ -483,16 +483,17 @@ MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, | |||
483 | * | 483 | * |
484 | * @param daemon daemon to configure callback for | 484 | * @param daemon daemon to configure callback for |
485 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. | 485 | * @param cb must be of type `gnutls_certificate_retrieve_function2 *`. |
486 | * @return #MHD_SC_OK on success | ||
486 | */ | 487 | */ |
487 | void | 488 | enum MHD_StatusCode |
488 | MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, | 489 | MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, |
489 | void *cb) | 490 | void *cb) |
490 | { | 491 | { |
491 | struct MHD_TLS_Plugin *plugin; | 492 | struct MHD_TLS_Plugin *plugin; |
492 | 493 | ||
493 | if (NULL == (plugin = daemon->tls_backend)) | 494 | if (NULL == (plugin = daemon->tls_api)) |
494 | return MHD_TLS_BACKEND_UNINITIALIZED; | 495 | return MHD_SC_TLS_BACKEND_UNINITIALIZED; |
495 | return MHD_TLS_BACKEND_OPERATION_UNSUPPORTED; | 496 | return MHD_SC_TLS_BACKEND_OPERATION_UNSUPPORTED; |
496 | } | 497 | } |
497 | 498 | ||
498 | 499 | ||
@@ -544,8 +545,8 @@ MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, | |||
544 | MHD_EarlyUriLogCallback cb, | 545 | MHD_EarlyUriLogCallback cb, |
545 | void *cb_cls) | 546 | void *cb_cls) |
546 | { | 547 | { |
547 | daemon->early_uri_logger_cb = cb; | 548 | daemon->early_uri_logger = cb; |
548 | daemon->early_uri_logger_cb_cls = cb_cls; | 549 | daemon->early_uri_logger_cls = cb_cls; |
549 | } | 550 | } |
550 | 551 | ||
551 | 552 | ||
@@ -710,7 +711,7 @@ MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon, | |||
710 | MHD_DLOG (daemon, | 711 | MHD_DLOG (daemon, |
711 | _("Specified value for NC_SIZE too large\n")); | 712 | _("Specified value for NC_SIZE too large\n")); |
712 | #endif | 713 | #endif |
713 | return MHD_DIGEST_AUTH_NC_LENGTH_TOO_BIG; | 714 | return MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG; |
714 | } | 715 | } |
715 | if (0 < nc_length) | 716 | if (0 < nc_length) |
716 | { | 717 | { |
@@ -725,13 +726,13 @@ MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon, | |||
725 | _("Failed to allocate memory for nonce-nc map: %s\n"), | 726 | _("Failed to allocate memory for nonce-nc map: %s\n"), |
726 | MHD_strerror_ (errno)); | 727 | MHD_strerror_ (errno)); |
727 | #endif | 728 | #endif |
728 | return MHD_DIGEST_AUTH_NC_ALLOCATION_FAILURE; | 729 | return MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE; |
729 | } | 730 | } |
730 | } | 731 | } |
731 | daemon->digest_nc_length = nc_length; | 732 | daemon->digest_nc_length = nc_length; |
732 | return MHD_SC_OK; | 733 | return MHD_SC_OK; |
733 | #else | 734 | #else |
734 | return MHD_DIGEST_AUTH_NOT_SUPPORTED_BY_BUILD; | 735 | return MHD_SC_DIGEST_AUTH_NOT_SUPPORTED_BY_BUILD; |
735 | #endif | 736 | #endif |
736 | } | 737 | } |
737 | 738 | ||
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c index 5ed6d29d..98126c68 100644 --- a/src/lib/daemon_start.c +++ b/src/lib/daemon_start.c | |||
@@ -643,9 +643,9 @@ setup_thread_pool (struct MHD_Daemon *daemon) | |||
643 | /* Coarse-grained count of connections per thread (note error | 643 | /* Coarse-grained count of connections per thread (note error |
644 | * due to integer division). Also keep track of how many | 644 | * due to integer division). Also keep track of how many |
645 | * connections are leftover after an equal split. */ | 645 | * connections are leftover after an equal split. */ |
646 | unsigned int conns_per_thread = daemon->connection_limit | 646 | unsigned int conns_per_thread = daemon->global_connection_limit |
647 | / daemon->threading_model; | 647 | / daemon->threading_model; |
648 | unsigned int leftover_conns = daemon->connection_limit | 648 | unsigned int leftover_conns = daemon->global_connection_limit |
649 | % daemon->threading_model; | 649 | % daemon->threading_model; |
650 | unsigned int i; | 650 | unsigned int i; |
651 | enum MHD_StatusCode sc; | 651 | enum MHD_StatusCode sc; |
@@ -674,9 +674,9 @@ setup_thread_pool (struct MHD_Daemon *daemon) | |||
674 | /* Divide available connections evenly amongst the threads. | 674 | /* Divide available connections evenly amongst the threads. |
675 | * Thread indexes in [0, leftover_conns) each get one of the | 675 | * Thread indexes in [0, leftover_conns) each get one of the |
676 | * leftover connections. */ | 676 | * leftover connections. */ |
677 | d->connection_limit = conns_per_thread; | 677 | d->global_connection_limit = conns_per_thread; |
678 | if (i < leftover_conns) | 678 | if (i < leftover_conns) |
679 | ++d->connection_limit; | 679 | ++d->global_connection_limit; |
680 | 680 | ||
681 | if (! daemon->disable_itc) | 681 | if (! daemon->disable_itc) |
682 | { | 682 | { |
diff --git a/src/lib/init.c b/src/lib/init.c index d7ba332d..96b0cbec 100644 --- a/src/lib/init.c +++ b/src/lib/init.c | |||
@@ -97,6 +97,8 @@ volatile int global_init_count = 0; | |||
97 | MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); | 97 | MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); |
98 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ | 98 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ |
99 | 99 | ||
100 | #endif | ||
101 | |||
100 | 102 | ||
101 | /** | 103 | /** |
102 | * Check whether global initialisation was performed | 104 | * Check whether global initialisation was performed |
diff --git a/src/lib/internal.c b/src/lib/internal.c index d2532c54..7e8d2286 100644 --- a/src/lib/internal.c +++ b/src/lib/internal.c | |||
@@ -92,17 +92,20 @@ MHD_state_to_string (enum MHD_CONNECTION_STATE state) | |||
92 | */ | 92 | */ |
93 | void | 93 | void |
94 | MHD_DLOG (const struct MHD_Daemon *daemon, | 94 | MHD_DLOG (const struct MHD_Daemon *daemon, |
95 | enum MHD_StatusCode sc, | ||
95 | const char *format, | 96 | const char *format, |
96 | ...) | 97 | ...) |
97 | { | 98 | { |
98 | va_list va; | 99 | va_list va; |
99 | 100 | ||
100 | if (0 == (daemon->options & MHD_USE_ERROR_LOG)) | 101 | if (NULL == daemon->logger) |
101 | return; | 102 | return; |
102 | va_start (va, format); | 103 | va_start (va, |
103 | daemon->custom_error_log (daemon->custom_error_log_cls, | 104 | format); |
104 | format, | 105 | daemon->logger (daemon->logger_cls, |
105 | va); | 106 | sc, |
107 | format, | ||
108 | va); | ||
106 | va_end (va); | 109 | va_end (va); |
107 | } | 110 | } |
108 | #endif | 111 | #endif |
@@ -204,9 +207,9 @@ MHD_parse_arguments_ (struct MHD_Connection *connection, | |||
204 | { | 207 | { |
205 | /* last argument, without '=' */ | 208 | /* last argument, without '=' */ |
206 | MHD_unescape_plus (args); | 209 | MHD_unescape_plus (args); |
207 | daemon->unescape_callback (daemon->unescape_callback_cls, | 210 | daemon->unescape_cb (daemon->unescape_cb_cls, |
208 | connection, | 211 | connection, |
209 | args); | 212 | args); |
210 | if (MHD_YES != cb (connection, | 213 | if (MHD_YES != cb (connection, |
211 | args, | 214 | args, |
212 | NULL, | 215 | NULL, |
@@ -219,13 +222,13 @@ MHD_parse_arguments_ (struct MHD_Connection *connection, | |||
219 | equals[0] = '\0'; | 222 | equals[0] = '\0'; |
220 | equals++; | 223 | equals++; |
221 | MHD_unescape_plus (args); | 224 | MHD_unescape_plus (args); |
222 | daemon->unescape_callback (daemon->unescape_callback_cls, | 225 | daemon->unescape_cb (daemon->unescape_cb_cls, |
223 | connection, | 226 | connection, |
224 | args); | 227 | args); |
225 | MHD_unescape_plus (equals); | 228 | MHD_unescape_plus (equals); |
226 | daemon->unescape_callback (daemon->unescape_callback_cls, | 229 | daemon->unescape_cb (daemon->unescape_cb_cls, |
227 | connection, | 230 | connection, |
228 | equals); | 231 | equals); |
229 | if (MHD_YES != cb (connection, | 232 | if (MHD_YES != cb (connection, |
230 | args, | 233 | args, |
231 | equals, | 234 | equals, |
@@ -235,16 +238,16 @@ MHD_parse_arguments_ (struct MHD_Connection *connection, | |||
235 | break; | 238 | break; |
236 | } | 239 | } |
237 | /* amper is non-NULL here */ | 240 | /* amper is non-NULL here */ |
238 | amper[0] = '\0'; | 241 | amper[0] = '\0';d |
239 | amper++; | 242 | amper++; |
240 | if ( (NULL == equals) || | 243 | if ( (NULL == equals) || |
241 | (equals >= amper) ) | 244 | (equals >= amper) ) |
242 | { | 245 | { |
243 | /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */ | 246 | /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */ |
244 | MHD_unescape_plus (args); | 247 | MHD_unescape_plus (args); |
245 | daemon->unescape_callback (daemon->unescape_callback_cls, | 248 | daemon->unescape_cb (daemon->unescape_cb_cls, |
246 | connection, | 249 | connection, |
247 | args); | 250 | args); |
248 | if (MHD_YES != cb (connection, | 251 | if (MHD_YES != cb (connection, |
249 | args, | 252 | args, |
250 | NULL, | 253 | NULL, |
@@ -260,13 +263,13 @@ MHD_parse_arguments_ (struct MHD_Connection *connection, | |||
260 | equals[0] = '\0'; | 263 | equals[0] = '\0'; |
261 | equals++; | 264 | equals++; |
262 | MHD_unescape_plus (args); | 265 | MHD_unescape_plus (args); |
263 | daemon->unescape_callback (daemon->unescape_callback_cls, | 266 | daemon->unescape_cb (daemon->unescape_cb_cls, |
264 | connection, | 267 | connection, |
265 | args); | 268 | args); |
266 | MHD_unescape_plus (equals); | 269 | MHD_unescape_plus (equals); |
267 | daemon->unescape_callback (daemon->unescape_callback_cls, | 270 | daemon->unescape_cb (daemon->unescape_cb_cls, |
268 | connection, | 271 | connection, |
269 | equals); | 272 | equals); |
270 | if (MHD_YES != cb (connection, | 273 | if (MHD_YES != cb (connection, |
271 | args, | 274 | args, |
272 | equals, | 275 | equals, |
diff --git a/src/lib/internal.h b/src/lib/internal.h index f5df8ce2..5a08a0b2 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "microhttpd2.h" | 32 | #include "microhttpd2.h" |
33 | #include "microhttpd_tls.h" | 33 | #include "microhttpd_tls.h" |
34 | #include "mhd_assert.h" | 34 | #include "mhd_assert.h" |
35 | #include "mhd_compat.h" | ||
36 | #include "memorypool.h" | ||
35 | 37 | ||
36 | #ifdef HTTPS_SUPPORT | 38 | #ifdef HTTPS_SUPPORT |
37 | #include <gnutls/gnutls.h> | 39 | #include <gnutls/gnutls.h> |
@@ -67,9 +69,23 @@ | |||
67 | #include "mhd_threads.h" | 69 | #include "mhd_threads.h" |
68 | #include "mhd_locks.h" | 70 | #include "mhd_locks.h" |
69 | #include "mhd_sockets.h" | 71 | #include "mhd_sockets.h" |
72 | #include "mhd_str.h" | ||
70 | #include "mhd_itc_types.h" | 73 | #include "mhd_itc_types.h" |
71 | 74 | ||
72 | 75 | ||
76 | #ifdef HAVE_MESSAGES | ||
77 | /** | ||
78 | * fprintf()-like helper function for logging debug | ||
79 | * messages. | ||
80 | */ | ||
81 | void | ||
82 | MHD_DLOG (const struct MHD_Daemon *daemon, | ||
83 | enum MHD_StatusCode sc, | ||
84 | const char *format, | ||
85 | ...); | ||
86 | #endif | ||
87 | |||
88 | |||
73 | /** | 89 | /** |
74 | * Close FD and abort execution if error is detected. | 90 | * Close FD and abort execution if error is detected. |
75 | * @param fd the FD to close | 91 | * @param fd the FD to close |
@@ -345,13 +361,40 @@ struct MHD_HTTP_Header | |||
345 | 361 | ||
346 | 362 | ||
347 | /** | 363 | /** |
364 | * What is this request waiting for? | ||
365 | */ | ||
366 | enum MHD_RequestEventLoopInfo | ||
367 | { | ||
368 | /** | ||
369 | * We are waiting to be able to read. | ||
370 | */ | ||
371 | MHD_EVENT_LOOP_INFO_READ = 0, | ||
372 | |||
373 | /** | ||
374 | * We are waiting to be able to write. | ||
375 | */ | ||
376 | MHD_EVENT_LOOP_INFO_WRITE = 1, | ||
377 | |||
378 | /** | ||
379 | * We are waiting for the application to provide data. | ||
380 | */ | ||
381 | MHD_EVENT_LOOP_INFO_BLOCK = 2, | ||
382 | |||
383 | /** | ||
384 | * We are finished and are awaiting cleanup. | ||
385 | */ | ||
386 | MHD_EVENT_LOOP_INFO_CLEANUP = 3 | ||
387 | }; | ||
388 | |||
389 | |||
390 | /** | ||
348 | * State kept for each HTTP request. | 391 | * State kept for each HTTP request. |
349 | */ | 392 | */ |
350 | struct MHD_Request | 393 | struct MHD_Request |
351 | { | 394 | { |
352 | 395 | ||
353 | /** | 396 | /** |
354 | * Reference to the MHD_Daemon struct. | 397 | * Reference to the `struct MHD_Daemon`. |
355 | */ | 398 | */ |
356 | struct MHD_Daemon *daemon; | 399 | struct MHD_Daemon *daemon; |
357 | 400 | ||
@@ -361,6 +404,12 @@ struct MHD_Request | |||
361 | struct MHD_Connection *connection; | 404 | struct MHD_Connection *connection; |
362 | 405 | ||
363 | /** | 406 | /** |
407 | * Response to return for this request, set once | ||
408 | * it is available. | ||
409 | */ | ||
410 | struct MHD_Response *response; | ||
411 | |||
412 | /** | ||
364 | * Linked list of parsed headers. | 413 | * Linked list of parsed headers. |
365 | */ | 414 | */ |
366 | struct MHD_HTTP_Header *headers_received; | 415 | struct MHD_HTTP_Header *headers_received; |
@@ -389,9 +438,10 @@ struct MHD_Request | |||
389 | void *client_context; | 438 | void *client_context; |
390 | 439 | ||
391 | /** | 440 | /** |
392 | * Request method. Should be GET/POST/etc. Allocated in pool. | 441 | * Request method as string. Should be GET/POST/etc. Allocated in |
442 | * pool. | ||
393 | */ | 443 | */ |
394 | char *method; | 444 | char *method_s; |
395 | 445 | ||
396 | /** | 446 | /** |
397 | * Requested URL (everything after "GET" only). Allocated | 447 | * Requested URL (everything after "GET" only). Allocated |
@@ -557,6 +607,11 @@ struct MHD_Request | |||
557 | enum MHD_REQUEST_STATE state; | 607 | enum MHD_REQUEST_STATE state; |
558 | 608 | ||
559 | /** | 609 | /** |
610 | * HTTP method, as an enum. | ||
611 | */ | ||
612 | enum MHD_Method method; | ||
613 | |||
614 | /** | ||
560 | * What is this request waiting for? | 615 | * What is this request waiting for? |
561 | */ | 616 | */ |
562 | enum MHD_RequestEventLoopInfo event_loop_info; | 617 | enum MHD_RequestEventLoopInfo event_loop_info; |
@@ -591,6 +646,54 @@ struct MHD_Request | |||
591 | }; | 646 | }; |
592 | 647 | ||
593 | 648 | ||
649 | #ifdef EPOLL_SUPPORT | ||
650 | /** | ||
651 | * State of the socket with respect to epoll (bitmask). | ||
652 | */ | ||
653 | enum MHD_EpollState | ||
654 | { | ||
655 | |||
656 | /** | ||
657 | * The socket is not involved with a defined state in epoll() right | ||
658 | * now. | ||
659 | */ | ||
660 | MHD_EPOLL_STATE_UNREADY = 0, | ||
661 | |||
662 | /** | ||
663 | * epoll() told us that data was ready for reading, and we did | ||
664 | * not consume all of it yet. | ||
665 | */ | ||
666 | MHD_EPOLL_STATE_READ_READY = 1, | ||
667 | |||
668 | /** | ||
669 | * epoll() told us that space was available for writing, and we did | ||
670 | * not consume all of it yet. | ||
671 | */ | ||
672 | MHD_EPOLL_STATE_WRITE_READY = 2, | ||
673 | |||
674 | /** | ||
675 | * Is this connection currently in the 'eready' EDLL? | ||
676 | */ | ||
677 | MHD_EPOLL_STATE_IN_EREADY_EDLL = 4, | ||
678 | |||
679 | /** | ||
680 | * Is this connection currently in the epoll() set? | ||
681 | */ | ||
682 | MHD_EPOLL_STATE_IN_EPOLL_SET = 8, | ||
683 | |||
684 | /** | ||
685 | * Is this connection currently suspended? | ||
686 | */ | ||
687 | MHD_EPOLL_STATE_SUSPENDED = 16, | ||
688 | |||
689 | /** | ||
690 | * Is this connection in some error state? | ||
691 | */ | ||
692 | MHD_EPOLL_STATE_ERROR = 128 | ||
693 | }; | ||
694 | #endif | ||
695 | |||
696 | |||
594 | /** | 697 | /** |
595 | * State kept per HTTP connection. | 698 | * State kept per HTTP connection. |
596 | */ | 699 | */ |
@@ -990,7 +1093,11 @@ struct MHD_Daemon | |||
990 | */ | 1093 | */ |
991 | bool allow_address_reuse; | 1094 | bool allow_address_reuse; |
992 | 1095 | ||
993 | 1096 | /** | |
1097 | * Are we shutting down? | ||
1098 | */ | ||
1099 | volatile bool shutdown; | ||
1100 | |||
994 | }; | 1101 | }; |
995 | 1102 | ||
996 | 1103 | ||
@@ -1000,10 +1107,11 @@ struct MHD_Daemon | |||
1000 | * | 1107 | * |
1001 | * @param cls action-specfic closure | 1108 | * @param cls action-specfic closure |
1002 | * @param request the request on which the action is to be performed | 1109 | * @param request the request on which the action is to be performed |
1110 | * @return #MHD_SC_OK on success, otherwise an error code | ||
1003 | */ | 1111 | */ |
1004 | typedef void | 1112 | typedef enum MHD_StatusCode |
1005 | (*ActionCallback) (void *cls, | 1113 | (*ActionCallback) (void *cls, |
1006 | const struct MHD_Request *request); | 1114 | struct MHD_Request *request); |
1007 | 1115 | ||
1008 | 1116 | ||
1009 | /** | 1117 | /** |
@@ -1153,4 +1261,44 @@ struct MHD_Response | |||
1153 | 1261 | ||
1154 | 1262 | ||
1155 | 1263 | ||
1264 | /** | ||
1265 | * Callback invoked when iterating over @a key / @a value | ||
1266 | * argument pairs during parsing. | ||
1267 | * | ||
1268 | * @param connection context of the iteration | ||
1269 | * @param key 0-terminated key string, never NULL | ||
1270 | * @param value 0-terminated value string, may be NULL | ||
1271 | * @param kind origin of the key-value pair | ||
1272 | * @return #MHD_YES on success (continue to iterate) | ||
1273 | * #MHD_NO to signal failure (and abort iteration) | ||
1274 | */ | ||
1275 | typedef int | ||
1276 | (*MHD_ArgumentIterator_)(struct MHD_Connection *connection, | ||
1277 | const char *key, | ||
1278 | const char *value, | ||
1279 | enum MHD_ValueKind kind); | ||
1280 | |||
1281 | |||
1282 | /** | ||
1283 | * Parse and unescape the arguments given by the client | ||
1284 | * as part of the HTTP request URI. | ||
1285 | * | ||
1286 | * @param kind header kind to pass to @a cb | ||
1287 | * @param connection connection to add headers to | ||
1288 | * @param[in,out] args argument URI string (after "?" in URI), | ||
1289 | * clobbered in the process! | ||
1290 | * @param cb function to call on each key-value pair found | ||
1291 | * @param[out] num_headers set to the number of headers found | ||
1292 | * @return #MHD_NO on failure (@a cb returned #MHD_NO), | ||
1293 | * #MHD_YES for success (parsing succeeded, @a cb always | ||
1294 | * returned #MHD_YES) | ||
1295 | */ | ||
1296 | int | ||
1297 | MHD_parse_arguments_ (struct MHD_Connection *connection, | ||
1298 | enum MHD_ValueKind kind, | ||
1299 | char *args, | ||
1300 | MHD_ArgumentIterator_ cb, | ||
1301 | unsigned int *num_headers); | ||
1302 | |||
1303 | |||
1156 | #endif | 1304 | #endif |
diff --git a/src/lib/request.c b/src/lib/request.c index 0e280efa..b834ba9d 100644 --- a/src/lib/request.c +++ b/src/lib/request.c | |||
@@ -24,6 +24,7 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Karlson2k (Evgeny Grin) | 25 | * @author Karlson2k (Evgeny Grin) |
26 | */ | 26 | */ |
27 | #include "internal.h" | ||
27 | 28 | ||
28 | 29 | ||
29 | /** | 30 | /** |
diff --git a/src/lib/response.c b/src/lib/response.c index 25943883..2a9a2604 100644 --- a/src/lib/response.c +++ b/src/lib/response.c | |||
@@ -129,7 +129,7 @@ MHD_response_add_header (struct MHD_Response *response, | |||
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_TRUE : MHD_FALSE; | 132 | content) ? MHD_YES : MHD_NO; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
@@ -151,7 +151,7 @@ MHD_response_add_trailer (struct MHD_Response *response, | |||
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_TRUE : MHD_FALSE; | 154 | content) ? MHD_YES : MHD_NO; |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
diff --git a/src/lib/response_from_buffer.c b/src/lib/response_from_buffer.c index be6a1e00..a53537b0 100644 --- a/src/lib/response_from_buffer.c +++ b/src/lib/response_from_buffer.c | |||
@@ -46,7 +46,7 @@ MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc, | |||
46 | struct MHD_Response *response; | 46 | struct MHD_Response *response; |
47 | void *tmp; | 47 | void *tmp; |
48 | 48 | ||
49 | mhd_assert ( (NULL != data) || | 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, |
@@ -68,19 +68,19 @@ MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc, | |||
68 | return NULL; | 68 | return NULL; |
69 | } | 69 | } |
70 | memcpy (tmp, | 70 | memcpy (tmp, |
71 | data, | 71 | buffer, |
72 | size); | 72 | size); |
73 | data = tmp; | 73 | buffer = tmp; |
74 | } | 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 = data; | 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; |
83 | response->data = data; | 83 | response->data = buffer; |
84 | response->data_size = size; | 84 | response->data_size = size; |
85 | return response; | 85 | return response; |
86 | } | 86 | } |
diff --git a/src/lib/response_from_fd.c b/src/lib/response_from_fd.c index ea486600..cdeb7aa5 100644 --- a/src/lib/response_from_fd.c +++ b/src/lib/response_from_fd.c | |||
@@ -180,7 +180,8 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, | |||
180 | ((int64_t) (size + offset) < 0) ) | 180 | ((int64_t) (size + offset) < 0) ) |
181 | return NULL; | 181 | return NULL; |
182 | 182 | ||
183 | response = MHD_response_from_callback (size, | 183 | response = MHD_response_from_callback (sc, |
184 | size, | ||
184 | 4 * 1024, | 185 | 4 * 1024, |
185 | &file_reader, | 186 | &file_reader, |
186 | NULL, | 187 | NULL, |
@@ -188,7 +189,6 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, | |||
188 | if (NULL == response) | 189 | if (NULL == response) |
189 | return NULL; | 190 | return NULL; |
190 | response->fd = fd; | 191 | response->fd = fd; |
191 | response->status_code = sc; | ||
192 | response->fd_off = offset; | 192 | response->fd_off = offset; |
193 | response->crc_cls = response; | 193 | response->crc_cls = response; |
194 | return response; | 194 | return response; |
diff --git a/src/lib/version.c b/src/lib/version.c index 9ef03e53..472a8c04 100644 --- a/src/lib/version.c +++ b/src/lib/version.c | |||
@@ -65,8 +65,8 @@ MHD_get_version (void) | |||
65 | * feature is not supported or feature is unknown. | 65 | * feature is not supported or feature is unknown. |
66 | * @ingroup specialized | 66 | * @ingroup specialized |
67 | */ | 67 | */ |
68 | _MHD_EXTERN int | 68 | _MHD_EXTERN enum MHD_Bool |
69 | MHD_is_feature_supported(enum MHD_FEATURE feature) | 69 | MHD_is_feature_supported(enum MHD_Feature feature) |
70 | { | 70 | { |
71 | switch(feature) | 71 | switch(feature) |
72 | { | 72 | { |
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index c999ea35..9be34144 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -751,10 +751,10 @@ MHD_socket_noninheritable_ (MHD_socket sock); | |||
751 | /** | 751 | /** |
752 | * Create a listen socket, with noninheritable flag if possible. | 752 | * Create a listen socket, with noninheritable flag if possible. |
753 | * | 753 | * |
754 | * @param use_ipv6 if set to non-zero IPv6 is used | 754 | * @param pf protocol family to use |
755 | * @return created socket or MHD_INVALID_SOCKET in case of errors | 755 | * @return created socket or MHD_INVALID_SOCKET in case of errors |
756 | */ | 756 | */ |
757 | MHD_socket | 757 | MHD_socket |
758 | MHD_socket_create_listen_ (bool use_ipv6); | 758 | MHD_socket_create_listen_ (int pf); |
759 | 759 | ||
760 | #endif /* ! MHD_SOCKETS_H */ | 760 | #endif /* ! MHD_SOCKETS_H */ |