diff options
Diffstat (limited to 'src/include/microhttpd2.h')
-rw-r--r-- | src/include/microhttpd2.h | 669 |
1 files changed, 655 insertions, 14 deletions
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 |