00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00072 #ifndef MHD_MICROHTTPD_H
00073 #define MHD_MICROHTTPD_H
00074
00075 #ifdef __cplusplus
00076 extern "C"
00077 {
00078 #if 0
00079 }
00080 #endif
00081 #endif
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifndef MHD_PLATFORM_H
00094 #include <unistd.h>
00095 #include <stdarg.h>
00096 #include <stdint.h>
00097 #ifdef __MINGW32__
00098 #include <ws2tcpip.h>
00099 #else
00100 #include <sys/time.h>
00101 #include <sys/types.h>
00102 #include <sys/socket.h>
00103 #endif
00104 #endif
00105
00109 #define MHD_VERSION 0x00090200
00110
00114 #define MHD_YES 1
00115
00119 #define MHD_NO 0
00120
00124 #define MHD_INVALID_NONCE -1
00125
00130 #ifdef UINT64_MAX
00131 #define MHD_SIZE_UNKNOWN UINT64_MAX
00132 #else
00133 #define MHD_SIZE_UNKNOWN ((uint64_t) -1LL)
00134 #endif
00135
00139 #define MHD_HTTP_CONTINUE 100
00140 #define MHD_HTTP_SWITCHING_PROTOCOLS 101
00141 #define MHD_HTTP_PROCESSING 102
00142
00143 #define MHD_HTTP_OK 200
00144 #define MHD_HTTP_CREATED 201
00145 #define MHD_HTTP_ACCEPTED 202
00146 #define MHD_HTTP_NON_AUTHORITATIVE_INFORMATION 203
00147 #define MHD_HTTP_NO_CONTENT 204
00148 #define MHD_HTTP_RESET_CONTENT 205
00149 #define MHD_HTTP_PARTIAL_CONTENT 206
00150 #define MHD_HTTP_MULTI_STATUS 207
00151
00152 #define MHD_HTTP_MULTIPLE_CHOICES 300
00153 #define MHD_HTTP_MOVED_PERMANENTLY 301
00154 #define MHD_HTTP_FOUND 302
00155 #define MHD_HTTP_SEE_OTHER 303
00156 #define MHD_HTTP_NOT_MODIFIED 304
00157 #define MHD_HTTP_USE_PROXY 305
00158 #define MHD_HTTP_SWITCH_PROXY 306
00159 #define MHD_HTTP_TEMPORARY_REDIRECT 307
00160
00161 #define MHD_HTTP_BAD_REQUEST 400
00162 #define MHD_HTTP_UNAUTHORIZED 401
00163 #define MHD_HTTP_PAYMENT_REQUIRED 402
00164 #define MHD_HTTP_FORBIDDEN 403
00165 #define MHD_HTTP_NOT_FOUND 404
00166 #define MHD_HTTP_METHOD_NOT_ALLOWED 405
00167 #define MHD_HTTP_METHOD_NOT_ACCEPTABLE 406
00168 #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
00169 #define MHD_HTTP_REQUEST_TIMEOUT 408
00170 #define MHD_HTTP_CONFLICT 409
00171 #define MHD_HTTP_GONE 410
00172 #define MHD_HTTP_LENGTH_REQUIRED 411
00173 #define MHD_HTTP_PRECONDITION_FAILED 412
00174 #define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 413
00175 #define MHD_HTTP_REQUEST_URI_TOO_LONG 414
00176 #define MHD_HTTP_UNSUPPORTED_MEDIA_TYPE 415
00177 #define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416
00178 #define MHD_HTTP_EXPECTATION_FAILED 417
00179 #define MHD_HTTP_UNPROCESSABLE_ENTITY 422
00180 #define MHD_HTTP_LOCKED 423
00181 #define MHD_HTTP_FAILED_DEPENDENCY 424
00182 #define MHD_HTTP_UNORDERED_COLLECTION 425
00183 #define MHD_HTTP_UPGRADE_REQUIRED 426
00184 #define MHD_HTTP_RETRY_WITH 449
00185
00186 #define MHD_HTTP_INTERNAL_SERVER_ERROR 500
00187 #define MHD_HTTP_NOT_IMPLEMENTED 501
00188 #define MHD_HTTP_BAD_GATEWAY 502
00189 #define MHD_HTTP_SERVICE_UNAVAILABLE 503
00190 #define MHD_HTTP_GATEWAY_TIMEOUT 504
00191 #define MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
00192 #define MHD_HTTP_VARIANT_ALSO_NEGOTIATES 506
00193 #define MHD_HTTP_INSUFFICIENT_STORAGE 507
00194 #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
00195 #define MHD_HTTP_NOT_EXTENDED 510
00196
00202 #define MHD_ICY_FLAG ((uint32_t)(1 << 31))
00203
00204
00205 #define MHD_HTTP_HEADER_ACCEPT "Accept"
00206 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
00207 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
00208 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
00209 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
00210 #define MHD_HTTP_HEADER_AGE "Age"
00211 #define MHD_HTTP_HEADER_ALLOW "Allow"
00212 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
00213 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
00214 #define MHD_HTTP_HEADER_CONNECTION "Connection"
00215 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
00216 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
00217 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
00218 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
00219 #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5"
00220 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
00221 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
00222 #define MHD_HTTP_HEADER_COOKIE "Cookie"
00223 #define MHD_HTTP_HEADER_DATE "Date"
00224 #define MHD_HTTP_HEADER_ETAG "ETag"
00225 #define MHD_HTTP_HEADER_EXPECT "Expect"
00226 #define MHD_HTTP_HEADER_EXPIRES "Expires"
00227 #define MHD_HTTP_HEADER_FROM "From"
00228 #define MHD_HTTP_HEADER_HOST "Host"
00229 #define MHD_HTTP_HEADER_IF_MATCH "If-Match"
00230 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
00231 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
00232 #define MHD_HTTP_HEADER_IF_RANGE "If-Range"
00233 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
00234 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
00235 #define MHD_HTTP_HEADER_LOCATION "Location"
00236 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
00237 #define MHD_HTTP_HEADER_PRAGMA "Pragma"
00238 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
00239 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
00240 #define MHD_HTTP_HEADER_RANGE "Range"
00241 #define MHD_HTTP_HEADER_REFERER "Referer"
00242 #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After"
00243 #define MHD_HTTP_HEADER_SERVER "Server"
00244 #define MHD_HTTP_HEADER_SET_COOKIE "Set-Cookie"
00245 #define MHD_HTTP_HEADER_SET_COOKIE2 "Set-Cookie2"
00246 #define MHD_HTTP_HEADER_TE "TE"
00247 #define MHD_HTTP_HEADER_TRAILER "Trailer"
00248 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
00249 #define MHD_HTTP_HEADER_UPGRADE "Upgrade"
00250 #define MHD_HTTP_HEADER_USER_AGENT "User-Agent"
00251 #define MHD_HTTP_HEADER_VARY "Vary"
00252 #define MHD_HTTP_HEADER_VIA "Via"
00253 #define MHD_HTTP_HEADER_WARNING "Warning"
00254 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
00255
00260 #define MHD_HTTP_VERSION_1_0 "HTTP/1.0"
00261 #define MHD_HTTP_VERSION_1_1 "HTTP/1.1"
00262
00266 #define MHD_HTTP_METHOD_CONNECT "CONNECT"
00267 #define MHD_HTTP_METHOD_DELETE "DELETE"
00268 #define MHD_HTTP_METHOD_GET "GET"
00269 #define MHD_HTTP_METHOD_HEAD "HEAD"
00270 #define MHD_HTTP_METHOD_OPTIONS "OPTIONS"
00271 #define MHD_HTTP_METHOD_POST "POST"
00272 #define MHD_HTTP_METHOD_PUT "PUT"
00273 #define MHD_HTTP_METHOD_TRACE "TRACE"
00274
00279 #define MHD_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded"
00280 #define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
00281
00292 enum MHD_FLAG
00293 {
00297 MHD_NO_FLAG = 0,
00298
00304 MHD_USE_DEBUG = 1,
00305
00309 MHD_USE_SSL = 2,
00310
00314 MHD_USE_THREAD_PER_CONNECTION = 4,
00315
00319 MHD_USE_SELECT_INTERNALLY = 8,
00320
00325 MHD_USE_IPv6 = 16,
00326
00336 MHD_USE_PEDANTIC_CHECKS = 32,
00337
00343 MHD_USE_POLL = 64
00344 };
00345
00350 enum MHD_OPTION
00351 {
00352
00357 MHD_OPTION_END = 0,
00358
00363 MHD_OPTION_CONNECTION_MEMORY_LIMIT = 1,
00364
00369 MHD_OPTION_CONNECTION_LIMIT = 2,
00370
00376 MHD_OPTION_CONNECTION_TIMEOUT = 3,
00377
00390 MHD_OPTION_NOTIFY_COMPLETED = 4,
00391
00402 MHD_OPTION_PER_IP_CONNECTION_LIMIT = 5,
00403
00409 MHD_OPTION_SOCK_ADDR = 6,
00410
00432 MHD_OPTION_URI_LOG_CALLBACK = 7,
00433
00440 MHD_OPTION_HTTPS_MEM_KEY = 8,
00441
00448 MHD_OPTION_HTTPS_MEM_CERT = 9,
00449
00455 MHD_OPTION_HTTPS_CRED_TYPE = 10,
00456
00461 MHD_OPTION_HTTPS_PRIORITIES = 11,
00462
00469 MHD_OPTION_LISTEN_SOCKET = 12,
00470
00483 MHD_OPTION_EXTERNAL_LOGGER = 13,
00484
00493 MHD_OPTION_THREAD_POOL_SIZE = 14,
00494
00514 MHD_OPTION_ARRAY = 15,
00515
00534 MHD_OPTION_UNESCAPE_CALLBACK = 16,
00535
00545 MHD_OPTION_DIGEST_AUTH_RANDOM = 17,
00546
00552 MHD_OPTION_NONCE_NC_SIZE = 18
00553 };
00554
00555
00559 struct MHD_OptionItem
00560 {
00565 enum MHD_OPTION option;
00566
00572 intptr_t value;
00573
00578 void *ptr_value;
00579
00580 };
00581
00582
00587 enum MHD_ValueKind
00588 {
00589
00593 MHD_RESPONSE_HEADER_KIND = 0,
00594
00598 MHD_HEADER_KIND = 1,
00599
00604 MHD_COOKIE_KIND = 2,
00605
00614 MHD_POSTDATA_KIND = 4,
00615
00619 MHD_GET_ARGUMENT_KIND = 8,
00620
00624 MHD_FOOTER_KIND = 16
00625 };
00626
00631 enum MHD_RequestTerminationCode
00632 {
00633
00637 MHD_REQUEST_TERMINATED_COMPLETED_OK = 0,
00638
00644 MHD_REQUEST_TERMINATED_WITH_ERROR = 1,
00645
00651 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2,
00652
00657 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3
00658
00659 };
00660
00661
00666 enum MHD_ConnectionInfoType
00667 {
00672 MHD_CONNECTION_INFO_CIPHER_ALGO,
00673
00678 MHD_CONNECTION_INFO_PROTOCOL,
00679
00684 MHD_CONNECTION_INFO_CLIENT_ADDRESS,
00685
00689 MHD_CONNECTION_INFO_GNUTLS_SESSION
00690 };
00691
00696 enum MHD_DaemonInfoType
00697 {
00704 MHD_DAEMON_INFO_KEY_SIZE,
00705
00712 MHD_DAEMON_INFO_MAC_KEY_SIZE,
00713
00718 MHD_DAEMON_INFO_LISTEN_FD
00719 };
00720
00721
00722
00726 struct MHD_Daemon;
00727
00734 struct MHD_Connection;
00735
00739 struct MHD_Response;
00740
00744 struct MHD_PostProcessor;
00745
00753 typedef void (*MHD_PanicCallback) (void *cls,
00754 const char *file,
00755 unsigned int line,
00756 const char *reason);
00757
00765 typedef int
00766 (*MHD_AcceptPolicyCallback) (void *cls,
00767 const struct sockaddr * addr,
00768 socklen_t addrlen);
00769
00805 typedef int
00806 (*MHD_AccessHandlerCallback) (void *cls,
00807 struct MHD_Connection * connection,
00808 const char *url,
00809 const char *method,
00810 const char *version,
00811 const char *upload_data,
00812 size_t *upload_data_size,
00813 void **con_cls);
00814
00826 typedef void
00827 (*MHD_RequestCompletedCallback) (void *cls,
00828 struct MHD_Connection * connection,
00829 void **con_cls,
00830 enum MHD_RequestTerminationCode toe);
00831
00842 typedef int
00843 (*MHD_KeyValueIterator) (void *cls,
00844 enum MHD_ValueKind kind,
00845 const char *key, const char *value);
00846
00881 typedef ssize_t
00882 (*MHD_ContentReaderCallback) (void *cls,
00883 uint64_t pos,
00884 char *buf,
00885 size_t max);
00886
00893 typedef void (*MHD_ContentReaderFreeCallback) (void *cls);
00894
00914 typedef int
00915 (*MHD_PostDataIterator) (void *cls,
00916 enum MHD_ValueKind kind,
00917 const char *key,
00918 const char *filename,
00919 const char *content_type,
00920 const char *transfer_encoding,
00921 const char *data, uint64_t off, size_t size);
00922
00923
00924
00941 struct MHD_Daemon *MHD_start_daemon_va (unsigned int options,
00942 uint16_t port,
00943 MHD_AcceptPolicyCallback apc,
00944 void *apc_cls,
00945 MHD_AccessHandlerCallback dh,
00946 void *dh_cls, va_list ap);
00947
00963 struct MHD_Daemon *MHD_start_daemon (unsigned int flags,
00964 uint16_t port,
00965 MHD_AcceptPolicyCallback apc,
00966 void *apc_cls,
00967 MHD_AccessHandlerCallback dh,
00968 void *dh_cls, ...);
00969
00975 void MHD_stop_daemon (struct MHD_Daemon *daemon);
00976
00977
00991 int
00992 MHD_get_fdset (struct MHD_Daemon *daemon,
00993 fd_set * read_fd_set,
00994 fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd);
00995
01008 int MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout);
01009
01010
01022 int MHD_run (struct MHD_Daemon *daemon);
01023
01024
01025
01026
01037 int
01038 MHD_get_connection_values (struct MHD_Connection *connection,
01039 enum MHD_ValueKind kind,
01040 MHD_KeyValueIterator iterator, void *iterator_cls);
01041
01071 int
01072 MHD_set_connection_value (struct MHD_Connection *connection,
01073 enum MHD_ValueKind kind,
01074 const char *key, const char *value);
01075
01091 void MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
01092
01102 const char *MHD_lookup_connection_value (struct MHD_Connection *connection,
01103 enum MHD_ValueKind kind,
01104 const char *key);
01105
01116 int
01117 MHD_queue_response (struct MHD_Connection *connection,
01118 unsigned int status_code, struct MHD_Response *response);
01119
01120
01121
01122
01138 struct MHD_Response *MHD_create_response_from_callback (uint64_t size,
01139 size_t block_size,
01140 MHD_ContentReaderCallback
01141 crc, void *crc_cls,
01142 MHD_ContentReaderFreeCallback
01143 crfc);
01144
01157 struct MHD_Response *MHD_create_response_from_data (size_t size,
01158 void *data,
01159 int must_free,
01160 int must_copy);
01161
01162
01171 struct MHD_Response *MHD_create_response_from_fd (size_t size,
01172 int fd);
01173
01182 void MHD_destroy_response (struct MHD_Response *response);
01183
01193 int
01194 MHD_add_response_header (struct MHD_Response *response,
01195 const char *header, const char *content);
01196
01205 int
01206 MHD_del_response_header (struct MHD_Response *response,
01207 const char *header, const char *content);
01208
01218 int
01219 MHD_get_response_headers (struct MHD_Response *response,
01220 MHD_KeyValueIterator iterator, void *iterator_cls);
01221
01222
01230 const char *MHD_get_response_header (struct MHD_Response *response,
01231 const char *key);
01232
01233
01234
01235
01259 struct MHD_PostProcessor *MHD_create_post_processor (struct MHD_Connection
01260 *connection,
01261 size_t buffer_size,
01262 MHD_PostDataIterator
01263 iter, void *cls);
01264
01279 int
01280 MHD_post_process (struct MHD_PostProcessor *pp,
01281 const char *post_data, size_t post_data_len);
01282
01292 int MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
01293
01294
01295
01296
01297
01302 #define MHD_INVALID_NONCE -1
01303
01304
01312 char *
01313 MHD_digest_auth_get_username (struct MHD_Connection *connection);
01314
01315
01328 int
01329 MHD_digest_auth_check (struct MHD_Connection *connection,
01330 const char *realm,
01331 const char *username,
01332 const char *password,
01333 unsigned int nonce_timeout);
01334
01335
01349 int
01350 MHD_queue_auth_fail_response (struct MHD_Connection *connection,
01351 const char *realm,
01352 const char *opaque,
01353 struct MHD_Response *response,
01354 int signal_stale);
01355
01356
01357
01358
01362 union MHD_ConnectionInfo
01363 {
01364
01368 int cipher_algorithm;
01369
01373 int protocol;
01374
01378 void * tls_session;
01379
01383 struct sockaddr_in * client_addr;
01384 };
01385
01395 const union MHD_ConnectionInfo *MHD_get_connection_info (struct MHD_Connection
01396 *connection,
01397 enum
01398 MHD_ConnectionInfoType
01399 infoType, ...);
01400
01401
01405 union MHD_DaemonInfo
01406 {
01410 size_t key_size;
01411
01415 size_t mac_key_size;
01416
01420 int listen_fd;
01421 };
01422
01433 const union MHD_DaemonInfo *MHD_get_daemon_info (struct MHD_Daemon *daemon,
01434 enum MHD_DaemonInfoType
01435 infoType, ...);
01436
01442 const char* MHD_get_version(void);
01443
01444 #if 0
01445 {
01446 #endif
01447 #ifdef __cplusplus
01448 }
01449 #endif
01450
01451 #endif