86 #ifndef MHD_MICROHTTPD_H
87 #define MHD_MICROHTTPD_H
107 #ifndef MHD_PLATFORM_H
110 #include <sys/types.h>
111 #if defined(_WIN32) && !defined(__CYGWIN__)
112 #include <ws2tcpip.h>
113 #if defined(_MSC_FULL_VER) && !defined (_SSIZE_T_DEFINED)
114 #define _SSIZE_T_DEFINED
115 typedef intptr_t ssize_t;
116 #endif // !_SSIZE_T_DEFINED */
119 #include <sys/time.h>
120 #include <sys/socket.h>
124 #if defined(__CYGWIN__) && !defined(_SYS_TYPES_FD_SET)
126 #error Cygwin with winsock fd_set is not supported
133 #define MHD_VERSION 0x00093900
148 #define MHD_INVALID_NONCE -1
155 #define MHD_SIZE_UNKNOWN UINT64_MAX
157 #define MHD_SIZE_UNKNOWN ((uint64_t) -1LL)
161 #define MHD_CONTENT_READER_END_OF_STREAM SIZE_MAX
162 #define MHD_CONTENT_READER_END_WITH_ERROR (SIZE_MAX - 1)
164 #define MHD_CONTENT_READER_END_OF_STREAM ((size_t) -1LL)
165 #define MHD_CONTENT_READER_END_WITH_ERROR (((size_t) -1LL) - 1)
169 #if defined(_WIN32) && defined(MHD_W32LIB)
170 #define _MHD_EXTERN extern
171 #elif defined (_WIN32) && defined(MHD_W32DLL)
173 #define _MHD_EXTERN __declspec(dllimport)
175 #define _MHD_EXTERN extern
179 #ifndef MHD_SOCKET_DEFINED
183 #if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
184 #define MHD_POSIX_SOCKETS 1
186 #define MHD_INVALID_SOCKET (-1)
188 #define MHD_WINSOCK_SOCKETS 1
189 #include <winsock2.h>
191 #define MHD_INVALID_SOCKET (INVALID_SOCKET)
193 #define MHD_SOCKET_DEFINED 1
201 #ifndef MHD_LONG_LONG
205 #define MHD_LONG_LONG long long
206 #define MHD_UNSIGNED_LONG_LONG unsigned long long
212 #ifndef MHD_LONG_LONG_PRINTF
216 #define MHD_LONG_LONG_PRINTF "ll"
217 #define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
226 #define MHD_HTTP_CONTINUE 100
227 #define MHD_HTTP_SWITCHING_PROTOCOLS 101
228 #define MHD_HTTP_PROCESSING 102
230 #define MHD_HTTP_OK 200
231 #define MHD_HTTP_CREATED 201
232 #define MHD_HTTP_ACCEPTED 202
233 #define MHD_HTTP_NON_AUTHORITATIVE_INFORMATION 203
234 #define MHD_HTTP_NO_CONTENT 204
235 #define MHD_HTTP_RESET_CONTENT 205
236 #define MHD_HTTP_PARTIAL_CONTENT 206
237 #define MHD_HTTP_MULTI_STATUS 207
239 #define MHD_HTTP_MULTIPLE_CHOICES 300
240 #define MHD_HTTP_MOVED_PERMANENTLY 301
241 #define MHD_HTTP_FOUND 302
242 #define MHD_HTTP_SEE_OTHER 303
243 #define MHD_HTTP_NOT_MODIFIED 304
244 #define MHD_HTTP_USE_PROXY 305
245 #define MHD_HTTP_SWITCH_PROXY 306
246 #define MHD_HTTP_TEMPORARY_REDIRECT 307
248 #define MHD_HTTP_BAD_REQUEST 400
249 #define MHD_HTTP_UNAUTHORIZED 401
250 #define MHD_HTTP_PAYMENT_REQUIRED 402
251 #define MHD_HTTP_FORBIDDEN 403
252 #define MHD_HTTP_NOT_FOUND 404
253 #define MHD_HTTP_METHOD_NOT_ALLOWED 405
254 #define MHD_HTTP_NOT_ACCEPTABLE 406
256 #define MHD_HTTP_METHOD_NOT_ACCEPTABLE 406
257 #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
258 #define MHD_HTTP_REQUEST_TIMEOUT 408
259 #define MHD_HTTP_CONFLICT 409
260 #define MHD_HTTP_GONE 410
261 #define MHD_HTTP_LENGTH_REQUIRED 411
262 #define MHD_HTTP_PRECONDITION_FAILED 412
263 #define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 413
264 #define MHD_HTTP_REQUEST_URI_TOO_LONG 414
265 #define MHD_HTTP_UNSUPPORTED_MEDIA_TYPE 415
266 #define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416
267 #define MHD_HTTP_EXPECTATION_FAILED 417
268 #define MHD_HTTP_UNPROCESSABLE_ENTITY 422
269 #define MHD_HTTP_LOCKED 423
270 #define MHD_HTTP_FAILED_DEPENDENCY 424
271 #define MHD_HTTP_UNORDERED_COLLECTION 425
272 #define MHD_HTTP_UPGRADE_REQUIRED 426
273 #define MHD_HTTP_NO_RESPONSE 444
274 #define MHD_HTTP_RETRY_WITH 449
275 #define MHD_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
276 #define MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
278 #define MHD_HTTP_INTERNAL_SERVER_ERROR 500
279 #define MHD_HTTP_NOT_IMPLEMENTED 501
280 #define MHD_HTTP_BAD_GATEWAY 502
281 #define MHD_HTTP_SERVICE_UNAVAILABLE 503
282 #define MHD_HTTP_GATEWAY_TIMEOUT 504
283 #define MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
284 #define MHD_HTTP_VARIANT_ALSO_NEGOTIATES 506
285 #define MHD_HTTP_INSUFFICIENT_STORAGE 507
286 #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
287 #define MHD_HTTP_NOT_EXTENDED 510
297 #define MHD_ICY_FLAG ((uint32_t)(1 << 31))
305 #define MHD_HTTP_HEADER_ACCEPT "Accept"
306 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
307 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
308 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
309 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
310 #define MHD_HTTP_HEADER_AGE "Age"
311 #define MHD_HTTP_HEADER_ALLOW "Allow"
312 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
313 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
314 #define MHD_HTTP_HEADER_CONNECTION "Connection"
315 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
316 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
317 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
318 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
319 #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5"
320 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
321 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
322 #define MHD_HTTP_HEADER_COOKIE "Cookie"
323 #define MHD_HTTP_HEADER_DATE "Date"
324 #define MHD_HTTP_HEADER_ETAG "ETag"
325 #define MHD_HTTP_HEADER_EXPECT "Expect"
326 #define MHD_HTTP_HEADER_EXPIRES "Expires"
327 #define MHD_HTTP_HEADER_FROM "From"
328 #define MHD_HTTP_HEADER_HOST "Host"
329 #define MHD_HTTP_HEADER_IF_MATCH "If-Match"
330 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
331 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
332 #define MHD_HTTP_HEADER_IF_RANGE "If-Range"
333 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
334 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
335 #define MHD_HTTP_HEADER_LOCATION "Location"
336 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
337 #define MHD_HTTP_HEADER_PRAGMA "Pragma"
338 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
339 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
340 #define MHD_HTTP_HEADER_RANGE "Range"
342 #define MHD_HTTP_HEADER_REFERER "Referer"
343 #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After"
344 #define MHD_HTTP_HEADER_SERVER "Server"
345 #define MHD_HTTP_HEADER_SET_COOKIE "Set-Cookie"
346 #define MHD_HTTP_HEADER_SET_COOKIE2 "Set-Cookie2"
347 #define MHD_HTTP_HEADER_TE "TE"
348 #define MHD_HTTP_HEADER_TRAILER "Trailer"
349 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
350 #define MHD_HTTP_HEADER_UPGRADE "Upgrade"
351 #define MHD_HTTP_HEADER_USER_AGENT "User-Agent"
352 #define MHD_HTTP_HEADER_VARY "Vary"
353 #define MHD_HTTP_HEADER_VIA "Via"
354 #define MHD_HTTP_HEADER_WARNING "Warning"
355 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
356 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN "Access-Control-Allow-Origin"
366 #define MHD_HTTP_VERSION_1_0 "HTTP/1.0"
367 #define MHD_HTTP_VERSION_1_1 "HTTP/1.1"
376 #define MHD_HTTP_METHOD_CONNECT "CONNECT"
377 #define MHD_HTTP_METHOD_DELETE "DELETE"
378 #define MHD_HTTP_METHOD_GET "GET"
379 #define MHD_HTTP_METHOD_HEAD "HEAD"
380 #define MHD_HTTP_METHOD_OPTIONS "OPTIONS"
381 #define MHD_HTTP_METHOD_POST "POST"
382 #define MHD_HTTP_METHOD_PUT "PUT"
383 #define MHD_HTTP_METHOD_TRACE "TRACE"
392 #define MHD_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded"
393 #define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
424 struct MHD_PostProcessor;
1153 const char *reason);
1165 const struct sockaddr *addr,
1214 const char *upload_data,
1215 size_t *upload_data_size,
1347 const char *filename,
1348 const char *content_type,
1349 const char *transfer_encoding,
1470 const struct sockaddr *addr,
1495 fd_set *read_fd_set,
1496 fd_set *write_fd_set,
1497 fd_set *except_fd_set,
1524 fd_set *read_fd_set,
1525 fd_set *write_fd_set,
1526 fd_set *except_fd_set,
1528 unsigned int fd_setsize);
1550 #define MHD_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \
1551 MHD_get_fdset2((daemon),(read_fd_set),(write_fd_set),(except_fd_set),(max_fd),FD_SETSIZE)
1617 const fd_set *read_fd_set,
1618 const fd_set *write_fd_set,
1619 const fd_set *except_fd_set);
1737 unsigned int status_code,
1974 enum MHD_UpgradeAction
1985 MHD_UPGRADE_ACTION_CLOSE = 0,
1996 MHD_UPGRADE_ACTION_CORK
2013 (*MHD_UpgradeActionCallback)(
void *cls,
2014 enum MHD_UpgradeAction action,
2063 (*MHD_UpgradeHandler)(
void *cls,
2066 MHD_UpgradeActionCallback upgrade_action,
2067 void *upgrade_action_cls);
2100 MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
2101 void *upgrade_handler_cls);
2130 const char *content);
2145 const char *content);
2160 const char *content);
2239 const char *post_data,
size_t post_data_len);
2264 #define MHD_INVALID_NONCE -1
2295 const char *username,
2296 const char *password,
2297 unsigned int nonce_timeout);
int(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon_va(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_callback(uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
_MHD_EXTERN const char * MHD_get_version(void)
_MHD_EXTERN const char * MHD_lookup_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
_MHD_EXTERN int MHD_add_response_header(struct MHD_Response *response, const char *header, const char *content)
MHD_ContentReaderFreeCallback crfc
_MHD_EXTERN int MHD_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
void(* MHD_ContentReaderFreeCallback)(void *cls)
_MHD_EXTERN int MHD_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen)
int(* MHD_PostDataIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd_at_offset(size_t size, int fd, off_t offset)
_MHD_EXTERN int MHD_queue_basic_auth_fail_response(struct MHD_Connection *connection, const char *realm, struct MHD_Response *response)
MHD_RequestTerminationCode
_MHD_EXTERN int MHD_destroy_post_processor(struct MHD_PostProcessor *pp)
_MHD_EXTERN int MHD_digest_auth_check(struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
_MHD_EXTERN void MHD_set_panic_func(MHD_PanicCallback cb, void *cls)
#define MHD_UNSIGNED_LONG_LONG
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
_MHD_EXTERN struct MHD_PostProcessor * MHD_create_post_processor(struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls)
void(* MHD_LogCallback)(void *cls, const char *fm, va_list ap)
_MHD_EXTERN const union MHD_ConnectionInfo * MHD_get_connection_info(struct MHD_Connection *connection, enum MHD_ConnectionInfoType info_type,...)
_MHD_EXTERN char * MHD_basic_auth_get_username_password(struct MHD_Connection *connection, char **password)
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN int MHD_queue_auth_fail_response(struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale)
_MHD_EXTERN int MHD_add_response_footer(struct MHD_Response *response, const char *footer, const char *content)
_MHD_EXTERN int MHD_run_from_select(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
_MHD_EXTERN char * MHD_digest_auth_get_username(struct MHD_Connection *connection)
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
_MHD_EXTERN void MHD_suspend_connection(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_set_connection_option(struct MHD_Connection *connection, enum MHD_CONNECTION_OPTION option,...)
struct MHD_Daemon * daemon
_MHD_EXTERN int MHD_post_process(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd(size_t size, int fd)
_MHD_EXTERN int MHD_queue_response(struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
MHD_AcceptPolicyCallback apc
int(* MHD_AccessHandlerCallback)(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
_MHD_EXTERN int MHD_set_response_options(struct MHD_Response *response, enum MHD_ResponseFlags flags,...)
_MHD_EXTERN int MHD_get_connection_values(struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
_MHD_EXTERN int MHD_run(struct MHD_Daemon *daemon)
#define MHD_get_fdset(daemon, read_fd_set, write_fd_set, except_fd_set, max_fd)
MHD_ContentReaderCallback crc
_MHD_EXTERN int MHD_is_feature_supported(enum MHD_FEATURE feature)
struct sockaddr * client_addr
_MHD_EXTERN int MHD_del_response_header(struct MHD_Response *response, const char *header, const char *content)
_MHD_EXTERN int MHD_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_data(size_t size, void *data, int must_free, int must_copy)
_MHD_EXTERN const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
_MHD_EXTERN MHD_socket MHD_quiesce_daemon(struct MHD_Daemon *daemon)
unsigned int num_connections
int(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
_MHD_EXTERN const union MHD_DaemonInfo * MHD_get_daemon_info(struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...)
_MHD_EXTERN size_t MHD_http_unescape(char *val)
_MHD_EXTERN int MHD_set_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
MHD_FLAG
Flags for the struct MHD_Daemon.
_MHD_EXTERN int MHD_get_response_headers(struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
_MHD_EXTERN void MHD_resume_connection(struct MHD_Connection *connection)